in reply to prettyfy hashes
What a pity! In Emacs, you can use align-regex , which I usually bind to C-x l . I can then just select the region and press C-x l => Enter and voilą!
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: prettyfy hashes (emacs)
by LanX (Saint) on Apr 03, 2016 at 03:39 UTC | |
One day I'll automatise it to happen with each auto indent. .. FWIW I seem to remember that perltidy can't do this.
Cheers Rolf
| [reply] [d/l] |
by choroba (Cardinal) on Apr 03, 2016 at 13:10 UTC | |
Moving the structure from the assignment line doesn't help:
| [reply] [d/l] [select] |
by LanX (Saint) on Apr 03, 2016 at 14:02 UTC | |
But this could be solved with separate rules for = , =~ and => and/or "sections separations". please note how this works
That's because { is a section separator while ( is not
using M-x customize-group RET align RET will facilitate customizing (it provides a textual UI for lisp data) the rule in question in align-rules-list is
this [~>]? part should be deleted or replaced. (BTW: not sure what the -* is intended to do...)
Cheers Rolf
| [reply] [d/l] [select] |
by choroba (Cardinal) on Apr 03, 2016 at 14:08 UTC | |
by LanX (Saint) on Mar 23, 2019 at 14:05 UTC | |
So task number one would be to separate these cases. Secondly we need to define region separators. as a demo: resetting the align-region-separate to handle parentheses helped (snippet from customize: Align Region Separate: Value Menu Regexp defines section boundaries: [][{}]) to format
to this, hence handling different levels accordingly
but this doesn't help with this because the separators will be inside each line
The only way to solve this is to use indentation to distinguish groups. According to the docs it's possible to use a function call back instead of a regex, but documentation is sparse. I wanted to document my findings before getting lost in other projects ... ;-)
Cheers Rolf
| [reply] [d/l] [select] |
by LanX (Saint) on Mar 25, 2019 at 00:08 UTC | |
by LanX (Saint) on Apr 03, 2016 at 14:35 UTC | |
wrong see http://perltidy.sourceforge.net/node005.html I think I confused it with Data::Dump and Data::Dumper which do not align (fat) commas.
updateBut I'm still not convinced about perltidy's performance for interactive use from within an IDE.
Cheers Rolf
| [reply] |
|
Re^2: prettyfy hashes
by LanX (Saint) on Apr 03, 2016 at 15:26 UTC | |
There is room for much improvement... 1. selecting the region: a combination of backward-up-list and mark-sexp will select the surrounding structure (repeating will extend the selection till statement (ie. ';') boundary. (please note that cperl-mode injects here some semantic knowledge about the code's structure which can't be reflected in a simple regexp rule) 2. the rule for align-current has the advantage to harmonize the surrounding whitespaces too. And align-regexp seems to allow the same extended logic. So combining both steps bound to a key should make alignment of fat-commas quite easy. I experimented with a kmacro and it seemed quite nice. :)
Cheers Rolf
| [reply] |