Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^2: How would you indent this? (cperl-indent-region)by LanX (Saint) |
on Mar 18, 2021 at 16:19 UTC ( [id://11129913]=note: print w/replies, xml ) | Need Help?? |
> (Update: I can't reproduce this! ) OK, I only used TAB indentation for each line so far. (emacs default is that TAB indents a line) If I mark the region and apply an explicit M-x cperl-indent-region I'm getting your result. That's also available from the "Perl" menu as indent region . Tested in 24.3 and 27.1 on Windows. From my experience does cperl not attempt to format nested data structures, there are many styles and interfering with the styles of Data::Dumper , Data::Dump, Data::Printer or Perl::Tidy is cumbersome. Cperl-mode only does indenting! It is also NOT attempting to vertically align elements in a 2D structure. It's a requirement close to AI to DWIM nested data. My preference here is Data::Dump, but it's also resorting hash-keys alphabetically and I wouldn't want my editor to take away this decision from me. The best format depends on the POV. Anyway ... what you are experiencing looks to me like a misinterpretation of the left curly as a block start like in for (...) { Please note how replacing the hashes with arrays is fixing this: (NB: I'd personally line-break right of the assignment)
workaroundsA) as quick workaround I'd suggest manually undoing nested data structures when indenting a large block of code. Since emacs has "regional undo" of marked regions ° this should be easy and you can use the formatter of your taste for nested datastructures. B) If you don't wanna use an external formatter, you can also appease yourself with this format by manually introducing line-breaks before right curlies } , b/c cperl-indent-region won't change this. ( I also manually did a vertical alignment)
Breaking the hash elements into individual lines works too. C) UPDATE Or don't use cperl-indent-* If you are working in a team, you'll need to use an RCS like GIT and chances are low everybody is using the same IDE. Resorting to a fixed Perl::Tidy setting hooked into your RCS is the only way here. Otherwise all reindented lines will show up as diffs.
what's nextI'll try to write a test for this problem in Perl to figure out the root cause. Could also be that the emacs maintainers changed some fundamentals which are sabotaging cperl-mode. HTH! :)
Cheers Rolf °) I haven't seen any other editor yet offering this.
In Section
Seekers of Perl Wisdom
|
|