##// END OF EJS Templates
HGcommand.vim : doc integration
"Mathieu Clabaut " -
r2603:f8005740 default
parent child Browse files
Show More
This diff has been collapsed as it changes many lines, (721 lines changed) Show them Hide them
@@ -1,1265 +1,1984 b''
1 " vim600: set foldmethod=marker:
1 " vim600: set foldmethod=marker:
2 "
2 "
3 " Vim plugin to assist in working with HG-controlled files.
3 " Vim plugin to assist in working with HG-controlled files.
4 "
4 "
5 " Last Change: 2006/02/22
5 " Last Change: 2006/02/22
6 " Version: 1.76
6 " Version: 1.76
7 " Maintainer: Mathieu Clabaut <mathieu.clabaut@gmail.com>
7 " Maintainer: Mathieu Clabaut <mathieu.clabaut@gmail.com>
8 " License: This file is placed in the public domain.
8 " License: This file is placed in the public domain.
9 " Credits: {{{1
9 " Credits: {{{1
10 " Bob Hiestand <bob.hiestand@gmail.com> for the fabulous
10 " Bob Hiestand <bob.hiestand@gmail.com> for the fabulous
11 " cvscommand.vim from which this script was directly created by
11 " cvscommand.vim from which this script was directly created by
12 " means of sed commands and minor tweaks.
12 " means of sed commands and minor tweaks.
13
13
14 " Section: Documentation {{{1
14 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
15 "
16 " Section: Documentation
17 "----------------------------
18 "
19 " Documentation should be available by ":help hgcommand" command, once the
20 " script has been copied in you .vim/plugin directory.
21 "
22 " You still can read the documentation at the end of this file. Locate it by
23 " searching the "hgcommand-contents" string (and set ft=help to have
24 " appropriate syntaxic coloration).
25 "
26 " Section: Documentation : detail {{{1
15 "
27 "
16 " Provides functions to invoke various HG commands on the current file
28 " Provides functions to invoke various HG commands on the current file
17 " (either the current buffer, or, in the case of an directory buffer, the file
29 " (either the current buffer, or, in the case of an directory buffer, the file
18 " on the current line). The output of the commands is captured in a new
30 " on the current line). The output of the commands is captured in a new
19 " scratch window. For convenience, if the functions are invoked on a HG
31 " scratch window. For convenience, if the functions are invoked on a HG
20 " output window, the original file is used for the hg operation instead after
32 " output window, the original file is used for the hg operation instead after
21 " the window is split. This is primarily useful when running HGCommit and
33 " the window is split. This is primarily useful when running HGCommit and
22 " you need to see the changes made, so that HGDiff is usable and shows up in
34 " you need to see the changes made, so that HGDiff is usable and shows up in
23 " another window.
35 " another window.
24 "
36 "
25 " Command documentation {{{2
37 " Command documentation {{{2
26 "
38 "
27 " HGAdd Performs "hg add" on the current file.
39 " HGAdd Performs "hg add" on the current file.
28 "
40 "
29 " HGAnnotate Performs "hg annotate" on the current file. If an
41 " HGAnnotate Performs "hg annotate" on the current file. If an
30 " argument is given, the argument is used as a revision
42 " argument is given, the argument is used as a revision
31 " number to display. If not given an argument, it uses the
43 " number to display. If not given an argument, it uses the
32 " most recent version of the file on the current branch.
44 " most recent version of the file on the current branch.
33 " Additionally, if the current buffer is a HGAnnotate buffer
45 " Additionally, if the current buffer is a HGAnnotate buffer
34 " already, the version number on the current line is used.
46 " already, the version number on the current line is used.
35 "
47 "
36 " If the 'HGCommandAnnotateParent' variable is set to a
48 " If the 'HGCommandAnnotateParent' variable is set to a
37 " non-zero value, the version previous to the one on the
49 " non-zero value, the version previous to the one on the
38 " current line is used instead. This allows one to navigate
50 " current line is used instead. This allows one to navigate
39 " back to examine the previous version of a line.
51 " back to examine the previous version of a line.
40 "
52 "
41 " HGCommit[!] If called with arguments, this performs "hg commit" using
53 " HGCommit[!] If called with arguments, this performs "hg commit" using
42 " the arguments as the log message.
54 " the arguments as the log message.
43 "
55 "
44 " If '!' is used, an empty log message is committed.
56 " If '!' is used, an empty log message is committed.
45 "
57 "
46 " If called with no arguments, this is a two-step command.
58 " If called with no arguments, this is a two-step command.
47 " The first step opens a buffer to accept a log message.
59 " The first step opens a buffer to accept a log message.
48 " When that buffer is written, it is automatically closed and
60 " When that buffer is written, it is automatically closed and
49 " the file is committed using the information from that log
61 " the file is committed using the information from that log
50 " message. The commit can be abandoned if the log message
62 " message. The commit can be abandoned if the log message
51 " buffer is deleted or wiped before being written.
63 " buffer is deleted or wiped before being written.
52 "
64 "
53 " HGDiff With no arguments, this performs "hg diff" on the current
65 " HGDiff With no arguments, this performs "hg diff" on the current
54 " file. With one argument, "hg diff" is performed on the
66 " file. With one argument, "hg diff" is performed on the
55 " current file against the specified revision. With two
67 " current file against the specified revision. With two
56 " arguments, hg diff is performed between the specified
68 " arguments, hg diff is performed between the specified
57 " revisions of the current file. This command uses the
69 " revisions of the current file. This command uses the
58 " 'HGCommandDiffOpt' variable to specify diff options. If
70 " 'HGCommandDiffOpt' variable to specify diff options. If
59 " that variable does not exist, then 'wbBc' is assumed. If
71 " that variable does not exist, then 'wbBc' is assumed. If
60 " you wish to have no options, then set it to the empty
72 " you wish to have no options, then set it to the empty
61 " string.
73 " string.
62 "
74 "
63 " HGGotoOriginal Returns the current window to the source buffer if the
75 " HGGotoOriginal Returns the current window to the source buffer if the
64 " current buffer is a HG output buffer.
76 " current buffer is a HG output buffer.
65 "
77 "
66 " HGLog Performs "hg log" on the current file.
78 " HGLog Performs "hg log" on the current file.
67 "
79 "
68 " HGRevert Replaces the modified version of the current file with the
80 " HGRevert Replaces the modified version of the current file with the
69 " most recent version from the repository.
81 " most recent version from the repository.
70 "
82 "
71 " HGReview Retrieves a particular version of the current file. If no
83 " HGReview Retrieves a particular version of the current file. If no
72 " argument is given, the most recent version of the file on
84 " argument is given, the most recent version of the file on
73 " the current branch is retrieved. The specified revision is
85 " the current branch is retrieved. The specified revision is
74 " retrieved into a new buffer.
86 " retrieved into a new buffer.
75 "
87 "
76 " HGStatus Performs "hg status" on the current file.
88 " HGStatus Performs "hg status" on the current file.
77 "
89 "
78 " HGUpdate Performs "hg update" on the current file.
90 " HGUpdate Performs "hg update" on the current file.
79 "
91 "
80 " HGVimDiff With no arguments, this prompts the user for a revision and
92 " HGVimDiff With no arguments, this prompts the user for a revision and
81 " then uses vimdiff to display the differences between the
93 " then uses vimdiff to display the differences between the
82 " current file and the specified revision. If no revision is
94 " current file and the specified revision. If no revision is
83 " specified, the most recent version of the file on the
95 " specified, the most recent version of the file on the
84 " current branch is used. With one argument, that argument
96 " current branch is used. With one argument, that argument
85 " is used as the revision as above. With two arguments, the
97 " is used as the revision as above. With two arguments, the
86 " differences between the two revisions is displayed using
98 " differences between the two revisions is displayed using
87 " vimdiff.
99 " vimdiff.
88 "
100 "
89 " With either zero or one argument, the original buffer is used
101 " With either zero or one argument, the original buffer is used
90 " to perform the vimdiff. When the other buffer is closed, the
102 " to perform the vimdiff. When the other buffer is closed, the
91 " original buffer will be returned to normal mode.
103 " original buffer will be returned to normal mode.
92 "
104 "
93 " Once vimdiff mode is started using the above methods,
105 " Once vimdiff mode is started using the above methods,
94 " additional vimdiff buffers may be added by passing a single
106 " additional vimdiff buffers may be added by passing a single
95 " version argument to the command. There may be up to 4
107 " version argument to the command. There may be up to 4
96 " vimdiff buffers total.
108 " vimdiff buffers total.
97 "
109 "
98 " Using the 2-argument form of the command resets the vimdiff
110 " Using the 2-argument form of the command resets the vimdiff
99 " to only those 2 versions. Additionally, invoking the
111 " to only those 2 versions. Additionally, invoking the
100 " command on a different file will close the previous vimdiff
112 " command on a different file will close the previous vimdiff
101 " buffers.
113 " buffers.
102 "
114 "
103 "
115 "
104 " Mapping documentation: {{{2
116 " Mapping documentation: {{{2
105 "
117 "
106 " By default, a mapping is defined for each command. User-provided mappings
118 " By default, a mapping is defined for each command. User-provided mappings
107 " can be used instead by mapping to <Plug>CommandName, for instance:
119 " can be used instead by mapping to <Plug>CommandName, for instance:
108 "
120 "
109 " nnoremap ,ca <Plug>HGAdd
121 " nnoremap ,ca <Plug>HGAdd
110 "
122 "
111 " The default mappings are as follow:
123 " The default mappings are as follow:
112 "
124 "
113 " <Leader>hga HGAdd
125 " <Leader>hga HGAdd
114 " <Leader>hgn HGAnnotate
126 " <Leader>hgn HGAnnotate
115 " <Leader>hgc HGCommit
127 " <Leader>hgc HGCommit
116 " <Leader>hgd HGDiff
128 " <Leader>hgd HGDiff
117 " <Leader>hgg HGGotoOriginal
129 " <Leader>hgg HGGotoOriginal
118 " <Leader>hgG HGGotoOriginal!
130 " <Leader>hgG HGGotoOriginal!
119 " <Leader>hgl HGLog
131 " <Leader>hgl HGLog
120 " <Leader>hgr HGReview
132 " <Leader>hgr HGReview
121 " <Leader>hgs HGStatus
133 " <Leader>hgs HGStatus
122 " <Leader>hgu HGUpdate
134 " <Leader>hgu HGUpdate
123 " <Leader>hgv HGVimDiff
135 " <Leader>hgv HGVimDiff
124 "
136 "
125 " Options documentation: {{{2
137 " Options documentation: {{{2
126 "
138 "
127 " Several variables are checked by the script to determine behavior as follow:
139 " Several variables are checked by the script to determine behavior as follow:
128 "
140 "
129 " HGCommandAnnotateParent
141 " HGCommandAnnotateParent
130 " This variable, if set to a non-zero value, causes the zero-argument form
142 " This variable, if set to a non-zero value, causes the zero-argument form
131 " of HGAnnotate when invoked on a HGAnnotate buffer to go to the version
143 " of HGAnnotate when invoked on a HGAnnotate buffer to go to the version
132 " previous to that displayed on the current line. If not set, it defaults
144 " previous to that displayed on the current line. If not set, it defaults
133 " to 0.
145 " to 0.
134 "
146 "
135 " HGCommandCommitOnWrite
147 " HGCommandCommitOnWrite
136 " This variable, if set to a non-zero value, causes the pending hg commit
148 " This variable, if set to a non-zero value, causes the pending hg commit
137 " to take place immediately as soon as the log message buffer is written.
149 " to take place immediately as soon as the log message buffer is written.
138 " If set to zero, only the HGCommit mapping will cause the pending commit
150 " If set to zero, only the HGCommit mapping will cause the pending commit
139 " to occur. If not set, it defaults to 1.
151 " to occur. If not set, it defaults to 1.
140 "
152 "
141 " HGCommandDeleteOnHide
153 " HGCommandDeleteOnHide
142 " This variable, if set to a non-zero value, causes the temporary HG result
154 " This variable, if set to a non-zero value, causes the temporary HG result
143 " buffers to automatically delete themselves when hidden.
155 " buffers to automatically delete themselves when hidden.
144 "
156 "
145 " HGCommandDiffOpt
157 " HGCommandDiffOpt
146 " This variable, if set, determines the options passed to the diff command
158 " This variable, if set, determines the options passed to the diff command
147 " of HG. If not set, it defaults to 'wbBc'.
159 " of HG. If not set, it defaults to 'wbBc'.
148 "
160 "
149 " HGCommandDiffSplit
161 " HGCommandDiffSplit
150 " This variable overrides the HGCommandSplit variable, but only for buffers
162 " This variable overrides the HGCommandSplit variable, but only for buffers
151 " created with HGVimDiff.
163 " created with HGVimDiff.
152 "
164 "
153 " HGCommandEdit
165 " HGCommandEdit
154 " This variable controls whether the original buffer is replaced ('edit') or
166 " This variable controls whether the original buffer is replaced ('edit') or
155 " split ('split'). If not set, it defaults to 'edit'.
167 " split ('split'). If not set, it defaults to 'edit'.
156 "
168 "
157 " HGCommandEnableBufferSetup
169 " HGCommandEnableBufferSetup
158 " This variable, if set to a non-zero value, activates HG buffer management
170 " This variable, if set to a non-zero value, activates HG buffer management
159 " mode. This mode means that two buffer variables, 'HGRevision' and
171 " mode. This mode means that two buffer variables, 'HGRevision' and
160 " 'HGBranch', are set if the file is HG-controlled. This is useful for
172 " 'HGBranch', are set if the file is HG-controlled. This is useful for
161 " displaying version information in the status bar.
173 " displaying version information in the status bar.
162 "
174 "
163 " HGCommandInteractive
175 " HGCommandInteractive
164 " This variable, if set to a non-zero value, causes appropriate functions (for
176 " This variable, if set to a non-zero value, causes appropriate functions (for
165 " the moment, only HGReview) to query the user for a revision to use
177 " the moment, only HGReview) to query the user for a revision to use
166 " instead of the current revision if none is specified.
178 " instead of the current revision if none is specified.
167 "
179 "
168 " HGCommandNameMarker
180 " HGCommandNameMarker
169 " This variable, if set, configures the special attention-getting characters
181 " This variable, if set, configures the special attention-getting characters
170 " that appear on either side of the hg buffer type in the buffer name.
182 " that appear on either side of the hg buffer type in the buffer name.
171 " This has no effect unless 'HGCommandNameResultBuffers' is set to a true
183 " This has no effect unless 'HGCommandNameResultBuffers' is set to a true
172 " value. If not set, it defaults to '_'.
184 " value. If not set, it defaults to '_'.
173 "
185 "
174 " HGCommandNameResultBuffers
186 " HGCommandNameResultBuffers
175 " This variable, if set to a true value, causes the hg result buffers to be
187 " This variable, if set to a true value, causes the hg result buffers to be
176 " named in the old way ('<source file name> _<hg command>_'). If not set
188 " named in the old way ('<source file name> _<hg command>_'). If not set
177 " or set to a false value, the result buffer is nameless.
189 " or set to a false value, the result buffer is nameless.
178 "
190 "
179 " HGCommandSplit
191 " HGCommandSplit
180 " This variable controls the orientation of the various window splits that
192 " This variable controls the orientation of the various window splits that
181 " may occur (such as with HGVimDiff, when using a HG command on a HG
193 " may occur (such as with HGVimDiff, when using a HG command on a HG
182 " command buffer, or when the 'HGCommandEdit' variable is set to 'split'.
194 " command buffer, or when the 'HGCommandEdit' variable is set to 'split'.
183 " If set to 'horizontal', the resulting windows will be on stacked on top of
195 " If set to 'horizontal', the resulting windows will be on stacked on top of
184 " one another. If set to 'vertical', the resulting windows will be
196 " one another. If set to 'vertical', the resulting windows will be
185 " side-by-side. If not set, it defaults to 'horizontal' for all but
197 " side-by-side. If not set, it defaults to 'horizontal' for all but
186 " HGVimDiff windows.
198 " HGVimDiff windows.
187 "
199 "
188 " Event documentation {{{2
200 " Event documentation {{{2
189 " For additional customization, hgcommand.vim uses User event autocommand
201 " For additional customization, hgcommand.vim uses User event autocommand
190 " hooks. Each event is in the HGCommand group, and different patterns
202 " hooks. Each event is in the HGCommand group, and different patterns
191 " match the various hooks.
203 " match the various hooks.
192 "
204 "
193 " For instance, the following could be added to the vimrc to provide a 'q'
205 " For instance, the following could be added to the vimrc to provide a 'q'
194 " mapping to quit a HG buffer:
206 " mapping to quit a HG buffer:
195 "
207 "
196 " augroup HGCommand
208 " augroup HGCommand
197 " au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr>
209 " au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr>
198 " augroup END
210 " augroup END
199 "
211 "
200 " The following hooks are available:
212 " The following hooks are available:
201 "
213 "
202 " HGBufferCreated This event is fired just after a hg command
214 " HGBufferCreated This event is fired just after a hg command
203 " result buffer is created and filled with the
215 " result buffer is created and filled with the
204 " result of a hg command. It is executed within
216 " result of a hg command. It is executed within
205 " the context of the new buffer.
217 " the context of the new buffer.
206 "
218 "
207 " HGBufferSetup This event is fired just after HG buffer setup
219 " HGBufferSetup This event is fired just after HG buffer setup
208 " occurs, if enabled.
220 " occurs, if enabled.
209 "
221 "
210 " HGPluginInit This event is fired when the HGCommand plugin
222 " HGPluginInit This event is fired when the HGCommand plugin
211 " first loads.
223 " first loads.
212 "
224 "
213 " HGPluginFinish This event is fired just after the HGCommand
225 " HGPluginFinish This event is fired just after the HGCommand
214 " plugin loads.
226 " plugin loads.
215 "
227 "
216 " HGVimDiffFinish This event is fired just after the HGVimDiff
228 " HGVimDiffFinish This event is fired just after the HGVimDiff
217 " command executes to allow customization of,
229 " command executes to allow customization of,
218 " for instance, window placement and focus.
230 " for instance, window placement and focus.
219 "
231 "
220 " Section: Plugin header {{{1
232 " Section: Plugin header {{{1
221
233
222 " loaded_hgcommand is set to 1 when the initialization begins, and 2 when it
234 " loaded_hgcommand is set to 1 when the initialization begins, and 2 when it
223 " completes. This allows various actions to only be taken by functions after
235 " completes. This allows various actions to only be taken by functions after
224 " system initialization.
236 " system initialization.
225
237
226 if exists("loaded_hgcommand")
238 if exists("loaded_hgcommand")
227 finish
239 finish
228 endif
240 endif
229 let loaded_hgcommand = 1
241 let loaded_hgcommand = 1
230
242
231 if v:version < 602
243 if v:version < 602
232 echohl WarningMsg|echomsg "HGCommand 1.69 or later requires VIM 6.2 or later"|echohl None
244 echohl WarningMsg|echomsg "HGCommand 1.69 or later requires VIM 6.2 or later"|echohl None
233 finish
245 finish
234 endif
246 endif
235
247
236 " Section: Event group setup {{{1
248 " Section: Event group setup {{{1
237
249
238 augroup HGCommand
250 augroup HGCommand
239 augroup END
251 augroup END
240
252
241 " Section: Plugin initialization {{{1
253 " Section: Plugin initialization {{{1
242 silent do HGCommand User HGPluginInit
254 silent do HGCommand User HGPluginInit
243
255
244 " Section: Script variable initialization {{{1
256 " Section: Script variable initialization {{{1
245
257
246 let s:HGCommandEditFileRunning = 0
258 let s:HGCommandEditFileRunning = 0
247 unlet! s:vimDiffRestoreCmd
259 unlet! s:vimDiffRestoreCmd
248 unlet! s:vimDiffSourceBuffer
260 unlet! s:vimDiffSourceBuffer
249 unlet! s:vimDiffBufferCount
261 unlet! s:vimDiffBufferCount
250 unlet! s:vimDiffScratchList
262 unlet! s:vimDiffScratchList
251
263
252 " Section: Utility functions {{{1
264 " Section: Utility functions {{{1
253
265
254 " Function: s:HGResolveLink() {{{2
266 " Function: s:HGResolveLink() {{{2
255 " Fully resolve the given file name to remove shortcuts or symbolic links.
267 " Fully resolve the given file name to remove shortcuts or symbolic links.
256
268
257 function! s:HGResolveLink(fileName)
269 function! s:HGResolveLink(fileName)
258 let resolved = resolve(a:fileName)
270 let resolved = resolve(a:fileName)
259 if resolved != a:fileName
271 if resolved != a:fileName
260 let resolved = s:HGResolveLink(resolved)
272 let resolved = s:HGResolveLink(resolved)
261 endif
273 endif
262 return resolved
274 return resolved
263 endfunction
275 endfunction
264
276
265 " Function: s:HGChangeToCurrentFileDir() {{{2
277 " Function: s:HGChangeToCurrentFileDir() {{{2
266 " Go to the directory in which the current HG-controlled file is located.
278 " Go to the directory in which the current HG-controlled file is located.
267 " If this is a HG command buffer, first switch to the original file.
279 " If this is a HG command buffer, first switch to the original file.
268
280
269 function! s:HGChangeToCurrentFileDir(fileName)
281 function! s:HGChangeToCurrentFileDir(fileName)
270 let oldCwd=getcwd()
282 let oldCwd=getcwd()
271 let fileName=s:HGResolveLink(a:fileName)
283 let fileName=s:HGResolveLink(a:fileName)
272 let newCwd=fnamemodify(fileName, ':h')
284 let newCwd=fnamemodify(fileName, ':h')
273 if strlen(newCwd) > 0
285 if strlen(newCwd) > 0
274 execute 'cd' escape(newCwd, ' ')
286 execute 'cd' escape(newCwd, ' ')
275 endif
287 endif
276 return oldCwd
288 return oldCwd
277 endfunction
289 endfunction
278
290
279 " Function: s:HGGetOption(name, default) {{{2
291 " Function: s:HGGetOption(name, default) {{{2
280 " Grab a user-specified option to override the default provided. Options are
292 " Grab a user-specified option to override the default provided. Options are
281 " searched in the window, buffer, then global spaces.
293 " searched in the window, buffer, then global spaces.
282
294
283 function! s:HGGetOption(name, default)
295 function! s:HGGetOption(name, default)
284 if exists("s:" . a:name . "Override")
296 if exists("s:" . a:name . "Override")
285 execute "return s:".a:name."Override"
297 execute "return s:".a:name."Override"
286 elseif exists("w:" . a:name)
298 elseif exists("w:" . a:name)
287 execute "return w:".a:name
299 execute "return w:".a:name
288 elseif exists("b:" . a:name)
300 elseif exists("b:" . a:name)
289 execute "return b:".a:name
301 execute "return b:".a:name
290 elseif exists("g:" . a:name)
302 elseif exists("g:" . a:name)
291 execute "return g:".a:name
303 execute "return g:".a:name
292 else
304 else
293 return a:default
305 return a:default
294 endif
306 endif
295 endfunction
307 endfunction
296
308
297 " Function: s:HGEditFile(name, origBuffNR) {{{2
309 " Function: s:HGEditFile(name, origBuffNR) {{{2
298 " Wrapper around the 'edit' command to provide some helpful error text if the
310 " Wrapper around the 'edit' command to provide some helpful error text if the
299 " current buffer can't be abandoned. If name is provided, it is used;
311 " current buffer can't be abandoned. If name is provided, it is used;
300 " otherwise, a nameless scratch buffer is used.
312 " otherwise, a nameless scratch buffer is used.
301 " Returns: 0 if successful, -1 if an error occurs.
313 " Returns: 0 if successful, -1 if an error occurs.
302
314
303 function! s:HGEditFile(name, origBuffNR)
315 function! s:HGEditFile(name, origBuffNR)
304 "Name parameter will be pasted into expression.
316 "Name parameter will be pasted into expression.
305 let name = escape(a:name, ' *?\')
317 let name = escape(a:name, ' *?\')
306
318
307 let editCommand = s:HGGetOption('HGCommandEdit', 'edit')
319 let editCommand = s:HGGetOption('HGCommandEdit', 'edit')
308 if editCommand != 'edit'
320 if editCommand != 'edit'
309 if s:HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
321 if s:HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
310 if name == ""
322 if name == ""
311 let editCommand = 'rightbelow new'
323 let editCommand = 'rightbelow new'
312 else
324 else
313 let editCommand = 'rightbelow split ' . name
325 let editCommand = 'rightbelow split ' . name
314 endif
326 endif
315 else
327 else
316 if name == ""
328 if name == ""
317 let editCommand = 'vert rightbelow new'
329 let editCommand = 'vert rightbelow new'
318 else
330 else
319 let editCommand = 'vert rightbelow split ' . name
331 let editCommand = 'vert rightbelow split ' . name
320 endif
332 endif
321 endif
333 endif
322 else
334 else
323 if name == ""
335 if name == ""
324 let editCommand = 'enew'
336 let editCommand = 'enew'
325 else
337 else
326 let editCommand = 'edit ' . name
338 let editCommand = 'edit ' . name
327 endif
339 endif
328 endif
340 endif
329
341
330 " Protect against useless buffer set-up
342 " Protect against useless buffer set-up
331 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
343 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
332 try
344 try
333 execute editCommand
345 execute editCommand
334 finally
346 finally
335 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
347 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
336 endtry
348 endtry
337
349
338 let b:HGOrigBuffNR=a:origBuffNR
350 let b:HGOrigBuffNR=a:origBuffNR
339 let b:HGCommandEdit='split'
351 let b:HGCommandEdit='split'
340 endfunction
352 endfunction
341
353
342 " Function: s:HGCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2
354 " Function: s:HGCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2
343 " Creates a new scratch buffer and captures the output from execution of the
355 " Creates a new scratch buffer and captures the output from execution of the
344 " given command. The name of the scratch buffer is returned.
356 " given command. The name of the scratch buffer is returned.
345
357
346 function! s:HGCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR)
358 function! s:HGCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR)
347 let fileName=bufname(a:origBuffNR)
359 let fileName=bufname(a:origBuffNR)
348
360
349 let resultBufferName=''
361 let resultBufferName=''
350
362
351 if s:HGGetOption("HGCommandNameResultBuffers", 0)
363 if s:HGGetOption("HGCommandNameResultBuffers", 0)
352 let nameMarker = s:HGGetOption("HGCommandNameMarker", '_')
364 let nameMarker = s:HGGetOption("HGCommandNameMarker", '_')
353 if strlen(a:statusText) > 0
365 if strlen(a:statusText) > 0
354 let bufName=a:cmdName . ' -- ' . a:statusText
366 let bufName=a:cmdName . ' -- ' . a:statusText
355 else
367 else
356 let bufName=a:cmdName
368 let bufName=a:cmdName
357 endif
369 endif
358 let bufName=fileName . ' ' . nameMarker . bufName . nameMarker
370 let bufName=fileName . ' ' . nameMarker . bufName . nameMarker
359 let counter=0
371 let counter=0
360 let resultBufferName = bufName
372 let resultBufferName = bufName
361 while buflisted(resultBufferName)
373 while buflisted(resultBufferName)
362 let counter=counter + 1
374 let counter=counter + 1
363 let resultBufferName=bufName . ' (' . counter . ')'
375 let resultBufferName=bufName . ' (' . counter . ')'
364 endwhile
376 endwhile
365 endif
377 endif
366
378
367 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
379 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
368 echomsg "DBG :".hgCommand
380 echomsg "DBG :".hgCommand
369 let hgOut = system(hgCommand)
381 let hgOut = system(hgCommand)
370 " HACK: diff command does not return proper error codes
382 " HACK: diff command does not return proper error codes
371 if v:shell_error && a:cmdName != 'hgdiff'
383 if v:shell_error && a:cmdName != 'hgdiff'
372 if strlen(hgOut) == 0
384 if strlen(hgOut) == 0
373 echoerr "HG command failed"
385 echoerr "HG command failed"
374 else
386 else
375 echoerr "HG command failed: " . hgOut
387 echoerr "HG command failed: " . hgOut
376 endif
388 endif
377 return -1
389 return -1
378 endif
390 endif
379 if strlen(hgOut) == 0
391 if strlen(hgOut) == 0
380 " Handle case of no output. In this case, it is important to check the
392 " Handle case of no output. In this case, it is important to check the
381 " file status, especially since hg edit/unedit may change the attributes
393 " file status, especially since hg edit/unedit may change the attributes
382 " of the file with no visible output.
394 " of the file with no visible output.
383
395
384 echomsg "No output from HG command"
396 echomsg "No output from HG command"
385 checktime
397 checktime
386 return -1
398 return -1
387 endif
399 endif
388
400
389 if s:HGEditFile(resultBufferName, a:origBuffNR) == -1
401 if s:HGEditFile(resultBufferName, a:origBuffNR) == -1
390 return -1
402 return -1
391 endif
403 endif
392
404
393 set buftype=nofile
405 set buftype=nofile
394 set noswapfile
406 set noswapfile
395 set filetype=
407 set filetype=
396
408
397 if s:HGGetOption("HGCommandDeleteOnHide", 0)
409 if s:HGGetOption("HGCommandDeleteOnHide", 0)
398 set bufhidden=delete
410 set bufhidden=delete
399 endif
411 endif
400
412
401 silent 0put=hgOut
413 silent 0put=hgOut
402
414
403 " The last command left a blank line at the end of the buffer. If the
415 " The last command left a blank line at the end of the buffer. If the
404 " last line is folded (a side effect of the 'put') then the attempt to
416 " last line is folded (a side effect of the 'put') then the attempt to
405 " remove the blank line will kill the last fold.
417 " remove the blank line will kill the last fold.
406 "
418 "
407 " This could be fixed by explicitly detecting whether the last line is
419 " This could be fixed by explicitly detecting whether the last line is
408 " within a fold, but I prefer to simply unfold the result buffer altogether.
420 " within a fold, but I prefer to simply unfold the result buffer altogether.
409
421
410 if has('folding')
422 if has('folding')
411 normal zR
423 normal zR
412 endif
424 endif
413
425
414 $d
426 $d
415 1
427 1
416
428
417 " Define the environment and execute user-defined hooks.
429 " Define the environment and execute user-defined hooks.
418
430
419 let b:HGSourceFile=fileName
431 let b:HGSourceFile=fileName
420 let b:HGCommand=a:cmdName
432 let b:HGCommand=a:cmdName
421 if a:statusText != ""
433 if a:statusText != ""
422 let b:HGStatusText=a:statusText
434 let b:HGStatusText=a:statusText
423 endif
435 endif
424
436
425 silent do HGCommand User HGBufferCreated
437 silent do HGCommand User HGBufferCreated
426 return bufnr("%")
438 return bufnr("%")
427 endfunction
439 endfunction
428
440
429 " Function: s:HGBufferCheck(hgBuffer) {{{2
441 " Function: s:HGBufferCheck(hgBuffer) {{{2
430 " Attempts to locate the original file to which HG operations were applied
442 " Attempts to locate the original file to which HG operations were applied
431 " for a given buffer.
443 " for a given buffer.
432
444
433 function! s:HGBufferCheck(hgBuffer)
445 function! s:HGBufferCheck(hgBuffer)
434 let origBuffer = getbufvar(a:hgBuffer, "HGOrigBuffNR")
446 let origBuffer = getbufvar(a:hgBuffer, "HGOrigBuffNR")
435 if origBuffer
447 if origBuffer
436 if bufexists(origBuffer)
448 if bufexists(origBuffer)
437 return origBuffer
449 return origBuffer
438 else
450 else
439 " Original buffer no longer exists.
451 " Original buffer no longer exists.
440 return -1
452 return -1
441 endif
453 endif
442 else
454 else
443 " No original buffer
455 " No original buffer
444 return a:hgBuffer
456 return a:hgBuffer
445 endif
457 endif
446 endfunction
458 endfunction
447
459
448 " Function: s:HGCurrentBufferCheck() {{{2
460 " Function: s:HGCurrentBufferCheck() {{{2
449 " Attempts to locate the original file to which HG operations were applied
461 " Attempts to locate the original file to which HG operations were applied
450 " for the current buffer.
462 " for the current buffer.
451
463
452 function! s:HGCurrentBufferCheck()
464 function! s:HGCurrentBufferCheck()
453 return s:HGBufferCheck(bufnr("%"))
465 return s:HGBufferCheck(bufnr("%"))
454 endfunction
466 endfunction
455
467
456 " Function: s:HGToggleDeleteOnHide() {{{2
468 " Function: s:HGToggleDeleteOnHide() {{{2
457 " Toggles on and off the delete-on-hide behavior of HG buffers
469 " Toggles on and off the delete-on-hide behavior of HG buffers
458
470
459 function! s:HGToggleDeleteOnHide()
471 function! s:HGToggleDeleteOnHide()
460 if exists("g:HGCommandDeleteOnHide")
472 if exists("g:HGCommandDeleteOnHide")
461 unlet g:HGCommandDeleteOnHide
473 unlet g:HGCommandDeleteOnHide
462 else
474 else
463 let g:HGCommandDeleteOnHide=1
475 let g:HGCommandDeleteOnHide=1
464 endif
476 endif
465 endfunction
477 endfunction
466
478
467 " Function: s:HGDoCommand(hgcmd, cmdName, statusText) {{{2
479 " Function: s:HGDoCommand(hgcmd, cmdName, statusText) {{{2
468 " General skeleton for HG function execution.
480 " General skeleton for HG function execution.
469 " Returns: name of the new command buffer containing the command results
481 " Returns: name of the new command buffer containing the command results
470
482
471 function! s:HGDoCommand(cmd, cmdName, statusText)
483 function! s:HGDoCommand(cmd, cmdName, statusText)
472 let hgBufferCheck=s:HGCurrentBufferCheck()
484 let hgBufferCheck=s:HGCurrentBufferCheck()
473 if hgBufferCheck == -1
485 if hgBufferCheck == -1
474 echo "Original buffer no longer exists, aborting."
486 echo "Original buffer no longer exists, aborting."
475 return -1
487 return -1
476 endif
488 endif
477
489
478 let fileName=bufname(hgBufferCheck)
490 let fileName=bufname(hgBufferCheck)
479 if isdirectory(fileName)
491 if isdirectory(fileName)
480 let fileName=fileName . "/" . getline(".")
492 let fileName=fileName . "/" . getline(".")
481 endif
493 endif
482 let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t')
494 let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t')
483 let oldCwd=s:HGChangeToCurrentFileDir(fileName)
495 let oldCwd=s:HGChangeToCurrentFileDir(fileName)
484 try
496 try
485 " TODO
497 " TODO
486 "if !filereadable('HG/Root')
498 "if !filereadable('HG/Root')
487 "throw fileName . ' is not a HG-controlled file.'
499 "throw fileName . ' is not a HG-controlled file.'
488 "endif
500 "endif
489 let fullCmd = a:cmd . ' "' . realFileName . '"'
501 let fullCmd = a:cmd . ' "' . realFileName . '"'
490 "echomsg "DEBUG".fullCmd
502 "echomsg "DEBUG".fullCmd
491 let resultBuffer=s:HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
503 let resultBuffer=s:HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
492 return resultBuffer
504 return resultBuffer
493 catch
505 catch
494 echoerr v:exception
506 echoerr v:exception
495 return -1
507 return -1
496 finally
508 finally
497 execute 'cd' escape(oldCwd, ' ')
509 execute 'cd' escape(oldCwd, ' ')
498 endtry
510 endtry
499 endfunction
511 endfunction
500
512
501
513
502 " Function: s:HGGetStatusVars(revision, branch, repository) {{{2
514 " Function: s:HGGetStatusVars(revision, branch, repository) {{{2
503 "
515 "
504 " Obtains a HG revision number and branch name. The 'revisionVar',
516 " Obtains a HG revision number and branch name. The 'revisionVar',
505 " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold
517 " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold
506 " the corresponding results.
518 " the corresponding results.
507 "
519 "
508 " Returns: string to be exec'd that sets the multiple return values.
520 " Returns: string to be exec'd that sets the multiple return values.
509
521
510 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
522 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
511 let hgBufferCheck=s:HGCurrentBufferCheck()
523 let hgBufferCheck=s:HGCurrentBufferCheck()
512 if hgBufferCheck == -1
524 if hgBufferCheck == -1
513 return ""
525 return ""
514 endif
526 endif
515 let fileName=bufname(hgBufferCheck)
527 let fileName=bufname(hgBufferCheck)
516 let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t')
528 let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t')
517 let oldCwd=s:HGChangeToCurrentFileDir(fileName)
529 let oldCwd=s:HGChangeToCurrentFileDir(fileName)
518 try
530 try
519 ""TODO
531 ""TODO
520 "if !filereadable('HG/Root')
532 "if !filereadable('HG/Root')
521 "return ""
533 "return ""
522 "endif
534 "endif
523 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . fileName
535 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . fileName
524 let statustext=system(hgCommand)
536 let statustext=system(hgCommand)
525 if(v:shell_error)
537 if(v:shell_error)
526 return ""
538 return ""
527 endif
539 endif
528 if match(statustext, '^[?I]') >= 0
540 if match(statustext, '^[?I]') >= 0
529 let revision="NEW"
541 let revision="NEW"
530 elseif match(statustext, '^[R]') >= 0
542 elseif match(statustext, '^[R]') >= 0
531 let revision="REMOVED"
543 let revision="REMOVED"
532 elseif match(statustext, '^[D]') >= 0
544 elseif match(statustext, '^[D]') >= 0
533 let revision="DELETED"
545 let revision="DELETED"
534 elseif match(statustext, '^[A]') >= 0
546 elseif match(statustext, '^[A]') >= 0
535 let revision="ADDED"
547 let revision="ADDED"
536 endif
548 endif
537
549
538 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b "
550 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b "
539 let statustext=system(hgCommand)
551 let statustext=system(hgCommand)
540 if(v:shell_error)
552 if(v:shell_error)
541 return ""
553 return ""
542 endif
554 endif
543 if exists('revision')
555 if exists('revision')
544 let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
556 let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
545 else
557 else
546 let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
558 let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
547 let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
559 let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
548 endif
560 endif
549
561
550 if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
562 if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
551 let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
563 let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
552 let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
564 let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
553 endif
565 endif
554 if a:repositoryVar != ""
566 if a:repositoryVar != ""
555 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " root "
567 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " root "
556 let roottext=system(hgCommand)
568 let roottext=system(hgCommand)
557 let repository=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
569 let repository=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
558 let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . repository . "'"
570 let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . repository . "'"
559 endif
571 endif
560
572
561
573
562
574
563 return returnExpression
575 return returnExpression
564 finally
576 finally
565 execute 'cd' escape(oldCwd, ' ')
577 execute 'cd' escape(oldCwd, ' ')
566 endtry
578 endtry
567 endfunction
579 endfunction
568
580
569 " Function: s:HGSetupBuffer() {{{2
581 " Function: s:HGSetupBuffer() {{{2
570 " Attempts to set the b:HGBranch, b:HGRevision and b:HGRepository variables.
582 " Attempts to set the b:HGBranch, b:HGRevision and b:HGRepository variables.
571
583
572 function! s:HGSetupBuffer()
584 function! s:HGSetupBuffer()
573 if (exists("b:HGBufferSetup") && b:HGBufferSetup)
585 if (exists("b:HGBufferSetup") && b:HGBufferSetup)
574 " This buffer is already set up.
586 " This buffer is already set up.
575 return
587 return
576 endif
588 endif
577
589
578 if !s:HGGetOption("HGCommandEnableBufferSetup", 0)
590 if !s:HGGetOption("HGCommandEnableBufferSetup", 0)
579 \ || @% == ""
591 \ || @% == ""
580 \ || s:HGCommandEditFileRunning > 0
592 \ || s:HGCommandEditFileRunning > 0
581 \ || exists("b:HGOrigBuffNR")
593 \ || exists("b:HGOrigBuffNR")
582 unlet! b:HGRevision
594 unlet! b:HGRevision
583 unlet! b:HGBranch
595 unlet! b:HGBranch
584 unlet! b:HGRepository
596 unlet! b:HGRepository
585 return
597 return
586 endif
598 endif
587
599
588 if !filereadable(expand("%"))
600 if !filereadable(expand("%"))
589 return -1
601 return -1
590 endif
602 endif
591
603
592 let revision=""
604 let revision=""
593 let branch=""
605 let branch=""
594 let repository=""
606 let repository=""
595
607
596 exec s:HGGetStatusVars('revision', 'branch', 'repository')
608 exec s:HGGetStatusVars('revision', 'branch', 'repository')
597 "echomsg "DBG ".revision."#".branch."#".repository
609 "echomsg "DBG ".revision."#".branch."#".repository
598 if revision != ""
610 if revision != ""
599 let b:HGRevision=revision
611 let b:HGRevision=revision
600 else
612 else
601 unlet! b:HGRevision
613 unlet! b:HGRevision
602 endif
614 endif
603 if branch != ""
615 if branch != ""
604 let b:HGBranch=branch
616 let b:HGBranch=branch
605 else
617 else
606 unlet! b:HGBranch
618 unlet! b:HGBranch
607 endif
619 endif
608 if repository != ""
620 if repository != ""
609 let b:HGRepository=repository
621 let b:HGRepository=repository
610 else
622 else
611 unlet! b:HGRepository
623 unlet! b:HGRepository
612 endif
624 endif
613 silent do HGCommand User HGBufferSetup
625 silent do HGCommand User HGBufferSetup
614 let b:HGBufferSetup=1
626 let b:HGBufferSetup=1
615 endfunction
627 endfunction
616
628
617 " Function: s:HGMarkOrigBufferForSetup(hgbuffer) {{{2
629 " Function: s:HGMarkOrigBufferForSetup(hgbuffer) {{{2
618 " Resets the buffer setup state of the original buffer for a given HG buffer.
630 " Resets the buffer setup state of the original buffer for a given HG buffer.
619 " Returns: The HG buffer number in a passthrough mode.
631 " Returns: The HG buffer number in a passthrough mode.
620
632
621 function! s:HGMarkOrigBufferForSetup(hgBuffer)
633 function! s:HGMarkOrigBufferForSetup(hgBuffer)
622 checktime
634 checktime
623 if a:hgBuffer != -1
635 if a:hgBuffer != -1
624 let origBuffer = s:HGBufferCheck(a:hgBuffer)
636 let origBuffer = s:HGBufferCheck(a:hgBuffer)
625 "This should never not work, but I'm paranoid
637 "This should never not work, but I'm paranoid
626 if origBuffer != a:hgBuffer
638 if origBuffer != a:hgBuffer
627 call setbufvar(origBuffer, "HGBufferSetup", 0)
639 call setbufvar(origBuffer, "HGBufferSetup", 0)
628 endif
640 endif
629 endif
641 endif
630 return a:hgBuffer
642 return a:hgBuffer
631 endfunction
643 endfunction
632
644
633 " Function: s:HGOverrideOption(option, [value]) {{{2
645 " Function: s:HGOverrideOption(option, [value]) {{{2
634 " Provides a temporary override for the given HG option. If no value is
646 " Provides a temporary override for the given HG option. If no value is
635 " passed, the override is disabled.
647 " passed, the override is disabled.
636
648
637 function! s:HGOverrideOption(option, ...)
649 function! s:HGOverrideOption(option, ...)
638 if a:0 == 0
650 if a:0 == 0
639 unlet! s:{a:option}Override
651 unlet! s:{a:option}Override
640 else
652 else
641 let s:{a:option}Override = a:1
653 let s:{a:option}Override = a:1
642 endif
654 endif
643 endfunction
655 endfunction
644
656
645 " Function: s:HGWipeoutCommandBuffers() {{{2
657 " Function: s:HGWipeoutCommandBuffers() {{{2
646 " Clears all current HG buffers of the specified type for a given source.
658 " Clears all current HG buffers of the specified type for a given source.
647
659
648 function! s:HGWipeoutCommandBuffers(originalBuffer, hgCommand)
660 function! s:HGWipeoutCommandBuffers(originalBuffer, hgCommand)
649 let buffer = 1
661 let buffer = 1
650 while buffer <= bufnr('$')
662 while buffer <= bufnr('$')
651 if getbufvar(buffer, 'HGOrigBuffNR') == a:originalBuffer
663 if getbufvar(buffer, 'HGOrigBuffNR') == a:originalBuffer
652 if getbufvar(buffer, 'HGCommand') == a:hgCommand
664 if getbufvar(buffer, 'HGCommand') == a:hgCommand
653 execute 'bw' buffer
665 execute 'bw' buffer
654 endif
666 endif
655 endif
667 endif
656 let buffer = buffer + 1
668 let buffer = buffer + 1
657 endwhile
669 endwhile
658 endfunction
670 endfunction
659
671
672 " Function: s:HGInstallDocumentation(full_name, revision) {{{2
673 " Install help documentation.
674 " Arguments:
675 " full_name: Full name of this vim plugin script, including path name.
676 " revision: Revision of the vim script. #version# mark in the document file
677 " will be replaced with this string with 'v' prefix.
678 " Return:
679 " 1 if new document installed, 0 otherwise.
680 " Note: Cleaned and generalized by guo-peng Wen
681 "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
682
683 function! s:HGInstallDocumentation(full_name, revision)
684 " Name of the document path based on the system we use:
685 if (has("unix"))
686 " On UNIX like system, using forward slash:
687 let l:slash_char = '/'
688 let l:mkdir_cmd = ':silent !mkdir -p '
689 else
690 " On M$ system, use backslash. Also mkdir syntax is different.
691 " This should only work on W2K and up.
692 let l:slash_char = '\'
693 let l:mkdir_cmd = ':silent !mkdir '
694 endif
695
696 let l:doc_path = l:slash_char . 'doc'
697 let l:doc_home = l:slash_char . '.vim' . l:slash_char . 'doc'
698
699 " Figure out document path based on full name of this script:
700 let l:vim_plugin_path = fnamemodify(a:full_name, ':h')
701 let l:vim_doc_path = fnamemodify(a:full_name, ':h:h') . l:doc_path
702 if (!(filewritable(l:vim_doc_path) == 2))
703 echomsg "Doc path: " . l:vim_doc_path
704 execute l:mkdir_cmd . '"' . l:vim_doc_path . '"'
705 if (!(filewritable(l:vim_doc_path) == 2))
706 " Try a default configuration in user home:
707 let l:vim_doc_path = expand("~") . l:doc_home
708 if (!(filewritable(l:vim_doc_path) == 2))
709 execute l:mkdir_cmd . '"' . l:vim_doc_path . '"'
710 if (!(filewritable(l:vim_doc_path) == 2))
711 " Put a warning:
712 echomsg "Unable to open documentation directory"
713 echomsg " type :help add-local-help for more informations."
714 return 0
715 endif
716 endif
717 endif
718 endif
719
720 " Exit if we have problem to access the document directory:
721 if (!isdirectory(l:vim_plugin_path)
722 \ || !isdirectory(l:vim_doc_path)
723 \ || filewritable(l:vim_doc_path) != 2)
724 return 0
725 endif
726
727 " Full name of script and documentation file:
728 let l:script_name = fnamemodify(a:full_name, ':t')
729 let l:doc_name = fnamemodify(a:full_name, ':t:r') . '.txt'
730 let l:plugin_file = l:vim_plugin_path . l:slash_char . l:script_name
731 let l:doc_file = l:vim_doc_path . l:slash_char . l:doc_name
732
733 " Bail out if document file is still up to date:
734 if (filereadable(l:doc_file) &&
735 \ getftime(l:plugin_file) < getftime(l:doc_file))
736 return 0
737 endif
738
739 " Prepare window position restoring command:
740 if (strlen(@%))
741 let l:go_back = 'b ' . bufnr("%")
742 else
743 let l:go_back = 'enew!'
744 endif
745
746 " Create a new buffer & read in the plugin file (me):
747 setl nomodeline
748 exe 'enew!'
749 exe 'r ' . l:plugin_file
750
751 setl modeline
752 let l:buf = bufnr("%")
753 setl noswapfile modifiable
754
755 norm zR
756 norm gg
757
758 " Delete from first line to a line starts with
759 " === START_DOC
760 1,/^=\{3,}\s\+START_DOC\C/ d
761
762 " Delete from a line starts with
763 " === END_DOC
764 " to the end of the documents:
765 /^=\{3,}\s\+END_DOC\C/,$ d
766
767 " Remove fold marks:
768 %s/{\{3}[1-9]/ /
769
770 " Add modeline for help doc: the modeline string is mangled intentionally
771 " to avoid it be recognized by VIM:
772 call append(line('$'), '')
773 call append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:')
774
775 " Replace revision:
776 exe "normal :1s/#version#/ v" . a:revision . "/\<CR>"
777
778 " Save the help document:
779 exe 'w! ' . l:doc_file
780 exe l:go_back
781 exe 'bw ' . l:buf
782
783 " Build help tags:
784 exe 'helptags ' . l:vim_doc_path
785
786 return 1
787 endfunction
788
660 " Section: Public functions {{{1
789 " Section: Public functions {{{1
661
790
662 " Function: HGGetRevision() {{{2
791 " Function: HGGetRevision() {{{2
663 " Global function for retrieving the current buffer's HG revision number.
792 " Global function for retrieving the current buffer's HG revision number.
664 " Returns: Revision number or an empty string if an error occurs.
793 " Returns: Revision number or an empty string if an error occurs.
665
794
666 function! HGGetRevision()
795 function! HGGetRevision()
667 let revision=""
796 let revision=""
668 exec s:HGGetStatusVars('revision', '', '')
797 exec s:HGGetStatusVars('revision', '', '')
669 return revision
798 return revision
670 endfunction
799 endfunction
671
800
672 " Function: HGDisableBufferSetup() {{{2
801 " Function: HGDisableBufferSetup() {{{2
673 " Global function for deactivating the buffer autovariables.
802 " Global function for deactivating the buffer autovariables.
674
803
675 function! HGDisableBufferSetup()
804 function! HGDisableBufferSetup()
676 let g:HGCommandEnableBufferSetup=0
805 let g:HGCommandEnableBufferSetup=0
677 silent! augroup! HGCommandPlugin
806 silent! augroup! HGCommandPlugin
678 endfunction
807 endfunction
679
808
680 " Function: HGEnableBufferSetup() {{{2
809 " Function: HGEnableBufferSetup() {{{2
681 " Global function for activating the buffer autovariables.
810 " Global function for activating the buffer autovariables.
682
811
683 function! HGEnableBufferSetup()
812 function! HGEnableBufferSetup()
684 let g:HGCommandEnableBufferSetup=1
813 let g:HGCommandEnableBufferSetup=1
685 augroup HGCommandPlugin
814 augroup HGCommandPlugin
686 au!
815 au!
687 au BufEnter * call s:HGSetupBuffer()
816 au BufEnter * call s:HGSetupBuffer()
688 augroup END
817 augroup END
689
818
690 " Only auto-load if the plugin is fully loaded. This gives other plugins a
819 " Only auto-load if the plugin is fully loaded. This gives other plugins a
691 " chance to run.
820 " chance to run.
692 if g:loaded_hgcommand == 2
821 if g:loaded_hgcommand == 2
693 call s:HGSetupBuffer()
822 call s:HGSetupBuffer()
694 endif
823 endif
695 endfunction
824 endfunction
696
825
697 " Function: HGGetStatusLine() {{{2
826 " Function: HGGetStatusLine() {{{2
698 " Default (sample) status line entry for HG files. This is only useful if
827 " Default (sample) status line entry for HG files. This is only useful if
699 " HG-managed buffer mode is on (see the HGCommandEnableBufferSetup variable
828 " HG-managed buffer mode is on (see the HGCommandEnableBufferSetup variable
700 " for how to do this).
829 " for how to do this).
701
830
702 function! HGGetStatusLine()
831 function! HGGetStatusLine()
703 if exists('b:HGSourceFile')
832 if exists('b:HGSourceFile')
704 " This is a result buffer
833 " This is a result buffer
705 let value='[' . b:HGCommand . ' ' . b:HGSourceFile
834 let value='[' . b:HGCommand . ' ' . b:HGSourceFile
706 if exists('b:HGStatusText')
835 if exists('b:HGStatusText')
707 let value=value . ' ' . b:HGStatusText
836 let value=value . ' ' . b:HGStatusText
708 endif
837 endif
709 let value = value . ']'
838 let value = value . ']'
710 return value
839 return value
711 endif
840 endif
712
841
713 if exists('b:HGRevision')
842 if exists('b:HGRevision')
714 \ && b:HGRevision != ''
843 \ && b:HGRevision != ''
715 \ && exists('b:HGBranch')
844 \ && exists('b:HGBranch')
716 \ && b:HGBranch != ''
845 \ && b:HGBranch != ''
717 \ && exists('b:HGRepository')
846 \ && exists('b:HGRepository')
718 \ && b:HGRepository != ''
847 \ && b:HGRepository != ''
719 \ && exists('g:HGCommandEnableBufferSetup')
848 \ && exists('g:HGCommandEnableBufferSetup')
720 \ && g:HGCommandEnableBufferSetup
849 \ && g:HGCommandEnableBufferSetup
721 return '[HG ' . b:HGRepository . '/' . b:HGBranch .'/' . b:HGRevision . ']'
850 return '[HG ' . b:HGRepository . '/' . b:HGBranch .'/' . b:HGRevision . ']'
722 else
851 else
723 return ''
852 return ''
724 endif
853 endif
725 endfunction
854 endfunction
726
855
727 " Section: HG command functions {{{1
856 " Section: HG command functions {{{1
728
857
729 " Function: s:HGAdd() {{{2
858 " Function: s:HGAdd() {{{2
730 function! s:HGAdd()
859 function! s:HGAdd()
731 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('add', 'hgadd', ''))
860 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('add', 'hgadd', ''))
732 endfunction
861 endfunction
733
862
734 " Function: s:HGAnnotate(...) {{{2
863 " Function: s:HGAnnotate(...) {{{2
735 function! s:HGAnnotate(...)
864 function! s:HGAnnotate(...)
736 if a:0 == 0
865 if a:0 == 0
737 if &filetype == "HGAnnotate"
866 if &filetype == "HGAnnotate"
738 " This is a HGAnnotate buffer. Perform annotation of the version
867 " This is a HGAnnotate buffer. Perform annotation of the version
739 " indicated by the current line.
868 " indicated by the current line.
740 let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','')
869 let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','')
741 if s:HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
870 if s:HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
742 let revision = revision - 1
871 let revision = revision - 1
743 endif
872 endif
744 else
873 else
745 let revision=HGGetRevision()
874 let revision=HGGetRevision()
746 if revision == ""
875 if revision == ""
747 echoerr "Unable to obtain HG version information."
876 echoerr "Unable to obtain HG version information."
748 return -1
877 return -1
749 endif
878 endif
750 endif
879 endif
751 else
880 else
752 let revision=a:1
881 let revision=a:1
753 endif
882 endif
754
883
755 if revision == "NEW"
884 if revision == "NEW"
756 echo "No annotatation available for new file."
885 echo "No annotatation available for new file."
757 return -1
886 return -1
758 endif
887 endif
759
888
760 let resultBuffer=s:HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision)
889 let resultBuffer=s:HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision)
761 echomsg "DBG: ".resultBuffer
890 echomsg "DBG: ".resultBuffer
762 if resultBuffer != -1
891 if resultBuffer != -1
763 set filetype=HGAnnotate
892 set filetype=HGAnnotate
764 endif
893 endif
765
894
766 return resultBuffer
895 return resultBuffer
767 endfunction
896 endfunction
768
897
769 " Function: s:HGCommit() {{{2
898 " Function: s:HGCommit() {{{2
770 function! s:HGCommit(...)
899 function! s:HGCommit(...)
771 " Handle the commit message being specified. If a message is supplied, it
900 " Handle the commit message being specified. If a message is supplied, it
772 " is used; if bang is supplied, an empty message is used; otherwise, the
901 " is used; if bang is supplied, an empty message is used; otherwise, the
773 " user is provided a buffer from which to edit the commit message.
902 " user is provided a buffer from which to edit the commit message.
774 if a:2 != "" || a:1 == "!"
903 if a:2 != "" || a:1 == "!"
775 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
904 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
776 endif
905 endif
777
906
778 let hgBufferCheck=s:HGCurrentBufferCheck()
907 let hgBufferCheck=s:HGCurrentBufferCheck()
779 if hgBufferCheck == -1
908 if hgBufferCheck == -1
780 echo "Original buffer no longer exists, aborting."
909 echo "Original buffer no longer exists, aborting."
781 return -1
910 return -1
782 endif
911 endif
783
912
784 " Protect against windows' backslashes in paths. They confuse exec'd
913 " Protect against windows' backslashes in paths. They confuse exec'd
785 " commands.
914 " commands.
786
915
787 let shellSlashBak = &shellslash
916 let shellSlashBak = &shellslash
788 try
917 try
789 set shellslash
918 set shellslash
790
919
791 let messageFileName = tempname()
920 let messageFileName = tempname()
792
921
793 let fileName=bufname(hgBufferCheck)
922 let fileName=bufname(hgBufferCheck)
794 let realFilePath=s:HGResolveLink(fileName)
923 let realFilePath=s:HGResolveLink(fileName)
795 let newCwd=fnamemodify(realFilePath, ':h')
924 let newCwd=fnamemodify(realFilePath, ':h')
796 if strlen(newCwd) == 0
925 if strlen(newCwd) == 0
797 " Account for autochdir being in effect, which will make this blank, but
926 " Account for autochdir being in effect, which will make this blank, but
798 " we know we'll be in the current directory for the original file.
927 " we know we'll be in the current directory for the original file.
799 let newCwd = getcwd()
928 let newCwd = getcwd()
800 endif
929 endif
801
930
802 let realFileName=fnamemodify(realFilePath, ':t')
931 let realFileName=fnamemodify(realFilePath, ':t')
803
932
804 if s:HGEditFile(messageFileName, hgBufferCheck) == -1
933 if s:HGEditFile(messageFileName, hgBufferCheck) == -1
805 return
934 return
806 endif
935 endif
807
936
808 " Protect against case and backslash issues in Windows.
937 " Protect against case and backslash issues in Windows.
809 let autoPattern = '\c' . messageFileName
938 let autoPattern = '\c' . messageFileName
810
939
811 " Ensure existance of group
940 " Ensure existance of group
812 augroup HGCommit
941 augroup HGCommit
813 augroup END
942 augroup END
814
943
815 execute 'au HGCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")'
944 execute 'au HGCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")'
816 execute 'au HGCommit BufDelete' autoPattern 'au! HGCommit * ' autoPattern
945 execute 'au HGCommit BufDelete' autoPattern 'au! HGCommit * ' autoPattern
817
946
818 " Create a commit mapping. The mapping must clear all autocommands in case
947 " Create a commit mapping. The mapping must clear all autocommands in case
819 " it is invoked when HGCommandCommitOnWrite is active, as well as to not
948 " it is invoked when HGCommandCommitOnWrite is active, as well as to not
820 " invoke the buffer deletion autocommand.
949 " invoke the buffer deletion autocommand.
821
950
822 execute 'nnoremap <silent> <buffer> <Plug>HGCommit '.
951 execute 'nnoremap <silent> <buffer> <Plug>HGCommit '.
823 \ ':au! HGCommit * ' . autoPattern . '<CR>'.
952 \ ':au! HGCommit * ' . autoPattern . '<CR>'.
824 \ ':g/^HG:/d<CR>'.
953 \ ':g/^HG:/d<CR>'.
825 \ ':update<CR>'.
954 \ ':update<CR>'.
826 \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
955 \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
827 \ '"' . newCwd . '",' .
956 \ '"' . newCwd . '",' .
828 \ '"' . realFileName . '",' .
957 \ '"' . realFileName . '",' .
829 \ hgBufferCheck . ')<CR>'
958 \ hgBufferCheck . ')<CR>'
830
959
831 silent 0put ='HG: ----------------------------------------------------------------------'
960 silent 0put ='HG: ----------------------------------------------------------------------'
832 silent put =\"HG: Enter Log. Lines beginning with `HG:' are removed automatically\"
961 silent put =\"HG: Enter Log. Lines beginning with `HG:' are removed automatically\"
833 silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
962 silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
834
963
835 if s:HGGetOption('HGCommandCommitOnWrite', 1) == 1
964 if s:HGGetOption('HGCommandCommitOnWrite', 1) == 1
836 execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d'
965 execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d'
837 execute 'au HGCommit BufWritePost' autoPattern 'call s:HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
966 execute 'au HGCommit BufWritePost' autoPattern 'call s:HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
838 silent put ='HG: or write this buffer'
967 silent put ='HG: or write this buffer'
839 endif
968 endif
840
969
841 silent put ='HG: to finish this commit operation'
970 silent put ='HG: to finish this commit operation'
842 silent put ='HG: ----------------------------------------------------------------------'
971 silent put ='HG: ----------------------------------------------------------------------'
843 $
972 $
844 let b:HGSourceFile=fileName
973 let b:HGSourceFile=fileName
845 let b:HGCommand='HGCommit'
974 let b:HGCommand='HGCommit'
846 set filetype=hg
975 set filetype=hg
847 finally
976 finally
848 let &shellslash = shellSlashBak
977 let &shellslash = shellSlashBak
849 endtry
978 endtry
850
979
851 endfunction
980 endfunction
852
981
853 " Function: s:HGDiff(...) {{{2
982 " Function: s:HGDiff(...) {{{2
854 function! s:HGDiff(...)
983 function! s:HGDiff(...)
855 if a:0 == 1
984 if a:0 == 1
856 let revOptions = '-r' . a:1
985 let revOptions = '-r' . a:1
857 let caption = a:1 . ' -> current'
986 let caption = a:1 . ' -> current'
858 elseif a:0 == 2
987 elseif a:0 == 2
859 let revOptions = '-r' . a:1 . ' -r' . a:2
988 let revOptions = '-r' . a:1 . ' -r' . a:2
860 let caption = a:1 . ' -> ' . a:2
989 let caption = a:1 . ' -> ' . a:2
861 else
990 else
862 let revOptions = ''
991 let revOptions = ''
863 let caption = ''
992 let caption = ''
864 endif
993 endif
865
994
866 let hgdiffopt=s:HGGetOption('HGCommandDiffOpt', 'w')
995 let hgdiffopt=s:HGGetOption('HGCommandDiffOpt', 'w')
867
996
868 if hgdiffopt == ""
997 if hgdiffopt == ""
869 let diffoptionstring=""
998 let diffoptionstring=""
870 else
999 else
871 let diffoptionstring=" -" . hgdiffopt . " "
1000 let diffoptionstring=" -" . hgdiffopt . " "
872 endif
1001 endif
873
1002
874 let resultBuffer = s:HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
1003 let resultBuffer = s:HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
875 if resultBuffer != -1
1004 if resultBuffer != -1
876 set filetype=diff
1005 set filetype=diff
877 endif
1006 endif
878 return resultBuffer
1007 return resultBuffer
879 endfunction
1008 endfunction
880
1009
881
1010
882 " Function: s:HGGotoOriginal(["!]) {{{2
1011 " Function: s:HGGotoOriginal(["!]) {{{2
883 function! s:HGGotoOriginal(...)
1012 function! s:HGGotoOriginal(...)
884 let origBuffNR = s:HGCurrentBufferCheck()
1013 let origBuffNR = s:HGCurrentBufferCheck()
885 if origBuffNR > 0
1014 if origBuffNR > 0
886 let origWinNR = bufwinnr(origBuffNR)
1015 let origWinNR = bufwinnr(origBuffNR)
887 if origWinNR == -1
1016 if origWinNR == -1
888 execute 'buffer' origBuffNR
1017 execute 'buffer' origBuffNR
889 else
1018 else
890 execute origWinNR . 'wincmd w'
1019 execute origWinNR . 'wincmd w'
891 endif
1020 endif
892 if a:0 == 1
1021 if a:0 == 1
893 if a:1 == "!"
1022 if a:1 == "!"
894 let buffnr = 1
1023 let buffnr = 1
895 let buffmaxnr = bufnr("$")
1024 let buffmaxnr = bufnr("$")
896 while buffnr <= buffmaxnr
1025 while buffnr <= buffmaxnr
897 if getbufvar(buffnr, "HGOrigBuffNR") == origBuffNR
1026 if getbufvar(buffnr, "HGOrigBuffNR") == origBuffNR
898 execute "bw" buffnr
1027 execute "bw" buffnr
899 endif
1028 endif
900 let buffnr = buffnr + 1
1029 let buffnr = buffnr + 1
901 endwhile
1030 endwhile
902 endif
1031 endif
903 endif
1032 endif
904 endif
1033 endif
905 endfunction
1034 endfunction
906
1035
907 " Function: s:HGFinishCommit(messageFile, targetDir, targetFile) {{{2
1036 " Function: s:HGFinishCommit(messageFile, targetDir, targetFile) {{{2
908 function! s:HGFinishCommit(messageFile, targetDir, targetFile, origBuffNR)
1037 function! s:HGFinishCommit(messageFile, targetDir, targetFile, origBuffNR)
909 if filereadable(a:messageFile)
1038 if filereadable(a:messageFile)
910 let oldCwd=getcwd()
1039 let oldCwd=getcwd()
911 if strlen(a:targetDir) > 0
1040 if strlen(a:targetDir) > 0
912 execute 'cd' escape(a:targetDir, ' ')
1041 execute 'cd' escape(a:targetDir, ' ')
913 endif
1042 endif
914 let resultBuffer=s:HGCreateCommandBuffer('commit -F "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
1043 let resultBuffer=s:HGCreateCommandBuffer('commit -F "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
915 execute 'cd' escape(oldCwd, ' ')
1044 execute 'cd' escape(oldCwd, ' ')
916 execute 'bw' escape(a:messageFile, ' *?\')
1045 execute 'bw' escape(a:messageFile, ' *?\')
917 silent execute 'call delete("' . a:messageFile . '")'
1046 silent execute 'call delete("' . a:messageFile . '")'
918 return s:HGMarkOrigBufferForSetup(resultBuffer)
1047 return s:HGMarkOrigBufferForSetup(resultBuffer)
919 else
1048 else
920 echoerr "Can't read message file; no commit is possible."
1049 echoerr "Can't read message file; no commit is possible."
921 return -1
1050 return -1
922 endif
1051 endif
923 endfunction
1052 endfunction
924
1053
925 " Function: s:HGLog() {{{2
1054 " Function: s:HGLog() {{{2
926 function! s:HGLog(...)
1055 function! s:HGLog(...)
927 if a:0 == 0
1056 if a:0 == 0
928 let versionOption = ""
1057 let versionOption = ""
929 let caption = ''
1058 let caption = ''
930 else
1059 else
931 let versionOption=" -r" . a:1
1060 let versionOption=" -r" . a:1
932 let caption = a:1
1061 let caption = a:1
933 endif
1062 endif
934
1063
935 let resultBuffer=s:HGDoCommand('log' . versionOption, 'hglog', caption)
1064 let resultBuffer=s:HGDoCommand('log' . versionOption, 'hglog', caption)
936 if resultBuffer != ""
1065 if resultBuffer != ""
937 set filetype=rcslog
1066 set filetype=rcslog
938 endif
1067 endif
939 return resultBuffer
1068 return resultBuffer
940 endfunction
1069 endfunction
941
1070
942 " Function: s:HGRevert() {{{2
1071 " Function: s:HGRevert() {{{2
943 function! s:HGRevert()
1072 function! s:HGRevert()
944 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('revert', 'hgrevert', ''))
1073 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('revert', 'hgrevert', ''))
945 endfunction
1074 endfunction
946
1075
947 " Function: s:HGReview(...) {{{2
1076 " Function: s:HGReview(...) {{{2
948 function! s:HGReview(...)
1077 function! s:HGReview(...)
949 if a:0 == 0
1078 if a:0 == 0
950 let versiontag=""
1079 let versiontag=""
951 if s:HGGetOption('HGCommandInteractive', 0)
1080 if s:HGGetOption('HGCommandInteractive', 0)
952 let versiontag=input('Revision: ')
1081 let versiontag=input('Revision: ')
953 endif
1082 endif
954 if versiontag == ""
1083 if versiontag == ""
955 let versiontag="(current)"
1084 let versiontag="(current)"
956 let versionOption=""
1085 let versionOption=""
957 else
1086 else
958 let versionOption=" -r " . versiontag . " "
1087 let versionOption=" -r " . versiontag . " "
959 endif
1088 endif
960 else
1089 else
961 let versiontag=a:1
1090 let versiontag=a:1
962 let versionOption=" -r " . versiontag . " "
1091 let versionOption=" -r " . versiontag . " "
963 endif
1092 endif
964
1093
965 let resultBuffer = s:HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
1094 let resultBuffer = s:HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
966 if resultBuffer > 0
1095 if resultBuffer > 0
967 let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype')
1096 let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype')
968 endif
1097 endif
969
1098
970 return resultBuffer
1099 return resultBuffer
971 endfunction
1100 endfunction
972
1101
973 " Function: s:HGStatus() {{{2
1102 " Function: s:HGStatus() {{{2
974 function! s:HGStatus()
1103 function! s:HGStatus()
975 return s:HGDoCommand('status', 'hgstatus', '')
1104 return s:HGDoCommand('status', 'hgstatus', '')
976 endfunction
1105 endfunction
977
1106
978
1107
979 " Function: s:HGUpdate() {{{2
1108 " Function: s:HGUpdate() {{{2
980 function! s:HGUpdate()
1109 function! s:HGUpdate()
981 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('update', 'update', ''))
1110 return s:HGMarkOrigBufferForSetup(s:HGDoCommand('update', 'update', ''))
982 endfunction
1111 endfunction
983
1112
984 " Function: s:HGVimDiff(...) {{{2
1113 " Function: s:HGVimDiff(...) {{{2
985 function! s:HGVimDiff(...)
1114 function! s:HGVimDiff(...)
986 let originalBuffer = s:HGCurrentBufferCheck()
1115 let originalBuffer = s:HGCurrentBufferCheck()
987 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
1116 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
988 try
1117 try
989 " If there's already a VimDiff'ed window, restore it.
1118 " If there's already a VimDiff'ed window, restore it.
990 " There may only be one HGVimDiff original window at a time.
1119 " There may only be one HGVimDiff original window at a time.
991
1120
992 if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
1121 if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
993 " Clear the existing vimdiff setup by removing the result buffers.
1122 " Clear the existing vimdiff setup by removing the result buffers.
994 call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
1123 call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
995 endif
1124 endif
996
1125
997 " Split and diff
1126 " Split and diff
998 if(a:0 == 2)
1127 if(a:0 == 2)
999 " Reset the vimdiff system, as 2 explicit versions were provided.
1128 " Reset the vimdiff system, as 2 explicit versions were provided.
1000 if exists('s:vimDiffSourceBuffer')
1129 if exists('s:vimDiffSourceBuffer')
1001 call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
1130 call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
1002 endif
1131 endif
1003 let resultBuffer = s:HGReview(a:1)
1132 let resultBuffer = s:HGReview(a:1)
1004 if resultBuffer < 0
1133 if resultBuffer < 0
1005 echomsg "Can't open HG revision " . a:1
1134 echomsg "Can't open HG revision " . a:1
1006 return resultBuffer
1135 return resultBuffer
1007 endif
1136 endif
1008 let b:HGCommand = 'vimdiff'
1137 let b:HGCommand = 'vimdiff'
1009 diffthis
1138 diffthis
1010 let s:vimDiffBufferCount = 1
1139 let s:vimDiffBufferCount = 1
1011 let s:vimDiffScratchList = '{'. resultBuffer . '}'
1140 let s:vimDiffScratchList = '{'. resultBuffer . '}'
1012 " If no split method is defined, cheat, and set it to vertical.
1141 " If no split method is defined, cheat, and set it to vertical.
1013 try
1142 try
1014 call s:HGOverrideOption('HGCommandSplit', s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
1143 call s:HGOverrideOption('HGCommandSplit', s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
1015 let resultBuffer=s:HGReview(a:2)
1144 let resultBuffer=s:HGReview(a:2)
1016 finally
1145 finally
1017 call s:HGOverrideOption('HGCommandSplit')
1146 call s:HGOverrideOption('HGCommandSplit')
1018 endtry
1147 endtry
1019 if resultBuffer < 0
1148 if resultBuffer < 0
1020 echomsg "Can't open HG revision " . a:1
1149 echomsg "Can't open HG revision " . a:1
1021 return resultBuffer
1150 return resultBuffer
1022 endif
1151 endif
1023 let b:HGCommand = 'vimdiff'
1152 let b:HGCommand = 'vimdiff'
1024 diffthis
1153 diffthis
1025 let s:vimDiffBufferCount = 2
1154 let s:vimDiffBufferCount = 2
1026 let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}'
1155 let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}'
1027 else
1156 else
1028 " Add new buffer
1157 " Add new buffer
1029 try
1158 try
1030 " Force splitting behavior, otherwise why use vimdiff?
1159 " Force splitting behavior, otherwise why use vimdiff?
1031 call s:HGOverrideOption("HGCommandEdit", "split")
1160 call s:HGOverrideOption("HGCommandEdit", "split")
1032 call s:HGOverrideOption("HGCommandSplit", s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
1161 call s:HGOverrideOption("HGCommandSplit", s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
1033 if(a:0 == 0)
1162 if(a:0 == 0)
1034 let resultBuffer=s:HGReview()
1163 let resultBuffer=s:HGReview()
1035 else
1164 else
1036 let resultBuffer=s:HGReview(a:1)
1165 let resultBuffer=s:HGReview(a:1)
1037 endif
1166 endif
1038 finally
1167 finally
1039 call s:HGOverrideOption("HGCommandEdit")
1168 call s:HGOverrideOption("HGCommandEdit")
1040 call s:HGOverrideOption("HGCommandSplit")
1169 call s:HGOverrideOption("HGCommandSplit")
1041 endtry
1170 endtry
1042 if resultBuffer < 0
1171 if resultBuffer < 0
1043 echomsg "Can't open current HG revision"
1172 echomsg "Can't open current HG revision"
1044 return resultBuffer
1173 return resultBuffer
1045 endif
1174 endif
1046 let b:HGCommand = 'vimdiff'
1175 let b:HGCommand = 'vimdiff'
1047 diffthis
1176 diffthis
1048
1177
1049 if !exists('s:vimDiffBufferCount')
1178 if !exists('s:vimDiffBufferCount')
1050 " New instance of vimdiff.
1179 " New instance of vimdiff.
1051 let s:vimDiffBufferCount = 2
1180 let s:vimDiffBufferCount = 2
1052 let s:vimDiffScratchList = '{' . resultBuffer . '}'
1181 let s:vimDiffScratchList = '{' . resultBuffer . '}'
1053
1182
1054 " This could have been invoked on a HG result buffer, not the
1183 " This could have been invoked on a HG result buffer, not the
1055 " original buffer.
1184 " original buffer.
1056 wincmd W
1185 wincmd W
1057 execute 'buffer' originalBuffer
1186 execute 'buffer' originalBuffer
1058 " Store info for later original buffer restore
1187 " Store info for later original buffer restore
1059 let s:vimDiffRestoreCmd =
1188 let s:vimDiffRestoreCmd =
1060 \ "call setbufvar(".originalBuffer.", \"&diff\", ".getbufvar(originalBuffer, '&diff').")"
1189 \ "call setbufvar(".originalBuffer.", \"&diff\", ".getbufvar(originalBuffer, '&diff').")"
1061 \ . "|call setbufvar(".originalBuffer.", \"&foldcolumn\", ".getbufvar(originalBuffer, '&foldcolumn').")"
1190 \ . "|call setbufvar(".originalBuffer.", \"&foldcolumn\", ".getbufvar(originalBuffer, '&foldcolumn').")"
1062 \ . "|call setbufvar(".originalBuffer.", \"&foldenable\", ".getbufvar(originalBuffer, '&foldenable').")"
1191 \ . "|call setbufvar(".originalBuffer.", \"&foldenable\", ".getbufvar(originalBuffer, '&foldenable').")"
1063 \ . "|call setbufvar(".originalBuffer.", \"&foldmethod\", '".getbufvar(originalBuffer, '&foldmethod')."')"
1192 \ . "|call setbufvar(".originalBuffer.", \"&foldmethod\", '".getbufvar(originalBuffer, '&foldmethod')."')"
1064 \ . "|call setbufvar(".originalBuffer.", \"&scrollbind\", ".getbufvar(originalBuffer, '&scrollbind').")"
1193 \ . "|call setbufvar(".originalBuffer.", \"&scrollbind\", ".getbufvar(originalBuffer, '&scrollbind').")"
1065 \ . "|call setbufvar(".originalBuffer.", \"&wrap\", ".getbufvar(originalBuffer, '&wrap').")"
1194 \ . "|call setbufvar(".originalBuffer.", \"&wrap\", ".getbufvar(originalBuffer, '&wrap').")"
1066 \ . "|if &foldmethod=='manual'|execute 'normal zE'|endif"
1195 \ . "|if &foldmethod=='manual'|execute 'normal zE'|endif"
1067 diffthis
1196 diffthis
1068 wincmd w
1197 wincmd w
1069 else
1198 else
1070 " Adding a window to an existing vimdiff
1199 " Adding a window to an existing vimdiff
1071 let s:vimDiffBufferCount = s:vimDiffBufferCount + 1
1200 let s:vimDiffBufferCount = s:vimDiffBufferCount + 1
1072 let s:vimDiffScratchList = s:vimDiffScratchList . '{' . resultBuffer . '}'
1201 let s:vimDiffScratchList = s:vimDiffScratchList . '{' . resultBuffer . '}'
1073 endif
1202 endif
1074 endif
1203 endif
1075
1204
1076 let s:vimDiffSourceBuffer = originalBuffer
1205 let s:vimDiffSourceBuffer = originalBuffer
1077
1206
1078 " Avoid executing the modeline in the current buffer after the autocommand.
1207 " Avoid executing the modeline in the current buffer after the autocommand.
1079
1208
1080 let currentBuffer = bufnr('%')
1209 let currentBuffer = bufnr('%')
1081 let saveModeline = getbufvar(currentBuffer, '&modeline')
1210 let saveModeline = getbufvar(currentBuffer, '&modeline')
1082 try
1211 try
1083 call setbufvar(currentBuffer, '&modeline', 0)
1212 call setbufvar(currentBuffer, '&modeline', 0)
1084 silent do HGCommand User HGVimDiffFinish
1213 silent do HGCommand User HGVimDiffFinish
1085 finally
1214 finally
1086 call setbufvar(currentBuffer, '&modeline', saveModeline)
1215 call setbufvar(currentBuffer, '&modeline', saveModeline)
1087 endtry
1216 endtry
1088 return resultBuffer
1217 return resultBuffer
1089 finally
1218 finally
1090 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1219 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1091 endtry
1220 endtry
1092 endfunction
1221 endfunction
1093
1222
1094 " Section: Command definitions {{{1
1223 " Section: Command definitions {{{1
1095 " Section: Primary commands {{{2
1224 " Section: Primary commands {{{2
1096 com! HGAdd call s:HGAdd()
1225 com! HGAdd call s:HGAdd()
1097 com! -nargs=? HGAnnotate call s:HGAnnotate(<f-args>)
1226 com! -nargs=? HGAnnotate call s:HGAnnotate(<f-args>)
1098 com! -bang -nargs=? HGCommit call s:HGCommit(<q-bang>, <q-args>)
1227 com! -bang -nargs=? HGCommit call s:HGCommit(<q-bang>, <q-args>)
1099 com! -nargs=* HGDiff call s:HGDiff(<f-args>)
1228 com! -nargs=* HGDiff call s:HGDiff(<f-args>)
1100 com! -bang HGGotoOriginal call s:HGGotoOriginal(<q-bang>)
1229 com! -bang HGGotoOriginal call s:HGGotoOriginal(<q-bang>)
1101 com! -nargs=? HGLog call s:HGLog(<f-args>)
1230 com! -nargs=? HGLog call s:HGLog(<f-args>)
1102 com! HGRevert call s:HGRevert()
1231 com! HGRevert call s:HGRevert()
1103 com! -nargs=? HGReview call s:HGReview(<f-args>)
1232 com! -nargs=? HGReview call s:HGReview(<f-args>)
1104 com! HGStatus call s:HGStatus()
1233 com! HGStatus call s:HGStatus()
1105 com! HGUpdate call s:HGUpdate()
1234 com! HGUpdate call s:HGUpdate()
1106 com! -nargs=* HGVimDiff call s:HGVimDiff(<f-args>)
1235 com! -nargs=* HGVimDiff call s:HGVimDiff(<f-args>)
1107
1236
1108 " Section: HG buffer management commands {{{2
1237 " Section: HG buffer management commands {{{2
1109 com! HGDisableBufferSetup call HGDisableBufferSetup()
1238 com! HGDisableBufferSetup call HGDisableBufferSetup()
1110 com! HGEnableBufferSetup call HGEnableBufferSetup()
1239 com! HGEnableBufferSetup call HGEnableBufferSetup()
1111
1240
1112 " Allow reloading hgcommand.vim
1241 " Allow reloading hgcommand.vim
1113 com! HGReload unlet! loaded_hgcommand | runtime plugin/hgcommand.vim
1242 com! HGReload unlet! loaded_hgcommand | runtime plugin/hgcommand.vim
1114
1243
1115 " Section: Plugin command mappings {{{1
1244 " Section: Plugin command mappings {{{1
1116 nnoremap <silent> <Plug>HGAdd :HGAdd<CR>
1245 nnoremap <silent> <Plug>HGAdd :HGAdd<CR>
1117 nnoremap <silent> <Plug>HGAnnotate :HGAnnotate<CR>
1246 nnoremap <silent> <Plug>HGAnnotate :HGAnnotate<CR>
1118 nnoremap <silent> <Plug>HGCommit :HGCommit<CR>
1247 nnoremap <silent> <Plug>HGCommit :HGCommit<CR>
1119 nnoremap <silent> <Plug>HGDiff :HGDiff<CR>
1248 nnoremap <silent> <Plug>HGDiff :HGDiff<CR>
1120 nnoremap <silent> <Plug>HGGotoOriginal :HGGotoOriginal<CR>
1249 nnoremap <silent> <Plug>HGGotoOriginal :HGGotoOriginal<CR>
1121 nnoremap <silent> <Plug>HGClearAndGotoOriginal :HGGotoOriginal!<CR>
1250 nnoremap <silent> <Plug>HGClearAndGotoOriginal :HGGotoOriginal!<CR>
1122 nnoremap <silent> <Plug>HGLog :HGLog<CR>
1251 nnoremap <silent> <Plug>HGLog :HGLog<CR>
1123 nnoremap <silent> <Plug>HGRevert :HGRevert<CR>
1252 nnoremap <silent> <Plug>HGRevert :HGRevert<CR>
1124 nnoremap <silent> <Plug>HGReview :HGReview<CR>
1253 nnoremap <silent> <Plug>HGReview :HGReview<CR>
1125 nnoremap <silent> <Plug>HGStatus :HGStatus<CR>
1254 nnoremap <silent> <Plug>HGStatus :HGStatus<CR>
1126 nnoremap <silent> <Plug>HGUpdate :HGUpdate<CR>
1255 nnoremap <silent> <Plug>HGUpdate :HGUpdate<CR>
1127 nnoremap <silent> <Plug>HGVimDiff :HGVimDiff<CR>
1256 nnoremap <silent> <Plug>HGVimDiff :HGVimDiff<CR>
1128 nnoremap <silent> <Plug>HGWatchers :HGWatchers<CR>
1257 nnoremap <silent> <Plug>HGWatchers :HGWatchers<CR>
1129 nnoremap <silent> <Plug>HGWatchAdd :HGWatchAdd<CR>
1258 nnoremap <silent> <Plug>HGWatchAdd :HGWatchAdd<CR>
1130 nnoremap <silent> <Plug>HGWatchOn :HGWatchOn<CR>
1259 nnoremap <silent> <Plug>HGWatchOn :HGWatchOn<CR>
1131 nnoremap <silent> <Plug>HGWatchOff :HGWatchOff<CR>
1260 nnoremap <silent> <Plug>HGWatchOff :HGWatchOff<CR>
1132 nnoremap <silent> <Plug>HGWatchRemove :HGWatchRemove<CR>
1261 nnoremap <silent> <Plug>HGWatchRemove :HGWatchRemove<CR>
1133
1262
1134 " Section: Default mappings {{{1
1263 " Section: Default mappings {{{1
1135 if !hasmapto('<Plug>HGAdd')
1264 if !hasmapto('<Plug>HGAdd')
1136 nmap <unique> <Leader>hga <Plug>HGAdd
1265 nmap <unique> <Leader>hga <Plug>HGAdd
1137 endif
1266 endif
1138 if !hasmapto('<Plug>HGAnnotate')
1267 if !hasmapto('<Plug>HGAnnotate')
1139 nmap <unique> <Leader>hgn <Plug>HGAnnotate
1268 nmap <unique> <Leader>hgn <Plug>HGAnnotate
1140 endif
1269 endif
1141 if !hasmapto('<Plug>HGClearAndGotoOriginal')
1270 if !hasmapto('<Plug>HGClearAndGotoOriginal')
1142 nmap <unique> <Leader>hgG <Plug>HGClearAndGotoOriginal
1271 nmap <unique> <Leader>hgG <Plug>HGClearAndGotoOriginal
1143 endif
1272 endif
1144 if !hasmapto('<Plug>HGCommit')
1273 if !hasmapto('<Plug>HGCommit')
1145 nmap <unique> <Leader>hgc <Plug>HGCommit
1274 nmap <unique> <Leader>hgc <Plug>HGCommit
1146 endif
1275 endif
1147 if !hasmapto('<Plug>HGDiff')
1276 if !hasmapto('<Plug>HGDiff')
1148 nmap <unique> <Leader>hgd <Plug>HGDiff
1277 nmap <unique> <Leader>hgd <Plug>HGDiff
1149 endif
1278 endif
1150 if !hasmapto('<Plug>HGGotoOriginal')
1279 if !hasmapto('<Plug>HGGotoOriginal')
1151 nmap <unique> <Leader>hgg <Plug>HGGotoOriginal
1280 nmap <unique> <Leader>hgg <Plug>HGGotoOriginal
1152 endif
1281 endif
1153 if !hasmapto('<Plug>HGLog')
1282 if !hasmapto('<Plug>HGLog')
1154 nmap <unique> <Leader>hgl <Plug>HGLog
1283 nmap <unique> <Leader>hgl <Plug>HGLog
1155 endif
1284 endif
1156 if !hasmapto('<Plug>HGRevert')
1285 if !hasmapto('<Plug>HGRevert')
1157 nmap <unique> <Leader>hgq <Plug>HGRevert
1286 nmap <unique> <Leader>hgq <Plug>HGRevert
1158 endif
1287 endif
1159 if !hasmapto('<Plug>HGReview')
1288 if !hasmapto('<Plug>HGReview')
1160 nmap <unique> <Leader>hgr <Plug>HGReview
1289 nmap <unique> <Leader>hgr <Plug>HGReview
1161 endif
1290 endif
1162 if !hasmapto('<Plug>HGStatus')
1291 if !hasmapto('<Plug>HGStatus')
1163 nmap <unique> <Leader>hgs <Plug>HGStatus
1292 nmap <unique> <Leader>hgs <Plug>HGStatus
1164 endif
1293 endif
1165 if !hasmapto('<Plug>HGUpdate')
1294 if !hasmapto('<Plug>HGUpdate')
1166 nmap <unique> <Leader>hgu <Plug>HGUpdate
1295 nmap <unique> <Leader>hgu <Plug>HGUpdate
1167 endif
1296 endif
1168 if !hasmapto('<Plug>HGVimDiff')
1297 if !hasmapto('<Plug>HGVimDiff')
1169 nmap <unique> <Leader>hgv <Plug>HGVimDiff
1298 nmap <unique> <Leader>hgv <Plug>HGVimDiff
1170 endif
1299 endif
1171
1300
1172 " Section: Menu items {{{1
1301 " Section: Menu items {{{1
1173 silent! aunmenu Plugin.HG
1302 silent! aunmenu Plugin.HG
1174 amenu <silent> &Plugin.HG.&Add <Plug>HGAdd
1303 amenu <silent> &Plugin.HG.&Add <Plug>HGAdd
1175 amenu <silent> &Plugin.HG.A&nnotate <Plug>HGAnnotate
1304 amenu <silent> &Plugin.HG.A&nnotate <Plug>HGAnnotate
1176 amenu <silent> &Plugin.HG.&Commit <Plug>HGCommit
1305 amenu <silent> &Plugin.HG.&Commit <Plug>HGCommit
1177 amenu <silent> &Plugin.HG.&Diff <Plug>HGDiff
1306 amenu <silent> &Plugin.HG.&Diff <Plug>HGDiff
1178 amenu <silent> &Plugin.HG.&Log <Plug>HGLog
1307 amenu <silent> &Plugin.HG.&Log <Plug>HGLog
1179 amenu <silent> &Plugin.HG.Revert <Plug>HGRevert
1308 amenu <silent> &Plugin.HG.Revert <Plug>HGRevert
1180 amenu <silent> &Plugin.HG.&Review <Plug>HGReview
1309 amenu <silent> &Plugin.HG.&Review <Plug>HGReview
1181 amenu <silent> &Plugin.HG.&Status <Plug>HGStatus
1310 amenu <silent> &Plugin.HG.&Status <Plug>HGStatus
1182 amenu <silent> &Plugin.HG.&Update <Plug>HGUpdate
1311 amenu <silent> &Plugin.HG.&Update <Plug>HGUpdate
1183 amenu <silent> &Plugin.HG.&VimDiff <Plug>HGVimDiff
1312 amenu <silent> &Plugin.HG.&VimDiff <Plug>HGVimDiff
1184 amenu <silent> &Plugin.HG.&Watchers <Plug>HGWatchers
1313 amenu <silent> &Plugin.HG.&Watchers <Plug>HGWatchers
1185 amenu <silent> &Plugin.HG.WatchAdd <Plug>HGWatchAdd
1314 amenu <silent> &Plugin.HG.WatchAdd <Plug>HGWatchAdd
1186 amenu <silent> &Plugin.HG.WatchOn <Plug>HGWatchOn
1315 amenu <silent> &Plugin.HG.WatchOn <Plug>HGWatchOn
1187 amenu <silent> &Plugin.HG.WatchOff <Plug>HGWatchOff
1316 amenu <silent> &Plugin.HG.WatchOff <Plug>HGWatchOff
1188 amenu <silent> &Plugin.HG.WatchRemove <Plug>HGWatchRemove
1317 amenu <silent> &Plugin.HG.WatchRemove <Plug>HGWatchRemove
1189
1318
1190 " Section: Autocommands to restore vimdiff state {{{1
1319 " Section: Autocommands to restore vimdiff state {{{1
1191 function! s:HGVimDiffRestore(vimDiffBuff)
1320 function! s:HGVimDiffRestore(vimDiffBuff)
1192 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
1321 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
1193 try
1322 try
1194 if exists("s:vimDiffSourceBuffer")
1323 if exists("s:vimDiffSourceBuffer")
1195 if a:vimDiffBuff == s:vimDiffSourceBuffer
1324 if a:vimDiffBuff == s:vimDiffSourceBuffer
1196 " Original file is being removed.
1325 " Original file is being removed.
1197 unlet! s:vimDiffSourceBuffer
1326 unlet! s:vimDiffSourceBuffer
1198 unlet! s:vimDiffBufferCount
1327 unlet! s:vimDiffBufferCount
1199 unlet! s:vimDiffRestoreCmd
1328 unlet! s:vimDiffRestoreCmd
1200 unlet! s:vimDiffScratchList
1329 unlet! s:vimDiffScratchList
1201 elseif match(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}') >= 0
1330 elseif match(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}') >= 0
1202 let s:vimDiffScratchList = substitute(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}', '', '')
1331 let s:vimDiffScratchList = substitute(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}', '', '')
1203 let s:vimDiffBufferCount = s:vimDiffBufferCount - 1
1332 let s:vimDiffBufferCount = s:vimDiffBufferCount - 1
1204 if s:vimDiffBufferCount == 1 && exists('s:vimDiffRestoreCmd')
1333 if s:vimDiffBufferCount == 1 && exists('s:vimDiffRestoreCmd')
1205 " All scratch buffers are gone, reset the original.
1334 " All scratch buffers are gone, reset the original.
1206 " Only restore if the source buffer is still in Diff mode
1335 " Only restore if the source buffer is still in Diff mode
1207
1336
1208 let sourceWinNR=bufwinnr(s:vimDiffSourceBuffer)
1337 let sourceWinNR=bufwinnr(s:vimDiffSourceBuffer)
1209 if sourceWinNR != -1
1338 if sourceWinNR != -1
1210 " The buffer is visible in at least one window
1339 " The buffer is visible in at least one window
1211 let currentWinNR = winnr()
1340 let currentWinNR = winnr()
1212 while winbufnr(sourceWinNR) != -1
1341 while winbufnr(sourceWinNR) != -1
1213 if winbufnr(sourceWinNR) == s:vimDiffSourceBuffer
1342 if winbufnr(sourceWinNR) == s:vimDiffSourceBuffer
1214 execute sourceWinNR . 'wincmd w'
1343 execute sourceWinNR . 'wincmd w'
1215 if getwinvar('', "&diff")
1344 if getwinvar('', "&diff")
1216 execute s:vimDiffRestoreCmd
1345 execute s:vimDiffRestoreCmd
1217 endif
1346 endif
1218 endif
1347 endif
1219 let sourceWinNR = sourceWinNR + 1
1348 let sourceWinNR = sourceWinNR + 1
1220 endwhile
1349 endwhile
1221 execute currentWinNR . 'wincmd w'
1350 execute currentWinNR . 'wincmd w'
1222 else
1351 else
1223 " The buffer is hidden. It must be visible in order to set the
1352 " The buffer is hidden. It must be visible in order to set the
1224 " diff option.
1353 " diff option.
1225 let currentBufNR = bufnr('')
1354 let currentBufNR = bufnr('')
1226 execute "hide buffer" s:vimDiffSourceBuffer
1355 execute "hide buffer" s:vimDiffSourceBuffer
1227 if getwinvar('', "&diff")
1356 if getwinvar('', "&diff")
1228 execute s:vimDiffRestoreCmd
1357 execute s:vimDiffRestoreCmd
1229 endif
1358 endif
1230 execute "hide buffer" currentBufNR
1359 execute "hide buffer" currentBufNR
1231 endif
1360 endif
1232
1361
1233 unlet s:vimDiffRestoreCmd
1362 unlet s:vimDiffRestoreCmd
1234 unlet s:vimDiffSourceBuffer
1363 unlet s:vimDiffSourceBuffer
1235 unlet s:vimDiffBufferCount
1364 unlet s:vimDiffBufferCount
1236 unlet s:vimDiffScratchList
1365 unlet s:vimDiffScratchList
1237 elseif s:vimDiffBufferCount == 0
1366 elseif s:vimDiffBufferCount == 0
1238 " All buffers are gone.
1367 " All buffers are gone.
1239 unlet s:vimDiffSourceBuffer
1368 unlet s:vimDiffSourceBuffer
1240 unlet s:vimDiffBufferCount
1369 unlet s:vimDiffBufferCount
1241 unlet s:vimDiffScratchList
1370 unlet s:vimDiffScratchList
1242 endif
1371 endif
1243 endif
1372 endif
1244 endif
1373 endif
1245 finally
1374 finally
1246 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1375 let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
1247 endtry
1376 endtry
1248 endfunction
1377 endfunction
1249
1378
1250 augroup HGVimDiffRestore
1379 augroup HGVimDiffRestore
1251 au!
1380 au!
1252 au BufUnload * call s:HGVimDiffRestore(expand("<abuf>"))
1381 au BufUnload * call s:HGVimDiffRestore(expand("<abuf>"))
1253 augroup END
1382 augroup END
1254
1383
1255 " Section: Optional activation of buffer management {{{1
1384 " Section: Optional activation of buffer management {{{1
1256
1385
1257 if s:HGGetOption('HGCommandEnableBufferSetup', 0)
1386 if s:HGGetOption('HGCommandEnableBufferSetup', 0)
1258 call HGEnableBufferSetup()
1387 call HGEnableBufferSetup()
1259 endif
1388 endif
1260
1389
1390 " Section: Doc installation {{{1
1391 "
1392 let s:revision="0.1"
1393 silent! let s:install_status =
1394 \ s:HGInstallDocumentation(expand('<sfile>:p'), s:revision)
1395 if (s:install_status == 1)
1396 echom expand("<sfile>:t:r") . ' v' . s:revision .
1397 \ ': Help-documentation installed.'
1398 endif
1399
1400
1261 " Section: Plugin completion {{{1
1401 " Section: Plugin completion {{{1
1262
1402
1263 let loaded_hgcommand=2
1403 let loaded_hgcommand=2
1264 silent do HGCommand User HGPluginFinish
1404 silent do HGCommand User HGPluginFinish
1265 " vim:se expandtab sts=2 sw=2:
1405 " vim:se expandtab sts=2 sw=2:
1406 finish
1407
1408 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1409 " Section: Documentation content {{{1
1410 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1411 === START_DOC
1412 *hgcommand.txt* Mercurial vim integration #version#
1413
1414
1415 HGCOMMAND REFERENCE MANUAL~
1416
1417
1418 Author: Mathieu Clabaut <mathieu.clabaut@gmail.com>
1419 Credits: Bob Hiestand <bob.hiestand@gmail.com>
1420 Mercurial: http://www.selenic.com/mercurial
1421 Mercurial (noted Hg) is a fast, lightweight Source Control Management
1422 system designed for efficient handling of very large distributed projects.
1423
1424 ==============================================================================
1425 1. Contents *hgcommand-contents*
1426
1427 Installation : |hgcommand-install|
1428 HGCommand Intro : |hgcommand|
1429 HGCommand Manual : |hgcommand-manual|
1430 Customization : |hgcommand-customize|
1431 SSH "integration" : |hgcommand-ssh|
1432 Bugs : |hgcommand-bugs|
1433
1434 ==============================================================================
1435 *hgcommand-install*
1436 2. HGCommand Installation
1437
1438 In order to install the plugin, place the hgcommand.vim file into a plugin'
1439 directory in your runtime path (please see |add-global-plugin| and
1440 |'runtimepath'|.
1441
1442 HGCommand may be customized by setting variables, creating maps, and
1443 specifying event handlers. Please see |hgcommand-customize| for more
1444 details.
1445
1446 *hgcommand-auto-help*
1447 The help file is automagically generated when the |vimspell| script is
1448 loaded for the first time.
1449
1450 ==============================================================================
1451
1452 3. HGCommand Intro *hgcommand*
1453 *hgcommand-intro*
1454
1455 The HGCommand plugin provides global ex commands for manipulating
1456 HG-controlled source files. In general, each command operates on the current
1457 buffer and accomplishes a separate hg function, such as update, commit, log,
1458 and others (please see |hgcommand-commands| for a list of all available
1459 commands). The results of each operation are displayed in a scratch buffer.
1460 Several buffer variables are defined for those scratch buffers (please see
1461 |hgcommand-buffer-variables|).
1462
1463 The notion of "current file" means either the current buffer, or, in the case
1464 of a directory buffer, the file on the current line within the buffer.
1465
1466 For convenience, any HGCommand invoked on a HGCommand scratch buffer acts as
1467 though it was invoked on the original file and splits the screen so that the
1468 output appears in a new window.
1469
1470 Many of the commands accept revisions as arguments. By default, most operate
1471 on the most recent revision on the current branch if no revision is specified
1472 (though see |HGCommandInteractive| to prompt instead).
1473
1474 Each HGCommand is mapped to a key sequence starting with the <Leader>
1475 keystroke. The default mappings may be overridden by supplying different
1476 mappings before the plugin is loaded, such as in the vimrc, in the standard
1477 fashion for plugin mappings. For examples, please see
1478 |hgcommand-mappings-override|.
1479
1480 The HGCommand plugin may be configured in several ways. For more details,
1481 please see |hgcommand-customize|.
1482
1483 ==============================================================================
1484
1485 4. HGCommand Manual *hgcommand-manual*
1486
1487 4.1 HGCommand commands *hgcommand-commands*
1488
1489 HGCommand defines the following commands:
1490
1491 |:HGAdd|
1492 |:HGAnnotate|
1493 |:HGCommit|
1494 |:HGDiff|
1495 |:HGGotoOriginal|
1496 |:HGLog|
1497 |:HGRevert|
1498 |:HGReview|
1499 |:HGStatus|
1500 |:HGUnedit|
1501 |:HGUpdate|
1502 |:HGVimDiff|
1503
1504 :HGAdd *:HGAdd*
1505
1506 This command performs "hg add" on the current file. Please note, this does
1507 not commit the newly-added file.
1508
1509 :HGAnnotate *:HGAnnotate*
1510
1511 This command performs "hg annotate" on the current file. If an argument is
1512 given, the argument is used as a revision number to display. If not given an
1513 argument, it uses the most recent version of the file on the current branch.
1514 Additionally, if the current buffer is a HGAnnotate buffer already, the
1515 version number on the current line is used.
1516
1517 If the |HGCommandAnnotateParent| variable is set to a non-zero value, the
1518 version previous to the one on the current line is used instead. This allows
1519 one to navigate back to examine the previous version of a line.
1520
1521 The filetype of the HGCommand scratch buffer is set to 'HGAnnotate', to take
1522 advantage of the bundled syntax file.
1523
1524
1525 :HGCommit[!] *:HGCommit*
1526
1527 If called with arguments, this performs "hg commit" using the arguments as
1528 the log message.
1529
1530 If '!' is used with no arguments, an empty log message is committed.
1531
1532 If called with no arguments, this is a two-step command. The first step opens
1533 a buffer to accept a log message. When that buffer is written, it is
1534 automatically closed and the file is committed using the information from that
1535 log message. The commit can be abandoned if the log message buffer is deleted
1536 or wiped before being written.
1537
1538 Alternatively, the mapping that is used to invoke :HGCommit (by default
1539 <Leader>hgc) can be used in the log message buffer to immediately commit.
1540 This
1541 is useful if the |HGCommandCommitOnWrite| variable is set to 0 to disable the
1542 normal commit-on-write behavior.
1543
1544 :HGDiff *:HGDiff*
1545
1546 With no arguments, this performs "hg diff" on the current file against the
1547 current repository version.
1548
1549 With one argument, "hg diff" is performed on the current file against the
1550 specified revision.
1551
1552 With two arguments, hg diff is performed between the specified
1553 revisions of the current file.
1554
1555 This command uses the 'HGCommandDiffOpt' variable to specify diff options.
1556 If that variable does not exist, then 'wbBc' is assumed. If you wish to have
1557 no options, then set it to the empty string.
1558
1559
1560 This command performs "hg edit" on the current file.
1561
1562 :HGGotoOriginal *:HGGotoOriginal*
1563
1564 This command returns the current window to the source buffer, if the current
1565 buffer is a HG command output buffer.
1566
1567 :HGGotoOriginal!
1568
1569 Like ":HGGotoOriginal" but also executes :bufwipeout on all HG command
1570 output buffers for the source buffer.
1571
1572 :HGLog *:HGLog*
1573
1574 Performs "hg log" on the current file.
1575
1576 If an argument is given, it is passed as an argument to the "-r" option of
1577 "hg log".
1578
1579 :HGRevert *:HGRevert*
1580
1581 Replaces the current file with the most recent version from the repository in
1582 order to wipe out any undesired changes.
1583
1584 :HGReview *:HGReview*
1585
1586 Retrieves a particular version of the current file. If no argument is given,
1587 the most recent version of the file on the current branch is retrieved.
1588 Otherwise, the specified version is retrieved.
1589
1590 :HGStatus *:HGStatus*
1591
1592 Performs "hg status" on the current file.
1593
1594 :HGUnedit *:HGUnedit*
1595
1596 Performs "hg unedit" on the current file. Again, yes, the output buffer here
1597 is basically useless.
1598
1599 :HGUpdate *:HGUpdate*
1600
1601 Performs "hg update" on the current file. This intentionally does not
1602 automatically reload the current buffer, though vim should prompt the user to
1603 do so if the underlying file is altered by this command.
1604
1605 :HGVimDiff *:HGVimDiff*
1606
1607 With no arguments, this prompts the user for a revision and then uses vimdiff
1608 to display the differences between the current file and the specified
1609 revision. If no revision is specified, the most recent version of the file on
1610 the current branch is used.
1611
1612 With one argument, that argument is used as the revision as above. With two
1613 arguments, the differences between the two revisions is displayed using
1614 vimdiff.
1615
1616 With either zero or one argument, the original buffer is used to perform the
1617 vimdiff. When the other buffer is closed, the original buffer will be
1618 returned to normal mode.
1619
1620 Once vimdiff mode is started using the above methods, additional vimdiff
1621 buffers may be added by passing a single version argument to the command.
1622 There may be up to 4 vimdiff buffers total.
1623
1624 Using the 2-argument form of the command resets the vimdiff to only those 2
1625 versions. Additionally, invoking the command on a different file will close
1626 the previous vimdiff buffers.
1627
1628
1629 4.2 Mappings *hgcommand-mappings*
1630
1631 By default, a mapping is defined for each command. These mappings execute the
1632 default (no-argument) form of each command.
1633
1634 <Leader>hga HGAdd
1635 <Leader>hgn HGAnnotate
1636 <Leader>hgc HGCommit
1637 <Leader>hgd HGDiff
1638 <Leader>hgg HGGotoOriginal
1639 <Leader>hgG HGGotoOriginal!
1640 <Leader>hgl HGLog
1641 <Leader>hgr HGReview
1642 <Leader>hgs HGStatus
1643 <Leader>hgt HGUnedit
1644 <Leader>hgu HGUpdate
1645 <Leader>hgv HGVimDiff
1646
1647 *hgcommand-mappings-override*
1648
1649 The default mappings can be overriden by user-provided instead by mapping to
1650 <Plug>CommandName. This is especially useful when these mappings collide with
1651 other existing mappings (vim will warn of this during plugin initialization,
1652 but will not clobber the existing mappings).
1653
1654 For instance, to override the default mapping for :HGAdd to set it to '\add',
1655 add the following to the vimrc:
1656
1657 nmap \add <Plug>HGAdd
1658
1659 4.3 Automatic buffer variables *hgcommand-buffer-variables*
1660
1661 Several buffer variables are defined in each HGCommand result buffer. These
1662 may be useful for additional customization in callbacks defined in the event
1663 handlers (please see |hgcommand-events|).
1664
1665 The following variables are automatically defined:
1666
1667 b:hgOrigBuffNR *b:hgOrigBuffNR*
1668
1669 This variable is set to the buffer number of the source file.
1670
1671 b:hgcmd *b:hgcmd*
1672
1673 This variable is set to the name of the hg command that created the result
1674 buffer.
1675 ==============================================================================
1676
1677 5. Configuration and customization *hgcommand-customize*
1678 *hgcommand-config*
1679
1680 The HGCommand plugin can be configured in two ways: by setting configuration
1681 variables (see |hgcommand-options|) or by defining HGCommand event handlers
1682 (see |hgcommand-events|). Additionally, the HGCommand plugin provides
1683 several option for naming the HG result buffers (see |hgcommand-naming|) and
1684 supported a customized status line (see |hgcommand-statusline| and
1685 |hgcommand-buffer-management|).
1686
1687 5.1 HGCommand configuration variables *hgcommand-options*
1688
1689 Several variables affect the plugin's behavior. These variables are checked
1690 at time of execution, and may be defined at the window, buffer, or global
1691 level and are checked in that order of precedence.
1692
1693
1694 The following variables are available:
1695
1696 |HGCommandAnnotateParent|
1697 |HGCommandCommitOnWrite|
1698 |HGCommandHGExec|
1699 |HGCommandDeleteOnHide|
1700 |HGCommandDiffOpt|
1701 |HGCommandDiffSplit|
1702 |HGCommandEdit|
1703 |HGCommandEnableBufferSetup|
1704 |HGCommandInteractive|
1705 |HGCommandNameMarker|
1706 |HGCommandNameResultBuffers|
1707 |HGCommandSplit|
1708
1709 HGCommandAnnotateParent *HGCommandAnnotateParent*
1710
1711 This variable, if set to a non-zero value, causes the zero-argument form of
1712 HGAnnotate when invoked on a HGAnnotate buffer to go to the version previous
1713 to that displayed on the current line. If not set, it defaults to 0.
1714
1715 HGCommandCommitOnWrite *HGCommandCommitOnWrite*
1716
1717 This variable, if set to a non-zero value, causes the pending hg commit
1718 to take place immediately as soon as the log message buffer is written.
1719 If set to zero, only the HGCommit mapping will cause the pending commit to
1720 occur. If not set, it defaults to 1.
1721
1722 HGCommandHGExec *HGCommandHGExec*
1723
1724 This variable controls the executable used for all HG commands If not set,
1725 it defaults to "hg".
1726
1727 HGCommandDeleteOnHide *HGCommandDeleteOnHide*
1728
1729 This variable, if set to a non-zero value, causes the temporary HG result
1730 buffers to automatically delete themselves when hidden.
1731
1732 HGCommandDiffOpt *HGCommandDiffOpt*
1733
1734 This variable, if set, determines the options passed to the diff command of
1735 HG. If not set, it defaults to 'wbBc'.
1736
1737 HGCommandDiffSplit *HGCommandDiffSplit*
1738
1739 This variable overrides the |HGCommandSplit| variable, but only for buffers
1740 created with |:HGVimDiff|.
1741
1742 HGCommandEdit *HGCommandEdit*
1743
1744 This variable controls whether the original buffer is replaced ('edit') or
1745 split ('split'). If not set, it defaults to 'edit'.
1746
1747 HGCommandEnableBufferSetup *HGCommandEnableBufferSetup*
1748
1749 This variable, if set to a non-zero value, activates HG buffer management
1750 mode see (|hgcommand-buffer-management|). This mode means that two buffer
1751 variables, 'HGRevision' and 'HGBranch', are set if the file is
1752 HG-controlled. This is useful for displaying version information in the
1753 status bar.
1754
1755 HGCommandInteractive *HGCommandInteractive*
1756
1757 This variable, if set to a non-zero value, causes appropriate commands (for
1758 the moment, only |:HGReview|) to query the user for a revision to use instead
1759 of the current revision if none is specified.
1760
1761 HGCommandNameMarker *HGCommandNameMarker*
1762
1763 This variable, if set, configures the special attention-getting characters
1764 that appear on either side of the hg buffer type in the buffer name. This
1765 has no effect unless |HGCommandNameResultBuffers| is set to a true value. If
1766 not set, it defaults to '_'.
1767
1768 HGCommandNameResultBuffers *HGCommandNameResultBuffers*
1769
1770 This variable, if set to a true value, causes the hg result buffers to be
1771 named in the old way ('<source file name> _<hg command>_'). If not set
1772 or set to a false value, the result buffer is nameless.
1773
1774 HGCommandSplit *HGCommandSplit*
1775
1776 This variable controls the orientation of the various window splits that
1777 may occur (such as with HGVimDiff, when using a HG command on a HG
1778 command buffer, or when the |HGCommandEdit| variable is set to 'split'.
1779 If set to 'horizontal', the resulting windows will be on stacked on top of
1780 one another. If set to 'vertical', the resulting windows will be
1781 side-by-side. If not set, it defaults to 'horizontal' for all but
1782 HGVimDiff windows.
1783
1784 5.2 HGCommand events *hgcommand-events*
1785
1786 For additional customization, HGCommand can trigger user-defined events.
1787 Event handlers are provided by defining User event autocommands (see
1788 |autocommand|, |User|) in the HGCommand group with patterns matching the
1789 event name.
1790
1791 For instance, the following could be added to the vimrc to provide a 'q'
1792 mapping to quit a HGCommand scratch buffer:
1793
1794 augroup HGCommand
1795 au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q: bwipeout<cr>
1796 augroup END
1797
1798 The following hooks are available:
1799
1800 HGBufferCreated This event is fired just after a hg command
1801 result buffer is created and filled with the
1802 result of a hg command. It is executed within
1803 the context of the HG command buffer. The
1804 HGCommand buffer variables may be useful for
1805 handlers of this event (please see
1806 |hgcommand-buffer-variables|).
1807
1808 HGBufferSetup This event is fired just after HG buffer setup
1809 occurs, if enabled.
1810
1811 HGPluginInit This event is fired when the HGCommand plugin
1812 first loads.
1813
1814 HGPluginFinish This event is fired just after the HGCommand
1815 plugin loads.
1816
1817 HGVimDiffFinish This event is fired just after the HGVimDiff
1818 command executes to allow customization of,
1819 for instance, window placement and focus.
1820
1821 5.3 HGCommand buffer naming *hgcommand-naming*
1822
1823 By default, the buffers containing the result of HG commands are nameless
1824 scratch buffers. It is intended that buffer variables of those buffers be
1825 used to customize the statusline option so that the user may fully control the
1826 display of result buffers.
1827
1828 If the old-style naming is desired, please enable the
1829 |HGCommandNameResultBuffers| variable. Then, each result buffer will receive
1830 a unique name that includes the source file name, the HG command, and any
1831 extra data (such as revision numbers) that were part of the command.
1832
1833 5.4 HGCommand status line support *hgcommand-statusline*
1834
1835 It is intended that the user will customize the |'statusline'| option to
1836 include HG result buffer attributes. A sample function that may be used in
1837 the |'statusline'| option is provided by the plugin, HGGetStatusLine(). In
1838 order to use that function in the status line, do something like the
1839 following:
1840
1841 set statusline=%<%f\ %{HGGetStatusLine()}\ %h%m%r%=%l,%c%V\ %P
1842
1843 of which %{HGGetStatusLine()} is the relevant portion.
1844
1845 The sample HGGetStatusLine() function handles both HG result buffers and
1846 HG-managed files if HGCommand buffer management is enabled (please see
1847 |hgcommand-buffer-management|).
1848
1849 5.5 HGCommand buffer management *hgcommand-buffer-management*
1850
1851 The HGCommand plugin can operate in buffer management mode, which means that
1852 it attempts to set two buffer variables ('HGRevision' and 'HGBranch') upon
1853 entry into a buffer. This is rather slow because it means that 'hg status'
1854 will be invoked at each entry into a buffer (during the |BufEnter|
1855 autocommand).
1856
1857 This mode is disabled by default. In order to enable it, set the
1858 |HGCommandEnableBufferSetup| variable to a true (non-zero) value. Enabling
1859 this mode simply provides the buffer variables mentioned above. The user must
1860 explicitly include those in the |'statusline'| option if they are to appear in
1861 the status line (but see |hgcommand-statusline| for a simple way to do that).
1862
1863 ==============================================================================
1864
1865 6. SSH "integration" *hgcommand-ssh*
1866
1867 The following instructions are intended for use in integrating the
1868 hgcommand.vim plugin with an SSH-based HG environment.
1869
1870 Familiarity with SSH and HG are assumed.
1871
1872 These instructions assume that the intent is to have a message box pop up in
1873 order to allow the user to enter a passphrase. If, instead, the user is
1874 comfortable using certificate-based authentication, then only instructions
1875 6.1.1 and 6.1.2 (and optionally 6.1.4) need to be followed; ssh should then
1876 work transparently.
1877
1878 6.1 Environment settings *hgcommand-ssh-env*
1879
1880 6.1.1 HGROOT should be set to something like:
1881
1882 :ext:user@host:/path_to_repository
1883
1884 6.1.2 HG_RSH should be set to:
1885
1886 ssh
1887
1888 Together, those settings tell HG to use ssh as the transport when
1889 performing HG calls.
1890
1891 6.1.3 SSH_ASKPASS should be set to the password-dialog program. In my case,
1892 running gnome, it's set to:
1893
1894 /usr/libexec/openssh/gnome-ssh-askpass
1895
1896 This tells SSH how to get passwords if no input is available.
1897
1898 6.1.4 OPTIONAL. You may need to set SSH_SERVER to the location of the hg
1899 executable on the remote (server) machine.
1900
1901 6.2 HG wrapper program *hgcommand-ssh-wrapper*
1902
1903 Now you need to convince SSH to use the password-dialog program. This means
1904 you need to execute SSH (and therefore HG) without standard input. The
1905 following script is a simple perl wrapper that dissasociates the HG command
1906 from the current terminal. Specific steps to do this may vary from system to
1907 system; the following example works for me on linux.
1908
1909 #!/usr/bin/perl -w
1910 use strict;
1911 use POSIX qw(setsid);
1912 open STDIN, '/dev/null';
1913 fork and do {wait; exit;};
1914 setsid;
1915 exec('hg', @ARGV);
1916
1917 6.3 Configuring hgcommand.vim *hgcommand-ssh-config*
1918
1919 At this point, you should be able to use your wrapper script to invoke HG with
1920 various commands, and get the password dialog. All that's left is to make HG
1921 use your newly-created wrapper script.
1922
1923 6.3.1 Tell hgcommand.vim what HG executable to use. The easiest way to do this
1924 is globally, by putting the following in your .vimrc:
1925
1926 let HGCommandHGExec=/path/to/hg/wrapper/script
1927
1928 6.4 Where to go from here *hgcommand-ssh-other*
1929
1930 The script given above works even when non-SSH HG connections are used,
1931 except possibly when interactively entering the message for HG commit log
1932 (depending on the editor you use... VIM works fine). Since the hgcommand.vim
1933 plugin handles that message without a terminal, the wrapper script can be used
1934 all the time.
1935
1936 This allows mixed-mode operation, where some work is done with SSH-based HG
1937 repositories, and others with pserver or local access.
1938
1939 It is possible, though beyond the scope of the plugin, to dynamically set the
1940 HG executable based on the HGROOT for the file being edited. The user
1941 events provided (such as HGBufferCreated and HGBufferSetup) can be used to
1942 set a buffer-local value (b:HGCommandHGExec) to override the HG executable
1943 on a file-by-file basis. Alternatively, much the same can be done (less
1944 automatically) by the various project-oriented plugins out there.
1945
1946 It is highly recommended for ease-of-use that certificates with no passphrase
1947 or ssh-agent are employed so that the user is not given the password prompt
1948 too often.
1949
1950 ==============================================================================
1951 9. Tips *hgcommand-tips*
1952
1953 9.1 Split window annotation, by Michael Anderson
1954
1955 :nmap <Leader>hgN :vs<CR><C-w>h<Leader>hgn:vertical res 40<CR>
1956 \ggdddd:set scb<CR>:set nowrap<CR><C-w>lgg:set scb<CR>
1957 \:set nowrap<CR>
1958
1959 This splits the buffer vertically, puts an annotation on the left (minus the
1960 header) with the width set to 40. An editable/normal copy is placed on the
1961 right. The two versions are scroll locked so they move as one. and wrapping
1962 is turned off so that the lines line up correctly. The advantages are...
1963
1964 1) You get a versioning on the right.
1965 2) You can still edit your own code.
1966 3) Your own code still has syntax highlighting.
1967
1968 ==============================================================================
1969
1970 8. Known bugs *hgcommand-bugs*
1971
1972 Please let me know if you run across any.
1973
1974 HGVimDiff, when using the original (real) source buffer as one of the diff
1975 buffers, uses some hacks to try to restore the state of the original buffer
1976 when the scratch buffer containing the other version is destroyed. There may
1977 still be bugs in here, depending on many configuration details.
1978
1979 ==============================================================================
1980 === END_DOC
1981 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
1982 " v im:tw=78:ts=8:ft=help:norl:
1983 " vim600: set foldmethod=marker tabstop=8 shiftwidth=2 softtabstop=2 smartindent smarttab :
1984 "fileencoding=iso-8859-15
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (567 lines changed) Show them Hide them
General Comments 0
You need to be logged in to leave comments. Login now