Rewrite MRU mode
+ Delay saving MRU list to disk. + Remove g:ctrlp_mruf_last_entered and make the setting a default feature.
This commit is contained in:
parent
c4a3c3953e
commit
97f955c89c
@ -12,15 +12,12 @@ fu! ctrlp#mrufiles#opts()
|
|||||||
\ 'g:ctrlp_mruf_exclude': ['s:ex', ''],
|
\ 'g:ctrlp_mruf_exclude': ['s:ex', ''],
|
||||||
\ 'g:ctrlp_mruf_case_sensitive': ['s:csen', 1],
|
\ 'g:ctrlp_mruf_case_sensitive': ['s:csen', 1],
|
||||||
\ 'g:ctrlp_mruf_relative': ['s:re', 0],
|
\ 'g:ctrlp_mruf_relative': ['s:re', 0],
|
||||||
\ 'g:ctrlp_mruf_last_entered': ['s:mre', 0],
|
|
||||||
\ }
|
\ }
|
||||||
for [ke, va] in items(opts)
|
for [ke, va] in items(opts)
|
||||||
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
|
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
|
||||||
endfo
|
endfo
|
||||||
let [s:csen, s:mrbs] = [s:csen ? '#' : '?', []]
|
let [s:csen, s:mrbs, s:mrufs] = [s:csen ? '#' : '?', [], []]
|
||||||
if exists('s:locked')
|
if exists('s:locked') | cal ctrlp#mrufiles#init() | en
|
||||||
cal ctrlp#mrufiles#init()
|
|
||||||
en
|
|
||||||
endf
|
endf
|
||||||
cal ctrlp#mrufiles#opts()
|
cal ctrlp#mrufiles#opts()
|
||||||
" Utilities {{{1
|
" Utilities {{{1
|
||||||
@ -28,6 +25,19 @@ fu! s:excl(fn)
|
|||||||
retu !empty(s:ex) && a:fn =~# s:ex
|
retu !empty(s:ex) && a:fn =~# s:ex
|
||||||
endf
|
endf
|
||||||
|
|
||||||
|
fu! s:mergelists()
|
||||||
|
let diskmrufs = s:readcache()
|
||||||
|
cal filter(diskmrufs, 'index(s:mrufs, v:val) < 0')
|
||||||
|
let mrufs = s:mrufs + diskmrufs
|
||||||
|
if v:version < 702 | cal filter(mrufs, 'count(mrufs, v:val) == 1') | en
|
||||||
|
retu s:chop(mrufs)
|
||||||
|
endf
|
||||||
|
|
||||||
|
fu! s:chop(mrufs)
|
||||||
|
if len(a:mrufs) > s:max | cal remove(a:mrufs, s:max, -1) | en
|
||||||
|
retu a:mrufs
|
||||||
|
endf
|
||||||
|
|
||||||
fu! s:readcache()
|
fu! s:readcache()
|
||||||
if !exists('s:cadir') || !exists('s:cafile')
|
if !exists('s:cadir') || !exists('s:cafile')
|
||||||
let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'
|
let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'
|
||||||
@ -41,10 +51,10 @@ fu! s:reformat(mrufs)
|
|||||||
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
|
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
|
||||||
cal filter(a:mrufs, '!stridx(v:val, cwd)')
|
cal filter(a:mrufs, '!stridx(v:val, cwd)')
|
||||||
en
|
en
|
||||||
retu map(a:mrufs, 'fnamemodify(v:val, '':.'')')
|
retu map(a:mrufs, 'fnamemodify(v:val, ":.")')
|
||||||
endf
|
endf
|
||||||
|
|
||||||
fu! s:record(bufnr, ...)
|
fu! s:record(bufnr)
|
||||||
if s:locked | retu | en
|
if s:locked | retu | en
|
||||||
let bufnr = a:bufnr + 0
|
let bufnr = a:bufnr + 0
|
||||||
if bufnr <= 0 | retu | en
|
if bufnr <= 0 | retu | en
|
||||||
@ -54,71 +64,61 @@ fu! s:record(bufnr, ...)
|
|||||||
cal insert(s:mrbs, fn)
|
cal insert(s:mrbs, fn)
|
||||||
if empty(fn) || !empty(&bt) || ( !empty(s:in) && fn !~# s:in )
|
if empty(fn) || !empty(&bt) || ( !empty(s:in) && fn !~# s:in )
|
||||||
\ || ( !empty(s:ex) && fn =~# s:ex ) || !filereadable(fn)
|
\ || ( !empty(s:ex) && fn =~# s:ex ) || !filereadable(fn)
|
||||||
\ || ( a:0 && a:1 == 1 )
|
|
||||||
retu
|
retu
|
||||||
en
|
en
|
||||||
let mrufs = s:readcache()
|
cal filter(s:mrufs, 'v:val !='.s:csen.' fn')
|
||||||
cal filter(mrufs, 'v:val !='.s:csen.' fn')
|
cal insert(s:mrufs, fn)
|
||||||
cal insert(mrufs, fn)
|
let s:mrufs = s:chop(s:mrufs)
|
||||||
if len(mrufs) > s:max | cal remove(mrufs, s:max, -1) | en
|
endf
|
||||||
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
|
|
||||||
|
fu! s:savetofile(mrufs)
|
||||||
|
cal ctrlp#utils#writecache(a:mrufs, s:cadir, s:cafile)
|
||||||
endf
|
endf
|
||||||
" Public {{{1
|
" Public {{{1
|
||||||
fu! ctrlp#mrufiles#refresh(...)
|
fu! ctrlp#mrufiles#refresh(...)
|
||||||
let mrufs = s:readcache()
|
let s:mrufs = s:mergelists()
|
||||||
cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
|
cal filter(s:mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
|
||||||
if exists('+ssl')
|
if exists('+ssl')
|
||||||
cal map(mrufs, 'tr(v:val, ''/'', ''\'')')
|
cal map(s:mrufs, 'tr(v:val, "/", "\\")')
|
||||||
cal filter(mrufs, 'count(mrufs, v:val) == 1')
|
cal filter(s:mrufs, 'count(s:mrufs, v:val) == 1')
|
||||||
en
|
en
|
||||||
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
|
cal s:savetofile(s:mrufs)
|
||||||
retu a:0 && a:1 == 'raw' ? [] : s:reformat(mrufs)
|
retu a:0 && a:1 == 'raw' ? [] : s:reformat(copy(s:mrufs))
|
||||||
endf
|
endf
|
||||||
|
|
||||||
fu! ctrlp#mrufiles#remove(files)
|
fu! ctrlp#mrufiles#remove(files)
|
||||||
let mrufs = []
|
let s:mrufs = []
|
||||||
if a:files != []
|
if a:files != []
|
||||||
let mrufs = s:readcache()
|
let s:mrufs = s:mergelists()
|
||||||
cal filter(mrufs, 'index(a:files, v:val) < 0')
|
cal filter(s:mrufs, 'index(a:files, v:val) < 0')
|
||||||
en
|
en
|
||||||
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
|
cal s:savetofile(s:mrufs)
|
||||||
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
|
retu s:reformat(copy(s:mrufs))
|
||||||
endf
|
endf
|
||||||
|
|
||||||
fu! ctrlp#mrufiles#list(...)
|
fu! ctrlp#mrufiles#list(...)
|
||||||
if a:0 && a:1 != 'raw' | cal s:record(a:1) | retu | en
|
if a:0 && a:1 != 'raw' | retu | en
|
||||||
retu a:0 && a:1 == 'raw' ? s:readcache() : s:reformat(s:readcache())
|
retu a:0 && a:1 == 'raw' ? s:mergelists() : s:reformat(s:mergelists())
|
||||||
endf
|
endf
|
||||||
|
|
||||||
fu! ctrlp#mrufiles#bufs()
|
fu! ctrlp#mrufiles#bufs()
|
||||||
retu s:mrbs
|
retu s:mrbs
|
||||||
endf
|
endf
|
||||||
|
|
||||||
|
fu! ctrlp#mrufiles#mrufs()
|
||||||
|
retu s:mrufs
|
||||||
|
endf
|
||||||
|
|
||||||
fu! ctrlp#mrufiles#init()
|
fu! ctrlp#mrufiles#init()
|
||||||
if !has('autocmd') | retu | en
|
if !has('autocmd') | retu | en
|
||||||
let s:locked = 0
|
let s:locked = 0
|
||||||
aug CtrlPMRUF
|
aug CtrlPMRUF
|
||||||
au!
|
au!
|
||||||
au BufReadPost,BufNewFile,BufWritePost * cal s:record(expand('<abuf>', 1))
|
au BufAdd,BufEnter,BufUnload * cal s:record(expand('<abuf>', 1))
|
||||||
au QuickFixCmdPre *vimgrep* let s:locked = 1
|
au QuickFixCmdPre *vimgrep* let s:locked = 1
|
||||||
au QuickFixCmdPost *vimgrep* let s:locked = 0
|
au QuickFixCmdPost *vimgrep* let s:locked = 0
|
||||||
|
au VimLeavePre * cal s:savetofile(s:mergelists())
|
||||||
aug END
|
aug END
|
||||||
aug CtrlPMREB
|
|
||||||
au!
|
|
||||||
au BufEnter,BufUnload * cal s:record(expand('<abuf>', 1), 1)
|
|
||||||
aug END
|
|
||||||
if exists('#CtrlPMREF')
|
|
||||||
au! CtrlPMREF
|
|
||||||
en
|
|
||||||
if s:mre
|
|
||||||
aug CtrlPMREF
|
|
||||||
au!
|
|
||||||
au BufEnter,BufUnload * cal s:record(expand('<abuf>', 1))
|
|
||||||
aug END
|
|
||||||
if exists('#CtrlPMREB')
|
|
||||||
au! CtrlPMREB
|
|
||||||
en
|
|
||||||
en
|
|
||||||
endf
|
endf
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
|
@ -213,11 +213,6 @@ MRU entries: >
|
|||||||
let g:ctrlp_mruf_case_sensitive = 1
|
let g:ctrlp_mruf_case_sensitive = 1
|
||||||
<
|
<
|
||||||
|
|
||||||
*'g:ctrlp_mruf_last_entered'*
|
|
||||||
Set to 1 to sort the MRU file list to most-recently-entered-buffer order: >
|
|
||||||
let g:ctrlp_mruf_last_entered = 0
|
|
||||||
<
|
|
||||||
|
|
||||||
*'g:ctrlp_dotfiles'*
|
*'g:ctrlp_dotfiles'*
|
||||||
Set this to 0 if you don’t want CtrlP to scan for dotfiles and dotdirs: >
|
Set this to 0 if you don’t want CtrlP to scan for dotfiles and dotdirs: >
|
||||||
let g:ctrlp_dotfiles = 1
|
let g:ctrlp_dotfiles = 1
|
||||||
@ -909,6 +904,7 @@ Special thanks:~
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
CHANGELOG *ctrlp-changelog*
|
CHANGELOG *ctrlp-changelog*
|
||||||
|
|
||||||
|
+ Remove: g:ctrlp_mruf_last_entered, make it the default for MRU mode.
|
||||||
+ New commands: |:CtrlPLastMode|, open CtrlP in the last mode used.
|
+ New commands: |:CtrlPLastMode|, open CtrlP in the last mode used.
|
||||||
|:CtrlPMixed|, search in both files and MRU files.
|
|:CtrlPMixed|, search in both files and MRU files.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user