Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Formatting Perl code with Emacs

by karlgoethebier (Abbot)
on Nov 06, 2013 at 15:12 UTC ( [id://1061440]=note: print w/replies, xml ) Need Help??


in reply to Formatting Perl code with Emacs

Perhaps using perltidy is an alternative it does'n - results don't look bad:

sub _get_options { Getopt::Long::Configure('gnu_getopt'); return Getopt::Long::GetOptions( \%Options, qw( version|V debug ) ); }

And perhaps you can configure perltidy to get exactly the result you want :-)

Nice command to invoke perltidy from within emacs:

Type C-x h and then M-1 M-| to run the shell command (perltidy) on the marked region.

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^2: Formatting Perl code with Emacs
by karlgoethebier (Abbot) on Nov 07, 2013 at 09:30 UTC
    "If you have to run shell command from the text editor to format your code, why don't you run another one to save the file?.."

    Perhaps a misunderstanding? But it is quite simple:

    • Mark the region that you want to format
    • Apply the described command (Shell command on region: perltidy)
    • Save your stuff

    Alternatively you can run perltidy from the commandline. Then you must rename the resulting formatted file and reload the buffer (M-x revert-buffer).

    IMHO applying the shell command (perltidy) on a region respectively running perltidy from within emacs is convinient - and the results look good.

    Update:

    The macro and the binding to F11:

    (fset 'perltidy "\C-xh\C-[1\C-[|perltidy\C-m") (global-set-key [f11] 'perltidy)

    Run it with F11 or M-x perltidy

    Update2:

    OK, on a Mac F11 isn't a good idea :-(

    (global-set-key [f5] 'perltidy)

    Best regards, Karl

    P.S.: BTW, i think, many stuff posted on PM is formatted with perltidy, from within emacs or vim. See also

    «The Crux of the Biscuit is the Apostrophe»

      It's not that complicated, you can easily bind the whole process to a key!

      Either define and save a macro or search for ready-to-use elisp snippets. There are plenty...

      Cheers Rolf

      ( addicted to the Perl Programming Language)

      Thanks. Perltidy is quite good, but I don't use it in my coding practice, because I prefer to format my code manually with the editor commands at the same time as I type it. TMTOWTDI.

Re^2: Formatting Perl code with Emacs
by isntvoid (Novice) on Nov 07, 2013 at 08:32 UTC

    Thank you, but this way is too complicated for me. If you have to run shell command from the text editor to format your code, why don't you run another one to save the file?..

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-20 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found