branch: externals/denote commit eee100cc508b6e6ff05150c329ff7a82406d0e8c Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Add denote-dired-rename-file This is not limited to notes that were created with Denote: it works on any file in any directory. The idea is to apply the Denote-style file name in more contexts, such as for longer-term storage and attachments to notes. Also see commit 431124f, which is thematically aligned with this one. Thanks to Ypot for giving me the idea in issue 1 over at the GitHub mirror: <https://github.com/protesilaos/denote/issues/1>. --- denote-dired.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/denote-dired.el b/denote-dired.el index 8628f5a1d2..efc78008cd 100644 --- a/denote-dired.el +++ b/denote-dired.el @@ -34,11 +34,42 @@ ;;; Code: (require 'denote) +(require 'dired) (defgroup denote-dired () "Integration between Denote and Dired." :group 'denote) +;;;; Commands + +;;;###autoload +(defun denote-dired-rename-file (title keywords) + "Rename file at point to new file with TITLE and KEYWORDS. +This command is intended to complement note-taking, such as by +renaming attachments that the user adds to their notes." + (interactive + (list + (denote--title-prompt) + (denote--keywords-prompt))) + (let* ((file (dired-get-filename)) + (dir (file-name-directory file)) + (old-name (file-name-nondirectory file)) + (extension (file-name-extension file t)) + (new-name (denote--format-file + dir + (format-time-string denote--id) + keywords + (denote--sluggify title) + extension))) + (when (y-or-n-p + (format "Rename %s to %s?" + (propertize old-name 'face 'error) + (propertize (file-name-nondirectory new-name) 'face 'success))) + (rename-file old-name new-name nil) + (revert-buffer)))) + +;;;; Extra fontification + (defvar dired-font-lock-keywords) (defvar denote-dired-original-keywords dired-font-lock-keywords