Automatically rename the note after saving it
While experimenting with Denote, users may need to try different workflows to figure out what works for them. Those might involve changing keywords and specifying titles in a particular way. The following sample can be used:
emacs-lisp
(defun my-denote-always-rename-on-save-based-on-front-matter ()
"Rename the current Denote file, if needed, upon saving the file.
Rename the file based on its front matter, checking for changes in the
title or keywords fields.
Add this function to the `after-save-hook'."
(let ((denote-rename-confirmations nil)
(denote-save-buffers t)) ; to save again post-rename
(when (and buffer-file-name (denote-file-is-note-p buffer-file-name))
(ignore-errors (denote-rename-file-using-front-matter buffer-file-name))
(message "Buffer saved; Denote file renamed"))))
(add-hook 'after-save-hook #'my-denote-always-rename-on-save-based-on-front-matter)