From: Tino Calancha <tino.calancha@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 25942@debbugs.gnu.org, juri@linkov.net, tino.calancha@gmail.com
Subject: bug#25942: 26.0.50; dired-mark-extension prepend '.' to suffix if not present
Date: Tue, 28 Mar 2017 00:32:25 +0900 [thread overview]
Message-ID: <871stid9bq.fsf@calancha-pc> (raw)
In-Reply-To: <83poh294lq.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 27 Mar 2017 17:28:01 +0300")
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Tino Calancha <tino.calancha@gmail.com>
>> Cc: 25942@debbugs.gnu.org, juri@linkov.net, tino.calancha@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@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
\f
;;; 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
next prev parent reply other threads:[~2017-03-27 15:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 3:40 bug#25942: 26.0.50; dired-mark-extension prepend '.' to suffix if not present Tino Calancha
2017-03-26 22:40 ` Juri Linkov
2017-03-27 1:30 ` Tino Calancha
2017-03-27 1:32 ` Tino Calancha
2017-03-27 2:35 ` Eli Zaretskii
2017-03-27 5:34 ` Tino Calancha
2017-03-27 14:28 ` Eli Zaretskii
2017-03-27 15:32 ` Tino Calancha [this message]
2017-03-27 22:44 ` Juri Linkov
2017-03-28 1:23 ` Tino Calancha
2017-03-31 8:34 ` Tino Calancha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871stid9bq.fsf@calancha-pc \
--to=tino.calancha@gmail.com \
--cc=25942@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=juri@linkov.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).