1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Add 'completions-detailed' to add prefix/suffix with 'affixation-function'

* doc/lispref/minibuf.texi (Completion Variables)
(Programmed Completion): Add affixation-function.

* lisp/help-fns.el (help--symbol-completion-table-affixation): New function.
(help--symbol-completion-table): Set affixation-function when
completions-detailed is non-nil.

* lisp/minibuffer.el (completion-metadata): Add affixation-function
to docstring.
(completions-annotations): Inherit from shadow with italic.
(completions-detailed): New defcustom.
(completion--insert-strings): Count string-width on all strings in
completion list.  Insert prefix and suffix.
(completion-extra-properties): Add affixation-function to docstring.
(minibuffer-completion-help): Call affixation-function.
(minibuffer-default-prompt-format): Move down closer to its use.

https://lists.gnu.org/archive/html/emacs-devel/2020-11/msg00613.html
This commit is contained in:
Juri Linkov 2020-11-25 10:46:59 +02:00
parent d7a580c7eb
commit 3b740591b0
4 changed files with 138 additions and 42 deletions

View file

@ -126,17 +126,48 @@ with the current prefix. The files are chosen according to
:group 'help
:version "26.3")
(defun help--symbol-completion-table-affixation (completions)
(mapcar (lambda (c)
(let* ((s (intern c))
(doc (condition-case nil (documentation s) (error nil)))
(doc (and doc (substring doc 0 (string-match "\n" doc)))))
(list c (propertize
(concat (cond ((commandp s)
"c") ; command
((eq (car-safe (symbol-function s)) 'macro)
"m") ; macro
((fboundp s)
"f") ; function
((custom-variable-p s)
"u") ; user option
((boundp s)
"v") ; variable
((facep s)
"a") ; fAce
((and (fboundp 'cl-find-class)
(cl-find-class s))
"t") ; CL type
(" ")) ; something else
" ") ; prefix separator
'face 'completions-annotations)
(if doc (propertize (format " -- %s" doc)
'face 'completions-annotations)
""))))
completions))
(defun help--symbol-completion-table (string pred action)
(when help-enable-completion-autoload
(let ((prefixes (radix-tree-prefixes (help-definition-prefixes) string)))
(help--load-prefixes prefixes)))
(let ((prefix-completions
(and help-enable-completion-autoload
(mapcar #'intern (all-completions string definition-prefixes)))))
(complete-with-action action obarray string
(if pred (lambda (sym)
(or (funcall pred sym)
(memq sym prefix-completions)))))))
(if (and completions-detailed (eq action 'metadata))
'(metadata (affixation-function . help--symbol-completion-table-affixation))
(when help-enable-completion-autoload
(let ((prefixes (radix-tree-prefixes (help-definition-prefixes) string)))
(help--load-prefixes prefixes)))
(let ((prefix-completions
(and help-enable-completion-autoload
(mapcar #'intern (all-completions string definition-prefixes)))))
(complete-with-action action obarray string
(if pred (lambda (sym)
(or (funcall pred sym)
(memq sym prefix-completions))))))))
(defvar describe-function-orig-buffer nil
"Buffer that was current when `describe-function' was invoked.