From 54428444410aaacc8d1e86678dcb9a8e95fccd4b Mon Sep 17 00:00:00 2001 From: Tino Calancha 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 ;; 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