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