]> code.delx.au - gnu-emacs-elpa/commitdiff
Make swiper compatible with visual-line-mode
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 2 Oct 2015 12:02:16 +0000 (14:02 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 2 Oct 2015 12:02:16 +0000 (14:02 +0200)
* swiper.el (swiper--candidates): Use `end-of-visual-line' and
  `line-move' appropriately.
(swiper--update-input-ivy):
(swiper--action): Use `line-move' instead of `forward-line'.
(swiper--add-overlays): Update.

Fixes #227

swiper.el

index 1b2d9067a2ead450a3eb42c67ff2e4493f72a8d3..cfc80cd0c6c64b6e119bb06b7113042c9082d994 100644 (file)
--- a/swiper.el
+++ b/swiper.el
           (swiper-font-lock-ensure)
           (while (< (point) (point-max))
             (let ((str (concat " " (buffer-substring
-                                    (line-beginning-position)
-                                    (line-end-position)))))
+                                    (point)
+                                    (if visual-line-mode
+                                        (save-excursion
+                                          (end-of-visual-line)
+                                          (point))
+                                      (line-end-position))))))
               (put-text-property 0 1 'display
                                  (format swiper--format-spec
                                          (cl-incf line-number))
                                  str)
               (push str candidates))
-            (forward-line 1))
+            (line-move 1))
           (nreverse candidates))))))
 
 (defvar swiper--opoint 1
@@ -318,7 +322,7 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
         (goto-char (point-min))
         (when (cl-plusp num)
           (goto-char (point-min))
-          (forward-line (1- num))
+          (line-move (1- num))
           (if (and (equal ivy-text "")
                    (>= swiper--opoint (line-beginning-position))
                    (<= swiper--opoint (line-end-position)))
@@ -334,9 +338,17 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
 (defun swiper--add-overlays (re &optional beg end)
   "Add overlays for RE regexp in visible part of the current buffer.
 BEG and END, when specified, are the point bounds."
-  (let ((ov (make-overlay
-             (line-beginning-position)
-             (1+ (line-end-position)))))
+  (let ((ov (if visual-line-mode
+                (make-overlay
+                 (save-excursion
+                   (beginning-of-visual-line)
+                   (point))
+                 (save-excursion
+                   (end-of-visual-line)
+                   (point)))
+              (make-overlay
+               (line-beginning-position)
+               (1+ (line-end-position))))))
     (overlay-put ov 'face 'swiper-line-face)
     (overlay-put ov 'window (ivy-state-window ivy-last))
     (push ov swiper--overlays)
@@ -377,7 +389,7 @@ BEG and END, when specified, are the point bounds."
   (if (null x)
       (user-error "No candidates")
     (goto-char (point-min))
-    (forward-line (1- (read (get-text-property 0 'display x))))
+    (line-move (1- (read (get-text-property 0 'display x))))
     (re-search-forward
      (ivy--regex input) (line-end-position) t)
     (swiper--ensure-visible)