]> code.delx.au - gnu-emacs-elpa/commitdiff
Fix up visual-line-mode limitation logic
authorOleh Krehel <ohwoeowho@gmail.com>
Mon, 5 Oct 2015 16:46:08 +0000 (18:46 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Mon, 5 Oct 2015 16:46:08 +0000 (18:46 +0200)
* swiper.el (swiper-use-visual-line): New defvar.
(swiper--candidates):
(swiper--update-input-ivy):
(swiper--action): Update.

Re #227

swiper.el

index 0f8ff31d2262fe257849242ace812deadb1a975d..bd7dc18afb03fe8c36862c61a37ef3edb1337309 100644 (file)
--- a/swiper.el
+++ b/swiper.el
 (defvar swiper--width nil
   "Store the amount of digits needed for the longest line nubmer.")
 
+(defvar swiper-use-visual-line nil
+  "When non-nil, use `line-move' instead of `forward-line'.")
+
 (defun swiper--candidates ()
   "Return a list of this buffer lines."
+  (setq swiper-use-visual-line
+        (and (not (eq major-mode 'org-mode))
+             visual-line-mode
+             (< (buffer-size) 20000)))
   (let ((n-lines (count-lines (point-min) (point-max))))
     (unless (zerop n-lines)
       (setq swiper--width (1+ (floor (log n-lines 10))))
       (setq swiper--format-spec
             (format "%%-%dd " swiper--width))
       (let ((line-number 0)
-            (advancer (if (and visual-line-mode
-                               (< (buffer-size) 20000))
+            (advancer (if swiper-use-visual-line
                           (lambda (arg) (line-move arg t))
                         #'forward-line))
             candidates)
           (while (< (point) (point-max))
             (let ((str (concat " " (buffer-substring
                                     (point)
-                                    (if visual-line-mode
+                                    (if swiper-use-visual-line
                                         (save-excursion
                                           (end-of-visual-line)
                                           (point))
@@ -354,7 +360,7 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
         (goto-char (point-min))
         (when (cl-plusp num)
           (goto-char (point-min))
-          (if visual-line-mode
+          (if swiper-use-visual-line
               (line-move (1- num))
             (forward-line (1- num)))
           (if (and (equal ivy-text "")
@@ -423,7 +429,7 @@ BEG and END, when specified, are the point bounds."
   (if (null x)
       (user-error "No candidates")
     (goto-char (point-min))
-    (funcall (if visual-line-mode
+    (funcall (if swiper-use-visual-line
                  #'line-move
                #'forward-line)
              (1- (read (get-text-property 0 'display x))))