Using emacs as a perl IDE

I admit, I’m an emacs philistine. I use it as a text editor and when I’ve got a machine or linux VM that I’m going to be using, I’ll set up “cperl-mode” with syntax colouring. I don’t even bother even creating a tags file to be able to bounce around files from the use of a function.method to its definition.

At an interview yesterday, I mentioned this and asked If my interviewers had ever used eclipse for development and their snorts said it all. So, this girded my loins to look at setting up a more productive emacs environment. So, a quick google gives us:

For a top hit in Google, that’s a bit rubbish.

  • suggests than an IDE should fulfil:
    • Source code editor – OK, we have this, with shiny cperl mode. But I’m not entirely sure I’m making the most of the go-faster striped there. I shall dig more later.
    • Compiler – I tend to get M-x compile to run my tests for me.
    • Debugging – I cant’t remember the last time I used the perl debugger.
    • Documentation Lookup – see below!
    • Version Control – see below!
    • OO features like class lookup and object inspector – is this just ETAGS?

Cperl’s documentation is here: Suggestions that jump out at me from this are:

Using perltidy:

“For the emacs editor, first mark a region and then pipe it through perltidy. For example, to format an entire file, select it with C-x h and then pipe it with M-1 M-| and then perltidy. The numeric argument, M-1 causes the output from perltidy to replace the marked text. See “GNU Emacs Manual for more information,

Yuk. That’s clunky.

You can access perldoc from within emacs:

In order to use perldoc from Emacs, type ‘M-x cperl-perldoc’, hit Return and type the keyword to look up.

Not sure what that gains. I usually run perldoc in an xterm!

The comments on this go on to suggest:

  • vc.el – I had no luck in the early days getting svn integrated. I should probably take another look. This also attempts to gather together info on version control in emacs: psvn looks powerful and might well have saved me time.
  • – the emacs code browser for zapping round file trees. Again, I just tend to end up having the modules I care about loaded and just switching between them in Dired. Maybe on a huge project with libraries?

Ah, perlnow looks interesting:

  • Templates for starting off modules
  • Syntax checking with going to errors
  • Test script templates

I know Piers Cawley has done work on refactoctoring code with emacs, but I can’t find recent references to his work.

Finally, a big shout out to Aquamacs on the Mac. I find this to blend well with the Mac environment. GNU emacs on Linux. Don’t even think about Xemacs.

Still not entirely sure there’s anything in here I’ll make use of! Got any suggestions?

[Bloglines] [] [Digg] [Facebook] [Google] [Reddit] [Windows Live] [Yahoo!] [Email]

Related Posts:

7 Responses to “Using emacs as a perl IDE”

  1. Dave Cross says:

    I haven’t used it myself (I keep meaning to) but I’m told that PerlySense ( is the dog’s.

    Personally, I’m becoming vey happy with Padre as my Perl editor of choice.

  2. Sam Graham says:

    I’ve integrated Perl::Critic into Emacs to give continuous static analysis using Flymake mode, you can find the code here:

    Along with a fork of Flykmake itself at:

    Hope you find those helpful…

  3. cms says:

    Nobody can ever explain to me what ‘Aquamacs’ or any of the other ‘mac-enhanced’ emacs distributions do that GNU emacs does not do ?

    Semantic / CEDET is where all the ‘IDE’ work is going in emacs 24. Perl is noticably missing from the list of things they can parse. I don’t know if anyone is working on it.

    To my way of thinking, expecting emacs to be an anything out-of-the-box is missing the point. You’re supposed to gently bend it into the shape of the tool you want to use.

    Probably the most useful feature of emacs for me when developing across a range of languages / remote machines using a laptop is tramp-mode, which lets me conveniently edit things in-place on foreign systems, using my local emacs installation, so long as I have ssh authentication. I use macros *a lot* to automate edits. I often use emacs to munge and transform text output from other things.

    Usually I build and installed via macports, although I sometimes grab a nightly from and run with it for a while if there’s anything new I’m exploring.

  4. [...] emacs as a perl IDE Posted on January 27, 2012 by briang 2012-01-25 by Dave Hodgkinson Related Posts:The 10 rules of the pragmatic programmerEmacs Reference Sheetemacs voting systemNotes [...]

  5. Fahad says:

    Regards perltidy, have a look at the comment:

    Is there a way to get it to work consistently with


  6. Reini Urban says:

    Aquamacs uses more Mac-consistent keys. So if you are not switching OS, Aquamacs is better, and also looks better.
    I just needed these key tricks on my german macbook:

    some more tricks:

    perltidy or HTML tidy:
    ; Function to run Tidy HTML parser on region
    ; NOTE: this requires external Tidy program
    (setq shell-command-default-error-buffer “tidy-errors”) ; define an error buffer
    (global-set-key “\C-xt” ‘tidy-region)
    ;(define-key ctl-x-map “it” ‘tidy-region)
    (defun tidy-region ()
    “Run Tidy HTML parser on current region.”
    (let ((start (mark))
    (end (point))
    (command “tidy”))
    (shell-command-on-region start end t t command shell-command-default-error-buffer)))

    (defun perltidy ()
    “execute perltidy for the selected region or the current buffer”
    (unless (mark-active)
    (shell-command-on-region (point) (mark) “perltidy -q” nil t)
    (message “Tidied”)
    (goto-line orig-line))

    (defun cperl-hooks ()
    (local-set-key “\C-ct” ‘perltidy)
    ;(local-set-key “\C-ct” ‘increment-test-counter)
    (setq indent-tabs-mode nil)
    (add-hook ‘cperl-mode-hook ‘cperl-hooks)
    (defun hook-notabs () (setq indent-tabs-mode nil))
    (add-hook ‘change-log-mode-hook ‘hook-notabs)
    (add-hook ‘c-mode-hook ‘hook-notabs)

  7. davehodg says:

    Reini, thanks for those lines, I should really use them.

    In other news, I can’t use the # key!

    This is an up-to-date Mavericks and Aquamacs:

    Aquamacs 3.0a GNU Emacs (x86_64-apple-darwin13.0.0, NS apple-appkit-1265.00) of 2014-01-21 (Aquamacs-3.0a) on watson

Leave a Reply