diff options
author | Daniel Mendler <mail@daniel-mendler.de> | 2025-02-03 16:39:49 +0100 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2025-02-15 13:39:33 +0200 |
commit | a8a4c3a091bc6ebab40db3b33f4d15bb1040dbcb (patch) | |
tree | 14a0306910f9d7c0db671b9d6f2d66a827bf2010 /lisp/emacs-lisp/crm.el | |
parent | 6491fee366f58a831689c57aa31493dd70bc2245 (diff) | |
download | emacs-a8a4c3a091bc6ebab40db3b33f4d15bb1040dbcb.tar.gz emacs-a8a4c3a091bc6ebab40db3b33f4d15bb1040dbcb.tar.bz2 emacs-a8a4c3a091bc6ebab40db3b33f4d15bb1040dbcb.zip |
completing-read-multiple: CRM indication and prompt customization
The `completing-read-multiple' prompt indicates multi
completion. The customization option `crm-prompt' configures
the formatting of the prompt. The variable can be set to "%p"
in order to only display the original prompt, to "[%d] %p" to
display the separator description and the prompt, or to "[CRM%s]
%p" to display a shorter indicator of only the separator string
and the prompt.
* lisp/emacs-lisp/crm.el (crm-prompt): New user option.
(crm-separator): Update value and docstring.
(completing-read-multiple): Use `crm-prompt' to format the
prompt.
* etc/NEWS: Announce the change.
(Bug#76028)
Diffstat (limited to 'lisp/emacs-lisp/crm.el')
-rw-r--r-- | lisp/emacs-lisp/crm.el | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/crm.el b/lisp/emacs-lisp/crm.el index a371a8e14de..676252ae126 100644 --- a/lisp/emacs-lisp/crm.el +++ b/lisp/emacs-lisp/crm.el @@ -79,9 +79,25 @@ (define-obsolete-variable-alias 'crm-default-separator 'crm-separator "29.1") -(defvar crm-separator "[ \t]*,[ \t]*" +(defvar crm-separator + (propertize "[ \t]*,[ \t]*" 'separator "," 'description "comma-separated list") "Separator regexp used for separating strings in `completing-read-multiple'. -It should be a regexp that does not match the list of completion candidates.") +It should be a regexp that does not match the list of completion +candidates. The regexp string can carry the text properties `separator' +and `description', which if present `completing-read-multiple' will show +as part of the prompt. See the user option `crm-prompt'.") + +(defcustom crm-prompt "[%d] %p" + "Prompt format for `completing-read-multiple'. +The prompt is formatted by `format-spec' with the keys %d, %s and %p +standing for the separator description, the separator itself and the +original prompt respectively." + :type '(choice (const :tag "Original prompt" "%p") + (const :tag "Description and prompt" "[%d] %p") + (const :tag "Short CRM indication" "[CRM%s] %p") + (string :tag "Custom string")) + :group 'minibuffer + :version "31.1") (defvar-keymap crm-local-completion-map :doc "Local keymap for minibuffer multiple input with completion. @@ -266,8 +282,14 @@ with empty strings removed." (unless (eq require-match t) require-match)) (setq-local crm-completion-table table)) (setq input (read-from-minibuffer - prompt initial-input map - nil hist def inherit-input-method))) + (format-spec + crm-prompt + (let* ((sep (or (get-text-property 0 'separator crm-separator) + (string-replace "[ \t]*" "" crm-separator))) + (desc (or (get-text-property 0 'description crm-separator) + (concat "list separated by " sep)))) + `((?s . ,sep) (?d . ,desc) (?p . ,prompt)))) + initial-input map nil hist def inherit-input-method))) ;; If the user enters empty input, `read-from-minibuffer' ;; returns the empty string, not DEF. (when (and def (string-equal input "")) |