Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jplindstrom (594)

  (email not shown publicly)

Journal of jplindstrom (594)

Monday August 09, 2004
03:56 AM

Emacs cperl indentation

[ #20312 ]

Having started using Emacs for Perl programming, I'm thoroughly confused by the indentation settings and how they work together. Two things still bother me.

First is the continued line indentation. Consider this code:

if($install) {
    $oB->saySystemOrDie("Installing", 3,
                        "$prog install", "Errors during installation");

What I really want is for the continued line to be indented two tab stops. It should _not_ be aligned with the opening paren on the line above, because that changes with each method name length... This is what I want:

if($install) {
    $oB->saySystemOrDie("Installing", 3,
            "$prog install", "Errors during installation");

The second weirdness seems related. I can understand that cperl gets confused, but I'd still would like it to work.

The problem is that I have a layout habit I find useful. I write methods like this:

sub systemOrDie { my $self = shift;
    my ($command, $dieMessage) = @_;

Having the $self on the same line as the sub name is a nice visual cue that this is a method. However, Emacs insists that if I do that, the proper indentation is:

sub systemOrDie { my $self = shift;
                  my ($command, $dieMessage) = @_;

and that doesn't really do it for me.

Now, I think these two has something to do with cperl-continued-statement-offset and/or cperl-continued-brace-offset, but I can't seem to get it working.

Any hints?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • First, make sure that you have the latest cperl-mode. A lot of distributions don't include the latest one. Your file cperl-mode.el should be at least version 4.32. Find it on CPAN (I think). That fixes some problems with indentation.

    My indenting style is probably different than yours, but this from my ~/.emacs might at least give you some ideas:

       '(cperl-label-offset 0)
       '(cperl-indent-level 4)
       '(cperl-continued-statement-offset 2)

  • First, make sure you've got cperl-mode [] 5.0. Then, have a look at the cperl-indent-parens-as-block setting. That'll fix the first one, but I don't know how to do the second.


  • You could sidestep the issue and use perltidy on your code. It tends to be smarter than cperl-mode on the whole, and is very configurable.