Smart indent new bheaviour (removing whitespaces) is messing with Git
조회 수: 11 (최근 30일)
이전 댓글 표시
Hello everyone,
I recently bumped from R2017b to R2022a.
Previously on R2017b, the "Smart Indent" beheviour looked like this :
Empty lines were filled with whitespaces.
The current behaviour in R2022a looks like this :
Empty lines are not filled with whitespaces.
When I make even the smallest modification in a file, I have a habit do ctrl+A then ctrl+I to "Smart indent" the whole file. Now, all whitespaces are deleted and Git detectes theses changes.
Is there an option to go back to the previous behaviour for "Smart indent" ? This way Git will not yell at me that the whole file changed at every empty line. Also, I'm still using R2017b and even older version to check easily that the fresh code is still compatible with older versions of MATLAB.
Best,
Benoît
댓글 수: 0
답변 (3개)
goc3
2022년 9월 10일
I submitted a service request regarding the change to smart indenting removing all tab space in blank lines (which I find to be infuriating) and was told that that is the new intended functionality! However, not all MATLAB users find this change to be desired or an improvement.
There is an undocumented settings modification that fixes this behavior in some respects:
While this does not completely fix the problem of white space being removed on blank lines, it does fix some of the editor behavior to align with older versions.
For what it's worth, I also formerly used the commands for select all text (command/ctrl-A) and then smart indent (command/ctrl-I). However, due to these editor differences in newer releases, I no longer do that. Dependent on the code, I either (1) higlight a block of lines and use command/ctrl-I, if no lines within the highlighting are blank, or (2) highlight a specific set of lines and use tab or shift-tab to manually create correct indentation, if any within the selection are blank.
It would be best if MathWorks would make this setting documented and a user-configurable preference.
댓글 수: 0
Sean de Wolski
2022년 9월 9일
This isn't a direct answer to your question but a couple ideas:
1) In my opinion, the new behavior is smarter. There shouldn't be empty whitespace if there's nothing.
2) You can get the active editor document and smart indent it programmatically. If I was in your situation, I'd script opening every file, smart indenting all of them at once, and eating that in one git changeset.
docs = matlab.desktop.editor.getAll
smartIndentContents(docs)
save(docs)
goc3
2024년 3월 22일
편집: goc3
2024년 4월 1일
Release 2024a includes a setting for this!! The following code will stop smart indenting from removing white space:
s = settings;
s.matlab.editor.indent.PadEmptyLines.PersonalValue = 1;
You may also need to set the following:
s.matlab.editor.indent.RemoveAutomaticWhitespace.PersonalValue = 0;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!