-
Notifications
You must be signed in to change notification settings - Fork 54
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
add bibtex-actions-history #120
Conversation
Yes, that's all you need to do!
History is only active at certain times, when you are in the minibuffer or at a shell prompt, a REPL prompt, etc. It's not active in regular text buffers. I'm sure you have used history before; when it is active you can cycle through history items using the up and down arrow keys or For this package, the history we are talking about would be active in the minibuffer when you run one of these commands that prompts you for a reference. |
As in, I'm done? Well, I may want to add a defcustom for predefined search strings? But otherwise, completing-read, etc will handle the details? |
Yes, I'd say you are done. (I may have explained more than necessary in my previous comment because I found it very odd that you expected You may not need a defcustom for the predefined searches, maybe just an example of storing them in the history variable in the README would be enough. But also, I'm not so sure my suggestion of prepopulating the history is really such a good solution. As you use the commands the history grows and makes it harder to find your predefined searches. Maybe they should be keep separate. As a low-tech solution you could do something like this: (defcustom bibtex-actions-presets nil
"List of predefined searches")
(defun bibtex-actions-insert-preset ()
"Prompt for and insert a predefined search."
(interactive)
(when-let ((search (completing-read "Preset: " bibtex-actions-presets)))
(delete-minibuffer-contents)
(insert search))) And just tell users to bind that command to some key in |
Yeah, I was wondering about that :-)
That seems better indeed, and low-tech seems appropriate here. So I could include those two bits of code, and we could add an example of how to configure that on the wiki. @apc - care to experiment with this idea? Thanks @oantolin! |
Awesome! Will have a look. May not have time today, but will get back to you tomorrow or so. |
Quick check: is it by design that when navigating through the history I see the entire string with all the spaces in between that, I imagine, are there only for formatting purposes? Also, is it by design that repeatedly pressing |
Is that inserting the candidate string, rather than the search that led to that? BTW, I added that code to the branch.
I'm a little unclear on how you access that history from selectrum, since those kbs by default migrate among the candidates. |
I'll let @bdarcus say whether it is by design, that is whether it is intended in this case, but I can confirm that is how the normal Emacs history mechanism works. First, the history items are full selected candidates from previous runs, not just the bit you typed before selecting a candidate (say, with the arrow keys and RET) and are displayed just as they would be when you selected them the first time, containing all the special formatting present. Second, |
Come to think about it, @bdarcus, maybe the future history is a good place to put the predefined searches. The history grows with use but the future history is whatever the developer puts there. |
Putting the predefined in searches in the future history can be done in addition to any other approach you might also want to implement. |
So for example, if there are multiple candidates that a user selected, this would insert them all in that CRM prompt? Therefore, it's not the history of what you see in the list of candidates, but of what you select among them? I didn't realize that. I think this may just be another place where the default CRM UI in these tools just does not play well with the design of these bibtex-completion frontends, which rely on long candidate strings. I need to think how well this would work, even with the positive (for these cases) changes contemplated in radian-software/selectrum#489. This isn't how the predefined search approach in Thoughts @apc?
OK, thanks! |
I think if the completion UI (in this case |
Yes, I think there's something a bit unfortunate about having the entire candidate string populate the prompt either when navigating through history or when selecting multiple entries to pass to one of the Incidentally, I no longer see how to combine the saved queries as just part of the history, since presumably the queries wouldn't correspond to a single candidate. Earlier I thought that the history would be populated by search strings, in which case you would be able to save helpful searches that way. But if it is populated with individual candidates, I'm not sure how this would help e.g. save a search for all entries having some word in the title. @oantolin were you thinking about the saved searches differently than I am? |
The things automatically stored by Emacs in the history are full chosen crm-separated candidate sets. The things manually put in the future history by the developer are arbitrary strings, you can put any sensible query you want there. |
Alright, time to play with future history. This seems a good post: https://engineering.collbox.co/post/working-faster-in-emacs-by-reading-the-future/ |
There's discussion of future history, with examples, also on the consult issue tracker: EDIT: in fact, this would seem to be the general solution I was earlier looking for. Using future history could replace the current "initial-value" approach I merged yesterday for the precooked filters. Consult, IIRC, has an |
Here's a minimal example, @apc, that allows to see how it would work: (completing-read "Select: "
(list "one text" "two text" "three text" "four file") nil nil nil nil '("text" "file")) The future history list is in the "default" slot. EDIT: just pushed the start of this change; not tested yet though. |
Neat! Will play around with it next time I have a chance. |
I keep getting this Also, calling But I assume you want the value of |
Very nice! One question: do you want the first item in (Incidentally: did you consider renaming |
To clarify, you mean you prefer the full candidate set to be added, as with your first screenshots in this PR?
Yes. I think it's searching now for presence of both. I think I need to change that to a regex to get the or. @oantolin - what's the syntax for |
No, sorry. At the moment I take it there are two ways of accessing the saved searches: typing |
You are right, @apc, sorry for the oversight. I use
orderless only matches against candidates strings. I don't know if you already put the information of whether an item has a link or pdf in your candidate strings, @bdarcus, but if you don't there is nothing orderless can do here. If you do add the string "has:pdf" (or similar, like "#pdf") to items that have a pdf, then a user could use "has:pdf" to match them (of course that would also match items without a pdf but that happen to have "has:pdf" in the title, or were authored by "steve has:pdf", but one hopes that is unlikely). If an orderless user has a style dispatcher for If you do add "has:pdf" or "#pdf" or some sort of marker to the candidates that have pdfs, but don't want this marker visible you can add the invisible property to the marker: even invisible text can be matched against. |
Yeah, I already have this. Sorry; I should have explained more. The problem @apc noticed is that I add this string to the initial value for the "open" command:
The problem is that will only match candidates that have both, of course, when what we need is to match either/or; the sort of thing you might do with a traditional regexp like:
Can I do that with orderless? I was trying different variations, but nothing worked. |
Ok, so initially you were advocating to keep I just pushed the change you suggested, and it works. I'm not sure myself. I guess we could just include it and see what a wider circle of users think. EDIT: I did just note one advantage of the "insert" approach is you can include more than one preset in the prompt. Also, the future history UI works exactly the same in |
Oh, I see. Well you can't use traditional syntax for regexps in orderless, but you can certainly use Emacs syntax for regexps (of course you need to use regexp matching style for this, but it is on by default). The Emacs syntax uses |
The one variant I hadn't tried! Awesome; thank you! Edit: nevermind. I did just add a note to the README strongly recommending orderless or prescient. |
I think there’s a place for both, especially in light of your point about combining predefined searches below. At first I couldn’t see a reason to have the future history solution other than it made use of stuff that was already there. But after playing around with it I see it’s quite a nice way to implement this feature too.
fair enough!
Neat!
exactly the same as it does with order less/selectrum or exactly the same as |
I mean the UX you get in selectrum is the same with the others, whether using future history, or Not surprising, but helpful to have confirmed. |
Should we update the If yes, any suggestions? |
Good point. How about this? (use-package bibtex-actions
:bind (("C-c b" . bibtex-actions-insert-citation)
:map minibuffer-local-map
("M-b" . bibtex-actions-insert-preset))
:after embark
:config
;; Make the 'bibtex-actions' bindings available from `embark-act'.
(add-to-list 'embark-keymap-alist '(bibtex . bibtex-actions-map)))
A mnemonic could be Also, if you want to include a bit in the (use-package bibtex-actions
:bind (("C-c b" . bibtex-actions-insert-citation)
:map minibuffer-local-map
("M-b" . bibtex-actions-insert-preset))
:after embark
:config
;; Make the 'bibtex-actions' bindings available from `embark-act'.
(add-to-list 'embark-keymap-alist '(bibtex . bibtex-actions-map))
:custom
(bibtex-completion-bibliography '("~/bib/references.bib")))
|
OK, I think this is RTM; your extended use-package example included @apc. I was thinking I should add you two as co-authors on the commit. If that sounds good, can you get me your email addresses, or just tell me it's OK to leave it out? |
Either way is fine by me! My email is my University's email address, using my GH username before the |
Full name or gh user name on the commit, @apc? |
Don't really mind either way. gh user name is shorter! Full name is 'Alejandro Pérez Carballo'. |
Done. Thanks much to you both. I fixed the bug with open while I was at it, BTW. |
@apc, this is a Selectrum thing. Other completion UIs don't not aggressively promote the default value like that. In default completion, Icomplete and Vertico the default is not shown unless you include it by hand in the prompt. |
I also don't mind either being included or not; up to you, @bdarcus. My name and email can be found by doing |
This adds history support.
It also may address #119, per suggestion from @oantolin in #119 (comment).
Two questions, @oantolin:
First, to "prepopulate the history", Is it really so simple as the below?
Second, how to activate the history?
If I run
consult-history
, for example, in any random buffer, I get a "no history configured" for that mode error.Would this be something where I would just need to turn it on, for say,
text-mode
?? If yes, how? And in this package, or in a suggested README config?