]> code.delx.au - gnu-emacs-elpa/commitdiff
Support multiple-width chars in annotations
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 16 Nov 2014 20:45:53 +0000 (22:45 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 16 Nov 2014 20:45:53 +0000 (22:45 +0200)
Fixes #230

company-tests.el
company.el

index 0663c71f9fef75159454d951d1565ae1cda9e5cc..26e98e2a98c0e481e40333c96ad67c81e09ba051 100644 (file)
                              "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 ()
                      " 蛙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
index 10e18076525b9c10df7d74d6c6bd2c2d5211f2e5..a44f1507b3f8937ae8e2215e17d6052d3c3d549c 100644 (file)
@@ -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)))