Can I customize the indentation of ternary operators in emacs' cperl-mode?

Posted by Ryan Thompson on Stack Overflow See other posts from Stack Overflow or by Ryan Thompson
Published on 2010-05-05T18:56:28Z Indexed on 2010/05/05 19:48 UTC
Read the original article Hit count: 227

In emacs cperl-mode, ternary operators are not treated specially. If you break them over multiple lines, cperl-mode simply indents each line the same way it indents any continued statement, like this:

$result = ($foo == $bar)  ? 'result1' :
    ($foo == $baz)  ? 'result2' :
        ($foo == $qux)  ? 'result3' :
            ($foo == $quux) ? 'result4' : 
                fail_result;

This is not very readable. Is there some way that I can convince cperl-mode indent like this?

$result = ($foo == $bar)  ? 'result1' :
          ($foo == $baz)  ? 'result2' :
          ($foo == $qux)  ? 'result3' :
          ($foo == $quux) ? 'result4' : 
                            fail_result;

By the way, code example from this question.

© Stack Overflow or respective owner

Related posts about cperl-mode

Related posts about emacs