]> code.delx.au - gnu-emacs-elpa/blobdiff - counsel.el
Fix counsel-grep-last-line bug
[gnu-emacs-elpa] / counsel.el
index 4620c1e0f046d2c2e63adb51665f44f54106363f..e23e354a23b428c932d946a4e6da3452b1b1aba8 100644 (file)
@@ -141,6 +141,7 @@ Or the time of the last minibuffer update.")
            (ivy--set-candidates
             (ivy--sort-maybe
              cands))
+           (setq counsel-grep-last-line nil)
            (setq counsel--async-duration
                  (time-to-seconds (time-since counsel--async-start)))
            (let ((re (funcall ivy--regex-function ivy-text)))
@@ -1411,6 +1412,8 @@ the command."
        (format counsel-grep-base-command regex counsel--git-grep-dir))
       nil)))
 
+(defvar counsel-grep-last-line nil)
+
 (defun counsel-grep-action (x)
   (with-ivy-window
     (swiper--cleanup)
@@ -1424,8 +1427,13 @@ the command."
                    (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)))
+        (setq line-number (string-to-number line-number))
+        (if (null counsel-grep-last-line)
+            (progn
+              (goto-char (point-min))
+              (forward-line (1- (setq counsel-grep-last-line line-number))))
+          (forward-line (- line-number counsel-grep-last-line))
+          (setq counsel-grep-last-line line-number))
         (re-search-forward (ivy--regex ivy-text t) (line-end-position) t)
         (if (eq ivy-exit 'done)
             (swiper--ensure-visible)
@@ -1465,6 +1473,7 @@ the command."
 (defun counsel-grep ()
   "Grep for a string in the current file."
   (interactive)
+  (setq counsel-grep-last-line nil)
   (setq counsel--git-grep-dir (buffer-file-name))
   (let ((init-point (point))
         res)
@@ -1896,6 +1905,34 @@ And insert it into the minibuffer. Useful during
     (ivy-read "Expr: " (delete-dups read-expression-history)
               :action #'insert)))
 
+;;** `counsel-esh-history'
+(defun counsel--browse-history (elements)
+  "Use Ivy to navigate through ELEMENTS."
+  (setq ivy-completion-beg (point))
+  (setq ivy-completion-end (point))
+  (ivy-read "Symbol name: "
+            (delete-dups
+             (ring-elements elements))
+            :action #'ivy-completion-in-region-action))
+
+(defvar eshell-history-ring)
+
+;;;###autoload
+(defun counsel-esh-history ()
+  "Browse Eshell history."
+  (interactive)
+  (require 'em-hist)
+  (counsel--browse-history eshell-history-ring))
+
+(defvar comint-input-ring)
+
+;;;###autoload
+(defun counsel-shell-history ()
+  "Browse shell history."
+  (interactive)
+  (require 'comint)
+  (counsel--browse-history comint-input-ring))
+
 ;;* Misc OS
 ;;** `counsel-rhythmbox'
 (defvar helm-rhythmbox-library)