[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 8f08f38 155/184: counsel.el (counsel--grep-last-pos): Refa

From: Oleh Krehel
Subject: [elpa] master 8f08f38 155/184: counsel.el (counsel--grep-last-pos): Refactor from counsel-grep-last-line
Date: Wed, 16 Oct 2019 13:15:13 -0400 (EDT)

branch: master
commit 8f08f38990ebaa8af945237264ce0e19150282e7
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel--grep-last-pos): Refactor from counsel-grep-last-line
    It's only used in `counsel-grep-action' now, instead of 2 other places.
 counsel.el | 16 +++++++++-------
 ivy.el     |  2 --
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/counsel.el b/counsel.el
index 1b7dc5b..28575a0 100644
--- a/counsel.el
+++ b/counsel.el
@@ -215,8 +215,6 @@ respectively."
     (set-process-filter proc (or filter #'counsel--async-filter))
-(defvar counsel-grep-last-line nil)
 (defun counsel--split-string (&optional str)
    (or str (buffer-string))
@@ -232,7 +230,6 @@ respectively."
             (with-current-buffer (process-buffer process)
-          (setq counsel-grep-last-line nil)
           (when counsel--async-start
             (setq counsel--async-duration
                   (time-to-seconds (time-since counsel--async-start))))
@@ -3017,6 +3014,12 @@ substituted by the search regexp and file, respectively. 
       (format counsel-grep-command (shell-quote-argument regex)))
+(defvar counsel--grep-last-pos nil
+  "Store the last point and line that `counsel-grep-action' scrolled to.
+This speeds up scrolling: instead of going to `point-min' and
+`forward-line' with a huge arg (e.g. to scroll 50K lines), scroll
+relative to the last position stored here.")
 (defun counsel-grep-action (x)
   "Go to candidate X."
@@ -3037,11 +3040,11 @@ substituted by the search regexp and file, 
respectively.  Neither
         (with-current-buffer (or (get-file-buffer file-name)
                                  (find-file file-name))
           (setq line-number (string-to-number line-number))
-          (if counsel-grep-last-line
-              (forward-line (- line-number counsel-grep-last-line))
+          (if (and counsel--grep-last-pos (= (point) (car 
+              (forward-line (- line-number (cdr counsel--grep-last-pos)))
             (goto-char (point-min))
             (forward-line (1- line-number)))
-          (setq counsel-grep-last-line line-number)
+          (setq counsel--grep-last-pos (cons (point) line-number))
           (when (re-search-forward (ivy--regex ivy-text t) (line-end-position) 
             (when swiper-goto-start-of-match
               (goto-char (match-beginning 0))))
@@ -3075,7 +3078,6 @@ When non-nil, INITIAL-INPUT is the initial search 
   (unless buffer-file-name
     (user-error "Current buffer is not visiting a file"))
   (counsel-require-program counsel-grep-base-command)
-  (setq counsel-grep-last-line nil)
   (setq counsel-grep-command
         (format counsel-grep-base-command
                 "%s" (shell-quote-argument
diff --git a/ivy.el b/ivy.el
index b78c001..1c44f22 100644
--- a/ivy.el
+++ b/ivy.el
@@ -4877,7 +4877,6 @@ EVENT gives the mouse position."
 (declare-function swiper--cleanup "swiper")
 (declare-function swiper--add-overlays "swiper")
 (defvar ivy-occur-timer nil)
-(defvar counsel-grep-last-line)
 (defun ivy--occur-press-update-window ()
   (cl-case (ivy-state-caller ivy-occur-last)
@@ -4922,7 +4921,6 @@ EVENT gives the mouse position."
            (action (ivy--get-action ivy-last))
            (ivy-exit 'done))
-        (setq counsel-grep-last-line nil)
         (with-current-buffer (ivy--occur-press-buffer)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]