Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Breathing life into the (Emacs) cperl-mode

by haj (Deacon)
on Jul 02, 2020 at 15:29 UTC ( #11118826=perlmeditation: print w/replies, xml ) Need Help??

This also appeared on

If you are an Emacs user, you might know or even use cperl-mode. I am using it, more or less since my first days with Perl. Back then, newsgroups were a thing, and Ilya Zakharevich recommended it occasionally. In older times cperl-mode was shipped with Perl, today it is part of Emacs.

If you use cperl-mode, you might also have had a look at the code and noticed that it hasn't seen much love in the last decade or so. Perl, on the other hand, evolves. Version 5.32, for example, brings a new infix operator, and some future version might bring Cor. Wouldn't it be nice if cperl-mode understood these new keywords?

I'm on my way to get familiar with emacs-lisp, ERT, and other stuff to see what I can do. Ideas, contributions, comments, bug requests and criticism is welcome - There's a GitHub repository to get started.

  • Comment on Breathing life into the (Emacs) cperl-mode

Replies are listed 'Best First'.
Re: Breathing life into the (Emacs) cperl-mode
by LanX (Cardinal) on Jul 02, 2020 at 15:57 UTC
    Great project.

    But what's ERT?

    Some ideas:

    • last time I looked it had about 9000 lines, so my first approach works be to divide and conquer into smaller modules.
    • some Elisp code should be generated from Perl. (Lispers will kill me) For instance a large chunk is made of help docs dating back from Perl 4
    • Ilya always wanted to be backwards compatible with emacs 18 or 19 which didn't have a very fancy parsing tech. Consider dropping that Code.
    • you'll need a test suite, preferably written in Perl too.
    and... TL;dW ;)

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

      Thanks for the feedback! To wit: ERT is Emacs Lisp Regression Testing.
      • Dividing the existing source is surely an option, but isn't very high on my priority list. There's little benefit, and a division needs care for production and installation to fit into the Emacs package. Emacs makes navigation in a big file rather easy. New features, in particular optional stuff, might go into extra files.
      • Updating the docs is ... indeed interesting. There used to be a tool (written in Perl) to convert POD to texinfo, to read it directly in Emacs, but this seems to be no longer functional.
      • I've already dropped all the special cases for XEmacs, Emacs below version 26, font-lock-extra, choose-color.el, and cperl-mode's homegrown fontification for multiline strings. Did I miss something? Apropos: The selection of the minimum Emacs version is a somewhat unfortunate consequence from cperl-mode being bundled with Emacs. I haven't checked yet how much effort a backport to, say, Emacs 24 would be.
      • Yes, I need a test suite, and I've started writing tests for the bugs I fixed. However, I doubt that I'll write tests for the existing code unless I find bug reports. Though I would love to write a test suite in Perl (the Test:: infrastructure is lightyears ahead of ERT), ERT is mandated if you want to get stuff into Emacs. Also, it isn't that easy to query the fontification of a particular character in an Emacs buffer from Perl...

      With regard to integrating with Perl, a connection to modules like PPI or even Code::ART would be interesting. To quote THeDamian: How hard can that be? But then, I'm not Damian, he's doing his sourcery in Vimscript, so don't hold your breath.

        > it isn't that easy to query the fontification of a particular character in an Emacs buffer from Perl

        Just use htmlize and your favourite Perl HTML parser ;-)

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        • division: the final .el should be a single one, sure. I was thinking of a build and testing process triggered from a Perl script joining different parts. Testing with different emacs versions° is not easy and you'll find more contributors providing Perl tests.
        • docs: sorry, you misunderstood me, cperl has a long list of one liner description for each Perl command. IMHO these should be outsourced.
        • info: What you mean is the hypertext help system which relies on static perldocs in "info" format. Info is great for navigation of deep manuals, perldocs are rather flat and should be IMHO better displayed with "woman.el" (man doesn't work on windows).
        • if you drop support for older or other versions like XEmacs you should maybe consider renaming the fork of cperl-mode

        On a different note: elisp regexing is a PITA because of slasheritis and pretty unreadable. (Btw: XEmacs solved this with raw strings)

        I was thinking of translating Perl regex to lisp to open up for a broader audience.

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

        °) and Perl versions and extensions

Re: Breathing life into the (Emacs) cperl-mode
by bojinlund (Prior) on Jul 03, 2020 at 10:47 UTC

    Very good!

    I have in most of my Perl files:

    # (compile (concat "perltidy " (buffer-name)) nil) # (ediff-files (concat (buffer-name) ".tdy") (buffer-name))
    to make it easy to tidy up a file.

    A command in the modernized cperl-mode to run perltidy with the input from a emacs buffer hade been good!?

      So something like perltidy-mode?

      Or rather, run perltidy with input from a buffer which has not yet been saved, and write the output to another buffer? I guess that makes sense (probably also for perlcritic). Please open an issue at my Github Repo!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://11118826]
Approved by LanX
Front-paged by LanX
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2020-08-10 16:35 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (58 votes). Check out past polls.