Why do try-with-resources break indentation in Emacs? "

Emacs 24 Java mode does not create the correct try-with-resource construct.

 class X{ void foo() { try { check(); // ((statement-block-intro 35)) } } void bar() { try (Lock l = bar()) { check(); // ((substatement 140) (statement-block-intro 140)) } } } 

As you can see above, statements inside such a try block are indented by an additional 4 spaces, the value of c-basic-indent , including a trailing bracket.

The only difference between try and try-with-resource that I have identified is the syntax information for the first statement in the block, the last has an additional (substatement) in the head. Could this be the reason for his break?

If I manually remove 4 spaces from the first line, then the rest of the lines are indented correctly, except for the closing bracket, which still has padding with extra spaces.

It drives me crazy. If this solution changes me, then changing c-guess-basic-syntax is non-trivial, perhaps a workaround using tips?

+6
source share
2 answers

This is a well-known bug in emacs , and there is a thread on list.gnu.org about this patch issue that fixes this bug: https://lists.gnu.org/archive/html/bug-gnu-emacs/2013-07 /msg00577.html

Moreover, according to this: http://osdir.com/ml/emacs-diffs-gnu/2013-07/msg00350.html it seems that this error was fixed as early as 2013-07-27.

+1
source

Although the stream http://osdir.com/ml/emacs-diffs-gnu/2013-07/msg00350.html does have a fix, it is still not in the last cc mode. I grabbed the last cc mode and set it, then grabbed diff and applied it (it wasn’t applied cleanly, but was short and easy to use). Correct indentation! The path is more annoying than it should be, but I have the correct indentation, and I'm happy.

+1
source

Source: https://habr.com/ru/post/945026/


All Articles