Function: image-dired-mark-tagged-files

image-dired-mark-tagged-files is an autoloaded, interactive and byte-compiled function defined in image-dired-dired.el.gz.

Signature

(image-dired-mark-tagged-files REGEXP)

Documentation

Mark files whose tag matches REGEXP.

A tag is a keyword, a piece of meta data, associated with an image file and stored in image-dired's database file. This command prompts for a regexp, and then matches it against all the tags of all the image files in the database file. The files that have a matching tag will be marked in the Dired buffer.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/image/image-dired-dired.el.gz
;;;###autoload
(defun image-dired-mark-tagged-files (regexp)
  "Mark files whose tag matches REGEXP.
A `tag' is a keyword, a piece of meta data, associated with an
image file and stored in image-dired's database file.  This command
prompts for a regexp, and then matches it against all the tags
of all the image files in the database file.  The files that have a
matching tag will be marked in the Dired buffer."
  (interactive "sMark tagged files (regexp): " dired-mode)
  (image-dired-sane-db-file)
  (let ((hits 0)
        files)
    (image-dired--with-db-file
      ;; Collect matches
      (while (search-forward-regexp "\\(^[^;\n]+\\);\\(.*\\)" nil t)
        (let ((file (match-string 1))
              (tags (split-string (match-string 2) ";")))
          (when (seq-find (lambda (tag)
                            (string-match-p regexp tag))
                          tags)
            (push file files)))))
    ;; Mark files
    (dolist (curr-file files)
      ;; I tried using `dired-mark-files-regexp' but it was waaaay to
      ;; slow.  Don't bother about hits found in other directories
      ;; than the current one.
      (when (string= (file-name-as-directory
                      (expand-file-name default-directory))
                     (file-name-as-directory
                      (file-name-directory curr-file)))
        (setq curr-file (file-name-nondirectory curr-file))
        (goto-char (point-min))
        (when (search-forward-regexp (format "\\s %s[*@]?$" (regexp-quote curr-file)) nil t)
          (setq hits (+ hits 1))
          (dired-mark 1))))
    (message "%d files with matching tag marked" hits)))