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