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

Just an idea: denote for attachments #1

Closed
Ypot opened this issue Jun 7, 2022 · 9 comments
Closed

Just an idea: denote for attachments #1

Ypot opened this issue Jun 7, 2022 · 9 comments

Comments

@Ypot
Copy link

Ypot commented Jun 7, 2022

If you think this is something you might use, but disagree with some of its decisions, now is the best time to act.

Just in case this idea could be useful:
I use attached or linked local files for adding multimedia (jpg, pdf, etc) or references (saved html, podcasts, etc) to my org notes.
These multimedia files are in a folder almost kaotically.
To sort those files in the way you've described could give to them a new dimension.

Thanks for elisping!

@protesilaos
Copy link
Owner

Thanks @Ypot!

Just in case this idea could be useful:

Yes, it is useful.

I use attached or linked local files for adding multimedia (jpg, pdf,
etc) or references (saved html, podcasts, etc) to my org notes. These
multimedia files are in a folder almost kaotically. To sort those
files in the way you've described could give to them a new dimension.

I already do this locally for my multimedia, but I don't have any Elisp
for it.

I am now trying to think how it could be done. We could have a command,
say, denote-dired-rename which only changes the name of the file at
point. It will prompt for TITLE and KEYWORDS, just like denote and
denote-org-capture, but it will also ask for a file type extension:
jpd, pdf, and others can be available as completion candidates.

Unlike the other commands, denote-dired-rename will not create a
"note" per se.

What do you think?

[ Maybe a better name is denote-dired-rename-non-note or something to
make it clear we are not operating on notes. ]

Though we need to be careful not to go very far with this idea, as it is
not directly connected to the note-taking goal.

Thanks for elisping!

You are welcome!

@Ypot
Copy link
Author

Ypot commented Jun 7, 2022

Not sure! I just thought attachments could be benefited with an analogous naming and listing. But it's more like a brainstormed idea that could fit in your project, if it suits you.

For completion candidates I would find more useful keywords than extensions (why bother with existing extensions?).

Best regards :-)

@protesilaos
Copy link
Owner

protesilaos commented Jun 8, 2022

Hello again! Here is a prototype (I made some other changes):

(defun denote-dired-rename-file (title keywords)
  "Return path to new file with TITLE and KEYWORDS."
  (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))))

It uses the standard prompts for TITLE and KEYWORDS and converts
them to a familiar Denote path. The file type extension is read from
the underlying file. So if you are renaming a .pdf it stays a .pdf, if
it is an .mp3 it remains that way, and so on.

The renaming only happens relative to the current directory. It does
not move the file between directories. I think this is consistent with
the task, which basically is "Give me a Denote-style file name".

EDIT: I removed the sample diff, as I already pushed the changes.

protesilaos added a commit that referenced this issue Jun 8, 2022
There is no need to limit it to the denote-directory.  We ultimately
want to fontify all Denote-style file names, not just the notes created
by Denote.

For example, I have been recording all my longer-term storage using such
a naming scheme: this mode gives me the extra faces for .pdf, .mp3, and
other files.

Users of Denote may want this for attachments.

The upside of having this as a buffer-local mode is that the user can
write a wrapper function that applies the mode only in a given
directory (like we were doing before).

Thanks to Ypot for suggesting a kernel of this idea in issue 1 over at
the GitHub mirror: <#1>.
protesilaos added a commit that referenced this issue Jun 8, 2022
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: <#1>.
@protesilaos
Copy link
Owner

I made some changes early today to how renaming works. The current functionality is described here: https://protesilaos.com/emacs/denote#h:532e8e2a-9b7d-41c0-8f4b-3c5cbb7d4dca

@Ypot
Copy link
Author

Ypot commented Jun 13, 2022

I am receiving this message:
dired-move-to-filename: No file on this line

Maybe I should try without customizations.

@Ypot
Copy link
Author

Ypot commented Jun 13, 2022

Offtopic: I am trying to send you what seems to be a "typo". But I don't know how to, I share it here (last line):

;; Generic:
;; (add-hook 'dired-mode-hook #'denote-dired-mode)
;;
;; OR better:
(add-hook 'dired-mode-hook #'denote-dired-mode-in-directories)

;; You can bind `denote' to a global key if you prefer not to use
;; `org-capture' or want an alternative.  Denote does not define any key
;; bindings though: this is for the user to decide.  For example:
(let ((map global-map))
  (define-key map (kbd "C-c n") #'denote)
  (define-key map (kbd "C-c N") #'denote-type))

(with-eval-after-load 'org-capture
  (require 'denote-org-capture)
  (setq denote-org-capture-specifiers "%l\n%i\n%?")
  (add-to-list 'org-capture-templates
               '("n" "New note (with denote.el)" plain
                 (file denote-last-path)
                 #'denote-org-capture
                 :no-save t
                 :immediate-finish nil
                 :kill-buffer t
;; Should be here just 3 )))?                 :jump-to-captured t))))

protesilaos added a commit that referenced this issue Jun 13, 2022
@protesilaos
Copy link
Owner

Offtopic: I am trying to send you what seems to be a "typo".

Fixed. Thank you!

@protesilaos
Copy link
Owner

I am receiving this message: dired-move-to-filename: No file on this line

Maybe I should try without customizations.

Can you please report this in a new issue? It will be easier to track
things.

Also please note what you tried to produce this error. Maybe
denote-dired-rename-file?

@protesilaos
Copy link
Owner

I am closing this issue now as Denote supports the idea of renaming other files.

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

No branches or pull requests

2 participants