diff --git a/.vim/plugin/vcsbzr.vim b/.vim/plugin/vcsbzr.vim deleted file mode 100644 index 966f2ee..0000000 --- a/.vim/plugin/vcsbzr.vim +++ /dev/null @@ -1,264 +0,0 @@ -" vim600: set foldmethod=marker: -" -" BZR extension for VCSCommand. -" -" Maintainer: Bob Hiestand -" License: -" Copyright (c) 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 -" -" Options documentation: {{{2 -" -" VCSCommandBZRExec -" This variable specifies the BZR executable. If not set, it defaults to -" 'bzr' executed from the user's executable path. - -" Section: Plugin header {{{1 - -if exists('VCSCommandDisableAll') - finish -endif - -if v:version < 700 - echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None - finish -endif - -if !exists('g:loaded_VCSCommand') - runtime plugin/vcscommand.vim -endif - -if !executable(VCSCommandGetOption('VCSCommandBZRExec', 'bzr')) - " BZR is not installed - finish -endif - -let s:save_cpo=&cpo -set cpo&vim - -" Section: Variable initialization {{{1 - -let s:bzrFunctions = {} - -" Section: Utility functions {{{1 - -" Function: s:Executable() {{{2 -" Returns the executable used to invoke bzr suitable for use in a shell -" command. -function! s:Executable() - return VCSCommandGetOption('VCSCommandBZRExec', 'bzr') -endfunction - -" Function: s:DoCommand(cmd, cmdName, statusText) {{{2 -" Wrapper to VCSCommandDoCommand to add the name of the BZR executable to the -" command argument. -function! s:DoCommand(cmd, cmdName, statusText, options) - if VCSCommandGetVCSType(expand('%')) == 'BZR' - let fullCmd = s:Executable() . ' ' . a:cmd - return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options) - else - throw 'BZR VCSCommand plugin called on non-BZR item.' - endif -endfunction - -" Section: VCS function implementations {{{1 - -" Function: s:bzrFunctions.Identify(buffer) {{{2 -function! s:bzrFunctions.Identify(buffer) - let fileName = resolve(bufname(a:buffer)) - let l:save_bzr_log=$BZR_LOG - try - let $BZR_LOG=has("win32") || has("win95") || has("win64") || has("win16") ? "nul" : "/dev/null" - let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . fileName . '"') - finally - let $BZR_LOG=l:save_bzr_log - endtry - if(v:shell_error) - return 0 - else - return 1 - endif -endfunction - -" Function: s:bzrFunctions.Add() {{{2 -function! s:bzrFunctions.Add(argList) - return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {}) -endfunction - -" Function: s:bzrFunctions.Annotate(argList) {{{2 -function! s:bzrFunctions.Annotate(argList) - if len(a:argList) == 0 - if &filetype ==? 'bzrannotate' - " Perform annotation of the version indicated by the current line. - let caption = matchstr(getline('.'),'\v^\s+\zs\d+') - let options = ' -r' . caption - else - let caption = '' - let options = '' - endif - elseif len(a:argList) == 1 && a:argList[0] !~ '^-' - let caption = a:argList[0] - let options = ' -r' . caption - else - let caption = join(a:argList, ' ') - let options = ' ' . caption - endif - - let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {}) - if resultBuffer > 0 - normal! 1G2dd - endif - return resultBuffer -endfunction - -" Function: s:bzrFunctions.Commit(argList) {{{2 -function! s:bzrFunctions.Commit(argList) - let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {}) - if resultBuffer == 0 - echomsg 'No commit needed.' - endif -endfunction - -" Function: s:bzrFunctions.Delete() {{{2 -function! s:bzrFunctions.Delete(argList) - return s:DoCommand(join(['rm'] + a:argList, ' '), 'rm', join(a:argList, ' '), {}) -endfunction - -" Function: s:bzrFunctions.Diff(argList) {{{2 -function! s:bzrFunctions.Diff(argList) - if len(a:argList) == 0 - let revOptions = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let revOptions = ['-r' . join(a:argList, '..')] - let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')' - else - " Pass-through - let caption = join(a:argList, ' ') - let revOptions = a:argList - endif - - return s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {'allowNonZeroExit': 1}) -endfunction - -" Function: s:bzrFunctions.GetBufferInfo() {{{2 -" Provides version control details for the current file. Current version -" number and current repository version number are required to be returned by -" the vcscommand plugin. -" Returns: List of results: [revision, repository] - -function! s:bzrFunctions.GetBufferInfo() - let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) - let fileName = resolve(bufname(originalBuffer)) - let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -S -- "' . fileName . '"') - let revision = s:VCSCommandUtility.system(s:Executable() . ' revno -- "' . fileName . '"') - if(v:shell_error) - return [] - endif - - " File not under BZR control. - if statusText =~ '^?' - return ['Unknown'] - endif - - let [flags, repository] = matchlist(statusText, '^\(.\{3}\)\s\+\(\S\+\)')[1:2] - if revision == '' - " Error - return ['Unknown'] - elseif flags =~ '^A' - return ['New', 'New'] - else - return [revision, repository] - endif -endfunction - -" Function: s:bzrFunctions.Info(argList) {{{2 -function! s:bzrFunctions.Info(argList) - return s:DoCommand(join(['version-info'] + a:argList, ' '), 'version-info', join(a:argList, ' '), {}) -endfunction - -" Function: s:bzrFunctions.Lock(argList) {{{2 -function! s:bzrFunctions.Lock(argList) - echomsg 'bzr lock is not necessary' -endfunction - -" Function: s:bzrFunctions.Log() {{{2 -function! s:bzrFunctions.Log(argList) - if len(a:argList) == 0 - let options = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let options = ['-r' . join(a:argList, ':')] - let caption = options[0] - else - " Pass-through - let options = a:argList - let caption = join(a:argList, ' ') - endif - - let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {}) - return resultBuffer -endfunction - -" Function: s:bzrFunctions.Revert(argList) {{{2 -function! s:bzrFunctions.Revert(argList) - return s:DoCommand('revert', 'revert', '', {}) -endfunction - -" Function: s:bzrFunctions.Review(argList) {{{2 -function! s:bzrFunctions.Review(argList) - if len(a:argList) == 0 - let versiontag = '(current)' - let versionOption = '' - else - let versiontag = a:argList[0] - let versionOption = ' -r ' . versiontag . ' ' - endif - - return s:DoCommand('cat' . versionOption, 'review', versiontag, {}) -endfunction - -" Function: s:bzrFunctions.Status(argList) {{{2 -function! s:bzrFunctions.Status(argList) - let options = ['-S'] - if len(a:argList) != 0 - let options = a:argList - endif - return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {}) -endfunction - -" Function: s:bzrFunctions.Unlock(argList) {{{2 -function! s:bzrFunctions.Unlock(argList) - echomsg 'bzr unlock is not necessary' -endfunction -" Function: s:bzrFunctions.Update(argList) {{{2 -function! s:bzrFunctions.Update(argList) - return s:DoCommand('update', 'update', '', {}) -endfunction - -" Annotate setting {{{2 -let s:bzrFunctions.AnnotateSplitRegex = '^[^|]\+ | ' - -" Section: Plugin Registration {{{1 -let s:VCSCommandUtility = VCSCommandRegisterModule('BZR', expand(''), s:bzrFunctions, []) - -let &cpo = s:save_cpo diff --git a/.vim/plugin/vcscommand.vim b/.vim/plugin/vcscommand.vim deleted file mode 100644 index 2726436..0000000 --- a/.vim/plugin/vcscommand.vim +++ /dev/null @@ -1,1530 +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. -" -" Maintainer: Bob Hiestand -" License: -" Copyright (c) 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. 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 CommandName, for instance: -" -" nmap ,ca VCSAdd -" -" The default mappings are as follow: -" -" ca VCSAdd -" cn VCSAnnotate -" cN VCSAnnotate! -" cc VCSCommit -" cD VCSDelete -" cd VCSDiff -" cg VCSGotoOriginal -" cG VCSGotoOriginal! -" ci VCSInfo -" cl VCSLog -" cL VCSLock -" cr VCSReview -" cs VCSStatus -" cu VCSUpdate -" cU VCSUnlock -" 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. -" -" VCSCommandDisableMenu -" This variable, if set to a non-zero value, prevents the default command -" menu from being set. -" -" 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 ('c'). -" This allows customization of the mapping space used by the vcscommand -" shortcuts. -" -" VCSCommandMenuPriority -" This variable, if set, overrides the default menu priority '' (empty) -" -" VCSCommandMenuRoot -" This variable, if set, overrides the default menu root 'Plugin.VCS' -" -" 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. -" -" VCSCommandVCSTypePreference -" This variable allows the VCS type detection to be weighted towards a -" specific VCS, in case more than one potential VCS is detected as useable. -" The format of the variable is either a list or a space-separated string -" containing the ordered-by-preference abbreviations of the preferred VCS -" types. -" -" 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 q :bwipeout -" 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 - -" Hidden functions for use by extensions -let s:VCSCommandUtility = {} - -" plugin-specific information: {vcs -> [script, {command -> function}, {key -> mapping}]} -let s:plugins = {} - -" Stack of dictionaries representing nested options -let s:executionContext = [] - -" state flag used to vary behavior of certain automated actions -let s:isEditFileRunning = 0 - -" 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:VCSCommandUtility.system(...) {{{2 -" Replacement for system() function. This version protects the quoting in the -" command line on Windows systems. - -function! s:VCSCommandUtility.system(...) - if (has("win32") || has("win64")) && &sxq !~ '"' - let save_sxq = &sxq - set sxq=\" - endif - try - let output = call('system', a:000) - if exists('*iconv') && has('multi_byte') - if(strlen(&tenc) && &tenc != &enc) - let output = iconv(output, &tenc, &enc) - else - let originalBuffer = VCSCommandGetOriginalBuffer(VCSCommandGetOption('VCSCommandEncodeAsFile', 0)) - if originalBuffer - let fenc = getbufvar(originalBuffer, '&fenc') - if fenc != &enc - let output = iconv(output, fenc, &enc) - endif - endif - endif - - endif - finally - if exists("save_sxq") - let &sxq = save_sxq - endif - endtry - return output -endfunction - -" Function: s:VCSCommandUtility.addMenuItem(shortcut, command) {{{2 -" Adds the given menu item. - -function! s:VCSCommandUtility.addMenuItem(shortcut, command) - if s:menuEnabled - exe 'amenu '.s:menuPriority.' '.s:menuRoot.'.'.a:shortcut.' '.a:command - endif -endfunction - -" Function: s:VCSCommandUtility.pushContext(context) {{{2 -" Adds a dictionary containing current options to the stack. - -function! s:VCSCommandUtility.pushContext(context) - call insert(s:executionContext, a:context) -endfunction - -" Function: s:VCSCommandUtility.popContext() {{{2 -" Removes a dictionary containing current options from the stack. - -function! s:VCSCommandUtility.popContext() - call remove(s:executionContext, 0) -endfunction - -" Function: s:ClearMenu() {{{2 -" Removes all VCSCommand menu items -function! s:ClearMenu() - if s:menuEnabled - execute 'aunmenu' s:menuRoot - endif -endfunction - -" Function: s:CreateMapping(shortcut, expansion, display) {{{2 -" Creates the given mapping by prepending the contents of -" 'VCSCommandMapPrefix' (by default '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', 'c') . a:shortcut - if !hasmapto(a:expansion) - try - execute 'nmap ' 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] . "\" -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 bufexists(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 bufexists(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:IdentifyVCSType() {{{2 -" This function implements the non-cached identification strategy for -" VcsCommandGetVCSType(). -" -" Returns: VCS type name identified for the given buffer; an exception is -" thrown in case no type can be identified. - -function! s:IdentifyVCSType(buffer) - if exists("g:VCSCommandVCSTypeOverride") - let fullpath = fnamemodify(bufname(a:buffer), ':p') - for [path, vcsType] in g:VCSCommandVCSTypeOverride - if match(fullpath, path) > -1 - return vcsType - endif - endfor - endif - let matches = [] - let exactMatch = '' - let exactMatchCount = 0 - for vcsType in keys(s:plugins) - let identified = s:plugins[vcsType][1].Identify(a:buffer) - if identified - if identified == g:VCSCOMMAND_IDENTIFY_EXACT - let exactMatch = vcsType - let exactMatchCount += 1 - endif - call add(matches, [vcsType, identified]) - endif - endfor - if len(matches) == 1 - return matches[0][0] - elseif len(matches) == 0 - throw 'No suitable plugin' - else - let preferences = VCSCommandGetOption("VCSCommandVCSTypePreference", []) - if len(preferences) > 0 - if type(preferences) == 1 - let listPreferences = split(preferences, '\W\+') - unlet preferences - let preferences = listPreferences - endif - for preferred in preferences - for [vcsType, identified] in matches - if vcsType ==? preferred - return vcsType - endif - endfor - endfor - endif - - if exactMatchCount == 1 - return exactMatch - endif - - throw 'can''t identify VCS type for current buffer due to too many matching VCS: ' . join(map(matches, 'v:val[0]')) - endif -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 = tolower(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: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('t:vcsCommandVimDiffSourceBuffer') - if a:vimDiffBuff == t:vcsCommandVimDiffSourceBuffer - " Original file is being removed. - unlet! t:vcsCommandVimDiffSourceBuffer - unlet! t:vcsCommandVimDiffRestoreCmd - unlet! t:vcsCommandVimDiffScratchList - else - let index = index(t:vcsCommandVimDiffScratchList, a:vimDiffBuff) - if index >= 0 - call remove(t:vcsCommandVimDiffScratchList, index) - if len(t:vcsCommandVimDiffScratchList) == 0 - if exists('t:vcsCommandVimDiffRestoreCmd') - " All scratch buffers are gone, reset the original. - " Only restore if the source buffer is still in Diff mode - - let sourceWinNR = bufwinnr(t:vcsCommandVimDiffSourceBuffer) - if sourceWinNR != -1 - " The buffer is visible in at least one window - let currentWinNR = winnr() - while winbufnr(sourceWinNR) != -1 - if winbufnr(sourceWinNR) == t:vcsCommandVimDiffSourceBuffer - execute sourceWinNR . 'wincmd w' - if getwinvar(0, '&diff') - execute t:vcsCommandVimDiffRestoreCmd - 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' t:vcsCommandVimDiffSourceBuffer - if getwinvar(0, '&diff') - execute t:vcsCommandVimDiffRestoreCmd - endif - execute 'hide buffer' currentBufNR - endif - - unlet t:vcsCommandVimDiffRestoreCmd - endif - " All buffers are gone. - unlet t:vcsCommandVimDiffSourceBuffer - unlet t:vcsCommandVimDiffScratchList - 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, ...) - call s:VCSCommandUtility.pushContext({'VCSCommandEncodeAsFile': bufnr('%')}) - try - let line = line('.') - let currentBuffer = bufnr('%') - let originalBuffer = VCSCommandGetOriginalBuffer(currentBuffer) - - 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 - wincmd J - let originalFileType = getbufvar(originalBuffer, '&ft') - let annotateFileType = getbufvar(annotateBuffer, '&ft') - - let saveselection = &selection - set selection=inclusive - try - execute "normal! 0zR\G/" . splitRegex . "/e\d" - finally - let &selection = saveselection - endtry - - call setbufvar('%', '&filetype', getbufvar(originalBuffer, '&filetype')) - set scrollbind - leftabove vert new - normal! 0P - execute "normal!" . (col('$') + (&number ? &numberwidth : 0)). "\|" - call s:SetupScratchBuffer('annotate', vcsType, originalBuffer, 'header') - wincmd l - endif - - if currentBuffer == originalBuffer - " Starting from the original source buffer, so the - " current line is relevant. - if a:0 == 0 - " No argument list means that we're annotating - " the current version, so jumping to the same - " line is the expected action. - execute "normal!" line . 'G' - if has('folding') - " The execution of the buffer created autocommand - " re-folds the buffer. Display the current line - " unfolded. - normal! zv - endif - endif - endif - - return annotateBuffer - catch - call s:ReportError(v:exception) - return -1 - finally - call s:VCSCommandUtility.popContext() - 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 VCSCommit :call VCSFinishCommitWithBuffer() - - 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 cc (or your own VCSCommit mapping)' - - if VCSCommandGetOption('VCSCommandCommitOnWrite', 1) == 1 - setlocal buftype=acwrite - au VCSCommandCommit BufWriteCmd call s:VCSFinishCommitWithBuffer() - silent put ='VCS: or write this buffer' - endif - - silent put ='VCS: ----------------------------------------------------------------------' - $ - setlocal nomodified - silent do VCSCommand User VCSBufferCreated - 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 messageFileName = tempname() - if exists('*iconv') && has('multi_byte') - if(strlen(&tenc) && &tenc != &enc) - call map(a:logMessageList, 'iconv(v:val, &enc, &tenc)') - endif - endif - 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 -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:VCSDiff(...) "{{{2 - call s:VCSCommandUtility.pushContext({'VCSCommandEncodeAsFile': bufnr('%')}) - try - let resultBuffer = s:ExecuteVCSCommand('Diff', a:000) - if resultBuffer > 0 - let &filetype = 'diff' - elseif resultBuffer == 0 - echomsg 'No differences found' - endif - return resultBuffer - finally - call s:VCSCommandUtility.popContext() - endtry -endfunction - -function! s:VCSReview(...) "{{{2 - call s:VCSCommandUtility.pushContext({'VCSCommandEncodeAsFile': bufnr('%')}) - try - let resultBuffer = s:ExecuteVCSCommand('Review', a:000) - if resultBuffer > 0 - let &filetype = getbufvar(b:VCSCommandOriginalBuffer, '&filetype') - endif - return resultBuffer - finally - call s:VCSCommandUtility.popContext() - endtry -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('t:vcsCommandVimDiffSourceBuffer') && t:vcsCommandVimDiffSourceBuffer != originalBuffer - " Clear the existing vimdiff setup by removing the result buffers. - call s:WipeoutCommandBuffers(t:vcsCommandVimDiffSourceBuffer, '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('t:vcsCommandVimDiffSourceBuffer') - call s:WipeoutCommandBuffers(t:vcsCommandVimDiffSourceBuffer, 'vimdiff') - endif - let resultBuffer = s:VCSReview(a:1) - if resultBuffer < 0 - echomsg 'Can''t open revision ' . a:1 - return resultBuffer - endif - let b:VCSCommandCommand = 'vimdiff' - diffthis - let t:vcsCommandVimDiffScratchList = [resultBuffer] - " If no split method is defined, cheat, and set it to vertical. - call s:VCSCommandUtility.pushContext({'VCSCommandSplit': orientation}) - try - let resultBuffer = s:VCSReview(a:2) - finally - call s:VCSCommandUtility.popContext() - endtry - if resultBuffer < 0 - echomsg 'Can''t open revision ' . a:1 - return resultBuffer - endif - let b:VCSCommandCommand = 'vimdiff' - diffthis - let t:vcsCommandVimDiffScratchList += [resultBuffer] - else - " Add new buffer. Force splitting behavior, otherwise why use vimdiff? - call s:VCSCommandUtility.pushContext({'VCSCommandEdit': 'split', 'VCSCommandSplit': orientation}) - try - if(a:0 == 0) - let resultBuffer = s:VCSReview() - else - let resultBuffer = s:VCSReview(a:1) - endif - finally - call s:VCSCommandUtility.popContext() - endtry - if resultBuffer < 0 - echomsg 'Can''t open current revision' - return resultBuffer - endif - let b:VCSCommandCommand = 'vimdiff' - diffthis - - if !exists('t:vcsCommandVimDiffSourceBuffer') - " New instance of vimdiff. - let t:vcsCommandVimDiffScratchList = [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 t:vcsCommandVimDiffRestoreCmd = - \ '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 has('cursorbind') - let t:vcsCommandVimDiffRestoreCmd .= '|call setbufvar('.originalBuffer.', ''&cursorbind'', '.getbufvar(originalBuffer, '&cursorbind').')' - endif - let t:vcsCommandVimDiffRestoreCmd .= '|if &foldmethod==''manual''|execute ''normal! zE''|endif' - diffthis - wincmd w - else - " Adding a window to an existing vimdiff - let t:vcsCommandVimDiffScratchList += [resultBuffer] - endif - endif - - let t:vcsCommandVimDiffSourceBuffer = 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 -" This function sets the b:VCSCommandVCSType variable in the given buffer to the -" appropriate source control system name and returns the same name. -" -" Returns: VCS type name identified for the given buffer. An exception is -" thrown if no type can be identified. -" -" Rules for determining type: -" 1. use previously-cached value -" 2. use value from 'VCSCommandVCSTypeOverride' -" 3. use single match -" 4. use first matching value from 'VCSCommandTypePreference' -" 5. use single exact match -" 6. error if multiple matching types -" 7. error if no matching types - -function! VCSCommandGetVCSType(buffer) - let vcsType = VCSCommandGetOption('VCSCommandVCSTypeExplicitOverride', '') - if len(vcsType) == 0 - let vcsType = getbufvar(a:buffer, 'VCSCommandVCSType') - if strlen(vcsType) == 0 - let vcsType = s:IdentifyVCSType(a:buffer) - call setbufvar(a:buffer, 'VCSCommandVCSType', vcsType) - endif - endif - return vcsType -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 - if exists("*fnameescape") - execute command fnameescape(a:directory) - else - execute command escape(a:directory, ' ') - endif -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 -endfunction - -" Function: VCSCommandGetOriginalBuffer(vcsBuffer) {{{2 -" Attempts to locate the original file to which VCS operations were applied -" for a given buffer. - -function! VCSCommandGetOriginalBuffer(vcsBuffer) - let origBuffer = getbufvar(a:vcsBuffer, 'VCSCommandOriginalBuffer') - if origBuffer - if bufexists(origBuffer) - return origBuffer - else - " Original buffer no longer exists. - throw 'Original buffer for this VCS buffer no longer exists.' - endif - else - " No original buffer - return a:vcsBuffer - endif -endfunction - -" Function: VCSCommandRegisterModule(name, file, commandMap) {{{2 -" Allows VCS modules to register themselves. - -function! VCSCommandRegisterModule(name, path, commandMap, mappingMap) - let s:plugins[a:name] = [a:path, a:commandMap, a:mappingMap] - if !empty(a:mappingMap) - \ && !exists("g:no_plugin_maps") - \ && !VCSCommandGetOption('VCSCommandDisableMappings', 0) - \ && !VCSCommandGetOption('VCSCommandDisableExtensionMappings', 0) - for shortcut in keys(a:mappingMap) - let expansion = ":call ExecuteExtensionMapping('" . shortcut . "')" - call s:CreateMapping(shortcut, expansion, a:name . " extension mapping " . shortcut) - endfor - endif - return s:VCSCommandUtility -endfunction - -" Function: VCSCommandDoCommand(cmd, cmdName, statusText, [options]) {{{2 -" General skeleton for VCS function execution. The given command is executed -" after appending the current buffer name (or substituting it for -" , if such a token is present). The output is captured in a -" new buffer. -" -" The optional 'options' Dictionary may contain the following options: -" allowNonZeroExit: if non-zero, if the underlying VCS command has a -" non-zero exit status, the command is still considered -" successfuly. This defaults to zero. -" Returns: name of the new command buffer containing the command results - -function! VCSCommandDoCommand(cmd, cmdName, statusText, options) - let allowNonZeroExit = 0 - if has_key(a:options, 'allowNonZeroExit') - let allowNonZeroExit = a:options.allowNonZeroExit - endif - - let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) - if originalBuffer == -1 - throw 'Original buffer no longer exists, aborting.' - endif - - let path = resolve(bufname(originalBuffer)) - - " Work with netrw or other systems where a directory listing is displayed in - " a buffer. - - if isdirectory(path) - let fileName = '.' - else - let fileName = fnamemodify(path, ':t') - endif - - if match(a:cmd, '') > 0 - let fullCmd = substitute(a:cmd, '', fileName, 'g') - else - let fullCmd = a:cmd . ' -- ' . shellescape(fileName) - endif - - " Change to the directory of the current buffer. This is done for CVS, but - " is left in for other systems as it does not affect them negatively. - - let oldCwd = VCSCommandChangeToCurrentFileDir(path) - try - let output = s:VCSCommandUtility.system(fullCmd) - finally - call VCSCommandChdir(oldCwd) - endtry - - " HACK: if line endings in the repository have been corrupted, the output - " of the command will be confused. - let output = substitute(output, "\r", '', 'g') - - if v:shell_error && !allowNonZeroExit - if strlen(output) == 0 - throw 'Version control command failed' - else - let output = substitute(output, '\n', ' ', 'g') - throw 'Version control command failed: ' . output - endif - endif - - if strlen(output) == 0 - " Handle case of no output. In this case, it is important to check the - " file status, especially since cvs edit/unedit may change the attributes - " of the file with no visible output. - - checktime - return 0 - endif - - call s:EditFile(a:cmdName, originalBuffer, a:statusText) - - silent 0put=output - - " The last command left a blank line at the end of the buffer. If the - " last line is folded (a side effect of the 'put') then the attempt to - " remove the blank line will kill the last fold. - " - " This could be fixed by explicitly detecting whether the last line is - " within a fold, but I prefer to simply unfold the result buffer altogether. - - if has('folding') - normal! zR - endif - - $d - 1 - - " Define the environment and execute user-defined hooks. - - silent do VCSCommand User VCSBufferCreated - return bufnr('%') -endfunction - -" Function: VCSCommandGetOption(name, default) {{{2 -" Grab a user-specified option to override the default provided. Options are -" searched in the window, buffer, then global spaces. - -function! VCSCommandGetOption(name, default) - for context in s:executionContext - if has_key(context, a:name) - return context[a:name] - endif - endfor - if exists('w:' . a:name) - return w:{a:name} - elseif exists('b:' . a:name) - return b:{a:name} - elseif exists('g:' . a:name) - return g:{a:name} - else - return a:default - endif -endfunction - -" Function: VCSCommandDisableBufferSetup() {{{2 -" Global function for deactivating the buffer autovariables. - -function! VCSCommandDisableBufferSetup() - let g:VCSCommandEnableBufferSetup = 0 - silent! augroup! VCSCommandPlugin -endfunction - -" Function: VCSCommandEnableBufferSetup() {{{2 -" Global function for activating the buffer autovariables. - -function! VCSCommandEnableBufferSetup() - let g:VCSCommandEnableBufferSetup = 1 - augroup VCSCommandPlugin - au! - au BufEnter * call s:SetupBuffer() - augroup END - - " Only auto-load if the plugin is fully loaded. This gives other plugins a - " chance to run. - if g:loaded_VCSCommand == 2 - call s:SetupBuffer() - endif -endfunction - -" Function: VCSCommandGetStatusLine() {{{2 -" Default (sample) status line entry for VCS-controlled files. This is only -" useful if VCS-managed buffer mode is on (see the VCSCommandEnableBufferSetup -" variable for how to do this). - -function! VCSCommandGetStatusLine() - if exists('b:VCSCommandCommand') - " This is a result buffer. Return nothing because the buffer name - " contains information already. - return '' - endif - - if exists('b:VCSCommandVCSType') - \ && exists('g:VCSCommandEnableBufferSetup') - \ && g:VCSCommandEnableBufferSetup - \ && exists('b:VCSCommandBufferInfo') - return '[' . join(extend([b:VCSCommandVCSType], b:VCSCommandBufferInfo), ' ') . ']' - else - return '' - endif -endfunction - -function! VCSCommandSetVCSType(type) - if exists('b:VCSCommandBufferSetup') - unlet b:VCSCommandBufferSetup - endif - let b:VCSCommandVCSType = a:type - call s:SetupBuffer() -endfunction - -" Section: Command definitions {{{1 -" Section: Primary commands {{{2 -com! -nargs=* VCSAdd call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Add', [])) -com! -nargs=* -bang VCSAnnotate call s:VCSAnnotate(, ) -com! -nargs=* -bang VCSBlame call s:VCSAnnotate(, ) -com! -nargs=? -bang VCSCommit call s:VCSCommit(, ) -com! -nargs=* VCSDelete call s:ExecuteVCSCommand('Delete', []) -com! -nargs=* VCSDiff call s:VCSDiff() -com! -nargs=0 -bang VCSGotoOriginal call s:VCSGotoOriginal() -com! -nargs=* VCSInfo call s:ExecuteVCSCommand('Info', []) -com! -nargs=* VCSLock call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Lock', [])) -com! -nargs=* VCSLog call s:ExecuteVCSCommand('Log', []) -com! -nargs=* VCSRemove call s:ExecuteVCSCommand('Delete', []) -com! -nargs=0 VCSRevert call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Revert', [])) -com! -nargs=? VCSReview call s:VCSReview() -com! -nargs=* VCSStatus call s:ExecuteVCSCommand('Status', []) -com! -nargs=* VCSUnlock call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Unlock', [])) -com! -nargs=0 VCSUpdate call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Update', [])) -com! -nargs=* VCSVimDiff call s:VCSVimDiff() - -" Section: VCS buffer management commands {{{2 -com! VCSCommandDisableBufferSetup call VCSCommandDisableBufferSetup() -com! VCSCommandEnableBufferSetup call VCSCommandEnableBufferSetup() - -" Allow reloading VCSCommand.vim -com! VCSReload let savedPlugins = s:plugins|let s:plugins = {}|call s:ClearMenu()|unlet! g:loaded_VCSCommand|runtime plugin/vcscommand.vim|for plugin in values(savedPlugins)|execute 'source' plugin[0]|endfor|unlet savedPlugins - -" Section: Plugin command mappings {{{1 -if !exists("no_plugin_maps") - nnoremap VCSAdd :VCSAdd - nnoremap VCSAnnotate :VCSAnnotate - nnoremap VCSCommit :VCSCommit - nnoremap VCSDelete :VCSDelete - nnoremap VCSDiff :VCSDiff - nnoremap VCSGotoOriginal :VCSGotoOriginal - nnoremap VCSClearAndGotoOriginal :VCSGotoOriginal! - nnoremap VCSInfo :VCSInfo - nnoremap VCSLock :VCSLock - nnoremap VCSLog :VCSLog - nnoremap VCSRevert :VCSRevert - nnoremap VCSReview :VCSReview - nnoremap VCSSplitAnnotate :VCSAnnotate! - nnoremap VCSStatus :VCSStatus - nnoremap VCSUnlock :VCSUnlock - nnoremap VCSUpdate :VCSUpdate - nnoremap VCSVimDiff :VCSVimDiff -endif - -" Section: Default mappings {{{1 - -let s:defaultMappings = [ - \['a', 'VCSAdd'], - \['c', 'VCSCommit'], - \['D', 'VCSDelete'], - \['d', 'VCSDiff'], - \['G', 'VCSClearAndGotoOriginal'], - \['g', 'VCSGotoOriginal'], - \['i', 'VCSInfo'], - \['L', 'VCSLock'], - \['l', 'VCSLog'], - \['N', 'VCSSplitAnnotate'], - \['n', 'VCSAnnotate'], - \['q', 'VCSRevert'], - \['r', 'VCSReview'], - \['s', 'VCSStatus'], - \['U', 'VCSUnlock'], - \['u', 'VCSUpdate'], - \['v', 'VCSVimDiff'], - \] - -if !exists("g:no_plugin_maps") && !VCSCommandGetOption('VCSCommandDisableMappings', 0) - for [s:shortcut, s:vcsFunction] in VCSCommandGetOption('VCSCommandMappings', s:defaultMappings) - call s:CreateMapping(s:shortcut, '' . s:vcsFunction, '''' . s:vcsFunction . '''') - endfor - unlet s:shortcut s:vcsFunction -endif -unlet s:defaultMappings - -" Section: Menu items {{{1 - -let s:menuEnabled = !VCSCommandGetOption('VCSCommandDisableMenu', 0) -let s:menuRoot = VCSCommandGetOption('VCSCommandMenuRoot', '&Plugin.VCS') -let s:menuPriority = VCSCommandGetOption('VCSCommandMenuPriority', '') - -for [s:shortcut, s:command] in [ - \['&Add', 'VCSAdd'], - \['A&nnotate', 'VCSAnnotate'], - \['&Commit', 'VCSCommit'], - \['Delete', 'VCSDelete'], - \['&Diff', 'VCSDiff'], - \['&Info', 'VCSInfo'], - \['&Log', 'VCSLog'], - \['Revert', 'VCSRevert'], - \['&Review', 'VCSReview'], - \['&Status', 'VCSStatus'], - \['&Update', 'VCSUpdate'], - \['&VimDiff', 'VCSVimDiff'] - \] - call s:VCSCommandUtility.addMenuItem(s:shortcut, s:command) -endfor -unlet s:shortcut s:command - -" Section: Autocommands to restore vimdiff state {{{1 -augroup VimDiffRestore - au! - au BufUnload * call s:VimDiffRestore(str2nr(expand(''))) -augroup END - -" Section: Optional activation of buffer management {{{1 - -if VCSCommandGetOption('VCSCommandEnableBufferSetup', 0) - call VCSCommandEnableBufferSetup() -endif - -" Section: VIM shutdown hook {{{1 - -" Close all result buffers when VIM exits, to prevent them from being restored -" via viminfo. - -" Function: s:CloseAllResultBuffers() {{{2 -" Closes all vcscommand result buffers. -function! s:CloseAllResultBuffers() - " This avoids using bufdo as that may load buffers already loaded in another - " vim process, resulting in an error. - let buffnr = 1 - let buffmaxnr = bufnr('$') - while buffnr <= buffmaxnr - if getbufvar(buffnr, 'VCSCommandOriginalBuffer') != "" - execute 'bw' buffnr - endif - let buffnr = buffnr + 1 - endwhile -endfunction - -augroup VCSCommandVIMShutdown - au! - au VimLeavePre * call s:CloseAllResultBuffers() -augroup END - -" Section: Plugin completion {{{1 - -let loaded_VCSCommand = 2 - -silent do VCSCommand User VCSPluginFinish - -let &cpo = s:save_cpo diff --git a/.vim/plugin/vcscvs.vim b/.vim/plugin/vcscvs.vim deleted file mode 100644 index 11c7433..0000000 --- a/.vim/plugin/vcscvs.vim +++ /dev/null @@ -1,453 +0,0 @@ -" vim600: set foldmethod=marker: -" -" CVS extension for VCSCommand. -" -" Maintainer: Bob Hiestand -" License: -" Copyright (c) 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 -" -" Command documentation {{{2 -" -" The following commands only apply to files under CVS source control. -" -" CVSEdit Performs "cvs edit" on the current file. -" -" CVSEditors Performs "cvs editors" on the current file. -" -" CVSUnedit Performs "cvs unedit" on the current file. -" -" CVSWatch Takes an argument which must be one of [on|off|add|remove]. -" Performs "cvs watch" with the given argument on the current -" file. -" -" CVSWatchers Performs "cvs watchers" on the current file. -" -" CVSWatchAdd Alias for "CVSWatch add" -" -" CVSWatchOn Alias for "CVSWatch on" -" -" CVSWatchOff Alias for "CVSWatch off" -" -" CVSWatchRemove Alias for "CVSWatch remove" -" -" Mapping documentation: {{{2 -" -" By default, a mapping is defined for each command. User-provided mappings -" can be used instead by mapping to CommandName, for instance: -" -" nnoremap ,ce CVSEdit -" -" The default mappings are as follow: -" -" ce CVSEdit -" cE CVSEditors -" ct CVSUnedit -" cwv CVSWatchers -" cwa CVSWatchAdd -" cwn CVSWatchOn -" cwf CVSWatchOff -" cwr CVSWatchRemove -" -" Options documentation: {{{2 -" -" VCSCommandCVSExec -" This variable specifies the CVS executable. If not set, it defaults to -" 'cvs' executed from the user's executable path. -" -" VCSCommandCVSDiffOpt -" This variable, if set, determines the options passed to the cvs diff -" command. If not set, it defaults to 'u'. - -" Section: Plugin header {{{1 - -if exists('VCSCommandDisableAll') - finish -endif - -if v:version < 700 - echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None - finish -endif - -if !exists('g:loaded_VCSCommand') - runtime plugin/vcscommand.vim -endif - -if !executable(VCSCommandGetOption('VCSCommandCVSExec', 'cvs')) - " CVS is not installed - finish -endif - -let s:save_cpo=&cpo -set cpo&vim - -" Section: Variable initialization {{{1 - -let s:cvsFunctions = {} - -" Section: Utility functions {{{1 - -" Function: s:Executable() {{{2 -" Returns the executable used to invoke cvs suitable for use in a shell -" command. -function! s:Executable() - return VCSCommandGetOption('VCSCommandCVSExec', 'cvs') -endfunction - -" Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2 -" Wrapper to VCSCommandDoCommand to add the name of the CVS executable to the -" command argument. -function! s:DoCommand(cmd, cmdName, statusText, options) - if VCSCommandGetVCSType(expand('%')) == 'CVS' - let fullCmd = s:Executable() . ' ' . a:cmd - let ret = VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options) - - if ret > 0 - if getline(line('$')) =~ '^cvs \w\+: closing down connection' - $d - 1 - endif - - endif - - return ret - else - throw 'CVS VCSCommand plugin called on non-CVS item.' - endif -endfunction - -" Function: s:GetRevision() {{{2 -" Function for retrieving the current buffer's revision number. -" Returns: Revision number or an empty string if an error occurs. - -function! s:GetRevision() - if !exists('b:VCSCommandBufferInfo') - let b:VCSCommandBufferInfo = s:cvsFunctions.GetBufferInfo() - endif - - if len(b:VCSCommandBufferInfo) > 0 - return b:VCSCommandBufferInfo[0] - else - return '' - endif -endfunction - -" Section: VCS function implementations {{{1 - -" Function: s:cvsFunctions.Identify(buffer) {{{2 -function! s:cvsFunctions.Identify(buffer) - let fileName = resolve(bufname(a:buffer)) - if isdirectory(fileName) - let directoryName = fileName - else - let directoryName = fnamemodify(fileName, ':h') - endif - if strlen(directoryName) > 0 - let CVSRoot = directoryName . '/CVS/Root' - else - let CVSRoot = 'CVS/Root' - endif - if filereadable(CVSRoot) - return 1 - else - return 0 - endif -endfunction - -" Function: s:cvsFunctions.Add(argList) {{{2 -function! s:cvsFunctions.Add(argList) - return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {}) -endfunction - -" Function: s:cvsFunctions.Annotate(argList) {{{2 -function! s:cvsFunctions.Annotate(argList) - if len(a:argList) == 0 - if &filetype ==? 'cvsannotate' - " This is a CVSAnnotate buffer. Perform annotation of the version - " indicated by the current line. - let caption = matchstr(getline('.'),'\v^[0-9.]+') - - if VCSCommandGetOption('VCSCommandCVSAnnotateParent', 0) != 0 - if caption != '1.1' - let revmaj = matchstr(caption,'\v[0-9.]+\ze\.[0-9]+') - let revmin = matchstr(caption,'\v[0-9.]+\.\zs[0-9]+') - 1 - if revmin == 0 - " Jump to ancestor branch - let caption = matchstr(revmaj,'\v[0-9.]+\ze\.[0-9]+') - else - let caption = revmaj . "." . revmin - endif - endif - endif - - let options = ['-r' . caption] - else - " CVS defaults to pulling HEAD, regardless of current branch. - " Therefore, always pass desired revision. - let caption = '' - let options = ['-r' . s:GetRevision()] - endif - elseif len(a:argList) == 1 && a:argList[0] !~ '^-' - let caption = a:argList[0] - let options = ['-r' . caption] - else - let caption = join(a:argList) - let options = a:argList - endif - - let resultBuffer = s:DoCommand(join(['-q', 'annotate'] + options), 'annotate', caption, {}) - if resultBuffer > 0 - " Remove header lines from standard error - silent v/^\d\+\%(\.\d\+\)\+/d - endif - return resultBuffer -endfunction - -" Function: s:cvsFunctions.Commit(argList) {{{2 -function! s:cvsFunctions.Commit(argList) - let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {}) - if resultBuffer == 0 - echomsg 'No commit needed.' - endif - return resultBuffer -endfunction - -" Function: s:cvsFunctions.Delete() {{{2 -" By default, use the -f option to remove the file first. If options are -" passed in, use those instead. -function! s:cvsFunctions.Delete(argList) - let options = ['-f'] - let caption = '' - if len(a:argList) > 0 - let options = a:argList - let caption = join(a:argList, ' ') - endif - return s:DoCommand(join(['remove'] + options, ' '), 'delete', caption, {}) -endfunction - -" Function: s:cvsFunctions.Diff(argList) {{{2 -function! s:cvsFunctions.Diff(argList) - if len(a:argList) == 0 - let revOptions = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let revOptions = ['-r' . join(a:argList, ' -r')] - let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')' - else - " Pass-through - let caption = join(a:argList, ' ') - let revOptions = a:argList - endif - - let cvsDiffOpt = VCSCommandGetOption('VCSCommandCVSDiffOpt', 'u') - if cvsDiffOpt == '' - let diffOptions = [] - else - let diffOptions = ['-' . cvsDiffOpt] - endif - - return s:DoCommand(join(['diff'] + diffOptions + revOptions), 'diff', caption, {'allowNonZeroExit': 1}) -endfunction - -" Function: s:cvsFunctions.GetBufferInfo() {{{2 -" Provides version control details for the current file. Current version -" number and current repository version number are required to be returned by -" the vcscommand plugin. This CVS extension adds branch name to the return -" list as well. -" Returns: List of results: [revision, repository, branch] - -function! s:cvsFunctions.GetBufferInfo() - let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) - let fileName = bufname(originalBuffer) - if isdirectory(fileName) - let tag = '' - if filereadable(fileName . '/CVS/Tag') - let tagFile = readfile(fileName . '/CVS/Tag') - if len(tagFile) == 1 - let tag = substitute(tagFile[0], '^T', '', '') - endif - endif - return [tag] - endif - let realFileName = fnamemodify(resolve(fileName), ':t') - if !filereadable(fileName) - return ['Unknown'] - endif - let oldCwd = VCSCommandChangeToCurrentFileDir(fileName) - try - let statusText=s:VCSCommandUtility.system(s:Executable() . ' status -- "' . realFileName . '"') - if(v:shell_error) - return [] - endif - let revision=substitute(statusText, '^\_.*Working revision:\s*\(\d\+\%(\.\d\+\)\+\|New file!\)\_.*$', '\1', '') - - " We can still be in a CVS-controlled directory without this being a CVS - " file - if match(revision, '^New file!$') >= 0 - let revision='New' - elseif match(revision, '^\d\+\.\d\+\%(\.\d\+\.\d\+\)*$') <0 - return ['Unknown'] - endif - - let branch=substitute(statusText, '^\_.*Sticky Tag:\s\+\(\d\+\%(\.\d\+\)\+\|\a[A-Za-z0-9-_]*\|(none)\).*$', '\1', '') - let repository=substitute(statusText, '^\_.*Repository revision:\s*\(\d\+\%(\.\d\+\)\+\|New file!\|No revision control file\)\_.*$', '\1', '') - let repository=substitute(repository, '^New file!\|No revision control file$', 'New', '') - return [revision, repository, branch] - finally - call VCSCommandChdir(oldCwd) - endtry -endfunction - -" Function: s:cvsFunctions.Log() {{{2 -function! s:cvsFunctions.Log(argList) - if len(a:argList) == 0 - let options = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let options = ['-r' . join(a:argList, ':')] - let caption = options[0] - else - " Pass-through - let options = a:argList - let caption = join(a:argList, ' ') - endif - - return s:DoCommand(join(['log'] + options), 'log', caption, {}) -endfunction - -" Function: s:cvsFunctions.Revert(argList) {{{2 -function! s:cvsFunctions.Revert(argList) - return s:DoCommand('update -C', 'revert', '', {}) -endfunction - -" Function: s:cvsFunctions.Review(argList) {{{2 -function! s:cvsFunctions.Review(argList) - if len(a:argList) == 0 - let versiontag = '(current)' - let versionOption = '' - else - let versiontag = a:argList[0] - let versionOption = ' -r ' . versiontag . ' ' - endif - - return s:DoCommand('-q update -p' . versionOption, 'review', versiontag, {}) -endfunction - -" Function: s:cvsFunctions.Status(argList) {{{2 -function! s:cvsFunctions.Status(argList) - return s:DoCommand(join(['status'] + a:argList, ' '), 'status', join(a:argList, ' '), {}) -endfunction - -" Function: s:cvsFunctions.Update(argList) {{{2 -function! s:cvsFunctions.Update(argList) - return s:DoCommand('update', 'update', '', {}) -endfunction - -" Section: CVS-specific functions {{{1 - -" Function: s:CVSEdit() {{{2 -function! s:CVSEdit() - return s:DoCommand('edit', 'cvsedit', '', {}) -endfunction - -" Function: s:CVSEditors() {{{2 -function! s:CVSEditors() - return s:DoCommand('editors', 'cvseditors', '', {}) -endfunction - -" Function: s:CVSUnedit() {{{2 -function! s:CVSUnedit() - return s:DoCommand('unedit', 'cvsunedit', '', {}) -endfunction - -" Function: s:CVSWatch(onoff) {{{2 -function! s:CVSWatch(onoff) - if a:onoff !~ '^\c\%(on\|off\|add\|remove\)$' - echoerr 'Argument to CVSWatch must be one of [on|off|add|remove]' - return -1 - end - return s:DoCommand('watch ' . tolower(a:onoff), 'cvswatch', '', {}) -endfunction - -" Function: s:CVSWatchers() {{{2 -function! s:CVSWatchers() - return s:DoCommand('watchers', 'cvswatchers', '', {}) -endfunction - -" Annotate setting {{{2 -let s:cvsFunctions.AnnotateSplitRegex = '): ' - -" Section: Command definitions {{{1 -" Section: Primary commands {{{2 -com! CVSEdit call s:CVSEdit() -com! CVSEditors call s:CVSEditors() -com! CVSUnedit call s:CVSUnedit() -com! -nargs=1 CVSWatch call s:CVSWatch() -com! CVSWatchAdd call s:CVSWatch('add') -com! CVSWatchOn call s:CVSWatch('on') -com! CVSWatchOff call s:CVSWatch('off') -com! CVSWatchRemove call s:CVSWatch('remove') -com! CVSWatchers call s:CVSWatchers() - -" Section: Plugin command mappings {{{1 - -let s:cvsExtensionMappings = {} -if !exists("no_plugin_maps") - let mappingInfo = [ - \['CVSEdit', 'CVSEdit', 'e'], - \['CVSEditors', 'CVSEditors', 'E'], - \['CVSUnedit', 'CVSUnedit', 't'], - \['CVSWatchers', 'CVSWatchers', 'wv'], - \['CVSWatchAdd', 'CVSWatch add', 'wa'], - \['CVSWatchOff', 'CVSWatch off', 'wf'], - \['CVSWatchOn', 'CVSWatch on', 'wn'], - \['CVSWatchRemove', 'CVSWatch remove', 'wr'] - \] - - for [pluginName, commandText, shortCut] in mappingInfo - execute 'nnoremap ' . pluginName . ' :' . commandText . '' - if !hasmapto('' . pluginName) - let s:cvsExtensionMappings[shortCut] = commandText - endif - endfor -endif - -" Section: Plugin Registration {{{1 -let s:VCSCommandUtility = VCSCommandRegisterModule('CVS', expand(''), s:cvsFunctions, s:cvsExtensionMappings) - -" Section: Menu items {{{1 -for [s:shortcut, s:command] in [ - \['CVS.&Edit', 'CVSEdit'], - \['CVS.Ed&itors', 'CVSEditors'], - \['CVS.Unedi&t', 'CVSUnedit'], - \['CVS.&Watchers', 'CVSWatchers'], - \['CVS.WatchAdd', 'CVSWatchAdd'], - \['CVS.WatchOn', 'CVSWatchOn'], - \['CVS.WatchOff', 'CVSWatchOff'], - \['CVS.WatchRemove', 'CVSWatchRemove'] - \] - call s:VCSCommandUtility.addMenuItem(s:shortcut, s:command) -endfor -unlet s:shortcut s:command - -let &cpo = s:save_cpo diff --git a/.vim/plugin/vcsgit.vim b/.vim/plugin/vcsgit.vim deleted file mode 100755 index 2667982..0000000 --- a/.vim/plugin/vcsgit.vim +++ /dev/null @@ -1,249 +0,0 @@ -" vim600: set foldmethod=marker: -" -" git extension for VCSCommand. -" -" Maintainer: Bob Hiestand -" License: -" Copyright (c) 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 -" -" Options documentation: {{{2 -" -" VCSCommandGitExec -" This variable specifies the git executable. If not set, it defaults to -" 'git' executed from the user's executable path. -" -" VCSCommandGitDiffOpt -" This variable, if set, determines the default options passed to the -" VCSDiff command. If any options (starting with '-') are passed to the -" command, this variable is not used. - -" Section: Plugin header {{{1 - -if exists('VCSCommandDisableAll') - finish -endif - -if v:version < 700 - echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None - finish -endif - -if !exists('g:loaded_VCSCommand') - runtime plugin/vcscommand.vim -endif - -if !executable(VCSCommandGetOption('VCSCommandGitExec', 'git')) - " git is not installed - finish -endif - -let s:save_cpo=&cpo -set cpo&vim - -" Section: Variable initialization {{{1 - -let s:gitFunctions = {} - -" Section: Utility functions {{{1 - -" Function: s:Executable() {{{2 -" Returns the executable used to invoke git suitable for use in a shell -" command. -function! s:Executable() - return VCSCommandGetOption('VCSCommandGitExec', 'git') -endfunction - -" Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2 -" Wrapper to VCSCommandDoCommand to add the name of the git executable to the -" command argument. -function! s:DoCommand(cmd, cmdName, statusText, options) - if VCSCommandGetVCSType(expand('%')) == 'git' - let fullCmd = s:Executable() . ' ' . a:cmd - return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options) - else - throw 'git VCSCommand plugin called on non-git item.' - endif -endfunction - -" Section: VCS function implementations {{{1 - -" Function: s:gitFunctions.Identify(buffer) {{{2 -" This function only returns an inexact match due to the detection method used -" by git, which simply traverses the directory structure upward. -function! s:gitFunctions.Identify(buffer) - let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(a:buffer))) - try - call s:VCSCommandUtility.system(s:Executable() . ' rev-parse --is-inside-work-tree') - if(v:shell_error) - return 0 - else - return g:VCSCOMMAND_IDENTIFY_INEXACT - endif - finally - call VCSCommandChdir(oldCwd) - endtry -endfunction - -" Function: s:gitFunctions.Add(argList) {{{2 -function! s:gitFunctions.Add(argList) - return s:DoCommand(join(['add'] + ['-v'] + a:argList, ' '), 'add', join(a:argList, ' '), {}) -endfunction - -" Function: s:gitFunctions.Annotate(argList) {{{2 -function! s:gitFunctions.Annotate(argList) - if len(a:argList) == 0 - if &filetype == 'gitannotate' - " Perform annotation of the version indicated by the current line. - let options = matchstr(getline('.'),'^\x\+') - else - let options = '' - endif - elseif len(a:argList) == 1 && a:argList[0] !~ '^-' - let options = a:argList[0] - else - let options = join(a:argList, ' ') - endif - - return s:DoCommand('blame ' . options, 'annotate', options, {}) -endfunction - -" Function: s:gitFunctions.Commit(argList) {{{2 -function! s:gitFunctions.Commit(argList) - try - return s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {}) - catch /\m^Version control command failed.*nothing\%( added\)\? to commit/ - echomsg 'No commit needed.' - endtry -endfunction - -" Function: s:gitFunctions.Delete() {{{2 -" All options are passed through. -function! s:gitFunctions.Delete(argList) - let options = a:argList - let caption = join(a:argList, ' ') - return s:DoCommand(join(['rm'] + options, ' '), 'delete', caption, {}) -endfunction - -" Function: s:gitFunctions.Diff(argList) {{{2 -" Pass-through call to git-diff. If no options (starting with '-') are found, -" then the options in the 'VCSCommandGitDiffOpt' variable are added. -function! s:gitFunctions.Diff(argList) - let gitDiffOpt = VCSCommandGetOption('VCSCommandGitDiffOpt', '') - if gitDiffOpt == '' - let diffOptions = [] - else - let diffOptions = [gitDiffOpt] - for arg in a:argList - if arg =~ '^-' - let diffOptions = [] - break - endif - endfor - endif - - return s:DoCommand(join(['diff'] + diffOptions + a:argList), 'diff', join(a:argList), {}) -endfunction - -" Function: s:gitFunctions.GetBufferInfo() {{{2 -" Provides version control details for the current file. Current version -" number and current repository version number are required to be returned by -" the vcscommand plugin. This CVS extension adds branch name to the return -" list as well. -" Returns: List of results: [revision, repository, branch] - -function! s:gitFunctions.GetBufferInfo() - let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname('%'))) - try - let branch = substitute(s:VCSCommandUtility.system(s:Executable() . ' symbolic-ref -q HEAD'), '\n$', '', '') - if v:shell_error - let branch = 'DETACHED' - else - let branch = substitute(branch, '^refs/heads/', '', '') - endif - - let info = [branch] - - for method in split(VCSCommandGetOption('VCSCommandGitDescribeArgList', (',tags,all,always')), ',', 1) - if method != '' - let method = ' --' . method - endif - let tag = substitute(s:VCSCommandUtility.system(s:Executable() . ' describe' . method), '\n$', '', '') - if !v:shell_error - call add(info, tag) - break - endif - endfor - - return info - finally - call VCSCommandChdir(oldCwd) - endtry -endfunction - -" Function: s:gitFunctions.Log() {{{2 -function! s:gitFunctions.Log(argList) - return s:DoCommand(join(['log'] + a:argList), 'log', join(a:argList, ' '), {}) -endfunction - -" Function: s:gitFunctions.Revert(argList) {{{2 -function! s:gitFunctions.Revert(argList) - return s:DoCommand('checkout', 'revert', '', {}) -endfunction - -" Function: s:gitFunctions.Review(argList) {{{2 -function! s:gitFunctions.Review(argList) - if len(a:argList) == 0 - let revision = 'HEAD' - else - let revision = a:argList[0] - endif - - let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(VCSCommandGetOriginalBuffer('%')))) - try - let prefix = s:VCSCommandUtility.system(s:Executable() . ' rev-parse --show-prefix') - finally - call VCSCommandChdir(oldCwd) - endtry - - let prefix = substitute(prefix, '\n$', '', '') - let blob = '"' . revision . ':' . prefix . '"' - return s:DoCommand('show ' . blob, 'review', revision, {}) -endfunction - -" Function: s:gitFunctions.Status(argList) {{{2 -function! s:gitFunctions.Status(argList) - return s:DoCommand(join(['status'] + a:argList), 'status', join(a:argList), {'allowNonZeroExit': 1}) -endfunction - -" Function: s:gitFunctions.Update(argList) {{{2 -function! s:gitFunctions.Update(argList) - throw "This command is not implemented for git because file-by-file update doesn't make much sense in that context. If you have an idea for what it should do, please let me know." -endfunction - -" Annotate setting {{{2 -let s:gitFunctions.AnnotateSplitRegex = ') ' - -" Section: Plugin Registration {{{1 -let s:VCSCommandUtility = VCSCommandRegisterModule('git', expand(''), s:gitFunctions, []) - -let &cpo = s:save_cpo diff --git a/.vim/plugin/vcshg.vim b/.vim/plugin/vcshg.vim deleted file mode 100644 index 775ede0..0000000 --- a/.vim/plugin/vcshg.vim +++ /dev/null @@ -1,275 +0,0 @@ -" vim600: set foldmethod=marker: -" -" Mercurial extension for VCSCommand. -" -" Maintainer: Bob Hiestand -" License: -" Copyright (c) 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 -" -" Options documentation: {{{2 -" -" VCSCommandHGExec -" This variable specifies the mercurial executable. If not set, it defaults -" to 'hg' executed from the user's executable path. -" -" VCSCommandHGDiffExt -" This variable, if set, sets the external diff program used by Subversion. -" -" VCSCommandHGDiffOpt -" This variable, if set, determines the options passed to the hg diff -" command (such as 'u', 'w', or 'b'). - -" Section: Plugin header {{{1 - -if exists('VCSCommandDisableAll') - finish -endif - -if v:version < 700 - echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None - finish -endif - -if !exists('g:loaded_VCSCommand') - runtime plugin/vcscommand.vim -endif - -if !executable(VCSCommandGetOption('VCSCommandHGExec', 'hg')) - " HG is not installed - finish -endif - -let s:save_cpo=&cpo -set cpo&vim - -" Section: Variable initialization {{{1 - -let s:hgFunctions = {} - -" Section: Utility functions {{{1 - -" Function: s:Executable() {{{2 -" Returns the executable used to invoke hg suitable for use in a shell -" command. -function! s:Executable() - return VCSCommandGetOption('VCSCommandHGExec', 'hg') -endfunction - -" Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2 -" Wrapper to VCSCommandDoCommand to add the name of the HG executable to the -" command argument. -function! s:DoCommand(cmd, cmdName, statusText, options) - if VCSCommandGetVCSType(expand('%')) == 'HG' - let fullCmd = s:Executable() . ' ' . a:cmd - return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options) - else - throw 'HG VCSCommand plugin called on non-HG item.' - endif -endfunction - -" Section: VCS function implementations {{{1 - -" Function: s:hgFunctions.Identify(buffer) {{{2 -function! s:hgFunctions.Identify(buffer) - let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(a:buffer))) - try - call s:VCSCommandUtility.system(s:Executable() . ' root') - if(v:shell_error) - return 0 - else - return g:VCSCOMMAND_IDENTIFY_INEXACT - endif - finally - call VCSCommandChdir(oldCwd) - endtry -endfunction - -" Function: s:hgFunctions.Add() {{{2 -function! s:hgFunctions.Add(argList) - return s:DoCommand(join(['add -v'] + a:argList, ' '), 'add', join(a:argList, ' '), {}) -endfunction - -" Function: s:hgFunctions.Annotate(argList) {{{2 -function! s:hgFunctions.Annotate(argList) - if len(a:argList) == 0 - if &filetype ==? 'hgannotate' - " Perform annotation of the version indicated by the current line. - let caption = matchstr(getline('.'),'\v^\s*\w+\s+\zs\d+') - let options = ' -un -r' . caption - else - let caption = '' - let options = ' -un' - endif - elseif len(a:argList) == 1 && a:argList[0] !~ '^-' - let caption = a:argList[0] - let options = ' -un -r' . caption - else - let caption = join(a:argList, ' ') - let options = ' ' . caption - endif - - return s:DoCommand('blame' . options, 'annotate', caption, {}) -endfunction - -" Function: s:hgFunctions.Commit(argList) {{{2 -function! s:hgFunctions.Commit(argList) - try - return s:DoCommand('commit -v -l "' . a:argList[0] . '"', 'commit', '', {}) - catch /Version control command failed.*nothing changed/ - echomsg 'No commit needed.' - endtry -endfunction - -" Function: s:hgFunctions.Delete() {{{2 -function! s:hgFunctions.Delete(argList) - return s:DoCommand(join(['remove'] + a:argList, ' '), 'remove', join(a:argList, ' '), {}) -endfunction - -" Function: s:hgFunctions.Diff(argList) {{{2 -function! s:hgFunctions.Diff(argList) - if len(a:argList) == 0 - let revOptions = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let revOptions = ['-r' . join(a:argList, ':')] - let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')' - else - " Pass-through - let caption = join(a:argList, ' ') - let revOptions = a:argList - endif - - let hgDiffExt = VCSCommandGetOption('VCSCommandHGDiffExt', '') - if hgDiffExt == '' - let diffExt = [] - else - let diffExt = ['--diff-cmd ' . hgDiffExt] - endif - - let hgDiffOpt = VCSCommandGetOption('VCSCommandHGDiffOpt', '') - if hgDiffOpt == '' - let diffOptions = [] - else - let diffOptions = ['-x -' . hgDiffOpt] - endif - - return s:DoCommand(join(['diff'] + diffExt + diffOptions + revOptions), 'diff', caption, {}) -endfunction - -" Function: s:hgFunctions.Info(argList) {{{2 -function! s:hgFunctions.Info(argList) - return s:DoCommand(join(['log --limit 1'] + a:argList, ' '), 'log', join(a:argList, ' '), {}) -endfunction - -" Function: s:hgFunctions.GetBufferInfo() {{{2 -" Provides version control details for the current file. Current version -" number and current repository version number are required to be returned by -" the vcscommand plugin. -" Returns: List of results: [revision, repository, branch] - -function! s:hgFunctions.GetBufferInfo() - let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) - let fileName = bufname(originalBuffer) - let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -- "' . fileName . '"') - if(v:shell_error) - return [] - endif - - " File not under HG control. - if statusText =~ '^?' - return ['Unknown'] - endif - - let parentsText = s:VCSCommandUtility.system(s:Executable() . ' parents -- "' . fileName . '"') - let revision = matchlist(parentsText, '^changeset:\s\+\(\S\+\)\n')[1] - - let logText = s:VCSCommandUtility.system(s:Executable() . ' log -- "' . fileName . '"') - let repository = matchlist(logText, '^changeset:\s\+\(\S\+\)\n')[1] - - if revision == '' - " Error - return ['Unknown'] - elseif statusText =~ '^A' - return ['New', 'New'] - else - return [revision, repository] - endif -endfunction - -" Function: s:hgFunctions.Log(argList) {{{2 -function! s:hgFunctions.Log(argList) - if len(a:argList) == 0 - let options = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let options = ['-r' . join(a:argList, ':')] - let caption = options[0] - else - " Pass-through - let options = a:argList - let caption = join(a:argList, ' ') - endif - - let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {}) - return resultBuffer -endfunction - -" Function: s:hgFunctions.Revert(argList) {{{2 -function! s:hgFunctions.Revert(argList) - return s:DoCommand('revert', 'revert', '', {}) -endfunction - -" Function: s:hgFunctions.Review(argList) {{{2 -function! s:hgFunctions.Review(argList) - if len(a:argList) == 0 - let versiontag = '(current)' - let versionOption = '' - else - let versiontag = a:argList[0] - let versionOption = ' -r ' . versiontag . ' ' - endif - - return s:DoCommand('cat' . versionOption, 'review', versiontag, {}) -endfunction - -" Function: s:hgFunctions.Status(argList) {{{2 -function! s:hgFunctions.Status(argList) - let options = ['-A', '-v'] - if len(a:argList) != 0 - let options = a:argList - endif - return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {}) -endfunction - -" Function: s:hgFunctions.Update(argList) {{{2 -function! s:hgFunctions.Update(argList) - return s:DoCommand('update', 'update', '', {}) -endfunction - -" Annotate setting {{{2 -let s:hgFunctions.AnnotateSplitRegex = '\d\+: ' - -" Section: Plugin Registration {{{1 -let s:VCSCommandUtility = VCSCommandRegisterModule('HG', expand(''), s:hgFunctions, []) - -let &cpo = s:save_cpo diff --git a/.vim/plugin/vcssvk.vim b/.vim/plugin/vcssvk.vim deleted file mode 100644 index bee84c3..0000000 --- a/.vim/plugin/vcssvk.vim +++ /dev/null @@ -1,259 +0,0 @@ -" vim600: set foldmethod=marker: -" -" SVK extension for VCSCommand. -" -" Maintainer: Bob Hiestand -" License: -" Copyright (c) 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 -" -" Options documentation: {{{2 -" -" VCSCommandSVKExec -" This variable specifies the SVK executable. If not set, it defaults to -" 'svk' executed from the user's executable path. - -" Section: Plugin header {{{1 - -if exists('VCSCommandDisableAll') - finish -endif - -if v:version < 700 - echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None - finish -endif - -if !exists('g:loaded_VCSCommand') - runtime plugin/vcscommand.vim -endif - -if !executable(VCSCommandGetOption('VCSCommandSVKExec', 'svk')) - " SVK is not installed - finish -endif - -let s:save_cpo=&cpo -set cpo&vim - -" Section: Variable initialization {{{1 - -let s:svkFunctions = {} - -" Section: Utility functions {{{1 - -" Function: s:Executable() {{{2 -" Returns the executable used to invoke SVK suitable for use in a shell -" command. -function! s:Executable() - return VCSCommandGetOption('VCSCommandSVKExec', 'svk') -endfunction - -" Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2 -" Wrapper to VCSCommandDoCommand to add the name of the SVK executable to the -" command argument. -function! s:DoCommand(cmd, cmdName, statusText, options) - if VCSCommandGetVCSType(expand('%')) == 'SVK' - let fullCmd = s:Executable() . ' ' . a:cmd - return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options) - else - throw 'SVK VCSCommand plugin called on non-SVK item.' - endif -endfunction - -" Section: VCS function implementations {{{1 - -" Function: s:svkFunctions.Identify(buffer) {{{2 -function! s:svkFunctions.Identify(buffer) - let fileName = resolve(bufname(a:buffer)) - if isdirectory(fileName) - let directoryName = fileName - else - let directoryName = fnamemodify(fileName, ':p:h') - endif - let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . directoryName . '"', "no") - if(v:shell_error) - return 0 - else - return 1 - endif -endfunction - -" Function: s:svkFunctions.Add() {{{2 -function! s:svkFunctions.Add(argList) - return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {}) -endfunction - -" Function: s:svkFunctions.Annotate(argList) {{{2 -function! s:svkFunctions.Annotate(argList) - if len(a:argList) == 0 - if &filetype ==? 'svkannotate' - " Perform annotation of the version indicated by the current line. - let caption = matchstr(getline('.'),'\v^\s+\zs\d+') - let options = ' -r' . caption - else - let caption = '' - let options = '' - endif - elseif len(a:argList) == 1 && a:argList[0] !~ '^-' - let caption = a:argList[0] - let options = ' -r' . caption - else - let caption = join(a:argList, ' ') - let options = ' ' . caption - endif - - let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {}) - if resultBuffer > 0 - normal! 1G2dd - endif - return resultBuffer -endfunction - -" Function: s:svkFunctions.Commit(argList) {{{2 -function! s:svkFunctions.Commit(argList) - let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {}) - if resultBuffer == 0 - echomsg 'No commit needed.' - endif -endfunction - -" Function: s:svkFunctions.Delete() {{{2 -function! s:svkFunctions.Delete(argList) - return s:DoCommand(join(['delete'] + a:argList, ' '), 'delete', join(a:argList, ' '), {}) -endfunction - -" Function: s:svkFunctions.Diff(argList) {{{2 -function! s:svkFunctions.Diff(argList) - if len(a:argList) == 0 - let revOptions = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let revOptions = ['-r' . join(a:argList, ':')] - let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')' - else - " Pass-through - let caption = join(a:argList, ' ') - let revOptions = a:argList - endif - - return s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {}) -endfunction - -" Function: s:svkFunctions.GetBufferInfo() {{{2 -" Provides version control details for the current file. Current version -" number and current repository version number are required to be returned by -" the vcscommand plugin. -" Returns: List of results: [revision, repository] - -function! s:svkFunctions.GetBufferInfo() - let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) - let fileName = resolve(bufname(originalBuffer)) - let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -v -- "' . fileName . '"') - if(v:shell_error) - return [] - endif - - " File not under SVK control. - if statusText =~ '^?' - return ['Unknown'] - endif - - let [flags, revision, repository] = matchlist(statusText, '^\(.\{3}\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s')[1:3] - if revision == '' - " Error - return ['Unknown'] - elseif flags =~ '^A' - return ['New', 'New'] - else - return [revision, repository] - endif -endfunction - -" Function: s:svkFunctions.Info(argList) {{{2 -function! s:svkFunctions.Info(argList) - return s:DoCommand(join(['info'] + a:argList, ' '), 'info', join(a:argList, ' '), {}) -endfunction - -" Function: s:svkFunctions.Lock(argList) {{{2 -function! s:svkFunctions.Lock(argList) - return s:DoCommand(join(['lock'] + a:argList, ' '), 'lock', join(a:argList, ' '), {}) -endfunction - -" Function: s:svkFunctions.Log() {{{2 -function! s:svkFunctions.Log(argList) - if len(a:argList) == 0 - let options = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let options = ['-r' . join(a:argList, ':')] - let caption = options[0] - else - " Pass-through - let options = a:argList - let caption = join(a:argList, ' ') - endif - - let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {}) - return resultBuffer -endfunction - -" Function: s:svkFunctions.Revert(argList) {{{2 -function! s:svkFunctions.Revert(argList) - return s:DoCommand('revert', 'revert', '', {}) -endfunction - -" Function: s:svkFunctions.Review(argList) {{{2 -function! s:svkFunctions.Review(argList) - if len(a:argList) == 0 - let versiontag = '(current)' - let versionOption = '' - else - let versiontag = a:argList[0] - let versionOption = ' -r ' . versiontag . ' ' - endif - - return s:DoCommand('cat' . versionOption, 'review', versiontag, {}) -endfunction - -" Function: s:svkFunctions.Status(argList) {{{2 -function! s:svkFunctions.Status(argList) - let options = ['-v'] - if len(a:argList) != 0 - let options = a:argList - endif - return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {}) -endfunction - -" Function: s:svkFunctions.Unlock(argList) {{{2 -function! s:svkFunctions.Unlock(argList) - return s:DoCommand(join(['unlock'] + a:argList, ' '), 'unlock', join(a:argList, ' '), {}) -endfunction -" Function: s:svkFunctions.Update(argList) {{{2 -function! s:svkFunctions.Update(argList) - return s:DoCommand('update', 'update', '', {}) -endfunction - -" Section: Plugin Registration {{{1 -let s:VCSCommandUtility = VCSCommandRegisterModule('SVK', expand(''), s:svkFunctions, []) - -let &cpo = s:save_cpo diff --git a/.vim/plugin/vcssvn.vim b/.vim/plugin/vcssvn.vim deleted file mode 100644 index 8ad6388..0000000 --- a/.vim/plugin/vcssvn.vim +++ /dev/null @@ -1,281 +0,0 @@ -" vim600: set foldmethod=marker: -" -" SVN extension for VCSCommand. -" -" Maintainer: Bob Hiestand -" License: -" Copyright (c) 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 -" -" Options documentation: {{{2 -" -" VCSCommandSVNExec -" This variable specifies the SVN executable. If not set, it defaults to -" 'svn' executed from the user's executable path. -" -" VCSCommandSVNDiffExt -" This variable, if set, sets the external diff program used by Subversion. -" -" VCSCommandSVNDiffOpt -" This variable, if set, determines the options passed to the svn diff -" command (such as 'u', 'w', or 'b'). - -" Section: Plugin header {{{1 - -if exists('VCSCommandDisableAll') - finish -endif - -if v:version < 700 - echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None - finish -endif - -if !exists('g:loaded_VCSCommand') - runtime plugin/vcscommand.vim -endif - -if !executable(VCSCommandGetOption('VCSCommandSVNExec', 'svn')) - " SVN is not installed - finish -endif - -let s:save_cpo=&cpo -set cpo&vim - -" Section: Variable initialization {{{1 - -let s:svnFunctions = {} - -" Section: Utility functions {{{1 - -" Function: s:Executable() {{{2 -" Returns the executable used to invoke git suitable for use in a shell -" command. -function! s:Executable() - return VCSCommandGetOption('VCSCommandSVNExec', 'svn') -endfunction - -" Function: s:DoCommand(cmd, cmdName, statusText, options) {{{2 -" Wrapper to VCSCommandDoCommand to add the name of the SVN executable to the -" command argument. -function! s:DoCommand(cmd, cmdName, statusText, options) - if VCSCommandGetVCSType(expand('%')) == 'SVN' - let fullCmd = s:Executable() . ' ' . a:cmd - return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options) - else - throw 'SVN VCSCommand plugin called on non-SVN item.' - endif -endfunction - -" Section: VCS function implementations {{{1 - -" Function: s:svnFunctions.Identify(buffer) {{{2 -function! s:svnFunctions.Identify(buffer) - let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(a:buffer))) - try - call s:VCSCommandUtility.system(s:Executable() . ' info .') - if(v:shell_error) - return 0 - else - return g:VCSCOMMAND_IDENTIFY_EXACT - endif - finally - call VCSCommandChdir(oldCwd) - endtry -endfunction - -" Function: s:svnFunctions.Add() {{{2 -function! s:svnFunctions.Add(argList) - return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {}) -endfunction - -" Function: s:svnFunctions.Annotate(argList) {{{2 -function! s:svnFunctions.Annotate(argList) - if len(a:argList) == 0 - if &filetype ==? 'svnannotate' - " Perform annotation of the version indicated by the current line. - let caption = matchstr(getline('.'),'\v^\s+\zs\d+') - let options = ' -r' . caption - else - let caption = '' - let options = '' - endif - elseif len(a:argList) == 1 && a:argList[0] !~ '^-' - let caption = a:argList[0] - let options = ' -r' . caption - else - let caption = join(a:argList, ' ') - let options = ' ' . caption - endif - - return s:DoCommand('blame --non-interactive' . options, 'annotate', caption, {}) -endfunction - -" Function: s:svnFunctions.Commit(argList) {{{2 -function! s:svnFunctions.Commit(argList) - let resultBuffer = s:DoCommand('commit --non-interactive -F "' . a:argList[0] . '"', 'commit', '', {}) - if resultBuffer == 0 - echomsg 'No commit needed.' - endif -endfunction - -" Function: s:svnFunctions.Delete() {{{2 -function! s:svnFunctions.Delete(argList) - return s:DoCommand(join(['delete --non-interactive'] + a:argList, ' '), 'delete', join(a:argList, ' '), {}) -endfunction - -" Function: s:svnFunctions.Diff(argList) {{{2 -function! s:svnFunctions.Diff(argList) - if len(a:argList) == 0 - let revOptions = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let revOptions = ['-r' . join(a:argList, ':')] - let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')' - else - " Pass-through - let caption = join(a:argList, ' ') - let revOptions = a:argList - endif - - let svnDiffExt = VCSCommandGetOption('VCSCommandSVNDiffExt', '') - if svnDiffExt == '' - let diffExt = [] - else - let diffExt = ['--diff-cmd ' . svnDiffExt] - endif - - let svnDiffOpt = VCSCommandGetOption('VCSCommandSVNDiffOpt', '') - if svnDiffOpt == '' - let diffOptions = [] - else - let diffOptions = ['-x -' . svnDiffOpt] - endif - - return s:DoCommand(join(['diff --non-interactive'] + diffExt + diffOptions + revOptions), 'diff', caption, {}) -endfunction - -" Function: s:svnFunctions.GetBufferInfo() {{{2 -" Provides version control details for the current file. Current version -" number and current repository version number are required to be returned by -" the vcscommand plugin. -" Returns: List of results: [revision, repository, branch] - -function! s:svnFunctions.GetBufferInfo() - let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) - let fileName = bufname(originalBuffer) - let statusText = s:VCSCommandUtility.system(s:Executable() . ' status --non-interactive -v -- "' . fileName . '"') - if(v:shell_error) - return [] - endif - - " File not under SVN control. - if statusText =~ '^?' - return ['Unknown'] - endif - - let [flags, revision, repository] = matchlist(statusText, '^\(.\{9}\)\s*\(\d\+\)\s\+\(\d\+\)')[1:3] - if revision == '' - " Error - return ['Unknown'] - elseif flags =~ '^A' - return ['New', 'New'] - elseif flags =~ '*' - return [revision, repository, '*'] - else - return [revision, repository] - endif -endfunction - -" Function: s:svnFunctions.Info(argList) {{{2 -function! s:svnFunctions.Info(argList) - return s:DoCommand(join(['info --non-interactive'] + a:argList, ' '), 'info', join(a:argList, ' '), {}) -endfunction - -" Function: s:svnFunctions.Lock(argList) {{{2 -function! s:svnFunctions.Lock(argList) - return s:DoCommand(join(['lock --non-interactive'] + a:argList, ' '), 'lock', join(a:argList, ' '), {}) -endfunction - -" Function: s:svnFunctions.Log(argList) {{{2 -function! s:svnFunctions.Log(argList) - if len(a:argList) == 0 - let options = [] - let caption = '' - elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1 - let options = ['-r' . join(a:argList, ':')] - let caption = options[0] - else - " Pass-through - let options = a:argList - let caption = join(a:argList, ' ') - endif - - let resultBuffer = s:DoCommand(join(['log --non-interactive', '-v'] + options), 'log', caption, {}) - return resultBuffer -endfunction - -" Function: s:svnFunctions.Revert(argList) {{{2 -function! s:svnFunctions.Revert(argList) - return s:DoCommand('revert', 'revert', '', {}) -endfunction - -" Function: s:svnFunctions.Review(argList) {{{2 -function! s:svnFunctions.Review(argList) - if len(a:argList) == 0 - let versiontag = '(current)' - let versionOption = '' - else - let versiontag = a:argList[0] - let versionOption = ' -r ' . versiontag . ' ' - endif - - return s:DoCommand('cat --non-interactive' . versionOption, 'review', versiontag, {}) -endfunction - -" Function: s:svnFunctions.Status(argList) {{{2 -function! s:svnFunctions.Status(argList) - let options = ['-u', '-v'] - if len(a:argList) != 0 - let options = a:argList - endif - return s:DoCommand(join(['status --non-interactive'] + options, ' '), 'status', join(options, ' '), {}) -endfunction - -" Function: s:svnFunctions.Unlock(argList) {{{2 -function! s:svnFunctions.Unlock(argList) - return s:DoCommand(join(['unlock --non-interactive'] + a:argList, ' '), 'unlock', join(a:argList, ' '), {}) -endfunction - -" Function: s:svnFunctions.Update(argList) {{{2 -function! s:svnFunctions.Update(argList) - return s:DoCommand('update --non-interactive', 'update', '', {}) -endfunction - -" Annotate setting {{{2 -let s:svnFunctions.AnnotateSplitRegex = '\s\+\S\+\s\+\S\+ ' - -" Section: Plugin Registration {{{1 -let s:VCSCommandUtility = VCSCommandRegisterModule('SVN', expand(''), s:svnFunctions, []) - -let &cpo = s:save_cpo diff --git a/.vimrc b/.vimrc index a643f8f..d919d2f 100644 --- a/.vimrc +++ b/.vimrc @@ -456,6 +456,9 @@ Plugin 'mbbill/echofunc' " What to test some color ? Plugin 'vim-scripts/Colour-Sampler-Pack.git' +"More VCS Management +Plugin 'vim-scripts/vcscommand.vim' + " More Snippets : Plugin 'tomtom/tlib_vim' Plugin 'MarcWeber/vim-addon-mw-utils'