mirror of
https://github.com/gryf/.vim.git
synced 2025-12-18 03:50:30 +01:00
Moja prawie współczesna konfiguracja. Dużo rzeczy :)
This commit is contained in:
1070
plugin/DirDiff.vim
Normal file
1070
plugin/DirDiff.vim
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
4059
plugin/NERD_tree.vim
Normal file
4059
plugin/NERD_tree.vim
Normal file
File diff suppressed because it is too large
Load Diff
635
plugin/delimitMate.vim
Normal file
635
plugin/delimitMate.vim
Normal file
@@ -0,0 +1,635 @@
|
||||
" ============================================================================
|
||||
" File: delimitMate.vim
|
||||
" Version: 2.0
|
||||
" Description: This plugin tries to emulate the auto-completion of delimiters
|
||||
" that TextMate provides.
|
||||
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
||||
" Manual: Read ":help delimitMate".
|
||||
" Credits: Some of the code is modified or just copied from the following:
|
||||
"
|
||||
" - Ian McCracken
|
||||
" Post titled: Vim, Part II: Matching Pairs:
|
||||
" http://concisionandconcinnity.blogspot.com/
|
||||
"
|
||||
" - Aristotle Pagaltzis
|
||||
" From the comments on the previous blog post and from:
|
||||
" http://gist.github.com/144619
|
||||
"
|
||||
" - Vim Scripts:
|
||||
" http://www.vim.org/scripts/
|
||||
|
||||
" Initialization: {{{
|
||||
if exists("g:loaded_delimitMate") "{{{
|
||||
" User doesn't want this plugin, let's get out!
|
||||
finish
|
||||
endif
|
||||
let g:loaded_delimitMate = 1
|
||||
|
||||
if exists("s:loaded_delimitMate") && !exists("g:delimitMate_testing")
|
||||
" Don't define the functions if they already exist: just do the work
|
||||
" (unless we are testing):
|
||||
call s:DelimitMateDo()
|
||||
finish
|
||||
endif
|
||||
|
||||
if v:version < 700
|
||||
echoerr "delimitMate: this plugin requires vim >= 7!"
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:loaded_delimitMate = 1 " }}}
|
||||
let delimitMate_version = '2.0'
|
||||
|
||||
function! s:Init() "{{{
|
||||
|
||||
let b:loaded_delimitMate = 1
|
||||
|
||||
" delimitMate_autoclose {{{
|
||||
if !exists("b:delimitMate_autoclose") && !exists("g:delimitMate_autoclose")
|
||||
let b:delimitMate_autoclose = 1
|
||||
elseif !exists("b:delimitMate_autoclose") && exists("g:delimitMate_autoclose")
|
||||
let b:delimitMate_autoclose = g:delimitMate_autoclose
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_matchpairs {{{
|
||||
if !exists("b:delimitMate_matchpairs") && !exists("g:delimitMate_matchpairs")
|
||||
if s:ValidMatchpairs(&matchpairs) == 1
|
||||
let s:matchpairs_temp = &matchpairs
|
||||
else
|
||||
echoerr "delimitMate: There seems to be a problem with 'matchpairs', read ':help matchpairs' and fix it or notify the maintainer of this script if this is a bug."
|
||||
finish
|
||||
endif
|
||||
elseif exists("b:delimitMate_matchpairs")
|
||||
if s:ValidMatchpairs(b:delimitMate_matchpairs) || b:delimitMate_matchpairs == ""
|
||||
let s:matchpairs_temp = b:delimitMate_matchpairs
|
||||
else
|
||||
echoerr "delimitMate: Invalid format in 'b:delimitMate_matchpairs', falling back to matchpairs. Fix the error and use the command :DelimitMateReload to try again."
|
||||
if s:ValidMatchpairs(&matchpairs) == 1
|
||||
let s:matchpairs_temp = &matchpairs
|
||||
else
|
||||
echoerr "delimitMate: There seems to be a problem with 'matchpairs', read ':help matchpairs' and fix it or notify the maintainer of this script if this is a bug."
|
||||
let s:matchpairs_temp = ""
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if s:ValidMatchpairs(g:delimitMate_matchpairs) || g:delimitMate_matchpairs == ""
|
||||
let s:matchpairs_temp = g:delimitMate_matchpairs
|
||||
else
|
||||
echoerr "delimitMate: Invalid format in 'g:delimitMate_matchpairs', falling back to matchpairs. Fix the error and use the command :DelimitMateReload to try again."
|
||||
if s:ValidMatchpairs(&matchpairs) == 1
|
||||
let s:matchpairs_temp = &matchpairs
|
||||
else
|
||||
echoerr "delimitMate: There seems to be a problem with 'matchpairs', read ':help matchpairs' and fix it or notify the maintainer of this script if this is a bug."
|
||||
let s:matchpairs_temp = ""
|
||||
endif
|
||||
endif
|
||||
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_quotes {{{
|
||||
if exists("b:delimitMate_quotes")
|
||||
if b:delimitMate_quotes =~ '^\(\S\)\(\s\S\)*$' || b:delimitMate_quotes == ""
|
||||
let s:quotes = split(b:delimitMate_quotes)
|
||||
else
|
||||
let s:quotes = split("\" ' `")
|
||||
echoerr "delimitMate: There is a problem with the format of 'b:delimitMate_quotes', it should be a string of single characters separated by spaces. Falling back to default values."
|
||||
endif
|
||||
elseif exists("g:delimitMate_quotes")
|
||||
if g:delimitMate_quotes =~ '^\(\S\)\(\s\S\)*$' || g:delimitMate_quotes == ""
|
||||
let s:quotes = split(g:delimitMate_quotes)
|
||||
else
|
||||
let s:quotes = split("\" ' `")
|
||||
echoerr "delimitMate: There is a problem with the format of 'g:delimitMate_quotes', it should be a string of single characters separated by spaces. Falling back to default values."
|
||||
endif
|
||||
else
|
||||
let s:quotes = split("\" ' `")
|
||||
endif
|
||||
let b:delimitMate_quotes_list = s:quotes " }}}
|
||||
|
||||
" delimitMate_visual_leader {{{
|
||||
if !exists("b:delimitMate_visual_leader") && !exists("g:delimitMate_visual_leader")
|
||||
let b:delimitMate_visual_leader = exists('b:maplocalleader') ? b:maplocalleader :
|
||||
\ exists('g:mapleader') ? g:mapleader : "\\"
|
||||
elseif !exists("b:delimitMate_visual_leader") && exists("g:delimitMate_visual_leader")
|
||||
let b:delimitMate_visual_leader = g:delimitMate_visual_leader
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_expand_space {{{
|
||||
if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space")
|
||||
let b:delimitMate_expand_space = 0
|
||||
elseif !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space")
|
||||
let b:delimitMate_expand_space = g:delimitMate_expand_space
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_expand_cr {{{
|
||||
if !exists("b:delimitMate_expand_cr") && !exists("g:delimitMate_expand_cr")
|
||||
let b:delimitMate_expand_cr = 0
|
||||
elseif !exists("b:delimitMate_expand_cr") && exists("g:delimitMate_expand_cr")
|
||||
let b:delimitMate_expand_cr = g:delimitMate_expand_cr
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_smart_quotes {{{
|
||||
if !exists("b:delimitMate_smart_quotes") && !exists("g:delimitMate_smart_quotes")
|
||||
let b:delimitMate_smart_quotes = 1
|
||||
elseif !exists("b:delimitMate_smart_quotes") && exists("g:delimitMate_smart_quotes")
|
||||
let b:delimitMate_smart_quotes = split(g:delimitMate_smart_quotes)
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_apostrophes {{{
|
||||
if !exists("b:delimitMate_apostrophes") && !exists("g:delimitMate_apostrophes")
|
||||
"let s:apostrophes = split("n't:'s:'re:'m:'d:'ll:'ve:s'",':')
|
||||
let s:apostrophes = []
|
||||
elseif !exists("b:delimitMate_apostrophes") && exists("g:delimitMate_apostrophes")
|
||||
let s:apostrophes = split(g:delimitMate_apostrophes)
|
||||
else
|
||||
let s:apostrophes = split(b:delimitMate_apostrophes)
|
||||
endif
|
||||
let b:delimitMate_apostrophes_list = s:apostrophes " }}}
|
||||
|
||||
" delimitMate_tab2exit {{{
|
||||
if !exists("b:delimitMate_tab2exit") && !exists("g:delimitMate_tab2exit")
|
||||
let b:delimitMate_tab2exit = 1
|
||||
elseif !exists("b:delimitMate_tab2exit") && exists("g:delimitMate_tab2exit")
|
||||
let b:delimitMate_tab2exit = g:delimitMate_tab2exit
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
let b:delimitMate_matchpairs_list = split(s:matchpairs_temp, ',')
|
||||
let b:delimitMate_left_delims = split(s:matchpairs_temp, ':.,\=')
|
||||
let b:delimitMate_right_delims = split(s:matchpairs_temp, ',\=.:')
|
||||
let s:VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode."
|
||||
|
||||
call s:UnMap()
|
||||
if b:delimitMate_autoclose
|
||||
call s:AutoClose()
|
||||
else
|
||||
call s:NoAutoClose()
|
||||
endif
|
||||
call s:VisualMaps()
|
||||
call s:ExtraMappings()
|
||||
|
||||
endfunction "}}} Init()
|
||||
"}}}
|
||||
|
||||
" Utilities: {{{
|
||||
function! s:ValidMatchpairs(str) "{{{
|
||||
if a:str !~ '^.:.\(,.:.\)*$'
|
||||
return 0
|
||||
endif
|
||||
for pair in split(a:str,',')
|
||||
if strpart(pair, 0, 1) == strpart(pair, 2, 1) || strlen(pair) != 3
|
||||
return 0
|
||||
endif
|
||||
endfor
|
||||
return 1
|
||||
endfunction "}}}
|
||||
|
||||
function! DelimitMate_ShouldJump() "{{{
|
||||
let char = getline('.')[col('.') - 1]
|
||||
for pair in b:delimitMate_matchpairs_list
|
||||
if char == split( pair, ':' )[1]
|
||||
" Same character on the rigth, jump over it.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
for quote in b:delimitMate_quotes_list
|
||||
if char == quote
|
||||
" Same character on the rigth, jump over it.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! s:IsBlockVisual() " {{{
|
||||
if visualmode() == "<C-V>"
|
||||
return 1
|
||||
endif
|
||||
" Store unnamed register values for later use in s:RestoreRegister().
|
||||
let s:save_reg = getreg('"')
|
||||
let s:save_reg_mode = getregtype('"')
|
||||
|
||||
if len(getline('.')) == 0
|
||||
" This for proper wrap of empty lines.
|
||||
let @" = "\n"
|
||||
endif
|
||||
return 0
|
||||
endfunction " }}}
|
||||
|
||||
function! s:IsEmptyPair(str) "{{{
|
||||
for pair in b:delimitMate_matchpairs_list
|
||||
if a:str == join( split( pair, ':' ),'' )
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
for quote in b:delimitMate_quotes_list
|
||||
if a:str == quote . quote
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! DelimitMate_WithinEmptyPair() "{{{
|
||||
let cur = strpart( getline('.'), col('.')-2, 2 )
|
||||
return s:IsEmptyPair( cur )
|
||||
endfunction "}}}
|
||||
|
||||
function! s:WriteBefore(str) "{{{
|
||||
let len = len(a:str)
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if col < 0
|
||||
call setline('.',line[(col+len+1):])
|
||||
else
|
||||
call setline('.',line[:(col)].line[(col+len+1):])
|
||||
endif
|
||||
return a:str
|
||||
endfunction " }}}
|
||||
|
||||
function! s:WriteAfter(str) "{{{
|
||||
let len = len(a:str)
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if (col) < 0
|
||||
call setline('.',a:str.line)
|
||||
else
|
||||
call setline('.',line[:(col)].a:str.line[(col+len):])
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! s:RestoreRegister() " {{{
|
||||
" Restore unnamed register values store in s:IsBlockVisual().
|
||||
call setreg('"', s:save_reg, s:save_reg_mode)
|
||||
echo ""
|
||||
endfunction " }}}
|
||||
" }}}
|
||||
|
||||
" Doers: {{{
|
||||
function! s:JumpIn(char) " {{{
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if (col) < 0
|
||||
call setline('.',a:char.line)
|
||||
else
|
||||
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
||||
call setline('.',line[:(col)].a:char.line[(col+1):])
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! s:JumpOut(char) "{{{
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if line[col+1] == a:char
|
||||
call setline('.',line[:(col)].line[(col+2):])
|
||||
endif
|
||||
return a:char
|
||||
endfunction " }}}
|
||||
|
||||
function! DelimitMate_JumpAny() " {{{
|
||||
let nchar = getline('.')[col('.')-1]
|
||||
return nchar . "\<Del>"
|
||||
endfunction " DelimitMate_JumpAny() }}}
|
||||
|
||||
function! s:SkipDelim(char) "{{{
|
||||
let cur = strpart( getline('.'), col('.')-2, 3 )
|
||||
if cur[0] == "\\"
|
||||
" Escaped character
|
||||
return a:char
|
||||
elseif cur[1] == a:char
|
||||
" Exit pair
|
||||
return s:WriteBefore(a:char)
|
||||
"elseif cur[1] == ' ' && cur[2] == a:char
|
||||
"" I'm leaving this in case someone likes it. Jump an space and delimiter.
|
||||
"return "\<Right>\<Right>"
|
||||
elseif s:IsEmptyPair( cur[0] . a:char )
|
||||
" Add closing delimiter and jump back to the middle.
|
||||
return s:WriteAfter(a:char)
|
||||
else
|
||||
" Nothing special here, return the same character.
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:QuoteDelim(char) "{{{
|
||||
let line = getline('.')
|
||||
let col = col('.') - 2
|
||||
if line[col] == "\\"
|
||||
" Seems like a escaped character, insert one quotation mark.
|
||||
return a:char
|
||||
elseif line[col + 1] == a:char
|
||||
" Get out of the string.
|
||||
return s:WriteBefore(a:char)
|
||||
elseif (line[col] =~ '[a-zA-Z0-9]' && a:char == "'") ||
|
||||
\(line[col] =~ '[a-zA-Z0-9]' && b:delimitMate_smart_quotes)
|
||||
" Seems like an apostrophe or a closing, insert a single quote.
|
||||
return a:char
|
||||
elseif (line[col] == a:char && line[col + 1 ] != a:char) && b:delimitMate_smart_quotes
|
||||
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
|
||||
return s:WriteAfter(a:char)
|
||||
else
|
||||
" Insert a pair and jump to the middle.
|
||||
call s:WriteAfter(a:char)
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:MapMsg(msg) "{{{
|
||||
redraw
|
||||
echomsg a:msg
|
||||
return ""
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Mappings: {{{
|
||||
function! s:NoAutoClose() "{{{
|
||||
" inoremap <buffer> ) <C-R>=<SID>SkipDelim('\)')<CR>
|
||||
for delim in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>SkipDelim("' . escape(delim,'"') . '")<CR>'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! s:AutoClose() "{{{
|
||||
" Add matching pair and jump to the midle:
|
||||
" inoremap <buffer> ( ()<Left>
|
||||
let i = 0
|
||||
while i < len(b:delimitMate_matchpairs_list)
|
||||
let ld = b:delimitMate_left_delims[i]
|
||||
let rd = b:delimitMate_right_delims[i]
|
||||
exec 'inoremap <buffer> ' . ld . ' ' . ld . '<C-R>=<SID>JumpIn("' . rd . '")<CR>'
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
|
||||
" inoremap <buffer> " <C-R>=<SID>QuoteDelim("\"")<CR>
|
||||
for delim in b:delimitMate_quotes_list
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>QuoteDelim("\' . delim . '")<CR>'
|
||||
endfor
|
||||
|
||||
" Exit from inside the matching pair:
|
||||
for delim in b:delimitMate_right_delims
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>JumpOut("\' . delim . '")<CR>'
|
||||
endfor
|
||||
|
||||
" Try to fix the use of apostrophes (de-activated by default):
|
||||
" inoremap <buffer> n't n't
|
||||
for map in b:delimitMate_apostrophes_list
|
||||
exec "inoremap <buffer> " . map . " " . map
|
||||
endfor
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! s:VisualMaps() " {{{
|
||||
let vleader = b:delimitMate_visual_leader
|
||||
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
|
||||
let i = 0
|
||||
while i < len(b:delimitMate_matchpairs_list)
|
||||
" Map left delimiter:
|
||||
let ld = b:delimitMate_left_delims[i]
|
||||
let rd = b:delimitMate_right_delims[i]
|
||||
exec 'vnoremap <buffer> <expr> ' . vleader . ld . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . ld . '\<C-R>\"' . rd . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||
|
||||
" Map right delimiter:
|
||||
exec 'vnoremap <buffer> <expr> ' . vleader . rd . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . ld . '\<C-R>\"' . rd . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
" Wrap the selection with matching quotes, but do nothing if blockwise visual mode is active:
|
||||
for quote in b:delimitMate_quotes_list
|
||||
" vnoremap <buffer> <expr> \' <SID>IsBlockVisual() ? <SID>MapMsg("Message") : "s'\<C-R>\"'\<Esc>:call <SID>RestoreRegister()<CR>"
|
||||
exec 'vnoremap <buffer> <expr> ' . vleader . quote . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . escape(quote,'"') .'\<C-R>\"' . escape(quote,'"') . '\<Esc>:call <SID>RestoreRegister()<CR>"'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! DelimitMate_ExpandReturn() "{{{
|
||||
" Expand:
|
||||
return "\<Esc>a\<CR>x\<CR>\<Esc>k$\"_xa"
|
||||
endfunction "}}}
|
||||
|
||||
function! DelimitMate_ExpandSpace() "{{{
|
||||
" Expand:
|
||||
return s:WriteAfter(' ') . "\<Space>"
|
||||
endfunction "}}}
|
||||
|
||||
function! s:ExtraMappings() "{{{
|
||||
" If pair is empty, delete both delimiters:
|
||||
inoremap <buffer> <expr> <BS> DelimitMate_WithinEmptyPair() ? "\<Right>\<BS>\<BS>" : "\<BS>"
|
||||
|
||||
" If pair is empty, delete closing delimiter:
|
||||
inoremap <buffer> <expr> <S-BS> DelimitMate_WithinEmptyPair() ? "\<Del>" : "\<S-BS>"
|
||||
|
||||
" Expand return if inside an empty pair:
|
||||
if b:delimitMate_expand_cr != 0
|
||||
inoremap <buffer> <expr> <CR> DelimitMate_WithinEmptyPair() ?
|
||||
\ DelimitMate_ExpandReturn() : "\<CR>"
|
||||
endif
|
||||
|
||||
" Expand space if inside an empty pair:
|
||||
if b:delimitMate_expand_space != 0
|
||||
inoremap <buffer> <expr> <Space> DelimitMate_WithinEmptyPair() ?
|
||||
\ DelimitMate_ExpandSpace() : "\<Space>"
|
||||
endif
|
||||
|
||||
" Jump out ot any empty pair:
|
||||
if b:delimitMate_tab2exit
|
||||
inoremap <buffer> <expr> <S-Tab> DelimitMate_ShouldJump() ? DelimitMate_JumpAny() : "\<S-Tab>"
|
||||
endif
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Tools: {{{
|
||||
function! s:TestMappings() "{{{
|
||||
if b:delimitMate_autoclose
|
||||
exec "normal i* AUTOCLOSE:\<CR>"
|
||||
for i in range(len(b:delimitMate_left_delims))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i]. "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . " |"
|
||||
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
|
||||
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
for i in range(len(b:delimitMate_quotes_list))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Delete: "
|
||||
exec "normal A". b:delimitMate_quotes_list[i]
|
||||
exec "normal a\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . " |"
|
||||
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
else
|
||||
exec "normal i* NO AUTOCLOSE:\<CR>"
|
||||
for i in range(len(b:delimitMate_left_delims))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . " |"
|
||||
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
|
||||
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
for i in range(len(b:delimitMate_quotes_list))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . " |"
|
||||
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
endif
|
||||
exec "normal \<Esc>i"
|
||||
endfunction "}}}
|
||||
|
||||
function! s:SwitchAutoclose() "{{{
|
||||
if !exists("g:delimitMate_autoclose")
|
||||
let g:delimitMate_autoclose = 1
|
||||
elseif g:delimitMate_autoclose == 1
|
||||
let g:delimitMate_autoclose = 0
|
||||
else
|
||||
let g:delimitMate_autoclose = 1
|
||||
endif
|
||||
DelimitMateReload
|
||||
endfunction "}}}
|
||||
|
||||
function! s:UnMap() " {{{
|
||||
" No Autoclose Mappings:
|
||||
for char in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
if maparg(char,"i") =~? 'SkipDelim'
|
||||
exec 'silent! iunmap <buffer> ' . char
|
||||
"echomsg 'iunmap <buffer> ' . char
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Autoclose Mappings:
|
||||
let i = 0
|
||||
let l = len(b:delimitMate_matchpairs_list)
|
||||
while i < l
|
||||
if maparg(b:delimitMate_left_delims[i],"i") =~? 'JumpIn'
|
||||
exec 'silent! iunmap <buffer> ' . b:delimitMate_left_delims[i]
|
||||
"echomsg 'iunmap <buffer> ' . b:delimitMate_left_delims[i]
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
for char in b:delimitMate_quotes_list
|
||||
if maparg(char, "i") =~? 'QuoteDelim'
|
||||
exec 'silent! iunmap <buffer> ' . char
|
||||
"echomsg 'iunmap <buffer> ' . char
|
||||
endif
|
||||
endfor
|
||||
for char in b:delimitMate_right_delims
|
||||
if maparg(char, "i") =~? 'JumpOut'
|
||||
exec 'silent! iunmap <buffer> ' . char
|
||||
"echomsg 'iunmap <buffer> ' . char
|
||||
endif
|
||||
endfor
|
||||
for map in b:delimitMate_apostrophes_list
|
||||
exec "silent! iunmap <buffer> " . map
|
||||
endfor
|
||||
|
||||
" Visual Mappings:
|
||||
for char in b:delimitMate_right_delims + b:delimitMate_left_delims + b:delimitMate_quotes_list
|
||||
if maparg(b:delimitMate_visual_leader . char,"v") =~? 'IsBlock'
|
||||
exec 'silent! vunmap <buffer> ' . b:delimitMate_visual_leader . char
|
||||
"echomsg 'vunmap <buffer> ' . b:delimitMate_visual_leader . char
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Expansion Mappings:
|
||||
if maparg('<BS>', "i") =~? 'WithinEmptyPair'
|
||||
silent! iunmap <buffer> <BS>
|
||||
"echomsg "silent! iunmap <buffer> <BS>"
|
||||
endif
|
||||
if maparg('<S-BS>', "i") =~? 'WithinEmptyPair'
|
||||
silent! iunmap <buffer> <BS>
|
||||
"echomsg "silent! iunmap <buffer> <BS>"
|
||||
endif
|
||||
if maparg('<CR>',"i") =~? 'DelimitMate_ExpandReturn'
|
||||
silent! iunmap <buffer> <CR>
|
||||
"echomsg "silent! iunmap <buffer> <CR>"
|
||||
endif
|
||||
if maparg('<Space>',"i") =~? 'DelimitMate_ExpandSpace'
|
||||
silent! iunmap <buffer> <Space>
|
||||
"echomsg "silent! iunmap <buffer> <Space>"
|
||||
endif
|
||||
if maparg('<S-Tab>', "i") =~? 'ShouldJump'
|
||||
silent! iunmap <buffer> <S-Tab>
|
||||
"echomsg "silent! iunmap <buffer> <S-Tab>"
|
||||
endif
|
||||
endfunction " }}} s:ExtraMappings()
|
||||
|
||||
function! s:TestMappingsDo() "{{{
|
||||
"DelimitMateReload
|
||||
if !exists("g:delimitMate_testing")
|
||||
"call s:DelimitMateDo()
|
||||
call s:TestMappings()
|
||||
else
|
||||
call s:SwitchAutoclose()
|
||||
call s:TestMappings()
|
||||
exec "normal i\<CR>"
|
||||
call s:SwitchAutoclose()
|
||||
call s:TestMappings()
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:DelimitMateDo() "{{{
|
||||
if exists("g:delimitMate_excluded_ft")
|
||||
" Check if this file type is excluded:
|
||||
for ft in split(g:delimitMate_excluded_ft,',')
|
||||
if ft ==? &filetype
|
||||
if !exists("b:delimitMate_quotes_list")
|
||||
return 1
|
||||
endif
|
||||
"echomsg "excluded"
|
||||
call s:UnMap()
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
try
|
||||
"echomsg "included"
|
||||
let save_cpo = &cpo
|
||||
set cpo&vim
|
||||
call s:Init()
|
||||
finally
|
||||
let &cpo = save_cpo
|
||||
endtry
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Commands: {{{
|
||||
call s:DelimitMateDo()
|
||||
|
||||
" Let me refresh without re-loading the buffer:
|
||||
command! DelimitMateReload call s:DelimitMateDo()
|
||||
|
||||
" Quick test:
|
||||
command! DelimitMateTest call s:TestMappingsDo()
|
||||
|
||||
" Run on file type events.
|
||||
"autocmd VimEnter * autocmd FileType * call <SID>DelimitMateDo()
|
||||
autocmd FileType * call <SID>DelimitMateDo()
|
||||
|
||||
" Run on new buffers.
|
||||
autocmd BufNewFile,BufRead,BufEnter * if !exists("b:loaded_delimitMate") | call <SID>DelimitMateDo() | endif
|
||||
|
||||
"function! s:GetSynRegion () | echo synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') | endfunction
|
||||
"}}}
|
||||
|
||||
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
|
||||
" vim:foldmethod=marker:foldcolumn=4
|
||||
1788
plugin/eclim_py.vim
Normal file
1788
plugin/eclim_py.vim
Normal file
File diff suppressed because it is too large
Load Diff
177
plugin/fuf.vim
Normal file
177
plugin/fuf.vim
Normal file
@@ -0,0 +1,177 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
" GetLatestVimScripts: 1984 1 :AutoInstall: FuzzyFinder
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_fuf')
|
||||
finish
|
||||
elseif v:version < 702
|
||||
echoerr 'FuzzyFinder does not support this version of vim (' . v:version . ').'
|
||||
finish
|
||||
endif
|
||||
let g:loaded_fuf = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function s:initialize()
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_modes' , [
|
||||
\ 'buffer', 'file', 'dir', 'mrufile', 'mrucmd',
|
||||
\ 'bookmark', 'tag', 'taggedfile',
|
||||
\ 'jumplist', 'changelist', 'quickfix', 'line', 'help',
|
||||
\ 'givenfile', 'givendir', 'givencmd',
|
||||
\ 'callbackfile', 'callbackitem',
|
||||
\ ])
|
||||
call s:defineOption('g:fuf_modesDisable' , [ 'mrufile', 'mrucmd', ])
|
||||
call s:defineOption('g:fuf_keyOpen' , '<CR>')
|
||||
call s:defineOption('g:fuf_keyOpenSplit' , '<C-j>')
|
||||
call s:defineOption('g:fuf_keyOpenVsplit' , '<C-k>')
|
||||
call s:defineOption('g:fuf_keyOpenTabpage' , '<C-l>')
|
||||
call s:defineOption('g:fuf_keyPreview' , '<C-@>')
|
||||
call s:defineOption('g:fuf_keyNextMode' , '<C-t>')
|
||||
call s:defineOption('g:fuf_keyPrevMode' , '<C-y>')
|
||||
call s:defineOption('g:fuf_keyPrevPattern' , '<C-s>')
|
||||
call s:defineOption('g:fuf_keyNextPattern' , '<C-_>')
|
||||
call s:defineOption('g:fuf_keySwitchMatching', '<C-\><C-\>')
|
||||
call s:defineOption('g:fuf_infoFile' , '~/.vim-fuf')
|
||||
call s:defineOption('g:fuf_abbrevMap' , {})
|
||||
call s:defineOption('g:fuf_patternSeparator' , ';')
|
||||
call s:defineOption('g:fuf_promptHighlight' , 'Question')
|
||||
call s:defineOption('g:fuf_ignoreCase' , 1)
|
||||
call s:defineOption('g:fuf_splitPathMatching', 1)
|
||||
call s:defineOption('g:fuf_smartBs' , 1)
|
||||
call s:defineOption('g:fuf_reuseWindow' , 1)
|
||||
call s:defineOption('g:fuf_timeFormat' , '(%Y-%m-%d %H:%M:%S)')
|
||||
call s:defineOption('g:fuf_learningLimit' , 100)
|
||||
call s:defineOption('g:fuf_enumeratingLimit' , 50)
|
||||
call s:defineOption('g:fuf_maxMenuWidth' , 78)
|
||||
call s:defineOption('g:fuf_previewHeight' , 10)
|
||||
call s:defineOption('g:fuf_useMigemo' , 0)
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_buffer_prompt' , '>Buffer[]>')
|
||||
call s:defineOption('g:fuf_buffer_switchOrder', 10)
|
||||
call s:defineOption('g:fuf_buffer_mruOrder' , 1)
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_file_prompt' , '>File[]>')
|
||||
call s:defineOption('g:fuf_file_switchOrder', 20)
|
||||
call s:defineOption('g:fuf_file_exclude' , '\v\~$|\.(o|exe|dll|bak|sw[po])$|(^|[/\\])\.(hg|git|bzr)($|[/\\])')
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_dir_prompt' , '>Dir[]>')
|
||||
call s:defineOption('g:fuf_dir_switchOrder', 30)
|
||||
call s:defineOption('g:fuf_dir_exclude' , '\v(^|[/\\])\.(hg|git|bzr)($|[/\\])')
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_mrufile_prompt' , '>Mru-File[]>')
|
||||
call s:defineOption('g:fuf_mrufile_switchOrder', 40)
|
||||
call s:defineOption('g:fuf_mrufile_exclude' , '\v\~$|\.(bak|sw[po])$|^(\/\/|\\\\|\/mnt\/|\/media\/)')
|
||||
call s:defineOption('g:fuf_mrufile_maxItem' , 200)
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_mrucmd_prompt' , '>Mru-Cmd[]>')
|
||||
call s:defineOption('g:fuf_mrucmd_switchOrder', 50)
|
||||
call s:defineOption('g:fuf_mrucmd_exclude' , '^$')
|
||||
call s:defineOption('g:fuf_mrucmd_maxItem' , 200)
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_bookmark_prompt' , '>Bookmark[]>')
|
||||
call s:defineOption('g:fuf_bookmark_switchOrder', 60)
|
||||
call s:defineOption('g:fuf_bookmark_searchRange', 400)
|
||||
call s:defineOption('g:fuf_bookmark_keyDelete' , '<C-]>')
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_tag_prompt' , '>Tag[]>')
|
||||
call s:defineOption('g:fuf_tag_switchOrder', 70)
|
||||
call s:defineOption('g:fuf_tag_cache_dir' , '~/.vim-fuf-cache/tag')
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_taggedfile_prompt' , '>Tagged-File[]>')
|
||||
call s:defineOption('g:fuf_taggedfile_switchOrder', 80)
|
||||
call s:defineOption('g:fuf_taggedfile_cache_dir' , '~/.vim-fuf-cache/taggedfile')
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_jumplist_prompt' , '>Jump-List[]>')
|
||||
call s:defineOption('g:fuf_jumplist_switchOrder', 90)
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_changelist_prompt' , '>Change-List[]>')
|
||||
call s:defineOption('g:fuf_changelist_switchOrder', 100)
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_quickfix_prompt' , '>Quickfix[]>')
|
||||
call s:defineOption('g:fuf_quickfix_switchOrder', 110)
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_line_prompt' , '>Line[]>')
|
||||
call s:defineOption('g:fuf_line_switchOrder', 120)
|
||||
"---------------------------------------------------------------------------
|
||||
call s:defineOption('g:fuf_help_prompt' , '>Help[]>')
|
||||
call s:defineOption('g:fuf_help_switchOrder', 130)
|
||||
call s:defineOption('g:fuf_help_cache_dir' , '~/.vim-fuf-cache/help')
|
||||
"---------------------------------------------------------------------------
|
||||
call filter(g:fuf_modes, 'count(g:fuf_modesDisable, v:val) == 0')
|
||||
for m in g:fuf_modes
|
||||
call fuf#{m}#renewCache()
|
||||
call fuf#{m}#onInit()
|
||||
endfor
|
||||
"---------------------------------------------------------------------------
|
||||
command! -bang -narg=0 FufEditInfo call fuf#editInfoFile()
|
||||
command! -bang -narg=0 FufRenewCache call s:renewCachesOfAllModes()
|
||||
"---------------------------------------------------------------------------
|
||||
for m in g:fuf_modes
|
||||
if fuf#{m}#requiresOnCommandPre()
|
||||
" cnoremap has a problem, which doesn't expand cabbrev.
|
||||
cmap <silent> <expr> <CR> <SID>onCommandPre()
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
"---------------------------------------------------------------------------
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:initMisc()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:defineOption(name, default)
|
||||
if !exists(a:name)
|
||||
let {a:name} = a:default
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:renewCachesOfAllModes()
|
||||
for m in g:fuf_modes
|
||||
call fuf#{m}#renewCache()
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:onBufEnter()
|
||||
for m in g:fuf_modes
|
||||
call fuf#{m}#onBufEnter()
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:onBufWritePost()
|
||||
for m in g:fuf_modes
|
||||
call fuf#{m}#onBufWritePost()
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:onCommandPre()
|
||||
for m in filter(copy(g:fuf_modes), 'fuf#{v:val}#requiresOnCommandPre()')
|
||||
call fuf#{m}#onCommandPre(getcmdtype() . getcmdline())
|
||||
endfor
|
||||
" lets last entry become the newest in the history
|
||||
call histadd(getcmdtype(), getcmdline())
|
||||
" this is not mapped again (:help recursive_mapping)
|
||||
return "\<CR>"
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" INITIALIZATION {{{1
|
||||
|
||||
call s:initialize()
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
38
plugin/getscriptPlugin.vim
Normal file
38
plugin/getscriptPlugin.vim
Normal file
@@ -0,0 +1,38 @@
|
||||
" ---------------------------------------------------------------------
|
||||
" getscriptPlugin.vim
|
||||
" Author: Charles E. Campbell, Jr.
|
||||
" Date: Jan 07, 2008
|
||||
" Installing: :help glvs-install
|
||||
" Usage: :help glvs
|
||||
"
|
||||
" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
|
||||
"
|
||||
" (Rom 15:11 WEB) Again, "Praise the Lord, all you Gentiles! Let
|
||||
" all the peoples praise Him."
|
||||
" ---------------------------------------------------------------------
|
||||
" Initialization: {{{1
|
||||
" if you're sourcing this file, surely you can't be
|
||||
" expecting vim to be in its vi-compatible mode
|
||||
if &cp || exists("g:loaded_getscriptPlugin")
|
||||
if &verbose
|
||||
echo "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
|
||||
endif
|
||||
finish
|
||||
endif
|
||||
let g:loaded_getscriptPlugin = "v29"
|
||||
let s:keepcpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" Public Interface: {{{1
|
||||
com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
|
||||
com! -nargs=0 GetScripts call getscript#GetLatestVimScripts()
|
||||
silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts()
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" Restore Options: {{{1
|
||||
let &cpo= s:keepcpo
|
||||
unlet s:keepcpo
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" vim: ts=8 sts=2 fdm=marker nowrap
|
||||
854
plugin/grep.vim
Normal file
854
plugin/grep.vim
Normal file
@@ -0,0 +1,854 @@
|
||||
" File: grep.vim
|
||||
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
|
||||
" Version: 1.9
|
||||
" Last Modified: September 10, 2007
|
||||
"
|
||||
" Overview
|
||||
" --------
|
||||
" The grep plugin integrates the grep, fgrep, egrep, and agrep tools with
|
||||
" Vim and allows you to search for a pattern in one or more files and jump
|
||||
" to them.
|
||||
"
|
||||
" To use this plugin, you need the grep, fgrep, egrep, agrep, find and
|
||||
" xargs utilities. These tools are present in most of the Unix installations.
|
||||
" For MS-Windows systems, you can download the GNU grep and find utilities
|
||||
" from the following sites:
|
||||
"
|
||||
" http://gnuwin32.sourceforge.net/packages/grep.htm
|
||||
" http://gnuwin32.sourceforge.net/packages/findutils.htm
|
||||
"
|
||||
" Installation
|
||||
" ------------
|
||||
" 1. Copy the grep.vim file to the $HOME/.vim/plugin or $HOME/vimfiles/plugin
|
||||
" or $VIM/vimfiles/plugin directory.
|
||||
" Refer to the following Vim help topics for more information about Vim
|
||||
" plugins:
|
||||
" :help add-plugin
|
||||
" :help add-global-plugin
|
||||
" :help runtimepath
|
||||
" 2. If the grep executables are not already present in one of the directories
|
||||
" in the PATH environment variable, then set the Grep_Path and other _Path
|
||||
" variables to point to the location of the grep utilites in the .vimrc
|
||||
" file.
|
||||
" 3. Restart Vim.
|
||||
" 4. You can now use the ":Grep" and other commands to search for patterns in
|
||||
" files.
|
||||
"
|
||||
" Usage
|
||||
" -----
|
||||
" The grep.vim plugin introduces the following Vim commands:
|
||||
"
|
||||
" :Grep - Search for the specified pattern in the specified files
|
||||
" :GrepAdd - Same as ":Grep" but adds the results to the current results
|
||||
" :Rgrep - Run recursive grep
|
||||
" :RgrepAdd - Same as ":Rgrep" but adds the results to the current results
|
||||
" :GrepBuffer - Search for a pattern on all open buffers
|
||||
" :GrepBufferAdd - Same as ":GrepBuffer" but adds the results to the current
|
||||
" results
|
||||
" :Bgrep - Same as :GrepBuffer
|
||||
" :BgrepAdd - Same as :GrepBufferAdd
|
||||
" :GrepArgs - Search for a pattern on all the Vim argument
|
||||
" filenames (:args)
|
||||
" :GrepArgsAdd - Same as ":GrepArgs" but adds the results to the current
|
||||
" results
|
||||
" :Fgrep - Run fgrep
|
||||
" :FgrepAdd - Same as ":Fgrep" but adds the results to the current
|
||||
" results
|
||||
" :Rfgrep - Run recursive fgrep
|
||||
" :RfgrepAdd - Same as ":Rfgrep" but adds the results to the current
|
||||
" results
|
||||
" :Egrep - Run egrep
|
||||
" :EgrepAdd - Same as ":Egrep" but adds the results to the current
|
||||
" results
|
||||
" :Regrep - Run recursive egrep
|
||||
" :RegrepAdd - Same as ":Regrep" but adds the results to the current
|
||||
" results
|
||||
" :Agrep - Run agrep
|
||||
" :AgrepAdd - Same as ":Agrep" but adds the results to the current
|
||||
" results
|
||||
" :Ragrep - Run recursive agrep
|
||||
" :RagrepAdd - Same as ":Ragrep" but adds the results to the current
|
||||
" results
|
||||
"
|
||||
" The above commands can be invoked like this:
|
||||
"
|
||||
" :Grep [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :Rgrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :Fgrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :Rfgrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :Egrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :Regrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :Agrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :Ragrep [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
"
|
||||
" :GrepAdd [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :RgrepAdd [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :FgrepAdd [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :RfgrepAdd [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :EgrepAdd [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :RegrepAdd [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :AgrepAdd [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
" :RagrepAdd [<grep_options>] [<search_pattern> [<file_name(s)>]]
|
||||
"
|
||||
" :GrepBuffer [<grep_options>] [<search_pattern>]
|
||||
" :Bgrep [<grep_options>] [<search_pattern>]
|
||||
" :GrepArgs [<grep_options>] [<search_pattern>]
|
||||
"
|
||||
" :GrepBufferAdd [<grep_options>] [<search_pattern>]
|
||||
" :BgrepAdd [<grep_options>] [<search_pattern>]
|
||||
" :GrepArgsAdd [<grep_options>] [<search_pattern>]
|
||||
"
|
||||
" In the above commands, all the arguments are optional.
|
||||
"
|
||||
" You can specify grep options like -i (ignore case) or -w (search for a word)
|
||||
" to the above commands. If the <grep_options> are not specified, then the
|
||||
" default grep options specified by the variable Grep_Default_Options is
|
||||
" used.
|
||||
"
|
||||
" You can specify the grep pattern to search as an argument to the above
|
||||
" commands. If the <search_pattern> is not specified, then you will be
|
||||
" prompted to enter a search pattern. By default, the keyword under the cursor
|
||||
" is displayed for the search pattern prompt. You can accept the default or
|
||||
" modify it.
|
||||
"
|
||||
" The search pattern is automatically enclosed by the character specified in
|
||||
" the Grep_Shell_Quote_Char variable. You should not enclose the search
|
||||
" pattern with a shell escape character.
|
||||
"
|
||||
" If you want to specify a search pattern with space characters or a
|
||||
" multi-word pattern, then you should use the Grep command pattern input
|
||||
" prompt to supply the pattern.
|
||||
"
|
||||
" You can specify one or more file names (or file patterns) to the above
|
||||
" commands. If the <file_names> are not specified, then you will be prompted
|
||||
" to enter file names. By default, the pattern specified by the
|
||||
" Grep_Default_Filelist variable is used. To specify the file name(s) as an
|
||||
" argument to the above commands, you have to specify the search pattern also.
|
||||
"
|
||||
" When you enter only the command name, you will be prompted to enter the
|
||||
" search pattern and the files in which to search for the pattern. By default,
|
||||
" the keyword under the cursor is displayed for the search pattern prompt.
|
||||
" Depending on the command, you may prompted for additional parameters like
|
||||
" the directories to search for the pattern.
|
||||
"
|
||||
" You can retrieve previously entered values for the Grep prompts using the up
|
||||
" and down arrow keys. You can cancel the command by pressing the escape key.
|
||||
" You can use CTRL-U to erase the default shown for the prompt and CTRL-W to
|
||||
" erase the previous word in the prompt. For more information about editing
|
||||
" the prompt, read ':help cmdline-editing' Vim help topic.
|
||||
"
|
||||
" After invoking any of the grep commands, you can cancel the command, when
|
||||
" you are prompted for a search pattern or file names or a directory by
|
||||
" pressing the <Esc> key. You cannot cancel (or kill) the
|
||||
" grep/fgrep/egrep/agrep commands after the external command is invoked.
|
||||
"
|
||||
" The GrepAdd, RgrepAdd and other *Add commands append the search output to
|
||||
" the current search output. This is useful if you want to see the search
|
||||
" results for multiple patterns at the same time. These commands are available
|
||||
" only in Vim version 7.0 and above.
|
||||
"
|
||||
" You can map a key to invoke any of the above commands. For example, the
|
||||
" following map invokes the :Grep command to search for the keyword under the
|
||||
" cursor:
|
||||
"
|
||||
" nnoremap <silent> <F3> :Grep<CR>
|
||||
"
|
||||
" The output of the grep command will be listed in the Vim quickfix window.
|
||||
" 1. You can select a line in the quickfix window and press <Enter> or double
|
||||
" click on a match to jump to that line.
|
||||
" 2. You can use the ":cnext" and ":cprev" commands to the jump to the next or
|
||||
" previous output line.
|
||||
" 3. You can use the ":colder" and ":cnewer" commands to go between multiple
|
||||
" grep quickfix output windows.
|
||||
" 4. The quickfix window need not be opened always to use the grep output.
|
||||
" You can close the quickfix window and use the quickfix commands to jump
|
||||
" to the grep matches. Use the ":copen" command to open the quickfix
|
||||
" window again.
|
||||
"
|
||||
" For more information about other quickfix commands read ":help quickfix"
|
||||
"
|
||||
" When using GUI Vim, the Tools->Search menu item with a few sub-menu items is
|
||||
" created for few variations of the search command.
|
||||
"
|
||||
" Configuration
|
||||
" -------------
|
||||
" By changing the following variables you can configure the behavior of this
|
||||
" plugin. Set the following variables in your .vimrc file using the 'let'
|
||||
" command.
|
||||
"
|
||||
" The 'Grep_Path' variable is used to locate the grep utility. By default,
|
||||
" this is set to grep. You can change this using the let command:
|
||||
"
|
||||
" :let Grep_Path = 'd:\tools\grep.exe'
|
||||
"
|
||||
" The 'Fgrep_Path' variable is used to locate the fgrep utility. By default,
|
||||
" this is set to fgrep. You can change this using the let command:
|
||||
"
|
||||
" :let Fgrep_Path = 'd:\tools\fgrep.exe'
|
||||
"
|
||||
" The 'Egrep_Path' variable is used to locate the egrep utility. By default,
|
||||
" this is set to egrep. You can change this using the let command:
|
||||
"
|
||||
" :let Egrep_Path = 'd:\tools\egrep.exe'
|
||||
"
|
||||
" The 'Agrep_Path' variable is used to locate the agrep utility. By default,
|
||||
" this is set to agrep. You can change this using the let command:
|
||||
"
|
||||
" :let Agrep_Path = 'd:\tools\agrep.exe'
|
||||
"
|
||||
" The 'Grep_Find_Path' variable is used to locate the find utility. By
|
||||
" default, this is set to d:\tools\find.exe. You can change this using the let
|
||||
" command:
|
||||
"
|
||||
" :let Grep_Find_Path = 'd:\tools\find.exe'
|
||||
"
|
||||
" The 'Grep_Xargs_Path' variable is used to locate the xargs utility. By
|
||||
" default, this is set to xargs. You can change this using the let
|
||||
" command:
|
||||
"
|
||||
" :let Grep_Xargs_Path = 'd:\tools\xargs.exe'
|
||||
"
|
||||
" When running any one of the Grep commands, you will be prompted for the
|
||||
" files in which to search for the pattern. The 'Grep_Default_Filelist'
|
||||
" variable is used to specify to default for this prompt. By default, this
|
||||
" variable is set to '*'. You can specify multiple matching patterns separated
|
||||
" by spaces. You can change this settings using the let command:
|
||||
"
|
||||
" :let Grep_Default_Filelist = '*.[chS]'
|
||||
" :let Grep_Default_Filelist = '*.c *.cpp *.asm'
|
||||
"
|
||||
" The 'Grep_Default_Options' is used to pass default command line options to
|
||||
" the grep/fgrep/egrep/agrep utilities. By default, this is set to an empty
|
||||
" string. You can change this using the let command:
|
||||
"
|
||||
" :let Grep_Default_Options = '-i'
|
||||
"
|
||||
" The 'Grep_Skip_Dirs' variable specifies the list of directories to skip
|
||||
" while doing recursive searches. By default, this is set to 'RCS CVS SCCS'.
|
||||
" You can change this using the let command:
|
||||
"
|
||||
" :let Grep_Skip_Dirs = 'dir1 dir2 dir3'
|
||||
"
|
||||
" The 'Grep_Skip_Files' variable specifies the list of files to skip while
|
||||
" doing recursive searches. By default, this is set to '*~ *,v s.*'. You can
|
||||
" change this using the let command:
|
||||
"
|
||||
" :let Grep_Skip_Files = '*.bak *~'
|
||||
"
|
||||
" By default, when you invoke the Grep commands the quickfix window will be
|
||||
" opened with the grep output. You can disable opening the quickfix window,
|
||||
" by setting the 'Grep_OpenQuickfixWindow' variable to zero:
|
||||
"
|
||||
" :let Grep_OpenQuickfixWindow = 0
|
||||
"
|
||||
" You can manually open the quickfix window using the :cwindow command.
|
||||
"
|
||||
" By default, for recursive searches, the 'find' and 'xargs' utilities are
|
||||
" used. If you don't have the 'xargs' utility or don't want to use the
|
||||
" 'xargs' utility, " then you can set the 'Grep_Find_Use_Xargs' variable to
|
||||
" zero. If this is set to zero, then only the 'find' utility is used for
|
||||
" recursive searches:
|
||||
"
|
||||
" :let Grep_Find_Use_Xargs = 0
|
||||
"
|
||||
" To handle file names with space characters in them, the xargs utility
|
||||
" is invoked with the '--null' argument. If the xargs utility in your system
|
||||
" doesn't accept the '--null' argument, then you can change the
|
||||
" Grep_Xargs_Options variable. For example, to use the '--print0' xargs
|
||||
" argument, you can use the following command:
|
||||
"
|
||||
" :let Grep_Xargs_Options = '--print0'
|
||||
"
|
||||
" The Grep_Cygwin_Find variable should be set to 1, if you are using the find
|
||||
" utility from the cygwin package. This setting is used to handle the
|
||||
" difference between the backslash and forward slash path separators.
|
||||
"
|
||||
" :let Grep_Cygwin_Find = 1
|
||||
"
|
||||
" The 'Grep_Null_Device' variable specifies the name of the null device to
|
||||
" pass to the grep commands. This is needed to force the grep commands to
|
||||
" print the name of the file in which a match is found, if only one filename
|
||||
" is specified. For Unix systems, this is set to /dev/null and for MS-Windows
|
||||
" systems, this is set to NUL. You can modify this by using the let command:
|
||||
"
|
||||
" :let Grep_Null_Device = '/dev/null'
|
||||
"
|
||||
" The 'Grep_Shell_Quote_Char' variable specifies the quote character to use
|
||||
" for protecting patterns from being interpreted by the shell. For Unix
|
||||
" systems, this is set to "'" and for MS-Window systems, this is set to an
|
||||
" empty string. You can change this using the let command:
|
||||
"
|
||||
" :let Grep_Shell_Quote_Char = "'"
|
||||
"
|
||||
" The 'Grep_Shell_Escape_Char' variable specifies the escape character to use
|
||||
" for protecting special characters from being interpreted by the shell. For
|
||||
" Unix systems, this is set to '\' and for MS-Window systems, this is set to
|
||||
" an empty string. You can change this using the let command:
|
||||
"
|
||||
" :let Grep_Shell_Escape_Char = "'"
|
||||
"
|
||||
" --------------------- Do not modify after this line ---------------------
|
||||
if exists("loaded_grep")
|
||||
finish
|
||||
endif
|
||||
let loaded_grep = 1
|
||||
|
||||
" Line continuation used here
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Location of the grep utility
|
||||
if !exists("Grep_Path")
|
||||
let Grep_Path = 'grep'
|
||||
endif
|
||||
|
||||
" Location of the fgrep utility
|
||||
if !exists("Fgrep_Path")
|
||||
let Fgrep_Path = 'fgrep'
|
||||
endif
|
||||
|
||||
" Location of the egrep utility
|
||||
if !exists("Egrep_Path")
|
||||
let Egrep_Path = 'egrep'
|
||||
endif
|
||||
|
||||
" Location of the agrep utility
|
||||
if !exists("Agrep_Path")
|
||||
let Agrep_Path = 'agrep'
|
||||
endif
|
||||
|
||||
" Location of the find utility
|
||||
if !exists("Grep_Find_Path")
|
||||
let Grep_Find_Path = 'find'
|
||||
endif
|
||||
|
||||
" Location of the xargs utility
|
||||
if !exists("Grep_Xargs_Path")
|
||||
let Grep_Xargs_Path = 'xargs'
|
||||
endif
|
||||
|
||||
" Open the Grep output window. Set this variable to zero, to not open
|
||||
" the Grep output window by default. You can open it manually by using
|
||||
" the :cwindow command.
|
||||
if !exists("Grep_OpenQuickfixWindow")
|
||||
let Grep_OpenQuickfixWindow = 1
|
||||
endif
|
||||
|
||||
" Default grep file list
|
||||
if !exists("Grep_Default_Filelist")
|
||||
let Grep_Default_Filelist = '*'
|
||||
endif
|
||||
|
||||
" Default grep options
|
||||
if !exists("Grep_Default_Options")
|
||||
let Grep_Default_Options = ''
|
||||
endif
|
||||
|
||||
" Use the 'xargs' utility in combination with the 'find' utility. Set this
|
||||
" to zero to not use the xargs utility.
|
||||
if !exists("Grep_Find_Use_Xargs")
|
||||
let Grep_Find_Use_Xargs = 1
|
||||
endif
|
||||
|
||||
" The command-line arguments to supply to the xargs utility
|
||||
if !exists('Grep_Xargs_Options')
|
||||
let Grep_Xargs_Options = '--null'
|
||||
endif
|
||||
|
||||
" The find utility is from the cygwin package or some other find utility.
|
||||
if !exists("Grep_Cygwin_Find")
|
||||
let Grep_Cygwin_Find = 0
|
||||
endif
|
||||
|
||||
" NULL device name to supply to grep. We need this because, grep will not
|
||||
" print the name of the file, if only one filename is supplied. We need the
|
||||
" filename for Vim quickfix processing.
|
||||
if !exists("Grep_Null_Device")
|
||||
if has("win32") || has("win16") || has("win95")
|
||||
let Grep_Null_Device = 'NUL'
|
||||
else
|
||||
let Grep_Null_Device = '/dev/null'
|
||||
endif
|
||||
endif
|
||||
|
||||
" Character to use to quote patterns and filenames before passing to grep.
|
||||
if !exists("Grep_Shell_Quote_Char")
|
||||
if has("win32") || has("win16") || has("win95")
|
||||
let Grep_Shell_Quote_Char = ''
|
||||
else
|
||||
let Grep_Shell_Quote_Char = "'"
|
||||
endif
|
||||
endif
|
||||
|
||||
" Character to use to escape special characters before passing to grep.
|
||||
if !exists("Grep_Shell_Escape_Char")
|
||||
if has("win32") || has("win16") || has("win95")
|
||||
let Grep_Shell_Escape_Char = ''
|
||||
else
|
||||
let Grep_Shell_Escape_Char = '\'
|
||||
endif
|
||||
endif
|
||||
|
||||
" The list of directories to skip while searching for a pattern. Set this
|
||||
" variable to '', if you don't want to skip directories.
|
||||
if !exists("Grep_Skip_Dirs")
|
||||
let Grep_Skip_Dirs = 'RCS CVS SCCS'
|
||||
endif
|
||||
|
||||
" The list of files to skip while searching for a pattern. Set this variable
|
||||
" to '', if you don't want to skip any files.
|
||||
if !exists("Grep_Skip_Files")
|
||||
let Grep_Skip_Files = '*~ *,v s.*'
|
||||
endif
|
||||
|
||||
" RunGrepCmd()
|
||||
" Run the specified grep command using the supplied pattern
|
||||
function! s:RunGrepCmd(cmd, pattern, action)
|
||||
let cmd_output = system(a:cmd)
|
||||
|
||||
if cmd_output == ""
|
||||
echohl WarningMsg |
|
||||
\ echomsg "Error: Pattern " . a:pattern . " not found" |
|
||||
\ echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let tmpfile = tempname()
|
||||
|
||||
let old_verbose = &verbose
|
||||
set verbose&vim
|
||||
|
||||
exe "redir! > " . tmpfile
|
||||
silent echon '[Search results for pattern: ' . a:pattern . "]\n"
|
||||
silent echon cmd_output
|
||||
redir END
|
||||
|
||||
let &verbose = old_verbose
|
||||
|
||||
let old_efm = &efm
|
||||
set efm=%f:%\\s%#%l:%m
|
||||
|
||||
if v:version >= 700 && a:action == 'add'
|
||||
execute "silent! caddfile " . tmpfile
|
||||
else
|
||||
if exists(":cgetfile")
|
||||
execute "silent! cgetfile " . tmpfile
|
||||
else
|
||||
execute "silent! cfile " . tmpfile
|
||||
endif
|
||||
endif
|
||||
|
||||
let &efm = old_efm
|
||||
|
||||
" Open the grep output window
|
||||
if g:Grep_OpenQuickfixWindow == 1
|
||||
" Open the quickfix window below the current window
|
||||
botright copen
|
||||
endif
|
||||
|
||||
call delete(tmpfile)
|
||||
endfunction
|
||||
|
||||
" RunGrepRecursive()
|
||||
" Run specified grep command recursively
|
||||
function! s:RunGrepRecursive(cmd_name, grep_cmd, action, ...)
|
||||
if a:0 > 0 && (a:1 == "-?" || a:1 == "-h")
|
||||
echo 'Usage: ' . a:cmd_name . " [<grep_options>] [<search_pattern> " .
|
||||
\ "[<file_name(s)>]]"
|
||||
return
|
||||
endif
|
||||
|
||||
let grep_opt = ""
|
||||
let pattern = ""
|
||||
let filepattern = ""
|
||||
|
||||
let argcnt = 1
|
||||
while argcnt <= a:0
|
||||
if a:{argcnt} =~ '^-'
|
||||
let grep_opt = grep_opt . " " . a:{argcnt}
|
||||
elseif pattern == ""
|
||||
let pattern = g:Grep_Shell_Quote_Char . a:{argcnt} .
|
||||
\ g:Grep_Shell_Quote_Char
|
||||
else
|
||||
let filepattern = filepattern . " " . a:{argcnt}
|
||||
endif
|
||||
let argcnt= argcnt + 1
|
||||
endwhile
|
||||
if grep_opt == ""
|
||||
let grep_opt = g:Grep_Default_Options
|
||||
endif
|
||||
|
||||
if a:grep_cmd != 'agrep'
|
||||
" Don't display messages about non-existent files
|
||||
" Agrep doesn't support the -s option
|
||||
let grep_opt = grep_opt . " -s"
|
||||
endif
|
||||
|
||||
if a:grep_cmd == 'grep'
|
||||
let grep_path = g:Grep_Path
|
||||
let grep_expr_option = '--'
|
||||
elseif a:grep_cmd == 'fgrep'
|
||||
let grep_path = g:Fgrep_Path
|
||||
let grep_expr_option = '-e'
|
||||
elseif a:grep_cmd == 'egrep'
|
||||
let grep_path = g:Egrep_Path
|
||||
let grep_expr_option = '-e'
|
||||
elseif a:grep_cmd == 'agrep'
|
||||
let grep_path = g:Agrep_Path
|
||||
let grep_expr_option = ''
|
||||
else
|
||||
return
|
||||
endif
|
||||
|
||||
" No argument supplied. Get the identifier and file list from user
|
||||
if pattern == ""
|
||||
let pattern = input("Search for pattern: ", expand("<cword>"))
|
||||
if pattern == ""
|
||||
return
|
||||
endif
|
||||
let pattern = g:Grep_Shell_Quote_Char . pattern .
|
||||
\ g:Grep_Shell_Quote_Char
|
||||
endif
|
||||
|
||||
let cwd = getcwd()
|
||||
if g:Grep_Cygwin_Find == 1
|
||||
let cwd = substitute(cwd, "\\", "/", "g")
|
||||
endif
|
||||
if v:version >= 700
|
||||
let startdir = input("Start searching from directory: ", cwd, "dir")
|
||||
else
|
||||
let startdir = input("Start searching from directory: ", cwd)
|
||||
endif
|
||||
if startdir == ""
|
||||
return
|
||||
endif
|
||||
|
||||
if filepattern == ""
|
||||
let filepattern = input("Search in files matching pattern: ",
|
||||
\ g:Grep_Default_Filelist)
|
||||
if filepattern == ""
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
let txt = filepattern . ' '
|
||||
let find_file_pattern = ''
|
||||
while txt != ''
|
||||
let one_pattern = strpart(txt, 0, stridx(txt, ' '))
|
||||
if find_file_pattern != ''
|
||||
let find_file_pattern = find_file_pattern . ' -o'
|
||||
endif
|
||||
let find_file_pattern = find_file_pattern . ' -name ' .
|
||||
\ g:Grep_Shell_Quote_Char . one_pattern . g:Grep_Shell_Quote_Char
|
||||
let txt = strpart(txt, stridx(txt, ' ') + 1)
|
||||
endwhile
|
||||
let find_file_pattern = g:Grep_Shell_Escape_Char . '(' .
|
||||
\ find_file_pattern . ' ' . g:Grep_Shell_Escape_Char . ')'
|
||||
|
||||
let txt = g:Grep_Skip_Dirs
|
||||
let find_prune = ''
|
||||
if txt != ''
|
||||
let txt = txt . ' '
|
||||
while txt != ''
|
||||
let one_dir = strpart(txt, 0, stridx(txt, ' '))
|
||||
if find_prune != ''
|
||||
let find_prune = find_prune . ' -o'
|
||||
endif
|
||||
let find_prune = find_prune . ' -name ' . one_dir
|
||||
let txt = strpart(txt, stridx(txt, ' ') + 1)
|
||||
endwhile
|
||||
let find_prune = '-type d ' . g:Grep_Shell_Escape_Char . '(' .
|
||||
\ find_prune
|
||||
let find_prune = find_prune . ' ' . g:Grep_Shell_Escape_Char . ')'
|
||||
endif
|
||||
|
||||
let txt = g:Grep_Skip_Files
|
||||
let find_skip_files = '-type f'
|
||||
if txt != ''
|
||||
let txt = txt . ' '
|
||||
while txt != ''
|
||||
let one_file = strpart(txt, 0, stridx(txt, ' '))
|
||||
let find_skip_files = find_skip_files . ' ! -name ' .
|
||||
\ g:Grep_Shell_Quote_Char . one_file .
|
||||
\ g:Grep_Shell_Quote_Char
|
||||
let txt = strpart(txt, stridx(txt, ' ') + 1)
|
||||
endwhile
|
||||
endif
|
||||
|
||||
if g:Grep_Find_Use_Xargs == 1
|
||||
let cmd = g:Grep_Find_Path . " " . startdir
|
||||
let cmd = cmd . " " . find_prune . " -prune -o"
|
||||
let cmd = cmd . " " . find_skip_files
|
||||
let cmd = cmd . " " . find_file_pattern
|
||||
let cmd = cmd . " -print0 | "
|
||||
let cmd = cmd . g:Grep_Xargs_Path . ' ' . g:Grep_Xargs_Options
|
||||
let cmd = cmd . ' ' . grep_path . " " . grep_opt . " -n "
|
||||
let cmd = cmd . grep_expr_option . " " . pattern
|
||||
let cmd = cmd . ' ' . g:Grep_Null_Device
|
||||
else
|
||||
let cmd = g:Grep_Find_Path . " " . startdir
|
||||
let cmd = cmd . " " . find_prune . " -prune -o"
|
||||
let cmd = cmd . " " . find_skip_files
|
||||
let cmd = cmd . " " . find_file_pattern
|
||||
let cmd = cmd . " -exec " . grep_path . " " . grep_opt . " -n "
|
||||
let cmd = cmd . grep_expr_option . " " . pattern
|
||||
let cmd = cmd . " {} " . g:Grep_Null_Device . ' ' .
|
||||
\ g:Grep_Shell_Escape_Char . ';'
|
||||
endif
|
||||
|
||||
call s:RunGrepCmd(cmd, pattern, a:action)
|
||||
endfunction
|
||||
|
||||
" RunGrepSpecial()
|
||||
" Search for a pattern in all the opened buffers or filenames in the
|
||||
" argument list
|
||||
function! s:RunGrepSpecial(cmd_name, which, action, ...)
|
||||
if a:0 > 0 && (a:1 == "-?" || a:1 == "-h")
|
||||
echo 'Usage: ' . a:cmd_name . " [<grep_options>] [<search_pattern>]"
|
||||
return
|
||||
endif
|
||||
|
||||
" Search in all the Vim buffers
|
||||
if a:which == 'buffer'
|
||||
" Get a list of all the buffer names
|
||||
let last_bufno = bufnr("$")
|
||||
|
||||
let i = 1
|
||||
let filenames = ""
|
||||
|
||||
while i <= last_bufno
|
||||
if bufexists(i) && buflisted(i)
|
||||
let filenames = filenames . " " . bufname(i)
|
||||
endif
|
||||
let i = i + 1
|
||||
endwhile
|
||||
|
||||
" No buffers
|
||||
if filenames == ""
|
||||
return
|
||||
endif
|
||||
elseif a:which == 'args'
|
||||
" Search in all the filenames in the argument list
|
||||
let arg_cnt = argc()
|
||||
|
||||
if arg_cnt == 0
|
||||
echohl WarningMsg
|
||||
echomsg "Error: Argument list is empty"
|
||||
echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let i = 0
|
||||
let filenames = ""
|
||||
|
||||
while i < arg_cnt
|
||||
let filenames = filenames . " " . argv(i)
|
||||
let i = i + 1
|
||||
endwhile
|
||||
|
||||
" No arguments
|
||||
if filenames == ""
|
||||
echohl WarningMsg
|
||||
echomsg "Error: Argument list is empty"
|
||||
echohl None
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
let grep_opt = ""
|
||||
let pattern = ""
|
||||
|
||||
" Get the list of optional grep command-line options (if present)
|
||||
" supplied by the user. All the grep options will be preceded
|
||||
" by a '-'
|
||||
let argcnt= 1
|
||||
while argcnt <= a:0 && a:{argcnt} =~ '^-'
|
||||
let grep_opt = grep_opt . " " . a:{argcnt}
|
||||
let argcnt = argcnt + 1
|
||||
endwhile
|
||||
|
||||
" If the user didn't specify the option, then use the defaults
|
||||
if grep_opt == ""
|
||||
let grep_opt = g:Grep_Default_Options
|
||||
endif
|
||||
|
||||
" Don't display messages about non-existent files
|
||||
let grep_opt = grep_opt . " -s"
|
||||
|
||||
" The last argument specified by the user is the pattern
|
||||
if argcnt == a:0
|
||||
let pattern = a:{argcnt}
|
||||
else
|
||||
" No argument supplied. Get the identifier and file list from user
|
||||
let pattern = input("Search for pattern: ", expand("<cword>"))
|
||||
if pattern == ""
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
let pattern = g:Grep_Shell_Quote_Char . pattern . g:Grep_Shell_Quote_Char
|
||||
|
||||
" Add /dev/null to the list of filenames, so that grep print the
|
||||
" filename and linenumber when grepping in a single file
|
||||
let filenames = filenames . " " . g:Grep_Null_Device
|
||||
let cmd = g:Grep_Path . " " . grep_opt . " -n -- "
|
||||
let cmd = cmd . pattern . " " . filenames
|
||||
|
||||
call s:RunGrepCmd(cmd, pattern, a:action)
|
||||
endfunction
|
||||
|
||||
" RunGrep()
|
||||
" Run the specified grep command
|
||||
function! s:RunGrep(cmd_name, grep_cmd, action, ...)
|
||||
if a:0 > 0 && (a:1 == "-?" || a:1 == "-h")
|
||||
echo 'Usage: ' . a:cmd_name . " [<grep_options>] [<search_pattern> " .
|
||||
\ "[<file_name(s)>]]"
|
||||
return
|
||||
endif
|
||||
|
||||
let grep_opt = ""
|
||||
let pattern = ""
|
||||
let filenames = ""
|
||||
|
||||
" Parse the arguments
|
||||
" grep command-line flags are specified using the "-flag" format
|
||||
" the next argument is assumed to be the pattern
|
||||
" and the next arguments are assumed to be filenames or file patterns
|
||||
let argcnt = 1
|
||||
while argcnt <= a:0
|
||||
if a:{argcnt} =~ '^-'
|
||||
let grep_opt = grep_opt . " " . a:{argcnt}
|
||||
elseif pattern == ""
|
||||
let pattern = g:Grep_Shell_Quote_Char . a:{argcnt} .
|
||||
\ g:Grep_Shell_Quote_Char
|
||||
else
|
||||
let filenames= filenames . " " . a:{argcnt}
|
||||
endif
|
||||
let argcnt = argcnt + 1
|
||||
endwhile
|
||||
|
||||
if grep_opt == ""
|
||||
let grep_opt = g:Grep_Default_Options
|
||||
endif
|
||||
|
||||
if a:grep_cmd != 'agrep'
|
||||
" Don't display messages about non-existent files
|
||||
" Agrep doesn't support the -s option
|
||||
let grep_opt = grep_opt . " -s"
|
||||
endif
|
||||
|
||||
if a:grep_cmd == 'grep'
|
||||
let grep_path = g:Grep_Path
|
||||
let grep_expr_option = '--'
|
||||
elseif a:grep_cmd == 'fgrep'
|
||||
let grep_path = g:Fgrep_Path
|
||||
let grep_expr_option = '-e'
|
||||
elseif a:grep_cmd == 'egrep'
|
||||
let grep_path = g:Egrep_Path
|
||||
let grep_expr_option = '-e'
|
||||
elseif a:grep_cmd == 'agrep'
|
||||
let grep_path = g:Agrep_Path
|
||||
let grep_expr_option = ''
|
||||
else
|
||||
return
|
||||
endif
|
||||
|
||||
" Get the identifier and file list from user
|
||||
if pattern == ""
|
||||
let pattern = input("Search for pattern: ", expand("<cword>"))
|
||||
if pattern == ""
|
||||
return
|
||||
endif
|
||||
let pattern = g:Grep_Shell_Quote_Char . pattern .
|
||||
\ g:Grep_Shell_Quote_Char
|
||||
endif
|
||||
|
||||
if filenames == ""
|
||||
if v:version >= 700
|
||||
let filenames = input("Search in files: ", g:Grep_Default_Filelist,
|
||||
\ "file")
|
||||
else
|
||||
let filenames = input("Search in files: ", g:Grep_Default_Filelist)
|
||||
endif
|
||||
if filenames == ""
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
" Add /dev/null to the list of filenames, so that grep print the
|
||||
" filename and linenumber when grepping in a single file
|
||||
let filenames = filenames . " " . g:Grep_Null_Device
|
||||
let cmd = grep_path . " " . grep_opt . " -n "
|
||||
let cmd = cmd . grep_expr_option . " " . pattern
|
||||
let cmd = cmd . " " . filenames
|
||||
|
||||
call s:RunGrepCmd(cmd, pattern, a:action)
|
||||
endfunction
|
||||
|
||||
" Define the set of grep commands
|
||||
command! -nargs=* -complete=file Grep
|
||||
\ call s:RunGrep('Grep', 'grep', 'set', <f-args>)
|
||||
command! -nargs=* -complete=file Rgrep
|
||||
\ call s:RunGrepRecursive('Rgrep', 'grep', 'set', <f-args>)
|
||||
command! -nargs=* GrepBuffer
|
||||
\ call s:RunGrepSpecial('GrepBuffer', 'buffer', 'set', <f-args>)
|
||||
command! -nargs=* Bgrep
|
||||
\ call s:RunGrepSpecial('Bgrep', 'buffer', 'set', <f-args>)
|
||||
command! -nargs=* GrepArgs
|
||||
\ call s:RunGrepSpecial('GrepArgs', 'args', 'set', <f-args>)
|
||||
|
||||
command! -nargs=* -complete=file Fgrep
|
||||
\ call s:RunGrep('Fgrep', 'fgrep', 'set', <f-args>)
|
||||
command! -nargs=* -complete=file Rfgrep
|
||||
\ call s:RunGrepRecursive('Rfgrep', 'fgrep', 'set', <f-args>)
|
||||
command! -nargs=* -complete=file Egrep
|
||||
\ call s:RunGrep('Egrep', 'egrep', 'set', <f-args>)
|
||||
command! -nargs=* -complete=file Regrep
|
||||
\ call s:RunGrepRecursive('Regrep', 'egrep', 'set', <f-args>)
|
||||
command! -nargs=* -complete=file Agrep
|
||||
\ call s:RunGrep('Agrep', 'agrep', 'set', <f-args>)
|
||||
command! -nargs=* -complete=file Ragrep
|
||||
\ call s:RunGrepRecursive('Ragrep', 'agrep', 'set', <f-args>)
|
||||
|
||||
if v:version >= 700
|
||||
command! -nargs=* -complete=file GrepAdd
|
||||
\ call s:RunGrep('GrepAdd', 'grep', 'add', <f-args>)
|
||||
command! -nargs=* -complete=file RgrepAdd
|
||||
\ call s:RunGrepRecursive('RgrepAdd', 'grep', 'add', <f-args>)
|
||||
command! -nargs=* GrepBufferAdd
|
||||
\ call s:RunGrepSpecial('GrepBufferAdd', 'buffer', 'add', <f-args>)
|
||||
command! -nargs=* BgrepAdd
|
||||
\ call s:RunGrepSpecial('BgrepAdd', 'buffer', 'add', <f-args>)
|
||||
command! -nargs=* GrepArgsAdd
|
||||
\ call s:RunGrepSpecial('GrepArgsAdd', 'args', 'add', <f-args>)
|
||||
|
||||
command! -nargs=* -complete=file FgrepAdd
|
||||
\ call s:RunGrep('FgrepAdd', 'fgrep', 'add', <f-args>)
|
||||
command! -nargs=* -complete=file RfgrepAdd
|
||||
\ call s:RunGrepRecursive('RfgrepAdd', 'fgrep', 'add', <f-args>)
|
||||
command! -nargs=* -complete=file EgrepAdd
|
||||
\ call s:RunGrep('EgrepAdd', 'egrep', 'add', <f-args>)
|
||||
command! -nargs=* -complete=file RegrepAdd
|
||||
\ call s:RunGrepRecursive('RegrepAdd', 'egrep', 'add', <f-args>)
|
||||
command! -nargs=* -complete=file AgrepAdd
|
||||
\ call s:RunGrep('AgrepAdd', 'agrep', 'add', <f-args>)
|
||||
command! -nargs=* -complete=file RagrepAdd
|
||||
\ call s:RunGrepRecursive('RagrepAdd', 'agrep', 'add', <f-args>)
|
||||
endif
|
||||
|
||||
" Add the Tools->Search Files menu
|
||||
if has('gui_running')
|
||||
anoremenu <silent> Tools.Search.Current\ Directory<Tab>:Grep
|
||||
\ :Grep<CR>
|
||||
anoremenu <silent> Tools.Search.Recursively<Tab>:Rgrep
|
||||
\ :Rgrep<CR>
|
||||
anoremenu <silent> Tools.Search.Buffer\ List<Tab>:Bgrep
|
||||
\ :Bgrep<CR>
|
||||
anoremenu <silent> Tools.Search.Argument\ List<Tab>:GrepArgs
|
||||
\ :GrepArgs<CR>
|
||||
endif
|
||||
|
||||
" restore 'cpo'
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
623
plugin/jsbeautify.vim
Normal file
623
plugin/jsbeautify.vim
Normal file
@@ -0,0 +1,623 @@
|
||||
if &cp || exists("loaded_jsbeautify")
|
||||
finish
|
||||
endif
|
||||
let loaded_jsbeautify = 3
|
||||
|
||||
|
||||
|
||||
function! s:trim_output()
|
||||
while len(s:output) > 0 && (s:output[len(s:output)-1] == " " || s:output[len(s:output)-1] == s:indent_string)
|
||||
call remove(s:output, -1)
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! s:print_newline(ignore_repeated)
|
||||
let s:if_line_flag = 0
|
||||
call s:trim_output()
|
||||
if len(s:output)==0
|
||||
return
|
||||
endif
|
||||
if s:output[len(s:output)-1] != "\n" || !a:ignore_repeated
|
||||
call add(s:output, "\n")
|
||||
endif
|
||||
let index = 0
|
||||
while index < s:indent_level
|
||||
call add(s:output, s:indent_string)
|
||||
let index += 1
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! s:print_space()
|
||||
let last_output = " "
|
||||
if len(s:output) > 0
|
||||
let last_output = s:output[len(s:output) - 1]
|
||||
endif
|
||||
if last_output != " " && last_output != "\n" && last_output != s:indent_string
|
||||
call add(s:output, " ")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:print_token()
|
||||
call add(s:output, s:token_text)
|
||||
endfunctio
|
||||
|
||||
function! s:indent()
|
||||
let s:indent_level += 1
|
||||
endfunction
|
||||
|
||||
function! s:unindent()
|
||||
if s:indent_level
|
||||
let s:indent_level -= 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:remove_indent()
|
||||
if len(s:output)>0 && s:output[len(s:output) -1] == s:indent_string
|
||||
call remove(s:output, -1)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:set_mode(mode)
|
||||
call add(s:modes, s:current_mode)
|
||||
let s:current_mode = a:mode
|
||||
endfunction
|
||||
|
||||
function! s:restore_mode()
|
||||
if s:current_mode == "DO_BLOCK"
|
||||
let s:do_block_just_closed = 1
|
||||
else
|
||||
let s:do_block_just_closed = 0
|
||||
endif
|
||||
let s:current_mode = remove(s:modes, -1)
|
||||
endfunction
|
||||
|
||||
function! s:in_array(what, arr)
|
||||
return index(a:arr, a:what) != -1
|
||||
endfunction
|
||||
|
||||
function! s:get_next_token()
|
||||
let n_newlines = 0
|
||||
|
||||
if s:parser_pos >= len(s:input)
|
||||
return ["", "TK_EOF"]
|
||||
endif
|
||||
|
||||
let c = s:input[s:parser_pos]
|
||||
let s:parser_pos += 1
|
||||
|
||||
while s:in_array(c, s:whitespace)
|
||||
if s:parser_pos >= len(s:input)
|
||||
return ["", "TK_EOF"]
|
||||
endif
|
||||
|
||||
if c == "\n"
|
||||
let n_newlines += 1
|
||||
endif
|
||||
|
||||
let c = s:input[s:parser_pos]
|
||||
let s:parser_pos += 1
|
||||
endwhile
|
||||
|
||||
let wanted_newline = 0
|
||||
|
||||
if s:opt_preserve_newlines
|
||||
if n_newlines > 1
|
||||
for i in [0, 1]
|
||||
call s:print_newline(i==0)
|
||||
endfor
|
||||
endif
|
||||
let wanted_newline = n_newlines == 1
|
||||
endif
|
||||
|
||||
if s:in_array(c, s:wordchar)
|
||||
if s:parser_pos < len(s:input)
|
||||
while s:in_array(s:input[s:parser_pos], s:wordchar)
|
||||
let c .= s:input[s:parser_pos]
|
||||
let s:parser_pos += 1
|
||||
if s:parser_pos == len(s:input)
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
endif
|
||||
|
||||
"if s:parser_pos != len(s:input) && c =~ /^[0-9]+[Ee]$/ && (s:input[s:parser_pos] == "-" || s:input[s:parser_pos] == "+")
|
||||
"let sign = s:input[s:parser_pos]
|
||||
"let s:parser_pos += 1
|
||||
|
||||
"let t = get_next_token(s:parser_pos)
|
||||
"let c .= sign . t[0]
|
||||
"return [c, "TK_WORD"]
|
||||
" endif
|
||||
|
||||
if c == "in"
|
||||
return [c, "TK_OPERATOR"]
|
||||
endif
|
||||
if wanted_newline && s:last_type != "TK_OPERATOR" && !s:if_line_flag
|
||||
call s:print_newline(1)
|
||||
endif
|
||||
return [c, "TK_WORD"]
|
||||
endif
|
||||
if c == "(" || c == "["
|
||||
return [c, "TK_START_EXPR"]
|
||||
endif
|
||||
|
||||
if c == ")" || c == "]"
|
||||
return [c, "TK_END_EXPR"]
|
||||
endif
|
||||
|
||||
if c == "{"
|
||||
return [c, "TK_START_BLOCK"]
|
||||
endif
|
||||
|
||||
if c == "}"
|
||||
return [c, "TK_END_BLOCK"]
|
||||
endif
|
||||
|
||||
if c == ";"
|
||||
return [c, "TK_SEMICOLON"]
|
||||
endif
|
||||
|
||||
if c == "/"
|
||||
let comment = ""
|
||||
if s:input[s:parser_pos] == "*"
|
||||
let s:parser_pos += 1
|
||||
if s:parser_pos < len(s:input)
|
||||
while !(s:input[s:parser_pos] == "*" && s:parser_pos + 1 < len(s:input) && s:input[s:parser_pos + 1] == "/" && s:parser_pos < len(s:input))
|
||||
let comment .= s:input[s:parser_pos]
|
||||
let s:parser_pos += 1
|
||||
if s:parser_pos >= len(s:input)
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
endif
|
||||
let s:parser_pos += 2
|
||||
return ['/*' . comment . '*/', 'TK_BLOCK_COMMENT']
|
||||
endif
|
||||
|
||||
" peek for comment // ...
|
||||
if s:input[s:parser_pos] == "/"
|
||||
let comment = c
|
||||
while s:input[s:parser_pos] != "\r" && s:input[s:parser_pos] != "\n"
|
||||
let comment .= s:input[s:parser_pos]
|
||||
let s:parser_pos += 1
|
||||
if s:parser_pos >= len(s:input)
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
let s:parser_pos += 1
|
||||
if wanted_newline
|
||||
call s:print_newline(1)
|
||||
endif
|
||||
return [comment, "TK_COMMENT"]
|
||||
endif
|
||||
endif
|
||||
|
||||
if c == "'" || c =='"' || (c == "/" && ((s:last_type == "TK_WORD" && s:last_text == "return") || (s:last_type == "TK_START_EXPR" || s:last_type == "TK_START_BLOCK" || s:last_type == "TK_END_BLOCK" || s:last_type == "TK_OPERATOR" || s:last_type == "TK_EOF" || s:last_type == "TK_SEMICOLON")))
|
||||
let sep = c
|
||||
let esc = 0
|
||||
let resulting_string = c
|
||||
|
||||
if s:parser_pos < len(s:input)
|
||||
while esc || s:input[s:parser_pos] != sep
|
||||
let resulting_string .= s:input[s:parser_pos]
|
||||
if !esc
|
||||
let esc = s:input[s:parser_pos] == "\\"
|
||||
else
|
||||
let esc = 0
|
||||
endif
|
||||
let s:parser_pos += 1
|
||||
if s:parser_pos >= len(s:input)
|
||||
return [resulting_string, "TK_STRING"]
|
||||
endif
|
||||
endwhile
|
||||
endif
|
||||
|
||||
let s:parser_pos += 1
|
||||
|
||||
let resulting_string .= sep
|
||||
|
||||
if sep == "/"
|
||||
|
||||
while s:parser_pos < len(s:input) && s:in_array(s:input[s:parser_pos], s:wordchar)
|
||||
let resulting_string .= s:input[s:parser_pos]
|
||||
let s:parser_pos += 1
|
||||
endwhile
|
||||
endif
|
||||
return [resulting_string, "TK_STRING"]
|
||||
endif
|
||||
|
||||
if c == "#"
|
||||
let sharp = "#"
|
||||
if s:parser_pos < len(s:input) && s:in_array(s:input[s:parser_pos], s:digits)
|
||||
let c = s:input[s:parser_pos]
|
||||
let sharp .= c
|
||||
let s:parser_pos += 1
|
||||
|
||||
while s:parser_pos < len(s:input) && c != "#" && c !="="
|
||||
let c = s:input[s:parser_pos]
|
||||
let sharp .= c
|
||||
let s:parser_pos += 1
|
||||
endwhile
|
||||
|
||||
if c == "#"
|
||||
return [sharp, "TK_WORD"]
|
||||
else
|
||||
return [sharp, "TK_OPERATOR"]
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
if c == "<" && s:input[s:parser_pos-1 : s:parser_pos+3] == "<!--"
|
||||
let s:parser_pos += 3
|
||||
return ["<!--", "TK_COMMENT"]
|
||||
endif
|
||||
|
||||
if c == "-" && s:input[s:parser_pos-1 : s:parser_pos+2] == "-->"
|
||||
let s:parser_pos += 2
|
||||
if wanted_newline
|
||||
call s:print_newline(1)
|
||||
endif
|
||||
return ["-->", "TK_COMMENT"]
|
||||
endif
|
||||
|
||||
if s:in_array(c, s:punct)
|
||||
while s:parser_pos < len(s:input) && s:in_array(c . s:input[s:parser_pos], s:punct)
|
||||
let c .= s:input[s:parser_pos]
|
||||
let s:parser_pos += 1
|
||||
if s:parser_pos >= len(s:input)
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
return [c, "TK_OPERATOR"]
|
||||
endif
|
||||
|
||||
return [c, "TK_UNKNOWN"]
|
||||
endif
|
||||
|
||||
|
||||
|
||||
endfunction
|
||||
|
||||
function! s:is_js()
|
||||
return expand("%:e") == "js"
|
||||
endfunction
|
||||
|
||||
"function! g:Jsbeautify(js_source_text, options)
|
||||
function! g:Jsbeautify()
|
||||
if !s:is_js()
|
||||
echo "Not a JS file."
|
||||
return
|
||||
endif
|
||||
|
||||
"let a:options = {}
|
||||
let s:opt_indent_size = 1
|
||||
let s:opt_indent_char = "\t"
|
||||
let s:opt_preserve_newlines = 1
|
||||
let s:opt_indent_level = 0
|
||||
|
||||
let s:if_line_flag = 0
|
||||
"--------------------------------
|
||||
|
||||
let s:indent_string = ""
|
||||
while s:opt_indent_size > 0
|
||||
let s:indent_string .= s:opt_indent_char
|
||||
let s:opt_indent_size -= 1
|
||||
endwhile
|
||||
|
||||
let s:indent_level = s:opt_indent_level
|
||||
|
||||
let lines = getline(1, "$")
|
||||
let s:input = join(lines, "\n")
|
||||
"let s:input = a:js_source_text
|
||||
|
||||
let s:last_word = "" "last 'TK_WORD' passed
|
||||
let s:last_type = "TK_START_EXPR" "last token type
|
||||
let s:last_text = "" "last token text
|
||||
let s:output = []
|
||||
|
||||
let s:do_block_just_closed = 0
|
||||
let s:var_line = 0
|
||||
let s:var_line_tainted = 0
|
||||
|
||||
let s:whitespace = ["\n", "\r", "\t", " "]
|
||||
let s:wordchar = split("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$", '\zs')
|
||||
let s:digits = split("0123456789", '\zs')
|
||||
|
||||
"<!-- is a special case (ok, it"s a minor hack actually)
|
||||
let s:punct = split("+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::", " ")
|
||||
|
||||
let s:line_starters = split("continue,try,throw,return,var,if,switch,case,default,for,while,break", ",")
|
||||
|
||||
let s:current_mode = "BLOCK"
|
||||
let s:modes = [s:current_mode]
|
||||
|
||||
let s:parser_pos = 0
|
||||
let s:in_case = 0
|
||||
while 1
|
||||
let t = s:get_next_token()
|
||||
let s:token_text = t[0]
|
||||
let s:token_type = t[1]
|
||||
if s:token_type == "TK_EOF"
|
||||
break
|
||||
endif
|
||||
|
||||
try
|
||||
if s:token_type == "TK_START_EXPR"
|
||||
let s:var_line = 0
|
||||
call s:set_mode("EXPRESSION")
|
||||
if s:last_text == ";"
|
||||
call s:print_newline(1)
|
||||
elseif s:last_type == "TK_END_EXPR" || s:last_type == "TK_START_EXPR"
|
||||
" do nothing on (( and )( and ][ and ]( ..
|
||||
elseif s:last_type != "TK_WORD" && s:last_type != "TK_OPERATOR"
|
||||
call s:print_space()
|
||||
elseif s:in_array(s:last_word, s:line_starters)
|
||||
call s:print_space()
|
||||
endif
|
||||
|
||||
call s:print_token()
|
||||
|
||||
elseif s:token_type == "TK_END_EXPR"
|
||||
call s:print_token()
|
||||
call s:restore_mode()
|
||||
elseif s:token_type == "TK_START_BLOCK"
|
||||
|
||||
if s:last_word == "do"
|
||||
call s:set_mode("DO_BLOCK")
|
||||
else
|
||||
call s:set_mode("BLOCK")
|
||||
endif
|
||||
if s:last_type != "TK_OPERATOR" && s:last_type != "TK_START_EXPR"
|
||||
if s:last_type == "TK_START_BLOCK"
|
||||
call s:print_newline(1)
|
||||
else
|
||||
call s:print_space()
|
||||
endif
|
||||
endif
|
||||
call s:print_token()
|
||||
call s:indent()
|
||||
elseif s:token_type == "TK_END_BLOCK"
|
||||
if s:last_type == "TK_START_BLOCK"
|
||||
call s:remove_indent()
|
||||
call s:unindent()
|
||||
else
|
||||
call s:unindent()
|
||||
call s:print_newline(1)
|
||||
endif
|
||||
call s:print_token()
|
||||
call s:restore_mode()
|
||||
|
||||
elseif s:token_type == "TK_WORD"
|
||||
if s:do_block_just_closed
|
||||
" do {} ## while ()
|
||||
call s:print_space()
|
||||
call s:print_token()
|
||||
call s:print_space()
|
||||
let s:do_block_just_closed = 0
|
||||
throw "jump out"
|
||||
endif
|
||||
if s:token_text == "case" || s:token_text == "default"
|
||||
if s:last_text == ":"
|
||||
"switch cases following one another
|
||||
call s:remove_indent()
|
||||
else
|
||||
" case statement starts in the same line where switch
|
||||
call s:unindent()
|
||||
call s:print_newline(1)
|
||||
call s:indent()
|
||||
endif
|
||||
call s:print_token()
|
||||
let s:in_case = 1
|
||||
throw "jump out"
|
||||
endif
|
||||
|
||||
let s:prefix = "NONE"
|
||||
|
||||
if s:last_type == "TK_END_BLOCK"
|
||||
if !s:in_array(tolower(s:token_text), ["else", "catch", "finally"])
|
||||
let s:prefix = "NEWLINE"
|
||||
else
|
||||
let s:prefix = "SPACE"
|
||||
call s:print_space()
|
||||
endif
|
||||
elseif s:last_type == "TK_SEMICOLON" && (s:current_mode == "BLOCK" || s:current_mode == "DO_BLOCK")
|
||||
let s:prefix = "NEWLINE"
|
||||
elseif s:last_type == "TK_SEMICOLON" && s:current_mode == "EXPRESSION"
|
||||
let s:prefix = "SPACE"
|
||||
elseif s:last_type == "TK_STRING"
|
||||
let s:prefix = "NEWLINE"
|
||||
elseif s:last_type == "TK_WORD"
|
||||
let s:prefix = "SPACE"
|
||||
elseif s:last_type == "TK_START_BLOCK"
|
||||
let s:prefix = "NEWLINE"
|
||||
elseif s:last_type == "TK_END_EXPR"
|
||||
call s:print_space()
|
||||
let s:prefix = "NEWLINE"
|
||||
endif
|
||||
|
||||
if s:last_type != "TK_END_BLOCK" && s:in_array(tolower(s:token_text), ["else", "catch", "finally"])
|
||||
call s:print_newline(1)
|
||||
elseif s:in_array(s:token_text, s:line_starters) || s:prefix == "NEWLINE"
|
||||
if s:last_text == "else"
|
||||
call s:print_space()
|
||||
elseif (s:last_type == "TK_START_EXPR" || s:last_text == "=" || s:last_text == ",") && s:token_text == "function"
|
||||
" no need to force newline on "function":
|
||||
" DONOTHINT
|
||||
elseif s:last_type == "TK_WORD" && (s:last_text == "return" || s:last_text == "throw")
|
||||
" no newline between "return nnn"
|
||||
call s:print_space()
|
||||
elseif s:last_type != "TK_END_EXPR"
|
||||
if (s:last_type != "TK_START_EXPR" || s:token_text != "var") && s:last_text != ":"
|
||||
" no need to force newline on "var": for (var
|
||||
" x = 0...)
|
||||
if s:token_text == "if" && s:last_type == "TK_WORD" && s:last_word == "else"
|
||||
" no newline for } else if {
|
||||
call s:print_space()
|
||||
else
|
||||
call s:print_newline(1)
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if s:in_array(s:token_text, s:line_starters) && s:last_text != ")"
|
||||
call s:print_newline(1)
|
||||
endif
|
||||
endif
|
||||
elseif s:prefix == "SPACE"
|
||||
call s:print_space()
|
||||
endif
|
||||
call s:print_token()
|
||||
let s:last_word = s:token_text
|
||||
|
||||
if s:token_text == "var"
|
||||
let s:var_line = 1
|
||||
let s:var_line_tainted = 0
|
||||
endif
|
||||
|
||||
if s:token_text == "if" || s:token_text == "else"
|
||||
let s:if_line_flag = 1
|
||||
endif
|
||||
|
||||
elseif s:token_type == "TK_SEMICOLON"
|
||||
call s:print_token()
|
||||
let s:var_line = 0
|
||||
|
||||
elseif s:token_type == "TK_STRING"
|
||||
if s:last_type == "TK_START_BLOCK" || s:last_type == "TK_END_BLOCK" || s:last_type == "TK_SEMICOLON"
|
||||
call s:print_newline(1)
|
||||
elseif s:last_type == "TK_WORD"
|
||||
call s:print_space()
|
||||
endif
|
||||
call s:print_token()
|
||||
|
||||
elseif s:token_type == "TK_OPERATOR"
|
||||
|
||||
let start_delim = 1
|
||||
let end_delim = 1
|
||||
if s:var_line && s:token_text != ","
|
||||
let s:var_line_tainted = 1
|
||||
if s:token_text == ":"
|
||||
let s:var_line = 0
|
||||
endif
|
||||
endif
|
||||
if s:var_line && s:token_text=="," && s:current_mode == "EXPRESSION"
|
||||
" do not break on comma, for(var a = 1, b = 2)
|
||||
let s:var_line_tainted = 0
|
||||
endif
|
||||
|
||||
if s:token_text == ":" && s:in_case
|
||||
call s:print_token()
|
||||
call s:print_newline(1)
|
||||
throw "jump out"
|
||||
endif
|
||||
|
||||
if s:token_text == "::"
|
||||
" no spaces around exotic namespacing syntax operator
|
||||
call s:print_token()
|
||||
throw "jump out"
|
||||
endif
|
||||
|
||||
let s:in_case = 0
|
||||
|
||||
if s:token_text == ","
|
||||
if s:var_line
|
||||
if s:var_line_tainted
|
||||
call s:print_token()
|
||||
call s:print_newline(1)
|
||||
let s:var_line_tainted = 0
|
||||
else
|
||||
call s:print_token()
|
||||
call s:print_space()
|
||||
endif
|
||||
elseif s:last_type == "TK_END_BLOCK"
|
||||
call s:print_token()
|
||||
call s:print_newline(1)
|
||||
else
|
||||
if s:current_mode == "BLOCK"
|
||||
call s:print_token()
|
||||
call s:print_newline(1)
|
||||
else
|
||||
" EXPR od DO_BLOCK
|
||||
call s:print_token()
|
||||
call s:print_space()
|
||||
endif
|
||||
endif
|
||||
throw "jump out"
|
||||
elseif s:token_text == "--" || s:token_text == "++" " unary operators special case
|
||||
if s:last_text == ";"
|
||||
" space for (;; ++i)
|
||||
let start_delim = 1
|
||||
let end_delim = 0
|
||||
else
|
||||
let start_delim = 0
|
||||
let end_delim = 0
|
||||
endif
|
||||
elseif s:token_text == "!" && s:last_type == "TK_START_EXPR"
|
||||
" special case handling: if (!a)
|
||||
let start_delim = 0
|
||||
let end_delim = 0
|
||||
elseif s:last_type == "TK_OPERATOR"
|
||||
let s:start_delim = 0
|
||||
let s:end_delim = 0
|
||||
elseif s:last_type == "TK_END_EXPR"
|
||||
let s:start_delim = 1
|
||||
let s:end_delim = 1
|
||||
elseif s:token_text == "."
|
||||
" decimal digits or object.property
|
||||
let start_delim = 0
|
||||
let end_delim = 0
|
||||
elseif s:token_text == ":"
|
||||
" zz: xx
|
||||
" can"t differentiate ternary op, so for now it"s a ? b:
|
||||
" c;without space before colon
|
||||
if s:last_text =~ '/^\d+$/'
|
||||
" a little help for ternary a ? 1 : 0
|
||||
let start_delim = 1
|
||||
else
|
||||
let start_delim = 0
|
||||
endif
|
||||
endif
|
||||
if start_delim
|
||||
call s:print_space()
|
||||
endif
|
||||
|
||||
call s:print_token()
|
||||
|
||||
if end_delim
|
||||
call s:print_space()
|
||||
endif
|
||||
throw "jump out"
|
||||
|
||||
elseif s:token_type == "TK_BLOCK_COMMENT"
|
||||
call s:print_newline(1)
|
||||
call s:print_token()
|
||||
call s:print_newline(1)
|
||||
|
||||
elseif s:token_type == "TK_COMMENT"
|
||||
|
||||
"call s:print_newline(1)
|
||||
call s:print_space()
|
||||
call s:print_token()
|
||||
call s:print_newline(1)
|
||||
|
||||
elseif s:token_type == "TK_UNKNOWN"
|
||||
call s:print_token()
|
||||
throw "jump out"
|
||||
endif
|
||||
catch /.*/
|
||||
if v:exception != 'jump out'
|
||||
echo "exception caught: " v:exception
|
||||
endif
|
||||
endtry
|
||||
|
||||
let s:last_type = s:token_type
|
||||
let s:last_text = s:token_text
|
||||
endwhile
|
||||
|
||||
let ret = join(s:output, "")
|
||||
:g/.*/d
|
||||
let @0 = ret
|
||||
:put!0
|
||||
endfunction
|
||||
|
||||
nnoremap <silent> <leader>ff :call g:Jsbeautify()<cr>
|
||||
209
plugin/mark.vim
Normal file
209
plugin/mark.vim
Normal file
@@ -0,0 +1,209 @@
|
||||
" Script Name: mark.vim
|
||||
" Description: Highlight several words in different colors simultaneously.
|
||||
"
|
||||
" Copyright: (C) 2005-2008 by Yuheng Xie
|
||||
" (C) 2008-2009 by Ingo Karkat
|
||||
" The VIM LICENSE applies to this script; see ':help copyright'.
|
||||
"
|
||||
" Maintainer: Ingo Karkat <ingo@karkat.de>
|
||||
" Orig Author: Yuheng Xie <elephant@linux.net.cn>
|
||||
" Contributors:Luc Hermitte, Ingo Karkat
|
||||
"
|
||||
" Dependencies:
|
||||
" - Requires Vim 7.1 with "matchadd()", or Vim 7.2 or higher.
|
||||
" - mark.vim autoload script.
|
||||
"
|
||||
" Version: 2.3.2
|
||||
" Changes:
|
||||
" 17-Nov-2009, Ingo Karkat
|
||||
" - Replaced the (overly) generic mark#GetVisualSelectionEscaped() with
|
||||
" mark#GetVisualSelectionAsRegexp() and
|
||||
" mark#GetVisualSelectionAsLiteralPattern().
|
||||
"
|
||||
" 04-Jul-2009, Ingo Karkat
|
||||
" - A [count] before any mapping either caused "No range allowed" error or just
|
||||
" repeated the :call [count] times, resulting in the current search pattern
|
||||
" echoed [count] times and a hit-enter prompt. Now suppressing [count] via
|
||||
" <C-u> and handling it inside the implementation.
|
||||
" - Now passing isBackward (0/1) instead of optional 'b' flag into functions.
|
||||
" Also passing empty regexp to mark#MarkRegex() to avoid any optional
|
||||
" arguments.
|
||||
"
|
||||
" 02-Jul-2009, Ingo Karkat
|
||||
" - Split off functions into autoload script.
|
||||
" - Removed g:force_reload_mark.
|
||||
" - Initialization of global variables and autocommands is now done lazily on
|
||||
" the first use, not during loading of the plugin. This reduces Vim startup
|
||||
" time and footprint as long as the functionality isn't yet used.
|
||||
"
|
||||
" 6-Jun-2009, Ingo Karkat
|
||||
" 1. Somehow s:WrapMessage() needs a redraw before the :echo to avoid that a
|
||||
" later Vim redraw clears the wrap message. This happened when there's no
|
||||
" statusline and thus :echo'ing into the ruler.
|
||||
" 2. Removed line-continuations and ':set cpo=...'. Upper-cased <SID> and <CR>.
|
||||
" 3. Added default highlighting for the special search type.
|
||||
"
|
||||
" 2-Jun-2009, Ingo Karkat
|
||||
" 1. Replaced highlighting via :syntax with matchadd() / matchdelete(). This
|
||||
" requires Vim 7.2 / 7.1 with patches. This method is faster, there are no
|
||||
" more clashes with syntax highlighting (:match always has preference), and
|
||||
" the background highlighting does not disappear under 'cursorline'.
|
||||
" 2. Factored :windo application out into s:MarkScope().
|
||||
" 3. Using winrestcmd() to fix effects of :windo: By entering a window, its
|
||||
" height is potentially increased from 0 to 1.
|
||||
" 4. Handling multiple tabs by calling s:UpdateScope() on the TabEnter event.
|
||||
"
|
||||
" 1-Jun-2009, Ingo Karkat
|
||||
" 1. Now using Vim List for g:mwWord and thus requiring Vim 7. g:mwCycle is now
|
||||
" zero-based, but the syntax groups "MarkWordx" are still one-based.
|
||||
" 2. Added missing setter for re-inclusion guard.
|
||||
" 3. Factored :syntax operations out of s:DoMark() and s:UpdateMark() so that
|
||||
" they can all be done in a single :windo.
|
||||
" 4. Normal mode <Plug>MarkSet now has the same semantics as its visual mode
|
||||
" cousin: If the cursor is on an existing mark, the mark is removed.
|
||||
" Beforehand, one could only remove a visually selected mark via again
|
||||
" selecting it. Now, one simply can invoke the mapping when on such a mark.
|
||||
" 5. Highlighting can now actually be overridden in the vimrc (anywhere
|
||||
" _before_ sourcing this script) by using ':hi def'.
|
||||
"
|
||||
" 31-May-2009, Ingo Karkat
|
||||
" 1. Refactored s:Search() to optionally take advantage of SearchSpecial.vim
|
||||
" autoload functionality for echoing of search pattern, wrap and error
|
||||
" messages.
|
||||
" 2. Now prepending search type ("any-mark", "same-mark", "new-mark") for
|
||||
" better identification.
|
||||
" 3. Retired the algorithm in s:PrevWord in favor of simply using <cword>,
|
||||
" which makes mark.vim work like the * command. At the end of a line,
|
||||
" non-keyword characters may now be marked; the previous algorithm prefered
|
||||
" any preceding word.
|
||||
" 4. BF: If 'iskeyword' contains characters that have a special meaning in a
|
||||
" regex (e.g. [.*]), these are now escaped properly.
|
||||
"
|
||||
" 01-Sep-2008, Ingo Karkat: bugfixes and enhancements
|
||||
" 1. Added <Plug>MarkAllClear (without a default mapping), which clears all
|
||||
" marks, even when the cursor is on a mark.
|
||||
" 2. Added <Plug>... mappings for hard-coded \*, \#, \/, \?, * and #, to allow
|
||||
" re-mapping and disabling. Beforehand, there were some <Plug>... mappings
|
||||
" and hard-coded ones; now, everything can be customized.
|
||||
" 3. Bugfix: Using :autocmd without <bang> to avoid removing _all_ autocmds for
|
||||
" the BufWinEnter event. (Using a custom :augroup would be even better.)
|
||||
" 4. Bugfix: Explicitly defining s:current_mark_position; some execution paths
|
||||
" left it undefined, causing errors.
|
||||
" 5. Refactoring: Instead of calling s:InitMarkVariables() at the beginning of
|
||||
" several functions, just calling it once when sourcing the script.
|
||||
" 6. Refactoring: Moved multiple 'let lastwinnr = winnr()' to a single one at the
|
||||
" top of DoMark().
|
||||
" 7. ENH: Make the match according to the 'ignorecase' setting, like the star
|
||||
" command.
|
||||
" 8. The jumps to the next/prev occurrence now print 'search hit BOTTOM,
|
||||
" continuing at TOP" and "Pattern not found:..." messages, like the * and
|
||||
" n/N Vim search commands.
|
||||
" 9. Jumps now open folds if the occurrence is inside a closed fold, just like n/N
|
||||
" do.
|
||||
"
|
||||
" 10th Mar 2006, Yuheng Xie: jump to ANY mark
|
||||
" (*) added \* \# \/ \? for the ability of jumping to ANY mark, even when the
|
||||
" cursor is not currently over any mark
|
||||
"
|
||||
" 20th Sep 2005, Yuheng Xie: minor modifications
|
||||
" (*) merged MarkRegexVisual into MarkRegex
|
||||
" (*) added GetVisualSelectionEscaped for multi-lines visual selection and
|
||||
" visual selection contains ^, $, etc.
|
||||
" (*) changed the name ThisMark to CurrentMark
|
||||
" (*) added SearchCurrentMark and re-used raw map (instead of Vim function) to
|
||||
" implement * and #
|
||||
"
|
||||
" 14th Sep 2005, Luc Hermitte: modifications done on v1.1.4
|
||||
" (*) anti-reinclusion guards. They do not guard colors definitions in case
|
||||
" this script must be reloaded after .gvimrc
|
||||
" (*) Protection against disabled |line-continuation|s.
|
||||
" (*) Script-local functions
|
||||
" (*) Default keybindings
|
||||
" (*) \r for visual mode
|
||||
" (*) uses <Leader> instead of "\"
|
||||
" (*) do not mess with global variable g:w
|
||||
" (*) regex simplified -> double quotes changed into simple quotes.
|
||||
" (*) strpart(str, idx, 1) -> str[idx]
|
||||
" (*) command :Mark
|
||||
" -> e.g. :Mark Mark.\{-}\ze(
|
||||
|
||||
" Avoid installing twice or when in unsupported Vim version.
|
||||
if exists('g:loaded_mark') || (v:version == 701 && ! exists('*matchadd')) || (v:version < 702)
|
||||
finish
|
||||
endif
|
||||
let g:loaded_mark = 1
|
||||
|
||||
"- default highlightings ------------------------------------------------------
|
||||
" You may define your own colors in your vimrc file, in the form as below:
|
||||
highlight def MarkWord1 ctermbg=Cyan ctermfg=Black guibg=#8CCBEA guifg=Black
|
||||
highlight def MarkWord2 ctermbg=Green ctermfg=Black guibg=#A4E57E guifg=Black
|
||||
highlight def MarkWord3 ctermbg=Yellow ctermfg=Black guibg=#FFDB72 guifg=Black
|
||||
highlight def MarkWord4 ctermbg=Red ctermfg=Black guibg=#FF7272 guifg=Black
|
||||
highlight def MarkWord5 ctermbg=Magenta ctermfg=Black guibg=#FFB3FF guifg=Black
|
||||
highlight def MarkWord6 ctermbg=Blue ctermfg=Black guibg=#9999FF guifg=Black
|
||||
|
||||
" Default highlighting for the special search type.
|
||||
" You can override this by defining / linking the 'SearchSpecialSearchType'
|
||||
" highlight group before this script is sourced.
|
||||
highlight def link SearchSpecialSearchType MoreMsg
|
||||
|
||||
|
||||
"- mappings -------------------------------------------------------------------
|
||||
nnoremap <silent> <Plug>MarkSet :<C-u>call mark#MarkCurrentWord()<CR>
|
||||
vnoremap <silent> <Plug>MarkSet <C-\><C-n>:call mark#DoMark(mark#GetVisualSelectionAsLiteralPattern())<CR>
|
||||
nnoremap <silent> <Plug>MarkRegex :<C-u>call mark#MarkRegex('')<CR>
|
||||
vnoremap <silent> <Plug>MarkRegex <C-\><C-n>:call mark#MarkRegex(mark#GetVisualSelectionAsRegexp())<CR>
|
||||
nnoremap <silent> <Plug>MarkClear :<C-u>call mark#DoMark(mark#CurrentMark()[0])<CR>
|
||||
nnoremap <silent> <Plug>MarkAllClear :<C-u>call mark#DoMark()<CR>
|
||||
|
||||
nnoremap <silent> <Plug>MarkSearchCurrentNext :<C-u>call mark#SearchCurrentMark(0)<CR>
|
||||
nnoremap <silent> <Plug>MarkSearchCurrentPrev :<C-u>call mark#SearchCurrentMark(1)<CR>
|
||||
nnoremap <silent> <Plug>MarkSearchAnyNext :<C-u>call mark#SearchAnyMark(0)<CR>
|
||||
nnoremap <silent> <Plug>MarkSearchAnyPrev :<C-u>call mark#SearchAnyMark(1)<CR>
|
||||
nnoremap <silent> <Plug>MarkSearchNext :<C-u>if !mark#SearchNext(0)<Bar>execute 'normal! *zv'<Bar>endif<CR>
|
||||
nnoremap <silent> <Plug>MarkSearchPrev :<C-u>if !mark#SearchNext(1)<Bar>execute 'normal! #zv'<Bar>endif<CR>
|
||||
" When typed, [*#nN] open the fold at the search result, but inside a mapping or
|
||||
" :normal this must be done explicitly via 'zv'.
|
||||
|
||||
|
||||
if !hasmapto('<Plug>MarkSet', 'n')
|
||||
nmap <unique> <silent> <Leader>m <Plug>MarkSet
|
||||
endif
|
||||
if !hasmapto('<Plug>MarkSet', 'v')
|
||||
vmap <unique> <silent> <Leader>m <Plug>MarkSet
|
||||
endif
|
||||
if !hasmapto('<Plug>MarkRegex', 'n')
|
||||
nmap <unique> <silent> <Leader>r <Plug>MarkRegex
|
||||
endif
|
||||
if !hasmapto('<Plug>MarkRegex', 'v')
|
||||
vmap <unique> <silent> <Leader>r <Plug>MarkRegex
|
||||
endif
|
||||
if !hasmapto('<Plug>MarkClear', 'n')
|
||||
nmap <unique> <silent> <Leader>n <Plug>MarkClear
|
||||
endif
|
||||
" No default mapping for <Plug>MarkAllClear.
|
||||
|
||||
if !hasmapto('<Plug>MarkSearchCurrentNext', 'n')
|
||||
nmap <unique> <silent> <Leader>* <Plug>MarkSearchCurrentNext
|
||||
endif
|
||||
if !hasmapto('<Plug>MarkSearchCurrentPrev', 'n')
|
||||
nmap <unique> <silent> <Leader># <Plug>MarkSearchCurrentPrev
|
||||
endif
|
||||
if !hasmapto('<Plug>MarkSearchAnyNext', 'n')
|
||||
nmap <unique> <silent> <Leader>/ <Plug>MarkSearchAnyNext
|
||||
endif
|
||||
if !hasmapto('<Plug>MarkSearchAnyPrev', 'n')
|
||||
nmap <unique> <silent> <Leader>? <Plug>MarkSearchAnyPrev
|
||||
endif
|
||||
if !hasmapto('<Plug>MarkSearchNext', 'n')
|
||||
nmap <unique> <silent> * <Plug>MarkSearchNext
|
||||
endif
|
||||
if !hasmapto('<Plug>MarkSearchPrev', 'n')
|
||||
nmap <unique> <silent> # <Plug>MarkSearchPrev
|
||||
endif
|
||||
|
||||
|
||||
"- commands -------------------------------------------------------------------
|
||||
command! -nargs=? Mark call mark#DoMark(<f-args>)
|
||||
|
||||
" vim: ts=2 sw=2
|
||||
84
plugin/occur.vim
Normal file
84
plugin/occur.vim
Normal file
@@ -0,0 +1,84 @@
|
||||
"=============================================================================
|
||||
" File: occur.vim
|
||||
" Author: FURUSAWA, Noriyoshi (noriyosi xxx gmail dot com) xxx=@,dot=.
|
||||
" Last Change: 2008/7/13
|
||||
" Version: 0.03
|
||||
"=============================================================================
|
||||
|
||||
if exists('loaded_occur') || &cp
|
||||
finish
|
||||
endif
|
||||
let loaded_occur=1
|
||||
|
||||
if v:version < 700
|
||||
echo "Sorry, occur ONLY runs with Vim 7.0 and greater."
|
||||
finish
|
||||
endif
|
||||
|
||||
if !exists("g:occur_no_quickfix_map")
|
||||
let g:occur_no_quickfix_map = 0
|
||||
endif
|
||||
|
||||
" Key bind
|
||||
nnoremap <silent> <unique> <Leader>oc :Occur<CR>
|
||||
nnoremap <silent> <unique> <Leader>om :Moccur<CR>
|
||||
nnoremap <silent> <unique> <Leader>8 *<C-o>:Moccur<CR>
|
||||
|
||||
" Create commands
|
||||
command! Occur silent call s:SetupAndGo('s:Occur')
|
||||
command! Moccur silent call s:SetupAndGo('s:Moccur')
|
||||
command! StarOccur exec "normal! *<C-o>" <Bar> Moccur
|
||||
|
||||
function! s:Occur()
|
||||
let expr = 'caddexpr expand("%") . ":" . line(".") . ":" . getline(".")'
|
||||
exec 'silent keepjumps g/' . @/ . '/' . expr
|
||||
endfunction
|
||||
|
||||
function! s:Moccur()
|
||||
" Create the buffer list
|
||||
redir => command_out
|
||||
ls
|
||||
redir END
|
||||
|
||||
let buffers = []
|
||||
for line in split(command_out, '\n')
|
||||
call add(buffers, split(line, ' ')[0])
|
||||
endfor
|
||||
|
||||
" Search the pattern in all buffers
|
||||
for buf_number in buffers
|
||||
exec 'keepjumps buffer ' . buf_number
|
||||
call s:Occur()
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:SetupAndGo(func)
|
||||
let org_efm = &errorformat
|
||||
let &errorformat = '%f:%l:%m'
|
||||
|
||||
" Clear the results window
|
||||
cexpr "================= occur result ================="
|
||||
cclose
|
||||
|
||||
" Log the current cursor position
|
||||
normal! H
|
||||
|
||||
" Do Occur
|
||||
call function(a:func)()
|
||||
|
||||
" Open the results window (and restore cursor position)
|
||||
keepjumps cfirst 1
|
||||
exec "normal! \<C-o>"
|
||||
copen
|
||||
|
||||
" Map the key sequence on the QuickFix
|
||||
if !g:occur_no_quickfix_map
|
||||
nnoremap <buffer> <silent> <Space> <C-w><C-_>
|
||||
nnoremap <buffer> <silent> x 10<C-w>_<CR>zxzz:copen<CR>
|
||||
nnoremap <buffer> <silent> <CR> <CR>zxzz:cclose<CR>
|
||||
nnoremap <buffer> <silent> q :cclose<CR>
|
||||
endif
|
||||
|
||||
let &errorformat = org_efm
|
||||
endfunction
|
||||
|
||||
102
plugin/pysmell.vim
Normal file
102
plugin/pysmell.vim
Normal file
@@ -0,0 +1,102 @@
|
||||
" pysmell.vim
|
||||
" Omnicompletions provider for Python, using PYSMELLTAGS files
|
||||
" Copyright (C) 2008 Orestis Markou
|
||||
" All rights reserved
|
||||
" E-mail: orestis@orestis.gr
|
||||
|
||||
" pysmell v0.7.2
|
||||
" http://orestis.gr
|
||||
|
||||
" Released subject to the BSD License
|
||||
|
||||
" Options:
|
||||
" g:pysmell_debug : set to 1 and create a PYSMELL_DEBUG buffer. Info will get appended there.
|
||||
" g:pysmell_matcher : one of the following, listed from stricter to fuzzier:
|
||||
" 'case-sensitive'
|
||||
" 'case-insensitive' "default
|
||||
" 'camel-case'
|
||||
" 'camel-case-sensitive'
|
||||
" 'smartass'
|
||||
" 'fuzzy-ci'
|
||||
" 'fuzzy-cs'
|
||||
|
||||
|
||||
if !has('python')
|
||||
echo "Error: Required vim compiled with +python"
|
||||
finish
|
||||
endif
|
||||
|
||||
if !exists('g:pysmell_debug')
|
||||
let g:pysmell_debug = 0
|
||||
endif
|
||||
if !exists('g:pysmell_matcher')
|
||||
let g:pysmell_matcher='case-insensitive'
|
||||
endif
|
||||
|
||||
python << eopython
|
||||
from pysmell import vimhelper, idehelper
|
||||
import vim
|
||||
import string
|
||||
TRANSLATEQUOTES = string.maketrans("\'\"", "\"\'")
|
||||
eopython
|
||||
|
||||
function! pysmell#Complete(findstart, base)
|
||||
"findstart = 1 when we need to get the text length
|
||||
if a:findstart == 1
|
||||
python << eopython
|
||||
row, col = vim.current.window.cursor
|
||||
line = vim.current.buffer[row-1]
|
||||
index = idehelper.findBase(line, col)
|
||||
vim.command('let g:pysmell_origCol = %d' % col)
|
||||
vim.command('let g:pysmell_origLine = %r' % line)
|
||||
vim.command('return %d' % index)
|
||||
eopython
|
||||
"findstart = 0 when we need to return the list of completions
|
||||
else
|
||||
let g:pysmell_args = 0
|
||||
let g:pysmell_completions = []
|
||||
python << eopython
|
||||
origCol = int(vim.eval('g:pysmell_origCol'))
|
||||
origLine = vim.eval('g:pysmell_origLine')
|
||||
origSourceLines = vim.current.buffer[:]
|
||||
lineno = vim.current.window.cursor[0]
|
||||
origSourceLines[lineno - 1] = origLine
|
||||
origSource = '\n'.join(origSourceLines)
|
||||
vimcompletePYSMELL(origSource, lineno, origCol, vim.eval("a:base"))
|
||||
|
||||
eopython
|
||||
return g:pysmell_completions
|
||||
endif
|
||||
endfunction
|
||||
|
||||
python << eopython
|
||||
def vimcompletePYSMELL(origSource, origLineNo, origCol, base):
|
||||
fullPath = vim.current.buffer.name
|
||||
PYSMELLDICT = idehelper.findPYSMELLDICT(fullPath)
|
||||
if not PYSMELLDICT:
|
||||
vim.command("echoerr 'No PYSMELLTAGS found. You have to generate one.'")
|
||||
return
|
||||
|
||||
try:
|
||||
options = idehelper.detectCompletionType(fullPath, origSource, origLineNo, origCol, base, PYSMELLDICT)
|
||||
except:
|
||||
f = file('pysmell_exc.txt', 'wb')
|
||||
import traceback
|
||||
f.write(traceback.format_exc())
|
||||
f.close()
|
||||
vim.command("echoerr 'Exception written out at pysmell_exc.txt'")
|
||||
return
|
||||
|
||||
if int(vim.eval('g:pysmell_debug')):
|
||||
for b in vim.buffers:
|
||||
if b.name.endswith('PYSMELL_DEBUG'):
|
||||
b.append("%s %s %s %s" % (fullPath, origSource[origLineNo], origCol, base))
|
||||
b.append("%r" % options)
|
||||
break
|
||||
|
||||
completions = idehelper.findCompletions(base, PYSMELLDICT, options, vim.eval('g:pysmell_matcher'))
|
||||
output = repr(completions)
|
||||
translated = output.translate(TRANSLATEQUOTES)
|
||||
vim.command('let g:pysmell_completions = %s' % (translated, ))
|
||||
|
||||
eopython
|
||||
507
plugin/showmarks.vim
Normal file
507
plugin/showmarks.vim
Normal file
@@ -0,0 +1,507 @@
|
||||
" ==============================================================================
|
||||
" Name: ShowMarks
|
||||
" Description: Visually displays the location of marks.
|
||||
" Authors: Anthony Kruize <trandor@labyrinth.net.au>
|
||||
" Michael Geddes <michaelrgeddes@optushome.com.au>
|
||||
" Version: 2.2
|
||||
" Modified: 17 August 2004
|
||||
" License: Released into the public domain.
|
||||
" ChangeLog: See :help showmarks-changelog
|
||||
"
|
||||
" Usage: Copy this file into the plugins directory so it will be
|
||||
" automatically sourced.
|
||||
"
|
||||
" Default keymappings are:
|
||||
" <Leader>mt - Toggles ShowMarks on and off.
|
||||
" <Leader>mo - Turns ShowMarks on, and displays marks.
|
||||
" <Leader>mh - Clears a mark.
|
||||
" <Leader>ma - Clears all marks.
|
||||
" <Leader>mm - Places the next available mark.
|
||||
"
|
||||
" Hiding a mark doesn't actually remove it, it simply moves it
|
||||
" to line 1 and hides it visually.
|
||||
"
|
||||
" Configuration: ***********************************************************
|
||||
" * PLEASE read the included help file(showmarks.txt) for a *
|
||||
" * more thorough explanation of how to use ShowMarks. *
|
||||
" ***********************************************************
|
||||
" The following options can be used to customize the behavior
|
||||
" of ShowMarks. Simply include them in your vimrc file with
|
||||
" the desired settings.
|
||||
"
|
||||
" showmarks_enable (Default: 1)
|
||||
" Defines whether ShowMarks is enabled by default.
|
||||
" Example: let g:showmarks_enable=0
|
||||
" showmarks_include (Default: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.'`^<>[]{}()\"")
|
||||
" Defines all marks, in precedence order (only the highest
|
||||
" precence will show on lines having more than one mark).
|
||||
" Can be buffer-specific (set b:showmarks_include)
|
||||
" showmarks_ignore_type (Default: "hq")
|
||||
" Defines the buffer types to be ignored.
|
||||
" Valid types are:
|
||||
" h - Help p - preview
|
||||
" q - quickfix r - readonly
|
||||
" m - non-modifiable
|
||||
" showmarks_textlower (Default: ">")
|
||||
" Defines how the mark is to be displayed.
|
||||
" A maximum of two characters can be displayed. To include
|
||||
" the mark in the text use a tab(\t) character. A single
|
||||
" character will display as the mark with the character
|
||||
" suffixed (same as "\t<character>")
|
||||
" Examples:
|
||||
" To display the mark with a > suffixed:
|
||||
" let g:showmarks_textlower="\t>"
|
||||
" or
|
||||
" let g:showmarks_textlower=">"
|
||||
" To display the mark with a ( prefixed:
|
||||
" let g:showmarks_textlower="(\t"
|
||||
" To display two > characters:
|
||||
" let g:showmarks_textlower=">>"
|
||||
" showmarks_textupper (Default: ">")
|
||||
" Same as above but for the marks A-Z.
|
||||
" Example: let g:showmarks_textupper="**"
|
||||
" showmarks_textother (Default: ">")
|
||||
" Same as above but for all other marks.
|
||||
" Example: let g:showmarks_textother="--"
|
||||
" showmarks_hlline_lower (Default: 0)
|
||||
" showmarks_hlline_upper (Default: 0)
|
||||
" showmarks_hlline_other (Default: 0)
|
||||
" Defines whether the entire line for a particular mark
|
||||
" should be highlighted.
|
||||
" Example: let g:showmarks_hlline_lower=1
|
||||
"
|
||||
" Setting Highlighting Colours
|
||||
" ShowMarks uses the following highlighting groups:
|
||||
" ShowMarksHLl - For marks a-z
|
||||
" ShowMarksHLu - For marks A-Z
|
||||
" ShowMarksHLo - For all other marks
|
||||
" ShowMarksHLm - For multiple marks on the same line.
|
||||
" (Highest precendece mark is shown)
|
||||
"
|
||||
" By default they are set to a bold blue on light blue.
|
||||
" Defining a highlight for each of these groups will
|
||||
" override the default highlighting.
|
||||
" See the VIM help for more information about highlighting.
|
||||
" ==============================================================================
|
||||
|
||||
" Check if we should continue loading
|
||||
if exists( "loaded_showmarks" )
|
||||
finish
|
||||
endif
|
||||
let loaded_showmarks = 1
|
||||
|
||||
" Bail if Vim isn't compiled with signs support.
|
||||
if has( "signs" ) == 0
|
||||
echohl ErrorMsg
|
||||
echo "ShowMarks requires Vim to have +signs support."
|
||||
echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
" Options: Set up some nice defaults
|
||||
if !exists('g:showmarks_enable' ) | let g:showmarks_enable = 1 | endif
|
||||
if !exists('g:showmarks_textlower' ) | let g:showmarks_textlower = ">" | endif
|
||||
if !exists('g:showmarks_textupper' ) | let g:showmarks_textupper = ">" | endif
|
||||
if !exists('g:showmarks_textother' ) | let g:showmarks_textother = ">" | endif
|
||||
if !exists('g:showmarks_ignore_type' ) | let g:showmarks_ignore_type = "hq" | endif
|
||||
if !exists('g:showmarks_ignore_name' ) | let g:showmarks_ignore_name = "" | endif
|
||||
if !exists('g:showmarks_hlline_lower') | let g:showmarks_hlline_lower = "0" | endif
|
||||
if !exists('g:showmarks_hlline_upper') | let g:showmarks_hlline_upper = "0" | endif
|
||||
if !exists('g:showmarks_hlline_other') | let g:showmarks_hlline_other = "0" | endif
|
||||
|
||||
" This is the default, and used in ShowMarksSetup to set up info for any
|
||||
" possible mark (not just those specified in the possibly user-supplied list
|
||||
" of marks to show -- it can be changed on-the-fly).
|
||||
let s:all_marks = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.'`^<>[]{}()\""
|
||||
|
||||
" Commands
|
||||
com! -nargs=0 ShowMarksToggle :call <sid>ShowMarksToggle()
|
||||
com! -nargs=0 ShowMarksOn :call <sid>ShowMarksOn()
|
||||
com! -nargs=0 ShowMarksClearMark :call <sid>ShowMarksClearMark()
|
||||
com! -nargs=0 ShowMarksClearAll :call <sid>ShowMarksClearAll()
|
||||
com! -nargs=0 ShowMarksPlaceMark :call <sid>ShowMarksPlaceMark()
|
||||
|
||||
" Mappings (NOTE: Leave the '|'s immediately following the '<cr>' so the mapping does not contain any trailing spaces!)
|
||||
if !hasmapto( '<Plug>ShowmarksShowMarksToggle' ) | map <silent> <unique> <leader>mt :ShowMarksToggle<cr>| endif
|
||||
if !hasmapto( '<Plug>ShowmarksShowMarksOn' ) | map <silent> <unique> <leader>mo :ShowMarksOn<cr>| endif
|
||||
if !hasmapto( '<Plug>ShowmarksClearMark' ) | map <silent> <unique> <leader>mh :ShowMarksClearMark<cr>| endif
|
||||
if !hasmapto( '<Plug>ShowmarksClearAll' ) | map <silent> <unique> <leader>ma :ShowMarksClearAll<cr>| endif
|
||||
if !hasmapto( '<Plug>ShowmarksPlaceMark' ) | map <silent> <unique> <leader>mm :ShowMarksPlaceMark<cr>| endif
|
||||
noremap <unique> <script> \sm m
|
||||
noremap <silent> m :exe 'norm \sm'.nr2char(getchar())<bar>call <sid>ShowMarks()<CR>
|
||||
|
||||
" AutoCommands: Only if ShowMarks is enabled
|
||||
if g:showmarks_enable == 1
|
||||
aug ShowMarks
|
||||
au!
|
||||
autocmd CursorHold * call s:ShowMarks()
|
||||
aug END
|
||||
endif
|
||||
|
||||
" Highlighting: Setup some nice colours to show the mark positions.
|
||||
hi default ShowMarksHLl ctermfg=darkblue ctermbg=blue cterm=bold guifg=blue guibg=lightblue gui=bold
|
||||
hi default ShowMarksHLu ctermfg=darkblue ctermbg=blue cterm=bold guifg=blue guibg=lightblue gui=bold
|
||||
hi default ShowMarksHLo ctermfg=darkblue ctermbg=blue cterm=bold guifg=blue guibg=lightblue gui=bold
|
||||
hi default ShowMarksHLm ctermfg=darkblue ctermbg=blue cterm=bold guifg=blue guibg=lightblue gui=bold
|
||||
|
||||
" Function: IncludeMarks()
|
||||
" Description: This function returns the list of marks (in priority order) to
|
||||
" show in this buffer. Each buffer, if not already set, inherits the global
|
||||
" setting; if the global include marks have not been set; that is set to the
|
||||
" default value.
|
||||
fun! s:IncludeMarks()
|
||||
if exists('b:showmarks_include') && exists('b:showmarks_previous_include') && b:showmarks_include != b:showmarks_previous_include
|
||||
" The user changed the marks to include; hide all marks; change the
|
||||
" included mark list, then show all marks. Prevent infinite
|
||||
" recursion during this switch.
|
||||
if exists('s:use_previous_include')
|
||||
" Recursive call from ShowMarksHideAll()
|
||||
return b:showmarks_previous_include
|
||||
elseif exists('s:use_new_include')
|
||||
" Recursive call from ShowMarks()
|
||||
return b:showmarks_include
|
||||
else
|
||||
let s:use_previous_include = 1
|
||||
call <sid>ShowMarksHideAll()
|
||||
unlet s:use_previous_include
|
||||
let s:use_new_include = 1
|
||||
call <sid>ShowMarks()
|
||||
unlet s:use_new_include
|
||||
endif
|
||||
endif
|
||||
|
||||
if !exists('g:showmarks_include')
|
||||
let g:showmarks_include = s:all_marks
|
||||
endif
|
||||
if !exists('b:showmarks_include')
|
||||
let b:showmarks_include = g:showmarks_include
|
||||
endif
|
||||
|
||||
" Save this include setting so we can detect if it was changed.
|
||||
let b:showmarks_previous_include = b:showmarks_include
|
||||
|
||||
return b:showmarks_include
|
||||
endf
|
||||
|
||||
" Function: NameOfMark()
|
||||
" Paramaters: mark - Specifies the mark to find the name of.
|
||||
" Description: Convert marks that cannot be used as part of a variable name to
|
||||
" something that can be. i.e. We cannot use [ as a variable-name suffix (as
|
||||
" in 'placed_['; this function will return something like 63, so the variable
|
||||
" will be something like 'placed_63').
|
||||
" 10 is added to the mark's index to avoid colliding with the numeric marks
|
||||
" 0-9 (since a non-word mark could be listed in showmarks_include in the
|
||||
" first 10 characters if the user overrides the default).
|
||||
" Returns: The name of the requested mark.
|
||||
fun! s:NameOfMark(mark)
|
||||
let name = a:mark
|
||||
if a:mark =~# '\W'
|
||||
let name = stridx(s:all_marks, a:mark) + 10
|
||||
endif
|
||||
return name
|
||||
endf
|
||||
|
||||
" Function: VerifyText()
|
||||
" Paramaters: which - Specifies the variable to verify.
|
||||
" Description: Verify the validity of a showmarks_text{upper,lower,other} setup variable.
|
||||
" Default to ">" if it is found to be invalid.
|
||||
fun! s:VerifyText(which)
|
||||
if strlen(g:showmarks_text{a:which}) == 0 || strlen(g:showmarks_text{a:which}) > 2
|
||||
echohl ErrorMsg
|
||||
echo "ShowMarks: text".a:which." must contain only 1 or 2 characters."
|
||||
echohl None
|
||||
let g:showmarks_text{a:which}=">"
|
||||
endif
|
||||
endf
|
||||
|
||||
" Function: ShowMarksSetup()
|
||||
" Description: This function sets up the sign definitions for each mark.
|
||||
" It uses the showmarks_textlower, showmarks_textupper and showmarks_textother
|
||||
" variables to determine how to draw the mark.
|
||||
fun! s:ShowMarksSetup()
|
||||
" Make sure the textlower, textupper, and textother options are valid.
|
||||
call s:VerifyText('lower')
|
||||
call s:VerifyText('upper')
|
||||
call s:VerifyText('other')
|
||||
|
||||
let n = 0
|
||||
let s:maxmarks = strlen(s:all_marks)
|
||||
while n < s:maxmarks
|
||||
let c = strpart(s:all_marks, n, 1)
|
||||
let nm = s:NameOfMark(c)
|
||||
let text = '>'.c
|
||||
let lhltext = ''
|
||||
if c =~# '[a-z]'
|
||||
if strlen(g:showmarks_textlower) == 1
|
||||
let text=c.g:showmarks_textlower
|
||||
elseif strlen(g:showmarks_textlower) == 2
|
||||
let t1 = strpart(g:showmarks_textlower,0,1)
|
||||
let t2 = strpart(g:showmarks_textlower,1,1)
|
||||
if t1 == "\t"
|
||||
let text=c.t2
|
||||
elseif t2 == "\t"
|
||||
let text=t1.c
|
||||
else
|
||||
let text=g:showmarks_textlower
|
||||
endif
|
||||
endif
|
||||
let s:ShowMarksDLink{nm} = 'ShowMarksHLl'
|
||||
if g:showmarks_hlline_lower == 1
|
||||
let lhltext = 'linehl='.s:ShowMarksDLink{nm}.nm
|
||||
endif
|
||||
elseif c =~# '[A-Z]'
|
||||
if strlen(g:showmarks_textupper) == 1
|
||||
let text=c.g:showmarks_textupper
|
||||
elseif strlen(g:showmarks_textupper) == 2
|
||||
let t1 = strpart(g:showmarks_textupper,0,1)
|
||||
let t2 = strpart(g:showmarks_textupper,1,1)
|
||||
if t1 == "\t"
|
||||
let text=c.t2
|
||||
elseif t2 == "\t"
|
||||
let text=t1.c
|
||||
else
|
||||
let text=g:showmarks_textupper
|
||||
endif
|
||||
endif
|
||||
let s:ShowMarksDLink{nm} = 'ShowMarksHLu'
|
||||
if g:showmarks_hlline_upper == 1
|
||||
let lhltext = 'linehl='.s:ShowMarksDLink{nm}.nm
|
||||
endif
|
||||
else " Other signs, like ', ., etc.
|
||||
if strlen(g:showmarks_textother) == 1
|
||||
let text=c.g:showmarks_textother
|
||||
elseif strlen(g:showmarks_textother) == 2
|
||||
let t1 = strpart(g:showmarks_textother,0,1)
|
||||
let t2 = strpart(g:showmarks_textother,1,1)
|
||||
if t1 == "\t"
|
||||
let text=c.t2
|
||||
elseif t2 == "\t"
|
||||
let text=t1.c
|
||||
else
|
||||
let text=g:showmarks_textother
|
||||
endif
|
||||
endif
|
||||
let s:ShowMarksDLink{nm} = 'ShowMarksHLo'
|
||||
if g:showmarks_hlline_other == 1
|
||||
let lhltext = 'linehl='.s:ShowMarksDLink{nm}.nm
|
||||
endif
|
||||
endif
|
||||
|
||||
" Define the sign with a unique highlight which will be linked when placed.
|
||||
exe 'sign define ShowMark'.nm.' '.lhltext.' text='.text.' texthl='.s:ShowMarksDLink{nm}.nm
|
||||
let b:ShowMarksLink{nm} = ''
|
||||
let n = n + 1
|
||||
endw
|
||||
endf
|
||||
|
||||
" Set things up
|
||||
call s:ShowMarksSetup()
|
||||
|
||||
" Function: ShowMarksOn
|
||||
" Description: Enable showmarks, and show them now.
|
||||
fun! s:ShowMarksOn()
|
||||
if g:showmarks_enable == 0
|
||||
call <sid>ShowMarksToggle()
|
||||
else
|
||||
call <sid>ShowMarks()
|
||||
endif
|
||||
endf
|
||||
|
||||
" Function: ShowMarksToggle()
|
||||
" Description: This function toggles whether marks are displayed or not.
|
||||
fun! s:ShowMarksToggle()
|
||||
if g:showmarks_enable == 0
|
||||
let g:showmarks_enable = 1
|
||||
call <sid>ShowMarks()
|
||||
aug ShowMarks
|
||||
au!
|
||||
autocmd CursorHold * call s:ShowMarks()
|
||||
aug END
|
||||
else
|
||||
let g:showmarks_enable = 0
|
||||
call <sid>ShowMarksHideAll()
|
||||
aug ShowMarks
|
||||
au!
|
||||
autocmd BufEnter * call s:ShowMarksHideAll()
|
||||
aug END
|
||||
endif
|
||||
endf
|
||||
|
||||
" Function: ShowMarks()
|
||||
" Description: This function runs through all the marks and displays or
|
||||
" removes signs as appropriate. It is called on the CursorHold autocommand.
|
||||
" We use the marked_{ln} variables (containing a timestamp) to track what marks
|
||||
" we've shown (placed) in this call to ShowMarks; to only actually place the
|
||||
" first mark on any particular line -- this forces only the first mark
|
||||
" (according to the order of showmarks_include) to be shown (i.e., letters
|
||||
" take precedence over marks like paragraph and sentence.)
|
||||
fun! s:ShowMarks()
|
||||
if g:showmarks_enable == 0
|
||||
return
|
||||
endif
|
||||
|
||||
if ((match(g:showmarks_ignore_type, "[Hh]") > -1) && (&buftype == "help" ))
|
||||
\ || ((match(g:showmarks_ignore_type, "[Qq]") > -1) && (&buftype == "quickfix"))
|
||||
\ || ((match(g:showmarks_ignore_type, "[Pp]") > -1) && (&pvw == 1 ))
|
||||
\ || ((match(g:showmarks_ignore_type, "[Rr]") > -1) && (&readonly == 1 ))
|
||||
\ || ((match(g:showmarks_ignore_type, "[Mm]") > -1) && (&modifiable == 0 ))
|
||||
return
|
||||
endif
|
||||
|
||||
let n = 0
|
||||
let s:maxmarks = strlen(s:IncludeMarks())
|
||||
while n < s:maxmarks
|
||||
let c = strpart(s:IncludeMarks(), n, 1)
|
||||
let nm = s:NameOfMark(c)
|
||||
let id = n + (s:maxmarks * winbufnr(0))
|
||||
let ln = line("'".c)
|
||||
|
||||
if ln == 0 && (exists('b:placed_'.nm) && b:placed_{nm} != ln)
|
||||
exe 'sign unplace '.id.' buffer='.winbufnr(0)
|
||||
elseif ln > 1 || c !~ '[a-zA-Z]'
|
||||
" Have we already placed a mark here in this call to ShowMarks?
|
||||
if exists('mark_at'.ln)
|
||||
" Already placed a mark, set the highlight to multiple
|
||||
if c =~# '[a-zA-Z]' && b:ShowMarksLink{mark_at{ln}} != 'ShowMarksHLm'
|
||||
let b:ShowMarksLink{mark_at{ln}} = 'ShowMarksHLm'
|
||||
exe 'hi link '.s:ShowMarksDLink{mark_at{ln}}.mark_at{ln}.' '.b:ShowMarksLink{mark_at{ln}}
|
||||
endif
|
||||
else
|
||||
if !exists('b:ShowMarksLink'.nm) || b:ShowMarksLink{nm} != s:ShowMarksDLink{nm}
|
||||
let b:ShowMarksLink{nm} = s:ShowMarksDLink{nm}
|
||||
exe 'hi link '.s:ShowMarksDLink{nm}.nm.' '.b:ShowMarksLink{nm}
|
||||
endif
|
||||
let mark_at{ln} = nm
|
||||
if !exists('b:placed_'.nm) || b:placed_{nm} != ln
|
||||
exe 'sign unplace '.id.' buffer='.winbufnr(0)
|
||||
exe 'sign place '.id.' name=ShowMark'.nm.' line='.ln.' buffer='.winbufnr(0)
|
||||
let b:placed_{nm} = ln
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
let n = n + 1
|
||||
endw
|
||||
endf
|
||||
|
||||
" Function: ShowMarksClearMark()
|
||||
" Description: This function hides the mark at the current line.
|
||||
" It simply moves the mark to line 1 and removes the sign.
|
||||
" Only marks a-z and A-Z are supported.
|
||||
fun! s:ShowMarksClearMark()
|
||||
let ln = line(".")
|
||||
let n = 0
|
||||
let s:maxmarks = strlen(s:IncludeMarks())
|
||||
while n < s:maxmarks
|
||||
let c = strpart(s:IncludeMarks(), n, 1)
|
||||
if c =~# '[a-zA-Z]' && ln == line("'".c)
|
||||
let nm = s:NameOfMark(c)
|
||||
let id = n + (s:maxmarks * winbufnr(0))
|
||||
exe 'sign unplace '.id.' buffer='.winbufnr(0)
|
||||
exe '1 mark '.c
|
||||
let b:placed_{nm} = 1
|
||||
endif
|
||||
let n = n + 1
|
||||
endw
|
||||
endf
|
||||
|
||||
" Function: ShowMarksClearAll()
|
||||
" Description: This function clears all marks in the buffer.
|
||||
" It simply moves the marks to line 1 and removes the signs.
|
||||
" Only marks a-z and A-Z are supported.
|
||||
fun! s:ShowMarksClearAll()
|
||||
let n = 0
|
||||
let s:maxmarks = strlen(s:IncludeMarks())
|
||||
while n < s:maxmarks
|
||||
let c = strpart(s:IncludeMarks(), n, 1)
|
||||
if c =~# '[a-zA-Z]'
|
||||
let nm = s:NameOfMark(c)
|
||||
let id = n + (s:maxmarks * winbufnr(0))
|
||||
exe 'sign unplace '.id.' buffer='.winbufnr(0)
|
||||
exe '1 mark '.c
|
||||
let b:placed_{nm} = 1
|
||||
endif
|
||||
let n = n + 1
|
||||
endw
|
||||
endf
|
||||
|
||||
" Function: ShowMarksHideAll()
|
||||
" Description: This function hides all marks in the buffer.
|
||||
" It simply removes the signs.
|
||||
fun! s:ShowMarksHideAll()
|
||||
let n = 0
|
||||
let s:maxmarks = strlen(s:IncludeMarks())
|
||||
while n < s:maxmarks
|
||||
let c = strpart(s:IncludeMarks(), n, 1)
|
||||
let nm = s:NameOfMark(c)
|
||||
if exists('b:placed_'.nm)
|
||||
let id = n + (s:maxmarks * winbufnr(0))
|
||||
exe 'sign unplace '.id.' buffer='.winbufnr(0)
|
||||
unlet b:placed_{nm}
|
||||
endif
|
||||
let n = n + 1
|
||||
endw
|
||||
endf
|
||||
|
||||
" Function: ShowMarksPlaceMark()
|
||||
" Description: This function will place the next unplaced mark (in priority
|
||||
" order) to the current location. The idea here is to automate the placement
|
||||
" of marks so the user doesn't have to remember which marks are placed or not.
|
||||
" Hidden marks are considered to be unplaced.
|
||||
" Only marks a-z are supported.
|
||||
fun! s:ShowMarksPlaceMark()
|
||||
" Find the first, next, and last [a-z] mark in showmarks_include (i.e.
|
||||
" priority order), so we know where to "wrap".
|
||||
let first_alpha_mark = -1
|
||||
let last_alpha_mark = -1
|
||||
let next_mark = -1
|
||||
|
||||
if !exists('b:previous_auto_mark')
|
||||
let b:previous_auto_mark = -1
|
||||
endif
|
||||
|
||||
" Find the next unused [a-z] mark (in priority order); if they're all
|
||||
" used, find the next one after the previously auto-assigned mark.
|
||||
let n = 0
|
||||
let s:maxmarks = strlen(s:IncludeMarks())
|
||||
while n < s:maxmarks
|
||||
let c = strpart(s:IncludeMarks(), n, 1)
|
||||
if c =~# '[a-z]'
|
||||
if line("'".c) <= 1
|
||||
" Found an unused [a-z] mark; we're done.
|
||||
let next_mark = n
|
||||
break
|
||||
endif
|
||||
|
||||
if first_alpha_mark < 0
|
||||
let first_alpha_mark = n
|
||||
endif
|
||||
let last_alpha_mark = n
|
||||
if n > b:previous_auto_mark && next_mark == -1
|
||||
let next_mark = n
|
||||
endif
|
||||
endif
|
||||
let n = n + 1
|
||||
endw
|
||||
|
||||
if next_mark == -1 && (b:previous_auto_mark == -1 || b:previous_auto_mark == last_alpha_mark)
|
||||
" Didn't find an unused mark, and haven't placed any auto-chosen marks yet,
|
||||
" or the previously placed auto-chosen mark was the last alpha mark --
|
||||
" use the first alpha mark this time.
|
||||
let next_mark = first_alpha_mark
|
||||
endif
|
||||
|
||||
if (next_mark == -1)
|
||||
echohl WarningMsg
|
||||
echo 'No marks in [a-z] included! (No "next mark" to choose from)'
|
||||
echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let c = strpart(s:IncludeMarks(), next_mark, 1)
|
||||
let b:previous_auto_mark = next_mark
|
||||
exe 'mark '.c
|
||||
call <sid>ShowMarks()
|
||||
endf
|
||||
|
||||
" -----------------------------------------------------------------------------
|
||||
" vim:ts=4:sw=4:noet
|
||||
247
plugin/snipMate.vim
Normal file
247
plugin/snipMate.vim
Normal 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
|
||||
4546
plugin/taglist.vim
Normal file
4546
plugin/taglist.vim
Normal file
File diff suppressed because it is too large
Load Diff
375
plugin/tasklist.vim
Normal file
375
plugin/tasklist.vim
Normal file
@@ -0,0 +1,375 @@
|
||||
"------------------------------------------------------------------------------
|
||||
" Name Of File: tasklist.vim
|
||||
"
|
||||
" Description: Vim plugin to search for a list of tokens and display a
|
||||
" window with matches.
|
||||
"
|
||||
" Author: Juan Frias (juandfrias at gmail.com)
|
||||
"
|
||||
" Last Change: 2009 Apr 11
|
||||
" Version: 1.0.1
|
||||
"
|
||||
" Copyright: Permission is hereby granted to use and distribute this code,
|
||||
" with or without modifications, provided that this header
|
||||
" is included with it.
|
||||
"
|
||||
" This script is to be distributed freely in the hope that it
|
||||
" will be useful, but is provided 'as is' and without warranties
|
||||
" as to performance of merchantability or any other warranties
|
||||
" whether expressed or implied. Because of the various hardware
|
||||
" and software environments into which this script may be put,
|
||||
" no warranty of fitness for a particular purpose is offered.
|
||||
"
|
||||
" GOOD DATA PROCESSING PROCEDURE DICTATES THAT ANY SCRIPT BE
|
||||
" THOROUGHLY TESTED WITH NON-CRITICAL DATA BEFORE RELYING ON IT.
|
||||
"
|
||||
" THE USER MUST ASSUME THE ENTIRE RISK OF USING THE SCRIPT.
|
||||
"
|
||||
" The author does not retain any liability on any damage caused
|
||||
" through the use of this script.
|
||||
"
|
||||
" Install: 1. Read the section titled 'Options'
|
||||
" 2. Setup any variables need in your vimrc file
|
||||
" 3. Copy 'tasklist.vim' to your plugin directory.
|
||||
"
|
||||
" Mapped Keys: <Leader>t Display list.
|
||||
"
|
||||
" Usage: Start the script with the mapped key, a new window appears
|
||||
" with the matches found, moving around the window will also
|
||||
" update the position of the current document.
|
||||
"
|
||||
" The following keys are mapped to the results window:
|
||||
"
|
||||
" q - Quit, and restore original cursor position.
|
||||
"
|
||||
" e - Exit, and keep results window open note that
|
||||
" movements on the result window will no longer be
|
||||
" updated.
|
||||
"
|
||||
" <cr> - Quit and place the cursor on the selected line.
|
||||
"
|
||||
" Aknowledgments: Many thanks to Zhang Shuhan for taking the time to beta
|
||||
" test and suggest many of the improvements and features
|
||||
" found in the script. I don't think I would have
|
||||
" implemented it wihout his help. Thanks!
|
||||
"
|
||||
"------------------------------------------------------------------------------
|
||||
" Please send me any bugs you find, so I can keep the script up to date.
|
||||
"------------------------------------------------------------------------------
|
||||
|
||||
" History: {{{1
|
||||
"------------------------------------------------------------------------------
|
||||
"
|
||||
" 1.00 Initial version.
|
||||
"
|
||||
" User Options: {{{1
|
||||
"------------------------------------------------------------------------------
|
||||
"
|
||||
" <Leader>t
|
||||
" This is the default key map to view the task list.
|
||||
" to overwrite use something like:
|
||||
" map <leader>v <Plug>TaskList
|
||||
" in your vimrc file
|
||||
"
|
||||
" g:tlWindowPosition
|
||||
" This is specifies the position of the window to be opened. By
|
||||
" default it will open at on top. To overwrite use:
|
||||
" let g:tlWindowPosition = 1
|
||||
" in your vimrc file, options are as follows:
|
||||
" 0 = Open on top
|
||||
" 1 = Open on the bottom
|
||||
"
|
||||
" g:tlTokenList
|
||||
" This is the list of tokens to search for default is
|
||||
" 'FIXME TODO XXX'. The results are groupped and displayed in the
|
||||
" order that they appear. to overwrite use:
|
||||
" let g:tlTokenList = ['TOKEN1', 'TOKEN2', 'TOKEN3']
|
||||
" in your vimrc file
|
||||
"
|
||||
" g:tlRememberPosition
|
||||
" If this is set to 1 then the script will try to get back to the
|
||||
" position where it last was closed. By default it will find the line
|
||||
" closest to the current cursor position.
|
||||
" to overwrite use:
|
||||
" let g:tlRememberPosition = 1
|
||||
" in your vimrc file
|
||||
"
|
||||
|
||||
" Global variables: {{{1
|
||||
"------------------------------------------------------------------------------
|
||||
|
||||
" Load script once
|
||||
"------------------------------------------------------------------------------
|
||||
if exists("g:loaded_tasklist") || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_tasklist = 1
|
||||
|
||||
" Set where the window opens
|
||||
"------------------------------------------------------------------------------
|
||||
if !exists('g:tlWindowPosition')
|
||||
" 0 = Open at top
|
||||
let g:tlWindowPosition = 0
|
||||
endif
|
||||
|
||||
" Set the token list
|
||||
"------------------------------------------------------------------------------
|
||||
if !exists('g:tlTokenList')
|
||||
" default list of tokens
|
||||
let g:tlTokenList = ["FIXME", "TODO", "XXX"]
|
||||
endif
|
||||
|
||||
" Remember position
|
||||
"------------------------------------------------------------------------------
|
||||
if !exists('g:tlRememberPosition')
|
||||
" 0 = Donot remember, find closest match
|
||||
let g:tlRememberPosition = 0
|
||||
endif
|
||||
|
||||
" Script variables: {{{1
|
||||
"------------------------------------------------------------------------------
|
||||
|
||||
" Function: Open Window {{{1
|
||||
"--------------------------------------------------------------------------
|
||||
function! s:OpenWindow(buffnr, lineno)
|
||||
" Open results window and place items there.
|
||||
if g:tlWindowPosition == 0
|
||||
execute 'sp -TaskList_'.a:buffnr.'-'
|
||||
else
|
||||
execute 'botright sp -TaskList_'.a:buffnr.'-'
|
||||
endif
|
||||
|
||||
let b:original_buffnr = a:buffnr
|
||||
let b:original_line = a:lineno
|
||||
|
||||
set noswapfile
|
||||
set modifiable
|
||||
normal! "zPGddgg
|
||||
set fde=getline(v:lnum)[0]=='L'
|
||||
set foldmethod=expr
|
||||
set foldlevel=0
|
||||
normal! zR
|
||||
|
||||
" Resize line if too big.
|
||||
let l:hits = line("$")
|
||||
if l:hits < winheight(0)
|
||||
sil! exe "resize ".l:hits
|
||||
endif
|
||||
|
||||
" Clean up.
|
||||
let @z = ""
|
||||
set nomodified
|
||||
endfunction
|
||||
|
||||
" Function: Search file {{{1
|
||||
"--------------------------------------------------------------------------
|
||||
function! s:SearchFile(hits, word)
|
||||
" Search at the beginning and keep adding them to the register
|
||||
let l:match_count = 0
|
||||
normal! gg0
|
||||
let l:max = strlen(line('$'))
|
||||
let l:last_match = -1
|
||||
let l:div = 0
|
||||
while search(a:word, "Wc") > 0
|
||||
let l:curr_line = line('.')
|
||||
if l:last_match == l:curr_line
|
||||
if l:curr_line == line('$')
|
||||
break
|
||||
endif
|
||||
normal! j0
|
||||
continue
|
||||
endif
|
||||
let l:last_match = l:curr_line
|
||||
if foldlevel(l:curr_line) != 0
|
||||
normal! 99zo
|
||||
endif
|
||||
if l:div == 0
|
||||
if a:hits != 0
|
||||
let @z = @z."\n"
|
||||
endif
|
||||
let l:div = 1
|
||||
endif
|
||||
normal! 0
|
||||
let l:lineno = ' '.l:curr_line
|
||||
let @z = @z.'Ln '.strpart(l:lineno, strlen(l:lineno) - l:max).': '
|
||||
let l:text = getline(".")
|
||||
let @z = @z.strpart(l:text, stridx(l:text, a:word))
|
||||
let @z = @z."\n"
|
||||
normal! $
|
||||
let l:match_count = l:match_count + 1
|
||||
endwhile
|
||||
return l:match_count
|
||||
endfunction
|
||||
|
||||
" Function: Get line number {{{1
|
||||
"--------------------------------------------------------------------------
|
||||
function! s:LineNumber()
|
||||
let l:text = getline(".")
|
||||
if strpart(l:text, 0, 5) == "File:"
|
||||
return 0
|
||||
endif
|
||||
if strlen(l:text) == 0
|
||||
return -1
|
||||
endif
|
||||
let l:num = matchstr(l:text, '[0-9]\+')
|
||||
if l:num == ''
|
||||
return -1
|
||||
endif
|
||||
return l:num
|
||||
endfunction
|
||||
|
||||
" Function: Update document position {{{1
|
||||
"--------------------------------------------------------------------------
|
||||
function! s:UpdateDoc()
|
||||
let l:line_hit = <sid>LineNumber()
|
||||
|
||||
match none
|
||||
if l:line_hit == -1
|
||||
redraw
|
||||
return
|
||||
endif
|
||||
|
||||
let l:buffnr = b:original_buffnr
|
||||
exe 'match Search /\%'.line(".").'l.*/'
|
||||
if line(".") < (line("$") - (winheight(0) / 2)) + 1
|
||||
normal! zz
|
||||
endif
|
||||
execute bufwinnr(l:buffnr)." wincmd w"
|
||||
match none
|
||||
if l:line_hit == 0
|
||||
normal! 1G
|
||||
else
|
||||
exe "normal! ".l:line_hit."Gzz"
|
||||
exe 'match Search /\%'.line(".").'l.*/'
|
||||
endif
|
||||
execute bufwinnr('-TaskList_'.l:buffnr.'-')." wincmd w"
|
||||
redraw
|
||||
endfunction
|
||||
|
||||
" Function: Clean up on exit {{{1
|
||||
"--------------------------------------------------------------------------
|
||||
function! s:Exit(key)
|
||||
|
||||
call <sid>UpdateDoc()
|
||||
match none
|
||||
|
||||
let l:original_line = b:original_line
|
||||
let l:last_position = line('.')
|
||||
|
||||
if a:key == -1
|
||||
nunmap <buffer> e
|
||||
nunmap <buffer> q
|
||||
nunmap <buffer> <cr>
|
||||
execute bufwinnr(b:original_buffnr)." wincmd w"
|
||||
else
|
||||
bd!
|
||||
endif
|
||||
|
||||
let b:last_position = l:last_position
|
||||
|
||||
if a:key == 0
|
||||
exe "normal! ".l:original_line."G"
|
||||
endif
|
||||
|
||||
match none
|
||||
normal! zz
|
||||
|
||||
execute "set updatetime=".s:old_updatetime
|
||||
endfunction
|
||||
|
||||
" Function: Check for screen update {{{1
|
||||
"--------------------------------------------------------------------------
|
||||
function! s:CheckForUpdate()
|
||||
if stridx(expand("%:t"), '-TaskList_') == -1
|
||||
return
|
||||
endif
|
||||
if b:selected_line != line(".")
|
||||
call <sid>UpdateDoc()
|
||||
let b:selected_line = line(".")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: Start the search. {{{1
|
||||
"--------------------------------------------------------------------------
|
||||
function! s:TaskList()
|
||||
let l:original_buffnr = bufnr('%')
|
||||
let l:original_line = line(".")
|
||||
|
||||
" last position
|
||||
if !exists('b:last_position')
|
||||
let b:last_position = 1
|
||||
endif
|
||||
let l:last_position = b:last_position
|
||||
|
||||
|
||||
" get file name
|
||||
let @z = "File:".expand("%:p")."\n\n"
|
||||
|
||||
" search file
|
||||
let l:index = 0
|
||||
let l:count = 0
|
||||
let l:hits = 0
|
||||
while l:index < len(g:tlTokenList)
|
||||
let l:search_word = g:tlTokenList[l:index]
|
||||
let l:hits = s:SearchFile(l:hits, l:search_word)
|
||||
let l:count = l:count + l:hits
|
||||
let l:index = l:index + 1
|
||||
endwhile
|
||||
|
||||
" Make sure we at least have one hit.
|
||||
if l:count == 0
|
||||
echohl Search
|
||||
echo "tasklist.vim: No task information found."
|
||||
echohl None
|
||||
execute 'normal! '.l:original_line.'G'
|
||||
return
|
||||
endif
|
||||
|
||||
" display window
|
||||
call s:OpenWindow(l:original_buffnr, l:original_line)
|
||||
|
||||
" restore the cursor position
|
||||
if g:tlRememberPosition != 0
|
||||
exec 'normal! '.l:last_position.'G'
|
||||
else
|
||||
normal! gg
|
||||
endif
|
||||
|
||||
" Map exit keys
|
||||
nnoremap <buffer> <silent> q :call <sid>Exit(0)<cr>
|
||||
nnoremap <buffer> <silent> <cr> :call <sid>Exit(1)<cr>
|
||||
nnoremap <buffer> <silent> e :call <sid>Exit(-1)<cr>
|
||||
|
||||
" Setup syntax highlight {{{
|
||||
syntax match tasklistFileDivider /^File:.*$/
|
||||
syntax match tasklistLineNumber /^Ln\s\+\d\+:/
|
||||
|
||||
highlight def link tasklistFileDivider Title
|
||||
highlight def link tasklistLineNumber LineNr
|
||||
highlight def link tasklistSearchWord Search
|
||||
" }}}
|
||||
|
||||
" Save globals and change updatetime
|
||||
let b:selected_line = line(".")
|
||||
let s:old_updatetime = &updatetime
|
||||
set updatetime=350
|
||||
|
||||
" update the doc and hook the CheckForUpdate function.
|
||||
call <sid>UpdateDoc()
|
||||
au! CursorHold <buffer> nested call <sid>CheckForUpdate()
|
||||
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
" Command
|
||||
command! TaskList call s:TaskList()
|
||||
|
||||
" Default key map
|
||||
if !hasmapto('<Plug>TaskList')
|
||||
map <unique> <Leader>T <Plug>TaskList
|
||||
endif
|
||||
|
||||
" Key map to Command
|
||||
nnoremap <unique> <script> <Plug>TaskList :TaskList<CR>
|
||||
|
||||
" vim:fdm=marker:tw=75:ff=unix:
|
||||
263
plugin/vcsbzr.vim
Normal file
263
plugin/vcsbzr.vim
Normal file
@@ -0,0 +1,263 @@
|
||||
" 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 l:save_bzr_log=$BZR_LOG
|
||||
try
|
||||
let $BZR_LOG=has("win32") || has("win95") || has("win64") || has("win16") ? "nul" : "/dev/null"
|
||||
let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . fileName . '"')
|
||||
finally
|
||||
let $BZR_LOG=l:save_bzr_log
|
||||
endtry
|
||||
if(v:shell_error)
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Add() {{{2
|
||||
function! s:bzrFunctions.Add(argList)
|
||||
return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Annotate(argList) {{{2
|
||||
function! s:bzrFunctions.Annotate(argList)
|
||||
if len(a:argList) == 0
|
||||
if &filetype == 'BZRannotate'
|
||||
" Perform annotation of the version indicated by the current line.
|
||||
let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
|
||||
let options = ' -r' . caption
|
||||
else
|
||||
let caption = ''
|
||||
let options = ''
|
||||
endif
|
||||
elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
|
||||
let caption = a:argList[0]
|
||||
let options = ' -r' . caption
|
||||
else
|
||||
let caption = join(a:argList, ' ')
|
||||
let options = ' ' . caption
|
||||
endif
|
||||
|
||||
let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {})
|
||||
if resultBuffer > 0
|
||||
normal 1G2dd
|
||||
endif
|
||||
return resultBuffer
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Commit(argList) {{{2
|
||||
function! s:bzrFunctions.Commit(argList)
|
||||
let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
|
||||
if resultBuffer == 0
|
||||
echomsg 'No commit needed.'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Delete() {{{2
|
||||
function! s:bzrFunctions.Delete(argList)
|
||||
return s:DoCommand(join(['rm'] + a:argList, ' '), 'rm', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Diff(argList) {{{2
|
||||
function! s:bzrFunctions.Diff(argList)
|
||||
if len(a:argList) == 0
|
||||
let revOptions = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let revOptions = ['-r' . join(a:argList, '..')]
|
||||
let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
|
||||
else
|
||||
" Pass-through
|
||||
let caption = join(a:argList, ' ')
|
||||
let revOptions = a:argList
|
||||
endif
|
||||
|
||||
return s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {'allowNonZeroExit': 1})
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.GetBufferInfo() {{{2
|
||||
" Provides version control details for the current file. Current version
|
||||
" number and current repository version number are required to be returned by
|
||||
" the vcscommand plugin.
|
||||
" Returns: List of results: [revision, repository]
|
||||
|
||||
function! s:bzrFunctions.GetBufferInfo()
|
||||
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
|
||||
let fileName = resolve(bufname(originalBuffer))
|
||||
let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -S -- "' . fileName . '"')
|
||||
let revision = s:VCSCommandUtility.system(s:Executable() . ' revno -- "' . fileName . '"')
|
||||
if(v:shell_error)
|
||||
return []
|
||||
endif
|
||||
|
||||
" File not under BZR control.
|
||||
if statusText =~ '^?'
|
||||
return ['Unknown']
|
||||
endif
|
||||
|
||||
let [flags, repository] = matchlist(statusText, '^\(.\{3}\)\s\+\(\S\+\)')[1:2]
|
||||
if revision == ''
|
||||
" Error
|
||||
return ['Unknown']
|
||||
elseif flags =~ '^A'
|
||||
return ['New', 'New']
|
||||
else
|
||||
return [revision, repository]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Info(argList) {{{2
|
||||
function! s:bzrFunctions.Info(argList)
|
||||
return s:DoCommand(join(['version-info'] + a:argList, ' '), 'version-info', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Lock(argList) {{{2
|
||||
function! s:bzrFunctions.Lock(argList)
|
||||
echomsg 'bzr lock is not necessary'
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Log() {{{2
|
||||
function! s:bzrFunctions.Log(argList)
|
||||
if len(a:argList) == 0
|
||||
let options = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let options = ['-r' . join(a:argList, ':')]
|
||||
let caption = options[0]
|
||||
else
|
||||
" Pass-through
|
||||
let options = a:argList
|
||||
let caption = join(a:argList, ' ')
|
||||
endif
|
||||
|
||||
let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {})
|
||||
return resultBuffer
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Revert(argList) {{{2
|
||||
function! s:bzrFunctions.Revert(argList)
|
||||
return s:DoCommand('revert', 'revert', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Review(argList) {{{2
|
||||
function! s:bzrFunctions.Review(argList)
|
||||
if len(a:argList) == 0
|
||||
let versiontag = '(current)'
|
||||
let versionOption = ''
|
||||
else
|
||||
let versiontag = a:argList[0]
|
||||
let versionOption = ' -r ' . versiontag . ' '
|
||||
endif
|
||||
|
||||
return s:DoCommand('cat' . versionOption, 'review', versiontag, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Status(argList) {{{2
|
||||
function! s:bzrFunctions.Status(argList)
|
||||
let options = ['-S']
|
||||
if len(a:argList) == 0
|
||||
let options = a:argList
|
||||
endif
|
||||
return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:bzrFunctions.Unlock(argList) {{{2
|
||||
function! s:bzrFunctions.Unlock(argList)
|
||||
echomsg 'bzr unlock is not necessary'
|
||||
endfunction
|
||||
" Function: s:bzrFunctions.Update(argList) {{{2
|
||||
function! s:bzrFunctions.Update(argList)
|
||||
return s:DoCommand('update', 'update', '', {})
|
||||
endfunction
|
||||
|
||||
" Annotate setting {{{2
|
||||
let s:bzrFunctions.AnnotateSplitRegex = '^[^|]\+ | '
|
||||
|
||||
" Section: Plugin Registration {{{1
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('BZR', expand('<sfile>'), s:bzrFunctions, [])
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
1397
plugin/vcscommand.vim
Normal file
1397
plugin/vcscommand.vim
Normal file
File diff suppressed because it is too large
Load Diff
445
plugin/vcscvs.vim
Normal file
445
plugin/vcscvs.vim
Normal file
@@ -0,0 +1,445 @@
|
||||
" vim600: set foldmethod=marker:
|
||||
"
|
||||
" CVS extension for VCSCommand.
|
||||
"
|
||||
" Version: VCS development
|
||||
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
|
||||
" License:
|
||||
" Copyright (c) 2007 Bob Hiestand
|
||||
"
|
||||
" Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
" of this software and associated documentation files (the "Software"), to
|
||||
" deal in the Software without restriction, including without limitation the
|
||||
" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
" sell copies of the Software, and to permit persons to whom the Software is
|
||||
" furnished to do so, subject to the following conditions:
|
||||
"
|
||||
" The above copyright notice and this permission notice shall be included in
|
||||
" all copies or substantial portions of the Software.
|
||||
"
|
||||
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
" IN THE SOFTWARE.
|
||||
"
|
||||
" Section: Documentation {{{1
|
||||
"
|
||||
" Command documentation {{{2
|
||||
"
|
||||
" The following commands only apply to files under CVS source control.
|
||||
"
|
||||
" CVSEdit Performs "cvs edit" on the current file.
|
||||
"
|
||||
" CVSEditors Performs "cvs editors" on the current file.
|
||||
"
|
||||
" CVSUnedit Performs "cvs unedit" on the current file.
|
||||
"
|
||||
" CVSWatch Takes an argument which must be one of [on|off|add|remove].
|
||||
" Performs "cvs watch" with the given argument on the current
|
||||
" file.
|
||||
"
|
||||
" CVSWatchers Performs "cvs watchers" on the current file.
|
||||
"
|
||||
" CVSWatchAdd Alias for "CVSWatch add"
|
||||
"
|
||||
" CVSWatchOn Alias for "CVSWatch on"
|
||||
"
|
||||
" CVSWatchOff Alias for "CVSWatch off"
|
||||
"
|
||||
" CVSWatchRemove Alias for "CVSWatch remove"
|
||||
"
|
||||
" Mapping documentation: {{{2
|
||||
"
|
||||
" By default, a mapping is defined for each command. User-provided mappings
|
||||
" can be used instead by mapping to <Plug>CommandName, for instance:
|
||||
"
|
||||
" nnoremap ,ce <Plug>CVSEdit
|
||||
"
|
||||
" The default mappings are as follow:
|
||||
"
|
||||
" <Leader>ce CVSEdit
|
||||
" <Leader>cE CVSEditors
|
||||
" <Leader>ct CVSUnedit
|
||||
" <Leader>cwv CVSWatchers
|
||||
" <Leader>cwa CVSWatchAdd
|
||||
" <Leader>cwn CVSWatchOn
|
||||
" <Leader>cwf CVSWatchOff
|
||||
" <Leader>cwr CVSWatchRemove
|
||||
"
|
||||
" Options documentation: {{{2
|
||||
"
|
||||
" VCSCommandCVSExec
|
||||
" This variable specifies the CVS executable. If not set, it defaults to
|
||||
" 'cvs' executed from the user's executable path.
|
||||
"
|
||||
" VCSCommandCVSDiffOpt
|
||||
" This variable, if set, determines the options passed to the cvs diff
|
||||
" command. If not set, it defaults to 'u'.
|
||||
|
||||
" Section: Plugin header {{{1
|
||||
|
||||
if exists('VCSCommandDisableAll')
|
||||
finish
|
||||
endif
|
||||
|
||||
if v:version < 700
|
||||
echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime plugin/vcscommand.vim
|
||||
|
||||
if !executable(VCSCommandGetOption('VCSCommandCVSExec', 'cvs'))
|
||||
" CVS is not installed
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:save_cpo=&cpo
|
||||
set cpo&vim
|
||||
|
||||
" Section: Variable initialization {{{1
|
||||
|
||||
let s:cvsFunctions = {}
|
||||
|
||||
" Section: Utility functions {{{1
|
||||
|
||||
" Function: s:Executable() {{{2
|
||||
" Returns the executable used to invoke cvs suitable for use in a shell
|
||||
" command.
|
||||
function! s:Executable()
|
||||
return 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 = s:Executable() . ' ' . a:cmd
|
||||
let ret = VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
|
||||
|
||||
if ret > 0
|
||||
if getline(line('$')) =~ '^cvs \w\+: closing down connection'
|
||||
$d
|
||||
1
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
return ret
|
||||
else
|
||||
throw 'CVS VCSCommand plugin called on non-CVS item.'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:GetRevision() {{{2
|
||||
" Function for retrieving the current buffer's revision number.
|
||||
" Returns: Revision number or an empty string if an error occurs.
|
||||
|
||||
function! s:GetRevision()
|
||||
if !exists('b:VCSCommandBufferInfo')
|
||||
let b:VCSCommandBufferInfo = s:cvsFunctions.GetBufferInfo()
|
||||
endif
|
||||
|
||||
if len(b:VCSCommandBufferInfo) > 0
|
||||
return b:VCSCommandBufferInfo[0]
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Section: VCS function implementations {{{1
|
||||
|
||||
" Function: s:cvsFunctions.Identify(buffer) {{{2
|
||||
function! s:cvsFunctions.Identify(buffer)
|
||||
let fileName = resolve(bufname(a:buffer))
|
||||
if isdirectory(fileName)
|
||||
let directoryName = fileName
|
||||
else
|
||||
let directoryName = fnamemodify(fileName, ':h')
|
||||
endif
|
||||
if strlen(directoryName) > 0
|
||||
let CVSRoot = directoryName . '/CVS/Root'
|
||||
else
|
||||
let CVSRoot = 'CVS/Root'
|
||||
endif
|
||||
if filereadable(CVSRoot)
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Add(argList) {{{2
|
||||
function! s:cvsFunctions.Add(argList)
|
||||
return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Annotate(argList) {{{2
|
||||
function! s:cvsFunctions.Annotate(argList)
|
||||
if len(a:argList) == 0
|
||||
if &filetype == 'CVSannotate'
|
||||
" This is a CVSAnnotate buffer. Perform annotation of the version
|
||||
" indicated by the current line.
|
||||
let caption = matchstr(getline('.'),'\v^[0-9.]+')
|
||||
|
||||
if VCSCommandGetOption('VCSCommandCVSAnnotateParent', 0) != 0
|
||||
if caption != '1.1'
|
||||
let revmaj = matchstr(caption,'\v[0-9.]+\ze\.[0-9]+')
|
||||
let revmin = matchstr(caption,'\v[0-9.]+\.\zs[0-9]+') - 1
|
||||
if revmin == 0
|
||||
" Jump to ancestor branch
|
||||
let caption = matchstr(revmaj,'\v[0-9.]+\ze\.[0-9]+')
|
||||
else
|
||||
let caption = revmaj . "." . revmin
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
let options = ['-r' . caption]
|
||||
else
|
||||
" CVS defaults to pulling HEAD, regardless of current branch.
|
||||
" Therefore, always pass desired revision.
|
||||
let caption = ''
|
||||
let options = ['-r' . s:GetRevision()]
|
||||
endif
|
||||
elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
|
||||
let caption = a:argList[0]
|
||||
let options = ['-r' . caption]
|
||||
else
|
||||
let caption = join(a:argList)
|
||||
let options = a:argList
|
||||
endif
|
||||
|
||||
let resultBuffer = s:DoCommand(join(['-q', 'annotate'] + options), 'annotate', caption, {})
|
||||
if resultBuffer > 0
|
||||
" Remove header lines from standard error
|
||||
silent v/^\d\+\%(\.\d\+\)\+/d
|
||||
endif
|
||||
return resultBuffer
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Commit(argList) {{{2
|
||||
function! s:cvsFunctions.Commit(argList)
|
||||
let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
|
||||
if resultBuffer == 0
|
||||
echomsg 'No commit needed.'
|
||||
endif
|
||||
return resultBuffer
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Delete() {{{2
|
||||
" By default, use the -f option to remove the file first. If options are
|
||||
" passed in, use those instead.
|
||||
function! s:cvsFunctions.Delete(argList)
|
||||
let options = ['-f']
|
||||
let caption = ''
|
||||
if len(a:argList) > 0
|
||||
let options = a:argList
|
||||
let caption = join(a:argList, ' ')
|
||||
endif
|
||||
return s:DoCommand(join(['remove'] + options, ' '), 'delete', caption, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Diff(argList) {{{2
|
||||
function! s:cvsFunctions.Diff(argList)
|
||||
if len(a:argList) == 0
|
||||
let revOptions = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let revOptions = ['-r' . join(a:argList, ' -r')]
|
||||
let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
|
||||
else
|
||||
" Pass-through
|
||||
let caption = join(a:argList, ' ')
|
||||
let revOptions = a:argList
|
||||
endif
|
||||
|
||||
let cvsDiffOpt = VCSCommandGetOption('VCSCommandCVSDiffOpt', 'u')
|
||||
if cvsDiffOpt == ''
|
||||
let diffOptions = []
|
||||
else
|
||||
let diffOptions = ['-' . cvsDiffOpt]
|
||||
endif
|
||||
|
||||
return s:DoCommand(join(['diff'] + diffOptions + revOptions), 'diff', caption, {'allowNonZeroExit': 1})
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.GetBufferInfo() {{{2
|
||||
" Provides version control details for the current file. Current version
|
||||
" number and current repository version number are required to be returned by
|
||||
" the vcscommand plugin. This CVS extension adds branch name to the return
|
||||
" list as well.
|
||||
" Returns: List of results: [revision, repository, branch]
|
||||
|
||||
function! s:cvsFunctions.GetBufferInfo()
|
||||
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
|
||||
let fileName = bufname(originalBuffer)
|
||||
if isdirectory(fileName)
|
||||
let tag = ''
|
||||
if filereadable(fileName . '/CVS/Tag')
|
||||
let tagFile = readfile(fileName . '/CVS/Tag')
|
||||
if len(tagFile) == 1
|
||||
let tag = substitute(tagFile[0], '^T', '', '')
|
||||
endif
|
||||
endif
|
||||
return [tag]
|
||||
endif
|
||||
let realFileName = fnamemodify(resolve(fileName), ':t')
|
||||
if !filereadable(fileName)
|
||||
return ['Unknown']
|
||||
endif
|
||||
let oldCwd = VCSCommandChangeToCurrentFileDir(fileName)
|
||||
try
|
||||
let statusText=s:VCSCommandUtility.system(s:Executable() . ' status -- "' . realFileName . '"')
|
||||
if(v:shell_error)
|
||||
return []
|
||||
endif
|
||||
let revision=substitute(statusText, '^\_.*Working revision:\s*\(\d\+\%(\.\d\+\)\+\|New file!\)\_.*$', '\1', '')
|
||||
|
||||
" We can still be in a CVS-controlled directory without this being a CVS
|
||||
" file
|
||||
if match(revision, '^New file!$') >= 0
|
||||
let revision='New'
|
||||
elseif match(revision, '^\d\+\.\d\+\%(\.\d\+\.\d\+\)*$') <0
|
||||
return ['Unknown']
|
||||
endif
|
||||
|
||||
let branch=substitute(statusText, '^\_.*Sticky Tag:\s\+\(\d\+\%(\.\d\+\)\+\|\a[A-Za-z0-9-_]*\|(none)\).*$', '\1', '')
|
||||
let repository=substitute(statusText, '^\_.*Repository revision:\s*\(\d\+\%(\.\d\+\)\+\|New file!\|No revision control file\)\_.*$', '\1', '')
|
||||
let repository=substitute(repository, '^New file!\|No revision control file$', 'New', '')
|
||||
return [revision, repository, branch]
|
||||
finally
|
||||
call VCSCommandChdir(oldCwd)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Log() {{{2
|
||||
function! s:cvsFunctions.Log(argList)
|
||||
if len(a:argList) == 0
|
||||
let options = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let options = ['-r' . join(a:argList, ':')]
|
||||
let caption = options[0]
|
||||
else
|
||||
" Pass-through
|
||||
let options = a:argList
|
||||
let caption = join(a:argList, ' ')
|
||||
endif
|
||||
|
||||
return s:DoCommand(join(['log'] + options), 'log', caption, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Revert(argList) {{{2
|
||||
function! s:cvsFunctions.Revert(argList)
|
||||
return s:DoCommand('update -C', 'revert', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Review(argList) {{{2
|
||||
function! s:cvsFunctions.Review(argList)
|
||||
if len(a:argList) == 0
|
||||
let versiontag = '(current)'
|
||||
let versionOption = ''
|
||||
else
|
||||
let versiontag = a:argList[0]
|
||||
let versionOption = ' -r ' . versiontag . ' '
|
||||
endif
|
||||
|
||||
return s:DoCommand('-q update -p' . versionOption, 'review', versiontag, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Status(argList) {{{2
|
||||
function! s:cvsFunctions.Status(argList)
|
||||
return s:DoCommand(join(['status'] + a:argList, ' '), 'status', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:cvsFunctions.Update(argList) {{{2
|
||||
function! s:cvsFunctions.Update(argList)
|
||||
return s:DoCommand('update', 'update', '', {})
|
||||
endfunction
|
||||
|
||||
" Section: CVS-specific functions {{{1
|
||||
|
||||
" Function: s:CVSEdit() {{{2
|
||||
function! s:CVSEdit()
|
||||
return s:DoCommand('edit', 'cvsedit', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:CVSEditors() {{{2
|
||||
function! s:CVSEditors()
|
||||
return s:DoCommand('editors', 'cvseditors', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:CVSUnedit() {{{2
|
||||
function! s:CVSUnedit()
|
||||
return s:DoCommand('unedit', 'cvsunedit', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:CVSWatch(onoff) {{{2
|
||||
function! s:CVSWatch(onoff)
|
||||
if a:onoff !~ '^\c\%(on\|off\|add\|remove\)$'
|
||||
echoerr 'Argument to CVSWatch must be one of [on|off|add|remove]'
|
||||
return -1
|
||||
end
|
||||
return s:DoCommand('watch ' . tolower(a:onoff), 'cvswatch', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:CVSWatchers() {{{2
|
||||
function! s:CVSWatchers()
|
||||
return s:DoCommand('watchers', 'cvswatchers', '', {})
|
||||
endfunction
|
||||
|
||||
" Annotate setting {{{2
|
||||
let s:cvsFunctions.AnnotateSplitRegex = '): '
|
||||
|
||||
" Section: Command definitions {{{1
|
||||
" Section: Primary commands {{{2
|
||||
com! CVSEdit call s:CVSEdit()
|
||||
com! CVSEditors call s:CVSEditors()
|
||||
com! CVSUnedit call s:CVSUnedit()
|
||||
com! -nargs=1 CVSWatch call s:CVSWatch(<f-args>)
|
||||
com! CVSWatchAdd call s:CVSWatch('add')
|
||||
com! CVSWatchOn call s:CVSWatch('on')
|
||||
com! CVSWatchOff call s:CVSWatch('off')
|
||||
com! CVSWatchRemove call s:CVSWatch('remove')
|
||||
com! CVSWatchers call s:CVSWatchers()
|
||||
|
||||
" Section: Plugin command mappings {{{1
|
||||
|
||||
let s:cvsExtensionMappings = {}
|
||||
let mappingInfo = [
|
||||
\['CVSEdit', 'CVSEdit', 'e'],
|
||||
\['CVSEditors', 'CVSEditors', 'E'],
|
||||
\['CVSUnedit', 'CVSUnedit', 't'],
|
||||
\['CVSWatchers', 'CVSWatchers', 'wv'],
|
||||
\['CVSWatchAdd', 'CVSWatch add', 'wa'],
|
||||
\['CVSWatchOff', 'CVSWatch off', 'wf'],
|
||||
\['CVSWatchOn', 'CVSWatch on', 'wn'],
|
||||
\['CVSWatchRemove', 'CVSWatch remove', 'wr']
|
||||
\]
|
||||
|
||||
for [pluginName, commandText, shortCut] in mappingInfo
|
||||
execute 'nnoremap <silent> <Plug>' . pluginName . ' :' . commandText . '<CR>'
|
||||
if !hasmapto('<Plug>' . pluginName)
|
||||
let s:cvsExtensionMappings[shortCut] = commandText
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Section: Menu items {{{1
|
||||
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
|
||||
amenu <silent> &Plugin.VCS.CVS.&Watchers <Plug>CVSWatchers
|
||||
amenu <silent> &Plugin.VCS.CVS.WatchAdd <Plug>CVSWatchAdd
|
||||
amenu <silent> &Plugin.VCS.CVS.WatchOn <Plug>CVSWatchOn
|
||||
amenu <silent> &Plugin.VCS.CVS.WatchOff <Plug>CVSWatchOff
|
||||
amenu <silent> &Plugin.VCS.CVS.WatchRemove <Plug>CVSWatchRemove
|
||||
|
||||
" Section: Plugin Registration {{{1
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('CVS', expand('<sfile>'), s:cvsFunctions, s:cvsExtensionMappings)
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
248
plugin/vcsgit.vim
Normal file
248
plugin/vcsgit.vim
Normal file
@@ -0,0 +1,248 @@
|
||||
" vim600: set foldmethod=marker:
|
||||
"
|
||||
" git extension for VCSCommand.
|
||||
"
|
||||
" Version: VCS development
|
||||
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
|
||||
" License:
|
||||
" Copyright (c) 2008 Bob Hiestand
|
||||
"
|
||||
" Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
" of this software and associated documentation files (the "Software"), to
|
||||
" deal in the Software without restriction, including without limitation the
|
||||
" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
" sell copies of the Software, and to permit persons to whom the Software is
|
||||
" furnished to do so, subject to the following conditions:
|
||||
"
|
||||
" The above copyright notice and this permission notice shall be included in
|
||||
" all copies or substantial portions of the Software.
|
||||
"
|
||||
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
" IN THE SOFTWARE.
|
||||
"
|
||||
" Section: Documentation {{{1
|
||||
"
|
||||
" Options documentation: {{{2
|
||||
"
|
||||
" VCSCommandGitExec
|
||||
" This variable specifies the git executable. If not set, it defaults to
|
||||
" 'git' executed from the user's executable path.
|
||||
"
|
||||
" VCSCommandGitDiffOpt
|
||||
" This variable, if set, determines the default options passed to the
|
||||
" VCSDiff command. If any options (starting with '-') are passed to the
|
||||
" command, this variable is not used.
|
||||
|
||||
" Section: Plugin header {{{1
|
||||
|
||||
if exists('VCSCommandDisableAll')
|
||||
finish
|
||||
endif
|
||||
|
||||
if v:version < 700
|
||||
echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime plugin/vcscommand.vim
|
||||
|
||||
if !executable(VCSCommandGetOption('VCSCommandGitExec', 'git'))
|
||||
" git is not installed
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:save_cpo=&cpo
|
||||
set cpo&vim
|
||||
|
||||
" Section: Variable initialization {{{1
|
||||
|
||||
let s:gitFunctions = {}
|
||||
|
||||
" Section: Utility functions {{{1
|
||||
|
||||
" Function: s:Executable() {{{2
|
||||
" Returns the executable used to invoke git suitable for use in a shell
|
||||
" command.
|
||||
function! s:Executable()
|
||||
return 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 = s:Executable() . ' ' . a:cmd
|
||||
return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
|
||||
else
|
||||
throw 'git VCSCommand plugin called on non-git item.'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Section: VCS function implementations {{{1
|
||||
|
||||
" Function: s:gitFunctions.Identify(buffer) {{{2
|
||||
" This function only returns an inexact match due to the detection method used
|
||||
" by git, which simply traverses the directory structure upward.
|
||||
function! s:gitFunctions.Identify(buffer)
|
||||
let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(a:buffer)))
|
||||
try
|
||||
call s:VCSCommandUtility.system(s:Executable() . ' rev-parse --is-inside-work-tree')
|
||||
if(v:shell_error)
|
||||
return 0
|
||||
else
|
||||
return g:VCSCOMMAND_IDENTIFY_INEXACT
|
||||
endif
|
||||
finally
|
||||
call VCSCommandChdir(oldCwd)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Add(argList) {{{2
|
||||
function! s:gitFunctions.Add(argList)
|
||||
return s:DoCommand(join(['add'] + ['-v'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Annotate(argList) {{{2
|
||||
function! s:gitFunctions.Annotate(argList)
|
||||
if len(a:argList) == 0
|
||||
if &filetype == 'gitannotate'
|
||||
" Perform annotation of the version indicated by the current line.
|
||||
let options = matchstr(getline('.'),'^\x\+')
|
||||
else
|
||||
let options = ''
|
||||
endif
|
||||
elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
|
||||
let options = a:argList[0]
|
||||
else
|
||||
let options = join(a:argList, ' ')
|
||||
endif
|
||||
|
||||
return s:DoCommand('blame ' . options, 'annotate', options, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Commit(argList) {{{2
|
||||
function! s:gitFunctions.Commit(argList)
|
||||
let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
|
||||
if resultBuffer == 0
|
||||
echomsg 'No commit needed.'
|
||||
endif
|
||||
return resultBuffer
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Delete() {{{2
|
||||
" All options are passed through.
|
||||
function! s:gitFunctions.Delete(argList)
|
||||
let options = a:argList
|
||||
let caption = join(a:argList, ' ')
|
||||
return s:DoCommand(join(['rm'] + options, ' '), 'delete', caption, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Diff(argList) {{{2
|
||||
" Pass-through call to git-diff. If no options (starting with '-') are found,
|
||||
" then the options in the 'VCSCommandGitDiffOpt' variable are added.
|
||||
function! s:gitFunctions.Diff(argList)
|
||||
let gitDiffOpt = VCSCommandGetOption('VCSCommandGitDiffOpt', '')
|
||||
if gitDiffOpt == ''
|
||||
let diffOptions = []
|
||||
else
|
||||
let diffOptions = [gitDiffOpt]
|
||||
for arg in a:argList
|
||||
if arg =~ '^-'
|
||||
let diffOptions = []
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
return s:DoCommand(join(['diff'] + diffOptions + a:argList), 'diff', join(a:argList), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.GetBufferInfo() {{{2
|
||||
" Provides version control details for the current file. Current version
|
||||
" number and current repository version number are required to be returned by
|
||||
" the vcscommand plugin. This CVS extension adds branch name to the return
|
||||
" list as well.
|
||||
" Returns: List of results: [revision, repository, branch]
|
||||
|
||||
function! s:gitFunctions.GetBufferInfo()
|
||||
let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname('%')))
|
||||
try
|
||||
let branch = substitute(s:VCSCommandUtility.system(s:Executable() . ' symbolic-ref -q HEAD'), '\n$', '', '')
|
||||
if v:shell_error
|
||||
let branch = 'DETACHED'
|
||||
else
|
||||
let branch = substitute(branch, '^refs/heads/', '', '')
|
||||
endif
|
||||
|
||||
let info = [branch]
|
||||
|
||||
for method in split(VCSCommandGetOption('VCSCommandGitDescribeArgList', (',tags,all,always')), ',', 1)
|
||||
if method != ''
|
||||
let method = ' --' . method
|
||||
endif
|
||||
let tag = substitute(s:VCSCommandUtility.system(s:Executable() . ' describe' . method), '\n$', '', '')
|
||||
if !v:shell_error
|
||||
call add(info, tag)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
return info
|
||||
finally
|
||||
call VCSCommandChdir(oldCwd)
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Log() {{{2
|
||||
function! s:gitFunctions.Log(argList)
|
||||
return s:DoCommand(join(['log'] + a:argList), 'log', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Revert(argList) {{{2
|
||||
function! s:gitFunctions.Revert(argList)
|
||||
return s:DoCommand('checkout', 'revert', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Review(argList) {{{2
|
||||
function! s:gitFunctions.Review(argList)
|
||||
if len(a:argList) == 0
|
||||
let revision = 'HEAD'
|
||||
else
|
||||
let revision = a:argList[0]
|
||||
endif
|
||||
|
||||
let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(VCSCommandGetOriginalBuffer('%'))))
|
||||
try
|
||||
let prefix = s:VCSCommandUtility.system(s:Executable() . ' rev-parse --show-prefix')
|
||||
finally
|
||||
call VCSCommandChdir(oldCwd)
|
||||
endtry
|
||||
|
||||
let prefix = substitute(prefix, '\n$', '', '')
|
||||
let blob = '"' . revision . ':' . prefix . '<VCSCOMMANDFILE>"'
|
||||
return s:DoCommand('show ' . blob, 'review', revision, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Status(argList) {{{2
|
||||
function! s:gitFunctions.Status(argList)
|
||||
return s:DoCommand(join(['status'] + a:argList), 'status', join(a:argList), {'allowNonZeroExit': 1})
|
||||
endfunction
|
||||
|
||||
" Function: s:gitFunctions.Update(argList) {{{2
|
||||
function! s:gitFunctions.Update(argList)
|
||||
throw "This command is not implemented for git because file-by-file update doesn't make much sense in that context. If you have an idea for what it should do, please let me know."
|
||||
endfunction
|
||||
|
||||
" Annotate setting {{{2
|
||||
let s:gitFunctions.AnnotateSplitRegex = ') '
|
||||
|
||||
" Section: Plugin Registration {{{1
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('git', expand('<sfile>'), s:gitFunctions, [])
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
273
plugin/vcshg.vim
Normal file
273
plugin/vcshg.vim
Normal file
@@ -0,0 +1,273 @@
|
||||
" 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
|
||||
|
||||
return s:DoCommand('blame' . options, 'annotate', caption, {})
|
||||
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
|
||||
|
||||
return s:DoCommand(join(['diff'] + diffExt + diffOptions + revOptions), 'diff', caption, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:hgFunctions.Info(argList) {{{2
|
||||
function! s:hgFunctions.Info(argList)
|
||||
return s:DoCommand(join(['log --limit 1'] + a:argList, ' '), 'log', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:hgFunctions.GetBufferInfo() {{{2
|
||||
" Provides version control details for the current file. Current version
|
||||
" number and current repository version number are required to be returned by
|
||||
" the vcscommand plugin.
|
||||
" Returns: List of results: [revision, repository, branch]
|
||||
|
||||
function! s:hgFunctions.GetBufferInfo()
|
||||
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
|
||||
let fileName = bufname(originalBuffer)
|
||||
let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -- "' . fileName . '"')
|
||||
if(v:shell_error)
|
||||
return []
|
||||
endif
|
||||
|
||||
" File not under HG control.
|
||||
if statusText =~ '^?'
|
||||
return ['Unknown']
|
||||
endif
|
||||
|
||||
let parentsText = s:VCSCommandUtility.system(s:Executable() . ' parents -- "' . fileName . '"')
|
||||
let revision = matchlist(parentsText, '^changeset:\s\+\(\S\+\)\n')[1]
|
||||
|
||||
let logText = s:VCSCommandUtility.system(s:Executable() . ' log -- "' . fileName . '"')
|
||||
let repository = matchlist(logText, '^changeset:\s\+\(\S\+\)\n')[1]
|
||||
|
||||
if revision == ''
|
||||
" Error
|
||||
return ['Unknown']
|
||||
elseif statusText =~ '^A'
|
||||
return ['New', 'New']
|
||||
else
|
||||
return [revision, repository]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:hgFunctions.Log(argList) {{{2
|
||||
function! s:hgFunctions.Log(argList)
|
||||
if len(a:argList) == 0
|
||||
let options = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let options = ['-r' . join(a:argList, ':')]
|
||||
let caption = options[0]
|
||||
else
|
||||
" Pass-through
|
||||
let options = a:argList
|
||||
let caption = join(a:argList, ' ')
|
||||
endif
|
||||
|
||||
let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {})
|
||||
return resultBuffer
|
||||
endfunction
|
||||
|
||||
" Function: s:hgFunctions.Revert(argList) {{{2
|
||||
function! s:hgFunctions.Revert(argList)
|
||||
return s:DoCommand('revert', 'revert', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:hgFunctions.Review(argList) {{{2
|
||||
function! s:hgFunctions.Review(argList)
|
||||
if len(a:argList) == 0
|
||||
let versiontag = '(current)'
|
||||
let versionOption = ''
|
||||
else
|
||||
let versiontag = a:argList[0]
|
||||
let versionOption = ' -r ' . versiontag . ' '
|
||||
endif
|
||||
|
||||
return s:DoCommand('cat' . versionOption, 'review', versiontag, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:hgFunctions.Status(argList) {{{2
|
||||
function! s:hgFunctions.Status(argList)
|
||||
let options = ['-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
|
||||
258
plugin/vcssvk.vim
Normal file
258
plugin/vcssvk.vim
Normal file
@@ -0,0 +1,258 @@
|
||||
" vim600: set foldmethod=marker:
|
||||
"
|
||||
" SVK extension for VCSCommand.
|
||||
"
|
||||
" Version: VCS development
|
||||
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
|
||||
" License:
|
||||
" Copyright (c) 2007 Bob Hiestand
|
||||
"
|
||||
" Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
" of this software and associated documentation files (the "Software"), to
|
||||
" deal in the Software without restriction, including without limitation the
|
||||
" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
" sell copies of the Software, and to permit persons to whom the Software is
|
||||
" furnished to do so, subject to the following conditions:
|
||||
"
|
||||
" The above copyright notice and this permission notice shall be included in
|
||||
" all copies or substantial portions of the Software.
|
||||
"
|
||||
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
" IN THE SOFTWARE.
|
||||
"
|
||||
" Section: Documentation {{{1
|
||||
"
|
||||
" Options documentation: {{{2
|
||||
"
|
||||
" VCSCommandSVKExec
|
||||
" This variable specifies the SVK executable. If not set, it defaults to
|
||||
" 'svk' executed from the user's executable path.
|
||||
|
||||
" Section: Plugin header {{{1
|
||||
|
||||
if exists('VCSCommandDisableAll')
|
||||
finish
|
||||
endif
|
||||
|
||||
if v:version < 700
|
||||
echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime plugin/vcscommand.vim
|
||||
|
||||
if !executable(VCSCommandGetOption('VCSCommandSVKExec', 'svk'))
|
||||
" SVK is not installed
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:save_cpo=&cpo
|
||||
set cpo&vim
|
||||
|
||||
" Section: Variable initialization {{{1
|
||||
|
||||
let s:svkFunctions = {}
|
||||
|
||||
" Section: Utility functions {{{1
|
||||
|
||||
" Function: s:Executable() {{{2
|
||||
" Returns the executable used to invoke SVK suitable for use in a shell
|
||||
" command.
|
||||
function! s:Executable()
|
||||
return 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 = s:Executable() . ' ' . a:cmd
|
||||
return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
|
||||
else
|
||||
throw 'SVK VCSCommand plugin called on non-SVK item.'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Section: VCS function implementations {{{1
|
||||
|
||||
" Function: s:svkFunctions.Identify(buffer) {{{2
|
||||
function! s:svkFunctions.Identify(buffer)
|
||||
let fileName = resolve(bufname(a:buffer))
|
||||
if isdirectory(fileName)
|
||||
let directoryName = fileName
|
||||
else
|
||||
let directoryName = fnamemodify(fileName, ':p:h')
|
||||
endif
|
||||
let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . directoryName . '"', "no")
|
||||
if(v:shell_error)
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Add() {{{2
|
||||
function! s:svkFunctions.Add(argList)
|
||||
return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Annotate(argList) {{{2
|
||||
function! s:svkFunctions.Annotate(argList)
|
||||
if len(a:argList) == 0
|
||||
if &filetype == 'SVKannotate'
|
||||
" Perform annotation of the version indicated by the current line.
|
||||
let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
|
||||
let options = ' -r' . caption
|
||||
else
|
||||
let caption = ''
|
||||
let options = ''
|
||||
endif
|
||||
elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
|
||||
let caption = a:argList[0]
|
||||
let options = ' -r' . caption
|
||||
else
|
||||
let caption = join(a:argList, ' ')
|
||||
let options = ' ' . caption
|
||||
endif
|
||||
|
||||
let resultBuffer = s:DoCommand('blame' . options, 'annotate', caption, {})
|
||||
if resultBuffer > 0
|
||||
normal 1G2dd
|
||||
endif
|
||||
return resultBuffer
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Commit(argList) {{{2
|
||||
function! s:svkFunctions.Commit(argList)
|
||||
let resultBuffer = s:DoCommand('commit -F "' . a:argList[0] . '"', 'commit', '', {})
|
||||
if resultBuffer == 0
|
||||
echomsg 'No commit needed.'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Delete() {{{2
|
||||
function! s:svkFunctions.Delete(argList)
|
||||
return s:DoCommand(join(['delete'] + a:argList, ' '), 'delete', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Diff(argList) {{{2
|
||||
function! s:svkFunctions.Diff(argList)
|
||||
if len(a:argList) == 0
|
||||
let revOptions = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let revOptions = ['-r' . join(a:argList, ':')]
|
||||
let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
|
||||
else
|
||||
" Pass-through
|
||||
let caption = join(a:argList, ' ')
|
||||
let revOptions = a:argList
|
||||
endif
|
||||
|
||||
return s:DoCommand(join(['diff'] + revOptions), 'diff', caption, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.GetBufferInfo() {{{2
|
||||
" Provides version control details for the current file. Current version
|
||||
" number and current repository version number are required to be returned by
|
||||
" the vcscommand plugin.
|
||||
" Returns: List of results: [revision, repository]
|
||||
|
||||
function! s:svkFunctions.GetBufferInfo()
|
||||
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
|
||||
let fileName = resolve(bufname(originalBuffer))
|
||||
let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -v -- "' . fileName . '"')
|
||||
if(v:shell_error)
|
||||
return []
|
||||
endif
|
||||
|
||||
" File not under SVK control.
|
||||
if statusText =~ '^?'
|
||||
return ['Unknown']
|
||||
endif
|
||||
|
||||
let [flags, revision, repository] = matchlist(statusText, '^\(.\{3}\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s')[1:3]
|
||||
if revision == ''
|
||||
" Error
|
||||
return ['Unknown']
|
||||
elseif flags =~ '^A'
|
||||
return ['New', 'New']
|
||||
else
|
||||
return [revision, repository]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Info(argList) {{{2
|
||||
function! s:svkFunctions.Info(argList)
|
||||
return s:DoCommand(join(['info'] + a:argList, ' '), 'info', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Lock(argList) {{{2
|
||||
function! s:svkFunctions.Lock(argList)
|
||||
return s:DoCommand(join(['lock'] + a:argList, ' '), 'lock', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Log() {{{2
|
||||
function! s:svkFunctions.Log(argList)
|
||||
if len(a:argList) == 0
|
||||
let options = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let options = ['-r' . join(a:argList, ':')]
|
||||
let caption = options[0]
|
||||
else
|
||||
" Pass-through
|
||||
let options = a:argList
|
||||
let caption = join(a:argList, ' ')
|
||||
endif
|
||||
|
||||
let resultBuffer = s:DoCommand(join(['log', '-v'] + options), 'log', caption, {})
|
||||
return resultBuffer
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Revert(argList) {{{2
|
||||
function! s:svkFunctions.Revert(argList)
|
||||
return s:DoCommand('revert', 'revert', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Review(argList) {{{2
|
||||
function! s:svkFunctions.Review(argList)
|
||||
if len(a:argList) == 0
|
||||
let versiontag = '(current)'
|
||||
let versionOption = ''
|
||||
else
|
||||
let versiontag = a:argList[0]
|
||||
let versionOption = ' -r ' . versiontag . ' '
|
||||
endif
|
||||
|
||||
return s:DoCommand('cat' . versionOption, 'review', versiontag, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Status(argList) {{{2
|
||||
function! s:svkFunctions.Status(argList)
|
||||
let options = ['-v']
|
||||
if len(a:argList) == 0
|
||||
let options = a:argList
|
||||
endif
|
||||
return s:DoCommand(join(['status'] + options, ' '), 'status', join(options, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svkFunctions.Unlock(argList) {{{2
|
||||
function! s:svkFunctions.Unlock(argList)
|
||||
return s:DoCommand(join(['unlock'] + a:argList, ' '), 'unlock', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
" Function: s:svkFunctions.Update(argList) {{{2
|
||||
function! s:svkFunctions.Update(argList)
|
||||
return s:DoCommand('update', 'update', '', {})
|
||||
endfunction
|
||||
|
||||
" Section: Plugin Registration {{{1
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('SVK', expand('<sfile>'), s:svkFunctions, [])
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
285
plugin/vcssvn.vim
Normal file
285
plugin/vcssvn.vim
Normal file
@@ -0,0 +1,285 @@
|
||||
" vim600: set foldmethod=marker:
|
||||
"
|
||||
" SVN extension for VCSCommand.
|
||||
"
|
||||
" Version: VCS development
|
||||
" Maintainer: Bob Hiestand <bob.hiestand@gmail.com>
|
||||
" License:
|
||||
" Copyright (c) 2007 Bob Hiestand
|
||||
"
|
||||
" Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
" of this software and associated documentation files (the "Software"), to
|
||||
" deal in the Software without restriction, including without limitation the
|
||||
" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
" sell copies of the Software, and to permit persons to whom the Software is
|
||||
" furnished to do so, subject to the following conditions:
|
||||
"
|
||||
" The above copyright notice and this permission notice shall be included in
|
||||
" all copies or substantial portions of the Software.
|
||||
"
|
||||
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
" IN THE SOFTWARE.
|
||||
"
|
||||
" Section: Documentation {{{1
|
||||
"
|
||||
" Options documentation: {{{2
|
||||
"
|
||||
" VCSCommandSVNExec
|
||||
" This variable specifies the SVN executable. If not set, it defaults to
|
||||
" 'svn' executed from the user's executable path.
|
||||
"
|
||||
" VCSCommandSVNDiffExt
|
||||
" This variable, if set, sets the external diff program used by Subversion.
|
||||
"
|
||||
" VCSCommandSVNDiffOpt
|
||||
" This variable, if set, determines the options passed to the svn diff
|
||||
" command (such as 'u', 'w', or 'b').
|
||||
|
||||
" Section: Plugin header {{{1
|
||||
|
||||
if exists('VCSCommandDisableAll')
|
||||
finish
|
||||
endif
|
||||
|
||||
if v:version < 700
|
||||
echohl WarningMsg|echomsg 'VCSCommand requires at least VIM 7.0'|echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime plugin/vcscommand.vim
|
||||
|
||||
if !executable(VCSCommandGetOption('VCSCommandSVNExec', 'svn'))
|
||||
" SVN is not installed
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:save_cpo=&cpo
|
||||
set cpo&vim
|
||||
|
||||
" Section: Variable initialization {{{1
|
||||
|
||||
let s:svnFunctions = {}
|
||||
|
||||
" Section: Utility functions {{{1
|
||||
|
||||
" Function: s:Executable() {{{2
|
||||
" Returns the executable used to invoke git suitable for use in a shell
|
||||
" command.
|
||||
function! s:Executable()
|
||||
return 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 = s:Executable() . ' ' . a:cmd
|
||||
return VCSCommandDoCommand(fullCmd, a:cmdName, a:statusText, a:options)
|
||||
else
|
||||
throw 'SVN VCSCommand plugin called on non-SVN item.'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Section: VCS function implementations {{{1
|
||||
|
||||
" Function: s:svnFunctions.Identify(buffer) {{{2
|
||||
function! s:svnFunctions.Identify(buffer)
|
||||
let fileName = resolve(bufname(a:buffer))
|
||||
if isdirectory(fileName)
|
||||
let directoryName = fileName
|
||||
else
|
||||
let directoryName = fnamemodify(fileName, ':h')
|
||||
endif
|
||||
if strlen(directoryName) > 0
|
||||
let svnDir = directoryName . '/.svn'
|
||||
else
|
||||
let svnDir = '.svn'
|
||||
endif
|
||||
if isdirectory(svnDir)
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Add() {{{2
|
||||
function! s:svnFunctions.Add(argList)
|
||||
return s:DoCommand(join(['add'] + a:argList, ' '), 'add', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Annotate(argList) {{{2
|
||||
function! s:svnFunctions.Annotate(argList)
|
||||
if len(a:argList) == 0
|
||||
if &filetype == 'SVNannotate'
|
||||
" Perform annotation of the version indicated by the current line.
|
||||
let caption = matchstr(getline('.'),'\v^\s+\zs\d+')
|
||||
let options = ' -r' . caption
|
||||
else
|
||||
let caption = ''
|
||||
let options = ''
|
||||
endif
|
||||
elseif len(a:argList) == 1 && a:argList[0] !~ '^-'
|
||||
let caption = a:argList[0]
|
||||
let options = ' -r' . caption
|
||||
else
|
||||
let caption = join(a:argList, ' ')
|
||||
let options = ' ' . caption
|
||||
endif
|
||||
|
||||
return s:DoCommand('blame --non-interactive' . options, 'annotate', caption, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Commit(argList) {{{2
|
||||
function! s:svnFunctions.Commit(argList)
|
||||
let resultBuffer = s:DoCommand('commit --non-interactive -F "' . a:argList[0] . '"', 'commit', '', {})
|
||||
if resultBuffer == 0
|
||||
echomsg 'No commit needed.'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Delete() {{{2
|
||||
function! s:svnFunctions.Delete(argList)
|
||||
return s:DoCommand(join(['delete --non-interactive'] + a:argList, ' '), 'delete', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Diff(argList) {{{2
|
||||
function! s:svnFunctions.Diff(argList)
|
||||
if len(a:argList) == 0
|
||||
let revOptions = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let revOptions = ['-r' . join(a:argList, ':')]
|
||||
let caption = '(' . a:argList[0] . ' : ' . get(a:argList, 1, 'current') . ')'
|
||||
else
|
||||
" Pass-through
|
||||
let caption = join(a:argList, ' ')
|
||||
let revOptions = a:argList
|
||||
endif
|
||||
|
||||
let svnDiffExt = VCSCommandGetOption('VCSCommandSVNDiffExt', '')
|
||||
if svnDiffExt == ''
|
||||
let diffExt = []
|
||||
else
|
||||
let diffExt = ['--diff-cmd ' . svnDiffExt]
|
||||
endif
|
||||
|
||||
let svnDiffOpt = VCSCommandGetOption('VCSCommandSVNDiffOpt', '')
|
||||
if svnDiffOpt == ''
|
||||
let diffOptions = []
|
||||
else
|
||||
let diffOptions = ['-x -' . svnDiffOpt]
|
||||
endif
|
||||
|
||||
return s:DoCommand(join(['diff --non-interactive'] + diffExt + diffOptions + revOptions), 'diff', caption, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.GetBufferInfo() {{{2
|
||||
" Provides version control details for the current file. Current version
|
||||
" number and current repository version number are required to be returned by
|
||||
" the vcscommand plugin.
|
||||
" Returns: List of results: [revision, repository, branch]
|
||||
|
||||
function! s:svnFunctions.GetBufferInfo()
|
||||
let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%'))
|
||||
let fileName = bufname(originalBuffer)
|
||||
let statusText = s:VCSCommandUtility.system(s:Executable() . ' status --non-interactive -vu -- "' . fileName . '"')
|
||||
if(v:shell_error)
|
||||
return []
|
||||
endif
|
||||
|
||||
" File not under SVN control.
|
||||
if statusText =~ '^?'
|
||||
return ['Unknown']
|
||||
endif
|
||||
|
||||
let [flags, revision, repository] = matchlist(statusText, '^\(.\{9}\)\s*\(\d\+\)\s\+\(\d\+\)')[1:3]
|
||||
if revision == ''
|
||||
" Error
|
||||
return ['Unknown']
|
||||
elseif flags =~ '^A'
|
||||
return ['New', 'New']
|
||||
elseif flags =~ '*'
|
||||
return [revision, repository, '*']
|
||||
else
|
||||
return [revision, repository]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Info(argList) {{{2
|
||||
function! s:svnFunctions.Info(argList)
|
||||
return s:DoCommand(join(['info --non-interactive'] + a:argList, ' '), 'info', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Lock(argList) {{{2
|
||||
function! s:svnFunctions.Lock(argList)
|
||||
return s:DoCommand(join(['lock --non-interactive'] + a:argList, ' '), 'lock', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Log(argList) {{{2
|
||||
function! s:svnFunctions.Log(argList)
|
||||
if len(a:argList) == 0
|
||||
let options = []
|
||||
let caption = ''
|
||||
elseif len(a:argList) <= 2 && match(a:argList, '^-') == -1
|
||||
let options = ['-r' . join(a:argList, ':')]
|
||||
let caption = options[0]
|
||||
else
|
||||
" Pass-through
|
||||
let options = a:argList
|
||||
let caption = join(a:argList, ' ')
|
||||
endif
|
||||
|
||||
let resultBuffer = s:DoCommand(join(['log --non-interactive', '-v'] + options), 'log', caption, {})
|
||||
return resultBuffer
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Revert(argList) {{{2
|
||||
function! s:svnFunctions.Revert(argList)
|
||||
return s:DoCommand('revert', 'revert', '', {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Review(argList) {{{2
|
||||
function! s:svnFunctions.Review(argList)
|
||||
if len(a:argList) == 0
|
||||
let versiontag = '(current)'
|
||||
let versionOption = ''
|
||||
else
|
||||
let versiontag = a:argList[0]
|
||||
let versionOption = ' -r ' . versiontag . ' '
|
||||
endif
|
||||
|
||||
return s:DoCommand('cat --non-interactive' . versionOption, 'review', versiontag, {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Status(argList) {{{2
|
||||
function! s:svnFunctions.Status(argList)
|
||||
let options = ['-u', '-v']
|
||||
if len(a:argList) == 0
|
||||
let options = a:argList
|
||||
endif
|
||||
return s:DoCommand(join(['status --non-interactive'] + options, ' '), 'status', join(options, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Unlock(argList) {{{2
|
||||
function! s:svnFunctions.Unlock(argList)
|
||||
return s:DoCommand(join(['unlock --non-interactive'] + a:argList, ' '), 'unlock', join(a:argList, ' '), {})
|
||||
endfunction
|
||||
|
||||
" Function: s:svnFunctions.Update(argList) {{{2
|
||||
function! s:svnFunctions.Update(argList)
|
||||
return s:DoCommand('update --non-interactive', 'update', '', {})
|
||||
endfunction
|
||||
|
||||
" Annotate setting {{{2
|
||||
let s:svnFunctions.AnnotateSplitRegex = '\s\+\S\+\s\+\S\+ '
|
||||
|
||||
" Section: Plugin Registration {{{1
|
||||
let s:VCSCommandUtility = VCSCommandRegisterModule('SVN', expand('<sfile>'), s:svnFunctions, [])
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
405
plugin/vimwiki.vim
Normal file
405
plugin/vimwiki.vim
Normal file
@@ -0,0 +1,405 @@
|
||||
" Vimwiki plugin file
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
" Home: http://code.google.com/p/vimwiki/
|
||||
" GetLatestVimScripts: 2226 1 :AutoInstall: vimwiki
|
||||
|
||||
if exists("loaded_vimwiki") || &cp
|
||||
finish
|
||||
endif
|
||||
let loaded_vimwiki = 1
|
||||
|
||||
let s:old_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" HELPER functions {{{
|
||||
function! s:default(varname, value) "{{{
|
||||
if !exists('g:vimwiki_'.a:varname)
|
||||
let g:vimwiki_{a:varname} = a:value
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! Str_common_part(str1, str2)"{{{
|
||||
let idx = 0
|
||||
let minlen = min([len(a:str1), len(a:str2)])
|
||||
while (idx < minlen) && (a:str1[idx] == a:str2[idx])
|
||||
let idx = idx + 1
|
||||
endwhile
|
||||
|
||||
return strpart(a:str1, 0, idx)
|
||||
endfunction"}}}
|
||||
|
||||
function! s:chomp_slash(str)"{{{
|
||||
return substitute(a:str, '[/\\]\+$', '', '')
|
||||
endfunction"}}}
|
||||
|
||||
function! s:find_wiki(path) "{{{
|
||||
let idx = 0
|
||||
while idx < len(g:vimwiki_list)
|
||||
let path = s:chomp_slash(expand(VimwikiGet('path', idx)))
|
||||
if Str_common_part(path, a:path) == path
|
||||
return idx
|
||||
endif
|
||||
let idx += 1
|
||||
endwhile
|
||||
return -1
|
||||
endfunction "}}}
|
||||
|
||||
function! s:setup_buffer_leave()"{{{
|
||||
if &filetype == 'vimwiki' && !exists("b:vimwiki_idx")
|
||||
let b:vimwiki_idx = g:vimwiki_current_idx
|
||||
endif
|
||||
|
||||
" Set up menu
|
||||
if g:vimwiki_menu != ""
|
||||
exe 'nmenu disable '.g:vimwiki_menu.'.Table'
|
||||
endif
|
||||
endfunction"}}}
|
||||
|
||||
function! s:setup_buffer_enter() "{{{
|
||||
if exists("b:vimwiki_idx")
|
||||
let g:vimwiki_current_idx = b:vimwiki_idx
|
||||
else
|
||||
" Find what wiki current buffer belongs to.
|
||||
" If wiki does not exist in g:vimwiki_list -- add new wiki there with
|
||||
" buffer's path and ext.
|
||||
" Else set g:vimwiki_current_idx to that wiki index.
|
||||
let path = expand('%:p:h')
|
||||
let ext = '.'.expand('%:e')
|
||||
let idx = s:find_wiki(path)
|
||||
|
||||
" The buffer's file is not in the path and user do not want his wiki
|
||||
" extension to be global -- do not add new wiki.
|
||||
if idx == -1 && g:vimwiki_global_ext == 0
|
||||
return
|
||||
endif
|
||||
|
||||
if idx == -1
|
||||
call add(g:vimwiki_list, {'path': path, 'ext': ext})
|
||||
let g:vimwiki_current_idx = len(g:vimwiki_list) - 1
|
||||
else
|
||||
let g:vimwiki_current_idx = idx
|
||||
endif
|
||||
|
||||
let b:vimwiki_idx = g:vimwiki_current_idx
|
||||
endif
|
||||
|
||||
call s:setup_colors()
|
||||
|
||||
if &filetype != 'vimwiki'
|
||||
setlocal ft=vimwiki
|
||||
else
|
||||
setlocal syntax=vimwiki
|
||||
endif
|
||||
|
||||
" Settings foldmethod, foldexpr and foldtext are local to window. Thus in a
|
||||
" new tab with the same buffer folding is reset to vim defaults. So we
|
||||
" insist vimwiki folding here.
|
||||
" TODO: remove the same from ftplugin.
|
||||
if g:vimwiki_folding == 1 && &fdm != 'expr'
|
||||
setlocal fdm=expr
|
||||
setlocal foldexpr=VimwikiFoldLevel(v:lnum)
|
||||
setlocal foldtext=VimwikiFoldText()
|
||||
endif
|
||||
|
||||
" Set up menu
|
||||
if g:vimwiki_menu != ""
|
||||
exe 'nmenu enable '.g:vimwiki_menu.'.Table'
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:setup_colors()"{{{
|
||||
if g:vimwiki_hl_headers == 0
|
||||
return
|
||||
endif
|
||||
|
||||
if &background == 'light'
|
||||
hi def VimwikiHeader1 guibg=bg guifg=#aa5858 gui=bold ctermfg=DarkRed
|
||||
hi def VimwikiHeader2 guibg=bg guifg=#309010 gui=bold ctermfg=DarkGreen
|
||||
hi def VimwikiHeader3 guibg=bg guifg=#1030a0 gui=bold ctermfg=DarkBlue
|
||||
hi def VimwikiHeader4 guibg=bg guifg=#103040 gui=bold ctermfg=Black
|
||||
hi def VimwikiHeader5 guibg=bg guifg=#001020 gui=bold ctermfg=Black
|
||||
hi def VimwikiHeader6 guibg=bg guifg=#000000 gui=bold ctermfg=Black
|
||||
else
|
||||
hi def VimwikiHeader1 guibg=bg guifg=#e08090 gui=bold ctermfg=Red
|
||||
hi def VimwikiHeader2 guibg=bg guifg=#80e090 gui=bold ctermfg=Green
|
||||
hi def VimwikiHeader3 guibg=bg guifg=#6090e0 gui=bold ctermfg=Blue
|
||||
hi def VimwikiHeader4 guibg=bg guifg=#c0c0f0 gui=bold ctermfg=White
|
||||
hi def VimwikiHeader5 guibg=bg guifg=#e0e0f0 gui=bold ctermfg=White
|
||||
hi def VimwikiHeader6 guibg=bg guifg=#f0f0f0 gui=bold ctermfg=White
|
||||
endif
|
||||
endfunction"}}}
|
||||
|
||||
" OPTION get/set functions {{{
|
||||
" return value of option for current wiki or if second parameter exists for
|
||||
" wiki with a given index.
|
||||
function! VimwikiGet(option, ...) "{{{
|
||||
if a:0 == 0
|
||||
let idx = g:vimwiki_current_idx
|
||||
else
|
||||
let idx = a:1
|
||||
endif
|
||||
if !has_key(g:vimwiki_list[idx], a:option) &&
|
||||
\ has_key(s:vimwiki_defaults, a:option)
|
||||
if a:option == 'path_html'
|
||||
let g:vimwiki_list[idx][a:option] =
|
||||
\VimwikiGet('path', idx)[:-2].'_html/'
|
||||
else
|
||||
let g:vimwiki_list[idx][a:option] =
|
||||
\s:vimwiki_defaults[a:option]
|
||||
endif
|
||||
endif
|
||||
|
||||
" if path's ending is not a / or \
|
||||
" then add it
|
||||
if a:option == 'path' || a:option == 'path_html'
|
||||
let p = g:vimwiki_list[idx][a:option]
|
||||
" resolve doesn't work quite right with symlinks ended with / or \
|
||||
let p = substitute(p, '[/\\]\+$', '', '')
|
||||
let p = resolve(expand(p))
|
||||
let g:vimwiki_list[idx][a:option] = p.'/'
|
||||
endif
|
||||
|
||||
return g:vimwiki_list[idx][a:option]
|
||||
endfunction "}}}
|
||||
|
||||
" set option for current wiki or if third parameter exists for
|
||||
" wiki with a given index.
|
||||
function! VimwikiSet(option, value, ...) "{{{
|
||||
if a:0 == 0
|
||||
let idx = g:vimwiki_current_idx
|
||||
else
|
||||
let idx = a:1
|
||||
endif
|
||||
let g:vimwiki_list[idx][a:option] = a:value
|
||||
endfunction "}}}
|
||||
" }}}
|
||||
|
||||
" }}}
|
||||
|
||||
" CALLBACK function "{{{
|
||||
" User can redefine it.
|
||||
if !exists("*VimwikiWeblinkHandler") "{{{
|
||||
function VimwikiWeblinkHandler(weblink)
|
||||
for browser in g:vimwiki_browsers
|
||||
if executable(browser)
|
||||
if has("win32")
|
||||
execute '!start "'.browser.'" ' . a:weblink
|
||||
else
|
||||
execute '!'.browser.' ' . a:weblink
|
||||
endif
|
||||
return
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
endif "}}}
|
||||
" CALLBACK }}}
|
||||
|
||||
" DEFAULT wiki {{{
|
||||
let s:vimwiki_defaults = {}
|
||||
let s:vimwiki_defaults.path = '~/vimwiki/'
|
||||
let s:vimwiki_defaults.path_html = '~/vimwiki_html/'
|
||||
let s:vimwiki_defaults.css_name = 'style.css'
|
||||
let s:vimwiki_defaults.index = 'index'
|
||||
let s:vimwiki_defaults.ext = '.wiki'
|
||||
let s:vimwiki_defaults.maxhi = 1
|
||||
let s:vimwiki_defaults.syntax = 'default'
|
||||
let s:vimwiki_defaults.gohome = 'split'
|
||||
let s:vimwiki_defaults.html_header = ''
|
||||
let s:vimwiki_defaults.html_footer = ''
|
||||
let s:vimwiki_defaults.nested_syntaxes = {}
|
||||
let s:vimwiki_defaults.auto_export = 0
|
||||
|
||||
" diary
|
||||
let s:vimwiki_defaults.diary_rel_path = 'diary/'
|
||||
let s:vimwiki_defaults.diary_index = 'diary'
|
||||
let s:vimwiki_defaults.diary_header = 'Diary'
|
||||
|
||||
" Do not change this! Will wait till vim would be more datetime awareable.
|
||||
let s:vimwiki_defaults.diary_link_fmt = '%Y-%m-%d'
|
||||
|
||||
let s:vimwiki_defaults.diary_link_count = 4
|
||||
|
||||
"}}}
|
||||
|
||||
" DEFAULT options {{{
|
||||
call s:default('list', [s:vimwiki_defaults])
|
||||
if &encoding == 'utf-8'
|
||||
call s:default('upper', 'A-Z\u0410-\u042f')
|
||||
call s:default('lower', 'a-z\u0430-\u044f')
|
||||
else
|
||||
call s:default('upper', 'A-Z')
|
||||
call s:default('lower', 'a-z')
|
||||
endif
|
||||
call s:default('other', '0-9')
|
||||
call s:default('stripsym', '_')
|
||||
call s:default('badsyms', '')
|
||||
call s:default('auto_checkbox', 1)
|
||||
call s:default('use_mouse', 0)
|
||||
call s:default('folding', 0)
|
||||
call s:default('fold_trailing_empty_lines', 0)
|
||||
call s:default('fold_lists', 0)
|
||||
call s:default('menu', 'Vimwiki')
|
||||
call s:default('global_ext', 1)
|
||||
call s:default('hl_headers', 1)
|
||||
call s:default('hl_cb_checked', 0)
|
||||
call s:default('camel_case', 1)
|
||||
call s:default('list_ignore_newline', 1)
|
||||
call s:default('listsyms', ' .oOX')
|
||||
if has("win32")
|
||||
call s:default('browsers',
|
||||
\ [
|
||||
\ expand('~').'\Local Settings\Application Data\Google\Chrome\Application\chrome.exe',
|
||||
\ 'C:\Program Files\Opera\opera.exe',
|
||||
\ 'C:\Program Files\Mozilla Firefox\firefox.exe',
|
||||
\ 'C:\Program Files\Internet Explorer\iexplore.exe',
|
||||
\ ])
|
||||
else
|
||||
call s:default('browsers',
|
||||
\ [
|
||||
\ 'opera',
|
||||
\ 'firefox',
|
||||
\ 'konqueror',
|
||||
\ ])
|
||||
endif
|
||||
|
||||
call s:default('use_calendar', 1)
|
||||
call s:default('table_auto_fmt', 1)
|
||||
call s:default('w32_dir_enc', '')
|
||||
|
||||
call s:default('current_idx', 0)
|
||||
|
||||
let upp = g:vimwiki_upper
|
||||
let low = g:vimwiki_lower
|
||||
let oth = g:vimwiki_other
|
||||
let nup = low.oth
|
||||
let nlo = upp.oth
|
||||
let any = upp.nup
|
||||
|
||||
let g:vimwiki_word1 = '\C\<['.upp.']['.nlo.']*['.
|
||||
\ low.']['.nup.']*['.upp.']['.any.']*\>'
|
||||
let g:vimwiki_word2 = '\[\[[^\]]\+\]\]'
|
||||
let g:vimwiki_word3 = '\[\[[^\]]\+\]\[[^\]]\+\]\]'
|
||||
if g:vimwiki_camel_case
|
||||
let g:vimwiki_rxWikiWord = g:vimwiki_word1.'\|'.g:vimwiki_word2.'\|'.g:vimwiki_word3
|
||||
else
|
||||
let g:vimwiki_rxWikiWord = g:vimwiki_word2.'\|'.g:vimwiki_word3
|
||||
endif
|
||||
let g:vimwiki_rxWeblink = '\%("[^"(]\+\((\([^)]\+\))\)\?":\)\?'.
|
||||
\'\%(https\?\|ftp\|gopher\|telnet\|file\|notes\|ms-help\):'.
|
||||
\'\%(\%(\%(//\)\|\%(\\\\\)\)\+[A-Za-z0-9:#@%/;,$~()_?+=.&\\\-]*\)'
|
||||
"}}}
|
||||
|
||||
" AUTOCOMMANDS for all known wiki extensions {{{
|
||||
" Getting all extensions that different wikies could have
|
||||
let extensions = {}
|
||||
for wiki in g:vimwiki_list
|
||||
if has_key(wiki, 'ext')
|
||||
let extensions[wiki.ext] = 1
|
||||
else
|
||||
let extensions['.wiki'] = 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
augroup filetypedetect
|
||||
" clear FlexWiki's stuff
|
||||
au! * *.wiki
|
||||
augroup end
|
||||
|
||||
augroup vimwiki
|
||||
autocmd!
|
||||
for ext in keys(extensions)
|
||||
exe 'autocmd BufEnter *'.ext.' call s:setup_buffer_enter()'
|
||||
exe 'autocmd BufLeave,BufHidden *'.ext.' call s:setup_buffer_leave()'
|
||||
|
||||
" ColorScheme could have or could have not a
|
||||
" VimwikiHeader1..VimwikiHeader6 highlight groups. We need to refresh
|
||||
" syntax after colorscheme change.
|
||||
exe 'autocmd ColorScheme *'.ext.' call s:setup_colors()'.
|
||||
\ ' | set syntax=vimwiki'
|
||||
|
||||
" Format tables when exit from insert mode. Do not use textwidth to
|
||||
" autowrap tables.
|
||||
if g:vimwiki_table_auto_fmt
|
||||
exe 'autocmd InsertLeave *'.ext.' call vimwiki_tbl#format(line("."))'
|
||||
exe 'autocmd InsertEnter *'.ext.' call vimwiki_tbl#reset_tw(line("."))'
|
||||
endif
|
||||
endfor
|
||||
augroup END
|
||||
"}}}
|
||||
|
||||
" COMMANDS {{{
|
||||
command! VimwikiUISelect call vimwiki#WikiUISelect()
|
||||
command! -count VimwikiGoHome
|
||||
\ call vimwiki#WikiGoHome(v:count1)
|
||||
command! -count VimwikiTabGoHome tabedit <bar>
|
||||
\ call vimwiki#WikiGoHome(v:count1)
|
||||
|
||||
command! -count VimwikiMakeDiaryNote
|
||||
\ call vimwiki_diary#make_note(v:count1)
|
||||
command! -count VimwikiTabMakeDiaryNote tabedit <bar>
|
||||
\ call vimwiki_diary#make_note(v:count1)
|
||||
"}}}
|
||||
|
||||
" MAPPINGS {{{
|
||||
if !hasmapto('<Plug>VimwikiGoHome')
|
||||
map <silent><unique> <Leader>ww <Plug>VimwikiGoHome
|
||||
endif
|
||||
noremap <unique><script> <Plug>VimwikiGoHome :VimwikiGoHome<CR>
|
||||
|
||||
if !hasmapto('<Plug>VimwikiTabGoHome')
|
||||
map <silent><unique> <Leader>wt <Plug>VimwikiTabGoHome
|
||||
endif
|
||||
noremap <unique><script> <Plug>VimwikiTabGoHome :VimwikiTabGoHome<CR>
|
||||
|
||||
if !hasmapto('<Plug>VimwikiUISelect')
|
||||
map <silent><unique> <Leader>ws <Plug>VimwikiUISelect
|
||||
endif
|
||||
noremap <unique><script> <Plug>VimwikiUISelect :VimwikiUISelect<CR>
|
||||
|
||||
if !hasmapto('<Plug>VimwikiMakeDiaryNote')
|
||||
map <silent><unique> <Leader>w<Leader>w <Plug>VimwikiMakeDiaryNote
|
||||
endif
|
||||
noremap <unique><script> <Plug>VimwikiMakeDiaryNote :VimwikiMakeDiaryNote<CR>
|
||||
|
||||
if !hasmapto('<Plug>VimwikiTabMakeDiaryNote')
|
||||
map <silent><unique> <Leader>w<Leader>t <Plug>VimwikiTabMakeDiaryNote
|
||||
endif
|
||||
noremap <unique><script> <Plug>VimwikiTabMakeDiaryNote
|
||||
\ :VimwikiTabMakeDiaryNote<CR>
|
||||
|
||||
"}}}
|
||||
|
||||
" MENU {{{
|
||||
function! s:build_menu(topmenu)
|
||||
let idx = 0
|
||||
while idx < len(g:vimwiki_list)
|
||||
let norm_path = fnamemodify(VimwikiGet('path', idx), ':h:t')
|
||||
let norm_path = escape(norm_path, '\ ')
|
||||
execute 'menu '.a:topmenu.'.Open\ index.'.norm_path.
|
||||
\ ' :call vimwiki#WikiGoHome('.(idx + 1).')<CR>'
|
||||
execute 'menu '.a:topmenu.'.Open/Create\ diary\ note.'.norm_path.
|
||||
\ ' :call vimwiki_diary#make_note('.(idx + 1).')<CR>'
|
||||
let idx += 1
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! s:build_table_menu(topmenu)
|
||||
exe 'menu '.a:topmenu.'.-Sep- :'
|
||||
exe 'menu '.a:topmenu.'.Table.Create\ (enter\ cols\ rows) :VimwikiTable '
|
||||
exe 'nmenu '.a:topmenu.'.Table.Format<tab>gqq gqq'
|
||||
exe 'nmenu disable '.a:topmenu.'.Table'
|
||||
endfunction
|
||||
|
||||
if !empty(g:vimwiki_menu)
|
||||
call s:build_menu(g:vimwiki_menu)
|
||||
call s:build_table_menu(g:vimwiki_menu)
|
||||
endif
|
||||
" }}}
|
||||
|
||||
" CALENDAR Hook "{{{
|
||||
if g:vimwiki_use_calendar
|
||||
let g:calendar_action = 'vimwiki_diary#calendar_action'
|
||||
endif
|
||||
"}}}
|
||||
|
||||
let &cpo = s:old_cpo
|
||||
68
plugin/vstplugin.vim
Normal file
68
plugin/vstplugin.vim
Normal file
@@ -0,0 +1,68 @@
|
||||
" Vim reStructured Text
|
||||
" (c) Mikolaj Machowski 2006
|
||||
" Author: Mikolaj Machowski ( mikmach AT wp DOT pl )
|
||||
" Last Change: 4 Nov 2006
|
||||
" Version: 1.4
|
||||
" License:
|
||||
" Copyright (C) 2006 Mikolaj Machowski <mikmach@wp.pl>
|
||||
"
|
||||
" This script is free software; you can redistribute it and/or
|
||||
" modify it under the terms of the GNU Library General Public
|
||||
" License as published by the Free Software Foundation; either
|
||||
" version 2 of the License, or (at your option) any later version.
|
||||
"
|
||||
" This library is distributed in the hope that it will be useful,
|
||||
" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
" Library General Public License for more details.
|
||||
"
|
||||
" You should have received a copy of the GNU Library General Public License
|
||||
" along with this library; see the file COPYING.LIB. If not, write to
|
||||
" the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
" Boston, MA 02110-1301, USA.
|
||||
"
|
||||
" VST requires Vim7
|
||||
if v:version < 700
|
||||
finish
|
||||
endif
|
||||
|
||||
" Command :Vst
|
||||
command! -range=% -nargs=? -complete=custom,VST_Args Vst call vst#vst#VST_Export(<line1>, <line2>, <q-args>)
|
||||
command! -range=% -nargs=? -complete=custom,VST_Args Vsti call vst#vst#VST_InstantWrapper(<line1>, <line2>, <q-args>)
|
||||
command! -range=% -nargs=? -complete=custom,VST_Args Vstm call VST_Menus()
|
||||
|
||||
" VST_Args: Command line completion for :Vst command {{{
|
||||
function! VST_Args(A, C, P)
|
||||
let args = "html,tex,latex,pdf,toc,head,fold,link,slink,rep,srep,preproc,help,rest"
|
||||
return substitute(args, ',', '\n', 'g')
|
||||
endfunction
|
||||
" }}}
|
||||
" Menus {{{
|
||||
function! VST_Menus()
|
||||
if has("gui_running")
|
||||
menu VreST.Export\ to\ HTML :Vst html<cr>
|
||||
menu VreST.Export\ to\ LaTeX :Vst tex<cr>
|
||||
menu VreST.Export\ to\ PDF :Vst pdf<cr>
|
||||
menu VreST.Export\ to\ reST :Vst rest<cr>
|
||||
menu VreST.Fold :Vst fold<cr>
|
||||
menu VreST.Headers :Vst head<cr>
|
||||
menu VreST.TOC :Vst toc<cr>
|
||||
menu VreST.Help :Vst help<cr>
|
||||
inoremenu VreST.Export\ to\ HTML <c-o>:Vst html<cr>
|
||||
inoremenu VreST.Export\ to\ LaTeX <c-o>:Vst tex<cr>
|
||||
inoremenu VreST.Export\ to\ PDF <c-o>:Vst pdf<cr>
|
||||
inoremenu VreST.Export\ to\ reST <c-o>:Vst rest<cr>
|
||||
inoremenu VreST.Fold <c-o>:Vst fold<cr>
|
||||
inoremenu VreST.Headers <c-o>:Vst head<cr>
|
||||
inoremenu VreST.TOC <c-o>:Vst toc<cr>
|
||||
inoremenu VreST.Help <c-o>:Vst help<cr>
|
||||
endif
|
||||
endfunction
|
||||
if exists("g:vst_showmenu") && g:vst_load_menus != 0
|
||||
call VST_Menus()
|
||||
endif
|
||||
" }}}
|
||||
" Load auxiliary mappings:
|
||||
call vst#vst#VST_AuxiliaryMappings()
|
||||
|
||||
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4:nowrap
|
||||
Reference in New Issue
Block a user