denote
denote copied to clipboard
use consult for `denote-link-insert-*`
Hi,
I'm really loving denote so far, and super impressed with all the work you've put into all of your packages, so thanks!
I was wondering if there's a way to use consult, possibly leveraging consult-notes
for getting a nicer interface to inserting links - I don't ever have a reason to see the actual filenames of notes, as they are quite clunky and hard to read at a glance.
I looked around the code a bit, and it looks lioke there's a denotes-specific function that populates the list.. as I'm not so proficient with elisp, I can't go much further than this :)
Hello @JonatanSahar!
In principle, consult-notes
or anything consult
related can be used for this task. I still want to experiment with consult-notes
but have not found the chance to do so. If an existing user reads this, maybe they have an idea on how to go about providing this facility.
@JonatanSahar I have something simple and very hackish that may work for you. I am not very good at elisp.
(defun rlct/denote--pretty-format-filename (file)
(let* (
(title (denote-retrieve-filename-title file))
(keywords (denote-extract-keywords-from-path file))
(keywords-as-string (mapconcat 'identity keywords ", "))
)
(concat title " " "(" keywords-as-string ")" )
)
)
(defun rlct/denote--find-file-with-pretty-format (&optional initial-text)
(interactive)
(let* (
(paths (mapcar #'(lambda (file)
(cons (rlct/denote--pretty-format-filename file) file))
(denote-directory-files)))
(filename (cdr (assoc (completing-read "Select a file: " paths nil t) paths)))
)
filename
)
)
(defun rlct/denote-link()
(interactive)
(let ((denote-file-prompt 'rlct/denote--find-file-with-pretty-format))
(advice-add 'denote-file-prompt :around denote-file-prompt)
)
(call-interactively 'denote-link)
(advice-remove 'denote-file-prompt 'rlct/denote--find-file-with-pretty-format)
)
Instead of calling denote-link
, you can call rlct/denote-link
which shows better formatted titles and keywords. You can customize rlct/denote--pretty-format-filename
function to make it whatever way you like (add colors, faces etc). I use Vertico
, Consult
and so on family of packages and completing-read works well for me.
consult-notes
uses denote-retrieve-title-value
also to get "true" titles from the file, however, in my setup with 600+ notes I found it to be slow (understandably). Hence, I am just using denote-retrieve-filename-title
which just converts the filename into something better looking and doesn't read the actual titles from the files. You can use denote-retrieve-title-value
if you really want to.
That look great, thanks! I'll have a go with it.
On Sun, Mar 26, 2023, 16:18 relict007 @.***> wrote:
@JonatanSahar https://github.com/JonatanSahar I have something simple and very hackish that may work for you. I am not very good at elisp.
(defun rlct/denote--pretty-format-filename (file) (let* ( (title (denote-retrieve-filename-title file)) (keywords (denote-extract-keywords-from-path file)) (keywords-as-string (mapconcat 'identity keywords ", ")) ) (concat title " " "(" keywords-as-string ")" ) ) )
(defun rlct/denote--find-file-with-pretty-format (&optional initial-text) (interactive) (let* ( (paths (mapcar #'(lambda (file) (cons (rlct/denote--pretty-format-filename file) file)) (denote-directory-files))) (filename (cdr (assoc (completing-read "Select a file: " paths nil t) paths))) ) filename ) )
(defun rlct/denote-link() (interactive) (let ((denote-file-prompt 'rlct/denote--find-file-with-pretty-format)) (advice-add 'denote-file-prompt :around denote-file-prompt) ) (call-interactively 'denote-link) (advice-remove 'denote-file-prompt 'rlct/denote--find-file-with-pretty-format) )
Instead of calling denote-link, you can call rlct/denote-link which shows better formatted titles and keywords. You can customize rlct/denote--pretty-format-filename function to make it whatever way you like (add colors, faces etc). I use Vertico, Consult and so on family of packages and completing-read works well for me.
consult-notes uses denote-retrieve-title-value also to get "true" titles from the file, however, in my setup with 600+ notes I found it to be slow (understandably). Hence, I am just using denote-retrieve-filename-title which just converts the filename into something better looking and doesn't read the actual titles from the files. You can use denote-retrieve-title-value if you really want to.
— Reply to this email directly, view it on GitHub https://github.com/protesilaos/denote/issues/143#issuecomment-1484094478, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEL3S3DS5UP46CRWR4YQSKDW6A63BANCNFSM6AAAAAAWFFU7YQ . You are receiving this because you were mentioned.Message ID: @.***>
Just an update on my previous comment.
however, in my setup with 600+ notes I found it to be slow (understandably).
I just tested with the latest consult-notes
and its not slow anymore. I will check its source again and see if something has changed.
Hi!
There's some bug with the code which prevents the creation of a new note when entering a new name - I get [match required] instead of [confirm] when I use your code to wrap around denote-link-or-create
like so:
(defun my/denote-link-or-create()
(interactive)
(let ((denote-file-prompt 'my/denote--find-file-with-pretty-format))
(advice-add 'denote-file-prompt :around denote-file-prompt)
)
(call-interactively 'denote-link-or-create)
(advice-remove 'denote-file-prompt 'my/denote--find-file-with-pretty-format)
)
Which also persists when I call denote-link-or-create
directly - even though the advice is removed...
@JonatanSahar Thanks for updating the code. I actually never tried creating a new note that way. My work-flow is mostly through org-capture
.
Hello again folks! I am closing this issue as it cannot be acted upon here. If/when my arm gets better and I can type longer I will consider working on this as a separate package. Thank you!