diff options
author | Tino Calancha <tino.calancha@gmail.com> | 2017-03-31 17:27:08 +0900 |
---|---|---|
committer | Tino Calancha <tino.calancha@gmail.com> | 2017-03-31 17:27:08 +0900 |
commit | 1da9a207669a3cf5d27ac1dd61543c1492e05360 (patch) | |
tree | d82a538a97595e3c118c535cdf7ee0a92f353ca6 /lisp | |
parent | 3a11b3e330e88a42386ac3a635330ebd9c610827 (diff) | |
download | emacs-1da9a207669a3cf5d27ac1dd61543c1492e05360.tar.gz emacs-1da9a207669a3cf5d27ac1dd61543c1492e05360.tar.bz2 emacs-1da9a207669a3cf5d27ac1dd61543c1492e05360.zip |
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.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/dired-x.el | 85 |
1 files changed, 56 insertions, 29 deletions
diff --git a/lisp/dired-x.el b/lisp/dired-x.el index 6c8fb0e7dae..527685acf37 100644 --- a/lisp/dired-x.el +++ b/lisp/dired-x.el @@ -332,46 +332,73 @@ See also the functions: ;;; 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)) |