-
Notifications
You must be signed in to change notification settings - Fork 53
Add embark support for citation keys at point
#143
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
Conversation
|
Thanks! Any thoughts on the CI warning on "with-eval-after-load" @ilupin @publicimageltd? Any general comments on this embark-focused PR @oantolin? |
AFAIU it's a warning which we can ignore insofar we do know what we do. But I don't know offhand how to silence this warning. |
And are we comfortable ignoring it? Just want to confirm :-) BTW, I tried to test this, but I have some problems on my end (long story). So a question. if in Edit: BTW, just for context for some of my perspective, bibtex actions will be included in Doom Emacs, as part of the forthcoming monster selectrum (embark, consult, etc) module merger. The intention is that this completion module replace the current ivy default. The ideas here are a future-facing alternative to a current PR (submitted more than a year ago) focused on org-ref. Of course, none of my perspective is specific to Doom though. |
@ilupin - are there any other alternatives you considered for this piece? |
I haven't read any of this new code, but this sounded a little suspicious to me. Here's what I thought would happen:
But as I said, I haven't looked at this carefully. |
Edit: I read the above too quickly and skipped the "minibuffer prompt" bit somehow. We just need to pass the list of in-buffer keys as argument to the functions; ultimately like: (bibtex-actions-open-notes '("one" "two" "three"))Thanks @oantolin - this sounds familiar from our discussions of embark and CRM. If this indeed the case, and we could avoid having to add specialized functions to do this, would have a huge advantage: We could then just have a standardized API for these functions; take a list of keys and do X (edit: maybe not that simple in its own, but ...). This would then allow mixing-and-matching these functions from different packages via embark. Right??? |
How about
You need the following code to make |
As @bdarcus said, we are dealing with in-buffer citation keys and there is no
|
I'm not really sure myself. Does that just silence the warning, but the setup code then works if embark is present? I was also wondering, will there be any problem with a user using different maps in their config?
While I can probably help you, could you please include README additions and modifications for all this, when the code is settled? Particularly the config details. |
bibtex-actions.el
Outdated
| map) | ||
| "Keymap for Embark citation-key actions.") | ||
|
|
||
| (defun bibtex-actions-embark-open (keys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next big question: why do we need these bibtex-actions-embark-* functions?
Can we not just have a little function to split if a string, and leave alone otherwise, something like:
(defun bibtex-actions--process-keys (keys)
(if (stringp keys) (split-string keys ";") keys))... and then something like:
(defun bibtex-actions-add-pdf-to-library (keys)
(interactive (list (bibtex-actions-read :rebuild-cache current-prefix-arg)))
(bibtex-completion-add-pdf-to-library (bibtex-actions--process-keys keys)))... and then remove these functions entirely?
Aside from raising the maintenance burden and decreasing flexibility, these additional functions result in really long names that are a problem in which-key (which Doom, for example, uses), at least.
BTW, if anyone has a great shorter and more general (non-bibtex-specific, because I'm expecting to be able to add support for CSL JSON in the future) name for this package ... :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that bibtex-actions-embark-* functions should be removed finally.
... and then something like:
It doesn't seem to work as expected. The tricky part is the entries are always chosen via completing-read when bibtex-actions-add-pdf-to-library is interactively called. embark also interactively calls bibtex-actions-add-pdf-to-library, which means the keys found at point are not used by bibtex-actions-add-pdf-to-library. I need to find a proper way to handle this.
embark treats interactive functions specially according to #143 (comment). I think we can just use non-interactive bibtex-completion-* functions as embark actions and pass a list of keys to them directly (see bb07e66).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't thought about the "add" commands. Could always defer those to a later PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is the same for bibtex-actions-open-* actually.
bibtex-actions.el
Outdated
| (cons 'citation-key (if (listp key) (string-join key ";") key)))) | ||
|
|
||
| (with-eval-after-load 'embark | ||
| (add-to-list 'embark-target-finders 'bibtex-actions-citation-key-at-point) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another question (and it is a question; I'm not sure) for both @publicimageltd and @ilupin:
Right now, one effectively cannot get to the default action directly. One must open embark, and then hit RET.
And both bibtex-actions-at-point and embark-act do the exact same thing; call embark-act.
Is that the right UX?
I could see also the first running "default" instead.
Or it could be this is a user-preference thing. Do we need a defcustom to configure this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this new comment, and linked new commit, from @minad; it's definitely relevant.
doomemacs/doomemacs#4664 (review)
The command embark-dwim executes the default action at point.
Seems we want to bind default to embark-dwim (the new name for embark-default-action), and suggest users have a keybinding for it in the README.
So default action is embark-dwim, embark-act brings up the option menu.
From the monster doom PR I mentioned, which includes this package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with adding a defcustom to make embark-dwim the default (see a80cb02). It will be consistent with the case where embark is not installed.
I wouldn't do that, because we do not want to interfere with the way the user wants embark to be loaded. The After looking at the info page for See this example code: (progn
(setq my-var nil)
(add-to-list 'my-var :element)
(defvar my-var '(a b c))
my-var)
;; -> yields (:element), but we would want (a b c :element) |
I don't have time ATM to look into it, but what about I just remembered that's an approach used a lot in Doom. |
Maybe we should ask at reddit or stackoverflow for good ways to silence the compiler warning and best practices. But as I said above, the case of adding elements to a variable which has to be set by the package itself is exactly one of those cases, in my eyes, for which |
This post seems helpful? https://emacs.stackexchange.com/a/51463 Maybe the "eval" option he gives makes sense? Could also just require embark, or remove this code (three lines) and put it in the README config section. |
The code at stackexchange wraps some definitions into an Here's a good solution (I didn't try it, but it looks good): https://github.com/tarao/bundle-el/blob/original/eval-after-load-compile.el The idea seems to be to "load" or "require" the feature only when the code is compiling. This seems to be the core part: (let (loaded)
(eval-when-compile
(setq loaded
(condition-case ()
;; don't eval after-loads during compilation
(let ((after-load-alist nil))
(require 'embark))
(error nil))))
(with-eval-after-load 'embark
....))There's some byte compile vodoo going on in the snipped; I didn't quite get why the macro calls byte-compile in the case it is compiled. That might be a trick my snipped above doesn't catch. So maybe we just copy paste this macro, give it credit where due, and if it works, then it works, right? I am currently procrastinating, I should do my work instead of this stuff. But it is an interesting problem. :-) |
|
That seems clever, but OTOH, it's simpler to just require embark, or remove those lines and add to the example config in the README. Whether to require embark or not is not only a technical question, I'm thinking. It also signals priorities and such. I'm not sure what I think ATM. Maybe once this is ready for review (the other issues are addressed) we can ask for feedback on the whole thing. @ilupin could add an explicit "REVIEW" comment to this piece. But it would be good to resolve the compiler warnings to facilitate review (else I need to turn off CI or something). |
So when org-cite is merged to org master, we probably want to add the first piece to the package, and the second to the README? |
|
Another solution would be to stuff all embark-related initializations into a function, and then offer a minor mode for embark. Initializiation from the user pov could then look like this: (use-package bibtex-actions
:config
;; for those who want to use it with embark:
(use-package embark
:config
(bibtex-actions-embark-minor-mode))) ;; or less verbose nameThe (define-minor-mode bibtex-actions-minor-mode
:lighter ""
:group 'bibtex-actions
:global t
(unless (require 'embark nil t)
(user-error "Bibtex actions embark mode requires embark to be installed."))
(if bibtex-actions-minor-mode
....setup...
....teardown...)) |
This is another detail I'm not super familiar with (from a developer POV), but seems worth considering. Also occurs to me we might defer all this for a separate PR, if it holds up merging. |
|
@oantolin - on this:
... I think we may have misunderstood you were saying here. Can you clarify? Are you saying, for example, that the in-buffer at-point target-finder somehow gets run through, internally, completing-read? And since embark will convert the CRM string to a list, it should work here too, without additional code? |
|
Oh, thanks for pinging me again, @bdarcus! It gives me a chance to correct myself. My earlier comment is completing wrong because I confused two package names: bibtex-completion and bibtex-actions! When I wrote that earlier comment I thought you wanted to use the functions from bibtex-actions (even though I mistakenly wrote bibtex-completions I was really thinking of bibtex-actions) as actions. Those functions are interactive commands, so when used as actions, Embark runs them interactively and inserts the target at the minibuffer prompt. The target must be a string for this to work. And, in this case, there would be a completing-read call involved: the completing-read call present in the bibtex-actions commands. But I was confused, you were really talking about bibtex-completion, and that's a different ball game because the functions there are not commands (i.e., the do not have an This is good news for this PR, I believe, because for non-interactive functions, Embark does not require the argument to be a string! I believe the functions in bibtex-completion take an argument which is a list of citation keys, right? The target finder can simply return a cons of the form |
@oantolin - sorry, this is indeed confusing, and I guess we didn't help :-) To recap:
I personally think ideally we want to remove the Edit: in other words, we want ideally to be able to use the same bibtex-actions interactive functions both with CRM, and at-point. I think we just weren't sure how best to do that. See, for example, #143 (comment). Does that make better sense now? |
Of course. I will update README when there is no problem with the code.
Yes. |
|
Maybe better for a separate PR, but ...
For short-to-medium run, we could add config info (probably on the README or the wiki), that makes use of this, to replace the command names in the menus with their descriptions: https://github.com/justbur/emacs-which-key#custom-string-replacement-options So rather than seeing "bibtex-completion-open-any" a user would see, for example, "Open (PDF or link)", both in buffer and minibuffer. Incomplete example for illustration. (which-key-add-keymap-based-replacements bibtex-actions-map
"o" '("Open source (PDF or link)" . bibtex-actions-open)
"p" '("Open source (PDF)" . bibtex-actions-open-pdf)
"l" '("Open source (link)" . bibtex-actions-open-link)
"n" '("Open notes" . bibtex-actions-open-notes))
(which-key-add-keymap-based-replacements bibtex-actions-map-buffer
"o" '("Open source (PDF or link)" . bibtex-completion-open-any)
"p" '("Open source (PDF)" . bibtex-completion-open-pdf)
"l" '("Open source (link)" . bibtex-completion-open-doi-or-url)
"n" '("Open notes" . bibtex-completion-open-notes))Incidentally, this is the same mechanism that Doom uses for its which-key-based menus (though hidden behind a macro). So we could hopefully include this in that Edit: not sure if this is new (looking more, I don't think so), but it might be worth experimenting with Ideally whatever we do works the same in |
With the workaround in d11dc1d, interactive commands The workaround, i.e. overriding |
Do you want to add a warning to that effect in the docstring? PS - this is looking good! |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Bruce D'Arcus <[email protected]>
|
@ilupin - could you update the first post with the commit message, so I can squash merge it, and use that? I'm a bit distracted ATM. |
embark support for citation keys at point
|
This looks RTM. Last call for feedback. I'll plan to merge later today (I'm in US West Coast ATM) or tomorrow. |
|
Thanks again @ilupin; this is a nice addition! |
|
@ilupin - back from travel, and so have more time to play with the new embark at-point functionality. Are we missing something here to configure, or should it "just work" if I have embark configured? https://github.com/bdarcus/bibtex-actions#basic It currently doesn't appear to be working for me. Edit: if I'm in a latex buffer, and run |
|
It doesn't need additional configuration.
It is expected if you call
Yes. What is the warning message? |
What I thought. Hmm ...
So how do you get the Edit: and for now (until org-cite), is latex the only context where this will work?
That the item key isn't found. In this case, the key was wrong; if I correct it, |
No. There is a
I see. In this case, |
Is there a way we can have both though? If the basic metaphor of Like, hit That's what I was assuming with the question at least.
OK. |
It is what In fact, when If |
|
Now that I committed the follow processor (I've opened a Doom PR to add OC support, so helpful to have that merged), back to this @ilupin: So my big question: is there a way for us to have both That would be ideal. It's also a bit confusing to me that when on an org-citation, calling If yes, what's involved in adding that capability? If no, maybe we should make that nil by default?
|

This PR enhances
embarksupport forbibtex-actions-at-point, which is inspired by the discussion in #142 and the code presented by @publicimageltd.If
embarkis installed,bibtex-actions-at-pointwill callembark-dwim(the default) orembark-act, depending on the optionbibtex-actions-embark-dwim, when one or more citation keys are found at point, whereembark-dwimruns the default action andembark-actprompts the user for an action inbibtex-actions-embark-map. If no key is found,bibtex-actions-readis used for choosing entries, and functions inbibtex-actions-mapcan still be called viaembark-act.This PR uses
bibtex-actions-get-key-org-citeandbibtex-completion-key-at-pointto find citation keys, and should work withorg-citeand latex-mode/bibtex-mode buffers.BTW,embark-target-findersrequires the TARGET at point being a string, whilebibtex-completion-*only accept a list of citation keys as input. Therefore,bibtex-completion-*cannot be used inbibtex-actions-embark-mapdirectly, andbibtex-actions-embark-*does the argument conversion.