contrib/vim/hgcommand.vim
changeset 2592 457846f400e8
parent 2591 61f2008cd6bf
child 2603 f80057407c07
equal deleted inserted replaced
2591:61f2008cd6bf 2592:457846f400e8
     1 " vim600: set foldmethod=marker:
     1 " vim600: set foldmethod=marker:
     2 "
     2 "
     3 " Vim plugin to assist in working with CVS-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.76
     7 " Maintainer:    Bob Hiestand <bob.hiestand@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: {{{1
     9 " Credits: {{{1
    10 "                Mathieu Clabaut for many suggestions and improvements.
    10 "                Bob Hiestand <bob.hiestand@gmail.com> for the fabulous
    11 "
    11 "                cvscommand.vim from which this script was directly created by
    12 "                Suresh Govindachar and Jeeva Chelladhurai for finding waaaay
    12 "                means of sed commands and minor tweaks.
    13 "                too many bugs.
       
    14 "
       
    15 "                Suresh Govindachar (again!) for finding the
       
    16 "                fully-folded-last-line-delete bug.
       
    17 "
       
    18 "                Albrecht Gass for the Delete-on-Hide behavior suggestion.
       
    19 "
       
    20 "                Joe MacDonald for finding the CVS log message header bug and
       
    21 "                pointing out that buffer refreshes are needed after CVS
       
    22 "                \%(un\)\?edit.
       
    23 "
       
    24 "                Srinath Avadhanula for the suggestion and original patch for
       
    25 "                the CVSCommitOnWrite option and mapping hot key.
       
    26 "
       
    27 "                John Sivak for helping to debug Windows issues and suggesting
       
    28 "                the CVSEditors and CVSWatchers commands.
       
    29 "
       
    30 "                Igor Levko for the patch to recognize numerical sticky tags.
       
    31 "
       
    32 "                Domink Strasser for the patch to correct the status line for
       
    33 "                CVSAdd'd files.
       
    34 "
       
    35 "                Weerapong Sirikanya for finding a bug with CVSCommit and
       
    36 "                autochdir.
       
    37 "
       
    38 "                David Gotz for finding a bug with CVSVimDiff buffer splitting
       
    39 "                and original buffer restoration.
       
    40 "
       
    41 "                CJ van den Berg for the patch to not change working directory
       
    42 "                when editing a non-CVS file.
       
    43 "
       
    44 "                Luca Gerli for noticing bad behavior for keywords in files
       
    45 "                after commit if split windows are used.
       
    46 
    13 
    47 " Section: Documentation {{{1
    14 " Section: Documentation {{{1
    48 "
    15 "
    49 " Provides functions to invoke various CVS commands on the current file
    16 " Provides functions to invoke various HG commands on the current file
    50 " (either the current buffer, or, in the case of an directory buffer, the file
    17 " (either the current buffer, or, in the case of an directory buffer, the file
    51 " on the current line).  The output of the commands is captured in a new
    18 " on the current line).  The output of the commands is captured in a new
    52 " scratch window.  For convenience, if the functions are invoked on a CVS
    19 " scratch window.  For convenience, if the functions are invoked on a HG
    53 " output window, the original file is used for the cvs operation instead after
    20 " output window, the original file is used for the hg operation instead after
    54 " the window is split.  This is primarily useful when running CVSCommit and
    21 " the window is split.  This is primarily useful when running HGCommit and
    55 " you need to see the changes made, so that CVSDiff is usable and shows up in
    22 " you need to see the changes made, so that HGDiff is usable and shows up in
    56 " another window.
    23 " another window.
    57 "
    24 "
    58 " Command documentation {{{2
    25 " Command documentation {{{2
    59 "
    26 "
    60 " CVSAdd           Performs "cvs add" on the current file.
    27 " HGAdd           Performs "hg add" on the current file.
    61 "
    28 "
    62 " CVSAnnotate      Performs "cvs annotate" on the current file.  If an
    29 " HGAnnotate      Performs "hg annotate" on the current file.  If an
    63 "                  argument is given, the argument is used as a revision
    30 "                  argument is given, the argument is used as a revision
    64 "                  number to display.  If not given an argument, it uses the
    31 "                  number to display.  If not given an argument, it uses the
    65 "                  most recent version of the file on the current branch.
    32 "                  most recent version of the file on the current branch.
    66 "                  Additionally, if the current buffer is a CVSAnnotate buffer
    33 "                  Additionally, if the current buffer is a HGAnnotate buffer
    67 "                  already, the version number on the current line is used.
    34 "                  already, the version number on the current line is used.
    68 "
    35 "
    69 "                  If the 'CVSCommandAnnotateParent' variable is set to a
    36 "                  If the 'HGCommandAnnotateParent' variable is set to a
    70 "                  non-zero value, the version previous to the one on the
    37 "                  non-zero value, the version previous to the one on the
    71 "                  current line is used instead.  This allows one to navigate
    38 "                  current line is used instead.  This allows one to navigate
    72 "                  back to examine the previous version of a line.
    39 "                  back to examine the previous version of a line.
    73 "
    40 "
    74 " CVSCommit[!]     If called with arguments, this performs "cvs commit" using
    41 " HGCommit[!]     If called with arguments, this performs "hg commit" using
    75 "                  the arguments as the log message.
    42 "                  the arguments as the log message.
    76 "
    43 "
    77 "                  If '!' is used, an empty log message is committed.
    44 "                  If '!' is used, an empty log message is committed.
    78 "
    45 "
    79 "                  If called with no arguments, this is a two-step command.
    46 "                  If called with no arguments, this is a two-step command.
    81 "                  When that buffer is written, it is automatically closed and
    48 "                  When that buffer is written, it is automatically closed and
    82 "                  the file is committed using the information from that log
    49 "                  the file is committed using the information from that log
    83 "                  message.  The commit can be abandoned if the log message
    50 "                  message.  The commit can be abandoned if the log message
    84 "                  buffer is deleted or wiped before being written.
    51 "                  buffer is deleted or wiped before being written.
    85 "
    52 "
    86 " CVSDiff          With no arguments, this performs "cvs diff" on the current
    53 " HGDiff          With no arguments, this performs "hg diff" on the current
    87 "                  file.  With one argument, "cvs diff" is performed on the
    54 "                  file.  With one argument, "hg diff" is performed on the
    88 "                  current file against the specified revision.  With two
    55 "                  current file against the specified revision.  With two
    89 "                  arguments, cvs diff is performed between the specified
    56 "                  arguments, hg diff is performed between the specified
    90 "                  revisions of the current file.  This command uses the
    57 "                  revisions of the current file.  This command uses the
    91 "                  'CVSCommandDiffOpt' variable to specify diff options.  If
    58 "                  'HGCommandDiffOpt' variable to specify diff options.  If
    92 "                  that variable does not exist, then 'wbBc' is assumed.  If
    59 "                  that variable does not exist, then 'wbBc' is assumed.  If
    93 "                  you wish to have no options, then set it to the empty
    60 "                  you wish to have no options, then set it to the empty
    94 "                  string.
    61 "                  string.
    95 "
    62 "
    96 " CVSEdit          Performs "cvs edit" on the current file.
    63 " HGGotoOriginal  Returns the current window to the source buffer if the
    97 "
    64 "                  current buffer is a HG output buffer.
    98 " CVSEditors       Performs "cvs editors" on the current file.
    65 "
    99 "
    66 " HGLog           Performs "hg log" on the current file.
   100 " CVSGotoOriginal  Returns the current window to the source buffer if the
    67 "
   101 "                  current buffer is a CVS output buffer.
    68 " HGRevert        Replaces the modified version of the current file with the
   102 "
       
   103 " CVSLog           Performs "cvs log" on the current file.
       
   104 "
       
   105 " CVSRevert        Replaces the modified version of the current file with the
       
   106 "                  most recent version from the repository.
    69 "                  most recent version from the repository.
   107 "
    70 "
   108 " CVSReview        Retrieves a particular version of the current file.  If no
    71 " HGReview        Retrieves a particular version of the current file.  If no
   109 "                  argument is given, the most recent version of the file on
    72 "                  argument is given, the most recent version of the file on
   110 "                  the current branch is retrieved.  The specified revision is
    73 "                  the current branch is retrieved.  The specified revision is
   111 "                  retrieved into a new buffer.
    74 "                  retrieved into a new buffer.
   112 "
    75 "
   113 " CVSStatus        Performs "cvs status" on the current file.
    76 " HGStatus        Performs "hg status" on the current file.
   114 "
    77 "
   115 " CVSUnedit        Performs "cvs unedit" on the current file.
    78 " HGUpdate        Performs "hg update" on the current file.
   116 "
    79 "
   117 " CVSUpdate        Performs "cvs update" on the current file.
    80 " HGVimDiff       With no arguments, this prompts the user for a revision and
   118 "
       
   119 " CVSVimDiff       With no arguments, this prompts the user for a revision and
       
   120 "                  then uses vimdiff to display the differences between the
    81 "                  then uses vimdiff to display the differences between the
   121 "                  current file and the specified revision.  If no revision is
    82 "                  current file and the specified revision.  If no revision is
   122 "                  specified, the most recent version of the file on the
    83 "                  specified, the most recent version of the file on the
   123 "                  current branch is used.  With one argument, that argument
    84 "                  current branch is used.  With one argument, that argument
   124 "                  is used as the revision as above.  With two arguments, the
    85 "                  is used as the revision as above.  With two arguments, the
   137 "                  Using the 2-argument form of the command resets the vimdiff
    98 "                  Using the 2-argument form of the command resets the vimdiff
   138 "                  to only those 2 versions.  Additionally, invoking the
    99 "                  to only those 2 versions.  Additionally, invoking the
   139 "                  command on a different file will close the previous vimdiff
   100 "                  command on a different file will close the previous vimdiff
   140 "                  buffers.
   101 "                  buffers.
   141 "
   102 "
   142 " CVSWatch         Takes an argument which must be one of [on|off|add|remove].
       
   143 "                  Performs "cvs watch" with the given argument on the current
       
   144 "                  file.
       
   145 "
       
   146 " CVSWatchers      Performs "cvs watchers" on the current file.
       
   147 "
       
   148 " CVSWatchAdd      Alias for "CVSWatch add"
       
   149 "
       
   150 " CVSWatchOn       Alias for "CVSWatch on"
       
   151 "
       
   152 " CVSWatchOff      Alias for "CVSWatch off"
       
   153 "
       
   154 " CVSWatchRemove   Alias for "CVSWatch remove"
       
   155 "
   103 "
   156 " Mapping documentation: {{{2
   104 " Mapping documentation: {{{2
   157 "
   105 "
   158 " By default, a mapping is defined for each command.  User-provided mappings
   106 " By default, a mapping is defined for each command.  User-provided mappings
   159 " can be used instead by mapping to <Plug>CommandName, for instance:
   107 " can be used instead by mapping to <Plug>CommandName, for instance:
   160 "
   108 "
   161 " nnoremap ,ca <Plug>CVSAdd
   109 " nnoremap ,ca <Plug>HGAdd
   162 "
   110 "
   163 " The default mappings are as follow:
   111 " The default mappings are as follow:
   164 "
   112 "
   165 "   <Leader>ca CVSAdd
   113 "   <Leader>hga HGAdd
   166 "   <Leader>cn CVSAnnotate
   114 "   <Leader>hgn HGAnnotate
   167 "   <Leader>cc CVSCommit
   115 "   <Leader>hgc HGCommit
   168 "   <Leader>cd CVSDiff
   116 "   <Leader>hgd HGDiff
   169 "   <Leader>ce CVSEdit
   117 "   <Leader>hgg HGGotoOriginal
   170 "   <Leader>ci CVSEditors
   118 "   <Leader>hgG HGGotoOriginal!
   171 "   <Leader>cg CVSGotoOriginal
   119 "   <Leader>hgl HGLog
   172 "   <Leader>cG CVSGotoOriginal!
   120 "   <Leader>hgr HGReview
   173 "   <Leader>cl CVSLog
   121 "   <Leader>hgs HGStatus
   174 "   <Leader>cr CVSReview
   122 "   <Leader>hgu HGUpdate
   175 "   <Leader>cs CVSStatus
   123 "   <Leader>hgv HGVimDiff
   176 "   <Leader>ct CVSUnedit
       
   177 "   <Leader>cu CVSUpdate
       
   178 "   <Leader>cv CVSVimDiff
       
   179 "   <Leader>cwv CVSWatchers
       
   180 "   <Leader>cwa CVSWatchAdd
       
   181 "   <Leader>cwn CVSWatchOn
       
   182 "   <Leader>cwa CVSWatchOff
       
   183 "   <Leader>cwr CVSWatchRemove
       
   184 "
   124 "
   185 " Options documentation: {{{2
   125 " Options documentation: {{{2
   186 "
   126 "
   187 " Several variables are checked by the script to determine behavior as follow:
   127 " Several variables are checked by the script to determine behavior as follow:
   188 "
   128 "
   189 " CVSCommandAnnotateParent
   129 " HGCommandAnnotateParent
   190 "   This variable, if set to a non-zero value, causes the zero-argument form
   130 "   This variable, if set to a non-zero value, causes the zero-argument form
   191 "   of CVSAnnotate when invoked on a CVSAnnotate buffer to go to the version
   131 "   of HGAnnotate when invoked on a HGAnnotate buffer to go to the version
   192 "   previous to that displayed on the current line.  If not set, it defaults
   132 "   previous to that displayed on the current line.  If not set, it defaults
   193 "   to 0.
   133 "   to 0.
   194 "
   134 "
   195 " CVSCommandCommitOnWrite
   135 " HGCommandCommitOnWrite
   196 "   This variable, if set to a non-zero value, causes the pending cvs commit
   136 "   This variable, if set to a non-zero value, causes the pending hg commit
   197 "   to take place immediately as soon as the log message buffer is written.
   137 "   to take place immediately as soon as the log message buffer is written.
   198 "   If set to zero, only the CVSCommit mapping will cause the pending commit
   138 "   If set to zero, only the HGCommit mapping will cause the pending commit
   199 "   to occur.  If not set, it defaults to 1.
   139 "   to occur.  If not set, it defaults to 1.
   200 "
   140 "
   201 " CVSCommandDeleteOnHide
   141 " HGCommandDeleteOnHide
   202 "   This variable, if set to a non-zero value, causes the temporary CVS result
   142 "   This variable, if set to a non-zero value, causes the temporary HG result
   203 "   buffers to automatically delete themselves when hidden.
   143 "   buffers to automatically delete themselves when hidden.
   204 "
   144 "
   205 " CVSCommandDiffOpt
   145 " HGCommandDiffOpt
   206 "   This variable, if set, determines the options passed to the diff command
   146 "   This variable, if set, determines the options passed to the diff command
   207 "   of CVS.  If not set, it defaults to 'wbBc'.
   147 "   of HG.  If not set, it defaults to 'wbBc'.
   208 "
   148 "
   209 " CVSCommandDiffSplit
   149 " HGCommandDiffSplit
   210 "   This variable overrides the CVSCommandSplit variable, but only for buffers
   150 "   This variable overrides the HGCommandSplit variable, but only for buffers
   211 "   created with CVSVimDiff.
   151 "   created with HGVimDiff.
   212 "
   152 "
   213 " CVSCommandEdit
   153 " HGCommandEdit
   214 "   This variable controls whether the original buffer is replaced ('edit') or
   154 "   This variable controls whether the original buffer is replaced ('edit') or
   215 "   split ('split').  If not set, it defaults to 'edit'.
   155 "   split ('split').  If not set, it defaults to 'edit'.
   216 "
   156 "
   217 " CVSCommandEnableBufferSetup
   157 " HGCommandEnableBufferSetup
   218 "   This variable, if set to a non-zero value, activates CVS buffer management
   158 "   This variable, if set to a non-zero value, activates HG buffer management
   219 "   mode.  This mode means that two buffer variables, 'CVSRevision' and
   159 "   mode.  This mode means that two buffer variables, 'HGRevision' and
   220 "   'CVSBranch', are set if the file is CVS-controlled.  This is useful for
   160 "   'HGBranch', are set if the file is HG-controlled.  This is useful for
   221 "   displaying version information in the status bar.
   161 "   displaying version information in the status bar.
   222 "
   162 "
   223 " CVSCommandInteractive
   163 " HGCommandInteractive
   224 "   This variable, if set to a non-zero value, causes appropriate functions (for
   164 "   This variable, if set to a non-zero value, causes appropriate functions (for
   225 "   the moment, only CVSReview) to query the user for a revision to use
   165 "   the moment, only HGReview) to query the user for a revision to use
   226 "   instead of the current revision if none is specified.
   166 "   instead of the current revision if none is specified.
   227 "
   167 "
   228 " CVSCommandNameMarker
   168 " HGCommandNameMarker
   229 "   This variable, if set, configures the special attention-getting characters
   169 "   This variable, if set, configures the special attention-getting characters
   230 "   that appear on either side of the cvs buffer type in the buffer name.
   170 "   that appear on either side of the hg buffer type in the buffer name.
   231 "   This has no effect unless 'CVSCommandNameResultBuffers' is set to a true
   171 "   This has no effect unless 'HGCommandNameResultBuffers' is set to a true
   232 "   value.  If not set, it defaults to '_'.  
   172 "   value.  If not set, it defaults to '_'.  
   233 "
   173 "
   234 " CVSCommandNameResultBuffers
   174 " HGCommandNameResultBuffers
   235 "   This variable, if set to a true value, causes the cvs result buffers to be
   175 "   This variable, if set to a true value, causes the hg result buffers to be
   236 "   named in the old way ('<source file name> _<cvs command>_').  If not set
   176 "   named in the old way ('<source file name> _<hg command>_').  If not set
   237 "   or set to a false value, the result buffer is nameless.
   177 "   or set to a false value, the result buffer is nameless.
   238 "
   178 "
   239 " CVSCommandSplit
   179 " HGCommandSplit
   240 "   This variable controls the orientation of the various window splits that
   180 "   This variable controls the orientation of the various window splits that
   241 "   may occur (such as with CVSVimDiff, when using a CVS command on a CVS
   181 "   may occur (such as with HGVimDiff, when using a HG command on a HG
   242 "   command buffer, or when the 'CVSCommandEdit' variable is set to 'split'.
   182 "   command buffer, or when the 'HGCommandEdit' variable is set to 'split'.
   243 "   If set to 'horizontal', the resulting windows will be on stacked on top of
   183 "   If set to 'horizontal', the resulting windows will be on stacked on top of
   244 "   one another.  If set to 'vertical', the resulting windows will be
   184 "   one another.  If set to 'vertical', the resulting windows will be
   245 "   side-by-side.  If not set, it defaults to 'horizontal' for all but
   185 "   side-by-side.  If not set, it defaults to 'horizontal' for all but
   246 "   CVSVimDiff windows.
   186 "   HGVimDiff windows.
   247 "
   187 "
   248 " Event documentation {{{2
   188 " Event documentation {{{2
   249 "   For additional customization, cvscommand.vim uses User event autocommand
   189 "   For additional customization, hgcommand.vim uses User event autocommand
   250 "   hooks.  Each event is in the CVSCommand group, and different patterns
   190 "   hooks.  Each event is in the HGCommand group, and different patterns
   251 "   match the various hooks.
   191 "   match the various hooks.
   252 "
   192 "
   253 "   For instance, the following could be added to the vimrc to provide a 'q'
   193 "   For instance, the following could be added to the vimrc to provide a 'q'
   254 "   mapping to quit a CVS buffer:
   194 "   mapping to quit a HG buffer:
   255 "
   195 "
   256 "   augroup CVSCommand
   196 "   augroup HGCommand
   257 "     au CVSCommand User CVSBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr> 
   197 "     au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr> 
   258 "   augroup END
   198 "   augroup END
   259 "
   199 "
   260 "   The following hooks are available:
   200 "   The following hooks are available:
   261 "
   201 "
   262 "   CVSBufferCreated           This event is fired just after a cvs command
   202 "   HGBufferCreated           This event is fired just after a hg command
   263 "                              result buffer is created and filled with the
   203 "                              result buffer is created and filled with the
   264 "                              result of a cvs command.  It is executed within
   204 "                              result of a hg command.  It is executed within
   265 "                              the context of the new buffer.
   205 "                              the context of the new buffer.
   266 "
   206 "
   267 "   CVSBufferSetup             This event is fired just after CVS buffer setup
   207 "   HGBufferSetup             This event is fired just after HG buffer setup
   268 "                              occurs, if enabled.
   208 "                              occurs, if enabled.
   269 "
   209 "
   270 "   CVSPluginInit              This event is fired when the CVSCommand plugin
   210 "   HGPluginInit              This event is fired when the HGCommand plugin
   271 "                              first loads.
   211 "                              first loads.
   272 "
   212 "
   273 "   CVSPluginFinish            This event is fired just after the CVSCommand
   213 "   HGPluginFinish            This event is fired just after the HGCommand
   274 "                              plugin loads.
   214 "                              plugin loads.
   275 "
   215 "
   276 "   CVSVimDiffFinish           This event is fired just after the CVSVimDiff
   216 "   HGVimDiffFinish           This event is fired just after the HGVimDiff
   277 "                              command executes to allow customization of,
   217 "                              command executes to allow customization of,
   278 "                              for instance, window placement and focus.
   218 "                              for instance, window placement and focus.
   279 "
   219 "
   280 " Section: Plugin header {{{1
   220 " Section: Plugin header {{{1
   281 
   221 
   282 " loaded_cvscommand is set to 1 when the initialization begins, and 2 when it
   222 " loaded_hgcommand is set to 1 when the initialization begins, and 2 when it
   283 " completes.  This allows various actions to only be taken by functions after
   223 " completes.  This allows various actions to only be taken by functions after
   284 " system initialization.
   224 " system initialization.
   285 
   225 
   286 if exists("loaded_cvscommand")
   226 if exists("loaded_hgcommand")
   287    finish
   227    finish
   288 endif
   228 endif
   289 let loaded_cvscommand = 1
   229 let loaded_hgcommand = 1
   290 
   230 
   291 if v:version < 602
   231 if v:version < 602
   292   echohl WarningMsg|echomsg "CVSCommand 1.69 or later requires VIM 6.2 or later"|echohl None
   232   echohl WarningMsg|echomsg "HGCommand 1.69 or later requires VIM 6.2 or later"|echohl None
   293   finish
   233   finish
   294 endif
   234 endif
   295 
   235 
   296 " Section: Event group setup {{{1
   236 " Section: Event group setup {{{1
   297 
   237 
   298 augroup CVSCommand
   238 augroup HGCommand
   299 augroup END
   239 augroup END
   300 
   240 
   301 " Section: Plugin initialization {{{1
   241 " Section: Plugin initialization {{{1
   302 silent do CVSCommand User CVSPluginInit
   242 silent do HGCommand User HGPluginInit
   303 
   243 
   304 " Section: Script variable initialization {{{1
   244 " Section: Script variable initialization {{{1
   305 
   245 
   306 let s:CVSCommandEditFileRunning = 0
   246 let s:HGCommandEditFileRunning = 0
   307 unlet! s:vimDiffRestoreCmd
   247 unlet! s:vimDiffRestoreCmd
   308 unlet! s:vimDiffSourceBuffer
   248 unlet! s:vimDiffSourceBuffer
   309 unlet! s:vimDiffBufferCount
   249 unlet! s:vimDiffBufferCount
   310 unlet! s:vimDiffScratchList
   250 unlet! s:vimDiffScratchList
   311 
   251 
   312 " Section: Utility functions {{{1
   252 " Section: Utility functions {{{1
   313 
   253 
   314 " Function: s:CVSResolveLink() {{{2
   254 " Function: s:HGResolveLink() {{{2
   315 " Fully resolve the given file name to remove shortcuts or symbolic links.
   255 " Fully resolve the given file name to remove shortcuts or symbolic links.
   316 
   256 
   317 function! s:CVSResolveLink(fileName)
   257 function! s:HGResolveLink(fileName)
   318   let resolved = resolve(a:fileName)
   258   let resolved = resolve(a:fileName)
   319   if resolved != a:fileName
   259   if resolved != a:fileName
   320     let resolved = s:CVSResolveLink(resolved)
   260     let resolved = s:HGResolveLink(resolved)
   321   endif
   261   endif
   322   return resolved
   262   return resolved
   323 endfunction
   263 endfunction
   324 
   264 
   325 " Function: s:CVSChangeToCurrentFileDir() {{{2
   265 " Function: s:HGChangeToCurrentFileDir() {{{2
   326 " Go to the directory in which the current CVS-controlled file is located.
   266 " Go to the directory in which the current HG-controlled file is located.
   327 " If this is a CVS command buffer, first switch to the original file.
   267 " If this is a HG command buffer, first switch to the original file.
   328 
   268 
   329 function! s:CVSChangeToCurrentFileDir(fileName)
   269 function! s:HGChangeToCurrentFileDir(fileName)
   330   let oldCwd=getcwd()
   270   let oldCwd=getcwd()
   331   let fileName=s:CVSResolveLink(a:fileName)
   271   let fileName=s:HGResolveLink(a:fileName)
   332   let newCwd=fnamemodify(fileName, ':h')
   272   let newCwd=fnamemodify(fileName, ':h')
   333   if strlen(newCwd) > 0
   273   if strlen(newCwd) > 0
   334     execute 'cd' escape(newCwd, ' ')
   274     execute 'cd' escape(newCwd, ' ')
   335   endif
   275   endif
   336   return oldCwd
   276   return oldCwd
   337 endfunction
   277 endfunction
   338 
   278 
   339 " Function: s:CVSGetOption(name, default) {{{2
   279 " Function: s:HGGetOption(name, default) {{{2
   340 " Grab a user-specified option to override the default provided.  Options are
   280 " Grab a user-specified option to override the default provided.  Options are
   341 " searched in the window, buffer, then global spaces.
   281 " searched in the window, buffer, then global spaces.
   342 
   282 
   343 function! s:CVSGetOption(name, default)
   283 function! s:HGGetOption(name, default)
   344   if exists("s:" . a:name . "Override")
   284   if exists("s:" . a:name . "Override")
   345     execute "return s:".a:name."Override"
   285     execute "return s:".a:name."Override"
   346   elseif exists("w:" . a:name)
   286   elseif exists("w:" . a:name)
   347     execute "return w:".a:name
   287     execute "return w:".a:name
   348   elseif exists("b:" . a:name)
   288   elseif exists("b:" . a:name)
   352   else
   292   else
   353     return a:default
   293     return a:default
   354   endif
   294   endif
   355 endfunction
   295 endfunction
   356 
   296 
   357 " Function: s:CVSEditFile(name, origBuffNR) {{{2
   297 " Function: s:HGEditFile(name, origBuffNR) {{{2
   358 " Wrapper around the 'edit' command to provide some helpful error text if the
   298 " Wrapper around the 'edit' command to provide some helpful error text if the
   359 " current buffer can't be abandoned.  If name is provided, it is used;
   299 " current buffer can't be abandoned.  If name is provided, it is used;
   360 " otherwise, a nameless scratch buffer is used.
   300 " otherwise, a nameless scratch buffer is used.
   361 " Returns: 0 if successful, -1 if an error occurs.
   301 " Returns: 0 if successful, -1 if an error occurs.
   362 
   302 
   363 function! s:CVSEditFile(name, origBuffNR)
   303 function! s:HGEditFile(name, origBuffNR)
   364   "Name parameter will be pasted into expression.
   304   "Name parameter will be pasted into expression.
   365   let name = escape(a:name, ' *?\')
   305   let name = escape(a:name, ' *?\')
   366 
   306 
   367   let editCommand = s:CVSGetOption('CVSCommandEdit', 'edit')
   307   let editCommand = s:HGGetOption('HGCommandEdit', 'edit')
   368   if editCommand != 'edit'
   308   if editCommand != 'edit'
   369     if s:CVSGetOption('CVSCommandSplit', 'horizontal') == 'horizontal'
   309     if s:HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal'
   370       if name == ""
   310       if name == ""
   371         let editCommand = 'rightbelow new'
   311         let editCommand = 'rightbelow new'
   372       else
   312       else
   373         let editCommand = 'rightbelow split ' . name
   313         let editCommand = 'rightbelow split ' . name
   374       endif
   314       endif
   386       let editCommand = 'edit ' . name
   326       let editCommand = 'edit ' . name
   387     endif
   327     endif
   388   endif
   328   endif
   389 
   329 
   390   " Protect against useless buffer set-up
   330   " Protect against useless buffer set-up
   391   let s:CVSCommandEditFileRunning = s:CVSCommandEditFileRunning + 1
   331   let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
   392   try
   332   try
   393     execute editCommand
   333     execute editCommand
   394   finally
   334   finally
   395     let s:CVSCommandEditFileRunning = s:CVSCommandEditFileRunning - 1
   335     let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
   396   endtry
   336   endtry
   397 
   337 
   398   let b:CVSOrigBuffNR=a:origBuffNR
   338   let b:HGOrigBuffNR=a:origBuffNR
   399   let b:CVSCommandEdit='split'
   339   let b:HGCommandEdit='split'
   400 endfunction
   340 endfunction
   401 
   341 
   402 " Function: s:CVSCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2
   342 " Function: s:HGCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2
   403 " Creates a new scratch buffer and captures the output from execution of the
   343 " Creates a new scratch buffer and captures the output from execution of the
   404 " given command.  The name of the scratch buffer is returned.
   344 " given command.  The name of the scratch buffer is returned.
   405 
   345 
   406 function! s:CVSCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR)
   346 function! s:HGCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR)
   407   let fileName=bufname(a:origBuffNR)
   347   let fileName=bufname(a:origBuffNR)
   408 
   348 
   409   let resultBufferName=''
   349   let resultBufferName=''
   410 
   350 
   411   if s:CVSGetOption("CVSCommandNameResultBuffers", 0)
   351   if s:HGGetOption("HGCommandNameResultBuffers", 0)
   412     let nameMarker = s:CVSGetOption("CVSCommandNameMarker", '_')
   352     let nameMarker = s:HGGetOption("HGCommandNameMarker", '_')
   413     if strlen(a:statusText) > 0
   353     if strlen(a:statusText) > 0
   414       let bufName=a:cmdName . ' -- ' . a:statusText
   354       let bufName=a:cmdName . ' -- ' . a:statusText
   415     else
   355     else
   416       let bufName=a:cmdName
   356       let bufName=a:cmdName
   417     endif
   357     endif
   422       let counter=counter + 1
   362       let counter=counter + 1
   423       let resultBufferName=bufName . ' (' . counter . ')'
   363       let resultBufferName=bufName . ' (' . counter . ')'
   424     endwhile
   364     endwhile
   425   endif
   365   endif
   426 
   366 
   427   let cvsCommand = s:CVSGetOption("CVSCommandCVSExec", "cvs") . " " . a:cmd
   367   let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd
   428   let cvsOut = system(cvsCommand)
   368   echomsg "DBG :".hgCommand
       
   369   let hgOut = system(hgCommand)
   429   " HACK:  diff command does not return proper error codes
   370   " HACK:  diff command does not return proper error codes
   430   if v:shell_error && a:cmdName != 'cvsdiff'
   371   if v:shell_error && a:cmdName != 'hgdiff'
   431     if strlen(cvsOut) == 0
   372     if strlen(hgOut) == 0
   432       echoerr "CVS command failed"
   373       echoerr "HG command failed"
   433     else
   374     else
   434       echoerr "CVS command failed:  " . cvsOut
   375       echoerr "HG command failed:  " . hgOut
   435     endif
   376     endif
   436     return -1
   377     return -1
   437   endif
   378   endif
   438   if strlen(cvsOut) == 0
   379   if strlen(hgOut) == 0
   439     " Handle case of no output.  In this case, it is important to check the
   380     " Handle case of no output.  In this case, it is important to check the
   440     " file status, especially since cvs edit/unedit may change the attributes
   381     " file status, especially since hg edit/unedit may change the attributes
   441     " of the file with no visible output.
   382     " of the file with no visible output.
   442 
   383 
   443     echomsg "No output from CVS command"
   384     echomsg "No output from HG command"
   444     checktime
   385     checktime
   445     return -1
   386     return -1
   446   endif
   387   endif
   447 
   388 
   448   if s:CVSEditFile(resultBufferName, a:origBuffNR) == -1
   389   if s:HGEditFile(resultBufferName, a:origBuffNR) == -1
   449     return -1
   390     return -1
   450   endif
   391   endif
   451 
   392 
   452   set buftype=nofile
   393   set buftype=nofile
   453   set noswapfile
   394   set noswapfile
   454   set filetype=
   395   set filetype=
   455 
   396 
   456   if s:CVSGetOption("CVSCommandDeleteOnHide", 0)
   397   if s:HGGetOption("HGCommandDeleteOnHide", 0)
   457     set bufhidden=delete
   398     set bufhidden=delete
   458   endif
   399   endif
   459 
   400 
   460   silent 0put=cvsOut
   401   silent 0put=hgOut
   461 
   402 
   462   " The last command left a blank line at the end of the buffer.  If the
   403   " The last command left a blank line at the end of the buffer.  If the
   463   " last line is folded (a side effect of the 'put') then the attempt to
   404   " last line is folded (a side effect of the 'put') then the attempt to
   464   " remove the blank line will kill the last fold.
   405   " remove the blank line will kill the last fold.
   465   "
   406   "
   473   $d
   414   $d
   474   1
   415   1
   475 
   416 
   476   " Define the environment and execute user-defined hooks.
   417   " Define the environment and execute user-defined hooks.
   477 
   418 
   478   let b:CVSSourceFile=fileName
   419   let b:HGSourceFile=fileName
   479   let b:CVSCommand=a:cmdName
   420   let b:HGCommand=a:cmdName
   480   if a:statusText != ""
   421   if a:statusText != ""
   481     let b:CVSStatusText=a:statusText
   422     let b:HGStatusText=a:statusText
   482   endif
   423   endif
   483 
   424 
   484   silent do CVSCommand User CVSBufferCreated
   425   silent do HGCommand User HGBufferCreated
   485   return bufnr("%")
   426   return bufnr("%")
   486 endfunction
   427 endfunction
   487 
   428 
   488 " Function: s:CVSBufferCheck(cvsBuffer) {{{2
   429 " Function: s:HGBufferCheck(hgBuffer) {{{2
   489 " Attempts to locate the original file to which CVS operations were applied
   430 " Attempts to locate the original file to which HG operations were applied
   490 " for a given buffer.
   431 " for a given buffer.
   491 
   432 
   492 function! s:CVSBufferCheck(cvsBuffer)
   433 function! s:HGBufferCheck(hgBuffer)
   493   let origBuffer = getbufvar(a:cvsBuffer, "CVSOrigBuffNR")
   434   let origBuffer = getbufvar(a:hgBuffer, "HGOrigBuffNR")
   494   if origBuffer
   435   if origBuffer
   495     if bufexists(origBuffer)
   436     if bufexists(origBuffer)
   496       return origBuffer
   437       return origBuffer
   497     else
   438     else
   498       " Original buffer no longer exists.
   439       " Original buffer no longer exists.
   499       return -1 
   440       return -1 
   500     endif
   441     endif
   501   else
   442   else
   502     " No original buffer
   443     " No original buffer
   503     return a:cvsBuffer
   444     return a:hgBuffer
   504   endif
   445   endif
   505 endfunction
   446 endfunction
   506 
   447 
   507 " Function: s:CVSCurrentBufferCheck() {{{2
   448 " Function: s:HGCurrentBufferCheck() {{{2
   508 " Attempts to locate the original file to which CVS operations were applied
   449 " Attempts to locate the original file to which HG operations were applied
   509 " for the current buffer.
   450 " for the current buffer.
   510 
   451 
   511 function! s:CVSCurrentBufferCheck()
   452 function! s:HGCurrentBufferCheck()
   512   return s:CVSBufferCheck(bufnr("%"))
   453   return s:HGBufferCheck(bufnr("%"))
   513 endfunction
   454 endfunction
   514 
   455 
   515 " Function: s:CVSToggleDeleteOnHide() {{{2
   456 " Function: s:HGToggleDeleteOnHide() {{{2
   516 " Toggles on and off the delete-on-hide behavior of CVS buffers
   457 " Toggles on and off the delete-on-hide behavior of HG buffers
   517 
   458 
   518 function! s:CVSToggleDeleteOnHide()
   459 function! s:HGToggleDeleteOnHide()
   519   if exists("g:CVSCommandDeleteOnHide")
   460   if exists("g:HGCommandDeleteOnHide")
   520     unlet g:CVSCommandDeleteOnHide
   461     unlet g:HGCommandDeleteOnHide
   521   else
   462   else
   522     let g:CVSCommandDeleteOnHide=1
   463     let g:HGCommandDeleteOnHide=1
   523   endif
   464   endif
   524 endfunction
   465 endfunction
   525 
   466 
   526 " Function: s:CVSDoCommand(cvscmd, cmdName, statusText) {{{2
   467 " Function: s:HGDoCommand(hgcmd, cmdName, statusText) {{{2
   527 " General skeleton for CVS function execution.
   468 " General skeleton for HG function execution.
   528 " Returns: name of the new command buffer containing the command results
   469 " Returns: name of the new command buffer containing the command results
   529 
   470 
   530 function! s:CVSDoCommand(cmd, cmdName, statusText)
   471 function! s:HGDoCommand(cmd, cmdName, statusText)
   531   let cvsBufferCheck=s:CVSCurrentBufferCheck()
   472   let hgBufferCheck=s:HGCurrentBufferCheck()
   532   if cvsBufferCheck == -1 
   473   if hgBufferCheck == -1 
   533     echo "Original buffer no longer exists, aborting."
   474     echo "Original buffer no longer exists, aborting."
   534     return -1
   475     return -1
   535   endif
   476   endif
   536 
   477 
   537   let fileName=bufname(cvsBufferCheck)
   478   let fileName=bufname(hgBufferCheck)
   538   if isdirectory(fileName)
   479   if isdirectory(fileName)
   539     let fileName=fileName . "/" . getline(".")
   480     let fileName=fileName . "/" . getline(".")
   540   endif
   481   endif
   541   let realFileName = fnamemodify(s:CVSResolveLink(fileName), ':t')
   482   let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t')
   542   let oldCwd=s:CVSChangeToCurrentFileDir(fileName)
   483   let oldCwd=s:HGChangeToCurrentFileDir(fileName)
   543   try
   484   try
   544     if !filereadable('CVS/Root')
   485      " TODO
   545       throw fileName . ' is not a CVS-controlled file.'
   486     "if !filereadable('HG/Root')
   546     endif
   487       "throw fileName . ' is not a HG-controlled file.'
       
   488     "endif
   547     let fullCmd = a:cmd . ' "' . realFileName . '"'
   489     let fullCmd = a:cmd . ' "' . realFileName . '"'
   548     let resultBuffer=s:CVSCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, cvsBufferCheck)
   490     "echomsg "DEBUG".fullCmd
       
   491     let resultBuffer=s:HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck)
   549     return resultBuffer
   492     return resultBuffer
   550   catch
   493   catch
   551     echoerr v:exception
   494     echoerr v:exception
   552     return -1
   495     return -1
   553   finally
   496   finally
   554     execute 'cd' escape(oldCwd, ' ')
   497     execute 'cd' escape(oldCwd, ' ')
   555   endtry
   498   endtry
   556 endfunction
   499 endfunction
   557 
   500 
   558 
   501 
   559 " Function: s:CVSGetStatusVars(revision, branch, repository) {{{2
   502 " Function: s:HGGetStatusVars(revision, branch, repository) {{{2
   560 "
   503 "
   561 " Obtains a CVS revision number and branch name.  The 'revisionVar',
   504 " Obtains a HG revision number and branch name.  The 'revisionVar',
   562 " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold
   505 " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold
   563 " the corresponding results.
   506 " the corresponding results.
   564 "
   507 "
   565 " Returns: string to be exec'd that sets the multiple return values.
   508 " Returns: string to be exec'd that sets the multiple return values.
   566 
   509 
   567 function! s:CVSGetStatusVars(revisionVar, branchVar, repositoryVar)
   510 function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar)
   568   let cvsBufferCheck=s:CVSCurrentBufferCheck()
   511   let hgBufferCheck=s:HGCurrentBufferCheck()
   569   if cvsBufferCheck == -1 
   512   if hgBufferCheck == -1 
   570     return ""
   513     return ""
   571   endif
   514   endif
   572   let fileName=bufname(cvsBufferCheck)
   515   let fileName=bufname(hgBufferCheck)
   573   let realFileName = fnamemodify(s:CVSResolveLink(fileName), ':t')
   516   let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t')
   574   let oldCwd=s:CVSChangeToCurrentFileDir(fileName)
   517   let oldCwd=s:HGChangeToCurrentFileDir(fileName)
   575   try
   518   try
   576     if !filereadable('CVS/Root')
   519      ""TODO
   577       return ""
   520     "if !filereadable('HG/Root')
   578     endif
   521       "return ""
   579     let cvsCommand = s:CVSGetOption("CVSCommandCVSExec", "cvs") . " status " . escape(realFileName, ' *?\')
   522     "endif
   580     let statustext=system(cvsCommand)
   523     let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . fileName
       
   524     let statustext=system(hgCommand)
   581     if(v:shell_error)
   525     if(v:shell_error)
   582       return ""
   526       return ""
   583     endif
   527     endif
   584     let revision=substitute(statustext, '^\_.*Working revision:\s*\(\d\+\%(\.\d\+\)\+\|New file!\)\_.*$', '\1', "")
   528     if match(statustext, '^[?I]') >= 0 
   585 
       
   586     " We can still be in a CVS-controlled directory without this being a CVS
       
   587     " file
       
   588     if match(revision, '^New file!$') >= 0 
       
   589       let revision="NEW"
   529       let revision="NEW"
   590     elseif match(revision, '^\d\+\.\d\+\%(\.\d\+\.\d\+\)*$') >=0
   530     elseif match(statustext, '^[R]') >= 0 
       
   531       let revision="REMOVED"
       
   532     elseif match(statustext, '^[D]') >= 0 
       
   533       let revision="DELETED"
       
   534     elseif match(statustext, '^[A]') >= 0 
       
   535       let revision="ADDED"
       
   536     endif
       
   537 
       
   538     let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b  " 
       
   539     let statustext=system(hgCommand)
       
   540     if(v:shell_error)
       
   541         return ""
       
   542     endif
       
   543     if exists('revision')
       
   544       let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
   591     else
   545     else
   592       return ""
   546       let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
   593     endif
   547       let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
   594 
   548     endif
   595     let returnExpression = "let " . a:revisionVar . "='" . revision . "'"
   549 
   596 
   550     if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
   597     if a:branchVar != ""
   551       let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
   598       let branch=substitute(statustext, '^\_.*Sticky Tag:\s\+\(\d\+\%(\.\d\+\)\+\|\a[A-Za-z0-9-_]*\|(none)\).*$', '\1', "")
       
   599       let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
   552       let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
   600     endif
   553     endif
   601 
       
   602     if a:repositoryVar != ""
   554     if a:repositoryVar != ""
   603       let repository=substitute(statustext, '^\_.*Repository revision:\s*\(\d\+\%(\.\d\+\)\+\|New file!\|No revision control file\)\_.*$', '\1', "")
   555       let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " root  " 
   604       let repository=substitute(repository, '^New file!\|No revision control file$', 'NEW', "")
   556       let roottext=system(hgCommand)
       
   557       let repository=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','')
   605       let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . repository . "'"
   558       let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . repository . "'"
   606     endif
   559     endif
       
   560 
       
   561 
   607 
   562 
   608     return returnExpression
   563     return returnExpression
   609   finally
   564   finally
   610     execute 'cd' escape(oldCwd, ' ')
   565     execute 'cd' escape(oldCwd, ' ')
   611   endtry
   566   endtry
   612 endfunction
   567 endfunction
   613 
   568 
   614 " Function: s:CVSSetupBuffer() {{{2
   569 " Function: s:HGSetupBuffer() {{{2
   615 " Attempts to set the b:CVSBranch, b:CVSRevision and b:CVSRepository variables.
   570 " Attempts to set the b:HGBranch, b:HGRevision and b:HGRepository variables.
   616 
   571 
   617 function! s:CVSSetupBuffer()
   572 function! s:HGSetupBuffer()
   618   if (exists("b:CVSBufferSetup") && b:CVSBufferSetup)
   573   if (exists("b:HGBufferSetup") && b:HGBufferSetup)
   619     " This buffer is already set up.
   574     " This buffer is already set up.
   620     return
   575     return
   621   endif
   576   endif
   622 
   577 
   623   if !s:CVSGetOption("CVSCommandEnableBufferSetup", 0)
   578   if !s:HGGetOption("HGCommandEnableBufferSetup", 0)
   624         \ || @% == ""
   579         \ || @% == ""
   625         \ || s:CVSCommandEditFileRunning > 0
   580         \ || s:HGCommandEditFileRunning > 0
   626         \ || exists("b:CVSOrigBuffNR")
   581         \ || exists("b:HGOrigBuffNR")
   627     unlet! b:CVSRevision
   582     unlet! b:HGRevision
   628     unlet! b:CVSBranch
   583     unlet! b:HGBranch
   629     unlet! b:CVSRepository
   584     unlet! b:HGRepository
   630     return
   585     return
   631   endif
   586   endif
   632 
   587 
   633   if !filereadable(expand("%"))
   588   if !filereadable(expand("%"))
   634     return -1
   589     return -1
   636 
   591 
   637   let revision=""
   592   let revision=""
   638   let branch=""
   593   let branch=""
   639   let repository=""
   594   let repository=""
   640 
   595 
   641   exec s:CVSGetStatusVars('revision', 'branch', 'repository')
   596   exec s:HGGetStatusVars('revision', 'branch', 'repository')
       
   597   "echomsg "DBG ".revision."#".branch."#".repository
   642   if revision != ""
   598   if revision != ""
   643     let b:CVSRevision=revision
   599     let b:HGRevision=revision
   644   else
   600   else
   645     unlet! b:CVSRevision
   601     unlet! b:HGRevision
   646   endif
   602   endif
   647   if branch != ""
   603   if branch != ""
   648     let b:CVSBranch=branch
   604     let b:HGBranch=branch
   649   else
   605   else
   650     unlet! b:CVSBranch
   606     unlet! b:HGBranch
   651   endif
   607   endif
   652   if repository != ""
   608   if repository != ""
   653      let b:CVSRepository=repository
   609      let b:HGRepository=repository
   654   else
   610   else
   655      unlet! b:CVSRepository
   611      unlet! b:HGRepository
   656   endif
   612   endif
   657   silent do CVSCommand User CVSBufferSetup
   613   silent do HGCommand User HGBufferSetup
   658   let b:CVSBufferSetup=1
   614   let b:HGBufferSetup=1
   659 endfunction
   615 endfunction
   660 
   616 
   661 " Function: s:CVSMarkOrigBufferForSetup(cvsbuffer) {{{2
   617 " Function: s:HGMarkOrigBufferForSetup(hgbuffer) {{{2
   662 " Resets the buffer setup state of the original buffer for a given CVS buffer.
   618 " Resets the buffer setup state of the original buffer for a given HG buffer.
   663 " Returns:  The CVS buffer number in a passthrough mode.
   619 " Returns:  The HG buffer number in a passthrough mode.
   664 
   620 
   665 function! s:CVSMarkOrigBufferForSetup(cvsBuffer)
   621 function! s:HGMarkOrigBufferForSetup(hgBuffer)
   666   checktime
   622   checktime
   667   if a:cvsBuffer != -1
   623   if a:hgBuffer != -1
   668     let origBuffer = s:CVSBufferCheck(a:cvsBuffer)
   624     let origBuffer = s:HGBufferCheck(a:hgBuffer)
   669     "This should never not work, but I'm paranoid
   625     "This should never not work, but I'm paranoid
   670     if origBuffer != a:cvsBuffer
   626     if origBuffer != a:hgBuffer
   671       call setbufvar(origBuffer, "CVSBufferSetup", 0)
   627       call setbufvar(origBuffer, "HGBufferSetup", 0)
   672     endif
   628     endif
   673   endif
   629   endif
   674   return a:cvsBuffer
   630   return a:hgBuffer
   675 endfunction
   631 endfunction
   676 
   632 
   677 " Function: s:CVSOverrideOption(option, [value]) {{{2
   633 " Function: s:HGOverrideOption(option, [value]) {{{2
   678 " Provides a temporary override for the given CVS option.  If no value is
   634 " Provides a temporary override for the given HG option.  If no value is
   679 " passed, the override is disabled.
   635 " passed, the override is disabled.
   680 
   636 
   681 function! s:CVSOverrideOption(option, ...)
   637 function! s:HGOverrideOption(option, ...)
   682   if a:0 == 0
   638   if a:0 == 0
   683     unlet! s:{a:option}Override
   639     unlet! s:{a:option}Override
   684   else
   640   else
   685     let s:{a:option}Override = a:1
   641     let s:{a:option}Override = a:1
   686   endif
   642   endif
   687 endfunction
   643 endfunction
   688 
   644 
   689 " Function: s:CVSWipeoutCommandBuffers() {{{2
   645 " Function: s:HGWipeoutCommandBuffers() {{{2
   690 " Clears all current CVS buffers of the specified type for a given source.
   646 " Clears all current HG buffers of the specified type for a given source.
   691 
   647 
   692 function! s:CVSWipeoutCommandBuffers(originalBuffer, cvsCommand)
   648 function! s:HGWipeoutCommandBuffers(originalBuffer, hgCommand)
   693   let buffer = 1
   649   let buffer = 1
   694   while buffer <= bufnr('$')
   650   while buffer <= bufnr('$')
   695     if getbufvar(buffer, 'CVSOrigBuffNR') == a:originalBuffer
   651     if getbufvar(buffer, 'HGOrigBuffNR') == a:originalBuffer
   696       if getbufvar(buffer, 'CVSCommand') == a:cvsCommand
   652       if getbufvar(buffer, 'HGCommand') == a:hgCommand
   697         execute 'bw' buffer
   653         execute 'bw' buffer
   698       endif
   654       endif
   699     endif
   655     endif
   700     let buffer = buffer + 1
   656     let buffer = buffer + 1
   701   endwhile
   657   endwhile
   702 endfunction
   658 endfunction
   703 
   659 
   704 " Section: Public functions {{{1
   660 " Section: Public functions {{{1
   705 
   661 
   706 " Function: CVSGetRevision() {{{2
   662 " Function: HGGetRevision() {{{2
   707 " Global function for retrieving the current buffer's CVS revision number.
   663 " Global function for retrieving the current buffer's HG revision number.
   708 " Returns: Revision number or an empty string if an error occurs.
   664 " Returns: Revision number or an empty string if an error occurs.
   709 
   665 
   710 function! CVSGetRevision()
   666 function! HGGetRevision()
   711   let revision=""
   667   let revision=""
   712   exec s:CVSGetStatusVars('revision', '', '')
   668   exec s:HGGetStatusVars('revision', '', '')
   713   return revision
   669   return revision
   714 endfunction
   670 endfunction
   715 
   671 
   716 " Function: CVSDisableBufferSetup() {{{2
   672 " Function: HGDisableBufferSetup() {{{2
   717 " Global function for deactivating the buffer autovariables.
   673 " Global function for deactivating the buffer autovariables.
   718 
   674 
   719 function! CVSDisableBufferSetup()
   675 function! HGDisableBufferSetup()
   720   let g:CVSCommandEnableBufferSetup=0
   676   let g:HGCommandEnableBufferSetup=0
   721   silent! augroup! CVSCommandPlugin
   677   silent! augroup! HGCommandPlugin
   722 endfunction
   678 endfunction
   723 
   679 
   724 " Function: CVSEnableBufferSetup() {{{2
   680 " Function: HGEnableBufferSetup() {{{2
   725 " Global function for activating the buffer autovariables.
   681 " Global function for activating the buffer autovariables.
   726 
   682 
   727 function! CVSEnableBufferSetup()
   683 function! HGEnableBufferSetup()
   728   let g:CVSCommandEnableBufferSetup=1
   684   let g:HGCommandEnableBufferSetup=1
   729   augroup CVSCommandPlugin
   685   augroup HGCommandPlugin
   730     au!
   686     au!
   731     au BufEnter * call s:CVSSetupBuffer()
   687     au BufEnter * call s:HGSetupBuffer()
   732   augroup END
   688   augroup END
   733 
   689 
   734   " Only auto-load if the plugin is fully loaded.  This gives other plugins a
   690   " Only auto-load if the plugin is fully loaded.  This gives other plugins a
   735   " chance to run.
   691   " chance to run.
   736   if g:loaded_cvscommand == 2
   692   if g:loaded_hgcommand == 2
   737     call s:CVSSetupBuffer()
   693     call s:HGSetupBuffer()
   738   endif
   694   endif
   739 endfunction
   695 endfunction
   740 
   696 
   741 " Function: CVSGetStatusLine() {{{2
   697 " Function: HGGetStatusLine() {{{2
   742 " Default (sample) status line entry for CVS files.  This is only useful if
   698 " Default (sample) status line entry for HG files.  This is only useful if
   743 " CVS-managed buffer mode is on (see the CVSCommandEnableBufferSetup variable
   699 " HG-managed buffer mode is on (see the HGCommandEnableBufferSetup variable
   744 " for how to do this).
   700 " for how to do this).
   745 
   701 
   746 function! CVSGetStatusLine()
   702 function! HGGetStatusLine()
   747   if exists('b:CVSSourceFile')
   703   if exists('b:HGSourceFile')
   748     " This is a result buffer
   704     " This is a result buffer
   749     let value='[' . b:CVSCommand . ' ' . b:CVSSourceFile
   705     let value='[' . b:HGCommand . ' ' . b:HGSourceFile
   750     if exists('b:CVSStatusText')
   706     if exists('b:HGStatusText')
   751       let value=value . ' ' . b:CVSStatusText
   707       let value=value . ' ' . b:HGStatusText
   752     endif
   708     endif
   753     let value = value . ']'
   709     let value = value . ']'
   754     return value
   710     return value
   755   endif
   711   endif
   756 
   712 
   757   if exists('b:CVSRevision')
   713   if exists('b:HGRevision')
   758         \ && b:CVSRevision != ''
   714         \ && b:HGRevision != ''
   759         \ && exists('b:CVSBranch')
   715         \ && exists('b:HGBranch')
   760         \ && b:CVSBranch != ''
   716         \ && b:HGBranch != ''
   761         \ && exists('b:CVSRepository')
   717         \ && exists('b:HGRepository')
   762         \ && b:CVSRepository != ''
   718         \ && b:HGRepository != ''
   763         \ && exists('g:CVSCommandEnableBufferSetup')
   719         \ && exists('g:HGCommandEnableBufferSetup')
   764         \ && g:CVSCommandEnableBufferSetup
   720         \ && g:HGCommandEnableBufferSetup
   765     if b:CVSRevision == b:CVSRepository
   721    return '[HG ' . b:HGRepository . '/' . b:HGBranch .'/' . b:HGRevision . ']'
   766       return '[CVS ' . b:CVSBranch . '/' . b:CVSRevision . ']'
       
   767     else
       
   768       return '[CVS ' . b:CVSBranch . '/' . b:CVSRevision . '/' . b:CVSRepository . ']'
       
   769     endif
       
   770   else
   722   else
   771     return ''
   723     return ''
   772   endif
   724   endif
   773 endfunction
   725 endfunction
   774 
   726 
   775 " Section: CVS command functions {{{1
   727 " Section: HG command functions {{{1
   776 
   728 
   777 " Function: s:CVSAdd() {{{2
   729 " Function: s:HGAdd() {{{2
   778 function! s:CVSAdd()
   730 function! s:HGAdd()
   779   return s:CVSMarkOrigBufferForSetup(s:CVSDoCommand('add', 'cvsadd', ''))
   731   return s:HGMarkOrigBufferForSetup(s:HGDoCommand('add', 'hgadd', ''))
   780 endfunction
   732 endfunction
   781 
   733 
   782 " Function: s:CVSAnnotate(...) {{{2
   734 " Function: s:HGAnnotate(...) {{{2
   783 function! s:CVSAnnotate(...)
   735 function! s:HGAnnotate(...)
   784   if a:0 == 0
   736   if a:0 == 0
   785     if &filetype == "CVSAnnotate"
   737     if &filetype == "HGAnnotate"
   786       " This is a CVSAnnotate buffer.  Perform annotation of the version
   738       " This is a HGAnnotate buffer.  Perform annotation of the version
   787       " indicated by the current line.
   739       " indicated by the current line.
   788       let revision = substitute(getline("."),'\(^[0-9.]*\).*','\1','')
   740       let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','')
   789       let revmin = substitute(revision,'^[0-9.]*\.\([0-9]\+\)','\1','')
   741       if s:HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0
   790       let revmaj = substitute(revision,'^\([0-9.]*\)\.[0-9]\+','\1','')
   742         let revision = revision - 1
   791       if s:CVSGetOption('CVSCommandAnnotateParent', 0) != 0
       
   792         let revmin = revmin - 1
       
   793       endif
       
   794       if revmin == 0
       
   795         " Jump to ancestor branch
       
   796         let revision = substitute(revmaj,'^\([0-9.]*\)\.[0-9]\+','\1','')
       
   797       else
       
   798         let revision=revmaj . "." .  revmin
       
   799       endif
   743       endif
   800     else
   744     else
   801       let revision=CVSGetRevision()
   745       let revision=HGGetRevision()
   802       if revision == ""
   746       if revision == ""
   803         echoerr "Unable to obtain CVS version information."
   747         echoerr "Unable to obtain HG version information."
   804         return -1
   748         return -1
   805       endif
   749       endif
   806     endif
   750     endif
   807   else
   751   else
   808     let revision=a:1
   752     let revision=a:1
   811   if revision == "NEW"
   755   if revision == "NEW"
   812     echo "No annotatation available for new file."
   756     echo "No annotatation available for new file."
   813     return -1
   757     return -1
   814   endif
   758   endif
   815 
   759 
   816   let resultBuffer=s:CVSDoCommand('-q annotate -r ' . revision, 'cvsannotate', revision) 
   760   let resultBuffer=s:HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision) 
       
   761   echomsg "DBG: ".resultBuffer
   817   if resultBuffer !=  -1
   762   if resultBuffer !=  -1
   818     set filetype=CVSAnnotate
   763     set filetype=HGAnnotate
   819     " Remove header lines from standard error
       
   820     silent v/^\d\+\%(\.\d\+\)\+/d
       
   821   endif
   764   endif
   822 
   765 
   823   return resultBuffer
   766   return resultBuffer
   824 endfunction
   767 endfunction
   825 
   768 
   826 " Function: s:CVSCommit() {{{2
   769 " Function: s:HGCommit() {{{2
   827 function! s:CVSCommit(...)
   770 function! s:HGCommit(...)
   828   " Handle the commit message being specified.  If a message is supplied, it
   771   " Handle the commit message being specified.  If a message is supplied, it
   829   " is used; if bang is supplied, an empty message is used; otherwise, the
   772   " is used; if bang is supplied, an empty message is used; otherwise, the
   830   " user is provided a buffer from which to edit the commit message.
   773   " user is provided a buffer from which to edit the commit message.
   831   if a:2 != "" || a:1 == "!"
   774   if a:2 != "" || a:1 == "!"
   832     return s:CVSMarkOrigBufferForSetup(s:CVSDoCommand('commit -m "' . a:2 . '"', 'cvscommit', ''))
   775     return s:HGMarkOrigBufferForSetup(s:HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', ''))
   833   endif
   776   endif
   834 
   777 
   835   let cvsBufferCheck=s:CVSCurrentBufferCheck()
   778   let hgBufferCheck=s:HGCurrentBufferCheck()
   836   if cvsBufferCheck ==  -1
   779   if hgBufferCheck ==  -1
   837     echo "Original buffer no longer exists, aborting."
   780     echo "Original buffer no longer exists, aborting."
   838     return -1
   781     return -1
   839   endif
   782   endif
   840 
   783 
   841   " Protect against windows' backslashes in paths.  They confuse exec'd
   784   " Protect against windows' backslashes in paths.  They confuse exec'd
   845   try
   788   try
   846     set shellslash
   789     set shellslash
   847 
   790 
   848     let messageFileName = tempname()
   791     let messageFileName = tempname()
   849 
   792 
   850     let fileName=bufname(cvsBufferCheck)
   793     let fileName=bufname(hgBufferCheck)
   851     let realFilePath=s:CVSResolveLink(fileName)
   794     let realFilePath=s:HGResolveLink(fileName)
   852     let newCwd=fnamemodify(realFilePath, ':h')
   795     let newCwd=fnamemodify(realFilePath, ':h')
   853     if strlen(newCwd) == 0
   796     if strlen(newCwd) == 0
   854       " Account for autochdir being in effect, which will make this blank, but
   797       " Account for autochdir being in effect, which will make this blank, but
   855       " we know we'll be in the current directory for the original file.
   798       " we know we'll be in the current directory for the original file.
   856       let newCwd = getcwd()
   799       let newCwd = getcwd()
   857     endif
   800     endif
   858 
   801 
   859     let realFileName=fnamemodify(realFilePath, ':t')
   802     let realFileName=fnamemodify(realFilePath, ':t')
   860 
   803 
   861     if s:CVSEditFile(messageFileName, cvsBufferCheck) == -1
   804     if s:HGEditFile(messageFileName, hgBufferCheck) == -1
   862       return
   805       return
   863     endif
   806     endif
   864 
   807 
   865     " Protect against case and backslash issues in Windows.
   808     " Protect against case and backslash issues in Windows.
   866     let autoPattern = '\c' . messageFileName
   809     let autoPattern = '\c' . messageFileName
   867 
   810 
   868     " Ensure existance of group
   811     " Ensure existance of group
   869     augroup CVSCommit
   812     augroup HGCommit
   870     augroup END
   813     augroup END
   871 
   814 
   872     execute 'au CVSCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")'
   815     execute 'au HGCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")'
   873     execute 'au CVSCommit BufDelete' autoPattern 'au! CVSCommit * ' autoPattern
   816     execute 'au HGCommit BufDelete' autoPattern 'au! HGCommit * ' autoPattern
   874 
   817 
   875     " Create a commit mapping.  The mapping must clear all autocommands in case
   818     " Create a commit mapping.  The mapping must clear all autocommands in case
   876     " it is invoked when CVSCommandCommitOnWrite is active, as well as to not
   819     " it is invoked when HGCommandCommitOnWrite is active, as well as to not
   877     " invoke the buffer deletion autocommand.
   820     " invoke the buffer deletion autocommand.
   878 
   821 
   879     execute 'nnoremap <silent> <buffer> <Plug>CVSCommit '.
   822     execute 'nnoremap <silent> <buffer> <Plug>HGCommit '.
   880           \ ':au! CVSCommit * ' . autoPattern . '<CR>'.
   823           \ ':au! HGCommit * ' . autoPattern . '<CR>'.
   881           \ ':g/^CVS:/d<CR>'.
   824           \ ':g/^HG:/d<CR>'.
   882           \ ':update<CR>'.
   825           \ ':update<CR>'.
   883           \ ':call <SID>CVSFinishCommit("' . messageFileName . '",' .
   826           \ ':call <SID>HGFinishCommit("' . messageFileName . '",' .
   884           \                             '"' . newCwd . '",' .
   827           \                             '"' . newCwd . '",' .
   885           \                             '"' . realFileName . '",' .
   828           \                             '"' . realFileName . '",' .
   886           \                             cvsBufferCheck . ')<CR>'
   829           \                             hgBufferCheck . ')<CR>'
   887 
   830 
   888     silent 0put ='CVS: ----------------------------------------------------------------------'
   831     silent 0put ='HG: ----------------------------------------------------------------------'
   889     silent put =\"CVS: Enter Log.  Lines beginning with `CVS:' are removed automatically\"
   832     silent put =\"HG: Enter Log.  Lines beginning with `HG:' are removed automatically\"
   890     silent put ='CVS: Type <leader>cc (or your own <Plug>CVSCommit mapping)'
   833     silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)'
   891 
   834 
   892     if s:CVSGetOption('CVSCommandCommitOnWrite', 1) == 1
   835     if s:HGGetOption('HGCommandCommitOnWrite', 1) == 1
   893       execute 'au CVSCommit BufWritePre' autoPattern 'g/^CVS:/d'
   836       execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d'
   894       execute 'au CVSCommit BufWritePost' autoPattern 'call s:CVSFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . cvsBufferCheck . ') | au! * ' autoPattern
   837       execute 'au HGCommit BufWritePost' autoPattern 'call s:HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern
   895       silent put ='CVS: or write this buffer'
   838       silent put ='HG: or write this buffer'
   896     endif
   839     endif
   897 
   840 
   898     silent put ='CVS: to finish this commit operation'
   841     silent put ='HG: to finish this commit operation'
   899     silent put ='CVS: ----------------------------------------------------------------------'
   842     silent put ='HG: ----------------------------------------------------------------------'
   900     $
   843     $
   901     let b:CVSSourceFile=fileName
   844     let b:HGSourceFile=fileName
   902     let b:CVSCommand='CVSCommit'
   845     let b:HGCommand='HGCommit'
   903     set filetype=cvs
   846     set filetype=hg
   904   finally
   847   finally
   905     let &shellslash = shellSlashBak
   848     let &shellslash = shellSlashBak
   906   endtry
   849   endtry
   907 
   850 
   908 endfunction
   851 endfunction
   909 
   852 
   910 " Function: s:CVSDiff(...) {{{2
   853 " Function: s:HGDiff(...) {{{2
   911 function! s:CVSDiff(...)
   854 function! s:HGDiff(...)
   912   if a:0 == 1
   855   if a:0 == 1
   913     let revOptions = '-r' . a:1
   856     let revOptions = '-r' . a:1
   914     let caption = a:1 . ' -> current'
   857     let caption = a:1 . ' -> current'
   915   elseif a:0 == 2
   858   elseif a:0 == 2
   916     let revOptions = '-r' . a:1 . ' -r' . a:2
   859     let revOptions = '-r' . a:1 . ' -r' . a:2
   918   else
   861   else
   919     let revOptions = ''
   862     let revOptions = ''
   920     let caption = ''
   863     let caption = ''
   921   endif
   864   endif
   922 
   865 
   923   let cvsdiffopt=s:CVSGetOption('CVSCommandDiffOpt', 'wbBc')
   866   let hgdiffopt=s:HGGetOption('HGCommandDiffOpt', 'w')
   924 
   867 
   925   if cvsdiffopt == ""
   868   if hgdiffopt == ""
   926     let diffoptionstring=""
   869     let diffoptionstring=""
   927   else
   870   else
   928     let diffoptionstring=" -" . cvsdiffopt . " "
   871     let diffoptionstring=" -" . hgdiffopt . " "
   929   endif
   872   endif
   930 
   873 
   931   let resultBuffer = s:CVSDoCommand('diff ' . diffoptionstring . revOptions , 'cvsdiff', caption)
   874   let resultBuffer = s:HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption)
   932   if resultBuffer != -1 
   875   if resultBuffer != -1 
   933     set filetype=diff
   876     set filetype=diff
   934   endif
   877   endif
   935   return resultBuffer
   878   return resultBuffer
   936 endfunction
   879 endfunction
   937 
   880 
   938 " Function: s:CVSEdit() {{{2
   881 
   939 function! s:CVSEdit()
   882 " Function: s:HGGotoOriginal(["!]) {{{2
   940   return s:CVSDoCommand('edit', 'cvsedit', '')
   883 function! s:HGGotoOriginal(...)
   941 endfunction
   884   let origBuffNR = s:HGCurrentBufferCheck()
   942 
       
   943 " Function: s:CVSEditors() {{{2
       
   944 function! s:CVSEditors()
       
   945   return s:CVSDoCommand('editors', 'cvseditors', '')
       
   946 endfunction
       
   947 
       
   948 " Function: s:CVSGotoOriginal(["!]) {{{2
       
   949 function! s:CVSGotoOriginal(...)
       
   950   let origBuffNR = s:CVSCurrentBufferCheck()
       
   951   if origBuffNR > 0
   885   if origBuffNR > 0
   952     let origWinNR = bufwinnr(origBuffNR)
   886     let origWinNR = bufwinnr(origBuffNR)
   953     if origWinNR == -1
   887     if origWinNR == -1
   954       execute 'buffer' origBuffNR
   888       execute 'buffer' origBuffNR
   955     else
   889     else
   958     if a:0 == 1
   892     if a:0 == 1
   959       if a:1 == "!"
   893       if a:1 == "!"
   960         let buffnr = 1
   894         let buffnr = 1
   961         let buffmaxnr = bufnr("$")
   895         let buffmaxnr = bufnr("$")
   962         while buffnr <= buffmaxnr
   896         while buffnr <= buffmaxnr
   963           if getbufvar(buffnr, "CVSOrigBuffNR") == origBuffNR
   897           if getbufvar(buffnr, "HGOrigBuffNR") == origBuffNR
   964             execute "bw" buffnr
   898             execute "bw" buffnr
   965           endif
   899           endif
   966           let buffnr = buffnr + 1
   900           let buffnr = buffnr + 1
   967         endwhile
   901         endwhile
   968       endif
   902       endif
   969     endif
   903     endif
   970   endif
   904   endif
   971 endfunction
   905 endfunction
   972 
   906 
   973 " Function: s:CVSFinishCommit(messageFile, targetDir, targetFile) {{{2
   907 " Function: s:HGFinishCommit(messageFile, targetDir, targetFile) {{{2
   974 function! s:CVSFinishCommit(messageFile, targetDir, targetFile, origBuffNR)
   908 function! s:HGFinishCommit(messageFile, targetDir, targetFile, origBuffNR)
   975   if filereadable(a:messageFile)
   909   if filereadable(a:messageFile)
   976     let oldCwd=getcwd()
   910     let oldCwd=getcwd()
   977     if strlen(a:targetDir) > 0
   911     if strlen(a:targetDir) > 0
   978       execute 'cd' escape(a:targetDir, ' ')
   912       execute 'cd' escape(a:targetDir, ' ')
   979     endif
   913     endif
   980     let resultBuffer=s:CVSCreateCommandBuffer('commit -F "' . a:messageFile . '" "'. a:targetFile . '"', 'cvscommit', '', a:origBuffNR)
   914     let resultBuffer=s:HGCreateCommandBuffer('commit -F "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR)
   981     execute 'cd' escape(oldCwd, ' ')
   915     execute 'cd' escape(oldCwd, ' ')
   982     execute 'bw' escape(a:messageFile, ' *?\')
   916     execute 'bw' escape(a:messageFile, ' *?\')
   983     silent execute 'call delete("' . a:messageFile . '")'
   917     silent execute 'call delete("' . a:messageFile . '")'
   984     return s:CVSMarkOrigBufferForSetup(resultBuffer)
   918     return s:HGMarkOrigBufferForSetup(resultBuffer)
   985   else
   919   else
   986     echoerr "Can't read message file; no commit is possible."
   920     echoerr "Can't read message file; no commit is possible."
   987     return -1
   921     return -1
   988   endif
   922   endif
   989 endfunction
   923 endfunction
   990 
   924 
   991 " Function: s:CVSLog() {{{2
   925 " Function: s:HGLog() {{{2
   992 function! s:CVSLog(...)
   926 function! s:HGLog(...)
   993   if a:0 == 0
   927   if a:0 == 0
   994     let versionOption = ""
   928     let versionOption = ""
   995     let caption = ''
   929     let caption = ''
   996   else
   930   else
   997     let versionOption=" -r" . a:1
   931     let versionOption=" -r" . a:1
   998     let caption = a:1
   932     let caption = a:1
   999   endif
   933   endif
  1000 
   934 
  1001   let resultBuffer=s:CVSDoCommand('log' . versionOption, 'cvslog', caption)
   935   let resultBuffer=s:HGDoCommand('log' . versionOption, 'hglog', caption)
  1002   if resultBuffer != ""
   936   if resultBuffer != ""
  1003     set filetype=rcslog
   937     set filetype=rcslog
  1004   endif
   938   endif
  1005   return resultBuffer
   939   return resultBuffer
  1006 endfunction
   940 endfunction
  1007 
   941 
  1008 " Function: s:CVSRevert() {{{2
   942 " Function: s:HGRevert() {{{2
  1009 function! s:CVSRevert()
   943 function! s:HGRevert()
  1010   return s:CVSMarkOrigBufferForSetup(s:CVSDoCommand('update -C', 'cvsrevert', ''))
   944   return s:HGMarkOrigBufferForSetup(s:HGDoCommand('revert', 'hgrevert', ''))
  1011 endfunction
   945 endfunction
  1012 
   946 
  1013 " Function: s:CVSReview(...) {{{2
   947 " Function: s:HGReview(...) {{{2
  1014 function! s:CVSReview(...)
   948 function! s:HGReview(...)
  1015   if a:0 == 0
   949   if a:0 == 0
  1016     let versiontag=""
   950     let versiontag=""
  1017     if s:CVSGetOption('CVSCommandInteractive', 0)
   951     if s:HGGetOption('HGCommandInteractive', 0)
  1018       let versiontag=input('Revision:  ')
   952       let versiontag=input('Revision:  ')
  1019     endif
   953     endif
  1020     if versiontag == ""
   954     if versiontag == ""
  1021       let versiontag="(current)"
   955       let versiontag="(current)"
  1022       let versionOption=""
   956       let versionOption=""
  1026   else
   960   else
  1027     let versiontag=a:1
   961     let versiontag=a:1
  1028     let versionOption=" -r " . versiontag . " "
   962     let versionOption=" -r " . versiontag . " "
  1029   endif
   963   endif
  1030 
   964 
  1031   let resultBuffer = s:CVSDoCommand('-q update -p' . versionOption, 'cvsreview', versiontag)
   965   let resultBuffer = s:HGDoCommand('cat' . versionOption, 'hgreview', versiontag)
  1032   if resultBuffer > 0
   966   if resultBuffer > 0
  1033     let &filetype=getbufvar(b:CVSOrigBuffNR, '&filetype')
   967     let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype')
  1034   endif
   968   endif
  1035 
   969 
  1036   return resultBuffer
   970   return resultBuffer
  1037 endfunction
   971 endfunction
  1038 
   972 
  1039 " Function: s:CVSStatus() {{{2
   973 " Function: s:HGStatus() {{{2
  1040 function! s:CVSStatus()
   974 function! s:HGStatus()
  1041   return s:CVSDoCommand('status', 'cvsstatus', '')
   975   return s:HGDoCommand('status', 'hgstatus', '')
  1042 endfunction
   976 endfunction
  1043 
   977 
  1044 " Function: s:CVSUnedit() {{{2
   978 
  1045 function! s:CVSUnedit()
   979 " Function: s:HGUpdate() {{{2
  1046   return s:CVSDoCommand('unedit', 'cvsunedit', '')
   980 function! s:HGUpdate()
  1047 endfunction
   981   return s:HGMarkOrigBufferForSetup(s:HGDoCommand('update', 'update', ''))
  1048 
   982 endfunction
  1049 " Function: s:CVSUpdate() {{{2
   983 
  1050 function! s:CVSUpdate()
   984 " Function: s:HGVimDiff(...) {{{2
  1051   return s:CVSMarkOrigBufferForSetup(s:CVSDoCommand('update', 'update', ''))
   985 function! s:HGVimDiff(...)
  1052 endfunction
   986   let originalBuffer = s:HGCurrentBufferCheck()
  1053 
   987   let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
  1054 " Function: s:CVSVimDiff(...) {{{2
       
  1055 function! s:CVSVimDiff(...)
       
  1056   let originalBuffer = s:CVSCurrentBufferCheck()
       
  1057   let s:CVSCommandEditFileRunning = s:CVSCommandEditFileRunning + 1
       
  1058   try
   988   try
  1059     " If there's already a VimDiff'ed window, restore it.
   989     " If there's already a VimDiff'ed window, restore it.
  1060     " There may only be one CVSVimDiff original window at a time.
   990     " There may only be one HGVimDiff original window at a time.
  1061 
   991 
  1062     if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
   992     if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer
  1063       " Clear the existing vimdiff setup by removing the result buffers.
   993       " Clear the existing vimdiff setup by removing the result buffers.
  1064       call s:CVSWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
   994       call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
  1065     endif
   995     endif
  1066 
   996 
  1067     " Split and diff
   997     " Split and diff
  1068     if(a:0 == 2)
   998     if(a:0 == 2)
  1069       " Reset the vimdiff system, as 2 explicit versions were provided.
   999       " Reset the vimdiff system, as 2 explicit versions were provided.
  1070       if exists('s:vimDiffSourceBuffer')
  1000       if exists('s:vimDiffSourceBuffer')
  1071         call s:CVSWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
  1001         call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
  1072       endif
  1002       endif
  1073       let resultBuffer = s:CVSReview(a:1)
  1003       let resultBuffer = s:HGReview(a:1)
  1074       if resultBuffer < 0
  1004       if resultBuffer < 0
  1075         echomsg "Can't open CVS revision " . a:1
  1005         echomsg "Can't open HG revision " . a:1
  1076         return resultBuffer
  1006         return resultBuffer
  1077       endif
  1007       endif
  1078       let b:CVSCommand = 'vimdiff'
  1008       let b:HGCommand = 'vimdiff'
  1079       diffthis
  1009       diffthis
  1080       let s:vimDiffBufferCount = 1
  1010       let s:vimDiffBufferCount = 1
  1081       let s:vimDiffScratchList = '{'. resultBuffer . '}'
  1011       let s:vimDiffScratchList = '{'. resultBuffer . '}'
  1082       " If no split method is defined, cheat, and set it to vertical.
  1012       " If no split method is defined, cheat, and set it to vertical.
  1083       try
  1013       try
  1084         call s:CVSOverrideOption('CVSCommandSplit', s:CVSGetOption('CVSCommandDiffSplit', s:CVSGetOption('CVSCommandSplit', 'vertical')))
  1014         call s:HGOverrideOption('HGCommandSplit', s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
  1085         let resultBuffer=s:CVSReview(a:2)
  1015         let resultBuffer=s:HGReview(a:2)
  1086       finally
  1016       finally
  1087         call s:CVSOverrideOption('CVSCommandSplit')
  1017         call s:HGOverrideOption('HGCommandSplit')
  1088       endtry
  1018       endtry
  1089       if resultBuffer < 0
  1019       if resultBuffer < 0
  1090         echomsg "Can't open CVS revision " . a:1
  1020         echomsg "Can't open HG revision " . a:1
  1091         return resultBuffer
  1021         return resultBuffer
  1092       endif
  1022       endif
  1093       let b:CVSCommand = 'vimdiff'
  1023       let b:HGCommand = 'vimdiff'
  1094       diffthis
  1024       diffthis
  1095       let s:vimDiffBufferCount = 2
  1025       let s:vimDiffBufferCount = 2
  1096       let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}'
  1026       let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}'
  1097     else
  1027     else
  1098       " Add new buffer
  1028       " Add new buffer
  1099       try
  1029       try
  1100         " Force splitting behavior, otherwise why use vimdiff?
  1030         " Force splitting behavior, otherwise why use vimdiff?
  1101         call s:CVSOverrideOption("CVSCommandEdit", "split")
  1031         call s:HGOverrideOption("HGCommandEdit", "split")
  1102         call s:CVSOverrideOption("CVSCommandSplit", s:CVSGetOption('CVSCommandDiffSplit', s:CVSGetOption('CVSCommandSplit', 'vertical')))
  1032         call s:HGOverrideOption("HGCommandSplit", s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical')))
  1103         if(a:0 == 0)
  1033         if(a:0 == 0)
  1104           let resultBuffer=s:CVSReview()
  1034           let resultBuffer=s:HGReview()
  1105         else
  1035         else
  1106           let resultBuffer=s:CVSReview(a:1)
  1036           let resultBuffer=s:HGReview(a:1)
  1107         endif
  1037         endif
  1108       finally
  1038       finally
  1109         call s:CVSOverrideOption("CVSCommandEdit")
  1039         call s:HGOverrideOption("HGCommandEdit")
  1110         call s:CVSOverrideOption("CVSCommandSplit")
  1040         call s:HGOverrideOption("HGCommandSplit")
  1111       endtry
  1041       endtry
  1112       if resultBuffer < 0
  1042       if resultBuffer < 0
  1113         echomsg "Can't open current CVS revision"
  1043         echomsg "Can't open current HG revision"
  1114         return resultBuffer
  1044         return resultBuffer
  1115       endif
  1045       endif
  1116       let b:CVSCommand = 'vimdiff'
  1046       let b:HGCommand = 'vimdiff'
  1117       diffthis
  1047       diffthis
  1118 
  1048 
  1119       if !exists('s:vimDiffBufferCount')
  1049       if !exists('s:vimDiffBufferCount')
  1120         " New instance of vimdiff.
  1050         " New instance of vimdiff.
  1121         let s:vimDiffBufferCount = 2
  1051         let s:vimDiffBufferCount = 2
  1122         let s:vimDiffScratchList = '{' . resultBuffer . '}'
  1052         let s:vimDiffScratchList = '{' . resultBuffer . '}'
  1123 
  1053 
  1124         " This could have been invoked on a CVS result buffer, not the
  1054         " This could have been invoked on a HG result buffer, not the
  1125         " original buffer.
  1055         " original buffer.
  1126         wincmd W
  1056         wincmd W
  1127         execute 'buffer' originalBuffer
  1057         execute 'buffer' originalBuffer
  1128         " Store info for later original buffer restore
  1058         " Store info for later original buffer restore
  1129         let s:vimDiffRestoreCmd = 
  1059         let s:vimDiffRestoreCmd = 
  1149 
  1079 
  1150     let currentBuffer = bufnr('%')
  1080     let currentBuffer = bufnr('%')
  1151     let saveModeline = getbufvar(currentBuffer, '&modeline')
  1081     let saveModeline = getbufvar(currentBuffer, '&modeline')
  1152     try
  1082     try
  1153       call setbufvar(currentBuffer, '&modeline', 0)
  1083       call setbufvar(currentBuffer, '&modeline', 0)
  1154       silent do CVSCommand User CVSVimDiffFinish
  1084       silent do HGCommand User HGVimDiffFinish
  1155     finally
  1085     finally
  1156       call setbufvar(currentBuffer, '&modeline', saveModeline)
  1086       call setbufvar(currentBuffer, '&modeline', saveModeline)
  1157     endtry
  1087     endtry
  1158     return resultBuffer
  1088     return resultBuffer
  1159   finally
  1089   finally
  1160     let s:CVSCommandEditFileRunning = s:CVSCommandEditFileRunning - 1
  1090     let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
  1161   endtry
  1091   endtry
  1162 endfunction
       
  1163 
       
  1164 " Function: s:CVSWatch(onoff) {{{2
       
  1165 function! s:CVSWatch(onoff)
       
  1166   if a:onoff !~ '^\c\%(on\|off\|add\|remove\)$'
       
  1167     echoerr "Argument to CVSWatch must be one of [on|off|add|remove]"
       
  1168     return -1
       
  1169   end
       
  1170   return s:CVSDoCommand('watch ' . tolower(a:onoff), 'cvswatch', '')
       
  1171 endfunction
       
  1172 
       
  1173 " Function: s:CVSWatchers() {{{2
       
  1174 function! s:CVSWatchers()
       
  1175   return s:CVSDoCommand('watchers', 'cvswatchers', '')
       
  1176 endfunction
  1092 endfunction
  1177 
  1093 
  1178 " Section: Command definitions {{{1
  1094 " Section: Command definitions {{{1
  1179 " Section: Primary commands {{{2
  1095 " Section: Primary commands {{{2
  1180 com! CVSAdd call s:CVSAdd()
  1096 com! HGAdd call s:HGAdd()
  1181 com! -nargs=? CVSAnnotate call s:CVSAnnotate(<f-args>)
  1097 com! -nargs=? HGAnnotate call s:HGAnnotate(<f-args>)
  1182 com! -bang -nargs=? CVSCommit call s:CVSCommit(<q-bang>, <q-args>)
  1098 com! -bang -nargs=? HGCommit call s:HGCommit(<q-bang>, <q-args>)
  1183 com! -nargs=* CVSDiff call s:CVSDiff(<f-args>)
  1099 com! -nargs=* HGDiff call s:HGDiff(<f-args>)
  1184 com! CVSEdit call s:CVSEdit()
  1100 com! -bang HGGotoOriginal call s:HGGotoOriginal(<q-bang>)
  1185 com! CVSEditors call s:CVSEditors()
  1101 com! -nargs=? HGLog call s:HGLog(<f-args>)
  1186 com! -bang CVSGotoOriginal call s:CVSGotoOriginal(<q-bang>)
  1102 com! HGRevert call s:HGRevert()
  1187 com! -nargs=? CVSLog call s:CVSLog(<f-args>)
  1103 com! -nargs=? HGReview call s:HGReview(<f-args>)
  1188 com! CVSRevert call s:CVSRevert()
  1104 com! HGStatus call s:HGStatus()
  1189 com! -nargs=? CVSReview call s:CVSReview(<f-args>)
  1105 com! HGUpdate call s:HGUpdate()
  1190 com! CVSStatus call s:CVSStatus()
  1106 com! -nargs=* HGVimDiff call s:HGVimDiff(<f-args>)
  1191 com! CVSUnedit call s:CVSUnedit()
  1107 
  1192 com! CVSUpdate call s:CVSUpdate()
  1108 " Section: HG buffer management commands {{{2
  1193 com! -nargs=* CVSVimDiff call s:CVSVimDiff(<f-args>)
  1109 com! HGDisableBufferSetup call HGDisableBufferSetup()
  1194 com! -nargs=1 CVSWatch call s:CVSWatch(<f-args>)
  1110 com! HGEnableBufferSetup call HGEnableBufferSetup()
  1195 com! CVSWatchAdd call s:CVSWatch('add')
  1111 
  1196 com! CVSWatchOn call s:CVSWatch('on')
  1112 " Allow reloading hgcommand.vim
  1197 com! CVSWatchOff call s:CVSWatch('off')
  1113 com! HGReload unlet! loaded_hgcommand | runtime plugin/hgcommand.vim
  1198 com! CVSWatchRemove call s:CVSWatch('remove')
       
  1199 com! CVSWatchers call s:CVSWatchers()
       
  1200 
       
  1201 " Section: CVS buffer management commands {{{2
       
  1202 com! CVSDisableBufferSetup call CVSDisableBufferSetup()
       
  1203 com! CVSEnableBufferSetup call CVSEnableBufferSetup()
       
  1204 
       
  1205 " Allow reloading cvscommand.vim
       
  1206 com! CVSReload unlet! loaded_cvscommand | runtime plugin/cvscommand.vim
       
  1207 
  1114 
  1208 " Section: Plugin command mappings {{{1
  1115 " Section: Plugin command mappings {{{1
  1209 nnoremap <silent> <Plug>CVSAdd :CVSAdd<CR>
  1116 nnoremap <silent> <Plug>HGAdd :HGAdd<CR>
  1210 nnoremap <silent> <Plug>CVSAnnotate :CVSAnnotate<CR>
  1117 nnoremap <silent> <Plug>HGAnnotate :HGAnnotate<CR>
  1211 nnoremap <silent> <Plug>CVSCommit :CVSCommit<CR>
  1118 nnoremap <silent> <Plug>HGCommit :HGCommit<CR>
  1212 nnoremap <silent> <Plug>CVSDiff :CVSDiff<CR>
  1119 nnoremap <silent> <Plug>HGDiff :HGDiff<CR>
  1213 nnoremap <silent> <Plug>CVSEdit :CVSEdit<CR>
  1120 nnoremap <silent> <Plug>HGGotoOriginal :HGGotoOriginal<CR>
  1214 nnoremap <silent> <Plug>CVSEditors :CVSEditors<CR>
  1121 nnoremap <silent> <Plug>HGClearAndGotoOriginal :HGGotoOriginal!<CR>
  1215 nnoremap <silent> <Plug>CVSGotoOriginal :CVSGotoOriginal<CR>
  1122 nnoremap <silent> <Plug>HGLog :HGLog<CR>
  1216 nnoremap <silent> <Plug>CVSClearAndGotoOriginal :CVSGotoOriginal!<CR>
  1123 nnoremap <silent> <Plug>HGRevert :HGRevert<CR>
  1217 nnoremap <silent> <Plug>CVSLog :CVSLog<CR>
  1124 nnoremap <silent> <Plug>HGReview :HGReview<CR>
  1218 nnoremap <silent> <Plug>CVSRevert :CVSRevert<CR>
  1125 nnoremap <silent> <Plug>HGStatus :HGStatus<CR>
  1219 nnoremap <silent> <Plug>CVSReview :CVSReview<CR>
  1126 nnoremap <silent> <Plug>HGUpdate :HGUpdate<CR>
  1220 nnoremap <silent> <Plug>CVSStatus :CVSStatus<CR>
  1127 nnoremap <silent> <Plug>HGVimDiff :HGVimDiff<CR>
  1221 nnoremap <silent> <Plug>CVSUnedit :CVSUnedit<CR>
  1128 nnoremap <silent> <Plug>HGWatchers :HGWatchers<CR>
  1222 nnoremap <silent> <Plug>CVSUpdate :CVSUpdate<CR>
  1129 nnoremap <silent> <Plug>HGWatchAdd :HGWatchAdd<CR>
  1223 nnoremap <silent> <Plug>CVSVimDiff :CVSVimDiff<CR>
  1130 nnoremap <silent> <Plug>HGWatchOn :HGWatchOn<CR>
  1224 nnoremap <silent> <Plug>CVSWatchers :CVSWatchers<CR>
  1131 nnoremap <silent> <Plug>HGWatchOff :HGWatchOff<CR>
  1225 nnoremap <silent> <Plug>CVSWatchAdd :CVSWatchAdd<CR>
  1132 nnoremap <silent> <Plug>HGWatchRemove :HGWatchRemove<CR>
  1226 nnoremap <silent> <Plug>CVSWatchOn :CVSWatchOn<CR>
       
  1227 nnoremap <silent> <Plug>CVSWatchOff :CVSWatchOff<CR>
       
  1228 nnoremap <silent> <Plug>CVSWatchRemove :CVSWatchRemove<CR>
       
  1229 
  1133 
  1230 " Section: Default mappings {{{1
  1134 " Section: Default mappings {{{1
  1231 if !hasmapto('<Plug>CVSAdd')
  1135 if !hasmapto('<Plug>HGAdd')
  1232   nmap <unique> <Leader>ca <Plug>CVSAdd
  1136   nmap <unique> <Leader>hga <Plug>HGAdd
  1233 endif
  1137 endif
  1234 if !hasmapto('<Plug>CVSAnnotate')
  1138 if !hasmapto('<Plug>HGAnnotate')
  1235   nmap <unique> <Leader>cn <Plug>CVSAnnotate
  1139   nmap <unique> <Leader>hgn <Plug>HGAnnotate
  1236 endif
  1140 endif
  1237 if !hasmapto('<Plug>CVSClearAndGotoOriginal')
  1141 if !hasmapto('<Plug>HGClearAndGotoOriginal')
  1238   nmap <unique> <Leader>cG <Plug>CVSClearAndGotoOriginal
  1142   nmap <unique> <Leader>hgG <Plug>HGClearAndGotoOriginal
  1239 endif
  1143 endif
  1240 if !hasmapto('<Plug>CVSCommit')
  1144 if !hasmapto('<Plug>HGCommit')
  1241   nmap <unique> <Leader>cc <Plug>CVSCommit
  1145   nmap <unique> <Leader>hgc <Plug>HGCommit
  1242 endif
  1146 endif
  1243 if !hasmapto('<Plug>CVSDiff')
  1147 if !hasmapto('<Plug>HGDiff')
  1244   nmap <unique> <Leader>cd <Plug>CVSDiff
  1148   nmap <unique> <Leader>hgd <Plug>HGDiff
  1245 endif
  1149 endif
  1246 if !hasmapto('<Plug>CVSEdit')
  1150 if !hasmapto('<Plug>HGGotoOriginal')
  1247   nmap <unique> <Leader>ce <Plug>CVSEdit
  1151   nmap <unique> <Leader>hgg <Plug>HGGotoOriginal
  1248 endif
  1152 endif
  1249 if !hasmapto('<Plug>CVSEditors')
  1153 if !hasmapto('<Plug>HGLog')
  1250   nmap <unique> <Leader>ci <Plug>CVSEditors
  1154   nmap <unique> <Leader>hgl <Plug>HGLog
  1251 endif
  1155 endif
  1252 if !hasmapto('<Plug>CVSGotoOriginal')
  1156 if !hasmapto('<Plug>HGRevert')
  1253   nmap <unique> <Leader>cg <Plug>CVSGotoOriginal
  1157   nmap <unique> <Leader>hgq <Plug>HGRevert
  1254 endif
  1158 endif
  1255 if !hasmapto('<Plug>CVSLog')
  1159 if !hasmapto('<Plug>HGReview')
  1256   nmap <unique> <Leader>cl <Plug>CVSLog
  1160   nmap <unique> <Leader>hgr <Plug>HGReview
  1257 endif
  1161 endif
  1258 if !hasmapto('<Plug>CVSRevert')
  1162 if !hasmapto('<Plug>HGStatus')
  1259   nmap <unique> <Leader>cq <Plug>CVSRevert
  1163   nmap <unique> <Leader>hgs <Plug>HGStatus
  1260 endif
  1164 endif
  1261 if !hasmapto('<Plug>CVSReview')
  1165 if !hasmapto('<Plug>HGUpdate')
  1262   nmap <unique> <Leader>cr <Plug>CVSReview
  1166   nmap <unique> <Leader>hgu <Plug>HGUpdate
  1263 endif
  1167 endif
  1264 if !hasmapto('<Plug>CVSStatus')
  1168 if !hasmapto('<Plug>HGVimDiff')
  1265   nmap <unique> <Leader>cs <Plug>CVSStatus
  1169   nmap <unique> <Leader>hgv <Plug>HGVimDiff
  1266 endif
       
  1267 if !hasmapto('<Plug>CVSUnedit')
       
  1268   nmap <unique> <Leader>ct <Plug>CVSUnedit
       
  1269 endif
       
  1270 if !hasmapto('<Plug>CVSUpdate')
       
  1271   nmap <unique> <Leader>cu <Plug>CVSUpdate
       
  1272 endif
       
  1273 if !hasmapto('<Plug>CVSVimDiff')
       
  1274   nmap <unique> <Leader>cv <Plug>CVSVimDiff
       
  1275 endif
       
  1276 if !hasmapto('<Plug>CVSWatchers')
       
  1277   nmap <unique> <Leader>cwv <Plug>CVSWatchers
       
  1278 endif
       
  1279 if !hasmapto('<Plug>CVSWatchAdd')
       
  1280   nmap <unique> <Leader>cwa <Plug>CVSWatchAdd
       
  1281 endif
       
  1282 if !hasmapto('<Plug>CVSWatchOn')
       
  1283   nmap <unique> <Leader>cwn <Plug>CVSWatchOn
       
  1284 endif
       
  1285 if !hasmapto('<Plug>CVSWatchOff')
       
  1286   nmap <unique> <Leader>cwf <Plug>CVSWatchOff
       
  1287 endif
       
  1288 if !hasmapto('<Plug>CVSWatchRemove')
       
  1289   nmap <unique> <Leader>cwr <Plug>CVSWatchRemove
       
  1290 endif
  1170 endif
  1291 
  1171 
  1292 " Section: Menu items {{{1
  1172 " Section: Menu items {{{1
  1293 silent! aunmenu Plugin.CVS
  1173 silent! aunmenu Plugin.HG
  1294 amenu <silent> &Plugin.CVS.&Add        <Plug>CVSAdd
  1174 amenu <silent> &Plugin.HG.&Add        <Plug>HGAdd
  1295 amenu <silent> &Plugin.CVS.A&nnotate   <Plug>CVSAnnotate
  1175 amenu <silent> &Plugin.HG.A&nnotate   <Plug>HGAnnotate
  1296 amenu <silent> &Plugin.CVS.&Commit     <Plug>CVSCommit
  1176 amenu <silent> &Plugin.HG.&Commit     <Plug>HGCommit
  1297 amenu <silent> &Plugin.CVS.&Diff       <Plug>CVSDiff
  1177 amenu <silent> &Plugin.HG.&Diff       <Plug>HGDiff
  1298 amenu <silent> &Plugin.CVS.&Edit       <Plug>CVSEdit
  1178 amenu <silent> &Plugin.HG.&Log        <Plug>HGLog
  1299 amenu <silent> &Plugin.CVS.Ed&itors    <Plug>CVSEditors
  1179 amenu <silent> &Plugin.HG.Revert      <Plug>HGRevert
  1300 amenu <silent> &Plugin.CVS.&Log        <Plug>CVSLog
  1180 amenu <silent> &Plugin.HG.&Review     <Plug>HGReview
  1301 amenu <silent> &Plugin.CVS.Revert      <Plug>CVSRevert
  1181 amenu <silent> &Plugin.HG.&Status     <Plug>HGStatus
  1302 amenu <silent> &Plugin.CVS.&Review     <Plug>CVSReview
  1182 amenu <silent> &Plugin.HG.&Update     <Plug>HGUpdate
  1303 amenu <silent> &Plugin.CVS.&Status     <Plug>CVSStatus
  1183 amenu <silent> &Plugin.HG.&VimDiff    <Plug>HGVimDiff
  1304 amenu <silent> &Plugin.CVS.Unedi&t     <Plug>CVSUnedit
  1184 amenu <silent> &Plugin.HG.&Watchers   <Plug>HGWatchers
  1305 amenu <silent> &Plugin.CVS.&Update     <Plug>CVSUpdate
  1185 amenu <silent> &Plugin.HG.WatchAdd    <Plug>HGWatchAdd
  1306 amenu <silent> &Plugin.CVS.&VimDiff    <Plug>CVSVimDiff
  1186 amenu <silent> &Plugin.HG.WatchOn     <Plug>HGWatchOn
  1307 amenu <silent> &Plugin.CVS.&Watchers   <Plug>CVSWatchers
  1187 amenu <silent> &Plugin.HG.WatchOff    <Plug>HGWatchOff
  1308 amenu <silent> &Plugin.CVS.WatchAdd    <Plug>CVSWatchAdd
  1188 amenu <silent> &Plugin.HG.WatchRemove <Plug>HGWatchRemove
  1309 amenu <silent> &Plugin.CVS.WatchOn     <Plug>CVSWatchOn
       
  1310 amenu <silent> &Plugin.CVS.WatchOff    <Plug>CVSWatchOff
       
  1311 amenu <silent> &Plugin.CVS.WatchRemove <Plug>CVSWatchRemove
       
  1312 
  1189 
  1313 " Section: Autocommands to restore vimdiff state {{{1
  1190 " Section: Autocommands to restore vimdiff state {{{1
  1314 function! s:CVSVimDiffRestore(vimDiffBuff)
  1191 function! s:HGVimDiffRestore(vimDiffBuff)
  1315   let s:CVSCommandEditFileRunning = s:CVSCommandEditFileRunning + 1
  1192   let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1
  1316   try
  1193   try
  1317     if exists("s:vimDiffSourceBuffer")
  1194     if exists("s:vimDiffSourceBuffer")
  1318       if a:vimDiffBuff == s:vimDiffSourceBuffer
  1195       if a:vimDiffBuff == s:vimDiffSourceBuffer
  1319         " Original file is being removed.
  1196         " Original file is being removed.
  1320         unlet! s:vimDiffSourceBuffer
  1197         unlet! s:vimDiffSourceBuffer
  1364           unlet s:vimDiffScratchList
  1241           unlet s:vimDiffScratchList
  1365         endif
  1242         endif
  1366       endif
  1243       endif
  1367     endif
  1244     endif
  1368   finally
  1245   finally
  1369     let s:CVSCommandEditFileRunning = s:CVSCommandEditFileRunning - 1
  1246     let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1
  1370   endtry
  1247   endtry
  1371 endfunction
  1248 endfunction
  1372 
  1249 
  1373 augroup CVSVimDiffRestore
  1250 augroup HGVimDiffRestore
  1374   au!
  1251   au!
  1375   au BufUnload * call s:CVSVimDiffRestore(expand("<abuf>"))
  1252   au BufUnload * call s:HGVimDiffRestore(expand("<abuf>"))
  1376 augroup END
  1253 augroup END
  1377 
  1254 
  1378 " Section: Optional activation of buffer management {{{1
  1255 " Section: Optional activation of buffer management {{{1
  1379 
  1256 
  1380 if s:CVSGetOption('CVSCommandEnableBufferSetup', 0)
  1257 if s:HGGetOption('HGCommandEnableBufferSetup', 0)
  1381   call CVSEnableBufferSetup()
  1258   call HGEnableBufferSetup()
  1382 endif
  1259 endif
  1383 
  1260 
  1384 " Section: Plugin completion {{{1
  1261 " Section: Plugin completion {{{1
  1385 
  1262 
  1386 let loaded_cvscommand=2
  1263 let loaded_hgcommand=2
  1387 silent do CVSCommand User CVSPluginFinish
  1264 silent do HGCommand User HGPluginFinish
       
  1265 " vim:se expandtab sts=2 sw=2: