bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#39902: 28.0.50; Marking in dired with active region


From: Juri Linkov
Subject: bug#39902: 28.0.50; Marking in dired with active region
Date: Fri, 20 Mar 2020 01:54:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>> I see our different views as of the same right and value.  And the use
>> case (who uses marking commands with an active region at all?) is a
>> corner case.  I don't mind about the default as long as there is a new
>> option.
>
> So Dired could do the same and support both range types using a new option
> 'dired-mark-inclusive'.
>
>> I would rather want to discuss what else should be done
>> (behavior of other marking commands etc, should we change
>> `dired-mark-if', etc.
>
> I think `dired-mark-if' should respect that option too.

Here is a complete implementation, please try if it works for you:

diff --git a/lisp/dired.el b/lisp/dired.el
index a4de51f609..6858245ab7 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -296,6 +296,12 @@ dired-always-read-filesystem
   :version "26.1"
   :group 'dired)
 
+(defcustom dired-mark-inclusive nil
+  "Non-nil means `dired-mark' is inclusive."
+  :type 'boolean
+  :version "28.1"
+  :group 'dired)
+
 ;; Internal variables
 
 (defvar dired-marker-char ?*           ; the answer is 42
@@ -613,7 +619,21 @@ dired-mark-if
 MSG is a noun phrase for the type of files being marked.
 It should end with a noun that can be pluralized by adding `s'.
 Return value is the number of files marked, or nil if none were marked."
-  `(let ((inhibit-read-only t) count)
+  `(let ((inhibit-read-only t) count
+         (beg (if (use-region-p)
+                  (save-excursion
+                    (goto-char (region-beginning))
+                    (line-beginning-position))
+                (point-min)))
+         (end (if (use-region-p)
+                  (save-excursion
+                    (goto-char (region-end))
+                    (if (if dired-mark-inclusive
+                            (not (bolp))
+                          (get-text-property (1- (point)) 'dired-filename))
+                        (line-end-position)
+                      (line-beginning-position)))
+                (point-max))))
     (save-excursion
       (setq count 0)
       (when ,msg
@@ -626,8 +646,8 @@ dired-mark-if
                 (if (eq dired-del-marker dired-marker-char)
                     " for deletion"
                   "")))
-      (goto-char (point-min))
-      (while (not (eobp))
+      (goto-char beg)
+      (while (< (point) end)
         (when ,predicate
           (unless (= (following-char) dired-marker-char)
             (delete-char 1)
@@ -3597,7 +3622,12 @@ dired-mark
            (end (region-end)))
        (dired-mark-files-in-region
         (progn (goto-char beg) (line-beginning-position))
-        (progn (goto-char end) (line-beginning-position))))))
+        (progn (goto-char end)
+                (if (if dired-mark-inclusive
+                        (not (bolp))
+                      (get-text-property (1- (point)) 'dired-filename))
+                    (line-end-position)
+                  (line-beginning-position)))))))
    ;; Mark subdir files from the subdir headerline.
    ((dired-get-subdir)
     (save-excursion (dired-mark-subdir-files)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]