Smart Indenting now Removes Whitespace

조회 수: 18 (최근 30일)
Grant Giesbrecht
Grant Giesbrecht 2022년 8월 26일
댓글: Grant Giesbrecht 2024년 4월 1일
In recent versions of MATLAB (I believe this behavior started with R2021a), the smart indent feature changed its behavior. The way it behaves in R2020b and earlier is, if your cursor is on a line that has been indented:
  1. If you press return one or more times, the cursor will be indented on the same level as the previous line.
  2. If you then click to a line that was previously smart-indented to the correct level, the cursor will be on that correct indentation level.
The way it behaves in R2022a is:
  1. (Same as R2020b) If you press return one or more times, the cursor will be indented on the same level as the previous line.
  2. If you then click to a line that was previously smart-indented to the correct level, the cursor will not be on the correct indentation level. It will have zero indentation, implying that the smart-indent features doesn't leave whitespace behind.
I find the behavior of the R2022a smart indentor to be very difficult to use, because it means going back and adding to indented code often requires you to manually hit tab a few times until your code is properly indented. This seems to largely defeats the purpose of automatic indenting. I've poked through settings looking for a way to restore R2020b indenting behavior, but cannot find an option to make it return to "correct" indenting.
Does anyone know how to restore the smart-indenting behavior to the R2020b behavior? I'm also curious if you know why this change was made; rather than shaking my tiny fist at the MATLAB gods in frustration, I'd like to know why this change can be benefitial to some users.
  댓글 수: 3
Grant Giesbrecht
Grant Giesbrecht 2022년 8월 26일
I see what you mean about anticipating what the user wants. The reason I'm still surprised to see it is: 1.) I think the previous MATLAB editor's implementation of guessing what the user wanted was pretty reasonable, and I'd rarely need to adjust the indentation level it provided and 2.) Most other editors also perform this guesswork reasonably well (eg. Atom, XCode, Spyder, PyCharm, etc).
Andrew Robbins
Andrew Robbins 2023년 4월 1일
이동: Matt J 2023년 4월 2일
Hello, I want to echo how awful this feature is for some basic workflows. (I'm using R2022b)
One simple example is:
Say you want to start an if statement and you're already on the 3rd indent. I would do the following:
  1. Type "if <expr>"
  2. Press enter twice
  3. Type "end"
  4. Click up arrow once to start putting in the contents of the if statement
function myFunc()
for i = 1:5
if true
<no tabs>
end
end
end
And now you have to tab yourself or put some code there and smart indent manually. Earlier versions of MATLAB just worked. The indenting was correct to begin with, no tabbing or anything required.
Am I using this is some unique and niche way? I would LOVE to opt to the old system, not because fixing this costs a significant amount of time, but because it is so stupid and unnecessary.

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

채택된 답변

goc3
goc3 2024년 3월 22일
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;
See the documentation page for more details on this and other editor settings.
  댓글 수: 1
Grant Giesbrecht
Grant Giesbrecht 2024년 4월 1일
Great find! Though for me at least, I also needed to set:
s.matlab.editor.indent.RemoveAutomaticWhitespace = 0;
in order for the new PadEmptyLines setting to take effect.

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

추가 답변 (1개)

Matt J
Matt J 2022년 8월 26일
편집: Matt J 2022년 8월 26일
This is just my suspicion but, in the Matlab editor, the tab key doesn't really seem to insert tab characters. It appears just to be a shortkey for inserting a certain number of space characters. As a result, it is not possible to backward tab in a single keystroke: when undoing indentation, you have to delete individual spaces.
Therefore, if you are inserting code into a blank line where you want indentation level 2 when the previous line has an indentation level of 3, it will cost you a lot more keystrokes to go backward from 3 than to start at an indentation level of 0 and hit the tab key twice.
The above argument ignores the possibility of doing Ctrl+[ to undo indentation, but I think control and escape sequences are considered more laborious and need to be weighted differently than single key sequences when evaluating the keystroke count.
  댓글 수: 4
Levi Blake
Levi Blake 2024년 1월 5일
"As a result, it is not possible to backward tab in a single keystroke: when undoing indentation, you have to delete individual spaces."
You do not need to delete individual spaces when undoing indentation. On windows you can remove however many spaces you use for indents by pressing shift + tab. Effectively, it's the reverse of using tab, and matches the behavior of many other programs such as Microsoft Word and OneNote.
Steven Lord
Steven Lord 2024년 1월 5일
This is just my suspicion but, in the Matlab editor, the tab key doesn't really seem to insert tab characters.
That depends on your preferences. See the Editor/Debugger Tab Preferences section on this documentation page.

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

카테고리

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