0

If I create a C file I get 2 character indentation which is what I want. However, if I create a java file, eg Hello.java then I am getting 4 character indentation. And I can't work out why.

My .emacs file:

(custom-set-variables
 '(column-number-mode t)
 '(tab-width 2)
 '(inhibit-startup-screen t)
 '(initial-scratch-message nil)
 '(tool-bar-mode nil))
(custom-set-faces
 )

(setq-default indent-tabs-mode nil)

1 Answer 1

2

Check c-basic-offset, c-default-style, and c-style-alist.

The default style for java is:

("java" (c-basic-offset . 4) (c-comment-only-line-offset 0 . 0)
  (c-offsets-alist (inline-open . 0) (topmost-intro-cont . +)
                   (statement-block-intro . +) (knr-argdecl-intro . 5)
                   (substatement-open . +) (substatement-label . +) (label . +)
                   (statement-case-open . +) (statement-cont . +)
                   (arglist-intro . c-lineup-arglist-intro-after-paren)
                   (arglist-close . c-lineup-arglist)
                   (brace-list-intro first c-lineup-2nd-brace-entry-in-arglist
                                     c-lineup-class-decl-init-+ +)
                   (access-label . 0) (inher-cont . c-lineup-java-inher)
                   (func-decl-cont . c-lineup-java-throws)))

If you just want to use 2 character indentation,

(setq c-basic-offset 2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.