[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 20/30: Handle non-printable and multiple-width chars in completio
From: |
Dmitry Gutov |
Subject: |
[elpa] 20/30: Handle non-printable and multiple-width chars in completions |
Date: |
Tue, 14 Oct 2014 22:22:52 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit a0e1a71fa288c0db6dc855fdc92ef53318fe7a39
Author: Dmitry Gutov <address@hidden>
Date: Wed Oct 8 07:05:50 2014 +0400
Handle non-printable and multiple-width chars in completions
#199
---
company-tests.el | 21 ++++++++++++++++++++-
company.el | 22 +++++++++++++++++++++-
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/company-tests.el b/company-tests.el
index 6060aed..517ad41 100644
--- a/company-tests.el
+++ b/company-tests.el
@@ -557,8 +557,27 @@
(should (eq 'company-tooltip-selection
(get-text-property (1- ww) 'face
(car res))))
+ )))
+
+(ert-deftest company-create-lines-clears-out-non-printables ()
+ (let (company-show-numbers
+ (company-candidates (list
+ (decode-coding-string "avalis\351e" 'utf-8)
+ "avatar"))
+ (company-candidates-length 2)
+ (company-backend 'ignore))
+ (should (equal '(" avalis‗e "
+ " avatar ")
+ (company--create-lines 0 999)))))
-)))
+(ert-deftest company-create-lines-handles-multiple-width ()
+ (let (company-show-numbers
+ (company-candidates '("蛙蛙蛙蛙" "蛙abc"))
+ (company-candidates-length 2)
+ (company-backend 'ignore))
+ (should (equal '(" 蛙蛙蛙蛙 "
+ " 蛙abc ")
+ (company--create-lines 0 999)))))
(ert-deftest company-column-with-composition ()
:tags '(interactive)
diff --git a/company.el b/company.el
index c7b7be7..0ae9b27 100644
--- a/company.el
+++ b/company.el
@@ -2093,6 +2093,7 @@ If SHOW-VERSION is non-nil, show the version in the echo
area."
(common (or (company-call-backend 'match value)
(length company-common)))
(ann-ralign company-tooltip-align-annotations)
+ (value (company--clean-string value))
(ann-truncate (< width
(+ (length value) (length annotation)
(if ann-ralign 1 0))))
@@ -2151,6 +2152,25 @@ If SHOW-VERSION is non-nil, show the version in the echo
area."
line)))
line))
+(defun company--clean-string (str)
+ (replace-regexp-in-string
+ "\\([^[:graph:] ]\\)\\|\\(\ufeff\\)\\|[[:multibyte:]]"
+ (lambda (match)
+ (cond
+ ((match-beginning 1)
+ ;; FIXME: Better char for 'non-printable'?
+ ;; We shouldn't get any of these, but sometimes we might.
+ "\u2017")
+ ((match-beginning 2)
+ ;; Zero-width non-breakable space.
+ "")
+ ((> (string-width match) 1)
+ (concat
+ (make-string (1- (string-width match)) ?\ufeff)
+ match))
+ (t match)))
+ str))
+
;;; replace
(defun company-buffer-lines (beg end)
@@ -2278,7 +2298,7 @@ If SHOW-VERSION is non-nil, show the version in the echo
area."
;; `lisp-completion-at-point' adds a space.
(setq annotation (comment-string-strip annotation t nil)))
(push (cons value annotation) items)
- (setq width (max (+ (length value)
+ (setq width (max (+ (string-width value)
(if (and annotation
company-tooltip-align-annotations)
(1+ (length annotation))
(length annotation)))
- [elpa] 08/30: company-post-command: Handle being called after quitting, (continued)
- [elpa] 08/30: company-post-command: Handle being called after quitting, Dmitry Gutov, 2014/10/14
- [elpa] 09/30: company-files.el: Change regexp prefix, Dmitry Gutov, 2014/10/14
- [elpa] 10/30: Update docstring, change words, bump copyright year, Dmitry Gutov, 2014/10/14
- [elpa] 13/30: Update a comment, Dmitry Gutov, 2014/10/14
- [elpa] 11/30: company-files-complete: Include mtime in the cache key, Dmitry Gutov, 2014/10/14
- [elpa] 15/30: company-files: Fix cache behavior for when we're backspacing, Dmitry Gutov, 2014/10/14
- [elpa] 16/30: company-file--keys-match-p: Handle OLD being nil, Dmitry Gutov, 2014/10/14
- [elpa] 17/30: company-begin-commands: Add `orgtbl-self-insert-command', Dmitry Gutov, 2014/10/14
- [elpa] 19/30: company-clang-arguments: Fix default element value, Dmitry Gutov, 2014/10/14
- [elpa] 21/30: company-call-backend-raw: Use `condition-case-unless-debug', too, Dmitry Gutov, 2014/10/14
- [elpa] 20/30: Handle non-printable and multiple-width chars in completions,
Dmitry Gutov <=
- [elpa] 18/30: Use `condition-case-unless-debug' more, Dmitry Gutov, 2014/10/14
- [elpa] 22/30: company-dabbrev--search: Ignore "uninteresting" buffers, Dmitry Gutov, 2014/10/14
- [elpa] 23/30: Make new tests and interactive-only, Dmitry Gutov, 2014/10/14
- [elpa] 24/30: company-fill-propertize: Use `string-width' on `company-common', Dmitry Gutov, 2014/10/14
- [elpa] 25/30: Handle nil company-common, in order not to bind it in tests, Dmitry Gutov, 2014/10/14
- [elpa] 12/30: Update NEWS; do the forgotten version bump, Dmitry Gutov, 2014/10/14
- [elpa] 14/30: company-files.el: Use the "private function" naming convention, Dmitry Gutov, 2014/10/14
- [elpa] 26/30: Call `bbdb-search' inside `eval' block, Dmitry Gutov, 2014/10/14
- [elpa] 27/30: Extract regexp for buffers to ignore into a new var, Dmitry Gutov, 2014/10/14
- [elpa] 28/30: company-template-c-like-templatify: Support generics, Dmitry Gutov, 2014/10/14