Renaming Files Using Denote Schema in a Dired Buffer
Summary: A quick walk through of a dired function to loop through marked files and prompt for how to rename them.
I wrote Creating an Emacs Command to Rename Files per Denote File Naming Schema. I’ve been using it in a one-off situation.
And I wrote a wrapping function to call in dired.
(defun jf/dired-rename-files-to-denote-schema ()
"Rename marked files in `dired-mode'."
(interactive)
(when (seq-find (lambda (file)
(member (file-name-nondirectory file) '("." "..")))
(dired-get-marked-files))
(user-error "Can't rename \".\" or \"..\" files"))
(dolist (file (dired-get-marked-files))
(let ((current-prefix-arg nil))
(apply #'jf/rename-file-to-denote-schema
(list :file file :signature :prompt)))))
The above did require a bit of a refinement to the initial implementation. The refined jf/rename-file-to-denote-schema is available here.
What all of this means is that I can go to a directory, mark the files I want to rename (typing m on the row), then invoking M-x jf/dired-rename-files-to-denote-schema.
This also demonstrates the utility and flexibility of separating the looping logic from the logic for performing an action.