branch: master
commit 7fc6ad9300a7bb2666def38537acd5ddcad49323
Merge: 856c66a d5f3a95
Author: Dmitry Gutov <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #941 from amosbird/master
add option to show numbers on the left
---
NEWS.md | 1 +
company.el | 14 +++++++++-----
test/frontends-tests.el | 8 ++++++++
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index a551f13..9e99c00 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -13,6 +13,7 @@
map binding `TAB` to "jump to the next field"). Affects both
`company-template` and `yasnippet` (requires changes from 2019-04-21,
currently unreleased).
+* New values for option `company-show-numbers` to show number on the left.
## 2019-04-15 (0.9.10)
diff --git a/company.el b/company.el
index 1ee7d4d..dedaa30 100644
--- a/company.el
+++ b/company.el
@@ -641,7 +641,8 @@ commands in the `company-' namespace, abort completion."
(defcustom company-show-numbers nil
"If enabled, show quick-access numbers for the first ten candidates."
:type '(choice (const :tag "off" nil)
- (const :tag "on" t)))
+ (const :tag "left" 'left)
+ (const :tag "on" 't)))
(defcustom company-show-numbers-function #'company--show-numbers
"Function called to get quick-access numbers for the first ten candidates.
@@ -2817,17 +2818,20 @@ If SHOW-VERSION is non-nil, show the version in the
echo area."
(let* ((item (pop items))
(str (car item))
(annotation (cdr item))
- (right (company-space-string company-tooltip-margin))
+ (margin (company-space-string company-tooltip-margin))
+ (left margin)
+ (right margin)
(width width))
(when (< numbered 10)
(cl-decf width 2)
(cl-incf numbered)
- (setq right (concat (funcall company-show-numbers-function
numbered) right)))
+ (setf (if (eq company-show-numbers 'left) left right)
+ (concat (funcall company-show-numbers-function numbered)
+ margin)))
(push (concat
(company-fill-propertize str annotation
width (equal i selection)
- (company-space-string
- company-tooltip-margin)
+ left
right)
(when scrollbar-bounds
(company--scrollbar i scrollbar-bounds)))
diff --git a/test/frontends-tests.el b/test/frontends-tests.el
index 7212c3f..f7f578e 100644
--- a/test/frontends-tests.el
+++ b/test/frontends-tests.el
@@ -139,6 +139,14 @@
(should (equal '(" x 1 " " y 2 " " z 3 ")
(company--create-lines 0 999)))))
+(ert-deftest company-create-lines-shows-numbers-on-the-left ()
+ (let ((company-show-numbers 'left)
+ (company-candidates '("x" "y" "z"))
+ (company-candidates-length 3)
+ (company-backend 'ignore))
+ (should (equal '(" 1 x " " 2 y " " 3 z ")
+ (company--create-lines 0 999)))))
+
(ert-deftest company-create-lines-truncates-annotations ()
(let* ((ww (company--window-width))
(data `(("1" . "(123)")