I’m using auto-complete-mode. It works fine in many major modes. But I don’t like using TAB for selecting candidates.
The user manual has this example line of lisp for using RET to select completions:
(define-key ac-mode-map (kbd "RET") 'auto-complete)
This is great for completions.
However, now that I can select candidates using RET, I can no longer use RET to insert line breaks.
Is it possible to do both?
Ideally, I’d like to use RET to select candidates from completions lists, but when no list is presented, I’d like to use RET normally – to insert line breaks.
How do I do this?
you can’t simply remap the RET key, because as you say then you lose the default behavior. You’ve got to build a function that checks if you are at the end of a word for autocomplete, and otherwise do the normal thing:
This snippet is a modification of this post.
Then you would remap RET to use the function:
This solution has two drawbacks:
You can’t pass arguments to
auto-complete. This can be done withinteractive, but I don’t know exactly how it works.If you press RET at the end of a line, it would try to run
auto-completeinstead of inserting a new line. You’ll have to improve the condition, although I don’t know how.