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

Generalize the "notes" part of citar-open #612

Closed
bdarcus opened this issue May 26, 2022 · 13 comments
Closed

Generalize the "notes" part of citar-open #612

bdarcus opened this issue May 26, 2022 · 13 comments

Comments

@bdarcus
Copy link
Contributor

bdarcus commented May 26, 2022

We need to adjust citar-open to #603 (or drop the command altogether?).

The problem currently is the candidate list here is file paths, and typed as such for Embark.

And citar--select-resource takes a list of files as input.

But for org-roam v2, for example, with its more general concept of note, the candidates would be "org-roam-ref" "nodes".

I need to look, but I suspect we need to add another defcustom for the candidates.


Notes

  • org-roam-ref-read is the completion function
  • it has a customizable annotation function, to display the metadata
  • it uses org-roam-ref-read--completions; its candidates are a key and a list of org-roam nodes, which look like this:
(#("agnew2003" 0 9
   (node #s(org-roam-node :file "/home/bruce/org/roam/biblio/agnew2003.org" :file-title nil :file-hash nil :file-atime nil :file-mtime nil :id "fd1e8dfa-8bfd-43fb-884a-b350a7a0850a" :level nil :point 1 :todo nil :priority nil :scheduled nil :deadline nil :title "Notes on Agnew, From Megalopolis to Global City-Region?" :properties nil :olp nil :tags nil :aliases nil :refs nil)
          type "cite"))
  . #s(org-roam-node :file "/home/bruce/org/roam/biblio/agnew2003.org" :file-title nil :file-hash nil :file-atime nil :file-mtime nil :id "fd1e8dfa-8bfd-43fb-884a-b350a7a0850a" :level nil :point 1 :todo nil :priority nil :scheduled nil :deadline nil :title "Notes on Agnew, From Megalopolis to Global City-Region?" :properties nil :olp nil :tags nil :aliases nil :refs nil))
@bdarcus
Copy link
Contributor Author

bdarcus commented Jun 2, 2022

@aikrahguzar no rush, but since you've been working on and thinking about completing-read and embark, any thoughts on how to handle this elegantly?

@aikrahguzar
Copy link
Contributor

@aikrahguzar no rush, but since you've been working on and thinking about completing-read and embark, any thoughts on how to handle this elegantly?

I am not much of a note taker :)

From what I can tell you want to be able to address both files or location within a file and what springs to mind is bookmarks. I haven't used them myself but from what I have read about them they should work for both cases i.e. convert both filenames and org-roam nodes to a bookmark and use bookmark as an embark category.

An other approach would be provide something basic here and have a separate package which depends on consult to provide a richer interface. consult--multi can accept multiple sources with different categories and embark-act will work with the correct category of the candidate. Try M-x consult-buffer and it has both buffers and files in there and embark-act picks the right category. So you might want to look at how it achieves this if you prefer files and org-roam nodes to have different categories.

But I would say if you are really pushing the boundaries of completing-read it is better to just depend on consult since it has mastered that art. The only downside of that approach is that one has to depend on private functions in consult.

@bdarcus
Copy link
Contributor Author

bdarcus commented Jun 2, 2022

From what I can tell you want to be able to address both files or location within a file and what springs to mind is bookmarks. I haven't used them myself but from what I have read about them they should work for both cases i.e. convert both filenames and org-roam nodes to a bookmark and use bookmark as an embark category.

Ah, I hadn't thought about that.

An other approach would be provide something basic here and have a separate package which depends on consult to provide a richer interface. consult--multi can accept multiple sources with different categories and embark-act will work with the correct category of the candidate.

I had earlier thought of this, if not specifically for this issue. But that is certainly a possibility, in which case I might just drop citar-open.

I'll need to experiment with consult--multi again.

@mclearc is working on this consult-notes package, which makes use of consult--multi.

https://github.com/mclear-tools/consult-notes

It's purely focused on notes, however, whereas citar-open is focused on resources related to citation references, including notes.

@bdarcus
Copy link
Contributor Author

bdarcus commented Jun 3, 2022

@mclearc

It's purely focused on notes, however, whereas citar-open is focused on resources related to citation references, including notes.

Maybe a wild idea:

Do you think it would be feasible to replace citar-open with something based on consult--multi, where one could plug in different associated notes (well, really resources) functions, including one from consult-notes??

I played again with consult--multi, but I couldn't figure out the org-roam part; e.g this is broken, but illustrates the idea:

(defun concite-notes-org-roam ()
  "Notes."
  (org-roam-ref-read--completions))

(defvar concite-source-notes
  `(:name "Notes"
    :narrow ?n
    :category org-roam-node
    :items ,#'concite-notes-org-roam))

@mclearc
Copy link
Contributor

mclearc commented Jun 3, 2022

@bdarcus -- yeah interesting idea. I'll see if i can get something working.

@bdarcus
Copy link
Contributor Author

bdarcus commented Jun 3, 2022

I actually had in mind at one point a generalization of even that, called consult-scholar. But that may be overkill/over-generalization :-)

@mclearc
Copy link
Contributor

mclearc commented Jun 3, 2022

there is this function from the consult-org-roam package that might be useful. I'm not sure I have time today to get into this all that much but we'll see...

@bdarcus
Copy link
Contributor Author

bdarcus commented Jun 3, 2022 via email

@bdarcus
Copy link
Contributor Author

bdarcus commented Jun 3, 2022

I figured it out:

I think the constraint that consult--multi imposes is that candidates must be a list of strings. More complex candidates as in org-roam or citar are not allowed.

So this works, for example:

(defun concite--notes ()
  "Notes."
  (mapcar #'car (org-roam-ref-read--completions)))

But one can probably propertize those strings to embed additional metadata in them.

Edit: actually, org-roam itself uses propertized strings for the candidates, so should be able to use those for the annotations (for example, to extract the node). I just didn't figure that part out yet.

I also am not a fan of those completion candidates; completing on the keys.

And the other thing I don't see ATM: affixation functions. So in the above, would just attach an annotation function. See this issue for affixation:

minad/consult#565

Finally, the other limitation (though may not matter): no multiple selection.

@mclearc
Copy link
Contributor

mclearc commented Jun 3, 2022

Cool -- i've generalized the consult-notes function so that it accepts arbitrary sources as normal for consult--multi so this works. I'm pretty sure I can figure out how to add annotation data of some sort.

Screen Shot 2022-06-03 at 17 43 51

@mclearc
Copy link
Contributor

mclearc commented Jun 4, 2022

I also am not a fan of those completion candidates; completing on the keys.

This seems better:
Screen Shot 2022-06-04 at 14 48 43

the relevant code being:

    :items ,(lambda () (let* ((node (mapcar #'cdr (org-roam-ref-read--completions)))
                                   (title (mapcar #'org-roam-node-title node)))
                    (progn title)))

I'm having real trouble (perhaps predictably) getting any good annotations though. We'll see.

@mclearc
Copy link
Contributor

mclearc commented Jun 4, 2022

Actually -- I think this works:

Screen Shot 2022-06-04 at 15 15 39

    :annotate ,(lambda (cand)
                 (let* ((file (org-roam-node-file (org-roam-node-from-title-or-alias cand)))
                        (attrs (file-attributes file))
                        (dir (file-name-nondirectory (directory-file-name (file-name-directory file))))
                        (size
                         (file-size-human-readable (file-attribute-size (file-attributes file))))
                        (time (consult-notes--time (file-attribute-modification-time attrs)))
                        )
                   (concat (format "%7s %7s" dir size) "  " (format "%10s" time))
                   ))

@bdarcus
Copy link
Contributor Author

bdarcus commented Jul 10, 2022

Closed via #634

@bdarcus bdarcus closed this as completed Jul 10, 2022
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 a pull request may close this issue.

3 participants