Smart indent new bheaviour (removing whitespaces) is messing with Git

조회 수: 11 (최근 30일)
Benoît Béranger
Benoît Béranger 2022년 9월 9일
편집: goc3 2024년 4월 1일
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

답변 (3개)

goc3
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.

Sean de Wolski
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)
  댓글 수: 1
Benoît Béranger
Benoît Béranger 2022년 9월 14일
For a new project, I would rather user the new bejaviour, I agree it's smarter in most cases. But not when we have to use older versions of Matlab.
But, in my case, and this might concern other people using control version systems, not being able de control the behaviour of "smart indent" brings more problem that tha adavantage of the feature.
The user should have the oportunity to decide which method fits best its needs, like any option in the Preferences menu.

댓글을 달려면 로그인하십시오.


goc3
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;
See the documentation page for more details on this and other editor settings.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by