[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 0e75e46b32 138/355: Improve denote-dired-rename-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 0e75e46b32 138/355: Improve denote-dired-rename-file |
Date: |
Sun, 26 Jun 2022 23:58:14 -0400 (EDT) |
branch: externals/denote
commit 0e75e46b32ca8f31251f170317037ade6fd9a9f7
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Improve denote-dired-rename-file
It now preserves the identifier, if it exists. So if you want to change
the title/keywords in a note's front matter, this command can then be
called to also update the file name (maybe there is some way to automate
this, but let's leave it for now).
---
README.org | 22 +++++++++++++++++-----
denote-dired.el | 38 ++++++++++++++++++++++++++++++--------
denote.el | 9 +++++----
3 files changed, 52 insertions(+), 17 deletions(-)
diff --git a/README.org b/README.org
index 6007a5e22f..4765d39402 100644
--- a/README.org
+++ b/README.org
@@ -626,7 +626,7 @@ Have more ideas? Something does not work quite right?
Areas you wish
were more abstract in the code? Please participate in the development
process.
-* Renaming non-notes
+* Renaming files
:PROPERTIES:
:CUSTOM_ID: h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca
:END:
@@ -638,10 +638,22 @@ Denote does not manage such files, it already has all the
mechanisms to
facilitate the task of renaming them.
#+findex: denote-dired-rename-file
-To this end, invoke ~denote-dired-rename-file~ when point is over a file
-in Dired to rename it. The commaand prompts for a =TITLE= and
-=KEYWORDS= the same way the ~denote~ command does it
([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]).
-It finally asks for confirmation before renaming the file at point.
+To this end, we provide the ~denote-dired-rename-file~ command. It has
+a two-fold purpose: (i) to change the file name of an existing note
+while retaining its identifier and (ii) to write a Denote-style file
+name for an item that was not created by ~denote~ or related commands
+(such as an image or PDF).
+
+The ~denote-dired-rename-file~ command will target the file at point if
+it finds one in the current Dired buffer. Otherwise it prompts with
+minibuffer completion for a file name. It then uses the familiar
+prompts for a =TITLE= and =KEYWORDS= the same way the ~denote~ command
+does it ([[#h:17896c8c-d97a-4faa-abf6-31df99746ca6][Points of entry]]). As a
final step it asks for confirmation
+before renaming the file at point, showing a message like:
+
+#+begin_example
+Rename denote-link.el to 20220612T052900--what-the-thing__testing.el? (y or n)
+#+end_example
The file type extension (e.g. =.pdf=) is read from the underlying file
and is preserved in the renaming process. Files that have no extension
diff --git a/denote-dired.el b/denote-dired.el
index 6e36bfddd7..2598ecae9b 100644
--- a/denote-dired.el
+++ b/denote-dired.el
@@ -80,22 +80,43 @@
;;;; Commands
+(defun denote-dired--file-name-id (file)
+ "Return FILE identifier, else provide one."
+ (if (string-match denote--id-regexp file)
+ (substring file (match-beginning 0) (match-end 0))
+ (format-time-string denote--id)))
+
;;;###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."
+(defun denote-dired-rename-file (file title keywords)
+ "Rename FILE to include TITLE and KEYWORDS.
+If in Dired consider FILE the one at point, else prompt with
+completion.
+
+If FILE has a Denote-style identifier, retain it while updating
+the TITLE and KEYWORDS fields. Else create an identifier,
+replacing the whole name.
+
+The file type extension (e.g. .pdf) is read from the underlying
+file and is preserved in the renaming process. Files that have
+no extension are simply left without one.
+
+Renaming only occurs relative to the current directory. Files
+are not moved between directories.
+
+This command is intended to (i) rename existing Denote
+notes, (ii) complement note-taking, such as by renaming
+attachments that the user adds to their notes."
(interactive
(list
+ (or (dired-get-filename nil t) (read-file-name "Rename file Denote-style:
"))
(denote--title-prompt)
(denote--keywords-prompt)))
- (let* ((file (dired-get-filename))
- (dir (file-name-directory file))
+ (let* ((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)
+ (denote-dired--file-name-id file)
keywords
(denote--sluggify title)
extension)))
@@ -104,7 +125,8 @@ renaming attachments that the user adds to their notes."
(propertize old-name 'face 'error)
(propertize (file-name-nondirectory new-name) 'face
'success)))
(rename-file old-name new-name nil)
- (revert-buffer))))
+ (when (eq major-mode 'dired-mode)
+ (revert-buffer)))))
;;;; Extra fontification
diff --git a/denote.el b/denote.el
index a5d5822bd0..f1bb86434f 100644
--- a/denote.el
+++ b/denote.el
@@ -436,13 +436,14 @@ TITLE, DATE, KEYWORDS, FILENAME, ID are all strings which
are
('text (format denote-text-front-matter title date kw-space id
denote-text-front-matter-delimiter))
(_ (format denote-org-front-matter title date kw-space id)))))
-(defun denote--path (title keywords)
+(defun denote--path (title keywords &optional dir id)
"Return path to new file with TITLE and KEYWORDS.
-Format current time, else use optional ID."
+With optional DIR, use it instead of variable `denote-directory'.
+With optional ID, use it else format the current time."
(setq denote-last-path
(denote--format-file
- (file-name-as-directory denote-directory)
- (format-time-string denote--id)
+ (or dir (file-name-as-directory denote-directory))
+ (or id (format-time-string denote--id))
(denote--sluggify-keywords keywords)
(denote--sluggify title)
(denote--file-extension))))
- [elpa] externals/denote 7366004e91 106/355: Fix markdown-toml front matter format, (continued)
- [elpa] externals/denote 7366004e91 106/355: Fix markdown-toml front matter format, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 5fd4e97dad 105/355: Add support for markdown-toml, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 1a8b57a9a8 104/355: Fix const in denote-file-type (extends 2bc5df6), ELPA Syncer, 2022/06/26
- [elpa] externals/denote c225201c49 124/355: Use appropriate name for internal variable, ELPA Syncer, 2022/06/26
- [elpa] externals/denote a70b4cd32d 114/355: Refine backlinks' heading per file type, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 7cba33e08e 119/355: LAST BREAKING CHANGE to file-naming scheme, ELPA Syncer, 2022/06/26
- [elpa] externals/denote c5a5748594 116/355: Abstract plain text front matter delimiter, ELPA Syncer, 2022/06/26
- [elpa] externals/denote e394057985 134/355: Document how to store multiple types of notes, ELPA Syncer, 2022/06/26
- [elpa] externals/denote d90695213c 151/355: Add minor clarifications in the manual, ELPA Syncer, 2022/06/26
- [elpa] externals/denote ce41b421ef 147/355: Update denote-retrieve symbols in denote-link, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 0e75e46b32 138/355: Improve denote-dired-rename-file,
ELPA Syncer <=
- [elpa] externals/denote cdb7f554f2 160/355: Remove extra parenthesis from sample configuration, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 88e64be2cb 176/355: Fix plain text link format, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 7fab21926d 183/355: Process 'find' output in denote-retrieve, ELPA Syncer, 2022/06/26
- [elpa] externals/denote ecc7922a77 169/355: BREAKING remove support for hardcoded backlinks, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 49a2932d42 189/355: Implement denote-link-add-links, ELPA Syncer, 2022/06/26
- [elpa] externals/denote a7a0bf0255 207/355: Tweak doc string, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 2338ee4698 181/355: Refine how identifier is retrieved from file names, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 1a124c2be6 204/355: Make 'denote:' link follow links like 'file:', ELPA Syncer, 2022/06/26
- [elpa] externals/denote a76b7fb0b8 193/355: Make plain text links the same as Org's, ELPA Syncer, 2022/06/26
- [elpa] externals/denote 683180bcfc 206/355: Remove superfluous function and var, ELPA Syncer, 2022/06/26