Skip to content

Commit

Permalink
make numbers after candidates customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
yqrashawn committed Jan 16, 2019
1 parent f53327b commit 66ed6df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -2,6 +2,8 @@

## Next

* Add custom variable `company-show-numbers-function` to make numbers of
candidates customizable.
* When a symbol is already typed in full, calling `M-x company-complete` will
now run its post-completion action (e.g. inserting method parameters
template). Calling `M-x company-manual-begin` or invoking a backend command
Expand Down
13 changes: 12 additions & 1 deletion company.el
Expand Up @@ -632,6 +632,14 @@ commands in the `company-' namespace, abort completion."
:type '(choice (const :tag "off" nil)
(const :tag "on" t)))

(defcustom company-show-numbers-function #'company--show-numbers
"Function called to get custom quick-access numbers for the first then candidates.
If nil falls back to default function that generates 1...8, 9, 0. The function get
the number of candidates (from 1 to 10 means 1st to 10th candidate) and should
return a string prefixed with one space."
:type 'function)

(defcustom company-selection-wrap-around nil
"If enabled, selecting item before first or after last wraps around."
:type '(choice (const :tag "off" nil)
Expand Down Expand Up @@ -2635,6 +2643,9 @@ If SHOW-VERSION is non-nil, show the version in the echo area."
new
(company-safe-substring old (+ offset (length new)))))

(defun company--show-numbers (numbered)
(format " %d" (mod numbered 10)))

(defsubst company--window-height ()
(if (fboundp 'window-screen-lines)
(floor (window-screen-lines))
Expand Down Expand Up @@ -2787,7 +2798,7 @@ If SHOW-VERSION is non-nil, show the version in the echo area."
(when (< numbered 10)
(cl-decf width 2)
(cl-incf numbered)
(setq right (concat (format " %d" (mod numbered 10)) right)))
(setq right (concat (funcall company-show-numbers-function numbered) right)))
(push (concat
(company-fill-propertize str annotation
width (equal i selection)
Expand Down

0 comments on commit 66ed6df

Please sign in to comment.