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