PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/contrib/vim/hgcommand.vim

https://bitbucket.org/mirror/mercurial/
Vim Script | 1703 lines | 1317 code | 193 blank | 193 comment | 179 complexity | 2591293077482d926847df4276bea070 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. " vim600: set foldmethod=marker:
  2. "
  3. " Vim plugin to assist in working with HG-controlled files.
  4. "
  5. " Last Change: 2006/02/22
  6. " Version: 1.77
  7. " Maintainer: Mathieu Clabaut <mathieu.clabaut@gmail.com>
  8. " License: This file is placed in the public domain.
  9. " Credits:
  10. " Bob Hiestand <bob.hiestand@gmail.com> for the fabulous
  11. " cvscommand.vim from which this script was directly created by
  12. " means of sed commands and minor tweaks.
  13. " Note:
  14. " For Vim7 the use of Bob Hiestand's vcscommand.vim
  15. " <http://www.vim.org/scripts/script.php?script_id=90>
  16. " in conjunction with Vladmir Marek's Hg backend
  17. " <http://www.vim.org/scripts/script.php?script_id=1898>
  18. " is recommended.
  19. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  20. "
  21. " Section: Documentation
  22. "----------------------------
  23. "
  24. " Documentation should be available by ":help hgcommand" command, once the
  25. " script has been copied in you .vim/plugin directory.
  26. "
  27. " You still can read the documentation at the end of this file. Locate it by
  28. " searching the "hgcommand-contents" string (and set ft=help to have
  29. " appropriate syntactic coloration).
  30. " Section: Plugin header {{{1
  31. " loaded_hgcommand is set to 1 when the initialization begins, and 2 when it
  32. " completes. This allows various actions to only be taken by functions after
  33. " system initialization.
  34. if exists("g:loaded_hgcommand")
  35. finish
  36. endif
  37. let g:loaded_hgcommand = 1
  38. " store 'compatible' settings
  39. let s:save_cpo = &cpo
  40. set cpo&vim
  41. " run checks
  42. let s:script_name = expand("<sfile>:t:r")
  43. function! s:HGCleanupOnFailure(err)
  44. echohl WarningMsg
  45. echomsg s:script_name . ":" a:err "Plugin not loaded"
  46. echohl None
  47. let g:loaded_hgcommand = "no"
  48. unlet s:save_cpo s:script_name
  49. endfunction
  50. if v:version < 602
  51. call <SID>HGCleanupOnFailure("VIM 6.2 or later required.")
  52. finish
  53. endif
  54. if !exists("*system")
  55. call <SID>HGCleanupOnFailure("builtin system() function required.")
  56. finish
  57. endif
  58. let s:script_version = "v0.2"
  59. " Section: Event group setup {{{1
  60. augroup HGCommand
  61. augroup END
  62. " Section: Plugin initialization {{{1
  63. silent do HGCommand User HGPluginInit
  64. " Section: Script variable initialization {{{1
  65. let s:HGCommandEditFileRunning = 0
  66. unlet! s:vimDiffRestoreCmd
  67. unlet! s:vimDiffSourceBuffer
  68. unlet! s:vimDiffBufferCount
  69. unlet! s:vimDiffScratchList
  70. " Section: Utility functions {{{1
  71. " Function: s:HGResolveLink() {{{2
  72. " Fully resolve the given file name to remove shortcuts or symbolic links.
  73. function! s:HGResolveLink(fileName)
  74. let resolved = resolve(a:fileName)
  75. if resolved != a:fileName
  76. let resolved = <SID>HGResolveLink(resolved)
  77. endif
  78. return resolved
  79. endfunction
  80. " Function: s:HGChangeToCurrentFileDir() {{{2
  81. " Go to the directory in which the current HG-controlled file is located.
  82. " If this is a HG command buffer, first switch to the original file.
  83. function! s:HGChangeToCurrentFileDir(fileName)
  84. let oldCwd=getcwd()
  85. let fileName=<SID>HGResolveLink(a:fileName)
  86. let newCwd=fnamemodify(fileName, ':h')
  87. if strlen(newCwd) > 0
  88. try | execute 'cd' escape(newCwd, ' ') | catch | | endtry
  89. endif
  90. return oldCwd
  91. endfunction
  92. " Function: <SID>HGGetOption(name, default) {{{2
  93. " Grab a user-specified option to override the default provided. Options are
  94. " searched in the window, buffer, then global spaces.
  95. function! s:HGGetOption(name, default)
  96. if exists("s:" . a:name . "Override")
  97. execute "return s:".a:name."Override"
  98. elseif exists("w:" . a:name)
  99. execute "return w:".a:name
  100. elseif exists("b:" . a:name)
  101. execute "return b:".a:name
  102. elseif exists("g:" . a:name)
  103. execute "return g:".a:name
  104. else
  105. return a:default
  106. endif
  107. endfunction
  108. " Function: s:HGEditFile(name, origBuffNR) {{{2
  109. " Wrapper around the 'edit' command to provide some helpful error text if the
  110. " current buffer can't be abandoned. If name is provided, it is used;
  111. " otherwise, a nameless scratch buffer is used.
  112. " Returns: 0 if successful, -1 if an error occurs.
  113. function! s:HGEditFile(name, origBuffNR)
  114. "Name parameter will be pasted into expression.
  115. let name = escape(a:name, ' *?\')
  116. let editCommand = <SID>HGGetOption('HGCommandEdit', 'edit')
  117. if editCommand != 'edit'
  118. if <SID>HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
  119. if name == ""
  120. let editCommand = 'rightbelow new'
  121. else
  122. let editCommand = 'rightbelow split ' . name
  123. endif
  124. else
  125. if name == ""
  126. let editCommand = 'vert rightbelow new'
  127. else
  128. let editCommand = 'vert rightbelow split ' . name
  129. endif
  130. endif
  131. else
  132. if name == ""
  133. let editCommand = 'enew'
  134. else
  135. let editCommand = 'edit ' . name
  136. endif
  137. endif
  138. " Protect against useless buffer set-up
  139. let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
  140. try
  141. execute editCommand
  142. finally
  143. let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
  144. endtry
  145. let b:HGOrigBuffNR=a:origBuffNR
  146. let b:HGCommandEdit='split'
  147. endfunction
  148. " Function: s:HGCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2
  149. " Creates a new scratch buffer and captures the output from execution of the
  150. " given command. The name of the scratch buffer is returned.
  151. function! s:HGCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR)
  152. let fileName=bufname(a:origBuffNR)
  153. let resultBufferName=''
  154. if <SID>HGGetOption("HGCommandNameResultBuffers", 0)
  155. let nameMarker = <SID>HGGetOption("HGCommandNameMarker", '_')
  156. if strlen(a:statusText) > 0
  157. let bufName=a:cmdName . ' -- ' . a:statusText
  158. else
  159. let bufName=a:cmdName
  160. endif
  161. let bufName=fileName . ' ' . nameMarker . bufName . nameMarker
  162. let counter=0
  163. let resultBufferName = bufName
  164. while buflisted(resultBufferName)
  165. let counter=counter + 1
  166. let resultBufferName=bufName . ' (' . counter . ')'
  167. endwhile
  168. endif
  169. let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
  170. "echomsg "DBG :".hgCommand
  171. let hgOut = system(hgCommand)
  172. " HACK: diff command does not return proper error codes
  173. if v:shell_error && a:cmdName != 'hgdiff'
  174. if strlen(hgOut) == 0
  175. echoerr "HG command failed"
  176. else
  177. echoerr "HG command failed: " . hgOut
  178. endif
  179. return -1
  180. endif
  181. if strlen(hgOut) == 0
  182. " Handle case of no output. In this case, it is important to check the
  183. " file status, especially since hg edit/unedit may change the attributes
  184. " of the file with no visible output.
  185. echomsg "No output from HG command"
  186. checktime
  187. return -1
  188. endif
  189. if <SID>HGEditFile(resultBufferName, a:origBuffNR) == -1
  190. return -1
  191. endif
  192. set buftype=nofile
  193. set noswapfile
  194. set filetype=
  195. if <SID>HGGetOption("HGCommandDeleteOnHide", 0)
  196. set bufhidden=delete
  197. endif
  198. silent 0put=hgOut
  199. " The last command left a blank line at the end of the buffer. If the
  200. " last line is folded (a side effect of the 'put') then the attempt to
  201. " remove the blank line will kill the last fold.
  202. "
  203. " This could be fixed by explicitly detecting whether the last line is
  204. " within a fold, but I prefer to simply unfold the result buffer altogether.
  205. if has("folding")
  206. setlocal nofoldenable
  207. endif
  208. $d
  209. 1
  210. " Define the environment and execute user-defined hooks.
  211. let b:HGSourceFile=fileName
  212. let b:HGCommand=a:cmdName
  213. if a:statusText != ""
  214. let b:HGStatusText=a:statusText
  215. endif
  216. silent do HGCommand User HGBufferCreated
  217. return bufnr("%")
  218. endfunction
  219. " Function: s:HGBufferCheck(hgBuffer) {{{2
  220. " Attempts to locate the original file to which HG operations were applied
  221. " for a given buffer.
  222. function! s:HGBufferCheck(hgBuffer)
  223. let origBuffer = getbufvar(a:hgBuffer, "HGOrigBuffNR")
  224. if origBuffer
  225. if bufexists(origBuffer)
  226. return origBuffer
  227. else
  228. " Original buffer no longer exists.
  229. return -1
  230. endif
  231. else
  232. " No original buffer
  233. return a:hgBuffer
  234. endif
  235. endfunction
  236. " Function: s:HGCurrentBufferCheck() {{{2
  237. " Attempts to locate the original file to which HG operations were applied
  238. " for the current buffer.
  239. function! s:HGCurrentBufferCheck()
  240. return <SID>HGBufferCheck(bufnr("%"))
  241. endfunction
  242. " Function: s:HGToggleDeleteOnHide() {{{2
  243. " Toggles on and off the delete-on-hide behavior of HG buffers
  244. function! s:HGToggleDeleteOnHide()
  245. if exists("g:HGCommandDeleteOnHide")
  246. unlet g:HGCommandDeleteOnHide
  247. else
  248. let g:HGCommandDeleteOnHide=1
  249. endif
  250. endfunction
  251. " Function: s:HGDoCommand(hgcmd, cmdName, statusText) {{{2
  252. " General skeleton for HG function execution.
  253. " Returns: name of the new command buffer containing the command results
  254. function! s:HGDoCommand(cmd, cmdName, statusText)
  255. let hgBufferCheck=<SID>HGCurrentBufferCheck()
  256. if hgBufferCheck == -1
  257. echo "Original buffer no longer exists, aborting."
  258. return -1
  259. endif
  260. let fileName=bufname(hgBufferCheck)
  261. if isdirectory(fileName)
  262. let fileName=fileName . "/" . getline(".")
  263. endif
  264. let realFileName = fnamemodify(<SID>HGResolveLink(fileName), ':t')
  265. let oldCwd=<SID>HGChangeToCurrentFileDir(fileName)
  266. try
  267. " TODO
  268. "if !filereadable('HG/Root')
  269. "throw fileName . ' is not a HG-controlled file.'
  270. "endif
  271. let fullCmd = a:cmd . ' "' . realFileName . '"'
  272. "echomsg "DEBUG".fullCmd
  273. let resultBuffer=<SID>HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
  274. return resultBuffer
  275. catch
  276. echoerr v:exception
  277. return -1
  278. finally
  279. execute 'cd' escape(oldCwd, ' ')
  280. endtry
  281. endfunction
  282. " Function: s:HGGetStatusVars(revision, branch, repository) {{{2
  283. "
  284. " Obtains a HG revision number and branch name. The 'revisionVar',
  285. " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold
  286. " the corresponding results.
  287. "
  288. " Returns: string to be exec'd that sets the multiple return values.
  289. function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
  290. let hgBufferCheck=<SID>HGCurrentBufferCheck()
  291. "echomsg "DBG : in HGGetStatusVars"
  292. if hgBufferCheck == -1
  293. return ""
  294. endif
  295. let fileName=bufname(hgBufferCheck)
  296. let fileNameWithoutLink=<SID>HGResolveLink(fileName)
  297. let realFileName = fnamemodify(fileNameWithoutLink, ':t')
  298. let oldCwd=<SID>HGChangeToCurrentFileDir(realFileName)
  299. try
  300. let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " root "
  301. let roottext=system(hgCommand)
  302. " Suppress ending null char ! Does it work in window ?
  303. let roottext=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
  304. if match(getcwd()."/".fileNameWithoutLink, roottext) == -1
  305. return ""
  306. endif
  307. let returnExpression = ""
  308. if a:repositoryVar != ""
  309. let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . roottext . "'"
  310. endif
  311. let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . realFileName
  312. let statustext=system(hgCommand)
  313. if(v:shell_error)
  314. return ""
  315. endif
  316. if match(statustext, '^[?I]') >= 0
  317. let revision="NEW"
  318. elseif match(statustext, '^[R]') >= 0
  319. let revision="REMOVED"
  320. elseif match(statustext, '^[D]') >= 0
  321. let revision="DELETED"
  322. elseif match(statustext, '^[A]') >= 0
  323. let revision="ADDED"
  324. else
  325. " The file is tracked, we can try to get is revision number
  326. let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " parents "
  327. let statustext=system(hgCommand)
  328. if(v:shell_error)
  329. return ""
  330. endif
  331. let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
  332. if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
  333. let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
  334. let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
  335. endif
  336. endif
  337. if (exists('revision'))
  338. let returnExpression = "let " . a:revisionVar . "='" . revision . "' " . returnExpression
  339. endif
  340. return returnExpression
  341. finally
  342. try | execute 'cd' escape(oldCwd, ' ') | catch | | endtry
  343. endtry
  344. endfunction
  345. " Function: s:HGSetupBuffer() {{{2
  346. " Attempts to set the b:HGBranch, b:HGRevision and b:HGRepository variables.
  347. function! s:HGSetupBuffer(...)
  348. if (exists("b:HGBufferSetup") && b:HGBufferSetup && !exists('a:1'))
  349. " This buffer is already set up.
  350. return
  351. endif
  352. if !<SID>HGGetOption("HGCommandEnableBufferSetup", 0)
  353. \ || @% == ""
  354. \ || s:HGCommandEditFileRunning > 0
  355. \ || exists("b:HGOrigBuffNR")
  356. unlet! b:HGRevision
  357. unlet! b:HGBranch
  358. unlet! b:HGRepository
  359. return
  360. endif
  361. if !filereadable(expand("%"))
  362. return -1
  363. endif
  364. let revision=""
  365. let branch=""
  366. let repository=""
  367. exec <SID>HGGetStatusVars('revision', 'branch', 'repository')
  368. "echomsg "DBG ".revision."#".branch."#".repository
  369. if revision != ""
  370. let b:HGRevision=revision
  371. else
  372. unlet! b:HGRevision
  373. endif
  374. if branch != ""
  375. let b:HGBranch=branch
  376. else
  377. unlet! b:HGBranch
  378. endif
  379. if repository != ""
  380. let b:HGRepository=repository
  381. else
  382. unlet! b:HGRepository
  383. endif
  384. silent do HGCommand User HGBufferSetup
  385. let b:HGBufferSetup=1
  386. endfunction
  387. " Function: s:HGMarkOrigBufferForSetup(hgbuffer) {{{2
  388. " Resets the buffer setup state of the original buffer for a given HG buffer.
  389. " Returns: The HG buffer number in a passthrough mode.
  390. function! s:HGMarkOrigBufferForSetup(hgBuffer)
  391. checktime
  392. if a:hgBuffer != -1
  393. let origBuffer = <SID>HGBufferCheck(a:hgBuffer)
  394. "This should never not work, but I'm paranoid
  395. if origBuffer != a:hgBuffer
  396. call setbufvar(origBuffer, "HGBufferSetup", 0)
  397. endif
  398. else
  399. "We are presumably in the original buffer
  400. let b:HGBufferSetup = 0
  401. "We do the setup now as now event will be triggered allowing it later.
  402. call <SID>HGSetupBuffer()
  403. endif
  404. return a:hgBuffer
  405. endfunction
  406. " Function: s:HGOverrideOption(option, [value]) {{{2
  407. " Provides a temporary override for the given HG option. If no value is
  408. " passed, the override is disabled.
  409. function! s:HGOverrideOption(option, ...)
  410. if a:0 == 0
  411. unlet! s:{a:option}Override
  412. else
  413. let s:{a:option}Override = a:1
  414. endif
  415. endfunction
  416. " Function: s:HGWipeoutCommandBuffers() {{{2
  417. " Clears all current HG buffers of the specified type for a given source.
  418. function! s:HGWipeoutCommandBuffers(originalBuffer, hgCommand)
  419. let buffer = 1
  420. while buffer <= bufnr('$')
  421. if getbufvar(buffer, 'HGOrigBuffNR') == a:originalBuffer
  422. if getbufvar(buffer, 'HGCommand') == a:hgCommand
  423. execute 'bw' buffer
  424. endif
  425. endif
  426. let buffer = buffer + 1
  427. endwhile
  428. endfunction
  429. " Function: s:HGInstallDocumentation(full_name, revision) {{{2
  430. " Install help documentation.
  431. " Arguments:
  432. " full_name: Full name of this vim plugin script, including path name.
  433. " revision: Revision of the vim script. #version# mark in the document file
  434. " will be replaced with this string with 'v' prefix.
  435. " Return:
  436. " 1 if new document installed, 0 otherwise.
  437. " Note: Cleaned and generalized by guo-peng Wen
  438. "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  439. " Helper function to make mkdir as portable as possible
  440. function! s:HGFlexiMkdir(dir)
  441. if exists("*mkdir") " we can use Vim's own mkdir()
  442. call mkdir(a:dir)
  443. elseif !exists("+shellslash")
  444. call system("mkdir -p '".a:dir."'")
  445. else " M$
  446. let l:ssl = &shellslash
  447. try
  448. set shellslash
  449. " no single quotes?
  450. call system('mkdir "'.a:dir.'"')
  451. finally
  452. let &shellslash = l:ssl
  453. endtry
  454. endif
  455. endfunction
  456. function! s:HGInstallDocumentation(full_name)
  457. " Figure out document path based on full name of this script:
  458. let l:vim_doc_path = fnamemodify(a:full_name, ":h:h") . "/doc"
  459. if filewritable(l:vim_doc_path) != 2
  460. echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
  461. silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
  462. if filewritable(l:vim_doc_path) != 2
  463. " Try first item in 'runtimepath':
  464. let l:vim_doc_path =
  465. \ substitute(&runtimepath, '^\([^,]*\).*', '\1/doc', 'e')
  466. if filewritable(l:vim_doc_path) != 2
  467. echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
  468. silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
  469. if filewritable(l:vim_doc_path) != 2
  470. " Put a warning:
  471. echomsg "Unable to open documentation directory"
  472. echomsg " type `:help add-local-help' for more information."
  473. return 0
  474. endif
  475. endif
  476. endif
  477. endif
  478. " Full name of documentation file:
  479. let l:doc_file =
  480. \ l:vim_doc_path . "/" . s:script_name . ".txt"
  481. " Bail out if document file is still up to date:
  482. if filereadable(l:doc_file) &&
  483. \ getftime(a:full_name) < getftime(l:doc_file)
  484. return 0
  485. endif
  486. " temporary global settings
  487. let l:lz = &lazyredraw
  488. let l:hls = &hlsearch
  489. set lazyredraw nohlsearch
  490. " Create a new buffer & read in the plugin file (me):
  491. 1 new
  492. setlocal noswapfile modifiable nomodeline
  493. if has("folding")
  494. setlocal nofoldenable
  495. endif
  496. silent execute "read" escape(a:full_name, " ")
  497. let l:doc_buf = bufnr("%")
  498. 1
  499. " Delete from first line to a line starts with
  500. " === START_DOC
  501. silent 1,/^=\{3,}\s\+START_DOC\C/ delete _
  502. " Delete from a line starts with
  503. " === END_DOC
  504. " to the end of the documents:
  505. silent /^=\{3,}\s\+END_DOC\C/,$ delete _
  506. " Add modeline for help doc: the modeline string is mangled intentionally
  507. " to avoid it be recognized by VIM:
  508. call append(line("$"), "")
  509. call append(line("$"), " v" . "im:tw=78:ts=8:ft=help:norl:")
  510. " Replace revision:
  511. silent execute "normal :1s/#version#/" . s:script_version . "/\<CR>"
  512. " Save the help document and wipe out buffer:
  513. silent execute "wq!" escape(l:doc_file, " ") "| bw" l:doc_buf
  514. " Build help tags:
  515. silent execute "helptags" l:vim_doc_path
  516. let &hlsearch = l:hls
  517. let &lazyredraw = l:lz
  518. return 1
  519. endfunction
  520. " Section: Public functions {{{1
  521. " Function: HGGetRevision() {{{2
  522. " Global function for retrieving the current buffer's HG revision number.
  523. " Returns: Revision number or an empty string if an error occurs.
  524. function! HGGetRevision()
  525. let revision=""
  526. exec <SID>HGGetStatusVars('revision', '', '')
  527. return revision
  528. endfunction
  529. " Function: HGDisableBufferSetup() {{{2
  530. " Global function for deactivating the buffer autovariables.
  531. function! HGDisableBufferSetup()
  532. let g:HGCommandEnableBufferSetup=0
  533. silent! augroup! HGCommandPlugin
  534. endfunction
  535. " Function: HGEnableBufferSetup() {{{2
  536. " Global function for activating the buffer autovariables.
  537. function! HGEnableBufferSetup()
  538. let g:HGCommandEnableBufferSetup=1
  539. augroup HGCommandPlugin
  540. au!
  541. au BufEnter * call <SID>HGSetupBuffer()
  542. au BufWritePost * call <SID>HGSetupBuffer()
  543. " Force resetting up buffer on external file change (HG update)
  544. au FileChangedShell * call <SID>HGSetupBuffer(1)
  545. augroup END
  546. " Only auto-load if the plugin is fully loaded. This gives other plugins a
  547. " chance to run.
  548. if g:loaded_hgcommand == 2
  549. call <SID>HGSetupBuffer()
  550. endif
  551. endfunction
  552. " Function: HGGetStatusLine() {{{2
  553. " Default (sample) status line entry for HG files. This is only useful if
  554. " HG-managed buffer mode is on (see the HGCommandEnableBufferSetup variable
  555. " for how to do this).
  556. function! HGGetStatusLine()
  557. if exists('b:HGSourceFile')
  558. " This is a result buffer
  559. let value='[' . b:HGCommand . ' ' . b:HGSourceFile
  560. if exists('b:HGStatusText')
  561. let value=value . ' ' . b:HGStatusText
  562. endif
  563. let value = value . ']'
  564. return value
  565. endif
  566. if exists('b:HGRevision')
  567. \ && b:HGRevision != ''
  568. \ && exists('b:HGRepository')
  569. \ && b:HGRepository != ''
  570. \ && exists('g:HGCommandEnableBufferSetup')
  571. \ && g:HGCommandEnableBufferSetup
  572. if !exists('b:HGBranch')
  573. let l:branch=''
  574. else
  575. let l:branch=b:HGBranch
  576. endif
  577. return '[HG ' . b:HGRepository . '/' . l:branch .'/' . b:HGRevision . ']'
  578. else
  579. return ''
  580. endif
  581. endfunction
  582. " Section: HG command functions {{{1
  583. " Function: s:HGAdd() {{{2
  584. function! s:HGAdd()
  585. return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('add', 'hgadd', ''))
  586. endfunction
  587. " Function: s:HGAnnotate(...) {{{2
  588. function! s:HGAnnotate(...)
  589. if a:0 == 0
  590. if &filetype == "HGAnnotate"
  591. " This is a HGAnnotate buffer. Perform annotation of the version
  592. " indicated by the current line.
  593. let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','')
  594. if <SID>HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
  595. let revision = revision - 1
  596. endif
  597. else
  598. let revision=HGGetRevision()
  599. if revision == ""
  600. echoerr "Unable to obtain HG version information."
  601. return -1
  602. endif
  603. endif
  604. else
  605. let revision=a:1
  606. endif
  607. if revision == "NEW"
  608. echo "No annotatation available for new file."
  609. return -1
  610. endif
  611. let resultBuffer=<SID>HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision)
  612. "echomsg "DBG: ".resultBuffer
  613. if resultBuffer != -1
  614. set filetype=HGAnnotate
  615. endif
  616. return resultBuffer
  617. endfunction
  618. " Function: s:HGCommit() {{{2
  619. function! s:HGCommit(...)
  620. " Handle the commit message being specified. If a message is supplied, it
  621. " is used; if bang is supplied, an empty message is used; otherwise, the
  622. " user is provided a buffer from which to edit the commit message.
  623. if a:2 != "" || a:1 == "!"
  624. return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
  625. endif
  626. let hgBufferCheck=<SID>HGCurrentBufferCheck()
  627. if hgBufferCheck == -1
  628. echo "Original buffer no longer exists, aborting."
  629. return -1
  630. endif
  631. " Protect against windows' backslashes in paths. They confuse exec'd
  632. " commands.
  633. let shellSlashBak = &shellslash
  634. try
  635. set shellslash
  636. let messageFileName = tempname()
  637. let fileName=bufname(hgBufferCheck)
  638. let realFilePath=<SID>HGResolveLink(fileName)
  639. let newCwd=fnamemodify(realFilePath, ':h')
  640. if strlen(newCwd) == 0
  641. " Account for autochdir being in effect, which will make this blank, but
  642. " we know we'll be in the current directory for the original file.
  643. let newCwd = getcwd()
  644. endif
  645. let realFileName=fnamemodify(realFilePath, ':t')
  646. if <SID>HGEditFile(messageFileName, hgBufferCheck) == -1
  647. return
  648. endif
  649. " Protect against case and backslash issues in Windows.
  650. let autoPattern = '\c' . messageFileName
  651. " Ensure existence of group
  652. augroup HGCommit
  653. augroup END
  654. execute 'au HGCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")'
  655. execute 'au HGCommit BufDelete' autoPattern 'au! HGCommit * ' autoPattern
  656. " Create a commit mapping. The mapping must clear all autocommands in case
  657. " it is invoked when HGCommandCommitOnWrite is active, as well as to not
  658. " invoke the buffer deletion autocommand.
  659. execute 'nnoremap <silent> <buffer> <Plug>HGCommit '.
  660. \ ':au! HGCommit * ' . autoPattern . '<CR>'.
  661. \ ':g/^HG:/d<CR>'.
  662. \ ':update<CR>'.
  663. \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
  664. \ '"' . newCwd . '",' .
  665. \ '"' . realFileName . '",' .
  666. \ hgBufferCheck . ')<CR>'
  667. silent 0put ='HG: ----------------------------------------------------------------------'
  668. silent put =\"HG: Enter Log. Lines beginning with `HG:' are removed automatically\"
  669. silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
  670. if <SID>HGGetOption('HGCommandCommitOnWrite', 1) == 1
  671. execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d'
  672. execute 'au HGCommit BufWritePost' autoPattern 'call <SID>HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
  673. silent put ='HG: or write this buffer'
  674. endif
  675. silent put ='HG: to finish this commit operation'
  676. silent put ='HG: ----------------------------------------------------------------------'
  677. $
  678. let b:HGSourceFile=fileName
  679. let b:HGCommand='HGCommit'
  680. set filetype=hg
  681. finally
  682. let &shellslash = shellSlashBak
  683. endtry
  684. endfunction
  685. " Function: s:HGDiff(...) {{{2
  686. function! s:HGDiff(...)
  687. if a:0 == 1
  688. let revOptions = '-r' . a:1
  689. let caption = a:1 . ' -> current'
  690. elseif a:0 == 2
  691. let revOptions = '-r' . a:1 . ' -r' . a:2
  692. let caption = a:1 . ' -> ' . a:2
  693. else
  694. let revOptions = ''
  695. let caption = ''
  696. endif
  697. let hgdiffopt=<SID>HGGetOption('HGCommandDiffOpt', 'w')
  698. if hgdiffopt == ""
  699. let diffoptionstring=""
  700. else
  701. let diffoptionstring=" -" . hgdiffopt . " "
  702. endif
  703. let resultBuffer = <SID>HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
  704. if resultBuffer != -1
  705. set filetype=diff
  706. endif
  707. return resultBuffer
  708. endfunction
  709. " Function: s:HGGotoOriginal(["!]) {{{2
  710. function! s:HGGotoOriginal(...)
  711. let origBuffNR = <SID>HGCurrentBufferCheck()
  712. if origBuffNR > 0
  713. let origWinNR = bufwinnr(origBuffNR)
  714. if origWinNR == -1
  715. execute 'buffer' origBuffNR
  716. else
  717. execute origWinNR . 'wincmd w'
  718. endif
  719. if a:0 == 1
  720. if a:1 == "!"
  721. let buffnr = 1
  722. let buffmaxnr = bufnr("$")
  723. while buffnr <= buffmaxnr
  724. if getbufvar(buffnr, "HGOrigBuffNR") == origBuffNR
  725. execute "bw" buffnr
  726. endif
  727. let buffnr = buffnr + 1
  728. endwhile
  729. endif
  730. endif
  731. endif
  732. endfunction
  733. " Function: s:HGFinishCommit(messageFile, targetDir, targetFile) {{{2
  734. function! s:HGFinishCommit(messageFile, targetDir, targetFile, origBuffNR)
  735. if filereadable(a:messageFile)
  736. let oldCwd=getcwd()
  737. if strlen(a:targetDir) > 0
  738. execute 'cd' escape(a:targetDir, ' ')
  739. endif
  740. let resultBuffer=<SID>HGCreateCommandBuffer('commit -l "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
  741. execute 'cd' escape(oldCwd, ' ')
  742. execute 'bw' escape(a:messageFile, ' *?\')
  743. silent execute 'call delete("' . a:messageFile . '")'
  744. return <SID>HGMarkOrigBufferForSetup(resultBuffer)
  745. else
  746. echoerr "Can't read message file; no commit is possible."
  747. return -1
  748. endif
  749. endfunction
  750. " Function: s:HGLog() {{{2
  751. function! s:HGLog(...)
  752. if a:0 == 0
  753. let versionOption = ""
  754. let caption = ''
  755. else
  756. let versionOption=" -r" . a:1
  757. let caption = a:1
  758. endif
  759. let resultBuffer=<SID>HGDoCommand('log' . versionOption, 'hglog', caption)
  760. if resultBuffer != ""
  761. set filetype=rcslog
  762. endif
  763. return resultBuffer
  764. endfunction
  765. " Function: s:HGRevert() {{{2
  766. function! s:HGRevert()
  767. return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('revert', 'hgrevert', ''))
  768. endfunction
  769. " Function: s:HGReview(...) {{{2
  770. function! s:HGReview(...)
  771. if a:0 == 0
  772. let versiontag=""
  773. if <SID>HGGetOption('HGCommandInteractive', 0)
  774. let versiontag=input('Revision: ')
  775. endif
  776. if versiontag == ""
  777. let versiontag="(current)"
  778. let versionOption=""
  779. else
  780. let versionOption=" -r " . versiontag . " "
  781. endif
  782. else
  783. let versiontag=a:1
  784. let versionOption=" -r " . versiontag . " "
  785. endif
  786. let resultBuffer = <SID>HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
  787. if resultBuffer > 0
  788. let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype')
  789. endif
  790. return resultBuffer
  791. endfunction
  792. " Function: s:HGStatus() {{{2
  793. function! s:HGStatus()
  794. return <SID>HGDoCommand('status', 'hgstatus', '')
  795. endfunction
  796. " Function: s:HGUpdate() {{{2
  797. function! s:HGUpdate()
  798. return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('update', 'update', ''))
  799. endfunction
  800. " Function: s:HGVimDiff(...) {{{2
  801. function! s:HGVimDiff(...)
  802. let originalBuffer = <SID>HGCurrentBufferCheck()
  803. let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
  804. try
  805. " If there's already a VimDiff'ed window, restore it.
  806. " There may only be one HGVimDiff original window at a time.
  807. if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
  808. " Clear the existing vimdiff setup by removing the result buffers.
  809. call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
  810. endif
  811. " Split and diff
  812. if(a:0 == 2)
  813. " Reset the vimdiff system, as 2 explicit versions were provided.
  814. if exists('s:vimDiffSourceBuffer')
  815. call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
  816. endif
  817. let resultBuffer = <SID>HGReview(a:1)
  818. if resultBuffer < 0
  819. echomsg "Can't open HG revision " . a:1
  820. return resultBuffer
  821. endif
  822. let b:HGCommand = 'vimdiff'
  823. diffthis
  824. let s:vimDiffBufferCount = 1
  825. let s:vimDiffScratchList = '{'. resultBuffer . '}'
  826. " If no split method is defined, cheat, and set it to vertical.
  827. try
  828. call <SID>HGOverrideOption('HGCommandSplit', <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
  829. let resultBuffer=<SID>HGReview(a:2)
  830. finally
  831. call <SID>HGOverrideOption('HGCommandSplit')
  832. endtry
  833. if resultBuffer < 0
  834. echomsg "Can't open HG revision " . a:1
  835. return resultBuffer
  836. endif
  837. let b:HGCommand = 'vimdiff'
  838. diffthis
  839. let s:vimDiffBufferCount = 2
  840. let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}'
  841. else
  842. " Add new buffer
  843. try
  844. " Force splitting behavior, otherwise why use vimdiff?
  845. call <SID>HGOverrideOption("HGCommandEdit", "split")
  846. call <SID>HGOverrideOption("HGCommandSplit", <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
  847. if(a:0 == 0)
  848. let resultBuffer=<SID>HGReview()
  849. else
  850. let resultBuffer=<SID>HGReview(a:1)
  851. endif
  852. finally
  853. call <SID>HGOverrideOption("HGCommandEdit")
  854. call <SID>HGOverrideOption("HGCommandSplit")
  855. endtry
  856. if resultBuffer < 0
  857. echomsg "Can't open current HG revision"
  858. return resultBuffer
  859. endif
  860. let b:HGCommand = 'vimdiff'
  861. diffthis
  862. if !exists('s:vimDiffBufferCount')
  863. " New instance of vimdiff.
  864. let s:vimDiffBufferCount = 2
  865. let s:vimDiffScratchList = '{' . resultBuffer . '}'
  866. " This could have been invoked on a HG result buffer, not the
  867. " original buffer.
  868. wincmd W
  869. execute 'buffer' originalBuffer
  870. " Store info for later original buffer restore
  871. let s:vimDiffRestoreCmd =
  872. \ "call setbufvar(".originalBuffer.", \"&diff\", ".getbufvar(originalBuffer, '&diff').")"
  873. \ . "|call setbufvar(".originalBuffer.", \"&foldcolumn\", ".getbufvar(originalBuffer, '&foldcolumn').")"
  874. \ . "|call setbufvar(".originalBuffer.", \"&foldenable\", ".getbufvar(originalBuffer, '&foldenable').")"
  875. \ . "|call setbufvar(".originalBuffer.", \"&foldmethod\", '".getbufvar(originalBuffer, '&foldmethod')."')"
  876. \ . "|call setbufvar(".originalBuffer.", \"&scrollbind\", ".getbufvar(originalBuffer, '&scrollbind').")"
  877. \ . "|call setbufvar(".originalBuffer.", \"&wrap\", ".getbufvar(originalBuffer, '&wrap').")"
  878. \ . "|if &foldmethod=='manual'|execute 'normal! zE'|endif"
  879. diffthis
  880. wincmd w
  881. else
  882. " Adding a window to an existing vimdiff
  883. let s:vimDiffBufferCount = s:vimDiffBufferCount + 1
  884. let s:vimDiffScratchList = s:vimDiffScratchList . '{' . resultBuffer . '}'
  885. endif
  886. endif
  887. let s:vimDiffSourceBuffer = originalBuffer
  888. " Avoid executing the modeline in the current buffer after the autocommand.
  889. let currentBuffer = bufnr('%')
  890. let saveModeline = getbufvar(currentBuffer, '&modeline')
  891. try
  892. call setbufvar(currentBuffer, '&modeline', 0)
  893. silent do HGCommand User HGVimDiffFinish
  894. finally
  895. call setbufvar(currentBuffer, '&modeline', saveModeline)
  896. endtry
  897. return resultBuffer
  898. finally
  899. let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
  900. endtry
  901. endfunction
  902. " Section: Command definitions {{{1
  903. " Section: Primary commands {{{2
  904. com! HGAdd call <SID>HGAdd()
  905. com! -nargs=? HGAnnotate call <SID>HGAnnotate(<f-args>)
  906. com! -bang -nargs=? HGCommit call <SID>HGCommit(<q-bang>, <q-args>)
  907. com! -nargs=* HGDiff call <SID>HGDiff(<f-args>)
  908. com! -bang HGGotoOriginal call <SID>HGGotoOriginal(<q-bang>)
  909. com! -nargs=? HGLog call <SID>HGLog(<f-args>)
  910. com! HGRevert call <SID>HGRevert()
  911. com! -nargs=? HGReview call <SID>HGReview(<f-args>)
  912. com! HGStatus call <SID>HGStatus()
  913. com! HGUpdate call <SID>HGUpdate()
  914. com! -nargs=* HGVimDiff call <SID>HGVimDiff(<f-args>)
  915. " Section: HG buffer management commands {{{2
  916. com! HGDisableBufferSetup call HGDisableBufferSetup()
  917. com! HGEnableBufferSetup call HGEnableBufferSetup()
  918. " Allow reloading hgcommand.vim
  919. com! HGReload unlet! g:loaded_hgcommand | runtime plugin/hgcommand.vim
  920. " Section: Plugin command mappings {{{1
  921. nnoremap <silent> <Plug>HGAdd :HGAdd<CR>
  922. nnoremap <silent> <Plug>HGAnnotate :HGAnnotate<CR>
  923. nnoremap <silent> <Plug>HGCommit :HGCommit<CR>
  924. nnoremap <silent> <Plug>HGDiff :HGDiff<CR>
  925. nnoremap <silent> <Plug>HGGotoOriginal :HGGotoOriginal<CR>
  926. nnoremap <silent> <Plug>HGClearAndGotoOriginal :HGGotoOriginal!<CR>
  927. nnoremap <silent> <Plug>HGLog :HGLog<CR>
  928. nnoremap <silent> <Plug>HGRevert :HGRevert<CR>
  929. nnoremap <silent> <Plug>HGReview :HGReview<CR>
  930. nnoremap <silent> <Plug>HGStatus :HGStatus<CR>
  931. nnoremap <silent> <Plug>HGUpdate :HGUpdate<CR>
  932. nnoremap <silent> <Plug>HGVimDiff :HGVimDiff<CR>
  933. " Section: Default mappings {{{1
  934. if !hasmapto('<Plug>HGAdd')
  935. nmap <unique> <Leader>hga <Plug>HGAdd
  936. endif
  937. if !hasmapto('<Plug>HGAnnotate')
  938. nmap <unique> <Leader>hgn <Plug>HGAnnotate
  939. endif
  940. if !hasmapto('<Plug>HGClearAndGotoOriginal')
  941. nmap <unique> <Leader>hgG <Plug>HGClearAndGotoOriginal
  942. endif
  943. if !hasmapto('<Plug>HGCommit')
  944. nmap <unique> <Leader>hgc <Plug>HGCommit
  945. endif
  946. if !hasmapto('<Plug>HGDiff')
  947. nmap <unique> <Leader>hgd <Plug>HGDiff
  948. endif
  949. if !hasmapto('<Plug>HGGotoOriginal')
  950. nmap <unique> <Leader>hgg <Plug>HGGotoOriginal
  951. endif
  952. if !hasmapto('<Plug>HGLog')
  953. nmap <unique> <Leader>hgl <Plug>HGLog
  954. endif
  955. if !hasmapto('<Plug>HGRevert')
  956. nmap <unique> <Leader>hgq <Plug>HGRevert
  957. endif
  958. if !hasmapto('<Plug>HGReview')
  959. nmap <unique> <Leader>hgr <Plug>HGReview
  960. endif
  961. if !hasmapto('<Plug>HGStatus')
  962. nmap <unique> <Leader>hgs <Plug>HGStatus
  963. endif
  964. if !hasmapto('<Plug>HGUpdate')
  965. nmap <unique> <Leader>hgu <Plug>HGUpdate
  966. endif
  967. if !hasmapto('<Plug>HGVimDiff')
  968. nmap <unique> <Leader>hgv <Plug>HGVimDiff
  969. endif
  970. " Section: Menu items {{{1
  971. silent! aunmenu Plugin.HG
  972. amenu <silent> &Plugin.HG.&Add <Plug>HGAdd
  973. amenu <silent> &Plugin.HG.A&nnotate <Plug>HGAnnotate
  974. amenu <silent> &Plugin.HG.&Commit <Plug>HGCommit
  975. amenu <silent> &Plugin.HG.&Diff <Plug>HGDiff
  976. amenu <silent> &Plugin.HG.&Log <Plug>HGLog
  977. amenu <silent> &Plugin.HG.Revert <Plug>HGRevert
  978. amenu <silent> &Plugin.HG.&Review <Plug>HGReview
  979. amenu <silent> &Plugin.HG.&Status <Plug>HGStatus
  980. amenu <silent> &Plugin.HG.&Update <Plug>HGUpdate
  981. amenu <silent> &Plugin.HG.&VimDiff <Plug>HGVimDiff
  982. " Section: Autocommands to restore vimdiff state {{{1
  983. function! s:HGVimDiffRestore(vimDiffBuff)
  984. let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
  985. try
  986. if exists("s:vimDiffSourceBuffer")
  987. if a:vimDiffBuff == s:vimDiffSourceBuffer
  988. " Original file is being removed.
  989. unlet! s:vimDiffSourceBuffer
  990. unlet! s:vimDiffBufferCount
  991. unlet! s:vimDiffRestoreCmd
  992. unlet! s:vimDiffScratchList
  993. elseif match(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}') >= 0
  994. let s:vimDiffScratchList = substitute(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}', '', '')
  995. let s:vimDiffBufferCount = s:vimDiffBufferCount - 1
  996. if s:vimDiffBufferCount == 1 && exists('s:vimDiffRestoreCmd')
  997. " All scratch buffers are gone, reset the original.
  998. " Only restore if the source buffer is still in Diff mode
  999. let sourceWinNR=bufwinnr(s:vimDiffSourceBuffer)
  1000. if sourceWinNR != -1
  1001. " The buffer is visible in at least one window
  1002. let currentWinNR = winnr()
  1003. while winbufnr(sourceWinNR) != -1
  1004. if winbufnr(sourceWinNR) == s:vimDiffSourceBuffer
  1005. execute sourceWinNR . 'wincmd w'
  1006. if getwinvar('', "&diff")
  1007. execute s:vimDiffRestoreCmd
  1008. endif
  1009. endif
  1010. let sourceWinNR = sourceWinNR + 1
  1011. endwhile
  1012. execute currentWinNR . 'wincmd w'
  1013. else
  1014. " The buffer is hidden. It must be visible in order to set the
  1015. " diff option.
  1016. let currentBufNR = bufnr('')
  1017. execute "hide buffer" s:vimDiffSourceBuffer
  1018. if getwinvar('', "&diff")
  1019. execute s:vimDiffRestoreCmd
  1020. endif
  1021. execute "hide buffer" currentBufNR
  1022. endif
  1023. unlet s:vimDiffRestoreCmd
  1024. unlet s:vimDiffSourceBuffer
  1025. unlet s:vimDiffBufferCount
  1026. unlet s:vimDiffScratchList
  1027. elseif s:vimDiffBufferCount == 0
  1028. " All buffers are gone.
  1029. unlet s:vimDiffSourceBuffer
  1030. unlet s:vimDiffBufferCount
  1031. unlet s:vimDiffScratchList
  1032. endif
  1033. endif
  1034. endif
  1035. finally
  1036. let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
  1037. endtry
  1038. endfunction
  1039. augroup HGVimDiffRestore
  1040. au!
  1041. au BufUnload * call <SID>HGVimDiffRestore(expand("<abuf>"))
  1042. augroup END
  1043. " Section: Optional activation of buffer management {{{1
  1044. if s:HGGetOption('HGCommandEnableBufferSetup', 1)
  1045. call HGEnableBufferSetup()
  1046. endif
  1047. " Section: Doc installation {{{1
  1048. if <SID>HGInstallDocumentation(expand("<sfile>:p"))
  1049. echomsg s:script_name s:script_version . ": updated documentation"
  1050. endif
  1051. " Section: Plugin completion {{{1
  1052. " delete one-time vars and functions
  1053. delfunction <SID>HGInstallDocumentation
  1054. delfunction <SID>HGFlexiMkdir
  1055. delfunction <SID>HGCleanupOnFailure
  1056. unlet s:script_version s:script_name
  1057. let g:loaded_hgcommand=2
  1058. silent do HGCommand User HGPluginFinish
  1059. let &cpo = s:save_cpo
  1060. unlet s:save_cpo
  1061. " vim:se expandtab sts=2 sw=2:
  1062. finish
  1063. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  1064. " Section: Documentation content {{{1
  1065. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  1066. === START_DOC
  1067. *hgcommand.txt* Mercurial vim integration #version#
  1068. HGCOMMAND REFERENCE MANUAL~
  1069. Author: Mathieu Clabaut <mathieu.clabaut@gmail.com>
  1070. Credits: Bob Hiestand <bob.hiestand@gmail.com>
  1071. Mercurial: http://mercurial.selenic.com/
  1072. Mercurial (noted Hg) is a fast, lightweight Source Control Management
  1073. system designed for efficient handling of very large distributed projects.
  1074. ==============================================================================
  1075. 1. Contents *hgcommand-contents*
  1076. Installation : |hgcommand-install|
  1077. HGCommand Intro : |hgcommand|
  1078. HGCommand Manual : |hgcommand-manual|
  1079. Customization : |hgcommand-customize|
  1080. Bugs : |hgcommand-bugs|
  1081. ==============================================================================
  1082. 2. HGCommand Installation *hgcommand-install*
  1083. In order to install the plugin, place the hgcommand.vim file into a plugin'
  1084. directory in your runtime path (please see |add-global-plugin| and
  1085. |'runtimepath'|.
  1086. HGCommand may be customized by setting variables, creating maps, and
  1087. specifying event handlers. Please see |hgcommand-customize| for more
  1088. details.
  1089. *hgcommand-auto-help*
  1090. The help file is automagically generated when the |hgcommand| script is
  1091. loaded for the first time.
  1092. ==============================================================================
  1093. 3. HGCommand Intro *hgcommand*
  1094. *hgcommand-intro*
  1095. The HGCommand plugin provides global ex commands for manipulating
  1096. HG-controlled source files. In general, each command operates on the
  1097. current buffer and accomplishes a separate hg function, such as update,
  1098. commit, log, and others (please see |hgcommand-commands| for a list of all
  1099. available commands). The results of each operation are displayed in a
  1100. scratch buffer. Several buffer variables are defined for those scratch
  1101. buffers (please see |hgcommand-buffer-variables|).
  1102. The notion of "current file" means either the current buffer, or, in the
  1103. case of a directory buffer, the file on the current line within the buffer.
  1104. For convenience, any HGCommand invoked on a HGCommand scratch buffer acts
  1105. as though it was invoked on the original file and splits the screen so that
  1106. the output appears in a new window.
  1107. Many of the commands accept revisions as arguments. By default, most
  1108. operate on the most recent revision on the current branch if no revision is
  1109. specified (though see |HGCommandInteractive| to prompt instead).
  1110. Each HGCommand is mapped to a key sequence starting with the <Leader>
  1111. keystroke. The default mappings may be overridden by supplying different
  1112. mappings before the plugin is loaded, such as in the vimrc, in the standard
  1113. fashion for plugin mappings. For examples, please see
  1114. |hgcommand-mappings-override|.
  1115. The HGCommand plugin may be configured in several ways. For more details,
  1116. please see |hgcommand-customize|.
  1117. ==============================================================================
  1118. 4. HGCommand Manual *hgcommand-manual*
  1119. 4.1 HGCommand commands *hgcommand-commands*
  1120. HGCommand defines the following commands:
  1121. |:HGAdd|
  1122. |:HGAnnotate|
  1123. |:HGCommit|
  1124. |:HGDiff|
  1125. |:HGGotoOriginal|
  1126. |:HGLog|
  1127. |:HGRevert|
  1128. |:HGReview|
  1129. |:HGStatus|
  1130. |:HGUpdate|
  1131. |:HGVimDiff|
  1132. :HGAdd *:HGAdd*
  1133. This command performs "hg add" on the current file. Please note, this does
  1134. not commit the newly-added file.
  1135. :HGAnnotate *:HGAnnotate*
  1136. This command performs "hg annotate" on the current file. If an argument is
  1137. given, the argument is used as a revision number to display. If not given
  1138. an argument, it uses the most recent version of the file on the current
  1139. branch. Additionally, if the current buffer is a HGAnnotate buffer
  1140. already, the version number on the current line is used.
  1141. If the |HGCommandAnnotateParent| variable is set to a non-zero value, the
  1142. version previous to the one on the current line is used instead. This
  1143. allows one to navigate back to examine the previous version of a line.
  1144. The filetype of the HGCommand scratch buffer is set to 'HGAnnotate', to
  1145. take advantage of the bundled syntax file.
  1146. :HGCommit[!] *:HGCommit*
  1147. If called with arguments, this performs "hg commit" using the arguments as
  1148. the log message.
  1149. If '!' is used with no arguments, an empty log message is committed.
  1150. If called with no arguments, this is a two-step command. The first step
  1151. opens a buffer to accept a log message. When that buffer is written, it is
  1152. automatically closed and the file is committed using the information from
  1153. that log message. The commit can be abandoned if the log message buffer is
  1154. deleted or wiped before being written.
  1155. Alternatively, the mapping that is used to invoke :HGCommit (by default
  1156. <Leader>hgc) can be used in the log message buffer to immediately commit.
  1157. This is useful if the |HGCommandCommitOnWrite| variable is set to 0 to
  1158. disable the normal commit-on-write behavior.
  1159. :HGDiff *:HGDiff*
  1160. With no arguments, this performs "hg diff" on the current file against the
  1161. current repository version.
  1162. With one argument, "hg diff" is performed on the current file against the
  1163. specified revision.
  1164. With two arguments, hg diff is performed between the specified revisions of
  1165. the current file.
  1166. This command uses the 'HGCommandDiffOpt' variable to specify diff options.
  1167. If that variable does not exist, then 'wbBc' is assumed. If you wish to
  1168. have no options, then set it to the empty string.
  1169. :HGGotoOriginal *:HGGotoOriginal*
  1170. This command returns the current window to the source buffer, if the
  1171. current buffer is a HG command output buffer.
  1172. :HGGotoOriginal!
  1173. Like ":HGGotoOriginal" but also executes :bufwipeout on all HG command
  1174. output buffers for the source buffer.
  1175. :HGLog *:HGLog*
  1176. Performs "hg log" on the current file.
  1177. If an argument is given, it is passed as an argument to the "-r" option of
  1178. "hg log".
  1179. :HGRevert *:HGRevert*
  1180. Replaces the current file with the most recent version from the repository
  1181. in order to wipe out any undesired changes.
  1182. :HGReview *:HGReview*
  1183. Retrieves a particular version of the current file. If no argument is
  1184. given, the most recent version of the file on the current branch is
  1185. retrieved. Otherwise, the specified version is retrieved.
  1186. :HGStatus *:HGStatus*
  1187. Performs "hg status" on the current file.
  1188. :HGUpdate *:HGUpdate*
  1189. Performs "hg update" on the current file. This intentionally does not
  1190. automatically reload the current buffer, though vim should prompt the user
  1191. to do so if the underlying file is altered by this command.
  1192. :HGVimDiff *:HGVimDiff*
  1193. With no arguments, this prompts the user for a revision and then uses
  1194. vimdiff to display the differences between the current file and the
  1195. specified revision. If no revision is specified, the most recent version
  1196. of the file on the current branch is used.
  1197. With one argument, that argument is used as the revision as above. With
  1198. two arguments, the differences between the two revisions is displayed using
  1199. vimdiff.
  1200. With either zero or one argument, the original buffer is used to perform
  1201. the vimdiff. When the other buffer is closed, the original buffer will be
  1202. returned to normal mode.
  1203. Once vimdiff mode is started using the above methods, additional vimdiff
  1204. buffers may be added by passing a single version argument to the command.
  1205. There may be up to 4 vimdiff buffers total.
  1206. Using the 2-argument form of the command resets the vimdiff to only those 2
  1207. versions. Additionally, invoking the command on a different file will
  1208. close the previous vimdiff buffers.
  1209. 4.2 Mappings *hgcommand-mappings*
  1210. By default, a mapping is defined for each command. These mappings execute
  1211. the default (no-argument) form of each command.
  1212. <Leader>hga HGAdd
  1213. <Leader>hgn HGAnnotate
  1214. <Leader>hgc HGCommit
  1215. <Leader>hgd HGDiff
  1216. <Leader>hgg HGGotoOriginal
  1217. <Leader>hgG HGGotoOriginal!
  1218. <Leader>hgl HGLog
  1219. <Leader>hgr HGReview
  1220. <Leader>hgs HGStatus
  1221. <Leader>hgu HGUpdate
  1222. <Leader>hgv HGVimDiff
  1223. *hgcommand-mappings-override*
  1224. The default mappings can be overridden by user-provided instead by mapping
  1225. to <Plug>CommandName. This is especially useful when these mappings
  1226. collide with other existing mappings (vim will warn of this during plugin
  1227. initialization, but will not clobber the existing mappings).
  1228. For instance, to override the default mapping for :HGAdd to set it to
  1229. '\add', add the following to the vimrc: >
  1230. nmap \add <Plug>HGAdd
  1231. <
  1232. 4.3 Automatic buffer variables *hgcommand-buffer-variables*
  1233. Several buffer variables are defined in each HGCommand result buffer.
  1234. These may be useful for additional customization in callbacks defined in
  1235. the event handlers (please see |hgcommand-events|).
  1236. The following variables are automatically defined:
  1237. b:hgOrigBuffNR *b:hgOrigBuffNR*
  1238. This variable is set to the buffer number of the source file.
  1239. b:hgcmd *b:hgcmd*
  1240. This variable is set to the name of the hg command that created the result
  1241. buffer.
  1242. ==============================================================================
  1243. 5. Configuration and customization *hgcommand-customize*
  1244. *hgcommand-config*
  1245. The HGCommand plugin can be configured in two ways: by setting
  1246. configuration variables (see |hgcommand-options|) or by defining HGCommand
  1247. event handlers (see |hgcommand-events|). Additionally, the HGCommand
  1248. plugin provides several option for naming the HG result buffers (see
  1249. |hgcommand-naming|) and supported a customized status line (see
  1250. |hgcommand-statusline| and |hgcommand-buffer-management|).
  1251. 5.1 HGCommand configuration variables *hgcommand-options*
  1252. Several variables affect the plugin's behavior. These variables are
  1253. checked at time of execution, and may be defined at the window, buffer, or
  1254. global level and are checked in that order of precedence.
  1255. The following variables are available:
  1256. |HGCommandAnnotateParent|
  1257. |HGCommandCommitOnWrite|
  1258. |HGCommandHGExec|
  1259. |HGCommandDeleteOnHide|
  1260. |HGCommandDiffOpt|
  1261. |HGCommandDiffSplit|
  1262. |HGCommandEdit|
  1263. |HGCommandEnableBufferSetup|
  1264. |HGCommandInteractive|
  1265. |HGCommandNameMarker|
  1266. |HGCommandNameResultBuffers|
  1267. |HGCommandSplit|
  1268. HGCommandAnnotateParent *HGCommandAnnotateParent*
  1269. This variable, if set to a non-zero value, causes the zero-argument form of
  1270. HGAnnotate when invoked on a HGAnnotate buffer to go to the version
  1271. previous to that displayed on the current line. If not set, it defaults to
  1272. 0.
  1273. HGCommandCommitOnWrite

Large files files are truncated, but you can click here to view the full file