Annotate completion candidates (GNU Emacs)
GNU Emacs supports annotation for completion candidates. An annotation is a small bit of useful information shown next to a completion candidate which a package developer can use to provide additional help to the user while making a selection. e.g. while selecting a command, this is usually the keyboard shortcut.
In the following example, annotation is used to display a sample text with the candidate font-family applied.
(defun test ()
(interactive)
(let* ((completion-extra-properties
`(:annotation-function
(lambda (a)
(propertize " (OIly10)" 'face
`(:family ,a :background "grey"))))))
(completing-read "Font family: " (font-family-list))
))
(interactive)
(let* ((completion-extra-properties
`(:annotation-function
(lambda (a)
(propertize " (OIly10)" 'face
`(:family ,a :background "grey"))))))
(completing-read "Font family: " (font-family-list))
))
By default, Emacs uses completions-annotations face for the annotation. Use the following patch to skip changing the face when the annotation already has a face attached.
modified lisp/minibuffer.el
@@ -1754,8 +1754,10 @@ completion--insert-strings
(let ((beg (point))
(end (progn (insert (cadr str)) (point))))
(put-text-property beg end 'mouse-face nil)
- (font-lock-prepend-text-property beg end 'face
- 'completions-annotations)))
+ (or (get-text-property beg 'face)
+ (font-lock-append-text-property beg end 'face
+ 'completions-annotations))
+ ))
(cond
((eq completions-format 'vertical)
;; Vertical format
@@ -1754,8 +1754,10 @@ completion--insert-strings
(let ((beg (point))
(end (progn (insert (cadr str)) (point))))
(put-text-property beg end 'mouse-face nil)
- (font-lock-prepend-text-property beg end 'face
- 'completions-annotations)))
+ (or (get-text-property beg 'face)
+ (font-lock-append-text-property beg end 'face
+ 'completions-annotations))
+ ))
(cond
((eq completions-format 'vertical)
;; Vertical format
Comments
Post a Comment