Subject: Re: bug#27236: 25.1; grep: nonsensical default commands offered

From: Lars Ingebrigtsen <[email-masked]>
Date: Tue, 17 May 2022 21:00:38 +0200

Yuri Khan <[email-masked]> writes:

> The call sequence is as follows:
>
> * ‘grep’ computes the initial command and the first default command.
> * ‘grep’ calls ‘read-shell-command’.
> * ‘read-shell-command’ calls ‘read-from-minibuffer’ with a setup hook
> that binds ‘minibuffer-default-add-function’ to
> ‘minibuffer-default-add-shell-commands’.
> * ‘minibuffer-default-add-shell-commands’ interprets the provided
> default command as a file name and consults
> ‘mailcap-file-default-commands’ for commands applicable to that file
> name.
> * The default command has no file extension, so
> ‘mailcap-file-default-commands’ assumes it is a text/plain file and
> returns a list of text editors and viewers.

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

Looking at this call chain, there doesn't seem to be any easy way to
defeat this behaviour -- in this case, we really don't want any of the
guesses from minibuffer-default-add-shell-commands/mailcap, I think?

So perhaps we should add a variable to inhibit this action?

On the other hand, the mailcap function is called with something that
"clearly" isn't a file, namely:

(mailcap-file-default-commands '("grep --color=auto -nH --null '' "))
=> ("/usr/bin/emacs -nw")

So perhaps we could introduce some logic to this mailcap function to
detect that we don't really have a file name here.

So I've now done the latter in Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no