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!