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