How can I rename my denote file on save? #430
Answered
by
protesilaos
LukasCBossert
asked this question in
Q&A
Replies: 3 comments 6 replies
-
From: "Lukas C. Bossert" ***@***.***>
Date: Sun, 8 Sep 2024 12:14:51 -0700
[... 3 lines elided]
I was wondering if I could automate this step in that way that
everytime I am working on a denote file (how can I detect that?) that
it is renamed on save.
[... 21 lines elided]
If I understand this correctly, this should work:
(defun my-denote-always-rename-on-save ()
"Rename the current Denote file upon saving the file.
Add this to `after-save-hook'."
(let ((denote-rename-confirmations nil)
(denote-save-buffers t)) ; to save again post-rename
(when (denote-file-is-note-p buffer-file-name)
(ignore-errors (denote-rename-file-using-front-matter buffer-file-name))
(message "Buffer saved and denote-file renamed!"))))
(add-hook 'after-save-hook #'my-denote-always-rename-on-save)
…--
Protesilaos Stavrou
https://protesilaos.com
|
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
LukasCBossert
-
From: "Lukas C. Bossert" ***@***.***>
Date: Sun, 8 Sep 2024 23:37:28 -0700
that does the trick!
Great! I will write about this in the manual.
…--
Protesilaos Stavrou
https://protesilaos.com
|
Beta Was this translation helpful? Give feedback.
1 reply
-
From: "Lukas C. Bossert" ***@***.***>
Date: Fri, 20 Sep 2024 02:38:04 -0700
This is perfect. I notice it even fixes some side effects I noticed earlier but couldnt properly define them.
Very well!
…--
Protesilaos Stavrou
https://protesilaos.com
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am currently setting up my files using denote and I am playing around a lot with tags (to find the suitable amount and proper tags). Every time I have changed tags I am running
denote-rename-file-using-font-matter
.I was wondering if I could automate this step in that way that everytime I am working on a denote file (how can I detect that?) that it is renamed on save.
My approach fails:
I am even not sure if
denote-rename-file-using-front-matter
is the proper function for it.The code works fine, but when I am not in a denote buffer I get the warning
denote-rename-file-using-front-matter: No identifier or front matter
.Is there a way to make sure the function is only executed when I am in a denote buffer?
Beta Was this translation helpful? Give feedback.
All reactions