hgcommand.vim: requirements & doc self-install more consistent; cosmetics
authorChristian Ebert <blacktrash@gmx.net>
Wed, 02 Aug 2006 00:20:28 +0200
changeset 2759 19436facb073
parent 2758 c9359142cba3
child 2760 e6bef16b6cec
hgcommand.vim: requirements & doc self-install more consistent; cosmetics Check for availability of builtin system(). Set 'compatible' while sourcing script. File operation during doc self-install: Escape spaces in ex-commands. Use quotes in system calls. Incremented revision number(s). Size of patch is due to cosmetic cleanups: Removal of spaces at line endings. <SID>Prefix to functions when called.
contrib/vim/hgcommand.vim
--- a/contrib/vim/hgcommand.vim	Tue Aug 01 15:40:54 2006 -0700
+++ b/contrib/vim/hgcommand.vim	Wed Aug 02 00:20:28 2006 +0200
@@ -3,7 +3,7 @@
 " Vim plugin to assist in working with HG-controlled files.
 "
 " Last Change:   2006/02/22
-" Version:       1.76
+" Version:       1.77
 " Maintainer:    Mathieu Clabaut <mathieu.clabaut@gmail.com>
 " License:       This file is placed in the public domain.
 " Credits:
@@ -13,7 +13,7 @@
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 "
-" Section: Documentation 
+" Section: Documentation
 "----------------------------
 "
 " Documentation should be available by ":help hgcommand" command, once the
@@ -21,7 +21,7 @@
 "
 " You still can read the documentation at the end of this file. Locate it by
 " searching the "hgcommand-contents" string (and set ft=help to have
-" appropriate syntaxic coloration). 
+" appropriate syntaxic coloration).
 
 " Section: Plugin header {{{1
 
@@ -34,11 +34,33 @@
 endif
 let loaded_hgcommand = 1
 
+" store 'compatible' settings
+let s:save_cpo = &cpo
+set cpo&vim
+
+" run checks
+let s:script_name = expand("<sfile>:t:r")
+
+function! s:HGCleanupOnFailure(err)
+  echohl WarningMsg
+  echomsg s:script_name . ":" a:err "Plugin not loaded"
+  echohl None
+  let loaded_hgcommand = "no"
+  unlet s:save_cpo s:script_name
+endfunction
+
 if v:version < 602
-  echohl WarningMsg|echomsg "HGCommand 1.69 or later requires VIM 6.2 or later"|echohl None
+  call <SID>HGCleanupOnFailure("VIM 6.2 or later required.")
   finish
 endif
 
+if !exists("*system")
+  call <SID>HGCleanupOnFailure("builtin system() function required.")
+  finish
+endif
+
+let s:script_version = "v0.2"
+
 " Section: Event group setup {{{1
 
 augroup HGCommand
@@ -63,7 +85,7 @@
 function! s:HGResolveLink(fileName)
   let resolved = resolve(a:fileName)
   if resolved != a:fileName
-    let resolved = s:HGResolveLink(resolved)
+    let resolved = <SID>HGResolveLink(resolved)
   endif
   return resolved
 endfunction
@@ -74,7 +96,7 @@
 
 function! s:HGChangeToCurrentFileDir(fileName)
   let oldCwd=getcwd()
-  let fileName=s:HGResolveLink(a:fileName)
+  let fileName=<SID>HGResolveLink(a:fileName)
   let newCwd=fnamemodify(fileName, ':h')
   if strlen(newCwd) > 0
     execute 'cd' escape(newCwd, ' ')
@@ -82,7 +104,7 @@
   return oldCwd
 endfunction
 
-" Function: s:HGGetOption(name, default) {{{2
+" Function: <SID>HGGetOption(name, default) {{{2
 " Grab a user-specified option to override the default provided.  Options are
 " searched in the window, buffer, then global spaces.
 
@@ -110,9 +132,9 @@
   "Name parameter will be pasted into expression.
   let name = escape(a:name, ' *?\')
 
-  let editCommand = s:HGGetOption('HGCommandEdit', 'edit')
+  let editCommand = <SID>HGGetOption('HGCommandEdit', 'edit')
   if editCommand != 'edit'
-    if s:HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
+    if <SID>HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
       if name == ""
         let editCommand = 'rightbelow new'
       else
@@ -154,8 +176,8 @@
 
   let resultBufferName=''
 
-  if s:HGGetOption("HGCommandNameResultBuffers", 0)
-    let nameMarker = s:HGGetOption("HGCommandNameMarker", '_')
+  if <SID>HGGetOption("HGCommandNameResultBuffers", 0)
+    let nameMarker = <SID>HGGetOption("HGCommandNameMarker", '_')
     if strlen(a:statusText) > 0
       let bufName=a:cmdName . ' -- ' . a:statusText
     else
@@ -170,7 +192,7 @@
     endwhile
   endif
 
-  let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
+  let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
   "echomsg "DBG :".hgCommand
   let hgOut = system(hgCommand)
   " HACK:  diff command does not return proper error codes
@@ -192,7 +214,7 @@
     return -1
   endif
 
-  if s:HGEditFile(resultBufferName, a:origBuffNR) == -1
+  if <SID>HGEditFile(resultBufferName, a:origBuffNR) == -1
     return -1
   endif
 
@@ -200,7 +222,7 @@
   set noswapfile
   set filetype=
 
-  if s:HGGetOption("HGCommandDeleteOnHide", 0)
+  if <SID>HGGetOption("HGCommandDeleteOnHide", 0)
     set bufhidden=delete
   endif
 
@@ -213,8 +235,8 @@
   " This could be fixed by explicitly detecting whether the last line is
   " within a fold, but I prefer to simply unfold the result buffer altogether.
 
-  if has('folding')
-    normal zR
+  if has("folding")
+    setlocal nofoldenable
   endif
 
   $d
@@ -243,7 +265,7 @@
       return origBuffer
     else
       " Original buffer no longer exists.
-      return -1 
+      return -1
     endif
   else
     " No original buffer
@@ -256,7 +278,7 @@
 " for the current buffer.
 
 function! s:HGCurrentBufferCheck()
-  return s:HGBufferCheck(bufnr("%"))
+  return <SID>HGBufferCheck(bufnr("%"))
 endfunction
 
 " Function: s:HGToggleDeleteOnHide() {{{2
@@ -275,8 +297,8 @@
 " Returns: name of the new command buffer containing the command results
 
 function! s:HGDoCommand(cmd, cmdName, statusText)
-  let hgBufferCheck=s:HGCurrentBufferCheck()
-  if hgBufferCheck == -1 
+  let hgBufferCheck=<SID>HGCurrentBufferCheck()
+  if hgBufferCheck == -1
     echo "Original buffer no longer exists, aborting."
     return -1
   endif
@@ -285,8 +307,8 @@
   if isdirectory(fileName)
     let fileName=fileName . "/" . getline(".")
   endif
-  let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t')
-  let oldCwd=s:HGChangeToCurrentFileDir(fileName)
+  let realFileName = fnamemodify(<SID>HGResolveLink(fileName), ':t')
+  let oldCwd=<SID>HGChangeToCurrentFileDir(fileName)
   try
      " TODO
     "if !filereadable('HG/Root')
@@ -294,7 +316,7 @@
     "endif
     let fullCmd = a:cmd . ' "' . realFileName . '"'
     "echomsg "DEBUG".fullCmd
-    let resultBuffer=s:HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
+    let resultBuffer=<SID>HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
     return resultBuffer
   catch
     echoerr v:exception
@@ -314,17 +336,17 @@
 " Returns: string to be exec'd that sets the multiple return values.
 
 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
-  let hgBufferCheck=s:HGCurrentBufferCheck()
+  let hgBufferCheck=<SID>HGCurrentBufferCheck()
   "echomsg "DBG : in HGGetStatusVars"
-  if hgBufferCheck == -1 
+  if hgBufferCheck == -1
     return ""
   endif
   let fileName=bufname(hgBufferCheck)
-  let fileNameWithoutLink=s:HGResolveLink(fileName)
+  let fileNameWithoutLink=<SID>HGResolveLink(fileName)
   let realFileName = fnamemodify(fileNameWithoutLink, ':t')
-  let oldCwd=s:HGChangeToCurrentFileDir(realFileName)
+  let oldCwd=<SID>HGChangeToCurrentFileDir(realFileName)
   try
-    let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " root  " 
+    let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " root  "
     let roottext=system(hgCommand)
     " Suppress ending null char ! Does it work in window ?
     let roottext=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
@@ -335,22 +357,22 @@
     if a:repositoryVar != ""
       let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . roottext . "'"
     endif
-    let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . realFileName
+    let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . realFileName
     let statustext=system(hgCommand)
     if(v:shell_error)
       return ""
     endif
-    if match(statustext, '^[?I]') >= 0 
+    if match(statustext, '^[?I]') >= 0
       let revision="NEW"
-    elseif match(statustext, '^[R]') >= 0 
+    elseif match(statustext, '^[R]') >= 0
       let revision="REMOVED"
-    elseif match(statustext, '^[D]') >= 0 
+    elseif match(statustext, '^[D]') >= 0
       let revision="DELETED"
-    elseif match(statustext, '^[A]') >= 0 
+    elseif match(statustext, '^[A]') >= 0
       let revision="ADDED"
     else
       " The file is tracked, we can try to get is revision number
-      let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b  " 
+      let hgCommand = <SID>HGGetOption("HGCommandHGExec", "hg") . " parents -b  "
       let statustext=system(hgCommand)
       if(v:shell_error)
           return ""
@@ -381,7 +403,7 @@
     return
   endif
 
-  if !s:HGGetOption("HGCommandEnableBufferSetup", 0)
+  if !<SID>HGGetOption("HGCommandEnableBufferSetup", 0)
         \ || @% == ""
         \ || s:HGCommandEditFileRunning > 0
         \ || exists("b:HGOrigBuffNR")
@@ -399,7 +421,7 @@
   let branch=""
   let repository=""
 
-  exec s:HGGetStatusVars('revision', 'branch', 'repository')
+  exec <SID>HGGetStatusVars('revision', 'branch', 'repository')
   "echomsg "DBG ".revision."#".branch."#".repository
   if revision != ""
     let b:HGRevision=revision
@@ -427,7 +449,7 @@
 function! s:HGMarkOrigBufferForSetup(hgBuffer)
   checktime
   if a:hgBuffer != -1
-    let origBuffer = s:HGBufferCheck(a:hgBuffer)
+    let origBuffer = <SID>HGBufferCheck(a:hgBuffer)
     "This should never not work, but I'm paranoid
     if origBuffer != a:hgBuffer
       call setbufvar(origBuffer, "HGBufferSetup", 0)
@@ -436,7 +458,7 @@
     "We are presumably in the original buffer
     let b:HGBufferSetup = 0
     "We do the setup now as now event will be triggered allowing it later.
-    call s:HGSetupBuffer()
+    call <SID>HGSetupBuffer()
   endif
   return a:hgBuffer
 endfunction
@@ -483,11 +505,12 @@
   if exists("*mkdir") " we can use Vim's own mkdir()
     call mkdir(a:dir)
   elseif !exists("+shellslash")
-    call system('mkdir -p "'.a:dir.'"')
+    call system("mkdir -p '".a:dir."'")
   else " M$
     let l:ssl = &shellslash
     try
       set shellslash
+      " no single quotes?
       call system('mkdir "'.a:dir.'"')
     finally
       let &shellslash = l:ssl
@@ -495,19 +518,18 @@
   endif
 endfunction
 
-function! s:HGInstallDocumentation(full_name, revision)
+function! s:HGInstallDocumentation(full_name)
   " Figure out document path based on full name of this script:
-  let l:vim_plugin_path = fnamemodify(a:full_name, ':h')
-  let l:vim_doc_path  = fnamemodify(a:full_name, ':h:h') . "/doc"
+  let l:vim_doc_path = fnamemodify(a:full_name, ":h:h") . "/doc"
   if filewritable(l:vim_doc_path) != 2
-    echomsg "hgcommand: Trying to update docs at: " . l:vim_doc_path
+    echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
     silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
     if filewritable(l:vim_doc_path) != 2
       " Try first item in 'runtimepath':
-      let l:vimfiles = matchstr(&runtimepath, '[^,]\+\ze,')
-      let l:vim_doc_path = l:vimfiles . "/doc"
+      let l:vim_doc_path =
+            \ substitute(&runtimepath, '^\([^,]*\).*', '\1/doc', 'e')
       if filewritable(l:vim_doc_path) != 2
-        echomsg "hgcommand: Trying to update docs at: " . l:vim_doc_path
+        echomsg s:script_name . ": Trying to update docs at" l:vim_doc_path
         silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
         if filewritable(l:vim_doc_path) != 2
           " Put a warning:
@@ -519,54 +541,51 @@
     endif
   endif
 
-  " Full name of script and documentation file:
-  let l:script_name = fnamemodify(a:full_name, ':t')
-  let l:doc_name  = fnamemodify(a:full_name, ':t:r') . '.txt'
-  let l:doc_file  = l:vim_doc_path . "/" . l:doc_name
-
+  " Full name of documentation file:
+  let l:doc_file =
+        \ l:vim_doc_path . "/" . s:script_name . ".txt"
   " Bail out if document file is still up to date:
-  if filereadable(l:doc_file)  && getftime(a:full_name) < getftime(l:doc_file)
+  if filereadable(l:doc_file)  &&
+        \ getftime(a:full_name) < getftime(l:doc_file)
     return 0
   endif
 
+  " temporary global settings
+  let l:lz = &lazyredraw
+  let l:hls = &hlsearch
+  set lazyredraw nohlsearch
   " Create a new buffer & read in the plugin file (me):
-  setl nomodeline
-  1 new!
-  setl noswapfile modifiable
-  sil exe 'read ' . a:full_name
+  1 new
+  setlocal noswapfile modifiable nomodeline
+  if has("folding")
+    setlocal nofoldenable
+  endif
+  silent execute "read" escape(a:full_name, " ")
+  let l:doc_buf = bufnr("%")
 
-  setl modeline
-  let l:buf = bufnr("%")
-
-  norm zR
-  norm gg
-
+  1
   " Delete from first line to a line starts with
   " === START_DOC
-  sil 1,/^=\{3,}\s\+START_DOC\C/ d
-
+  silent 1,/^=\{3,}\s\+START_DOC\C/ d
   " Delete from a line starts with
   " === END_DOC
   " to the end of the documents:
-  sil /^=\{3,}\s\+END_DOC\C/,$ d
-
-  " Remove fold marks:
-  sil %s/{\{3}[1-9]/  /e
+  silent /^=\{3,}\s\+END_DOC\C/,$ d
 
   " Add modeline for help doc: the modeline string is mangled intentionally
   " to avoid it be recognized by VIM:
-  call append(line('$'), '')
-  call append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:')
+  call append(line("$"), "")
+  call append(line("$"), " v" . "im:tw=78:ts=8:ft=help:norl:")
 
   " Replace revision:
-  sil exe "normal :1s/#version#/ v" . a:revision . "/\<CR>"
-
+  silent execute "normal :1s/#version#/" . s:script_version . "/\<CR>"
   " Save the help document and wipe out buffer:
-  sil exe 'wq! ' . l:doc_file . ' | bw ' . l:buf
-
+  silent execute "wq!" escape(l:doc_file, " ") "| bw" l:doc_buf
   " Build help tags:
-  sil exe 'helptags ' . l:vim_doc_path
+  silent execute "helptags" l:vim_doc_path
 
+  let &hlsearch = l:hls
+  let &lazyredraw = l:lz
   return 1
 endfunction
 
@@ -578,7 +597,7 @@
 
 function! HGGetRevision()
   let revision=""
-  exec s:HGGetStatusVars('revision', '', '')
+  exec <SID>HGGetStatusVars('revision', '', '')
   return revision
 endfunction
 
@@ -597,16 +616,16 @@
   let g:HGCommandEnableBufferSetup=1
   augroup HGCommandPlugin
     au!
-    au BufEnter * call s:HGSetupBuffer()
-    au BufWritePost * call s:HGSetupBuffer()
+    au BufEnter * call <SID>HGSetupBuffer()
+    au BufWritePost * call <SID>HGSetupBuffer()
     " Force resetting up buffer on external file change (HG update)
-    au FileChangedShell * call s:HGSetupBuffer(1)
+    au FileChangedShell * call <SID>HGSetupBuffer(1)
   augroup END
 
   " Only auto-load if the plugin is fully loaded.  This gives other plugins a
   " chance to run.
   if g:loaded_hgcommand == 2
-    call s:HGSetupBuffer()
+    call <SID>HGSetupBuffer()
   endif
 endfunction
 
@@ -647,7 +666,7 @@
 
 " Function: s:HGAdd() {{{2
 function! s:HGAdd()
-  return s:HGMarkOrigBufferForSetup(s:HGDoCommand('add', 'hgadd', ''))
+  return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('add', 'hgadd', ''))
 endfunction
 
 " Function: s:HGAnnotate(...) {{{2
@@ -657,7 +676,7 @@
       " This is a HGAnnotate buffer.  Perform annotation of the version
       " indicated by the current line.
       let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','')
-      if s:HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
+      if <SID>HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
         let revision = revision - 1
       endif
     else
@@ -676,7 +695,7 @@
     return -1
   endif
 
-  let resultBuffer=s:HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision) 
+  let resultBuffer=<SID>HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision)
   "echomsg "DBG: ".resultBuffer
   if resultBuffer !=  -1
     set filetype=HGAnnotate
@@ -691,10 +710,10 @@
   " is used; if bang is supplied, an empty message is used; otherwise, the
   " user is provided a buffer from which to edit the commit message.
   if a:2 != "" || a:1 == "!"
-    return s:HGMarkOrigBufferForSetup(s:HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
+    return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
   endif
 
-  let hgBufferCheck=s:HGCurrentBufferCheck()
+  let hgBufferCheck=<SID>HGCurrentBufferCheck()
   if hgBufferCheck ==  -1
     echo "Original buffer no longer exists, aborting."
     return -1
@@ -710,7 +729,7 @@
     let messageFileName = tempname()
 
     let fileName=bufname(hgBufferCheck)
-    let realFilePath=s:HGResolveLink(fileName)
+    let realFilePath=<SID>HGResolveLink(fileName)
     let newCwd=fnamemodify(realFilePath, ':h')
     if strlen(newCwd) == 0
       " Account for autochdir being in effect, which will make this blank, but
@@ -720,7 +739,7 @@
 
     let realFileName=fnamemodify(realFilePath, ':t')
 
-    if s:HGEditFile(messageFileName, hgBufferCheck) == -1
+    if <SID>HGEditFile(messageFileName, hgBufferCheck) == -1
       return
     endif
 
@@ -751,9 +770,9 @@
     silent put =\"HG: Enter Log.  Lines beginning with `HG:' are removed automatically\"
     silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
 
-    if s:HGGetOption('HGCommandCommitOnWrite', 1) == 1
+    if <SID>HGGetOption('HGCommandCommitOnWrite', 1) == 1
       execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d'
-      execute 'au HGCommit BufWritePost' autoPattern 'call s:HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
+      execute 'au HGCommit BufWritePost' autoPattern 'call <SID>HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
       silent put ='HG: or write this buffer'
     endif
 
@@ -782,7 +801,7 @@
     let caption = ''
   endif
 
-  let hgdiffopt=s:HGGetOption('HGCommandDiffOpt', 'w')
+  let hgdiffopt=<SID>HGGetOption('HGCommandDiffOpt', 'w')
 
   if hgdiffopt == ""
     let diffoptionstring=""
@@ -790,8 +809,8 @@
     let diffoptionstring=" -" . hgdiffopt . " "
   endif
 
-  let resultBuffer = s:HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
-  if resultBuffer != -1 
+  let resultBuffer = <SID>HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
+  if resultBuffer != -1
     set filetype=diff
   endif
   return resultBuffer
@@ -800,7 +819,7 @@
 
 " Function: s:HGGotoOriginal(["!]) {{{2
 function! s:HGGotoOriginal(...)
-  let origBuffNR = s:HGCurrentBufferCheck()
+  let origBuffNR = <SID>HGCurrentBufferCheck()
   if origBuffNR > 0
     let origWinNR = bufwinnr(origBuffNR)
     if origWinNR == -1
@@ -830,11 +849,11 @@
     if strlen(a:targetDir) > 0
       execute 'cd' escape(a:targetDir, ' ')
     endif
-    let resultBuffer=s:HGCreateCommandBuffer('commit -l "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
+    let resultBuffer=<SID>HGCreateCommandBuffer('commit -l "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
     execute 'cd' escape(oldCwd, ' ')
     execute 'bw' escape(a:messageFile, ' *?\')
     silent execute 'call delete("' . a:messageFile . '")'
-    return s:HGMarkOrigBufferForSetup(resultBuffer)
+    return <SID>HGMarkOrigBufferForSetup(resultBuffer)
   else
     echoerr "Can't read message file; no commit is possible."
     return -1
@@ -851,7 +870,7 @@
     let caption = a:1
   endif
 
-  let resultBuffer=s:HGDoCommand('log' . versionOption, 'hglog', caption)
+  let resultBuffer=<SID>HGDoCommand('log' . versionOption, 'hglog', caption)
   if resultBuffer != ""
     set filetype=rcslog
   endif
@@ -860,14 +879,14 @@
 
 " Function: s:HGRevert() {{{2
 function! s:HGRevert()
-  return s:HGMarkOrigBufferForSetup(s:HGDoCommand('revert', 'hgrevert', ''))
+  return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('revert', 'hgrevert', ''))
 endfunction
 
 " Function: s:HGReview(...) {{{2
 function! s:HGReview(...)
   if a:0 == 0
     let versiontag=""
-    if s:HGGetOption('HGCommandInteractive', 0)
+    if <SID>HGGetOption('HGCommandInteractive', 0)
       let versiontag=input('Revision:  ')
     endif
     if versiontag == ""
@@ -881,7 +900,7 @@
     let versionOption=" -r " . versiontag . " "
   endif
 
-  let resultBuffer = s:HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
+  let resultBuffer = <SID>HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
   if resultBuffer > 0
     let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype')
   endif
@@ -891,18 +910,18 @@
 
 " Function: s:HGStatus() {{{2
 function! s:HGStatus()
-  return s:HGDoCommand('status', 'hgstatus', '')
+  return <SID>HGDoCommand('status', 'hgstatus', '')
 endfunction
 
 
 " Function: s:HGUpdate() {{{2
 function! s:HGUpdate()
-  return s:HGMarkOrigBufferForSetup(s:HGDoCommand('update', 'update', ''))
+  return <SID>HGMarkOrigBufferForSetup(<SID>HGDoCommand('update', 'update', ''))
 endfunction
 
 " Function: s:HGVimDiff(...) {{{2
 function! s:HGVimDiff(...)
-  let originalBuffer = s:HGCurrentBufferCheck()
+  let originalBuffer = <SID>HGCurrentBufferCheck()
   let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
   try
     " If there's already a VimDiff'ed window, restore it.
@@ -910,16 +929,16 @@
 
     if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
       " Clear the existing vimdiff setup by removing the result buffers.
-      call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
+      call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
     endif
 
     " Split and diff
     if(a:0 == 2)
       " Reset the vimdiff system, as 2 explicit versions were provided.
       if exists('s:vimDiffSourceBuffer')
-        call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
+        call <SID>HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
       endif
-      let resultBuffer = s:HGReview(a:1)
+      let resultBuffer = <SID>HGReview(a:1)
       if resultBuffer < 0
         echomsg "Can't open HG revision " . a:1
         return resultBuffer
@@ -930,10 +949,10 @@
       let s:vimDiffScratchList = '{'. resultBuffer . '}'
       " If no split method is defined, cheat, and set it to vertical.
       try
-        call s:HGOverrideOption('HGCommandSplit', s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
-        let resultBuffer=s:HGReview(a:2)
+        call <SID>HGOverrideOption('HGCommandSplit', <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
+        let resultBuffer=<SID>HGReview(a:2)
       finally
-        call s:HGOverrideOption('HGCommandSplit')
+        call <SID>HGOverrideOption('HGCommandSplit')
       endtry
       if resultBuffer < 0
         echomsg "Can't open HG revision " . a:1
@@ -947,16 +966,16 @@
       " Add new buffer
       try
         " Force splitting behavior, otherwise why use vimdiff?
-        call s:HGOverrideOption("HGCommandEdit", "split")
-        call s:HGOverrideOption("HGCommandSplit", s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
+        call <SID>HGOverrideOption("HGCommandEdit", "split")
+        call <SID>HGOverrideOption("HGCommandSplit", <SID>HGGetOption('HGCommandDiffSplit', <SID>HGGetOption('HGCommandSplit', 'vertical')))
         if(a:0 == 0)
-          let resultBuffer=s:HGReview()
+          let resultBuffer=<SID>HGReview()
         else
-          let resultBuffer=s:HGReview(a:1)
+          let resultBuffer=<SID>HGReview(a:1)
         endif
       finally
-        call s:HGOverrideOption("HGCommandEdit")
-        call s:HGOverrideOption("HGCommandSplit")
+        call <SID>HGOverrideOption("HGCommandEdit")
+        call <SID>HGOverrideOption("HGCommandSplit")
       endtry
       if resultBuffer < 0
         echomsg "Can't open current HG revision"
@@ -975,14 +994,14 @@
         wincmd W
         execute 'buffer' originalBuffer
         " Store info for later original buffer restore
-        let s:vimDiffRestoreCmd = 
+        let s:vimDiffRestoreCmd =
               \    "call setbufvar(".originalBuffer.", \"&diff\", ".getbufvar(originalBuffer, '&diff').")"
               \ . "|call setbufvar(".originalBuffer.", \"&foldcolumn\", ".getbufvar(originalBuffer, '&foldcolumn').")"
               \ . "|call setbufvar(".originalBuffer.", \"&foldenable\", ".getbufvar(originalBuffer, '&foldenable').")"
               \ . "|call setbufvar(".originalBuffer.", \"&foldmethod\", '".getbufvar(originalBuffer, '&foldmethod')."')"
               \ . "|call setbufvar(".originalBuffer.", \"&scrollbind\", ".getbufvar(originalBuffer, '&scrollbind').")"
               \ . "|call setbufvar(".originalBuffer.", \"&wrap\", ".getbufvar(originalBuffer, '&wrap').")"
-              \ . "|if &foldmethod=='manual'|execute 'normal zE'|endif"
+              \ . "|if &foldmethod=='manual'|execute 'normal! zE'|endif"
         diffthis
         wincmd w
       else
@@ -1012,17 +1031,17 @@
 
 " Section: Command definitions {{{1
 " Section: Primary commands {{{2
-com! HGAdd call s:HGAdd()
-com! -nargs=? HGAnnotate call s:HGAnnotate(<f-args>)
-com! -bang -nargs=? HGCommit call s:HGCommit(<q-bang>, <q-args>)
-com! -nargs=* HGDiff call s:HGDiff(<f-args>)
-com! -bang HGGotoOriginal call s:HGGotoOriginal(<q-bang>)
-com! -nargs=? HGLog call s:HGLog(<f-args>)
-com! HGRevert call s:HGRevert()
-com! -nargs=? HGReview call s:HGReview(<f-args>)
-com! HGStatus call s:HGStatus()
-com! HGUpdate call s:HGUpdate()
-com! -nargs=* HGVimDiff call s:HGVimDiff(<f-args>)
+com! HGAdd call <SID>HGAdd()
+com! -nargs=? HGAnnotate call <SID>HGAnnotate(<f-args>)
+com! -bang -nargs=? HGCommit call <SID>HGCommit(<q-bang>, <q-args>)
+com! -nargs=* HGDiff call <SID>HGDiff(<f-args>)
+com! -bang HGGotoOriginal call <SID>HGGotoOriginal(<q-bang>)
+com! -nargs=? HGLog call <SID>HGLog(<f-args>)
+com! HGRevert call <SID>HGRevert()
+com! -nargs=? HGReview call <SID>HGReview(<f-args>)
+com! HGStatus call <SID>HGStatus()
+com! HGUpdate call <SID>HGUpdate()
+com! -nargs=* HGVimDiff call <SID>HGVimDiff(<f-args>)
 
 " Section: HG buffer management commands {{{2
 com! HGDisableBufferSetup call HGDisableBufferSetup()
@@ -1158,7 +1177,7 @@
 
 augroup HGVimDiffRestore
   au!
-  au BufUnload * call s:HGVimDiffRestore(expand("<abuf>"))
+  au BufUnload * call <SID>HGVimDiffRestore(expand("<abuf>"))
 augroup END
 
 " Section: Optional activation of buffer management {{{1
@@ -1168,23 +1187,24 @@
 endif
 
 " Section: Doc installation {{{1
-"
-  let s:revision="0.1"
-  if s:HGInstallDocumentation(escape(expand('<sfile>:p'), ' '), s:revision)
-      echom expand('<sfile>:t:r') . ' v' . s:revision .
-                \ ': Help-documentation installed.'
-  endif
 
-  " delete one-time vars and functions
-  delfunction <SID>HGInstallDocumentation
-  delfunction <SID>HGFlexiMkdir
-  unlet s:revision
-
+if <SID>HGInstallDocumentation(expand("<sfile>:p"))
+  echomsg s:script_name s:script_version . ": updated documentation"
+endif
 
 " Section: Plugin completion {{{1
 
+" delete one-time vars and functions
+delfunction <SID>HGInstallDocumentation
+delfunction <SID>HGFlexiMkdir
+delfunction <SID>HGCleanupOnFailure
+unlet s:script_version s:script_name
+
 let loaded_hgcommand=2
 silent do HGCommand User HGPluginFinish
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
 " vim:se expandtab sts=2 sw=2:
 finish
 
@@ -1216,16 +1236,16 @@
 ==============================================================================
 2. HGCommand Installation				   *hgcommand-install*
 
-   In order to install the plugin, place the hgcommand.vim file into a plugin' 
-   directory in your runtime path (please see |add-global-plugin| and 
+   In order to install the plugin, place the hgcommand.vim file into a plugin'
+   directory in your runtime path (please see |add-global-plugin| and
    |'runtimepath'|.
 
-   HGCommand may be customized by setting variables, creating maps, and 
+   HGCommand may be customized by setting variables, creating maps, and
    specifying event handlers.  Please see |hgcommand-customize| for more
    details.
 
                                                          *hgcommand-auto-help*
-   The help file is automagically generated when the |hgcommand| script is 
+   The help file is automagically generated when the |hgcommand| script is
    loaded for the first time.
 
 ==============================================================================
@@ -1233,32 +1253,32 @@
 3. HGCommand Intro					           *hgcommand*
                                                              *hgcommand-intro*
 
-   The HGCommand plugin provides global ex commands for manipulating 
-   HG-controlled source files.  In general, each command operates on the 
-   current buffer and accomplishes a separate hg function, such as update, 
+   The HGCommand plugin provides global ex commands for manipulating
+   HG-controlled source files.  In general, each command operates on the
+   current buffer and accomplishes a separate hg function, such as update,
    commit, log, and others (please see |hgcommand-commands| for a list of all
-   available commands).  The results of each operation are displayed in a 
-   scratch buffer.  Several buffer variables are defined for those scratch 
+   available commands).  The results of each operation are displayed in a
+   scratch buffer.  Several buffer variables are defined for those scratch
    buffers (please see |hgcommand-buffer-variables|).
 
-   The notion of "current file" means either the current buffer, or, in the 
+   The notion of "current file" means either the current buffer, or, in the
    case of a directory buffer, the file on the current line within the buffer.
 
-   For convenience, any HGCommand invoked on a HGCommand scratch buffer acts 
-   as though it was invoked on the original file and splits the screen so that 
+   For convenience, any HGCommand invoked on a HGCommand scratch buffer acts
+   as though it was invoked on the original file and splits the screen so that
    the output appears in a new window.
 
-   Many of the commands accept revisions as arguments.  By default, most 
-   operate on the most recent revision on the current branch if no revision is 
+   Many of the commands accept revisions as arguments.  By default, most
+   operate on the most recent revision on the current branch if no revision is
    specified (though see |HGCommandInteractive| to prompt instead).
 
-   Each HGCommand is mapped to a key sequence starting with the <Leader> 
-   keystroke.  The default mappings may be overridden by supplying different 
-   mappings before the plugin is loaded, such as in the vimrc, in the standard 
-   fashion for plugin mappings.  For examples, please see 
+   Each HGCommand is mapped to a key sequence starting with the <Leader>
+   keystroke.  The default mappings may be overridden by supplying different
+   mappings before the plugin is loaded, such as in the vimrc, in the standard
+   fashion for plugin mappings.  For examples, please see
    |hgcommand-mappings-override|.
 
-   The HGCommand plugin may be configured in several ways.  For more details, 
+   The HGCommand plugin may be configured in several ways.  For more details,
    please see |hgcommand-customize|.
 
 ==============================================================================
@@ -1282,85 +1302,85 @@
 
 :HGAdd							              *:HGAdd*
 
-   This command performs "hg add" on the current file.  Please note, this does 
+   This command performs "hg add" on the current file.  Please note, this does
    not commit the newly-added file.
 
 :HGAnnotate						         *:HGAnnotate*
 
-   This command performs "hg annotate" on the current file.  If an argument is 
-   given, the argument is used as a revision number to display.  If not given 
-   an argument, it uses the most recent version of the file on the current 
-   branch.  Additionally, if the current buffer is a HGAnnotate buffer 
+   This command performs "hg annotate" on the current file.  If an argument is
+   given, the argument is used as a revision number to display.  If not given
+   an argument, it uses the most recent version of the file on the current
+   branch.  Additionally, if the current buffer is a HGAnnotate buffer
    already, the version number on the current line is used.
 
-   If the |HGCommandAnnotateParent| variable is set to a non-zero value, the 
-   version previous to the one on the current line is used instead.  This 
+   If the |HGCommandAnnotateParent| variable is set to a non-zero value, the
+   version previous to the one on the current line is used instead.  This
    allows one to navigate back to examine the previous version of a line.
 
-   The filetype of the HGCommand scratch buffer is set to 'HGAnnotate', to 
+   The filetype of the HGCommand scratch buffer is set to 'HGAnnotate', to
    take advantage of the bundled syntax file.
 
 
 :HGCommit[!]						           *:HGCommit*
 
-   If called with arguments, this performs "hg commit" using the arguments as 
+   If called with arguments, this performs "hg commit" using the arguments as
    the log message.
 
    If '!' is used with no arguments, an empty log message is committed.
 
-   If called with no arguments, this is a two-step command.  The first step 
-   opens a buffer to accept a log message.  When that buffer is written, it is 
-   automatically closed and the file is committed using the information from 
-   that log message.  The commit can be abandoned if the log message buffer is 
+   If called with no arguments, this is a two-step command.  The first step
+   opens a buffer to accept a log message.  When that buffer is written, it is
+   automatically closed and the file is committed using the information from
+   that log message.  The commit can be abandoned if the log message buffer is
    deleted or wiped before being written.
 
-   Alternatively, the mapping that is used to invoke :HGCommit (by default 
-   <Leader>hgc) can be used in the log message buffer to immediately commit.  
-   This is useful if the |HGCommandCommitOnWrite| variable is set to 0 to 
+   Alternatively, the mapping that is used to invoke :HGCommit (by default
+   <Leader>hgc) can be used in the log message buffer to immediately commit.
+   This is useful if the |HGCommandCommitOnWrite| variable is set to 0 to
    disable the normal commit-on-write behavior.
 
 :HGDiff						                     *:HGDiff*
 
-   With no arguments, this performs "hg diff" on the current file against the 
+   With no arguments, this performs "hg diff" on the current file against the
    current repository version.
 
-   With one argument, "hg diff" is performed on the current file against the 
+   With one argument, "hg diff" is performed on the current file against the
    specified revision.
 
-   With two arguments, hg diff is performed between the specified revisions of 
+   With two arguments, hg diff is performed between the specified revisions of
    the current file.
 
-   This command uses the 'HGCommandDiffOpt' variable to specify diff options.  
-   If that variable does not exist, then 'wbBc' is assumed.  If you wish to 
+   This command uses the 'HGCommandDiffOpt' variable to specify diff options.
+   If that variable does not exist, then 'wbBc' is assumed.  If you wish to
    have no options, then set it to the empty string.
 
 
 :HGGotoOriginal					             *:HGGotoOriginal*
 
-   This command returns the current window to the source buffer, if the 
+   This command returns the current window to the source buffer, if the
    current buffer is a HG command output buffer.
 
 :HGGotoOriginal!
 
-   Like ":HGGotoOriginal" but also executes :bufwipeout on all HG command 
+   Like ":HGGotoOriginal" but also executes :bufwipeout on all HG command
    output buffers for the source buffer.
 
 :HGLog							              *:HGLog*
 
    Performs "hg log" on the current file.
 
-   If an argument is given, it is passed as an argument to the "-r" option of 
+   If an argument is given, it is passed as an argument to the "-r" option of
    "hg log".
 
 :HGRevert						           *:HGRevert*
 
-   Replaces the current file with the most recent version from the repository 
+   Replaces the current file with the most recent version from the repository
    in order to wipe out any undesired changes.
- 
+
 :HGReview						           *:HGReview*
 
-   Retrieves a particular version of the current file.  If no argument is 
-   given, the most recent version of the file on the current branch is 
+   Retrieves a particular version of the current file.  If no argument is
+   given, the most recent version of the file on the current branch is
    retrieved.  Otherwise, the specified version is retrieved.
 
 :HGStatus					 	           *:HGStatus*
@@ -1369,37 +1389,37 @@
 
 :HGUpdate						           *:HGUpdate*
 
-   Performs "hg update" on the current file.  This intentionally does not 
-   automatically reload the current buffer, though vim should prompt the user 
+   Performs "hg update" on the current file.  This intentionally does not
+   automatically reload the current buffer, though vim should prompt the user
    to do so if the underlying file is altered by this command.
 
 :HGVimDiff						          *:HGVimDiff*
 
-   With no arguments, this prompts the user for a revision and then uses 
-   vimdiff to display the differences between the current file and the 
-   specified revision.  If no revision is specified, the most recent version 
+   With no arguments, this prompts the user for a revision and then uses
+   vimdiff to display the differences between the current file and the
+   specified revision.  If no revision is specified, the most recent version
    of the file on the current branch is used.
 
-   With one argument, that argument is used as the revision as above.  With 
-   two arguments, the differences between the two revisions is displayed using 
+   With one argument, that argument is used as the revision as above.  With
+   two arguments, the differences between the two revisions is displayed using
    vimdiff.
 
-   With either zero or one argument, the original buffer is used to perform 
-   the vimdiff.  When the other buffer is closed, the original buffer will be 
+   With either zero or one argument, the original buffer is used to perform
+   the vimdiff.  When the other buffer is closed, the original buffer will be
    returned to normal mode.
 
-   Once vimdiff mode is started using the above methods, additional vimdiff 
-   buffers may be added by passing a single version argument to the command.  
+   Once vimdiff mode is started using the above methods, additional vimdiff
+   buffers may be added by passing a single version argument to the command.
    There may be up to 4 vimdiff buffers total.
 
-   Using the 2-argument form of the command resets the vimdiff to only those 2 
-   versions.  Additionally, invoking the command on a different file will 
+   Using the 2-argument form of the command resets the vimdiff to only those 2
+   versions.  Additionally, invoking the command on a different file will
    close the previous vimdiff buffers.
 
 
 4.2 Mappings						  *hgcommand-mappings*
 
-   By default, a mapping is defined for each command.  These mappings execute 
+   By default, a mapping is defined for each command.  These mappings execute
    the default (no-argument) form of each command.
 
       <Leader>hga HGAdd
@@ -1416,20 +1436,20 @@
 
                                                  *hgcommand-mappings-override*
 
-   The default mappings can be overriden by user-provided instead by mapping 
-   to <Plug>CommandName.  This is especially useful when these mappings 
-   collide with other existing mappings (vim will warn of this during plugin 
+   The default mappings can be overriden by user-provided instead by mapping
+   to <Plug>CommandName.  This is especially useful when these mappings
+   collide with other existing mappings (vim will warn of this during plugin
    initialization, but will not clobber the existing mappings).
 
-   For instance, to override the default mapping for :HGAdd to set it to 
+   For instance, to override the default mapping for :HGAdd to set it to
    '\add', add the following to the vimrc: >
 
       nmap \add <Plug>HGAdd
 <
 4.3 Automatic buffer variables			  *hgcommand-buffer-variables*
 
-   Several buffer variables are defined in each HGCommand result buffer.	
-   These may be useful for additional customization in callbacks defined in 
+   Several buffer variables are defined in each HGCommand result buffer.
+   These may be useful for additional customization in callbacks defined in
    the event handlers (please see |hgcommand-events|).
 
    The following variables are automatically defined:
@@ -1440,24 +1460,24 @@
 
 b:hgcmd						                     *b:hgcmd*
 
-   This variable is set to the name of the hg command that created the result 
+   This variable is set to the name of the hg command that created the result
    buffer.
 ==============================================================================
 
 5. Configuration and customization			 *hgcommand-customize*
                                                             *hgcommand-config*
 
-   The HGCommand plugin can be configured in two ways:  by setting 
-   configuration variables (see |hgcommand-options|) or by defining HGCommand 
-   event handlers (see |hgcommand-events|).  Additionally, the HGCommand 
-   plugin provides several option for naming the HG result buffers (see 
-   |hgcommand-naming|) and supported a customized status line (see 
+   The HGCommand plugin can be configured in two ways:  by setting
+   configuration variables (see |hgcommand-options|) or by defining HGCommand
+   event handlers (see |hgcommand-events|).  Additionally, the HGCommand
+   plugin provides several option for naming the HG result buffers (see
+   |hgcommand-naming|) and supported a customized status line (see
    |hgcommand-statusline| and |hgcommand-buffer-management|).
 
 5.1 HGCommand configuration variables			   *hgcommand-options*
 
-   Several variables affect the plugin's behavior.  These variables are 
-   checked at time of execution, and may be defined at the window, buffer, or 
+   Several variables affect the plugin's behavior.  These variables are
+   checked at time of execution, and may be defined at the window, buffer, or
    global level and are checked in that order of precedence.
 
 
@@ -1478,87 +1498,87 @@
 
 HGCommandAnnotateParent			             *HGCommandAnnotateParent*
 
-   This variable, if set to a non-zero value, causes the zero-argument form of 
-   HGAnnotate when invoked on a HGAnnotate buffer to go to the version 
-   previous to that displayed on the current line. If not set, it defaults to 
+   This variable, if set to a non-zero value, causes the zero-argument form of
+   HGAnnotate when invoked on a HGAnnotate buffer to go to the version
+   previous to that displayed on the current line. If not set, it defaults to
    0.
 
 HGCommandCommitOnWrite				      *HGCommandCommitOnWrite*
 
-   This variable, if set to a non-zero value, causes the pending hg commit to 
-   take place immediately as soon as the log message buffer is written.  If 
-   set to zero, only the HGCommit mapping will cause the pending commit to 
+   This variable, if set to a non-zero value, causes the pending hg commit to
+   take place immediately as soon as the log message buffer is written.  If
+   set to zero, only the HGCommit mapping will cause the pending commit to
    occur.  If not set, it defaults to 1.
 
 HGCommandHGExec				                     *HGCommandHGExec*
 
-   This variable controls the executable used for all HG commands.  If not 
+   This variable controls the executable used for all HG commands.  If not
    set, it defaults to "hg".
 
 HGCommandDeleteOnHide				       *HGCommandDeleteOnHide*
 
-   This variable, if set to a non-zero value, causes the temporary HG result 
+   This variable, if set to a non-zero value, causes the temporary HG result
    buffers to automatically delete themselves when hidden.
 
 HGCommandDiffOpt				            *HGCommandDiffOpt*
 
-   This variable, if set, determines the options passed to the diff command of 
+   This variable, if set, determines the options passed to the diff command of
    HG.  If not set, it defaults to 'w'.
 
 HGCommandDiffSplit				          *HGCommandDiffSplit*
 
-   This variable overrides the |HGCommandSplit| variable, but only for buffers 
+   This variable overrides the |HGCommandSplit| variable, but only for buffers
    created with |:HGVimDiff|.
 
 HGCommandEdit					               *HGCommandEdit*
 
-   This variable controls whether the original buffer is replaced ('edit') or 
+   This variable controls whether the original buffer is replaced ('edit') or
    split ('split').  If not set, it defaults to 'edit'.
 
 HGCommandEnableBufferSetup			  *HGCommandEnableBufferSetup*
 
-   This variable, if set to a non-zero value, activates HG buffer management 
-   mode see (|hgcommand-buffer-management|).  This mode means that three 
-   buffer variables, 'HGRepository', 'HGRevision' and 'HGBranch', are set if 
-   the file is HG-controlled.  This is useful for displaying version 
+   This variable, if set to a non-zero value, activates HG buffer management
+   mode see (|hgcommand-buffer-management|).  This mode means that three
+   buffer variables, 'HGRepository', 'HGRevision' and 'HGBranch', are set if
+   the file is HG-controlled.  This is useful for displaying version
    information in the status bar.
 
 HGCommandInteractive				        *HGCommandInteractive*
 
-   This variable, if set to a non-zero value, causes appropriate commands (for 
-   the moment, only |:HGReview|) to query the user for a revision to use 
+   This variable, if set to a non-zero value, causes appropriate commands (for
+   the moment, only |:HGReview|) to query the user for a revision to use
    instead of the current revision if none is specified.
 
 HGCommandNameMarker				         *HGCommandNameMarker*
 
-   This variable, if set, configures the special attention-getting characters 
-   that appear on either side of the hg buffer type in the buffer name.  This 
-   has no effect unless |HGCommandNameResultBuffers| is set to a true value.  
-   If not set, it defaults to '_'.  
+   This variable, if set, configures the special attention-getting characters
+   that appear on either side of the hg buffer type in the buffer name.  This
+   has no effect unless |HGCommandNameResultBuffers| is set to a true value.
+   If not set, it defaults to '_'.
 
 HGCommandNameResultBuffers			  *HGCommandNameResultBuffers*
 
-   This variable, if set to a true value, causes the hg result buffers to be 
-   named in the old way ('<source file name> _<hg command>_').  If not set or 
+   This variable, if set to a true value, causes the hg result buffers to be
+   named in the old way ('<source file name> _<hg command>_').  If not set or
    set to a false value, the result buffer is nameless.
 
 HGCommandSplit					              *HGCommandSplit*
 
-   This variable controls the orientation of the various window splits that 
-   may occur (such as with HGVimDiff, when using a HG command on a HG command 
-   buffer, or when the |HGCommandEdit| variable is set to 'split'.  If set to 
-   'horizontal', the resulting windows will be on stacked on top of one 
-   another.  If set to 'vertical', the resulting windows will be side-by-side.  
+   This variable controls the orientation of the various window splits that
+   may occur (such as with HGVimDiff, when using a HG command on a HG command
+   buffer, or when the |HGCommandEdit| variable is set to 'split'.  If set to
+   'horizontal', the resulting windows will be on stacked on top of one
+   another.  If set to 'vertical', the resulting windows will be side-by-side.
    If not set, it defaults to 'horizontal' for all but HGVimDiff windows.
 
 5.2 HGCommand events				            *hgcommand-events*
 
-   For additional customization, HGCommand can trigger user-defined events.  
-   Event handlers are provided by defining User event autocommands (see 
-   |autocommand|, |User|) in the HGCommand group with patterns matching the 
+   For additional customization, HGCommand can trigger user-defined events.
+   Event handlers are provided by defining User event autocommands (see
+   |autocommand|, |User|) in the HGCommand group with patterns matching the
    event name.
 
-   For instance, the following could be added to the vimrc to provide a 'q' 
+   For instance, the following could be added to the vimrc to provide a 'q'
    mapping to quit a HGCommand scratch buffer: >
 
       augroup HGCommand
@@ -1570,10 +1590,10 @@
    The following hooks are available:
 
 HGBufferCreated		This event is fired just after a hg command result
-                        buffer is created and filled with the result of a hg 
-                        command.  It is executed within the context of the HG 
-                        command buffer.  The HGCommand buffer variables may be 
-                        useful for handlers of this event (please see 
+                        buffer is created and filled with the result of a hg
+                        command.  It is executed within the context of the HG
+                        command buffer.  The HGCommand buffer variables may be
+                        useful for handlers of this event (please see
                         |hgcommand-buffer-variables|).
 
 HGBufferSetup		This event is fired just after HG buffer setup occurs,
@@ -1586,50 +1606,50 @@
                         loads.
 
 HGVimDiffFinish		This event is fired just after the HGVimDiff command
-                        executes to allow customization of, for instance, 
+                        executes to allow customization of, for instance,
                         window placement and focus.
 
 5.3 HGCommand buffer naming				    *hgcommand-naming*
 
-   By default, the buffers containing the result of HG commands are nameless 
-   scratch buffers.  It is intended that buffer variables of those buffers be 
-   used to customize the statusline option so that the user may fully control 
+   By default, the buffers containing the result of HG commands are nameless
+   scratch buffers.  It is intended that buffer variables of those buffers be
+   used to customize the statusline option so that the user may fully control
    the display of result buffers.
 
-   If the old-style naming is desired, please enable the 
-   |HGCommandNameResultBuffers| variable.  Then, each result buffer will 
-   receive a unique name that includes the source file name, the HG command, 
-   and any extra data (such as revision numbers) that were part of the 
+   If the old-style naming is desired, please enable the
+   |HGCommandNameResultBuffers| variable.  Then, each result buffer will
+   receive a unique name that includes the source file name, the HG command,
+   and any extra data (such as revision numbers) that were part of the
    command.
 
 5.4 HGCommand status line support			*hgcommand-statusline*
 
-   It is intended that the user will customize the |'statusline'| option to 
-   include HG result buffer attributes.  A sample function that may be used in 
-   the |'statusline'| option is provided by the plugin, HGGetStatusLine().  In 
-   order to use that function in the status line, do something like the 
+   It is intended that the user will customize the |'statusline'| option to
+   include HG result buffer attributes.  A sample function that may be used in
+   the |'statusline'| option is provided by the plugin, HGGetStatusLine().  In
+   order to use that function in the status line, do something like the
    following: >
 
       set statusline=%<%f\ %{HGGetStatusLine()}\ %h%m%r%=%l,%c%V\ %P
 <
    of which %{HGGetStatusLine()} is the relevant portion.
 
-   The sample HGGetStatusLine() function handles both HG result buffers and 
-   HG-managed files if HGCommand buffer management is enabled (please see 
+   The sample HGGetStatusLine() function handles both HG result buffers and
+   HG-managed files if HGCommand buffer management is enabled (please see
    |hgcommand-buffer-management|).
 
 5.5 HGCommand buffer management		         *hgcommand-buffer-management*
 
-   The HGCommand plugin can operate in buffer management mode, which means 
-   that it attempts to set two buffer variables ('HGRevision' and 'HGBranch') 
-   upon entry into a buffer.  This is rather slow because it means that 'hg 
-   status' will be invoked at each entry into a buffer (during the |BufEnter| 
+   The HGCommand plugin can operate in buffer management mode, which means
+   that it attempts to set two buffer variables ('HGRevision' and 'HGBranch')
+   upon entry into a buffer.  This is rather slow because it means that 'hg
+   status' will be invoked at each entry into a buffer (during the |BufEnter|
    autocommand).
 
-   This mode is enabled by default.  In order to disable it, set the 
-   |HGCommandEnableBufferSetup| variable to a false (zero) value.  Enabling 
-   this mode simply provides the buffer variables mentioned above.  The user 
-   must explicitly include those in the |'statusline'| option if they are to 
+   This mode is enabled by default.  In order to disable it, set the
+   |HGCommandEnableBufferSetup| variable to a false (zero) value.  Enabling
+   this mode simply provides the buffer variables mentioned above.  The user
+   must explicitly include those in the |'statusline'| option if they are to
    appear in the status line (but see |hgcommand-statusline| for a simple way
    to do that).
 
@@ -1643,10 +1663,10 @@
                  \:set nowrap<CR>
 <
 
-   This splits the buffer vertically, puts an annotation on the left (minus 
-   the header) with the width set to 40. An editable/normal copy is placed on 
-   the right.  The two versions are scroll locked so they  move as one. and 
-   wrapping is turned off so that the lines line up correctly. The advantages 
+   This splits the buffer vertically, puts an annotation on the left (minus
+   the header) with the width set to 40. An editable/normal copy is placed on
+   the right.  The two versions are scroll locked so they  move as one. and
+   wrapping is turned off so that the lines line up correctly. The advantages
    are...
 
    1) You get a versioning on the right.
@@ -1659,9 +1679,9 @@
 
    Please let me know if you run across any.
 
-   HGVimDiff, when using the original (real) source buffer as one of the diff 
-   buffers, uses some hacks to try to restore the state of the original buffer 
-   when the scratch buffer containing the other version is destroyed.  There 
+   HGVimDiff, when using the original (real) source buffer as one of the diff
+   buffers, uses some hacks to try to restore the state of the original buffer
+   when the scratch buffer containing the other version is destroyed.  There
    may still be bugs in here, depending on many configuration details.
 
 ==============================================================================
@@ -1674,4 +1694,4 @@
 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 " v im:tw=78:ts=8:ft=help:norl:
 " vim600: set foldmethod=marker  tabstop=8 shiftwidth=2 softtabstop=2 smartindent smarttab  :
-"fileencoding=iso-8859-15 
+"fileencoding=iso-8859-15