denote icon indicating copy to clipboard operation
denote copied to clipboard

use consult for `denote-link-insert-*`

Open JonatanSahar opened this issue 1 year ago • 6 comments

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 :)

JonatanSahar avatar Mar 23 '23 13:03 JonatanSahar

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.

protesilaos avatar Mar 25 '23 16:03 protesilaos

@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.

relict007 avatar Mar 26 '23 13:03 relict007

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: @.***>

JonatanSahar avatar Mar 26 '23 13:03 JonatanSahar

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.

relict007 avatar Mar 27 '23 01:03 relict007

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 avatar Mar 27 '23 05:03 JonatanSahar

@JonatanSahar Thanks for updating the code. I actually never tried creating a new note that way. My work-flow is mostly through org-capture.

relict007 avatar Mar 27 '23 06:03 relict007

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!

protesilaos avatar Mar 04 '24 05:03 protesilaos