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

12 ビュー (過去 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 Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by