diff options
| author | Juri Linkov | 2020-03-23 02:35:33 +0200 |
|---|---|---|
| committer | Juri Linkov | 2020-03-23 02:35:33 +0200 |
| commit | 3b7cb5f3ac0fdd5e1a0177cc86b3fc4b420b9e4f (patch) | |
| tree | b686e0da6e95c3e505a3d646de15ad31c18e1574 | |
| parent | 813478c8557541efa918de18f7d863a33210a598 (diff) | |
| download | emacs-3b7cb5f3ac0fdd5e1a0177cc86b3fc4b420b9e4f.tar.gz emacs-3b7cb5f3ac0fdd5e1a0177cc86b3fc4b420b9e4f.zip | |
* lisp/dired.el (dired-mark-region): New defcustom (bug#39902)
* lisp/dired.el (dired-mark-if): Use dired-mark-region.
(dired-mark): Use dired-mark-region. Fix docstring.
(dired-mark-files-regexp, dired-mark-files-containing-regexp)
(dired-mark-symlinks, dired-mark-directories)
(dired-mark-executables, dired-flag-auto-save-files)
(dired-flag-backup-files): Mention dired-mark-region in docstring.
* lisp/dired-aux.el (dired-compare-directories):
* lisp/dired-x.el (dired-mark-unmarked-files, dired-mark-sexp):
Mention dired-mark-region in docstring.
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/dired-aux.el | 5 | ||||
| -rw-r--r-- | lisp/dired-x.el | 8 | ||||
| -rw-r--r-- | lisp/dired.el | 105 |
4 files changed, 106 insertions, 18 deletions
| @@ -101,6 +101,12 @@ shows equivalent key bindings for all commands that have them. | |||
| 101 | 101 | ||
| 102 | ** Dired | 102 | ** Dired |
| 103 | 103 | ||
| 104 | *** New option 'dired-mark-region' affects all Dired commands that mark files. | ||
| 105 | When non-nil and the region is active in Transient Mark mode, | ||
| 106 | then Dired commands operate only on files in the active region. | ||
| 107 | The values 'exclusive' and 'inclusive' of this option define | ||
| 108 | the details of marking the last file at the end of the region. | ||
| 109 | |||
| 104 | *** State changing VC operations are supported in dired-mode on files | 110 | *** State changing VC operations are supported in dired-mode on files |
| 105 | (but still not on directories). | 111 | (but still not on directories). |
| 106 | 112 | ||
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 8f00317c2b0..6f50a3da6ca 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el | |||
| @@ -205,7 +205,10 @@ Examples of PREDICATE: | |||
| 205 | (not (and (= (file-attribute-user-id fa1) - mark files with different UID | 205 | (not (and (= (file-attribute-user-id fa1) - mark files with different UID |
| 206 | (file-attribute-user-id fa2)) | 206 | (file-attribute-user-id fa2)) |
| 207 | (= (file-attribute-group-id fa1) - and GID. | 207 | (= (file-attribute-group-id fa1) - and GID. |
| 208 | (file-attribute-group-id fa2))))" | 208 | (file-attribute-group-id fa2)))) |
| 209 | |||
| 210 | If the region is active in Transient Mark mode, mark files | ||
| 211 | only in the active region if `dired-mark-region' is non-nil." | ||
| 209 | (interactive | 212 | (interactive |
| 210 | (list | 213 | (list |
| 211 | (let* ((target-dir (dired-dwim-target-directory)) | 214 | (let* ((target-dir (dired-dwim-target-directory)) |
diff --git a/lisp/dired-x.el b/lisp/dired-x.el index 623a1dd3255..873d586ca1b 100644 --- a/lisp/dired-x.el +++ b/lisp/dired-x.el | |||
| @@ -623,7 +623,9 @@ interactively, prompt for REGEXP. | |||
| 623 | With prefix argument, unflag all those files. | 623 | With prefix argument, unflag all those files. |
| 624 | Optional fourth argument LOCALP is as in `dired-get-filename'. | 624 | Optional fourth argument LOCALP is as in `dired-get-filename'. |
| 625 | Optional fifth argument CASE-FOLD-P specifies the value of | 625 | Optional fifth argument CASE-FOLD-P specifies the value of |
| 626 | `case-fold-search' used for matching REGEXP." | 626 | `case-fold-search' used for matching REGEXP. |
| 627 | If the region is active in Transient Mark mode, operate only on | ||
| 628 | files in the active region if `dired-mark-region' is non-nil." | ||
| 627 | (interactive | 629 | (interactive |
| 628 | (list (read-regexp | 630 | (list (read-regexp |
| 629 | "Mark unmarked files matching regexp (default all): " | 631 | "Mark unmarked files matching regexp (default all): " |
| @@ -1386,7 +1388,9 @@ present for some values of `ls-lisp-emulation'. | |||
| 1386 | 1388 | ||
| 1387 | This function operates only on the buffer content and does not | 1389 | This function operates only on the buffer content and does not |
| 1388 | refer at all to the underlying file system. Contrast this with | 1390 | refer at all to the underlying file system. Contrast this with |
| 1389 | `find-dired', which might be preferable for the task at hand." | 1391 | `find-dired', which might be preferable for the task at hand. |
| 1392 | If the region is active in Transient Mark mode, mark files | ||
| 1393 | only in the active region if `dired-mark-region' is non-nil." | ||
| 1390 | ;; Using sym="" instead of nil avoids the trap of | 1394 | ;; Using sym="" instead of nil avoids the trap of |
| 1391 | ;; (string-match "foo" sym) into which a user would soon fall. | 1395 | ;; (string-match "foo" sym) into which a user would soon fall. |
| 1392 | ;; Give `equal' instead of `=' in the example, as this works on | 1396 | ;; Give `equal' instead of `=' in the example, as this works on |
diff --git a/lisp/dired.el b/lisp/dired.el index a4de51f6091..438f5e7d8b4 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -296,6 +296,34 @@ new Dired buffers." | |||
| 296 | :version "26.1" | 296 | :version "26.1" |
| 297 | :group 'dired) | 297 | :group 'dired) |
| 298 | 298 | ||
| 299 | (defcustom dired-mark-region 'exclusive | ||
| 300 | "Defines what commands that mark files do with the active region. | ||
| 301 | |||
| 302 | When nil, marking commands don't operate on all files in the | ||
| 303 | active region. They process their prefix arguments as usual. | ||
| 304 | |||
| 305 | When the value of this option is non-nil, then all Dired commands | ||
| 306 | that mark or unmark files will operate on all files in the region | ||
| 307 | if the region is active in Transient Mark mode. | ||
| 308 | |||
| 309 | When `exclusive', don't mark the file if the end of the region is | ||
| 310 | before the file name displayed on the Dired line, so the file name | ||
| 311 | is visually outside the region. This behavior is consistent with | ||
| 312 | marking files without the region using the key `m' that advances | ||
| 313 | point to the next line after marking the file. Thus the number | ||
| 314 | of keys used to mark files is the same as the number of keys | ||
| 315 | used to select the region, e.g. `M-2 m' marks 2 files, and | ||
| 316 | `C-SPC M-2 n m' marks 2 files, and `M-2 S-down m' marks 2 files. | ||
| 317 | |||
| 318 | When `inclusive', include the file into marking if the end of the region | ||
| 319 | is anywhere on its Dired line, except the beginning of the line." | ||
| 320 | :type '(choice | ||
| 321 | (const :tag "Don't mark files in active region" nil) | ||
| 322 | (const :tag "Exclude file name outside of region" exclusive) | ||
| 323 | (const :tag "Include the file at region end line" inclusive)) | ||
| 324 | :group 'dired | ||
| 325 | :version "28.1") | ||
| 326 | |||
| 299 | ;; Internal variables | 327 | ;; Internal variables |
| 300 | 328 | ||
| 301 | (defvar dired-marker-char ?* ; the answer is 42 | 329 | (defvar dired-marker-char ?* ; the answer is 42 |
| @@ -612,12 +640,31 @@ Subexpression 2 must end right before the \\n.") | |||
| 612 | PREDICATE is evaluated on each line, with point at beginning of line. | 640 | PREDICATE is evaluated on each line, with point at beginning of line. |
| 613 | MSG is a noun phrase for the type of files being marked. | 641 | MSG is a noun phrase for the type of files being marked. |
| 614 | It should end with a noun that can be pluralized by adding `s'. | 642 | It should end with a noun that can be pluralized by adding `s'. |
| 643 | |||
| 644 | In Transient Mark mode, if the mark is active, operate on the contents | ||
| 645 | of the region if `dired-mark-region' is non-nil. Otherwise, operate | ||
| 646 | on the whole buffer. | ||
| 647 | |||
| 615 | Return value is the number of files marked, or nil if none were marked." | 648 | Return value is the number of files marked, or nil if none were marked." |
| 616 | `(let ((inhibit-read-only t) count) | 649 | `(let ((inhibit-read-only t) count |
| 650 | (beg (if (and dired-mark-region (use-region-p)) | ||
| 651 | (save-excursion | ||
| 652 | (goto-char (region-beginning)) | ||
| 653 | (line-beginning-position)) | ||
| 654 | (point-min))) | ||
| 655 | (end (if (and dired-mark-region (use-region-p)) | ||
| 656 | (save-excursion | ||
| 657 | (goto-char (region-end)) | ||
| 658 | (if (if (eq dired-mark-region 'inclusive) | ||
| 659 | (not (bolp)) | ||
| 660 | (get-text-property (1- (point)) 'dired-filename)) | ||
| 661 | (line-end-position) | ||
| 662 | (line-beginning-position))) | ||
| 663 | (point-max)))) | ||
| 617 | (save-excursion | 664 | (save-excursion |
| 618 | (setq count 0) | 665 | (setq count 0) |
| 619 | (when ,msg | 666 | (when ,msg |
| 620 | (message "%s %ss%s..." | 667 | (message "%s %ss%s%s..." |
| 621 | (cond ((eq dired-marker-char ?\s) "Unmarking") | 668 | (cond ((eq dired-marker-char ?\s) "Unmarking") |
| 622 | ((eq dired-del-marker dired-marker-char) | 669 | ((eq dired-del-marker dired-marker-char) |
| 623 | "Flagging") | 670 | "Flagging") |
| @@ -625,22 +672,28 @@ Return value is the number of files marked, or nil if none were marked." | |||
| 625 | ,msg | 672 | ,msg |
| 626 | (if (eq dired-del-marker dired-marker-char) | 673 | (if (eq dired-del-marker dired-marker-char) |
| 627 | " for deletion" | 674 | " for deletion" |
| 628 | ""))) | 675 | "") |
| 629 | (goto-char (point-min)) | 676 | (if (and dired-mark-region (use-region-p)) |
| 630 | (while (not (eobp)) | 677 | " in region" |
| 678 | ""))) | ||
| 679 | (goto-char beg) | ||
| 680 | (while (< (point) end) | ||
| 631 | (when ,predicate | 681 | (when ,predicate |
| 632 | (unless (= (following-char) dired-marker-char) | 682 | (unless (= (following-char) dired-marker-char) |
| 633 | (delete-char 1) | 683 | (delete-char 1) |
| 634 | (insert dired-marker-char) | 684 | (insert dired-marker-char) |
| 635 | (setq count (1+ count)))) | 685 | (setq count (1+ count)))) |
| 636 | (forward-line 1)) | 686 | (forward-line 1)) |
| 637 | (when ,msg (message "%s %s%s %s%s" | 687 | (when ,msg (message "%s %s%s %s%s%s" |
| 638 | count | 688 | count |
| 639 | ,msg | 689 | ,msg |
| 640 | (dired-plural-s count) | 690 | (dired-plural-s count) |
| 641 | (if (eq dired-marker-char ?\s) "un" "") | 691 | (if (eq dired-marker-char ?\s) "un" "") |
| 642 | (if (eq dired-marker-char dired-del-marker) | 692 | (if (eq dired-marker-char dired-del-marker) |
| 643 | "flagged" "marked")))) | 693 | "flagged" "marked") |
| 694 | (if (and dired-mark-region (use-region-p)) | ||
| 695 | " in region" | ||
| 696 | "")))) | ||
| 644 | (and (> count 0) count))) | 697 | (and (> count 0) count))) |
| 645 | 698 | ||
| 646 | (defmacro dired-map-over-marks (body arg &optional show-progress | 699 | (defmacro dired-map-over-marks (body arg &optional show-progress |
| @@ -3580,7 +3633,8 @@ no ARGth marked file is found before this line." | |||
| 3580 | 3633 | ||
| 3581 | (defun dired-mark (arg &optional interactive) | 3634 | (defun dired-mark (arg &optional interactive) |
| 3582 | "Mark the file at point in the Dired buffer. | 3635 | "Mark the file at point in the Dired buffer. |
| 3583 | If the region is active, mark all files in the region. | 3636 | If the region is active in Transient Mark mode, mark all files |
| 3637 | in the region if `dired-mark-region' is non-nil. | ||
| 3584 | Otherwise, with a prefix arg, mark files on the next ARG lines. | 3638 | Otherwise, with a prefix arg, mark files on the next ARG lines. |
| 3585 | 3639 | ||
| 3586 | If on a subdir headerline, mark all its files except `.' and `..'. | 3640 | If on a subdir headerline, mark all its files except `.' and `..'. |
| @@ -3591,13 +3645,18 @@ this subdir." | |||
| 3591 | (interactive (list current-prefix-arg t)) | 3645 | (interactive (list current-prefix-arg t)) |
| 3592 | (cond | 3646 | (cond |
| 3593 | ;; Mark files in the active region. | 3647 | ;; Mark files in the active region. |
| 3594 | ((and interactive (use-region-p)) | 3648 | ((and dired-mark-region interactive (use-region-p)) |
| 3595 | (save-excursion | 3649 | (save-excursion |
| 3596 | (let ((beg (region-beginning)) | 3650 | (let ((beg (region-beginning)) |
| 3597 | (end (region-end))) | 3651 | (end (region-end))) |
| 3598 | (dired-mark-files-in-region | 3652 | (dired-mark-files-in-region |
| 3599 | (progn (goto-char beg) (line-beginning-position)) | 3653 | (progn (goto-char beg) (line-beginning-position)) |
| 3600 | (progn (goto-char end) (line-beginning-position)))))) | 3654 | (progn (goto-char end) |
| 3655 | (if (if (eq dired-mark-region 'inclusive) | ||
| 3656 | (not (bolp)) | ||
| 3657 | (get-text-property (1- (point)) 'dired-filename)) | ||
| 3658 | (line-end-position) | ||
| 3659 | (line-beginning-position))))))) | ||
| 3601 | ;; Mark subdir files from the subdir headerline. | 3660 | ;; Mark subdir files from the subdir headerline. |
| 3602 | ((dired-get-subdir) | 3661 | ((dired-get-subdir) |
| 3603 | (save-excursion (dired-mark-subdir-files))) | 3662 | (save-excursion (dired-mark-subdir-files))) |
| @@ -3678,6 +3737,9 @@ As always, hidden subdirs are not affected." | |||
| 3678 | A prefix argument means to unmark them instead. | 3737 | A prefix argument means to unmark them instead. |
| 3679 | `.' and `..' are never marked. | 3738 | `.' and `..' are never marked. |
| 3680 | 3739 | ||
| 3740 | If the region is active in Transient Mark mode, mark files | ||
| 3741 | only in the active region if `dired-mark-region' is non-nil. | ||
| 3742 | |||
| 3681 | REGEXP is an Emacs regexp, not a shell wildcard. Thus, use `\\.o$' for | 3743 | REGEXP is an Emacs regexp, not a shell wildcard. Thus, use `\\.o$' for |
| 3682 | object files--just `.o' will mark more than you might think." | 3744 | object files--just `.o' will mark more than you might think." |
| 3683 | (interactive | 3745 | (interactive |
| @@ -3729,6 +3791,9 @@ object files--just `.o' will mark more than you might think." | |||
| 3729 | A prefix argument means to unmark them instead. | 3791 | A prefix argument means to unmark them instead. |
| 3730 | `.' and `..' are never marked. | 3792 | `.' and `..' are never marked. |
| 3731 | 3793 | ||
| 3794 | If the region is active in Transient Mark mode, mark files | ||
| 3795 | only in the active region if `dired-mark-region' is non-nil. | ||
| 3796 | |||
| 3732 | Note that if a file is visited in an Emacs buffer, and | 3797 | Note that if a file is visited in an Emacs buffer, and |
| 3733 | `dired-always-read-filesystem' is nil, this command will | 3798 | `dired-always-read-filesystem' is nil, this command will |
| 3734 | look in the buffer without revisiting the file, so the results might | 3799 | look in the buffer without revisiting the file, so the results might |
| @@ -3773,14 +3838,18 @@ The match is against the non-directory part of the filename. Use `^' | |||
| 3773 | 3838 | ||
| 3774 | (defun dired-mark-symlinks (unflag-p) | 3839 | (defun dired-mark-symlinks (unflag-p) |
| 3775 | "Mark all symbolic links. | 3840 | "Mark all symbolic links. |
| 3776 | With prefix argument, unmark or unflag all those files." | 3841 | With prefix argument, unmark or unflag all those files. |
| 3842 | If the region is active in Transient Mark mode, mark files | ||
| 3843 | only in the active region if `dired-mark-region' is non-nil." | ||
| 3777 | (interactive "P") | 3844 | (interactive "P") |
| 3778 | (let ((dired-marker-char (if unflag-p ?\s dired-marker-char))) | 3845 | (let ((dired-marker-char (if unflag-p ?\s dired-marker-char))) |
| 3779 | (dired-mark-if (looking-at-p dired-re-sym) "symbolic link"))) | 3846 | (dired-mark-if (looking-at-p dired-re-sym) "symbolic link"))) |
| 3780 | 3847 | ||
| 3781 | (defun dired-mark-directories (unflag-p) | 3848 | (defun dired-mark-directories (unflag-p) |
| 3782 | "Mark all directory file lines except `.' and `..'. | 3849 | "Mark all directory file lines except `.' and `..'. |
| 3783 | With prefix argument, unmark or unflag all those files." | 3850 | With prefix argument, unmark or unflag all those files. |
| 3851 | If the region is active in Transient Mark mode, mark files | ||
| 3852 | only in the active region if `dired-mark-region' is non-nil." | ||
| 3784 | (interactive "P") | 3853 | (interactive "P") |
| 3785 | (let ((dired-marker-char (if unflag-p ?\s dired-marker-char))) | 3854 | (let ((dired-marker-char (if unflag-p ?\s dired-marker-char))) |
| 3786 | (dired-mark-if (and (looking-at-p dired-re-dir) | 3855 | (dired-mark-if (and (looking-at-p dired-re-dir) |
| @@ -3789,7 +3858,9 @@ With prefix argument, unmark or unflag all those files." | |||
| 3789 | 3858 | ||
| 3790 | (defun dired-mark-executables (unflag-p) | 3859 | (defun dired-mark-executables (unflag-p) |
| 3791 | "Mark all executable files. | 3860 | "Mark all executable files. |
| 3792 | With prefix argument, unmark or unflag all those files." | 3861 | With prefix argument, unmark or unflag all those files. |
| 3862 | If the region is active in Transient Mark mode, mark files | ||
| 3863 | only in the active region if `dired-mark-region' is non-nil." | ||
| 3793 | (interactive "P") | 3864 | (interactive "P") |
| 3794 | (let ((dired-marker-char (if unflag-p ?\s dired-marker-char))) | 3865 | (let ((dired-marker-char (if unflag-p ?\s dired-marker-char))) |
| 3795 | (dired-mark-if (looking-at-p dired-re-exe) "executable file"))) | 3866 | (dired-mark-if (looking-at-p dired-re-exe) "executable file"))) |
| @@ -3799,7 +3870,9 @@ With prefix argument, unmark or unflag all those files." | |||
| 3799 | 3870 | ||
| 3800 | (defun dired-flag-auto-save-files (&optional unflag-p) | 3871 | (defun dired-flag-auto-save-files (&optional unflag-p) |
| 3801 | "Flag for deletion files whose names suggest they are auto save files. | 3872 | "Flag for deletion files whose names suggest they are auto save files. |
| 3802 | A prefix argument says to unmark or unflag those files instead." | 3873 | A prefix argument says to unmark or unflag those files instead. |
| 3874 | If the region is active in Transient Mark mode, flag files | ||
| 3875 | only in the active region if `dired-mark-region' is non-nil." | ||
| 3803 | (interactive "P") | 3876 | (interactive "P") |
| 3804 | (let ((dired-marker-char (if unflag-p ?\s dired-del-marker))) | 3877 | (let ((dired-marker-char (if unflag-p ?\s dired-del-marker))) |
| 3805 | (dired-mark-if | 3878 | (dired-mark-if |
| @@ -3839,7 +3912,9 @@ A prefix argument says to unmark or unflag those files instead." | |||
| 3839 | 3912 | ||
| 3840 | (defun dired-flag-backup-files (&optional unflag-p) | 3913 | (defun dired-flag-backup-files (&optional unflag-p) |
| 3841 | "Flag all backup files (names ending with `~') for deletion. | 3914 | "Flag all backup files (names ending with `~') for deletion. |
| 3842 | With prefix argument, unmark or unflag these files." | 3915 | With prefix argument, unmark or unflag these files. |
| 3916 | If the region is active in Transient Mark mode, flag files | ||
| 3917 | only in the active region if `dired-mark-region' is non-nil." | ||
| 3843 | (interactive "P") | 3918 | (interactive "P") |
| 3844 | (let ((dired-marker-char (if unflag-p ?\s dired-del-marker))) | 3919 | (let ((dired-marker-char (if unflag-p ?\s dired-del-marker))) |
| 3845 | (dired-mark-if | 3920 | (dired-mark-if |