fix root in cp-find-file / cp-switch-to-buffer

For some reason, when one of these two functions was used as an action
in cp-switch-project, its actions were losing track of the project root
against which to expand filenames (they were using the root of the root
of the project from which cp-switch-project was called instead of the
root of the selected project to switch to). To fix this issue, the correct root is now recorded in the candidate
files / buffers.
This commit is contained in:
Eric Danan 2016-09-26 14:47:55 +02:00
parent b157a8d12c
commit e5f2f20a16

View file

@ -71,9 +71,12 @@ With a prefix ARG invalidates the cache first."
(interactive "P")
(projectile-maybe-invalidate-cache arg)
(ivy-read (projectile-prepend-project-name "Find file: ")
(projectile-current-project-files)
(let ((root (projectile-project-root)))
(mapcar (lambda (name)
(cons name (expand-file-name name root)))
(projectile-current-project-files)))
:action (lambda (x)
(find-file (projectile-expand-root x)))
(find-file (cdr x)))
:require-match t
:keymap counsel-projectile-map
:caller 'counsel-projectile-find-file)
@ -82,7 +85,7 @@ With a prefix ARG invalidates the cache first."
(ivy-set-actions
'counsel-projectile-find-file
'(("j" (lambda (x)
(find-file-other-window (projectile-expand-root x)))
(find-file-other-window (cdr x)))
"other window")))
;;; counsel-projectile-find-dir
@ -95,11 +98,14 @@ With a prefix ARG invalidates the cache first."
(interactive "P")
(projectile-maybe-invalidate-cache arg)
(ivy-read (projectile-prepend-project-name "Find dir: ")
(if projectile-find-dir-includes-top-level
(append '("./") (projectile-current-project-dirs))
(projectile-current-project-dirs))
(let ((root (projectile-project-root)))
(mapcar (lambda (name)
(cons name (expand-file-name name root)))
(if projectile-find-dir-includes-top-level
(append '("./") (projectile-current-project-dirs))
(projectile-current-project-dirs))))
:action (lambda (x)
(dired (projectile-expand-root x)))
(dired (cdr x)))
:require-match t
:keymap counsel-projectile-map
:caller 'counsel-projectile-find-dir)
@ -108,7 +114,7 @@ With a prefix ARG invalidates the cache first."
(ivy-set-actions
'counsel-projectile-find-dir
'(("j" (lambda (x)
(dired-other-window (projectile-expand-root x)))
(dired-other-window (cdr x)))
"other window")))
;;; counsel-projectile-switch-to-buffer