mirror of
https://github.com/akelge/zsh
synced 2025-07-03 21:19:06 +00:00
Moved statusline def into a separate file
Added guitablabel def Updated VCS plugin Added keymap for choosing tabs (Cmd-1, Cmd-2, ...)
This commit is contained in:
108
vim/plugin/open_terminal.vim
Normal file
108
vim/plugin/open_terminal.vim
Normal file
@ -0,0 +1,108 @@
|
||||
"
|
||||
" File: open_terminal.vim
|
||||
"
|
||||
" Requires:
|
||||
" platform Terminal File manager
|
||||
" Mac Terminal.app Finder
|
||||
" (with Applescript)
|
||||
" Gnome gnome-terminal nautilus
|
||||
" KDE konsole konqueror
|
||||
" Windows cmd explorer
|
||||
" (with start)
|
||||
" cygwin bash explorer
|
||||
"
|
||||
" Example:
|
||||
" nnoremap <silent> <F9> :OpenTerminal<CR>
|
||||
" nnoremap <silent> <F10> :OpenFilemanager<CR><CR>
|
||||
"
|
||||
" Commands:
|
||||
" OpenTerminal
|
||||
" OpenFilemanager
|
||||
"
|
||||
|
||||
" OpenTerminal {{{1
|
||||
function! s:open_terminal()
|
||||
let l:current_dir = getcwd()
|
||||
execute("chdir " . escape(expand("%:p:h"), " \"'"))
|
||||
|
||||
if has("mac")
|
||||
let l:cmd = "
|
||||
\ tell application 'System Events' \n
|
||||
\ set is_term_running to exists application process '$Terminal' \n
|
||||
\ end tell \n
|
||||
\
|
||||
\ set cmd to 'cd $current_path' \n
|
||||
\ tell application '$Terminal' \n
|
||||
\ activate \n
|
||||
\ if is_term_running is true then \n
|
||||
\ do script with command cmd \n
|
||||
\ else \n
|
||||
\ do script with command cmd in window 1 \n
|
||||
\ end if \n
|
||||
\ end tell \n
|
||||
\ "
|
||||
let l:cmd = substitute(l:cmd, "'", '\\"', 'g')
|
||||
let l:cmd = substitute( l:cmd, "$Terminal", "Terminal", "g" )
|
||||
let l:cmd = substitute( l:cmd, "$current_path", "'" . expand("%:p:h") . "'" , "g")
|
||||
call system('osascript -e " ' . l:cmd . '"')
|
||||
|
||||
elseif has("gui_gnome") && executable("gnome-terminal")
|
||||
call system("gnome-terminal &")
|
||||
elseif has("gui_gnome") && executable("konsole")
|
||||
call system("konsole &")
|
||||
elseif has("gui_win32")
|
||||
try
|
||||
call system("start cmd")
|
||||
catch /E484:/
|
||||
echo "Ignore E484 error in Windows platform"
|
||||
endtry
|
||||
elseif executable("bash")
|
||||
!bash
|
||||
elseif has("win32")
|
||||
stop
|
||||
endif
|
||||
|
||||
execute("chdir " . escape(l:current_dir, " \"'"))
|
||||
endfunction
|
||||
|
||||
command! -nargs=0 -bar OpenTerminal call s:open_terminal()
|
||||
|
||||
"}}}1
|
||||
|
||||
" OpenFilemanager {{{1
|
||||
function! s:open_filemanager()
|
||||
let l:cmd = "$cmd ."
|
||||
|
||||
let l:current_dir = getcwd()
|
||||
execute("chdir " . escape(expand("%:p:h"), " \"'"))
|
||||
|
||||
if has("mac")
|
||||
call system("open .")
|
||||
elseif has("gui_gnome") && executable("nautilus")
|
||||
call system("nautilus .")
|
||||
elseif has("gui_gnome") && executable("konqueror")
|
||||
call system("konqueror .")
|
||||
elseif has("gui_win32") || has("win32")
|
||||
call system("explorer .")
|
||||
elseif executable("bash")
|
||||
!bash
|
||||
endif
|
||||
|
||||
execute("chdir " . escape(l:current_dir, " \"'"))
|
||||
endfunction
|
||||
|
||||
command! -nargs=0 -bar OpenFilemanager call s:open_filemanager()
|
||||
" }}}1
|
||||
|
||||
" About file info {{{1
|
||||
"=============================================================================
|
||||
" Copyright (c) 2009 by neocoin
|
||||
" File: open_terminal.vim
|
||||
" Author: Sangmin Ryu (neocoin@gmail.com)
|
||||
" Date: Tue Dec 22 13:33:32 PST 2009
|
||||
" License: The MIT License
|
||||
" Version: 0.1
|
||||
"=============================================================================
|
||||
" }}}1
|
||||
|
||||
" vim: set fdm=marker:
|
91
vim/plugin/statusline.vim
Normal file
91
vim/plugin/statusline.vim
Normal file
@ -0,0 +1,91 @@
|
||||
" """"""""""""
|
||||
" Status Line
|
||||
" """"""""""""
|
||||
" Some useful functions
|
||||
"return the syntax highlight group under the cursor ''
|
||||
function! StatuslineCurrentHighlight()
|
||||
let name = synIDattr(synID(line('.'),col('.'),1),'name')
|
||||
if name == ''
|
||||
return ''
|
||||
else
|
||||
return '[' . name . ']'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"recalculate the tab warning flag when idle and after writing
|
||||
autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
|
||||
"
|
||||
"return '[&et]' if &et is set wrong
|
||||
"return '[mixed-indenting]' if spaces and tabs are used to indent
|
||||
"return an empty string if everything is fine
|
||||
function! StatuslineTabWarning()
|
||||
if !exists("b:statusline_tab_warning")
|
||||
let tabs = search('^\t', 'nw') != 0
|
||||
let spaces = search('^ ', 'nw') != 0
|
||||
|
||||
if tabs && spaces
|
||||
let b:statusline_tab_warning = '[mixed-indenting]'
|
||||
elseif (spaces && !&et) || (tabs && &et)
|
||||
let b:statusline_tab_warning = '[&et]'
|
||||
else
|
||||
let b:statusline_tab_warning = ''
|
||||
endif
|
||||
endif
|
||||
return b:statusline_tab_warning
|
||||
endfunction
|
||||
|
||||
"recalculate the trailing whitespace warning when idle, and after saving
|
||||
autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
|
||||
|
||||
"return '[\s]' if trailing white space is detected
|
||||
"return '' otherwise
|
||||
function! StatuslineTrailingSpaceWarning()
|
||||
if !exists("b:statusline_trailing_space_warning")
|
||||
if search('\s\+$', 'nw') != 0
|
||||
let b:statusline_trailing_space_warning = '[\s]'
|
||||
else
|
||||
let b:statusline_trailing_space_warning = ''
|
||||
endif
|
||||
endif
|
||||
return b:statusline_trailing_space_warning
|
||||
endfunction
|
||||
|
||||
|
||||
" Real Status line definition
|
||||
set statusline=%t\ "tail of the filename
|
||||
|
||||
"display a warning if fileformat isnt unix
|
||||
set statusline+=%#warningmsg#
|
||||
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
|
||||
set statusline+=%*
|
||||
|
||||
"display a warning if file encoding isnt utf-8
|
||||
set statusline+=%#warningmsg#
|
||||
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
|
||||
set statusline+=%*
|
||||
|
||||
set statusline+=%h "help file flag
|
||||
set statusline+=%y "filetype
|
||||
set statusline+=%r "read only flag
|
||||
set statusline+=%m "modified flag
|
||||
|
||||
"display a warning if &et is wrong, or we have mixed-indenting
|
||||
set statusline+=%#error#
|
||||
set statusline+=%{StatuslineTabWarning()}
|
||||
set statusline+=%*
|
||||
|
||||
set statusline+=%{StatuslineTrailingSpaceWarning()}
|
||||
|
||||
"display a warning if &paste is set
|
||||
set statusline+=%#error#
|
||||
set statusline+=%{&paste?'[paste]':'[nopaste]'}
|
||||
set statusline+=%*
|
||||
|
||||
set statusline+=%= "left/right separator
|
||||
set statusline+=%{StatuslineCurrentHighlight()}\ \ "current highlight
|
||||
set statusline+=%02c, "cursor column
|
||||
set statusline+=%03l/%03L "cursor line/total lines
|
||||
set statusline+=\ hex:\ 0x%02B
|
||||
set statusline+=\ %P "percent through file
|
||||
|
||||
" vim: set ts=4 sw=4 tw=78 ft=vim :
|
72
vim/plugin/tabline.vim
Normal file
72
vim/plugin/tabline.vim
Normal file
@ -0,0 +1,72 @@
|
||||
" set up tab labels with tab number, buffer name, number of windows
|
||||
function! GuiTabLabel()
|
||||
let label = ''
|
||||
let bufnrlist = tabpagebuflist(v:lnum)
|
||||
|
||||
|
||||
" Append the tab number
|
||||
let label .= tabpagenr().': '
|
||||
|
||||
" Append the buffer name
|
||||
let name = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
|
||||
if name == ''
|
||||
" give a name to no-name documents
|
||||
if &buftype=='quickfix'
|
||||
let name = '[Quickfix List]'
|
||||
else
|
||||
let name = '[No Name]'
|
||||
endif
|
||||
else
|
||||
" get only the file name
|
||||
let name = fnamemodify(name,":t")
|
||||
endif
|
||||
let label .= name
|
||||
|
||||
for bufnr in bufnrlist
|
||||
if getbufvar(bufnr, "&modified")
|
||||
let label .= ' [+]'
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
return label
|
||||
endfunction
|
||||
|
||||
" set up tab tooltips with every buffer name
|
||||
function! GuiTabToolTip()
|
||||
let tip = ''
|
||||
let bufnrlist = tabpagebuflist(v:lnum)
|
||||
|
||||
for bufnr in bufnrlist
|
||||
" separate buffer entries
|
||||
if tip!=''
|
||||
let tip .= ' | '
|
||||
endif
|
||||
|
||||
" Add name of buffer
|
||||
let name=bufname(bufnr)
|
||||
if name == ''
|
||||
" give a name to no name documents
|
||||
if getbufvar(bufnr,'&buftype')=='quickfix'
|
||||
let name = '[Quickfix List]'
|
||||
else
|
||||
let name = '[No Name]'
|
||||
endif
|
||||
endif
|
||||
let tip.=name
|
||||
|
||||
" add modified/modifiable flags
|
||||
if getbufvar(bufnr, "&modified")
|
||||
let tip .= ' [+]'
|
||||
endif
|
||||
if getbufvar(bufnr, "&modifiable")==0
|
||||
let tip .= ' [-]'
|
||||
endif
|
||||
endfor
|
||||
|
||||
return tip
|
||||
endfunction
|
||||
|
||||
set guitablabel=%!GuiTabLabel()
|
||||
set guitabtooltip=%!GuiTabToolTip()
|
||||
|
||||
" vim: set ts=4 sw=4 tw=78 ft=vim :
|
268
vim/plugin/vcsbzr.vim
Normal file
268
vim/plugin/vcsbzr.vim
Normal file
@ -0,0 +1,268 @@
|
||||
" 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 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('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 shellescape(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 statusText = s:VCSCommandUtility.system(s:Executable() . ' 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 = 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
|
||||
|
||||
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
|
||||
|
||||
" Annotate setting {{{2
|
||||
let s:bzrFunctions.AnnotateSplitRegex = '^[^|]\+ | '
|
||||
|
||||
" Section: Plugin Registration {{{1
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('BZR', expand('<sfile>'), s:bzrFunctions, [])
|
||||
|
||||
let &cpo = s:save_cpo
|
@ -4,7 +4,6 @@
|
||||
" Control Systems, such as CVS, SVN, SVK, and git.
|
||||
"
|
||||
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
|
||||
" Version: Beta 29
|
||||
" License:
|
||||
" Copyright (c) 2008 Bob Hiestand
|
||||
"
|
||||
@ -33,18 +32,17 @@
|
||||
" directory and all subdirectories associated with the current buffer). The
|
||||
" output of the commands is captured in a new scratch window.
|
||||
"
|
||||
" This plugin needs additional extension plugins, each specific to a source
|
||||
" control system, to function. Those plugins should be placed in a
|
||||
" subdirectory of the standard plugin directory named 'vcscommand'. Several
|
||||
" options include the name of the version control system in the option name.
|
||||
" Such options use the placeholder text '{VCSType}', which would be replaced
|
||||
" in actual usage with 'CVS' or 'SVN', for instance.
|
||||
" 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
|
||||
" 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
|
||||
@ -52,6 +50,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.
|
||||
@ -89,7 +91,7 @@
|
||||
" VCS scratch buffers associated with the original file.
|
||||
"
|
||||
" VCSInfo Displays extended information about the current file in a
|
||||
" new scratch buffer.
|
||||
" new scratch buffer.
|
||||
"
|
||||
" VCSLock Locks the current file in order to prevent other users from
|
||||
" concurrently modifying it. The exact semantics of this
|
||||
@ -152,6 +154,7 @@
|
||||
"
|
||||
" <Leader>ca VCSAdd
|
||||
" <Leader>cn VCSAnnotate
|
||||
" <Leader>cN VCSAnnotate!
|
||||
" <Leader>cc VCSCommit
|
||||
" <Leader>cD VCSDelete
|
||||
" <Leader>cd VCSDiff
|
||||
@ -268,7 +271,7 @@
|
||||
" mapping to quit a VCS scratch buffer:
|
||||
"
|
||||
" augroup VCSCommand
|
||||
" au VCSCommand User VCSBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr>
|
||||
" au VCSCommand User VCSBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr>
|
||||
" augroup END
|
||||
"
|
||||
" The following hooks are available:
|
||||
@ -331,6 +334,9 @@ 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 = {}
|
||||
|
||||
@ -346,7 +352,7 @@ unlet! s:vimDiffRestoreCmd
|
||||
" original buffer currently reflected in vimdiff windows
|
||||
unlet! s:vimDiffSourceBuffer
|
||||
|
||||
"
|
||||
"
|
||||
unlet! s:vimDiffScratchList
|
||||
|
||||
" Section: Utility functions {{{1
|
||||
@ -359,6 +365,23 @@ 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
|
||||
return call('system', a:000)
|
||||
finally
|
||||
if exists("save_sxq")
|
||||
let &sxq = save_sxq
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Function: s:CreateMapping(shortcut, expansion, display) {{{2
|
||||
" Creates the given mapping by prepending the contents of
|
||||
@ -480,15 +503,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
|
||||
@ -503,28 +517,45 @@ function! s:EditFile(command, originalBuffer, statusText)
|
||||
|
||||
enew
|
||||
|
||||
let b:VCSCommandCommand = a:command
|
||||
let b:VCSCommandOriginalBuffer = a:originalBuffer
|
||||
let b:VCSCommandSourceFile = bufname(a:originalBuffer)
|
||||
let b:VCSCommandVCSType = vcsType
|
||||
call s:SetupScratchBuffer(a:command, vcsType, a:originalBuffer, a:statusText)
|
||||
|
||||
setlocal buftype=nofile
|
||||
setlocal noswapfile
|
||||
let &filetype = vcsType . a:command
|
||||
|
||||
if a:statusText != ''
|
||||
let b:VCSCommandStatusText = a:statusText
|
||||
endif
|
||||
|
||||
if VCSCommandGetOption('VCSCommandDeleteOnHide', 0)
|
||||
setlocal bufhidden=delete
|
||||
endif
|
||||
silent noautocmd file `=resultBufferName`
|
||||
finally
|
||||
let s:isEditFileRunning -= 1
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Function: s:SetupScratchBuffer(command, vcsType, originalBuffer, statusText) {{{2
|
||||
" Creates convenience buffer variables and the name of a vcscommand result
|
||||
" buffer.
|
||||
|
||||
function! s:SetupScratchBuffer(command, vcsType, originalBuffer, statusText)
|
||||
let nameExtension = VCSCommandGetOption('VCSCommandResultBufferNameExtension', '')
|
||||
if nameExtension == ''
|
||||
let nameFunction = VCSCommandGetOption('VCSCommandResultBufferNameFunction', 's:GenerateResultBufferName')
|
||||
else
|
||||
let nameFunction = VCSCommandGetOption('VCSCommandResultBufferNameFunction', 's:GenerateResultBufferNameWithExtension')
|
||||
endif
|
||||
|
||||
let name = call(nameFunction, [a:command, a:originalBuffer, a:vcsType, a:statusText])
|
||||
|
||||
let b:VCSCommandCommand = a:command
|
||||
let b:VCSCommandOriginalBuffer = a:originalBuffer
|
||||
let b:VCSCommandSourceFile = bufname(a:originalBuffer)
|
||||
let b:VCSCommandVCSType = a:vcsType
|
||||
if a:statusText != ''
|
||||
let b:VCSCommandStatusText = a:statusText
|
||||
endif
|
||||
|
||||
setlocal buftype=nofile
|
||||
setlocal noswapfile
|
||||
let &filetype = a:vcsType . a:command
|
||||
|
||||
if VCSCommandGetOption('VCSCommandDeleteOnHide', 0)
|
||||
setlocal bufhidden=delete
|
||||
endif
|
||||
silent noautocmd file `=name`
|
||||
endfunction
|
||||
|
||||
" Function: s:SetupBuffer() {{{2
|
||||
" Attempts to set the b:VCSCommandBufferInfo variable
|
||||
|
||||
@ -563,7 +594,7 @@ endfunction
|
||||
|
||||
function! s:MarkOrigBufferForSetup(buffer)
|
||||
checktime
|
||||
if a:buffer > 0
|
||||
if a:buffer > 0
|
||||
let origBuffer = VCSCommandGetOriginalBuffer(a:buffer)
|
||||
" This should never not work, but I'm paranoid
|
||||
if origBuffer != a:buffer
|
||||
@ -652,7 +683,7 @@ function! s:VimDiffRestore(vimDiffBuff)
|
||||
endif
|
||||
|
||||
unlet s:vimDiffRestoreCmd
|
||||
endif
|
||||
endif
|
||||
" All buffers are gone.
|
||||
unlet s:vimDiffSourceBuffer
|
||||
unlet s:vimDiffScratchList
|
||||
@ -667,6 +698,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
|
||||
@ -717,7 +785,7 @@ endfunction
|
||||
|
||||
function! s:VCSFinishCommitWithBuffer()
|
||||
setlocal nomodified
|
||||
let currentBuffer = bufnr('%')
|
||||
let currentBuffer = bufnr('%')
|
||||
let logMessageList = getbufline('%', 1, '$')
|
||||
call filter(logMessageList, 'v:val !~ ''^\s*VCS:''')
|
||||
let resultBuffer = s:VCSFinishCommit(logMessageList, b:VCSCommandOriginalBuffer)
|
||||
@ -855,7 +923,7 @@ function! s:VCSVimDiff(...)
|
||||
wincmd W
|
||||
execute 'buffer' originalBuffer
|
||||
" Store info for later original buffer restore
|
||||
let s:vimDiffRestoreCmd =
|
||||
let s:vimDiffRestoreCmd =
|
||||
\ 'call setbufvar('.originalBuffer.', ''&diff'', '.getbufvar(originalBuffer, '&diff').')'
|
||||
\ . '|call setbufvar('.originalBuffer.', ''&foldcolumn'', '.getbufvar(originalBuffer, '&foldcolumn').')'
|
||||
\ . '|call setbufvar('.originalBuffer.', ''&foldenable'', '.getbufvar(originalBuffer, '&foldenable').')'
|
||||
@ -997,6 +1065,7 @@ function! VCSCommandRegisterModule(name, path, commandMap, mappingMap)
|
||||
call s:CreateMapping(shortcut, expansion, a:name . " extension mapping " . shortcut)
|
||||
endfor
|
||||
endif
|
||||
return s:VCSCommandUtility
|
||||
endfunction
|
||||
|
||||
" Function: VCSCommandDoCommand(cmd, cmdName, statusText, [options]) {{{2
|
||||
@ -1018,7 +1087,7 @@ function! VCSCommandDoCommand(cmd, cmdName, statusText, options)
|
||||
endif
|
||||
|
||||
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
|
||||
if originalBuffer == -1
|
||||
if originalBuffer == -1
|
||||
throw 'Original buffer no longer exists, aborting.'
|
||||
endif
|
||||
|
||||
@ -1036,7 +1105,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 . ' -- "' . fileName . '"'
|
||||
endif
|
||||
|
||||
" Change to the directory of the current buffer. This is done for CVS, but
|
||||
@ -1044,7 +1113,7 @@ function! VCSCommandDoCommand(cmd, cmdName, statusText, options)
|
||||
|
||||
let oldCwd = VCSCommandChangeToCurrentFileDir(path)
|
||||
try
|
||||
let output = system(fullCmd)
|
||||
let output = s:VCSCommandUtility.system(fullCmd)
|
||||
finally
|
||||
call VCSCommandChdir(oldCwd)
|
||||
endtry
|
||||
@ -1163,8 +1232,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>])
|
||||
@ -1200,6 +1269,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>
|
||||
@ -1217,6 +1287,7 @@ let s:defaultMappings = [
|
||||
\['i', 'VCSInfo'],
|
||||
\['L', 'VCSLock'],
|
||||
\['l', 'VCSLog'],
|
||||
\['N', 'VCSSplitAnnotate'],
|
||||
\['n', 'VCSAnnotate'],
|
||||
\['q', 'VCSRevert'],
|
||||
\['r', 'VCSReview'],
|
||||
@ -1271,7 +1342,7 @@ function! s:CloseAllResultBuffers()
|
||||
let buffnr = 1
|
||||
let buffmaxnr = bufnr('$')
|
||||
while buffnr <= buffmaxnr
|
||||
if getbufvar(buffnr, 'VCSCommandOriginalBuffer') != ""
|
||||
if getbufvar(buffnr, 'VCSCommandOriginalBuffer') != ""
|
||||
execute 'bw' buffnr
|
||||
endif
|
||||
let buffnr = buffnr + 1
|
||||
|
@ -32,23 +32,23 @@
|
||||
" 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
|
||||
@ -106,23 +106,40 @@ 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 shellescape(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 = VCSCommandGetOption('VCSCommandCVSExec', 'cvs') . ' ' . a:cmd
|
||||
return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
|
||||
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: GetRevision() {{{2
|
||||
" 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! GetRevision()
|
||||
function! s:GetRevision()
|
||||
if !exists('b:VCSCommandBufferInfo')
|
||||
let b:VCSCommandBufferInfo = s:cvsFunctions.GetBufferInfo()
|
||||
endif
|
||||
@ -187,7 +204,7 @@ function! s:cvsFunctions.Annotate(argList)
|
||||
" CVS defaults to pulling HEAD, regardless of current branch.
|
||||
" Therefore, always pass desired revision.
|
||||
let caption = ''
|
||||
let options = ['-r' . GetRevision()]
|
||||
let options = ['-r' . s:GetRevision()]
|
||||
endif
|
||||
elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
|
||||
let caption = a:argList[0]
|
||||
@ -284,7 +301,7 @@ function! s:cvsFunctions.GetBufferInfo()
|
||||
endif
|
||||
let oldCwd = VCSCommandChangeToCurrentFileDir(fileName)
|
||||
try
|
||||
let statusText=system(VCSCommandGetOption('VCSCommandCVSExec', 'cvs') . ' status "' . realFileName . '"')
|
||||
let statusText=s:VCSCommandUtility.system(s:Executable() . ' status -- "' . realFileName . '"')
|
||||
if(v:shell_error)
|
||||
return []
|
||||
endif
|
||||
@ -292,7 +309,7 @@ function! s:cvsFunctions.GetBufferInfo()
|
||||
|
||||
" We can still be in a CVS-controlled directory without this being a CVS
|
||||
" file
|
||||
if match(revision, '^New file!$') >= 0
|
||||
if match(revision, '^New file!$') >= 0
|
||||
let revision='New'
|
||||
elseif match(revision, '^\d\+\.\d\+\%(\.\d\+\.\d\+\)*$') <0
|
||||
return ['Unknown']
|
||||
@ -391,6 +408,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()
|
||||
@ -425,7 +445,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
|
||||
@ -436,6 +455,6 @@ amenu <silent> &Plugin.VCS.CVS.WatchOff <Plug>CVSWatchOff
|
||||
amenu <silent> &Plugin.VCS.CVS.WatchRemove <Plug>CVSWatchRemove
|
||||
|
||||
" Section: Plugin Registration {{{1
|
||||
call VCSCommandRegisterModule('CVS', expand('<sfile>'), s:cvsFunctions, s:cvsExtensionMappings)
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('CVS', expand('<sfile>'), s:cvsFunctions, s:cvsExtensionMappings)
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
@ -65,12 +65,19 @@ 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 shellescape(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 = VCSCommandGetOption('VCSCommandGitExec', 'git',) . ' ' . a:cmd
|
||||
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.'
|
||||
@ -85,7 +92,7 @@ endfunction
|
||||
function! s:gitFunctions.Identify(buffer)
|
||||
let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(a:buffer)))
|
||||
try
|
||||
call system(VCSCommandGetOption('VCSCommandGitExec', 'git') . ' rev-parse --is-inside-work-tree')
|
||||
call s:VCSCommandUtility.system(s:Executable() . ' rev-parse --is-inside-work-tree')
|
||||
if(v:shell_error)
|
||||
return 0
|
||||
else
|
||||
@ -116,7 +123,7 @@ function! s:gitFunctions.Annotate(argList)
|
||||
let options = join(a:argList, ' ')
|
||||
endif
|
||||
|
||||
let resultBuffer = s:DoCommand('blame ' . options . ' -- ', 'annotate', options, {})
|
||||
let resultBuffer = s:DoCommand('blame ' . options, 'annotate', options, {})
|
||||
if resultBuffer > 0
|
||||
normal 1G
|
||||
set filetype=gitAnnotate
|
||||
@ -177,7 +184,7 @@ endfunction
|
||||
function! s:gitFunctions.GetBufferInfo()
|
||||
let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname('%')))
|
||||
try
|
||||
let branch = substitute(system(VCSCommandGetOption('VCSCommandGitExec', 'git') . ' symbolic-ref -q HEAD'), '\n$', '', '')
|
||||
let branch = substitute(s:VCSCommandUtility.system(s:Executable() . ' symbolic-ref -q HEAD'), '\n$', '', '')
|
||||
if v:shell_error
|
||||
let branch = 'DETACHED'
|
||||
else
|
||||
@ -190,7 +197,7 @@ function! s:gitFunctions.GetBufferInfo()
|
||||
if method != ''
|
||||
let method = ' --' . method
|
||||
endif
|
||||
let tag = substitute(system(VCSCommandGetOption('VCSCommandGitExec', 'git') . ' describe' . method), '\n$', '', '')
|
||||
let tag = substitute(s:VCSCommandUtility.system(s:Executable() . ' describe' . method), '\n$', '', '')
|
||||
if !v:shell_error
|
||||
call add(info, tag)
|
||||
break
|
||||
@ -227,7 +234,7 @@ function! s:gitFunctions.Review(argList)
|
||||
|
||||
let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(VCSCommandGetOriginalBuffer('%'))))
|
||||
try
|
||||
let prefix = system(VCSCommandGetOption('VCSCommandGitExec', 'git') . ' rev-parse --show-prefix')
|
||||
let prefix = s:VCSCommandUtility.system(s:Executable() . ' rev-parse --show-prefix')
|
||||
finally
|
||||
call VCSCommandChdir(oldCwd)
|
||||
endtry
|
||||
@ -251,8 +258,10 @@ 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, [])
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('git', expand('<sfile>'), s:gitFunctions, [])
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
290
vim/plugin/vcshg.vim
Normal file
290
vim/plugin/vcshg.vim
Normal file
@ -0,0 +1,290 @@
|
||||
" 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:Executable() {{{2
|
||||
" Returns the executable used to invoke hg suitable for use in a shell
|
||||
" command.
|
||||
function! s:Executable()
|
||||
return shellescape(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'] + 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 = ' -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
|
||||
|
||||
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 = 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
|
||||
|
||||
" 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
|
||||
|
||||
" Annotate setting {{{2
|
||||
let s:hgFunctions.AnnotateSplitRegex = '\d\+: '
|
||||
|
||||
" Section: Plugin Registration {{{1
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('HG', expand('<sfile>'), s:hgFunctions, [])
|
||||
|
||||
let &cpo = s:save_cpo
|
@ -60,12 +60,19 @@ 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 shellescape(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 = VCSCommandGetOption('VCSCommandSVKExec', 'svk') . ' ' . a:cmd
|
||||
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.'
|
||||
@ -82,7 +89,7 @@ function! s:svkFunctions.Identify(buffer)
|
||||
else
|
||||
let directoryName = fnamemodify(fileName, ':p:h')
|
||||
endif
|
||||
let statusText = system(VCSCommandGetOption('VCSCommandSVKExec', 'svk') . ' info "' . directoryName . '"')
|
||||
let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . directoryName . '"', "no")
|
||||
if(v:shell_error)
|
||||
return 0
|
||||
else
|
||||
@ -138,7 +145,7 @@ endfunction
|
||||
" Function: s:svkFunctions.Diff(argList) {{{2
|
||||
function! s:svkFunctions.Diff(argList)
|
||||
if len(a:argList) == 0
|
||||
let revOptions = []
|
||||
let revOptions = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let revOptions = ['-r' . join(a:argList, ':')]
|
||||
@ -167,7 +174,7 @@ endfunction
|
||||
function! s:svkFunctions.GetBufferInfo()
|
||||
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
|
||||
let fileName = resolve(bufname(originalBuffer))
|
||||
let statusText = system(VCSCommandGetOption('VCSCommandSVKExec', 'svk') . ' status -v "' . fileName . '"')
|
||||
let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -v -- "' . fileName . '"')
|
||||
if(v:shell_error)
|
||||
return []
|
||||
endif
|
||||
@ -257,6 +264,6 @@ function! s:svkFunctions.Update(argList)
|
||||
endfunction
|
||||
|
||||
" Section: Plugin Registration {{{1
|
||||
call VCSCommandRegisterModule('SVK', expand('<sfile>'), s:svkFunctions, [])
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('SVK', expand('<sfile>'), s:svkFunctions, [])
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
@ -67,12 +67,19 @@ 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 shellescape(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 = VCSCommandGetOption('VCSCommandSVNExec', 'svn') . ' ' . a:cmd
|
||||
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.'
|
||||
@ -148,7 +155,7 @@ endfunction
|
||||
" Function: s:svnFunctions.Diff(argList) {{{2
|
||||
function! s:svnFunctions.Diff(argList)
|
||||
if len(a:argList) == 0
|
||||
let revOptions = []
|
||||
let revOptions = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let revOptions = ['-r' . join(a:argList, ':')]
|
||||
@ -193,7 +200,7 @@ endfunction
|
||||
function! s:svnFunctions.GetBufferInfo()
|
||||
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
|
||||
let fileName = bufname(originalBuffer)
|
||||
let statusText = system(VCSCommandGetOption('VCSCommandSVNExec', 'svn') . ' status --non-interactive -vu "' . fileName . '"')
|
||||
let statusText = s:VCSCommandUtility.system(s:Executable() . ' status --non-interactive -vu -- "' . fileName . '"')
|
||||
if(v:shell_error)
|
||||
return []
|
||||
endif
|
||||
@ -277,12 +284,16 @@ endfunction
|
||||
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
|
||||
call VCSCommandRegisterModule('SVN', expand('<sfile>'), s:svnFunctions, [])
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('SVN', expand('<sfile>'), s:svnFunctions, [])
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
Reference in New Issue
Block a user