jed-users mailing list

[2007 Date Index] [2007 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: perl mode indentation


On Mon, Mar 19, 2007 at 09:42:41AM +0100, Olesen, Mark wrote:
> > Waldemar R. Jankowski <waldemar@xxxxxxxxxxx> wrote:
> > >Currently my function calls that take an anonomous hash reference
> > indent
> > >like this:
> > >
> > >my $retval = function({
> > >                          foo => 'bar',
> > >                     });
> > >
> > >What I would like is this:
> > >
> > >my $retval = function({
> > >    foo => 'bar',
> > >})
> > [...]
> > >Is there a way to accomplish this?
> 
> The short answer: no, special treatment of a lone hash reference within a
> function parameter is, well, a bit too specialized.
> 
> If you are willing to treat hash references like any other parameter, the
> current heuristics will work fine:
> 
> my $retval = function(
>     { foo => 'bar' },
>     10, 20,
>     [qw( baz )]
> );
> 
> 
> If keeping the brace on the same line as the function name is a priority,
> you can have pre-declared functions and drop the parentheses:
> 
> use Data::Dumper;
> sub function {
>     my $i;
>     for (@_) {
> 	warn ++$i, " " , Dumper($_), "\n";
>     }
>     scalar @_;
> }
> 
> # call without '()'
> my $retval = function {
>     foo => 'bar'
> },
> {
>     baz => "yxx" 
> };
> 

> Although I am obviously obliged to like the perl mode indentation, I mostly
> use it to keep my code from getting too messy between calls to perltidy,
> which is bound to the "ESC Ctrl-T" combination. The "Ctrl-?" perl_help
> binding is also a godsend for quick reference.

> BTW: did you manage to find perltidy settings that worked for your preferred
> formatting? If perltidy doesn't manage it, neither can we!


Thank you for your response.  

I'm really after keeping the brace/bracket on the same line as the 
parenthesis in the function call and having the arguments on the next line 
indent 4 spaces, instead of all the way under the opening brace. The type
of brace usually happens to be a hash reference for me, but it could also 
be an array or subroutine reference. What I've usually done 
in the past is drop the brace to the next line:

my $retval = function (
    {
        foo => 'bar',
    },
);    

This way I can hit tab at each line and it doesn't push my arguments too far
to the right. I've been happily doing this until recently when I tried the 
newest cperl mode for emacs and saw that it was able to do what I describe.  
That's the only reason I brought it up.  No big deal though :)

Thanks for the tip about the perltidy binding.  I've been doing it the
hardway and running it from the command line.

I found that if you add 
-fnl    # do not want any changes to the line breaks

to your perltidyrc it will leave it alone and preserve the indentation, 
even if you have no vertical tightness.

As far as protyping all my functions, I don't want to go down that road just to
get the right spacing.

Thanks,
Waldemar

> 
> /mark
> 
> This e-mail message and any attachments may contain legally privileged, confidential or proprietary Information, or information otherwise protected by law of ArvinMeritor, Inc., its affiliates, or third parties. This notice serves as marking of its ?Confidential? status as defined in any confidentiality agreements concerning the sender and recipient. If you are not the intended recipient(s), or the employee or agent responsible for delivery of this message to the intended recipient(s), you are hereby notified that any dissemination, distribution or copying of this e-mail message is strictly prohibited. If you have received this message in error, please immediately notify the sender and delete this e-mail message from your computer.
> 
> 
> 
> --------------------------
> To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
> the word "unsubscribe" in the message body.
> Need help? Email <jed-users-owner@xxxxxxxxxxx>.
> 

-- 
+ Waldemar R. Jankowski: Senior Systems Analyst, Richweb, Inc.
+ Richweb.com: Providing Internet-Based Business Solutions since 1995
+ (804) 747.8592 x 105
+ GnuPG Public Key: http://richweb.com/wjankowski.gpg

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2007 date index] [2007 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]