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

* bug#22893: 25.1.50; dired-get-marked-files get all marked
  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-22  9:31 ` bug#22893: dired-marker-regexp use dired-re-mark Tino Calancha
  1 sibling, 2 replies; 13+ messages in thread
From: Lars Ingebrigtsen @ 2016-03-04 12:32 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 22893

Tino Calancha <f92capac@gmail.com> writes:

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

Looks good, I think.  Can you include a NEWS entry for this and resubmit
the patch?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#22893: 25.1.50; dired-get-marked-files get all marked
  2016-03-04 12:32 ` Lars Ingebrigtsen
@ 2016-03-05 13:14   ` Tino Calancha
  2016-03-08  5:18   ` Tino Calancha
  1 sibling, 0 replies; 13+ messages in thread
From: Tino Calancha @ 2016-03-05 13:14 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Tino Calancha, 22893

> Looks good, I think.  Can you include a NEWS entry for this and resubmit
> the patch?
Sure. I am sending it in the begining of incomming week.





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

* bug#22893: 25.1.50; dired-get-marked-files get all marked
  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
  1 sibling, 1 reply; 13+ messages in thread
From: Tino Calancha @ 2016-03-08  5:18 UTC (permalink / raw)
  To: 22893; +Cc: larsi

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


> Looks good, I think.  Can you include a NEWS entry for this and resubmit
> the patch?
Attached the patch including the NEWS entry.

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

From e2040516b2949ba3f626448463f10baeb178d57c Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac@gmail.com>
Date: Tue, 8 Mar 2016 13:32:49 +0900
Subject: [PATCH 1/2] Dired operate on all kind of mark characters

* lisp/dired.el (dired-map-over-marks): Added optional arg 'all-marks'.
(dired-marker-regexp): Idem.
(dired-get-marked-files): Added two optional args, 'marker-char'
and 'all-marks' (Bug#22893).
If MARKER-CHAR non-nil, return files marked with MARKER-CHAR.
If ALL-MARKS, non-nil, return files marked with any
mark character.

Callers are not affected.
---
 lisp/dired.el | 127 +++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 72 insertions(+), 55 deletions(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index 6c7445c..bf81649 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,60 @@ 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 mark characters.  Otherwise use
+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 +649,29 @@ 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 mark
+character to search.  Otherwise use `dired-marker-char'.
+
+Optional arg ALL-MARKS, if non-nil, then accept all mark characters.
+Otherwise use just MARKER-CHAR."
+  (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 +3043,13 @@ 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)
+  "Return a regexp matching `dired-marker-char' at the beginning of line.
+If optional argument ALL-MARKS evaluates to non-nil, the regexp
+matches any mark character."
+  (if all-marks
+      "^[^\t ]"
+    (concat "^" (regexp-quote (char-to-string dired-marker-char)))))
 
 (defun dired-plural-s (count)
   (if (= 1 count) "" "s"))
-- 
2.7.0


[-- Attachment #3: Type: text/plain, Size: 1763 bytes --]

From f0f31787a679b468e222740954af49c66626b13c Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac@gmail.com>
Date: Tue, 8 Mar 2016 14:04:13 +0900
Subject: [PATCH 2/2] ; Add NEWS entry for last commit

---
 ChangeLog.2 |  8 ++++++++
 etc/NEWS    | 11 +++++++++++
 2 files changed, 19 insertions(+)

diff --git a/ChangeLog.2 b/ChangeLog.2
index 6edc654..1ce9bee 100644
--- a/ChangeLog.2
+++ b/ChangeLog.2
@@ -1,3 +1,11 @@
+2016-03-08  Tino Calancha  <f92capac@gmail.com>
+
+	Dired operate on all kind of mark characters (Bug#22893).
+	* lisp/dired.el (dired-map-over-marks): Added optional arg 'all-marks'.
+	(dired-marker-regexp): Idem.
+	(dired-get-marked-files): Added two optional args, 'marker-char'
+	and 'all-marks'.
+
 2016-02-15  Glenn Morris  <rgm@gnu.org>
 
 	* lisp/dired-aux.el: Require cl-lib.  (Bug#22613)
diff --git a/etc/NEWS b/etc/NEWS
index cf09350..e385fab 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1471,6 +1471,17 @@ previous commands, `dired-do-search' and
 keys; rebind `A' and `Q' to invoke them if you want the old behavior
 back.  We intend to obsolete the old commands in a future release.
 
+---
+*** Dired operate on all kind of mark characters
+`dired-map-over-marks': New optional arg `all-marks'. When non-nil,
+operate over all marks, not just `dired-marker-char'.
+`dired-marker-regexp': Added optional arg `all-marks'.
+`dired-get-marked-files': Added optional args `marker-char' and `all-marks'.
+If MARKER-CHAR non-nil, then return files marked with such character.
+Otherwise return files marked with `dired-marker-char'.
+If ALL-MARKS non-nil, return all marked files. Otherwise return just those
+files marked with MARKER-CHAR.
+
 ** Tabulated List Mode
 
 +++
-- 
2.7.0


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

* bug#22893: 25.1.50; dired-get-marked-files get all marked
  2016-03-08  5:18   ` Tino Calancha
@ 2016-03-08 16:01     ` Eli Zaretskii
  2016-03-09 15:27       ` Tino Calancha
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2016-03-08 16:01 UTC (permalink / raw)
  To: Tino Calancha; +Cc: larsi, 22893

> Date: Tue, 8 Mar 2016 14:18:58 +0900 (JST)
> From: Tino Calancha <f92capac@gmail.com>
> Cc: larsi@gnus.org
> 
> > Looks good, I think.  Can you include a NEWS entry for this and resubmit
> > the patch?
> Attached the patch including the NEWS entry.

Thanks.  Can you reformat this in the style we use in NEWS, which is
more friendly to Outline mode used to read it?  Please take a look at
the existing entries there, I think they provide enough examples.





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

* bug#22893: 25.1.50; dired-get-marked-files get all marked
  2016-03-08 16:01     ` Eli Zaretskii
@ 2016-03-09 15:27       ` Tino Calancha
  2016-03-09 23:57         ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: Tino Calancha @ 2016-03-09 15:27 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Tino Calancha, larsi, 22893

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


> Thanks.  Can you reformat this in the style we use in NEWS, which is
> more friendly to Outline mode used to read it?  Please take a look at
> the existing entries there, I think they provide enough examples.
Sorry for the inconvenients. I edited the second commit with the NEWS.

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

From ce0dc33b76064b5b1bd5f7ae3c8de03c658bb2c0 Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac@gmail.com>
Date: Thu, 10 Mar 2016 00:04:48 +0900
Subject: [PATCH 2/2] ; Added NEWS entry for last commit

---
 etc/NEWS | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index cf09350..4fec101 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1471,6 +1471,14 @@ previous commands, `dired-do-search' and
 keys; rebind `A' and `Q' to invoke them if you want the old behavior
 back.  We intend to obsolete the old commands in a future release.
 
+*** New optional arg ALL-MARKS for `dired-map-over-marks'
+allow to operate over all marked files, not just those
+marked with `dired-marker-char'.
+
+*** New optional args MARKER-CHAR and ALL-MARKS for
+`dired-get-marked-files' to retrieve marked files with a
+particular mark character or with any.
+
 ** Tabulated List Mode
 
 +++
-- 
2.7.0


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

* bug#22893: 25.1.50; dired-get-marked-files get all marked
  2016-03-09 15:27       ` Tino Calancha
@ 2016-03-09 23:57         ` Juri Linkov
  2016-03-10  4:19           ` Tino Calancha
  2016-03-10  4:43           ` Tino Calancha
  0 siblings, 2 replies; 13+ messages in thread
From: Juri Linkov @ 2016-03-09 23:57 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 22893, larsi

merge 22893 22892
thanks

> +*** New optional arg ALL-MARKS for `dired-map-over-marks'
> +allow to operate over all marked files, not just those
> +marked with `dired-marker-char'.
> +
> +*** New optional args MARKER-CHAR and ALL-MARKS for
> +`dired-get-marked-files' to retrieve marked files with a
> +particular mark character or with any.

Since you are changing the function signatures anyway,
you could make them consistent between `dired-map-over-marks'
and `dired-get-marked-files' by adding an explicit arg `marker-char',
i.e. both `dired-get-marked-files' and `dired-map-over-marks'
could end with "distinguish-one-marked marker-char all-marks",
thus explicitly passing `marker-char' arg down the call chain.
Then you'll need `(or marker-char dired-marker-char)' in
`dired-marker-regexp' for backward-compatibility.  And then also
no need to let-bind `dired-marker-char' in `dired-get-marked-files'
(it's better to avoid dynamically binding global variables where possible).





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

* bug#22893: 25.1.50; dired-get-marked-files get all marked
  2016-03-09 23:57         ` Juri Linkov
@ 2016-03-10  4:19           ` Tino Calancha
  2019-06-25 14:07             ` bug#22892: " Lars Ingebrigtsen
  2016-03-10  4:43           ` Tino Calancha
  1 sibling, 1 reply; 13+ messages in thread
From: Tino Calancha @ 2016-03-10  4:19 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Tino Calancha, 22893, larsi

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


> Since you are changing the function signatures anyway,
> you could make them consistent between `dired-map-over-marks'
> and `dired-get-marked-files' by adding an explicit arg `marker-char',
> i.e. both `dired-get-marked-files' and `dired-map-over-marks'
> could end with "distinguish-one-marked marker-char all-marks",
> thus explicitly passing `marker-char' arg down the call chain.
> Then you'll need `(or marker-char dired-marker-char)' in
> `dired-marker-regexp' for backward-compatibility.  And then also
> no need to let-bind `dired-marker-char' in `dired-get-marked-files'
> (it's better to avoid dynamically binding global variables where possible).

It sounds good. Thank you. Implemented in the new patch.

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

From 54428444410aaacc8d1e86678dcb9a8e95fccd4b Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac@gmail.com>
Date: Thu, 10 Mar 2016 13:11:23 +0900
Subject: [PATCH] Avoid dynamic global var binding

* lisp/dired.el (dired-map-over-marks): Last 3 arguments
like in 'dired-get-marked-files' (Bug#22893).
(dired-get-marked-files): Passing arg. MARKER-CHAR directly to
'dired-map-over-marks' call instead of binding 'dired-marker-char'
as before.
Fixed typo in doc. string.
(dired-marker-regexp): Accept two optional args.
; * etc/NEWS: Document the change.
---
 etc/NEWS      |  5 +++++
 lisp/dired.el | 34 ++++++++++++++++++++--------------
 2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index b651b9e..83f66b3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1512,6 +1512,11 @@ previous commands, `dired-do-search' and
 keys; rebind `A' and `Q' to invoke them if you want the old behavior
 back.  We intend to obsolete the old commands in a future release.
 
+*** New optional args MARKER-CHAR and ALL-MARKS for
+`dired-map-over-marks', `dired-get-marked-files' and `dired-marker-regexp'
+allow to operate over files marked with MARKER-CHAR, or over all
+marked files.
+
 ** Tabulated List Mode
 
 +++
diff --git a/lisp/dired.el b/lisp/dired.el
index bf81649..618feb2 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 all-marks)
+                     distinguish-one-marked marker-char 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
@@ -581,8 +581,11 @@ dired-map-over-marks
 If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one
 marked file, return (t FILENAME) instead of (FILENAME).
 
+If MARKER-CHAR is non-nil, then it is the mark
+character to search.  Otherwise use `dired-marker-char'.
+
 If ALL-MARKS is non-nil, accept all mark characters.  Otherwise use
-just `dired-marker-char'."
+just MARKER-CHAR."
   ;;
   ;;Warning: BODY must not add new lines before point - this may cause an
   ;;endless loop.
@@ -602,7 +605,8 @@ dired-map-over-marks
              results))
            ;; non-nil, non-integer ARG means use current file:
            (list ,body))
-       (let ((regexp (dired-marker-regexp ,all-marks)) next-position)
+       (let ((regexp (dired-marker-regexp ,marker-char ,all-marks))
+             next-position)
          (save-excursion
            (goto-char (point-min))
            ;; remember position of next marked file before BODY
@@ -633,7 +637,7 @@ dired-map-over-marks
 (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.
+  "Return the marked files names as a list of strings.
 The list is in the same order as the buffer, that is, the car is the
   first marked file.
 Values returned are normally absolute file names.
@@ -656,13 +660,12 @@ dired-get-marked-files
 
 Optional arg ALL-MARKS, if non-nil, then accept all mark characters.
 Otherwise use just MARKER-CHAR."
-  (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)
+  (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 marker-char all-marks))))
+        result)
     (when (equal all-of-them '(t))
       (setq all-of-them nil))
     (if (not filter)
@@ -3043,13 +3046,16 @@ dired-clean-up-after-deletion
 \f
 ;; Confirmation
 
-(defun dired-marker-regexp (&optional all-marks)
+(defun dired-marker-regexp (&optional marker-char all-marks)
   "Return a regexp matching `dired-marker-char' at the beginning of line.
-If optional argument ALL-MARKS evaluates to non-nil, the regexp
+If MARKER-CHAR evaluates non-nil, then the regexp matches MARKER-CHAR
+instead of `dired-marker-char'.
+If optional argument ALL-MARKS evaluates to non-nil, then the regexp
 matches any mark character."
   (if all-marks
       "^[^\t ]"
-    (concat "^" (regexp-quote (char-to-string dired-marker-char)))))
+    (concat "^" (regexp-quote (char-to-string (or marker-char
+                                                  dired-marker-char))))))
 
 (defun dired-plural-s (count)
   (if (= 1 count) "" "s"))
-- 
2.7.0


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

* bug#22893: 25.1.50; dired-get-marked-files get all marked
  2016-03-09 23:57         ` Juri Linkov
  2016-03-10  4:19           ` Tino Calancha
@ 2016-03-10  4:43           ` Tino Calancha
  2016-03-11  0:48             ` Juri Linkov
  1 sibling, 1 reply; 13+ messages in thread
From: Tino Calancha @ 2016-03-10  4:43 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Tino Calancha, 22893, larsi


What about `dired-map-over-marks-check' in dired-aux.el?
Should we make resemble `dired-map-over-marks' in its
optional arguments?





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

* bug#22893: 25.1.50; dired-get-marked-files get all marked
  2016-03-10  4:43           ` Tino Calancha
@ 2016-03-11  0:48             ` Juri Linkov
  0 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2016-03-11  0:48 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 22893, larsi

> What about `dired-map-over-marks-check' in dired-aux.el?
> Should we make resemble `dired-map-over-marks' in its
> optional arguments?

Does it make sense to add ALL-MARKS to commands that use
`dired-map-over-marks-check', e.g. to compress or byte-compile
files flagged for deletion?

This also raises the question how do you want to use ALL-MARKS
in bug#22829 to display the number of marked files?  Shouldn't we
display the numbers separately for files flagged for deletion
(helps to see how much space will free up after deletion),
and marked with the default mark (to see whether the total sizes
of marked files will fit to copy to another file partition)?
Or there is not enough screen space in the echo area to display
statistics separately for every used marker-char?





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

* bug#22893: dired-marker-regexp use dired-re-mark
  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-22  9:31 ` Tino Calancha
  1 sibling, 0 replies; 13+ messages in thread
From: Tino Calancha @ 2016-03-22  9:31 UTC (permalink / raw)
  To: 22893

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


I just realized dired define the variable
'dired-re-mark' to match any mark.
Using it in `dired-marker-regexp'.

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

From cf1bb8e9bcc57aa68315413e36b8cbfbbb9ac617 Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac@gmail.com>
Date: Tue, 22 Mar 2016 18:18:54 +0900
Subject: [PATCH 3/3] 'dired-marker-regexp' use 'dired-re-mark'

* lisp/dired.el (dired-marker-regexp):
Return 'dired-re-mark' if ALL-MARKS non-nil (Bug#22893).
---
 lisp/dired.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index 618feb2..c8a712d 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3053,7 +3053,7 @@ dired-marker-regexp
 If optional argument ALL-MARKS evaluates to non-nil, then the regexp
 matches any mark character."
   (if all-marks
-      "^[^\t ]"
+      dired-re-mark
     (concat "^" (regexp-quote (char-to-string (or marker-char
                                                   dired-marker-char))))))
 
-- 
2.7.0


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

* bug#22892: bug#22893: 25.1.50; dired-get-marked-files get all marked
  2016-03-10  4:19           ` Tino Calancha
@ 2019-06-25 14:07             ` Lars Ingebrigtsen
  2020-08-12 11:58               ` Lars Ingebrigtsen
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-25 14:07 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 22892, 22893, Juri Linkov

Tino Calancha <f92capac@gmail.com> writes:

>> Since you are changing the function signatures anyway,
>> you could make them consistent between `dired-map-over-marks'
>> and `dired-get-marked-files' by adding an explicit arg `marker-char',
>> i.e. both `dired-get-marked-files' and `dired-map-over-marks'
>> could end with "distinguish-one-marked marker-char all-marks",
>> thus explicitly passing `marker-char' arg down the call chain.
>> Then you'll need `(or marker-char dired-marker-char)' in
>> `dired-marker-regexp' for backward-compatibility.  And then also
>> no need to let-bind `dired-marker-char' in `dired-get-marked-files'
>> (it's better to avoid dynamically binding global variables where possible).
>
> It sounds good. Thank you. Implemented in the new patch.

I think the consensus was to apply the patch, but it was never done at
the time, and now it won't apply since this code has changed
substantially in the meantime.

Would it be possible for you to rework the patch and resubmit?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#22892: bug#22893: 25.1.50; dired-get-marked-files get all marked
  2019-06-25 14:07             ` bug#22892: " Lars Ingebrigtsen
@ 2020-08-12 11:58               ` Lars Ingebrigtsen
  0 siblings, 0 replies; 13+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-12 11:58 UTC (permalink / raw)
  To: Tino Calancha; +Cc: 22892, 22893, Juri Linkov

Lars Ingebrigtsen <larsi@gnus.org> writes:

> I think the consensus was to apply the patch, but it was never done at
> the time, and now it won't apply since this code has changed
> substantially in the meantime.
>
> Would it be possible for you to rework the patch and resubmit?

I tried fixing up this myself, but the interface for all the marker
functions touched by this patch has changed too much for the patch to
even make sense, as far as I can see.

So I'm closing this bug report; a new one can be opened if this is
something somebody still wants to have in Dired.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[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).