GNU bug report logs - #25942
26.0.50; dired-mark-extension prepend '.' to suffix if not present

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Fri, 3 Mar 2017 03:41:01 UTC

Severity: wishlist

Tags: patch

Found in version 26.0.50

Done: Tino Calancha <tino.calancha <at> gmail.com>

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 25942 in the body.
You can then email your comments to 25942 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#25942; Package emacs. (Fri, 03 Mar 2017 03:41:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tino Calancha <tino.calancha <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 03 Mar 2017 03:41:02 GMT) Full text and rfc822 format available.

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

From: Tino Calancha <tino.calancha <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.0.50; dired-mark-extension prepend '.' to suffix if not present
Date: Fri, 03 Mar 2017 12:40:33 +0900
emacs -Q /tmp

(require 'dired-x)
(require 'ert)
;; Evaluate following sexp:
(let ((dirs '("Public" "Music"))
      (files '(".bashrc" "bar.c" "foo.c"))
      (dir (make-temp-file "Bug25942" 'dir)))
  (unwind-protect
      (progn
        (dolist (d dirs)
          (make-directory (expand-file-name d dir)))
        (dolist (f files)
          (write-region nil nil (expand-file-name f dir)))
        (dired dir)
        (dired-mark-extension "c")
        (should (= 2 (length (dired-get-marked-files)))))
    (delete-directory dir 'recursive)))
  
IMO, in this example looks better if just those files ending with
'.c' are marked i.e., to not mark 'Public' or 'Music'.
If the user really wish to mark all files ending with 'c', then would
be easy to do:
% M c \ ' RET




--8<-----------------------------cut here---------------start------------->8---
From a91a7ccdb98eff3ad520092944e6b23042d42e8f Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha <at> gmail.com>
Date: Fri, 3 Mar 2017 12:12:53 +0900
Subject: [PATCH] Automaticaly prepend a '.' to extension if not present

* lisp/dired-x.el (dired-mark-extension): Bug#25942.
---
 lisp/dired-x.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index 6c8fb0e7da..eb228ce541 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -335,7 +335,7 @@ dired-extra-startup
 ;; Mark files with some extension.
 (defun dired-mark-extension (extension &optional marker-char)
   "Mark all files with a certain EXTENSION for use in later commands.
-A `.' is *not* automatically prepended to the string entered.
+A `.' before EXTENSION is automatically prepended when not present.
 EXTENSION may also be a list of extensions instead of a single one.
 Optional MARKER-CHAR is marker to use.
 Interactively, ask for EXTENSION.
@@ -371,7 +371,10 @@ dired-mark-extension
   (dired-mark-files-regexp
    (concat ".";; don't match names with nothing but an extension
            "\\("
-           (mapconcat 'regexp-quote extension "\\|")
+           (mapconcat (lambda (x)
+                        (regexp-quote
+                         (if (string-prefix-p "." x) x (concat "." x))))
+                      extension "\\|")
            "\\)$")
    marker-char))
 
-- 
2.11.0

--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.22.8)
 of 2017-03-03
Repository revision: 55c0c3e31bc3dff83753cdba6288228bd025ac84




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25942; Package emacs. (Sun, 26 Mar 2017 22:45:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 25942 <at> debbugs.gnu.org
Subject: Re: bug#25942: 26.0.50;
 dired-mark-extension prepend '.' to suffix if not present
Date: Mon, 27 Mar 2017 01:40:28 +0300
> emacs -Q /tmp
>
> (require 'dired-x)
> (require 'ert)
> ;; Evaluate following sexp:
> (let ((dirs '("Public" "Music"))
>       (files '(".bashrc" "bar.c" "foo.c"))
>       (dir (make-temp-file "Bug25942" 'dir)))
>   (unwind-protect
>       (progn
>         (dolist (d dirs)
>           (make-directory (expand-file-name d dir)))
>         (dolist (f files)
>           (write-region nil nil (expand-file-name f dir)))
>         (dired dir)
>         (dired-mark-extension "c")
>         (should (= 2 (length (dired-get-marked-files)))))
>     (delete-directory dir 'recursive)))
>
> IMO, in this example looks better if just those files ending with
> '.c' are marked i.e., to not mark 'Public' or 'Music'.

Is this a backward-compatible change?  If not, then maybe better
prepend ‘.’ only to the default value for interactive uses?  So users
will get the right result when using ‘M-x dired-mark-extension RET RET’.
But for the programmatic uses it's the responsibility of the caller to
supply the right suffix in ‘(dired-mark-extension ".c")’




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25942; Package emacs. (Mon, 27 Mar 2017 01:31:01 GMT) Full text and rfc822 format available.

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

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 25942 <at> debbugs.gnu.org, Tino Calancha <tino.calancha <at> gmail.com>
Subject: Re: bug#25942: 26.0.50; dired-mark-extension prepend '.' to suffix
 if not present
Date: Mon, 27 Mar 2017 10:30:26 +0900 (JST)
[Message part 1 (text/plain, inline)]

On Mon, 27 Mar 2017, Juri Linkov wrote:

>> emacs -Q /tmp
>>
>> (require 'dired-x)
>> (require 'ert)
>> ;; Evaluate following sexp:
>> (let ((dirs '("Public" "Music"))
>>       (files '(".bashrc" "bar.c" "foo.c"))
>>       (dir (make-temp-file "Bug25942" 'dir)))
>>   (unwind-protect
>>       (progn
>>         (dolist (d dirs)
>>           (make-directory (expand-file-name d dir)))
>>         (dolist (f files)
>>           (write-region nil nil (expand-file-name f dir)))
>>         (dired dir)
>>         (dired-mark-extension "c")
>>         (should (= 2 (length (dired-get-marked-files)))))
>>     (delete-directory dir 'recursive)))
>>
>> IMO, in this example looks better if just those files ending with
>> '.c' are marked i.e., to not mark 'Public' or 'Music'.
>
> Is this a backward-compatible change?
Yes, it is; but it makes a better global picture when we consider
this function together with `file-name-extension' and
`file-name-sans-extension' (More below).

> If not, then maybe better
> prepend ‘.’ only to the default value for 
> interactive uses?  So users
> will get the right result when using ‘M-x dired-mark-extension RET RET’.
> But for the programmatic uses it's the responsibility of the caller to
> supply the right suffix in ‘(dired-mark-extension ".c")’
The problem is that this command has a concept of 'extension' different 
than the two other functions mentioned above.
[Using same names than in my code snippet]:

(file-name-extension "Music")
=> nil
(equal "Music" (file-name-sans-extension "Music"))
=> t

(file-name-extension "foo.c")
=> "c"
;; Note: this command consider extension "c" (without period).

(dired-mark-extension (file-name-extension "foo.c"))
;; This marks all the files, i.e., also marks "Music" and "Public".

IMHO the correct behaviour for
(dired-mark-extension (file-name-extension "foo.c"))
would be to mark those files satisfying
(lambda (f) (equal (file-name-extension f) (file-name-extension "foo.c")))

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25942; Package emacs. (Mon, 27 Mar 2017 01:33:02 GMT) Full text and rfc822 format available.

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

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 25942 <at> debbugs.gnu.org, Juri Linkov <juri <at> linkov.net>
Subject: Re: bug#25942: 26.0.50; dired-mark-extension prepend '.' to suffix
 if not present
Date: Mon, 27 Mar 2017 10:32:11 +0900 (JST)

On Mon, 27 Mar 2017, Tino Calancha wrote:

>
>
> On Mon, 27 Mar 2017, Juri Linkov wrote:
>
>>> emacs -Q /tmp
>>> 
>>> (require 'dired-x)
>>> (require 'ert)
>>> ;; Evaluate following sexp:
>>> (let ((dirs '("Public" "Music"))
>>>       (files '(".bashrc" "bar.c" "foo.c"))
>>>       (dir (make-temp-file "Bug25942" 'dir)))
>>>   (unwind-protect
>>>       (progn
>>>         (dolist (d dirs)
>>>           (make-directory (expand-file-name d dir)))
>>>         (dolist (f files)
>>>           (write-region nil nil (expand-file-name f dir)))
>>>         (dired dir)
>>>         (dired-mark-extension "c")
>>>         (should (= 2 (length (dired-get-marked-files)))))
>>>     (delete-directory dir 'recursive)))
>>> 
>>> IMO, in this example looks better if just those files ending with
>>> '.c' are marked i.e., to not mark 'Public' or 'Music'.
>> 
>> Is this a backward-compatible change?
> Yes, it is; but it makes a better global picture when we consider
> this function together with `file-name-extension' and
> `file-name-sans-extension' (More below).
Sorry, i meant 'No, it isn't; but it makes a better ...'




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25942; Package emacs. (Mon, 27 Mar 2017 02:36:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 25942 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#25942: 26.0.50;
 dired-mark-extension prepend '.' to suffix if not present
Date: Mon, 27 Mar 2017 05:35:45 +0300
> From: Tino Calancha <tino.calancha <at> gmail.com>
> Date: Mon, 27 Mar 2017 10:30:26 +0900 (JST)
> Cc: 25942 <at> debbugs.gnu.org, Tino Calancha <tino.calancha <at> gmail.com>
> 
> The problem is that this command has a concept of 'extension' different 
> than the two other functions mentioned above.

Then how about providing a new command, named dired-mark-suffix or
somesuch, which would work like dired-mark-extension does now?  Or
maybe have an optional argument, activated by prefix arg to
dired-mark-extension, to do that?  That would leave users a way to get
back the old behavior, if they want.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25942; Package emacs. (Mon, 27 Mar 2017 05:35:02 GMT) Full text and rfc822 format available.

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

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 25942 <at> debbugs.gnu.org, tino.calancha <at> gmail.com, juri <at> linkov.net
Subject: Re: bug#25942: 26.0.50;
 dired-mark-extension prepend '.' to suffix if not present
Date: Mon, 27 Mar 2017 14:34:30 +0900
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Tino Calancha <tino.calancha <at> gmail.com>
>> Date: Mon, 27 Mar 2017 10:30:26 +0900 (JST)
>> Cc: 25942 <at> debbugs.gnu.org, Tino Calancha <tino.calancha <at> gmail.com>
>> 
>> The problem is that this command has a concept of 'extension' different 
>> than the two other functions mentioned above.
>
> Then how about providing a new command, named dired-mark-suffix or
> somesuch, which would work like dired-mark-extension does now?  Or
> maybe have an optional argument, activated by prefix arg to
> dired-mark-extension, to do that?  That would leave users a way to get
> back the old behavior, if they want.
I like your first suggestion.  The second is less convenient because we
already use prefices 'C-u' and 'C-u C-u'.

The following patch adds a new command 'dired-mark-suffix', and
modifies 'dired-mark-extension'.
I) dired-mark-suffix: it behaves as 'dired-mark-extension' used to do,
   i.e., don't prepends any '.' to the user input.
II) dired-mark-extension: It prepends '.' to EXTENSION when not present.
    This way became consistent with 'file-name-extension', that is, if
    (file-name-extension FILE) returns nil, then 'dired-mark-extension'
    will not mark FILE.

--8<-----------------------------cuthere---------------start------------->8---
From e995e2ab6ffbd1ef94b9548d492394f9283fe490 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha <at> gmail.com>
Date: Mon, 27 Mar 2017 14:31:35 +0900
Subject: [PATCH] dired-mark-suffix: New command

Now dired-mark-extension prepends '.' to extension when not present.
Add the new command dired-mark-suffix to preserve the previous
behaviour (Bug#25942).
* lisp/dired-x.el (dired-mark-suffix): New command;
mark files ending in a given suffix.
(dired--mark-suffix-interactive-spec): New defun.
(dired-mark-extension, dired-mark-suffix): Use it.
* doc/misc/dired-x.texi (Advanced Mark Commands): Update manual.
; * etc/NEWS (Changes in Specialized Modes and Packages in Emacs 26.1):
; Mention these changes.
---
 doc/misc/dired-x.texi | 16 +++++++++--
 etc/NEWS              |  5 ++++
 lisp/dired-x.el       | 80 ++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 73 insertions(+), 28 deletions(-)

diff --git a/doc/misc/dired-x.texi b/doc/misc/dired-x.texi
index 1e6f4b03bb..369b2da42a 100644
--- a/doc/misc/dired-x.texi
+++ b/doc/misc/dired-x.texi
@@ -721,8 +721,7 @@ Advanced Mark Commands
 @item dired-mark-extension
 @findex dired-mark-extension
 Mark all files with a certain extension for use in later commands.  A @samp{.}
-is not automatically prepended to the string entered, you must type it
-explicitly.
+is automatically prepended to the string entered when not present.
 If invoked with prefix argument @kbd{C-u}, this command unmark files instead.
 If called with the @kbd{C-u C-u} prefix, asks for a character to use
 as the marker, and marks files with it.
@@ -730,6 +729,19 @@ Advanced Mark Commands
 When called from Lisp, @var{extension} may also be a list of extensions
 and an optional argument @var{marker-char} specifies the marker used.
 
+@item dired-mark-suffix
+@findex dired-mark-suffix
+Mark all files with a certain suffix for use in later commands.  A @samp{.}
+is not automatically prepended to the string entered, you must type it
+explicitly.  This is different than @var{dired-mark-extension} which prepends
+a @samp{.} if not present.
+If invoked with prefix argument @kbd{C-u}, this command unmark files instead.
+If called with the @kbd{C-u C-u} prefix, asks for a character to use
+as the marker, and marks files with it.
+
+When called from Lisp, @var{suffix} may also be a list of suffices
+and an optional argument @var{marker-char} specifies the marker used.
+
 @item dired-flag-extension
 @findex dired-flag-extension
 Flag all files with a certain extension for deletion.  A @samp{.} is
diff --git a/etc/NEWS b/etc/NEWS
index cd98f53399..3839439a32 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -474,6 +474,11 @@ where to place point after C-c M-r and C-c M-s.
 ** Dired
 
 +++
+*** Command 'dired-mark-extension' now automatically prepends a '.' to the
+extension when not present.  The new command 'dired-mark-suffix' behaves
+similarly but it doesn't prepend a '.'.
+
++++
 *** A new option 'dired-always-read-filesystem' default to nil.
 If non-nil, buffers visiting files are reverted before search them;
 for instance, in 'dired-mark-files-containing-regexp' a non-nil value
diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index 6c8fb0e7da..a043784a75 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -332,46 +332,74 @@ dired-extra-startup
 
 ;;; EXTENSION MARKING FUNCTIONS.
 
+(defun dired--mark-suffix-interactive-spec ()
+  (let* ((default
+           (let ((file (dired-get-filename nil t)))
+             (when file
+               (file-name-extension file))))
+         (suffix
+          (read-string (format "%s extension%s: "
+                               (if (equal current-prefix-arg '(4))
+                                   "UNmarking"
+                                 "Marking")
+                               (if default
+                                   (format " (default %s)" default)
+                                 "")) nil nil default))
+         (marker
+          (pcase current-prefix-arg
+            ('(4) ?\s)
+            ('(16)
+             (let* ((dflt (char-to-string dired-marker-char))
+                    (input (read-string
+                            (format
+                             "Marker character to use (default %s): " dflt)
+                            nil nil dflt)))
+               (aref input 0)))
+            (_ dired-marker-char))))
+    (list suffix marker)))
+
 ;; Mark files with some extension.
 (defun dired-mark-extension (extension &optional marker-char)
   "Mark all files with a certain EXTENSION for use in later commands.
-A `.' is *not* automatically prepended to the string entered.
+A `.' before EXTENSION is automatically prepended when not present.
 EXTENSION may also be a list of extensions instead of a single one.
 Optional MARKER-CHAR is marker to use.
 Interactively, ask for EXTENSION.
 Prefixed with one C-u, unmark files instead.
 Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it."
   (interactive
-   (let* ((default
-            (let ((file (dired-get-filename nil t)))
-              (when file
-                (file-name-extension file))))
-          (suffix
-           (read-string (format "%s extension%s: "
-                                (if (equal current-prefix-arg '(4))
-                                    "UNmarking"
-                                  "Marking")
-                                (if default
-                                    (format " (default %s)" default)
-                                  "")) nil nil default))
-          (marker
-           (pcase current-prefix-arg
-             ('(4) ?\s)
-             ('(16)
-              (let* ((dflt (char-to-string dired-marker-char))
-                     (input (read-string
-                             (format
-                              "Marker character to use (default %s): " dflt)
-                             nil nil dflt)))
-                (aref input 0)))
-             (_ dired-marker-char))))
-     (list suffix marker)))
+   (dired--mark-suffix-interactive-spec))
   (or (listp extension)
       (setq extension (list extension)))
   (dired-mark-files-regexp
    (concat ".";; don't match names with nothing but an extension
            "\\("
-           (mapconcat 'regexp-quote extension "\\|")
+           (mapconcat (lambda (x)
+                        (regexp-quote
+                         (if (string-prefix-p "." x) x (concat "." x))))
+                      extension "\\|")
+           "\\)$")
+   marker-char))
+
+;; Mark files ending with some suffix.
+(defun dired-mark-suffix (suffix &optional marker-char)
+  "Mark all files with a certain SUFFIX for use in later commands.
+A `.' is *not* automatically prepended to the string entered;  see
+also `dired-mark-extension', which is similar but automatically
+prepends `.' when not present.
+SUFFIX may also be a list of suffices instead of a single one.
+Optional MARKER-CHAR is marker to use.
+Interactively, ask for SUFFIX.
+Prefixed with one C-u, unmark files instead.
+Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it."
+  (interactive
+   (dired--mark-suffix-interactive-spec))
+  (or (listp suffix)
+      (setq suffix (list suffix)))
+  (dired-mark-files-regexp
+   (concat ".";; don't match names with nothing but an extension
+           "\\("
+           (mapconcat 'regexp-quote suffix "\\|")
            "\\)$")
    marker-char))
 
-- 
2.11.0

--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 12, x86_64-pc-linux-gnu, GTK+ Version 3.22.9)
 of 2017-03-27
Repository revision: 05bfebfc91bc053435287f560aeb956926d31583
  




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25942; Package emacs. (Mon, 27 Mar 2017 14:29:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 25942 <at> debbugs.gnu.org, tino.calancha <at> gmail.com, juri <at> linkov.net
Subject: Re: bug#25942: 26.0.50;
 dired-mark-extension prepend '.' to suffix if not present
Date: Mon, 27 Mar 2017 17:28:01 +0300
> From: Tino Calancha <tino.calancha <at> gmail.com>
> Cc: 25942 <at> debbugs.gnu.org,  juri <at> linkov.net, tino.calancha <at> gmail.com
> Date: Mon, 27 Mar 2017 14:34:30 +0900
> 
> +@item dired-mark-suffix
> +@findex dired-mark-suffix
> +Mark all files with a certain suffix for use in later commands.  A @samp{.}
> +is not automatically prepended to the string entered, you must type it
> +explicitly.  This is different than @var{dired-mark-extension} which prepends
                        ^^^^^^^^^^^^^^
"different from" or "in contrast to".

> +If invoked with prefix argument @kbd{C-u}, this command unmark files instead.
                                                           ^^^^^^
"unmarks"

> +When called from Lisp, @var{suffix} may also be a list of suffices
                                                             ^^^^^^^^
"suffixes"

>  ;; Mark files with some extension.
>  (defun dired-mark-extension (extension &optional marker-char)
>    "Mark all files with a certain EXTENSION for use in later commands.
> -A `.' is *not* automatically prepended to the string entered.
> +A `.' before EXTENSION is automatically prepended when not present.

"A `.' is automatically prepended to EXTENSION when not present."

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25942; Package emacs. (Mon, 27 Mar 2017 15:33:01 GMT) Full text and rfc822 format available.

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

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 25942 <at> debbugs.gnu.org, tino.calancha <at> gmail.com, juri <at> linkov.net
Subject: Re: bug#25942: 26.0.50;
 dired-mark-extension prepend '.' to suffix if not present
Date: Tue, 28 Mar 2017 00:32:25 +0900
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Tino Calancha <tino.calancha <at> gmail.com>
>> Cc: 25942 <at> debbugs.gnu.org,  juri <at> linkov.net, tino.calancha <at> gmail.com
>> Date: Mon, 27 Mar 2017 14:34:30 +0900
>> 
>> +@item dired-mark-suffix
>> +@findex dired-mark-suffix
>> +Mark all files with a certain suffix for use in later commands.  A @samp{.}
>> +is not automatically prepended to the string entered, you must type it
>> +explicitly.  This is different than @var{dired-mark-extension} which prepends
>                         ^^^^^^^^^^^^^^
> "different from" or "in contrast to".
>
>> +If invoked with prefix argument @kbd{C-u}, this command unmark files instead.
>                                                            ^^^^^^
> "unmarks"
>
>> +When called from Lisp, @var{suffix} may also be a list of suffices
>                                                              ^^^^^^^^
> "suffixes"
>
>>  ;; Mark files with some extension.
>>  (defun dired-mark-extension (extension &optional marker-char)
>>    "Mark all files with a certain EXTENSION for use in later commands.
>> -A `.' is *not* automatically prepended to the string entered.
>> +A `.' before EXTENSION is automatically prepended when not present.
>
> "A `.' is automatically prepended to EXTENSION when not present."
Thank you very much for the comments.  Below is the updated patch:
--8<-----------------------------cut here---------------start------------->8---
From de5dc41fa83b32ee81fad16a13f4192115bcd970 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha <at> gmail.com>
Date: Tue, 28 Mar 2017 00:27:34 +0900
Subject: [PATCH] dired-mark-suffix: New command

Now dired-mark-extension prepends '.' to extension when not present.
Add command dired-mark-suffix to preserve the previous
behaviour (Bug#25942).
* lisp/dired-x.el (dired-mark-suffix): New command;
mark files ending in a given suffix.
(dired--mark-suffix-interactive-spec): New defun.
(dired-mark-extension, dired-mark-suffix): Use it.
* doc/misc/dired-x.texi (Advanced Mark Commands): Update manual.
; * etc/NEWS (Changes in Specialized Modes and Packages in Emacs 26.1):
; Mention these changes.
---
 doc/misc/dired-x.texi | 18 ++++++++++--
 etc/NEWS              |  5 ++++
 lisp/dired-x.el       | 81 ++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 74 insertions(+), 30 deletions(-)

diff --git a/doc/misc/dired-x.texi b/doc/misc/dired-x.texi
index 1e6f4b03bb..bf103256f2 100644
--- a/doc/misc/dired-x.texi
+++ b/doc/misc/dired-x.texi
@@ -721,15 +721,27 @@ Advanced Mark Commands
 @item dired-mark-extension
 @findex dired-mark-extension
 Mark all files with a certain extension for use in later commands.  A @samp{.}
-is not automatically prepended to the string entered, you must type it
-explicitly.
-If invoked with prefix argument @kbd{C-u}, this command unmark files instead.
+is automatically prepended to the string entered when not present.
+If invoked with prefix argument @kbd{C-u}, this command unmarks files instead.
 If called with the @kbd{C-u C-u} prefix, asks for a character to use
 as the marker, and marks files with it.
 
 When called from Lisp, @var{extension} may also be a list of extensions
 and an optional argument @var{marker-char} specifies the marker used.
 
+@item dired-mark-suffix
+@findex dired-mark-suffix
+Mark all files with a certain suffix for use in later commands.  A @samp{.}
+is not automatically prepended to the string entered, you must type it
+explicitly.  This is different from @var{dired-mark-extension} which prepends
+a @samp{.} if not present.
+If invoked with prefix argument @kbd{C-u}, this command unmarks files instead.
+If called with the @kbd{C-u C-u} prefix, asks for a character to use
+as the marker, and marks files with it.
+
+When called from Lisp, @var{suffix} may also be a list of suffixes
+and an optional argument @var{marker-char} specifies the marker used.
+
 @item dired-flag-extension
 @findex dired-flag-extension
 Flag all files with a certain extension for deletion.  A @samp{.} is
diff --git a/etc/NEWS b/etc/NEWS
index cd98f53399..3839439a32 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -474,6 +474,11 @@ where to place point after C-c M-r and C-c M-s.
 ** Dired
 
 +++
+*** Command 'dired-mark-extension' now automatically prepends a '.' to the
+extension when not present.  The new command 'dired-mark-suffix' behaves
+similarly but it doesn't prepend a '.'.
+
++++
 *** A new option 'dired-always-read-filesystem' default to nil.
 If non-nil, buffers visiting files are reverted before search them;
 for instance, in 'dired-mark-files-containing-regexp' a non-nil value
diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index 6c8fb0e7da..a2c7e41cc2 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -332,46 +332,73 @@ dired-extra-startup
 
 ;;; EXTENSION MARKING FUNCTIONS.
 
+(defun dired--mark-suffix-interactive-spec ()
+  (let* ((default
+           (let ((file (dired-get-filename nil t)))
+             (when file
+               (file-name-extension file))))
+         (suffix
+          (read-string (format "%s extension%s: "
+                               (if (equal current-prefix-arg '(4))
+                                   "UNmarking"
+                                 "Marking")
+                               (if default
+                                   (format " (default %s)" default)
+                                 "")) nil nil default))
+         (marker
+          (pcase current-prefix-arg
+            ('(4) ?\s)
+            ('(16)
+             (let* ((dflt (char-to-string dired-marker-char))
+                    (input (read-string
+                            (format
+                             "Marker character to use (default %s): " dflt)
+                            nil nil dflt)))
+               (aref input 0)))
+            (_ dired-marker-char))))
+    (list suffix marker)))
+
 ;; Mark files with some extension.
 (defun dired-mark-extension (extension &optional marker-char)
   "Mark all files with a certain EXTENSION for use in later commands.
-A `.' is *not* automatically prepended to the string entered.
+A `.' is automatically prepended to EXTENSION when not present.
 EXTENSION may also be a list of extensions instead of a single one.
 Optional MARKER-CHAR is marker to use.
 Interactively, ask for EXTENSION.
 Prefixed with one C-u, unmark files instead.
 Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it."
-  (interactive
-   (let* ((default
-            (let ((file (dired-get-filename nil t)))
-              (when file
-                (file-name-extension file))))
-          (suffix
-           (read-string (format "%s extension%s: "
-                                (if (equal current-prefix-arg '(4))
-                                    "UNmarking"
-                                  "Marking")
-                                (if default
-                                    (format " (default %s)" default)
-                                  "")) nil nil default))
-          (marker
-           (pcase current-prefix-arg
-             ('(4) ?\s)
-             ('(16)
-              (let* ((dflt (char-to-string dired-marker-char))
-                     (input (read-string
-                             (format
-                              "Marker character to use (default %s): " dflt)
-                             nil nil dflt)))
-                (aref input 0)))
-             (_ dired-marker-char))))
-     (list suffix marker)))
+  (interactive (dired--mark-suffix-interactive-spec))
   (or (listp extension)
       (setq extension (list extension)))
   (dired-mark-files-regexp
    (concat ".";; don't match names with nothing but an extension
            "\\("
-           (mapconcat 'regexp-quote extension "\\|")
+           (mapconcat (lambda (x)
+                        (regexp-quote
+                         (if (string-prefix-p "." x) x (concat "." x))))
+                      extension "\\|")
+           "\\)$")
+   marker-char))
+
+;; Mark files ending with some suffix.
+(defun dired-mark-suffix (suffix &optional marker-char)
+  "Mark all files with a certain SUFFIX for use in later commands.
+A `.' is *not* automatically prepended to the string entered;  see
+also `dired-mark-extension', which is similar but automatically
+prepends `.' when not present.
+SUFFIX may also be a list of suffixes instead of a single one.
+Optional MARKER-CHAR is marker to use.
+Interactively, ask for SUFFIX.
+Prefixed with one C-u, unmark files instead.
+Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it."
+  (interactive
+   (dired--mark-suffix-interactive-spec))
+  (or (listp suffix)
+      (setq suffix (list suffix)))
+  (dired-mark-files-regexp
+   (concat ".";; don't match names with nothing but an extension
+           "\\("
+           (mapconcat 'regexp-quote suffix "\\|")
            "\\)$")
    marker-char))
 
-- 
2.11.0


--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.9)
 of 2017-03-27
Repository revision: 8ce827426e5400f2be80ae5d7394b74d8dd90373





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25942; Package emacs. (Mon, 27 Mar 2017 22:46:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: 25942 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#25942: 26.0.50;
 dired-mark-extension prepend '.' to suffix if not present
Date: Tue, 28 Mar 2017 01:44:12 +0300
> The following patch adds a new command 'dired-mark-suffix', and
> modifies 'dired-mark-extension'.
> I) dired-mark-suffix: it behaves as 'dired-mark-extension' used to do,
>    i.e., don't prepends any '.' to the user input.
> II) dired-mark-extension: It prepends '.' to EXTENSION when not present.
>     This way became consistent with 'file-name-extension', that is, if
>     (file-name-extension FILE) returns nil, then 'dired-mark-extension'
>     will not mark FILE.

Thanks.

> diff --git a/etc/NEWS b/etc/NEWS
> index cd98f53399..3839439a32 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -474,6 +474,11 @@ where to place point after C-c M-r and C-c M-s.
>  ** Dired
>
>  +++
> +*** Command 'dired-mark-extension' now automatically prepends a '.' to the
> +extension when not present.  The new command 'dired-mark-suffix' behaves
> +similarly but it doesn't prepend a '.'.
> +
> ++++
>  *** A new option 'dired-always-read-filesystem' default to nil.
>  If non-nil, buffers visiting files are reverted before search them;
>  for instance, in 'dired-mark-files-containing-regexp' a non-nil value

There is a special section in etc/NEWS for Incompatible Changes
that would be a more likely place to find this change.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25942; Package emacs. (Tue, 28 Mar 2017 01:24:02 GMT) Full text and rfc822 format available.

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

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 25942 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 tino.calancha <at> gmail.com
Subject: Re: bug#25942: 26.0.50;
 dired-mark-extension prepend '.' to suffix if not present
Date: Tue, 28 Mar 2017 10:23:32 +0900
Juri Linkov <juri <at> linkov.net> writes:

>> diff --git a/etc/NEWS b/etc/NEWS
>> index cd98f53399..3839439a32 100644
>> --- a/etc/NEWS
>> +++ b/etc/NEWS
>> @@ -474,6 +474,11 @@ where to place point after C-c M-r and C-c M-s.
>>  ** Dired
>>
>>  +++
>> +*** Command 'dired-mark-extension' now automatically prepends a '.' to the
>> +extension when not present.  The new command 'dired-mark-suffix' behaves
>> +similarly but it doesn't prepend a '.'.
>> +
>> ++++
>>  *** A new option 'dired-always-read-filesystem' default to nil.
>>  If non-nil, buffers visiting files are reverted before search them;
>>  for instance, in 'dired-mark-files-containing-regexp' a non-nil value
>
> There is a special section in etc/NEWS for Incompatible Changes
> that would be a more likely place to find this change.
That's right.  Thanks.
Here is the updated patch:
--8<-----------------------------cut here---------------start------------->8---
From 268eae94cdaf43bfd44c3b8d5cb74a32d26556c3 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha <at> gmail.com>
Date: Tue, 28 Mar 2017 10:18:59 +0900
Subject: [PATCH] dired-mark-suffix: New command

Now dired-mark-extension prepends '.' to extension when not present.
Add command dired-mark-suffix to preserve the previous
behaviour (Bug#25942).
* lisp/dired-x.el (dired-mark-suffix): New command;
mark files ending in a given suffix.
(dired--mark-suffix-interactive-spec): New defun.
(dired-mark-extension, dired-mark-suffix): Use it.
* doc/misc/dired-x.texi (Advanced Mark Commands): Update manual.
* test/lisp/dired-x-tests.el: New test suite; add test for these features.
; * etc/NEWS (Incompatible Lisp Changes in Emacs 26.1):
; Mention these changes.
---
 doc/misc/dired-x.texi      | 18 ++++++++--
 etc/NEWS                   |  7 ++--
 lisp/dired-x.el            | 85 ++++++++++++++++++++++++++++++----------------
 test/lisp/dired-x-tests.el | 48 ++++++++++++++++++++++++++
 4 files changed, 124 insertions(+), 34 deletions(-)
 create mode 100644 test/lisp/dired-x-tests.el

diff --git a/doc/misc/dired-x.texi b/doc/misc/dired-x.texi
index 1e6f4b03bb..bf103256f2 100644
--- a/doc/misc/dired-x.texi
+++ b/doc/misc/dired-x.texi
@@ -721,15 +721,27 @@ Advanced Mark Commands
 @item dired-mark-extension
 @findex dired-mark-extension
 Mark all files with a certain extension for use in later commands.  A @samp{.}
-is not automatically prepended to the string entered, you must type it
-explicitly.
-If invoked with prefix argument @kbd{C-u}, this command unmark files instead.
+is automatically prepended to the string entered when not present.
+If invoked with prefix argument @kbd{C-u}, this command unmarks files instead.
 If called with the @kbd{C-u C-u} prefix, asks for a character to use
 as the marker, and marks files with it.
 
 When called from Lisp, @var{extension} may also be a list of extensions
 and an optional argument @var{marker-char} specifies the marker used.
 
+@item dired-mark-suffix
+@findex dired-mark-suffix
+Mark all files with a certain suffix for use in later commands.  A @samp{.}
+is not automatically prepended to the string entered, you must type it
+explicitly.  This is different from @var{dired-mark-extension} which prepends
+a @samp{.} if not present.
+If invoked with prefix argument @kbd{C-u}, this command unmarks files instead.
+If called with the @kbd{C-u C-u} prefix, asks for a character to use
+as the marker, and marks files with it.
+
+When called from Lisp, @var{suffix} may also be a list of suffixes
+and an optional argument @var{marker-char} specifies the marker used.
+
 @item dired-flag-extension
 @findex dired-flag-extension
 Flag all files with a certain extension for deletion.  A @samp{.} is
diff --git a/etc/NEWS b/etc/NEWS
index cd98f53399..bfd7d2bd32 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -471,8 +471,6 @@ where to place point after C-c M-r and C-c M-s.
 ---
 *** Messages from CMake are now recognized.
 
-** Dired
-
 +++
 *** A new option 'dired-always-read-filesystem' default to nil.
 If non-nil, buffers visiting files are reverted before search them;
@@ -759,6 +757,11 @@ processes on exit.
 * Incompatible Lisp Changes in Emacs 26.1
 
 +++
+*** Command 'dired-mark-extension' now automatically prepends a '.' to the
+extension when not present.  The new command 'dired-mark-suffix' behaves
+similarly but it doesn't prepend a '.'.
+
++++
 ** Certain cond/pcase/cl-case forms are now compiled using a faster jump
 table implementation. This uses a new bytecode op `switch', which isn't
 compatible with previous Emacs versions. This functionality can be disabled
diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index 6c8fb0e7da..527685acf3 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -332,46 +332,73 @@ dired-extra-startup
 
 ;;; EXTENSION MARKING FUNCTIONS.
 
+(defun dired--mark-suffix-interactive-spec ()
+  (let* ((default
+           (let ((file (dired-get-filename nil t)))
+             (when file
+               (file-name-extension file))))
+         (suffix
+          (read-string (format "%s extension%s: "
+                               (if (equal current-prefix-arg '(4))
+                                   "UNmarking"
+                                 "Marking")
+                               (if default
+                                   (format " (default %s)" default)
+                                 "")) nil nil default))
+         (marker
+          (pcase current-prefix-arg
+            ('(4) ?\s)
+            ('(16)
+             (let* ((dflt (char-to-string dired-marker-char))
+                    (input (read-string
+                            (format
+                             "Marker character to use (default %s): " dflt)
+                            nil nil dflt)))
+               (aref input 0)))
+            (_ dired-marker-char))))
+    (list suffix marker)))
+
 ;; Mark files with some extension.
 (defun dired-mark-extension (extension &optional marker-char)
   "Mark all files with a certain EXTENSION for use in later commands.
-A `.' is *not* automatically prepended to the string entered.
+A `.' is automatically prepended to EXTENSION when not present.
 EXTENSION may also be a list of extensions instead of a single one.
 Optional MARKER-CHAR is marker to use.
 Interactively, ask for EXTENSION.
 Prefixed with one C-u, unmark files instead.
 Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it."
-  (interactive
-   (let* ((default
-            (let ((file (dired-get-filename nil t)))
-              (when file
-                (file-name-extension file))))
-          (suffix
-           (read-string (format "%s extension%s: "
-                                (if (equal current-prefix-arg '(4))
-                                    "UNmarking"
-                                  "Marking")
-                                (if default
-                                    (format " (default %s)" default)
-                                  "")) nil nil default))
-          (marker
-           (pcase current-prefix-arg
-             ('(4) ?\s)
-             ('(16)
-              (let* ((dflt (char-to-string dired-marker-char))
-                     (input (read-string
-                             (format
-                              "Marker character to use (default %s): " dflt)
-                             nil nil dflt)))
-                (aref input 0)))
-             (_ dired-marker-char))))
-     (list suffix marker)))
-  (or (listp extension)
-      (setq extension (list extension)))
+  (interactive (dired--mark-suffix-interactive-spec))
+  (unless (listp extension)
+    (setq extension (list extension)))
+  (dired-mark-files-regexp
+   (concat ".";; don't match names with nothing but an extension
+           "\\("
+           (mapconcat
+            (lambda (x)
+              (regexp-quote
+               (if (string-prefix-p "." x) x (concat "." x))))
+            extension "\\|")
+           "\\)$")
+   marker-char))
+
+;; Mark files ending with some suffix.
+(defun dired-mark-suffix (suffix &optional marker-char)
+  "Mark all files with a certain SUFFIX for use in later commands.
+A `.' is *not* automatically prepended to the string entered;  see
+also `dired-mark-extension', which is similar but automatically
+prepends `.' when not present.
+SUFFIX may also be a list of suffixes instead of a single one.
+Optional MARKER-CHAR is marker to use.
+Interactively, ask for SUFFIX.
+Prefixed with one C-u, unmark files instead.
+Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it."
+  (interactive (dired--mark-suffix-interactive-spec))
+  (unless (listp suffix)
+    (setq suffix (list suffix)))
   (dired-mark-files-regexp
    (concat ".";; don't match names with nothing but an extension
            "\\("
-           (mapconcat 'regexp-quote extension "\\|")
+           (mapconcat 'regexp-quote suffix "\\|")
            "\\)$")
    marker-char))
 
diff --git a/test/lisp/dired-x-tests.el b/test/lisp/dired-x-tests.el
new file mode 100644
index 0000000000..b11c440834
--- /dev/null
+++ b/test/lisp/dired-x-tests.el
@@ -0,0 +1,48 @@
+;;; dired-x-tests.el --- Test suite for dired-x. -*- lexical-binding: t -*-
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+(require 'ert)
+(require 'dired-x)
+
+
+(ert-deftest dired-test-bug25942 ()
+  "Test for http://debbugs.gnu.org/25942 ."
+  (let ((dirs '("Public" "Music"))
+        (files '(".bashrc" "bar.c" "foo.c" "c" ".c"))
+        (dir (make-temp-file "Bug25942" 'dir))
+        (extension "c"))
+    (unwind-protect
+        (progn
+          (dolist (d dirs)
+            (make-directory (expand-file-name d dir)))
+          (dolist (f files)
+            (write-region nil nil (expand-file-name f dir)))
+          (dired dir)
+          (dired-mark-extension extension)
+          (should (= (length '("foo.c" "bar.c"))
+                     (length (dired-get-marked-files))))
+          (dired-unmark-all-marks)
+          (dired-mark-suffix extension)
+          (should (= (length (delete "c" (append dirs files)))
+                     (length (dired-get-marked-files)))))
+      (delete-directory dir 'recursive))))
+
+(provide 'dired-x-tests)
+;; dired-x-tests.el ends here
-- 
2.11.0

--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.9)
 of 2017-03-27
Repository revision: a62437d4b933825a92ac3836836edbca3540fa1c




Reply sent to Tino Calancha <tino.calancha <at> gmail.com>:
You have taken responsibility. (Fri, 31 Mar 2017 08:35:01 GMT) Full text and rfc822 format available.

Notification sent to Tino Calancha <tino.calancha <at> gmail.com>:
bug acknowledged by developer. (Fri, 31 Mar 2017 08:35:02 GMT) Full text and rfc822 format available.

Message #37 received at 25942-done <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: 25942-done <at> debbugs.gnu.org
Subject: Re: bug#25942: 26.0.50;
 dired-mark-extension prepend '.' to suffix if not present
Date: Fri, 31 Mar 2017 17:34:26 +0900
Tino Calancha <tino.calancha <at> gmail.com> writes:

Pushed patch into master branch as commit:
1da9a207669a3cf5d27ac1dd61543c1492e05360

> Juri Linkov <juri <at> linkov.net> writes:
>> There is a special section in etc/NEWS for Incompatible Changes
>> that would be a more likely place to find this change.
> That's right.  Thanks.
> Here is the updated patch:
>
>>From 268eae94cdaf43bfd44c3b8d5cb74a32d26556c3 Mon Sep 17 00:00:00 2001
> From: Tino Calancha <tino.calancha <at> gmail.com>
> Date: Tue, 28 Mar 2017 10:18:59 +0900
> Subject: [PATCH] dired-mark-suffix: New command
>
> Now dired-mark-extension prepends '.' to extension when not present.
> Add command dired-mark-suffix to preserve the previous
> behaviour (Bug#25942).
> * lisp/dired-x.el (dired-mark-suffix): New command;
> mark files ending in a given suffix.
> (dired--mark-suffix-interactive-spec): New defun.
> (dired-mark-extension, dired-mark-suffix): Use it.
> * doc/misc/dired-x.texi (Advanced Mark Commands): Update manual.
> * test/lisp/dired-x-tests.el: New test suite; add test for these features.
> ; * etc/NEWS (Incompatible Lisp Changes in Emacs 26.1):
> ; Mention these changes.
> ---
>  doc/misc/dired-x.texi      | 18 ++++++++--
>  etc/NEWS                   |  7 ++--
>  lisp/dired-x.el            | 85 ++++++++++++++++++++++++++++++----------------
>  test/lisp/dired-x-tests.el | 48 ++++++++++++++++++++++++++
>  4 files changed, 124 insertions(+), 34 deletions(-)
>  create mode 100644 test/lisp/dired-x-tests.el
>
> diff --git a/doc/misc/dired-x.texi b/doc/misc/dired-x.texi
> index 1e6f4b03bb..bf103256f2 100644
> --- a/doc/misc/dired-x.texi
> +++ b/doc/misc/dired-x.texi
> @@ -721,15 +721,27 @@ Advanced Mark Commands
>  @item dired-mark-extension
>  @findex dired-mark-extension
>  Mark all files with a certain extension for use in later commands.  A @samp{.}
> -is not automatically prepended to the string entered, you must type it
> -explicitly.
> -If invoked with prefix argument @kbd{C-u}, this command unmark files instead.
> +is automatically prepended to the string entered when not present.
> +If invoked with prefix argument @kbd{C-u}, this command unmarks files instead.
>  If called with the @kbd{C-u C-u} prefix, asks for a character to use
>  as the marker, and marks files with it.
>  
>  When called from Lisp, @var{extension} may also be a list of extensions
>  and an optional argument @var{marker-char} specifies the marker used.
>  
> +@item dired-mark-suffix
> +@findex dired-mark-suffix
> +Mark all files with a certain suffix for use in later commands.  A @samp{.}
> +is not automatically prepended to the string entered, you must type it
> +explicitly.  This is different from @var{dired-mark-extension} which prepends
> +a @samp{.} if not present.
> +If invoked with prefix argument @kbd{C-u}, this command unmarks files instead.
> +If called with the @kbd{C-u C-u} prefix, asks for a character to use
> +as the marker, and marks files with it.
> +
> +When called from Lisp, @var{suffix} may also be a list of suffixes
> +and an optional argument @var{marker-char} specifies the marker used.
> +
>  @item dired-flag-extension
>  @findex dired-flag-extension
>  Flag all files with a certain extension for deletion.  A @samp{.} is
> diff --git a/etc/NEWS b/etc/NEWS
> index cd98f53399..bfd7d2bd32 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -471,8 +471,6 @@ where to place point after C-c M-r and C-c M-s.
>  ---
>  *** Messages from CMake are now recognized.
>  
> -** Dired
> -
>  +++
>  *** A new option 'dired-always-read-filesystem' default to nil.
>  If non-nil, buffers visiting files are reverted before search them;
> @@ -759,6 +757,11 @@ processes on exit.
>  * Incompatible Lisp Changes in Emacs 26.1
>  
>  +++
> +*** Command 'dired-mark-extension' now automatically prepends a '.' to the
> +extension when not present.  The new command 'dired-mark-suffix' behaves
> +similarly but it doesn't prepend a '.'.
> +
> ++++
>  ** Certain cond/pcase/cl-case forms are now compiled using a faster jump
>  table implementation. This uses a new bytecode op `switch', which isn't
>  compatible with previous Emacs versions. This functionality can be disabled
> diff --git a/lisp/dired-x.el b/lisp/dired-x.el
> index 6c8fb0e7da..527685acf3 100644
> --- a/lisp/dired-x.el
> +++ b/lisp/dired-x.el
> @@ -332,46 +332,73 @@ dired-extra-startup
>  
>  ;;; EXTENSION MARKING FUNCTIONS.
>  
> +(defun dired--mark-suffix-interactive-spec ()
> +  (let* ((default
> +           (let ((file (dired-get-filename nil t)))
> +             (when file
> +               (file-name-extension file))))
> +         (suffix
> +          (read-string (format "%s extension%s: "
> +                               (if (equal current-prefix-arg '(4))
> +                                   "UNmarking"
> +                                 "Marking")
> +                               (if default
> +                                   (format " (default %s)" default)
> +                                 "")) nil nil default))
> +         (marker
> +          (pcase current-prefix-arg
> +            ('(4) ?\s)
> +            ('(16)
> +             (let* ((dflt (char-to-string dired-marker-char))
> +                    (input (read-string
> +                            (format
> +                             "Marker character to use (default %s): " dflt)
> +                            nil nil dflt)))
> +               (aref input 0)))
> +            (_ dired-marker-char))))
> +    (list suffix marker)))
> +
>  ;; Mark files with some extension.
>  (defun dired-mark-extension (extension &optional marker-char)
>    "Mark all files with a certain EXTENSION for use in later commands.
> -A `.' is *not* automatically prepended to the string entered.
> +A `.' is automatically prepended to EXTENSION when not present.
>  EXTENSION may also be a list of extensions instead of a single one.
>  Optional MARKER-CHAR is marker to use.
>  Interactively, ask for EXTENSION.
>  Prefixed with one C-u, unmark files instead.
>  Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it."
> -  (interactive
> -   (let* ((default
> -            (let ((file (dired-get-filename nil t)))
> -              (when file
> -                (file-name-extension file))))
> -          (suffix
> -           (read-string (format "%s extension%s: "
> -                                (if (equal current-prefix-arg '(4))
> -                                    "UNmarking"
> -                                  "Marking")
> -                                (if default
> -                                    (format " (default %s)" default)
> -                                  "")) nil nil default))
> -          (marker
> -           (pcase current-prefix-arg
> -             ('(4) ?\s)
> -             ('(16)
> -              (let* ((dflt (char-to-string dired-marker-char))
> -                     (input (read-string
> -                             (format
> -                              "Marker character to use (default %s): " dflt)
> -                             nil nil dflt)))
> -                (aref input 0)))
> -             (_ dired-marker-char))))
> -     (list suffix marker)))
> -  (or (listp extension)
> -      (setq extension (list extension)))
> +  (interactive (dired--mark-suffix-interactive-spec))
> +  (unless (listp extension)
> +    (setq extension (list extension)))
> +  (dired-mark-files-regexp
> +   (concat ".";; don't match names with nothing but an extension
> +           "\\("
> +           (mapconcat
> +            (lambda (x)
> +              (regexp-quote
> +               (if (string-prefix-p "." x) x (concat "." x))))
> +            extension "\\|")
> +           "\\)$")
> +   marker-char))
> +
> +;; Mark files ending with some suffix.
> +(defun dired-mark-suffix (suffix &optional marker-char)
> +  "Mark all files with a certain SUFFIX for use in later commands.
> +A `.' is *not* automatically prepended to the string entered;  see
> +also `dired-mark-extension', which is similar but automatically
> +prepends `.' when not present.
> +SUFFIX may also be a list of suffixes instead of a single one.
> +Optional MARKER-CHAR is marker to use.
> +Interactively, ask for SUFFIX.
> +Prefixed with one C-u, unmark files instead.
> +Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it."
> +  (interactive (dired--mark-suffix-interactive-spec))
> +  (unless (listp suffix)
> +    (setq suffix (list suffix)))
>    (dired-mark-files-regexp
>     (concat ".";; don't match names with nothing but an extension
>             "\\("
> -           (mapconcat 'regexp-quote extension "\\|")
> +           (mapconcat 'regexp-quote suffix "\\|")
>             "\\)$")
>     marker-char))
>  
> diff --git a/test/lisp/dired-x-tests.el b/test/lisp/dired-x-tests.el
> new file mode 100644
> index 0000000000..b11c440834
> --- /dev/null
> +++ b/test/lisp/dired-x-tests.el
> @@ -0,0 +1,48 @@
> +;;; dired-x-tests.el --- Test suite for dired-x. -*- lexical-binding: t -*-
> +
> +;; Copyright (C) 2017 Free Software Foundation, Inc.
> +
> +;; This file is part of GNU Emacs.
> +
> +;; GNU Emacs is free software: you can redistribute it and/or modify
> +;; it under the terms of the GNU General Public License as published by
> +;; the Free Software Foundation, either version 3 of the License, or
> +;; (at your option) any later version.
> +
> +;; GNU Emacs is distributed in the hope that it will be useful,
> +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
> +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;; GNU General Public License for more details.
> +
> +;; You should have received a copy of the GNU General Public License
> +;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
> +
> +;;; Code:
> +(require 'ert)
> +(require 'dired-x)
> +
> +
> +(ert-deftest dired-test-bug25942 ()
> +  "Test for http://debbugs.gnu.org/25942 ."
> +  (let ((dirs '("Public" "Music"))
> +        (files '(".bashrc" "bar.c" "foo.c" "c" ".c"))
> +        (dir (make-temp-file "Bug25942" 'dir))
> +        (extension "c"))
> +    (unwind-protect
> +        (progn
> +          (dolist (d dirs)
> +            (make-directory (expand-file-name d dir)))
> +          (dolist (f files)
> +            (write-region nil nil (expand-file-name f dir)))
> +          (dired dir)
> +          (dired-mark-extension extension)
> +          (should (= (length '("foo.c" "bar.c"))
> +                     (length (dired-get-marked-files))))
> +          (dired-unmark-all-marks)
> +          (dired-mark-suffix extension)
> +          (should (= (length (delete "c" (append dirs files)))
> +                     (length (dired-get-marked-files)))))
> +      (delete-directory dir 'recursive))))
> +
> +(provide 'dired-x-tests)
> +;; dired-x-tests.el ends here




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 28 Apr 2017 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 364 days ago.

Previous Next


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