emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 4d8ac8c 17/66: Support multiple-width chars in annotations


From: Dmitry Gutov
Subject: [elpa] master 4d8ac8c 17/66: Support multiple-width chars in annotations
Date: Tue, 13 Jan 2015 02:44:48 +0000

branch: master
commit 4d8ac8c02cbabbcfda0cba00628f446877417795
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Support multiple-width chars in annotations
    
    Fixes #230
---
 company-tests.el |   16 ++++++++++++++--
 company.el       |   12 +++++++-----
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/company-tests.el b/company-tests.el
index 0663c71..26e98e2 100644
--- a/company-tests.el
+++ b/company-tests.el
@@ -567,8 +567,8 @@
                              "avatar"))
         (company-candidates-length 2)
         (company-backend 'ignore))
-    (should (equal '(" avalis‗e    "
-                     " avatar      ")
+    (should (equal '(" avalis‗e "
+                     " avatar   ")
                    (company--create-lines 0 999)))))
 
 (ert-deftest company-create-lines-handles-multiple-width ()
@@ -581,6 +581,18 @@
                      " 蛙abc    ")
                    (company--create-lines 0 999)))))
 
+(ert-deftest company-create-lines-handles-multiple-width-in-annotation ()
+  (let* (company-show-numbers
+         (alist '(("a" . " ︸") ("b" . " ︸︸")))
+         (company-candidates (mapcar #'car alist))
+         (company-candidates-length 2)
+         (company-backend (lambda (c &optional a)
+                            (when (eq c 'annotation)
+                              (assoc-default a alist)))))
+    (should (equal '(" a ︸   "
+                     " b ︸︸ ")
+                   (company--create-lines 0 999)))))
+
 (ert-deftest company-column-with-composition ()
   :tags '(interactive)
   (with-temp-buffer
diff --git a/company.el b/company.el
index 10e1807..a44f150 100644
--- a/company.el
+++ b/company.el
@@ -2103,7 +2103,6 @@ If SHOW-VERSION is non-nil, show the version in the echo 
area."
                          (string-width company-common)
                        0)))
          (ann-ralign company-tooltip-align-annotations)
-         (value (company--clean-string value))
          (ann-truncate (< width
                           (+ (length value) (length annotation)
                              (if ann-ralign 1 0))))
@@ -2324,11 +2323,14 @@ If SHOW-VERSION is non-nil, show the version in the 
echo area."
     (dotimes (_ len)
       (let* ((value (pop lines-copy))
              (annotation (company-call-backend 'annotation value)))
-        (when (and annotation company-tooltip-align-annotations)
-          ;; `lisp-completion-at-point' adds a space.
-          (setq annotation (comment-string-strip annotation t nil)))
+        (setq value (company--clean-string value))
+        (when annotation
+          (when company-tooltip-align-annotations
+            ;; `lisp-completion-at-point' adds a space.
+            (setq annotation (comment-string-strip annotation t nil)))
+          (setq annotation (company--clean-string annotation)))
         (push (cons value annotation) items)
-        (setq width (max (+ (string-width value)
+        (setq width (max (+ (length value)
                             (if (and annotation 
company-tooltip-align-annotations)
                                 (1+ (length annotation))
                               (length annotation)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]