-
Notifications
You must be signed in to change notification settings - Fork 33
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
Bleeding prompt background #235
Comments
I mentioned this before in minad/consult#1. Is this proper api use or some kind of undocumented bending of the api which somehow works by change? |
The ability to display strings as something different is a standard Emacs feature so I think it would be good to support that. Helm and ivy also display the selection correctly in this case. |
Good, then I think it is ok to use that. The highlighting works in helm and ivy? Is it broken only in selectrum? |
Yes the highlighting of the selected candidate works correctly with the others. What doesn't work is the highlighting of the matched parts as the matching happens against the strings and not how they are displayed. Because of this the usefulness of this is limited but still something I think we should support (looking into why the other frameworks already display the selection correctly in this case might also reveal something else we should do differently with regard to highlighting). |
It seems to work if one prepends the candidate with a single space and display-propertizes that. I am trying to use that for consult-line. However if starting the selection, the line numbers are bold and after pressing some keys they become normal weight?? Probably has to do with selectrum overwriting some weight property somewhere. |
And afterwards you simply strip the space again, nice hack :) |
Not necessary, the space is simply not displayed. And the selected candidate goes through the alist after selection. |
Now I only have to manage to make consult--buffer selectrum independent... |
That is nice! I don't know if |
It is possible to trick (icomplete-mode 1)
(define-key minibuffer-local-completion-map (kbd "SPC") 'self-insert-command)
(let ((coll nil)
(colla '("this" "is" "coll" "a"))
(collb '("and" "now" "coll" "b")))
(defun test (str pred action)
(cond ((string= (minibuffer-contents) "a ")
(goto-char (minibuffer-prompt-end))
(delete-char 2)
(insert (propertize "a " 'field t 'rear-nonsticky t))
(run-at-time 0 nil (lambda () (goto-char (point-max))))
(setq coll colla))
((string= (minibuffer-contents) "b ")
(goto-char (minibuffer-prompt-end))
(delete-char 2)
(insert (propertize "b " 'field t 'rear-nonsticky t))
(run-at-time 0 nil (lambda () (goto-char (point-max))))
(setq coll collb)))
(if (eq action 'metadata)
`(metadata
(cycle-sort-function . identity)
(display-sort-function . identity))
(complete-with-action action coll str pred))))
(completing-read "Check: " 'test) Not nice but may be a start. If you input "a " you get completion for collection |
@clemera I am not sure about this issue. As I described, if we always do the prefix like this |
Good point, but from a user point of view it is weird that you can't select the candidates as usual and ivy/helm behave better IMO. Though as this is probably a rare case anyway it may not be worth worrying about to much. |
Another way to fake the current minibuffer content would be to rebind |
I would rather like to keep the hacks to a minimum. I think it is ok to fallback on the selectrum-api if there is no other possibility. And we can always improve things as soon as the upstream api improves. I mean my goal is to have something which works (and if its nicely written thats a big bonus). I don't think trying to fit stuff onto some api at all costs makes sense. |
I'm just sketching possible approaches which would make this work using regular |
@clemera Sure, please do! Thank you a lot!
For me this question has been resolved negatively, I also meant it in a more restricted sense - if we can make this work while adhering to the standard api without using any special edge case behavior or tricks which make assumptions about the system lying below the api. For example reading the minibuffer-contents is using a side-effect which goes beyond what the api offers. If I look at the consult--buffer code (or the original code from the wiki), it is very straightforward. The completion function is just a pure function which does not use any effects. Therefore I had expected something like this to work: (progn
(let ((coll nil)
(colla '("this" "is" "coll" "a"))
(collb '("and" "now" "coll" "b")))
(defun test (str pred action)
(cond ((string-prefix-p "a " str)
(setq coll colla
str (substring str 2)))
((string-prefix-p "b " str)
(setq coll collb
str (substring str 2)))
(t (setq coll (append colla collb))))
(if (eq action 'metadata)
`(metadata
(cycle-sort-function . identity)
(display-sort-function . identity))
(complete-with-action action coll str pred))))
(completing-read "Check: " 'test)
) |
This would ideally work but it this is Emacs - unexpected side effects everywhere ;) Maybe we should propose this to the mailing list. |
I experimented a bit more and looked a bit more into the API and the following seems to work without advice almost as you would expect for default completion (also works with icomplete): (let ((colla '("this" "is" "the" "colla"))
(collb '("now" "showing" "collb")))
(defun test (str pred action)
(if (eq action 'metadata)
`(metadata
(cycle-sort-function . identity)
(display-sort-function . identity))
(let ((coll (cond ((string-prefix-p "a " str)
colla)
((string-prefix-p "b " str)
collb)
(t
(append colla collb)))))
(cond ((null action)
(cond ((or (string-prefix-p "a " str)
(string-prefix-p "b " str))
(concat (substring str 0 2)
(try-completion (substring str 2) coll pred)))
(t (try-completion str coll pred))))
((eq action t)
(all-completions
(cond ((or (string-prefix-p "a " str)
(string-prefix-p "b " str))
(substring str 2))
(t str))
coll pred))
(t nil)))))) You need to strip the prefix from the result afterwards if it was used. |
I tried it with selectrum and with icomplete and it doesn't seem to work for me. If I press "a SPC" it always completes to "colla". |
This sounds like you haven't rebound SPC?: (define-key minibuffer-local-completion-map (kbd "SPC") 'self-insert-command) It doesn't work with selectrum, we first need to fix #114. |
I assume you probably also use |
Yes, yes, yes.
I have not. Forgot it. It is easier if we exchange complete snippets.
I expected that, tried nevertheless.
I started using selectrum with orderless and haven't found a reason to switch to prescient yet. |
I also use |
Ok, sorting is something I haven't really understood yet. Which sorting is used by selectrum if I only use orderless? |
Ah this in the readme. Sounds reasonable. I am not sure if I need prescient yet. |
I use orderless for filtering as it also provides a |
Ok I see, maybe it would be a good idea to narrow the scope of prescient then or merge them, but I've just seen that you proposed that before :) Maybe it is also good to have some alternatives. |
@clemera I tried again the example you wrote above with SPC=self-insert-command and icomplete but it does not seem to work for me. When I press "a " I don't see anything, it shows "no matches". Is there anything else which could be wrong. EDIT: Sorry, I forgot. If I run it in emacs -Q without orderless, I can confirm it works. I will ask on the orderless issue tracker too regarding this. I would like to address the dynamic candidate issue at some point (let ((colla '("this" "is" "the" "colla"))
(collb '("now" "showing" "collb")))
(defun test (str pred action)
(if (eq action 'metadata)
`(metadata
(cycle-sort-function . identity)
(display-sort-function . identity))
(let ((coll (cond ((string-prefix-p "a " str)
colla)
((string-prefix-p "b " str)
collb)
(t
(append colla collb)))))
(cond ((null action)
(cond ((or (string-prefix-p "a " str)
(string-prefix-p "b " str))
(concat (substring str 0 2)
(try-completion (substring str 2) coll pred)))
(t (try-completion str coll pred))))
((eq action t)
(all-completions
(cond ((or (string-prefix-p "a " str)
(string-prefix-p "b " str))
(substring str 2))
(t str))
coll pred))
(t nil))))))
(define-key minibuffer-local-completion-map (kbd "SPC") 'self-insert-command)
(completing-read "Check: " 'test) |
You have to type "a" and then a space, then it should work. |
@clemera Sure, I wrote "a " above, meaning "a SPC". The problem I had now (and I forgot about that) might to be orderless. At least it works in "emacs -Q" after enabling icomplete-mode. Maybe @oantolin has an idea. I asked him on the orderless tracker. If it is possible to sort this out such that it works robustly with icomplete, it would be interesting to tackle the selectrum issue #114. |
Ah, okay no problem, I wrongly assumed you missed it. |
This is kind of the last big feature which one needs to use |
Yes, exactly! While I was skeptical in the beginning, I am pretty much convinced now that the standard apis are the way to go. I am testing with icomplete-vertical-mode from time to time and everything seems to work pretty well there too. Selectrum works better for me (faster etc, behaves somehow more natural to me). But for example this speed issue regarding icomplete - I was always wondering about that. Icomplete just feels somehow slow, is this due to delays? Even if I use a compution delay of 0. And I think I did also some profiling once and there icomplete performed pretty badly, but maybe I don't remember this correctly. I think I will try to profile this again now because I am wondering. |
Haha, interestingly the new marginalia-annotate-command-binding is appearing quite prominently now when profiling M-x in both selectrum/icomplete. This should not be, I think. But I guess I will investigate this profiling issue a bit more in detail. |
I think icomplete recomputes the table when you input something? The reason selectrum does not do this is the main reason for #114. I think we can handle this in selectrum by only doing recomputation for dynamic tables which are not know to be "static" on input like for example |
Hmm, yes that is probably the issue for the slowness. But if something similar as icomplete is done for selectrum, the performance will also degrade? How can this be avoided? By using the whitelists? I am not a big fan of such an approach. |
I think usually dynamic tables aren't too expensive to compute but there are a few built-in exceptions which we could exclude (see my edit in above comment). |
Ok, I agree (e.g. for the virtual buffer example it costs nothing), but then the question remains why icomplete is not as snappy as selectrum. Edit: Probably it is still the recomputation thing. If I try consult-buffer it is also fast on icomplete, but M-x is slow - so the recomputation cost can be significant? |
Yes, but I think this is mostly for the built in symbol tables so I hope by excluding those from recomputation it will work fine for most use cases. |
@sheijk I am observing this too. It also affects consult-line line numbers for example. But I think ist also happens with icomplete vertical. |
It seems using |
Yes they are not included in the hl. But there is also some bleeding of the prompt face into the line number face as long as nothing has been entered. Exactly the same issue which @sheijk observed. |
Not all properties. The background seems to be overwritten. But for example if the prompt is bold the boldness bleeds into the line number. This is what I am seeing. But it depends on the theme. If the theme sets the weight of the line numbers it won't bleed. |
Fixed by #413 |
EDIT: This was the display property issue which moved to #411, for the bleeding prompt see discussion starting here
It is possible to display candidates as different strings using the display property. Currently there is no indication of the current selection in this case.
The text was updated successfully, but these errors were encountered: