Make highlight groups overridable

This commit is contained in:
Kien N 2012-02-05 16:13:52 +07:00
parent ec31fa8bb8
commit 75e31e9341
8 changed files with 82 additions and 59 deletions

View File

@ -2,7 +2,7 @@
" File: autoload/ctrlp.vim
" Description: Fuzzy file, buffer, mru and tag finder.
" Author: Kien Nguyen <github.com/kien>
" 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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)

View File

@ -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 prompts base (Comment)
CtrlPPrtText : the prompts text (|hl-Normal|)
CtrlPPrtCursor : the prompts 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 thats 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*