Subject: Re: bug#35564: [PATCH v4] Tweak dired warning about "wildcard" characters

From: Kévin Le Gouguec <[email-masked]>
Date: Fri, 09 Aug 2019 14:43:12 +0200

Juri Linkov <[email-masked]> writes:

> I use the substitution feature in dired-do-shell-command quite rarely,
> but today I needed to use it, and it strikes as partly unusable
> and confusing.

Welcome to the club :)

> 2. The current question is too ambiguous:
>
>   Confirm--do you mean to use ‘?’ as a wildcard? (y or n)
>
> A wildcard can mean both dired substitution and shell substitution.
> A better question should use the same terms as documented in the
> docstring of `dired-do-shell-command', i.e. "marked files", "file list".
> So a better question would be:
>
>   Confirm--do you mean to substitute ‘?’ with marked files? (y or n)
>
> Or something similar that makes clear that substitution applies
> to dired files, not files matched by shell.

Mmm, I think that the current prompt *does* use the same terms as
documented in the docstring: it simply mistakenly assumes that if '?'
and '*' are not "isolated", the shell will unconditionally process them
as wildcards.  It is a heuristic that fails to consider that '?' and '*'
may be quoted or escaped.

So with this prompt, "yes" means "yes, I want the shell to (possibly)
substitute these characters", while "no" means "By Jove, what a silly
mistake I was about to make!  Thank you ever so much for catching it
Dired old chap!  Let me add some backquotes around this '?' so that you
can be sure I mean for you to substitute it for the marked files."

IIUC, your suggested prompt does not match what dired-do-shell-command
actually does: the function only ever substitutes '?' if it is
"isolated", i.e. surrounded with whitespace or backquotes.  Cf. the
docstring:

> ‘*’ and ‘?’ when not surrounded by whitespace nor ‘`’ have no special
> significance for ‘dired-do-shell-command’, and are passed through
> normally to the shell, but you must confirm first.

(Drew suggested that we may want to change *the code* to behave as your
prompt suggests[1], I sketched a possible way to let the user select
which occurrences to substitute[2], but did not act on it as AFAICT this
use-case is already handled by adding backquotes around '?')

>> What bothers me is that even if we can assert #2, nothing guarantees
>> that these colors will be distinguishable *to the user* (who may
>> e.g. have some form of color blindness).  It would therefore be nice if
>> this user could force Emacs to use ^ markers; I guess that would involve
>> a new variable.
>
> As was already discussed in this thread, using (:inherit '(warning underline))
> will solve this problem and improve accessibility.  So there will be
> no need in multi-line prompt when using underline face attribute.

Mmm.  I went to a TTY to check how (:inherit '(underline)) looks.  Since
(display-supports-face-attributes-p '(:underline t)) is nil there, the
"underline" face is defined as (:weight bold), which merely makes the
foreground color brighter.  So (:inherit '(warning underline)) amounts
to just (:inherit '(warning)).

Perhaps (display-supports-face-attributes-p '(:underline t)) can be used
to decide whether we need to add ^ markers.

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35564#89
[2] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28969#19