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?

1
  • 3
    You can hit C-c C-s (for c-show-syntactic-information) to see which syntactic elements could influence indentation at point.
    – legoscia
    Commented Sep 30, 2014 at 14:27

1 Answer 1

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.

1
  • Got it working, thanks @Sigma and @legoscia, the C-c C-s is invaluable for debugging this.
    – Lee H
    Commented Sep 30, 2014 at 15:11

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.