perl-mode

Homepage: https://www.gnu.org/software/emacs

Author: William F. Mann

Summary

Perl code editing commands for GNU Emacs

Commentary

To enter perl-mode automatically, add (autoload 'perl-mode "perl-mode")
to your init file and change the first line of your perl script to:
#!/usr/bin/perl --	 # -*-Perl-*-
With arguments to perl:
#!/usr/bin/perl -P-	 # -*-Perl-*-
To handle files included with do 'filename.pl';, add something like
(setq auto-mode-alist (append (list (cons "\\.pl\\'" 'perl-mode))
                              auto-mode-alist))
to your init file; otherwise the .pl suffix defaults to prolog-mode.

This code is based on the 18.53 version c-mode.el, with extensive
rewriting.  Most of the features of c-mode survived intact.

I added a new feature which adds functionality to TAB; it is controlled
by the variable perl-tab-to-comment.  With it enabled, TAB does the
first thing it can from the following list:  change the indentation;
move past leading white space; delete an empty comment; reindent a
comment; move to end of line; create an empty comment; tell you that
the line ends in a quoted string, or has a # which should be a \#.

If your machine is slow, you may want to remove some of the bindings
to perl-electric-terminator.  I changed the indenting defaults to be
what Larry Wall uses in perl/lib, but left in all the options.

I also tuned a few things:  comments and labels starting in column
zero are left there by perl-indent-exp; perl-beginning-of-function
goes back to the first open brace/paren in column zero, the open brace
in 'sub ... {', or the equal sign in 'format ... ='; perl-indent-exp
(meta-^q) indents from the current line through the close of the next
brace/paren, so you don't need to start exactly at a brace or paren.

It may be good style to put a set of redundant braces around your
main program.  This will let you reindent it with meta-^q.

Known problems (these are all caused by limitations in the Emacs Lisp
parsing routine (parse-partial-sexp), which was not designed for such
a rich language; writing a more suitable parser would be a big job):
2)  The globbing syntax  is not recognized, so special
      characters in the pattern string must be backslashed.

Here are some ugly tricks to bypass some of these problems:  the perl
expression /`/ (that's a back-tick) usually evaluates harmlessly,
but will trick perl-mode into starting a quoted string, which
can be ended with another /`/.  Assuming you have no embedded
back-ticks, this can used to help solve problem 3:

    /`/; $ugly = q?"'$?; /`/;

The same trick can be used for problem 6 as in:
    /{/; while (<${glob_me}>)
but a simpler solution is to add a space between the $ and the {:
    while (<$ {glob_me}>)

Problem 7 is even worse, but this 'fix' does work :-(
    $DB'stop#'
        [$DB'line#'
         ] =~ s/;9$//;

Dependencies