Input abbreviations
This commit is contained in:
parent
72ec4e95c9
commit
5bded09b77
@ -53,6 +53,7 @@ endf
|
|||||||
" Script local vars {{{2
|
" Script local vars {{{2
|
||||||
let [s:pref, s:bpref, s:opts, s:new_opts, s:lc_opts] =
|
let [s:pref, s:bpref, s:opts, s:new_opts, s:lc_opts] =
|
||||||
\ ['g:ctrlp_', 'b:ctrlp_', {
|
\ ['g:ctrlp_', 'b:ctrlp_', {
|
||||||
|
\ 'abbrev': ['s:abbrev', {}],
|
||||||
\ 'arg_map': ['s:argmap', 0],
|
\ 'arg_map': ['s:argmap', 0],
|
||||||
\ 'buffer_func': ['s:buffunc', {}],
|
\ 'buffer_func': ['s:buffunc', {}],
|
||||||
\ 'by_filename': ['s:byfname', 0],
|
\ 'by_filename': ['s:byfname', 0],
|
||||||
@ -276,7 +277,7 @@ fu! s:Close()
|
|||||||
exe s:winres[0]
|
exe s:winres[0]
|
||||||
en
|
en
|
||||||
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
|
||||||
\ s:mrbs
|
\ s:mrbs s:did_exp
|
||||||
cal ctrlp#recordhist()
|
cal ctrlp#recordhist()
|
||||||
cal s:execextvar('exit')
|
cal s:execextvar('exit')
|
||||||
cal s:log(0)
|
cal s:log(0)
|
||||||
@ -413,8 +414,9 @@ endf
|
|||||||
" * MatchedItems() {{{1
|
" * MatchedItems() {{{1
|
||||||
fu! s:MatchIt(items, pat, limit, exc)
|
fu! s:MatchIt(items, pat, limit, exc)
|
||||||
let [lines, id] = [[], 0]
|
let [lines, id] = [[], 0]
|
||||||
let pat = s:byfname ?
|
let pat =
|
||||||
\ map(split(a:pat, '^[^;]\+\zs;', 1), 's:martcs.v:val') : s:martcs.a:pat
|
\ s:byfname ? map(split(a:pat, '^[^;]\+\\\@<!\zs;', 1), 's:martcs.v:val')
|
||||||
|
\ : s:martcs.a:pat
|
||||||
for item in a:items
|
for item in a:items
|
||||||
let id += 1
|
let id += 1
|
||||||
try | if !( s:ispath && item == a:exc ) && call(s:mfunc, [item, pat]) >= 0
|
try | if !( s:ispath && item == a:exc ) && call(s:mfunc, [item, pat]) >= 0
|
||||||
@ -436,6 +438,7 @@ fu! s:MatchedItems(items, pat, limit)
|
|||||||
let lines = s:MatchIt(items, a:pat, a:limit, exc)
|
let lines = s:MatchIt(items, a:pat, a:limit, exc)
|
||||||
en
|
en
|
||||||
let s:matches = len(lines)
|
let s:matches = len(lines)
|
||||||
|
unl! s:did_exp
|
||||||
retu lines
|
retu lines
|
||||||
endf
|
endf
|
||||||
|
|
||||||
@ -474,7 +477,7 @@ endf
|
|||||||
" * BuildPrompt() {{{1
|
" * BuildPrompt() {{{1
|
||||||
fu! s:Render(lines, pat)
|
fu! s:Render(lines, pat)
|
||||||
let [&ma, lines, s:height] = [1, a:lines, min([len(a:lines), s:winh])]
|
let [&ma, lines, s:height] = [1, a:lines, min([len(a:lines), s:winh])]
|
||||||
let pat = s:byfname ? split(a:pat, '^[^;]\+\zs;', 1)[0] : a:pat
|
let pat = s:byfname ? split(a:pat, '^[^;]\+\\\@<!\zs;', 1)[0] : a:pat
|
||||||
" Setup the match window
|
" Setup the match window
|
||||||
sil! exe '%d _ | res' s:height
|
sil! exe '%d _ | res' s:height
|
||||||
" Print the new items
|
" Print the new items
|
||||||
@ -525,18 +528,14 @@ fu! s:Update(str)
|
|||||||
endf
|
endf
|
||||||
|
|
||||||
fu! s:ForceUpdate()
|
fu! s:ForceUpdate()
|
||||||
let [estr, prt] = ['"\', copy(s:prompt)]
|
sil! cal s:Update(escape(s:getinput(), '\'))
|
||||||
cal map(prt, 'escape(v:val, estr)')
|
|
||||||
sil! cal s:Update(join(prt, ''))
|
|
||||||
endf
|
endf
|
||||||
|
|
||||||
fu! s:BuildPrompt(upd)
|
fu! s:BuildPrompt(upd)
|
||||||
let base = ( s:regexp ? 'r' : '>' ).( s:byfname ? 'd' : '>' ).'> '
|
let base = ( s:regexp ? 'r' : '>' ).( s:byfname ? 'd' : '>' ).'> '
|
||||||
let [estr, prt] = ['"\', copy(s:prompt)]
|
let str = escape(s:getinput(), '\')
|
||||||
cal map(prt, 'escape(v:val, estr)')
|
let lazy = str == '' || exists('s:force') || !has('autocmd') ? 0 : s:lazy
|
||||||
let str = join(prt, '')
|
if a:upd && !lazy && ( s:matches || s:regexp || exists('s:did_exp')
|
||||||
let lazy = empty(str) || exists('s:force') || !has('autocmd') ? 0 : s:lazy
|
|
||||||
if a:upd && !lazy && ( s:matches || s:regexp
|
|
||||||
\ || str =~ '\(\\\(<\|>\)\|[*|]\)\|\(\\\:\([^:]\|\\:\)*$\)' )
|
\ || str =~ '\(\\\(<\|>\)\|[*|]\)\|\(\\\:\([^:]\|\\:\)*$\)' )
|
||||||
sil! cal s:Update(str)
|
sil! cal s:Update(str)
|
||||||
en
|
en
|
||||||
@ -548,6 +547,8 @@ fu! s:BuildPrompt(upd)
|
|||||||
let hibase = 'CtrlPPrtBase'
|
let hibase = 'CtrlPPrtBase'
|
||||||
" Build it
|
" Build it
|
||||||
redr
|
redr
|
||||||
|
let prt = copy(s:prompt)
|
||||||
|
cal map(prt, 'escape(v:val, ''"\'')')
|
||||||
exe 'echoh' hibase '| echon "'.base.'"
|
exe 'echoh' hibase '| echon "'.base.'"
|
||||||
\ | echoh' hiactive '| echon "'.prt[0].'"
|
\ | echoh' hiactive '| echon "'.prt[0].'"
|
||||||
\ | echoh' hicursor '| echon "'.prt[1].'"
|
\ | echoh' hicursor '| echon "'.prt[1].'"
|
||||||
@ -640,7 +641,7 @@ endf
|
|||||||
|
|
||||||
fu! s:PrtExpandDir()
|
fu! s:PrtExpandDir()
|
||||||
if !s:focus | retu | en
|
if !s:focus | retu | en
|
||||||
let str = s:prompt[0]
|
let str = s:getinput('c')
|
||||||
if str =~ '\v^\@(cd|lc[hd]?|chd)\s.+' && s:spi
|
if str =~ '\v^\@(cd|lc[hd]?|chd)\s.+' && s:spi
|
||||||
let hasat = split(str, '\v^\@(cd|lc[hd]?|chd)\s*\zs')
|
let hasat = split(str, '\v^\@(cd|lc[hd]?|chd)\s*\zs')
|
||||||
let str = get(hasat, 1, '')
|
let str = get(hasat, 1, '')
|
||||||
@ -963,7 +964,7 @@ endf
|
|||||||
|
|
||||||
fu! s:AcceptSelection(mode)
|
fu! s:AcceptSelection(mode)
|
||||||
if a:mode != 'e' && s:OpenMulti(a:mode) != -1 | retu | en
|
if a:mode != 'e' && s:OpenMulti(a:mode) != -1 | retu | en
|
||||||
let str = join(s:prompt, '')
|
let str = s:getinput()
|
||||||
if a:mode == 'e' | if s:SpecInputs(str) | retu | en | en
|
if a:mode == 'e' | if s:SpecInputs(str) | retu | en | en
|
||||||
" Get the selected line
|
" Get the selected line
|
||||||
let line = ctrlp#getcline()
|
let line = ctrlp#getcline()
|
||||||
@ -982,7 +983,7 @@ fu! s:AcceptSelection(mode)
|
|||||||
endf
|
endf
|
||||||
" - CreateNewFile() {{{1
|
" - CreateNewFile() {{{1
|
||||||
fu! s:CreateNewFile(...)
|
fu! s:CreateNewFile(...)
|
||||||
let [md, str] = ['', join(s:prompt, '')]
|
let [md, str] = ['', s:getinput('n')]
|
||||||
if empty(str) | retu | en
|
if empty(str) | retu | en
|
||||||
if s:argmap && !a:0
|
if s:argmap && !a:0
|
||||||
" Get the extra argument
|
" Get the extra argument
|
||||||
@ -1734,7 +1735,34 @@ endf
|
|||||||
fu! s:narrowable()
|
fu! s:narrowable()
|
||||||
retu exists('s:act_add') && exists('s:matched') && s:matched != []
|
retu exists('s:act_add') && exists('s:matched') && s:matched != []
|
||||||
\ && exists('s:mdata') && s:mdata[:2] == [s:dyncwd, s:itemtype, s:regexp]
|
\ && exists('s:mdata') && s:mdata[:2] == [s:dyncwd, s:itemtype, s:regexp]
|
||||||
\ && s:matcher == {}
|
\ && s:matcher == {} && !exists('s:did_exp')
|
||||||
|
endf
|
||||||
|
|
||||||
|
fu! s:getinput(...)
|
||||||
|
let [prt, spi] = [s:prompt, ( a:0 ? a:1 : '' )]
|
||||||
|
if s:abbrev != {}
|
||||||
|
let gmd = has_key(s:abbrev, 'gmode') ? s:abbrev['gmode'] : ''
|
||||||
|
let [ayt, nkw] = [( gmd =~ 't' ), ( gmd =~ 'k' )]
|
||||||
|
let str = ( ayt && !a:0 ) || spi == 'c' ? prt[0] : join(prt, '')
|
||||||
|
if ayt && nkw && !a:0 && matchstr(str, '.$') =~ '\k'
|
||||||
|
retu join(prt, '')
|
||||||
|
en
|
||||||
|
let [pf, rz] = [( s:byfname ? 'f' : 'p' ), ( s:regexp ? 'r' : 'z' )]
|
||||||
|
for dict in s:abbrev['abbrevs']
|
||||||
|
let dmd = has_key(dict, 'mode') ? dict['mode'] : ''
|
||||||
|
let pat = escape(dict['pattern'], '~')
|
||||||
|
if ( dmd == '' || ( dmd =~ pf && dmd =~ rz && !a:0 )
|
||||||
|
\ || dmd =~ '['.spi.']' ) && str =~ pat
|
||||||
|
let [str, s:did_exp] = [join(split(str, pat, 1), dict['expanded']), 1]
|
||||||
|
en
|
||||||
|
endfo
|
||||||
|
if ayt && !a:0
|
||||||
|
let prt[0] = str
|
||||||
|
el
|
||||||
|
retu str
|
||||||
|
en
|
||||||
|
en
|
||||||
|
retu spi == 'c' ? prt[0] : join(prt, '')
|
||||||
endf
|
endf
|
||||||
|
|
||||||
fu! s:migemo(str)
|
fu! s:migemo(str)
|
||||||
|
@ -63,6 +63,7 @@ Overview:~
|
|||||||
|ctrlp_follow_symlinks|.......Follow symbolic links or not.
|
|ctrlp_follow_symlinks|.......Follow symbolic links or not.
|
||||||
|ctrlp_lazy_update|...........Only update when typing has stopped.
|
|ctrlp_lazy_update|...........Only update when typing has stopped.
|
||||||
|ctrlp_default_input|.........Seed the prompt with an initial string.
|
|ctrlp_default_input|.........Seed the prompt with an initial string.
|
||||||
|
|ctrlp_abbrev|................Input abbreviations.
|
||||||
|ctrlp_key_loop|..............Use input looping for multi-byte input.
|
|ctrlp_key_loop|..............Use input looping for multi-byte input.
|
||||||
|ctrlp_use_migemo|............Use Migemo patterns for Japanese filenames.
|
|ctrlp_use_migemo|............Use Migemo patterns for Japanese filenames.
|
||||||
|ctrlp_prompt_mappings|.......Change the mappings inside the prompt.
|
|ctrlp_prompt_mappings|.......Change the mappings inside the prompt.
|
||||||
@ -418,6 +419,57 @@ as the default input: >
|
|||||||
let g:ctrlp_default_input = 'anystring'
|
let g:ctrlp_default_input = 'anystring'
|
||||||
<
|
<
|
||||||
|
|
||||||
|
*'g:ctrlp_abbrev'*
|
||||||
|
Define input abbreviations that can be expanded (either internally or visibly)
|
||||||
|
in the prompt: >
|
||||||
|
let g:ctrlp_abbrev = {}
|
||||||
|
<
|
||||||
|
Examples: >
|
||||||
|
let g:ctrlp_abbrev = {
|
||||||
|
\ 'gmode': 'i',
|
||||||
|
\ 'abbrevs': [
|
||||||
|
\ {
|
||||||
|
\ 'pattern': '^cd b',
|
||||||
|
\ 'expanded': '@cd ~/.vim/bundle',
|
||||||
|
\ 'mode': 'pfrz',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'pattern': '\(^@.\+\|\\\@<!:.\+\)\@<! ',
|
||||||
|
\ 'expanded': '.\{-}',
|
||||||
|
\ 'mode': 'pfr',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'pattern': '\\\@<!:.\+\zs\\\@<! ',
|
||||||
|
\ 'expanded': '\ ',
|
||||||
|
\ 'mode': 'pfz',
|
||||||
|
\ },
|
||||||
|
\ ]
|
||||||
|
\ }
|
||||||
|
<
|
||||||
|
The 'pattern' string is regexp matched against the entered input. The expansion
|
||||||
|
is as if the 'expanded' string was typed into the prompt.
|
||||||
|
|
||||||
|
For 'gmode' (optional):
|
||||||
|
i - expand internally (default).
|
||||||
|
t - insert the expanded results into the prompt as you type.
|
||||||
|
k - insert the expanded results when a non-keyword character is typed. Only
|
||||||
|
applies when "t" is also present.
|
||||||
|
|
||||||
|
For 'mode' (of each entry; optional):
|
||||||
|
f - only in filename mode.
|
||||||
|
p - only in full path mode.
|
||||||
|
r - only in regexp mode.
|
||||||
|
z - only in fuzzy mode.
|
||||||
|
n - only when creating a new file with <c-y> (use the expanded string in the
|
||||||
|
new filename).
|
||||||
|
c - only when auto-completing directory names with <tab> (expand the pattern
|
||||||
|
immediately before doing the auto-completion).
|
||||||
|
<empty> or not defined - always enable.
|
||||||
|
|
||||||
|
Note: the abbrev entries are evaluated in sequence, so a later entry can be
|
||||||
|
evaluated against the expanded result of a previous entry; this includes itself
|
||||||
|
when 'gmode' is "t".
|
||||||
|
|
||||||
*'g:ctrlp_key_loop'*
|
*'g:ctrlp_key_loop'*
|
||||||
An experimental feature. Set this to 1 to enable input looping for the typing
|
An experimental feature. Set this to 1 to enable input looping for the typing
|
||||||
of multi-byte characters: >
|
of multi-byte characters: >
|
||||||
@ -1192,7 +1244,8 @@ Special thanks:~
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
CHANGELOG *ctrlp-changelog*
|
CHANGELOG *ctrlp-changelog*
|
||||||
|
|
||||||
+ New options: |g:ctrlp_key_loop|,
|
+ New options: |g:ctrlp_abbrev|,
|
||||||
|
|g:ctrlp_key_loop|,
|
||||||
|g:ctrlp_open_func|,
|
|g:ctrlp_open_func|,
|
||||||
|g:ctrlp_tabpage_position|
|
|g:ctrlp_tabpage_position|
|
||||||
+ Rename:
|
+ Rename:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user