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

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Severity: minor; Reported by: Drew Adams <drew.adams@HIDDEN>; dated Sat, 12 Apr 2014 16:07:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 17251 <at> debbugs.gnu.org:


Received: (at 17251) by debbugs.gnu.org; 12 Apr 2014 16:28:46 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Apr 12 12:28:46 2014
Received: from localhost ([127.0.0.1]:46384 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1WZ0nN-00027j-6Z
	for submit <at> debbugs.gnu.org; Sat, 12 Apr 2014 12:28:45 -0400
Received: from userp1040.oracle.com ([156.151.31.81]:22726)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <drew.adams@HIDDEN>) id 1WZ0nK-00027Q-ES
 for 17251 <at> debbugs.gnu.org; Sat, 12 Apr 2014 12:28:43 -0400
Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238])
 by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id
 s3CGSZKj010313
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
 for <17251 <at> debbugs.gnu.org>; Sat, 12 Apr 2014 16:28:36 GMT
Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86])
 by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s3CGSXmF025475
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
 for <17251 <at> debbugs.gnu.org>; Sat, 12 Apr 2014 16:28:35 GMT
Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17])
 by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id s3CGSXb4000391
 for <17251 <at> debbugs.gnu.org>; Sat, 12 Apr 2014 16:28:33 GMT
MIME-Version: 1.0
Message-ID: <0628ccb7-0ee6-4522-bfba-bc853c5e8985@default>
Date: Sat, 12 Apr 2014 09:28:34 -0700 (PDT)
From: Drew Adams <drew.adams@HIDDEN>
To: 17251 <at> debbugs.gnu.org
Subject: RE: bug#17251: 24.4.50; `dired-guess-default': wrong logic
References: <97d70b54-93f6-4247-9a29-68145f9d8965@default>
In-Reply-To: <97d70b54-93f6-4247-9a29-68145f9d8965@default>
X-Priority: 3
X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8  (707110) [OL
 12.0.6691.5000 (x86)]
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Source-IP: acsinet22.oracle.com [141.146.126.238]
X-Spam-Score: -2.7 (--)
X-Debbugs-Envelope-To: 17251
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.7 (--)

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 REGEX=
P
;;;   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@HIDDEN:
bug#17251; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Apr 2014 16:06:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Apr 12 12:06:22 2014
Received: from localhost ([127.0.0.1]:46359 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1WZ0Rh-0001US-LK
	for submit <at> debbugs.gnu.org; Sat, 12 Apr 2014 12:06:22 -0400
Received: from eggs.gnu.org ([208.118.235.92]:49715)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <drew.adams@HIDDEN>) id 1WZ0Rf-0001UA-4I
 for submit <at> debbugs.gnu.org; Sat, 12 Apr 2014 12:06:20 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <drew.adams@HIDDEN>) id 1WZ0RP-0002Hk-Gs
 for submit <at> debbugs.gnu.org; Sat, 12 Apr 2014 12:06:13 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([208.118.235.17]:46347)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <drew.adams@HIDDEN>) id 1WZ0RP-0002Hg-EI
 for submit <at> debbugs.gnu.org; Sat, 12 Apr 2014 12:06:03 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:51427)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <drew.adams@HIDDEN>) id 1WZ0RG-0006Dj-L3
 for bug-gnu-emacs@HIDDEN; Sat, 12 Apr 2014 12:06:03 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <drew.adams@HIDDEN>) id 1WZ0R7-0002C8-UW
 for bug-gnu-emacs@HIDDEN; Sat, 12 Apr 2014 12:05:54 -0400
Received: from userp1040.oracle.com ([156.151.31.81]:24749)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <drew.adams@HIDDEN>) id 1WZ0R7-0002AG-Ms
 for bug-gnu-emacs@HIDDEN; Sat, 12 Apr 2014 12:05:45 -0400
Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93])
 by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id
 s3CG5guw029446
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
 for <bug-gnu-emacs@HIDDEN>; Sat, 12 Apr 2014 16:05:43 GMT
Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86])
 by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s3CG5fBS023313
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
 for <bug-gnu-emacs@HIDDEN>; Sat, 12 Apr 2014 16:05:42 GMT
Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17])
 by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id s3CG5fEA003098
 for <bug-gnu-emacs@HIDDEN>; Sat, 12 Apr 2014 16:05:41 GMT
MIME-Version: 1.0
Message-ID: <97d70b54-93f6-4247-9a29-68145f9d8965@default>
Date: Sat, 12 Apr 2014 09:05:42 -0700 (PDT)
From: Drew Adams <drew.adams@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 24.4.50; `dired-guess-default': wrong logic
X-Priority: 3
X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8  (707110) [OL
 12.0.6691.5000 (x86)]
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Source-IP: ucsinet21.oracle.com [156.151.31.93]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.17
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

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@HIDDEN
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=3D/c/Devel/emacs/snapshot/trunk
 --enable-checking=3Dyes,glyphs 'CFLAGS=3D-O0 -g3'
 LDFLAGS=3D-Lc:/Devel/emacs/lib 'CPPFLAGS=3D-DGC_MCHECK=3D1
 -Ic:/Devel/emacs/include''




Acknowledgement sent to Drew Adams <drew.adams@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#17251; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 31 Oct 2014 17:00:04 UTC

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