Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs auto-complete: don't trigger on RET in inline suggestion

I am very happy with auto-complete but one thing bugs me:

I'm setup to show the inline suggestion immediately but the menu with 0.9 s delay. I type the first few letters e.g. "del" which get immediately auto-completed inline to "delete". If I wanted to type "delete" I hit TAB and this is alright. But what if I wanted to actually type "del" and a newline - here hitting RET again auto-completes to "delete".

How can I force RET to be newline if only inline suggestion is shown? Once the auto-complete menu is displayed I want it to be the trigger key again as usual.

Thank you!

like image 648
user673592 Avatar asked Sep 30 '12 10:09

user673592


1 Answers

By adding the following lines after other settings for the auto-complete mode, you can enable completion by RET only when completion menu is displayed:

(define-key ac-completing-map "\C-m" nil)
(setq ac-use-menu-map t)
(define-key ac-menu-map "\C-m" 'ac-complete)

ac-completing-map is a keymap where RET is by default bound to ac-complete, and ac-menu-map is a keymap for completion on completion menu. The ac-menu-map keymap is enabled when the ac-use-menu-map variable is t.

FYI, completion can be stopped by pressing C-g at any time. So you will also be able to hit C-g and RET to enter a newline with the bindings of RET intact. Also, you can use C-j rather than RET when you want to enter a newline. C-j does not bind to ac-complete by default.

like image 146
dkim Avatar answered Nov 18 '22 22:11

dkim