Allow deleting MRU entries marked by <c-z> with <F7>

Close #122
This commit is contained in:
Kien N 2012-02-20 14:58:03 +07:00
parent 93cb20dbfb
commit ea0eef6d44
5 changed files with 55 additions and 52 deletions

View File

@ -366,6 +366,7 @@ fu! s:Render(lines, pat)
" Print the new items " Print the new items
if empty(lines) if empty(lines)
setl nocul setl nocul
let s:matched = []
cal setline(1, ' == NO ENTRIES ==') cal setline(1, ' == NO ENTRIES ==')
cal s:unmarksigns() cal s:unmarksigns()
if s:dohighlight() | cal clearmatches() | en if s:dohighlight() | cal clearmatches() | en
@ -459,8 +460,7 @@ endf
fu! s:PrtBS() fu! s:PrtBS()
unl! s:hstgot unl! s:hstgot
let [prt, s:matches] = [s:prompt, 1] let [s:prompt[0], s:matches] = [substitute(s:prompt[0], '.$', '', ''), 1]
let prt[0] = substitute(prt[0], '.$', '', '')
cal s:BuildPrompt(1) cal s:BuildPrompt(1)
endf endf
@ -485,7 +485,6 @@ endf
fu! s:PrtInsert(type) fu! s:PrtInsert(type)
unl! s:hstgot unl! s:hstgot
" Insert current word, search register, last visual and clipboard
let s:prompt[0] .= a:type == 'w' ? s:crword let s:prompt[0] .= a:type == 'w' ? s:crword
\ : a:type == 's' ? getreg('/') \ : a:type == 's' ? getreg('/')
\ : a:type == 'v' ? s:crvisual \ : a:type == 'v' ? s:crvisual
@ -507,20 +506,18 @@ fu! s:PrtExpandDir()
endf endf
" Movement {{{2 " Movement {{{2
fu! s:PrtCurLeft() fu! s:PrtCurLeft()
if !empty(s:prompt[0]) let prt = s:prompt
let prt = s:prompt if !empty(prt[0])
let prt[2] = prt[1] . prt[2] let s:prompt = [substitute(prt[0], '.$', '', ''), matchstr(prt[0], '.$'),
let prt[1] = matchstr(prt[0], '.$') \ prt[1] . prt[2]]
let prt[0] = substitute(prt[0], '.$', '', '')
en en
cal s:BuildPrompt(0) cal s:BuildPrompt(0)
endf endf
fu! s:PrtCurRight() fu! s:PrtCurRight()
let prt = s:prompt let prt = s:prompt
let prt[0] .= prt[1] let s:prompt = [prt[0] . prt[1], matchstr(prt[2], '^.'),
let prt[1] = matchstr(prt[2], '^.') \ substitute(prt[2], '^.', '', '')]
let prt[2] = substitute(prt[2], '^.', '', '')
cal s:BuildPrompt(0) cal s:BuildPrompt(0)
endf endf
@ -585,12 +582,16 @@ fu! s:PrtClearCache()
endf endf
fu! s:PrtDeleteMRU() fu! s:PrtDeleteMRU()
if s:itemtype == 2 if s:itemtype != 2 | retu | en
let s:force = 1 let [s:force, ags] = [1, [-1, 2]]
let g:ctrlp_lines = ctrlp#mrufiles#list(-1, 2) if exists('s:marked')
cal s:BuildPrompt(1) let ags = [-1, 2, values(s:marked)]
unl s:force cal s:unmarksigns()
unl s:marked
en en
let g:ctrlp_lines = call('ctrlp#mrufiles#list', ags)
cal s:BuildPrompt(1)
unl s:force
endf endf
fu! s:PrtExit() fu! s:PrtExit()
@ -617,8 +618,8 @@ fu! s:MapKeys(...)
" Normal keys " Normal keys
let pfunc = a:0 && !a:1 ? 'PrtSelectJump' : 'PrtAdd' let pfunc = a:0 && !a:1 ? 'PrtSelectJump' : 'PrtAdd'
let dojmp = s:byfname && pfunc == 'PrtSelectJump' ? ', 1' : '' let dojmp = s:byfname && pfunc == 'PrtSelectJump' ? ', 1' : ''
let cmd = "nn \<buffer> \<silent> \<char-%d> :\<c-u>cal \<SID>%s(\"%s\"%s)\<cr>"
for each in range(32, 126) for each in range(32, 126)
let cmd = "nn \<buffer> \<silent> \<char-%d> :\<c-u>cal \<SID>%s(\"%s\"%s)\<cr>"
exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'), dojmp) exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'), dojmp)
endfo endfo
" Special keys " Special keys
@ -773,17 +774,17 @@ fu! s:AcceptSelection(mode)
let str = join(s:prompt, '') let str = join(s:prompt, '')
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 = getline('.') let line = exists('s:matched') && !empty(s:matched)
if a:mode != 'e' && s:itemtype < 3 && line == ' == NO ENTRIES ==' \ ? s:matched[line('.') - 1] : ''
if a:mode != 'e' && s:itemtype < 3 && line == ''
\ && str !~ '\v^(\.\.|/|\\|\?)$' \ && str !~ '\v^(\.\.|/|\\|\?)$'
cal s:CreateNewFile(a:mode) | retu cal s:CreateNewFile(a:mode) | retu
en en
let matchstr = matchstr(line, '^> \zs.\+\ze\t*$') if empty(line) | retu | en
if empty(matchstr) | retu | en
" Do something with it " Do something with it
let actfunc = s:itemtype < 3 ? 'ctrlp#acceptfile' let actfunc = s:itemtype < 3 ? 'ctrlp#acceptfile'
\ : g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )]['accept'] \ : g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )]['accept']
cal call(actfunc, [a:mode, matchstr]) cal call(actfunc, [a:mode, line])
endf endf
fu! s:CreateNewFile(...) "{{{1 fu! s:CreateNewFile(...) "{{{1
let [md, str] = ['', join(s:prompt, '')] let [md, str] = ['', join(s:prompt, '')]
@ -807,7 +808,7 @@ fu! s:CreateNewFile(...) "{{{1
en en
if !exists('optyp') | retu | en if !exists('optyp') | retu | en
let [filpath, tail] = [fnamemodify(optyp, ':p'), s:tail()] let [filpath, tail] = [fnamemodify(optyp, ':p'), s:tail()]
cal s:insertcache(str) if !stridx(filpath, getcwd()) | cal s:insertcache(str) | en
cal s:PrtExit() cal s:PrtExit()
let cmd = md == 'r' ? ctrlp#normcmd('e') : let cmd = md == 'r' ? ctrlp#normcmd('e') :
\ s:newfop =~ '1\|t' || ( a:0 && a:1 == 't' ) || md == 't' ? 'tabe' : \ s:newfop =~ '1\|t' || ( a:0 && a:1 == 't' ) || md == 't' ? 'tabe' :
@ -973,7 +974,7 @@ fu! ctrlp#statusline()
let focus = s:Focus() ? 'prt' : 'win' let focus = s:Focus() ? 'prt' : 'win'
let byfname = s:byfname ? 'file' : 'path' let byfname = s:byfname ? 'file' : 'path'
let marked = s:opmul != '0' ? let marked = s:opmul != '0' ?
\ exists('s:marked') ? ' <'.s:dismrk().'>' : ' <+>' : '' \ exists('s:marked') ? ' <'.s:dismrk().'>' : ' <>' : ''
if has_key(s:status, 'main') if has_key(s:status, 'main')
let args = [focus, byfname, s:regexp, prv, item, nxt, marked] let args = [focus, byfname, s:regexp, prv, item, nxt, marked]
let &l:stl = call(s:status['main'], args) let &l:stl = call(s:status['main'], args)
@ -989,7 +990,7 @@ fu! ctrlp#statusline()
endf endf
fu! s:dismrk() fu! s:dismrk()
retu has('signs') ? '+'.len(s:marked) : retu has('signs') ? len(s:marked) :
\ '%<'.join(values(map(copy(s:marked), 'split(v:val, "[\\/]")[-1]')), ', ') \ '%<'.join(values(map(copy(s:marked), 'split(v:val, "[\\/]")[-1]')), ', ')
endf endf
@ -1274,8 +1275,7 @@ fu! s:setupblank()
endf endf
fu! s:leavepre() fu! s:leavepre()
if s:clrex && ( !has('clientserver') || if s:clrex && !( has('clientserver') && len(split(serverlist(), "\n")) > 1 )
\ ( has('clientserver') && len(split(serverlist(), "\n")) == 1 ) )
cal ctrlp#clra() cal ctrlp#clra()
en en
endf endf
@ -1321,17 +1321,21 @@ fu! s:argmaps(md, ...)
endf endf
" Misc {{{2 " Misc {{{2
fu! s:getenv() fu! s:getenv()
let s:winh = min([s:mxheight, &lines])
let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]] let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]]
let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)] let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
let [s:crword, s:crline] = [expand('<cword>'), getline('.')] let [s:crword, s:crline] = [expand('<cword>'), getline('.')]
let [s:tagfiles, s:crcursor] = [s:tagfiles(), getpos('.')] let [s:winh, s:crcursor] = [min([s:mxheight, &lines]), getpos('.')]
let [s:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()] let [s:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()]
if exists('g:ctrlp_extensions') && index(g:ctrlp_extensions, 'undo') >= 0
\ && v:version > 702 && has('patch005') && exists('*undotree')
let s:undotree = undotree()
en
let s:currwin = s:mwbottom ? winnr() : winnr() + has('autocmd') let s:currwin = s:mwbottom ? winnr() : winnr() + has('autocmd')
if exists('g:ctrlp_extensions')
if index(g:ctrlp_extensions, 'undo') >= 0
\ && v:version > 702 && has('patch005') && exists('*undotree')
let s:undotree = undotree()
en
if index(g:ctrlp_extensions, 'tag') >= 0
let s:tagfiles = s:tagfiles()
en
en
endf endf
fu! s:lastvisual() fu! s:lastvisual()

View File

@ -36,8 +36,13 @@ fu! ctrlp#mrufiles#list(bufnr, ...) "{{{1
let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt' let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt'
en en
if a:0 && a:1 == 2 if a:0 && a:1 == 2
cal ctrlp#utils#writecache([], s:cadir, s:cafile) let mrufs = []
retu [] if a:0 == 2
let mrufs = ctrlp#utils#readfile(s:cafile)
cal filter(mrufs, 'index(a:2, v:val) < 0')
en
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
en en
" Get the list " Get the list
let mrufs = ctrlp#utils#readfile(s:cafile) let mrufs = ctrlp#utils#readfile(s:cafile)
@ -59,8 +64,7 @@ fu! ctrlp#mrufiles#list(bufnr, ...) "{{{1
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd() let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
cal filter(mrufs, '!stridx(v:val, cwd)') cal filter(mrufs, '!stridx(v:val, cwd)')
en en
cal map(mrufs, 'fnamemodify(v:val, '':.'')') retu map(mrufs, 'fnamemodify(v:val, '':.'')')
retu mrufs
en en
" Remove old entry " Remove old entry
cal filter(mrufs, 'v:val !='.s:csen.' fn') cal filter(mrufs, 'v:val !='.s:csen.' fn')

View File

@ -23,14 +23,6 @@ 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) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1 " Utilities {{{1
fu! s:nodup(items)
let dict = {}
for each in a:items
cal extend(dict, { each : 0 })
endfo
retu keys(dict)
endf
fu! s:findcount(str) fu! s:findcount(str)
let [tg, fname] = split(a:str, '\t\+\ze[^\t]\+$') let [tg, fname] = split(a:str, '\t\+\ze[^\t]\+$')
let [fname, tgs] = [expand(fname, 1), taglist('^'.tg.'$')] let [fname, tgs] = [expand(fname, 1), taglist('^'.tg.'$')]
@ -67,7 +59,8 @@ endf
" Public {{{1 " Public {{{1
fu! ctrlp#tag#init(tagfiles) fu! ctrlp#tag#init(tagfiles)
if empty(a:tagfiles) | retu [] | en if empty(a:tagfiles) | retu [] | en
let [tagfiles, g:ctrlp_alltags] = [sort(s:nodup(a:tagfiles)), []] let g:ctrlp_alltags = []
let tagfiles = sort(filter(a:tagfiles, 'count(a:tagfiles, v:val) == 1'))
for each in tagfiles for each in tagfiles
let alltags = s:filter(ctrlp#utils#readfile(each)) let alltags = s:filter(ctrlp#utils#readfile(each))
cal extend(g:ctrlp_alltags, alltags) cal extend(g:ctrlp_alltags, alltags)
@ -82,15 +75,14 @@ endf
fu! ctrlp#tag#accept(mode, str) fu! ctrlp#tag#accept(mode, str)
cal ctrlp#exit() cal ctrlp#exit()
let str = matchstr(a:str, '^[^\t]\+\t\+[^\t]\+\ze\t') let str = matchstr(a:str, '^[^\t]\+\t\+[^\t]\+\ze\t')
let [md, tg] = [a:mode, split(str, '^[^\t]\+\zs\t')[0]] let [tg, fnd] = [split(str, '^[^\t]\+\zs\t')[0], s:findcount(str)]
let fnd = s:findcount(str)
let cmds = { let cmds = {
\ 't': ['tab sp', 'tab stj'], \ 't': ['tab sp', 'tab stj'],
\ 'h': ['sp', 'stj'], \ 'h': ['sp', 'stj'],
\ 'v': ['vs', 'vert stj'], \ 'v': ['vs', 'vert stj'],
\ 'e': ['', 'tj'], \ 'e': ['', 'tj'],
\ } \ }
let cmd = fnd[0] == 1 ? cmds[md][0] : cmds[md][1] let cmd = fnd[0] == 1 ? cmds[a:mode][0] : cmds[a:mode][1]
let cmd = cmd == 'tj' && &modified ? 'hid '.cmd : cmd let cmd = cmd == 'tj' && &modified ? 'hid '.cmd : cmd
let cmd = cmd =~ '^tab' ? tabpagenr('$').cmd : cmd let cmd = cmd =~ '^tab' ? tabpagenr('$').cmd : cmd
if fnd[0] == 1 if fnd[0] == 1

View File

@ -102,7 +102,9 @@ endf
fu! ctrlp#undo#init(undo) fu! ctrlp#undo#init(undo)
let entries = a:undo['entries'] let entries = a:undo['entries']
if empty(entries) | retu [] | en if empty(entries) | retu [] | en
cal s:syntax() if has('syntax') && exists('g:syntax_on')
cal s:syntax()
en
let g:ctrlp_nolimit = 1 let g:ctrlp_nolimit = 1
let entries = sort(s:dict2list(s:flatten(entries)), 's:compval') let entries = sort(s:dict2list(s:flatten(entries)), 's:compval')
retu map(entries, 'v:val[1]." [".v:val[0]."]"') retu map(entries, 'v:val[1]." [".v:val[0]."]"')

View File

@ -96,7 +96,6 @@ variable: >
.hg/ .hg/
.bzr/ .bzr/
_darcs/ _darcs/
root.dir
0 - dont manage working directory. 0 - dont manage working directory.
*'g:ctrlp_root_markers'* *'g:ctrlp_root_markers'*
@ -543,7 +542,8 @@ Once inside the prompt:~
- Remove deleted files from MRU list. - Remove deleted files from MRU list.
<F7> <F7>
Clear MRU list. - Wipe MRU list.
- Delete MRU entries marked by <c-z>.
<insert> <insert>
Insert the word under the cursor (in the active buffer) into the prompt. Insert the word under the cursor (in the active buffer) into the prompt.
@ -762,6 +762,7 @@ Special thanks:~
CHANGELOG *ctrlp-changelog* CHANGELOG *ctrlp-changelog*
+ New option: |g:ctrlp_mruf_last_entered| change MRU to recently-entered. + New option: |g:ctrlp_mruf_last_entered| change MRU to recently-entered.
+ Extend |g:ctrlp_user_command| to support multiple commands.
Before 2012/01/15~ Before 2012/01/15~