abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.31k stars 338 forks source link

Bad in-buffer completion highlighting with whitespace-mode at EOL #1824

Open basil-conto opened 5 years ago

basil-conto commented 5 years ago

This is a minor annoyance that remains after the crux of #1488 was resolved in commit 7434a792c7b4ace1f138fe4256338e20f49981fc.

  1. make plain

  2. M-:(setq whitespace-style '(face trailing))RET

  3. M-xwhitespace-modeRET

  4. SPCfC-M-i So far, so good:

    overlay-4

  5. M-> Trailing whitespace highlighting kicks in, but only before ivy-overlay-at:

    overlay-5

abo-abo commented 5 years ago

This is an artifact of how ivy-completion-in-region works. If you set (setq ivy-display-functions-alist nil), you'll see that f in the buffer is actually erased, and then it's added to ivy-text.

It didn't always work like this, previously the buffer was not modified, and ivy-text started out empty. Maybe it's time to bring that behavior back. Because I find it annoying that I have to type an extra space e.g. f C-M-i SPC col to get a match, since otherwise ivy-text will be "fcol" and it will not match fill-column.

basil-conto commented 5 years ago

It should be possible to avoid modifying the buffer until a completion has been selected (which is the correct behaviour in any case), whilst simultaneously offering the more convenient initial completion behaviour you describe, by being smarter about how the overlay display property is constructed (I won't have time to look into this for a while). I wonder, though, whether any of the other supported display functions rely on the current behaviour of premature buffer modification.

abo-abo commented 5 years ago

It should be possible to avoid modifying the buffer until a completion has been selected (which is the correct behaviour in any case)

Yes, this should be fixed eventually.

The current approach was introduced around a year ago in 55e34e887946690a5c8f05403f5fc352c31c3b8d.

The issue was: suppose I'm completing:

(fill|

if the next character is "a", than Ivy will select fillarray only. But with the old approach, there would be many more candidates, and in addition fill-individual-paragraphs and not fillarray would be preselected on input "a".

So if we revert that commit and make the buffer not modified until a completion is selected, we need to make Ivy aware of the completion prefix, and somehow factor it into the preselection logic.