]> code.delx.au - gnu-emacs-elpa/commitdiff
company-buffer-lines: handle multiline display better
authorDmitry Gutov <dgutov@yandex.ru>
Mon, 18 Aug 2014 01:51:10 +0000 (05:51 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Mon, 18 Aug 2014 01:51:10 +0000 (05:51 +0400)
Improves #136.

company-tests.el
company.el

index 898fb92dd591a73b983407bce2d027fba13ca584..33e0c987663c25d6d8c188bc587ec2b478b80160 100644 (file)
            (company-plainify (propertize "foobar" 'line-prefix "-*-"))
            "-*-foobar")))
 
+(ert-deftest company-buffer-lines-with-lines-folded ()
+  (with-temp-buffer
+    (insert (propertize "aaa\nbbb\nccc\nddd\n" 'display "aaa+\n"))
+    (insert "eee\nfff\nggg")
+    (should (equal (company-buffer-lines (point-min) (point-max))
+                   '("aaa" "eee" "fff" "ggg")))))
+
+(ert-deftest company-buffer-lines-with-multiline-display ()
+  (with-temp-buffer
+    (insert (propertize "a" 'display "bbb\nccc\ndddd\n"))
+    (insert "eee\nfff\nggg")
+    (should (equal (company-buffer-lines (point-min) (point-max))
+                   '("" "" "" "eee" "fff" "ggg")))))
+
 (ert-deftest company-modify-line ()
   (let ((str "-*-foobar"))
     (should (equal-including-properties
index e9ada823eeab568b417455d0a4e4f7a39f9b60ed..bbaea00a444ca5d27ed54ab5eb7adb7259cefb8c 100644 (file)
@@ -2169,8 +2169,8 @@ If SHOW-VERSION is non-nil, show the version in the echo area."
 
 (defun company-buffer-lines (beg end)
   (goto-char beg)
-  (let (lines)
-    (while (and (= 1 (vertical-motion 1))
+  (let (lines lines-moved)
+    (while (and (> (setq lines-moved (vertical-motion 1)) 0)
                 (<= (point) end))
       (let ((bound (min end (1- (point)))))
         ;; A visual line can contain several physical lines (e.g. with outline's
@@ -2181,6 +2181,10 @@ If SHOW-VERSION is non-nil, show the version in the echo area."
                                   (re-search-forward "$" bound 'move)
                                   (point)))
               lines))
+      ;; One physical line can be displayed as several visual ones as well:
+      ;; add empty strings to the list, to even the count.
+      (dotimes (_ (1- lines-moved))
+        (push "" lines))
       (setq beg (point)))
     (unless (eq beg end)
       (push (buffer-substring beg end) lines))