d12frosted / vulpea

A collection of functions for note taking based on `org` and `org-roam`.
GNU General Public License v3.0
236 stars 12 forks source link

Choice of description for vulpea-insert #167

Closed Cletip closed 1 year ago

Cletip commented 1 year ago

it's not really a way out. I still have a little trouble with the pull request, so I'm doing it here.

I've modified "vulpea-insert" to have the choice to select the description (see in "description" variable in the first let). Is this a good idea?

(defun vulpea-insert (&optional filter-fn)
  "Select a note and insert a link to it.

Allows capturing new notes. After link is inserted,
`vulpea-insert-handle-functions' are called with the inserted
note as the only argument regardless involvement of capture
process.

FILTER-FN is the function to apply on the candidates, which takes
as its argument a `vulpea-note'. Unless specified,
`vulpea-insert-default-filter' is used."
  (interactive)
  (unwind-protect
      (atomic-change-group
        (let* (region-text
               beg end
               (_ (when (region-active-p)
                    (setq
                     beg (set-marker
                          (make-marker) (region-beginning))
                     end (set-marker
                          (make-marker) (region-end))
                     region-text
                     (org-link-display-format
                      (buffer-substring-no-properties
                       beg end)))))
               (note (vulpea-select
                      "Note"
                      :filter-fn
                      (or filter-fn
                          vulpea-insert-default-filter)
                      :initial-prompt region-text))
               (description (or region-text
                                (if-let ((aliases (vulpea-note-aliases note))
                     (title (vulpea-note-title
                         (vulpea-db-get-by-id
                          (vulpea-note-id note))))
                     (all-aliases (push title aliases)))
                    (completing-read "Insert: " all-aliases)
                  (vulpea-note-title note)))))
          (if (vulpea-note-id note)
              (progn
                (when region-text
                  (delete-region beg end)
                  (set-marker beg nil)
                  (set-marker end nil))
                (insert (org-link-make-string
                         (concat "id:" (vulpea-note-id note))
                         description))
                (run-hook-with-args
                 'vulpea-insert-handle-functions
                 note))
            (org-roam-capture-
             :node (org-roam-node-create
                    :title (vulpea-note-title note))
             :props
             (append
              (when (and beg end)
                (list :region (cons beg end)))
              (list
               :insert-at (point-marker)
               :link-description description
               :finalize #'vulpea-insert--capture-finalize))))))
    (deactivate-mark)))
d12frosted commented 1 year ago

If you want to be able to use alias of the note when inserting a link, just select the alias in the first place. vulpea-select includes all aliases during completion. See as example the following screenshot.

image

Pinot Noir has multiple aliases: Pinot Nero, Rulandské modré, Spätburgunder, Blauburgunder, etc. When I what to type specific alias I either type the alias name (e.g. Spätburgunder) or type the original name and select among aliases. How do I distinguish between them? That's why vulpea-select-annotate-fn displays original name in parenthesis by default (see https://github.com/d12frosted/vulpea#vulpea-select).

So I wonder, why do you need an extra selection if data you need is present in the first one?

Cletip commented 1 year ago

I would like to be able to choose the alias for two main reasons:

d12frosted commented 1 year ago

first, sometimes we forget an alias. For example, let's say you write a text that criticizes Napoleon. You would then search for "Napoleon" for the note to insert, and insert "Napoleon". But just before you do, the system also propagates aliases, such as "the little corporal", which is a derogatory nickname for Napoleon. This is perfect! So you finally insert "the little corporal", which will be a link to Napoleon.

But that's exactly what current vulpea-select supports. You don't need extra selection because you can search by "Napoleon" and you will see "the little corporal (Napoleon)" in completion. Take a look at my example with grapes. I constantly forget some aliases as well, but I remember the primary title. Sometimes it's otherwise.

Same applies to the second bullet.

Cletip commented 1 year ago

Ah yes I'm too stupid, I had deleted this feature, obviously. Sorry for the waste of time :(

d12frosted commented 1 year ago

@Cletip no worries. I suspected that you simply changed the default behaviour of annotation after seeing your code. But I wanted to understand your use case better :) Thanks for sharing!