Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctrlp cache uses getcwd() as basename, with autochdir this causes reindexing for files in the same project with different directory #605

Open
char101 opened this issue May 11, 2022 · 1 comment

Comments

@char101
Copy link

char101 commented May 11, 2022

Hi,

ctrlp#utils#cachefile by default uses getcwd() as the cache filename. And it is called in https://github.com/ctrlpvim/ctrlp.vim/blob/master/autoload/ctrlp.vim#L381 without any parameter.

When autochdir is set, opening ctrlp with files in the same project root but that belongs to different directory causes reindexing to occur.

Can't the cache file uses to project root as base filename instead?

@char101
Copy link
Author

char101 commented May 11, 2022

What works for me

diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim
index d4445c8..0b074d4 100644
--- a/autoload/ctrlp.vim
+++ b/autoload/ctrlp.vim
@@ -379,7 +379,7 @@ fu! s:Reset(args)
 endf
 " * Files {{{1
 fu! ctrlp#files()
-       let cafile = ctrlp#utils#cachefile()
+       let cafile = ctrlp#utils#cachefile(s:dyncwd, 1)
        if g:ctrlp_newcache || !filereadable(cafile) || s:nocache(cafile)
                let [lscmd, s:initcwd, g:ctrlp_allfiles] = [s:lsCmd(), s:dyncwd, []]
                " Get the list of files
@@ -2637,7 +2637,7 @@ endf
 " Cache {{{2
 fu! s:writecache(cafile)
        if ( g:ctrlp_newcache || !filereadable(a:cafile) ) && !s:nocache()
-               cal ctrlp#utils#writecache(g:ctrlp_allfiles)
+               cal ctrlp#utils#writecache(g:ctrlp_allfiles, ctrlp#utils#cachedir(), a:cafile)
                let g:ctrlp_newcache = 0
        en
 endf
@@ -2670,7 +2670,7 @@ fu! s:insertcache(str)
                endfo
        en
        cal insert(data, str, pos)
-       cal s:writecache(ctrlp#utils#cachefile())
+       cal s:writecache(ctrlp#utils#cachefile(s:dyncwd, 1))
 endf
 " Extensions {{{2
 fu! s:mtype()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant