unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <f92capac@gmail.com>
To: 22894@debbugs.gnu.org
Subject: bug#22894: 25.1.50; dired-mark: Not remark a marked file
Date: Thu, 3 Mar 2016 19:09:39 +0900 (JST)	[thread overview]
Message-ID: <alpine.LRH.2.20.1603031908030.27140@calancha-ilc.kek.jp> (raw)

[-- Attachment #1: Type: text/plain, Size: 946 bytes --]



* lisp/dired.el (dired-mark-files-in-region,dired-mark):
A marked file can be remarked just:
1) To mark for deletion.
2) To unmark it, that is, the mark changes to `?\\s'.
3) If its marked for deletion, a different mark can be assigned.

The purpose of this changes is to prevent changing accidentally
the mark of a file. Current code allow to change marks on files very
easily.

Marking many files using several markers may need some time, with
some regexp gimnastics. Its a pity if someone accidentaly change
one of the marks. For instance, using `dired-mark-files-in-region',
the last/first file in the region could be included unintentionally
changing the mark of one file.


I'm not sure if allow 1) or to ban it.
I'm not sure if someone find this thread useful either :-)

In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.29)
  of 2016-03-03 built on calancha-pc
Repository revision: 887f6126c5ce9084f93083765ac026ca6b28175c

[-- Attachment #2: Type: text/plain, Size: 3428 bytes --]

diff --git a/lisp/dired.el b/lisp/dired.el
index 6c7445c..057e533 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3215,20 +3215,29 @@ dired-file-marker
 	       (following-char))))))
 
 (defun dired-mark-files-in-region (start end)
+  "Mark all files inside the region in the Dired buffer.
+The mark MARK of a file already marked only changes if:
+1) MARK equals to `dired-del-marker'.
+2) `dired-marked-char' equals to `?\\s' or `dired-del-marker'."
+
   (let ((inhibit-read-only t))
     (if (> start end)
-	(error "start > end"))
-    (goto-char start)			; assumed at beginning of line
+    (error "start > end"))
+    (goto-char start)           ; assumed at beginning of line
     (while (< (point) end)
       ;; Skip subdir line and following garbage like the `total' line:
       (while (and (< (point) end) (dired-between-files))
-	(forward-line 1))
-      (if (and (not (looking-at-p dired-re-dot))
-	       (dired-get-filename nil t))
-	  (progn
-	    (delete-char 1)
-	    (insert dired-marker-char)))
-      (forward-line 1))))
+    (forward-line 1))
+      (when (and (not (looking-at-p dired-re-dot))
+                 (or (looking-at-p "^ ")
+                     (looking-at-p (concat "^" (regexp-quote (char-to-string dired-del-marker))))
+                     (eq dired-marker-char ?\s)
+                     (eq dired-marker-char dired-del-marker))
+                 (dired-get-filename nil t))
+        (delete-char 1)
+        (insert dired-marker-char))
+      (forward-line 1))
+    (deactivate-mark 'force)))
 
 (defun dired-mark (arg &optional interactive)
   "Mark the file at point in the Dired buffer.
@@ -3237,6 +3246,10 @@ dired-mark
 
 If on a subdir headerline, mark all its files except `.' and `..'.
 
+The mark MARK of a file already marked only changes if:
+1) MARK equals to `dired-del-marker'.
+2) `dired-marked-char' equals to `?\\s' or `dired-del-marker'.
+
 Use \\[dired-unmark-all-files] to remove all marks
 and \\[dired-unmark] on a subdir to remove the marks in
 this subdir."
@@ -3246,10 +3259,10 @@ dired-mark
    ((and interactive (use-region-p))
     (save-excursion
       (let ((beg (region-beginning))
-	    (end (region-end)))
-	(dired-mark-files-in-region
-	 (progn (goto-char beg) (line-beginning-position))
-	 (progn (goto-char end) (line-beginning-position))))))
+        (end (region-end)))
+    (dired-mark-files-in-region
+     (progn (goto-char beg) (line-beginning-position))
+     (progn (goto-char end) (line-beginning-position))))))
    ;; Mark subdir files from the subdir headerline.
    ((dired-get-subdir)
     (save-excursion (dired-mark-subdir-files)))
@@ -3258,7 +3271,11 @@ dired-mark
     (let ((inhibit-read-only t))
       (dired-repeat-over-lines
        (prefix-numeric-value arg)
-       (function (lambda () (delete-char 1) (insert dired-marker-char))))))))
+       (function (lambda () (when (or (looking-at-p "^ ")
+                                      (looking-at-p (concat "^" (regexp-quote (char-to-string dired-del-marker))))
+                                      (eq dired-marker-char ?\s)
+                                      (eq dired-marker-char dired-del-marker))
+                              (delete-char 1) (insert dired-marker-char)))))))))
 
 (defun dired-unmark (arg &optional interactive)
   "Unmark the file at point in the Dired buffer.

             reply	other threads:[~2016-03-03 10:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-03 10:09 Tino Calancha [this message]
2016-03-04 12:31 ` bug#22894: 25.1.50; dired-mark: Not remark a marked file Lars Ingebrigtsen
2016-03-05 13:41   ` Tino Calancha
2016-03-05 18:59     ` Drew Adams
2016-03-05 14:06   ` Tino Calancha
2016-07-01  3:22     ` npostavs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LRH.2.20.1603031908030.27140@calancha-ilc.kek.jp \
    --to=f92capac@gmail.com \
    --cc=22894@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).