Snippets and vim updates and such, oh my

git-svn-id: http://photonzero.com/dotfiles/trunk@33 23f722f6-122a-0410-8cef-c75bd312dd78
This commit is contained in:
michener 2010-02-05 00:42:50 +00:00
parent a0995d6be5
commit 9d2548e8a9
56 changed files with 13433 additions and 129 deletions

3796
.vim/plugin/NERD_tree.vim Normal file

File diff suppressed because it is too large Load diff

16
.vim/plugin/cocoa.vim Normal file
View file

@ -0,0 +1,16 @@
" File: cocoa.vim
" Author: Michael Sanders msanders [at] gmail [dot] com
if exists('s:did_cocoa') || &cp || version < 700
finish
endif
let s:did_cocoa = 1
" These have to load after the normal ftplugins to override the defaults; I'd
" like to put this in ftplugin/objc_cocoa_mappings.vim, but that doesn't seem
" to work..
au FileType objc ru after/syntax/objc_enhanced.vim
\| let b:match_words = '@\(implementation\|interface\):@end'
\| setl inc=^\s*#\s*import omnifunc=objc#cocoacomplete#Complete
\| if globpath(expand('<afile>:p:h'), '*.xcodeproj') != '' |
\ setl makeprg=open\ -a\ xcode\ &&\ osascript\ -e\ 'tell\ app\ \"Xcode\"\ to\ build'
\| endif

996
.vim/plugin/genutils.vim Executable file

File diff suppressed because it is too large Load diff

32
.vim/plugin/slime.vim Normal file
View file

@ -0,0 +1,32 @@
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function Send_to_Screen(text)
if !exists("g:screen_sessionname") || !exists("g:screen_windowname")
call Screen_Vars()
end
echo system("screen -S " . g:screen_sessionname . " -p " . g:screen_windowname . " -X stuff '" . substitute(a:text, "'", "'\\\\''", 'g') . "'")
endfunction
function Screen_Session_Names(A,L,P)
return system("screen -ls | awk '/Attached/ {print $1}'")
endfunction
function Screen_Vars()
if !exists("g:screen_sessionname") || !exists("g:screen_windowname")
let g:screen_sessionname = ""
let g:screen_windowname = "0"
end
let g:screen_sessionname = input("session name: ", "", "custom,Screen_Session_Names")
let g:screen_windowname = input("window name: ", g:screen_windowname)
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vmap <C-c><C-c> "ry :call Send_to_Screen(@r)<CR>
nmap <C-c><C-c> vip<C-c><C-c>
nmap <C-c>v :call Screen_Vars()<CR>

247
.vim/plugin/snipMate.vim Normal file
View file

@ -0,0 +1,247 @@
" File: snipMate.vim
" Author: Michael Sanders
" Last Updated: July 13, 2009
" Version: 0.83
" Description: snipMate.vim implements some of TextMate's snippets features in
" Vim. A snippet is a piece of often-typed text that you can
" insert into your document using a trigger word followed by a "<tab>".
"
" For more help see snipMate.txt; you can do this by using:
" :helptags ~/.vim/doc
" :h snipMate.txt
if exists('loaded_snips') || &cp || version < 700
finish
endif
let loaded_snips = 1
if !exists('snips_author') | let snips_author = 'Me' | endif
au BufRead,BufNewFile *.snippets\= set ft=snippet
au FileType snippet setl noet fdm=indent
let s:snippets = {} | let s:multi_snips = {}
if !exists('snippets_dir')
let snippets_dir = substitute(globpath(&rtp, 'snippets/'), "\n", ',', 'g')
endif
fun! MakeSnip(scope, trigger, content, ...)
let multisnip = a:0 && a:1 != ''
let var = multisnip ? 's:multi_snips' : 's:snippets'
if !has_key({var}, a:scope) | let {var}[a:scope] = {} | endif
if !has_key({var}[a:scope], a:trigger)
let {var}[a:scope][a:trigger] = multisnip ? [[a:1, a:content]] : a:content
elseif multisnip | let {var}[a:scope][a:trigger] += [[a:1, a:content]]
else
echom 'Warning in snipMate.vim: Snippet '.a:trigger.' is already defined.'
\ .' See :h multi_snip for help on snippets with multiple matches.'
endif
endf
fun! ExtractSnips(dir, ft)
for path in split(globpath(a:dir, '*'), "\n")
if isdirectory(path)
let pathname = fnamemodify(path, ':t')
for snipFile in split(globpath(path, '*.snippet'), "\n")
call s:ProcessFile(snipFile, a:ft, pathname)
endfor
elseif fnamemodify(path, ':e') == 'snippet'
call s:ProcessFile(path, a:ft)
endif
endfor
endf
" Processes a single-snippet file; optionally add the name of the parent
" directory for a snippet with multiple matches.
fun s:ProcessFile(file, ft, ...)
let keyword = fnamemodify(a:file, ':t:r')
if keyword == '' | return | endif
try
let text = join(readfile(a:file), "\n")
catch /E484/
echom "Error in snipMate.vim: couldn't read file: ".a:file
endtry
return a:0 ? MakeSnip(a:ft, a:1, text, keyword)
\ : MakeSnip(a:ft, keyword, text)
endf
fun! ExtractSnipsFile(file, ft)
if !filereadable(a:file) | return | endif
let text = readfile(a:file)
let inSnip = 0
for line in text + ["\n"]
if inSnip && (line[0] == "\t" || line == '')
let content .= strpart(line, 1)."\n"
continue
elseif inSnip
call MakeSnip(a:ft, trigger, content[:-2], name)
let inSnip = 0
endif
if line[:6] == 'snippet'
let inSnip = 1
let trigger = strpart(line, 8)
let name = ''
let space = stridx(trigger, ' ') + 1
if space " Process multi snip
let name = strpart(trigger, space)
let trigger = strpart(trigger, 0, space - 1)
endif
let content = ''
endif
endfor
endf
fun! ResetSnippets()
let s:snippets = {} | let s:multi_snips = {} | let g:did_ft = {}
endf
let g:did_ft = {}
fun! GetSnippets(dir, filetypes)
for ft in split(a:filetypes, '\.')
if has_key(g:did_ft, ft) | continue | endif
call s:DefineSnips(a:dir, ft, ft)
if ft == 'objc' || ft == 'cpp' || ft == 'cs'
call s:DefineSnips(a:dir, 'c', ft)
elseif ft == 'xhtml'
call s:DefineSnips(a:dir, 'html', 'xhtml')
endif
let g:did_ft[ft] = 1
endfor
endf
" Define "aliasft" snippets for the filetype "realft".
fun s:DefineSnips(dir, aliasft, realft)
for path in split(globpath(a:dir, a:aliasft.'/')."\n".
\ globpath(a:dir, a:aliasft.'-*/'), "\n")
call ExtractSnips(path, a:realft)
endfor
for path in split(globpath(a:dir, a:aliasft.'.snippets')."\n".
\ globpath(a:dir, a:aliasft.'-*.snippets'), "\n")
call ExtractSnipsFile(path, a:realft)
endfor
endf
fun! TriggerSnippet()
if exists('g:SuperTabMappingForward')
if g:SuperTabMappingForward == "<tab>"
let SuperTabKey = "\<c-n>"
elseif g:SuperTabMappingBackward == "<tab>"
let SuperTabKey = "\<c-p>"
endif
endif
if pumvisible() " Update snippet if completion is used, or deal with supertab
if exists('SuperTabKey')
call feedkeys(SuperTabKey) | return ''
endif
call feedkeys("\<esc>a", 'n') " Close completion menu
call feedkeys("\<tab>") | return ''
endif
if exists('g:snipPos') | return snipMate#jumpTabStop(0) | endif
let word = matchstr(getline('.'), '\S\+\%'.col('.').'c')
for scope in [bufnr('%')] + split(&ft, '\.') + ['_']
let [trigger, snippet] = s:GetSnippet(word, scope)
" If word is a trigger for a snippet, delete the trigger & expand
" the snippet.
if snippet != ''
let col = col('.') - len(trigger)
sil exe 's/\V'.escape(trigger, '/.').'\%#//'
return snipMate#expandSnip(snippet, col)
endif
endfor
if exists('SuperTabKey')
call feedkeys(SuperTabKey)
return ''
endif
return "\<tab>"
endf
fun! BackwardsSnippet()
if exists('g:snipPos') | return snipMate#jumpTabStop(1) | endif
if exists('g:SuperTabMappingForward')
if g:SuperTabMappingBackward == "<s-tab>"
let SuperTabKey = "\<c-p>"
elseif g:SuperTabMappingForward == "<s-tab>"
let SuperTabKey = "\<c-n>"
endif
endif
if exists('SuperTabKey')
call feedkeys(SuperTabKey)
return ''
endif
return "\<s-tab>"
endf
" Check if word under cursor is snippet trigger; if it isn't, try checking if
" the text after non-word characters is (e.g. check for "foo" in "bar.foo")
fun s:GetSnippet(word, scope)
let word = a:word | let snippet = ''
while snippet == ''
if exists('s:snippets["'.a:scope.'"]["'.escape(word, '\"').'"]')
let snippet = s:snippets[a:scope][word]
elseif exists('s:multi_snips["'.a:scope.'"]["'.escape(word, '\"').'"]')
let snippet = s:ChooseSnippet(a:scope, word)
if snippet == '' | break | endif
else
if match(word, '\W') == -1 | break | endif
let word = substitute(word, '.\{-}\W', '', '')
endif
endw
if word == '' && a:word != '.' && stridx(a:word, '.') != -1
let [word, snippet] = s:GetSnippet('.', a:scope)
endif
return [word, snippet]
endf
fun s:ChooseSnippet(scope, trigger)
let snippet = []
let i = 1
for snip in s:multi_snips[a:scope][a:trigger]
let snippet += [i.'. '.snip[0]]
let i += 1
endfor
if i == 2 | return s:multi_snips[a:scope][a:trigger][0][1] | endif
let num = inputlist(snippet) - 1
return num == -1 ? '' : s:multi_snips[a:scope][a:trigger][num][1]
endf
fun! ShowAvailableSnips()
let line = getline('.')
let col = col('.')
let word = matchstr(getline('.'), '\S\+\%'.col.'c')
let words = [word]
if stridx(word, '.')
let words += split(word, '\.', 1)
endif
let matchlen = 0
let matches = []
for scope in [bufnr('%')] + split(&ft, '\.') + ['_']
let triggers = has_key(s:snippets, scope) ? keys(s:snippets[scope]) : []
if has_key(s:multi_snips, scope)
let triggers += keys(s:multi_snips[scope])
endif
for trigger in triggers
for word in words
if word == ''
let matches += [trigger] " Show all matches if word is empty
elseif trigger =~ '^'.word
let matches += [trigger]
let len = len(word)
if len > matchlen | let matchlen = len | endif
endif
endfor
endfor
endfor
" This is to avoid a bug with Vim when using complete(col - matchlen, matches)
" (Issue#46 on the Google Code snipMate issue tracker).
call setline(line('.'), substitute(line, repeat('.', matchlen).'\%'.col.'c', '', ''))
call complete(col, matches)
return ''
endf
" vim:noet:sw=4:ts=4:ft=vim

254
.vim/plugin/vcsbzr.vim Normal file
View file

@ -0,0 +1,254 @@
" vim600: set foldmethod=marker:
"
" BZR extension for VCSCommand.
"
" Version: VCS development
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
" License:
" Copyright (c) 2009 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 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
runtime plugin/vcscommand.vim
if !executable(VCSCommandGetOption('VCSCommandBZRExec', 'bzr'))
" BZR is not installed
finish
endif
" Section: Variable initialization {{{1
let s:bzrFunctions = {}
" Section: Utility functions {{{1
" 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 = VCSCommandGetOption('VCSCommandBZRExec', 'bzr') . ' ' . 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 statusText = system(VCSCommandGetOption('VCSCommandBZRExec', 'bzr') . ' info "' . fileName . '"')
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
set filetype=BZRAnnotate
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
let resultBuffer = s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {'allowNonZeroExit': 1})
if resultBuffer > 0
set filetype=diff
else
echomsg 'No differences found'
endif
return resultBuffer
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 = system(VCSCommandGetOption('VCSCommandBZRExec', 'bzr') . ' status -S "' . fileName . '"')
let revision = system(VCSCommandGetOption('VCSCommandBZRExec', 'bzr') . ' 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
let resultBuffer = s:DoCommand('cat' . versionOption, 'review', versiontag, {})
if resultBuffer > 0
let &filetype=getbufvar(b:VCSCommandOriginalBuffer, '&filetype')
endif
return resultBuffer
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
" Section: Plugin Registration {{{1
call VCSCommandRegisterModule('BZR', expand('<sfile>'), s:bzrFunctions, [])
let &cpo = s:save_cpo

View file

@ -1,11 +1,12 @@
" vim600: set foldmethod=marker:
"
" Vim plugin to assist in working with files under control of CVS or SVN.
" Vim plugin to assist in working with files under control of various Version
" Control Systems, such as CVS, SVN, SVK, and git.
"
" Version: Beta 22
" Version: 1.99.31
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
" License:
" Copyright (c) 2007 Bob Hiestand
" Copyright (c) 2008 Bob Hiestand
"
" Permission is hereby granted, free of charge, to any person obtaining a copy
" of this software and associated documentation files (the "Software"), to
@ -43,7 +44,7 @@
"
" VCSAdd Adds the current file to source control.
"
" VCSAnnotate Displays the current file with each line annotated with the
" 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
@ -51,6 +52,10 @@
" 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.
@ -151,6 +156,7 @@
"
" <Leader>ca VCSAdd
" <Leader>cn VCSAnnotate
" <Leader>cN VCSAnnotate!
" <Leader>cc VCSCommit
" <Leader>cD VCSDelete
" <Leader>cd VCSDiff
@ -187,6 +193,11 @@
" 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.
@ -207,6 +218,16 @@
" information in the status bar. Additional options may be set by
" individual VCS plugins.
"
" VCSCommandMappings
" This variable, if set, overrides the default mappings used for shortcuts.
" It should be a List of 2-element Lists, each containing a shortcut and
" function name pair.
"
" VCSCommandMapPrefix
" This variable, if set, overrides the default mapping prefix ('<Leader>c').
" This allows customization of the mapping space used by the vcscommand
" shortcuts.
"
" VCSCommandResultBufferNameExtension
" This variable, if set to a non-blank value, is appended to the name of the
" VCS command output buffers. For example, '.vcs'. Using this option may
@ -235,6 +256,14 @@
" side-by-side. If not set, it defaults to 'horizontal' for all but
" VCSVimDiff windows.
"
" VCSCommandVCSTypeOverride
" This variable allows the VCS type detection to be overridden on a
" path-by-path basis. The value of this variable is expected to be a List
" of Lists. Each high-level List item is a List containing two elements.
" The first element is a regular expression that will be matched against the
" full file name of a given buffer. If it matches, the second element will
" be used as the VCS type.
"
" Event documentation {{{2
" For additional customization, VCSCommand.vim uses User event autocommand
" hooks. Each event is in the VCSCommand group, and different patterns
@ -272,6 +301,10 @@
" 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
@ -331,6 +364,27 @@ function! s:ReportError(error)
echohl WarningMsg|echomsg 'VCSCommand: ' . a:error|echohl None
endfunction
" Function: s:CreateMapping(shortcut, expansion, display) {{{2
" Creates the given mapping by prepending the contents of
" 'VCSCommandMapPrefix' (by default '<Leader>c') to the given shortcut and
" mapping it to the given plugin function. If a mapping exists for the
" specified shortcut + prefix, emit an error but continue. If a mapping
" exists for the specified function, do nothing.
function! s:CreateMapping(shortcut, expansion, display)
let lhs = VCSCommandGetOption('VCSCommandMapPrefix', '<Leader>c') . a:shortcut
if !hasmapto(a:expansion)
try
execute 'nmap <silent> <unique>' lhs a:expansion
catch /^Vim(.*):E227:/
if(&verbose != 0)
echohl WarningMsg|echomsg 'VCSCommand: mapping ''' . lhs . ''' already exists, refusing to overwrite. The mapping for ' . a:display . ' will not be available.'|echohl None
endif
endtry
endif
endfunction
" Function: s:ExecuteExtensionMapping(mapping) {{{2
" Invokes the appropriate extension mapping depending on the type of the
" current buffer.
@ -431,15 +485,6 @@ endfunction
function! s:EditFile(command, originalBuffer, statusText)
let vcsType = getbufvar(a:originalBuffer, 'VCSCommandVCSType')
let nameExtension = VCSCommandGetOption('VCSCommandResultBufferNameExtension', '')
if nameExtension == ''
let nameFunction = VCSCommandGetOption('VCSCommandResultBufferNameFunction', 's:GenerateResultBufferName')
else
let nameFunction = VCSCommandGetOption('VCSCommandResultBufferNameFunction', 's:GenerateResultBufferNameWithExtension')
endif
let resultBufferName = call(nameFunction, [a:command, a:originalBuffer, vcsType, a:statusText])
" Protect against useless buffer set-up
let s:isEditFileRunning += 1
try
@ -451,27 +496,46 @@ function! s:EditFile(command, originalBuffer, statusText)
vert rightbelow split
endif
endif
edit `=resultBufferName`
let b:VCSCommandCommand = a:command
let b:VCSCommandOriginalBuffer = a:originalBuffer
let b:VCSCommandSourceFile = bufname(a:originalBuffer)
let b:VCSCommandVCSType = vcsType
set buftype=nofile
set noswapfile
let &filetype = vcsType . a:command
enew
if a:statusText != ''
let b:VCSCommandStatusText = a:statusText
endif
call s:SetupScratchBuffer(a:command, vcsType, a:originalBuffer, a:statusText)
if VCSCommandGetOption('VCSCommandDeleteOnHide', 0)
set bufhidden=delete
endif
finally
let s:isEditFileRunning -= 1
endtry
endfunction
" Function: s:SetupScratchBuffer(command, vcsType, originalBuffer, statusText) {{{2
" Creates convenience buffer variables and the name of a vcscommand result
" buffer.
function! s:SetupScratchBuffer(command, vcsType, originalBuffer, statusText)
let nameExtension = VCSCommandGetOption('VCSCommandResultBufferNameExtension', '')
if nameExtension == ''
let nameFunction = VCSCommandGetOption('VCSCommandResultBufferNameFunction', 's:GenerateResultBufferName')
else
let nameFunction = VCSCommandGetOption('VCSCommandResultBufferNameFunction', 's:GenerateResultBufferNameWithExtension')
endif
let name = call(nameFunction, [a:command, a:originalBuffer, a:vcsType, a:statusText])
let b:VCSCommandCommand = a:command
let b:VCSCommandOriginalBuffer = a:originalBuffer
let b:VCSCommandSourceFile = bufname(a:originalBuffer)
let b:VCSCommandVCSType = a:vcsType
if a:statusText != ''
let b:VCSCommandStatusText = a:statusText
endif
setlocal buftype=nofile
setlocal noswapfile
let &filetype = a:vcsType . a:command
if VCSCommandGetOption('VCSCommandDeleteOnHide', 0)
setlocal bufhidden=delete
endif
silent noautocmd file `=name`
endfunction
" Function: s:SetupBuffer() {{{2
@ -616,6 +680,43 @@ endfunction
" Section: Generic VCS command functions {{{1
" Function: s:VCSAnnotate(...) {{{2
function! s:VCSAnnotate(bang, ...)
try
let annotateBuffer = s:ExecuteVCSCommand('Annotate', a:000)
if annotateBuffer == -1
return -1
endif
if a:bang == '!' && VCSCommandGetOption('VCSCommandDisableSplitAnnotate', 0) == 0
let vcsType = VCSCommandGetVCSType(annotateBuffer)
let functionMap = s:plugins[vcsType][1]
let splitRegex = ''
if has_key(s:plugins[vcsType][1], 'AnnotateSplitRegex')
let splitRegex = s:plugins[vcsType][1]['AnnotateSplitRegex']
endif
let splitRegex = VCSCommandGetOption('VCSCommand' . vcsType . 'AnnotateSplitRegex', splitRegex)
if splitRegex == ''
return annotateBuffer
endif
let originalBuffer = VCSCommandGetOriginalBuffer(annotateBuffer)
let originalFileType = getbufvar(originalBuffer, '&ft')
let annotateFileType = getbufvar(annotateBuffer, '&ft')
execute "normal 0zR\<c-v>G/" . splitRegex . "/e\<cr>d"
call setbufvar('%', '&filetype', getbufvar(originalBuffer, '&filetype'))
set scrollbind
leftabove vert new
normal 0P
execute "normal" . col('$') . "\<c-w>|"
call s:SetupScratchBuffer('annotate', vcsType, originalBuffer, 'header')
wincmd l
endif
return annotateBuffer
catch
call s:ReportError(v:exception)
return -1
endtry
endfunction
" Function: s:VCSCommit() {{{2
function! s:VCSCommit(bang, message)
try
@ -635,7 +736,7 @@ function! s:VCSCommit(bang, message)
endif
call s:EditFile('commitlog', originalBuffer, '')
set ft=vcscommit
setlocal ft=vcscommit
" Create a commit mapping.
@ -646,14 +747,14 @@ function! s:VCSCommit(bang, message)
silent put ='VCS: To finish the commit, Type <leader>cc (or your own <Plug>VCSCommit mapping)'
if VCSCommandGetOption('VCSCommandCommitOnWrite', 1) == 1
set buftype=acwrite
setlocal buftype=acwrite
au VCSCommandCommit BufWriteCmd <buffer> call s:VCSFinishCommitWithBuffer()
silent put ='VCS: or write this buffer'
endif
silent put ='VCS: ----------------------------------------------------------------------'
$
set nomodified
setlocal nomodified
catch
call s:ReportError(v:exception)
return -1
@ -665,7 +766,7 @@ endfunction
" which removes all lines starting with 'VCS:'.
function! s:VCSFinishCommitWithBuffer()
set nomodified
setlocal nomodified
let currentBuffer = bufnr('%')
let logMessageList = getbufline('%', 1, '$')
call filter(logMessageList, 'v:val !~ ''^\s*VCS:''')
@ -738,6 +839,10 @@ function! s:VCSVimDiff(...)
call s:WipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff')
endif
let orientation = &diffopt =~ 'horizontal' ? 'horizontal' : 'vertical'
let orientation = VCSCommandGetOption('VCSCommandSplit', orientation)
let orientation = VCSCommandGetOption('VCSCommandDiffSplit', orientation)
" Split and diff
if(a:0 == 2)
" Reset the vimdiff system, as 2 explicit versions were provided.
@ -754,7 +859,7 @@ function! s:VCSVimDiff(...)
let s:vimDiffScratchList = [resultBuffer]
" If no split method is defined, cheat, and set it to vertical.
try
call s:OverrideOption('VCSCommandSplit', VCSCommandGetOption('VCSCommandDiffSplit', VCSCommandGetOption('VCSCommandSplit', 'vertical')))
call s:OverrideOption('VCSCommandSplit', orientation)
let resultBuffer = s:plugins[vcsType][1].Review([a:2])
finally
call s:OverrideOption('VCSCommandSplit')
@ -771,7 +876,7 @@ function! s:VCSVimDiff(...)
call s:OverrideOption('VCSCommandEdit', 'split')
try
" Force splitting behavior, otherwise why use vimdiff?
call s:OverrideOption('VCSCommandSplit', VCSCommandGetOption('VCSCommandDiffSplit', VCSCommandGetOption('VCSCommandSplit', 'vertical')))
call s:OverrideOption('VCSCommandSplit', orientation)
try
if(a:0 == 0)
let resultBuffer = s:plugins[vcsType][1].Review([])
@ -856,6 +961,15 @@ function! VCSCommandGetVCSType(buffer)
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)
@ -928,8 +1042,9 @@ function! VCSCommandRegisterModule(name, path, commandMap, mappingMap)
if !empty(a:mappingMap)
\ && !VCSCommandGetOption('VCSCommandDisableMappings', 0)
\ && !VCSCommandGetOption('VCSCommandDisableExtensionMappings', 0)
for mapname in keys(a:mappingMap)
execute 'noremap <silent> <Leader>' . mapname ':call <SID>ExecuteExtensionMapping(''' . mapname . ''')<CR>'
for shortcut in keys(a:mappingMap)
let expansion = ":call <SID>ExecuteExtensionMapping('" . shortcut . "')<CR>"
call s:CreateMapping(shortcut, expansion, a:name . " extension mapping " . shortcut)
endfor
endif
endfunction
@ -1098,8 +1213,8 @@ endfunction
" Section: Command definitions {{{1
" Section: Primary commands {{{2
com! -nargs=* VCSAdd call s:MarkOrigBufferForSetup(s:ExecuteVCSCommand('Add', [<f-args>]))
com! -nargs=* VCSAnnotate call s:ExecuteVCSCommand('Annotate', [<f-args>])
com! -nargs=* VCSBlame call s:ExecuteVCSCommand('Annotate', [<f-args>])
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>])
@ -1135,6 +1250,7 @@ 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>
@ -1142,55 +1258,30 @@ nnoremap <silent> <Plug>VCSVimDiff :VCSVimDiff<CR>
" 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 !VCSCommandGetOption('VCSCommandDisableMappings', 0)
if !hasmapto('<Plug>VCSAdd')
nmap <unique> <Leader>ca <Plug>VCSAdd
endif
if !hasmapto('<Plug>VCSAnnotate')
nmap <unique> <Leader>cn <Plug>VCSAnnotate
endif
if !hasmapto('<Plug>VCSClearAndGotoOriginal')
nmap <unique> <Leader>cG <Plug>VCSClearAndGotoOriginal
endif
if !hasmapto('<Plug>VCSCommit')
nmap <unique> <Leader>cc <Plug>VCSCommit
endif
if !hasmapto('<Plug>VCSDelete')
nmap <unique> <Leader>cD <Plug>VCSDelete
endif
if !hasmapto('<Plug>VCSDiff')
nmap <unique> <Leader>cd <Plug>VCSDiff
endif
if !hasmapto('<Plug>VCSGotoOriginal')
nmap <unique> <Leader>cg <Plug>VCSGotoOriginal
endif
if !hasmapto('<Plug>VCSInfo')
nmap <unique> <Leader>ci <Plug>VCSInfo
endif
if !hasmapto('<Plug>VCSLock')
nmap <unique> <Leader>cL <Plug>VCSLock
endif
if !hasmapto('<Plug>VCSLog')
nmap <unique> <Leader>cl <Plug>VCSLog
endif
if !hasmapto('<Plug>VCSRevert')
nmap <unique> <Leader>cq <Plug>VCSRevert
endif
if !hasmapto('<Plug>VCSReview')
nmap <unique> <Leader>cr <Plug>VCSReview
endif
if !hasmapto('<Plug>VCSStatus')
nmap <unique> <Leader>cs <Plug>VCSStatus
endif
if !hasmapto('<Plug>VCSUnlock')
nmap <unique> <Leader>cU <Plug>VCSUnlock
endif
if !hasmapto('<Plug>VCSUpdate')
nmap <unique> <Leader>cu <Plug>VCSUpdate
endif
if !hasmapto('<Plug>VCSVimDiff')
nmap <unique> <Leader>cv <Plug>VCSVimDiff
endif
for [shortcut, vcsFunction] in VCSCommandGetOption('VCSCommandMappings', s:defaultMappings)
call s:CreateMapping(shortcut, '<Plug>' . vcsFunction, '''' . vcsFunction . '''')
endfor
endif
" Section: Menu items {{{1

View file

@ -81,6 +81,10 @@
" 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
@ -108,7 +112,17 @@ let s:cvsFunctions = {}
function! s:DoCommand(cmd, cmdName, statusText, options)
if VCSCommandGetVCSType(expand('%')) == 'CVS'
let fullCmd = VCSCommandGetOption('VCSCommandCVSExec', 'cvs') . ' ' . a:cmd
return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
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
@ -387,6 +401,9 @@ 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()
@ -403,14 +420,14 @@ com! CVSWatchers call s:CVSWatchers()
let s:cvsExtensionMappings = {}
let mappingInfo = [
\['CVSEdit', 'CVSEdit', 'ce'],
\['CVSEditors', 'CVSEditors', 'cE'],
\['CVSUnedit', 'CVSUnedit', 'ct'],
\['CVSWatchers', 'CVSWatchers', 'cwv'],
\['CVSWatchAdd', 'CVSWatch add', 'cwa'],
\['CVSWatchOff', 'CVSWatch off', 'cwf'],
\['CVSWatchOn', 'CVSWatch on', 'cwn'],
\['CVSWatchRemove', 'CVSWatch remove', 'cwr']
\['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
@ -421,7 +438,6 @@ for [pluginName, commandText, shortCut] in mappingInfo
endfor
" Section: Menu items {{{1
silent! aunmenu Plugin.VCS.CVS
amenu <silent> &Plugin.VCS.CVS.&Edit <Plug>CVSEdit
amenu <silent> &Plugin.VCS.CVS.Ed&itors <Plug>CVSEditors
amenu <silent> &Plugin.VCS.CVS.Unedi&t <Plug>CVSUnedit

View file

@ -5,7 +5,7 @@
" Version: VCS development
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
" License:
" Copyright (c) 2007 Bob Hiestand
" Copyright (c) 2008 Bob Hiestand
"
" Permission is hereby granted, free of charge, to any person obtaining a copy
" of this software and associated documentation files (the "Software"), to
@ -40,6 +40,10 @@
" 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
@ -221,7 +225,7 @@ function! s:gitFunctions.Review(argList)
let revision = a:argList[0]
endif
let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname('%')))
let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(VCSCommandGetOriginalBuffer('%'))))
try
let prefix = system(VCSCommandGetOption('VCSCommandGitExec', 'git') . ' rev-parse --show-prefix')
finally
@ -229,7 +233,7 @@ function! s:gitFunctions.Review(argList)
endtry
let prefix = substitute(prefix, '\n$', '', '')
let blob = revision . ':' . prefix . '<VCSCOMMANDFILE>'
let blob = '"' . revision . ':' . prefix . '<VCSCOMMANDFILE>"'
let resultBuffer = s:DoCommand('show ' . blob, 'review', revision, {})
if resultBuffer > 0
let &filetype=getbufvar(b:VCSCommandOriginalBuffer, '&filetype')
@ -239,7 +243,7 @@ endfunction
" Function: s:gitFunctions.Status(argList) {{{2
function! s:gitFunctions.Status(argList)
return s:DoCommand(join(['status'] + a:argList), 'log', join(a:argList), {'allowNonZeroExit': 1})
return s:DoCommand(join(['status'] + a:argList), 'status', join(a:argList), {'allowNonZeroExit': 1})
endfunction
" Function: s:gitFunctions.Update(argList) {{{2
@ -247,6 +251,8 @@ 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
call VCSCommandRegisterModule('git', expand('<sfile>'), s:gitFunctions, [])

275
.vim/plugin/vcshg.vim Executable file
View file

@ -0,0 +1,275 @@
" vim600: set foldmethod=marker:
"
" Mercurial extension for VCSCommand.
"
" Version: VCS development
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
" License:
" Copyright (c) 2009 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
runtime plugin/vcscommand.vim
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: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 = VCSCommandGetOption('VCSCommandHGExec', 'hg') . ' ' . 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)
call system(VCSCommandGetOption('VCSCommandHGExec', 'hg') . ' root')
if(v:shell_error)
return 0
else
return g:VCSCOMMAND_IDENTIFY_INEXACT
endif
endfunction
" Function: s:hgFunctions.Add() {{{2
function! s:hgFunctions.Add(argList)
return s:DoCommand(join(['add'] + 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+\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
set filetype=HGAnnotate
endif
return resultBuffer
endfunction
" Function: s:hgFunctions.Commit(argList) {{{2
function! s:hgFunctions.Commit(argList)
let resultBuffer = s:DoCommand('commit -l "' . a:argList[0] . '"', 'commit', '', {})
if resultBuffer == 0
echomsg 'No commit needed.'
endif
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
let resultBuffer = s:DoCommand(join(['diff'] + diffExt + diffOptions + revOptions), 'diff', caption, {})
if resultBuffer > 0
set filetype=diff
else
if hgDiffExt == ''
echomsg 'No differences found'
endif
endif
return resultBuffer
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 = system(VCSCommandGetOption('VCSCommandHGExec', 'hg') . ' status "' . fileName . '"')
if(v:shell_error)
return []
endif
" File not under HG control.
if statusText =~ '^?'
return ['Unknown']
endif
let parentsText = system(VCSCommandGetOption('VCSCommandHGExec', 'hg') . ' parents "' . fileName . '"')
let [revision] = matchlist(parentsText, '^changeset:\s\+\(\S\+\)\n')[1]
let logText = system(VCSCommandGetOption('VCSCommandHGExec', 'hg') . ' 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
" let resultBuffer = s:DoCommand('cat --non-interactive' . versionOption, 'review', versiontag, {})
let resultBuffer = s:DoCommand('cat' . versionOption, 'review', versiontag, {})
if resultBuffer > 0
let &filetype = getbufvar(b:VCSCommandOriginalBuffer, '&filetype')
endif
return resultBuffer
endfunction
" Function: s:hgFunctions.Status(argList) {{{2
function! s:hgFunctions.Status(argList)
let options = ['-u', '-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
" Section: Plugin Registration {{{1
call VCSCommandRegisterModule('HG', expand('<sfile>'), s:hgFunctions, [])
let &cpo = s:save_cpo

View file

@ -35,6 +35,10 @@
" 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

View file

@ -42,6 +42,10 @@
" 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
@ -121,7 +125,7 @@ function! s:svnFunctions.Annotate(argList)
let options = ' ' . caption
endif
let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {})
let resultBuffer = s:DoCommand('blame --non-interactive' . options, 'annotate', caption, {})
if resultBuffer > 0
set filetype=SVNAnnotate
endif
@ -130,7 +134,7 @@ endfunction
" Function: s:svnFunctions.Commit(argList) {{{2
function! s:svnFunctions.Commit(argList)
let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
let resultBuffer = s:DoCommand('commit --non-interactive -F "' . a:argList[0] . '"', 'commit', '', {})
if resultBuffer == 0
echomsg 'No commit needed.'
endif
@ -138,7 +142,7 @@ endfunction
" Function: s:svnFunctions.Delete() {{{2
function! s:svnFunctions.Delete(argList)
return s:DoCommand(join(['delete'] + a:argList, ' '), 'delete', join(a:argList, ' '), {})
return s:DoCommand(join(['delete --non-interactive'] + a:argList, ' '), 'delete', join(a:argList, ' '), {})
endfunction
" Function: s:svnFunctions.Diff(argList) {{{2
@ -169,7 +173,7 @@ function! s:svnFunctions.Diff(argList)
let diffOptions = ['-x -' . svnDiffOpt]
endif
let resultBuffer = s:DoCommand(join(['diff'] + diffExt + diffOptions + revOptions), 'diff', caption, {})
let resultBuffer = s:DoCommand(join(['diff --non-interactive'] + diffExt + diffOptions + revOptions), 'diff', caption, {})
if resultBuffer > 0
set filetype=diff
else
@ -189,7 +193,7 @@ endfunction
function! s:svnFunctions.GetBufferInfo()
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
let fileName = bufname(originalBuffer)
let statusText = system(VCSCommandGetOption('VCSCommandSVNExec', 'svn') . ' status -vu "' . fileName . '"')
let statusText = system(VCSCommandGetOption('VCSCommandSVNExec', 'svn') . ' status --non-interactive -vu "' . fileName . '"')
if(v:shell_error)
return []
endif
@ -212,12 +216,12 @@ endfunction
" Function: s:svnFunctions.Info(argList) {{{2
function! s:svnFunctions.Info(argList)
return s:DoCommand(join(['info'] + a:argList, ' '), 'info', join(a: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'] + a:argList, ' '), 'lock', join(a:argList, ' '), {})
return s:DoCommand(join(['lock --non-interactive'] + a:argList, ' '), 'lock', join(a:argList, ' '), {})
endfunction
" Function: s:svnFunctions.Log(argList) {{{2
@ -234,7 +238,7 @@ function! s:svnFunctions.Log(argList)
let caption = join(a:argList, ' ')
endif
let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {})
let resultBuffer = s:DoCommand(join(['log --non-interactive', '-v'] + options), 'log', caption, {})
return resultBuffer
endfunction
@ -253,7 +257,7 @@ function! s:svnFunctions.Review(argList)
let versionOption = ' -r ' . versiontag . ' '
endif
let resultBuffer = s:DoCommand('cat' . versionOption, 'review', versiontag, {})
let resultBuffer = s:DoCommand('cat --non-interactive' . versionOption, 'review', versiontag, {})
if resultBuffer > 0
let &filetype = getbufvar(b:VCSCommandOriginalBuffer, '&filetype')
endif
@ -266,18 +270,22 @@ function! s:svnFunctions.Status(argList)
if len(a:argList) == 0
let options = a:argList
endif
return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {})
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'] + a:argList, ' '), 'unlock', join(a: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', 'update', '', {})
return s:DoCommand('update --non-interactive', 'update', '', {})
endfunction
" Annotate setting {{{2
let s:svnFunctions.AnnotateSplitRegex = '\s\+\S\+\s\+\S\+ '
" Section: Plugin Registration {{{1
call VCSCommandRegisterModule('SVN', expand('<sfile>'), s:svnFunctions, [])