summaryrefslogtreecommitdiff
path: root/.vim/plugin/vcscommand.vim
diff options
context:
space:
mode:
Diffstat (limited to '.vim/plugin/vcscommand.vim')
-rw-r--r--.vim/plugin/vcscommand.vim1344
1 files changed, 0 insertions, 1344 deletions
diff --git a/.vim/plugin/vcscommand.vim b/.vim/plugin/vcscommand.vim
deleted file mode 100644
index 2070e1a..0000000
--- a/.vim/plugin/vcscommand.vim
+++ /dev/null
@@ -1,1344 +0,0 @@
-" vim600: set foldmethod=marker:
-"
-" Vim plugin to assist in working with files under control of various Version
-" Control Systems, such as CVS, SVN, SVK, and git.
-"
-" Version: 1.99.31
-" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
-" License:
-" Copyright (c) 2008 Bob Hiestand
-"
-" Permission is hereby granted, free of charge, to any person obtaining a copy
-" of this software and associated documentation files (the "Software"), to
-" deal in the Software without restriction, including without limitation the
-" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-" sell copies of the Software, and to permit persons to whom the Software is
-" furnished to do so, subject to the following conditions:
-"
-" The above copyright notice and this permission notice shall be included in
-" all copies or substantial portions of the Software.
-"
-" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-" IN THE SOFTWARE.
-"
-" Section: Documentation {{{1
-"
-" Provides functions to invoke various source control commands on the current
-" file (either the current buffer, or, in the case of an directory buffer, the
-" directory and all subdirectories associated with the current buffer). The
-" output of the commands is captured in a new scratch window.
-"
-" This plugin needs additional extension plugins, each specific to a source
-" control system, to function. Those plugins should be placed in a
-" subdirectory of the standard plugin directory named 'vcscommand'. Several
-" options include the name of the version control system in the option name.
-" Such options use the placeholder text '{VCSType}', which would be replaced
-" in actual usage with 'CVS' or 'SVN', for instance.
-"
-" Command documentation {{{2
-"
-" VCSAdd Adds the current file to source control.
-"
-" VCSAnnotate[!] Displays the current file with each line annotated with the
-" version in which it was most recently changed. If an
-" argument is given, the argument is used as a revision
-" number to display. If not given an argument, it uses the
-" most recent version of the file on the current branch.
-" Additionally, if the current buffer is a VCSAnnotate buffer
-" already, the version number on the current line is used.
-"
-" If '!' is used, the view of the annotated buffer is split
-" so that the annotation is in a separate window from the
-" content, and each is highlighted separately.
-"
-" VCSBlame Alias for 'VCSAnnotate'.
-"
-" VCSCommit[!] Commits changes to the current file to source control.
-"
-" If called with arguments, the arguments are the log message.
-"
-" If '!' is used, an empty log message is committed.
-"
-" If called with no arguments, this is a two-step command.
-" The first step opens a buffer to accept a log message.
-" When that buffer is written, it is automatically closed and
-" the file is committed using the information from that log
-" message. The commit can be abandoned if the log message
-" buffer is deleted or wiped before being written.
-"
-" VCSDelete Deletes the current file and removes it from source control.
-"
-" VCSDiff With no arguments, this displays the differences between
-" the current file and its parent version under source
-" control in a new scratch buffer.
-"
-" With one argument, the diff is performed on the
-" current file against the specified revision.
-"
-" With two arguments, the diff is performed between the
-" specified revisions of the current file.
-"
-" This command uses the 'VCSCommand{VCSType}DiffOpt' variable
-" to specify diff options. If that variable does not exist,
-" a plugin-specific default is used. If you wish to have no
-" options, then set it to the empty string.
-"
-" VCSGotoOriginal Jumps to the source buffer if the current buffer is a VCS
-" scratch buffer. If VCSGotoOriginal[!] is used, remove all
-" VCS scratch buffers associated with the original file.
-"
-" VCSInfo Displays extended information about the current file in a
-" new scratch buffer.
-"
-" VCSLock Locks the current file in order to prevent other users from
-" concurrently modifying it. The exact semantics of this
-" command depend on the underlying VCS.
-"
-" VCSLog Displays the version history of the current file in a new
-" scratch buffer.
-"
-" VCSRemove Alias for 'VCSDelete'.
-"
-" VCSRevert Replaces the modified version of the current file with the
-" most recent version from the repository.
-"
-" VCSReview Displays a particular version of the current file in a new
-" scratch buffer. If no argument is given, the most recent
-" version of the file on the current branch is retrieved.
-"
-" VCSStatus Displays versioning information about the current file in a
-" new scratch buffer.
-"
-" VCSUnlock Unlocks the current file in order to allow other users from
-" concurrently modifying it. The exact semantics of this
-" command depend on the underlying VCS.
-"
-" VCSUpdate Updates the current file with any relevant changes from the
-" repository.
-"
-" VCSVimDiff Uses vimdiff to display differences between versions of the
-" current file.
-"
-" If no revision is specified, the most recent version of the
-" file on the current branch is used. With one argument,
-" that argument is used as the revision as above. With two
-" arguments, the differences between the two revisions is
-" displayed using vimdiff.
-"
-" With either zero or one argument, the original buffer is
-" used to perform the vimdiff. When the scratch buffer is
-" closed, the original buffer will be returned to normal
-" mode.
-"
-" Once vimdiff mode is started using the above methods,
-" additional vimdiff buffers may be added by passing a single
-" version argument to the command. There may be up to 4
-" vimdiff buffers total.
-"
-" Using the 2-argument form of the command resets the vimdiff
-" to only those 2 versions. Additionally, invoking the
-" command on a different file will close the previous vimdiff
-" buffers.
-"
-" Mapping documentation: {{{2
-"
-" By default, a mapping is defined for each command. User-provided mappings
-" can be used instead by mapping to <Plug>CommandName, for instance:
-"
-" nmap ,ca <Plug>VCSAdd
-"
-" The default mappings are as follow:
-"
-" <Leader>ca VCSAdd
-" <Leader>cn VCSAnnotate
-" <Leader>cN VCSAnnotate!
-" <Leader>cc VCSCommit
-" <Leader>cD VCSDelete
-" <Leader>cd VCSDiff
-" <Leader>cg VCSGotoOriginal
-" <Leader>cG VCSGotoOriginal!
-" <Leader>ci VCSInfo
-" <Leader>cl VCSLog
-" <Leader>cL VCSLock
-" <Leader>cr VCSReview
-" <Leader>cs VCSStatus
-" <Leader>cu VCSUpdate
-" <Leader>cU VCSUnlock
-" <Leader>cv VCSVimDiff
-"
-" Options documentation: {{{2
-"
-" Several variables are checked by the script to determine behavior as follow:
-"
-" VCSCommandCommitOnWrite
-" This variable, if set to a non-zero value, causes the pending commit to
-" take place immediately as soon as the log message buffer is written. If
-" set to zero, only the VCSCommit mapping will cause the pending commit to
-" occur. If not set, it defaults to 1.
-"
-" VCSCommandDeleteOnHide
-" This variable, if set to a non-zero value, causes the temporary VCS result
-" buffers to automatically delete themselves when hidden.
-"
-" VCSCommand{VCSType}DiffOpt
-" This variable, if set, determines the options passed to the diff command
-" of the underlying VCS. Each VCS plugin defines a default value.
-"
-" VCSCommandDiffSplit
-" This variable overrides the VCSCommandSplit variable, but only for buffers
-" created with VCSVimDiff.
-"
-" VCSCommandDisableAll
-" This variable, if set, prevents the plugin or any extensions from loading
-" at all. This is useful when a single runtime distribution is used on
-" multiple systems with varying versions.
-"
-" VCSCommandDisableMappings
-" This variable, if set to a non-zero value, prevents the default command
-" mappings from being set.
-"
-" VCSCommandDisableExtensionMappings
-" This variable, if set to a non-zero value, prevents the default command
-" mappings from being set for commands specific to an individual VCS.
-"
-" VCSCommandEdit
-" This variable controls whether to split the current window to display a
-" scratch buffer ('split'), or to display it in the current buffer ('edit').
-" If not set, it defaults to 'split'.
-"
-" VCSCommandEnableBufferSetup
-" This variable, if set to a non-zero value, activates VCS buffer management
-" mode. This mode means that the buffer variable 'VCSRevision' is set if
-" the file is VCS-controlled. This is useful for displaying version
-" information in the status bar. Additional options may be set by
-" individual VCS plugins.
-"
-" VCSCommandMappings
-" This variable, if set, overrides the default mappings used for shortcuts.
-" It should be a List of 2-element Lists, each containing a shortcut and
-" function name pair.
-"
-" VCSCommandMapPrefix
-" This variable, if set, overrides the default mapping prefix ('<Leader>c').
-" This allows customization of the mapping space used by the vcscommand
-" shortcuts.
-"
-" VCSCommandResultBufferNameExtension
-" This variable, if set to a non-blank value, is appended to the name of the
-" VCS command output buffers. For example, '.vcs'. Using this option may
-" help avoid problems caused by autocommands dependent on file extension.
-"
-" VCSCommandResultBufferNameFunction
-" This variable, if set, specifies a custom function for naming VCS command
-" output buffers. This function will be passed the following arguments:
-"
-" command - name of the VCS command being executed (such as 'Log' or
-" 'Diff').
-"
-" originalBuffer - buffer number of the source file.
-"
-" vcsType - type of VCS controlling this file (such as 'CVS' or 'SVN').
-"
-" statusText - extra text associated with the VCS action (such as version
-" numbers).
-"
-" VCSCommandSplit
-" This variable controls the orientation of the various window splits that
-" may occur (such as with VCSVimDiff, when using a VCS command on a VCS
-" command buffer, or when the 'VCSCommandEdit' variable is set to 'split'.
-" If set to 'horizontal', the resulting windows will be on stacked on top of
-" one another. If set to 'vertical', the resulting windows will be
-" side-by-side. If not set, it defaults to 'horizontal' for all but
-" VCSVimDiff windows.
-"
-" VCSCommandVCSTypeOverride
-" This variable allows the VCS type detection to be overridden on a
-" path-by-path basis. The value of this variable is expected to be a List
-" of Lists. Each high-level List item is a List containing two elements.
-" The first element is a regular expression that will be matched against the
-" full file name of a given buffer. If it matches, the second element will
-" be used as the VCS type.
-"
-" Event documentation {{{2
-" For additional customization, VCSCommand.vim uses User event autocommand
-" hooks. Each event is in the VCSCommand group, and different patterns
-" match the various hooks.
-"
-" For instance, the following could be added to the vimrc to provide a 'q'
-" mapping to quit a VCS scratch buffer:
-"
-" augroup VCSCommand
-" au VCSCommand User VCSBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr>
-" augroup END
-"
-" The following hooks are available:
-"
-" VCSBufferCreated This event is fired just after a VCS command
-" output buffer is created. It is executed
-" within the context of the new buffer.
-"
-" VCSBufferSetup This event is fired just after VCS buffer setup
-" occurs, if enabled.
-"
-" VCSPluginInit This event is fired when the VCSCommand plugin
-" first loads.
-"
-" VCSPluginFinish This event is fired just after the VCSCommand
-" plugin loads.
-"
-" VCSVimDiffFinish This event is fired just after the VCSVimDiff
-" command executes to allow customization of,
-" for instance, window placement and focus.
-"
-" Section: Plugin header {{{1
-
-" loaded_VCSCommand is set to 1 when the initialization begins, and 2 when it
-" completes. This allows various actions to only be taken by functions after
-" system initialization.
-
-if exists('VCSCommandDisableAll')
- finish
-endif
-
-if exists('loaded_VCSCommand')
- finish
-endif
-let loaded_VCSCommand = 1
-
-if v:version < 700
- echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
- finish
-endif
-
-let s:save_cpo=&cpo
-set cpo&vim
-
-" Section: Event group setup {{{1
-
-augroup VCSCommand
-augroup END
-
-augroup VCSCommandCommit
-augroup END
-
-" Section: Plugin initialization {{{1
-silent do VCSCommand User VCSPluginInit
-
-" Section: Constants declaration {{{1
-
-let g:VCSCOMMAND_IDENTIFY_EXACT = 1
-let g:VCSCOMMAND_IDENTIFY_INEXACT = -1
-
-" Section: Script variable initialization {{{1
-
-" plugin-specific information: {vcs -> [script, {command -> function}, {key -> mapping}]}
-let s:plugins = {}
-
-" temporary values of overridden configuration variables
-let s:optionOverrides = {}
-
-" state flag used to vary behavior of certain automated actions
-let s:isEditFileRunning = 0
-
-" commands needed to restore diff buffers to their original state
-unlet! s:vimDiffRestoreCmd
-
-" original buffer currently reflected in vimdiff windows
-unlet! s:vimDiffSourceBuffer
-
-"
-unlet! s:vimDiffScratchList
-
-" Section: Utility functions {{{1
-
-" Function: s:ReportError(mapping) {{{2
-" Displays the given error in a consistent faction. This is intended to be
-" invoked from a catch statement.
-
-function! s:ReportError(error)
- echohl WarningMsg|echomsg 'VCSCommand: ' . a:error|echohl None
-endfunction
-
-
-" Function: s:CreateMapping(shortcut, expansion, display) {{{2
-" Creates the given mapping by prepending the contents of
-" 'VCSCommandMapPrefix' (by default '<Leader>c') to the given shortcut and
-" mapping it to the given plugin function. If a mapping exists for the
-" specified shortcut + prefix, emit an error but continue. If a mapping
-" exists for the specified function, do nothing.
-
-function! s:CreateMapping(shortcut, expansion, display)
- let lhs = VCSCommandGetOption('VCSCommandMapPrefix', '<Leader>c') . a:shortcut
- if !hasmapto(a:expansion)
- try
- execute 'nmap <silent> <unique>' lhs a:expansion
- catch /^Vim(.*):E227:/
- if(&verbose != 0)
- echohl WarningMsg|echomsg 'VCSCommand: mapping ''' . lhs . ''' already exists, refusing to overwrite. The mapping for ' . a:display . ' will not be available.'|echohl None
- endif
- endtry
- endif
-endfunction
-
-" Function: s:ExecuteExtensionMapping(mapping) {{{2
-" Invokes the appropriate extension mapping depending on the type of the
-" current buffer.
-
-function! s:ExecuteExtensionMapping(mapping)
- let buffer = bufnr('%')
- let vcsType = VCSCommandGetVCSType(buffer)
- if !has_key(s:plugins, vcsType)
- throw 'Unknown VCS type: ' . vcsType
- endif
- if !has_key(s:plugins[vcsType][2], a:mapping)
- throw 'This extended mapping is not defined for ' . vcsType
- endif
- silent execute 'normal' ':' . s:plugins[vcsType][2][a:mapping] . "\<CR>"
-endfunction
-
-" Function: s:ExecuteVCSCommand(command, argList) {{{2
-" Calls the indicated plugin-specific VCS command on the current buffer.
-" Returns: buffer number of resulting output scratch buffer, or -1 if an error
-" occurs.
-
-function! s:ExecuteVCSCommand(command, argList)
- try
- let buffer = bufnr('%')
-
- let vcsType = VCSCommandGetVCSType(buffer)
- if !has_key(s:plugins, vcsType)
- throw 'Unknown VCS type: ' . vcsType
- endif
-
- let originalBuffer = VCSCommandGetOriginalBuffer(buffer)
- let bufferName = bufname(originalBuffer)
-
- " It is already known that the directory is under VCS control. No further
- " checks are needed. Otherwise, perform some basic sanity checks to avoid
- " VCS-specific error messages from confusing things.
- if !isdirectory(bufferName)
- if !filereadable(bufferName)
- throw 'No such file ' . bufferName
- endif
- endif
-
- let functionMap = s:plugins[vcsType][1]
- if !has_key(functionMap, a:command)
- throw 'Command ''' . a:command . ''' not implemented for ' . vcsType
- endif
- return functionMap[a:command](a:argList)
- catch
- call s:ReportError(v:exception)
- return -1
- endtry
-endfunction
-
-" Function: s:GenerateResultBufferName(command, originalBuffer, vcsType, statusText) {{{2
-" Default method of generating the name for VCS result buffers. This can be
-" overridden with the VCSResultBufferNameFunction variable.
-
-function! s:GenerateResultBufferName(command, originalBuffer, vcsType, statusText)
- let fileName = bufname(a:originalBuffer)
- let bufferName = a:vcsType . ' ' . a:command
- if strlen(a:statusText) > 0
- let bufferName .= ' ' . a:statusText
- endif
- let bufferName .= ' ' . fileName
- let counter = 0
- let versionedBufferName = bufferName
- while buflisted(versionedBufferName)
- let counter += 1
- let versionedBufferName = bufferName . ' (' . counter . ')'
- endwhile
- return versionedBufferName
-endfunction
-
-" Function: s:GenerateResultBufferNameWithExtension(command, originalBuffer, vcsType, statusText) {{{2
-" Method of generating the name for VCS result buffers that uses the original
-" file name with the VCS type and command appended as extensions.
-
-function! s:GenerateResultBufferNameWithExtension(command, originalBuffer, vcsType, statusText)
- let fileName = bufname(a:originalBuffer)
- let bufferName = a:vcsType . ' ' . a:command
- if strlen(a:statusText) > 0
- let bufferName .= ' ' . a:statusText
- endif
- let bufferName .= ' ' . fileName . VCSCommandGetOption('VCSCommandResultBufferNameExtension', '.vcs')
- let counter = 0
- let versionedBufferName = bufferName
- while buflisted(versionedBufferName)
- let counter += 1
- let versionedBufferName = '(' . counter . ') ' . bufferName
- endwhile
- return versionedBufferName
-endfunction
-
-" Function: s:EditFile(command, originalBuffer, statusText) {{{2
-" Creates a new buffer of the given name and associates it with the given
-" original buffer.
-
-function! s:EditFile(command, originalBuffer, statusText)
- let vcsType = getbufvar(a:originalBuffer, 'VCSCommandVCSType')
-
- " Protect against useless buffer set-up
- let s:isEditFileRunning += 1
- try
- let editCommand = VCSCommandGetOption('VCSCommandEdit', 'split')
- if editCommand == 'split'
- if VCSCommandGetOption('VCSCommandSplit', 'horizontal') == 'horizontal'
- rightbelow split
- else
- vert rightbelow split
- endif
- endif
-
- enew
-
- call s:SetupScratchBuffer(a:command, vcsType, a:originalBuffer, a:statusText)
-
- finally
- let s:isEditFileRunning -= 1
- endtry
-endfunction
-
-" Function: s:SetupScratchBuffer(command, vcsType, originalBuffer, statusText) {{{2
-" Creates convenience buffer variables and the name of a vcscommand result
-" buffer.
-
-function! s:SetupScratchBuffer(command, vcsType, originalBuffer, statusText)
- let nameExtension = VCSCommandGetOption('VCSCommandResultBufferNameExtension', '')
- if nameExtension == ''
- let nameFunction = VCSCommandGetOption('VCSCommandResultBufferNameFunction', 's:GenerateResultBufferName')
- else
- let nameFunction = VCSCommandGetOption('VCSCommandResultBufferNameFunction', 's:GenerateResultBufferNameWithExtension')
- endif
-
- let name = call(nameFunction, [a:command, a:originalBuffer, a:vcsType, a:statusText])
-
- let b:VCSCommandCommand = a:command
- let b:VCSCommandOriginalBuffer = a:originalBuffer
- let b:VCSCommandSourceFile = bufname(a:originalBuffer)
- let b:VCSCommandVCSType = a:vcsType
- if a:statusText != ''
- let b:VCSCommandStatusText = a:statusText
- endif
-
- setlocal buftype=nofile
- setlocal noswapfile
- let &filetype = a:vcsType . a:command
-
- if VCSCommandGetOption('VCSCommandDeleteOnHide', 0)
- setlocal bufhidden=delete
- endif
- silent noautocmd file `=name`
-endfunction
-
-" Function: s:SetupBuffer() {{{2
-" Attempts to set the b:VCSCommandBufferInfo variable
-
-function! s:SetupBuffer()
- if (exists('b:VCSCommandBufferSetup') && b:VCSCommandBufferSetup)
- " This buffer is already set up.
- return
- endif
-
- if !isdirectory(@%) && (strlen(&buftype) > 0 || !filereadable(@%))
- " No special status for special buffers other than directory buffers.
- return
- endif
-
- if !VCSCommandGetOption('VCSCommandEnableBufferSetup', 0) || s:isEditFileRunning > 0
- unlet! b:VCSCommandBufferSetup
- return
- endif
-
- try
- let vcsType = VCSCommandGetVCSType(bufnr('%'))
- let b:VCSCommandBufferInfo = s:plugins[vcsType][1].GetBufferInfo()
- silent do VCSCommand User VCSBufferSetup
- catch /No suitable plugin/
- " This is not a VCS-controlled file.
- let b:VCSCommandBufferInfo = []
- endtry
-
- let b:VCSCommandBufferSetup = 1
-endfunction
-
-" Function: s:MarkOrigBufferForSetup(buffer) {{{2
-" Resets the buffer setup state of the original buffer for a given VCS scratch
-" buffer.
-" Returns: The VCS buffer number in a passthrough mode.
-
-function! s:MarkOrigBufferForSetup(buffer)
- checktime
- if a:buffer > 0
- let origBuffer = VCSCommandGetOriginalBuffer(a:buffer)
- " This should never not work, but I'm paranoid
- if origBuffer != a:buffer
- call setbufvar(origBuffer, 'VCSCommandBufferSetup', 0)
- endif
- endif
- return a:buffer
-endfunction
-
-" Function: s:OverrideOption(option, [value]) {{{2
-" Provides a temporary override for the given VCS option. If no value is
-" passed, the override is disabled.
-
-function! s:OverrideOption(option, ...)
- if a:0 == 0
- call remove(s:optionOverrides[a:option], -1)
- else
- if !has_key(s:optionOverrides, a:option)
- let s:optionOverrides[a:option] = []
- endif
- call add(s:optionOverrides[a:option], a:1)
- endif
-endfunction
-
-" Function: s:WipeoutCommandBuffers() {{{2
-" Clears all current VCS output buffers of the specified type for a given source.
-
-function! s:WipeoutCommandBuffers(originalBuffer, VCSCommand)
- let buffer = 1
- while buffer <= bufnr('$')
- if getbufvar(buffer, 'VCSCommandOriginalBuffer') == a:originalBuffer
- if getbufvar(buffer, 'VCSCommandCommand') == a:VCSCommand
- execute 'bw' buffer
- endif
- endif
- let buffer = buffer + 1
- endwhile
-endfunction
-
-" Function: s:VimDiffRestore(vimDiffBuff) {{{2
-" Checks whether the given buffer is one whose deletion should trigger
-" restoration of an original buffer after it was diffed. If so, it executes
-" the appropriate setting command stored with that original buffer.
-
-function! s:VimDiffRestore(vimDiffBuff)
- let s:isEditFileRunning += 1
- try
- if exists('s:vimDiffSourceBuffer')
- if a:vimDiffBuff == s:vimDiffSourceBuffer
- " Original file is being removed.
- unlet! s:vimDiffSourceBuffer
- unlet! s:vimDiffRestoreCmd
- unlet! s:vimDiffScratchList
- else
- let index = index(s:vimDiffScratchList, a:vimDiffBuff)
- if index >= 0
- call remove(s:vimDiffScratchList, index)
- if len(s:vimDiffScratchList) == 0
- if exists('s:vimDiffRestoreCmd')
- " All scratch buffers are gone, reset the original.
- " Only restore if the source buffer is still in Diff mode
-
- let sourceWinNR = bufwinnr(s:vimDiffSourceBuffer)
- if sourceWinNR != -1
- " The buffer is visible in at least one window
- let currentWinNR = winnr()
- while winbufnr(sourceWinNR) != -1
- if winbufnr(sourceWinNR) == s:vimDiffSourceBuffer
- execute sourceWinNR . 'wincmd w'
- if getwinvar(0, '&diff')
- execute s:vimDiffRestoreCmd
- endif
- endif
- let sourceWinNR = sourceWinNR + 1
- endwhile
- execute currentWinNR . 'wincmd w'
- else
- " The buffer is hidden. It must be visible in order to set the
- " diff option.
- let currentBufNR = bufnr('')
- execute 'hide buffer' s:vimDiffSourceBuffer
- if getwinvar(0, '&diff')
- execute s:vimDiffRestoreCmd
- endif
- execute 'hide buffer' currentBufNR
- endif
-
- unlet s:vimDiffRestoreCmd
- endif
- " All buffers are gone.
- unlet s:vimDiffSourceBuffer
- unlet s:vimDiffScratchList
- endif
- endif
- endif
- endif
- finally
- let s:isEditFileRunning -= 1
- endtry
-endfunction
-
-" Section: Generic VCS command functions {{{1
-
-" Function: s:VCSAnnotate(...) {{{2
-function! s:VCSAnnotate(bang, ...)
- try
- let annotateBuffer = s:ExecuteVCSCommand('Annotate', a:000)
- if annotateBuffer == -1
- return -1
- endif
- if a:bang == '!' && VCSCommandGetOption('VCSCommandDisableSplitAnnotate', 0) == 0
- let vcsType = VCSCommandGetVCSType(annotateBuffer)
- let functionMap = s:plugins[vcsType][1]
- let splitRegex = ''
- if has_key(s:plugins[vcsType][1], 'AnnotateSplitRegex')
- let splitRegex = s:plugins[vcsType][1]['AnnotateSplitRegex']
- endif
- let splitRegex = VCSCommandGetOption('VCSCommand' . vcsType . 'AnnotateSplitRegex', splitRegex)
- if splitRegex == ''
- return annotateBuffer
- endif
- let originalBuffer = VCSCommandGetOriginalBuffer(annotateBuffer)
- let originalFileType = getbufvar(originalBuffer, '&ft')
- let annotateFileType = getbufvar(annotateBuffer, '&ft')
- execute "normal 0zR\<c-v>G/" . splitRegex . "/e\<cr>d"
- call setbufvar('%', '&filetype', getbufvar(originalBuffer, '&filetype'))
- set scrollbind
- leftabove vert new
- normal 0P
- execute "normal" . col('$') . "\<c-w>|"
- call s:SetupScratchBuffer('annotate', vcsType, originalBuffer, 'header')
- wincmd l
- endif
- return annotateBuffer
- catch
- call s:ReportError(v:exception)
- return -1
- endtry
-endfunction
-
-" Function: s:VCSCommit() {{{2
-function! s:VCSCommit(bang, message)
- try
- let vcsType = VCSCommandGetVCSType(bufnr('%'))
- if !has_key(s:plugins, vcsType)
- throw 'Unknown VCS type: ' . vcsType
- endif
-
- let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
-
- " Handle the commit message being specified. If a message is supplied, it
- " is used; if bang is supplied, an empty message is used; otherwise, the
- " user is provided a buffer from which to edit the commit message.
-
- if strlen(a:message) > 0 || a:bang == '!'
- return s:VCSFinishCommit([a:message], originalBuffer)
- endif
-
- call s:EditFile('commitlog', originalBuffer, '')
- setlocal ft=vcscommit
-
- " Create a commit mapping.
-
- nnoremap <silent> <buffer> <Plug>VCSCommit :call <SID>VCSFinishCommitWithBuffer()<CR>
-
- silent 0put ='VCS: ----------------------------------------------------------------------'
- silent put ='VCS: Please enter log message. Lines beginning with ''VCS:'' are removed automatically.'
- silent put ='VCS: To finish the commit, Type <leader>cc (or your own <Plug>VCSCommit mapping)'
-
- if VCSCommandGetOption('VCSCommandCommitOnWrite', 1) == 1
- setlocal buftype=acwrite
- au VCSCommandCommit BufWriteCmd <buffer> call s:VCSFinishCommitWithBuffer()
- silent put ='VCS: or write this buffer'
- endif
-
- silent put ='VCS: ----------------------------------------------------------------------'
- $
- setlocal nomodified
- catch
- call s:ReportError(v:exception)
- return -1
- endtry
-endfunction
-
-" Function: s:VCSFinishCommitWithBuffer() {{{2
-" Wrapper for s:VCSFinishCommit which is called only from a commit log buffer
-" which removes all lines starting with 'VCS:'.
-
-function! s:VCSFinishCommitWithBuffer()
- setlocal nomodified
- let currentBuffer = bufnr('%')
- let logMessageList = getbufline('%', 1, '$')
- call filter(logMessageList, 'v:val !~ ''^\s*VCS:''')
- let resultBuffer = s:VCSFinishCommit(logMessageList, b:VCSCommandOriginalBuffer)
- if resultBuffer >= 0
- execute 'bw' currentBuffer
- endif
- return resultBuffer
-endfunction
-
-" Function: s:VCSFinishCommit(logMessageList, originalBuffer) {{{2
-function! s:VCSFinishCommit(logMessageList, originalBuffer)
- let shellSlashBak = &shellslash
- try
- set shellslash
- let messageFileName = tempname()
- call writefile(a:logMessageList, messageFileName)
- try
- let resultBuffer = s:ExecuteVCSCommand('Commit', [messageFileName])
- if resultBuffer < 0
- return resultBuffer
- endif
- return s:MarkOrigBufferForSetup(resultBuffer)
- finally
- call delete(messageFileName)
- endtry
- finally
- let &shellslash = shellSlashBak
- endtry
-endfunction
-
-" Function: s:VCSGotoOriginal(bang) {{{2
-function! s:VCSGotoOriginal(bang)
- let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
- if originalBuffer > 0
- let origWinNR = bufwinnr(originalBuffer)
- if origWinNR == -1
- execute 'buffer' originalBuffer
- else
- execute origWinNR . 'wincmd w'
- endif
- if a:bang == '!'
- let buffnr = 1
- let buffmaxnr = bufnr('$')
- while buffnr <= buffmaxnr
- if getbufvar(buffnr, 'VCSCommandOriginalBuffer') == originalBuffer
- execute 'bw' buffnr
- endif
- let buffnr = buffnr + 1
- endwhile
- endif
- endif
-endfunction
-
-" Function: s:VCSVimDiff(...) {{{2
-function! s:VCSVimDiff(...)
- try
- let vcsType = VCSCommandGetVCSType(bufnr('%'))
- if !has_key(s:plugins, vcsType)
- throw 'Unknown VCS type: ' . vcsType
- endif
- let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
- let s:isEditFileRunning = s:isEditFileRunning + 1
- try
- " If there's already a VimDiff'ed window, restore it.
- " There may only be one VCSVimDiff original window at a time.
-
- if exists('s:vimDiffSourceBuffer') && s:vimDiffSourceBuffer != originalBuffer
- " Clear the existing vimdiff setup by removing the result buffers.
- call s:WipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
- endif
-
- let orientation = &diffopt =~ 'horizontal' ? 'horizontal' : 'vertical'
- let orientation = VCSCommandGetOption('VCSCommandSplit', orientation)
- let orientation = VCSCommandGetOption('VCSCommandDiffSplit', orientation)
-
- " Split and diff
- if(a:0 == 2)
- " Reset the vimdiff system, as 2 explicit versions were provided.
- if exists('s:vimDiffSourceBuffer')
- call s:WipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
- endif
- let resultBuffer = s:plugins[vcsType][1].Review([a:1])
- if resultBuffer < 0
- echomsg 'Can''t open revision ' . a:1
- return resultBuffer
- endif
- let b:VCSCommandCommand = 'vimdiff'
- diffthis
- let s:vimDiffScratchList = [resultBuffer]
- " If no split method is defined, cheat, and set it to vertical.
- try
- call s:OverrideOption('VCSCommandSplit', orientation)
- let resultBuffer = s:plugins[vcsType][1].Review([a:2])
- finally
- call s:OverrideOption('VCSCommandSplit')
- endtry
- if resultBuffer < 0
- echomsg 'Can''t open revision ' . a:1
- return resultBuffer
- endif
- let b:VCSCommandCommand = 'vimdiff'
- diffthis
- let s:vimDiffScratchList += [resultBuffer]
- else
- " Add new buffer
- call s:OverrideOption('VCSCommandEdit', 'split')
- try
- " Force splitting behavior, otherwise why use vimdiff?
- call s:OverrideOption('VCSCommandSplit', orientation)
- try
- if(a:0 == 0)
- let resultBuffer = s:plugins[vcsType][1].Review([])
- else
- let resultBuffer = s:plugins[vcsType][1].Review([a:1])
- endif
- finally
- call s:OverrideOption('VCSCommandSplit')
- endtry
- finally
- call s:OverrideOption('VCSCommandEdit')
- endtry
- if resultBuffer < 0
- echomsg 'Can''t open current revision'
- return resultBuffer
- endif
- let b:VCSCommandCommand = 'vimdiff'
- diffthis
-
- if !exists('s:vimDiffSourceBuffer')
- " New instance of vimdiff.
- let s:vimDiffScratchList = [resultBuffer]
-
- " This could have been invoked on a VCS result buffer, not the
- " original buffer.
- wincmd W
- execute 'buffer' originalBuffer
- " Store info for later original buffer restore
- let s:vimDiffRestoreCmd =
- \ 'call setbufvar('.originalBuffer.', ''&diff'', '.getbufvar(originalBuffer, '&diff').')'
- \ . '|call setbufvar('.originalBuffer.', ''&foldcolumn'', '.getbufvar(originalBuffer, '&foldcolumn').')'
- \ . '|call setbufvar('.originalBuffer.', ''&foldenable'', '.getbufvar(originalBuffer, '&foldenable').')'
- \ . '|call setbufvar('.originalBuffer.', ''&foldmethod'', '''.getbufvar(originalBuffer, '&foldmethod').''')'
- \ . '|call setbufvar('.originalBuffer.', ''&foldlevel'', '''.getbufvar(originalBuffer, '&foldlevel').''')'
- \ . '|call setbufvar('.originalBuffer.', ''&scrollbind'', '.getbufvar(originalBuffer, '&scrollbind').')'
- \ . '|call setbufvar('.originalBuffer.', ''&wrap'', '.getbufvar(originalBuffer, '&wrap').')'
- \ . '|if &foldmethod==''manual''|execute ''normal zE''|endif'
- diffthis
- wincmd w
- else
- " Adding a window to an existing vimdiff
- let s:vimDiffScratchList += [resultBuffer]
- endif
- endif
-
- let s:vimDiffSourceBuffer = originalBuffer
-
- " Avoid executing the modeline in the current buffer after the autocommand.
-
- let currentBuffer = bufnr('%')
- let saveModeline = getbufvar(currentBuffer, '&modeline')
- try
- call setbufvar(currentBuffer, '&modeline', 0)
- silent do VCSCommand User VCSVimDiffFinish
- finally
- call setbufvar(currentBuffer, '&modeline', saveModeline)
- endtry
- return resultBuffer
- finally
- let s:isEditFileRunning = s:isEditFileRunning - 1
- endtry
- catch
- call s:ReportError(v:exception)
- return -1
- endtry
-endfunction
-
-" Section: Public functions {{{1
-
-" Function: VCSCommandGetVCSType() {{{2
-" Sets the b:VCSCommandVCSType variable in the given buffer to the
-" appropriate source control system name.
-"
-" This uses the Identify extension function to test the buffer. If the
-" Identify function returns VCSCOMMAND_IDENTIFY_EXACT, the match is considered
-" exact. If the Identify function returns VCSCOMMAND_IDENTIFY_INEXACT, the
-" match is considered inexact, and is only applied if no exact match is found.
-" Multiple inexact matches is currently considered an error.
-
-function! VCSCommandGetVCSType(buffer)
- let vcsType = getbufvar(a:buffer, 'VCSCommandVCSType')
- if strlen(vcsType) > 0
- return vcsType
- endif
- if exists("g:VCSCommandVCSTypeOverride")
- let fullpath = fnamemodify(bufname(a:buffer), ':p')
- for [path, vcsType] in g:VCSCommandVCSTypeOverride
- if match(fullpath, path) > -1
- call setbufvar(a:buffer, 'VCSCommandVCSType', vcsType)
- return vcsType
- endif
- endfor
- endif
- let matches = []
- for vcsType in keys(s:plugins)
- let identified = s:plugins[vcsType][1].Identify(a:buffer)
- if identified
- if identified == g:VCSCOMMAND_IDENTIFY_EXACT
- let matches = [vcsType]
- break
- else
- let matches += [vcsType]
- endif
- endif
- endfor
- if len(matches) == 1
- call setbufvar(a:buffer, 'VCSCommandVCSType', matches[0])
- return matches[0]
- elseif len(matches) == 0
- throw 'No suitable plugin'
- else
- throw 'Too many matching VCS: ' . join(matches)
- endif
-endfunction
-
-" Function: VCSCommandChdir(directory) {{{2
-" Changes the current directory, respecting :lcd changes.
-
-function! VCSCommandChdir(directory)
- let command = 'cd'
- if exists("*haslocaldir") && haslocaldir()
- let command = 'lcd'
- endif
- execute command escape(a:directory, ' ')
-endfunction
-
-" Function: VCSCommandChangeToCurrentFileDir() {{{2
-" Go to the directory in which the given file is located.
-
-function! VCSCommandChangeToCurrentFileDir(fileName)
- let oldCwd = getcwd()
- let newCwd = fnamemodify(resolve(a:fileName), ':p:h')
- if strlen(newCwd) > 0
- call VCSCommandChdir(newCwd)
- endif
- return oldCwd
-endf