* bug#76028: 31; completing-read-multiple: Add prompt indicator
@ 2025-02-03 9:27 Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 12:48 ` Eli Zaretskii
2025-02-03 13:03 ` Stefan Kangas
0 siblings, 2 replies; 13+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-03 9:27 UTC (permalink / raw)
To: 76028; +Cc: Juri Linkov
The function `completing-read-multiple' (CRM) can be used to read
multiple candidates, separated by comma (see the variable
`crm-separator'). Besides that it acts similarly to `completing-read'.
To the user it is no obvious if CRM is used.
For years I have used an advice in my configuration which adds a CRM
indicator to the prompt. For example, the advice turns the
`describe-face' prompt from "Describe face: " into "[CRM ,] Describe
face: ", which tells the user that multiple face names are read,
separated by comma:
#+begin_src emacs-lisp
(defun crm-indicator (args)
(defvar crm-separator)
(cons (format "[%s %s] %s"
(propertize "CRM" 'face 'error)
(propertize
(replace-regexp-in-string
"\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
crm-separator)
'face 'success)
(car args))
(cdr args)))
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)
#+end_src
I propose to add such an indicator to CRM by default. Above I have
chosen the tag "CRM" for its shortness, but a more user friendly
solution might require a longer more descriptive name. Furthermore the
code above extracts the separator from the regular expression
`crm-separator', which is not robust for all separators.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-03 9:27 bug#76028: 31; completing-read-multiple: Add prompt indicator Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-02-03 12:48 ` Eli Zaretskii
2025-02-03 13:02 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 13:03 ` Stefan Kangas
1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2025-02-03 12:48 UTC (permalink / raw)
To: Daniel Mendler; +Cc: 76028, juri
> Cc: Juri Linkov <juri@linkov.net>
> Date: Mon, 03 Feb 2025 10:27:30 +0100
> From: Daniel Mendler via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>
> The function `completing-read-multiple' (CRM) can be used to read
> multiple candidates, separated by comma (see the variable
> `crm-separator'). Besides that it acts similarly to `completing-read'.
> To the user it is no obvious if CRM is used.
>
> For years I have used an advice in my configuration which adds a CRM
> indicator to the prompt. For example, the advice turns the
> `describe-face' prompt from "Describe face: " into "[CRM ,] Describe
> face: ", which tells the user that multiple face names are read,
> separated by comma:
>
> #+begin_src emacs-lisp
> (defun crm-indicator (args)
> (defvar crm-separator)
> (cons (format "[%s %s] %s"
> (propertize "CRM" 'face 'error)
> (propertize
> (replace-regexp-in-string
> "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
> crm-separator)
> 'face 'success)
> (car args))
> (cdr args)))
> (advice-add #'completing-read-multiple :filter-args #'crm-indicator)
> #+end_src
>
> I propose to add such an indicator to CRM by default. Above I have
> chosen the tag "CRM" for its shortness, but a more user friendly
> solution might require a longer more descriptive name. Furthermore the
> code above extracts the separator from the regular expression
> `crm-separator', which is not robust for all separators.
Isn't that too cryptic?
A prompt "Describe face: " which expects one or more faces is not the
best prompt text, and should preferably be improved by implying
multiple faces separated by a comma. Or maybe we need some
specialized help key there, which would spell that out. Or something
else which would be explicit even to users who are using CRM for the
first time in their lives.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-03 12:48 ` Eli Zaretskii
@ 2025-02-03 13:02 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 0 replies; 13+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-03 13:02 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 76028, juri
Eli Zaretskii <eliz@gnu.org> writes:
>> Cc: Juri Linkov <juri@linkov.net>
>> Date: Mon, 03 Feb 2025 10:27:30 +0100
>> From: Daniel Mendler via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>>
>> The function `completing-read-multiple' (CRM) can be used to read
>> multiple candidates, separated by comma (see the variable
>> `crm-separator'). Besides that it acts similarly to `completing-read'.
>> To the user it is no obvious if CRM is used.
>>
>> For years I have used an advice in my configuration which adds a CRM
>> indicator to the prompt. For example, the advice turns the
>> `describe-face' prompt from "Describe face: " into "[CRM ,] Describe
>> face: ", which tells the user that multiple face names are read,
>> separated by comma:
>>
>> #+begin_src emacs-lisp
>> (defun crm-indicator (args)
>> (defvar crm-separator)
>> (cons (format "[%s %s] %s"
>> (propertize "CRM" 'face 'error)
>> (propertize
>> (replace-regexp-in-string
>> "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
>> crm-separator)
>> 'face 'success)
>> (car args))
>> (cdr args)))
>> (advice-add #'completing-read-multiple :filter-args #'crm-indicator)
>> #+end_src
>>
>> I propose to add such an indicator to CRM by default. Above I have
>> chosen the tag "CRM" for its shortness, but a more user friendly
>> solution might require a longer more descriptive name. Furthermore the
>> code above extracts the separator from the regular expression
>> `crm-separator', which is not robust for all separators.
>
> Isn't that too cryptic?
Yes. For my purposes the cryptic text is sufficient but I would prefer
something more readable if we add such an indicator to
`completing-read-multiple'.
> A prompt "Describe face: " which expects one or more faces is not the
> best prompt text, and should preferably be improved by implying
> multiple faces separated by a comma. Or maybe we need some
> specialized help key there, which would spell that out. Or something
> else which would be explicit even to users who are using CRM for the
> first time in their lives.
Improving every `completing-read-multiple' prompt is an option too.
However I would prefer if we uniformly add an indicator to
`completing-read-multiple' such that multi completion becomes clearly
recognizable. Other options could be a help text in the mode line or a
`minibuffer-message' telling the user about multi completion. In any
case the indicator should be guarded by a customization options such
that it can be disabled or customized.
Daniel
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-03 9:27 bug#76028: 31; completing-read-multiple: Add prompt indicator Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 12:48 ` Eli Zaretskii
@ 2025-02-03 13:03 ` Stefan Kangas
2025-02-03 13:09 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 13:16 ` Eli Zaretskii
1 sibling, 2 replies; 13+ messages in thread
From: Stefan Kangas @ 2025-02-03 13:03 UTC (permalink / raw)
To: Daniel Mendler, 76028; +Cc: Juri Linkov
Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:
> I propose to add such an indicator to CRM by default. Above I have
> chosen the tag "CRM" for its shortness, but a more user friendly
> solution might require a longer more descriptive name. Furthermore the
> code above extracts the separator from the regular expression
> `crm-separator', which is not robust for all separators.
How about " [comma-separated list] "?
I'd also propose we should have a defcustom for it, allowing users to
set it to something shorter if they want.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-03 13:03 ` Stefan Kangas
@ 2025-02-03 13:09 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 15:51 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 13:16 ` Eli Zaretskii
1 sibling, 1 reply; 13+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-03 13:09 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 76028, Juri Linkov
Stefan Kangas <stefankangas@gmail.com> writes:
> Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of
> text editors" <bug-gnu-emacs@gnu.org> writes:
>
>> I propose to add such an indicator to CRM by default. Above I have
>> chosen the tag "CRM" for its shortness, but a more user friendly
>> solution might require a longer more descriptive name. Furthermore the
>> code above extracts the separator from the regular expression
>> `crm-separator', which is not robust for all separators.
>
> How about " [comma-separated list] "?
>
> I'd also propose we should have a defcustom for it, allowing users to
> set it to something shorter if they want.
Yes, this would look good. Note that `crm-separator' can be set to an
arbitrary regular expression. How can we turn `crm-separator' into a
string like "comma-separated list"? Maybe `crm-separator' should be
generalized? One could set it to a cons ("," . "comma-separated list")
with the regexp in the car and the description in the cdr. In cases
where `crm-separator' is a string, we could use a generic string like
"[multi list]".
Daniel
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-03 13:03 ` Stefan Kangas
2025-02-03 13:09 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-02-03 13:16 ` Eli Zaretskii
2025-02-03 17:56 ` Juri Linkov
1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2025-02-03 13:16 UTC (permalink / raw)
To: Stefan Kangas; +Cc: mail, 76028, juri
> Cc: Juri Linkov <juri@linkov.net>
> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Mon, 3 Feb 2025 05:03:12 -0800
>
> Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of
> text editors" <bug-gnu-emacs@gnu.org> writes:
>
> > I propose to add such an indicator to CRM by default. Above I have
> > chosen the tag "CRM" for its shortness, but a more user friendly
> > solution might require a longer more descriptive name. Furthermore the
> > code above extracts the separator from the regular expression
> > `crm-separator', which is not robust for all separators.
>
> How about " [comma-separated list] "?
Or maybe "Describe face (FACE1[,FACE2[,...]]): "
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-03 13:09 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-02-03 15:51 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 0 replies; 13+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-03 15:51 UTC (permalink / raw)
To: Stefan Kangas, 76028; +Cc: Eli Zaretskii, Juri Linkov
[-- Attachment #1: Type: text/plain, Size: 1260 bytes --]
Daniel Mendler <mail@daniel-mendler.de> writes:
> Stefan Kangas <stefankangas@gmail.com> writes:
>
>> Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of
>> text editors" <bug-gnu-emacs@gnu.org> writes:
>>
>>> I propose to add such an indicator to CRM by default. Above I have
>>> chosen the tag "CRM" for its shortness, but a more user friendly
>>> solution might require a longer more descriptive name. Furthermore the
>>> code above extracts the separator from the regular expression
>>> `crm-separator', which is not robust for all separators.
>>
>> How about " [comma-separated list] "?
>>
>> I'd also propose we should have a defcustom for it, allowing users to
>> set it to something shorter if they want.
>
> Yes, this would look good. Note that `crm-separator' can be set to an
> arbitrary regular expression. How can we turn `crm-separator' into a
> string like "comma-separated list"? Maybe `crm-separator' should be
> generalized? One could set it to a cons ("," . "comma-separated list")
> with the regexp in the car and the description in the cdr. In cases
> where `crm-separator' is a string, we could use a generic string like
> "[multi list]".
I have attached a patch to this mail which implements this proposal.
Daniel
[-- Attachment #2: 0001-completing-read-multiple-CRM-indication-and-prompt-c.patch --]
[-- Type: text/x-diff, Size: 6867 bytes --]
From 72f3b3890d138c7a5cd1b4da9f1918d5cf170a74 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <mail@daniel-mendler.de>
Date: Mon, 3 Feb 2025 16:39:49 +0100
Subject: [PATCH] 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 for
example 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): Make customizable, update value and docstring.
(crm--regexp): New helper function.
(crm--collection-fn, crm--current-element, crm-complete-and-exit)
(completing-read-multiple): Use it.
---
lisp/emacs-lisp/crm.el | 50 ++++++++++++++++++++++++++++++++----------
1 file changed, 39 insertions(+), 11 deletions(-)
diff --git a/lisp/emacs-lisp/crm.el b/lisp/emacs-lisp/crm.el
index 454c3e85074..fcaef6cc476 100644
--- a/lisp/emacs-lisp/crm.el
+++ b/lisp/emacs-lisp/crm.el
@@ -79,9 +79,23 @@
(define-obsolete-variable-alias 'crm-default-separator 'crm-separator "29.1")
-(defvar crm-separator "[ \t]*,[ \t]*"
- "Separator regexp used for separating strings in `completing-read-multiple'.
-It should be a regexp that does not match the list of completion candidates.")
+(defcustom crm-separator '("[ \t]*,[ \t]*" "," "comma-separated list")
+ "Separator used for separating strings in `completing-read-multiple'.
+It should be a regexp or a list of three strings of the form (regexp
+separator description). The regexp must not match the list of
+completion candidates, the separator string and the description can be
+shown in the prompt, see `crm-prompt'."
+ :type '(choice regexp (list regexp string string))
+ :group 'minibuffer)
+
+(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
+which stand for the separator description, the separator string and the
+original prompt respectively."
+ :type 'string
+ :group 'minibuffer
+ :version "31.1")
(defvar-keymap crm-local-completion-map
:doc "Local keymap for minibuffer multiple input with completion.
@@ -106,6 +120,10 @@ crm-completion-table
This is a table used for completion by `completing-read-multiple' and its
supporting functions.")
+(defun crm--regexp ()
+ "Separator regexp."
+ (or (car-safe crm-separator) crm-separator))
+
;; this function evolved from a posting by Stefan Monnier
(defun crm--collection-fn (string predicate flag)
"Function used by `completing-read-multiple' to compute completion values.
@@ -122,7 +140,7 @@ crm--collection-fn
Reference sections on “Programmed Completion” and “Basic Completion
Functions”."
(let ((beg 0))
- (while (string-match crm-separator string beg)
+ (while (string-match (crm--regexp) string beg)
(setq beg (match-end 0)))
(completion-table-with-context (substring string 0 beg)
crm-completion-table
@@ -135,11 +153,11 @@ crm--current-element
Return the element's boundaries as (START . END)."
(let ((bob (minibuffer-prompt-end)))
(cons (save-excursion
- (if (re-search-backward crm-separator bob t)
+ (if (re-search-backward (crm--regexp) bob t)
(match-end 0)
bob))
(save-excursion
- (if (re-search-forward crm-separator nil t)
+ (if (re-search-forward (crm--regexp) nil t)
(match-beginning 0)
(point-max))))))
@@ -195,7 +213,7 @@ crm-complete-and-exit
(lambda () (setq doexit t)))
(goto-char end)
(not (eobp))))
- (looking-at crm-separator))
+ (looking-at (crm--regexp)))
;; Skip to the next element.
(goto-char (match-end 0)))
(if doexit (exit-minibuffer))))
@@ -256,14 +274,16 @@ completing-read-multiple
(let* ((beg (save-excursion
(goto-char (minibuffer-prompt-end))
(or (search-forward start nil t)
- (search-forward-regexp crm-separator nil t)
+ (search-forward-regexp
+ (crm--regexp) nil t)
(minibuffer-prompt-end))))
(end (save-excursion
(goto-char (point-max))
(or (search-backward end nil t)
(progn
(goto-char beg)
- (search-forward-regexp crm-separator nil t))
+ (search-forward-regexp
+ (crm--regexp) nil t))
(point-max)))))
(completion--replace beg end choice))
(completion--replace start end choice))))
@@ -272,14 +292,22 @@ completing-read-multiple
(unless (eq require-match t) require-match))
(setq-local crm-completion-table table))
(setq input (read-from-minibuffer
- prompt initial-input map
+ (format-spec crm-prompt
+ (if (consp crm-separator)
+ `((?s . ,(nth 1 crm-separator))
+ (?d . ,(nth 2 crm-separator))
+ (?p . ,prompt))
+ `((?s . ,crm-separator)
+ (?d . "multi list")
+ (?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 ""))
(setq input (if (consp def) (car def) def)))
;; Remove empty strings in the list of read strings.
- (split-string input crm-separator t)))
+ (split-string input (crm--regexp) t)))
;; testing and debugging
;; (defun crm-init-test-environ ()
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-03 13:16 ` Eli Zaretskii
@ 2025-02-03 17:56 ` Juri Linkov
2025-02-03 18:37 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2025-02-03 17:56 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: mail, 76028, Stefan Kangas
>> > I propose to add such an indicator to CRM by default. Above I have
>> > chosen the tag "CRM" for its shortness, but a more user friendly
>> > solution might require a longer more descriptive name. Furthermore the
>> > code above extracts the separator from the regular expression
>> > `crm-separator', which is not robust for all separators.
>>
>> How about " [comma-separated list] "?
>
> Or maybe "Describe face (FACE1[,FACE2[,...]]): "
I see no more descriptive prompt that providing an example,
maybe with lower-case like all faces:
Describe face (face1,face2,...):
A more generalized prompt would make this less clear, e.g.
Describe face (separator ‘,’):
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-03 17:56 ` Juri Linkov
@ 2025-02-03 18:37 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-04 7:54 ` Juri Linkov
0 siblings, 1 reply; 13+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-03 18:37 UTC (permalink / raw)
To: Juri Linkov; +Cc: Eli Zaretskii, 76028, Stefan Kangas
Juri Linkov <juri@linkov.net> writes:
>>> > I propose to add such an indicator to CRM by default. Above I have
>>> > chosen the tag "CRM" for its shortness, but a more user friendly
>>> > solution might require a longer more descriptive name. Furthermore the
>>> > code above extracts the separator from the regular expression
>>> > `crm-separator', which is not robust for all separators.
>>>
>>> How about " [comma-separated list] "?
>>
>> Or maybe "Describe face (FACE1[,FACE2[,...]]): "
>
> I see no more descriptive prompt that providing an example,
> maybe with lower-case like all faces:
>
> Describe face (face1,face2,...):
>
> A more generalized prompt would make this less clear, e.g.
>
> Describe face (separator ‘,’):
Giving an example does not solve the general issue of a uniform CRM
indication for all `completing-read-multiple' calls. In the Emacs code
base `completing-read-multiple' is not used widely but it is used in
other packages, which we cannot update at once.
I find Stefan's suggestion of [comma-separated list] quite nice. See the
patch I have sent in the other mail. Maybe we could use the
[comma-separated list] indicator as fallback if a
`completing-read-multiple' call does not provide examples on its own?
Another possibility might be to use the completion category and the
separator string and convert that to an example, e.g., category face
would yield the prompt "Describe face (face1,face2,...):".
Daniel
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-03 18:37 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-02-04 7:54 ` Juri Linkov
2025-02-04 8:28 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2025-02-04 7:54 UTC (permalink / raw)
To: Daniel Mendler; +Cc: Eli Zaretskii, 76028, Stefan Kangas
>> Describe face (face1,face2,...):
>>
>> A more generalized prompt would make this less clear, e.g.
>>
>> Describe face (separator ‘,’):
>
> Giving an example does not solve the general issue of a uniform CRM
> indication for all `completing-read-multiple' calls. In the Emacs code
> base `completing-read-multiple' is not used widely but it is used in
> other packages, which we cannot update at once.
Wouldn't addition of more text to the prompt break these packages
in some way? Maybe only those that rely on the fixed format
like minibuf-eldef.el that is quite rare.
> I find Stefan's suggestion of [comma-separated list] quite nice. See the
> patch I have sent in the other mail. Maybe we could use the
> [comma-separated list] indicator as fallback if a
> `completing-read-multiple' call does not provide examples on its own?
The only problem with the patch is that it would be better
to leave the existing format of the variable 'crm-separator'
to avoid possible backward-compatibility problems,
and then add a new variable or two for the separator
and its description.
> Another possibility might be to use the completion category and the
> separator string and convert that to an example, e.g., category face
> would yield the prompt "Describe face (face1,face2,...):".
Maybe then it's possible to provide the separator and its description
in the metadata?
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-04 7:54 ` Juri Linkov
@ 2025-02-04 8:28 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-04 18:16 ` Juri Linkov
0 siblings, 1 reply; 13+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-04 8:28 UTC (permalink / raw)
To: Juri Linkov; +Cc: Eli Zaretskii, 76028, Stefan Kangas
Juri Linkov <juri@linkov.net> writes:
>>> Describe face (face1,face2,...):
>>>
>>> A more generalized prompt would make this less clear, e.g.
>>>
>>> Describe face (separator ‘,’):
>>
>> Giving an example does not solve the general issue of a uniform CRM
>> indication for all `completing-read-multiple' calls. In the Emacs code
>> base `completing-read-multiple' is not used widely but it is used in
>> other packages, which we cannot update at once.
>
> Wouldn't addition of more text to the prompt break these packages
> in some way? Maybe only those that rely on the fixed format
> like minibuf-eldef.el that is quite rare.
I have not seen many such packages which rely on the prompt format, but
yes, one should check the ones like minibuf-eldef.el. I have used my
[CRM,] indicator advice for a long time without big problems.
>> I find Stefan's suggestion of [comma-separated list] quite nice. See the
>> patch I have sent in the other mail. Maybe we could use the
>> [comma-separated list] indicator as fallback if a
>> `completing-read-multiple' call does not provide examples on its own?
>
> The only problem with the patch is that it would be better
> to leave the existing format of the variable 'crm-separator'
> to avoid possible backward-compatibility problems,
> and then add a new variable or two for the separator
> and its description.
Yes, the change of format could be a problem. However if one uses
multiple variables one can easily forget to bind or configure them
together, which leads to bugs or an inconsistency. Currently there is
code, also third-party code, which let-binds a custom crm-separator but
of course not the other variables, such that there would be an
inconsistency immediately if we introduce the new variables. Therefore I
would stick to a single variable. We could also introduce a new variable
crm-config with the proposed list format which is used if crm-separator
is nil. crm-separator will be nil by default and marked obsolete.
Another more tricky approach would be to attach text properties to
crm-separator which carry the additional data. This would be backward-
and forward-compatible also for third-party code, but maybe not very
elegant. What do you think?
>> Another possibility might be to use the completion category and the
>> separator string and convert that to an example, e.g., category face
>> would yield the prompt "Describe face (face1,face2,...):".
>
> Maybe then it's possible to provide the separator and its description
> in the metadata?
This would be more intrusive. Also the question is if the crm-separator
is truly bound to the completion table, or if it should be possible to
reuse the same table with different separators.
Daniel
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-04 8:28 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-02-04 18:16 ` Juri Linkov
2025-02-04 18:57 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2025-02-04 18:16 UTC (permalink / raw)
To: Daniel Mendler; +Cc: Eli Zaretskii, 76028, Stefan Kangas
> Another more tricky approach would be to attach text properties to
> crm-separator which carry the additional data. This would be backward-
> and forward-compatible also for third-party code, but maybe not very
> elegant. What do you think?
Although text properties are not customizable, this should not be
a problem for third-party packages. And crm-separator is a variable,
not a defcustom.
>>> Another possibility might be to use the completion category and the
>>> separator string and convert that to an example, e.g., category face
>>> would yield the prompt "Describe face (face1,face2,...):".
>>
>> Maybe then it's possible to provide the separator and its description
>> in the metadata?
>
> This would be more intrusive. Also the question is if the crm-separator
> is truly bound to the completion table, or if it should be possible to
> reuse the same table with different separators.
Then it's possible to override the separator. But anyway it seems
text properties are the least intrusive approach.
^ permalink raw reply [flat|nested] 13+ messages in thread
* bug#76028: 31; completing-read-multiple: Add prompt indicator
2025-02-04 18:16 ` Juri Linkov
@ 2025-02-04 18:57 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 0 replies; 13+ messages in thread
From: Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-04 18:57 UTC (permalink / raw)
To: Juri Linkov; +Cc: Eli Zaretskii, 76028, Stefan Kangas
[-- Attachment #1: Type: text/plain, Size: 1184 bytes --]
Juri Linkov <juri@linkov.net> writes:
>> Another more tricky approach would be to attach text properties to
>> crm-separator which carry the additional data. This would be backward-
>> and forward-compatible also for third-party code, but maybe not very
>> elegant. What do you think?
>
> Although text properties are not customizable, this should not be
> a problem for third-party packages. And crm-separator is a variable,
> not a defcustom.
>
>>>> Another possibility might be to use the completion category and the
>>>> separator string and convert that to an example, e.g., category face
>>>> would yield the prompt "Describe face (face1,face2,...):".
>>>
>>> Maybe then it's possible to provide the separator and its description
>>> in the metadata?
>>
>> This would be more intrusive. Also the question is if the crm-separator
>> is truly bound to the completion table, or if it should be possible to
>> reuse the same table with different separators.
>
> Then it's possible to override the separator. But anyway it seems
> text properties are the least intrusive approach.
It seems so. The patch gets quite short. I have attached the updated
patch to this mail.
Daniel
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-completing-read-multiple-CRM-indication-and-prompt-c.patch --]
[-- Type: text/x-diff, Size: 3096 bytes --]
From 0bc194f982a7fa74ab66f0449a5a3bd651a4b300 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <mail@daniel-mendler.de>
Date: Mon, 3 Feb 2025 16:39:49 +0100
Subject: [PATCH] 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.
---
lisp/emacs-lisp/crm.el | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/lisp/emacs-lisp/crm.el b/lisp/emacs-lisp/crm.el
index 454c3e85074..3a4e5a944ae 100644
--- a/lisp/emacs-lisp/crm.el
+++ b/lisp/emacs-lisp/crm.el
@@ -79,9 +79,22 @@
(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 variable `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 'string
+ :group 'minibuffer
+ :version "31.1")
(defvar-keymap crm-local-completion-map
:doc "Local keymap for minibuffer multiple input with completion.
@@ -272,7 +285,14 @@ completing-read-multiple
(unless (eq require-match t) require-match))
(setq-local crm-completion-table table))
(setq input (read-from-minibuffer
- prompt initial-input map
+ (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.
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-02-04 18:57 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-03 9:27 bug#76028: 31; completing-read-multiple: Add prompt indicator Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 12:48 ` Eli Zaretskii
2025-02-03 13:02 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 13:03 ` Stefan Kangas
2025-02-03 13:09 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 15:51 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 13:16 ` Eli Zaretskii
2025-02-03 17:56 ` Juri Linkov
2025-02-03 18:37 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-04 7:54 ` Juri Linkov
2025-02-04 8:28 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-04 18:16 ` Juri Linkov
2025-02-04 18:57 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.