]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel.el (counsel-git): Fix window selection
authorOleh Krehel <ohwoeowho@gmail.com>
Tue, 5 Jan 2016 10:39:15 +0000 (11:39 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Tue, 5 Jan 2016 10:39:15 +0000 (11:39 +0100)
* 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

index 062d95c07ee6df70b65ba3f43f28bbdf34a5e902..69b43a78069166bab5094abde9c63dcb6c73bdd9 100644 (file)
       #'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.")