GNU bug report logs - #17251
24.4.50; `dired-guess-default': wrong logic

Previous Next

Package: emacs;

Reported by: Drew Adams <drew.adams <at> oracle.com>

Date: Sat, 12 Apr 2014 16:07:01 UTC

Severity: minor

Tags: fixed

Found in version 24.4.50

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 17251 in the body.
You can then email your comments to 17251 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#17251; Package emacs. (Sat, 12 Apr 2014 16:07:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Drew Adams <drew.adams <at> oracle.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 12 Apr 2014 16:07:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4.50; `dired-guess-default': wrong logic
Date: Sat, 12 Apr 2014 09:05:42 -0700 (PDT)
The logic in the implementation of `dired-guess-default' is wrong, or
at least not optimal.  And it is not what users are entitled to expect,
based on the doc of `dired-guess-shell-alist-user'.

If this logic is kept as is (which would be unfortunate), then at least
there is a doc bug here, because the doc of user option
`dired-guess-shell-alist-user' does not reflect this logic.  Users will
thus get behavior that does not correspond to what they expect based on
the doc.

The doc gives the impression that if you have multiple entries in the
option value that use different regexps with the same command, these
will be used together, IOW, any and all of them will be associated
with the same command.

That is the whole point of this user option (and also of variable
`dired-guess-shell-alist-default'): to associate file names with one
or more commands.  The regexps are only a handy means to that end.

For example, from the doc, one can reasonably expect that if the
option value is this:

(("\\.png\\'" "foo.exe") ("\\.jpg\\'" "foo.exe"))

then command "foo.exe" can be used for a list of files such as:

("toto.png" "tata.jpg")

But this is not in fact what the behavior is.  To get that expected
behavior, the user would have to combine those entries into a single
entry such as this:

(("\\.\\(png\\|jpg\\)\\'" "foo.exe"))

This is not at all clear from the doc.  And it means extra work and
better knowledge of regexps on the part of users.

The culprit code is this part of `dired-guess-default':

;; If more than one file, see if all of FILES match regular expression.
(while (and flist (string-match-p regexp (car flist)))
  (setq flist (cdr flist)))

IOW, the code expects each of the files in the list of candidates to
match the given regexp.

In the case above, this means that the regexp "\\.png\\'" would be
tested against each of the files ("toto.png" "tata.jpg"), it would fail,
and so the command "foo.exe", which the user has explicitly configured
as appropriate for both PNG files and JPG files, would not be available.

IOW, instead of working off of the regexp only, the code should work off
of the associated COMMANDS.  What is important here is the COMMAND,
"foo.exe", and it is clearly (according to the user) appropriate for
all files whose names match either regexp (i.e., all PNG and JPG files).

IOW, the implementation is overly restrictive.  The true requirement is
that each of the file names in the list of candidates must be mapped to
the SAME COMMAND via *some* regexp.  The requirement is not (should not
be) that each of the file names must match the SAME REGEXP.

It is the COMMAND that is important.  The regexps are just a means of
associating file names with commands.

If you do not fix the implementation logic of `dired-guess-default'
(which would be unfortunate), then please at least fix the doc string of
option `dired-guess-shell-alist-user' so that it tells users that they
MUST COMBINE regexps that are mapped to the same command, i.e., they
must come up with a single regexp for the given command.  A list of
files whose names are associated with the same command via different
regexps will not be handled by that command.


In GNU Emacs 24.4.50.1 (i686-pc-mingw32)
 of 2014-04-08 on ODIEONE
Bzr revision: 116956 dancol <at> dancol.org-20140408123940-knoyutxt4l8ws7qm
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=/c/Devel/emacs/snapshot/trunk
 --enable-checking=yes,glyphs 'CFLAGS=-O0 -g3'
 LDFLAGS=-Lc:/Devel/emacs/lib 'CPPFLAGS=-DGC_MCHECK=1
 -Ic:/Devel/emacs/include''




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17251; Package emacs. (Sat, 12 Apr 2014 16:29:02 GMT) Full text and rfc822 format available.

Message #8 received at 17251 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: 17251 <at> debbugs.gnu.org
Subject: RE: bug#17251: 24.4.50; `dired-guess-default': wrong logic
Date: Sat, 12 Apr 2014 09:28:34 -0700 (PDT)
In fact, at the top of the section of `dired-x.el' which implements this,
you will find an English description of the overly restrictive logic:

;;; GUESS SHELL COMMAND.

;; Brief Description:
;;;
;; * `dired-do-shell-command' is bound to `!' by dired.el.
;;;
;; * `dired-guess-shell-command' provides smarter defaults for
;;;    dired-aux.el's `dired-read-shell-command'.
;;;
;; * `dired-guess-shell-command' calls `dired-guess-default' with list of
;;;    marked files.
;;;
;; * Parse `dired-guess-shell-alist-user' and
;;;   `dired-guess-shell-alist-default' (in that order) for the first REGEXP
;;;   that matches the first file in the file list.
;;;
;; * If the REGEXP matches all the entries of the file list then evaluate
;;;   COMMAND, which is either a string or a Lisp expression returning a
;;;   string.  COMMAND may be a list of commands.
;;;
;; * Return this command to `dired-guess-shell-command' which prompts user
;;;   with it.  The list of commands is put into the list of default values.
;;;   If a command is used successfully then it is stored permanently in
;;;   `dired-shell-command-history'.

The inappropriate part of the logic is described in the 5th bullet.
The logic should not be to require that a single REGEXP (the first regexp)
"matches all the entries of the file list" in order to find the appropriate
COMMAND.  It should be to require that all files in the file list are
associated with the same COMMAND.  Individual files in the list should be
able to be associated with the COMMAND in different ways (i.e., using
different regexps).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17251; Package emacs. (Sat, 29 May 2021 05:51:01 GMT) Full text and rfc822 format available.

Message #11 received at 17251 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 17251 <at> debbugs.gnu.org
Subject: Re: bug#17251: 24.4.50; `dired-guess-default': wrong logic
Date: Sat, 29 May 2021 07:49:57 +0200
Drew Adams <drew.adams <at> oracle.com> writes:

> But this is not in fact what the behavior is.  To get that expected
> behavior, the user would have to combine those entries into a single
> entry such as this:
>
> (("\\.\\(png\\|jpg\\)\\'" "foo.exe"))
>
> This is not at all clear from the doc. 

I've now mentioned this in the doc string.

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




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 29 May 2021 05:51:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 17251 <at> debbugs.gnu.org and Drew Adams <drew.adams <at> oracle.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 29 May 2021 05:51:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 26 Jun 2021 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 276 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.