branch: master commit fd27465819b085290ca172cc3ac11401dd082d80 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
counsel.el (counsel-git): Fix window selection * counsel.el (counsel--git-dir): New defvar. (counsel-git): Update. (counsel-git-action): New defun. Use `with-ivy-window', so that each new file chosen with e.g. "C-M-n" is selected in the same window. --- counsel.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/counsel.el b/counsel.el index 062d95c..69b43a7 100644 --- a/counsel.el +++ b/counsel.el @@ -331,22 +331,29 @@ #'cl-caddr (cider-sync-request:complete str ":same"))))) +(defvar counsel--git-dir nil + "Store the base git directory.") + ;;;###autoload (defun counsel-git () "Find file in the current Git repository." (interactive) - (let* ((default-directory (locate-dominating-file - default-directory ".git")) + (setq counsel--git-dir (expand-file-name + (locate-dominating-file + default-directory ".git"))) + (let* ((default-directory counsel--git-dir) (cands (split-string (shell-command-to-string "git ls-files --full-name --") "\n" - t)) - (action `(lambda (x) - (let ((default-directory ,default-directory)) - (find-file x))))) + t))) (ivy-read "Find file: " cands - :action action))) + :action #'counsel-git-action))) + +(defun counsel-git-action (x) + (with-ivy-window + (let ((default-directory counsel--git-dir)) + (find-file x)))) (defvar counsel--git-grep-dir nil "Store the base git directory.")