-
Notifications
You must be signed in to change notification settings - Fork 53
align insert citation behavior, consolidate Embark maps #394
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
Also, use completing-read instead of completing-read-multiple when only one key is required.
|
I ended up not using |
|
It looked pretty hard to modify the org-cite-insert logic into something that makes sense for Citar. In particular, it always insists on adding a single key if point is inside a citation (multiple keys are only allowed for new citations). And if the point is on a reference, it insists on changing that reference to a new one, rather than adding more references after it. The function I wrote is still using all of the org-cite parsing machinery, but just adapts it to what we want for a Citar major mode function, which is to add keys to the current citation or insert a new citation. |
Yes, I agree that was a limitation.
So how would you change one? BTW, as you work on this, since you did roll your own, you might see how the shift reference (shift-left/right) and edit pre/post notes (M-p) functions work with it and affixes. There were some issues with leading/trailing whitespace that I hadn't gotten around to. And ideally the latter function would also edit global affixes (for the citation, rather than the reference) depending on point. |
|
I was thinking of splitting the keys-at-point major mode function into two:
So in Citar, we would have two target finders, one for keys and the other for citations. Since the functions return proper bounds, if you want to delete an entire citation/reference, you can just embark-act and then delete-region. Then we add two new major mode actions to the "citation" target, backed by major mode functions:
To back this up, we need a new major mode function, delete-references-from-citation. This plus the existing insert-citation should be all we need. I'll take a look at the editing functions and see what they're doing now. |
|
Maybe when you're "done" with the org one we can both test it, and the you can use what we conclude in the others. |
Can you clarify this last bit? Right now, I don't see how to edit the style. But it's pretty important. |
|
I just pushed a new version that seems to work reasonably well for org. You should be able to insert citations in org and latex, and in org-mode I added a new action called Needless to say, there's work to be done in rationalizing the two remaining keymaps. There are no org-specific embark keymaps any more, just the two in citar.el. I've renamed citar-buffer-map to citar-citation-map. The two target types are called citar-reference (which was already there) and citar-citation (which takes over the duties of the oc-citation target type). This should be a minimal working setup to test in org mode and at least reasonably okay in latex mode. I haven't really tested markdown yet. |
I don't entirely understand this part. I don't have embark-cycle bound on my embark (doom) setup. Also, I need to play with it more, but my initial impression is the edit citation at point UX is not ideal. I had thought you said above that you had figured out how to have the existing references pre-selected when bringing this up, which probably would be nice. But without that, it seems more efficient and clear to just work with the references directly, using I think the more important citation-level editing would be of style/command, and (in biblatex and org) global affixes.
Editing an existing citation in latex doesn't really work correctly ATM, and the embark target finder doesn't appear to work. Finally, |
|
Yes, see my comment in #381 on consistency. I hadn't yet implemented the edit-citation part (which would preselect the existing keys and allow you to delete them by deselecting). Currently it only adds new keys if they're not already present (so a context-sensitive insert citation). I do think the proper edit interface would be what I suggested, and will work on that once we've settled the keymaps/actions. It should be fairly easy to implement as a layer on top of the operations we already have. The embark target finder does seem to work for me in Latex. Do you have an example of text where it doesn't work? It cycles between the key-at-point and the entire citation macro. Sorry, I should've been clearer about |
It turns out a trivial problem: BTW, WDYT of my earlier suggestion we might want to distinguish natbib and biblatex? Can worry about it later, but just wondering. |
|
Yes, I do think we should try to be smarter about detecting which bibliography package somebody is using. I believe auctex has a whole system in place for class detection, so maybe we can take advantage of that. But I don't know much about it, so will look into it once the current batch of changes is done. It would also be nice to have better editing support for biblatex multi-cite commands (which I remember you brought up somewhere recently). The new target finder does detect all keys in a multi-key command, but there's no editing support. With the current code, you can edit the style in org mode by placing point on the style part, embark-act, and press E. If this doesn't work, it's a bug that I can fix. |
A lightweight option is
AFAIK, it's not supported in bibtex-completion either, probably because it doesn't appear so straightforward to add. Perhaps the approach @aikrahguzar took here makes it easier.
That does work. But with point at same place, |
True, but maybe a good project for a slow weekend 🙂
That was the behaviour I was going for, because I thought it made sense for insert-citation to only deal with adding new citations or inserting new keys into existing citations (and we're considering being able to delete keys with it, but now I realize that needs some thinking about). Whereas edit-at-point (aka org-cite-insert) is the operation to change the style or replace the key at point. Does this seem like reasonable semantics for those two operations? |
|
There's another reason for doing it this way: org-cite-insert prompts for different things based on where point is, so it's not really suitable as an embark action. If your current target is a citation key (from the minibuffer), but then you The insert-citation command always prompts for citation keys first, not styles or prefix/affixes. |
|
I posted this before your latest post :-) Will read that now.
I think the problem we have ATM is two different approaches:
I don't see how we can support both at the same time without confusing people. Do you? Delete-keys, BTW, is supported now with I guess I don't see any downside in the org-cite-insert approach for a context-aware command, except that if you want to be able to edit the keys for the whole citation, you have to make a decision on which point to consider for that vs editing the style. |
Ah, right. That gets to my point earlier about maybe the embark menu doesn't have to do everything. It gets tricky sometimes to figure out how all this should fit together. |
|
Just to clarify, my proposal is
So both commands are context-sensitive, but the second one has a narrower focus. I don't think all the commands need to be accessible through the embark menu, but there needs to be one command that is accessible through the menu and does the Right Thing most of the time (which would be (1) in my proposal). The other command (2) is also available through the menu, but this is strictly for convenience, because it ignores the current target and just cares about the location of point. EDIT: The reason I'm proposing this is for consistency and predictability. If I invoke (1), then I know that I'm going to be asked for some keys and those keys will show up in the document, as close to point as makes sense. It will never prompt for a new style just because of where point happens to be, which I might not be expecting. But if I know I want to change the style or something about an existing citation, then I position point on what I want to change and invoke (2). |
How do we document that clearly vis-a-vis Do we tell people not to use it? Or we tell them the choice is up to them? |
Command (2) is exactly org-cite-insert in org-mode, so that should be easy. The behaviour I described is what org-cite-insert does already. So if they like that then they can just use (2) all the time. EDIT: And when the point is not on a citation, (1) and (2) do the same thing, so it doesn't matter which one you pick. |
This is a thin wrapper around org-cite-insert in org-mode, and citar-latex-insert-citation in latex. Available under "i" in the embark at-point map.
|
I've pushed a new version, following what you suggested in #381 (two keymaps, one for minibuffer targets and one for at-point, and most of the insert functions are only in the minibuffer map). The at-point map does have the binding "i" for citar-insert-edit, which is just a wrapper around org-cite-insert in org-mode and a similar small wrapper in latex-mode. As you said, maybe this is a good intermediate step for now and later we can reconsider simplifying further. No rush to look at it, and I'll probably test things on and off the next few days. We can then work out what needs to be done before merging (in particular, rebasing on top of #395; in this branch I haven't touched the Markdown code). I will also update docstrings, readme, etc. where required. |
|
I think it generally seems good to me, though it may be we'll have to merge (when otherwise ready) and see what people think. Questions/issues:
On 2, basic use cases; I want to:
Let's just talk about org, and note that ideally should work the same in latex and markdown, at least ultimately (if not in this PR).
|
It's actually constrained by But let's just design the UX we would like for those three use cases and deal with the implementation as needed:
I've never gotten Org-cite activation (and therefore the keymap at point) to work properly for me. I've been meaning to investigate why but haven't gotten around to it yet. But to make (2) easier maybe we can add some point-navigation commands to that keymap in addition to the shift-reference commands. |
Right.
Oddly, I find I run into times when it breaks, but very intermittently. |
Just to clarify, do you mean there is no check currently or there should be no check? If duplicate keys should be allowed, then maybe we can still use |
The former. |
|
Hmm, so let's see what the behaviour should be: You put point on one of the references in a citation, invoke insert-edit, and select a reference that's already cited (or do we remove existing citations from the completion list?). Then one of the following things can happen:
|
This comment has been minimized.
This comment has been minimized.
|
I think you might have some code lingering around from the main branch, probably the Embark target finder? That screenshot show's it acting on a target of type "oc-citation" which isn't there any more in this branch. |
|
Yes, the new Org and Latex target finders I wrote return not just the key/citation at point, but also the bounds. Embark then shows these bounds as highlighting. |
|
The styling there is problematic. So is that likely a doom theme issue? EDIT: yes, |
I just tested a bit, but ran into a few issues (which shouldn't be specific to markdown, but ...).
Also, minor thing: should we change |
|
|
||
| ;;; At-point functions for Embark | ||
|
|
||
| (defun citar-key-finder () |
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.
| (defun citar-key-finder () | |
| ;;;###autoload | |
| (defun citar-key-finder () |
|
Right, I'll have some time this weekend to finish the Markdown integration and get this merged. That'll involve doing a rebase onto the main branch (and probably opening a new PR against the main branch, instead of this one). There are now two major-mode functions, insert-citation and insert-edit. Org has a context-sensitive implementation of the former and calls There shouldn't be any load-order dependent errors. But if you're switching branches and re-evaluating buffers, there's some possibility that the |

org-cite-insert)citar-latex-insert-citation)