diff options
| author | Juri Linkov | 2020-06-05 01:17:30 +0300 |
|---|---|---|
| committer | Juri Linkov | 2020-06-05 01:17:30 +0300 |
| commit | 25390b28c43401caee749554871217d3436ea9bd (patch) | |
| tree | 1014abb36863cc1fa4f3e7f7240364729457128a | |
| parent | f4568bac56968c2d7837d6f5be561f3cf4430388 (diff) | |
| download | emacs-25390b28c43401caee749554871217d3436ea9bd.tar.gz emacs-25390b28c43401caee749554871217d3436ea9bd.zip | |
* lisp/dired.el (dired-toggle-marks): Use region for non-nil dired-mark-region
(dired-mark--region-use-p, dired-mark--region-beginning)
(dired-mark--region-end): New internal functions.
(dired-mark-if): Use new functions. (Bug#39902)
| -rw-r--r-- | lisp/dired.el | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/lisp/dired.el b/lisp/dired.el index aad44a6d698..1792250ac90 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -648,24 +648,10 @@ of the region if `dired-mark-region' is non-nil. Otherwise, operate | |||
| 648 | on the whole buffer. | 648 | on the whole buffer. |
| 649 | 649 | ||
| 650 | Return value is the number of files marked, or nil if none were marked." | 650 | Return value is the number of files marked, or nil if none were marked." |
| 651 | `(let* ((inhibit-read-only t) count | 651 | `(let ((inhibit-read-only t) count |
| 652 | (use-region-p (and dired-mark-region | 652 | (use-region-p (dired-mark--region-use-p)) |
| 653 | (region-active-p) | 653 | (beg (dired-mark--region-beginning)) |
| 654 | (> (region-end) (region-beginning)))) | 654 | (end (dired-mark--region-end))) |
| 655 | (beg (if use-region-p | ||
| 656 | (save-excursion | ||
| 657 | (goto-char (region-beginning)) | ||
| 658 | (line-beginning-position)) | ||
| 659 | (point-min))) | ||
| 660 | (end (if use-region-p | ||
| 661 | (save-excursion | ||
| 662 | (goto-char (region-end)) | ||
| 663 | (if (if (eq dired-mark-region 'line) | ||
| 664 | (not (bolp)) | ||
| 665 | (get-text-property (1- (point)) 'dired-filename)) | ||
| 666 | (line-end-position) | ||
| 667 | (line-beginning-position))) | ||
| 668 | (point-max)))) | ||
| 669 | (save-excursion | 655 | (save-excursion |
| 670 | (setq count 0) | 656 | (setq count 0) |
| 671 | (when ,msg | 657 | (when ,msg |
| @@ -817,6 +803,32 @@ ERROR can be a string with the error message." | |||
| 817 | (user-error (if (stringp error) error "No files specified"))) | 803 | (user-error (if (stringp error) error "No files specified"))) |
| 818 | result)) | 804 | result)) |
| 819 | 805 | ||
| 806 | (defun dired-mark--region-use-p () | ||
| 807 | "Whether Dired marking commands should act on region." | ||
| 808 | (and dired-mark-region | ||
| 809 | (region-active-p) | ||
| 810 | (> (region-end) (region-beginning)))) | ||
| 811 | |||
| 812 | (defun dired-mark--region-beginning () | ||
| 813 | "Return the value of the region beginning aligned to Dired file lines." | ||
| 814 | (if (dired-mark--region-use-p) | ||
| 815 | (save-excursion | ||
| 816 | (goto-char (region-beginning)) | ||
| 817 | (line-beginning-position)) | ||
| 818 | (point-min))) | ||
| 819 | |||
| 820 | (defun dired-mark--region-end () | ||
| 821 | "Return the value of the region end aligned to Dired file lines." | ||
| 822 | (if (dired-mark--region-use-p) | ||
| 823 | (save-excursion | ||
| 824 | (goto-char (region-end)) | ||
| 825 | (if (if (eq dired-mark-region 'line) | ||
| 826 | (not (bolp)) | ||
| 827 | (get-text-property (1- (point)) 'dired-filename)) | ||
| 828 | (line-end-position) | ||
| 829 | (line-beginning-position))) | ||
| 830 | (point-max))) | ||
| 831 | |||
| 820 | 832 | ||
| 821 | ;; The dired command | 833 | ;; The dired command |
| 822 | 834 | ||
| @@ -3719,12 +3731,18 @@ in the active region." | |||
| 3719 | "Toggle marks: marked files become unmarked, and vice versa. | 3731 | "Toggle marks: marked files become unmarked, and vice versa. |
| 3720 | Flagged files (indicated with flags such as `C' and `D', not | 3732 | Flagged files (indicated with flags such as `C' and `D', not |
| 3721 | with `*') are not affected, and `.' and `..' are never toggled. | 3733 | with `*') are not affected, and `.' and `..' are never toggled. |
| 3722 | As always, hidden subdirs are not affected." | 3734 | As always, hidden subdirs are not affected. |
| 3735 | |||
| 3736 | In Transient Mark mode, if the mark is active, operate on the contents | ||
| 3737 | of the region if `dired-mark-region' is non-nil. Otherwise, operate | ||
| 3738 | on the whole buffer." | ||
| 3723 | (interactive) | 3739 | (interactive) |
| 3724 | (save-excursion | 3740 | (save-excursion |
| 3725 | (goto-char (point-min)) | 3741 | (let ((inhibit-read-only t) |
| 3726 | (let ((inhibit-read-only t)) | 3742 | (beg (dired-mark--region-beginning)) |
| 3727 | (while (not (eobp)) | 3743 | (end (dired-mark--region-end))) |
| 3744 | (goto-char beg) | ||
| 3745 | (while (< (point) end) | ||
| 3728 | (or (dired-between-files) | 3746 | (or (dired-between-files) |
| 3729 | (looking-at-p dired-re-dot) | 3747 | (looking-at-p dired-re-dot) |
| 3730 | ;; use subst instead of insdel because it does not move | 3748 | ;; use subst instead of insdel because it does not move |