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