1
0
mirror of https://github.com/akelge/zsh synced 2025-07-04 21:49:05 +00:00

Added GetLatestScript update plugin and updated all plugins

This commit is contained in:
2013-01-17 12:18:17 +00:00
parent d9013ec2da
commit 4873c64f28
54 changed files with 10380 additions and 4761 deletions

View File

@ -5,7 +5,7 @@
"
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
" License:
" Copyright (c) 2008 Bob Hiestand
" 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
@ -204,6 +204,10 @@
" 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').
@ -226,6 +230,12 @@
" 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
@ -262,6 +272,13 @@
" 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
@ -340,21 +357,12 @@ let s:VCSCommandUtility = {}
" plugin-specific information: {vcs -> [script, {command -> function}, {key -> mapping}]}
let s:plugins = {}
" temporary values of overridden configuration variables
let s:optionOverrides = {}
" Stack of dictionaries representing nested options
let s:executionContext = []
" state flag used to vary behavior of certain automated actions
let s:isEditFileRunning = 0
" commands needed to restore diff buffers to their original state
unlet! s:vimDiffRestoreCmd
" original buffer currently reflected in vimdiff windows
unlet! s:vimDiffSourceBuffer
"
unlet! s:vimDiffScratchList
" Section: Utility functions {{{1
" Function: s:ReportError(mapping) {{{2
@ -365,7 +373,7 @@ function! s:ReportError(error)
echohl WarningMsg|echomsg 'VCSCommand: ' . a:error|echohl None
endfunction
" Function s:VCSCommandUtility.system(...) {{{2
" Function: s:VCSCommandUtility.system(...) {{{2
" Replacement for system() function. This version protects the quoting in the
" command line on Windows systems.
@ -375,12 +383,58 @@ function! s:VCSCommandUtility.system(...)
set sxq=\"
endif
try
return call('system', a:000)
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 <silent> '.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
@ -416,7 +470,7 @@ function! s:ExecuteExtensionMapping(mapping)
if !has_key(s:plugins[vcsType][2], a:mapping)
throw 'This extended mapping is not defined for ' . vcsType
endif
silent execute 'normal' ':' . s:plugins[vcsType][2][a:mapping] . "\<CR>"
silent execute 'normal!' ':' . s:plugins[vcsType][2][a:mapping] . "\<CR>"
endfunction
" Function: s:ExecuteVCSCommand(command, argList) {{{2
@ -469,7 +523,7 @@ function! s:GenerateResultBufferName(command, originalBuffer, vcsType, statusTex
let bufferName .= ' ' . fileName
let counter = 0
let versionedBufferName = bufferName
while buflisted(versionedBufferName)
while bufexists(versionedBufferName)
let counter += 1
let versionedBufferName = bufferName . ' (' . counter . ')'
endwhile
@ -489,7 +543,7 @@ function! s:GenerateResultBufferNameWithExtension(command, originalBuffer, vcsTy
let bufferName .= ' ' . fileName . VCSCommandGetOption('VCSCommandResultBufferNameExtension', '.vcs')
let counter = 0
let versionedBufferName = bufferName
while buflisted(versionedBufferName)
while bufexists(versionedBufferName)
let counter += 1
let versionedBufferName = '(' . counter . ') ' . bufferName
endwhile
@ -524,6 +578,64 @@ function! s:EditFile(command, originalBuffer, statusText)
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.
@ -548,7 +660,7 @@ function! s:SetupScratchBuffer(command, vcsType, originalBuffer, statusText)
setlocal buftype=nofile
setlocal noswapfile
let &filetype = a:vcsType . a:command
let &filetype = tolower(a:vcsType . a:command)
if VCSCommandGetOption('VCSCommandDeleteOnHide', 0)
setlocal bufhidden=delete
@ -604,21 +716,6 @@ function! s:MarkOrigBufferForSetup(buffer)
return a:buffer
endfunction
" Function: s:OverrideOption(option, [value]) {{{2
" Provides a temporary override for the given VCS option. If no value is
" passed, the override is disabled.
function! s:OverrideOption(option, ...)
if a:0 == 0
call remove(s:optionOverrides[a:option], -1)
else
if !has_key(s:optionOverrides, a:option)
let s:optionOverrides[a:option] = []
endif
call add(s:optionOverrides[a:option], a:1)
endif
endfunction
" Function: s:WipeoutCommandBuffers() {{{2
" Clears all current VCS output buffers of the specified type for a given source.
@ -642,30 +739,30 @@ endfunction
function! s:VimDiffRestore(vimDiffBuff)
let s:isEditFileRunning += 1
try
if exists('s:vimDiffSourceBuffer')
if a:vimDiffBuff == s:vimDiffSourceBuffer
if exists('t:vcsCommandVimDiffSourceBuffer')
if a:vimDiffBuff == t:vcsCommandVimDiffSourceBuffer
" Original file is being removed.
unlet! s:vimDiffSourceBuffer
unlet! s:vimDiffRestoreCmd
unlet! s:vimDiffScratchList
unlet! t:vcsCommandVimDiffSourceBuffer
unlet! t:vcsCommandVimDiffRestoreCmd
unlet! t:vcsCommandVimDiffScratchList
else
let index = index(s:vimDiffScratchList, a:vimDiffBuff)
let index = index(t:vcsCommandVimDiffScratchList, a:vimDiffBuff)
if index >= 0
call remove(s:vimDiffScratchList, index)
if len(s:vimDiffScratchList) == 0
if exists('s:vimDiffRestoreCmd')
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(s:vimDiffSourceBuffer)
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) == s:vimDiffSourceBuffer
if winbufnr(sourceWinNR) == t:vcsCommandVimDiffSourceBuffer
execute sourceWinNR . 'wincmd w'
if getwinvar(0, '&diff')
execute s:vimDiffRestoreCmd
execute t:vcsCommandVimDiffRestoreCmd
endif
endif
let sourceWinNR = sourceWinNR + 1
@ -675,18 +772,18 @@ function! s:VimDiffRestore(vimDiffBuff)
" The buffer is hidden. It must be visible in order to set the
" diff option.
let currentBufNR = bufnr('')
execute 'hide buffer' s:vimDiffSourceBuffer
execute 'hide buffer' t:vcsCommandVimDiffSourceBuffer
if getwinvar(0, '&diff')
execute s:vimDiffRestoreCmd
execute t:vcsCommandVimDiffRestoreCmd
endif
execute 'hide buffer' currentBufNR
endif
unlet s:vimDiffRestoreCmd
unlet t:vcsCommandVimDiffRestoreCmd
endif
" All buffers are gone.
unlet s:vimDiffSourceBuffer
unlet s:vimDiffScratchList
unlet t:vcsCommandVimDiffSourceBuffer
unlet t:vcsCommandVimDiffScratchList
endif
endif
endif
@ -700,7 +797,12 @@ endfunction
" 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
@ -716,22 +818,50 @@ function! s:VCSAnnotate(bang, ...)
if splitRegex == ''
return annotateBuffer
endif
let originalBuffer = VCSCommandGetOriginalBuffer(annotateBuffer)
wincmd J
let originalFileType = getbufvar(originalBuffer, '&ft')
let annotateFileType = getbufvar(annotateBuffer, '&ft')
execute "normal 0zR\<c-v>G/" . splitRegex . "/e\<cr>d"
let saveselection = &selection
set selection=inclusive
try
execute "normal! 0zR\<c-v>G/" . splitRegex . "/e\<cr>d"
finally
let &selection = saveselection
endtry
call setbufvar('%', '&filetype', getbufvar(originalBuffer, '&filetype'))
set scrollbind
leftabove vert new
normal 0P
execute "normal" . col('$') . "\<c-w>|"
normal! 0P
execute "normal!" . (col('$') + (&number ? &numberwidth : 0)). "\<c-w>|"
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
@ -773,6 +903,7 @@ function! s:VCSCommit(bang, message)
silent put ='VCS: ----------------------------------------------------------------------'
$
setlocal nomodified
silent do VCSCommand User VCSBufferCreated
catch
call s:ReportError(v:exception)
return -1
@ -797,22 +928,21 @@ endfunction
" Function: s:VCSFinishCommit(logMessageList, originalBuffer) {{{2
function! s:VCSFinishCommit(logMessageList, originalBuffer)
let shellSlashBak = &shellslash
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
set shellslash
let messageFileName = tempname()
call writefile(a:logMessageList, messageFileName)
try
let resultBuffer = s:ExecuteVCSCommand('Commit', [messageFileName])
if resultBuffer < 0
return resultBuffer
endif
return s:MarkOrigBufferForSetup(resultBuffer)
finally
call delete(messageFileName)
endtry
let resultBuffer = s:ExecuteVCSCommand('Commit', [messageFileName])
if resultBuffer < 0
return resultBuffer
endif
return s:MarkOrigBufferForSetup(resultBuffer)
finally
let &shellslash = shellSlashBak
call delete(messageFileName)
endtry
endfunction
@ -839,6 +969,34 @@ function! s:VCSGotoOriginal(bang)
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
@ -852,9 +1010,9 @@ function! s:VCSVimDiff(...)
" If there's already a VimDiff'ed window, restore it.
" There may only be one VCSVimDiff original window at a time.
if exists('s:vimDiffSourceBuffer') && s:vimDiffSourceBuffer != originalBuffer
if exists('t:vcsCommandVimDiffSourceBuffer') && t:vcsCommandVimDiffSourceBuffer != originalBuffer
" Clear the existing vimdiff setup by removing the result buffers.
call s:WipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
call s:WipeoutCommandBuffers(t:vcsCommandVimDiffSourceBuffer, 'vimdiff')
endif
let orientation = &diffopt =~ 'horizontal' ? 'horizontal' : 'vertical'
@ -864,23 +1022,23 @@ function! s:VCSVimDiff(...)
" Split and diff
if(a:0 == 2)
" Reset the vimdiff system, as 2 explicit versions were provided.
if exists('s:vimDiffSourceBuffer')
call s:WipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
if exists('t:vcsCommandVimDiffSourceBuffer')
call s:WipeoutCommandBuffers(t:vcsCommandVimDiffSourceBuffer, 'vimdiff')
endif
let resultBuffer = s:plugins[vcsType][1].Review([a:1])
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 s:vimDiffScratchList = [resultBuffer]
let t:vcsCommandVimDiffScratchList = [resultBuffer]
" If no split method is defined, cheat, and set it to vertical.
call s:VCSCommandUtility.pushContext({'VCSCommandSplit': orientation})
try
call s:OverrideOption('VCSCommandSplit', orientation)
let resultBuffer = s:plugins[vcsType][1].Review([a:2])
let resultBuffer = s:VCSReview(a:2)
finally
call s:OverrideOption('VCSCommandSplit')
call s:VCSCommandUtility.popContext()
endtry
if resultBuffer < 0
echomsg 'Can''t open revision ' . a:1
@ -888,24 +1046,18 @@ function! s:VCSVimDiff(...)
endif
let b:VCSCommandCommand = 'vimdiff'
diffthis
let s:vimDiffScratchList += [resultBuffer]
let t:vcsCommandVimDiffScratchList += [resultBuffer]
else
" Add new buffer
call s:OverrideOption('VCSCommandEdit', 'split')
" Add new buffer. Force splitting behavior, otherwise why use vimdiff?
call s:VCSCommandUtility.pushContext({'VCSCommandEdit': 'split', 'VCSCommandSplit': orientation})
try
" Force splitting behavior, otherwise why use vimdiff?
call s:OverrideOption('VCSCommandSplit', orientation)
try
if(a:0 == 0)
let resultBuffer = s:plugins[vcsType][1].Review([])
else
let resultBuffer = s:plugins[vcsType][1].Review([a:1])
endif
finally
call s:OverrideOption('VCSCommandSplit')
endtry
if(a:0 == 0)
let resultBuffer = s:VCSReview()
else
let resultBuffer = s:VCSReview(a:1)
endif
finally
call s:OverrideOption('VCSCommandEdit')
call s:VCSCommandUtility.popContext()
endtry
if resultBuffer < 0
echomsg 'Can''t open current revision'
@ -914,16 +1066,16 @@ function! s:VCSVimDiff(...)
let b:VCSCommandCommand = 'vimdiff'
diffthis
if !exists('s:vimDiffSourceBuffer')
if !exists('t:vcsCommandVimDiffSourceBuffer')
" New instance of vimdiff.
let s:vimDiffScratchList = [resultBuffer]
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 s:vimDiffRestoreCmd =
let t:vcsCommandVimDiffRestoreCmd =
\ 'call setbufvar('.originalBuffer.', ''&diff'', '.getbufvar(originalBuffer, '&diff').')'
\ . '|call setbufvar('.originalBuffer.', ''&foldcolumn'', '.getbufvar(originalBuffer, '&foldcolumn').')'
\ . '|call setbufvar('.originalBuffer.', ''&foldenable'', '.getbufvar(originalBuffer, '&foldenable').')'
@ -931,16 +1083,19 @@ function! s:VCSVimDiff(...)
\ . '|call setbufvar('.originalBuffer.', ''&foldlevel'', '''.getbufvar(originalBuffer, '&foldlevel').''')'
\ . '|call setbufvar('.originalBuffer.', ''&scrollbind'', '.getbufvar(originalBuffer, '&scrollbind').')'
\ . '|call setbufvar('.originalBuffer.', ''&wrap'', '.getbufvar(originalBuffer, '&wrap').')'
\ . '|if &foldmethod==''manual''|execute ''normal zE''|endif'
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 s:vimDiffScratchList += [resultBuffer]
let t:vcsCommandVimDiffScratchList += [resultBuffer]
endif
endif
let s:vimDiffSourceBuffer = originalBuffer
let t:vcsCommandVimDiffSourceBuffer = originalBuffer
" Avoid executing the modeline in the current buffer after the autocommand.
@ -965,49 +1120,31 @@ endfunction
" Section: Public functions {{{1
" Function: VCSCommandGetVCSType() {{{2
" Sets the b:VCSCommandVCSType variable in the given buffer to the
" appropriate source control system name.
" This function sets the b:VCSCommandVCSType variable in the given buffer to the
" appropriate source control system name and returns the same name.
"
" This uses the Identify extension function to test the buffer. If the
" Identify function returns VCSCOMMAND_IDENTIFY_EXACT, the match is considered
" exact. If the Identify function returns VCSCOMMAND_IDENTIFY_INEXACT, the
" match is considered inexact, and is only applied if no exact match is found.
" Multiple inexact matches is currently considered an error.
" 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 = getbufvar(a:buffer, 'VCSCommandVCSType')
if strlen(vcsType) > 0
return vcsType
endif
if exists("g:VCSCommandVCSTypeOverride")
let fullpath = fnamemodify(bufname(a:buffer), ':p')
for [path, vcsType] in g:VCSCommandVCSTypeOverride
if match(fullpath, path) > -1
call setbufvar(a:buffer, 'VCSCommandVCSType', vcsType)
return vcsType
endif
endfor
endif
let matches = []
for vcsType in keys(s:plugins)
let identified = s:plugins[vcsType][1].Identify(a:buffer)
if identified
if identified == g:VCSCOMMAND_IDENTIFY_EXACT
let matches = [vcsType]
break
else
let matches += [vcsType]
endif
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
endfor
if len(matches) == 1
call setbufvar(a:buffer, 'VCSCommandVCSType', matches[0])
return matches[0]
elseif len(matches) == 0
throw 'No suitable plugin'
else
throw 'Too many matching VCS: ' . join(matches)
endif
return vcsType
endfunction
" Function: VCSCommandChdir(directory) {{{2
@ -1018,7 +1155,11 @@ function! VCSCommandChdir(directory)
if exists("*haslocaldir") && haslocaldir()
let command = 'lcd'
endif
execute command escape(a:directory, ' ')
if exists("*fnameescape")
execute command fnameescape(a:directory)
else
execute command escape(a:directory, ' ')
endif
endfunction
" Function: VCSCommandChangeToCurrentFileDir() {{{2
@ -1058,6 +1199,7 @@ endfunction
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)
@ -1105,7 +1247,7 @@ function! VCSCommandDoCommand(cmd, cmdName, statusText, options)
if match(a:cmd, '<VCSCOMMANDFILE>') > 0
let fullCmd = substitute(a:cmd, '<VCSCOMMANDFILE>', fileName, 'g')
else
let fullCmd = a:cmd . ' -- "' . fileName . '"'
let fullCmd = a:cmd . ' -- ' . shellescape(fileName)
endif
" Change to the directory of the current buffer. This is done for CVS, but
@ -1152,7 +1294,7 @@ function! VCSCommandDoCommand(cmd, cmdName, statusText, options)
" within a fold, but I prefer to simply unfold the result buffer altogether.
if has('folding')
normal zR
normal! zR
endif
$d
@ -1169,9 +1311,12 @@ endfunction
" searched in the window, buffer, then global spaces.
function! VCSCommandGetOption(name, default)
if has_key(s:optionOverrides, a:name) && len(s:optionOverrides[a:name]) > 0
return s:optionOverrides[a:name][-1]
elseif exists('w:' . a:name)
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}
@ -1229,6 +1374,14 @@ function! VCSCommandGetStatusLine()
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', [<f-args>]))
@ -1236,14 +1389,14 @@ com! -nargs=* -bang VCSAnnotate call s:VCSAnnotate(<q-bang>, <f-args>)
com! -nargs=* -bang VCSBlame call s:VCSAnnotate(<q-bang>, <f-args>)
com! -nargs=? -bang VCSCommit call s:VCSCommit(<q-bang>, <q-args>)
com! -nargs=* VCSDelete call s:ExecuteVCSCommand('Delete', [<f-args>])
com! -nargs=* VCSDiff call s:ExecuteVCSCommand('Diff', [<f-args>])
com! -nargs=* VCSDiff call s:VCSDiff(<f-args>)
com! -nargs=0 -bang VCSGotoOriginal call s:VCSGotoOriginal(<q-bang>)
com! -nargs=* VCSInfo call s:ExecuteVCSCommand('Info', [<f-args>])
com! -nargs=* VCSLock call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Lock', [<f-args>]))
com! -nargs=* VCSLog call s:ExecuteVCSCommand('Log', [<f-args>])
com! -nargs=* VCSRemove call s:ExecuteVCSCommand('Delete', [<f-args>])
com! -nargs=0 VCSRevert call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Revert', []))
com! -nargs=? VCSReview call s:ExecuteVCSCommand('Review', [<f-args>])
com! -nargs=? VCSReview call s:VCSReview(<f-args>)
com! -nargs=* VCSStatus call s:ExecuteVCSCommand('Status', [<f-args>])
com! -nargs=* VCSUnlock call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Unlock', [<f-args>]))
com! -nargs=0 VCSUpdate call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Update', []))
@ -1254,26 +1407,28 @@ com! VCSCommandDisableBufferSetup call VCSCommandDisableBufferSetup()
com! VCSCommandEnableBufferSetup call VCSCommandEnableBufferSetup()
" Allow reloading VCSCommand.vim
com! VCSReload let savedPlugins = s:plugins|let s:plugins = {}|aunmenu Plugin.VCS|unlet! g:loaded_VCSCommand|runtime plugin/vcscommand.vim|for plugin in values(savedPlugins)|execute 'source' plugin[0]|endfor|unlet savedPlugins
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
nnoremap <silent> <Plug>VCSAdd :VCSAdd<CR>
nnoremap <silent> <Plug>VCSAnnotate :VCSAnnotate<CR>
nnoremap <silent> <Plug>VCSCommit :VCSCommit<CR>
nnoremap <silent> <Plug>VCSDelete :VCSDelete<CR>
nnoremap <silent> <Plug>VCSDiff :VCSDiff<CR>
nnoremap <silent> <Plug>VCSGotoOriginal :VCSGotoOriginal<CR>
nnoremap <silent> <Plug>VCSClearAndGotoOriginal :VCSGotoOriginal!<CR>
nnoremap <silent> <Plug>VCSInfo :VCSInfo<CR>
nnoremap <silent> <Plug>VCSLock :VCSLock<CR>
nnoremap <silent> <Plug>VCSLog :VCSLog<CR>
nnoremap <silent> <Plug>VCSRevert :VCSRevert<CR>
nnoremap <silent> <Plug>VCSReview :VCSReview<CR>
nnoremap <silent> <Plug>VCSSplitAnnotate :VCSAnnotate!<CR>
nnoremap <silent> <Plug>VCSStatus :VCSStatus<CR>
nnoremap <silent> <Plug>VCSUnlock :VCSUnlock<CR>
nnoremap <silent> <Plug>VCSUpdate :VCSUpdate<CR>
nnoremap <silent> <Plug>VCSVimDiff :VCSVimDiff<CR>
if !exists("no_plugin_maps")
nnoremap <silent> <Plug>VCSAdd :VCSAdd<CR>
nnoremap <silent> <Plug>VCSAnnotate :VCSAnnotate<CR>
nnoremap <silent> <Plug>VCSCommit :VCSCommit<CR>
nnoremap <silent> <Plug>VCSDelete :VCSDelete<CR>
nnoremap <silent> <Plug>VCSDiff :VCSDiff<CR>
nnoremap <silent> <Plug>VCSGotoOriginal :VCSGotoOriginal<CR>
nnoremap <silent> <Plug>VCSClearAndGotoOriginal :VCSGotoOriginal!<CR>
nnoremap <silent> <Plug>VCSInfo :VCSInfo<CR>
nnoremap <silent> <Plug>VCSLock :VCSLock<CR>
nnoremap <silent> <Plug>VCSLog :VCSLog<CR>
nnoremap <silent> <Plug>VCSRevert :VCSRevert<CR>
nnoremap <silent> <Plug>VCSReview :VCSReview<CR>
nnoremap <silent> <Plug>VCSSplitAnnotate :VCSAnnotate!<CR>
nnoremap <silent> <Plug>VCSStatus :VCSStatus<CR>
nnoremap <silent> <Plug>VCSUnlock :VCSUnlock<CR>
nnoremap <silent> <Plug>VCSUpdate :VCSUpdate<CR>
nnoremap <silent> <Plug>VCSVimDiff :VCSVimDiff<CR>
endif
" Section: Default mappings {{{1
@ -1297,25 +1452,37 @@ let s:defaultMappings = [
\['v', 'VCSVimDiff'],
\]
if !VCSCommandGetOption('VCSCommandDisableMappings', 0)
for [shortcut, vcsFunction] in VCSCommandGetOption('VCSCommandMappings', s:defaultMappings)
call s:CreateMapping(shortcut, '<Plug>' . vcsFunction, '''' . vcsFunction . '''')
if !exists("g:no_plugin_maps") && !VCSCommandGetOption('VCSCommandDisableMappings', 0)
for [s:shortcut, s:vcsFunction] in VCSCommandGetOption('VCSCommandMappings', s:defaultMappings)
call s:CreateMapping(s:shortcut, '<Plug>' . s:vcsFunction, '''' . s:vcsFunction . '''')
endfor
unlet s:shortcut s:vcsFunction
endif
unlet s:defaultMappings
" Section: Menu items {{{1
amenu <silent> &Plugin.VCS.&Add <Plug>VCSAdd
amenu <silent> &Plugin.VCS.A&nnotate <Plug>VCSAnnotate
amenu <silent> &Plugin.VCS.&Commit <Plug>VCSCommit
amenu <silent> &Plugin.VCS.Delete <Plug>VCSDelete
amenu <silent> &Plugin.VCS.&Diff <Plug>VCSDiff
amenu <silent> &Plugin.VCS.&Info <Plug>VCSInfo
amenu <silent> &Plugin.VCS.&Log <Plug>VCSLog
amenu <silent> &Plugin.VCS.Revert <Plug>VCSRevert
amenu <silent> &Plugin.VCS.&Review <Plug>VCSReview
amenu <silent> &Plugin.VCS.&Status <Plug>VCSStatus
amenu <silent> &Plugin.VCS.&Update <Plug>VCSUpdate
amenu <silent> &Plugin.VCS.&VimDiff <Plug>VCSVimDiff
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', '<Plug>VCSAdd'],
\['A&nnotate', '<Plug>VCSAnnotate'],
\['&Commit', '<Plug>VCSCommit'],
\['Delete', '<Plug>VCSDelete'],
\['&Diff', '<Plug>VCSDiff'],
\['&Info', '<Plug>VCSInfo'],
\['&Log', '<Plug>VCSLog'],
\['Revert', '<Plug>VCSRevert'],
\['&Review', '<Plug>VCSReview'],
\['&Status', '<Plug>VCSStatus'],
\['&Update', '<Plug>VCSUpdate'],
\['&VimDiff', '<Plug>VCSVimDiff']
\]
call s:VCSCommandUtility.addMenuItem(s:shortcut, s:command)
endfor
unlet s:shortcut s:command
" Section: Autocommands to restore vimdiff state {{{1
augroup VimDiffRestore