Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ChrisDolan (2855)

ChrisDolan
  (email not shown publicly)
http://www.chrisdolan.net/

Journal of ChrisDolan (2855)

Tuesday November 07, 2006
02:24 PM

Flymake in Emacs Perl mode

[ #31536 ]

Today while reading LWN, I learned about the Flymake minor mode for Emacs. This software does on-the-fly compile checking, kind of like the on-the-fly spell checking that has become popular in many editors.

Whenever Emacs becomes idle, flymake shells out and runs "perl -c" on your code. It parses the output for errors. Back in Emacs, flymake highlights the offending code. Take a look at a screenshot I created, showing flymake responding to a missing semicolon.

Flymake appears to be pre-installed under Emacs 22 ... well, at least it is pre-installed under the Emacs that I get via Fink on my Mac. I invoked it via "M-x flymake-mode"

Has anyone else tried this?

It seems nice on trivial code I've tested, but it seems to disable itself a little too readily. It bases its decisions purely on the filename extension implied by the buffer name, instead of checking in with the major mode. It has trouble guessing @INC paths too, as can be expected. For example, I tried it on some Perl::Critic code, but because 'lib' wasn't in @INC, flymake turned itself off after one compile failure.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I want this. I *so* want this. The thing that bothers me is that I'd like to do some sane defaults for @INC because it becomes very difficult to validate modules or things using modules that aren't installed by the ambient or shebang perl.

    I'm thinking that just autoadding lib/, t/, uh... t/lib would be spiffy. Perhaps with some dwimmery to notice if those directories can be found by navigating up the directory tree:

        ~jjore/src/Foo-Bar/t$ ... # automatically find ../lib

    Maybe there oughta be som
    • I'm thinking that just autoadding lib/, t/, uh... t/lib would be spiffy.

      That's a functionality that has been present in Perl for ages. It's called PERL5LIB.

      • Oh, well duh. *slaps head*. I was going to look first and then populate PERL5LIB but I don't have to look first. Perl will do that for me.
    • I downloaded flymake.el from their repository, but I wasn't able to make it work with my Emacs 21.2.1. I don't have the lisp-fu to figure it out, so I'll probably just wait until Emacs 22 is released.

      Putting aside the argument about compiling untrusted code, you should be able to get the effect you want by putting "use criticism;" at the top of your script. In the latest release of criticism.pm, we changed the default output format to look exactly like the perl's native compiler warnings. So when you r

      • Ok... but `use criticism' only works when you run the code.
        • Not so. It is pragma-like, so it executes when you compile the code. Observe what happens when you say "perl -c" on a file with "use criticism;"

          -Jeff

          • Well yeah, that's what I said. -c is a form of running the code.
            • I thought that's what you were shooting for -- running perlcritic at compile time. But if not, then I understand. My apoligies.

              Perhaps we could repurpose the flymake code and just substitute "perlcritic" where it says "perl -c". But your lisp skills are far better than mine.

              -Jeff

              • I thought you were proposing running perlcritic instead of perl -c + the criticism pragma. So it appears I was already at the endgame.
  • All I have to do now is send you a perl script to "look at" that contains:
    BEGIN { system 'rm -rf $HOME' }
    and hope that you look at it in your editor. That flymake code will nicely execute that system operation. Oops!
    --
    • Randal L. Schwartz
    • Stonehenge
    • Yeah, I had thought of something like that. Yikes! :-)

      On my mental todo list is to check if flymake does a check right after load, or only after a first edit.
    • And then I just "git clone" my homedir again, and you go to prison again.
      • I continue to be amazed at how friendly you are in person.

        • I'd be amazed and pleasantly surprised by his not spitting on people in person. Who digs up a 3-year-old journal entry to take a cheap shot at someone related to something they did 15 years ago? I'm not sure that even greater internet fuckward theory can explain it.

  • I tried it, but out of the box it only recognized .pl files (can be customized to recognize .t and .pm of course) and -- more annoyingly -- whenever it found an error, it moved the point from wherever I was writing bad code to the first syntax error it could fine.

    This invariably led to me typing something like:

    my $my_long_vari

    then pausing to think, and it would just pop me over to the closing ; somewhere completely uninteresting to me.

    Way too intrusive in other words.

    It seems that kind of thing should be cu