Edit: After reading the responses, I believe the answer is "don't do this", hence I marked an appropriate response as the official answer.
Is there an easy way to get emacs to display perl switch statements like perldoc.perl.org's switch page?
Here's the formatting on perldoc.perl.org:
use Switch;
switch ($val) {
case 1 { print "number 1" }
case "a" { print "string a" }
case [1..10,42] { print "number in list" }
case (\@array) { print "number in list" }
case /\w+/ { print "pattern" }
case qr/\w+/ { print "pattern" }
case (\%hash) { print "entry in hash" }
case (\&sub) { print "arg to subroutine" }
else { print "previous case not true" }
}
Here's the formatting in cperl-mode
after M-x indent-region
is run on the snippet:
use Switch;
switch ($val) {
case 1 { print "number 1" }
case "a" { print "string a" }
case [1..10,42] { print "number in list" }
case (\@array) { print "number in list" }
case /\w+/ { print "pattern" }
case qr/\w+/ { print "pattern" }
case (\%hash) { print "entry in hash" }
case (\&sub) { print "arg to subroutine" }
else { print "previous case not true" }
}
I'm having an inexplicable urge to stick with if-elsif constructs...
ps. I think this describes the desired process, but it looks like it'd take a while to parse.