Closed d-torrance closed 10 months ago
I'm not quite happy with this yet -- using this-command
to detect whether we just started a new line doesn't seem correct. Converting to a draft for now.
I'm happy with this now.
When the user specifically presses Tab (which is bound to indent-for-tab-command
in M2-mode and org-cycle
when looking at a Macaulay2 source block in Org Mode -- but more commands can be added by customizing M2-insert-tab-commands
), we get the classic M2-electric-tab
behavior of inserting spaces when on a blank line or to the right of some text.
But when M2-electric-tab
is called from any other command (e.g., from newline
, newline-and-indent
, org-return
, etc.), we indent based on the depth of the parentheses, matching the behavior of M2-newline-and-indent
.
This is an improved version of #18, which was eventually reverted (#22). The proposal is to keep the same basic behavior of indentation in
M2-mode
, but with a few improvements:M2-electric-tab
now checks to see if it was called fromnewline
, and if it was, replicates the behavior ofM2-newline-and-indent
. This means that we can deprecateM2-newline-and-indent
and just usenewline
, which is great because it has a lot more features. For example, users can now turn off automatic indentation after pressing Return by disablingelectric-indent-mode
.M2-electric-tab
is now documented!