3

Extending Customizing c-mode indentation behavior in emacs-24.4

How can electric indentation be disabled for other specific keys without disabling the entire mode?

Specifically, how can electric indentation be turned off for /* */ comments? Apparently disabling it for * does not do the job.

The following works only under some conditions.

(add-hook 'c-mode-hook
          (lambda ()
            (set-key (kbd "*") 'self-insert-command)))

Similarly, the following works only under some conditions

(add-hook 'c-mode-hook
         (lambda ()
           (setq electric-indent-chars
                       (remq "*" electric-indent-chars))))

(add-hook 'c-mode-hook
         (lambda ()
           (setq electric-indent-chars
                       (remq "*" electric-indent-chars))))

(?* and ?/ also do not work)

"some conditions": comment lines following another commented line keep their non-electric indentation after typing *, but a comment line immediately following a closing brace has its indentation reset upon typing the * in /*

user2127595
  • 81
  • 1
  • 3
  • [stefan's answer](http://emacs.stackexchange.com/a/3240/5296) doesn't work? (replace `?\n` with `?*`) – npostavs Mar 25 '15 at 19:16
  • See updated question. I am starting to think that something else is handling indentation of comments. – user2127595 Mar 25 '15 at 20:35
  • Long story short, I like to indent my comments with two tabs and my tabs keep getting killed. Turning electric indentation off globally fixes that, but I like the other things electric indentation does, so I want to find a more surgical solution. – user2127595 Mar 25 '15 at 20:45
  • 1
    ultimately, it looks like this was a duplicate of [In emacs how to disable comment auto-indent in C/C++](http://stackoverflow.com/questions/11061453/in-emacs-how-to-disable-comment-auto-indent-in-c-c) – user2127595 Mar 25 '15 at 21:01
  • Hmm, I could have sworn `electric-indent-chars` was supposed to cover other things, but actually it's only newline (maybe it's only *planned* to control other chars). – npostavs Mar 25 '15 at 21:14

0 Answers0