-
Notifications
You must be signed in to change notification settings - Fork 74
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
[WIP] Add embark-bibtex frontend. #355
base: master
Are you sure you want to change the base?
Conversation
Seems this will be a great test for embark and marginalia! FWIW, my biggest needs are elegant support for citation key insertion in org and markdown for document authoring, and ability to integrate with org-roam-bibtex (which takes over note-taking for bib notes for use with org-roam). |
Note that there is also no reason to depend on Marginalia if you provide your own annotation function. You can provide your own annotation-function in completing-read as part of the metadata. Marginalia is really meant to enhance existing commands (switch-to-buffer, find-file, etc.), not to be used in scenarios like here. I think I've mentioned that before. The only dependency you really need is Embark for action support. That's one of the main points of this package suite, everything is decoupled. Mostly standard builtins/APIs are used. |
If you want to see prefix annotations (icons for example), you should use affixation-function instead of annotation-function. But this is only supported by Selectrum and Emacs 28 default completion. Ideally you would provide both for backward compatibility, the affixation function will take precedence if supported. |
Out of my depth, but wouldn't Edit: sorry, I think I mean |
@bdarcus Yes, by providing your own annotation function you can do your own formatting in the way you want it. This is better than using the marginalia specific internals. |
One more suggestion - you can also remove the Embark dependency and just provide the keymap and the actions as commands. Then this keymap should be bound via Embark to the completion category in the init.el use-package definition. But this way you already get commands out of all the actions if you only have bibtex-completion+this-new-package. And then my point was that the stuff should just be moved into the bibtex-completion package altogether :) But maybe I should stay out of your way now... Please ping me if you want to discuss this further. |
Looks promising!
Have a look at |
embark-bibtex.el
Outdated
(bibtex-completion-candidates))) | ||
|
||
;;;###autoload | ||
(defun embark-bibtex (bib-entry) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Thanks a lot for the feedback everyone! @minad I did not know you could provide your own annotation function in @bdarcus @tmalsburg Thanks for the remarks. I will take all of your feedback into account for the next iteration. |
One limitation of marginalia and providing completion annotations is that the annotations are not matchable when selecting a candidate. For instance, if one of the entries is displayed as
I see this as a pretty big limitation of the An option would be to wrap completion candidates using cons cells, as described by John Kitchin in this answer. |
Indeed; if this is the case, I would find it unusable. The whole point is, if I have 1000 items in my db, I don't know the key. So I type in parts of authors and titles to narrow it. But I thought bibtex-complete presented an alist? |
There is no problem actually. Just make everything you want to match on part of the candidate string. Annotations are only auxiliary information which is per definition by Emacs not supposed to be matched on. Maybe annotations are not even necessary since you want to be able to match on everything? |
So @mtreca - can you not then just use |
@minad Yes this is what I am going for. it is actually easier than what I thought it was going to be. This snippet does proper completion matching, leverages built-in formatting functions from (let ((candidates
(mapcar
(lambda (cand)
(cons (bibtex-completion-format-entry cand 188)
(cdr (assoc "=key=" cand))))
(bibtex-completion-candidates))))
(cdr (assoc (completing-read "bib: " candidates) candidates))) |
Next step: No Embark :) |
@minad Agreed. Could you explain a bit further how I can shortcut the embark dependency by "providing the keymap and the actions as commands. " ? |
Okay, I can take another look soon. This PR is not up-to-date yet, right? Can you please push these Marginalia changes? |
No I did not push the changes yet, I am struggling a little incorporating these changes with the interactive lambda function using |
embark-bibtex.el
Outdated
("s" embark-bibtex-show-entry) | ||
("l" embark-bibtex-add-pdf-to-library)) | ||
|
||
(add-to-list 'embark-keymap-alist '(bib . embark-bibtex-map)) |
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.
- At this point, this line is the only dependency with Embark. Remove it and the Embark dependency. This line can be written in the user config instead in order to make the keymap available to embark.
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.
So in the end, the idea for a user who has selectrum setup as their completion framework, is they just install this package (or, ideally at some point, just bibtex-completion), and install and configure embark to use the keybindings, and so associate the bibtex-completion commands with the selected candidates?
@minad I added your remarks to a new version. My issue is that embark actions do not seem to be recognized anymore. |
I just tested this; just initially loading the bib and narrowing. One little thing: the matching is ordered? E.g. author, then title, etc. And if there's no author, I actually can't match on the rest (like title). Where should this best be addressed, and how? In the users selectrum setup? In this package? I was just testing this with emacs-sandbox, and the most minimal configuration. |
Yes, you are right; if I load selectrum-prescient, it works as I expect! Edit: when the key-map is working, how does one invoke it from the selected candidate? |
This comment has been minimized.
This comment has been minimized.
@tmalsburg - on the naming question, you suggested this:
Wouldn't that result in/require unnecessarily and awkwardly verbose command names? I actually think there's a good argument to keep Or, a reasonable compromise: cr-bibtex? |
This comment has been minimized.
This comment has been minimized.
Let me start with the caveat that I have only skimmed the conversation here, and haven't read it the whole thing carefully, nor have I looked at the code yet.
You can definitely use all the actions you have from an Embark collect buffer (indeed, the buffers wouldn't be very useful if you couldn't!). By default in the Embark collect buffers I don't know what is keeping this from working for you, but we'll figure it out. So what exactly happens when you try to run
I think this does sounds like exactly the issue that @minad reported. I know how to fix it but haven't done it yet since it is a fairly large change. (I hadn't even noticed the problem because I don't use which-key myself.) Knowing that more people are using prefix keymaps in Embark, I'll make more of an effort to find the time. However, I don't understand why you are using a prefix keymap here. Am I understanding correctly that you are placing every single bibtex action behind the prefix It looks like you already have all the actions in a keymap called (setf (alist-get 'bibtex embark-keymap-alist) 'bibtex-actions-map) |
No problem; you shouldn't need to read the conversation beyond that one message. Thanks!
Context: using Doom evil, and the WIP selectrum et al module. If I hit "a" within the collect buffer on If I do the That's what I see when using the bibtex commands also.
No problem at all. I'm just glad we know the problem, and it wasn't me!
OK, we'll do that. The issue I was trying to work around I note above in the "sorting/grouping" section of this post. Basically, too-long command names (which is related to an orthogonal question about package name), and wanting to sort or group the keybindings so easier to quickly grok.
|
So basically the Embark collect buffers don't let you use other actions at all under your Doom Emacs configuration, @bdarcus? Since I don't use Doom, maybe you can help me debug this issue. First, just to check the obvious possible problem: you are sure you are running |
Ugh; I should have thought of that! If I run the command directly, it works fine. I'll report it to that doom PR. Thanks again @oantolin! |
That's a relief, @bdarcus! It's sounds like it's just a keybinding or Evil state issue, then, which should probably just be fixed locally in your personal configuration. You should bind some key to run |
Doom has extensive keybinding support, including in that module for embark-act, so it should really be fixed there. I'll link your comment over there. |
Oh, I went to doomemacs/doomemacs#4664. It also loads Embark! So then the Evil normal state for embark-act in Embark collect buffers should be added there, not in your personal configuration. EDIT: Didn't see your above comment while writing this one. |
So for the broader questions I was asking, the simplest approach is to keep things as are with just The remaining issues I see are (mostly) minor:
|
It seems @oantolin already answered most questions satisfactorily? Thank you, @oantolin! @bdarcus Regarding Maybe Embark could get support for |
@bdarcus About using the
I think probably a better fix would be to hide all the general actions (that is, actions bound in |
At first glance, I like that idea @oantolin. Would we suggest that here, say in an example configuration in the docs? |
@@ -0,0 +1,116 @@ | |||
;;; bibtex-actions.el --- Bibliography manager action | |||
|
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.
;;; Commentary: | |
;;; | |
;;; Provides wrappers around bibtex-completion action-functions, to make | |
;;; them available as standard emacs commands, and within completing-read | |
;;; compatible completion systems such as selectrum and icomplete-vertical. | |
::: | |
::: For additional power and flexibility, install marginalia and embark, and set up | |
;;; the action keybindings like so: | |
;;; | |
;;; (setf (alist-get 'bibtex embark-keymap-alist) 'bibtex-actions-map) | |
;;; |
@@ -0,0 +1,116 @@ | |||
;;; bibtex-actions.el --- Bibliography manager action |
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.
;;; bibtex-actions.el --- Bibliography manager action | |
;;; bibtex-actions.el --- Bibliography manager actions |
For this example, I also think the selectrum UI for multiple selection would need work. It would seem to be better, at least optionally, to be able to mark the selected candidates in the selectrum minibuffer, as in helm. But with |
Hi all, I'm currently super busy at work and couldn't follow the recent discussion. I will soon catch up and look at the PR but it may take a couple of days. |
Same as @tmalsburg, I am really busy this month. Will take time to review these discussions and apply suggested changes. |
Sounds good @mtreca @tmalsburg. To pare down the content here, I've hidden some of the recent longer posts of mine. I think this post summarizes my view of the current status. |
"Return all keys from bibtex-completion-candidates." | ||
(mapcar | ||
(lambda (cand) | ||
(cons (bibtex-completion-format-entry cand (1- (frame-width))) |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
(defun bibtex-actions--get-candidates () | ||
"Return all keys from bibtex-completion-candidates." | ||
(mapcar | ||
(lambda (cand) | ||
(cons (bibtex-completion-format-entry cand (1- (frame-width))) | ||
(cdr (assoc "=key=" cand)))) | ||
(bibtex-completion-candidates))) |
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.
This suggestion uses cl-loop
, as elsewhere in the codebase and for better performance, and also uses propertize to allow us to support bibtex-completion-additional-search-fields
.
(defun bibtex-actions--get-candidates () | |
"Return all keys from bibtex-completion-candidates." | |
(mapcar | |
(lambda (cand) | |
(cons (bibtex-completion-format-entry cand (1- (frame-width))) | |
(cdr (assoc "=key=" cand)))) | |
(bibtex-completion-candidates))) | |
(defun bibtex-completion--get-candidates () | |
"Return all keys from bibtex-completion-candidates." | |
(cl-loop | |
for candidate in (bibtex-completion-candidates) | |
collect | |
(cons | |
;; Here use one string for display, and the other for search. | |
(propertize | |
(car candidate) 'display (bibtex-completion-format-entry candidate (1- (frame-width)))) | |
(cdr (assoc "=key=" candidate))))) |
@oantolin - maybe fodder for your wiki: how do I do this? |
Following issue #353, I worked on a prototype frontend for bibtex-completion leveraging the
embark
andmarginalia
packages.What changed since last iteration:
consult
dependency.What it looks like:
What is missing (a lot):
ivy-bibtex
(will add later once the prototype becomes more usable).bibtex-completion-format-entry
). From what I gather, this is because the default completion mechanism cannot rely on fancier display functions likeivy-set-display-transformer
. This means that I have to parse the completion options to only fetch the entry keys, pass them tocompleting-read
, and re-create annotations on top of that. It would be much nicer to reuse the bibtex-completion built-in tools.bibtex-completion-format-entry
.This is of course far from being PR-ready, but I would like to make this front-end a more collaborative effort, especially from people knowing both marginalia and bibtex-completion more than me.