# Is there a way to change the indentation behavior of the postfix operator //?

For example, using newlines after // results in some really weird indentation:

Ideally, I'd love to be able to do something like this:

x //
f1 //
f2 //
f3 //
f4 //
f5


or if possible, this would be even better:

x
// f1
// f2
// f3
// f4
// f5

• The last one is not possible because x on a line by itself is already a complete expression. x// is not a complete expression, so Mathematica will keep reading more from the next time. Similarly, x, newline, +y is two different expressions and not equivalent to x+, newline, y, i.e. x+y. If a line ends with a backslash, Mathematica will keep reading on the next line, but make sure no spaces follow the backslash. This is just a comment, I don't know the answer to your main question. You can use Code cells which don't indent at all but I don't think that's what you want. – Szabolcs Apr 17 '15 at 17:05
• I cannot recall seeing anything that would let us modify this indentation behavior but I like the question. – Mr.Wizard May 6 '15 at 6:21
• x // RightComposition[ f1, f2, f3, f4, f5] can have a relatively good appearance. x // f1 /* f2 /* f3 /* f4 /* f5 unfortunately doesn't. – Karsten 7. Jul 5 '15 at 10:39
• This would make a lot of sense considering all the operator forms introduced in v10. The current indentation behaviour for // is quite useless. Have you suggested this to Wolfram? – Szabolcs Jul 6 '15 at 12:34

You can use InputAutoReplacements with a TemplateBox to achieve the desired behavior:

CurrentValue[EvaluationNotebook[], {InputAutoReplacements,"//"}] = TemplateBox[
{},
"Postfix",
DisplayFunction->("//"&),
InterpretationFunction->("//"&),
SyntaxForm->"\[VerticalSeparator]"
];


The key is to change the SyntaxForm to a symbol that doesn't indent in the undesired fashion, which is most operators. However, it is necessary to use a symbol whose parsing precedence is lower than the default parsing precedence of "//".

Here's a portion of the precedence table from the documentation:

The above explains why I chose \[VerticalSeparator]for the SyntaxForm setting. Now, using // produces the following (as an image so you can see it in action):

A rough approximation using a string

toExpr[str_String] :=
str //
StringReplace[#, "\n" :> ""] & //
ToExpression;

"
x
//f1
//f2
//f3
//f4
//f5
" //
toExpr


f5[f4[f3[f2[f1[x]]]]]

Although, this is just a Composition

Composition[f5, f4, f3, f2, f1]@x


f5[f4[f3[f2[f1[x]]]]]

f5@*f4@*f3@*f2@*f1@x


f5[f4[f3[f2[f1[x]]]]]

% == %% == %%%


True