http://qs321.pair.com?node_id=11146004


in reply to Re^2: How has your coding style changed over the years?
in thread How has your coding style changed over the years?

could you please share your settings?

Sure! If you are using the "current" cperl-mode.el from git, you can do:

For older versions of cperl-mode.el, here's the list of settings:

("PBP" ;; Perl Best Practices by Damian Conway (cperl-indent-level . 4) (cperl-brace-offset . 0) (cperl-continued-brace-offset . 0) (cperl-label-offset . -2) (cperl-continued-statement-offset . 4) (cperl-close-paren-offset . -4) (cperl-extra-newline-before-brace . nil) (cperl-extra-newline-before-brace-multiline . nil) (cperl-merge-trailing-else . nil) (cperl-indent-parens-as-block . t) (cperl-tab-always-indent . t))
In the end I stopped using perltidy

That reminds me of an issue "A command to run perltidy with the input from an emacs buffer" for which a first implementation never made it to Emacs....

Replies are listed 'Best First'.
Re^4: How has your coding style changed over the years?
by LanX (Saint) on Aug 07, 2022 at 21:01 UTC
    > That reminds me of an issue "A command to run perltidy with the input from an emacs buffer" for which a first implementation never made it to Emacs....

    I'm not sure I understand, isn't that just a shell-command-on-region command after a mark-whole-buffer ° ?

    > For older versions of cperl-mode.el, here's the list of settings:

    Thanks, especially (cperl-indent-parens-as-block     .  t) fixed a longstanding issue I had.

    It would be nice tho to have a split screen scenario for experimentation.

    Like with code on one side and "live" config on the other side, where every change is temporarily activated and demonstrated in the other screen. When happy you just save the config buffer to a file.

    Hmm ... probably could be done with a macro already ...

    I'm getting this result now when formatting, but neither my emacs nor my cperl-mode is the newest, and probably other configs are jinxed too...

    for my $x (@x) { my %h = ( 'truncate' => { 'desc' => 'shorten a file', 'usage' => [ 'truncate FILEHANDLE,LENGTH', 'truncate EXPR,LENGTH', ] }, ); };

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

    update

    °) I'm pretty sure such code was included in PBP.

      About perltidy in Emacs:
      I'm not sure I understand, isn't that just a shell-command-on-region command after a mark-whole-buffer?

      Yes, these are parts of the solution. The other parts are:

      • Be able to restrict the perltidy-run to the current function, or the current region (i.e. avoid cosmetic changes in untouched places of the file which mess up VC history)
      • Don't let .tdy and .ERR files mess up your source directories
      • Present the source before and after tidying in an ediff session (with a bit of fine print like re-using an existing ediff session, so that you can re-run the command from within the ediff session, e.g. after accepting some changes)

      ...And indeed, indenting can be a mess. But it is improving. That's what I get with "hot" cperl-mode.el and PBP settings. The closing braces are under the first nonspace character of the line containing the opening braces, which I find ok.

      Note the newline before the last semicolon. This indicates that this semicolon is a new statement (or superfluous)!

      for my $x (@x) { my %h = ( 'truncate' => { 'desc' => 'shorten a file', 'usage' => [ 'truncate FILEHANDLE,LENGTH', 'truncate EXPR,LENGTH', ] } ); } ;
        > The closing braces are under the first nonspace character of the line containing the opening braces, which I find ok.

        yep that's what I wanted, thanks. :)

        > Note the newline before the last semicolon. This indicates that this semicolon is a new statement (or superfluous)!

        yes it's superfluous, I added it while experimenting to find the problem...

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

        I'm sure you know this already, but just in case

        > Be able to restrict the perltidy-run to the current function,

        M-x mark-defun aka C-M-h selects the current function.

        > or the current region (i.e. avoid cosmetic changes in untouched places of the file which mess up VC history)

        That's what M-x shell-command-on-region does, if you don't mark-whole-buffer

        IOW the right combination of these three commands do the job.

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