1

I am using corfu. Problem is that when I type something like "isearch" and want to continue with a new line and not to invoke a popup command.

When the corfu popup is open and suggesting isearch-cmds, isearch-face, ... and I hit ENTER Emacs does not start a new line. Instead it selects isearch-cmds from the corfu popup and inserts it.

When looking into corfu-map I see this:

(keymap
 (return)
 (ret)
 (67109092 . corfu-quit)
 (9 . corfu-complete)
 (13 . corfu-insert)
 (7 . corfu-quit)
 (27 keymap
     (100 . corfu-popupinfo-toggle)
     (32 . corfu-insert-separator)
     (104 . corfu-info-documentation)
     (103 . corfu-info-location)
     (112 . corfu-popupinfo-scroll-down)
     (110 . corfu-popupinfo-scroll-up))
 (tab . corfu-complete)
 (up . corfu-previous)
 (down . corfu-next)
 (remap keymap
        (keyboard-escape-quit . corfu-reset)
        (completion-at-point . corfu-complete)
        (previous-line . corfu-previous)
        (next-line . corfu-next)
        (scroll-up-command . corfu-scroll-up)
        (scroll-down-command . corfu-scroll-down)
        (end-of-buffer . corfu-last)
        (beginning-of-buffer . corfu-first)))

I think the 13 is the ENTER key and it is bound to corfu-insert.

So how do I remove the 13 entry from corfu-map so that hitting ENTER inserts a new line instead of invocing the command.

2 Answers 2

2

The question is likely a duplicate. Please search and if so, delete it.

(define-key corfu-map (kbd "<RET>") nil)
6
  • 1
    What seems to overwrite the keymap? In what way? All this code does is remove the RET binding for corfu-map. Whatever other binding RET has currently should then be in effect. The question, as I read it, is how to remove the binding of RET to corfu-insert. I answered that, I think.
    – Drew
    Commented Apr 4, 2023 at 16:45
  • Sorry I was wrong, Drew is right. It seems that you can overwrite the keymap if you specify some function other than nil.
    – roomworoof
    Commented Apr 4, 2023 at 17:30
  • If nil, the original function remains.
    – roomworoof
    Commented Apr 4, 2023 at 17:40
  • 1
    Confusingly this code adds (return) to the map but the 13 is not removed. But it has the desired effect!
    – Witek
    Commented Apr 5, 2023 at 7:54
  • @Witek: Really? What does M-: (kbd "<RET>") RET tell you? Does it tell you [return]? For me it returns "^M"; that is, a string with the single character Control M, which is 13.
    – Drew
    Commented Apr 5, 2023 at 22:49
0

How about overriding the called function corfu-insert? This overriden function just put a linefeed unless you tab-complete or move up/down to select.

(eval-after-load 'corfu
  '(defun corfu-insert ()
     (interactive)
     (if (> corfu--index 0) ;; was: >=0
         (corfu--insert 'finished) ;; original behavior
       (insert-char ?\n)))) ;; only put linefeed as you wish

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.