[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
29.3 occasional strange formatting in Java with treesitter java mode
From: |
Steinar Bang |
Subject: |
29.3 occasional strange formatting in Java with treesitter java mode |
Date: |
Sat, 13 Jul 2024 11:58:14 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Platform: emacs 29.3, editorconfig 0.10.1
In the last couple of weeks I've seen some strange formatting in tree
sitter mode. All of the ones I have encountered have been in test
files.
I was wondering if this is something in my setup or if others see
similar stuff?
Here is an example:
@Test
void testFormatDateAndSizeOnNullDate() {
var servlet = new OldalbumServlet();
var formattedNow =
servlet.formatDateAndSize(AlbumEntry.with().build());
assertThat(formattedNow).isEqualTo("");
}
(the void under @Test gets a strange indentation, and the two last lines
of the method gets strange indentation)
My setup, that predates the use of treesitter, is that
1. I use editorconfig to adopt the same project settings as eclipse and
IntelliJ (from .editorconfig files at the top of projects, setting
tab vs spaces, indentation, character encoding etc.)
2. I use my own homebrewed function ide-fix to correct indentation
before committing (the name comes from fixing up weird indentation
done by IDEs (mostly from the days before editorconfig))
The ide-fix code is (resides in my .emacs):
(defun ide-fix ()
"Remove trailing spaces and fix indentation"
(interactive)
(save-excursion
(goto-char (point-min))
(replace-regexp "[ \t]+$" "")
(goto-char (point-min))
(replace-string "\t" " ")
(indent-region (point-min) (point-max))))
The replacement of trailing spaces and replacing tabs with spaces comes
from a time when indent-region didn't always do the wanted thing and may
not be neccessary anymore?
(the removal of trailing spaces is from 2015 and the replacement of tabs
with spaces is from 2017)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 29.3 occasional strange formatting in Java with treesitter java mode,
Steinar Bang <=