From 206007c79cdffac04dcd30a8eeb6f6ad25536ddf Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Mon, 23 Sep 2013 03:36:31 +0300 Subject: [PATCH] * company-untabify: Rename to `company-plainify'. * company-modify-line: Move `line-prefix' logic to `company-plainify'. Fix #24, take four --- company-tests.el | 18 +++++++++++++----- company.el | 12 ++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/company-tests.el b/company-tests.el index 1031d0bc7..870ad2b10 100644 --- a/company-tests.el +++ b/company-tests.el @@ -217,14 +217,22 @@ (put-text-property (point-min) (point-max) 'line-prefix " ") (should (= (company--column) 2)))) -(ert-deftest company-modify-line-with-line-prefix () - (let ((str (propertize "foobar" 'line-prefix "-*-"))) +(ert-deftest company-plainify () + (let ((tab-width 8)) + (should (equal-including-properties + (company-plainify "\tabc\td\t") + (concat " " + "abc " + "d ")))) + (should (equal-including-properties + (company-plainify (propertize "foobar" 'line-prefix "-*-")) + "-*-foobar"))) + +(ert-deftest company-modify-line () + (let ((str "-*-foobar")) (should (equal-including-properties (company-modify-line str "zz" 4) "-*-fzzbar")) - (should (equal-including-properties - (company-modify-line str "zzxx" 1) - "-zzxxobar")) (should (equal-including-properties (company-modify-line str "xx" 0) "xx-foobar")) diff --git a/company.el b/company.el index dff2e06b7..253dcc02a 100644 --- a/company.el +++ b/company.el @@ -1637,7 +1637,11 @@ Example: \(company-begin-with '\(\"foo\" \"foobar\" \"foobarbaz\"\)\)" (defsubst company-round-tab (arg) (* (/ (+ arg tab-width) tab-width) tab-width)) -(defun company-untabify (str) +(defun company-plainify (str) + (let ((prefix (get-text-property 0 'line-prefix str))) + (when prefix ; Keep the original value unmodified, for no special reason. + (setq str (concat prefix str)) + (remove-text-properties 0 (length str) '(line-prefix) str))) (let* ((pieces (split-string str "\t")) (copy pieces)) (while (cdr copy) @@ -1698,10 +1702,6 @@ Example: \(company-begin-with '\(\"foo\" \"foobar\" \"foobarbaz\"\)\)" (nreverse lines))) (defun company-modify-line (old new offset) - (let ((prefix (get-text-property 0 'line-prefix old))) - (when prefix ; Keep the original value unmodified, for no special reason. - (setq old (concat prefix old)) - (remove-text-properties 0 (length old) '(line-prefix) old))) (concat (company-safe-substring old 0 offset) new (company-safe-substring old (+ offset (length new))))) @@ -1831,7 +1831,7 @@ Returns a negative number if the tooltip should be displayed above point." (move-to-window-line (+ row (abs height))) (point))) (ov (make-overlay beg end)) - (args (list (mapcar 'company-untabify + (args (list (mapcar 'company-plainify (company-buffer-lines beg end)) column nl above))) -- 2.39.2