Fetching contributors…
Cannot retrieve contributors at this time
8965 lines (8476 sloc) 322 KB
;;; cperl-mode.el --- Perl code editing commands for Emacs
;; Copyright (C) 1985, 1986, 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
;; 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
;; Free Software Foundation, Inc.
;; Author: Ilya Zakharevich
;; Bob Olson
;; Maintainer: Jonathan Rockway <>
;; Keywords: languages, Perl
;; This particular file is not actually part of GNU Emacs.
;; It is from
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <>.
;;; Corrections made by Ilya Zakharevich
;;; Commentary:
;; This version of the file contains support for the syntax added by
;; the MooseX::Declare CPAN module, as well as Perl 5.10 keyword
;; support.
;; The latest version is available from
;; (perhaps in the moosex-declare branch)
;; You can either fine-tune the bells and whistles of this mode or
;; bulk enable them by putting
;; (setq cperl-hairy t)
;; in your .emacs file. (Emacs rulers do not consider it politically
;; correct to make whistles enabled by default.)
;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
;; `cperl-praise', `cperl-speed'. <<<<<<
;; The mode information (on C-h m) provides some customization help.
;; If you use font-lock feature of this mode, it is advisable to use
;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
;; Faces used now: three faces for first-class and second-class keywords
;; and control flow words, one for each: comments, string, labels,
;; functions definitions and packages, arrays, hashes, and variable
;; definitions. If you do not see all these faces, your font-lock does
;; not define them, so you need to define them manually.
;; This mode supports font-lock, imenu and mode-compile. In the
;; hairy version font-lock is on, but you should activate imenu
;; yourself (note that mode-compile is not standard yet). Well, you
;; can use imenu from keyboard anyway (M-x imenu), but it is better
;; to bind it like that:
;; (define-key global-map [M-S-down-mouse-3] 'imenu)
;;; Font lock bugs as of v4.32:
;; The following kinds of Perl code erroneously start strings:
;; \$` \$' \$"
;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
;; likewise with m, tr, y, q, qX instead of s
;;; Code:
(defvar vc-rcs-header)
(defvar vc-sccs-header)
(condition-case nil
(require 'custom)
(error nil))
(condition-case nil
(require 'man)
(error nil))
(defvar cperl-can-font-lock
(or (featurep 'xemacs)
(and (boundp 'emacs-major-version)
(or window-system
(> emacs-major-version 20)))))
(if cperl-can-font-lock
(require 'font-lock))
(defvar msb-menu-cond)
(defvar gud-perldb-history)
(defvar font-lock-background-mode) ; not in Emacs
(defvar font-lock-display-type) ; ditto
(defvar paren-backwards-message) ; Not in newer XEmacs?
(or (fboundp 'defgroup)
(defmacro defgroup (name val doc &rest arr)
(or (fboundp 'custom-declare-variable)
(defmacro defcustom (name val doc &rest arr)
`(defvar ,name ,val ,doc)))
(or (and (fboundp 'custom-declare-variable)
(string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
(defmacro defface (&rest arr)
;; Avoid warning (tmp definitions)
(or (fboundp 'x-color-defined-p)
(defmacro x-color-defined-p (col)
(cond ((fboundp 'color-defined-p) `(color-defined-p ,col))
;; XEmacs >= 19.12
((fboundp 'valid-color-name-p) `(valid-color-name-p ,col))
;; XEmacs 19.11
((fboundp 'x-valid-color-name-p) `(x-valid-color-name-p ,col))
(t '(error "Cannot implement color-defined-p")))))
(defmacro cperl-is-face (arg) ; Takes quoted arg
(cond ((fboundp 'find-face)
`(find-face ,arg))
(;;(and (fboundp 'face-list)
;; (face-list))
(fboundp 'face-list)
`(member ,arg (and (fboundp 'face-list)
`(boundp ,arg))))
(defmacro cperl-make-face (arg descr) ; Takes unquoted arg
(cond ((fboundp 'make-face)
`(make-face (quote ,arg)))
`(defvar ,arg (quote ,arg) ,descr))))
(defmacro cperl-force-face (arg descr) ; Takes unquoted arg
(or (cperl-is-face (quote ,arg))
(cperl-make-face ,arg ,descr))
(or (boundp (quote ,arg)) ; We use unquoted variants too
(defvar ,arg (quote ,arg) ,descr))))
(if (featurep 'xemacs)
(defmacro cperl-etags-snarf-tag (file line)
(beginning-of-line 2)
(list ,file ,line)))
(defmacro cperl-etags-snarf-tag (file line)
(if (featurep 'xemacs)
(defmacro cperl-etags-goto-tag-location (elt)
;; (switch-to-buffer (get-file-buffer (elt ,elt 0)))
;; (set-buffer (get-file-buffer (elt ,elt 0)))
;; Probably will not work due to some save-excursion???
;; Or save-file-position?
;; (message "Did I get to line %s?" (elt ,elt 1))
`(goto-line (string-to-int (elt ,elt 1))))
(defmacro cperl-etags-goto-tag-location (elt)
`(etags-goto-tag-location ,elt))))
(defvar cperl-can-font-lock
(or (featurep 'xemacs)
(and (boundp 'emacs-major-version)
(or window-system
(> emacs-major-version 20)))))
(defun cperl-choose-color (&rest list)
(let (answer)
(while list
(or answer
(if (or (x-color-defined-p (car list))
(null (cdr list)))
(setq answer (car list))))
(setq list (cdr list)))
(defgroup cperl nil
"Major mode for editing Perl code."
:prefix "cperl-"
:group 'languages
:version "20.3")
(defgroup cperl-indentation-details nil
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-affected-by-hairy nil
"Variables affected by `cperl-hairy'."
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-autoinsert-details nil
"Auto-insert tuneup."
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-faces nil
"Fontification colors."
:link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-speed nil
"Speed vs. validity tuneup."
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-help-system nil
"Help system tuneup."
:prefix "cperl-"
:group 'cperl)
(defcustom cperl-extra-newline-before-brace nil
"*Non-nil means that if, elsif, while, until, else, for, foreach
and do constructs look like:
if ()
instead of:
if () {
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-extra-newline-before-brace-multiline
"*Non-nil means the same as `cperl-extra-newline-before-brace', but
for constructs with multiline if/unless/while/until/for/foreach condition."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-indent-level 2
"*Indentation of CPerl statements with respect to containing block."
:type 'integer
:group 'cperl-indentation-details)
;; Is is not unusual to put both things like perl-indent-level and
;; cperl-indent-level in the local variable section of a file. If only
;; one of perl-mode and cperl-mode is in use, a warning will be issued
;; about the variable. Autoload these here, so that no warning is
;; issued when using either perl-mode or cperl-mode.
;;;###autoload(put 'cperl-indent-level 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-brace-offset 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-continued-brace-offset 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-label-offset 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-continued-statement-offset 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-extra-newline-before-brace 'safe-local-variable 'booleanp)
;;;###autoload(put 'cperl-merge-trailing-else 'safe-local-variable 'booleanp)
(defcustom cperl-lineup-step nil
"*`cperl-lineup' will always lineup at multiple of this number.
If nil, the value of `cperl-indent-level' will be used."
:type '(choice (const nil) integer)
:group 'cperl-indentation-details)
(defcustom cperl-brace-imaginary-offset 0
"*Imagined indentation of a Perl open brace that actually follows a statement.
An open brace following other text is treated as if it were this far
to the right of the start of its line."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-brace-offset 0
"*Extra indentation for braces, compared with other text in same context."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-label-offset -2
"*Offset of CPerl label lines relative to usual indentation."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-min-label-indent 1
"*Minimal offset of CPerl label lines."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-continued-statement-offset 2
"*Extra indent for lines not starting new statements."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-continued-brace-offset 0
"*Extra indent for substatements that start with open-braces.
This is in addition to cperl-continued-statement-offset."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-close-paren-offset -1
"*Extra indent for substatements that start with close-parenthesis."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-indent-wrt-brace t
"*Non-nil means indent statements in if/etc block relative brace, not if/etc.
Versions 5.2 ... 5.20 behaved as if this were `nil'."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-indent-subs-specially t
"*Non-nil means indent subs that are inside other blocks (hash values, for example) relative to the beginning of the \"sub\" keyword, rather than relative to the statement that contains the declaration."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-auto-newline nil
"*Non-nil means automatically newline before and after braces,
and after colons and semicolons, inserted in CPerl code. The following
\\[cperl-electric-backspace] will remove the inserted whitespace.
Insertion after colons requires both this variable and
`cperl-auto-newline-after-colon' set."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-autoindent-on-semi nil
"*Non-nil means automatically indent after insertion of (semi)colon.
Active if `cperl-auto-newline' is false."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-auto-newline-after-colon nil
"*Non-nil means automatically newline even after colons.
Subject to `cperl-auto-newline' setting."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-tab-always-indent t
"*Non-nil means TAB in CPerl mode should always reindent the current line,
regardless of where in the line point is when the TAB command is used."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-font-lock nil
"*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-lbrace-space nil
"*Non-nil (and non-null) means { after $ should be preceded by ` '.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-parens-string "({[]})<"
"*String of parentheses that should be electric in CPerl.
Closing ones are electric only if the region is highlighted."
:type 'string
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-parens nil
"*Non-nil (and non-null) means parentheses should be electric in CPerl.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defvar zmacs-regions) ; Avoid warning
(defcustom cperl-electric-parens-mark
(and window-system
(or (and (boundp 'transient-mark-mode) ; For Emacs
(and (boundp 'zmacs-regions) ; For XEmacs
"*Not-nil means that electric parens look for active mark.
Default is yes if there is visual feedback on mark."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-electric-linefeed nil
"*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
In any case these two mean plain and hairy linefeeds together.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-keywords nil
"*Not-nil (and non-null) means keywords are electric in CPerl.
Can be overwritten by `cperl-hairy' if nil.
Uses `abbrev-mode' to do the expansion. If you want to use your
own abbrevs in cperl-mode, but do not want keywords to be
electric, you must redefine `cperl-mode-abbrev-table': do
\\[edit-abbrevs], search for `cperl-mode-abbrev-table', and, in
that paragraph, delete the words that appear at the ends of lines and
that begin with \"cperl-electric\".
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-backspace-untabify t
"*Not-nil means electric-backspace will untabify in CPerl."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-hairy nil
"*Not-nil means most of the bells and whistles are enabled in CPerl.
Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
`cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
`cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
:type 'boolean
:group 'cperl-affected-by-hairy)
(defcustom cperl-comment-column 32
"*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-indent-comment-at-column-0 nil
"*Non-nil means that comment started at column 0 should be indentable."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
"*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
:type '(repeat string)
:group 'cperl)
(defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
"*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
:type '(repeat string)
:group 'cperl)
;; This became obsolete...
(defvar cperl-vc-header-alist nil)
"use cperl-vc-rcs-header or cperl-vc-sccs-header instead.")
(defcustom cperl-clobber-mode-lists
(boundp 'interpreter-mode-alist)
(assoc "miniperl" interpreter-mode-alist)
(assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
"*Whether to install us into `interpreter-' and `extension' mode lists."
:type 'boolean
:group 'cperl)
(defcustom cperl-info-on-command-no-prompt nil
"*Not-nil (and non-null) means not to prompt on C-h f.
The opposite behavior is always available if prefixed with C-c.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-clobber-lisp-bindings nil
"*Not-nil (and non-null) means not overwrite C-h f.
The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-lazy-help-time nil
"*Not-nil (and non-null) means to show lazy help after given idle time.
Can be overwritten by `cperl-hairy' to be 5 sec if nil."
:type '(choice (const null) (const nil) integer)
:group 'cperl-affected-by-hairy)
(defcustom cperl-pod-face 'font-lock-comment-face
"*Face for POD highlighting."
:type 'face
:group 'cperl-faces)
(defcustom cperl-pod-head-face 'font-lock-variable-name-face
"*Face for POD highlighting.
Font for POD headers."
:type 'face
:group 'cperl-faces)
(defcustom cperl-here-face 'font-lock-string-face
"*Face for here-docs highlighting."
:type 'face
:group 'cperl-faces)
;;; Some double-evaluation happened with font-locks... Needed with 21.2...
(defvar cperl-singly-quote-face (featurep 'xemacs))
(defcustom cperl-invalid-face 'underline
"*Face for highlighting trailing whitespace."
:type 'face
:version "21.1"
:group 'cperl-faces)
(defcustom cperl-pod-here-fontify '(featurep 'font-lock)
"*Not-nil after evaluation means to highlight POD and here-docs sections."
:type 'boolean
:group 'cperl-faces)
(defcustom cperl-fontify-m-as-s t
"*Not-nil means highlight 1arg regular expressions operators same as 2arg."
:type 'boolean
:group 'cperl-faces)
(defcustom cperl-highlight-variables-indiscriminately nil
"*Non-nil means perform additional highlighting on variables.
Currently only changes how scalar variables are highlighted.
Note that that variable is only read at initialization time for
the variable `cperl-font-lock-keywords-2', so changing it after you've
entered CPerl mode the first time will have no effect."
:type 'boolean
:group 'cperl)
(defcustom cperl-pod-here-scan t
"*Not-nil means look for POD and here-docs sections during startup.
You can always make lookup from menu or using \\[cperl-find-pods-heres]."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-regexp-scan t
"*Not-nil means make marking of regular expression more thorough.
Effective only with `cperl-pod-here-scan'."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-hook-after-change t
"*Not-nil means install hook to know which regions of buffer are changed.
May significantly speed up delayed fontification. Changes take effect
after reload."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-imenu-addback nil
"*Not-nil means add backreferences to generated `imenu's.
May require patched `imenu' and `imenu-go'. Obsolete."
:type 'boolean
:group 'cperl-help-system)
(defcustom cperl-max-help-size 66
"*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
:type '(choice integer (const nil))
:group 'cperl-help-system)
(defcustom cperl-shrink-wrap-info-frame t
"*Non-nil means shrink-wrapping of info-buffer-frame allowed."
:type 'boolean
:group 'cperl-help-system)
(defcustom cperl-info-page "perl"
"*Name of the info page containing perl docs.
Older version of this page was called `perl5', newer `perl'."
:type 'string
:group 'cperl-help-system)
(defcustom cperl-use-syntax-table-text-property
(boundp 'parse-sexp-lookup-properties)
"*Non-nil means CPerl sets up and uses `syntax-table' text property."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-use-syntax-table-text-property-for-tags
"*Non-nil means: set up and use `syntax-table' text property generating TAGS."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
"*Regexp to match files to scan when generating TAGS."
:type 'regexp
:group 'cperl)
(defcustom cperl-noscan-files-regexp
"*Regexp to match files/dirs to skip when generating TAGS."
:type 'regexp
:group 'cperl)
(defcustom cperl-regexp-indent-step nil
"*Indentation used when beautifying regexps.
If nil, the value of `cperl-indent-level' will be used."
:type '(choice integer (const nil))
:group 'cperl-indentation-details)
(defcustom cperl-indent-left-aligned-comments t
"*Non-nil means that the comment starting in leftmost column should indent."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-under-as-char nil
"*Non-nil means that the _ (underline) should be treated as word char."
:type 'boolean
:group 'cperl)
(defcustom cperl-extra-perl-args ""
"*Extra arguments to use when starting Perl.
Currently used with `cperl-check-syntax' only."
:type 'string
:group 'cperl)
(defcustom cperl-message-electric-keyword t
"*Non-nil means that the `cperl-electric-keyword' prints a help message."
:type 'boolean
:group 'cperl-help-system)
(defcustom cperl-indent-region-fix-constructs 1
"*Amount of space to insert between `}' and `else' or `elsif'
in `cperl-indent-region'. Set to nil to leave as is. Values other
than 1 and nil will probably not work."
:type '(choice (const nil) (const 1))
:group 'cperl-indentation-details)
(defcustom cperl-break-one-line-blocks-when-indent t
"*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
need to be reformatted into multiline ones when indenting a region."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-fix-hanging-brace-when-indent t
"*Non-nil means that BLOCK-end `}' may be put on a separate line
when indenting a region.
Braces followed by else/elsif/while/until are excepted."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-merge-trailing-else t
"*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
may be merged to be on the same line when indenting a region."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-indent-parens-as-block nil
"*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
but for trailing \",\" inside the group, which won't increase indentation.
One should tune up `cperl-close-paren-offset' as well."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-syntaxify-by-font-lock
(and cperl-can-font-lock
(boundp 'parse-sexp-lookup-properties))
"*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
:type '(choice (const message) boolean)
:group 'cperl-speed)
(defcustom cperl-syntaxify-unwind
"*Non-nil means that CPerl unwinds to a start of a long construction
when syntaxifying a chunk of buffer."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-syntaxify-for-menu
"*Non-nil means that CPerl syntaxifies up to the point before showing menu.
This way enabling/disabling of menu items is more correct."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-ps-print-face-properties
'((font-lock-keyword-face nil nil bold shadow)
(font-lock-variable-name-face nil nil bold)
(font-lock-function-name-face nil nil bold italic box)
(font-lock-constant-face nil "LightGray" bold)
(cperl-array-face nil "LightGray" bold underline)
(cperl-hash-face nil "LightGray" bold italic underline)
(font-lock-comment-face nil "LightGray" italic)
(font-lock-string-face nil nil italic underline)
(cperl-nonoverridable-face nil nil italic underline)
(font-lock-type-face nil nil underline)
(font-lock-warning-face nil "LightGray" bold italic box)
(underline nil "LightGray" strikeout))
"List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
:type '(repeat (cons symbol
(cons (choice (const nil) string)
(cons (choice (const nil) string)
(repeat symbol)))))
:group 'cperl-faces)
(defvar cperl-dark-background
(cperl-choose-color "navy" "os2blue" "darkgreen"))
(defvar cperl-dark-foreground
(cperl-choose-color "orchid1" "orange"))
(defface cperl-nonoverridable-face
`((((class grayscale) (background light))
(:background "Gray90" :slant italic :underline t))
(((class grayscale) (background dark))
(:foreground "Gray80" :slant italic :underline t :weight bold))
(((class color) (background light))
(:foreground "chartreuse3"))
(((class color) (background dark))
(:foreground ,cperl-dark-foreground))
(t (:weight bold :underline t)))
"Font Lock mode face used non-overridable keywords and modifiers of regexps."
:group 'cperl-faces)
(defface cperl-array-face
`((((class grayscale) (background light))
(:background "Gray90" :weight bold))
(((class grayscale) (background dark))
(:foreground "Gray80" :weight bold))
(((class color) (background light))
(:foreground "Blue" :background "lightyellow2" :weight bold))
(((class color) (background dark))
(:foreground "yellow" :background ,cperl-dark-background :weight bold))
(t (:weight bold)))
"Font Lock mode face used to highlight array names."
:group 'cperl-faces)
(defface cperl-hash-face
`((((class grayscale) (background light))
(:background "Gray90" :weight bold :slant italic))
(((class grayscale) (background dark))
(:foreground "Gray80" :weight bold :slant italic))
(((class color) (background light))
(:foreground "Red" :background "lightyellow2" :weight bold :slant italic))
(((class color) (background dark))
(:foreground "Red" :background ,cperl-dark-background :weight bold :slant italic))
(t (:weight bold :slant italic)))
"Font Lock mode face used to highlight hash names."
:group 'cperl-faces)
;;; Short extra-docs.
(defvar cperl-tips 'please-ignore-this-line
"Get maybe newer version of this package from
Subdirectory `cperl-mode' may contain yet newer development releases and/or
patches to related files.
For best results apply to an older Emacs the patches from
\(this upgrades syntax-parsing abilities of Emacsen v19.34 and
v20.2 up to the level of Emacs v20.3 - a must for a good Perl
mode.) As of beginning of 2003, XEmacs may provide a similar ability.
Get support packages choose-color.el (or font-lock-extra.el before
19.30), imenu-go.el from the same place. \(Look for other files there
too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
later you should use choose-color.el *instead* of font-lock-extra.el
\(and you will not get smart highlighting in C :-().
Note that to enable Compile choices in the menu you need to install
If your Emacs does not default to `cperl-mode' on Perl files, and you
want it to: put the following into your .emacs file:
(defalias 'perl-mode 'cperl-mode)
Get perl5-info from
Also, one can generate a newer documentation running `pod2texi' converter
If you use imenu-go, run imenu on perl5-info buffer (you can do it
from Perl menu). If many files are related, generate TAGS files from
Tools/Tags submenu in Perl menu.
If some class structure is too complicated, use Tools/Hierarchy-view
from Perl menu, or hierarchic view of imenu. The second one uses the
current buffer only, the first one requires generation of TAGS from
Perl/Tools/Tags menu beforehand.
Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
Switch auto-help on/off with Perl/Tools/Auto-help.
Though with contemporary Emaxen CPerl mode should maintain the correct
parsing of Perl even when editing, sometimes it may be lost. Fix this by
In cases of more severe confusion sometimes it is helpful to do
\\[load-library] cperl-mode RET
Before reporting (non-)problems look in the problem section of online
micro-docs on what I know about CPerl problems.")
(defvar cperl-problems 'please-ignore-this-line
"Description of problems in CPerl mode.
Some faces will not be shown on some versions of Emacs unless you
install choose-color.el, available from
`fill-paragraph' on a comment may leave the point behind the
paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
to detect it and bulk out).
See documentation of a variable `cperl-problems-old-emaxen' for the
problems which disappear if you upgrade Emacs to a reasonably new
version (20.3 for Emacs, and those of 2004 for XEmacs).")
(defvar cperl-problems-old-emaxen 'please-ignore-this-line
"Description of problems in CPerl mode specific for older Emacs versions.
Emacs had a _very_ restricted syntax parsing engine until version
20.1. Most problems below are corrected starting from this version of
Emacs, and all of them should be fixed in version 20.3. (Or apply
patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
this respect (until 2003).
Note that even with newer Emacsen in some very rare cases the details
of interaction of `font-lock' and syntaxification may be not cleaned
up yet. You may get slightly different colors basing on the order of
fontification and syntaxification. Say, the initial faces is correct,
but editing the buffer breaks this.
Even with older Emacsen CPerl mode tries to corrects some Emacs
misunderstandings, however, for efficiency reasons the degree of
correction is different for different operations. The partially
corrected problems are: POD sections, here-documents, regexps. The
operations are: highlighting, indentation, electric keywords, electric
This may be confusing, since the regexp s#//#/#\; may be highlighted
as a comment, but it will be recognized as a regexp by the indentation
code. Or the opposite case, when a POD section is highlighted, but
may break the indentation of the following code (though indentation
should work if the balance of delimiters is not broken by POD).
The main trick (to make $ a \"backslash\") makes constructions like
${aaa} look like unbalanced braces. The only trick I can think of is
to insert it as $ {aaa} (valid in perl5, not in perl4).
Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
as /($|\\s)/. Note that such a transposition is not always possible.
The solution is to upgrade your Emacs or patch an older one. Note
that Emacs 20.2 has some bugs related to `syntax-table' text
properties. Patches are available on the main CPerl download site,
and on CPAN.
If these bugs cannot be fixed on your machine (say, you have an inferior
environment and cannot recompile), you may still disable all the fancy stuff
via `cperl-use-syntax-table-text-property'.")
(defvar cperl-praise 'please-ignore-this-line
"Advantages of CPerl mode.
0) It uses the newest `syntax-table' property ;-);
1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
mode - but the latter number may have improved too in last years) even
with old Emaxen which do not support `syntax-table' property.
When using `syntax-table' property for syntax assist hints, it should
handle 99.995% of lines correct - or somesuch. It automatically
updates syntax assist hints when you edit your script.
2) It is generally believed to be \"the most user-friendly Emacs
package\" whatever it may mean (I doubt that the people who say similar
things tried _all_ the rest of Emacs ;-), but this was not a lonely
3) Everything is customizable, one-by-one or in a big sweep;
4) It has many easily-accessible \"tools\":
a) Can run program, check syntax, start debugger;
b) Can lineup vertically \"middles\" of rows, like `=' in
a = b;
cc = d;
c) Can insert spaces where this impoves readability (in one
interactive sweep over the buffer);
d) Has support for imenu, including:
1) Separate unordered list of \"interesting places\";
2) Separate TOC of POD sections;
3) Separate list of packages;
4) Hierarchical view of methods in (sub)packages;
5) and functions (by the full name - with package);
e) Has an interface to INFO docs for Perl; The interface is
very flexible, including shrink-wrapping of
documentation buffer/frame;
f) Has a builtin list of one-line explanations for perl constructs.
g) Can show these explanations if you stay long enough at the
corresponding place (or on demand);
h) Has an enhanced fontification (using 3 or 4 additional faces
comparing to font-lock - basically, different
namespaces in Perl have different colors);
i) Can construct TAGS basing on its knowledge of Perl syntax,
the standard menu has 6 different way to generate
TAGS (if \"by directory\", .xs files - with C-language
bindings - are included in the scan);
j) Can build a hierarchical view of classes (via imenu) basing
on generated TAGS file;
k) Has electric parentheses, electric newlines, uses Abbrev
for electric logical constructs
while () {}
with different styles of expansion (context sensitive
to be not so bothering). Electric parentheses behave
\"as they should\" in a presence of a visible region.
l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
m) Can convert from
if (A) { B }
B if A;
n) Highlights (by user-choice) either 3-delimiters constructs
(such as tr/a/b/), or regular expressions and `y/tr';
o) Highlights trailing whitespace;
p) Is able to manipulate Perl Regular Expressions to ease
conversion to a more readable form.
q) Can ispell POD sections and HERE-DOCs.
r) Understands comments and character classes inside regular
expressions; can find matching () and [] in a regular expression.
s) Allows indentation of //x-style regular expressions;
t) Highlights different symbols in regular expressions according
to their function; much less problems with backslashitis;
u) Allows to find regular expressions which contain interpolated parts.
5) The indentation engine was very smart, but most of tricks may be
not needed anymore with the support for `syntax-table' property. Has
progress indicator for indentation (with `imenu' loaded).
6) Indent-region improves inline-comments as well; also corrects
whitespace *inside* the conditional/loop constructs.
7) Fill-paragraph correctly handles multi-line comments;
8) Can switch to different indentation styles by one command, and restore
the settings present before the switch.
9) When doing indentation of control constructs, may correct
line-breaks/spacing between elements of the construct.
10) Uses a linear-time algorith for indentation of regions (on Emaxen with
capable syntax engines).
11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
(defvar cperl-speed 'please-ignore-this-line
"This is an incomplete compendium of what is available in other parts
of CPerl documentation. (Please inform me if I skept anything.)
There is a perception that CPerl is slower than alternatives. This part
of documentation is designed to overcome this misconception.
*By default* CPerl tries to enable the most comfortable settings.
From most points of view, correctly working package is infinitely more
comfortable than a non-correctly working one, thus by default CPerl
prefers correctness over speed. Below is the guide how to change
settings if your preferences are different.
A) Speed of loading the file. When loading file, CPerl may perform a
scan which indicates places which cannot be parsed by primitive Emacs
syntax-parsing routines, and marks them up so that either
A1) CPerl may work around these deficiencies (for big chunks, mostly
PODs and HERE-documents), or
A2) On capable Emaxen CPerl will use improved syntax-handlings
which reads mark-up hints directly.
The scan in case A2 is much more comprehensive, thus may be slower.
User can disable syntax-engine-helping scan of A2 by setting
variable to nil (if it is set to t).
One can disable the scan altogether (both A1 and A2) by setting
to nil.
B) Speed of editing operations.
One can add a (minor) speedup to editing operations by setting
variable to nil (if it is set to t). This will disable
syntax-engine-helping scan, thus will make many more Perl
constructs be wrongly recognized by CPerl, thus may lead to
wrongly matched parentheses, wrong indentation, etc.
One can unset `cperl-syntaxify-unwind'. This might speed up editing
of, say, long POD sections.")
(defvar cperl-tips-faces 'please-ignore-this-line
"CPerl mode uses following faces for highlighting:
`cperl-array-face' Array names
`cperl-hash-face' Hash names
`font-lock-comment-face' Comments, PODs and whatever is considered
syntaxically to be not code
`font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
2-arg operators s/y/tr/ or of RExen,
`font-lock-warning-face' Special-cased m// and s//foo/,
`font-lock-function-name-face' _ as a target of a file tests, file tests,
subroutine names at the moment of definition
(except those conflicting with Perl operators),
package names (when recognized), format names
`font-lock-keyword-face' Control flow switch constructs, declarators
`cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
`font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
literal parts and the terminator of formats
and whatever is syntaxically considered
as string literals
`font-lock-type-face' Overridable keywords
`font-lock-variable-name-face' Variable declarations, indirect array and
hash names, POD headers/item names
`cperl-invalid' Trailing whitespace
Note that in several situations the highlighting tries to inform about
possible confusion, such as different colors for function names in
declarations depending on what they (do not) override, or special cases
m// and s/// which do not do what one would expect them to do.
Help with best setup of these faces for printout requested (for each of
the faces: please specify bold, italic, underline, shadow and box.)
In regular expressions (except character classes):
`font-lock-string-face' \"Normal\" stuff and non-0-length constructs
`font-lock-constant-face': Delimiters
`font-lock-warning-face' Special-cased m// and s//foo/,
Mismatched closing delimiters, parens
we couldn't match, misplaced quantifiers,
unrecognized escape sequences
`cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
`font-lock-type-face' POSIX classes inside charclasses,
escape sequences with arguments (\x \23 \p \N)
and others match-a-char escape sequences
`font-lock-keyword-face' Capturing parens, and |
`font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
`font-lock-builtin-face' \"Remaining\" 0-length constructs, executable
parts of a REx, not-capturing parens
`font-lock-variable-name-face' Interpolated constructs, embedded code
`font-lock-comment-face' Embedded comments
;;; Portability stuff:
(defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
`(define-key cperl-mode-map
,(if xemacs-key
`(if (featurep 'xemacs) ,xemacs-key ,emacs-key)
(defvar cperl-del-back-ch
(car (append (where-is-internal 'delete-backward-char)
(where-is-internal 'backward-delete-char-untabify)))
"Character generated by key bound to `delete-backward-char'.")
(and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
(setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
(defun cperl-mark-active () (mark)) ; Avoid undefined warning
(if (featurep 'xemacs)
;; "Active regions" are on: use region only if active
;; "Active regions" are off: use region unconditionally
(defun cperl-use-region-p ()
(if zmacs-regions (mark) t)))
(defun cperl-use-region-p ()
(if transient-mark-mode mark-active t))
(defun cperl-mark-active () mark-active))
(defsubst cperl-enable-font-lock ()
(defun cperl-putback-char (c) ; Emacs 19
(set 'unread-command-events (list c))) ; Avoid undefined warning
(if (featurep 'xemacs)
(defun cperl-putback-char (c) ; XEmacs >= 19.12
(setq unread-command-events (list (eval '(character-to-event c))))))
(or (fboundp 'uncomment-region)
(defun uncomment-region (beg end)
(interactive "r")
(comment-region beg end -1)))
(defvar cperl-do-not-fontify
(if (string< emacs-version "19.30")
"Text property which inhibits refontification.")
(defsubst cperl-put-do-not-fontify (from to &optional post)
;; If POST, do not do it with postponed fontification
(if (and post cperl-syntaxify-by-font-lock)
(put-text-property (max (point-min) (1- from))
to cperl-do-not-fontify t)))
(defcustom cperl-mode-hook nil
"Hook run by CPerl mode."
:type 'hook
:group 'cperl)
(defvar cperl-syntax-state nil)
(defvar cperl-syntax-done-to nil)
(defvar cperl-emacs-can-parse (> (length (save-excursion
(parse-partial-sexp (point) (point)))) 9))
;; Make customization possible "in reverse"
(defsubst cperl-val (symbol &optional default hairy)
((eq (symbol-value symbol) 'null) default)
(cperl-hairy (or hairy t))
(t (symbol-value symbol))))
(defun cperl-make-indent (column &optional minimum keep)
"Makes indent of the current line the requested amount.
Unless KEEP, removes the old indentation. Works around a bug in ancient
versions of Emacs."
(let ((prop (get-text-property (point) 'syntax-type)))
(or keep
(indent-to column minimum)
;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
(and prop
(> (current-column) 0)
(or (get-text-property (point) 'syntax-type)
(and (looking-at "\\=[ \t]")
(put-text-property (point) (match-end 0)
'syntax-type prop)))))))
;;; Probably it is too late to set these guys already, but it can help later:
;;;(and cperl-clobber-mode-lists
;;;(setq auto-mode-alist
;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
;;;(and (boundp 'interpreter-mode-alist)
;;; (setq interpreter-mode-alist (append interpreter-mode-alist
;;; '(("miniperl" . perl-mode))))))
(mapc (lambda (p)
(condition-case nil
(require p)
(error nil)))
'(imenu easymenu etags timer man info))
(if (fboundp 'ps-extend-face-list)
(defmacro cperl-ps-extend-face-list (arg)
`(ps-extend-face-list ,arg))
(defmacro cperl-ps-extend-face-list (arg)
`(error "This version of Emacs has no `ps-extend-face-list'")))
;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
;; macros instead of defsubsts don't work on Emacs, so we do the
;; expansion manually. Any other suggestions?
(require 'cl))
(defvar cperl-mode-abbrev-table nil
"Abbrev table in use in CPerl mode buffers.")
(add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
(defvar cperl-mode-map () "Keymap used in CPerl mode.")
(if cperl-mode-map nil
(setq cperl-mode-map (make-sparse-keymap))
(cperl-define-key "{" 'cperl-electric-lbrace)
(cperl-define-key "[" 'cperl-electric-paren)
(cperl-define-key "(" 'cperl-electric-paren)
(cperl-define-key "<" 'cperl-electric-paren)
(cperl-define-key "}" 'cperl-electric-brace)
(cperl-define-key "]" 'cperl-electric-rparen)
(cperl-define-key ")" 'cperl-electric-rparen)
(cperl-define-key ";" 'cperl-electric-semi)
(cperl-define-key ":" 'cperl-electric-terminator)
(cperl-define-key "\C-j" 'newline-and-indent)
(cperl-define-key "\C-c\C-j" 'cperl-linefeed)
(cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
(cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
(cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
(cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
(cperl-define-key "\C-c\C-f" 'auto-fill-mode)
(cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
(cperl-define-key "\C-c\C-b" 'cperl-find-bad-style)
(cperl-define-key "\C-c\C-p" 'cperl-pod-spell)
(cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell)
(cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc)
(cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx)
(cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0)
(cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1)
(cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
(cperl-define-key "\C-c\C-hp" 'cperl-perldoc)
(cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point)
(cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
(cperl-define-key [?\C-\M-\|] 'cperl-lineup
[(control meta |)])
;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
(cperl-define-key "\177" 'cperl-electric-backspace)
(cperl-define-key "\t" 'cperl-indent-command)
;; don't clobber the backspace binding:
(cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
[(control c) (control h) F])
(if (cperl-val 'cperl-clobber-lisp-bindings)
(cperl-define-key "\C-hf"
;;(concat (char-to-string help-char) "f") ; does not work
[(control h) f])
(cperl-define-key "\C-hv"
;;(concat (char-to-string help-char) "v") ; does not work
[(control h) v])
(cperl-define-key "\C-c\C-hf"
;;(concat (char-to-string help-char) "f") ; does not work
(key-binding "\C-hf")
[(control c) (control h) f])
(cperl-define-key "\C-c\C-hv"
;;(concat (char-to-string help-char) "v") ; does not work
(key-binding "\C-hv")
[(control c) (control h) v]))
(cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
[(control c) (control h) f])
(cperl-define-key "\C-c\C-hv"
;;(concat (char-to-string help-char) "v") ; does not work
[(control c) (control h) v]))
(if (and (featurep 'xemacs)
(<= emacs-minor-version 11) (<= emacs-major-version 19))
;; substitute-key-definition is usefulness-deenhanced...
;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
(cperl-define-key "\e;" 'cperl-indent-for-comment)
(cperl-define-key "\e\C-\\" 'cperl-indent-region))
(or (boundp 'fill-paragraph-function)
'fill-paragraph 'cperl-fill-paragraph
cperl-mode-map global-map))
'indent-sexp 'cperl-indent-exp
cperl-mode-map global-map)
'indent-region 'cperl-indent-region
cperl-mode-map global-map)
'indent-for-comment 'cperl-indent-for-comment
cperl-mode-map global-map)))
(defvar cperl-menu)
(defvar cperl-lazy-installed)
(defvar cperl-old-style nil)
(condition-case nil
(require 'easymenu)
cperl-menu cperl-mode-map "Menu for CPerl mode"
["Beginning of function" beginning-of-defun t]
["End of function" end-of-defun t]
["Mark function" mark-defun t]
["Indent expression" cperl-indent-exp t]
["Fill paragraph/comment" fill-paragraph t]
["Line up a construction" cperl-lineup (cperl-use-region-p)]
["Invert if/unless/while etc" cperl-invert-if-unless t]
["Beautify" cperl-beautify-regexp
["Beautify one level deep" (cperl-beautify-regexp 1)
["Beautify a group" cperl-beautify-level
["Beautify a group one level deep" (cperl-beautify-level 1)
["Contract a group" cperl-contract-level
["Contract groups" cperl-contract-levels
["Find next interpolated" cperl-next-interpolated-REx
(next-single-property-change (point-min) 'REx-interpolated)]
["Find next interpolated (no //o)"
(or (text-property-any (point-min) (point-max) 'REx-interpolated t)
(text-property-any (point-min) (point-max) 'REx-interpolated 1))]
["Find next interpolated (neither //o nor whole-REx)"
(text-property-any (point-min) (point-max) 'REx-interpolated t)])
["Insert spaces if needed to fix style" cperl-find-bad-style t]
["Refresh \"hard\" constructions" cperl-find-pods-heres t]
["Indent region" cperl-indent-region (cperl-use-region-p)]
["Comment region" cperl-comment-region (cperl-use-region-p)]
["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
["Run" mode-compile (fboundp 'mode-compile)]
["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
(get-buffer "*compilation*"))]
["Next error" next-error (get-buffer "*compilation*")]
["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
["Debugger" cperl-db t]
["Imenu" imenu (fboundp 'imenu)]
["Imenu on Perl Info" cperl-imenu-on-info (featurep 'imenu)]
["Ispell PODs" cperl-pod-spell
;; Better not to update syntaxification here:
;; debugging syntaxificatio can be broken by this???
(get-text-property (point-min) 'in-pod)
(< (progn
(and cperl-syntaxify-for-menu
(cperl-update-syntaxification (point-max) (point-max)))
(next-single-property-change (point-min) 'in-pod nil (point-max)))
["Ispell HERE-DOCs" cperl-here-doc-spell
(< (progn
(and cperl-syntaxify-for-menu
(cperl-update-syntaxification (point-max) (point-max)))
(next-single-property-change (point-min) 'here-doc-group nil (point-max)))
["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
(eq 'here-doc (progn
(and cperl-syntaxify-for-menu
(cperl-update-syntaxification (point) (point)))
(get-text-property (point) 'syntax-type)))]
["Select this HERE-DOC or POD section"
(memq (progn
(and cperl-syntaxify-for-menu
(cperl-update-syntaxification (point) (point)))
(get-text-property (point) 'syntax-type))
'(here-doc pod))]
["CPerl pretty print (exprmntl)" cperl-ps-print
(fboundp 'ps-extend-face-list)]
["Syntaxify region" cperl-find-pods-heres-region
["Profile syntaxification" cperl-time-fontification t]
["Debug errors in delayed fontification" cperl-emulate-lazy-lock t]
["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t]
["Debug backtrace on syntactic scan (BEWARE!!!)"
(cperl-toggle-set-debug-unwind nil t) t]
["Class Hierarchy from TAGS" cperl-tags-hier-init t]
;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
;;; ["Create tags for current file" cperl-etags t]
;;; ["Add tags for current file" (cperl-etags t) t]
;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
;;; ["Create tags for Perl files in (sub)directories"
;;; (cperl-etags nil 'recursive) t]
;;; ["Add tags for Perl files in (sub)directories"
;;; (cperl-etags t 'recursive) t])
;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
["Create tags for current file" (cperl-write-tags nil t) t]
["Add tags for current file" (cperl-write-tags) t]
["Create tags for Perl files in directory"
(cperl-write-tags nil t nil t) t]
["Add tags for Perl files in directory"
(cperl-write-tags nil nil nil t) t]
["Create tags for Perl files in (sub)directories"
(cperl-write-tags nil t t t) t]
["Add tags for Perl files in (sub)directories"
(cperl-write-tags nil nil t t) t]))
("Perl docs"
["Define word at point" imenu-go-find-at-position
(fboundp 'imenu-go-find-at-position)]
["Help on function" cperl-info-on-command t]
["Help on function at point" cperl-info-on-current-command t]
["Help on symbol at point" cperl-get-help t]
["Perldoc" cperl-perldoc t]
["Perldoc on word at point" cperl-perldoc-at-point t]
["View manpage of POD in this file" cperl-build-manpage t]
["Auto-help on" cperl-lazy-install
(and (fboundp 'run-with-idle-timer)
(not cperl-lazy-installed))]
["Auto-help off" cperl-lazy-unstall
(and (fboundp 'run-with-idle-timer)
["Auto newline" cperl-toggle-auto-newline t]
["Electric parens" cperl-toggle-electric t]
["Electric keywords" cperl-toggle-abbrev t]
["Fix whitespace on indent" cperl-toggle-construct-fix t]
["Auto-help on Perl constructs" cperl-toggle-autohelp t]
["Auto fill" auto-fill-mode t])
("Indent styles..."
["CPerl" (cperl-set-style "CPerl") t]
["PerlStyle" (cperl-set-style "PerlStyle") t]
["GNU" (cperl-set-style "GNU") t]
["C++" (cperl-set-style "C++") t]
["K&R" (cperl-set-style "K&R") t]
["BSD" (cperl-set-style "BSD") t]
["Whitesmith" (cperl-set-style "Whitesmith") t]
["Memorize Current" (cperl-set-style "Current") t]
["Memorized" (cperl-set-style-back) cperl-old-style])
["Tips" (describe-variable 'cperl-tips) t]
["Problems" (describe-variable 'cperl-problems) t]
["Speed" (describe-variable 'cperl-speed) t]
["Praise" (describe-variable 'cperl-praise) t]
["Faces" (describe-variable 'cperl-tips-faces) t]
["CPerl mode" (describe-function 'cperl-mode) t]
["CPerl version"
(message "The version of master-file for this CPerl is %s-Emacs"
cperl-version) t]))))
(error nil))
(autoload 'c-macro-expand "cmacexp"
"Display the result of expanding all C macros occurring in the region.
The expansion is entirely correct because it uses the C preprocessor."
;;; These two must be unwound, otherwise take exponential time
(defconst cperl-maybe-white-and-comment-rex "[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
"Regular expression to match optional whitespace with interpspersed comments.
Should contain exactly one group.")
;;; This one is tricky to unwind; still very inefficient...
(defconst cperl-white-and-comment-rex "\\([ \t\n]\\|#[^\n]*\n\\)+"
"Regular expression to match whitespace with interpspersed comments.
Should contain exactly one group.")
;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
;;; `cperl-outline-regexp', `defun-prompt-regexp'.
;;; Details of groups in this may be used in several functions; see comments
;;; near mentioned above variable(s)...
;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
(defsubst cperl-after-sub-regexp (named attr) ; 9 groups without attr...
"Match the text after `sub' in a subroutine declaration.
If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
of attributes (if present), or end of the name or prototype (whatever is
the last)."
(concat ; Assume n groups before this...
"\\(" ; n+1=name-group
cperl-white-and-comment-rex ; n+2=pre-name
"\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
"\\)" ; END n+1=name-group
(if named "" "?")
"\\(" ; n+4=proto-group
cperl-maybe-white-and-comment-rex ; n+5=pre-proto
"\\(([^()]*)\\)" ; n+6=prototype
"\\)?" ; END n+4=proto-group
"\\(" ; n+7=attr-group
cperl-maybe-white-and-comment-rex ; n+8=pre-attr
"\\(" ; n+9=start-attr
(if attr (concat
cperl-maybe-white-and-comment-rex ; whitespace-comments
"\\(\\sw\\|_\\)+" ; attr-name
;; attr-arg (1 level of internal parens allowed!)
"\\(" ; optional : (XXX allows trailing???)
cperl-maybe-white-and-comment-rex ; whitespace-comments
"\\)?" ; END n+6=proto-group
;;; Tired of editing this in 8 places every time I remember that there
;;; is another method-defining keyword
(defvar cperl-sub-keywords
(defvar cperl-sub-regexp (regexp-opt cperl-sub-keywords))
(defun cperl-char-ends-sub-keyword-p (char)
"Return T if CHAR is the last character of a perl sub keyword."
(loop for keyword in cperl-sub-keywords
when (eq char (aref keyword (1- (length keyword))))
return t))
;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
;;; and `cperl-outline-level'.
;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 8=sub-name (+3)
(defvar cperl-imenu--function-name-regexp-perl
"^\\(" ; 1 = all
"\\([ \t]*package" ; 2 = package-group
"\\(" ; 3 = package-name-group
cperl-white-and-comment-rex ; 4 = pre-package-name
"\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
"[ \t]*"
(cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
cperl-maybe-white-and-comment-rex ; 15=pre-block
"=head\\([1-4]\\)[ \t]+" ; 16=level
"\\([^\n]+\\)$" ; 17=text
(defvar cperl-outline-regexp
(concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
(defvar cperl-mode-syntax-table nil
"Syntax table in use in CPerl mode buffers.")
(defvar cperl-string-syntax-table nil
"Syntax table in use in CPerl mode string-like chunks.")
(defsubst cperl-1- (p)
(max (point-min) (1- p)))
(defsubst cperl-1+ (p)
(min (point-max) (1+ p)))
(if cperl-mode-syntax-table
(setq cperl-mode-syntax-table (make-syntax-table))
(modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
(modify-syntax-entry ?/ "." cperl-mode-syntax-table)
(modify-syntax-entry ?* "." cperl-mode-syntax-table)
(modify-syntax-entry ?+ "." cperl-mode-syntax-table)
(modify-syntax-entry ?- "." cperl-mode-syntax-table)
(modify-syntax-entry ?= "." cperl-mode-syntax-table)
(modify-syntax-entry ?% "." cperl-mode-syntax-table)
(modify-syntax-entry ?< "." cperl-mode-syntax-table)
(modify-syntax-entry ?> "." cperl-mode-syntax-table)
(modify-syntax-entry ?& "." cperl-mode-syntax-table)
(modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
(modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
(modify-syntax-entry ?# "<" cperl-mode-syntax-table)
(modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
(modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
(if cperl-under-as-char
(modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
(modify-syntax-entry ?: "_" cperl-mode-syntax-table)
(modify-syntax-entry ?| "." cperl-mode-syntax-table)
(setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
(modify-syntax-entry ?$ "." cperl-string-syntax-table)
(modify-syntax-entry ?\{ "." cperl-string-syntax-table)
(modify-syntax-entry ?\} "." cperl-string-syntax-table)
(modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment )
(defvar cperl-faces-init nil)
;; Fix for msb.el
(defvar cperl-msb-fixed nil)
(defvar cperl-use-major-mode 'cperl-mode)
(defvar cperl-font-lock-multiline-start nil)
(defvar cperl-font-lock-multiline nil)
(defvar cperl-font-locking nil)
;; NB as it stands the code in cperl-mode assumes this only has one
;; element. If Xemacs 19 support were dropped, this could all be simplified.
(defvar cperl-compilation-error-regexp-alist
;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
'(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
2 3))
"Alist that specifies how to match errors in perl output.")
(defvar compilation-error-regexp-alist)
(defun cperl-mode ()
"Major mode for editing Perl code.
Expression and list commands understand all C brackets.
Tab indents for Perl code.
Paragraphs are separated by blank lines only.
Delete converts tabs to spaces as it moves back.
Various characters in Perl almost always come in pairs: {}, (), [],
sometimes <>. When the user types the first, she gets the second as
well, with optional special formatting done on {}. (Disabled by
default.) You can always quote (with \\[quoted-insert]) the left
\"paren\" to avoid the expansion. The processing of < is special,
since most the time you mean \"less\". CPerl mode tries to guess
whether you want to type pair <>, and inserts is if it
appropriate. You can set `cperl-electric-parens-string' to the string that
contains the parenths from the above list you want to be electrical.
Electricity of parenths is controlled by `cperl-electric-parens'.
You may also set `cperl-electric-parens-mark' to have electric parens
look for active mark and \"embrace\" a region if possible.'
CPerl mode provides expansion of the Perl control constructs:
if, else, elsif, unless, while, until, continue, do,
for, foreach, formy and foreachmy.
and POD directives (Disabled by default, see `cperl-electric-keywords'.)
The user types the keyword immediately followed by a space, which
causes the construct to be expanded, and the point is positioned where
she is most likely to want to be. eg. when the user types a space
following \"if\" the following appears in the buffer: if () { or if ()
} { } and the cursor is between the parentheses. The user can then
type some boolean expression within the parens. Having done that,
typing \\[cperl-linefeed] places you - appropriately indented - on a
new line between the braces (if you typed \\[cperl-linefeed] in a POD
directive line, then appropriate number of new lines is inserted).
If CPerl decides that you want to insert \"English\" style construct like
bite if angry;
it will not do any expansion. See also help on variable
`cperl-extra-newline-before-brace'. (Note that one can switch the
help message on expansion by setting `cperl-message-electric-keyword'
to nil.)
\\[cperl-linefeed] is a convenience replacement for typing carriage
return. It places you in the next line with proper indentation, or if
you type it inside the inline block of control construct, like
foreach (@lines) {print; print}
and you are on a boundary of a statement inside braces, it will
transform the construct into a multiline and will place you into an
appropriately indented blank line. If you need a usual
`newline-and-indent' behavior, it is on \\[newline-and-indent],
see documentation on `cperl-electric-linefeed'.
Use \\[cperl-invert-if-unless] to change a construction of the form
if (A) { B }
B if A;
Setting the variable `cperl-font-lock' to t switches on font-lock-mode
\(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
on electric space between $ and {, `cperl-electric-parens-string' is
the string that contains parentheses that should be electric in CPerl
\(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
setting `cperl-electric-keywords' enables electric expansion of
control structures in CPerl. `cperl-electric-linefeed' governs which
one of two linefeed behavior is preferable. You can enable all these
options simultaneously (recommended mode of use) by setting
`cperl-hairy' to t. In this case you can switch separate options off
by setting them to `null'. Note that one may undo the extra
whitespace inserted by semis and braces in `auto-newline'-mode by
consequent \\[cperl-electric-backspace].
If your site has perl5 documentation in info format, you can use commands
\\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
These keys run commands `cperl-info-on-current-command' and
`cperl-info-on-command', which one is which is controlled by variable
`cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
\(in turn affected by `cperl-hairy').
Even if you have no info-format documentation, short one-liner-style
help is available on \\[cperl-get-help], and one can run perldoc or
man via menu.
It is possible to show this help automatically after some idle time.
This is regulated by variable `cperl-lazy-help-time'. Default with
`cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
secs idle time . It is also possible to switch this on/off from the
menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
Use \\[cperl-lineup] to vertically lineup some construction - put the
beginning of the region at the start of construction, and make region
span the needed amount of lines.
Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
`cperl-pod-face', `cperl-pod-head-face' control processing of POD and
here-docs sections. With capable Emaxen results of scan are used
for indentation too, otherwise they are used for highlighting only.
Variables controlling indentation style:
Non-nil means TAB in CPerl mode should always reindent the current line,
regardless of where in the line point is when the TAB command is used.
Non-nil means that the comment starting in leftmost column should indent.
Non-nil means automatically newline before and after braces,
and after colons and semicolons, inserted in Perl code. The following
\\[cperl-electric-backspace] will remove the inserted whitespace.
Insertion after colons requires both this variable and
`cperl-auto-newline-after-colon' set.
Non-nil means automatically newline even after colons.
Subject to `cperl-auto-newline' setting.
Indentation of Perl statements within surrounding block.
The surrounding block's indentation is the indentation
of the line on which the open-brace appears.
Extra indentation given to a substatement, such as the
then-clause of an if, or body of a while, or just a statement continuation.
Extra indentation given to a brace that starts a substatement.
This is in addition to `cperl-continued-statement-offset'.
Extra indentation for line if it starts with an open brace.
An open brace following other text is treated as if it the line started
this far to the right of the actual line indentation.
Extra indentation for line that is a label.
Minimal indentation for line that is a label.
Settings for classic indent-styles: K&R BSD=C++ GNU PerlStyle=Whitesmith
`cperl-indent-level' 5 4 2 4
`cperl-brace-offset' 0 0 0 0
`cperl-continued-brace-offset' -5 -4 0 0
`cperl-label-offset' -5 -4 -2 -4
`cperl-continued-statement-offset' 5 4 2 4
CPerl knows several indentation styles, and may bulk set the
corresponding variables. Use \\[cperl-set-style] to do this. Use
\\[cperl-set-style-back] to restore the memorized preexisting values
\(both available from menu). See examples in `cperl-style-examples'.
Part of the indentation style is how different parts of if/elsif/else
statements are broken into lines; in CPerl, this is reflected on how
templates for these constructs are created (controlled by
`cperl-extra-newline-before-brace'), and how reflow-logic should treat \"continuation\" blocks of else/elsif/continue, controlled by the same variable,
and by `cperl-extra-newline-before-brace-multiline',
`cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'.
If `cperl-indent-level' is 0, the statement after opening brace in
column 0 is indented on
Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
with no args.
DO NOT FORGET to read micro-docs (available from `Perl' menu)
or as help on variables `cperl-tips', `cperl-problems',
`cperl-praise', `cperl-speed'."
(use-local-map cperl-mode-map)
(if (cperl-val 'cperl-electric-linefeed)
(local-set-key "\C-J" 'cperl-linefeed)
(local-set-key "\C-C\C-J" 'newline-and-indent)))
(if (and
(cperl-val 'cperl-clobber-lisp-bindings)
(cperl-val 'cperl-info-on-command-no-prompt))
;; don't clobber the backspace binding:
(cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
(cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
[(control c) (control h) f])))
(setq major-mode cperl-use-major-mode)
(setq mode-name "CPerl")
(when (cperl-val 'cperl-electric-keywords)
(let ((prev-a-c abbrevs-changed))
(define-abbrev-table 'cperl-mode-abbrev-table '(
("if" "if" cperl-electric-keyword 0 :system)
("elsif" "elsif" cperl-electric-keyword 0 :system)
("while" "while" cperl-electric-keyword 0 :system)
("until" "until" cperl-electric-keyword 0 :system)
("unless" "unless" cperl-electric-keyword 0 :system)
("else" "else" cperl-electric-else 0 :system)
("continue" "continue" cperl-electric-else 0 :system)
("for" "for" cperl-electric-keyword 0 :system)
("foreach" "foreach" cperl-electric-keyword 0 :system)
("formy" "formy" cperl-electric-keyword 0 :system)
("foreachmy" "foreachmy" cperl-electric-keyword 0 :system)
("do" "do" cperl-electric-keyword 0 :system)
("=pod" "=pod" cperl-electric-pod 0 :system)
("=begin" "=begin" cperl-electric-pod 0 :system)
("=over" "=over" cperl-electric-pod 0 :system)
("=head1" "=head1" cperl-electric-pod 0 :system)
("=head2" "=head2" cperl-electric-pod 0 :system)
("pod" "pod" cperl-electric-pod 0 :system)
("over" "over" cperl-electric-pod 0 :system)
("head1" "head1" cperl-electric-pod 0 :system)
("head2" "head2" cperl-electric-pod 0 :system)))
(setq abbrevs-changed prev-a-c))
(setq local-abbrev-table cperl-mode-abbrev-table)
(abbrev-mode 1))
(set-syntax-table cperl-mode-syntax-table)
;; Until Emacs is multi-threaded, we do not actually need it local:
(make-local-variable 'cperl-font-lock-multiline-start)
(make-local-variable 'cperl-font-locking)
(make-local-variable 'outline-regexp)
;; (setq outline-regexp imenu-example--function-name-regexp-perl)
(setq outline-regexp cperl-outline-regexp)
(make-local-variable 'outline-level)
(setq outline-level 'cperl-outline-level)
(make-local-variable 'paragraph-start)
(setq paragraph-start (concat "^$\\|" page-delimiter))
(make-local-variable 'paragraph-separate)
(setq paragraph-separate paragraph-start)
(make-local-variable 'paragraph-ignore-fill-prefix)
(setq paragraph-ignore-fill-prefix t)
(if (featurep 'xemacs)
(make-local-variable 'paren-backwards-message)
(set 'paren-backwards-message t)))
(make-local-variable 'indent-line-function)
(setq indent-line-function 'cperl-indent-line)
(make-local-variable 'require-final-newline)
(setq require-final-newline mode-require-final-newline)
(make-local-variable 'comment-start)
(setq comment-start "# ")
(make-local-variable 'comment-end)
(setq comment-end "")
(make-local-variable 'comment-column)
(setq comment-column cperl-comment-column)
(make-local-variable 'comment-start-skip)
(setq comment-start-skip "#+ *")
(make-local-variable 'defun-prompt-regexp)
;;; "[ \t]*sub"
;;; (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
;;; cperl-maybe-white-and-comment-rex ; 15=pre-block
(setq defun-prompt-regexp
(concat "^[ \t]*\\("
(cperl-after-sub-regexp 'named 'attr-groups)
"\\|" ; per toke.c
(make-local-variable 'comment-indent-function)
(setq comment-indent-function 'cperl-comment-indent)
(and (boundp 'fill-paragraph-function)
(make-local-variable 'fill-paragraph-function)
(set 'fill-paragraph-function 'cperl-fill-paragraph)))
(make-local-variable 'parse-sexp-ignore-comments)
(setq parse-sexp-ignore-comments t)
(make-local-variable 'indent-region-function)
(setq indent-region-function 'cperl-indent-region)
;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
(make-local-variable 'imenu-create-index-function)
(setq imenu-create-index-function
(function cperl-imenu--create-perl-index))
(make-local-variable 'imenu-sort-function)
(setq imenu-sort-function nil)
(make-local-variable 'vc-rcs-header)
(set 'vc-rcs-header cperl-vc-rcs-header)
(make-local-variable 'vc-sccs-header)
(set 'vc-sccs-header cperl-vc-sccs-header)
;; This one is obsolete...
(make-local-variable 'vc-header-alist)
(set 'vc-header-alist (or cperl-vc-header-alist ; Avoid warning
`((SCCS ,(car cperl-vc-sccs-header))
(RCS ,(car cperl-vc-rcs-header)))))
(cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x
(make-local-variable 'compilation-error-regexp-alist-alist)
(set 'compilation-error-regexp-alist-alist
(cons (cons 'cperl (car cperl-compilation-error-regexp-alist))
(symbol-value 'compilation-error-regexp-alist-alist)))
(if (fboundp 'compilation-build-compilation-error-regexp-alist)
(let ((f 'compilation-build-compilation-error-regexp-alist))
(funcall f))
(make-local-variable 'compilation-error-regexp-alist)
(push 'cperl compilation-error-regexp-alist)))
((boundp 'compilation-error-regexp-alist);; xmeacs 19.x
(make-local-variable 'compilation-error-regexp-alist)
(set 'compilation-error-regexp-alist
(append cperl-compilation-error-regexp-alist
(symbol-value 'compilation-error-regexp-alist)))))
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
((string< emacs-version "19.30")
'(cperl-font-lock-keywords-2 nil nil ((?_ . "w"))))
((string< emacs-version "19.33") ; Which one to use?
cperl-font-lock-keywords-2) nil nil ((?_ . "w"))))
cperl-load-font-lock-keywords-2) nil nil ((?_ . "w"))))))
(make-local-variable 'cperl-syntax-state)
(setq cperl-syntax-state nil) ; reset syntaxification cache
(if cperl-use-syntax-table-text-property
(make-local-variable 'parse-sexp-lookup-properties)
;; Do not introduce variable if not needed, we check it!
(set 'parse-sexp-lookup-properties t)
;; Fix broken font-lock:
(or (boundp 'font-lock-unfontify-region-function)
(set 'font-lock-unfontify-region-function
(unless (featurep 'xemacs) ; Our: just a plug for wrong font-lock
(make-local-variable 'font-lock-unfontify-region-function)
(set 'font-lock-unfontify-region-function ; not present with old Emacs
(make-local-variable 'cperl-syntax-done-to)
(setq cperl-syntax-done-to nil) ; reset syntaxification cache
(make-local-variable 'font-lock-syntactic-keywords)
(setq font-lock-syntactic-keywords
(if cperl-syntaxify-by-font-lock
;; unless font-lock-syntactic-keywords, font-lock (pre-22.1)
;; used to ignore syntax-table text-properties. (t) is a hack
;; to make font-lock think that font-lock-syntactic-keywords
;; are defined.
(if (boundp 'font-lock-multiline) ; Newer font-lock; use its facilities
(setq cperl-font-lock-multiline t) ; Not localized...
(set (make-local-variable 'font-lock-multiline) t))
(make-local-variable 'font-lock-fontify-region-function)
(set 'font-lock-fontify-region-function ; not present with old Emacs
(make-local-variable 'font-lock-fontify-region-function)
(set 'font-lock-fontify-region-function ; not present with old Emacs
(make-local-variable 'cperl-old-style)
(if (boundp 'normal-auto-fill-function) ; 19.33 and later
(set (make-local-variable 'normal-auto-fill-function)
(or (fboundp 'cperl-old-auto-fill-mode)
(fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
(defun auto-fill-mode (&optional arg)
(interactive "P")
(eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
(and auto-fill-function (memq major-mode '(perl-mode cperl-mode))
(setq auto-fill-function 'cperl-do-auto-fill))))))
(if (cperl-enable-font-lock)
(if (cperl-val 'cperl-font-lock)
(progn (or cperl-faces-init (cperl-init-faces))
(font-lock-mode 1))))
(set (make-local-variable 'facemenu-add-face-function)
'cperl-facemenu-add-face-function) ; XXXX What this guy is for???
(and (boundp 'msb-menu-cond)
(not cperl-msb-fixed)
(if (featurep 'easymenu)
(easy-menu-add cperl-menu)) ; A NOP in Emacs.
(run-mode-hooks 'cperl-mode-hook)
(if cperl-hook-after-change
(add-hook 'after-change-functions 'cperl-after-change-function nil t))
;; After hooks since fontification will break this
(if cperl-pod-here-scan
(or cperl-syntaxify-by-font-lock
(progn (or cperl-faces-init (cperl-init-faces-weak))
;; Fix for perldb - make default reasonable
(defun cperl-db ()
(require 'gud)
(perldb (read-from-minibuffer "Run perldb (like this): "
(if (consp gud-perldb-history)
(car gud-perldb-history)
(concat "perl -d " ;;(file-name-nondirectory
;; I have problems
;; in OS/2
;; otherwise
nil nil
'(gud-perldb-history . 1))))
(defun cperl-msb-fix ()
;; Adds perl files to msb menu, supposes that msb is already loaded
(setq cperl-msb-fixed t)
(let* ((l (length msb-menu-cond))
(last (nth (1- l) msb-menu-cond))
(precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
(handle (1- (nth 1 last))))
(setcdr precdr (list
'(memq major-mode '(cperl-mode perl-mode))
"Perl Files (%d)")
;; This is used by indent-for-comment
;; to decide how much to indent a comment in CPerl code
;; based on its context. Do fallback if comment is found wrong.
(defvar cperl-wrong-comment)
(defvar cperl-st-cfence '(14)) ; Comment-fence
(defvar cperl-st-sfence '(15)) ; String-fence
(defvar cperl-st-punct '(1))
(defvar cperl-st-word '(2))
(defvar cperl-st-bra '(4 . ?\>))
(defvar cperl-st-ket '(5 . ?\<))
(defun cperl-comment-indent () ; called at point at supposed comment
(let ((p (point)) (c (current-column)) was phony)
(if (and (not cperl-indent-comment-at-column-0)
(looking-at "^#"))
0 ; Existing comment at bol stays there.
;; Wrong comment found
(setq was (cperl-to-comment-or-eol)
phony (eq (get-text-property (point) 'syntax-table)
(if phony
(progn ; Too naive???
(re-search-forward "#\\|$") ; Hmm, what about embedded #?
(if (eq (preceding-char) ?\#)
(forward-char -1))
(setq was nil)))
(if (= (point) p) ; Our caller found a correct place
(skip-chars-backward " \t")
(setq was (current-column))
(if (eq was 0)
(max (1+ was) ; Else indent at comment column
;; No, the caller found a random place; we need to edit ourselves
(if was nil
(insert comment-start)
(backward-char (length comment-start)))
(setq cperl-wrong-comment t)
(cperl-make-indent comment-column 1) ; Indent min 1
;;;(defun cperl-comment-indent-fallback ()
;;; "Is called if the standard comment-search procedure fails.
;;;Point is at start of real comment."
;;; (let ((c (current-column)) target cnt prevc)
;;; (if (= c comment-column) nil
;;; (setq cnt (skip-chars-backward "[ \t]"))
;;; (setq target (max (1+ (setq prevc
;;; (current-column))) ; Else indent at comment column
;;; comment-column))
;;; (if (= c comment-column) nil
;;; (delete-backward-char cnt)
;;; (while (< prevc target)
;;; (insert "\t")
;;; (setq prevc (current-column)))
;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
;;; (while (< prevc target)
;;; (insert " ")
;;; (setq prevc (current-column)))))))
(defun cperl-indent-for-comment ()
"Substitute for `indent-for-comment' in CPerl."
(let (cperl-wrong-comment)
(if cperl-wrong-comment ; set by `cperl-comment-indent'
(progn (cperl-to-comment-or-eol)
(forward-char (length comment-start))))))
(defun cperl-comment-region (b e arg)
"Comment or uncomment each line in the region in CPerl mode.
See `comment-region'."
(interactive "r\np")
(let ((comment-start "#"))
(comment-region b e arg)))
(defun cperl-uncomment-region (b e arg)
"Uncomment or comment each line in the region in CPerl mode.
See `comment-region'."
(interactive "r\np")
(let ((comment-start "#"))
(comment-region b e (- arg))))
(defvar cperl-brace-recursing nil)
(defun cperl-electric-brace (arg &optional only-before)
"Insert character and correct line's indentation.
If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
place (even in empty line), but not after. If after \")\" and the inserted
char is \"{\", insert extra newline before only if
(interactive "P")
(let (insertpos
(other-end (if (and cperl-electric-parens-mark
(< (mark) (point)))
(if (and other-end
(not cperl-brace-recursing)
(cperl-val 'cperl-electric-parens)
(>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
;; Need to insert a matching pair
(setq insertpos (point-marker))
(goto-char other-end)
(setq last-command-event ?\{)
(cperl-electric-lbrace arg insertpos))
(forward-char 1))
;; Check whether we close something "usual" with `}'
(if (and (eq last-command-event ?\})
(condition-case nil
(up-list (- (prefix-numeric-value arg)))
;;(cperl-after-block-p (point-min))
(or (cperl-after-expr-p nil "{;)")
;; after sub, else, continue
(cperl-after-block-p nil 'pre)))
(error nil))))
;; Just insert the guy
(self-insert-command (prefix-numeric-value arg))
(if (and (not arg) ; No args, end (of empty line or auto)
(or (and (null only-before)
(skip-chars-backward " \t")
(and (eq last-command-event ?\{) ; Do not insert newline
;; if after ")" and `cperl-extra-newline-before-brace'
;; is nil, do not insert extra newline.
(not cperl-extra-newline-before-brace)
(skip-chars-backward " \t")
(eq (preceding-char) ?\))))
(if cperl-auto-newline
(progn (cperl-indent-line) (newline) t) nil)))
(self-insert-command (prefix-numeric-value arg))
(if cperl-auto-newline
(setq insertpos (1- (point))))
(if (and cperl-auto-newline (null only-before))
(if insertpos (progn (goto-char insertpos)
(search-forward (make-string
1 last-command-event))
(setq insertpos (1- (point)))))
(delete-char -1))))
(if insertpos
(goto-char insertpos)
(self-insert-command (prefix-numeric-value arg)))
(self-insert-command (prefix-numeric-value arg)))))))
(defun cperl-electric-lbrace (arg &optional end)
"Insert character, correct line's indentation, correct quoting by space."
(interactive "P")
(let ((cperl-brace-recursing t)
(cperl-auto-newline cperl-auto-newline)
(other-end (or end
(if (and cperl-electric-parens-mark
(> (mark) (point)))
(goto-char (mark))
pos after)
(and (cperl-val 'cperl-electric-lbrace-space)
(eq (preceding-char) ?$)
(skip-chars-backward "$")
(looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
(insert ?\s))
;; Check whether we are in comment
(if (and
(not (looking-at "[ \t]*#")))
(cperl-after-expr-p nil "{;)"))
(setq cperl-auto-newline nil))
(cperl-electric-brace arg)
(and (cperl-val 'cperl-electric-parens)
(eq last-command-event ?{)
(memq last-command-event
(append cperl-electric-parens-string nil))
(or (if other-end (goto-char (marker-position other-end)))
(setq last-command-event ?} pos (point))
(progn (cperl-electric-brace arg t)
(goto-char pos)))))
(defun cperl-electric-paren (arg)
"Insert an opening parenthesis or a matching pair of parentheses.
See `cperl-electric-parens'."
(interactive "P")
(let ((beg (save-excursion (beginning-of-line) (point)))
(other-end (if (and cperl-electric-parens-mark
(> (mark) (point)))
(goto-char (mark))
(if (and (cperl-val 'cperl-electric-parens)
(memq last-command-event
(append cperl-electric-parens-string nil))
(>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
;;(not (save-excursion (search-backward "#" beg t)))
(if (eq last-command-event ?<)
(and abbrev-mode ; later it is too late, may be after `for'
(cperl-after-expr-p nil "{;(,:="))
(self-insert-command (prefix-numeric-value arg))
(if other-end (goto-char (marker-position other-end)))
(insert (make-string
(prefix-numeric-value arg)
(cdr (assoc last-command-event '((?{ .?})
(?[ . ?])
(?( . ?))
(?< . ?>))))))
(forward-char (- (prefix-numeric-value arg))))
(self-insert-command (prefix-numeric-value arg)))))
(defun cperl-electric-rparen (arg)
"Insert a matching pair of parentheses if marking is active.
If not, or if we are not at the end of marking range, would self-insert.
Affected by `cperl-electric-parens'."
(interactive "P")
(let ((beg (save-excursion (beginning-of-line) (point)))
(other-end (if (and cperl-electric-parens-mark
(cperl-val 'cperl-electric-parens)
(memq last-command-event
(append cperl-electric-parens-string nil))
(< (mark) (point)))
(if (and other-end
(cperl-val 'cperl-electric-parens)
(memq last-command-event '( ?\) ?\] ?\} ?\> ))
(>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
;;(not (save-excursion (search-backward "#" beg t)))
(self-insert-command (prefix-numeric-value arg))
(setq p (point))
(if other-end (goto-char other-end))
(insert (make-string
(prefix-numeric-value arg)
(cdr (assoc last-command-event '((?\} . ?\{)
(?\] . ?\[)
(?\) . ?\()
(?\> . ?\<))))))
(goto-char (1+ p)))
(self-insert-command (prefix-numeric-value arg)))))
(defun cperl-electric-keyword ()
"Insert a construction appropriate after a keyword.
Help message may be switched off by setting `cperl-message-electric-keyword'
to nil."
(let ((beg (save-excursion (beginning-of-line) (point)))
(dollar (and (eq last-command-event ?$)
(eq this-command 'self-insert-command)))
(delete (and (memq last-command-event '(?\s ?\n ?\t ?\f))
(memq this-command '(self-insert-command newline))))
my do)
(and (save-excursion
(condition-case nil
(backward-sexp 1)
(setq do (looking-at "do\\>")))
(error nil))
(cperl-after-expr-p nil "{;:"))
beg t)))
(save-excursion (or (not (re-search-backward "^=" nil t))
(looking-at "=cut")
(looking-at "=end")
(and cperl-use-syntax-table-text-property
(not (eq (get-text-property (point)
(save-excursion (forward-sexp -1)
(not (memq (following-char) (append "$@%&*" nil))))
(and (eq (preceding-char) ?y)
(progn ; "foreachmy"
(forward-char -2)
(insert " ")
(forward-char 2)
(setq my t dollar t
(memq this-command '(self-insert-command newline)))))
(and dollar (insert " $"))
;;(insert " () {\n}")
(insert (if do "\n" " ()\n"))
(insert "{")
(insert "\n")
(insert "\n}")
(and do (insert " while ();")))
(insert (if do " {\n} while ();" " () {\n}"))))
(or (looking-at "[ \t]\\|$") (insert " "))
(if dollar (progn (search-backward "$")
(if my
(forward-char 1)
(delete-char 1)))
(search-backward ")")
(if (eq last-command-event ?\()
(progn ; Avoid "if (())"
(delete-backward-char 1)
(delete-backward-char -1))))
(if delete
(cperl-putback-char cperl-del-back-ch))
(if cperl-message-electric-keyword
(message "Precede char by C-q to avoid expansion"))))))
(defun cperl-ensure-newlines (n &optional pos)
"Make sure there are N newlines after the point."
(or pos (setq pos (point)))
(if (looking-at "\n")
(forward-char 1)
(insert "\n"))
(if (> n 1)
(cperl-ensure-newlines (1- n) pos)
(goto-char pos)))
(defun cperl-electric-pod ()
"Insert a POD chunk appropriate after a =POD directive."
(let ((delete (and (memq last-command-event '(?\s ?\n ?\t ?\f))
(memq this-command '(self-insert-command newline))))
head1 notlast name p really-delete over)
(and (save-excursion
(forward-word -1)
(eq (preceding-char) ?=)
(setq head1 (looking-at "head1\\>[ \t]*$"))
(setq over (and (looking-at "over\\>[ \t]*$")
(not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
(forward-char -1)
(get-text-property (point) 'in-pod)
(cperl-after-expr-p nil "{;:")
(and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t)
(not (or (looking-at "\n*=cut")(looking-at "\n*=end")))
(or (not cperl-use-syntax-table-text-property)
(eq (get-text-property (point) 'syntax-type) 'pod))))))
(setq notlast (re-search-forward "^\n=" nil t)))
(or notlast
(insert "\n\n=cut")
(cperl-ensure-newlines 2)
(forward-word -2)
(if (and head1
(forward-char -1)
(re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
nil t)))) ; Only one
(forward-word 1)
(setq name (file-name-sans-extension
(file-name-nondirectory (buffer-file-name)))
p (point))
(insert " NAME\n\n" name
" - \n\n=head1 SYNOPSIS\n\n\n\n"
(cperl-ensure-newlines 4)
(goto-char p)
(forward-word 2)
(setq really-delete t))
(forward-word 1))))
(if over
(setq p (point))
(insert "\n\n=item \n\n\n\n"
(cperl-ensure-newlines 2)
(goto-char p)
(forward-word 1)
(setq really-delete t)))
(if (and delete really-delete)
(cperl-putback-char cperl-del-back-ch))))))
(defun cperl-electric-else ()
"Insert a construction appropriate after a keyword.
Help message may be switched off by setting `cperl-message-electric-keyword'
to nil."
(let ((beg (save-excursion (beginning-of-line) (point))))
(and (save-excursion
(backward-sexp 1)
(cperl-after-expr-p nil "{;:"))
beg t)))
(save-excursion (or (not (re-search-backward "^=" nil t))
(looking-at "=cut")
(looking-at "=end")
(and cperl-use-syntax-table-text-property
(not (eq (get-text-property (point)
;;(insert " {\n\n}")
(insert "\n")
(insert "{")
(insert "\n\n}"))
(insert " {\n\n}")))
(or (looking-at "[ \t]\\|$") (insert " "))
(forward-line -1)
(cperl-putback-char cperl-del-back-ch)
(setq this-command 'cperl-electric-else)
(if cperl-message-electric-keyword
(message "Precede char by C-q to avoid expansion"))))))
(defun cperl-linefeed ()
"Go to end of line, open a new line and indent appropriately.
If in POD, insert appropriate lines."
(let ((beg (save-excursion (beginning-of-line) (point)))
(end (save-excursion (end-of-line) (point)))
(pos (point)) start over cut res)
(if (and ; Check if we need to split:
; i.e., on a boundary and inside "{...}"
(save-excursion (cperl-to-comment-or-eol)
(>= (point) pos)) ; Not in a comment
(or (save-excursion
(skip-chars-backward " \t" beg)
(forward-char -1)
(looking-at "[;{]")) ; After { or ; + spaces
(looking-at "[ \t]*}") ; Before }
(re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
(eq (car (parse-partial-sexp pos end -1)) -1)
; Leave the level of parens
(looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
; Are at end
(cperl-after-block-p (point-min))
(backward-sexp 1)
(setq start (point-marker))
(<= start pos))))) ; Redundant? Are after the
; start of parens group.
(skip-chars-backward " \t")
(or (memq (preceding-char) (append ";{" nil))
(insert ";"))
(insert "\n")
(forward-line -1)
(goto-char start)
(or (looking-at "{[ \t]*$") ; If there is a statement
; before, move it to separate line
(forward-char 1)
(insert "\n")
(forward-line 1) ; We are on the target line
(or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
; after, move it to separate line
(search-backward "}" beg)
(skip-chars-backward " \t")
(or (memq (preceding-char) (append ";{" nil))
(insert ";"))
(insert "\n")
(forward-line -1)))
(forward-line -1) ; We are on the line before target
(end-of-line) ; else - no splitting
((and (looking-at "\n[ \t]*{$")
(skip-chars-backward " \t")
(eq (preceding-char) ?\)))) ; Probably if () {} group
; with an extra newline.
(forward-line 2)
((save-excursion ; In POD header
(forward-paragraph -1)
;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
;; We are after \n now, so look for the rest
(if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
(setq cut (looking-at "\\(\\`\n?\\|\n\\)=\\(cut\\|end\\)\\>"))
(setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
(if (and over
(forward-paragraph -1)
(forward-word 1)
(setq pos (point))
(setq cut (buffer-substring (point)
(delete-char (- (save-excursion (end-of-line) (point))
(setq res (expand-abbrev))
(goto-char pos)
(insert cut))
(cperl-ensure-newlines (if cut 2 4))
(forward-line 2)))
((get-text-property (point) 'in-pod) ; In POD section
(cperl-ensure-newlines 4)
(forward-line 2))
((looking-at "\n[ \t]*$") ; Next line is empty - use it.
(forward-line 1)
(defun cperl-electric-semi (arg)
"Insert character and correct line's indentation."
(interactive "P")
(if cperl-auto-newline
(cperl-electric-terminator arg)
(self-insert-command (prefix-numeric-value arg))
(if cperl-autoindent-on-semi
(defun cperl-electric-terminator (arg)
"Insert character and correct line's indentation."
(interactive "P")
(let ((end (point))
(auto (and cperl-auto-newline
(or (not (eq last-command-event ?:))
(if (and ;;(not arg)
(not (save-excursion
(skip-chars-forward " \t")
;; Ignore in comment lines
(= (following-char) ?#)
;; Colon is special only after a label
;; So quickly rule out most other uses of colon
;; and do no indentation for them.
(and (eq last-command-event ?:)
(forward-word 1)
(skip-chars-forward " \t")
(and (< (point) end)
(progn (goto-char (- end 1))
(not (looking-at ":"))))))
(let ((pps (parse-partial-sexp (point) end)))
(or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
(self-insert-command (prefix-numeric-value arg))
;;(forward-char -1)
(if auto (setq insertpos (point-marker)))
;;(forward-char 1)
(if auto
(if insertpos (goto-char (1- (marker-position insertpos)))
(forward-char -1))
(delete-char 1))))
(if insertpos
(goto-char insertpos)
(self-insert-command (prefix-numeric-value arg)))
(self-insert-command (prefix-numeric-value arg)))))
(defun cperl-electric-backspace (arg)
"Backspace, or remove the whitespace around the point inserted by an electric
key. Will untabify if `cperl-electric-backspace-untabify' is non-nil."
(interactive "p")
(if (and cperl-auto-newline
(memq last-command '(cperl-electric-semi
(memq (preceding-char) '(?\s ?\t ?\n)))
(let (p)
(if (eq last-command 'cperl-electric-lbrace)
(skip-chars-forward " \t\n"))
(setq p (point))
(skip-chars-backward " \t\n")
(delete-region (point) p))
(and (eq last-command 'cperl-electric-else)
;; We are removing the whitespace *inside* cperl-electric-else
(setq this-command 'cperl-electric-else-really))
(if (and cperl-auto-newline
(eq last-command 'cperl-electric-else-really)
(memq (preceding-char) '(?\s ?\t ?\n)))
(let (p)
(skip-chars-forward " \t\n")
(setq p (point))
(skip-chars-backward " \t\n")
(delete-region (point) p))
(if cperl-electric-backspace-untabify
(backward-delete-char-untabify arg)
(delete-backward-char arg)))))
(put 'cperl-electric-backspace 'delete-selection 'supersede)
(defun cperl-inside-parens-p () ;; NOT USED????
(condition-case ()
(narrow-to-region (point)
(progn (beginning-of-defun) (point)))
(goto-char (point-max))
(= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
(error nil)))
(defun cperl-indent-command (&optional whole-exp)
"Indent current line as Perl code, or in some cases insert a tab character.
If `cperl-tab-always-indent' is non-nil (the default), always indent current
line. Otherwise, indent the current line only if point is at the left margin
or in the line's indentation; otherwise insert a tab.
A numeric argument, regardless of its value,
means indent rigidly all the lines of the expression starting after point
so that this line becomes properly indented.
The relative indentation among the lines of the expression are preserved."
(interactive "P")
(cperl-update-syntaxification (point) (point))
(if whole-exp
;; If arg, always indent this line as Perl
;; and shift remaining lines of expression the same amount.
(let ((shift-amt (cperl-indent-line))
beg end)
(if cperl-tab-always-indent
(setq beg (point))
(forward-sexp 1)
(setq end (point))
(goto-char beg)
(forward-line 1)
(setq beg (point)))
(if (and shift-amt (> end beg))
(indent-code-rigidly beg end shift-amt "#")))
(if (and (not cperl-tab-always-indent)
(skip-chars-backward " \t")
(not (bolp))))
(defun cperl-indent-line (&optional parse-data)
"Indent current line as Perl code.
Return the amount the indentation changed by."
(let ((case-fold-search nil)
(pos (- (point-max) (point)))
indent i beg shift-amt)
(setq indent (cperl-calculate-indent parse-data)
i indent)
(setq beg (point))
(cond ((or (eq indent nil) (eq indent t))
(setq indent (current-indentation) i nil))
;;((eq indent t) ; Never?
;; (setq indent (cperl-calculate-indent-within-comment)))
;;((looking-at "[ \t]*#")
;; (setq indent 0))
(skip-chars-forward " \t")
(if (listp indent) (setq indent (car indent)))
(cond ((and (looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
(not (looking-at "[smy]:\\|tr:")))
(and (> indent 0)
(setq indent (max cperl-min-label-indent
(+ indent cperl-label-offset)))))
((= (following-char) ?})
(setq indent (- indent cperl-indent-level)))
((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
(setq indent (+ indent cperl-close-paren-offset)))
((= (following-char) ?{)
(setq indent (+ indent cperl-brace-offset))))))
(skip-chars-forward " \t")
(setq shift-amt (and i (- indent (current-column))))
(if (or (not shift-amt)
(zerop shift-amt))
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))
;;;(delete-region beg (point))
;;;(indent-to indent)
(cperl-make-indent indent)
;; If initial point was within line's indentation,
;; position after the indentation. Else stay at same point in text.
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos))))
(defun cperl-after-label ()
;; Returns true if the point is after label. Does not do save-excursion.
(and (eq (preceding-char) ?:)
(memq (char-syntax (char-after (- (point) 2)))
'(?w ?_))
(looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
(defun cperl-get-state (&optional parse-start start-state)
;; START is a good place to start parsing, or equal to
;; PARSE-START if preset,
;; STATE is what is returned by `parse-partial-sexp'.
;; DEPTH is true is we are immediately after end of block
;; which contains START.
;; PRESTART is the position basing on which START was found.
(let ((start-point (point)) depth state start prestart)
(if (and parse-start
(<= parse-start start-point))
(goto-char parse-start)
(setq start-state nil))
(setq prestart (point))
(if start-state nil
;; Try to go out, if sub is not on the outermost level
(while (< (point) start-point)
(setq start (point) parse-start start depth nil
state (parse-partial-sexp start start-point -1))
(if (> (car state) -1) nil
;; The current line could start like }}}, so the indentation
;; corresponds to a different level than what we reached
(setq depth t)
(beginning-of-line 2))) ; Go to the next line.
(if start (goto-char start))) ; Not at the start of file
(setq start (point))
(or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
(list start state depth prestart))))
(defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
(defun cperl-beginning-of-property (p prop &optional lim)
"Given that P has a property PROP, find where the property starts.
Will not look before LIM."
;;; XXXX What to do at point-max???
(or (previous-single-property-change (cperl-1+ p) prop lim)
;;; (cond ((eq p (point-min))
;;; p)
;;; ((and lim (<= p lim))
;;; p)
;;; ((not (get-text-property (1- p) prop))
;;; p)
;;; (t (or (previous-single-property-change p look-prop lim)
;;; (point-min))))
(defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start
;; Old workhorse for calculation of indentation; the major problem
;; is that it mixes the sniffer logic to understand what the current line
;; MEANS with the logic to actually calculate where to indent it.
;; The latter part should be eventually moved to `cperl-calculate-indent';
;; actually, this is mostly done now...
(cperl-update-syntaxification (point) (point))
(let ((res (get-text-property (point) 'syntax-type)))
((and (memq res '(pod here-doc here-doc-delim format))
(not (get-text-property (point) 'indentable)))
(vector res))
;; before start of POD - whitespace found since do not have 'pod!
((looking-at "[ \t]*\n=")
(error "Spaces before POD section!"))
((and (not cperl-indent-left-aligned-comments)
(looking-at "^#"))
((get-text-property (point) 'in-pod)
(let* ((indent-point (point))
(char-after-pos (save-excursion
(skip-chars-forward " \t")
(char-after (char-after char-after-pos))
(pre-indent-point (point))
p prop look-prop is-block delim)
(save-excursion ; Know we are not in POD, find appropriate pos before
(cperl-backward-to-noncomment nil)
(setq p (max (point-min) (1- (point)))
prop (get-text-property p 'syntax-type)
look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
(if (memq prop '(pod here-doc format here-doc-delim))
(goto-char (cperl-beginning-of-property p look-prop))
(setq pre-indent-point (point)))))
(goto-char pre-indent-point) ; Orig line skipping preceeding pod/etc
(let* ((case-fold-search nil)
(s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
(start (or (nth 2 parse-data) ; last complete sexp terminated
(nth 0 s-s))) ; Good place to start parsing
(state (nth 1 s-s))
(containing-sexp (car (cdr state)))
(if (and
;;containing-sexp ;; We are buggy at toplevel :-(
(setcar parse-data pre-indent-point)
(setcar (cdr parse-data) state)
(or (nth 2 parse-data)
(setcar (cddr parse-data) start))
;; Before this point: end of statement
(setq old-indent (nth 3 parse-data))))
(cond ((get-text-property (point) 'indentable)
;; indent to "after" the surrounding open
;; (same offset as `cperl-beautify-regexp-piece'),
;; skip blanks if we do not close the expression.
(setq delim ; We do not close the expression
(cperl-1+ char-after-pos) 'indentable)
p (1+ (cperl-beginning-of-property
(point) 'indentable))
is-block ; misused for: preceeding line in REx
(save-excursion ; Find preceeding line
(cperl-backward-to-noncomment p)
(if (<= (point) p)
(progn ; get indent from the first line
(goto-char p)
(skip-chars-forward " \t")
(if (memq (char-after (point))
(append "#\n" nil))
nil ; Can't use intentation of this line...
(skip-chars-forward " \t")
prop (parse-partial-sexp p char-after-pos))
(cond ((not delim) ; End the REx, ignore is-block
(vector 'indentable 'terminator p is-block))
(is-block ; Indent w.r.t. preceeding line
(vector 'indentable 'cont-line char-after-pos
is-block char-after p))
(t ; No preceeding line...
(vector 'indentable 'first-line p))))
((get-text-property char-after-pos 'REx-part2)
(vector 'REx-part2 (point)))
((nth 4 state)
((nth 3 state)
;; XXXX Do we need to special-case this?
((null containing-sexp)
;; Line is at top level. May be data or function definition,
;; or may be function argument declaration.
;; Indent like the previous top level line
;; unless that ends in a closeparen without semicolon,
;; in which case this line is the first argument decl.
(skip-chars-forward " \t")
(cperl-backward-to-noncomment (or old-indent (point-min)))
(setq state
(or (bobp)
(eq (point) old-indent) ; old-indent was at comment
(eq (preceding-char) ?\;)
;; Had ?\) too
(and (eq (preceding-char) ?\})
(point-min))) ; Was start - too close
(memq char-after (append ")]}" nil))
(and (eq (preceding-char) ?\:) ; label
(forward-sexp -1)
(skip-chars-backward " \t")
(looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
(get-text-property (point) 'first-format-line)))
;; Look at previous line that's at column 0
;; to determine whether we are in top-level decls
;; or function's arg decls. Set basic-indent accordingly.
;; Now add a little if this is a continuation line.
(and state
(not (eq char-after ?\C-j))
(setcdr (cddr parse-data)
(list pre-indent-point)))
(vector 'toplevel start char-after state (nth 2 s-s)))
(or (setq is-block
(and (setq delim (= (char-after containing-sexp) ?{))
(save-excursion ; Is it a hash?
(goto-char containing-sexp)
;; group is an expression, not a block:
;; indent to just after the surrounding open parens,
;; skip blanks if we do not close the expression.
(goto-char (1+ containing-sexp))
(or (memq char-after
(append (if delim "}" ")]}") nil))
(looking-at "[ \t]*\\(#\\|$\\)")
(skip-chars-forward " \t"))
(setq old-indent (point)) ; delim=is-brace
(vector 'in-parens char-after (point) delim containing-sexp))
;; Statement level. Is it a continuation or a new statement?
;; Find previous non-comment character.
(goto-char pre-indent-point) ; Skip one level of POD/etc
(cperl-backward-to-noncomment containing-sexp)
;; Back up over label lines, since they don't
;; affect whether our line is a continuation.
;; (Had \, too)
(while;;(or (eq (preceding-char) ?\,)
(and (eq (preceding-char) ?:)
(or;;(eq (char-after (- (point) 2)) ?\') ; ????
(memq (char-syntax (char-after (- (point) 2)))
'(?w ?_))))
;; This is always FALSE?
(if (eq (preceding-char) ?\,)
;; Will go to beginning of line, essentially.
;; Will ignore embedded sexpr XXXX.
(cperl-backward-to-start-of-continued-exp containing-sexp))
(cperl-backward-to-noncomment containing-sexp))
;; Now we get non-label preceeding the indent point
(if (not (or (eq (1- (point)) containing-sexp)
(and cperl-indent-parens-as-block
(not is-block))
(memq (preceding-char)
(append (if is-block " ;{" " ,;{") '(nil)))
(and (eq (preceding-char) ?\})
(get-text-property (point) 'first-format-line)))
;; This line is continuation of preceding line's statement;
;; indent `cperl-continued-statement-offset' more than the
;; previous line of the statement.
;; There might be a label on this line, just
;; consider it bad style and ignore it.
(cperl-backward-to-start-of-continued-exp containing-sexp)
(vector 'continuation (point) char-after is-block delim))
;; This line starts a new statement.
;; Position following last unclosed open brace
(goto-char containing-sexp)
;; Is line first statement after an open-brace?
;; If no, find that first statement and indent like
;; it. If the first statement begins with label, do
;; not believe when the indentation of the label is too
;; small.
(forward-char 1)
(let ((colon-line-end 0))
(progn (skip-chars-forward " \t\n")
;; s: foo : bar :x is NOT label
(and (looking-at "#\\|\\([a-zA-Z0-9_$]+\\):[^:]\\|=[a-zA-Z]")
(not (looking-at "[sym]:\\|tr:"))))
;; Skip over comments and labels following openbrace.
(cond ((= (following-char) ?\#)
(forward-line 1))
((= (following-char) ?\=)
(or (next-single-property-change (point) 'in-pod)
(point-max)))) ; do not loop if no syntaxification
;; label:
(save-excursion (end-of-line)
(setq colon-line-end (point)))
(search-forward ":"))))
;; We are at beginning of code (NOT label or comment)
;; First, the following code counts
;; if it is before the line we want to indent.
(and (< (point) indent-point)
(vector 'have-prev-sibling (point) colon-line-end
;; If no previous statement,
;; indent it relative to line brace is on.
;; For open-braces not the first thing in a line,
;; add in cperl-brace-imaginary-offset.
;; If first thing on a line: ?????
;; Move back over whitespace before the openbrace.
(setq ; brace first thing on a line
old-indent (progn (skip-chars-backward " \t") (bolp)))
;; Should we indent w.r.t. earlier than start?
;; Move to start of control group, possibly on a different line
(or cperl-indent-wrt-brace
(cperl-backward-to-noncomment (point-min)))
;; If the openbrace is preceded by a parenthesized exp,
;; move to the beginning of that;
(if (eq (preceding-char) ?\))
(forward-sexp -1)
(cperl-backward-to-noncomment (point-min))))
;; In the case it starts a subroutine, indent with
;; respect to `sub', not with respect to the
;; first thing on the line, say in the case of
;; anonymous sub in a hash.
(if (and;; Is it a sub in group starting on this line?
(cond ((get-text-property (point) 'attrib-group)
(goto-char (cperl-beginning-of-property
(point) 'attrib-group)))
((eq (preceding-char) ?b)
(forward-sexp -1)
(looking-at (concat cperl-sub-regexp "\\>"))))
(setq p (nth 1 ; start of innermost containing list
(save-excursion (beginning-of-line)
(goto-char (1+ p)) ; enclosing block on the same line
(skip-chars-forward " \t")
(vector 'code-start-in-block containing-sexp char-after
(and delim (not is-block)) ; is a HASH
old-indent ; brace first thing on a line
t (point) ; have something before...
;; Get initial indentation of the line we are on.
;; If line starts with label, calculate label indentation
(vector 'code-start-in-block containing-sexp char-after
(and delim (not is-block)) ; is a HASH
old-indent ; brace first thing on a line
nil (point))))))))))))))) ; nothing interesting before
(defvar cperl-indent-rules-alist
'((pod nil) ; via `syntax-type' property
(here-doc nil) ; via `syntax-type' property
(here-doc-delim nil) ; via `syntax-type' property
(format nil) ; via `syntax-type' property
(in-pod nil) ; via `in-pod' property
(comment-special:at-beginning-of-line nil)
(string t)
(comment nil))
"Alist of indentation rules for CPerl mode.
The values mean:
nil: do not indent;
number: add this amount of indentation.")
(defun cperl-calculate-indent (&optional parse-data) ; was parse-start
"Return appropriate indentation for current line as Perl code.
In usual case returns an integer: the column to indent to.
Returns nil if line starts inside a string, t if in a comment.
Will not correct the indentation for labels, but will correct it for braces
and closing parentheses and brackets."
;; This code is still a broken architecture: in some cases we need to
;; compensate for some modifications which `cperl-indent-line' will add later
(let ((i (cperl-sniff-for-indent parse-data)) what p)
;;((or (null i) (eq i t) (numberp i))
;; i)
((vectorp i)
(setq what (assoc (elt i 0) cperl-indent-rules-alist))
(let ((action (cadr what)))
(cond ((fboundp action) (apply action (list i parse-data)))
((numberp action) (+ action (current-indentation)))
(t 0))))
;; Indenters for regular expressions with //x and qw()
((eq 'REx-part2 (elt i 0)) ;; [self start] start of /REP in s//REP/x
(goto-char (elt i 1))
(condition-case nil ; Use indentation of the 1st part
(forward-sexp -1))
((eq 'indentable (elt i 0)) ; Indenter for REGEXP qw() etc
(cond ;;; [indentable terminator start-pos is-block]
((eq 'terminator (elt i 1)) ; Lone terminator of "indentable string"
(goto-char (elt i 2)) ; After opening parens
(1- (current-column)))
((eq 'first-line (elt i 1)); [indentable first-line start-pos]
(goto-char (elt i 2))
(+ (or cperl-regexp-indent-step cperl-indent-level)
((eq 'cont-line (elt i 1)); [indentable cont-line pos prev-pos first-char start-pos]
;; Indent as the level after closing parens
(goto-char (elt i 2)) ; indent line
(skip-chars-forward " \t)") ; Skip closing parens
(setq p (point))
(goto-char (elt i 3)) ; previous line
(skip-chars-forward " \t)") ; Skip closing parens
;; Number of parens in between:
(setq p (nth 0 (parse-partial-sexp (point) p))
what (elt i 4)) ; First char on current line
(goto-char (elt i 3)) ; previous line
(+ (* p (or cperl-regexp-indent-step cperl-indent-level))
(cond ((eq what ?\) )
(- cperl-close-paren-offset)) ; compensate
((eq what ?\| )
(- (or cperl-regexp-indent-step cperl-indent-level)))
(t 0))
(if (eq (following-char) ?\| )
(or cperl-regexp-indent-step cperl-indent-level)
(error "Unrecognized value of indent: %s" i))))
;; Indenter for stuff at toplevel
((eq 'toplevel (elt i 0)) ;; [toplevel start char-after state immed-after-block]
(+ (save-excursion ; To beg-of-defun, or end of last sexp
(goto-char (elt i 1)) ; start = Good place to start parsing
(- (current-indentation) ;
(if (elt i 4) cperl-indent-level 0))) ; immed-after-block
(if (eq (elt i 2) ?{) cperl-continued-brace-offset 0) ; char-after
;; Look at previous line that's at column 0
;; to determine whether we are in top-level decls
;; or function's arg decls. Set basic-indent accordingly.
;; Now add a little if this is a continuation line.
(if (elt i 3) ; state (XXX What is the semantic???)
;; Indenter for stuff in "parentheses" (or brackets, braces-as-hash)
((eq 'in-parens (elt i 0))
;; in-parens char-after old-indent-point is-brace containing-sexp
;; group is an expression, not a block:
;; indent to just after the surrounding open parens,
;; skip blanks if we do not close the expression.
(+ (progn
(goto-char (elt i 2)) ; old-indent-point
(if (and (elt i 3) ; is-brace
(eq (elt i 1) ?\})) ; char-after
;; Correct indentation of trailing ?\}
(+ cperl-indent-level cperl-close-paren-offset)
;; Indenter for continuation lines
((eq 'continuation (elt i 0))
;; [continuation statement-start char-after is-block is-brace]
(goto-char (elt i 1)) ; statement-start
(+ (if (or (memq (elt i 2) (append "}])" nil)) ; char-after
(eq 'continuation ; do not repeat cperl-close-paren-offset
(elt (cperl-sniff-for-indent parse-data) 0)))
0 ; Closing parenth
(if (or (elt i 3) ; is-block
(not (elt i 4)) ; is-brace
(not (eq (elt i 2) ?\}))) ; char-after
;; Now it is a hash reference
(+ cperl-indent-level cperl-close-paren-offset))
;; Labels do not take :: ...
(if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
(if (> (current-indentation) cperl-min-label-indent)
(- (current-indentation) cperl-label-offset)
;; Do not move `parse-data', this should
;; be quick anyway (this comment comes
;; from different location):
(if (eq (elt i 2) ?\{) ; char-after
cperl-continued-brace-offset 0)))
;; Indenter for lines in a block which are not leading lines
((eq 'have-prev-sibling (elt i 0))
;; [have-prev-sibling sibling-beg colon-line-end block-start]
(goto-char (elt i 1)) ; sibling-beg
(if (> (elt i 2) (point)) ; colon-line-end; have label before point
(if (> (current-indentation)
(- (current-indentation) cperl-label-offset)
;; Do not believe: `max' was involved in calculation of indent
(+ cperl-indent-level
(goto-char (elt i 3)) ; block-start
;; Indenter for the first line in a block
((eq 'code-start-in-block (elt i 0))
;;[code-start-in-block before-brace char-after
;; is-a-HASH-ref brace-is-first-thing-on-a-line
;; group-starts-before-start-of-sub start-of-control-group]
(goto-char (elt i 1))
;; For open brace in column zero, don't let statement
;; start there too. If cperl-indent-level=0,
;; use cperl-brace-offset + cperl-continued-statement-offset instead.
(+ (if (and (bolp) (zerop cperl-indent-level))
(+ cperl-brace-offset cperl-continued-statement-offset)
(if (and (elt i 3) ; is-a-HASH-ref
(eq (elt i 2) ?\})) ; char-after: End of a hash reference
(+ cperl-indent-level cperl-close-paren-offset)
;; Unless openbrace is the first nonwhite thing on the line,
;; add the cperl-brace-imaginary-offset.
(if (elt i 4) 0 ; brace-is-first-thing-on-a-line
(goto-char (elt i 6)) ; start-of-control-group
(if (elt i 5) ; group-starts-before-start-of-sub
;; Get initial indentation of the line we are on.
;; If line starts with label, calculate label indentation
(if (save-excursion
(looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
(if (> (current-indentation) cperl-min-label-indent)
(- (current-indentation) cperl-label-offset)
;; Do not move `parse-data', this should
;; be quick anyway:
(error "Unrecognized value of indent: %s" i))))
(error "Got strange value of indent: %s" i))))))
(defun cperl-calculate-indent-within-comment ()
"Return the indentation amount for line, assuming that
the current line is to be regarded as part of a block comment."
(let (end star-start)
(skip-chars-forward " \t")
(setq end (point))
(and (= (following-char) ?#)
(forward-line -1)
(setq end (point)))
(goto-char end)
(defun cperl-to-comment-or-eol ()
"Go to position before comment on the current line, or to end of line.
Returns true if comment is found. In POD will not move the point."
;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
;; then looks for literal # or end-of-line.
(let (state stop-in cpoint (lim (progn (end-of-line) (point))) pr e)
(or cperl-font-locking
(cperl-update-syntaxification lim lim))
(if (setq pr (get-text-property (point) 'syntax-type))
(setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
(if (or (eq pr 'pod)
(if (or (not e) (> e lim)) ; deep inside a group
(re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
(if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
;; Else - need to do it the hard way
(and (and e (<= e lim))
(goto-char e))
(while (not stop-in)
(setq state (parse-partial-sexp (point) lim nil nil nil t))
; stop at comment
;; If fails (beginning-of-line inside sexp), then contains not-comment
(if (nth 4 state) ; After `#';
; (nth 2 state) can be
; beginning of m,s,qq and so
; on
(if (nth 2 state)
(setq cpoint (point))
(goto-char (nth 2 state))
((looking-at "\\(s\\|tr\\)\\>")
(or (re-search-forward
"\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
lim 'move)
(setq stop-in t)))
((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
(or (re-search-forward
"\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
lim 'move)
(setq stop-in t)))
(t ; It was fair comment
(setq stop-in t) ; Finish
(goto-char (1- cpoint)))))
(setq stop-in t) ; Finish
(forward-char -1))
(setq stop-in t))) ; Finish
(nth 4 state))))
(defsubst cperl-modify-syntax-type (at how)
(if (< at (point-max))
(put-text-property at (1+ at) 'syntax-table how)
(put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
(defun cperl-protect-defun-start (s e)
;; C code looks for "^\\s(" to skip comment backward in "hard" situations
(goto-char s)
(while (re-search-forward "^\\s(" e 'to-end)
(put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
(defun cperl-commentify (bb e string &optional noface)
(if cperl-use-syntax-table-text-property
(if (eq noface 'n) ; Only immediate
;; We suppose that e is _after_ the end of construction, as after eol.
(setq string (if string cperl-st-sfence cperl-st-cfence))
(if (> bb (- e 2))
;; one-char string/comment?!
(cperl-modify-syntax-type bb cperl-st-punct)
(cperl-modify-syntax-type bb string)
(cperl-modify-syntax-type (1- e) string))
(if (and (eq string cperl-st-sfence) (> (- e 2) bb))
(put-text-property (1+ bb) (1- e)
'syntax-table cperl-string-syntax-table))
(cperl-protect-defun-start bb e))
;; Fontify
(or noface
(not cperl-pod-here-fontify)
(put-text-property bb e 'face (if string 'font-lock-string-face
(defvar cperl-starters '(( ?\( . ?\) )
( ?\[ . ?\] )
( ?\{ . ?\} )
( ?\< . ?\> )))
(defun cperl-cached-syntax-table (st)
"Get a syntax table cached in ST, or create and cache into ST a syntax table.
All the entries of the syntax table are \".\", except for a backslash, which
is quoting."
(if (car-safe st)
(car st)
(setcar st (make-syntax-table))
(setq st (car st))
(let ((i 0))
(while (< i 256)
(modify-syntax-entry i "." st)
(setq i (1+ i))))
(modify-syntax-entry ?\\ "\\" st)
(defun cperl-forward-re (lim end is-2arg st-l err-l argument
&optional ostart oend)
"Find the end of a regular expression or a stringish construct (q[] etc).
The point should be before the starting delimiter.
Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
is s/// or tr/// like expression. If END is nil, generates an error
message if needed. If SET-ST is non-nil, will use (or generate) a
cached syntax table in ST-L. If ERR-L is non-nil, will store the
error message in its CAR (unless it already contains some error
message). ARGUMENT should be the name of the construct (used in error
messages). OSTART, OEND may be set in recursive calls when processing
the second argument of 2ARG construct.
Works *before* syntax recognition is done. In IS-2ARG situation may
modify syntax-type text property if the situation is too hard."
(let (b starter ender st i i2 go-forward reset-st set-st)
(skip-chars-forward " \t")
;; ender means matching-char matcher.
(setq b (point)
starter (if (eobp) 0 (char-after b))
ender (cdr (assoc starter cperl-starters)))
;; What if starter == ?\\ ????
(setq st (cperl-cached-syntax-table st-l))
(setq set-st t)
;; Whether we have an intermediate point
(setq i nil)
;; Prepare the syntax table:
(if (not ender) ; m/blah/, s/x//, s/x/y/
(modify-syntax-entry starter "$" st)
(modify-syntax-entry starter (concat "(" (list ender)) st)
(modify-syntax-entry ender (concat ")" (list starter)) st))
(condition-case bb
;; We use `$' syntax class to find matching stuff, but $$
;; is recognized the same as $, so we need to check this manually.
(if (and (eq starter (char-after (cperl-1+ b)))
(not ender))
;; $ has TeXish matching rules, so $$ equiv $...
(forward-char 2)
(setq reset-st (syntax-table))
(set-syntax-table st)
(forward-sexp 1)
(if (<= (point) (1+ b))
(error "Unfinished regular expression"))
(set-syntax-table reset-st)
(setq reset-st nil)
;; Now the problem is with m;blah;;
(and (not ender)
(eq (preceding-char)
(char-after (- (point) 2)))
(forward-char -2)
(= 0 (% (skip-chars-backward "\\\\") 2)))
(forward-char -1)))
;; Now we are after the first part.
(and is-2arg ; Have trailing part
(not ender)
(eq (following-char) starter) ; Empty trailing part
(or (eq (char-syntax (following-char)) ?.)
;; Make trailing letter into punctuation
(cperl-modify-syntax-type (point) cperl-st-punct))
(setq is-2arg nil go-forward t))) ; Ignore the tail
(if is-2arg ; Not number => have second part
(setq i (point) i2 i)
(if ender
(if (memq (following-char) '(?\s ?\t ?\n ?\f))
(if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
(goto-char (match-end 0))
(skip-chars-forward " \t\n\f"))
(setq i2 (point))))
(forward-char -1))
(modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
(if ender (modify-syntax-entry ender "." st))
(setq set-st nil)
(setq ender (cperl-forward-re lim end nil st-l err-l
argument starter ender)
ender (nth 2 ender)))))
(error (goto-char lim)
(setq set-st nil)
(if reset-st
(set-syntax-table reset-st))
(or end
"End of `%s%s%c ... %c' string/RE not found: %s"
(if ostart (format "%c ... %c" ostart (or oend ostart)) "")
starter (or ender starter) bb)
(or (car err-l) (setcar err-l b)))))
(if set-st
(modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
(if ender (modify-syntax-entry ender "." st))))
;; i: have 2 args, after end of the first arg
;; i2: start of the second arg, if any (before delim if `ender').
;; ender: the last arg bounded by parens-like chars, the second one of them
;; starter: the starting delimiter of the first arg
;; go-forward: has 2 args, and the second part is empty
(list i i2 ender starter go-forward)))
(defun cperl-forward-group-in-re (&optional st-l)
"Find the end of a group in a REx.
Return the error message (if any). Does not work if delimiter is `)'.
Works before syntax recognition is done."
;; Works *before* syntax recognition is done
(or st-l (setq st-l (list nil))) ; Avoid overwriting '()
(let (st b reset-st)
(condition-case b
(setq st (cperl-cached-syntax-table st-l))
(modify-syntax-entry ?\( "()" st)
(modify-syntax-entry ?\) ")(" st)
(setq reset-st (syntax-table))
(set-syntax-table st)
(forward-sexp 1))
(error (message
"cperl-forward-group-in-re: error %s" b)))
;; now restore the initial state
(if st
(modify-syntax-entry ?\( "." st)
(modify-syntax-entry ?\) "." st)))
(if reset-st
(set-syntax-table reset-st))
(defvar font-lock-string-face)
;;(defvar font-lock-reference-face)
(defvar font-lock-constant-face)
(defsubst cperl-postpone-fontification (b e type val &optional now)
;; Do after syntactic fontification?
(if cperl-syntaxify-by-font-lock
(or now (put-text-property b e 'cperl-postpone (cons type val)))
(put-text-property b e type val)))
;;; Here is how the global structures (those which cannot be
;;; recognized locally) are marked:
;; a) PODs:
;; Start-to-end is marked `in-pod' ==> t
;; Each non-literal part is marked `syntax-type' ==> `pod'
;; Each literal part is marked `syntax-type' ==> `in-pod'
;; b) HEREs:
;; Start-to-end is marked `here-doc-group' ==> t
;; The body is marked `syntax-type' ==> `here-doc'
;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
;; c) FORMATs:
;; First line (to =) marked `first-format-line' ==> t
;; After-this--to-end is marked `syntax-type' ==> `format'
;; d) 'Q'uoted string:
;; part between markers inclusive is marked `syntax-type' ==> `string'
;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
;; second part of s///e is marked `syntax-type' ==> `multiline'
;; e) Attributes of subroutines: `attrib-group' ==> t
;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
;;; In addition, some parts of RExes may be marked as `REx-interpolated'
;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
(defun cperl-unwind-to-safe (before &optional end)
;; if BEFORE, go to the previous start-of-line on each step of unwinding
(let ((pos (point)) opos)
(while (and pos (progn
(get-text-property (setq pos (point)) 'syntax-type)))
(setq opos pos
pos (cperl-beginning-of-property pos 'syntax-type))
(if (eq pos (point-min))
(setq pos nil))
(if pos
(if before
(goto-char (cperl-1- pos))
(setq pos (point)))
(goto-char (setq pos (cperl-1- pos))))
;; Up to the start
(goto-char (point-min))))
;; Skip empty lines
(and (looking-at "\n*=")
(/= 0 (skip-chars-backward "\n"))
(setq pos (point))
(if end
;; Do the same for end, going small steps
(while (and end (get-text-property end 'syntax-type))
(setq pos end
end (next-single-property-change end 'syntax-type nil (point-max)))
(if end (progn (goto-char end)
(or (bolp) (forward-line 1))
(setq end (point)))))
(or end pos)))))
;;; These are needed for byte-compile (at least with v19)
(defvar cperl-nonoverridable-face)
(defvar font-lock-variable-name-face)
(defvar font-lock-function-name-face)
(defvar font-lock-keyword-face)
(defvar font-lock-builtin-face)
(defvar font-lock-type-face)
(defvar font-lock-comment-face)
(defvar font-lock-warning-face)
(defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
"Syntaxically mark (and fontify) attributes of a subroutine.
Should be called with the point before leading colon of an attribute."
;; Works *before* syntax recognition is done
(or st-l (setq st-l (list nil))) ; Avoid overwriting '()
(let (st b p reset-st after-first (start (point)) start1 end1)
(condition-case b
(while (looking-at
"\\(" ; 1=optional? colon
":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
(if after-first "?" "")
;; No space between name and paren allowed...
"\\(\\sw+\\)" ; 3=name
"\\((\\)?")) ; 4=optional paren
(and (match-beginning 1)
(match-beginning 0) (cperl-1+ (match-beginning 0))
'face font-lock-constant-face))
(setq start1 (match-beginning 3) end1 (match-end 3))
(cperl-postpone-fontification start1 end1
'face font-lock-constant-face)
(goto-char end1) ; end or before `('
(if (match-end 4) ; Have attribute arguments...
(if st nil
(setq st (cperl-cached-syntax-table st-l))
(modify-syntax-entry ?\( "()" st)
(modify-syntax-entry ?\) ")(" st))
(setq reset-st (syntax-table) p (point))
(set-syntax-table st)
(forward-sexp 1)
(set-syntax-table reset-st)
(setq reset-st nil)
(cperl-commentify p (point) t))) ; mark as string
(forward-comment (buffer-size))
(setq after-first t))
(error (message
"L%d: attribute `%s': %s"
(count-lines (point-min) (point))
(and start1 end1 (buffer-substring start1 end1)) b)
(setq start nil)))
(and start
(put-text-property start (point)
'attrib-group (if (looking-at "{") t 0))
(and pos
(< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
;; Apparently, we do not need `multiline': faces added now
(put-text-property (+ 3 pos) (cperl-1+ (point))
'syntax-type 'sub-decl))
(and b-fname ; Fontify here: the following condition
(cperl-postpone-fontification ; is too hard to determine by
b-fname e-fname 'face ; a REx, so do it here
(if (looking-at "{"