-
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 citar--select-multiple #591
Conversation
I think this would require completion UI specific code. |
As was the case with consult-crm initially. I guess Perhaps I can just include it for vertico, either in the code, or in the example config? @iyefrat: you sorted this out for consult-crm; any suggestions or tips? |
46745a3
to
1de36c2
Compare
When it comes to getting the custom bindings to work, it is indeed completion UI specific, the code in doom (linked in this comment) only worked for vertico. I'm not sure what you mean about |
Yes, and specifically I'm thinking I need to maybe do something on that function, but not sure what. |
@minad - this can't work with Embark; can it? |
I finally tried this out and it works well. The only two differences from the current situation are:
(defun citar--sort-by-selection (selected-hash cands)
"Sort the candidates by putting those in SELECTED-HASH first"
(let ((selected)
(others))
(dolist (cand cands (nreverse (nconc others selected)))
(if (gethash (substring-no-properties cand) selected-hash)
(push cand selected)
(push cand others)))))
(defun citar--select-multiple (prompt candidates &optional history)
"Select multiple CANDIDATES with PROMPT.
HISTORY is the 'completing-read' history argument."
;; Because completing-read-multiple just does not work for long candidate
;; strings, and IMO is a poor UI.
(let ((selected-hash (make-hash-table :test #'equal)))
(while
(let ((item
(completing-read
(format "%s (%s/%s): " prompt
(hash-table-count selected-hash)
(length candidates))
(lambda (str pred action)
(if (eq action 'metadata)
`(metadata (display-sort-function . (lambda (cands) (citar--sort-by-selection ,selected-hash cands)))
(cycle-sort-function . ,#'identity)
(group-function
. ,(lambda (cand transform)
(pcase (list (not (not transform)) (gethash (substring-no-properties cand) selected-hash))
('(nil nil) "Select Multiple")
('(nil t) "Selected")
('(t nil) cand)
('(t t ) (propertize cand 'face 'highlight))))))
(complete-with-action action candidates str pred)))
nil
t
nil
history ; FIX
"")))
(unless (equal item "")
(cond
((gethash item selected-hash)
(remhash item selected-hash))
(t
(puthash item t selected-hash)))
t)))
(hash-table-keys selected-hash))) brings it closer to the old behavior. I am not sure if |
|
One way I can think of: define another function that is vertico-exit but in addition sets a variable to t. We break the loop when this variable is t. But we need to bind this function at the right place (how does consult implement command specific keymaps?). Maybe this isn't worth it or maybe it can be added somewhere other than citar since it has to depend on the details of the completion system. I will probably hack something for myself. Maybe there is a way of setting such a variable using
There is no problem with your code but with that a selected candidate is in both the groups. I tried to fix that but that causes groups to exchange order sometimes and sort function fixes that. The one I wrote is basically the same as the |
I basically copied Daniel's first iteration of this idea, in #160. I think he figured out refinements for issues like this in the consult implementation.
Flexibility? Did you see my Embark question, BTW? |
I mean citar doesn't allow users to set their own sort function for candidates. Do we want that to be possible? Otherwise what I wrote should be fine.
I did, but I am out of loop on embark. I have used it as a bit by now ( |
Poking around a bit, I think |
I don't think so. |
This replaces completing-read-multiple with a simple alternative, courtesy of minad, that calls completing-read in a loop.
I added your mods @aikrahguzar. |
I don't see any changes. |
Oops; seems I forgot to push! Fixed. |
I've rebased this and fixed some conflicts, and also updated the issues list in the main post. Notably, embark doesn't work correctly with this (maybe we need a specialized target finder?), and I'd really like to figure out the keybinding issue. |
Assuming the current support for embark is due to (defun citar--embark-selected ()
"Return selected candidates from `citar--select-multiple' for embark."
(when-let (((eq minibuffer-history-variable 'citar-history))
(metadata (embark--metadata))
(group-function (completion-metadata-get metadata 'group-function))
(cands (all-completions
"" minibuffer-completion-table
(lambda (cand)
(and (equal "Selected" (funcall group-function cand nil))
(or (not minibuffer-completion-predicate)
(funcall minibuffer-completion-predicate cand)))))))
(cons (completion-metadata-get metadata 'category) cands))) It is using Getting selected candidates can actually be simplified if the |
Maybe I'm just tired today, but why? Wouldn't the function only get called by embark, and so that function would be loaded? |
That should work then. I was thinking that every thing defined by a package can only use functions/variables defined by packages transitively required by it, but that is definitely not how elisp works. |
Just getting back to this @aikrahguzar. I have, for now, added that function to a separate BTW, I tested this, and it doesn't seem to work, but I think something is screwed up with embark in general on my system ATM. Sigh ... Emacs. If you have time, could you see about testing it? And on another matter, this branch has diverged a fair bit from main, so it creates conflicts, which are not easy me to resolve. So if you do test it, and get your git setup, you can also feel free to create in a new PR, and I'll close this one. |
I actually didn't know what to test. I think the command is And what would be the simplest test to perform?
I will do this during coming days. Removal of |
Oh, that's right; you're also on Doom. So If your function doesn't work correctly, you will see generic commands. On my install, all of the sudden that binding isn't working at all. |
I will give it a try tomorrow.
|
I knew about that, but forgot! There's something really weird about when I do that. When I press Shrug. Maybe it's time for me to reinstall Doom and recompile everything. |
The embark problem is due to metadata not having a category and My takeaway is that there should be more code-sharing between |
This is a newer feature we were hoping would enable us to lessen dependence on multiple selection over time (though if we get this working well, we might not want that). It allows you, when using CR, to run commands against multiple candidates; for example, to mark some subset of them, or run against all.
Great; thanks! I'm going to close this for now then. |
This replaces completing-read-multiple with a simple alternative,
courtesy of minad (see #160), that calls completing-read in a loop.
See #582
This works, but needs testing, and polish. Details:
history doesn't work currently, even though I added a "history" argument.TAB
selects and deselects, andRET
completes. Is that possible, @minad?On 4, maybe want to borrow from earlier consult?
I've added my adaptation here in a commit for
citar-vertico.el
, though it doesn't work correctly currently. When I doM-x
I have to useTAB
to select the command, which is obviously not what we want. Rather, I only want this rebinding to happen withcitar--select-multiple
. But I don't really understand this code. Any suggestions?cc @aikrahguzar @localauthor