From 75e31e934135ae8a5e1094e948f8efb3f35baed2 Mon Sep 17 00:00:00 2001 From: Kien N Date: Sun, 5 Feb 2012 16:13:52 +0700 Subject: [PATCH] Make highlight groups overridable --- autoload/ctrlp.vim | 83 +++++++++++++++++++++--------------- autoload/ctrlp/buffertag.vim | 4 +- autoload/ctrlp/line.vim | 4 +- autoload/ctrlp/quickfix.vim | 4 +- autoload/ctrlp/rtscript.vim | 2 +- autoload/ctrlp/tag.vim | 4 +- autoload/ctrlp/undo.vim | 8 ++-- doc/ctrlp.txt | 32 +++++++------- 8 files changed, 82 insertions(+), 59 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 2730172..0d62d81 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -2,7 +2,7 @@ " File: autoload/ctrlp.vim " Description: Fuzzy file, buffer, mru and tag finder. " Author: Kien Nguyen -" Version: 1.6.9 +" Version: 1.7.1 " ============================================================================= " Static variables {{{1 @@ -135,6 +135,18 @@ let s:fpats = { \ '^\S\*$': '\*', \ '^\S\\?$': '\\?', \ } + +" Highlight groups +let s:hlgrps = { + \ 'NoEntries': 'Error', + \ 'Mode1': 'Character', + \ 'Mode2': 'LineNr', + \ 'Stats': 'Function', + \ 'Match': 'Identifier', + \ 'PrtBase': 'Comment', + \ 'PrtText': 'Normal', + \ 'PrtCursor': 'Constant', + \ } " * Open & Close {{{1 fu! s:Open() if exists('g:ctrlp_log') && g:ctrlp_log @@ -159,7 +171,8 @@ fu! s:Open() endf fu! s:Close() - try | noa bun! | cat | noa clo! | endt + try | noa bun! + cat | noa clo! | endt cal s:unmarksigns() for key in keys(s:glbs) sil! exe 'let &'.key.' = s:glb_'.key @@ -213,7 +226,8 @@ fu! s:Files() cal s:GlobPath(cwd, 0) el sil! cal ctrlp#progress('Indexing...') - try | cal s:UserCmd(cwd, lscmd) | cat | retu [] | endt + try | cal s:UserCmd(cwd, lscmd) + cat | retu [] | endt en " Remove base directory cal ctrlp#rmbasedir(g:ctrlp_allfiles) @@ -298,8 +312,9 @@ endf fu! s:MatchIt(items, pat, limit, mfunc) let newitems = [] for item in a:items - try | if call(a:mfunc, [item, a:pat]) >= 0 | cal add(newitems, item) | en - cat | brea | endt + try | if call(a:mfunc, [item, a:pat]) >= 0 + cal add(newitems, item) + en | cat | brea | endt if a:limit > 0 && len(newitems) >= a:limit | brea | en endfo retu newitems @@ -444,22 +459,22 @@ endf fu! s:PrtAdd(char) unl! s:hstgot - let s:prompt[0] = s:prompt[0] . a:char + let s:prompt[0] .= a:char cal s:BuildPrompt(1) endf fu! s:PrtBS() unl! s:hstgot let [prt, s:matches] = [s:prompt, 1] - let prt[0] = strpart(prt[0], -1, strlen(prt[0])) + let prt[0] = substitute(prt[0], '.$', '', '') cal s:BuildPrompt(1) endf fu! s:PrtDelete() unl! s:hstgot let [prt, s:matches] = [s:prompt, 1] - let prt[1] = strpart(prt[2], 0, 1) - let prt[2] = strpart(prt[2], 1) + let prt[1] = matchstr(prt[2], '^.') + let prt[2] = substitute(prt[2], '^.', '', '') cal s:BuildPrompt(1) endf @@ -501,30 +516,28 @@ fu! s:PrtCurLeft() if !empty(s:prompt[0]) let prt = s:prompt let prt[2] = prt[1] . prt[2] - let prt[1] = strpart(prt[0], strlen(prt[0]) - 1) - let prt[0] = strpart(prt[0], -1, strlen(prt[0])) + let prt[1] = matchstr(prt[0], '.$') + let prt[0] = substitute(prt[0], '.$', '', '') en cal s:BuildPrompt(0) endf fu! s:PrtCurRight() let prt = s:prompt - let prt[0] = prt[0] . prt[1] - let prt[1] = strpart(prt[2], 0, 1) - let prt[2] = strpart(prt[2], 1) + let prt[0] .= prt[1] + let prt[1] = matchstr(prt[2], '^.') + let prt[2] = substitute(prt[2], '^.', '', '') cal s:BuildPrompt(0) endf fu! s:PrtCurStart() - let prt = s:prompt - let str = join(prt, '') - let [prt[0], prt[1], prt[2]] = ['', strpart(str, 0, 1), strpart(str, 1)] + let str = join(s:prompt, '') + let s:prompt = ['', matchstr(str, '^.'), substitute(str, '^.', '', '')] cal s:BuildPrompt(0) endf fu! s:PrtCurEnd() - let prt = s:prompt - let [prt[0], prt[1], prt[2]] = [join(prt, ''), '', ''] + let s:prompt = [join(s:prompt, ''), '', ''] cal s:BuildPrompt(0) endf @@ -666,11 +679,11 @@ fu! s:ToggleType(dir) let s:itemtype = s:walker(g:ctrlp_builtins + ext, s:itemtype, a:dir) if s:byfname && !s:ispathitem() | let s:byfname = 0 | en unl! g:ctrlp_nolimit - cal s:SetLines(s:itemtype) - cal s:PrtSwitcher() if has('syntax') && exists('g:syntax_on') cal s:syntax() en + cal s:SetLines(s:itemtype) + cal s:PrtSwitcher() endf fu! s:PrtSwitcher() @@ -1114,32 +1127,32 @@ fu! ctrlp#setdir(path, ...) endf " Highlighting {{{2 fu! s:syntax() - sy match CtrlPNoEntries '^ == NO ENTRIES ==$' - sy match CtrlPLinePre '^>' - hi link CtrlPNoEntries Error - hi link CtrlPMode1 Character - hi link CtrlPMode2 LineNr - hi link CtrlPStats Function - hi link CtrlPMatch Identifier - hi link CtrlPPrtBase Comment - hi link CtrlPPrtText Normal - hi link CtrlPPrtCursor Constant - if hlexists('Normal') + for [ke, va] in items(s:hlgrps) | if !hlexists('CtrlP'.ke) + exe 'hi link CtrlP'.ke va + en | endfo + if !hlexists('CtrlPLinePre') + \ && synIDattr(synIDtrans(hlID('Normal')), 'bg') !~ '^-1$\|^$' sil! exe 'hi CtrlPLinePre '.( has("gui_running") ? 'gui' : 'cterm' ).'fg=bg' en + sy match CtrlPNoEntries '^ == NO ENTRIES ==$' + if hlexists('CtrlPLinePre') + sy match CtrlPLinePre '^>' + en endf fu! s:highlight(pat, grp) cal clearmatches() if !empty(a:pat) && s:ispathitem() let pat = s:regexp ? substitute(a:pat, '\\\@ \\zs', 'g') : a:pat - " Match only filename if s:byfname + " Match only filename let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g') let pat = substitute(pat, '$', '\\ze[^\\/]*$', 'g') en cal matchadd(a:grp, '\c'.pat) - cal matchadd('CtrlPLinePre', '^>') + if hlexists('CtrlPLinePre') + cal matchadd('CtrlPLinePre', '^>') + en en endf @@ -1481,10 +1494,10 @@ fu! ctrlp#init(type, ...) cal s:Open() cal s:SetWD(a:0 ? a:1 : '') cal s:MapKeys() - cal s:SetLines(a:type) if has('syntax') && exists('g:syntax_on') cal s:syntax() en + cal s:SetLines(a:type) cal s:BuildPrompt(1) endf if has('autocmd') "{{{1 diff --git a/autoload/ctrlp/buffertag.vim b/autoload/ctrlp/buffertag.vim index 5c8045b..a45d507 100644 --- a/autoload/ctrlp/buffertag.vim +++ b/autoload/ctrlp/buffertag.vim @@ -205,8 +205,10 @@ fu! ctrlp#buffertag#init(fname) let tftype = get(split(getbufvar(each, '&ft'), '\.'), 0, '') cal extend(lines, s:process(each, tftype)) endfo + if !hlexists('CtrlPTabExtra') + hi link CtrlPTabExtra Comment + en sy match CtrlPTabExtra '\zs\t.*\ze$' - hi link CtrlPTabExtra Comment retu lines endf diff --git a/autoload/ctrlp/line.vim b/autoload/ctrlp/line.vim index f200604..903bbf9 100644 --- a/autoload/ctrlp/line.vim +++ b/autoload/ctrlp/line.vim @@ -43,8 +43,10 @@ fu! ctrlp#line#init() cal filter(from_file, 'v:val !~ ''^\s*\t#:\d\+:\d\+$''') cal extend(lines, from_file) endfo + if !hlexists('CtrlPTabExtra') + hi link CtrlPTabExtra Comment + en sy match CtrlPTabExtra '\zs\t.*\ze$' - hi link CtrlPTabExtra Comment retu lines endf diff --git a/autoload/ctrlp/quickfix.vim b/autoload/ctrlp/quickfix.vim index cc64d2f..51e2bdd 100644 --- a/autoload/ctrlp/quickfix.vim +++ b/autoload/ctrlp/quickfix.vim @@ -30,8 +30,10 @@ endf " Public {{{1 fu! ctrlp#quickfix#init() let g:ctrlp_nolimit = 1 + if !hlexists('CtrlPqfLineCol') + hi link CtrlPqfLineCol Search + en sy match CtrlPqfLineCol '|\zs\d\+:\d\+\ze|' - hi def link CtrlPqfLineCol Search retu map(getqflist(), 's:lineout(v:val)') endf diff --git a/autoload/ctrlp/rtscript.vim b/autoload/ctrlp/rtscript.vim index 15fca51..dda9dd0 100644 --- a/autoload/ctrlp/rtscript.vim +++ b/autoload/ctrlp/rtscript.vim @@ -28,7 +28,7 @@ fu! ctrlp#rtscript#init() \ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[0] == &rtp ) sil! cal ctrlp#progress('Indexing...') let entries = split(globpath(&rtp, '**/*.*'), "\n") - cal filter(entries, 'index(entries, v:val, v:key + 1) < 0') + cal filter(entries, 'count(entries, v:val) == 1') let [entries, echoed] = [ctrlp#dirnfile(entries)[1], 1] el let [entries, results] = g:ctrlp_rtscache[2:3] diff --git a/autoload/ctrlp/tag.vim b/autoload/ctrlp/tag.vim index d74a38f..e969089 100644 --- a/autoload/ctrlp/tag.vim +++ b/autoload/ctrlp/tag.vim @@ -72,8 +72,10 @@ fu! ctrlp#tag#init(tagfiles) let alltags = s:filter(ctrlp#utils#readfile(each)) cal extend(g:ctrlp_alltags, alltags) endfo + if !hlexists('CtrlPTabExtra') + hi link CtrlPTabExtra Comment + en sy match CtrlPTabExtra '\zs\t.*\ze$' - hi link CtrlPTabExtra Comment retu g:ctrlp_alltags endf diff --git a/autoload/ctrlp/undo.vim b/autoload/ctrlp/undo.vim index 718c1ba..f4d4625 100644 --- a/autoload/ctrlp/undo.vim +++ b/autoload/ctrlp/undo.vim @@ -80,12 +80,14 @@ fu! s:humantime(nr) endf fu! s:syntax() + for [ke, va] in items({'T': 'Directory', 'Br': 'Comment', 'Nr': 'String'}) + if !hlexists('CtrlPUndo'.ke) + exe 'hi link CtrlPUndo'.ke va + en + endfo sy match CtrlPUndoT '\d\+ \zs[^ ]\+\ze' sy match CtrlPUndoBr '\[\|\]' sy match CtrlPUndoNr '\[\d\+\]$' contains=CtrlPUndoBr - hi link CtrlPUndoT Directory - hi link CtrlPUndoBr Comment - hi link CtrlPUndoNr String endf fu! s:dict2list(dict) diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index aadcd1e..46d9303 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -1,4 +1,4 @@ -*ctrlp.txt* Fuzzy file, buffer, mru and tag finder. v1.6.9 +*ctrlp.txt* Fuzzy file, buffer, mru and tag finder. v1.7.1 *CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'* =============================================================================== # # @@ -698,27 +698,27 @@ CUSTOMIZATION *ctrlp-customization* Highlighting:~ * For the |CtrlP| buffer: - CtrlPNoEntries (links to Error) - CtrlPMatch (links to Identifier) - CtrlPPrtBase (links to Comment) - CtrlPPrtText (links to |hl-Normal|) - CtrlPPrtCursor (links to Constant) - CtrlPLinePre (links to |hl-Normal|’s |guibg| and |ctermbg|) + CtrlPNoEntries : the message when no match is found (Error) + CtrlPMatch : the matched pattern (Identifier) + CtrlPLinePre : the line prefix '>' in the match window + CtrlPPrtBase : the prompt’s base (Comment) + CtrlPPrtText : the prompt’s text (|hl-Normal|) + CtrlPPrtCursor : the prompt’s cursor when moving over the text (Constant) * In extensions: - CtrlPTabExtra (links to Comment) - CtrlPqfLineCol (links to |hl-Search|) - CtrlPUndoT (links to |hl-Directory|) - CtrlPUndoBr (links to Comment) - CtrlPUndoNr (links to String) + CtrlPTabExtra : the part of each line that’s not matched against (Comment) + CtrlPqfLineCol : the line and column numbers in quickfix mode (|hl-Search|) + CtrlPUndoT : the elapsed time in undo mode (|hl-Directory|) + CtrlPUndoBr : the square brackets [] in undo mode (Comment) + CtrlPUndoNr : the undo number inside [] in undo mode (String) Statuslines:~ * Highlight groups: - CtrlPMode1 (links to Character) - CtrlPMode2 (links to |hl-LineNr|) - CtrlPStats (links to Function) + CtrlPMode1 : 'prt' or 'win', also for 'regex' (Character) + CtrlPMode2 : 'file' or 'path', also for the local working dir (|hl-LineNr|) + CtrlPStats : the scanning status (Function) - * For rebuilding the statuslines, see |g:ctrlp_status_func|. + For rebuilding the statuslines, see |g:ctrlp_status_func|. =============================================================================== CREDITS *ctrlp-credits*