File: perl-mode.el.html

To enter perl-mode automatically, 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 \#.

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 <pattern> 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 // (thats 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$//;

Defined variables (22)

perl--format-regexpRegexp to match the start of a format declaration.
perl-brace-imaginary-offsetImagined indentation of an open brace that actually follows a statement.
perl-brace-offsetExtra indentation for braces, compared with other text in same context.
perl-continued-brace-offsetExtra indent for substatements that start with open-braces.
perl-continued-statement-offsetExtra indent for lines not starting new statements.
perl-empty-syntax-tableSyntax table used internally for processing quote-like operators.
perl-flymake-commandExternal tool used to check Perl source code.
perl-font-lock-keywordsDefault expressions to highlight in Perl mode.
perl-font-lock-keywords-1Subdued level highlighting for Perl mode.
perl-font-lock-keywords-2Gaudy level highlighting for Perl mode.
perl-imenu-generic-expressionImenu generic expression for Perl mode. See ‘imenu-generic-expression’.
perl-indent-continued-argumentsIf non-nil offset of argument lines relative to usual indentation.
perl-indent-levelIndentation of Perl statements with respect to containing block.
perl-indent-parens-as-blockNon-nil means that non-block ()-, {}- and []-groups are indented as blocks.
perl-label-offsetOffset of Perl label lines relative to usual indentation.
perl-mode-abbrev-tableAbbrev table in use in perl-mode buffers.
perl-mode-hookNormal hook to run when entering Perl mode.
perl-mode-mapKeymap used in Perl mode.
perl-mode-syntax-tableSyntax table in use in ‘perl-mode’ buffers.
perl-nochangeLines starting with this regular expression are not auto-indented.
perl-tab-always-indentNon-nil means TAB in Perl mode always indents the current line.
perl-tab-to-commentNon-nil means TAB moves to eol or makes a comment in some cases.

Defined functions (23)

indent-perl-exp()
mark-perl-function()
perl--end-of-format-p()
perl-backward-to-noncomment()
perl-beginning-of-function(&optional ARG)
perl-calculate-indent()
perl-continuation-line-p()
perl-current-defun-name()
perl-electric-noindent-p(CHAR)
perl-electric-terminator(ARG)
perl-end-of-function(&optional ARG)
perl-flymake(REPORT-FN &rest ARGS)
perl-font-lock-syntactic-face-function(STATE)
perl-hanging-paren-p()
perl-indent-command(&optional ARG)
perl-indent-exp()
perl-indent-line(&optional NOCHANGE)
perl-indent-new-calculate(&optional VIRTUAL DEFAULT)
perl-mark-function()
perl-mode()
perl-quote-syntax-table(CHAR)
perl-syntax-propertize-function(START END)
perl-syntax-propertize-special-constructs(LIMIT)

Defined faces (2)

perl-heredocThe face for here-documents. Inherits from ‘font-lock-string-face’.
perl-non-scalar-variableFace used for non-scalar variables.