Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: How would you indent this? (cperl-indent-region)

by haj (Vicar)
on Mar 18, 2021 at 17:24 UTC ( [id://11129914]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How would you indent this? (cperl-indent-region)
in thread How would you indent this?

From my experience does cperl not attempt to format nested data structures

It shouldn't, but it does. As you suspect, CPerl mode mistakes the nested data structure as a control structure, which it reformats intentionally (see example here). It just takes a wrong turn in the function cperl-fix-line-spacing. Therefore, it is rather obvious that the issue doesn't occur with arrays: square brackets can't be confused with control structures.

If you want M-x cperl-indent-region and M-x cperl-indent-exp to do indentation and nothing else, set cperl-indent-region-fix-constructs to nil.

  • Comment on Re^3: How would you indent this? (cperl-indent-region)

Replies are listed 'Best First'.
Re^4: How would you indent this? (cperl-indent-region)
by LanX (Saint) on Mar 18, 2021 at 18:52 UTC
    > > From my experience does cperl not attempt to format nested data structures

    > It shouldn't, but it does.

    what I meant was that cperl doesn't attempt to mimic Data::Dump et al. (Many posters in this thread imply otherwise.)

    Which is a good thing, because the decision how to read the data must be left to the programmer.

    This particular example might have a "tabular interpretation" but others may not.

    > (see example here)

    oops, I was AFK and missed that

    > If you want M-x cperl-indent-region and M-x cperl-indent-exp to do indentation and nothing else, set cperl-indent-region-fix-constructs to nil.

    I can confirm this works.

    One quick solution could be to have another function cperl-format-region which activates the fix-construct flag internally.

    Tho having heuristics to distinguish between block and hash to avoid this problem would be nice.

    I'm also having another effect with 27.1 now

    {key    => 'k',...

    If I type a space between { and key , a TAB is introduced before the fat-comma => ?

    Can't be seen in 24.3 I'd say it's related to new global auto-indent settings in emacs.

    That's what I get after inserting a space after all {

    my @headings = ( { key => 'k', name => 'Kanji', class => 'kanji' }, { key => 'skip', name => 'SKIP', class => 'skip-code'}, { key => 'co', name => 'Suggestion', class => 'skip-code'}, { key => 'disc', name => 'Discussion'}, );

    UPDATE: Sorry, strike that. Seems like I had "silent" TABs in the code, which only jumped when a space was introduced.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129914]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-24 11:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found