summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2021-01-30 21:12:37 +0200
committerJuri Linkov <juri@linkov.net>2021-01-30 21:12:37 +0200
commitb32d4bf682c41e30c46d154093eb3b00dab6b0a5 (patch)
tree7a57cdaf7ebebafa3f51497da67e70c85c3fdc10 /lisp
parent42f45e52aacf513abf3dafe1773bf64f04cf5299 (diff)
downloademacs-b32d4bf682c41e30c46d154093eb3b00dab6b0a5.tar.gz
Allow the caller to specify own face on suffix in annotation-function
* lisp/minibuffer.el (completion--insert-strings): Don't add 'completions-annotations' face when the caller specified own face in annotation-function. Remove no-op code for 'unless prefix' branch. (completion-metadata, completion-extra-properties): Update docs of affixation-function. Suggested by Clemens <clemera@posteo.net> (bug#45780) * test/lisp/minibuffer-tests.el: Rename package name from completion-tests.el to minibuffer-tests.el. Add new test completion--insert-strings-faces. * doc/lispref/minibuf.texi (Completion Variables) (Programmed Completion): Update descriptions of annotation-function and affixation-function.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/minibuffer.el19
1 files changed, 8 insertions, 11 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 315f2d369af..03cc70c0d4d 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -122,7 +122,8 @@ This metadata is an alist. Currently understood keys are:
returns a string to append to STRING.
- `affixation-function': function to prepend/append a prefix/suffix to
entries. Takes one argument (COMPLETIONS) and should return a list
- of completions with a list of three elements: completion, its prefix
+ of completions with a list of either two elements: completion
+ and suffix, or three elements: completion, its prefix
and suffix. This function takes priority over `annotation-function'
when both are provided, so only this function is used.
- `display-sort-function': function to sort entries in *Completions*.
@@ -1785,22 +1786,17 @@ It also eliminates runs of equal strings."
(when prefix
(let ((beg (point))
(end (progn (insert prefix) (point))))
- (put-text-property beg end 'mouse-face nil)
- ;; When both prefix and suffix are added
- ;; by the caller via affixation-function,
- ;; then allow the caller to decide
- ;; what faces to put on prefix and suffix.
- (unless prefix
- (font-lock-prepend-text-property
- beg end 'face 'completions-annotations))))
+ (put-text-property beg end 'mouse-face nil)))
(put-text-property (point) (progn (insert (car str)) (point))
'mouse-face 'highlight)
(let ((beg (point))
(end (progn (insert suffix) (point))))
(put-text-property beg end 'mouse-face nil)
;; Put the predefined face only when suffix
- ;; is added via annotation-function.
- (unless prefix
+ ;; is added via annotation-function without prefix,
+ ;; and when the caller doesn't use own face.
+ (unless (or prefix (text-property-not-all
+ 0 (length suffix) 'face nil suffix))
(font-lock-prepend-text-property
beg end 'face 'completions-annotations)))))
(cond
@@ -1927,6 +1923,7 @@ These include:
`:affixation-function': Function to prepend/append a prefix/suffix to
completions. The function must accept one argument, a list of
completions, and return a list where each element is a list of
+ either two elements: a completion, and a suffix, or
three elements: a completion, a prefix and a suffix.
This function takes priority over `:annotation-function'
when both are provided, so only this function is used.