Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to rename directories using the denote format? #520

Open
maikol-solis opened this issue Jan 6, 2025 · 4 comments
Open

Is it possible to rename directories using the denote format? #520

maikol-solis opened this issue Jan 6, 2025 · 4 comments

Comments

@maikol-solis
Copy link
Contributor

Basically, this is the question. Suppose you have directories

A
B
C

And you want to rename them into something like

20250106T000001--a
20250106T000002--b
20250106T000003--c

It tried with denote-rename-file in dired, but it didn't work.

What do you think about this feature?

Best.

@protesilaos
Copy link
Owner

protesilaos commented Jan 7, 2025 via email

@maikol-solis
Copy link
Contributor Author

Hi Prot.

Yes, maybe my use case could be not so common, but I use a PARA system to organize my files. In particular, I want to organize my projects by date of creation. I write manually my folder with this structure (inspired by the denote nomenclature)

2025-01-06--another-project 
2024-12-20--one-project 
and so on 

My idea was to create a silo in my projects folder and see if I could use denote to rename those folders easily.

This way all my projects could be archived in order when they are finished.

I don't know whether the idea has potential or not, perhaps other users could give their insights.

Best.

@protesilaos
Copy link
Owner

I see, thank you for the explanation!

I am not sure we should go down this path. But maybe we can post the code here and interested parties will share their thoughts. Maybe there is no good reason for us to only accept regular files.

First you need this diff on top of the current commit (23098ea).

 denote.el | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/denote.el b/denote.el
index 678d805..d035a1e 100644
--- a/denote.el
+++ b/denote.el
@@ -3097,7 +3097,8 @@ (defun denote-rename-file-and-buffer (old-name new-name)
   (unless (string= (expand-file-name old-name) (expand-file-name new-name))
     (if (denote--file-type-org-extra-p)
         (setq denote-last-path-after-rename new-name)
-      (when (and (file-regular-p old-name)
+      (when (and (or (file-regular-p old-name)
+                     (file-directory-p old-name))
                  (file-writable-p new-name))
         (cond
          ((derived-mode-p 'dired-mode)
@@ -3403,10 +3404,7 @@ (defun denote--rename-dired-file-or-current-file-or-prompt ()
                          (format "Rename FILE Denote-style [%s]: " file)
                        "Rename FILE Denote-style: "))
              (selected-file (read-file-name format nil file t nil)))
-        (if (or (file-directory-p selected-file)
-                (not (file-regular-p selected-file)))
-            (user-error "Only rename regular files")
-          selected-file))))
+        selected-file)))
 
 (defun denote-rename-file-prompt (old-name new-name)
   "Prompt to rename file named OLD-NAME to NEW-NAME.
@@ -3478,7 +3476,8 @@ (defun denote--rename-file (file title keywords signature date)
          (date (if (string-empty-p id) nil (date-to-time id)))
          (new-name (denote-format-file-name directory id keywords title extension signature))
          (max-mini-window-height denote-rename-max-mini-window-height))
-    (when (and (file-regular-p new-name)
+    (when (and (or (file-regular-p new-name)
+                   (file-directory-p new-name))
                (not (string= (expand-file-name file) (expand-file-name new-name))))
       (user-error "The destination file `%s' already exists" new-name))
     ;; Modify file name, buffer name, or both

Then you can write a small wrapper function like this one to do what you want:

(defun my-denote-rename-folder ()
  (interactive)
  (let ((denote-prompts '(date title)))
    (call-interactively 'denote-rename-file)))

@reyman
Copy link

reyman commented Feb 4, 2025

Hi Prot.

Yes, maybe my use case could be not so common, but I use a PARA system to organize my files. In particular, I want to organize my projects by date of creation. I write manually my folder with this structure (inspired by the denote nomenclature)

2025-01-06--another-project 
2024-12-20--one-project 
and so on 

My idea was to create a silo in my projects folder and see if I could use denote to rename those folders easily.

Interesting idea !

They are multiple emacs people that use PARA or JohnyDecimal with Org. And even crazyiest guy (like me?) try to mix both systems (PARA + Johny.Decimal).

In both methods, folder and subfolder naming or tagging are really important.

For my use case i decide to follow Denote template + Johny.Decimal like using JohnyDecimalD++Date--name__tags signature for folders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants