dgutov pushed a commit to branch master in repository elpa. commit e40329f6b4af7557c4651d33fcf7d3ba93c58041 Author: Dmitry Gutov <dgu...@yandex.ru> Date: Mon Aug 18 05:51:10 2014 +0400
company-buffer-lines: handle multiline display better Improves #136. --- company-tests.el | 14 ++++++++++++++ company.el | 8 ++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/company-tests.el b/company-tests.el index 898fb92..33e0c98 100644 --- a/company-tests.el +++ b/company-tests.el @@ -597,6 +597,20 @@ (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 diff --git a/company.el b/company.el index e9ada82..bbaea00 100644 --- a/company.el +++ b/company.el @@ -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))