From e5f2f20a167941d212b98b95a52c776c42704baf Mon Sep 17 00:00:00 2001 From: Eric Danan Date: Mon, 26 Sep 2016 14:47:55 +0200 Subject: [PATCH] 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. --- counsel-projectile.el | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/counsel-projectile.el b/counsel-projectile.el index 570bd2d..ab4b812 100644 --- a/counsel-projectile.el +++ b/counsel-projectile.el @@ -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