Function: dired-mark-if
dired-mark-if is a macro defined in dired.el.gz.
Signature
(dired-mark-if PREDICATE MSG)
Documentation
Mark files for PREDICATE, according to dired-marker-char.
PREDICATE is evaluated on each line, with point at beginning of line.
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.
In Transient Mark mode, if the mark is active, operate on the contents
of the region if dired-mark-region is non-nil. Otherwise, operate
on the whole buffer.
Return value is the number of files marked, or nil if none were marked.
Source Code
;; Defined in /usr/src/emacs/lisp/dired.el.gz
;;; Macros
;; Macros must be defined before they are used, for the byte compiler.
(defmacro dired-mark-if (predicate msg)
"Mark files for PREDICATE, according to `dired-marker-char'.
PREDICATE is evaluated on each line, with point at beginning of line.
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'.
In Transient Mark mode, if the mark is active, operate on the contents
of the region if `dired-mark-region' is non-nil. Otherwise, operate
on the whole buffer.
Return value is the number of files marked, or nil if none were marked."
`(let ((msg ,msg)
(inhibit-read-only t) count
(use-region-p (dired-mark--region-use-p))
(beg (dired-mark--region-beginning))
(end (dired-mark--region-end)))
(save-excursion
(setq count 0)
(when msg
(message "%s %ss%s%s..."
(cond ((eq dired-marker-char ?\s) "Unmarking")
((eq dired-del-marker dired-marker-char)
"Flagging")
(t "Marking"))
msg
(if (eq dired-del-marker dired-marker-char)
" for deletion"
"")
(if use-region-p
" in region"
"")))
(goto-char beg)
(while (< (point) end)
(when ,predicate
(unless (= (following-char) dired-marker-char)
(delete-char 1)
(insert dired-marker-char)
(setq count (1+ count))))
(forward-line 1))
(when msg (message "%s %s%s %s%s%s"
count
msg
(dired-plural-s count)
(if (eq dired-marker-char ?\s) "un" "")
(if (eq dired-marker-char dired-del-marker)
"flagged" "marked")
(if use-region-p
" in region"
""))))
(and (> count 0) count)))