Can I indent triple operators in empers cperl mode?

In emacs cperl mode, ternary operators are not processed specifically. If you split them into several lines, cperl-mode simply postpones each line in the same way as indents of any continuation, for example:

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

This is not very readable. Is there a way I can convince cperl-mode indent as follows?

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

By the way, sample code from this question .

EDIT

There seems to be an error in the cperl mode of indenting triple operators. Take the following example, which was deflected using Emacs 23.1.1, cperl-mode version 5.23:

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

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

Note that outside of any curly braces, I basically get the indentation that I want. But inside the curly braces, the triple operator backed out a lot. Is there a fix for this?

+5
2

cperl-mode Emacs ? GNU Emacs 23.1, cperl-version 5.23, , :

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

, , :

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

, ( fail_result 'result') cperl. .: -)

+3

Cperl, M-1 M-S-| perltidy ( Perl:: Tidy) ( ). , , , , , , .perltidyrc.

- - - , PBP, , , , .

: cperl emacs

+3

All Articles