Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs, Auto Complete Mode, CSS, pain. (illustrated!)

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)
like image 544
a paid nerd Avatar asked Jan 04 '11 19:01

a paid nerd


2 Answers

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.

like image 172
Alain Avatar answered Nov 18 '22 09:11

Alain


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

like image 38
Paw Avatar answered Nov 18 '22 11:11

Paw