Dimitar Panayotov shares experience

Everything which eases programmer’s life and satisfies the clients

GNU Emacs: Avoid huge indentations in Java

Posted by Dimitar Panayotov on 29 November 2006, 2:41

Ever going crazy of default indenting of Java sources by Emacs? What about code like this?

Emacs screenshot showing custom tabulation hook in action

Much better, right? Here I use two things:

  1. No tabs — see No tabs article.
  2. I use custom c-mode-hook.

The custom hook should reside in your “.emacs” file like that:

(defun my-c-mode-hook ()
  (c-set-offset 'substatement-open 2)
  (setq c-basic-offset 2))

It is “plugged” to do its work when pressing TAB in Emacs, like that:

(add-hook 'c-mode-common-hook 'my-c-mode-hook)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>