unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#22893: 25.1.50; dired-get-marked-files get all marked
@ 2016-03-03  9:38 Tino Calancha
  2016-03-04 12:32 ` Lars Ingebrigtsen
  2016-03-22  9:31 ` bug#22893: dired-marker-regexp use dired-re-mark Tino Calancha
  0 siblings, 2 replies; 13+ messages in thread
From: Tino Calancha @ 2016-03-03  9:38 UTC (permalink / raw)
  To: 22893

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



* lisp/dired.el(dired-get-marked-files): Added two optional args,
`marker-char' and `all-maks'.
(dired-map-over-marks): Added optional arg `all-marks'.
(dired-marker-regexp): Added optional arg `all-marks'.

1) `marker-char'. If non-nil,
the files retrieved are those marked with MARKER-CHAR.
Otherwise the returned files are those marked with
`dired-marker-char'.

2) all-marks, if non-nil, all marked files are returned
regardless of their actual mark (`dired-marker-char' or
a different one).

Callers are not affected: the args are optional and
added at the end of the parameter list.


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: 6499 bytes --]

diff --git a/lisp/dired.el b/lisp/dired.el
index 6c7445c..1e48f32 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -553,7 +553,7 @@ dired-mark-if
     (and (> count 0) count)))
 
 (defmacro dired-map-over-marks (body arg &optional show-progress
-				     distinguish-one-marked)
+                     distinguish-one-marked all-marks)
   "Eval BODY with point on each marked line.  Return a list of BODY's results.
 If no marked file could be found, execute BODY on the current
 line.  ARG, if non-nil, specifies the files to use instead of the
@@ -579,55 +579,57 @@ dired-map-over-marks
 BODY should not be too long as it is expanded four times.
 
 If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one
-marked file, return (t FILENAME) instead of (FILENAME)."
+marked file, return (t FILENAME) instead of (FILENAME).
+
+If ALL-MARKS is non-nil, accept all non blank marks not just `dired-marker-char'."
   ;;
   ;;Warning: BODY must not add new lines before point - this may cause an
   ;;endless loop.
   ;;This warning should not apply any longer, sk  2-Sep-1991 14:10.
   `(prog1
        (let ((inhibit-read-only t) case-fold-search found results)
-	 (if ,arg
-	     (if (integerp ,arg)
-		 (progn	;; no save-excursion, want to move point.
-		   (dired-repeat-over-lines
-		    ,arg
-		    (function (lambda ()
-				(if ,show-progress (sit-for 0))
-				(setq results (cons ,body results)))))
-		   (if (< ,arg 0)
-		       (nreverse results)
-		     results))
-	       ;; non-nil, non-integer ARG means use current file:
-	       (list ,body))
-	   (let ((regexp (dired-marker-regexp)) next-position)
-	     (save-excursion
-	       (goto-char (point-min))
-	       ;; remember position of next marked file before BODY
-	       ;; can insert lines before the just found file,
-	       ;; confusing us by finding the same marked file again
-	       ;; and again and...
-	       (setq next-position (and (re-search-forward regexp nil t)
-					(point-marker))
-		     found (not (null next-position)))
-	       (while next-position
-		 (goto-char next-position)
-		 (if ,show-progress (sit-for 0))
-		 (setq results (cons ,body results))
-		 ;; move after last match
-		 (goto-char next-position)
-		 (forward-line 1)
-		 (set-marker next-position nil)
-		 (setq next-position (and (re-search-forward regexp nil t)
-					  (point-marker)))))
-	     (if (and ,distinguish-one-marked (= (length results) 1))
-		 (setq results (cons t results)))
-	     (if found
-		 results
-	       (list ,body)))))
+     (if ,arg
+         (if (integerp ,arg)
+         (progn ;; no save-excursion, want to move point.
+           (dired-repeat-over-lines
+            ,arg
+            (function (lambda ()
+                (if ,show-progress (sit-for 0))
+                (setq results (cons ,body results)))))
+           (if (< ,arg 0)
+               (nreverse results)
+             results))
+           ;; non-nil, non-integer ARG means use current file:
+           (list ,body))
+       (let ((regexp (dired-marker-regexp ,all-marks)) next-position)
+         (save-excursion
+           (goto-char (point-min))
+           ;; remember position of next marked file before BODY
+           ;; can insert lines before the just found file,
+           ;; confusing us by finding the same marked file again
+           ;; and again and...
+           (setq next-position (and (re-search-forward regexp nil t)
+                    (point-marker))
+             found (not (null next-position)))
+           (while next-position
+         (goto-char next-position)
+         (if ,show-progress (sit-for 0))
+         (setq results (cons ,body results))
+         ;; move after last match
+         (goto-char next-position)
+         (forward-line 1)
+         (set-marker next-position nil)
+         (setq next-position (and (re-search-forward regexp nil t)
+                      (point-marker)))))
+         (if (and ,distinguish-one-marked (= (length results) 1))
+         (setq results (cons t results)))
+         (if found
+         results
+           (list ,body)))))
      ;; save-excursion loses, again
      (dired-move-to-filename)))
 
-(defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked)
+(defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked marker-char all-marks)
   "Return the marked files' names as list of strings.
 The list is in the same order as the buffer, that is, the car is the
   first marked file.
@@ -644,22 +646,28 @@ dired-get-marked-files
 
 If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file,
 return (t FILENAME) instead of (FILENAME).
-Don't use that together with FILTER."
-  (let ((all-of-them
-	 (save-excursion
-	   (delq nil (dired-map-over-marks
-		      (dired-get-filename localp 'no-error-if-not-filep)
-		      arg nil distinguish-one-marked))))
-	result)
+Don't use that together with FILTER.
+
+Optional arg MARKER-CHAR, if non-nil, then it is the marker
+char to search. Otherwise `dired-marker-char' is used.
+
+Optional arg ALL-MARKS, if non-nil, then all non blank marks are accepted."
+  (let* ((dired-marker-char (or marker-char dired-marker-char))
+         (all-of-them
+          (save-excursion
+            (delq nil (dired-map-over-marks
+                       (dired-get-filename localp 'no-error-if-not-filep)
+                       arg nil distinguish-one-marked all-marks))))
+         result)
     (when (equal all-of-them '(t))
       (setq all-of-them nil))
     (if (not filter)
-	(if (and distinguish-one-marked (eq (car all-of-them) t))
-	    all-of-them
-	  (nreverse all-of-them))
+    (if (and distinguish-one-marked (eq (car all-of-them) t))
+        all-of-them
+      (nreverse all-of-them))
       (dolist (file all-of-them)
-	(if (funcall filter file)
-	    (push file result)))
+    (if (funcall filter file)
+        (push file result)))
       result)))
 \f
 ;; The dired command
@@ -3031,8 +3039,10 @@ dired-clean-up-after-deletion
 \f
 ;; Confirmation
 
-(defun dired-marker-regexp ()
-  (concat "^" (regexp-quote (char-to-string dired-marker-char))))
+(defun dired-marker-regexp (&optional all-marks)
+  (if all-marks
+      "^[^\t ]"
+    (concat "^" (regexp-quote (char-to-string dired-marker-char)))))
 
 (defun dired-plural-s (count)
   (if (= 1 count) "" "s"))

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-08-12 11:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-03  9:38 bug#22893: 25.1.50; dired-get-marked-files get all marked Tino Calancha
2016-03-04 12:32 ` Lars Ingebrigtsen
2016-03-05 13:14   ` Tino Calancha
2016-03-08  5:18   ` Tino Calancha
2016-03-08 16:01     ` Eli Zaretskii
2016-03-09 15:27       ` Tino Calancha
2016-03-09 23:57         ` Juri Linkov
2016-03-10  4:19           ` Tino Calancha
2019-06-25 14:07             ` bug#22892: " Lars Ingebrigtsen
2020-08-12 11:58               ` Lars Ingebrigtsen
2016-03-10  4:43           ` Tino Calancha
2016-03-11  0:48             ` Juri Linkov
2016-03-22  9:31 ` bug#22893: dired-marker-regexp use dired-re-mark Tino Calancha

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).