Smart indent new bheaviour (removing whitespaces) is messing with Git
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
goc3
el 10 de Sept. de 2022
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 comentarios
Sean de Wolski
el 9 de Sept. de 2022
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
el 22 de Mzo. de 2024
Editada: goc3
el 1 de Abr. de 2024
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 comentarios
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!