views:

185

answers:

1

I am using the auto-completion elisp for emacs. I am currently using it by pressing M-TAB but I would like it to also auto-complete after 4 characters.

I use yasnippet as a source for auto-complete so if I set it to auto-complete after 4 characters it won't show completions like if, for, inc, main.

If I set it to start auto-completion immediately then it gets in the way of my typing.

If I set a key binding and tell it start auto-completion after 4 characters, it ignores the key-bindings, and doesn't start completion

(setq ac-auto-start 4)
(define-key ac-mode-map (kbd "M-TAB") 'auto-complete)

I would like for it to complete when I press M-TAB or after 4 characters.

EDIT: I tried

(setq ac-auto-start 4)
(global-set-key (kbd "M-TAB") 'ac-start)

I also have

(global-auto-complete-mode t)

It still didn't work. when I hit M-TAB it displays "Nothing to complete" in the minibuffer.

A: 

"ac-mode-map" is only defined when the auto-complete popup is visible, so your "define-key" above won't work. Maybe use "global-set-key" instead.

Also, I believe you need to bind it to "ac-start", not "auto-complete".

In summary, try the following:

(setq ac-auto-start 4)
(global-set-key (kbd "M-TAB") 'ac-start)
sanityinc
I don't think that's true. `ac-complete-mode-map` is the map that's only available when the popup is visible. `ac-mode-map` is the map that's available when you have enabled auto-completem mode. If you enable it like this, then the code you wrote in your question will work fine: `(global-auto-complete-mode t)`
pheaver
I stand corrected re. the mode maps. No idea why neither of our suggestions are working for hazyarc.
sanityinc