Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Emacs, java mode, tab size

Posted on 1999-07-20
4
Medium Priority
?
901 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:mag062397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Expert Comment

by:awilkins
ID: 1635587
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
 

Accepted Solution

by:
DrChandra earned 400 total points
ID: 1635588
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
 

Author Comment

by:mag062397
ID: 1635589
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
 

Author Comment

by:mag062397
ID: 1635590
Hmm... It seems DrChandra was writing at the same time I was writing back to awilkins.

Thanks to both of you.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fine Tune your automatic Updates for Ubuntu / Debian
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question