]> code.delx.au - gnu-emacs-elpa/commitdiff
Use forward-line instead of line-move if possible
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 2 Oct 2015 13:33:07 +0000 (15:33 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 2 Oct 2015 13:33:07 +0000 (15:33 +0200)
* swiper.el (swiper--candidates):
(swiper--update-input-ivy):
(swiper--action): `line-move' is much slower than `forward-line'. Use it
only if `visual-line-mode' is on.

swiper.el

index cfc80cd0c6c64b6e119bb06b7113042c9082d994..9e70265f8618d940c657c5c20e2f8ab7872fc534 100644 (file)
--- a/swiper.el
+++ b/swiper.el
       (setq swiper--format-spec
             (format "%%-%dd " swiper--width))
       (let ((line-number 0)
+            (advancer (if visual-line-mode
+                          #'line-move
+                        #'forward-line))
             candidates)
         (save-excursion
           (goto-char (point-min))
                                          (cl-incf line-number))
                                  str)
               (push str candidates))
-            (line-move 1))
+            (funcall advancer 1))
           (nreverse candidates))))))
 
 (defvar swiper--opoint 1
@@ -322,7 +325,9 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
         (goto-char (point-min))
         (when (cl-plusp num)
           (goto-char (point-min))
-          (line-move (1- num))
+          (if visual-line-mode
+              (line-move (1- num))
+            (forward-line (1- num)))
           (if (and (equal ivy-text "")
                    (>= swiper--opoint (line-beginning-position))
                    (<= swiper--opoint (line-end-position)))
@@ -389,7 +394,10 @@ BEG and END, when specified, are the point bounds."
   (if (null x)
       (user-error "No candidates")
     (goto-char (point-min))
-    (line-move (1- (read (get-text-property 0 'display x))))
+    (funcall (if visual-line-mode
+                 #'line-move
+               #'forward-line)
+             (1- (read (get-text-property 0 'display x))))
     (re-search-forward
      (ivy--regex input) (line-end-position) t)
     (swiper--ensure-visible)