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