* counsel.el (counsel-grep-last-line): New defvar.
(counsel-grep): Set `counsel-grep-last-line' to nil.
(counsel-grep-action): 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 in `counsel-grep-last-line'.
This change resulted in a much smoother scrolling in a 50K line file
with 22K matches.
(format counsel-grep-base-command regex counsel--git-grep-dir))
nil)))
(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)
(defun counsel-grep-action (x)
(with-ivy-window
(swiper--cleanup)
(setq line-number (match-string-no-properties 2 x)))
(t nil))
(find-file file-name)
(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)
(re-search-forward (ivy--regex ivy-text t) (line-end-position) t)
(if (eq ivy-exit 'done)
(swiper--ensure-visible)
(defun counsel-grep ()
"Grep for a string in the current file."
(interactive)
(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)
(setq counsel--git-grep-dir (buffer-file-name))
(let ((init-point (point))
res)