emacs-citar / citar

Emacs package to quickly find and act on bibliographic references, and edit org, markdown, and latex academic documents.
GNU General Public License v3.0
479 stars 53 forks source link

Make citar-open more configurable #833

Open Risto-Stevcev opened 3 weeks ago

Risto-Stevcev commented 3 weeks ago

Is your feature request related to a problem? Please describe. I want to be able to get to the bibliography entry when I click on a citation or via citar-dwim or citar-open, but the menu that pops up only shows a link if there's a url associated with the bibliography entry, and/or one or more nodes if there's a node associated with the citation key. It's a common workflow to want to get to the entry, and it feels wonky to have to have a separate (citar-open-entry (citar-key-at-point)) for something like this.

Describe the solution you'd like If going to the bibtex entry were an option in the menu, I could just do citar-dwim, bind that to a key like C-c o, and then select it from the menu of actions for that citation key.

Describe alternatives you've considered Citar-embark doesn't solve the issue, because the ROAM_REFS keys are in the form of @foo @bar, which don't show up as actual highlighted links that I can click on or to C-c C-o. It does solve it sort of for [cite:@foo] links, but there's a bunch of extra stuff with embark that I don't want around because I can accidentally press a key or click on some embark menu entry that's unrelated to citar.

bdarcus commented 3 weeks ago

You're going to have to clarify this, as I don't really understand your issue, or what you would like.

Examples:

You don't mention at all org-roam until the alternatives?

And on that, while org doesn't highlight the refs, citar-embark should still work on them.

Finally, your config?

I will try to come back to this later next week.

Risto-Stevcev commented 3 weeks ago

It's in an org mode file/buffer, it's not the embark menu. I attached a screenshot of the menu I'm talking about, I don't know what this menu is called: Screenshot from 2024-06-14 08-51-29

This is my config:

(use-package citar-org-roam
 :after (citar org-roam)
 :custom
 (citar-org-roam-note-title-template "${title}")
 (citar-org-roam-capture-template-key "d") ;; Use the default org-roam capture template
 :config (citar-org-roam-mode))
(use-package citar
  :no-require
  :init
  (defun citar-open-entry-at-point ()
    "Open the citation entry at point in another window, reusing an existing window if possible."
    (interactive)
    (let ((key (citar-key-at-point)))
      (when key
        (let ((other-window (if (one-window-p)
                                (split-window-right)
                              (next-window))))
          (select-window other-window)
          (citar-open-entry key)))))

  :bind
  (("C-c o" . citar-open-entry-at-point))

  :custom
  (org-cite-global-bibliography '("~/projects/notes/references.bib"))
  (org-cite-insert-processor 'citar)
  (org-cite-follow-processor 'citar) ;; citar-open-entry will open bibtex
  (org-cite-activate-processor 'citar)
  (citar-bibliography org-cite-global-bibliography)

  :custom
  (add-hook 'org-roam-mode-hook
            (lambda ()
              (setq citar-notes-paths (list org-roam-directory))))
  )

My config shows the workaround, where I have C-c o bound to the function I made called citar-open-entry-at-point, which lets me open up the bibtex entry. I would be nice though if the bibtex entry were in that menu in the screenshot instead, so that I could click there to get to the entry and just do everything with C-c C-o and it's all in that one menu in the screenshot.

My workaround solves the issue with [cite:@foo] style links, but it also solves another use case as well. Which is to be able to click the citation(s) in :ROAM_REFS:, which is :ROAM_REFS: @minikanren in the screenshot, and then it takes me right to the citation entry.

I thought it was very likely that there's probably already a way to do these things, given how common it is to want to get to the bibliography entry, but I couldn't find anything in these and other (org, org-cite, org-roam) docs.

Embark did work for the [cite:@foo] type references in an org file, but it doesn't work for getting to the citation entry in :ROAM_REFS:, and it also has a bunch of extra commands in there that make it easy to accidentally press the wrong thing which slows down workflow. And then another downside to embark is that it's a second type of menu that increase the cognitive load vs just everything being in one menu.

bdarcus commented 3 weeks ago

That menu is for opening related resources; not the bibliographic entry. There's a separate command for that (am not near a computer and forget the name!).

You should be able to place point on a roam ref key and run embark-act, then select that option.

On Fri, Jun 14, 2024, 3:06 AM Risto Stevcev @.***> wrote:

I attached a screenshot a screenshot of the menu I'm talking about, I don't know what it's called Screenshot.from.2024-06-14.08-51-29.png (view on web) https://github.com/emacs-citar/citar/assets/6767374/b0a8f166-8443-47fb-8815-05958cda9100

This is my config:

(use-package citar-org-roam :after (citar org-roam) :custom (citar-org-roam-note-title-template "${title}") (citar-org-roam-capture-template-key "d") ;; Use the default org-roam capture template :config (citar-org-roam-mode))

(use-package citar :no-require :init (defun citar-open-entry-at-point () "Open the citation entry at point in another window, reusing an existing window if possible." (interactive) (let ((key (citar-key-at-point))) (when key (let ((other-window (if (one-window-p) (split-window-right) (next-window)))) (select-window other-window) (citar-open-entry key)))))

:bind (("C-c o" . citar-open-entry-at-point))

:custom (org-cite-global-bibliography '("~/projects/notes/references.bib")) (org-cite-insert-processor 'citar) (org-cite-follow-processor 'citar) ;; citar-open-entry will open bibtex (org-cite-activate-processor 'citar) (citar-bibliography org-cite-global-bibliography)

:custom (add-hook 'org-roam-mode-hook (lambda () (setq citar-notes-paths (list org-roam-directory)))) )

My config shows the workaround, where I have C-c o bound to the function I made called citar-open-entry-at-point, which lets me open up the bibtex entry. I would be nice though if the bibtex entry were in that menu in the screenshot instead, so that I could click there to get to the entry and just do everything with C-c C-o and it's all in that one menu in the screenshot.

My workaround solves the issue with @.*** style links, but it also solves another use case as well. Which is to be able to click the citation(s) in :ROAM_REFS:, which is :ROAM_REFS: @minikanren in the screenshot, and then it takes me right to the citation entry.

I thought it was very likely that there's probably already a way to do these things, given how common it is to want to get to the bibliography entry, but I couldn't find anything in these and other (org, org-cite, org-roam) docs.

— Reply to this email directly, view it on GitHub https://github.com/emacs-citar/citar/issues/833#issuecomment-2167372928, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAI3XRNQKGPNOG5AQWAC3ZHKJA5AVCNFSM6AAAAABJFE74RCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRXGM3TEOJSHA . You are receiving this because you commented.Message ID: @.***>

Risto-Stevcev commented 3 weeks ago

Embark did work for the [cite:@foo] type references in an org file, but it doesn't work for getting to the citation entry in :ROAM_REFS:, and it also has a bunch of extra commands in there that make it easy to accidentally press the wrong thing which slows down workflow. And then another downside to embark is that it's a second type of menu that increase the cognitive load vs just everything being in one menu.

bdarcus commented 2 weeks ago

Am back with access to a computer.

Embark did work for the [cite:@foo] type references in an org file, but it doesn't work for getting to the citation entry in :ROAM_REFS: ...

Both work for me as expected. This is the menu embark presents after running embark-act on the reference (you can see where point is on the left buffer).

image

That config is here.

So there may be something wrong with your config here, though I've not yet looked at that.

And then another downside to embark is that it's a second type of menu that increase the cognitive load vs just everything being in one menu.

Well, this is all a matter of opinion, and the design of citar and related packages like embark aim for flexibility and configurability.

Here's an example of using a hydra or transient menu alterative at point, but it has its own limitations, which you can feel free to play with if you like.

https://gist.github.com/bdarcus/09dff264a75ae78330d8ee1a1ee5e1b2

But I still don't really understand what you're asking for.

If you use citar-embark, embark provides the contextual actions and menus in the minibuffer and at point. And you have room to configure that via embark.

citar-open is just an interactive command that uses completing-read and the minibuffer to provide a UI.

I suppose there's a reasonable argument to be made that opening the source entry should be an option in citar-open, but we've so far resisted that view.

Risto-Stevcev commented 2 weeks ago

I'm probably not explaining it well, I did manage to get embark to work, but I'd ideally like to keep it all in that one menu that's in the screenshot I uploaded. I saw that citar-org-roam extends that menu like so:

citar-org-roam

I understand that embark is supposed to fulfill the role I'm asking about, but is there a way to programmatically extend that bottom menu like citar-org-roam does? I want to add a section for bibtex so it's all there.

bdarcus commented 2 weeks ago

... is there a way to programmatically extend that bottom menu like citar-org-roam does? I want to add a section for bibtex so it's all there.

You're asking for the last thing I mentioned in my latest reply: either to add the entry to citar-open, or to make it all configurable.

The notes section in that command menu alone is configurable. But beyond that, it's fixed.

So the title of this issue should really be something like "Make citar-open more configurable"?

Am not sure even how that might work. In the notes case, we have an API that notes sources code according to.

EDIT: I've changed the description accordingly, but will need to think about this, and I'm not sure when that might happen. In the meantime, If anyone else has input, feel free to add it.

I will say you can always write your own shadow command, borrowing that code as a starting point. And if you come up with an elegant solution, can always submit a PR.

Risto-Stevcev commented 2 weeks ago

Yeah, I guess the real question is how to make it more configurable. I didn't ask that initially because I thought that maybe I was using the library wrong. I guess I could copy whatever citar-org-roam is doing to add those new sections in the menu for my use case.

bdarcus commented 2 weeks ago

I guess I could copy whatever citar-org-roam is doing to add those new sections in the menu for my use case.

Actually no. Citar-org-roam is just providing a configuration that bundles some functions that citar calls.

You'd want to look at citar-open.

Other thing I forgot to mention: I encourage people to use the wiki to document custom config solution, as a possible interim bridge between user config and upstream code.