emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 3ffe839458 2/2: Add proof-of-concept denote-reve


From: ELPA Syncer
Subject: [elpa] externals/denote 3ffe839458 2/2: Add proof-of-concept denote-reverse-rename-file
Date: Fri, 5 Aug 2022 01:57:28 -0400 (EDT)

branch: externals/denote
commit 3ffe83945848bf10c3dd96306ff880c7cdf4d79f
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Add proof-of-concept denote-reverse-rename-file
    
    This is part of the work being done to add a "reverse rename" operation
    which will rename a file based on its front matter.
    
    Issue on the GitHub mirror: 
<https://github.com/protesilaos/denote/issues/74>.
    
    Mailing list threads (I wish they were not split like that, but here we
    are):
    
    - 
<https://lists.sr.ht/~protesilaos/denote/%3C87k081l6vw.fsf%40silverstone.mail-host-address-is-not-set%3E>
    - 
<https://lists.sr.ht/~protesilaos/denote/%3C878rogw5kk.fsf%40protesilaos.com%3E>
    - 
<https://lists.sr.ht/~protesilaos/denote/%3C87fsiljv1s.fsf%40hu.mail-host-address-is-not-set%3E>
    - 
<https://lists.sr.ht/~protesilaos/denote/%3C87r122afe3.fsf%40hu.mail-host-address-is-not-set%3E>
---
 denote.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/denote.el b/denote.el
index d597e4f050..ed7e24502a 100644
--- a/denote.el
+++ b/denote.el
@@ -1375,6 +1375,25 @@ The operation does the following:
   'denote-dired-rename-marked-files
   "0.5.0")
 
+;;;###autoload
+(defun denote-reverse-rename-file (file)
+  "Rename current FILE using its front matter as input.
+This basically is the inverse of `denote-rename-file'"
+  (interactive (list (buffer-file-name)))
+  (when (buffer-modified-p)
+    (user-error "Save buffer before proceeding"))
+  (if-let* ((title (denote--retrieve-value-title file))
+            (keywords (denote--front-matter-keywords-to-list 
(denote--retrieve-value-keywords file)))
+            (extension (file-name-extension file t))
+            (id (denote--file-name-id file))
+            (dir (file-name-directory file))
+            (new-name (denote--format-file
+                       dir id keywords (denote--sluggify title) extension)))
+      (progn
+        (denote--rename-file file new-name)
+        (denote-update-dired-buffers))
+    (user-error "No front matter for title, identifier, and/or keywords")))
+
 ;;;; The Denote faces
 
 (defgroup denote-faces ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]