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