diff options
| author | Tino Calancha | 2017-03-31 17:27:08 +0900 |
|---|---|---|
| committer | Tino Calancha | 2017-03-31 17:27:08 +0900 |
| commit | 1da9a207669a3cf5d27ac1dd61543c1492e05360 (patch) | |
| tree | d82a538a97595e3c118c535cdf7ee0a92f353ca6 | |
| parent | 3a11b3e330e88a42386ac3a635330ebd9c610827 (diff) | |
| download | emacs-1da9a207669a3cf5d27ac1dd61543c1492e05360.tar.gz 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.
| -rw-r--r-- | doc/misc/dired-x.texi | 18 | ||||
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/dired-x.el | 85 | ||||
| -rw-r--r-- | test/lisp/dired-x-tests.el | 53 |
4 files changed, 129 insertions, 34 deletions
diff --git a/doc/misc/dired-x.texi b/doc/misc/dired-x.texi index 1e6f4b03bb0..bf103256f29 100644 --- a/doc/misc/dired-x.texi +++ b/doc/misc/dired-x.texi | |||
| @@ -721,15 +721,27 @@ variable @code{window-min-height}. | |||
| 721 | @item dired-mark-extension | 721 | @item dired-mark-extension |
| 722 | @findex dired-mark-extension | 722 | @findex dired-mark-extension |
| 723 | Mark all files with a certain extension for use in later commands. A @samp{.} | 723 | Mark all files with a certain extension for use in later commands. A @samp{.} |
| 724 | is not automatically prepended to the string entered, you must type it | 724 | is automatically prepended to the string entered when not present. |
| 725 | explicitly. | 725 | If invoked with prefix argument @kbd{C-u}, this command unmarks files instead. |
| 726 | If invoked with prefix argument @kbd{C-u}, this command unmark files instead. | ||
| 727 | If called with the @kbd{C-u C-u} prefix, asks for a character to use | 726 | If called with the @kbd{C-u C-u} prefix, asks for a character to use |
| 728 | as the marker, and marks files with it. | 727 | as the marker, and marks files with it. |
| 729 | 728 | ||
| 730 | When called from Lisp, @var{extension} may also be a list of extensions | 729 | When called from Lisp, @var{extension} may also be a list of extensions |
| 731 | and an optional argument @var{marker-char} specifies the marker used. | 730 | and an optional argument @var{marker-char} specifies the marker used. |
| 732 | 731 | ||
| 732 | @item dired-mark-suffix | ||
| 733 | @findex dired-mark-suffix | ||
| 734 | Mark all files with a certain suffix for use in later commands. A @samp{.} | ||
| 735 | is not automatically prepended to the string entered, you must type it | ||
| 736 | explicitly. This is different from @var{dired-mark-extension} which prepends | ||
| 737 | a @samp{.} if not present. | ||
| 738 | If invoked with prefix argument @kbd{C-u}, this command unmarks files instead. | ||
| 739 | If called with the @kbd{C-u C-u} prefix, asks for a character to use | ||
| 740 | as the marker, and marks files with it. | ||
| 741 | |||
| 742 | When called from Lisp, @var{suffix} may also be a list of suffixes | ||
| 743 | and an optional argument @var{marker-char} specifies the marker used. | ||
| 744 | |||
| 733 | @item dired-flag-extension | 745 | @item dired-flag-extension |
| 734 | @findex dired-flag-extension | 746 | @findex dired-flag-extension |
| 735 | Flag all files with a certain extension for deletion. A @samp{.} is | 747 | Flag all files with a certain extension for deletion. A @samp{.} is |
| @@ -471,8 +471,6 @@ where to place point after C-c M-r and C-c M-s. | |||
| 471 | --- | 471 | --- |
| 472 | *** Messages from CMake are now recognized. | 472 | *** Messages from CMake are now recognized. |
| 473 | 473 | ||
| 474 | ** Dired | ||
| 475 | |||
| 476 | +++ | 474 | +++ |
| 477 | *** A new option 'dired-always-read-filesystem' default to nil. | 475 | *** A new option 'dired-always-read-filesystem' default to nil. |
| 478 | If non-nil, buffers visiting files are reverted before search them; | 476 | If non-nil, buffers visiting files are reverted before search them; |
| @@ -759,6 +757,11 @@ processes on exit. | |||
| 759 | * Incompatible Lisp Changes in Emacs 26.1 | 757 | * Incompatible Lisp Changes in Emacs 26.1 |
| 760 | 758 | ||
| 761 | +++ | 759 | +++ |
| 760 | *** Command 'dired-mark-extension' now automatically prepends a '.' to the | ||
| 761 | extension when not present. The new command 'dired-mark-suffix' behaves | ||
| 762 | similarly but it doesn't prepend a '.'. | ||
| 763 | |||
| 764 | +++ | ||
| 762 | ** Certain cond/pcase/cl-case forms are now compiled using a faster jump | 765 | ** Certain cond/pcase/cl-case forms are now compiled using a faster jump |
| 763 | table implementation. This uses a new bytecode op `switch', which isn't | 766 | table implementation. This uses a new bytecode op `switch', which isn't |
| 764 | compatible with previous Emacs versions. This functionality can be disabled | 767 | compatible with previous Emacs versions. This functionality can be disabled |
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: | |||
| 332 | 332 | ||
| 333 | ;;; EXTENSION MARKING FUNCTIONS. | 333 | ;;; EXTENSION MARKING FUNCTIONS. |
| 334 | 334 | ||
| 335 | (defun dired--mark-suffix-interactive-spec () | ||
| 336 | (let* ((default | ||
| 337 | (let ((file (dired-get-filename nil t))) | ||
| 338 | (when file | ||
| 339 | (file-name-extension file)))) | ||
| 340 | (suffix | ||
| 341 | (read-string (format "%s extension%s: " | ||
| 342 | (if (equal current-prefix-arg '(4)) | ||
| 343 | "UNmarking" | ||
| 344 | "Marking") | ||
| 345 | (if default | ||
| 346 | (format " (default %s)" default) | ||
| 347 | "")) nil nil default)) | ||
| 348 | (marker | ||
| 349 | (pcase current-prefix-arg | ||
| 350 | ('(4) ?\s) | ||
| 351 | ('(16) | ||
| 352 | (let* ((dflt (char-to-string dired-marker-char)) | ||
| 353 | (input (read-string | ||
| 354 | (format | ||
| 355 | "Marker character to use (default %s): " dflt) | ||
| 356 | nil nil dflt))) | ||
| 357 | (aref input 0))) | ||
| 358 | (_ dired-marker-char)))) | ||
| 359 | (list suffix marker))) | ||
| 360 | |||
| 335 | ;; Mark files with some extension. | 361 | ;; Mark files with some extension. |
| 336 | (defun dired-mark-extension (extension &optional marker-char) | 362 | (defun dired-mark-extension (extension &optional marker-char) |
| 337 | "Mark all files with a certain EXTENSION for use in later commands. | 363 | "Mark all files with a certain EXTENSION for use in later commands. |
| 338 | A `.' is *not* automatically prepended to the string entered. | 364 | A `.' is automatically prepended to EXTENSION when not present. |
| 339 | EXTENSION may also be a list of extensions instead of a single one. | 365 | EXTENSION may also be a list of extensions instead of a single one. |
| 340 | Optional MARKER-CHAR is marker to use. | 366 | Optional MARKER-CHAR is marker to use. |
| 341 | Interactively, ask for EXTENSION. | 367 | Interactively, ask for EXTENSION. |
| 342 | Prefixed with one C-u, unmark files instead. | 368 | Prefixed with one C-u, unmark files instead. |
| 343 | Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it." | 369 | Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it." |
| 344 | (interactive | 370 | (interactive (dired--mark-suffix-interactive-spec)) |
| 345 | (let* ((default | 371 | (unless (listp extension) |
| 346 | (let ((file (dired-get-filename nil t))) | 372 | (setq extension (list extension))) |
| 347 | (when file | 373 | (dired-mark-files-regexp |
| 348 | (file-name-extension file)))) | 374 | (concat ".";; don't match names with nothing but an extension |
| 349 | (suffix | 375 | "\\(" |
| 350 | (read-string (format "%s extension%s: " | 376 | (mapconcat |
| 351 | (if (equal current-prefix-arg '(4)) | 377 | (lambda (x) |
| 352 | "UNmarking" | 378 | (regexp-quote |
| 353 | "Marking") | 379 | (if (string-prefix-p "." x) x (concat "." x)))) |
| 354 | (if default | 380 | extension "\\|") |
| 355 | (format " (default %s)" default) | 381 | "\\)$") |
| 356 | "")) nil nil default)) | 382 | marker-char)) |
| 357 | (marker | 383 | |
| 358 | (pcase current-prefix-arg | 384 | ;; Mark files ending with some suffix. |
| 359 | ('(4) ?\s) | 385 | (defun dired-mark-suffix (suffix &optional marker-char) |
| 360 | ('(16) | 386 | "Mark all files with a certain SUFFIX for use in later commands. |
| 361 | (let* ((dflt (char-to-string dired-marker-char)) | 387 | A `.' is *not* automatically prepended to the string entered; see |
| 362 | (input (read-string | 388 | also `dired-mark-extension', which is similar but automatically |
| 363 | (format | 389 | prepends `.' when not present. |
| 364 | "Marker character to use (default %s): " dflt) | 390 | SUFFIX may also be a list of suffixes instead of a single one. |
| 365 | nil nil dflt))) | 391 | Optional MARKER-CHAR is marker to use. |
| 366 | (aref input 0))) | 392 | Interactively, ask for SUFFIX. |
| 367 | (_ dired-marker-char)))) | 393 | Prefixed with one C-u, unmark files instead. |
| 368 | (list suffix marker))) | 394 | Prefixed with two C-u's, prompt for MARKER-CHAR and mark files with it." |
| 369 | (or (listp extension) | 395 | (interactive (dired--mark-suffix-interactive-spec)) |
| 370 | (setq extension (list extension))) | 396 | (unless (listp suffix) |
| 397 | (setq suffix (list suffix))) | ||
| 371 | (dired-mark-files-regexp | 398 | (dired-mark-files-regexp |
| 372 | (concat ".";; don't match names with nothing but an extension | 399 | (concat ".";; don't match names with nothing but an extension |
| 373 | "\\(" | 400 | "\\(" |
| 374 | (mapconcat 'regexp-quote extension "\\|") | 401 | (mapconcat 'regexp-quote suffix "\\|") |
| 375 | "\\)$") | 402 | "\\)$") |
| 376 | marker-char)) | 403 | marker-char)) |
| 377 | 404 | ||
diff --git a/test/lisp/dired-x-tests.el b/test/lisp/dired-x-tests.el new file mode 100644 index 00000000000..e8352a4ecaf --- /dev/null +++ b/test/lisp/dired-x-tests.el | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | ;;; dired-x-tests.el --- Test suite for dired-x. -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Code: | ||
| 21 | (require 'ert) | ||
| 22 | (require 'dired-x) | ||
| 23 | |||
| 24 | |||
| 25 | (ert-deftest dired-test-bug25942 () | ||
| 26 | "Test for http://debbugs.gnu.org/25942 ." | ||
| 27 | (let* ((dirs (list "Public" "Music")) | ||
| 28 | (files (list ".bashrc" "bar.c" "foo.c" "c" ".c")) | ||
| 29 | (all-but-c | ||
| 30 | (sort | ||
| 31 | (append (copy-sequence dirs) | ||
| 32 | (delete "c" (copy-sequence files))) | ||
| 33 | #'string<)) | ||
| 34 | (dir (make-temp-file "Bug25942" 'dir)) | ||
| 35 | (extension "c")) | ||
| 36 | (unwind-protect | ||
| 37 | (progn | ||
| 38 | (dolist (d dirs) | ||
| 39 | (make-directory (expand-file-name d dir))) | ||
| 40 | (dolist (f files) | ||
| 41 | (write-region nil nil (expand-file-name f dir))) | ||
| 42 | (dired dir) | ||
| 43 | (dired-mark-extension extension) | ||
| 44 | (should (equal '("bar.c" "foo.c") | ||
| 45 | (sort (dired-get-marked-files 'local) #'string<))) | ||
| 46 | (dired-unmark-all-marks) | ||
| 47 | (dired-mark-suffix extension) | ||
| 48 | (should (equal all-but-c | ||
| 49 | (sort (dired-get-marked-files 'local) #'string<)))) | ||
| 50 | (delete-directory dir 'recursive)))) | ||
| 51 | |||
| 52 | (provide 'dired-x-tests) | ||
| 53 | ;; dired-x-tests.el ends here | ||