mynameisJEFF
mynameisJEFF

Reputation: 4239

Emacs: new line and automatic indentation in Java mode

I am new to Emacs. The Emacs that I am using now is not performing automatic indentation in Java mode. My problem can be best exemplified by the example below. Let | represent the cursor.

When I type:

public class Testing{
      public static void main(String[] args){|}
}

and press ENTER , the code becomes:

public class Testing{
      public static void main(String[] args){
|}
}

But this is not what I want. What I want is this (new line with auto-indentation):

public class Testing{
      public static void main(String[] args){
             |
      }
}

Can someone suggest what code I should add to the init.el file ?

Upvotes: 3

Views: 290

Answers (1)

rimero
rimero

Reputation: 2383

Did you already try the following to indent upon ENTER?

(global-set-key (kbd "RET") #'newline-and-indent)

Upvotes: 1

Related Questions