]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel.el (counsel-grep-action): Work better from ivy-occur
authorOleh Krehel <ohwoeowho@gmail.com>
Mon, 11 Apr 2016 14:13:17 +0000 (16:13 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Mon, 11 Apr 2016 14:13:17 +0000 (16:13 +0200)
counsel.el

index b5506a070b097753761b524e9d7af48d9894f7c0..4620c1e0f046d2c2e63adb51665f44f54106363f 100644 (file)
@@ -1414,19 +1414,24 @@ the command."
 (defun counsel-grep-action (x)
   (with-ivy-window
     (swiper--cleanup)
-    (when (string-match "\\`\\([0-9]+\\):\\(.*\\)\\'" x)
-      (let ((file-name counsel--git-grep-dir)
-            (line-number (match-string-no-properties 1 x)))
+    (let ((default-directory (file-name-directory counsel--git-grep-dir))
+          file-name line-number)
+      (when (cond ((string-match "\\`\\([0-9]+\\):\\(.*\\)\\'" x)
+                   (setq file-name counsel--git-grep-dir)
+                   (setq line-number (match-string-no-properties 1 x)))
+                  ((string-match "\\`\\([^:]+\\):\\([0-9]+\\):\\(.*\\)\\'" x)
+                   (setq file-name (match-string-no-properties 1 x))
+                   (setq line-number (match-string-no-properties 2 x)))
+                  (t nil))
         (find-file file-name)
         (goto-char (point-min))
         (forward-line (1- (string-to-number line-number)))
         (re-search-forward (ivy--regex ivy-text t) (line-end-position) t)
         (if (eq ivy-exit 'done)
             (swiper--ensure-visible)
-          (unless (eq ivy-exit 'done)
-            (isearch-range-invisible (line-beginning-position)
-                                     (line-end-position))
-            (swiper--add-overlays (ivy--regex ivy-text))))))))
+          (isearch-range-invisible (line-beginning-position)
+                                   (line-end-position))
+          (swiper--add-overlays (ivy--regex ivy-text)))))))
 
 (defun counsel-grep-occur ()
   "Generate a custom occur buffer for `counsel-grep'."