minad / corfu

:desert_island: corfu.el - COmpletion in Region FUnction
GNU General Public License v3.0
1.11k stars 43 forks source link

Stale corfu pop-up after comint-previous-matching-input-from-input #467

Closed egr95 closed 3 months ago

egr95 commented 3 months ago

The emacs inferior shell offers great tricks for access one's command history, so for example, I use the following mapping, which lets me type out the first few characters of a command that I have used in the past, and quickly autocomplete it by pressing M-p:

(define-key comint-mode-map (kbd "M-p") 'comint-previous-matching-input-from-input)

So for example, suppose I open an inferior shell and run python script.py --args. Then a few commands later I can just type "py" and press M-p, and the rest of my command will populate the prompt. With corfu autocompletion active, after typing "py", the usual corfu pop-up shows up correctly, suggesting completions like "python", but my issue is that once I hit M-p, the rest of my command populates but I am left with a stale corfu pop-up that simply says "No match" and doesn't go away after subsequent keypresses. This is annoying because I often want to pull up an earlier command and then add some modifications, and it would be nice to have all the usual benefits of corfu when doing this.

I have solved this issue by adding the following hook in my config, but it seems like this might be something that could be better addressed directly in the package?

(defun my-corfu-quit-wrapper (&rest _args)
  "Wrapper function to call `corfu-quit` and ignore any arguments."
  (corfu-quit))

(advice-add 'comint-previous-matching-input-from-input :after 'my-corfu-quit-wrapper)

Thanks!