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