32
votes

I've got Auto Complete Mode installed for Emacs.

First: When I'm typing declarations I get the normal auto-complete behavior:

Hosted by imgur.com

So I hit Tab to complete — no problem. But then I hit ;:

Hosted by imgur.com

It instantly tries to complete something! And I can't hit Enter because that'll accept the erroneous completion!

Hosted by imgur.com

So I have to hit C-j. What a pain.

Second: Once I'm done with a declaration, I type }:

Hosted by imgur.com

...but it doesn't get indented properly unless I type Tab.

What gives?

Update, settings:

I'm using Emacs 23. My css-electric-keys are } and ;. My Auto Complete configuration is as follows:

(ac-config-default)
(setq ac-auto-start t)
(setq ac-delay 0.1)
(setq ac-auto-show-menu nil)
(setq ac-show-menu-immediately-on-auto-complete t)
(setq ac-trigger-key nil)
2
Really? A vote to close? I can't ask Emacs questions on SO anymore? :(a paid nerd
Close vote offset by my +1 for showing me that this thing exists.nmichaels
The question is "what gives?" Despite all the graphics and the nice formatting, "what gives?" doesn't seem to be much of a question. If I try to interpret your questions, you seem to be asking about both auto-complete and indentation. One question per post, please.abelenky
@abelenky, If I could vote down your stuffy comment, I would. Why are you insisting that he rephrase his question in complete, proper english? Maybe you are a Turing machine... He wants to know how to make it work better. if you don't have the answer, step back.Cheeso

2 Answers

11
votes

Here's a few suggestions:

  1. (setq ac-auto-start t) starts autocomplete automatically. If you change that to (setq ac-auto-start 1) (or 2 or 3) then it will only start after that many characters have been typed. This might not solve your problem though if after you type the ;, it considers the entire preceding word as part of the current auto-complete search.

  2. Maybe the problem is that it isn't recognizing the semicolon as a delimiting character (like whitespace), so it thinks you're still adding to the last word. Perhaps adding the semicolon string to ac-ignores would do the trick? (Not sure what the syntax for that would be)

  3. Maybe you can prevent auto-completion via the enter key by adding: (define-key ac-complete-mode-map "\t" 'ac-complete) and (define-key ac-complete-mode-map "\r" nil). I'm not sure how this will interact with DWIM though (enabled by default).

  4. Try adding semicolon as an auto-complete key?

My .emacs knowledge on a scale of 0 to 10 is like a 1.5, but maybe this will jog some better ideas.

4
votes

Old stuff I know, but try the following:

(add-hook 'css-mode-hook       
  (lambda ()
     (make-local-variable 'ac-ignores)
     (add-to-list 'ac-ignores ";")))

From the manual