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