Emacs, java mode, tab size

I just installed RedHat 6.0 along with Emacs (X windows) and I noticed that the tab stop is 4 spaces instead of 2.
The emacs-nox program is still 2; however the plain emacs is 4.

For example: (This is what I want)
if (i == 0) {
  statement;
}

This is what I get:
if (i == 0) {
    statement;
}

Anyone know how to fix this?
Thanks
mag062397Asked:
Who is Participating?
 
DrChandraConnect With a Mentor Commented:
Place the following code in your .emacs startup file. It
will hook the entry into java mode, and set the indentation
variable for you every time.


;; Change the indentation amount to 2 spaces instead of 4.
;; You have to do it in this complicated way because of the
;; strange way the cc-mode initializes the value of `c-basic-offset'.
(add-hook 'java-mode-hook (lambda () (setq c-basic-offset 2)))

0
 
awilkinsCommented:
From memory:

You need to change the value of the variable c-mode-offset from its default of 4 to 2.  IIRC, this is done from help->configure->change specific variable.  Then type in c-mode-offset.  This should pop up a new screen in your main window.  Change the current value of 4 to 2, then save it.  You can then hide this screen and get back to your coding.

0
 
mag062397Author Commented:
Yes you're right.  I eventually found the source code file /usr/share/emacs/20.3/lisp/progmodes/cc-styles.el which contained a 4 for the java mode.  I changed it to a 2 and recompiled the program and now I am happy.

In version 20.2 this was a 2; however some java standard says it should be a 4 so they "fix" it in version 20.3.  I perfer the c standard, a 2, much better.  I love open source.

Thanks for you help.  I'll give you the points if you want to propose it as an answer.
0
 
mag062397Author Commented:
Hmm... It seems DrChandra was writing at the same time I was writing back to awilkins.

Thanks to both of you.
0
All Courses

From novice to tech pro — start learning today.