From a14bbe07376b5be9f1fb56a2a7a0a82b4c54ae0e Mon Sep 17 00:00:00 2001 From: Kien N Date: Sat, 7 Apr 2012 09:01:06 +0700 Subject: [PATCH] Reorganize syntax stuff --- autoload/ctrlp.vim | 32 ++++++++++++++++++++------------ autoload/ctrlp/buffertag.vim | 17 +++++------------ autoload/ctrlp/changes.vim | 15 +++++---------- autoload/ctrlp/dir.vim | 6 +++--- autoload/ctrlp/line.vim | 13 ++++--------- autoload/ctrlp/quickfix.vim | 14 ++++++++------ autoload/ctrlp/tag.vim | 14 ++++++++------ autoload/ctrlp/undo.vim | 9 +++------ 8 files changed, 56 insertions(+), 64 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 9371a0a..4425a9e 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -712,9 +712,7 @@ endf fu! s:ToggleType(dir) let ext = exists('g:ctrlp_ext_vars') ? len(g:ctrlp_ext_vars) : 0 unl! g:ctrlp_nolimit - if has('syntax') && exists('g:syntax_on') - cal ctrlp#syntax() - en + cal ctrlp#syntax() cal ctrlp#setlines(s:walker(2 + ext, s:itemtype, a:dir)) cal s:PrtSwitcher() endf @@ -1213,9 +1211,8 @@ fu! ctrlp#setlcdir() endf " Highlighting {{{2 fu! ctrlp#syntax() - for [ke, va] in items(s:hlgrps) | if !hlexists('CtrlP'.ke) - exe 'hi link CtrlP'.ke va - en | endfo + if ctrlp#nosy() | retu | en + for [ke, va] in items(s:hlgrps) | cal ctrlp#hicheck('CtrlP'.ke, va) | endfo if !hlexists('CtrlPLinePre') \ && synIDattr(synIDtrans(hlID('Normal')), 'bg') !~ '^-1$\|^$' sil! exe 'hi CtrlPLinePre '.( has("gui_running") ? 'gui' : 'cterm' ).'fg=bg' @@ -1510,6 +1507,11 @@ fu! s:openfile(cmd, fid, tail, ...) cal ctrlp#setlcdir() en endf + +fu! s:settype(type) + retu a:type < 0 ? exists('s:itemtype') ? s:itemtype + \ : exists('g:CTRLP_LAST_MODE') ? g:CTRLP_LAST_MODE : 0 : a:type +endf " Matching {{{2 fu! s:matchfname(item, pat) retu match(split(a:item, s:lash)[-1], a:pat) @@ -1603,6 +1605,16 @@ endf fu! ctrlp#switchtype(id) cal s:ToggleType(a:id - s:itemtype) endf + +fu! ctrlp#nosy() + retu !( has('syntax') && exists('g:syntax_on') ) +endf + +fu! ctrlp#hicheck(grp, defgrp) + if !hlexists(a:grp) + exe 'hi link' a:grp a:defgrp + en +endf "}}}1 " * Initialization {{{1 fu! ctrlp#setlines(...) @@ -1622,12 +1634,8 @@ fu! ctrlp#init(type, ...) cal s:SetWD(a:0 ? a:1 : '') cal s:SetDefTxt() cal s:MapKeys() - if has('syntax') && exists('g:syntax_on') - cal ctrlp#syntax() - en - let type = a:type < 0 ? exists('s:itemtype') ? s:itemtype - \ : exists('g:CTRLP_LAST_MODE') ? g:CTRLP_LAST_MODE : 0 : a:type - cal ctrlp#setlines(type) + cal ctrlp#syntax() + cal ctrlp#setlines(s:settype(a:type)) cal s:BuildPrompt(1) endf " - Autocmds {{{1 diff --git a/autoload/ctrlp/buffertag.vim b/autoload/ctrlp/buffertag.vim index cb2e1e9..a8a99f9 100644 --- a/autoload/ctrlp/buffertag.vim +++ b/autoload/ctrlp/buffertag.vim @@ -199,15 +199,10 @@ fu! s:parseline(line) 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 + if ctrlp#nosy() | retu | en + cal ctrlp#hicheck('CtrlPTagKind', 'Title') + cal ctrlp#hicheck('CtrlPBufName', 'Directory') + cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') sy match CtrlPTagKind '\zs[^\t|]\+\ze|\d\+:[^|]\+|\d\+|' sy match CtrlPBufName '|\d\+:\zs[^|]\+\ze|\d\+|' sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName,CtrlPTagKind @@ -223,9 +218,7 @@ fu! ctrlp#buffertag#init(fname) let tftype = get(split(getbufvar(bname, '&ft'), '\.'), 0, '') cal extend(lines, s:process(bname, tftype)) endfo - if has('syntax') && exists('g:syntax_on') - cal s:syntax() - en + cal s:syntax() retu lines endf diff --git a/autoload/ctrlp/changes.vim b/autoload/ctrlp/changes.vim index 736e911..ecc370f 100644 --- a/autoload/ctrlp/changes.vim +++ b/autoload/ctrlp/changes.vim @@ -46,12 +46,9 @@ fu! s:process(clines, ...) endf fu! s:syntax() - if !hlexists('CtrlPBufName') - hi link CtrlPBufName Directory - en - if !hlexists('CtrlPTabExtra') - hi link CtrlPTabExtra Comment - en + if ctrlp#nosy() | retu | en + cal ctrlp#hicheck('CtrlPBufName', 'Directory') + cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') sy match CtrlPBufName '\t|\d\+:\zs[^|]\+\ze|\d\+:\d\+|$' sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName endf @@ -72,10 +69,8 @@ fu! ctrlp#changes#init(original_bufnr, fname) sil! exe 'noa hid b' a:original_bufnr let &swb = swb let g:ctrlp_nolimit = 1 - if has('syntax') && exists('g:syntax_on') - cal ctrlp#syntax() - cal s:syntax() - en + cal ctrlp#syntax() + cal s:syntax() retu lines endf diff --git a/autoload/ctrlp/dir.vim b/autoload/ctrlp/dir.vim index 7b0e17d..5b44fc7 100644 --- a/autoload/ctrlp/dir.vim +++ b/autoload/ctrlp/dir.vim @@ -35,9 +35,9 @@ fu! s:globdirs(dirs, depth) let entries = split(globpath(a:dirs, s:glob), "\n") let [dirs, depth] = [ctrlp#dirnfile(entries)[0], a:depth + 1] cal extend(g:ctrlp_alldirs, dirs) - if !empty(dirs) && !s:max(len(g:ctrlp_alldirs), s:maxfiles) - \ && depth <= s:maxdepth - sil! cal ctrlp#progress(len(g:ctrlp_alldirs)) + let nr = len(g:ctrlp_alldirs) + if !empty(dirs) && !s:max(nr, s:maxfiles) && depth <= s:maxdepth + sil! cal ctrlp#progress(nr) cal s:globdirs(join(dirs, ','), depth) en endf diff --git a/autoload/ctrlp/line.vim b/autoload/ctrlp/line.vim index 28b81d6..d5a2c57 100644 --- a/autoload/ctrlp/line.vim +++ b/autoload/ctrlp/line.vim @@ -24,12 +24,9 @@ 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) " Utilities {{{1 fu! s:syntax() - if !hlexists('CtrlPBufName') - hi link CtrlPBufName Directory - en - if !hlexists('CtrlPTabExtra') - hi link CtrlPTabExtra Comment - en + if ctrlp#nosy() | retu | en + cal ctrlp#hicheck('CtrlPBufName', 'Directory') + cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') sy match CtrlPBufName '\t|\zs[^|]\+\ze|\d\+:\d\+|$' sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName endf @@ -48,9 +45,7 @@ fu! ctrlp#line#init() cal filter(from_file, 'v:val !~ ''^\s*\t|[^|]\+|\d\+:\d\+|$''') cal extend(lines, from_file) endfo - if has('syntax') && exists('g:syntax_on') - cal s:syntax() - en + cal s:syntax() retu lines endf diff --git a/autoload/ctrlp/quickfix.vim b/autoload/ctrlp/quickfix.vim index 1296df9..0878a90 100644 --- a/autoload/ctrlp/quickfix.vim +++ b/autoload/ctrlp/quickfix.vim @@ -28,15 +28,17 @@ fu! s:lineout(dict) retu printf('%s|%d:%d| %s', bufname(a:dict['bufnr']), a:dict['lnum'], \ a:dict['col'], matchstr(a:dict['text'], '\s*\zs.*\S')) endf +" Utilities {{{1 +fu! s:syntax() + if !ctrlp#nosy() + cal ctrlp#hicheck('CtrlPqfLineCol', 'Search') + sy match CtrlPqfLineCol '|\zs\d\+:\d\+\ze|' + en +endf " Public {{{1 fu! ctrlp#quickfix#init() let g:ctrlp_nolimit = 1 - if has('syntax') && exists('g:syntax_on') - if !hlexists('CtrlPqfLineCol') - hi link CtrlPqfLineCol Search - en - sy match CtrlPqfLineCol '|\zs\d\+:\d\+\ze|' - en + cal s:syntax() retu map(getqflist(), 's:lineout(v:val)') endf diff --git a/autoload/ctrlp/tag.vim b/autoload/ctrlp/tag.vim index 5e002ef..1b90b7f 100644 --- a/autoload/ctrlp/tag.vim +++ b/autoload/ctrlp/tag.vim @@ -57,6 +57,13 @@ fu! s:filter(tags) endw retu alltags endf + +fu! s:syntax() + if !ctrlp#nosy() + cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') + sy match CtrlPTabExtra '\zs\t.*\ze$' + en +endf " Public {{{1 fu! ctrlp#tag#init() if empty(s:tagfiles) | retu [] | en @@ -66,12 +73,7 @@ fu! ctrlp#tag#init() let alltags = s:filter(ctrlp#utils#readfile(each)) cal extend(g:ctrlp_alltags, alltags) endfo - if has('syntax') && exists('g:syntax_on') - if !hlexists('CtrlPTabExtra') - hi link CtrlPTabExtra Comment - en - sy match CtrlPTabExtra '\zs\t.*\ze$' - en + cal s:syntax() retu g:ctrlp_alltags endf diff --git a/autoload/ctrlp/undo.vim b/autoload/ctrlp/undo.vim index 3604ba0..9f0ef53 100644 --- a/autoload/ctrlp/undo.vim +++ b/autoload/ctrlp/undo.vim @@ -82,11 +82,10 @@ fu! s:elapsed(nr) endf fu! s:syntax() + if ctrlp#nosy() | retu | en for [ke, va] in items({'T': 'Directory', 'Br': 'Comment', 'Nr': 'String', \ 'Sv': 'Comment', 'Po': 'Title'}) - if !hlexists('CtrlPUndo'.ke) - exe 'hi link CtrlPUndo'.ke va - en + cal ctrlp#hicheck('CtrlPUndo'.ke, va) endfo sy match CtrlPUndoT '\v\d+ \zs[^ ]+\ze|\d+:\d+:\d+' sy match CtrlPUndoBr '\[\|\]' @@ -121,9 +120,6 @@ endf fu! ctrlp#undo#init() let entries = s:undos[0] ? s:undos[1]['entries'] : s:undos[1] if empty(entries) | retu [] | en - if has('syntax') && exists('g:syntax_on') - cal s:syntax() - en let g:ctrlp_nolimit = 1 if !exists('s:lines') if s:undos[0] @@ -133,6 +129,7 @@ fu! ctrlp#undo#init() let s:lines = map(reverse(entries), 's:formatul(v:val)') en en + cal s:syntax() retu s:lines endf