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-regexp | Regexp to match the start of a format declaration. |
perl-brace-imaginary-offset | Imagined indentation of an open brace that actually follows a statement. |
perl-brace-offset | Extra indentation for braces, compared with other text in same context. |
perl-continued-brace-offset | Extra indent for substatements that start with open-braces. |
perl-continued-statement-offset | Extra indent for lines not starting new statements. |
perl-empty-syntax-table | Syntax table used internally for processing quote-like operators. |
perl-flymake-command | External tool used to check Perl source code. |
perl-font-lock-keywords | Default expressions to highlight in Perl mode. |
perl-font-lock-keywords-1 | Subdued level highlighting for Perl mode. |
perl-font-lock-keywords-2 | Gaudy level highlighting for Perl mode. |
perl-imenu-generic-expression | Imenu generic expression for Perl mode. See ‘imenu-generic-expression’. |
perl-indent-continued-arguments | If non-nil offset of argument lines relative to usual indentation. |
perl-indent-level | Indentation of Perl statements with respect to containing block. |
perl-indent-parens-as-block | Non-nil means that non-block ()-, {}- and []-groups are indented as blocks. |
perl-label-offset | Offset of Perl label lines relative to usual indentation. |
perl-mode-abbrev-table | Abbrev table in use in ‘perl-mode’ buffers. |
perl-mode-hook | Normal hook to run when entering Perl mode. |
perl-mode-map | Keymap used in Perl mode. |
perl-mode-syntax-table | Syntax table in use in ‘perl-mode’ buffers. |
perl-nochange | Lines starting with this regular expression are not auto-indented. |
perl-tab-always-indent | Non-nil means TAB in Perl mode always indents the current line. |
perl-tab-to-comment | Non-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-heredoc | The face for here-documents. Inherits from ‘font-lock-string-face’. |
perl-non-scalar-variable | Face used for non-scalar variables. |