1
$\begingroup$

V 12.1 on windows.

This is easier shown in pictures. I like to have large indent for If and Do etc... to make it more clear. But the option LineIndent increases the indent for the whole code to the right, and very little for the stuff I am interested in, which is If, Do etc...

The default LineIndent is 1. Here are 3 pictures showing what happens when changing this from 1 to 2 to 3. Notice how the whole code shifts to the right. I do not want this. I want only to change the indent of these constructs above, inside the code. But without that initial indent added. Even though the indent for If has increased, but it has not increased by same proportion as the whole shift that happens.

enter image description here

So I really want is the following (which I did manually for illustration)

enter image description here

To get close to the above using LineIndent this is the result. You can see how much the whole code shifted to the right due to that initial indent, which I do not want

enter image description here

I played with some of the options in option inspector, but can't figure which will do what I want, if any

enter image description here

I know I can use code cell and do my own formatting, but code cells have its own issues as well.

Is there a setting that will change line indent, but without adding that initial indent? I do not like the whole code shifting so much to the right.

Here is the code used above

foo := Module[{x, y, m},
  x = 1;
  If[x == 1,
   Print["x=1"]
   ,
   Print["x is not 1"]
   ];

  Do[
   x = 1
   , {m, 1, 10}
   ];

  y
  ]
$\endgroup$
1
  • $\begingroup$ I believe your initial indent includes both the indent for := as well as the indent for Module. I don't think there is a way to change this. $\endgroup$
    – Carl Woll
    Commented May 27, 2020 at 23:25

1 Answer 1

1
$\begingroup$

I use the Code cell style rather than the Input cell style when I want complete control over indentation and formatting. On a Mac, it is Command-8 for Code and Command-9 for Input.

$\endgroup$
1
  • $\begingroup$ thanks, yes I know about code style, but it has its own issues. I wanted to use the standard input cell style, but only adjust the amount of indent as shown. $\endgroup$
    – Nasser
    Commented Jun 20, 2020 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.