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

Add initial-input argument to citar-select-ref #539

Closed

Conversation

andersjohansson
Copy link
Contributor

This can be useful when invoking it from another function, like
org-roam-capture.

My use case is for creating a new reading note with org-roam. If org-roam-node-find doesn’t find the author/title searched for, this is passed to org-roam-capture, where the citar search is initiated from the entered search string in roam ("${title}" in the capture template below).

I bypass the citar machinery in for file-notes here, because it seemed to assume a one note per file-system (the old org-roam way) which I don’t like (I currently use yearly files with date-trees for my notes).

(setq org-roam-capture-templates
'(
("l"
"Reading notes"
entry
"* Read %(aj/org-return-reference-author-year-title \"${title}\") :#reading%^g
:PROPERTIES:
:ID: %(org-id-new)
:ROAM_REFS: %(aj/org-last-returned-citation-key)
:END:
%U
%i
%?"
:empty-lines-before 1
:target (file+datetree "~/notes/notes-%<%Y>.org" month))))


(defvar aj/org-last-returned-citation-key nil)
(defun aj/org-last-returned-citation-key ()
  aj/org-last-returned-citation-key)

(defun aj/org-return-reference-author-year-title (&optional initial-input)
  "Fetch a simply formatted reference and return it as a string.
Possibly passss INITIAL-INPUT"
  (let* ((ref (citar-select-ref :initial-input initial-input))
         (key (car ref)))
    (setq aj/org-last-returned-citation-key key)
    (citar--format-entry-no-widths ref "${author editor} (${year issued date}) /${title}/")))

This can be useful when invoking it from another function, like
org-roam-capture.
@andersjohansson
Copy link
Contributor Author

Oh yes, you already pointed to the one note per file-issue here: #518

@bdarcus
Copy link
Contributor

bdarcus commented Jan 21, 2022

Awhile back, I removed initial-input support in favor of pre-filtering the candidates.

See #144

@andersjohansson
Copy link
Contributor Author

I see! Indeed, it doesn't work so well with CRM or consult-completing-read-multiple, as discussed earlier. (my use case here was for single ref selection, so I didn't realize that)

In my usage, I believe it is a little different from pre-filtering because there is no way to go back and change a bad search without quitting the command then. I see it as somewhat different than the aim to pre-filter by presence of pdfs etc, like the difference between the predicate and initial-input arguments to completing-read.

Perhaps it would be suitable only when the :multiple argument is not given to citar-select-ref then. I also saw the discussions on moving away from CRM in #492, so I guess this could be reconsidered if you choose to do that everywhere.

@bdarcus
Copy link
Contributor

bdarcus commented Jan 21, 2022

I just mentioned the context on initial-input, not entirely sure what you were trying to do ;-)

@andersjohansson
Copy link
Contributor Author

Yeah, the point is to go on from a failed search for an existing roam node to immediately start searching with the same terms in the citar-database in order to create a roam node for the reference. So I do think it is a valid use case for initial-input.

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

Successfully merging this pull request may close these issues.

2 participants