abo-abo / swiper

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

ivy-next-history-element breaks future history when there's no symbol at point #3034

Open catern opened 7 months ago

catern commented 7 months ago

ivy-next-history-element (run by M-n) contains a condition which inserts the symbol at point if (and (= minibuffer-history-position 0) (equal ivy-text "")).

If there is a symbol at point, then subsequent M-ns will skip that conditional and insert the actual future history. (aka, the list of defaults in this minibuffer session)

However, if there's no symbol at point, the first M-n will insert nothing. Since it also doesn't update minibuffer-history-position, the conditional will be hit every time, and so future history will never be used.

The fix is to delete this conditional in ivy-next-history-element; it's not the correct way to add a default. Instead, a default should be added in the normal way, either by adding values to minibuffer-default or by using minibuffer-default-add-function.

An example of one function that's broken by this is project-find-file (bound by default to C-x p f). Future history contains the current file path, so M-n is supposed to insert that, but ivy breaks this.