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