Better option handling

This commit is contained in:
Kien N 2012-04-22 02:08:18 +07:00
parent 4852c3214b
commit d4e658caa9
4 changed files with 177 additions and 172 deletions

View File

@ -5,7 +5,7 @@
" Version: 1.7.5
" =============================================================================
" * Static variables {{{1
" ** Static variables {{{1
fu! s:ignore() "{{{2
let igdirs = [
\ '\.git$',
@ -40,120 +40,95 @@ fu! s:ignore() "{{{2
\ 'dir': '\v'.join(igdirs, '|'),
\ 'file': '\v'.join(igfiles, '|'),
\ }
endf
"}}}
fu! s:opts()
" Options
let hst = exists('+hi') ? &hi : 20
let [pref, opts] = ['g:ctrlp_', {
\ 'arg_map': ['s:argmap', 0],
\ 'buffer_func': ['s:buffunc', {}],
\ 'by_filename': ['s:byfname', 0],
\ 'clear_cache_on_exit': ['s:clrex', 1],
\ 'custom_ignore': ['s:usrign', s:ignore()],
\ 'default_input': ['s:deftxt', 0],
\ 'dont_split': ['s:nosplit', 'netrw'],
\ 'dotfiles': ['s:dotfiles', 1],
\ 'extensions': ['s:extensions', []],
\ 'follow_symlinks': ['s:folsym', 0],
\ 'highlight_match': ['s:mathi', [1, 'CtrlPMatch']],
\ 'jump_to_buffer': ['s:jmptobuf', 2],
\ 'lazy_update': ['s:lazy', 0],
\ 'match_func': ['s:matcher', {}],
\ 'match_window_bottom': ['s:mwbottom', 1],
\ 'match_window_reversed': ['s:mwreverse', 1],
\ 'max_depth': ['s:maxdepth', 40],
\ 'max_files': ['s:maxfiles', 10000],
\ 'max_height': ['s:mxheight', 10],
\ 'max_history': ['s:maxhst', hst],
\ 'mruf_default_order': ['s:mrudef', 0],
\ 'open_multi': ['s:opmul', '1v'],
\ 'open_new_file': ['s:newfop', 'v'],
\ 'prompt_mappings': ['s:urprtmaps', 0],
\ 'regexp_search': ['s:regexp', 0],
\ 'root_markers': ['s:rmarkers', []],
\ 'split_window': ['s:splitwin', 0],
\ 'status_func': ['s:status', {}],
\ 'use_caching': ['s:caching', 1],
\ 'use_migemo': ['s:migemo', 0],
\ 'user_command': ['s:usrcmd', ''],
\ 'working_path_mode': ['s:pathmode', 2],
\ }]
for [ke, va] in items(opts)
let {va[0]} = exists(pref.ke) ? {pref.ke} : va[1]
endfo
unl va
let new_opts = {
\ 'open_multiple_files': 's:opmul',
\ 'regexp': 's:regexp',
\ 'reuse_window': 's:nosplit',
\ 'switch_buffer': 's:jmptobuf',
\ }
for [ke, va] in items(new_opts)
let {va} = {exists(pref.ke) ? pref.ke : va}
endfo
if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
let s:maxdepth = min([s:maxdepth, 100])
let s:mxheight = max([s:mxheight, 1])
let s:glob = s:dotfiles ? '.*\|*' : '*'
let s:igntype = empty(s:usrign) ? -1 : type(s:usrign)
" Extensions
for each in s:extensions
exe 'ru autoload/ctrlp/'.each.'.vim'
endfo
" Keymaps
let [s:lcmap, s:prtmaps] = ['nn <buffer> <silent>', {
\ 'PrtBS()': ['<bs>', '<c-]>'],
\ 'PrtDelete()': ['<del>'],
\ 'PrtDeleteWord()': ['<c-w>'],
\ 'PrtClear()': ['<c-u>'],
\ 'PrtSelectMove("j")': ['<c-j>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtSelectMove("t")': ['<Home>', '<kHome>'],
\ 'PrtSelectMove("b")': ['<End>', '<kEnd>'],
\ 'PrtSelectMove("u")': ['<PageUp>', '<kPageUp>'],
\ 'PrtSelectMove("d")': ['<PageDown>', '<kPageDown>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
\ 'AcceptSelection("t")': ['<c-t>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
\ 'ToggleFocus()': ['<s-tab>'],
\ 'ToggleRegex()': ['<c-r>'],
\ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtExpandDir()': ['<tab>'],
\ 'PrtInsert("c")': ['<MiddleMouse>', '<insert>'],
\ 'PrtInsert()': ['<c-\>'],
\ 'PrtCurStart()': ['<c-a>'],
\ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>', '<c-^>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteEnt()': ['<F7>'],
\ 'CreateNewFile()': ['<c-y>'],
\ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'],
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ }]
if !has('gui_running') && ( has('win32') || has('win64') )
cal add(s:prtmaps['PrtBS()'], remove(s:prtmaps['PrtCurLeft()'], 0))
en
if type(s:urprtmaps) == 4
cal extend(s:prtmaps, s:urprtmaps)
en
" Global options
let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0,
\ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'mouse': 'n',
\ 'gcr': 'a:blinkon0', 'ic': 1, 'scs': 1, 'lmap': '', 'mousef': 0,
\ 'imd': 1 }
if s:lazy
cal extend(s:glbs, { 'ut': ( s:lazy > 1 ? s:lazy : 250 ) })
en
endf
cal s:opts()
endf "}}}2
" Options
let [s:pref, s:opts, s:new_opts] = ['g:ctrlp_', {
\ 'arg_map': ['s:argmap', 0],
\ 'buffer_func': ['s:buffunc', {}],
\ 'by_filename': ['s:byfname', 0],
\ 'clear_cache_on_exit': ['s:clrex', 1],
\ 'custom_ignore': ['s:usrign', s:ignore()],
\ 'default_input': ['s:deftxt', 0],
\ 'dont_split': ['s:nosplit', 'netrw'],
\ 'dotfiles': ['s:dotfiles', 1],
\ 'extensions': ['s:extensions', []],
\ 'follow_symlinks': ['s:folsym', 0],
\ 'highlight_match': ['s:mathi', [1, 'CtrlPMatch']],
\ 'jump_to_buffer': ['s:jmptobuf', 2],
\ 'lazy_update': ['s:lazy', 0],
\ 'match_func': ['s:matcher', {}],
\ 'match_window_bottom': ['s:mwbottom', 1],
\ 'match_window_reversed': ['s:mwreverse', 1],
\ 'max_depth': ['s:maxdepth', 40],
\ 'max_files': ['s:maxfiles', 10000],
\ 'max_height': ['s:mxheight', 10],
\ 'max_history': ['s:maxhst', exists('+hi') ? &hi : 20],
\ 'mruf_default_order': ['s:mrudef', 0],
\ 'open_multi': ['s:opmul', '1v'],
\ 'open_new_file': ['s:newfop', 'v'],
\ 'prompt_mappings': ['s:urprtmaps', 0],
\ 'regexp_search': ['s:regexp', 0],
\ 'root_markers': ['s:rmarkers', []],
\ 'split_window': ['s:splitwin', 0],
\ 'status_func': ['s:status', {}],
\ 'use_caching': ['s:caching', 1],
\ 'use_migemo': ['s:migemo', 0],
\ 'user_command': ['s:usrcmd', ''],
\ 'working_path_mode': ['s:pathmode', 2],
\ }, {
\ 'open_multiple_files': 's:opmul',
\ 'regexp': 's:regexp',
\ 'reuse_window': 's:nosplit',
\ 'switch_buffer': 's:jmptobuf',
\ }]
" Global options
let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0,
\ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'mouse': 'n',
\ 'gcr': 'a:blinkon0', 'ic': 1, 'scs': 1, 'lmap': '', 'mousef': 0,
\ 'imd': 1 }
" Keymaps
let [s:lcmap, s:prtmaps] = ['nn <buffer> <silent>', {
\ 'PrtBS()': ['<bs>', '<c-]>'],
\ 'PrtDelete()': ['<del>'],
\ 'PrtDeleteWord()': ['<c-w>'],
\ 'PrtClear()': ['<c-u>'],
\ 'PrtSelectMove("j")': ['<c-j>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtSelectMove("t")': ['<Home>', '<kHome>'],
\ 'PrtSelectMove("b")': ['<End>', '<kEnd>'],
\ 'PrtSelectMove("u")': ['<PageUp>', '<kPageUp>'],
\ 'PrtSelectMove("d")': ['<PageDown>', '<kPageDown>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
\ 'AcceptSelection("t")': ['<c-t>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
\ 'ToggleFocus()': ['<s-tab>'],
\ 'ToggleRegex()': ['<c-r>'],
\ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtExpandDir()': ['<tab>'],
\ 'PrtInsert("c")': ['<MiddleMouse>', '<insert>'],
\ 'PrtInsert()': ['<c-\>'],
\ 'PrtCurStart()': ['<c-a>'],
\ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>', '<c-^>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteEnt()': ['<F7>'],
\ 'CreateNewFile()': ['<c-y>'],
\ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'],
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ }]
if !has('gui_running') && ( has('win32') || has('win64') )
cal add(s:prtmaps['PrtBS()'], remove(s:prtmaps['PrtCurLeft()'], 0))
en
let s:lash = ctrlp#utils#lash()
@ -168,7 +143,7 @@ let s:fpats = {
\ '^\S\\?$': '\\?',
\ }
" Mappings
" Specials
let s:prtunmaps = [
\ 'PrtBS()',
\ 'PrtDelete()',
@ -204,6 +179,44 @@ let s:hlgrps = {
\ 'PrtText': 'Normal',
\ 'PrtCursor': 'Constant',
\ }
fu! s:opts() "{{{2
" Options
unl! s:usrign s:usrcmd s:urprtmaps
for each in ['byfname', 'regexp', 'extensions'] | if exists('s:'.each)
let {each} = s:{each}
en | endfo
for [ke, va] in items(s:opts)
let {va[0]} = exists(s:pref.ke) ? {s:pref.ke} : va[1]
endfo
unl va
for [ke, va] in items(s:new_opts)
let {va} = {exists(s:pref.ke) ? s:pref.ke : va}
endfo
for each in ['byfname', 'regexp'] | if exists(each)
let s:{each} = {each}
en | endfo
if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
let s:maxdepth = min([s:maxdepth, 100])
let s:mxheight = max([s:mxheight, 1])
let s:glob = s:dotfiles ? '.*\|*' : '*'
let s:igntype = empty(s:usrign) ? -1 : type(s:usrign)
if s:lazy
cal extend(s:glbs, { 'ut': ( s:lazy > 1 ? s:lazy : 250 ) })
en
" Extensions
if !( exists('extensions') && extensions == s:extensions )
for each in s:extensions
exe 'ru autoload/ctrlp/'.each.'.vim'
endfo
en
" Keymaps
if type(s:urprtmaps) == 4
cal extend(s:prtmaps, s:urprtmaps)
en
endf
cal s:opts()
"}}}1
" * Open & Close {{{1
fu! s:Open()
cal s:log(1)
@ -266,7 +279,6 @@ fu! ctrlp#reset()
cal s:opts()
cal s:autocmds()
cal ctrlp#utils#opts()
cal ctrlp#mrufiles#opts()
cal s:execextvar('opts')
endf
" * Files {{{1
@ -1286,14 +1298,12 @@ fu! s:highlight(pat, grp)
let pat = substitute(pat, '\$\@<!$', '\\ze[^\\/]*$', 'g')
en
cal matchadd(a:grp, '\c'.pat)
if hlexists('CtrlPLinePre')
cal matchadd('CtrlPLinePre', '^>')
en
cal matchadd('CtrlPLinePre', '^>')
en
endf
fu! s:dohighlight()
retu s:mathi[0] && exists('*clearmatches')
retu s:mathi[0] && exists('*clearmatches') && !ctrlp#nosy()
endf
" Prompt history {{{2
fu! s:gethistloc()
@ -1725,6 +1735,7 @@ endf
fu! ctrlp#init(type, ...)
if exists('s:init') | retu | en
let [s:matches, s:init] = [1, 1]
cal ctrlp#reset()
cal s:Open()
cal s:SetWD(a:0 ? a:1 : '')
cal s:MapKeys()
@ -1734,14 +1745,17 @@ fu! ctrlp#init(type, ...)
cal s:BuildPrompt(1)
endf
" - Autocmds {{{1
fu! s:autocmds()
if !has('autocmd') | retu | en
if has('autocmd')
aug CtrlPAug
au!
au BufEnter ControlP cal s:checkbuf()
au BufLeave ControlP cal s:Close()
au VimLeavePre * cal s:leavepre()
aug END
en
fu! s:autocmds()
if !has('autocmd') | retu | en
if exists('#CtrlPLazy')
au! CtrlPLazy
en

View File

@ -25,41 +25,17 @@ cal add(g:ctrlp_ext_vars, {
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
fu! ctrlp#buffertag#opts()
let [pref, opts] = ['g:ctrlp_buftag_', {
\ 'systemenc': ['s:enc', &enc],
\ 'ctags_bin': ['s:bin', ''],
\ 'types': ['s:usr_types', ''],
\ }]
for [ke, va] in items(opts)
let {va[0]} = exists(pref.ke) ? {pref.ke} : va[1]
endfo
endf
cal ctrlp#buffertag#opts()
let s:bins = [
\ 'ctags-exuberant',
\ 'exuberant-ctags',
\ 'exctags',
\ '/usr/local/bin/ctags',
\ '/opt/local/bin/ctags',
\ 'ctags',
\ 'ctags.exe',
\ 'tags',
\ ]
fu! s:bins()
let bins = [
\ 'ctags-exuberant',
\ 'exuberant-ctags',
\ 'exctags',
\ '/usr/local/bin/ctags',
\ '/opt/local/bin/ctags',
\ 'ctags',
\ 'ctags.exe',
\ 'tags',
\ ]
if empty(s:bin)
for bin in bins | if executable(bin)
let s:bin = bin
brea
en | endfo
el
let s:bin = expand(s:bin, 1)
en
endf
cal s:bins()
" s:types {{{2
let s:types = {
\ 'asm' : '%sasm%sasm%sdlmt',
\ 'aspperl': '%sasp%sasp%sfsv',
@ -106,9 +82,28 @@ if executable('jsctags')
cal extend(s:types, { 'javascript': { 'args': '-f -', 'bin': 'jsctags' } })
en
if type(s:usr_types) == 4
fu! ctrlp#buffertag#opts()
let [pref, opts] = ['g:ctrlp_buftag_', {
\ 'systemenc': ['s:enc', &enc],
\ 'ctags_bin': ['s:bin', ''],
\ 'types': ['s:usr_types', {}],
\ }]
for [ke, va] in items(opts)
let {va[0]} = exists(pref.ke) ? {pref.ke} : va[1]
endfo
" Ctags bin
if empty(s:bin)
for bin in s:bins | if executable(bin)
let s:bin = bin
brea
en | endfo
el
let s:bin = expand(s:bin, 1)
en
" Types
cal extend(s:types, s:usr_types)
en
endf
cal ctrlp#buffertag#opts()
" Utilities {{{1
fu! s:validfile(fname, ftype)
if ( !empty(a:fname) || !empty(a:ftype) ) && filereadable(a:fname)

View File

@ -5,6 +5,8 @@
" =============================================================================
" Static variables {{{1
let [s:mrbs, s:mrufs] = [[], []]
fu! ctrlp#mrufiles#opts()
let [pref, opts] = ['g:ctrlp_mruf_', {
\ 'max': ['s:max', 250],
@ -14,15 +16,13 @@ fu! ctrlp#mrufiles#opts()
\ 'relative': ['s:re', 0],
\ }]
for [ke, va] in items(opts)
let {va[0]} = exists(pref.ke) ? {pref.ke} : va[1]
let [{va[0]}, {pref.ke}] = [pref.ke, exists(pref.ke) ? {pref.ke} : va[1]]
endfo
let [s:csen, s:mrbs, s:mrufs] = [s:cseno ? '#' : '?', [], []]
if exists('s:locked') | cal ctrlp#mrufiles#init() | en
endf
cal ctrlp#mrufiles#opts()
" Utilities {{{1
fu! s:excl(fn)
retu !empty(s:ex) && a:fn =~# s:ex
retu !empty({s:ex}) && a:fn =~# {s:ex}
endf
fu! s:mergelists()
@ -33,12 +33,12 @@ fu! s:mergelists()
endf
fu! s:chop(mrufs)
if len(a:mrufs) > s:max | cal remove(a:mrufs, s:max, -1) | en
if len(a:mrufs) > {s:max} | cal remove(a:mrufs, {s:max}, -1) | en
retu a:mrufs
endf
fu! s:reformat(mrufs)
if s:re
if {s:re}
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
cal filter(a:mrufs, '!stridx(v:val, cwd)')
en
@ -55,10 +55,10 @@ fu! s:record(bufnr)
let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
cal filter(s:mrbs, 'v:val != bufnr')
cal insert(s:mrbs, bufnr)
if ( !empty(s:in) && fn !~# s:in ) || ( !empty(s:ex) && fn =~# s:ex )
if ( !empty({s:in}) && fn !~# {s:in} ) || ( !empty({s:ex}) && fn =~# {s:ex} )
\ || !empty(&bt) || !filereadable(fn) | retu
en
cal filter(s:mrufs, 'v:val !='.s:csen.' fn')
cal filter(s:mrufs, 'v:val !='.( {s:cseno} ? '#' : '?' ).' fn')
cal insert(s:mrufs, fn)
endf
@ -81,7 +81,7 @@ fu! ctrlp#mrufiles#remove(files)
let s:mrufs = []
if a:files != []
let s:mrufs = s:mergelists()
cal filter(s:mrufs, 'index(a:files, v:val, 0, '.(!s:cseno).') < 0')
cal filter(s:mrufs, 'index(a:files, v:val, 0, '.(!{s:cseno}).') < 0')
en
cal s:savetofile(s:mrufs)
retu s:reformat(copy(s:mrufs))

View File

@ -560,10 +560,6 @@ COMMANDS *ctrlp-commands*
:CtrlPClearAllCaches
Delete all the cache files saved in |g:ctrlp_cache_dir|.
*:CtrlPReload*
:CtrlPReload
Load new values for the option variables.
-------------------------------------------------------------------------------
For commands provided by bundled extensions, see |ctrlp-extensions|.