5

I have the following code from Intellij's indentation:

public static String[] defaultMethodBlacklist = new String[]{
        "getClass",
        "wait",
        "notify",
        "notifyAll",
        "finalize"
};

And:

public InternalClusterInfoService(Settings settings, NodeSettingsService nodeSettingsService,
                                  TransportNodesStatsAction transportNodesStatsAction,
                                  TransportIndicesStatsAction transportIndicesStatsAction, ClusterService clusterService,
                                  ThreadPool threadPool) {

However, when I attempt to adjust/fix the indentation in Emacs, I get:

public static String[] defaultMethodBlacklist = new String[]{
    "getClass",
    "wait",
    "notify",
    "notifyAll",
    "finalize"
};

public InternalClusterInfoService(Settings settings, NodeSettingsService nodeSettingsService,
        TransportNodesStatsAction transportNodesStatsAction,
        TransportIndicesStatsAction transportIndicesStatsAction, ClusterService clusterService,
        ThreadPool threadPool) {

My current indentation configuration looks like:

  (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  . ++)
                      (arglist-close  . ++)
                      (arglist-cont-nonempty . ++)
                      (access-label   . 0)
                      (inher-cont     . ++)
                      (func-decl-cont . ++))))

How can I configure the indentation in emacs to match Intellij's for code like this?

Also, how can I diagnose and fix issues like this in the future myself? Is there a way to get which "type" of indentation is being used at a particular point?

Lee H
  • 2,697
  • 1
  • 16
  • 31
  • 3
    You can hit `C-c C-s` (for `c-show-syntactic-information`) to see which syntactic elements could influence indentation at point. – legoscia Sep 30 '14 at 14:27

1 Answers1

8

You can make your style look like this instead:

'((c-basic-offset . 8)
  (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)
                      (access-label   . 0)
                      (inher-cont     . ++)
                      (func-decl-cont . ++))))

As legoscia points out, C-c C-s gives valuable insight regarding the syntactic symbols used. But you'll also need the list of those symbols to look for what you really need.

Sigma
  • 4,510
  • 21
  • 27
  • Got it working, thanks @Sigma and @legoscia, the `C-c C-s` is invaluable for debugging this. – Lee H Sep 30 '14 at 15:11