1
0
mirror of https://github.com/gryf/.vim.git synced 2025-12-17 19:40:29 +01:00

Update of Mark, syntastic, taglisttoo and ctrlp plugins

This commit is contained in:
2012-03-26 19:05:47 +02:00
parent 1e1164cd0c
commit 1178b8be6d
21 changed files with 1335 additions and 778 deletions

View File

@@ -7,7 +7,7 @@ ScriptID SourceID Filename
3304 17406 gundo.vim 3304 17406 gundo.vim
2727 11120 jsbeautify.vim 2727 11120 jsbeautify.vim
2289 8922 loremipsum 2289 8922 loremipsum
2666 17554 Mark 2666 17661 Mark
1218 14455 nerdcommenter 1218 14455 nerdcommenter
2262 8944 occur.vim 2262 8944 occur.vim
2136 8206 repeat.vim 2136 8206 repeat.vim

View File

@@ -2,10 +2,10 @@
" File: autoload/ctrlp.vim " File: autoload/ctrlp.vim
" Description: Fuzzy file, buffer, mru and tag finder. " Description: Fuzzy file, buffer, mru and tag finder.
" Author: Kien Nguyen <github.com/kien> " Author: Kien Nguyen <github.com/kien>
" Version: 1.7.2 " Version: 1.7.4
" ============================================================================= " =============================================================================
" Static variables {{{1 " * Static variables {{{1
fu! s:opts() fu! s:opts()
" Options " Options
let hst = exists('+hi') ? &hi : 20 let hst = exists('+hi') ? &hi : 20
@@ -21,6 +21,7 @@ fu! s:opts()
\ 'g:ctrlp_highlight_match': ['s:mathi', [1, 'CtrlPMatch']], \ 'g:ctrlp_highlight_match': ['s:mathi', [1, 'CtrlPMatch']],
\ 'g:ctrlp_jump_to_buffer': ['s:jmptobuf', 2], \ 'g:ctrlp_jump_to_buffer': ['s:jmptobuf', 2],
\ 'g:ctrlp_lazy_update': ['s:lazy', 0], \ 'g:ctrlp_lazy_update': ['s:lazy', 0],
\ 'g:ctrlp_match_func': ['s:matcher', {}],
\ 'g:ctrlp_match_window_bottom': ['s:mwbottom', 1], \ 'g:ctrlp_match_window_bottom': ['s:mwbottom', 1],
\ 'g:ctrlp_match_window_reversed': ['s:mwreverse', 1], \ 'g:ctrlp_match_window_reversed': ['s:mwreverse', 1],
\ 'g:ctrlp_max_depth': ['s:maxdepth', 40], \ 'g:ctrlp_max_depth': ['s:maxdepth', 40],
@@ -203,7 +204,7 @@ fu! s:Close()
unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
\ g:ctrlp_nolimit \ g:ctrlp_nolimit
cal ctrlp#recordhist() cal ctrlp#recordhist()
cal s:onexit() cal s:extvar('exit')
cal s:log(0) cal s:log(0)
ec ec
endf endf
@@ -224,8 +225,10 @@ endf
fu! ctrlp#reset() fu! ctrlp#reset()
cal s:opts() cal s:opts()
cal s:autocmds()
cal ctrlp#utils#opts() cal ctrlp#utils#opts()
cal ctrlp#mrufiles#opts() cal ctrlp#mrufiles#opts()
cal s:extvar('opts')
endf endf
" * Files {{{1 " * Files {{{1
fu! ctrlp#files() fu! ctrlp#files()
@@ -307,25 +310,28 @@ fu! s:lsCmd()
retu cmd['types'][key][1] retu cmd['types'][key][1]
en en
endf endf
" Buffers {{{1 " - Buffers {{{1
fu! ctrlp#buffers() fu! ctrlp#buffers()
retu map(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))' retu map(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
\ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))'), \ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))'),
\ 'fnamemodify(bufname(v:val), ":.")') \ 'fnamemodify(bufname(v:val), ":.")')
endf endf
" * MatchedItems() {{{1 " * MatchedItems() {{{1
fu! s:MatchIt(items, pat, limit, mfunc, ipt) fu! s:MatchIt(items, pat, limit, mfunc, ipt, exc)
let [newitems, crfile] = [[], exists('s:crfilerel') ? s:crfilerel : ''] let [newitems, id, itlen] = [[], 0, len(a:items)]
for item in a:items wh id < itlen
try | if !( a:ipt && item == crfile ) && call(a:mfunc, [item, a:pat]) >= 0 let item = a:items[id]
let id += 1
try | if !( a:ipt && item == a:exc ) && call(a:mfunc, [item, a:pat]) >= 0
cal add(newitems, item) cal add(newitems, item)
en | cat | brea | endt en | cat | brea | endt
if a:limit > 0 && len(newitems) >= a:limit | brea | en if a:limit > 0 && len(newitems) >= a:limit | brea | en
endfo endw
let s:mdata = [s:dyncwd, s:itemtype, s:regexp, a:items[(id):]]
retu newitems retu newitems
endf endf
fu! s:MatchedItems(items, pat, limit, ipt) fu! s:MatchedItems(items, str, pat, limit, ipt)
let [type, mfunc] = [s:type(1), 'match'] let [type, mfunc] = [s:type(1), 'match']
if s:byfname && a:ipt if s:byfname && a:ipt
let mfunc = 's:matchfname' let mfunc = 's:matchfname'
@@ -333,11 +339,20 @@ fu! s:MatchedItems(items, pat, limit, ipt)
let types = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' } let types = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' }
if has_key(types, type) | let mfunc = types[type] | en if has_key(types, type) | let mfunc = types[type] | en
en en
let newitems = s:MatchIt(a:items, a:pat, a:limit, mfunc, a:ipt) let exc = exists('s:crfilerel') ? s:crfilerel : ''
let matfunc = 's:MatchIt'
let items = s:narrowable() ? s:matched + s:mdata[3] : a:items
let argms = [items, a:pat, a:limit, mfunc, a:ipt, exc]
if s:matcher != {} && has_key(s:matcher, 'match')
let [matfunc, argms[1], argms[3]] = s:matargs(mfunc, a:str)
let argms += [s:regexp]
en
let newitems = call(matfunc, argms)
let s:matches = len(newitems) let s:matches = len(newitems)
retu newitems retu newitems
endf endf
fu! s:SplitPattern(str) "{{{1
fu! s:SplitPattern(str)
let str = a:str let str = a:str
if s:migemo && s:regexp && len(str) > 0 && executable('cmigemo') if s:migemo && s:regexp && len(str) > 0 && executable('cmigemo')
let str = s:migemo(str) let str = s:migemo(str)
@@ -379,9 +394,8 @@ fu! s:Render(lines, pat, ipt)
if s:dohighlight() | cal clearmatches() | en if s:dohighlight() | cal clearmatches() | en
retu retu
en en
" Sort if not MRU if ( ( s:itemtype != 2 && !exists('g:ctrlp_nolimit') )
if ( s:itemtype != 2 && !exists('g:ctrlp_nolimit') ) \ || s:prompt != ['', '', ''] ) && s:matcher == {}
\ || s:prompt != ['', '', '']
let s:compat = a:pat let s:compat = a:pat
cal sort(lines, 's:mixedsort') cal sort(lines, 's:mixedsort')
unl s:compat unl s:compat
@@ -412,7 +426,7 @@ fu! s:Update(str)
if str == oldstr && !empty(str) && !exists('s:force') | retu | en if str == oldstr && !empty(str) && !exists('s:force') | retu | en
let [pat, ipt] = [s:SplitPattern(str), s:ispathitem()] let [pat, ipt] = [s:SplitPattern(str), s:ispathitem()]
let lines = exists('g:ctrlp_nolimit') && empty(str) ? copy(g:ctrlp_lines) let lines = exists('g:ctrlp_nolimit') && empty(str) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, pat, s:winh, ipt) \ : s:MatchedItems(g:ctrlp_lines, str, pat, s:winh, ipt)
cal s:Render(lines, pat, ipt) cal s:Render(lines, pat, ipt)
endf endf
@@ -459,8 +473,10 @@ endf
fu! s:PrtAdd(char) fu! s:PrtAdd(char)
unl! s:hstgot unl! s:hstgot
let s:act_add = 1
let s:prompt[0] .= a:char let s:prompt[0] .= a:char
cal s:BuildPrompt(1) cal s:BuildPrompt(1)
unl s:act_add
endf endf
fu! s:PrtBS() fu! s:PrtBS()
@@ -577,7 +593,7 @@ fu! s:PrtClearCache()
cal ctrlp#clr(s:statypes[s:itemtype][1]) cal ctrlp#clr(s:statypes[s:itemtype][1])
en en
if s:itemtype == 2 if s:itemtype == 2
let g:ctrlp_lines = ctrlp#mrufiles#list(-1, 1) let g:ctrlp_lines = ctrlp#mrufiles#refresh()
el el
cal ctrlp#setlines(s:itemtype) cal ctrlp#setlines(s:itemtype)
en en
@@ -588,13 +604,13 @@ endf
fu! s:PrtDeleteMRU() fu! s:PrtDeleteMRU()
if s:itemtype != 2 | retu | en if s:itemtype != 2 | retu | en
let [s:force, ags] = [1, [-1, 2]] let [s:force, tbrem] = [1, []]
if exists('s:marked') if exists('s:marked')
let ags = [-1, 2, values(s:marked)] let tbrem = values(s:marked)
cal s:unmarksigns() cal s:unmarksigns()
unl s:marked unl s:marked
en en
let g:ctrlp_lines = call('ctrlp#mrufiles#list', ags) let g:ctrlp_lines = ctrlp#mrufiles#remove(tbrem)
cal s:BuildPrompt(1) cal s:BuildPrompt(1)
unl s:force unl s:force
endf endf
@@ -684,7 +700,7 @@ endf
fu! s:ToggleType(dir) fu! s:ToggleType(dir)
let ext = exists('g:ctrlp_ext_vars') ? len(g:ctrlp_ext_vars) : 0 let ext = exists('g:ctrlp_ext_vars') ? len(g:ctrlp_ext_vars) : 0
let s:itemtype = s:walker(g:ctrlp_builtins + ext, s:itemtype, a:dir) let s:itemtype = s:walker(2 + ext, s:itemtype, a:dir)
if s:byfname && !s:ispathitem() | let s:byfname = 0 | en if s:byfname && !s:ispathitem() | let s:byfname = 0 | en
unl! g:ctrlp_nolimit unl! g:ctrlp_nolimit
if has('syntax') && exists('g:syntax_on') if has('syntax') && exists('g:syntax_on')
@@ -699,8 +715,10 @@ fu! s:PrtSwitcher()
cal s:BuildPrompt(1, s:Focus()) cal s:BuildPrompt(1, s:Focus())
unl s:force unl s:force
endf endf
fu! s:SetWD(...) "{{{1 " - SetWD() {{{1
let [pathmode, s:crfilerel] = [s:wpmode, fnamemodify(s:crfile, ':.')] fu! s:SetWD(...)
let pathmode = s:wpmode
let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
if a:0 && strlen(a:1) | if type(a:1) if a:0 && strlen(a:1) | if type(a:1)
cal ctrlp#setdir(a:1) | retu cal ctrlp#setdir(a:1) | retu
el el
@@ -717,7 +735,7 @@ fu! s:SetWD(...) "{{{1
cal extend(markers, s:rmarkers, 0) cal extend(markers, s:rmarkers, 0)
en en
for marker in markers for marker in markers
cal s:findroot(getcwd(), marker, 0, 0) cal s:findroot(s:dyncwd, marker, 0, 0)
if exists('s:foundroot') | brea | en if exists('s:foundroot') | brea | en
endfo endfo
unl! s:foundroot unl! s:foundroot
@@ -742,7 +760,7 @@ fu! ctrlp#acceptfile(mode, line, ...)
if j2l | cal ctrlp#j2l(j2l) | en if j2l | cal ctrlp#j2l(j2l) | en
el el
" Determine the command to use " Determine the command to use
let useb = bufnr > 0 && empty(tail) let useb = bufnr > 0 && getbufvar(bufnr, '&bl') && empty(tail)
let cmd = let cmd =
\ md == 't' || s:splitwin == 1 ? ( useb ? 'tab sb' : 'tabe' ) : \ md == 't' || s:splitwin == 1 ? ( useb ? 'tab sb' : 'tabe' ) :
\ md == 'h' || s:splitwin == 2 ? ( useb ? 'sb' : 'new' ) : \ md == 'h' || s:splitwin == 2 ? ( useb ? 'sb' : 'new' ) :
@@ -794,10 +812,11 @@ fu! s:AcceptSelection(mode)
if empty(line) | retu | en if empty(line) | retu | en
" Do something with it " Do something with it
let actfunc = s:itemtype < 3 ? 'ctrlp#acceptfile' let actfunc = s:itemtype < 3 ? 'ctrlp#acceptfile'
\ : g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )]['accept'] \ : g:ctrlp_ext_vars[s:itemtype - 3]['accept']
cal call(actfunc, [a:mode, line]) cal call(actfunc, [a:mode, line])
endf endf
fu! s:CreateNewFile(...) "{{{1 " - CreateNewFile() {{{1
fu! s:CreateNewFile(...)
let [md, str] = ['', join(s:prompt, '')] let [md, str] = ['', join(s:prompt, '')]
if empty(str) | retu | en if empty(str) | retu | en
if s:argmap && !a:0 if s:argmap && !a:0
@@ -830,8 +849,7 @@ fu! s:CreateNewFile(...) "{{{1
endf endf
" * OpenMulti() {{{1 " * OpenMulti() {{{1
fu! s:MarkToOpen() fu! s:MarkToOpen()
if s:bufnr <= 0 || s:opmul == '0' if s:bufnr <= 0 || s:opmul == '0' || ( s:itemtype > 2 && s:type() !~ 'rts' )
\ || ( s:itemtype > g:ctrlp_builtins && s:type() !~ 'rts' )
retu retu
en en
let line = !empty(s:matched) ? s:matched[line('.') - 1] : '' let line = !empty(s:matched) ? s:matched[line('.') - 1] : ''
@@ -875,7 +893,8 @@ fu! s:OpenMulti()
" Move the cursor to a reusable window " Move the cursor to a reusable window
let [tail, fnesc] = [s:tail(), exists('*fnameescape') && v:version > 701] let [tail, fnesc] = [s:tail(), exists('*fnameescape') && v:version > 701]
let [emptytail, nwpt] = [empty(tail), exists('g:ctrlp_open_multiple_files')] let [emptytail, nwpt] = [empty(tail), exists('g:ctrlp_open_multiple_files')]
let useb = bufnr('^'.mkd[0].'$') > 0 && emptytail let bufnr = bufnr('^'.mkd[0].'$')
let useb = bufnr > 0 && getbufvar(bufnr, '&bl') && emptytail
let fst = call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e']) let fst = call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e'])
" Check if it's a replaceable buffer " Check if it's a replaceable buffer
let repabl = ( empty(bufname('%')) && empty(&l:ft) ) || s:nosplit() let repabl = ( empty(bufname('%')) && empty(&l:ft) ) || s:nosplit()
@@ -886,7 +905,7 @@ fu! s:OpenMulti()
" Open the files " Open the files
for va in mkd for va in mkd
let bufnr = bufnr('^'.va.'$') let bufnr = bufnr('^'.va.'$')
let useb = bufnr > 0 && emptytail let useb = bufnr > 0 && getbufvar(bufnr, '&bl') && emptytail
let snd = md != '' && has_key(cmds, md) ? let snd = md != '' && has_key(cmds, md) ?
\ ( useb ? cmds[md][0] : cmds[md][1] ) : ( useb ? 'vert sb' : 'vne' ) \ ( useb ? cmds[md][0] : cmds[md][1] ) : ( useb ? 'vert sb' : 'vne' )
let cmd = ic == 1 && ( ucr == 'r' || repabl ) ? fst : snd let cmd = ic == 1 && ( ucr == 'r' || repabl ) ? fst : snd
@@ -925,6 +944,15 @@ fu! s:comptime(s1, s2)
retu time1 == time2 ? 0 : time1 < time2 ? 1 : -1 retu time1 == time2 ? 0 : time1 < time2 ? 1 : -1
endf endf
fu! s:compmre(...)
" By last entered time (buffer only)
if !exists('s:mrbs')
let s:mrbs = ctrlp#mrufiles#bufs()
en
let cwd = getcwd()
retu index(s:mrbs, cwd.s:lash().a:1) - index(s:mrbs, cwd.s:lash().a:2)
endf
fu! s:comparent(s1, s2) fu! s:comparent(s1, s2)
" By same parent dir " By same parent dir
let cwd = getcwd() let cwd = getcwd()
@@ -968,8 +996,11 @@ fu! s:mixedsort(s1, s2)
if s:itemtype < 3 && s:height < 51 if s:itemtype < 3 && s:height < 51
let [par, cfn] = [s:comparent(a:s1, a:s2), s:compfnlen(a:s1, a:s2)] let [par, cfn] = [s:comparent(a:s1, a:s2), s:compfnlen(a:s1, a:s2)]
if s:height < 21 if s:height < 21
let ctm = s:comptime(a:s1, a:s2) let [muls, ctm] = s:itemtype == 1
retu 12 * cml + 6 * par + 3 * cfn + 2 * ctm + cln \ ? [[6, 3, 2, 12], s:compmre(a:s1, a:s2)]
\ : [[12, 6, 3, 2], s:comptime(a:s1, a:s2)]
unl! s:mrbs
retu muls[0] * cml + muls[1] * par + muls[2] * cfn + muls[3] * ctm + cln
en en
retu 6 * cml + 3 * par + 2 * cfn + cln retu 6 * cml + 3 * par + 2 * cfn + cln
en en
@@ -1001,7 +1032,7 @@ fu! ctrlp#statusline()
let byfname = s:byfname ? 'file' : 'path' let byfname = s:byfname ? 'file' : 'path'
let marked = s:opmul != '0' ? let marked = s:opmul != '0' ?
\ exists('s:marked') ? ' <'.s:dismrk().'>' : ' <->' : '' \ exists('s:marked') ? ' <'.s:dismrk().'>' : ' <->' : ''
if has_key(s:status, 'main') if s:status != {} && has_key(s:status, 'main')
let args = [focus, byfname, s:regexp, prv, item, nxt, marked] let args = [focus, byfname, s:regexp, prv, item, nxt, marked]
let &l:stl = call(s:status['main'], args) let &l:stl = call(s:status['main'], args)
el el
@@ -1022,7 +1053,8 @@ endf
fu! ctrlp#progress(enum) fu! ctrlp#progress(enum)
if has('macunix') || has('mac') | sl 1m | en if has('macunix') || has('mac') | sl 1m | en
let &l:stl = has_key(s:status, 'prog') ? call(s:status['prog'], [a:enum]) let &l:stl = s:status != {} && has_key(s:status, 'prog')
\ ? call(s:status['prog'], [a:enum])
\ : '%#CtrlPStats# '.a:enum.' %* %=%<%#CtrlPMode2# '.getcwd().' %*' \ : '%#CtrlPStats# '.a:enum.' %* %=%<%#CtrlPMode2# '.getcwd().' %*'
redraws redraws
endf endf
@@ -1065,9 +1097,8 @@ fu! s:lash(...)
endf endf
fu! s:ispathitem() fu! s:ispathitem()
let ext = s:itemtype - ( g:ctrlp_builtins + 1 ) retu s:itemtype < 3 ||
retu s:itemtype < 3 \ ( s:itemtype > 2 && g:ctrlp_ext_vars[s:itemtype - 3]['type'] == 'path' )
\ || ( s:itemtype > 2 && g:ctrlp_ext_vars[ext]['type'] == 'path' )
endf endf
fu! ctrlp#dirnfile(entries) fu! ctrlp#dirnfile(entries)
@@ -1156,7 +1187,7 @@ endf
fu! ctrlp#setdir(path, ...) fu! ctrlp#setdir(path, ...)
let cmd = a:0 ? a:1 : 'lc!' let cmd = a:0 ? a:1 : 'lc!'
sil! exe cmd ctrlp#fnesc(a:path) sil! exe cmd ctrlp#fnesc(a:path)
let s:crfilerel = fnamemodify(s:crfile, ':.') let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
endf endf
fu! ctrlp#setlcdir() fu! ctrlp#setlcdir()
@@ -1180,6 +1211,7 @@ fu! ctrlp#syntax()
endf endf
fu! s:highlight(pat, grp, ipt) fu! s:highlight(pat, grp, ipt)
if s:matcher != {} | retu | en
cal clearmatches() cal clearmatches()
if !empty(a:pat) && a:ipt if !empty(a:pat) && a:ipt
let pat = s:regexp ? substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g') : a:pat let pat = s:regexp ? substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g') : a:pat
@@ -1342,6 +1374,22 @@ fu! s:argmaps(md, ...)
retu a:md retu a:md
endf endf
" Misc {{{2 " Misc {{{2
fu! s:narrowable()
retu exists('s:act_add') && exists('s:matched') && s:matched != []
\ && exists('s:mdata') && s:mdata[:2] == [s:dyncwd, s:itemtype, s:regexp]
\ && s:matcher == {}
endf
fu! s:matargs(mfunc, str)
let match_type = {
\ 'match': 'full-line',
\ 's:matchfname': 'filename-only',
\ 's:matchtabs': 'first-non-tab',
\ 's:matchtabe': 'until-last-tab',
\ }
retu [s:matcher['match'], a:str, match_type[a:mfunc]]
endf
fu! s:log(m) fu! s:log(m)
if exists('g:ctrlp_log') && g:ctrlp_log | if a:m if exists('g:ctrlp_log') && g:ctrlp_log | if a:m
let cadir = ctrlp#utils#cachedir() let cadir = ctrlp#utils#cachedir()
@@ -1365,9 +1413,8 @@ fu! s:getenv()
let s:wpmode = exists('b:ctrlp_working_path_mode') let s:wpmode = exists('b:ctrlp_working_path_mode')
\ ? b:ctrlp_working_path_mode : s:pathmode \ ? b:ctrlp_working_path_mode : s:pathmode
if exists('g:ctrlp_extensions') if exists('g:ctrlp_extensions')
if index(g:ctrlp_extensions, 'undo') >= 0 && exists('*undotree') if index(g:ctrlp_extensions, 'undo') >= 0
\ && ( v:version > 703 || ( v:version == 703 && has('patch005') ) ) let s:undos = s:getundo()
let s:undotree = undotree()
en en
if index(g:ctrlp_extensions, 'tag') >= 0 if index(g:ctrlp_extensions, 'tag') >= 0
let s:tagfiles = s:tagfiles() let s:tagfiles = s:tagfiles()
@@ -1440,8 +1487,8 @@ fu! s:regexfilter(str)
retu str retu str
endf endf
fu! s:walker(max, pos, dir) fu! s:walker(m, p, d)
retu a:dir > 0 ? a:pos < a:max ? a:pos + 1 : 0 : a:pos > 0 ? a:pos - 1 : a:max retu a:d > 0 ? a:p < a:m ? a:p + a:d : 0 : a:p > 0 ? a:p + a:d : a:m
endf endf
fu! s:matchfname(item, pat) fu! s:matchfname(item, pat)
@@ -1478,18 +1525,30 @@ fu! s:insertcache(str)
endf endf
" Extensions {{{2 " Extensions {{{2
fu! s:type(...) fu! s:type(...)
let ext = s:itemtype - ( g:ctrlp_builtins + 1 ) retu s:itemtype > 2
retu s:itemtype > 2 ? g:ctrlp_ext_vars[ext][a:0 ? 'type' : 'sname'] : s:itemtype \ ? g:ctrlp_ext_vars[s:itemtype - 3][a:0 ? 'type' : 'sname'] : s:itemtype
endf endf
fu! s:tagfiles() fu! s:tagfiles()
retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)') retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)')
endf endf
fu! s:onexit() fu! s:extvar(key)
if exists('g:ctrlp_ext_vars') if exists('g:ctrlp_ext_vars')
cal map(filter(copy(g:ctrlp_ext_vars), cal map(filter(copy(g:ctrlp_ext_vars),
\ 'has_key(v:val, "exit")'), 'eval(v:val["exit"])') \ 'has_key(v:val, a:key)'), 'eval(v:val[a:key])')
en
endf
fu! s:getundo()
if exists('*undotree')
\ && ( v:version > 703 || ( v:version == 703 && has('patch005') ) )
retu [1, undotree()]
el
redi => result
sil! undol
redi END
retu [0, split(result, "\n")[1:]]
en en
endf endf
@@ -1500,6 +1559,10 @@ endf
fu! ctrlp#prtclear() fu! ctrlp#prtclear()
cal s:PrtClear() cal s:PrtClear()
endf endf
fu! ctrlp#switchtype(id)
cal s:ToggleType(a:id - s:itemtype)
endf
"}}}1 "}}}1
" * Initialization {{{1 " * Initialization {{{1
fu! ctrlp#setlines(type) fu! ctrlp#setlines(type)
@@ -1507,7 +1570,7 @@ fu! ctrlp#setlines(type)
let types = [ let types = [
\ 'ctrlp#files()', \ 'ctrlp#files()',
\ 'ctrlp#buffers()', \ 'ctrlp#buffers()',
\ 'ctrlp#mrufiles#list(-1)', \ 'ctrlp#mrufiles#list()',
\ ] \ ]
if exists('g:ctrlp_ext_vars') if exists('g:ctrlp_ext_vars')
cal map(copy(g:ctrlp_ext_vars), 'add(types, v:val["init"])') cal map(copy(g:ctrlp_ext_vars), 'add(types, v:val["init"])')
@@ -1527,16 +1590,27 @@ fu! ctrlp#init(type, ...)
cal ctrlp#setlines(a:type) cal ctrlp#setlines(a:type)
cal s:BuildPrompt(1) cal s:BuildPrompt(1)
endf endf
if has('autocmd') "{{{1 " - Autocmds {{{1
fu! s:autocmds()
if !has('autocmd') | retu | en
aug CtrlPAug aug CtrlPAug
au! au!
au BufEnter ControlP cal s:checkbuf() au BufEnter ControlP cal s:checkbuf()
au BufLeave ControlP cal s:Close() au BufLeave ControlP cal s:Close()
au VimLeavePre * cal s:leavepre() au VimLeavePre * cal s:leavepre()
if s:lazy
au CursorHold ControlP cal s:ForceUpdate()
en
aug END aug END
en "}}} if exists('#CtrlPLazy')
au! CtrlPLazy
en
if s:lazy
aug CtrlPLazy
au!
au CursorHold ControlP cal s:ForceUpdate()
aug END
en
endf
cal s:autocmds()
"}}}
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2

View File

@@ -20,6 +20,7 @@ let s:buftag_var = {
\ 'sname': 'bft', \ 'sname': 'bft',
\ 'exit': 'ctrlp#buffertag#exit()', \ 'exit': 'ctrlp#buffertag#exit()',
\ 'type': 'tabs', \ 'type': 'tabs',
\ 'opts': 'ctrlp#buffertag#opts()',
\ } \ }
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
@@ -27,7 +28,7 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
fu! s:opts() fu! ctrlp#buffertag#opts()
let opts = { let opts = {
\ 'g:ctrlp_buftag_systemenc': ['s:enc', &enc], \ 'g:ctrlp_buftag_systemenc': ['s:enc', &enc],
\ 'g:ctrlp_buftag_ctags_bin': ['s:bin', ''], \ 'g:ctrlp_buftag_ctags_bin': ['s:bin', ''],
@@ -37,7 +38,7 @@ fu! s:opts()
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1]) exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
endfo endfo
endf endf
cal s:opts() cal ctrlp#buffertag#opts()
fu! s:bins() fu! s:bins()
let bins = [ let bins = [
@@ -196,6 +197,21 @@ fu! s:parseline(line)
let [bufnr, bufname] = [bufnr('^'.vals[2].'$'), fnamemodify(vals[2], ':p:t')] let [bufnr, bufname] = [bufnr('^'.vals[2].'$'), fnamemodify(vals[2], ':p:t')]
retu vals[1].' '.vals[4].'|'.bufnr.':'.bufname.'|'.vals[6].'| '.vals[3] retu vals[1].' '.vals[4].'|'.bufnr.':'.bufname.'|'.vals[6].'| '.vals[3]
endf endf
fu! s:syntax()
if !hlexists('CtrlPTagKind')
hi link CtrlPTagKind Title
en
if !hlexists('CtrlPBufName')
hi link CtrlPBufName Directory
en
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPTagKind '\zs[^\t|]\+\ze|\d\+:[^|]\+|\d\+|'
sy match CtrlPBufName '|\d\+:\zs[^|]\+\ze|\d\+|'
sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName,CtrlPTagKind
endf
" Public {{{1 " Public {{{1
fu! ctrlp#buffertag#init(fname) fu! ctrlp#buffertag#init(fname)
let bufs = exists('s:btmode') && s:btmode let bufs = exists('s:btmode') && s:btmode
@@ -203,14 +219,12 @@ fu! ctrlp#buffertag#init(fname)
\ : [exists('s:bufname') ? s:bufname : a:fname] \ : [exists('s:bufname') ? s:bufname : a:fname]
let lines = [] let lines = []
for each in bufs for each in bufs
let tftype = get(split(getbufvar(each, '&ft'), '\.'), 0, '') let bname = fnamemodify(each, ':p')
cal extend(lines, s:process(each, tftype)) let tftype = get(split(getbufvar(bname, '&ft'), '\.'), 0, '')
cal extend(lines, s:process(bname, tftype))
endfo endfo
if has('syntax') && exists('g:syntax_on') if has('syntax') && exists('g:syntax_on')
if !hlexists('CtrlPTabExtra') cal s:syntax()
hi link CtrlPTabExtra Comment
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
en en
retu lines retu lines
endf endf

View File

@@ -1,20 +1,9 @@
" ============================================================================= " =============================================================================
" File: autoload/ctrlp/changes.vim " File: autoload/ctrlp/changes.vim
" Description: Change list extension - Jump to a recent change in any buffer " Description: Change list extension
" Author: Kien Nguyen <github.com/kien> " Author: Kien Nguyen <github.com/kien>
" ============================================================================= " =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['changes']
" Create Some Commands:
" " Single buffer
" com! -n=? -com=buffer CtrlPChange
" \ cal ctrlp#init(ctrlp#changes#cmd(0, <q-args>))
" " All listed buffers
" com! CtrlPChangeAll cal ctrlp#init(ctrlp#changes#cmd(1))
"}}}
" Init {{{1 " Init {{{1
if exists('g:loaded_ctrlp_changes') && g:loaded_ctrlp_changes if exists('g:loaded_ctrlp_changes') && g:loaded_ctrlp_changes
fini fini
@@ -54,6 +43,17 @@ fu! s:process(clines, ...)
endfo endfo
retu reverse(filter(clines, 'count(clines, v:val) == 1')) retu reverse(filter(clines, 'count(clines, v:val) == 1'))
endf endf
fu! s:syntax()
if !hlexists('CtrlPBufName')
hi link CtrlPBufName Directory
en
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPBufName '\t|\d\+:\zs[^|]\+\ze|\d\+:\d\+|$'
sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName
endf
" Public {{{1 " Public {{{1
fu! ctrlp#changes#init(original_bufnr, fname) fu! ctrlp#changes#init(original_bufnr, fname)
let fname = exists('s:bufname') ? s:bufname : a:fname let fname = exists('s:bufname') ? s:bufname : a:fname
@@ -62,7 +62,8 @@ fu! ctrlp#changes#init(original_bufnr, fname)
let [swb, &swb] = [&swb, ''] let [swb, &swb] = [&swb, '']
let lines = [] let lines = []
for each in bufs for each in bufs
let [bufnr, fnamet] = [bufnr('^'.each.'$'), fnamemodify(each, ':t')] let [bname, fnamet] = [fnamemodify(each, ':p'), fnamemodify(each, ':t')]
let bufnr = bufnr('^'.bname.'$')
if bufnr > 0 if bufnr > 0
cal extend(lines, s:process(s:changelist(bufnr), bufnr, fnamet)) cal extend(lines, s:process(s:changelist(bufnr), bufnr, fnamet))
en en
@@ -72,10 +73,7 @@ fu! ctrlp#changes#init(original_bufnr, fname)
let g:ctrlp_nolimit = 1 let g:ctrlp_nolimit = 1
if has('syntax') && exists('g:syntax_on') if has('syntax') && exists('g:syntax_on')
cal ctrlp#syntax() cal ctrlp#syntax()
if !hlexists('CtrlPTabExtra') cal s:syntax()
hi link CtrlPTabExtra Comment
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
en en
retu lines retu lines
endf endf

View File

@@ -1,16 +1,9 @@
" ============================================================================= " =============================================================================
" File: autoload/ctrlp/line.vim " File: autoload/ctrlp/line.vim
" Description: Line extension - Find a line in any buffer " Description: Line extension
" Author: Kien Nguyen <github.com/kien> " Author: Kien Nguyen <github.com/kien>
" ============================================================================= " =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['line']
" Create A Command:
" com! CtrlPLine cal ctrlp#init(ctrlp#line#id())
"}}}
" Init {{{1 " Init {{{1
if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line
fini fini
@@ -29,13 +22,25 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:line_var) : [s:line_var] \ ? add(g:ctrlp_ext_vars, s:line_var) : [s:line_var]
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1
fu! s:syntax()
if !hlexists('CtrlPBufName')
hi link CtrlPBufName Directory
en
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPBufName '\t|\zs[^|]\+\ze|\d\+:\d\+|$'
sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName
endf
" Public {{{1 " Public {{{1
fu! ctrlp#line#init() fu! ctrlp#line#init()
let [bufs, lines] = [filter(ctrlp#buffers(), 'filereadable(v:val)'), []] let [bufs, lines] = [filter(ctrlp#buffers(), 'filereadable(v:val)'), []]
for each in bufs for each in bufs
let [fnamet, from_file] = [fnamemodify(each, ':t'), readfile(each)] let [fnamet, from_file] = [fnamemodify(each, ':t'), readfile(each)]
let bname = fnamemodify(each, ':p')
cal map(from_file, 'tr(v:val, '' '', '' '')') cal map(from_file, 'tr(v:val, '' '', '' '')')
let [id, len_ff, bufnr] = [1, len(from_file), bufnr('^'.each.'$')] let [id, len_ff, bufnr] = [1, len(from_file), bufnr('^'.bname.'$')]
wh id <= len_ff wh id <= len_ff
let from_file[id-1] .= ' |'.fnamet.'|'.bufnr.':'.id.'|' let from_file[id-1] .= ' |'.fnamet.'|'.bufnr.':'.id.'|'
let id += 1 let id += 1
@@ -44,10 +49,7 @@ fu! ctrlp#line#init()
cal extend(lines, from_file) cal extend(lines, from_file)
endfo endfo
if has('syntax') && exists('g:syntax_on') if has('syntax') && exists('g:syntax_on')
if !hlexists('CtrlPTabExtra') cal s:syntax()
hi link CtrlPTabExtra Comment
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
en en
retu lines retu lines
endf endf

View File

@@ -17,76 +17,108 @@ fu! ctrlp#mrufiles#opts()
for [ke, va] in items(opts) for [ke, va] in items(opts)
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1]) exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
endfo endfo
let s:csen = s:csen ? '#' : '?' let [s:csen, s:mrbs] = [s:csen ? '#' : '?', []]
if exists('s:locked')
cal ctrlp#mrufiles#init()
en
endf endf
cal ctrlp#mrufiles#opts() cal ctrlp#mrufiles#opts()
fu! ctrlp#mrufiles#list(bufnr, ...) "{{{1 " Utilities {{{1
if s:locked | retu | en fu! s:excl(fn)
let bufnr = a:bufnr + 0 retu !empty(s:ex) && a:fn =~# s:ex
if bufnr > 0 endf
let fn = fnamemodify(bufname(bufnr), ':p')
let fn = exists('+ssl') ? tr(fn, '/', '\') : fn fu! s:readcache()
if empty(fn) || !empty(&bt) || ( !empty(s:in) && fn !~# s:in )
\ || ( !empty(s:ex) && fn =~# s:ex ) || !filereadable(fn)
retu
en
en
if !exists('s:cadir') || !exists('s:cafile') if !exists('s:cadir') || !exists('s:cafile')
let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru' let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'
let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt' let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt'
en en
if a:0 && a:1 == 2 retu ctrlp#utils#readfile(s:cafile)
let mrufs = [] endf
if a:0 == 2
let mrufs = ctrlp#utils#readfile(s:cafile) fu! s:reformat(mrufs)
cal filter(mrufs, 'index(a:2, v:val) < 0') if s:re
en let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile) cal filter(a:mrufs, '!stridx(v:val, cwd)')
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
en en
" Get the list retu map(a:mrufs, 'fnamemodify(v:val, '':.'')')
let mrufs = ctrlp#utils#readfile(s:cafile) endf
" Remove non-existent files
if a:0 && a:1 == 1 fu! s:record(bufnr, ...)
cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)') if s:locked | retu | en
if exists('+ssl') let bufnr = a:bufnr + 0
cal map(mrufs, 'tr(v:val, ''/'', ''\'')') if bufnr <= 0 | retu | en
cal filter(mrufs, 'count(mrufs, v:val) == 1') let fn = fnamemodify(bufname(bufnr), ':p')
en let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile) cal filter(s:mrbs, 'v:val !='.s:csen.' fn')
cal insert(s:mrbs, fn)
if empty(fn) || !empty(&bt) || ( !empty(s:in) && fn !~# s:in )
\ || ( !empty(s:ex) && fn =~# s:ex ) || !filereadable(fn)
\ || ( a:0 && a:1 == 1 )
retu
en en
" Return the list with the active buffer removed let mrufs = s:readcache()
if bufnr == -1
if s:re
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
cal filter(mrufs, '!stridx(v:val, cwd)')
en
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
en
" Remove old entry
cal filter(mrufs, 'v:val !='.s:csen.' fn') cal filter(mrufs, 'v:val !='.s:csen.' fn')
" Insert new one
cal insert(mrufs, fn) cal insert(mrufs, fn)
" Remove oldest entry or entries
if len(mrufs) > s:max | cal remove(mrufs, s:max, -1) | en if len(mrufs) > s:max | cal remove(mrufs, s:max, -1) | en
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile) cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
endf "}}} endf
fu! s:excl(fn) "{{{ " Public {{{1
retu !empty(s:ex) && a:fn =~# s:ex fu! ctrlp#mrufiles#refresh()
endf "}}} let mrufs = s:readcache()
fu! ctrlp#mrufiles#init() "{{{1 cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
if exists('+ssl')
cal map(mrufs, 'tr(v:val, ''/'', ''\'')')
cal filter(mrufs, 'count(mrufs, v:val) == 1')
en
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
retu s:reformat(mrufs)
endf
fu! ctrlp#mrufiles#remove(files)
let mrufs = []
if a:files != []
let mrufs = s:readcache()
cal filter(mrufs, 'index(a:files, v:val) < 0')
en
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
endf
fu! ctrlp#mrufiles#list(...)
if a:0 | cal s:record(a:1) | retu | en
retu s:reformat(s:readcache())
endf
fu! ctrlp#mrufiles#bufs()
retu s:mrbs
endf
fu! ctrlp#mrufiles#init()
if !has('autocmd') | retu | en
let s:locked = 0 let s:locked = 0
aug CtrlPMRUF aug CtrlPMRUF
au! au!
au BufReadPost,BufNewFile,BufWritePost * au BufReadPost,BufNewFile,BufWritePost * cal s:record(expand('<abuf>', 1))
\ cal ctrlp#mrufiles#list(expand('<abuf>', 1))
if s:mre
au BufEnter,BufUnload *
\ cal ctrlp#mrufiles#list(expand('<abuf>', 1))
en
au QuickFixCmdPre *vimgrep* let s:locked = 1 au QuickFixCmdPre *vimgrep* let s:locked = 1
au QuickFixCmdPost *vimgrep* let s:locked = 0 au QuickFixCmdPost *vimgrep* let s:locked = 0
aug END aug END
aug CtrlPMREB
au!
au BufEnter,BufUnload * cal s:record(expand('<abuf>', 1), 1)
aug END
if exists('#CtrlPMREF')
au! CtrlPMREF
en
if s:mre
aug CtrlPMREF
au!
au BufEnter,BufUnload * cal s:record(expand('<abuf>', 1))
aug END
if exists('#CtrlPMREB')
au! CtrlPMREB
en
en
endf endf
"}}} "}}}

View File

@@ -1,28 +1,21 @@
" ============================================================================= " =============================================================================
" File: autoload/ctrlp/undo.vim " File: autoload/ctrlp/undo.vim
" Description: Undo extension - Browse undo history (requires Vim 7.3.005+) " Description: Undo extension
" Author: Kien Nguyen <github.com/kien> " Author: Kien Nguyen <github.com/kien>
" ============================================================================= " =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['undo']
" Create A Command:
" com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id())
"}}}
" Init {{{1 " Init {{{1
if ( exists('g:loaded_ctrlp_undo') && g:loaded_ctrlp_undo ) if ( exists('g:loaded_ctrlp_undo') && g:loaded_ctrlp_undo )
\ || !( v:version > 703 || ( v:version == 703 && has('patch005') ) )
fini fini
en en
let g:loaded_ctrlp_undo = 1 let g:loaded_ctrlp_undo = 1
let s:undo_var = { let s:undo_var = {
\ 'init': 'ctrlp#undo#init(s:undotree)', \ 'init': 'ctrlp#undo#init(s:undos)',
\ 'accept': 'ctrlp#undo#accept', \ 'accept': 'ctrlp#undo#accept',
\ 'lname': 'undo', \ 'lname': 'undo',
\ 'sname': 'udo', \ 'sname': 'udo',
\ 'exit': 'ctrlp#undo#exit()',
\ 'type': 'line', \ 'type': 'line',
\ } \ }
@@ -30,36 +23,31 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:undo_var) : [s:undo_var] \ ? add(g:ctrlp_ext_vars, s:undo_var) : [s:undo_var]
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
let s:text = map(['second', 'seconds', 'minutes', 'hours', 'days', 'weeks',
\ 'months', 'years'], '" ".v:val." ago"')
" Utilities {{{1 " Utilities {{{1
fu! s:flatten(tree) fu! s:flatten(tree, cur)
let flatdict = {} let flatdict = {}
for each in a:tree for each in a:tree
cal extend(flatdict, { each['seq'] : each['time'] }) let saved = has_key(each, 'save') ? 'saved' : ''
let current = each['seq'] == a:cur ? 'current' : ''
cal extend(flatdict, { each['seq'] : [each['time'], saved, current] })
if has_key(each, 'alt') if has_key(each, 'alt')
cal extend(flatdict, s:flatten(each['alt'])) cal extend(flatdict, s:flatten(each['alt'], a:cur))
en en
endfo endfo
retu flatdict retu flatdict
endf endf
fu! s:humantime(nr) fu! s:elapsed(nr)
let elapsed = localtime() - a:nr let [text, time] = [s:text, localtime() - a:nr]
let mins = elapsed / 60 let mins = time / 60
let hrs = elapsed / 3600 let hrs = time / 3600
let days = elapsed / 86400 let days = time / 86400
let wks = elapsed / 604800 let wks = time / 604800
let mons = elapsed / 2592000 let mons = time / 2592000
let yrs = elapsed / 31536000 let yrs = time / 31536000
let text = [
\ ' second ago',
\ ' seconds ago',
\ ' minutes ago',
\ ' hours ago',
\ ' days ago',
\ ' weeks ago',
\ ' months ago',
\ ' years ago',
\ ]
if yrs > 1 if yrs > 1
retu yrs.text[7] retu yrs.text[7]
elsei mons > 1 elsei mons > 1
@@ -72,42 +60,66 @@ fu! s:humantime(nr)
retu hrs.text[3] retu hrs.text[3]
elsei mins > 1 elsei mins > 1
retu mins.text[2] retu mins.text[2]
elsei elapsed == 1 elsei time == 1
retu elapsed.text[0] retu time.text[0]
elsei elapsed < 120 elsei time < 120
retu elapsed.text[1] retu time.text[1]
en en
endf endf
fu! s:syntax() fu! s:syntax()
for [ke, va] in items({'T': 'Directory', 'Br': 'Comment', 'Nr': 'String'}) for [ke, va] in items({'T': 'Directory', 'Br': 'Comment', 'Nr': 'String',
\ 'Sv': 'Comment', 'Po': 'Title'})
if !hlexists('CtrlPUndo'.ke) if !hlexists('CtrlPUndo'.ke)
exe 'hi link CtrlPUndo'.ke va exe 'hi link CtrlPUndo'.ke va
en en
endfo endfo
sy match CtrlPUndoT '\d\+ \zs[^ ]\+\ze' sy match CtrlPUndoT '\v\d+ \zs[^ ]+\ze|\d+:\d+:\d+'
sy match CtrlPUndoBr '\[\|\]' sy match CtrlPUndoBr '\[\|\]'
sy match CtrlPUndoNr '\[\d\+\]$' contains=CtrlPUndoBr sy match CtrlPUndoNr '\[\d\+\]' contains=CtrlPUndoBr
sy match CtrlPUndoSv 'saved'
sy match CtrlPUndoPo 'current'
endf endf
fu! s:dict2list(dict) fu! s:dict2list(dict)
let dict = map(a:dict, 's:humantime(v:val)') for ke in keys(a:dict)
retu map(keys(dict), 'eval(''[v:val, dict[v:val]]'')') let a:dict[ke][0] = s:elapsed(a:dict[ke][0])
endfo
retu map(keys(a:dict), 'eval(''[v:val, a:dict[v:val]]'')')
endf endf
fu! s:compval(...) fu! s:compval(...)
retu a:2[0] - a:1[0] retu a:2[0] - a:1[0]
endf endf
fu! s:format(...)
let saved = !empty(a:1[1][1]) ? ' '.a:1[1][1] : ''
let current = !empty(a:1[1][2]) ? ' '.a:1[1][2] : ''
retu a:1[1][0].' ['.a:1[0].']'.saved.current
endf
fu! s:formatul(...)
let parts = matchlist(a:1,
\ '\v^\s+(\d+)\s+\d+\s+([^ ]+\s?[^ ]+|\d+\s\w+\s\w+)(\s*\d*)$')
retu parts[2].' ['.parts[1].']'.( parts[3] != '' ? ' saved' : '' )
endf
" Public {{{1 " Public {{{1
fu! ctrlp#undo#init(undo) fu! ctrlp#undo#init(undo)
let entries = a:undo['entries'] let entries = a:undo[0] ? a:undo[1]['entries'] : a:undo[1]
if empty(entries) | retu [] | en if empty(entries) | retu [] | en
if has('syntax') && exists('g:syntax_on') if has('syntax') && exists('g:syntax_on')
cal s:syntax() cal s:syntax()
en en
let g:ctrlp_nolimit = 1 let g:ctrlp_nolimit = 1
let entries = sort(s:dict2list(s:flatten(entries)), 's:compval') if !exists('s:lines')
retu map(entries, 'v:val[1]." [".v:val[0]."]"') if a:undo[0]
let entries = s:dict2list(s:flatten(entries, a:undo[1]['seq_cur']))
let s:lines = map(sort(entries, 's:compval'), 's:format(v:val)')
el
let s:lines = map(reverse(entries), 's:formatul(v:val)')
en
en
retu s:lines
endf endf
fu! ctrlp#undo#accept(mode, str) fu! ctrlp#undo#accept(mode, str)
@@ -120,6 +132,10 @@ endf
fu! ctrlp#undo#id() fu! ctrlp#undo#id()
retu s:id retu s:id
endf endf
fu! ctrlp#undo#exit()
unl! s:lines
endf
"}}} "}}}
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2

View File

@@ -1,4 +1,4 @@
*ctrlp.txt* Fuzzy file, buffer, mru and tag finder. v1.7.2 *ctrlp.txt* Fuzzy file, buffer, mru and tag finder. v1.7.4
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'* *CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
=============================================================================== ===============================================================================
# # # #
@@ -175,12 +175,10 @@ only need to keep the lines that youve changed the values (inside []): >
\ } \ }
< <
Note: In some terminals, its not possible to remap <c-h> without also changing Note: In some terminals, its not possible to remap <c-h> without also changing
<bs> (|key-codes|). So if pressing <bs> moves the cursor to the left instead of <bs> (|keycodes|). So if pressing <bs> moves the cursor to the left instead of
deleting a char for you, add this to your |vimrc| to disable the default <c-h> deleting a char for you, add this to your |.vimrc| to disable the plugins
mapping: > default <c-h> mapping: >
let g:ctrlp_prompt_mappings = { let g:ctrlp_prompt_mappings = { 'PrtCurLeft()': ['<left>', '<c-^>'] }
\ 'PrtCurLeft()': ['<left>', '<c-^>']
\ }
< <
*'g:ctrlp_mruf_max'* *'g:ctrlp_mruf_max'*
@@ -386,8 +384,73 @@ Example: >
\ 'prog': 'Function_Name_2', \ 'prog': 'Function_Name_2',
\ } \ }
< <
Structure of the functions: >
function! Function_Name_1(focus, byfname, regex, prev, item, next, marked)
" Arguments:
" |
" +- a:focus : The focus of the prompt: "prt" or "win".
" |
" +- a:byfname : In filename mode or in full path mode: "file" or "path".
" |
" +- a:regex : In regex mode: 1 or 0.
" |
" +- a:prev : The previous search mode.
" |
" +- a:item : The current search mode.
" |
" +- a:next : The next search mode.
" |
" +- a:marked : The number of marked files, or a comma separated list of
" the filenames.
return full_statusline
endfunction
function! Function_Name_2(str)
" a:str : Either the number of files scanned so far, or a string indicating
" the current directory is being scanned with a user_command.
return full_statusline
endfunction
<
See https://gist.github.com/1610859 for a working example. See https://gist.github.com/1610859 for a working example.
*'g:ctrlp_match_func'*
Set an external fuzzy matching function for |CtrlP| to use: >
let g:ctrlp_match_func = {}
<
Example: >
let g:ctrlp_match_func = { 'match': 'Function_Name' }
<
Structure of the function: >
function! Function_Name(items, str, limit, mmode, ispath, crfile, regex)
" Arguments:
" |
" +- a:items : The full list of items to search in.
" |
" +- a:str : The string entered by the user.
" |
" +- a:limit : The max height of the match window. Can be used to limit
" | the number of items to return.
" |
" +- a:mmode : The match mode. Can be one of these strings:
" | + "full-line": match the entire line.
" | + "filename-only": match only the filename.
" | + "first-non-tab": match until the first tab char.
" | + "until-last-tab": match until the last tab char.
" |
" +- a:ispath : Is 1 when searching in file, buffer, mru, dir, and rtscript
" | modes. Is 0 otherwise.
" |
" +- a:crfile : The file in the current window. Should be excluded from the
" | results when a:ispath == 1.
" |
" +- a:regex : In regex mode: 1 or 0.
return list_of_matched_items
endfunction
<
=============================================================================== ===============================================================================
COMMANDS *ctrlp-commands* COMMANDS *ctrlp-commands*
@@ -613,7 +676,8 @@ EXTENSIONS *g:ctrlp-extensions*
Extensions are optional. To enable an extension, add its name to the variable Extensions are optional. To enable an extension, add its name to the variable
g:ctrlp_extensions: > g:ctrlp_extensions: >
let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript'] let g:ctrlp_extensions = ['tag', 'buffertag', 'quickfix', 'dir', 'rtscript',
\ 'undo', 'line', 'changes']
< <
The order of the items will be the order they appear on the statusline and when The order of the items will be the order they appear on the statusline and when
using <c-f>, <c-b>. using <c-f>, <c-b>.
@@ -634,8 +698,8 @@ Available extensions:~
- Name: 'buffertag' - Name: 'buffertag'
- Commands: ':CtrlPBufTag [buffer-name]', - Commands: ':CtrlPBufTag [buffer-name]',
':CtrlPBufTagAll'. ':CtrlPBufTagAll'.
- Search for a tag within the current buffer or all buffers and jump to the - Search for a tag within the current buffer or all listed buffers and jump
definition. Requires |exuberant_ctags| or compatible programs. to the definition. Requires |exuberant_ctags| or compatible programs.
*:CtrlPQuickfix* *:CtrlPQuickfix*
* Quickfix mode:~ * Quickfix mode:~
@@ -661,6 +725,27 @@ Available extensions:~
- Command: ':CtrlPRTS' - Command: ':CtrlPRTS'
- Search for files (vimscripts, docs, snippets...) in runtimepath. - Search for files (vimscripts, docs, snippets...) in runtimepath.
*:CtrlPUndo*
* Undo mode:~
- Name: 'undo'
- Command: ':CtrlPUndo'
- Browse undo history.
*:CtrlPLine*
* Line mode:~
- Name: 'line'
- Command: ':CtrlPLine'
- Search for a line in all listed buffers.
*:CtrlPChange*
*:CtrlPChangeAll*
* Change list mode:~
- Name: 'changes'
- Commands: ':CtrlPChange [buffer-name]',
':CtrlPChangeAll'.
- Search for and jump to a recent change in the current buffer or in all
listed buffers.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Buffer Tag mode options:~ Buffer Tag mode options:~
@@ -703,10 +788,14 @@ Highlighting:~
* In extensions: * In extensions:
CtrlPTabExtra : the part of each line thats not matched against (Comment) CtrlPTabExtra : the part of each line thats not matched against (Comment)
CtrlPqfLineCol : the line and column numbers in quickfix mode (|hl-Search|) CtrlPBufName : the buffer name an entry belongs to (|hl-Directory|)
CtrlPTagKind : the kind of the tag in buffer-tag mode (|hl-Title|)
CtrlPqfLineCol : the line and column numbers in quickfix mode (Comment)
CtrlPUndoT : the elapsed time in undo mode (|hl-Directory|) CtrlPUndoT : the elapsed time in undo mode (|hl-Directory|)
CtrlPUndoBr : the square brackets [] in undo mode (Comment) CtrlPUndoBr : the square brackets [] in undo mode (Comment)
CtrlPUndoNr : the undo number inside [] in undo mode (String) CtrlPUndoNr : the undo number inside [] in undo mode (String)
CtrlPUndoSv : the point where the file was saved (Comment)
CtrlPUndoPo : the current position in the undo tree (|hl-Title|)
Statuslines:~ Statuslines:~
* Highlight groups: * Highlight groups:
@@ -789,6 +878,7 @@ Special thanks:~
=============================================================================== ===============================================================================
CHANGELOG *ctrlp-changelog* CHANGELOG *ctrlp-changelog*
+ New option: |g:ctrlp_match_func|, allow using a custom fuzzy matcher.
+ Rename: + Rename:
*ClearCtrlPCache* -> |CtrlPClearCache| *ClearCtrlPCache* -> |CtrlPClearCache|
*ClearAllCtrlPCaches* -> |CtrlPClearAllCaches| *ClearAllCtrlPCaches* -> |CtrlPClearAllCaches|

View File

@@ -65,4 +65,18 @@ if index(s:ext, 'rtscript') >= 0
com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id()) com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id())
en en
if index(s:ext, 'undo') >= 0
com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id())
en
if index(s:ext, 'line') >= 0
com! CtrlPLine cal ctrlp#init(ctrlp#line#id())
en
if index(s:ext, 'changes') >= 0
com! -n=? -com=buffer CtrlPChange
\ cal ctrlp#init(ctrlp#changes#cmd(0, <q-args>))
com! CtrlPChangeAll cal ctrlp#init(ctrlp#changes#cmd(1))
en
unl s:ext unl s:ext

View File

@@ -374,7 +374,7 @@ function! s:HightlightErrors()
let force_callback = has_key(item, 'force_highlight_callback') && item['force_highlight_callback'] let force_callback = has_key(item, 'force_highlight_callback') && item['force_highlight_callback']
let group = item['type'] == 'E' ? 'SyntasticError' : 'SyntasticWarning' let group = item['type'] == 'E' ? 'SyntasticError' : 'SyntasticWarning'
if item['col'] && !force_callback if get( item, 'col' ) && !force_callback
let lastcol = col([item['lnum'], '$']) let lastcol = col([item['lnum'], '$'])
let lcol = min([lastcol, item['col']]) let lcol = min([lastcol, item['col']])
call matchadd(group, '\%'.item['lnum'].'l\%'.lcol.'c') call matchadd(group, '\%'.item['lnum'].'l\%'.lcol.'c')
@@ -466,8 +466,8 @@ endfunction
"load the chosen checker for the current filetype - useful for filetypes like "load the chosen checker for the current filetype - useful for filetypes like
"javascript that have more than one syntax checker "javascript that have more than one syntax checker
function! s:LoadChecker(checker) function! s:LoadChecker(checker, ft)
exec "runtime syntax_checkers/" . &ft . "/" . a:checker . ".vim" exec "runtime syntax_checkers/" . a:ft . "/" . a:checker . ".vim"
endfunction endfunction
"return a string representing the state of buffer according to "return a string representing the state of buffer according to
@@ -602,22 +602,24 @@ endfunction
"well as the names of the actual syntax checker executables. The checkers "well as the names of the actual syntax checker executables. The checkers
"should be listed in order of default preference. "should be listed in order of default preference.
" "
"if a option called 'g:syntastic_[filetype]_checker' exists then attempt to "a:ft should be the filetype for the checkers being loaded
"
"if a option called 'g:syntastic_{a:ft}_checker' exists then attempt to
"load the checker that it points to "load the checker that it points to
function! SyntasticLoadChecker(checkers) function! SyntasticLoadChecker(checkers, ft)
let opt_name = "g:syntastic_" . &ft . "_checker" let opt_name = "g:syntastic_" . a:ft . "_checker"
if exists(opt_name) if exists(opt_name)
let opt_val = {opt_name} let opt_val = {opt_name}
if index(a:checkers, opt_val) != -1 && executable(opt_val) if index(a:checkers, opt_val) != -1 && executable(opt_val)
call s:LoadChecker(opt_val) call s:LoadChecker(opt_val, a:ft)
else else
echoerr &ft . " syntax not supported or not installed." echoerr &ft . " syntax not supported or not installed."
endif endif
else else
for checker in a:checkers for checker in a:checkers
if executable(checker) if executable(checker)
return s:LoadChecker(checker) return s:LoadChecker(checker, a:ft)
endif endif
endfor endfor
endif endif

View File

@@ -19,4 +19,4 @@ endif
let loaded_go_syntax_checker = 1 let loaded_go_syntax_checker = 1
let s:supported_checkers = ["6g", "gofmt"] let s:supported_checkers = ["6g", "gofmt"]
call SyntasticLoadChecker(s:supported_checkers) call SyntasticLoadChecker(s:supported_checkers, 'go')

View File

@@ -20,4 +20,4 @@ endif
let loaded_javascript_syntax_checker = 1 let loaded_javascript_syntax_checker = 1
let s:supported_checkers = ["gjslint", "jslint", "jsl", "jshint"] let s:supported_checkers = ["gjslint", "jslint", "jsl", "jshint"]
call SyntasticLoadChecker(s:supported_checkers) call SyntasticLoadChecker(s:supported_checkers, 'javascript')

View File

@@ -20,4 +20,4 @@ endif
let loaded_json_syntax_checker = 1 let loaded_json_syntax_checker = 1
let s:supported_checkers = ["jsonlint", "jsonval"] let s:supported_checkers = ["jsonlint", "jsonval"]
call SyntasticLoadChecker(s:supported_checkers) call SyntasticLoadChecker(s:supported_checkers, 'json')

View File

@@ -19,21 +19,46 @@ if !executable("puppet")
finish finish
endif endif
function! s:ExtractVersion() if !exists("g:syntastic_puppet_lint_disable")
let g:syntastic_puppet_lint_disable = 0
endif
if !executable("puppet-lint")
let g:syntastic_puppet_lint_disable = 0
endif
function! s:PuppetExtractVersion()
let output = system("puppet --version") let output = system("puppet --version")
let output = substitute(output, '\n$', '', '') let output = substitute(output, '\n$', '', '')
return split(output, '\.') return split(output, '\.')
endfunction endfunction
let s:puppetVersion = s:ExtractVersion() function! s:PuppetLintExtractVersion()
let output = system("puppet-lint --version")
let output = substitute(output, '\n$', '', '')
let output = substitute(output, '^puppet-lint ', '', 'i')
return split(output, '\.')
endfunction
function! SyntaxCheckers_puppet_GetLocList() let s:puppetVersion = s:PuppetExtractVersion()
let s:lintVersion = s:PuppetLintExtractVersion()
if !(s:lintVersion[0] >= '0' && s:lintVersion[1] >= '1' && s:lintVersion[2] >= '10')
let g:syntastic_puppet_lint_disable = 0
endif
function! s:getPuppetLintErrors()
let makeprg = 'puppet-lint --log-format "\%{KIND} [\%{check}] \%{message} at \%{fullpath}:\%{linenumber}" '.shellescape(expand('%'))
let errorformat = '%t%*[a-zA-Z] %m at %f:%l'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' })
endfunction
function! s:getPuppetMakeprg()
"If puppet is >= version 2.7 then use the new executable "If puppet is >= version 2.7 then use the new executable
if s:puppetVersion[0] >= '2' && s:puppetVersion[1] >= '7' if s:puppetVersion[0] >= '2' && s:puppetVersion[1] >= '7'
let makeprg = 'puppet parser validate ' . let makeprg = 'puppet parser validate ' .
\ shellescape(expand('%')) . \ shellescape(expand('%')) .
\ ' --color=false' . \ ' --color=false'
\ ' --storeconfigs'
"add --ignoreimport for versions < 2.7.10 "add --ignoreimport for versions < 2.7.10
if s:puppetVersion[2] < '10' if s:puppetVersion[2] < '10'
@@ -43,12 +68,24 @@ function! SyntaxCheckers_puppet_GetLocList()
else else
let makeprg = 'puppet --color=false --parseonly --ignoreimport '.shellescape(expand('%')) let makeprg = 'puppet --color=false --parseonly --ignoreimport '.shellescape(expand('%'))
endif endif
return makeprg
endfunction
function! SyntaxCheckers_puppet_GetLocList()
let makeprg = s:getPuppetMakeprg()
"some versions of puppet (e.g. 2.7.10) output the message below if there "some versions of puppet (e.g. 2.7.10) output the message below if there
"are any syntax errors "are any syntax errors
let errorformat = '%-Gerr: Try ''puppet help parser validate'' for usage,' let errorformat = '%-Gerr: Try ''puppet help parser validate'' for usage,'
let errorformat .= 'err: Could not parse for environment %*[a-z]: %m at %f:%l' let errorformat .= 'err: Could not parse for environment %*[a-z]: %m at %f:%l'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
if !g:syntastic_puppet_lint_disable
let errors = errors + s:getPuppetLintErrors()
endif
return errors
endfunction endfunction

View File

@@ -24,4 +24,4 @@ if !exists('g:syntastic_python_checker_args')
endif endif
let s:supported_checkers = ["flake8", "pyflakes", "pylint"] let s:supported_checkers = ["flake8", "pyflakes", "pylint"]
call SyntasticLoadChecker(s:supported_checkers) call SyntasticLoadChecker(s:supported_checkers, 'python')

View File

@@ -5,10 +5,10 @@
" "
"============================================================================ "============================================================================
function! SyntaxCheckers_python_GetLocList() function! SyntaxCheckers_python_GetLocList()
let makeprg = 'pylint -f parseable -r n -i y ' . let makeprg = 'pylint '.g:syntastic_python_checker_args.' -f parseable -r n -i y ' .
\ shellescape(expand('%')) . \ shellescape(expand('%')) .
\ ' \| sed ''s_: \[[RC]_: \[W_''' . \ ' 2>&1 \| sed ''s_: \[[RC]_: \[W_''' .
\ ' \| sed ''s_: \[[F]_:\ \[E_''' \ ' \| sed ''s_: \[[F]_:\ \[E_'''
let errorformat = '%f:%l: [%t%n%.%#] %m,%-GNo config%m' let errorformat = '%f:%l: [%t%n%.%#] %m,%f:%l: [%t%.%#] %m,%Z,%-GNo config%m'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endfunction endfunction

View File

@@ -6,6 +6,9 @@
" "// modules: " and containing space delimited list of vala " "// modules: " and containing space delimited list of vala
" modules, used by the file, so this script can build correct " modules, used by the file, so this script can build correct
" --pkg arguments. " --pkg arguments.
" Alternatively you can set g:syntastic_vala_modules array
" in your .vimrc or .lvimrc with localvimrc plugin
" (http://www.vim.org/scripts/script.php?script_id=441).
" Valac compiler is not the fastest thing in the world, so you " Valac compiler is not the fastest thing in the world, so you
" may want to disable this plugin with " may want to disable this plugin with
" let g:syntastic_vala_check_disabled = 1 command in your .vimrc or " let g:syntastic_vala_check_disabled = 1 command in your .vimrc or
@@ -38,10 +41,19 @@ function! SyntaxCheckers_vala_GetHighlightRegex(pos)
endfunction endfunction
function! s:GetValaModules() function! s:GetValaModules()
if exists('g:syntastic_vala_modules')
if type(g:syntastic_vala_modules) == type('')
return split(g:syntastic_vala_modules, '\s\+')
elseif type(g:syntastic_vala_modules) == type([])
return g:syntastic_vala_modules
else
echoerr 'g:syntastic_vala_modules must be either list or string: fallback to in file modules string'
endif
endif
let modules_line = search('^// modules: ', 'n') let modules_line = search('^// modules: ', 'n')
let modules_str = getline(modules_line) let modules_str = getline(modules_line)
let modules = split(strpart(modules_str, 12), '\s\+') return split(strpart(modules_str, 12), '\s\+')
return modules
endfunction endfunction
function! SyntaxCheckers_vala_GetLocList() function! SyntaxCheckers_vala_GetLocList()

View File

@@ -1,7 +1,7 @@
" Author: Eric Van Dewoestine " Author: Eric Van Dewoestine
" "
" License: {{{ " License: {{{
" Copyright (c) 2005 - 2011, Eric Van Dewoestine " Copyright (c) 2005 - 2012, Eric Van Dewoestine
" All rights reserved. " All rights reserved.
" "
" Redistribution and use of this software in source and binary forms, with " Redistribution and use of this software in source and binary forms, with
@@ -122,7 +122,6 @@ function! s:ParseRegex(file, settings) " {{{
" prototype.js has Object.extend to extend existing objects. " prototype.js has Object.extend to extend existing objects.
call add(patterns, ['o', '(?:var\s+)?\b([A-Z][A-Za-z0-9_.]+)\s*=\s*Object\.extend\s*\(', 1]) call add(patterns, ['o', '(?:var\s+)?\b([A-Z][A-Za-z0-9_.]+)\s*=\s*Object\.extend\s*\(', 1])
call add(patterns, ['o', '\bObject\.extend\s*\(\b([A-Z][A-Za-z0-9_.]+)\s*,\s*\{', 1])
" mootools uses 'new Class' " mootools uses 'new Class'
call add(patterns, ['o', '(?:var\s+)?\b([A-Z][A-Za-z0-9_.]+)\s*=\s*new\s+Class\s*\(', 1]) call add(patterns, ['o', '(?:var\s+)?\b([A-Z][A-Za-z0-9_.]+)\s*=\s*new\s+Class\s*\(', 1])
@@ -135,6 +134,11 @@ function! s:ParseRegex(file, settings) " {{{
" vimperator uses var = (function() " vimperator uses var = (function()
call add(patterns, ['o', '([A-Za-z0-9_.]+)\s*=\s*\(function\s*\(', 1]) call add(patterns, ['o', '([A-Za-z0-9_.]+)\s*=\s*\(function\s*\(', 1])
" other library based exend calls (backbone, etc)
call add(patterns,
\ ['o', '(?:var\s+)?\b([A-Z][A-Za-z0-9_.]+)\s*=\s*[A-Za-z0-9_.]+\.extend\s*\({', 1])
call add(patterns, ['o', '\.extend\s*\(\b([A-Z][A-Za-z0-9_.]+)\s*,\s*\{', 1])
" Match Functions " Match Functions
call add(patterns, ['f', '\bfunction\s+([a-zA-Z0-9_.\$]+?)\s*\(', 1]) call add(patterns, ['f', '\bfunction\s+([a-zA-Z0-9_.\$]+?)\s*\(', 1])
call add(patterns, ['f', '([a-zA-Z0-9_.\$]+?)\s*=\s*function\s*\(', 1]) call add(patterns, ['f', '([a-zA-Z0-9_.\$]+?)\s*=\s*function\s*\(', 1])

View File

@@ -2,7 +2,7 @@
" Description: Highlight several words in different colors simultaneously. " Description: Highlight several words in different colors simultaneously.
" "
" Copyright: (C) 2005-2008 by Yuheng Xie " Copyright: (C) 2005-2008 by Yuheng Xie
" (C) 2008-2011 by Ingo Karkat " (C) 2008-2012 by Ingo Karkat
" The VIM LICENSE applies to this script; see ':help copyright'. " The VIM LICENSE applies to this script; see ':help copyright'.
" "
" Maintainer: Ingo Karkat <ingo@karkat.de> " Maintainer: Ingo Karkat <ingo@karkat.de>
@@ -10,8 +10,34 @@
" Dependencies: " Dependencies:
" - SearchSpecial.vim autoload script (optional, for improved search messages). " - SearchSpecial.vim autoload script (optional, for improved search messages).
" "
" Version: 2.5.2 " Version: 2.6.2
" Changes: " Changes:
" 26-Mar-2012, Ingo Karkat
" - ENH: When a [count] exceeding the number of available mark groups is given,
" a summary of marks is given and the user is asked to select a mark group.
" This allows to interactively choose a color via 99<Leader>m.
" - ENH: Include count of alternative patterns in :Marks list.
" - CHG: Use ">" for next mark and "/" for last search in :Marks.
"
" 23-Mar-2012, Ingo Karkat
" - ENH: Add :Marks command that prints all mark highlight groups and their
" search patterns, plus information about the current search mark, next mark
" group, and whether marks are disabled.
" - ENH: Show which mark group a pattern was set / added / removed / cleared.
" - Refactoring: Store index into s:pattern instead of pattern itself in
" s:lastSearch. For that, mark#CurrentMark() now additionally returns the
" index.
" - CHG: Show mark group number in same-mark search and rename search types from
" "any-mark", "same-mark", and "new-mark" to the shorter "mark-*", "mark-N",
" and "mark-N!", respectively.
"
" 22-Mar-2012, Ingo Karkat
" - ENH: Allow [count] for <Leader>m and :Mark to add / subtract match to / from
" highlight group [count], and use [count]<Leader>n to clear only highlight
" group [count]. This was also requested by Philipp Marek.
" - FIX: :Mark and <Leader>n actually toggled marks back on when they were
" already off. Now, they stay off on multiple invocations. Use :call
" mark#Toggle() / <Plug>MarkToggle if you want toggling.
" "
" 09-Nov-2011, Ingo Karkat " 09-Nov-2011, Ingo Karkat
" - BUG: With a single match and 'wrapscan' set, a search error was issued " - BUG: With a single match and 'wrapscan' set, a search error was issued
@@ -155,13 +181,44 @@
" - Split off functions into autoload script. " - Split off functions into autoload script.
"- functions ------------------------------------------------------------------ "- functions ------------------------------------------------------------------
silent! call SearchSpecial#DoesNotExist() " Execute a function to force autoload.
if exists('*SearchSpecial#WrapMessage')
function! s:WrapMessage( searchType, searchPattern, isBackward )
redraw
call SearchSpecial#WrapMessage(a:searchType, a:searchPattern, a:isBackward)
endfunction
function! s:EchoSearchPattern( searchType, searchPattern, isBackward )
call SearchSpecial#EchoSearchPattern(a:searchType, a:searchPattern, a:isBackward)
endfunction
else
function! s:Trim( message )
" Limit length to avoid "Hit ENTER" prompt.
return strpart(a:message, 0, (&columns / 2)) . (len(a:message) > (&columns / 2) ? "..." : "")
endfunction
function! s:WrapMessage( searchType, searchPattern, isBackward )
redraw
let v:warningmsg = printf('%s search hit %s, continuing at %s', a:searchType, (a:isBackward ? 'TOP' : 'BOTTOM'), (a:isBackward ? 'BOTTOM' : 'TOP'))
echohl WarningMsg
echo s:Trim(v:warningmsg)
echohl None
endfunction
function! s:EchoSearchPattern( searchType, searchPattern, isBackward )
let l:message = (a:isBackward ? '?' : '/') . a:searchPattern
echohl SearchSpecialSearchType
echo a:searchType
echohl None
echon s:Trim(l:message)
endfunction
endif
function! s:EscapeText( text ) function! s:EscapeText( text )
return substitute( escape(a:text, '\' . '^$.*[~'), "\n", '\\n', 'ge' ) return substitute( escape(a:text, '\' . '^$.*[~'), "\n", '\\n', 'ge' )
endfunction endfunction
" Mark the current word, like the built-in star command. " Mark the current word, like the built-in star command.
" If the cursor is on an existing mark, remove it. " If the cursor is on an existing mark, remove it.
function! mark#MarkCurrentWord() function! mark#MarkCurrentWord( groupNum )
let l:regexp = mark#CurrentMark()[0] let l:regexp = (a:groupNum == 0 ? mark#CurrentMark()[0] : '')
if empty(l:regexp) if empty(l:regexp)
let l:cword = expand('<cword>') let l:cword = expand('<cword>')
if ! empty(l:cword) if ! empty(l:cword)
@@ -173,10 +230,7 @@ function! mark#MarkCurrentWord()
endif endif
endif endif
endif endif
return (empty(l:regexp) ? 0 : mark#DoMark(a:groupNum, l:regexp))
if ! empty(l:regexp)
call mark#DoMark(l:regexp)
endif
endfunction endfunction
function! mark#GetVisualSelection() function! mark#GetVisualSelection()
@@ -205,7 +259,7 @@ function! mark#MarkRegex( regexpPreset )
echohl None echohl None
call inputrestore() call inputrestore()
if ! empty(l:regexp) if ! empty(l:regexp)
call mark#DoMark(l:regexp) call mark#DoMark(0, l:regexp)
endif endif
endfunction endfunction
@@ -215,6 +269,16 @@ function! s:Cycle( ... )
let s:cycle = (l:newCycle < s:markNum ? l:newCycle : 0) let s:cycle = (l:newCycle < s:markNum ? l:newCycle : 0)
return l:currentCycle return l:currentCycle
endfunction endfunction
function! s:FreeGroupIndex()
let i = 0
while i < s:markNum
if empty(s:pattern[i])
return i
endif
let i += 1
endwhile
return -1
endfunction
" Set match / clear matches in the current window. " Set match / clear matches in the current window.
function! s:MarkMatch( indices, expr ) function! s:MarkMatch( indices, expr )
@@ -239,7 +303,7 @@ function! s:MarkMatch( indices, expr )
let l:expr = ((&ignorecase && a:expr !~# '\\\@<!\\C') ? '\c' . a:expr : a:expr) let l:expr = ((&ignorecase && a:expr !~# '\\\@<!\\C') ? '\c' . a:expr : a:expr)
" To avoid an arbitrary ordering of highlightings, we assign a different " To avoid an arbitrary ordering of highlightings, we assign a different
" priority based on the highlighting group, and ensure that the highest " priority based on the highlight group, and ensure that the highest
" priority is -10, so that we do not override the 'hlsearch' of 0, and still " priority is -10, so that we do not override the 'hlsearch' of 0, and still
" allow other custom highlightings to sneak in between. " allow other custom highlightings to sneak in between.
let l:priority = -10 - s:markNum + 1 + l:index let l:priority = -10 - s:markNum + 1 + l:index
@@ -343,7 +407,7 @@ function! mark#ClearAll()
endif endif
let i += 1 let i += 1
endwhile endwhile
let s:lastSearch = '' let s:lastSearch = -1
" Re-enable marks; not strictly necessary, since all marks have just been " Re-enable marks; not strictly necessary, since all marks have just been
" cleared, and marks will be re-enabled, anyway, when the first mark is added. " cleared, and marks will be re-enabled, anyway, when the first mark is added.
@@ -359,30 +423,32 @@ function! mark#ClearAll()
echo 'All marks cleared' echo 'All marks cleared'
endif endif
endfunction endfunction
function! mark#DoMark(...) " DoMark(regexp) function! s:SetMark( index, regexp, ... )
let regexp = (a:0 ? a:1 : '') if a:0
if s:lastSearch == a:index
" Disable marks if regexp is empty. Otherwise, we will be either removing a let s:lastSearch = a:1
" mark or adding one, so marks will be re-enabled.
if empty(regexp)
call mark#Toggle()
return
endif
" clear the mark if it has been marked
let i = 0
while i < s:markNum
if regexp ==# s:pattern[i]
if s:lastSearch ==# s:pattern[i]
let s:lastSearch = ''
endif
call s:SetPattern(i, '')
call s:EnableAndMarkScope([i], '')
return
endif endif
let i += 1 endif
endwhile call s:SetPattern(a:index, a:regexp)
call s:EnableAndMarkScope([a:index], a:regexp)
endfunction
function! s:ClearMark( index )
" A last search there is reset.
call s:SetMark(a:index, '', -1)
endfunction
function! s:EchoMark( groupNum, regexp )
call s:EchoSearchPattern('mark-' . a:groupNum, a:regexp, 0)
endfunction
function! s:EchoMarkCleared( groupNum )
echohl SearchSpecialSearchType
echo 'mark-' . a:groupNum
echohl None
echon ' cleared'
endfunction
function! s:EchoMarksDisabled()
echo 'All marks disabled'
endfunction
function! mark#DoMark( groupNum, ...)
if s:markNum <= 0 if s:markNum <= 0
" Uh, somehow no mark highlightings were defined. Try to detect them again. " Uh, somehow no mark highlightings were defined. Try to detect them again.
call mark#Init() call mark#Init()
@@ -392,7 +458,62 @@ function! mark#DoMark(...) " DoMark(regexp)
echohl ErrorMsg echohl ErrorMsg
echomsg v:errmsg echomsg v:errmsg
echohl None echohl None
return return 0
endif
endif
let l:groupNum = a:groupNum
if l:groupNum > s:markNum
" This highlight group does not exist.
let l:groupNum = mark#QueryMarkGroupNum()
if l:groupNum < 1 || l:groupNum > s:markNum
return 0
endif
endif
let regexp = (a:0 ? a:1 : '')
if empty(regexp)
if l:groupNum == 0
" Disable all marks.
call s:MarkEnable(0)
call s:EchoMarksDisabled()
else
" Clear the mark represented by the passed highlight group number.
call s:ClearMark(l:groupNum - 1)
call s:EchoMarkCleared(l:groupNum)
endif
return 1
endif
if l:groupNum == 0
" Clear the mark if it has been marked.
let i = 0
while i < s:markNum
if regexp ==# s:pattern[i]
call s:ClearMark(i)
call s:EchoMarkCleared(i + 1)
return 1
endif
let i += 1
endwhile
else
" Add / subtract the pattern as an alternative to the mark represented
" by the passed highlight group number.
let existingPattern = s:pattern[l:groupNum - 1]
if ! empty(existingPattern)
" Split only on \|, but not on \\|.
let alternatives = split(existingPattern, '\%(\%(^\|[^\\]\)\%(\\\\\)*\\\)\@<!\\|')
if index(alternatives, regexp) == -1
let regexp = existingPattern . '\|' . regexp
else
let regexp = join(filter(alternatives, 'v:val !=# regexp'), '\|')
if empty(regexp)
call s:ClearMark(l:groupNum - 1)
call s:EchoMarkCleared(l:groupNum)
return 1
endif
endif
endif endif
endif endif
@@ -404,29 +525,30 @@ function! mark#DoMark(...) " DoMark(regexp)
call histadd('@', regexp) call histadd('@', regexp)
endif endif
" choose an unused mark group if l:groupNum == 0
let i = 0 let i = s:FreeGroupIndex()
while i < s:markNum if i != -1
if empty(s:pattern[i]) " Choose an unused highlight group. The last search is kept untouched.
call s:SetPattern(i, regexp)
call s:Cycle(i) call s:Cycle(i)
call s:EnableAndMarkScope([i], regexp) call s:SetMark(i, regexp)
return else
" Choose a highlight group by cycle. A last search there is reset.
let i = s:Cycle()
call s:SetMark(i, regexp, -1)
endif endif
let i += 1 else
endwhile let i = l:groupNum - 1
" Use and extend the passed highlight group. A last search is updated
" choose a mark group by cycle " and thereby kept active.
let i = s:Cycle() call s:SetMark(i, regexp, i)
if s:lastSearch ==# s:pattern[i]
let s:lastSearch = ''
endif endif
call s:SetPattern(i, regexp)
call s:EnableAndMarkScope([i], regexp) call s:EchoMark(i + 1, regexp)
return 1
endfunction endfunction
" Return [mark text, mark start position] of the mark under the cursor (or " Return [mark text, mark start position, mark index] of the mark under the
" ['', []] if there is no mark). " cursor (or ['', [], -1] if there is no mark).
" The mark can include the trailing newline character that concludes the line, " The mark can include the trailing newline character that concludes the line,
" but marks that span multiple lines are not supported. " but marks that span multiple lines are not supported.
function! mark#CurrentMark() function! mark#CurrentMark()
@@ -435,7 +557,7 @@ function! mark#CurrentMark()
" Highlighting groups with higher numbers take precedence over lower numbers, " Highlighting groups with higher numbers take precedence over lower numbers,
" and therefore its marks appear "above" other marks. To retrieve the visible " and therefore its marks appear "above" other marks. To retrieve the visible
" mark in case of overlapping marks, we need to check from highest to lowest " mark in case of overlapping marks, we need to check from highest to lowest
" highlighting group. " highlight group.
let i = s:markNum - 1 let i = s:markNum - 1
while i >= 0 while i >= 0
if ! empty(s:pattern[i]) if ! empty(s:pattern[i])
@@ -445,7 +567,7 @@ function! mark#CurrentMark()
let b = match(line, s:pattern[i], start) let b = match(line, s:pattern[i], start)
let e = matchend(line, s:pattern[i], start) let e = matchend(line, s:pattern[i], start)
if b < col('.') && col('.') <= e if b < col('.') && col('.') <= e
return [s:pattern[i], [line('.'), (b + 1)]] return [s:pattern[i], [line('.'), (b + 1)], i]
endif endif
if b == e if b == e
break break
@@ -455,54 +577,25 @@ function! mark#CurrentMark()
endif endif
let i -= 1 let i -= 1
endwhile endwhile
return ['', []] return ['', [], -1]
endfunction endfunction
" Search current mark. " Search current mark.
function! mark#SearchCurrentMark( isBackward ) function! mark#SearchCurrentMark( isBackward )
let [l:markText, l:markPosition] = mark#CurrentMark() let [l:markText, l:markPosition, l:markIndex] = mark#CurrentMark()
if empty(l:markText) if empty(l:markText)
if empty(s:lastSearch) if s:lastSearch == -1
call mark#SearchAnyMark(a:isBackward) call mark#SearchAnyMark(a:isBackward)
let s:lastSearch = mark#CurrentMark()[0] let s:lastSearch = mark#CurrentMark()[2]
else else
call s:Search(s:lastSearch, a:isBackward, [], 'same-mark') call s:Search(s:pattern[s:lastSearch], a:isBackward, [], 'mark-' . (s:lastSearch + 1))
endif endif
else else
call s:Search(l:markText, a:isBackward, l:markPosition, (l:markText ==# s:lastSearch ? 'same-mark' : 'new-mark')) call s:Search(l:markText, a:isBackward, l:markPosition, 'mark-' . (l:markIndex + 1) . (l:markIndex ==# s:lastSearch ? '' : '!'))
let s:lastSearch = l:markText let s:lastSearch = l:markIndex
endif endif
endfunction endfunction
silent! call SearchSpecial#DoesNotExist() " Execute a function to force autoload.
if exists('*SearchSpecial#WrapMessage')
function! s:WrapMessage( searchType, searchPattern, isBackward )
redraw
call SearchSpecial#WrapMessage(a:searchType, a:searchPattern, a:isBackward)
endfunction
function! s:EchoSearchPattern( searchType, searchPattern, isBackward )
call SearchSpecial#EchoSearchPattern(a:searchType, a:searchPattern, a:isBackward)
endfunction
else
function! s:Trim( message )
" Limit length to avoid "Hit ENTER" prompt.
return strpart(a:message, 0, (&columns / 2)) . (len(a:message) > (&columns / 2) ? "..." : "")
endfunction
function! s:WrapMessage( searchType, searchPattern, isBackward )
redraw
let v:warningmsg = printf('%s search hit %s, continuing at %s', a:searchType, (a:isBackward ? 'TOP' : 'BOTTOM'), (a:isBackward ? 'BOTTOM' : 'TOP'))
echohl WarningMsg
echo s:Trim(v:warningmsg)
echohl None
endfunction
function! s:EchoSearchPattern( searchType, searchPattern, isBackward )
let l:message = (a:isBackward ? '?' : '/') . a:searchPattern
echohl SearchSpecialSearchType
echo a:searchType
echohl None
echon s:Trim(l:message)
endfunction
endif
function! s:ErrorMessage( searchType, searchPattern, isBackward ) function! s:ErrorMessage( searchType, searchPattern, isBackward )
if &wrapscan if &wrapscan
let v:errmsg = a:searchType . ' not found: ' . a:searchPattern let v:errmsg = a:searchType . ' not found: ' . a:searchPattern
@@ -647,8 +740,8 @@ endfunction
function! mark#SearchAnyMark( isBackward ) function! mark#SearchAnyMark( isBackward )
let l:markPosition = mark#CurrentMark()[1] let l:markPosition = mark#CurrentMark()[1]
let l:markText = s:AnyMark() let l:markText = s:AnyMark()
call s:Search(l:markText, a:isBackward, l:markPosition, 'any-mark') call s:Search(l:markText, a:isBackward, l:markPosition, 'mark-*')
let s:lastSearch = "" let s:lastSearch = -1
endfunction endfunction
" Search last searched mark. " Search last searched mark.
@@ -657,7 +750,7 @@ function! mark#SearchNext( isBackward )
if empty(l:markText) if empty(l:markText)
return 0 return 0
else else
if empty(s:lastSearch) if s:lastSearch == -1
call mark#SearchAnyMark(a:isBackward) call mark#SearchAnyMark(a:isBackward)
else else
call mark#SearchCurrentMark(a:isBackward) call mark#SearchCurrentMark(a:isBackward)
@@ -754,6 +847,85 @@ function! mark#SaveCommand()
endfunction endfunction
" Query mark group number.
function! s:GetNextGroupIndex()
let l:nextGroupIndex = s:FreeGroupIndex()
if l:nextGroupIndex == -1
let l:nextGroupIndex = s:cycle
endif
return l:nextGroupIndex
endfunction
function! s:GetMarker( index, nextGroupIndex )
let l:marker = ''
if s:lastSearch == a:index
let l:marker .= '/'
endif
if a:index == a:nextGroupIndex
let l:marker .= '>'
endif
return l:marker
endfunction
function! s:GetAlternativeCount( pattern )
return len(split(a:pattern, '\%(\%(^\|[^\\]\)\%(\\\\\)*\\\)\@<!\\|'))
endfunction
function! s:PrintMarkGroup( nextGroupIndex )
for i in range(s:markNum)
echon ' '
execute 'echohl MarkWord' . (i + 1)
let c = s:GetAlternativeCount(s:pattern[i])
echon printf('%1s%s%2d ', s:GetMarker(i, a:nextGroupIndex), (c ? (c > 1 ? c : '') . '*' : ''), (i + 1))
echohl None
endfor
endfunction
function! mark#QueryMarkGroupNum()
echohl Question
echo 'Mark?'
echohl None
let l:nextGroupIndex = s:GetNextGroupIndex()
call s:PrintMarkGroup(l:nextGroupIndex)
let l:nr = 0
while 1
let l:char = nr2char(getchar())
if l:char ==# "\<CR>"
return (l:nr == 0 ? l:nextGroupIndex + 1 : l:nr)
elseif l:char !~# '\d'
return -1
endif
echon l:char
let l:nr = 10 * l:nr + l:char
if s:markNum < 10 * l:nr
return l:nr
endif
endwhile
endfunction
" :Marks command.
function! mark#List()
echohl Title
echo 'mark cnt Pattern'
echohl None
echon ' (> next mark group / current search mark)'
let l:nextGroupIndex = s:GetNextGroupIndex()
for i in range(s:markNum)
execute 'echohl MarkWord' . (i + 1)
let c = s:GetAlternativeCount(s:pattern[i])
echo printf('%1s%3d%4s %s', s:GetMarker(i, l:nextGroupIndex), (i + 1), (c > 1 ? '('.c.')' : ''), s:pattern[i])
echohl None
endfor
if ! s:enabled
echo 'Marks are currently disabled.'
endif
endfunction
function! mark#GetGroupNum()
return s:markNum
endfunction
"- initializations ------------------------------------------------------------ "- initializations ------------------------------------------------------------
augroup Mark augroup Mark
autocmd! autocmd!
@@ -769,7 +941,7 @@ function! mark#Init()
endwhile endwhile
let s:pattern = repeat([''], s:markNum) let s:pattern = repeat([''], s:markNum)
let s:cycle = 0 let s:cycle = 0
let s:lastSearch = '' let s:lastSearch = -1
let s:enabled = 1 let s:enabled = 1
endfunction endfunction
@@ -781,4 +953,4 @@ else
call mark#UpdateScope() call mark#UpdateScope()
endif endif
" vim: ts=2 sw=2 " vim: ts=4 sts=0 sw=4 noet

View File

@@ -31,6 +31,8 @@ the original:
- Jumps behave like the built-in search, including wrap and error messages. - Jumps behave like the built-in search, including wrap and error messages.
- Like the built-in commands, jumps take an optional [count] to quickly skip - Like the built-in commands, jumps take an optional [count] to quickly skip
over some marks. over some marks.
- Marks can be persisted, and patterns can be added / subtracted from
mark highlight groups.
RELATED WORKS * RELATED WORKS *
@@ -56,6 +58,26 @@ HIGHLIGHTING *mark-highlighting*
If already on a mark: Clear the mark, like If already on a mark: Clear the mark, like
|<Leader>n|. |<Leader>n|.
{Visual}<Leader>m Mark or unmark the visual selection. {Visual}<Leader>m Mark or unmark the visual selection.
[N]<Leader>m With [N], mark the word under the cursor with the
named highlight group [N]. When that group is not
empty, the word is added as an alternative match, so
you can highlight multiple words with the same color.
When the word is already contained in the list of
alternatives, it is removed.
When [N] is greater than the number of defined mark
groups, a summary of marks is printed. Active mark
groups are prefixed with "*" (or "M*" when there are
M pattern alternatives), the default next group with
">", the last used search with "/" (like |:Marks|
does). Input the mark group, accept the default with
<CR>, or abort with <Esc> or any other key.
This way, when unsure about which number represents
which color, just use 99<Leader>n and pick the color
interactively!
{Visual}[N]<Leader>m Ditto, based on the visual selection.
*<Leader>r* *v_<Leader>r* *<Leader>r* *v_<Leader>r*
<Leader>r Manually input a regular expression to mark. <Leader>r Manually input a regular expression to mark.
{Visual}<Leader>r Ditto, based on the visual selection. {Visual}<Leader>r Ditto, based on the visual selection.
@@ -67,14 +89,24 @@ HIGHLIGHTING *mark-highlighting*
<Leader>n Clear the mark under the cursor. <Leader>n Clear the mark under the cursor.
If not on a mark: Disable all marks, similar to If not on a mark: Disable all marks, similar to
|:nohlsearch|. |:nohlsearch|.
Note: Marks that span multiple lines are not detected, Note: Marks that span multiple lines are not detected,
so the use of <Leader>n on such a mark will so the use of <Leader>n on such a mark will
unintentionally remove all marks! Use unintentionally remove all marks! Use
{Visual}<Leader>r or :Mark {pattern} to clear {Visual}<Leader>r or :Mark {pattern} to clear
multi-line marks. multi-line marks (or pass [N] if you happen to know
the group number).
[N]<Leader>n Clear the marks represented by highlight group [N].
*:Mark* *:Mark*
:Mark {pattern} Mark or unmark {pattern}. :[N]Mark Clear the marks represented by highlight group [N].
:[N]Mark {pattern} Mark or unmark {pattern}. Unless [N] is given, the
next free highlight group is used.
With [N], mark the word under the cursor with the
named highlight group [N]. When that group is not
empty, the word is added as an alternative match, so
you can highlight multiple words with the same color.
When the word is already contained in the list of
alternatives, it is removed.
For implementation reasons, {pattern} cannot use the For implementation reasons, {pattern} cannot use the
'smartcase' setting, only 'ignorecase'. 'smartcase' setting, only 'ignorecase'.
:Mark Disable all marks, similar to |:nohlsearch|. Marks :Mark Disable all marks, similar to |:nohlsearch|. Marks
@@ -139,16 +171,32 @@ highlightings from Vim session to session, and be surprised by the arbitrary
highlight groups and occasional appearance of forgotten marks. If you want highlight groups and occasional appearance of forgotten marks. If you want
just that though and automatically restore any marks, set |g:mwAutoLoadMarks|. just that though and automatically restore any marks, set |g:mwAutoLoadMarks|.
You can also initialize the marks to static values, e.g. by including this in You can also initialize some marks (even using particular highlight groups) to
|vimrc|: > static values, e.g. by including this in |vimrc|: >
runtime plugin/mark.vim runtime plugin/mark.vim
silent MarkClear silent MarkClear
Mark foo 5Mark foo
Mark bar 6Mark bar
Or you can define custom commands that preset certain marks: > Or you can define custom commands that preset certain marks: >
command -bar MyMarks silent MarkClear | execute 'Mark foo' | execute 'Mark bar' command -bar MyMarks silent MarkClear | execute '5Mark foo' | execute '6Mark bar'
Or a command that adds to the existing marks and then toggles them: > Or a command that adds to the existing marks and then toggles them: >
command -bar ToggleFooBarMarks execute 'Mark foo' | execute 'Mark bar' command -bar ToggleFooBarMarks execute 'Mark foo' | execute 'Mark bar'
<
MARK INFORMATION *mark-information*
Both |mark-highlighting| and |mark-searching| commands print information about
the mark and search pattern, e.g.
mark-1/\<pattern\> ~
This is especially useful when you want to add or subtract patterns to a mark
highlight group via [N].
*:Marks*
:Marks List all mark highlight groups and the search patterns
defined for them.
The group that will be used for the next |:Mark| or
|<Leader>m| command (with [N]) is shown with a ">".
The last mark used for a search (via |<Leader>*|) is
shown with a "/".
============================================================================== ==============================================================================
INSTALLATION *mark-installation* INSTALLATION *mark-installation*
@@ -246,12 +294,39 @@ IDEAS *mark-ideas*
Taken from an alternative implementation at Taken from an alternative implementation at
http://vim.wikia.com/wiki/Highlight_multiple_words: http://vim.wikia.com/wiki/Highlight_multiple_words:
- Allow to specify the highlight group number via :[N]Mark {regexp}
- Use keys 1-9 on the numeric keypad to toggle a highlight group number. - Use keys 1-9 on the numeric keypad to toggle a highlight group number.
============================================================================== ==============================================================================
HISTORY *mark-history* HISTORY *mark-history*
2.6.2 26-Mar-2012
- ENH: When a [count] exceeding the number of available mark groups is given,
a summary of marks is given and the user is asked to select a mark group.
This allows to interactively choose a color via 99<Leader>m.
- ENH: Include count of alternative patterns in :Marks list.
- CHG: Use ">" for next mark and "/" for last search in :Marks.
2.6.1 23-Mar-2012
- ENH: Add :Marks command that prints all mark highlight groups and their
search patterns, plus information about the current search mark, next mark
group, and whether marks are disabled.
- ENH: Show which mark group a pattern was set / added / removed / cleared.
- FIX: When the cursor is positioned on the current mark, [N]<Leader>n /
<Plug>MarkClear with [N] appended the pattern for the current mark (again
and again) instead of clearing it. Must not pass current mark pattern when
[N] is given.
- CHG: Show mark group number in same-mark search and rename search types from
"any-mark", "same-mark", and "new-mark" to the shorter "mark-*", "mark-N",
and "mark-N!", respectively.
2.6.0 22-Mar-2012
- ENH: Allow [count] for <Leader>m and :Mark to add / subtract match to / from
highlight group [count], and use [count]<Leader>n to clear only highlight
group [count]. This was also requested by Philipp Marek.
- FIX: :Mark and <Leader>n actually toggled marks back on when they were
already off. Now, they stay off on multiple invocations. Use :call
mark#Toggle() / <Plug>MarkToggle if you want toggling.
2.5.3 02-Mar-2012 2.5.3 02-Mar-2012
- BUG: Version check mistakenly excluded Vim 7.1 versions that do have the - BUG: Version check mistakenly excluded Vim 7.1 versions that do have the
matchadd() function. Thanks to Philipp Marek for sending a patch. matchadd() function. Thanks to Philipp Marek for sending a patch.

View File

@@ -13,8 +13,22 @@
" - Requires Vim 7.1 with "matchadd()", or Vim 7.2 or higher. " - Requires Vim 7.1 with "matchadd()", or Vim 7.2 or higher.
" - mark.vim autoload script. " - mark.vim autoload script.
" "
" Version: 2.5.3 " Version: 2.6.1
" Changes: " Changes:
" 23-Mar-2012, Ingo Karkat
" - ENH: Add :Marks command that prints all mark highlight groups and their
" search patterns, plus information about the current search mark, next mark
" group, and whether marks are disabled.
" - FIX: When the cursor is positioned on the current mark, [N]<Leader>n /
" <Plug>MarkClear with [N] appended the pattern for the current mark (again
" and again) instead of clearing it. Must not pass current mark pattern when
" [N] is given.
"
" 22-Mar-2012, Ingo Karkat
" - ENH: Allow [count] for <Leader>m and :Mark to add / subtract match to / from
" highlight group [count], and use [count]<Leader>n to clear only highlight
" group [count]. This was also requested by Philipp Marek.
"
" 02-Mar-2012, Philipp Marek " 02-Mar-2012, Philipp Marek
" - BUG: Version check mistakenly excluded Vim 7.1 versions that do have the " - BUG: Version check mistakenly excluded Vim 7.1 versions that do have the
" matchadd() function. " matchadd() function.
@@ -195,13 +209,13 @@ highlight def link SearchSpecialSearchType MoreMsg
"- mappings ------------------------------------------------------------------- "- mappings -------------------------------------------------------------------
nnoremap <silent> <Plug>MarkSet :<C-u>call mark#MarkCurrentWord()<CR> nnoremap <silent> <Plug>MarkSet :<C-u>if !mark#MarkCurrentWord(v:count)<Bar>execute "normal! \<lt>C-\>\<lt>C-n>\<lt>Esc>"<Bar>endif<CR>
vnoremap <silent> <Plug>MarkSet <C-\><C-n>:call mark#DoMark(mark#GetVisualSelectionAsLiteralPattern())<CR> vnoremap <silent> <Plug>MarkSet :<C-u>if !mark#DoMark(v:count, mark#GetVisualSelectionAsLiteralPattern())<Bar>execute "normal! \<lt>C-\>\<lt>C-n>\<lt>Esc>"<Bar>endif<CR>
nnoremap <silent> <Plug>MarkRegex :<C-u>call mark#MarkRegex('')<CR> nnoremap <silent> <Plug>MarkRegex :<C-u>call mark#MarkRegex('')<CR>
vnoremap <silent> <Plug>MarkRegex <C-\><C-n>:call mark#MarkRegex(mark#GetVisualSelectionAsRegexp())<CR> vnoremap <silent> <Plug>MarkRegex :<C-u>call mark#MarkRegex(mark#GetVisualSelectionAsRegexp())<CR>
nnoremap <silent> <Plug>MarkClear :<C-u>call mark#DoMark(mark#CurrentMark()[0])<CR> nnoremap <silent> <Plug>MarkClear :<C-u>if !mark#DoMark(v:count, (v:count ? '' : mark#CurrentMark()[0]))<Bar>execute "normal! \<lt>C-\>\<lt>C-n>\<lt>Esc>"<Bar>endif<CR>
nnoremap <silent> <Plug>MarkAllClear :<C-u>call mark#ClearAll()<CR> nnoremap <silent> <Plug>MarkAllClear :<C-u>call mark#ClearAll()<CR>
nnoremap <silent> <Plug>MarkToggle :<C-u>call mark#Toggle()<CR> nnoremap <silent> <Plug>MarkToggle :<C-u>call mark#Toggle()<CR>
nnoremap <silent> <Plug>MarkSearchCurrentNext :<C-u>call mark#SearchCurrentMark(0)<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>MarkSearchCurrentPrev :<C-u>call mark#SearchCurrentMark(1)<CR>
@@ -252,8 +266,9 @@ endif
"- commands ------------------------------------------------------------------- "- commands -------------------------------------------------------------------
command! -nargs=? Mark call mark#DoMark(<f-args>) command! -count -nargs=? Mark if !mark#DoMark(<count>, <f-args>) | echoerr printf('Only %d mark highlight groups', mark#GetGroupNum()) | endif
command! -bar MarkClear call mark#ClearAll() command! -bar MarkClear call mark#ClearAll()
command! -bar Marks call mark#List()
command! -bar MarkLoad call mark#LoadCommand(1) command! -bar MarkLoad call mark#LoadCommand(1)
command! -bar MarkSave call mark#SaveCommand() command! -bar MarkSave call mark#SaveCommand()
@@ -290,4 +305,4 @@ if g:mwAutoLoadMarks
augroup END augroup END
endif endif
" vim: ts=2 sw=2 " vim: ts=4 sts=0 sw=4 noet