This question relates to Mathematica 12.3 (and possibly many other versions).
Mathematica's automatic indentation does not conform to my workflow. From the very old days of Mathematica 1.2, i.e. before the introduction of the notebook frontends, I am still used to writing in indentation notation with one brace or bracket below the matching one. At the end of a construct, I insert additional line breaks so that I can align the closing parenthesis to match the beginning of the construct.
However, the frontend prevents me from doing this when I use Input cells. I could circumvent this by using Code cells, but they have other drawbacks.
I found out that you can disable Mathematica's indentation in Input cells by changing the Input cell in your own Default.nb like this (it is an example of my favorite indentation style):
Cell[StyleData["Input"]
, AutoIndent -> False (* 2020-12-08 *)
, AutoSpacing -> False (* 2020-12-08 *)
, FontSize -> 13
, CellMargins->{{66, 10}, {5, 8}}
, StyleKeyMapping->{"=" -> "WolframAlphaShort"
, "*" -> "Item"
, ">" -> "ExternalLanguageDefault"
}
]
But this only works on new notebooks. For an existing one, you do this:
- call Format>OptionInspector: Show Option Values>Selected Notebook and set Lookup: AutoIndent to False, then click Apply,
- set Lookup: AutoSpacing to False, then click on Apply.
(If I do this with Show Option Values>Global, it still doesn't work on old notebooks after they have been loaded).
- How can I combine steps 1. and 2. programmatically?
- Can I make it happen automatically after I open an existing notebook?
My favorite indentation scheme:
Because function names, which precede a square bracket, practically belong to the bracket following them, I treat the function name regarding the indentation like an opening bracket. Then the closing square bracket is in the same indentation depth as the function name before the opening square bracket (and of course the closing bracket is not in-column with its particular opening one).
Mathematica syntax separates parameters and list items by commas. If you want to see where the next parameter or list element begins in an indented text, you have to keep looking back and forth between the beginning of the indented text and the end of the line. This is exhausting and tiring, and it is easy to miss a comma.
You can also consider the commas as parameter separators or between list elements as belonging to the same indentation order as the corresponding opening and closing brackets, braces or parentheses. In fact, the coloring of syntax elements during editing in the frontend, it highlights the associated brackets together with the keyword before them, e.g. if you click before a comma. My personal view on the syntax elements seems to be present among at least some developers of Mathematica).
My preferred indentation takes up more space in the vertical direction than absolutely necessary, but it makes it easier to see the relationships.