Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Further reduce MRU saving

Only save once when a new entry is added.
  • Loading branch information...
commit f1acbbc503f44fc6d9c057fa593733e4f074da5d 1 parent f9ada48
kien authored
Showing with 25 additions and 14 deletions.
  1. +25 −14 autoload/ctrlp/mrufiles.vim
39 autoload/ctrlp/mrufiles.vim
View
@@ -43,7 +43,13 @@ fu! s:reformat(mrufs)
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
cal filter(a:mrufs, '!stridx(v:val, cwd)')
en
- retu map(a:mrufs, 'fnamemodify(v:val, ":.")')
+ let cwd = getcwd()
+ let idx = strlen(cwd) + ( cwd !~ '[\/]$' )
+ if exists('+ssl') && &ssl
+ let cwd = tr(cwd, '\', '/')
+ cal map(a:mrufs, 'tr(v:val, "\\", "/")')
+ en
+ retu map(a:mrufs, '!stridx(v:val, cwd) ? strpart(v:val, idx) : v:val')
Karl Yngve Lervåg
lervag added a note

The change from

retu map(a:mrufs, 'fnamemodify(v:val, ":.")')

to

retu map(a:mrufs, '!stridx(v:val, cwd) ? strpart(v:val, idx) : v:val')

breaks ctrlp for me. I have an additional directory /home/user-dropbox/Dropbox (I find it a convenient way to hide the Dropbox folder), but the new update strips /home/user- if I use ctrlp when pwd is /home/user/....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
endf
fu! s:record(bufnr)
@@ -63,11 +69,11 @@ fu! s:addtomrufs(fname)
if ( !empty({s:in}) && fn !~# {s:in} ) || ( !empty({s:ex}) && fn =~# {s:ex} )
\ || !empty(getbufvar('^'.fn.'$', '&bt')) || !filereadable(fn) | retu
en
- if ( {s:cseno} && get(s:mrufs, 0, '') !=# fn )
- \ || ( !{s:cseno} && get(s:mrufs, 0, '') !=? fn )
+ let idx = index(s:mrufs, fn, 0, !{s:cseno})
+ if idx
cal filter(s:mrufs, 'v:val !='.( {s:cseno} ? '#' : '?' ).' fn')
cal insert(s:mrufs, fn)
- if {s:soup}
+ if {s:soup} && idx < 0
cal s:savetofile(s:mergelists())
en
en
@@ -78,24 +84,29 @@ fu! s:savetofile(mrufs)
endf
" Public {{{1
fu! ctrlp#mrufiles#refresh(...)
- let s:mrufs = s:mergelists()
- cal filter(s:mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
+ let mrufs = s:mergelists()
+ cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
if exists('+ssl')
+ cal map(mrufs, 'tr(v:val, "/", "\\")')
cal map(s:mrufs, 'tr(v:val, "/", "\\")')
- cal filter(s:mrufs, 'count(s:mrufs, v:val) == 1')
+ let cond = 'count(mrufs, v:val, !{s:cseno}) == 1'
+ cal filter(mrufs, cond)
+ cal filter(s:mrufs, cond)
en
- cal s:savetofile(s:mrufs)
- retu a:0 && a:1 == 'raw' ? [] : s:reformat(copy(s:mrufs))
+ cal s:savetofile(mrufs)
+ retu a:0 && a:1 == 'raw' ? [] : s:reformat(mrufs)
endf
fu! ctrlp#mrufiles#remove(files)
- let s:mrufs = []
+ let mrufs = []
if a:files != []
- let s:mrufs = s:mergelists()
- cal filter(s:mrufs, 'index(a:files, v:val, 0, '.(!{s:cseno}).') < 0')
+ let mrufs = s:mergelists()
+ let cond = 'index(a:files, v:val, 0, !{s:cseno}) < 0'
+ cal filter(mrufs, cond)
+ cal filter(s:mrufs, cond)
en
- cal s:savetofile(s:mrufs)
- retu s:reformat(copy(s:mrufs))
+ cal s:savetofile(mrufs)
+ retu s:reformat(mrufs)
endf
fu! ctrlp#mrufiles#add(fn)
Karl Yngve Lervåg

The change from

retu map(a:mrufs, 'fnamemodify(v:val, ":.")')

to

retu map(a:mrufs, '!stridx(v:val, cwd) ? strpart(v:val, idx) : v:val')

breaks ctrlp for me. I have an additional directory /home/user-dropbox/Dropbox (I find it a convenient way to hide the Dropbox folder), but the new update strips /home/user- if I use ctrlp when pwd is /home/user/....

Please sign in to comment.
Something went wrong with that request. Please try again.