1 ;;; cperl-mode.el --- Perl code editing commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 ;; 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
5 ;; Free Software Foundation, Inc.
7 ;; Author: Ilya Zakharevich and Bob Olson
8 ;; Maintainer: Ilya Zakharevich <ilyaz@cpan.org>
9 ;; Keywords: languages, Perl
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
28 ;;; Corrections made by Ilya Zakharevich ilyaz@cpan.org
32 ;; You can either fine-tune the bells and whistles of this mode or
33 ;; bulk enable them by putting
35 ;; (setq cperl-hairy t)
37 ;; in your .emacs file. (Emacs rulers do not consider it politically
38 ;; correct to make whistles enabled by default.)
40 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
41 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
42 ;; `cperl-praise', `cperl-speed'. <<<<<<
44 ;; The mode information (on C-h m) provides some customization help.
45 ;; If you use font-lock feature of this mode, it is advisable to use
46 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
48 ;; Faces used now: three faces for first-class and second-class keywords
49 ;; and control flow words, one for each: comments, string, labels,
50 ;; functions definitions and packages, arrays, hashes, and variable
51 ;; definitions. If you do not see all these faces, your font-lock does
52 ;; not define them, so you need to define them manually.
54 ;; This mode supports font-lock, imenu and mode-compile. In the
55 ;; hairy version font-lock is on, but you should activate imenu
56 ;; yourself (note that mode-compile is not standard yet). Well, you
57 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
58 ;; to bind it like that:
60 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
62 ;;; Font lock bugs as of v4.32:
64 ;; The following kinds of Perl code erroneously start strings:
66 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
67 ;; likewise with m, tr, y, q, qX instead of s
71 (defvar vc-rcs-header)
72 (defvar vc-sccs-header)
81 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
82 (defvar cperl-can-font-lock
84 (and (boundp 'emacs-major-version)
86 (> emacs-major-version 20)))))
87 (if cperl-can-font-lock
89 (defvar msb-menu-cond)
90 (defvar gud-perldb-history)
91 (defvar font-lock-background-mode) ; not in Emacs
92 (defvar font-lock-display-type) ; ditto
93 (defvar paren-backwards-message) ; Not in newer XEmacs?
94 (or (fboundp 'defgroup)
95 (defmacro defgroup (name val doc &rest arr)
97 (or (fboundp 'custom-declare-variable)
98 (defmacro defcustom (name val doc &rest arr)
99 (` (defvar (, name) (, val) (, doc)))))
100 (or (and (fboundp 'custom-declare-variable)
101 (string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
102 (defmacro defface (&rest arr)
104 ;; Avoid warning (tmp definitions)
105 (or (fboundp 'x-color-defined-p)
106 (defmacro x-color-defined-p (col)
107 (cond ((fboundp 'color-defined-p) (` (color-defined-p (, col))))
109 ((fboundp 'valid-color-name-p) (` (valid-color-name-p (, col))))
111 ((fboundp 'x-valid-color-name-p) (` (x-valid-color-name-p (, col))))
112 (t '(error "Cannot implement color-defined-p")))))
113 (defmacro cperl-is-face (arg) ; Takes quoted arg
114 (cond ((fboundp 'find-face)
115 (` (find-face (, arg))))
116 (;;(and (fboundp 'face-list)
119 (` (member (, arg) (and (fboundp 'face-list)
122 (` (boundp (, arg))))))
123 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
124 (cond ((fboundp 'make-face)
125 (` (make-face (quote (, arg)))))
127 (` (defvar (, arg) (quote (, arg)) (, descr))))))
128 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
130 (or (cperl-is-face (quote (, arg)))
131 (cperl-make-face (, arg) (, descr)))
132 (or (boundp (quote (, arg))) ; We use unquoted variants too
133 (defvar (, arg) (quote (, arg)) (, descr))))))
135 (defmacro cperl-etags-snarf-tag (file line)
137 (beginning-of-line 2)
138 (list (, file) (, line)))))
139 (defmacro cperl-etags-snarf-tag (file line)
140 (` (etags-snarf-tag))))
142 (defmacro cperl-etags-goto-tag-location (elt)
144 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
145 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
146 ;; Probably will not work due to some save-excursion???
147 ;; Or save-file-position?
148 ;; (message "Did I get to line %s?" (elt (, elt) 1))
149 (goto-line (string-to-int (elt (, elt) 1)))))
151 (defmacro cperl-etags-goto-tag-location (elt)
152 (` (etags-goto-tag-location (, elt))))))
154 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
156 (defvar cperl-can-font-lock
158 (and (boundp 'emacs-major-version)
160 (> emacs-major-version 20)))))
162 (defun cperl-choose-color (&rest list)
166 (if (or (x-color-defined-p (car list))
168 (setq answer (car list))))
169 (setq list (cdr list)))
173 "Major mode for editing Perl code."
178 (defgroup cperl-indentation-details nil
183 (defgroup cperl-affected-by-hairy nil
184 "Variables affected by `cperl-hairy'."
188 (defgroup cperl-autoinsert-details nil
189 "Auto-insert tuneup."
193 (defgroup cperl-faces nil
194 "Fontification colors."
195 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
199 (defgroup cperl-speed nil
200 "Speed vs. validity tuneup."
204 (defgroup cperl-help-system nil
205 "Help system tuneup."
210 (defcustom cperl-extra-newline-before-brace nil
211 "*Non-nil means that if, elsif, while, until, else, for, foreach
212 and do constructs look like:
223 :group 'cperl-autoinsert-details)
225 (defcustom cperl-extra-newline-before-brace-multiline
226 cperl-extra-newline-before-brace
227 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
228 for constructs with multiline if/unless/while/until/for/foreach condition."
230 :group 'cperl-autoinsert-details)
232 (defcustom cperl-indent-level 2
233 "*Indentation of CPerl statements with respect to containing block."
235 :group 'cperl-indentation-details)
237 (defcustom cperl-lineup-step nil
238 "*`cperl-lineup' will always lineup at multiple of this number.
239 If nil, the value of `cperl-indent-level' will be used."
240 :type '(choice (const nil) integer)
241 :group 'cperl-indentation-details)
243 (defcustom cperl-brace-imaginary-offset 0
244 "*Imagined indentation of a Perl open brace that actually follows a statement.
245 An open brace following other text is treated as if it were this far
246 to the right of the start of its line."
248 :group 'cperl-indentation-details)
250 (defcustom cperl-brace-offset 0
251 "*Extra indentation for braces, compared with other text in same context."
253 :group 'cperl-indentation-details)
254 (defcustom cperl-label-offset -2
255 "*Offset of CPerl label lines relative to usual indentation."
257 :group 'cperl-indentation-details)
258 (defcustom cperl-min-label-indent 1
259 "*Minimal offset of CPerl label lines."
261 :group 'cperl-indentation-details)
262 (defcustom cperl-continued-statement-offset 2
263 "*Extra indent for lines not starting new statements."
265 :group 'cperl-indentation-details)
266 (defcustom cperl-continued-brace-offset 0
267 "*Extra indent for substatements that start with open-braces.
268 This is in addition to cperl-continued-statement-offset."
270 :group 'cperl-indentation-details)
271 (defcustom cperl-close-paren-offset -1
272 "*Extra indent for substatements that start with close-parenthesis."
274 :group 'cperl-indentation-details)
276 (defcustom cperl-indent-wrt-brace t
277 "*Non-nil means indent statements in if/etc block relative brace, not if/etc.
278 Versions 5.2 ... 5.20 behaved as if this were `nil'."
280 :group 'cperl-indentation-details)
282 (defcustom cperl-auto-newline nil
283 "*Non-nil means automatically newline before and after braces,
284 and after colons and semicolons, inserted in CPerl code. The following
285 \\[cperl-electric-backspace] will remove the inserted whitespace.
286 Insertion after colons requires both this variable and
287 `cperl-auto-newline-after-colon' set."
289 :group 'cperl-autoinsert-details)
291 (defcustom cperl-autoindent-on-semi nil
292 "*Non-nil means automatically indent after insertion of (semi)colon.
293 Active if `cperl-auto-newline' is false."
295 :group 'cperl-autoinsert-details)
297 (defcustom cperl-auto-newline-after-colon nil
298 "*Non-nil means automatically newline even after colons.
299 Subject to `cperl-auto-newline' setting."
301 :group 'cperl-autoinsert-details)
303 (defcustom cperl-tab-always-indent t
304 "*Non-nil means TAB in CPerl mode should always reindent the current line,
305 regardless of where in the line point is when the TAB command is used."
307 :group 'cperl-indentation-details)
309 (defcustom cperl-font-lock nil
310 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
311 Can be overwritten by `cperl-hairy' if nil."
312 :type '(choice (const null) boolean)
313 :group 'cperl-affected-by-hairy)
315 (defcustom cperl-electric-lbrace-space nil
316 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
317 Can be overwritten by `cperl-hairy' if nil."
318 :type '(choice (const null) boolean)
319 :group 'cperl-affected-by-hairy)
321 (defcustom cperl-electric-parens-string "({[]})<"
322 "*String of parentheses that should be electric in CPerl.
323 Closing ones are electric only if the region is highlighted."
325 :group 'cperl-affected-by-hairy)
327 (defcustom cperl-electric-parens nil
328 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
329 Can be overwritten by `cperl-hairy' if nil."
330 :type '(choice (const null) boolean)
331 :group 'cperl-affected-by-hairy)
333 (defvar zmacs-regions) ; Avoid warning
335 (defcustom cperl-electric-parens-mark
337 (or (and (boundp 'transient-mark-mode) ; For Emacs
339 (and (boundp 'zmacs-regions) ; For XEmacs
341 "*Not-nil means that electric parens look for active mark.
342 Default is yes if there is visual feedback on mark."
344 :group 'cperl-autoinsert-details)
346 (defcustom cperl-electric-linefeed nil
347 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
348 In any case these two mean plain and hairy linefeeds together.
349 Can be overwritten by `cperl-hairy' if nil."
350 :type '(choice (const null) boolean)
351 :group 'cperl-affected-by-hairy)
353 (defcustom cperl-electric-keywords nil
354 "*Not-nil (and non-null) means keywords are electric in CPerl.
355 Can be overwritten by `cperl-hairy' if nil."
356 :type '(choice (const null) boolean)
357 :group 'cperl-affected-by-hairy)
359 (defcustom cperl-electric-backspace-untabify t
360 "*Not-nil means electric-backspace will untabify in CPerl."
362 :group 'cperl-autoinsert-details)
364 (defcustom cperl-hairy nil
365 "*Not-nil means most of the bells and whistles are enabled in CPerl.
366 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
367 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
368 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
369 `cperl-lazy-help-time'."
371 :group 'cperl-affected-by-hairy)
373 (defcustom cperl-comment-column 32
374 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
376 :group 'cperl-indentation-details)
378 (defcustom cperl-indent-comment-at-column-0 nil
379 "*Non-nil means that comment started at column 0 should be indentable."
381 :group 'cperl-indentation-details)
383 (defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
384 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
385 :type '(repeat string)
388 (defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
389 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
390 :type '(repeat string)
393 ;; This became obsolete...
394 (defvar cperl-vc-header-alist nil)
395 (make-obsolete-variable
396 'cperl-vc-header-alist
397 "use cperl-vc-rcs-header or cperl-vc-sccs-header instead.")
399 (defcustom cperl-clobber-mode-lists
402 (boundp 'interpreter-mode-alist)
403 (assoc "miniperl" interpreter-mode-alist)
404 (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
405 "*Whether to install us into `interpreter-' and `extension' mode lists."
409 (defcustom cperl-info-on-command-no-prompt nil
410 "*Not-nil (and non-null) means not to prompt on C-h f.
411 The opposite behavior is always available if prefixed with C-c.
412 Can be overwritten by `cperl-hairy' if nil."
413 :type '(choice (const null) boolean)
414 :group 'cperl-affected-by-hairy)
416 (defcustom cperl-clobber-lisp-bindings nil
417 "*Not-nil (and non-null) means not overwrite C-h f.
418 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
419 Can be overwritten by `cperl-hairy' if nil."
420 :type '(choice (const null) boolean)
421 :group 'cperl-affected-by-hairy)
423 (defcustom cperl-lazy-help-time nil
424 "*Not-nil (and non-null) means to show lazy help after given idle time.
425 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
426 :type '(choice (const null) (const nil) integer)
427 :group 'cperl-affected-by-hairy)
429 (defcustom cperl-pod-face 'font-lock-comment-face
430 "*Face for POD highlighting."
434 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
435 "*Face for POD highlighting.
436 Font for POD headers."
440 (defcustom cperl-here-face 'font-lock-string-face
441 "*Face for here-docs highlighting."
445 ;;; Some double-evaluation happened with font-locks... Needed with 21.2...
446 (defvar cperl-singly-quote-face cperl-xemacs-p)
448 (defcustom cperl-invalid-face 'underline
449 "*Face for highlighting trailing whitespace."
454 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
455 "*Not-nil after evaluation means to highlight POD and here-docs sections."
459 (defcustom cperl-fontify-m-as-s t
460 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
464 (defcustom cperl-highlight-variables-indiscriminately nil
465 "*Non-nil means perform additional highlighting on variables.
466 Currently only changes how scalar variables are highlighted.
467 Note that that variable is only read at initialization time for
468 the variable `cperl-font-lock-keywords-2', so changing it after you've
469 entered CPerl mode the first time will have no effect."
473 (defcustom cperl-pod-here-scan t
474 "*Not-nil means look for POD and here-docs sections during startup.
475 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
479 (defcustom cperl-regexp-scan t
480 "*Not-nil means make marking of regular expression more thorough.
481 Effective only with `cperl-pod-here-scan'."
485 (defcustom cperl-hook-after-change t
486 "*Not-nil means install hook to know which regions of buffer are changed.
487 May significantly speed up delayed fontification. Changes take effect
492 (defcustom cperl-imenu-addback nil
493 "*Not-nil means add backreferences to generated `imenu's.
494 May require patched `imenu' and `imenu-go'. Obsolete."
496 :group 'cperl-help-system)
498 (defcustom cperl-max-help-size 66
499 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
500 :type '(choice integer (const nil))
501 :group 'cperl-help-system)
503 (defcustom cperl-shrink-wrap-info-frame t
504 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
506 :group 'cperl-help-system)
508 (defcustom cperl-info-page "perl"
509 "*Name of the info page containing perl docs.
510 Older version of this page was called `perl5', newer `perl'."
512 :group 'cperl-help-system)
514 (defcustom cperl-use-syntax-table-text-property
515 (boundp 'parse-sexp-lookup-properties)
516 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
520 (defcustom cperl-use-syntax-table-text-property-for-tags
521 cperl-use-syntax-table-text-property
522 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
526 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
527 "*Regexp to match files to scan when generating TAGS."
531 (defcustom cperl-noscan-files-regexp
532 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
533 "*Regexp to match files/dirs to skip when generating TAGS."
537 (defcustom cperl-regexp-indent-step nil
538 "*Indentation used when beautifying regexps.
539 If nil, the value of `cperl-indent-level' will be used."
540 :type '(choice integer (const nil))
541 :group 'cperl-indentation-details)
543 (defcustom cperl-indent-left-aligned-comments t
544 "*Non-nil means that the comment starting in leftmost column should indent."
546 :group 'cperl-indentation-details)
548 (defcustom cperl-under-as-char nil
549 "*Non-nil means that the _ (underline) should be treated as word char."
553 (defcustom cperl-extra-perl-args ""
554 "*Extra arguments to use when starting Perl.
555 Currently used with `cperl-check-syntax' only."
559 (defcustom cperl-message-electric-keyword t
560 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
562 :group 'cperl-help-system)
564 (defcustom cperl-indent-region-fix-constructs 1
565 "*Amount of space to insert between `}' and `else' or `elsif'
566 in `cperl-indent-region'. Set to nil to leave as is. Values other
567 than 1 and nil will probably not work."
568 :type '(choice (const nil) (const 1))
569 :group 'cperl-indentation-details)
571 (defcustom cperl-break-one-line-blocks-when-indent t
572 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
573 need to be reformatted into multiline ones when indenting a region."
575 :group 'cperl-indentation-details)
577 (defcustom cperl-fix-hanging-brace-when-indent t
578 "*Non-nil means that BLOCK-end `}' may be put on a separate line
579 when indenting a region.
580 Braces followed by else/elsif/while/until are excepted."
582 :group 'cperl-indentation-details)
584 (defcustom cperl-merge-trailing-else t
585 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
586 may be merged to be on the same line when indenting a region."
588 :group 'cperl-indentation-details)
590 (defcustom cperl-indent-parens-as-block nil
591 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
592 but for trailing \",\" inside the group, which won't increase indentation.
593 One should tune up `cperl-close-paren-offset' as well."
595 :group 'cperl-indentation-details)
597 (defcustom cperl-syntaxify-by-font-lock
598 (and cperl-can-font-lock
599 (boundp 'parse-sexp-lookup-properties))
600 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
601 :type '(choice (const message) boolean)
604 (defcustom cperl-syntaxify-unwind
606 "*Non-nil means that CPerl unwinds to a start of a long construction
607 when syntaxifying a chunk of buffer."
611 (defcustom cperl-syntaxify-for-menu
613 "*Non-nil means that CPerl syntaxifies up to the point before showing menu.
614 This way enabling/disabling of menu items is more correct."
618 (defcustom cperl-ps-print-face-properties
619 '((font-lock-keyword-face nil nil bold shadow)
620 (font-lock-variable-name-face nil nil bold)
621 (font-lock-function-name-face nil nil bold italic box)
622 (font-lock-constant-face nil "LightGray" bold)
623 (cperl-array-face nil "LightGray" bold underline)
624 (cperl-hash-face nil "LightGray" bold italic underline)
625 (font-lock-comment-face nil "LightGray" italic)
626 (font-lock-string-face nil nil italic underline)
627 (cperl-nonoverridable-face nil nil italic underline)
628 (font-lock-type-face nil nil underline)
629 (font-lock-warning-face nil "LightGray" bold italic box)
630 (underline nil "LightGray" strikeout))
631 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
632 :type '(repeat (cons symbol
633 (cons (choice (const nil) string)
634 (cons (choice (const nil) string)
638 (defvar cperl-dark-background
639 (cperl-choose-color "navy" "os2blue" "darkgreen"))
640 (defvar cperl-dark-foreground
641 (cperl-choose-color "orchid1" "orange"))
643 (defface cperl-nonoverridable-face
644 `((((class grayscale) (background light))
645 (:background "Gray90" :slant italic :underline t))
646 (((class grayscale) (background dark))
647 (:foreground "Gray80" :slant italic :underline t :weight bold))
648 (((class color) (background light))
649 (:foreground "chartreuse3"))
650 (((class color) (background dark))
651 (:foreground ,cperl-dark-foreground))
652 (t (:weight bold :underline t)))
653 "Font Lock mode face used non-overridable keywords and modifiers of regexps."
656 (defface cperl-array-face
657 `((((class grayscale) (background light))
658 (:background "Gray90" :weight bold))
659 (((class grayscale) (background dark))
660 (:foreground "Gray80" :weight bold))
661 (((class color) (background light))
662 (:foreground "Blue" :background "lightyellow2" :weight bold))
663 (((class color) (background dark))
664 (:foreground "yellow" :background ,cperl-dark-background :weight bold))
666 "Font Lock mode face used to highlight array names."
669 (defface cperl-hash-face
670 `((((class grayscale) (background light))
671 (:background "Gray90" :weight bold :slant italic))
672 (((class grayscale) (background dark))
673 (:foreground "Gray80" :weight bold :slant italic))
674 (((class color) (background light))
675 (:foreground "Red" :background "lightyellow2" :weight bold :slant italic))
676 (((class color) (background dark))
677 (:foreground "Red" :background ,cperl-dark-background :weight bold :slant italic))
678 (t (:weight bold :slant italic)))
679 "Font Lock mode face used to highlight hash names."
684 ;;; Short extra-docs.
686 (defvar cperl-tips 'please-ignore-this-line
687 "Get maybe newer version of this package from
688 http://ilyaz.org/software/emacs
689 Subdirectory `cperl-mode' may contain yet newer development releases and/or
690 patches to related files.
692 For best results apply to an older Emacs the patches from
693 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
694 \(this upgrades syntax-parsing abilities of Emacsen v19.34 and
695 v20.2 up to the level of Emacs v20.3 - a must for a good Perl
696 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
698 Get support packages choose-color.el (or font-lock-extra.el before
699 19.30), imenu-go.el from the same place. \(Look for other files there
700 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
701 later you should use choose-color.el *instead* of font-lock-extra.el
702 \(and you will not get smart highlighting in C :-().
704 Note that to enable Compile choices in the menu you need to install
707 If your Emacs does not default to `cperl-mode' on Perl files, and you
708 want it to: put the following into your .emacs file:
710 (defalias 'perl-mode 'cperl-mode)
713 $CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
714 Also, one can generate a newer documentation running `pod2texi' converter
715 $CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
717 If you use imenu-go, run imenu on perl5-info buffer (you can do it
718 from Perl menu). If many files are related, generate TAGS files from
719 Tools/Tags submenu in Perl menu.
721 If some class structure is too complicated, use Tools/Hierarchy-view
722 from Perl menu, or hierarchic view of imenu. The second one uses the
723 current buffer only, the first one requires generation of TAGS from
724 Perl/Tools/Tags menu beforehand.
726 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
728 Switch auto-help on/off with Perl/Tools/Auto-help.
730 Though with contemporary Emaxen CPerl mode should maintain the correct
731 parsing of Perl even when editing, sometimes it may be lost. Fix this by
735 In cases of more severe confusion sometimes it is helpful to do
737 \\[load-library] cperl-mode RET
740 Before reporting (non-)problems look in the problem section of online
741 micro-docs on what I know about CPerl problems.")
743 (defvar cperl-problems 'please-ignore-this-line
744 "Description of problems in CPerl mode.
745 Some faces will not be shown on some versions of Emacs unless you
746 install choose-color.el, available from
747 http://ilyaz.org/software/emacs
749 `fill-paragraph' on a comment may leave the point behind the
750 paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
751 to detect it and bulk out).
753 See documentation of a variable `cperl-problems-old-emaxen' for the
754 problems which disappear if you upgrade Emacs to a reasonably new
755 version (20.3 for Emacs, and those of 2004 for XEmacs).")
757 (defvar cperl-problems-old-emaxen 'please-ignore-this-line
758 "Description of problems in CPerl mode specific for older Emacs versions.
760 Emacs had a _very_ restricted syntax parsing engine until version
761 20.1. Most problems below are corrected starting from this version of
762 Emacs, and all of them should be fixed in version 20.3. (Or apply
763 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
764 this respect (until 2003).
766 Note that even with newer Emacsen in some very rare cases the details
767 of interaction of `font-lock' and syntaxification may be not cleaned
768 up yet. You may get slightly different colors basing on the order of
769 fontification and syntaxification. Say, the initial faces is correct,
770 but editing the buffer breaks this.
772 Even with older Emacsen CPerl mode tries to corrects some Emacs
773 misunderstandings, however, for efficiency reasons the degree of
774 correction is different for different operations. The partially
775 corrected problems are: POD sections, here-documents, regexps. The
776 operations are: highlighting, indentation, electric keywords, electric
779 This may be confusing, since the regexp s#//#/#\; may be highlighted
780 as a comment, but it will be recognized as a regexp by the indentation
781 code. Or the opposite case, when a POD section is highlighted, but
782 may break the indentation of the following code (though indentation
783 should work if the balance of delimiters is not broken by POD).
785 The main trick (to make $ a \"backslash\") makes constructions like
786 ${aaa} look like unbalanced braces. The only trick I can think of is
787 to insert it as $ {aaa} (valid in perl5, not in perl4).
789 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
790 as /($|\\s)/. Note that such a transposition is not always possible.
792 The solution is to upgrade your Emacs or patch an older one. Note
793 that Emacs 20.2 has some bugs related to `syntax-table' text
794 properties. Patches are available on the main CPerl download site,
797 If these bugs cannot be fixed on your machine (say, you have an inferior
798 environment and cannot recompile), you may still disable all the fancy stuff
799 via `cperl-use-syntax-table-text-property'.")
801 (defvar cperl-praise 'please-ignore-this-line
802 "Advantages of CPerl mode.
804 0) It uses the newest `syntax-table' property ;-);
806 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
807 mode - but the latter number may have improved too in last years) even
808 with old Emaxen which do not support `syntax-table' property.
810 When using `syntax-table' property for syntax assist hints, it should
811 handle 99.995% of lines correct - or somesuch. It automatically
812 updates syntax assist hints when you edit your script.
814 2) It is generally believed to be \"the most user-friendly Emacs
815 package\" whatever it may mean (I doubt that the people who say similar
816 things tried _all_ the rest of Emacs ;-), but this was not a lonely
819 3) Everything is customizable, one-by-one or in a big sweep;
821 4) It has many easily-accessable \"tools\":
822 a) Can run program, check syntax, start debugger;
823 b) Can lineup vertically \"middles\" of rows, like `=' in
826 c) Can insert spaces where this impoves readability (in one
827 interactive sweep over the buffer);
828 d) Has support for imenu, including:
829 1) Separate unordered list of \"interesting places\";
830 2) Separate TOC of POD sections;
831 3) Separate list of packages;
832 4) Hierarchical view of methods in (sub)packages;
833 5) and functions (by the full name - with package);
834 e) Has an interface to INFO docs for Perl; The interface is
835 very flexible, including shrink-wrapping of
836 documentation buffer/frame;
837 f) Has a builtin list of one-line explanations for perl constructs.
838 g) Can show these explanations if you stay long enough at the
839 corresponding place (or on demand);
840 h) Has an enhanced fontification (using 3 or 4 additional faces
841 comparing to font-lock - basically, different
842 namespaces in Perl have different colors);
843 i) Can construct TAGS basing on its knowledge of Perl syntax,
844 the standard menu has 6 different way to generate
845 TAGS (if \"by directory\", .xs files - with C-language
846 bindings - are included in the scan);
847 j) Can build a hierarchical view of classes (via imenu) basing
848 on generated TAGS file;
849 k) Has electric parentheses, electric newlines, uses Abbrev
850 for electric logical constructs
852 with different styles of expansion (context sensitive
853 to be not so bothering). Electric parentheses behave
854 \"as they should\" in a presence of a visible region.
855 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
861 n) Highlights (by user-choice) either 3-delimiters constructs
862 (such as tr/a/b/), or regular expressions and `y/tr';
863 o) Highlights trailing whitespace;
864 p) Is able to manipulate Perl Regular Expressions to ease
865 conversion to a more readable form.
866 q) Can ispell POD sections and HERE-DOCs.
867 r) Understands comments and character classes inside regular
868 expressions; can find matching () and [] in a regular expression.
869 s) Allows indentation of //x-style regular expressions;
870 t) Highlights different symbols in regular expressions according
871 to their function; much less problems with backslashitis;
872 u) Allows to find regular expressions which contain interpolated parts.
874 5) The indentation engine was very smart, but most of tricks may be
875 not needed anymore with the support for `syntax-table' property. Has
876 progress indicator for indentation (with `imenu' loaded).
878 6) Indent-region improves inline-comments as well; also corrects
879 whitespace *inside* the conditional/loop constructs.
881 7) Fill-paragraph correctly handles multi-line comments;
883 8) Can switch to different indentation styles by one command, and restore
884 the settings present before the switch.
886 9) When doing indentation of control constructs, may correct
887 line-breaks/spacing between elements of the construct.
889 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
890 capable syntax engines).
892 11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
895 (defvar cperl-speed 'please-ignore-this-line
896 "This is an incomplete compendium of what is available in other parts
897 of CPerl documentation. (Please inform me if I skept anything.)
899 There is a perception that CPerl is slower than alternatives. This part
900 of documentation is designed to overcome this misconception.
902 *By default* CPerl tries to enable the most comfortable settings.
903 From most points of view, correctly working package is infinitely more
904 comfortable than a non-correctly working one, thus by default CPerl
905 prefers correctness over speed. Below is the guide how to change
906 settings if your preferences are different.
908 A) Speed of loading the file. When loading file, CPerl may perform a
909 scan which indicates places which cannot be parsed by primitive Emacs
910 syntax-parsing routines, and marks them up so that either
912 A1) CPerl may work around these deficiencies (for big chunks, mostly
913 PODs and HERE-documents), or
914 A2) On capable Emaxen CPerl will use improved syntax-handlings
915 which reads mark-up hints directly.
917 The scan in case A2 is much more comprehensive, thus may be slower.
919 User can disable syntax-engine-helping scan of A2 by setting
920 `cperl-use-syntax-table-text-property'
921 variable to nil (if it is set to t).
923 One can disable the scan altogether (both A1 and A2) by setting
924 `cperl-pod-here-scan'
927 B) Speed of editing operations.
929 One can add a (minor) speedup to editing operations by setting
930 `cperl-use-syntax-table-text-property'
931 variable to nil (if it is set to t). This will disable
932 syntax-engine-helping scan, thus will make many more Perl
933 constructs be wrongly recognized by CPerl, thus may lead to
934 wrongly matched parentheses, wrong indentation, etc.
936 One can unset `cperl-syntaxify-unwind'. This might speed up editing
937 of, say, long POD sections.")
939 (defvar cperl-tips-faces 'please-ignore-this-line
940 "CPerl mode uses following faces for highlighting:
942 `cperl-array-face' Array names
943 `cperl-hash-face' Hash names
944 `font-lock-comment-face' Comments, PODs and whatever is considered
945 syntaxically to be not code
946 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
947 2-arg operators s/y/tr/ or of RExen,
948 `font-lock-warning-face' Special-cased m// and s//foo/,
949 `font-lock-function-name-face' _ as a target of a file tests, file tests,
950 subroutine names at the moment of definition
951 (except those conflicting with Perl operators),
952 package names (when recognized), format names
953 `font-lock-keyword-face' Control flow switch constructs, declarators
954 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
955 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
956 literal parts and the terminator of formats
957 and whatever is syntaxically considered
959 `font-lock-type-face' Overridable keywords
960 `font-lock-variable-name-face' Variable declarations, indirect array and
961 hash names, POD headers/item names
962 `cperl-invalid' Trailing whitespace
964 Note that in several situations the highlighting tries to inform about
965 possible confusion, such as different colors for function names in
966 declarations depending on what they (do not) override, or special cases
967 m// and s/// which do not do what one would expect them to do.
969 Help with best setup of these faces for printout requested (for each of
970 the faces: please specify bold, italic, underline, shadow and box.)
972 In regular expressions (except character classes):
973 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs
974 `font-lock-constant-face': Delimiters
975 `font-lock-warning-face' Special-cased m// and s//foo/,
976 Mismatched closing delimiters, parens
977 we couldn't match, misplaced quantifiers,
978 unrecognized escape sequences
979 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
980 `font-lock-type-face' POSIX classes inside charclasses,
981 escape sequences with arguments (\x \23 \p \N)
982 and others match-a-char escape sequences
983 `font-lock-keyword-face' Capturing parens, and |
984 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
985 `font-lock-builtin-face' \"Remaining\" 0-length constructs, executable
986 parts of a REx, not-capturing parens
987 `font-lock-variable-name-face' Interpolated constructs, embedded code
988 `font-lock-comment-face' Embedded comments
994 ;;; Portability stuff:
996 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
997 `(define-key cperl-mode-map
999 `(if cperl-xemacs-p ,xemacs-key ,emacs-key)
1003 (defvar cperl-del-back-ch
1004 (car (append (where-is-internal 'delete-backward-char)
1005 (where-is-internal 'backward-delete-char-untabify)))
1006 "Character generated by key bound to `delete-backward-char'.")
1008 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
1009 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
1011 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
1014 ;; "Active regions" are on: use region only if active
1015 ;; "Active regions" are off: use region unconditionally
1016 (defun cperl-use-region-p ()
1017 (if zmacs-regions (mark) t)))
1018 (defun cperl-use-region-p ()
1019 (if transient-mark-mode mark-active t))
1020 (defun cperl-mark-active () mark-active))
1022 (defsubst cperl-enable-font-lock ()
1023 cperl-can-font-lock)
1025 (defun cperl-putback-char (c) ; Emacs 19
1026 (set 'unread-command-events (list c))) ; Avoid undefined warning
1029 (defun cperl-putback-char (c) ; XEmacs >= 19.12
1030 (setq unread-command-events (list (eval '(character-to-event c))))))
1032 (or (fboundp 'uncomment-region)
1033 (defun uncomment-region (beg end)
1035 (comment-region beg end -1)))
1037 (defvar cperl-do-not-fontify
1038 (if (string< emacs-version "19.30")
1041 "Text property which inhibits refontification.")
1043 (defsubst cperl-put-do-not-fontify (from to &optional post)
1044 ;; If POST, do not do it with postponed fontification
1045 (if (and post cperl-syntaxify-by-font-lock)
1047 (put-text-property (max (point-min) (1- from))
1048 to cperl-do-not-fontify t)))
1050 (defcustom cperl-mode-hook nil
1051 "Hook run by CPerl mode."
1055 (defvar cperl-syntax-state nil)
1056 (defvar cperl-syntax-done-to nil)
1057 (defvar cperl-emacs-can-parse (> (length (save-excursion
1058 (parse-partial-sexp (point) (point)))) 9))
1060 ;; Make customization possible "in reverse"
1061 (defsubst cperl-val (symbol &optional default hairy)
1063 ((eq (symbol-value symbol) 'null) default)
1064 (cperl-hairy (or hairy t))
1065 (t (symbol-value symbol))))
1068 (defun cperl-make-indent (column &optional minimum keep)
1069 "Makes indent of the current line the requested amount.
1070 Unless KEEP, removes the old indentation. Works around a bug in ancient
1072 (let ((prop (get-text-property (point) 'syntax-type)))
1074 (delete-horizontal-space))
1075 (indent-to column minimum)
1076 ;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
1078 (> (current-column) 0)
1081 (or (get-text-property (point) 'syntax-type)
1082 (and (looking-at "\\=[ \t]")
1083 (put-text-property (point) (match-end 0)
1084 'syntax-type prop)))))))
1086 ;;; Probably it is too late to set these guys already, but it can help later:
1088 ;;;(and cperl-clobber-mode-lists
1089 ;;;(setq auto-mode-alist
1090 ;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
1091 ;;;(and (boundp 'interpreter-mode-alist)
1092 ;;; (setq interpreter-mode-alist (append interpreter-mode-alist
1093 ;;; '(("miniperl" . perl-mode))))))
1099 '(imenu easymenu etags timer man info))
1100 (if (fboundp 'ps-extend-face-list)
1101 (defmacro cperl-ps-extend-face-list (arg)
1102 `(ps-extend-face-list ,arg))
1103 (defmacro cperl-ps-extend-face-list (arg)
1104 `(error "This version of Emacs has no `ps-extend-face-list'")))
1105 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
1106 ;; macros instead of defsubsts don't work on Emacs, so we do the
1107 ;; expansion manually. Any other suggestions?
1110 (defvar cperl-mode-abbrev-table nil
1111 "Abbrev table in use in CPerl mode buffers.")
1113 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
1115 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
1117 (if cperl-mode-map nil
1118 (setq cperl-mode-map (make-sparse-keymap))
1119 (cperl-define-key "{" 'cperl-electric-lbrace)
1120 (cperl-define-key "[" 'cperl-electric-paren)
1121 (cperl-define-key "(" 'cperl-electric-paren)
1122 (cperl-define-key "<" 'cperl-electric-paren)
1123 (cperl-define-key "}" 'cperl-electric-brace)
1124 (cperl-define-key "]" 'cperl-electric-rparen)
1125 (cperl-define-key ")" 'cperl-electric-rparen)
1126 (cperl-define-key ";" 'cperl-electric-semi)
1127 (cperl-define-key ":" 'cperl-electric-terminator)
1128 (cperl-define-key "\C-j" 'newline-and-indent)
1129 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
1130 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
1131 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
1132 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
1133 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
1134 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
1135 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
1136 (cperl-define-key "\C-c\C-b" 'cperl-find-bad-style)
1137 (cperl-define-key "\C-c\C-p" 'cperl-pod-spell)
1138 (cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell)
1139 (cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc)
1140 (cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx)
1141 (cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0)
1142 (cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1)
1143 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
1144 (cperl-define-key "\C-c\C-hp" 'cperl-perldoc)
1145 (cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point)
1146 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
1147 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
1149 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1150 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
1151 (cperl-define-key "\177" 'cperl-electric-backspace)
1152 (cperl-define-key "\t" 'cperl-indent-command)
1153 ;; don't clobber the backspace binding:
1154 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
1155 [(control c) (control h) F])
1156 (if (cperl-val 'cperl-clobber-lisp-bindings)
1158 (cperl-define-key "\C-hf"
1159 ;;(concat (char-to-string help-char) "f") ; does not work
1160 'cperl-info-on-command
1162 (cperl-define-key "\C-hv"
1163 ;;(concat (char-to-string help-char) "v") ; does not work
1166 (cperl-define-key "\C-c\C-hf"
1167 ;;(concat (char-to-string help-char) "f") ; does not work
1168 (key-binding "\C-hf")
1169 [(control c) (control h) f])
1170 (cperl-define-key "\C-c\C-hv"
1171 ;;(concat (char-to-string help-char) "v") ; does not work
1172 (key-binding "\C-hv")
1173 [(control c) (control h) v]))
1174 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
1175 [(control c) (control h) f])
1176 (cperl-define-key "\C-c\C-hv"
1177 ;;(concat (char-to-string help-char) "v") ; does not work
1179 [(control c) (control h) v]))
1180 (if (and cperl-xemacs-p
1181 (<= emacs-minor-version 11) (<= emacs-major-version 19))
1183 ;; substitute-key-definition is usefulness-deenhanced...
1184 ;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1185 (cperl-define-key "\e;" 'cperl-indent-for-comment)
1186 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
1187 (or (boundp 'fill-paragraph-function)
1188 (substitute-key-definition
1189 'fill-paragraph 'cperl-fill-paragraph
1190 cperl-mode-map global-map))
1191 (substitute-key-definition
1192 'indent-sexp 'cperl-indent-exp
1193 cperl-mode-map global-map)
1194 (substitute-key-definition
1195 'indent-region 'cperl-indent-region
1196 cperl-mode-map global-map)
1197 (substitute-key-definition
1198 'indent-for-comment 'cperl-indent-for-comment
1199 cperl-mode-map global-map)))
1202 (defvar cperl-lazy-installed)
1203 (defvar cperl-old-style nil)
1208 cperl-menu cperl-mode-map "Menu for CPerl mode"
1210 ["Beginning of function" beginning-of-defun t]
1211 ["End of function" end-of-defun t]
1212 ["Mark function" mark-defun t]
1213 ["Indent expression" cperl-indent-exp t]
1214 ["Fill paragraph/comment" fill-paragraph t]
1216 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
1217 ["Invert if/unless/while etc" cperl-invert-if-unless t]
1219 ["Beautify" cperl-beautify-regexp
1220 cperl-use-syntax-table-text-property]
1221 ["Beautify one level deep" (cperl-beautify-regexp 1)
1222 cperl-use-syntax-table-text-property]
1223 ["Beautify a group" cperl-beautify-level
1224 cperl-use-syntax-table-text-property]
1225 ["Beautify a group one level deep" (cperl-beautify-level 1)
1226 cperl-use-syntax-table-text-property]
1227 ["Contract a group" cperl-contract-level
1228 cperl-use-syntax-table-text-property]
1229 ["Contract groups" cperl-contract-levels
1230 cperl-use-syntax-table-text-property]
1232 ["Find next interpolated" cperl-next-interpolated-REx
1233 (next-single-property-change (point-min) 'REx-interpolated)]
1234 ["Find next interpolated (no //o)"
1235 cperl-next-interpolated-REx-0
1236 (or (text-property-any (point-min) (point-max) 'REx-interpolated t)
1237 (text-property-any (point-min) (point-max) 'REx-interpolated 1))]
1238 ["Find next interpolated (neither //o nor whole-REx)"
1239 cperl-next-interpolated-REx-1
1240 (text-property-any (point-min) (point-max) 'REx-interpolated t)])
1241 ["Insert spaces if needed to fix style" cperl-find-bad-style t]
1242 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
1244 ["Indent region" cperl-indent-region (cperl-use-region-p)]
1245 ["Comment region" cperl-comment-region (cperl-use-region-p)]
1246 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
1248 ["Run" mode-compile (fboundp 'mode-compile)]
1249 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
1250 (get-buffer "*compilation*"))]
1251 ["Next error" next-error (get-buffer "*compilation*")]
1252 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
1254 ["Debugger" cperl-db t]
1257 ["Imenu" imenu (fboundp 'imenu)]
1258 ["Imenu on Perl Info" cperl-imenu-on-info (featurep 'imenu)]
1260 ["Ispell PODs" cperl-pod-spell
1261 ;; Better not to update syntaxification here:
1262 ;; debugging syntaxificatio can be broken by this???
1264 (get-text-property (point-min) 'in-pod)
1266 (and cperl-syntaxify-for-menu
1267 (cperl-update-syntaxification (point-max) (point-max)))
1268 (next-single-property-change (point-min) 'in-pod nil (point-max)))
1270 ["Ispell HERE-DOCs" cperl-here-doc-spell
1272 (and cperl-syntaxify-for-menu
1273 (cperl-update-syntaxification (point-max) (point-max)))
1274 (next-single-property-change (point-min) 'here-doc-group nil (point-max)))
1276 ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
1277 (eq 'here-doc (progn
1278 (and cperl-syntaxify-for-menu
1279 (cperl-update-syntaxification (point) (point)))
1280 (get-text-property (point) 'syntax-type)))]
1281 ["Select this HERE-DOC or POD section"
1282 cperl-select-this-pod-or-here-doc
1284 (and cperl-syntaxify-for-menu
1285 (cperl-update-syntaxification (point) (point)))
1286 (get-text-property (point) 'syntax-type))
1289 ["CPerl pretty print (exprmntl)" cperl-ps-print
1290 (fboundp 'ps-extend-face-list)]
1292 ["Syntaxify region" cperl-find-pods-heres-region
1293 (cperl-use-region-p)]
1294 ["Profile syntaxification" cperl-time-fontification t]
1295 ["Debug errors in delayed fontification" cperl-emulate-lazy-lock t]
1296 ["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t]
1297 ["Debug backtrace on syntactic scan (BEWARE!!!)"
1298 (cperl-toggle-set-debug-unwind nil t) t]
1300 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
1301 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
1303 ;;; ["Create tags for current file" cperl-etags t]
1304 ;;; ["Add tags for current file" (cperl-etags t) t]
1305 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
1306 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
1307 ;;; ["Create tags for Perl files in (sub)directories"
1308 ;;; (cperl-etags nil 'recursive) t]
1309 ;;; ["Add tags for Perl files in (sub)directories"
1310 ;;; (cperl-etags t 'recursive) t])
1311 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
1312 ["Create tags for current file" (cperl-write-tags nil t) t]
1313 ["Add tags for current file" (cperl-write-tags) t]
1314 ["Create tags for Perl files in directory"
1315 (cperl-write-tags nil t nil t) t]
1316 ["Add tags for Perl files in directory"
1317 (cperl-write-tags nil nil nil t) t]
1318 ["Create tags for Perl files in (sub)directories"
1319 (cperl-write-tags nil t t t) t]
1320 ["Add tags for Perl files in (sub)directories"
1321 (cperl-write-tags nil nil t t) t]))
1323 ["Define word at point" imenu-go-find-at-position
1324 (fboundp 'imenu-go-find-at-position)]
1325 ["Help on function" cperl-info-on-command t]
1326 ["Help on function at point" cperl-info-on-current-command t]
1327 ["Help on symbol at point" cperl-get-help t]
1328 ["Perldoc" cperl-perldoc t]
1329 ["Perldoc on word at point" cperl-perldoc-at-point t]
1330 ["View manpage of POD in this file" cperl-build-manpage t]
1331 ["Auto-help on" cperl-lazy-install
1332 (and (fboundp 'run-with-idle-timer)
1333 (not cperl-lazy-installed))]
1334 ["Auto-help off" cperl-lazy-unstall
1335 (and (fboundp 'run-with-idle-timer)
1336 cperl-lazy-installed)])
1338 ["Auto newline" cperl-toggle-auto-newline t]
1339 ["Electric parens" cperl-toggle-electric t]
1340 ["Electric keywords" cperl-toggle-abbrev t]
1341 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
1342 ["Auto-help on Perl constructs" cperl-toggle-autohelp t]
1343 ["Auto fill" auto-fill-mode t])
1345 ["CPerl" (cperl-set-style "CPerl") t]
1346 ["PerlStyle" (cperl-set-style "PerlStyle") t]
1347 ["GNU" (cperl-set-style "GNU") t]
1348 ["C++" (cperl-set-style "C++") t]
1349 ["K&R" (cperl-set-style "K&R") t]
1350 ["BSD" (cperl-set-style "BSD") t]
1351 ["Whitesmith" (cperl-set-style "Whitesmith") t]
1352 ["Memorize Current" (cperl-set-style "Current") t]
1353 ["Memorized" (cperl-set-style-back) cperl-old-style])
1355 ["Tips" (describe-variable 'cperl-tips) t]
1356 ["Problems" (describe-variable 'cperl-problems) t]
1357 ["Speed" (describe-variable 'cperl-speed) t]
1358 ["Praise" (describe-variable 'cperl-praise) t]
1359 ["Faces" (describe-variable 'cperl-tips-faces) t]
1360 ["CPerl mode" (describe-function 'cperl-mode) t]
1362 (message "The version of master-file for this CPerl is %s-Emacs"
1363 cperl-version) t]))))
1366 (autoload 'c-macro-expand "cmacexp"
1367 "Display the result of expanding all C macros occurring in the region.
1368 The expansion is entirely correct because it uses the C preprocessor."
1371 ;;; These two must be unwound, otherwise take exponential time
1372 (defconst cperl-maybe-white-and-comment-rex "[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
1373 "Regular expression to match optional whitespace with interpspersed comments.
1374 Should contain exactly one group.")
1376 ;;; This one is tricky to unwind; still very inefficient...
1377 (defconst cperl-white-and-comment-rex "\\([ \t\n]\\|#[^\n]*\n\\)+"
1378 "Regular expression to match whitespace with interpspersed comments.
1379 Should contain exactly one group.")
1382 ;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
1383 ;;; `cperl-outline-regexp', `defun-prompt-regexp'.
1384 ;;; Details of groups in this may be used in several functions; see comments
1385 ;;; near mentioned above variable(s)...
1386 ;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
1387 (defsubst cperl-after-sub-regexp (named attr) ; 9 groups without attr...
1388 "Match the text after `sub' in a subroutine declaration.
1389 If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
1390 of attributes (if present), or end of the name or prototype (whatever is
1392 (concat ; Assume n groups before this...
1393 "\\(" ; n+1=name-group
1394 cperl-white-and-comment-rex ; n+2=pre-name
1395 "\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
1396 "\\)" ; END n+1=name-group
1398 "\\(" ; n+4=proto-group
1399 cperl-maybe-white-and-comment-rex ; n+5=pre-proto
1400 "\\(([^()]*)\\)" ; n+6=prototype
1401 "\\)?" ; END n+4=proto-group
1402 "\\(" ; n+7=attr-group
1403 cperl-maybe-white-and-comment-rex ; n+8=pre-attr
1404 "\\(" ; n+9=start-attr
1408 cperl-maybe-white-and-comment-rex ; whitespace-comments
1409 "\\(\\sw\\|_\\)+" ; attr-name
1410 ;; attr-arg (1 level of internal parens allowed!)
1411 "\\((\\(\\\\.\\|[^\\\\()]\\|([^\\\\()]*)\\)*)\\)?"
1412 "\\(" ; optional : (XXX allows trailing???)
1413 cperl-maybe-white-and-comment-rex ; whitespace-comments
1418 "\\)?" ; END n+6=proto-group
1421 ;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
1422 ;;; and `cperl-outline-level'.
1423 ;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 8=sub-name (+3)
1424 (defvar cperl-imenu--function-name-regexp-perl
1427 "\\([ \t]*package" ; 2 = package-group
1428 "\\(" ; 3 = package-name-group
1429 cperl-white-and-comment-rex ; 4 = pre-package-name
1430 "\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
1433 (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
1434 cperl-maybe-white-and-comment-rex ; 15=pre-block
1436 "=head\\([1-4]\\)[ \t]+" ; 16=level
1437 "\\([^\n]+\\)$" ; 17=text
1440 (defvar cperl-outline-regexp
1441 (concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
1443 (defvar cperl-mode-syntax-table nil
1444 "Syntax table in use in CPerl mode buffers.")
1446 (defvar cperl-string-syntax-table nil
1447 "Syntax table in use in CPerl mode string-like chunks.")
1449 (defsubst cperl-1- (p)
1450 (max (point-min) (1- p)))
1452 (defsubst cperl-1+ (p)
1453 (min (point-max) (1+ p)))
1455 (if cperl-mode-syntax-table
1457 (setq cperl-mode-syntax-table (make-syntax-table))
1458 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
1459 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
1460 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
1461 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
1462 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
1463 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
1464 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
1465 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
1466 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
1467 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
1468 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
1469 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
1470 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
1471 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
1472 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
1473 (if cperl-under-as-char
1474 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
1475 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
1476 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
1477 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
1478 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
1479 (modify-syntax-entry ?\{ "." cperl-string-syntax-table)
1480 (modify-syntax-entry ?\} "." cperl-string-syntax-table)
1481 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment )
1485 (defvar cperl-faces-init nil)
1487 (defvar cperl-msb-fixed nil)
1488 (defvar cperl-use-major-mode 'cperl-mode)
1489 (defvar cperl-font-lock-multiline-start nil)
1490 (defvar cperl-font-lock-multiline nil)
1491 (defvar cperl-compilation-error-regexp-alist nil)
1492 (defvar cperl-font-locking nil)
1495 (defun cperl-mode ()
1496 "Major mode for editing Perl code.
1497 Expression and list commands understand all C brackets.
1498 Tab indents for Perl code.
1499 Paragraphs are separated by blank lines only.
1500 Delete converts tabs to spaces as it moves back.
1502 Various characters in Perl almost always come in pairs: {}, (), [],
1503 sometimes <>. When the user types the first, she gets the second as
1504 well, with optional special formatting done on {}. (Disabled by
1505 default.) You can always quote (with \\[quoted-insert]) the left
1506 \"paren\" to avoid the expansion. The processing of < is special,
1507 since most the time you mean \"less\". CPerl mode tries to guess
1508 whether you want to type pair <>, and inserts is if it
1509 appropriate. You can set `cperl-electric-parens-string' to the string that
1510 contains the parenths from the above list you want to be electrical.
1511 Electricity of parenths is controlled by `cperl-electric-parens'.
1512 You may also set `cperl-electric-parens-mark' to have electric parens
1513 look for active mark and \"embrace\" a region if possible.'
1515 CPerl mode provides expansion of the Perl control constructs:
1517 if, else, elsif, unless, while, until, continue, do,
1518 for, foreach, formy and foreachmy.
1520 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
1522 The user types the keyword immediately followed by a space, which
1523 causes the construct to be expanded, and the point is positioned where
1524 she is most likely to want to be. eg. when the user types a space
1525 following \"if\" the following appears in the buffer: if () { or if ()
1526 } { } and the cursor is between the parentheses. The user can then
1527 type some boolean expression within the parens. Having done that,
1528 typing \\[cperl-linefeed] places you - appropriately indented - on a
1529 new line between the braces (if you typed \\[cperl-linefeed] in a POD
1530 directive line, then appropriate number of new lines is inserted).
1532 If CPerl decides that you want to insert \"English\" style construct like
1536 it will not do any expansion. See also help on variable
1537 `cperl-extra-newline-before-brace'. (Note that one can switch the
1538 help message on expansion by setting `cperl-message-electric-keyword'
1541 \\[cperl-linefeed] is a convenience replacement for typing carriage
1542 return. It places you in the next line with proper indentation, or if
1543 you type it inside the inline block of control construct, like
1545 foreach (@lines) {print; print}
1547 and you are on a boundary of a statement inside braces, it will
1548 transform the construct into a multiline and will place you into an
1549 appropriately indented blank line. If you need a usual
1550 `newline-and-indent' behavior, it is on \\[newline-and-indent],
1551 see documentation on `cperl-electric-linefeed'.
1553 Use \\[cperl-invert-if-unless] to change a construction of the form
1563 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
1564 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
1565 on electric space between $ and {, `cperl-electric-parens-string' is
1566 the string that contains parentheses that should be electric in CPerl
1567 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
1568 setting `cperl-electric-keywords' enables electric expansion of
1569 control structures in CPerl. `cperl-electric-linefeed' governs which
1570 one of two linefeed behavior is preferable. You can enable all these
1571 options simultaneously (recommended mode of use) by setting
1572 `cperl-hairy' to t. In this case you can switch separate options off
1573 by setting them to `null'. Note that one may undo the extra
1574 whitespace inserted by semis and braces in `auto-newline'-mode by
1575 consequent \\[cperl-electric-backspace].
1577 If your site has perl5 documentation in info format, you can use commands
1578 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
1579 These keys run commands `cperl-info-on-current-command' and
1580 `cperl-info-on-command', which one is which is controlled by variable
1581 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
1582 \(in turn affected by `cperl-hairy').
1584 Even if you have no info-format documentation, short one-liner-style
1585 help is available on \\[cperl-get-help], and one can run perldoc or
1588 It is possible to show this help automatically after some idle time.
1589 This is regulated by variable `cperl-lazy-help-time'. Default with
1590 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
1591 secs idle time . It is also possible to switch this on/off from the
1592 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
1594 Use \\[cperl-lineup] to vertically lineup some construction - put the
1595 beginning of the region at the start of construction, and make region
1596 span the needed amount of lines.
1598 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
1599 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
1600 here-docs sections. With capable Emaxen results of scan are used
1601 for indentation too, otherwise they are used for highlighting only.
1603 Variables controlling indentation style:
1604 `cperl-tab-always-indent'
1605 Non-nil means TAB in CPerl mode should always reindent the current line,
1606 regardless of where in the line point is when the TAB command is used.
1607 `cperl-indent-left-aligned-comments'
1608 Non-nil means that the comment starting in leftmost column should indent.
1609 `cperl-auto-newline'
1610 Non-nil means automatically newline before and after braces,
1611 and after colons and semicolons, inserted in Perl code. The following
1612 \\[cperl-electric-backspace] will remove the inserted whitespace.
1613 Insertion after colons requires both this variable and
1614 `cperl-auto-newline-after-colon' set.
1615 `cperl-auto-newline-after-colon'
1616 Non-nil means automatically newline even after colons.
1617 Subject to `cperl-auto-newline' setting.
1618 `cperl-indent-level'
1619 Indentation of Perl statements within surrounding block.
1620 The surrounding block's indentation is the indentation
1621 of the line on which the open-brace appears.
1622 `cperl-continued-statement-offset'
1623 Extra indentation given to a substatement, such as the
1624 then-clause of an if, or body of a while, or just a statement continuation.
1625 `cperl-continued-brace-offset'
1626 Extra indentation given to a brace that starts a substatement.
1627 This is in addition to `cperl-continued-statement-offset'.
1628 `cperl-brace-offset'
1629 Extra indentation for line if it starts with an open brace.
1630 `cperl-brace-imaginary-offset'
1631 An open brace following other text is treated as if it the line started
1632 this far to the right of the actual line indentation.
1633 `cperl-label-offset'
1634 Extra indentation for line that is a label.
1635 `cperl-min-label-indent'
1636 Minimal indentation for line that is a label.
1638 Settings for classic indent-styles: K&R BSD=C++ GNU PerlStyle=Whitesmith
1639 `cperl-indent-level' 5 4 2 4
1640 `cperl-brace-offset' 0 0 0 0
1641 `cperl-continued-brace-offset' -5 -4 0 0
1642 `cperl-label-offset' -5 -4 -2 -4
1643 `cperl-continued-statement-offset' 5 4 2 4
1645 CPerl knows several indentation styles, and may bulk set the
1646 corresponding variables. Use \\[cperl-set-style] to do this. Use
1647 \\[cperl-set-style-back] to restore the memorized preexisting values
1648 \(both available from menu). See examples in `cperl-style-examples'.
1650 Part of the indentation style is how different parts of if/elsif/else
1651 statements are broken into lines; in CPerl, this is reflected on how
1652 templates for these constructs are created (controlled by
1653 `cperl-extra-newline-before-brace'), and how reflow-logic should treat \"continuation\" blocks of else/elsif/continue, controlled by the same variable,
1654 and by `cperl-extra-newline-before-brace-multiline',
1655 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'.
1657 If `cperl-indent-level' is 0, the statement after opening brace in
1658 column 0 is indented on
1659 `cperl-brace-offset'+`cperl-continued-statement-offset'.
1661 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
1664 DO NOT FORGET to read micro-docs (available from `Perl' menu)
1665 or as help on variables `cperl-tips', `cperl-problems',
1666 `cperl-praise', `cperl-speed'."
1668 (kill-all-local-variables)
1669 (use-local-map cperl-mode-map)
1670 (if (cperl-val 'cperl-electric-linefeed)
1672 (local-set-key "\C-J" 'cperl-linefeed)
1673 (local-set-key "\C-C\C-J" 'newline-and-indent)))
1675 (cperl-val 'cperl-clobber-lisp-bindings)
1676 (cperl-val 'cperl-info-on-command-no-prompt))
1678 ;; don't clobber the backspace binding:
1679 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
1680 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
1681 [(control c) (control h) f])))
1682 (setq major-mode cperl-use-major-mode)
1683 (setq mode-name "CPerl")
1684 (if (not cperl-mode-abbrev-table)
1685 (let ((prev-a-c abbrevs-changed))
1686 (define-abbrev-table 'cperl-mode-abbrev-table '(
1687 ("if" "if" cperl-electric-keyword 0)
1688 ("elsif" "elsif" cperl-electric-keyword 0)
1689 ("while" "while" cperl-electric-keyword 0)
1690 ("until" "until" cperl-electric-keyword 0)
1691 ("unless" "unless" cperl-electric-keyword 0)
1692 ("else" "else" cperl-electric-else 0)
1693 ("continue" "continue" cperl-electric-else 0)
1694 ("for" "for" cperl-electric-keyword 0)
1695 ("foreach" "foreach" cperl-electric-keyword 0)
1696 ("formy" "formy" cperl-electric-keyword 0)
1697 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
1698 ("do" "do" cperl-electric-keyword 0)
1699 ("=pod" "=pod" cperl-electric-pod 0)
1700 ("=over" "=over" cperl-electric-pod 0)
1701 ("=head1" "=head1" cperl-electric-pod 0)
1702 ("=head2" "=head2" cperl-electric-pod 0)
1703 ("pod" "pod" cperl-electric-pod 0)
1704 ("over" "over" cperl-electric-pod 0)
1705 ("head1" "head1" cperl-electric-pod 0)
1706 ("head2" "head2" cperl-electric-pod 0)))
1707 (setq abbrevs-changed prev-a-c)))
1708 (setq local-abbrev-table cperl-mode-abbrev-table)
1709 (if (cperl-val 'cperl-electric-keywords)
1711 (set-syntax-table cperl-mode-syntax-table)
1712 ;; Until Emacs is multi-threaded, we do not actually need it local:
1713 (make-local-variable 'cperl-font-lock-multiline-start)
1714 (make-local-variable 'cperl-font-locking)
1715 (make-local-variable 'outline-regexp)
1716 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
1717 (setq outline-regexp cperl-outline-regexp)
1718 (make-local-variable 'outline-level)
1719 (setq outline-level 'cperl-outline-level)
1720 (make-local-variable 'paragraph-start)
1721 (setq paragraph-start (concat "^$\\|" page-delimiter))
1722 (make-local-variable 'paragraph-separate)
1723 (setq paragraph-separate paragraph-start)
1724 (make-local-variable 'paragraph-ignore-fill-prefix)
1725 (setq paragraph-ignore-fill-prefix t)
1728 (make-local-variable 'paren-backwards-message)
1729 (set 'paren-backwards-message t)))
1730 (make-local-variable 'indent-line-function)
1731 (setq indent-line-function 'cperl-indent-line)
1732 (make-local-variable 'require-final-newline)
1733 (setq require-final-newline mode-require-final-newline)
1734 (make-local-variable 'comment-start)
1735 (setq comment-start "# ")
1736 (make-local-variable 'comment-end)
1737 (setq comment-end "")
1738 (make-local-variable 'comment-column)
1739 (setq comment-column cperl-comment-column)
1740 (make-local-variable 'comment-start-skip)
1741 (setq comment-start-skip "#+ *")
1742 (make-local-variable 'defun-prompt-regexp)
1744 ;;; (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
1745 ;;; cperl-maybe-white-and-comment-rex ; 15=pre-block
1746 (setq defun-prompt-regexp
1747 (concat "^[ \t]*\\(sub"
1748 (cperl-after-sub-regexp 'named 'attr-groups)
1750 "\\(BEGIN\\|CHECK\\|INIT\\|END\\|AUTOLOAD\\|DESTROY\\)"
1752 cperl-maybe-white-and-comment-rex))
1753 (make-local-variable 'comment-indent-function)
1754 (setq comment-indent-function 'cperl-comment-indent)
1755 (and (boundp 'fill-paragraph-function)
1757 (make-local-variable 'fill-paragraph-function)
1758 (set 'fill-paragraph-function 'cperl-fill-paragraph)))
1759 (make-local-variable 'parse-sexp-ignore-comments)
1760 (setq parse-sexp-ignore-comments t)
1761 (make-local-variable 'indent-region-function)
1762 (setq indent-region-function 'cperl-indent-region)
1763 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
1764 (make-local-variable 'imenu-create-index-function)
1765 (setq imenu-create-index-function
1766 (function cperl-imenu--create-perl-index))
1767 (make-local-variable 'imenu-sort-function)
1768 (setq imenu-sort-function nil)
1769 (make-local-variable 'vc-rcs-header)
1770 (set 'vc-rcs-header cperl-vc-rcs-header)
1771 (make-local-variable 'vc-sccs-header)
1772 (set 'vc-sccs-header cperl-vc-sccs-header)
1773 ;; This one is obsolete...
1774 (make-local-variable 'vc-header-alist)
1775 (set 'vc-header-alist (or cperl-vc-header-alist ; Avoid warning
1776 (` ((SCCS (, (car cperl-vc-sccs-header)))
1777 (RCS (, (car cperl-vc-rcs-header)))))))
1778 (cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x
1779 (make-local-variable 'compilation-error-regexp-alist-alist)
1780 (set 'compilation-error-regexp-alist-alist
1781 (cons (cons 'cperl cperl-compilation-error-regexp-alist)
1782 (symbol-value 'compilation-error-regexp-alist-alist)))
1783 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
1784 (let ((f 'compilation-build-compilation-error-regexp-alist))
1786 (make-local-variable 'compilation-error-regexp-alist)
1787 (push 'cperl compilation-error-regexp-alist)))
1788 ((boundp 'compilation-error-regexp-alist);; xmeacs 19.x
1789 (make-local-variable 'compilation-error-regexp-alist)
1790 (set 'compilation-error-regexp-alist
1791 (cons cperl-compilation-error-regexp-alist
1792 (symbol-value 'compilation-error-regexp-alist)))))
1793 (make-local-variable 'font-lock-defaults)
1794 (setq font-lock-defaults
1796 ((string< emacs-version "19.30")
1797 '(cperl-font-lock-keywords-2 nil nil ((?_ . "w"))))
1798 ((string< emacs-version "19.33") ; Which one to use?
1799 '((cperl-font-lock-keywords
1800 cperl-font-lock-keywords-1
1801 cperl-font-lock-keywords-2) nil nil ((?_ . "w"))))
1803 '((cperl-load-font-lock-keywords
1804 cperl-load-font-lock-keywords-1
1805 cperl-load-font-lock-keywords-2) nil nil ((?_ . "w"))))))
1806 (make-local-variable 'cperl-syntax-state)
1807 (setq cperl-syntax-state nil) ; reset syntaxification cache
1808 (if cperl-use-syntax-table-text-property
1810 (make-local-variable 'parse-sexp-lookup-properties)
1811 ;; Do not introduce variable if not needed, we check it!
1812 (set 'parse-sexp-lookup-properties t)
1813 ;; Fix broken font-lock:
1814 (or (boundp 'font-lock-unfontify-region-function)
1815 (set 'font-lock-unfontify-region-function
1816 'font-lock-default-unfontify-region))
1817 (unless cperl-xemacs-p ; Our: just a plug for wrong font-lock
1818 (make-local-variable 'font-lock-unfontify-region-function)
1819 (set 'font-lock-unfontify-region-function ; not present with old Emacs
1820 'cperl-font-lock-unfontify-region-function))
1821 (make-local-variable 'cperl-syntax-done-to)
1822 (setq cperl-syntax-done-to nil) ; reset syntaxification cache
1823 (make-local-variable 'font-lock-syntactic-keywords)
1824 (setq font-lock-syntactic-keywords
1825 (if cperl-syntaxify-by-font-lock
1826 '((cperl-fontify-syntaxically))
1827 ;; unless font-lock-syntactic-keywords, font-lock (pre-22.1)
1828 ;; used to ignore syntax-table text-properties. (t) is a hack
1829 ;; to make font-lock think that font-lock-syntactic-keywords
1832 (if (boundp 'font-lock-multiline) ; Newer font-lock; use its facilities
1834 (setq cperl-font-lock-multiline t) ; Not localized...
1835 (set (make-local-variable 'font-lock-multiline) t))
1836 (make-local-variable 'font-lock-fontify-region-function)
1837 (set 'font-lock-fontify-region-function ; not present with old Emacs
1838 'cperl-font-lock-fontify-region-function))
1839 (make-local-variable 'font-lock-fontify-region-function)
1840 (set 'font-lock-fontify-region-function ; not present with old Emacs
1841 'cperl-font-lock-fontify-region-function)
1842 (make-local-variable 'cperl-old-style)
1843 (if (boundp 'normal-auto-fill-function) ; 19.33 and later
1844 (set (make-local-variable 'normal-auto-fill-function)
1845 'cperl-do-auto-fill)
1846 (or (fboundp 'cperl-old-auto-fill-mode)
1848 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
1849 (defun auto-fill-mode (&optional arg)
1851 (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
1852 (and auto-fill-function (memq major-mode '(perl-mode cperl-mode))
1853 (setq auto-fill-function 'cperl-do-auto-fill))))))
1854 (if (cperl-enable-font-lock)
1855 (if (cperl-val 'cperl-font-lock)
1856 (progn (or cperl-faces-init (cperl-init-faces))
1857 (font-lock-mode 1))))
1858 (set (make-local-variable 'facemenu-add-face-function)
1859 'cperl-facemenu-add-face-function) ; XXXX What this guy is for???
1860 (and (boundp 'msb-menu-cond)
1861 (not cperl-msb-fixed)
1863 (if (featurep 'easymenu)
1864 (easy-menu-add cperl-menu)) ; A NOP in Emacs.
1865 (run-mode-hooks 'cperl-mode-hook)
1866 (if cperl-hook-after-change
1868 (make-local-hook 'after-change-functions)
1869 (add-hook 'after-change-functions 'cperl-after-change-function nil t)))
1870 ;; After hooks since fontification will break this
1871 (if cperl-pod-here-scan
1872 (or cperl-syntaxify-by-font-lock
1873 (progn (or cperl-faces-init (cperl-init-faces-weak))
1874 (cperl-find-pods-heres)))))
1876 ;; Fix for perldb - make default reasonable
1880 (perldb (read-from-minibuffer "Run perldb (like this): "
1881 (if (consp gud-perldb-history)
1882 (car gud-perldb-history)
1883 (concat "perl " ;;(file-name-nondirectory
1887 (buffer-file-name)))
1889 '(gud-perldb-history . 1))))
1891 (defun cperl-msb-fix ()
1892 ;; Adds perl files to msb menu, supposes that msb is already loaded
1893 (setq cperl-msb-fixed t)
1894 (let* ((l (length msb-menu-cond))
1895 (last (nth (1- l) msb-menu-cond))
1896 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
1897 (handle (1- (nth 1 last))))
1898 (setcdr precdr (list
1900 '(memq major-mode '(cperl-mode perl-mode))
1905 ;; This is used by indent-for-comment
1906 ;; to decide how much to indent a comment in CPerl code
1907 ;; based on its context. Do fallback if comment is found wrong.
1909 (defvar cperl-wrong-comment)
1910 (defvar cperl-st-cfence '(14)) ; Comment-fence
1911 (defvar cperl-st-sfence '(15)) ; String-fence
1912 (defvar cperl-st-punct '(1))
1913 (defvar cperl-st-word '(2))
1914 (defvar cperl-st-bra '(4 . ?\>))
1915 (defvar cperl-st-ket '(5 . ?\<))
1918 (defun cperl-comment-indent () ; called at point at supposed comment
1919 (let ((p (point)) (c (current-column)) was phony)
1920 (if (and (not cperl-indent-comment-at-column-0)
1922 0 ; Existing comment at bol stays there.
1923 ;; Wrong comment found
1925 (setq was (cperl-to-comment-or-eol)
1926 phony (eq (get-text-property (point) 'syntax-table)
1929 (progn ; Too naive???
1930 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
1931 (if (eq (preceding-char) ?\#)
1934 (if (= (point) p) ; Our caller found a correct place
1936 (skip-chars-backward " \t")
1937 (setq was (current-column))
1940 (max (1+ was) ; Else indent at comment column
1942 ;; No, the caller found a random place; we need to edit ourselves
1944 (insert comment-start)
1945 (backward-char (length comment-start)))
1946 (setq cperl-wrong-comment t)
1947 (cperl-make-indent comment-column 1) ; Indent min 1
1950 ;;;(defun cperl-comment-indent-fallback ()
1951 ;;; "Is called if the standard comment-search procedure fails.
1952 ;;;Point is at start of real comment."
1953 ;;; (let ((c (current-column)) target cnt prevc)
1954 ;;; (if (= c comment-column) nil
1955 ;;; (setq cnt (skip-chars-backward "[ \t]"))
1956 ;;; (setq target (max (1+ (setq prevc
1957 ;;; (current-column))) ; Else indent at comment column
1958 ;;; comment-column))
1959 ;;; (if (= c comment-column) nil
1960 ;;; (delete-backward-char cnt)
1961 ;;; (while (< prevc target)
1963 ;;; (setq prevc (current-column)))
1964 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
1965 ;;; (while (< prevc target)
1967 ;;; (setq prevc (current-column)))))))
1969 (defun cperl-indent-for-comment ()
1970 "Substitute for `indent-for-comment' in CPerl."
1972 (let (cperl-wrong-comment)
1973 (indent-for-comment)
1974 (if cperl-wrong-comment ; set by `cperl-comment-indent'
1975 (progn (cperl-to-comment-or-eol)
1976 (forward-char (length comment-start))))))
1978 (defun cperl-comment-region (b e arg)
1979 "Comment or uncomment each line in the region in CPerl mode.
1980 See `comment-region'."
1981 (interactive "r\np")
1982 (let ((comment-start "#"))
1983 (comment-region b e arg)))
1985 (defun cperl-uncomment-region (b e arg)
1986 "Uncomment or comment each line in the region in CPerl mode.
1987 See `comment-region'."
1988 (interactive "r\np")
1989 (let ((comment-start "#"))
1990 (comment-region b e (- arg))))
1992 (defvar cperl-brace-recursing nil)
1994 (defun cperl-electric-brace (arg &optional only-before)
1995 "Insert character and correct line's indentation.
1996 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
1997 place (even in empty line), but not after. If after \")\" and the inserted
1998 char is \"{\", insert extra newline before only if
1999 `cperl-extra-newline-before-brace'."
2002 (other-end (if (and cperl-electric-parens-mark
2008 (not cperl-brace-recursing)
2009 (cperl-val 'cperl-electric-parens)
2010 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
2011 ;; Need to insert a matching pair
2014 (setq insertpos (point-marker))
2015 (goto-char other-end)
2016 (setq last-command-char ?\{)
2017 (cperl-electric-lbrace arg insertpos))
2019 ;; Check whether we close something "usual" with `}'
2020 (if (and (eq last-command-char ?\})
2024 (up-list (- (prefix-numeric-value arg)))
2025 ;;(cperl-after-block-p (point-min))
2026 (or (cperl-after-expr-p nil "{;)")
2027 ;; after sub, else, continue
2028 (cperl-after-block-p nil 'pre)))
2030 ;; Just insert the guy
2031 (self-insert-command (prefix-numeric-value arg))
2032 (if (and (not arg) ; No args, end (of empty line or auto)
2034 (or (and (null only-before)
2036 (skip-chars-backward " \t")
2038 (and (eq last-command-char ?\{) ; Do not insert newline
2039 ;; if after ")" and `cperl-extra-newline-before-brace'
2040 ;; is nil, do not insert extra newline.
2041 (not cperl-extra-newline-before-brace)
2043 (skip-chars-backward " \t")
2044 (eq (preceding-char) ?\))))
2045 (if cperl-auto-newline
2046 (progn (cperl-indent-line) (newline) t) nil)))
2048 (self-insert-command (prefix-numeric-value arg))
2050 (if cperl-auto-newline
2051 (setq insertpos (1- (point))))
2052 (if (and cperl-auto-newline (null only-before))
2055 (cperl-indent-line)))
2057 (if insertpos (progn (goto-char insertpos)
2058 (search-forward (make-string
2059 1 last-command-char))
2060 (setq insertpos (1- (point)))))
2064 (goto-char insertpos)
2065 (self-insert-command (prefix-numeric-value arg)))
2066 (self-insert-command (prefix-numeric-value arg)))))))
2068 (defun cperl-electric-lbrace (arg &optional end)
2069 "Insert character, correct line's indentation, correct quoting by space."
2071 (let ((cperl-brace-recursing t)
2072 (cperl-auto-newline cperl-auto-newline)
2074 (if (and cperl-electric-parens-mark
2082 (and (cperl-val 'cperl-electric-lbrace-space)
2083 (eq (preceding-char) ?$)
2085 (skip-chars-backward "$")
2086 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
2088 ;; Check whether we are in comment
2092 (not (looking-at "[ \t]*#")))
2093 (cperl-after-expr-p nil "{;)"))
2095 (setq cperl-auto-newline nil))
2096 (cperl-electric-brace arg)
2097 (and (cperl-val 'cperl-electric-parens)
2098 (eq last-command-char ?{)
2099 (memq last-command-char
2100 (append cperl-electric-parens-string nil))
2101 (or (if other-end (goto-char (marker-position other-end)))
2103 (setq last-command-char ?} pos (point))
2104 (progn (cperl-electric-brace arg t)
2107 (defun cperl-electric-paren (arg)
2108 "Insert an opening parenthesis or a matching pair of parentheses.
2109 See `cperl-electric-parens'."
2111 (let ((beg (save-excursion (beginning-of-line) (point)))
2112 (other-end (if (and cperl-electric-parens-mark
2119 (if (and (cperl-val 'cperl-electric-parens)
2120 (memq last-command-char
2121 (append cperl-electric-parens-string nil))
2122 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2123 ;;(not (save-excursion (search-backward "#" beg t)))
2124 (if (eq last-command-char ?<)
2126 (and abbrev-mode ; later it is too late, may be after `for'
2128 (cperl-after-expr-p nil "{;(,:="))
2131 (self-insert-command (prefix-numeric-value arg))
2132 (if other-end (goto-char (marker-position other-end)))
2133 (insert (make-string
2134 (prefix-numeric-value arg)
2135 (cdr (assoc last-command-char '((?{ .?})
2139 (forward-char (- (prefix-numeric-value arg))))
2140 (self-insert-command (prefix-numeric-value arg)))))
2142 (defun cperl-electric-rparen (arg)
2143 "Insert a matching pair of parentheses if marking is active.
2144 If not, or if we are not at the end of marking range, would self-insert.
2145 Affected by `cperl-electric-parens'."
2147 (let ((beg (save-excursion (beginning-of-line) (point)))
2148 (other-end (if (and cperl-electric-parens-mark
2149 (cperl-val 'cperl-electric-parens)
2150 (memq last-command-char
2151 (append cperl-electric-parens-string nil))
2158 (cperl-val 'cperl-electric-parens)
2159 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
2160 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2161 ;;(not (save-excursion (search-backward "#" beg t)))
2164 (self-insert-command (prefix-numeric-value arg))
2166 (if other-end (goto-char other-end))
2167 (insert (make-string
2168 (prefix-numeric-value arg)
2169 (cdr (assoc last-command-char '((?\} . ?\{)
2174 (self-insert-command (prefix-numeric-value arg)))))
2176 (defun cperl-electric-keyword ()
2177 "Insert a construction appropriate after a keyword.
2178 Help message may be switched off by setting `cperl-message-electric-keyword'
2180 (let ((beg (save-excursion (beginning-of-line) (point)))
2181 (dollar (and (eq last-command-char ?$)
2182 (eq this-command 'self-insert-command)))
2183 (delete (and (memq last-command-char '(?\s ?\n ?\t ?\f))
2184 (memq this-command '(self-insert-command newline))))
2186 (and (save-excursion
2190 (setq do (looking-at "do\\>")))
2192 (cperl-after-expr-p nil "{;:"))
2196 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2198 (save-excursion (or (not (re-search-backward "^=" nil t))
2201 (and cperl-use-syntax-table-text-property
2202 (not (eq (get-text-property (point)
2205 (save-excursion (forward-sexp -1)
2206 (not (memq (following-char) (append "$@%&*" nil))))
2208 (and (eq (preceding-char) ?y)
2209 (progn ; "foreachmy"
2215 (memq this-command '(self-insert-command newline)))))
2216 (and dollar (insert " $"))
2218 ;;(insert " () {\n}")
2220 (cperl-extra-newline-before-brace
2221 (insert (if do "\n" " ()\n"))
2227 (and do (insert " while ();")))
2229 (insert (if do " {\n} while ();" " () {\n}"))))
2230 (or (looking-at "[ \t]\\|$") (insert " "))
2232 (if dollar (progn (search-backward "$")
2236 (search-backward ")")
2237 (if (eq last-command-char ?\()
2238 (progn ; Avoid "if (())"
2239 (delete-backward-char 1)
2240 (delete-backward-char -1))))
2242 (cperl-putback-char cperl-del-back-ch))
2243 (if cperl-message-electric-keyword
2244 (message "Precede char by C-q to avoid expansion"))))))
2246 (defun cperl-ensure-newlines (n &optional pos)
2247 "Make sure there are N newlines after the point."
2248 (or pos (setq pos (point)))
2249 (if (looking-at "\n")
2253 (cperl-ensure-newlines (1- n) pos)
2256 (defun cperl-electric-pod ()
2257 "Insert a POD chunk appropriate after a =POD directive."
2258 (let ((delete (and (memq last-command-char '(?\s ?\n ?\t ?\f))
2259 (memq this-command '(self-insert-command newline))))
2260 head1 notlast name p really-delete over)
2261 (and (save-excursion
2264 (eq (preceding-char) ?=)
2266 (setq head1 (looking-at "head1\\>[ \t]*$"))
2267 (setq over (and (looking-at "over\\>[ \t]*$")
2268 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
2272 (get-text-property (point) 'in-pod)
2273 (cperl-after-expr-p nil "{;:")
2274 (and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t)
2275 (not (looking-at "\n*=cut"))
2276 (or (not cperl-use-syntax-table-text-property)
2277 (eq (get-text-property (point) 'syntax-type) 'pod))))))
2280 (setq notlast (re-search-forward "^\n=" nil t)))
2284 (cperl-ensure-newlines 2)
2290 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
2291 nil t)))) ; Only one
2294 (setq name (file-name-sans-extension
2295 (file-name-nondirectory (buffer-file-name)))
2297 (insert " NAME\n\n" name
2298 " - \n\n=head1 SYNOPSIS\n\n\n\n"
2299 "=head1 DESCRIPTION")
2300 (cperl-ensure-newlines 4)
2304 (setq really-delete t))
2309 (insert "\n\n=item \n\n\n\n"
2311 (cperl-ensure-newlines 2)
2315 (setq really-delete t)))
2316 (if (and delete really-delete)
2317 (cperl-putback-char cperl-del-back-ch))))))
2319 (defun cperl-electric-else ()
2320 "Insert a construction appropriate after a keyword.
2321 Help message may be switched off by setting `cperl-message-electric-keyword'
2323 (let ((beg (save-excursion (beginning-of-line) (point))))
2324 (and (save-excursion
2326 (cperl-after-expr-p nil "{;:"))
2330 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2332 (save-excursion (or (not (re-search-backward "^=" nil t))
2334 (and cperl-use-syntax-table-text-property
2335 (not (eq (get-text-property (point)
2340 ;;(insert " {\n\n}")
2342 (cperl-extra-newline-before-brace
2348 (insert " {\n\n}")))
2349 (or (looking-at "[ \t]\\|$") (insert " "))
2353 (cperl-putback-char cperl-del-back-ch)
2354 (setq this-command 'cperl-electric-else)
2355 (if cperl-message-electric-keyword
2356 (message "Precede char by C-q to avoid expansion"))))))
2358 (defun cperl-linefeed ()
2359 "Go to end of line, open a new line and indent appropriately.
2360 If in POD, insert appropriate lines."
2362 (let ((beg (save-excursion (beginning-of-line) (point)))
2363 (end (save-excursion (end-of-line) (point)))
2364 (pos (point)) start over cut res)
2365 (if (and ; Check if we need to split:
2366 ; i.e., on a boundary and inside "{...}"
2367 (save-excursion (cperl-to-comment-or-eol)
2368 (>= (point) pos)) ; Not in a comment
2370 (skip-chars-backward " \t" beg)
2372 (looking-at "[;{]")) ; After { or ; + spaces
2373 (looking-at "[ \t]*}") ; Before }
2374 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
2377 (eq (car (parse-partial-sexp pos end -1)) -1)
2378 ; Leave the level of parens
2379 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
2381 (cperl-after-block-p (point-min))
2384 (setq start (point-marker))
2385 (<= start pos))))) ; Redundant? Are after the
2386 ; start of parens group.
2388 (skip-chars-backward " \t")
2389 (or (memq (preceding-char) (append ";{" nil))
2395 (or (looking-at "{[ \t]*$") ; If there is a statement
2396 ; before, move it to separate line
2400 (cperl-indent-line)))
2401 (forward-line 1) ; We are on the target line
2404 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
2405 ; after, move it to separate line
2408 (search-backward "}" beg)
2409 (skip-chars-backward " \t")
2410 (or (memq (preceding-char) (append ";{" nil))
2415 (forward-line -1) ; We are on the line before target
2417 (newline-and-indent))
2418 (end-of-line) ; else - no splitting
2420 ((and (looking-at "\n[ \t]*{$")
2422 (skip-chars-backward " \t")
2423 (eq (preceding-char) ?\)))) ; Probably if () {} group
2424 ; with an extra newline.
2426 (cperl-indent-line))
2427 ((save-excursion ; In POD header
2428 (forward-paragraph -1)
2429 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
2430 ;; We are after \n now, so look for the rest
2431 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
2433 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
2434 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
2438 (forward-paragraph -1)
2441 (setq cut (buffer-substring (point)
2445 (delete-char (- (save-excursion (end-of-line) (point))
2447 (setq res (expand-abbrev))
2453 (cperl-ensure-newlines (if cut 2 4))
2455 ((get-text-property (point) 'in-pod) ; In POD section
2456 (cperl-ensure-newlines 4)
2458 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
2460 (cperl-indent-line))
2462 (newline-and-indent))))))
2464 (defun cperl-electric-semi (arg)
2465 "Insert character and correct line's indentation."
2467 (if cperl-auto-newline
2468 (cperl-electric-terminator arg)
2469 (self-insert-command (prefix-numeric-value arg))
2470 (if cperl-autoindent-on-semi
2471 (cperl-indent-line))))
2473 (defun cperl-electric-terminator (arg)
2474 "Insert character and correct line's indentation."
2477 (auto (and cperl-auto-newline
2478 (or (not (eq last-command-char ?:))
2479 cperl-auto-newline-after-colon)))
2481 (if (and ;;(not arg)
2483 (not (save-excursion
2485 (skip-chars-forward " \t")
2487 ;; Ignore in comment lines
2488 (= (following-char) ?#)
2489 ;; Colon is special only after a label
2490 ;; So quickly rule out most other uses of colon
2491 ;; and do no indentation for them.
2492 (and (eq last-command-char ?:)
2495 (skip-chars-forward " \t")
2496 (and (< (point) end)
2497 (progn (goto-char (- end 1))
2498 (not (looking-at ":"))))))
2500 (beginning-of-defun)
2501 (let ((pps (parse-partial-sexp (point) end)))
2502 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
2504 (self-insert-command (prefix-numeric-value arg))
2506 (if auto (setq insertpos (point-marker)))
2512 (cperl-indent-line)))
2514 (if insertpos (goto-char (1- (marker-position insertpos)))
2519 (goto-char insertpos)
2520 (self-insert-command (prefix-numeric-value arg)))
2521 (self-insert-command (prefix-numeric-value arg)))))
2523 (defun cperl-electric-backspace (arg)
2524 "Backspace, or remove the whitespace around the point inserted by an electric
2525 key. Will untabify if `cperl-electric-backspace-untabify' is non-nil."
2527 (if (and cperl-auto-newline
2528 (memq last-command '(cperl-electric-semi
2529 cperl-electric-terminator
2530 cperl-electric-lbrace))
2531 (memq (preceding-char) '(?\s ?\t ?\n)))
2533 (if (eq last-command 'cperl-electric-lbrace)
2534 (skip-chars-forward " \t\n"))
2536 (skip-chars-backward " \t\n")
2537 (delete-region (point) p))
2538 (and (eq last-command 'cperl-electric-else)
2539 ;; We are removing the whitespace *inside* cperl-electric-else
2540 (setq this-command 'cperl-electric-else-really))
2541 (if (and cperl-auto-newline
2542 (eq last-command 'cperl-electric-else-really)
2543 (memq (preceding-char) '(?\s ?\t ?\n)))
2545 (skip-chars-forward " \t\n")
2547 (skip-chars-backward " \t\n")
2548 (delete-region (point) p))
2549 (if cperl-electric-backspace-untabify
2550 (backward-delete-char-untabify arg)
2551 (delete-backward-char arg)))))
2553 (put 'cperl-electric-backspace 'delete-selection 'supersede)
2555 (defun cperl-inside-parens-p () ;; NOT USED????
2559 (narrow-to-region (point)
2560 (progn (beginning-of-defun) (point)))
2561 (goto-char (point-max))
2562 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
2565 (defun cperl-indent-command (&optional whole-exp)
2566 "Indent current line as Perl code, or in some cases insert a tab character.
2567 If `cperl-tab-always-indent' is non-nil (the default), always indent current
2568 line. Otherwise, indent the current line only if point is at the left margin
2569 or in the line's indentation; otherwise insert a tab.
2571 A numeric argument, regardless of its value,
2572 means indent rigidly all the lines of the expression starting after point
2573 so that this line becomes properly indented.
2574 The relative indentation among the lines of the expression are preserved."
2576 (cperl-update-syntaxification (point) (point))
2578 ;; If arg, always indent this line as Perl
2579 ;; and shift remaining lines of expression the same amount.
2580 (let ((shift-amt (cperl-indent-line))
2583 (if cperl-tab-always-indent
2584 (beginning-of-line))
2591 (if (and shift-amt (> end beg))
2592 (indent-code-rigidly beg end shift-amt "#")))
2593 (if (and (not cperl-tab-always-indent)
2595 (skip-chars-backward " \t")
2598 (cperl-indent-line))))
2600 (defun cperl-indent-line (&optional parse-data)
2601 "Indent current line as Perl code.
2602 Return the amount the indentation changed by."
2603 (let ((case-fold-search nil)
2604 (pos (- (point-max) (point)))
2605 indent i beg shift-amt)
2606 (setq indent (cperl-calculate-indent parse-data)
2610 (cond ((or (eq indent nil) (eq indent t))
2611 (setq indent (current-indentation) i nil))
2612 ;;((eq indent t) ; Never?
2613 ;; (setq indent (cperl-calculate-indent-within-comment)))
2614 ;;((looking-at "[ \t]*#")
2617 (skip-chars-forward " \t")
2618 (if (listp indent) (setq indent (car indent)))
2619 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
2621 (setq indent (max cperl-min-label-indent
2622 (+ indent cperl-label-offset)))))
2623 ((= (following-char) ?})
2624 (setq indent (- indent cperl-indent-level)))
2625 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
2626 (setq indent (+ indent cperl-close-paren-offset)))
2627 ((= (following-char) ?{)
2628 (setq indent (+ indent cperl-brace-offset))))))
2629 (skip-chars-forward " \t")
2630 (setq shift-amt (and i (- indent (current-column))))
2631 (if (or (not shift-amt)
2633 (if (> (- (point-max) pos) (point))
2634 (goto-char (- (point-max) pos)))
2635 ;;;(delete-region beg (point))
2636 ;;;(indent-to indent)
2637 (cperl-make-indent indent)
2638 ;; If initial point was within line's indentation,
2639 ;; position after the indentation. Else stay at same point in text.
2640 (if (> (- (point-max) pos) (point))
2641 (goto-char (- (point-max) pos))))
2644 (defun cperl-after-label ()
2645 ;; Returns true if the point is after label. Does not do save-excursion.
2646 (and (eq (preceding-char) ?:)
2647 (memq (char-syntax (char-after (- (point) 2)))
2651 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
2653 (defun cperl-get-state (&optional parse-start start-state)
2654 ;; returns list (START STATE DEPTH PRESTART),
2655 ;; START is a good place to start parsing, or equal to
2656 ;; PARSE-START if preset,
2657 ;; STATE is what is returned by `parse-partial-sexp'.
2658 ;; DEPTH is true is we are immediately after end of block
2659 ;; which contains START.
2660 ;; PRESTART is the position basing on which START was found.
2662 (let ((start-point (point)) depth state start prestart)
2663 (if (and parse-start
2664 (<= parse-start start-point))
2665 (goto-char parse-start)
2666 (beginning-of-defun)
2667 (setq start-state nil))
2668 (setq prestart (point))
2670 ;; Try to go out, if sub is not on the outermost level
2671 (while (< (point) start-point)
2672 (setq start (point) parse-start start depth nil
2673 state (parse-partial-sexp start start-point -1))
2674 (if (> (car state) -1) nil
2675 ;; The current line could start like }}}, so the indentation
2676 ;; corresponds to a different level than what we reached
2678 (beginning-of-line 2))) ; Go to the next line.
2679 (if start (goto-char start))) ; Not at the start of file
2680 (setq start (point))
2681 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
2682 (list start state depth prestart))))
2684 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
2686 (defun cperl-beginning-of-property (p prop &optional lim)
2687 "Given that P has a property PROP, find where the property starts.
2688 Will not look before LIM."
2689 ;;; XXXX What to do at point-max???
2690 (or (previous-single-property-change (cperl-1+ p) prop lim)
2692 ;;; (cond ((eq p (point-min))
2694 ;;; ((and lim (<= p lim))
2696 ;;; ((not (get-text-property (1- p) prop))
2698 ;;; (t (or (previous-single-property-change p look-prop lim)
2702 (defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start
2703 ;; Old workhorse for calculation of indentation; the major problem
2704 ;; is that it mixes the sniffer logic to understand what the current line
2705 ;; MEANS with the logic to actually calculate where to indent it.
2706 ;; The latter part should be eventually moved to `cperl-calculate-indent';
2707 ;; actually, this is mostly done now...
2708 (cperl-update-syntaxification (point) (point))
2709 (let ((res (get-text-property (point) 'syntax-type)))
2712 ((and (memq res '(pod here-doc here-doc-delim format))
2713 (not (get-text-property (point) 'indentable)))
2715 ;; before start of POD - whitespace found since do not have 'pod!
2716 ((looking-at "[ \t]*\n=")
2717 (error "Spaces before POD section!"))
2718 ((and (not cperl-indent-left-aligned-comments)
2720 [comment-special:at-beginning-of-line])
2721 ((get-text-property (point) 'in-pod)
2725 (let* ((indent-point (point))
2726 (char-after-pos (save-excursion
2727 (skip-chars-forward " \t")
2729 (char-after (char-after char-after-pos))
2730 (pre-indent-point (point))
2731 p prop look-prop is-block delim)
2732 (save-excursion ; Know we are not in POD, find appropriate pos before
2733 (cperl-backward-to-noncomment nil)
2734 (setq p (max (point-min) (1- (point)))
2735 prop (get-text-property p 'syntax-type)
2736 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
2738 (if (memq prop '(pod here-doc format here-doc-delim))
2740 (goto-char (cperl-beginning-of-property p look-prop))
2742 (setq pre-indent-point (point)))))
2743 (goto-char pre-indent-point) ; Orig line skipping preceeding pod/etc
2744 (let* ((case-fold-search nil)
2745 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
2746 (start (or (nth 2 parse-data) ; last complete sexp terminated
2747 (nth 0 s-s))) ; Good place to start parsing
2749 (containing-sexp (car (cdr state)))
2752 ;;containing-sexp ;; We are buggy at toplevel :-(
2755 (setcar parse-data pre-indent-point)
2756 (setcar (cdr parse-data) state)
2757 (or (nth 2 parse-data)
2758 (setcar (cddr parse-data) start))
2759 ;; Before this point: end of statement
2760 (setq old-indent (nth 3 parse-data))))
2761 (cond ((get-text-property (point) 'indentable)
2762 ;; indent to "after" the surrounding open
2763 ;; (same offset as `cperl-beautify-regexp-piece'),
2764 ;; skip blanks if we do not close the expression.
2765 (setq delim ; We do not close the expression
2767 (cperl-1+ char-after-pos) 'indentable)
2768 p (1+ (cperl-beginning-of-property
2769 (point) 'indentable))
2770 is-block ; misused for: preceeding line in REx
2771 (save-excursion ; Find preceeding line
2772 (cperl-backward-to-noncomment p)
2775 (progn ; get indent from the first line
2777 (skip-chars-forward " \t")
2778 (if (memq (char-after (point))
2780 nil ; Can't use intentation of this line...
2782 (skip-chars-forward " \t")
2784 prop (parse-partial-sexp p char-after-pos))
2785 (cond ((not delim) ; End the REx, ignore is-block
2786 (vector 'indentable 'terminator p is-block))
2787 (is-block ; Indent w.r.t. preceeding line
2788 (vector 'indentable 'cont-line char-after-pos
2789 is-block char-after p))
2790 (t ; No preceeding line...
2791 (vector 'indentable 'first-line p))))
2792 ((get-text-property char-after-pos 'REx-part2)
2793 (vector 'REx-part2 (point)))
2798 ;; XXXX Do we need to special-case this?
2799 ((null containing-sexp)
2800 ;; Line is at top level. May be data or function definition,
2801 ;; or may be function argument declaration.
2802 ;; Indent like the previous top level line
2803 ;; unless that ends in a closeparen without semicolon,
2804 ;; in which case this line is the first argument decl.
2805 (skip-chars-forward " \t")
2806 (cperl-backward-to-noncomment (or old-indent (point-min)))
2809 (eq (point) old-indent) ; old-indent was at comment
2810 (eq (preceding-char) ?\;)
2812 (and (eq (preceding-char) ?\})
2813 (cperl-after-block-and-statement-beg
2814 (point-min))) ; Was start - too close
2815 (memq char-after (append ")]}" nil))
2816 (and (eq (preceding-char) ?\:) ; label
2819 (skip-chars-backward " \t")
2820 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
2821 (get-text-property (point) 'first-format-line)))
2823 ;; Look at previous line that's at column 0
2824 ;; to determine whether we are in top-level decls
2825 ;; or function's arg decls. Set basic-indent accordingly.
2826 ;; Now add a little if this is a continuation line.
2829 (not (eq char-after ?\C-j))
2830 (setcdr (cddr parse-data)
2831 (list pre-indent-point)))
2832 (vector 'toplevel start char-after state (nth 2 s-s)))
2835 (and (setq delim (= (char-after containing-sexp) ?{))
2836 (save-excursion ; Is it a hash?
2837 (goto-char containing-sexp)
2839 cperl-indent-parens-as-block))
2840 ;; group is an expression, not a block:
2841 ;; indent to just after the surrounding open parens,
2842 ;; skip blanks if we do not close the expression.
2843 (goto-char (1+ containing-sexp))
2844 (or (memq char-after
2845 (append (if delim "}" ")]}") nil))
2846 (looking-at "[ \t]*\\(#\\|$\\)")
2847 (skip-chars-forward " \t"))
2848 (setq old-indent (point)) ; delim=is-brace
2849 (vector 'in-parens char-after (point) delim containing-sexp))
2851 ;; Statement level. Is it a continuation or a new statement?
2852 ;; Find previous non-comment character.
2853 (goto-char pre-indent-point) ; Skip one level of POD/etc
2854 (cperl-backward-to-noncomment containing-sexp)
2855 ;; Back up over label lines, since they don't
2856 ;; affect whether our line is a continuation.
2858 (while;;(or (eq (preceding-char) ?\,)
2859 (and (eq (preceding-char) ?:)
2860 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
2861 (memq (char-syntax (char-after (- (point) 2)))
2864 ;; This is always FALSE?
2865 (if (eq (preceding-char) ?\,)
2866 ;; Will go to beginning of line, essentially.
2867 ;; Will ignore embedded sexpr XXXX.
2868 (cperl-backward-to-start-of-continued-exp containing-sexp))
2870 (cperl-backward-to-noncomment containing-sexp))
2871 ;; Now we get non-label preceeding the indent point
2872 (if (not (or (eq (1- (point)) containing-sexp)
2873 (memq (preceding-char)
2874 (append (if is-block " ;{" " ,;{") '(nil)))
2875 (and (eq (preceding-char) ?\})
2876 (cperl-after-block-and-statement-beg
2878 (get-text-property (point) 'first-format-line)))
2879 ;; This line is continuation of preceding line's statement;
2880 ;; indent `cperl-continued-statement-offset' more than the
2881 ;; previous line of the statement.
2883 ;; There might be a label on this line, just
2884 ;; consider it bad style and ignore it.
2886 (cperl-backward-to-start-of-continued-exp containing-sexp)
2887 (vector 'continuation (point) char-after is-block delim))
2888 ;; This line starts a new statement.
2889 ;; Position following last unclosed open brace
2890 (goto-char containing-sexp)
2891 ;; Is line first statement after an open-brace?
2893 ;; If no, find that first statement and indent like
2894 ;; it. If the first statement begins with label, do
2895 ;; not believe when the indentation of the label is too
2899 (let ((colon-line-end 0))
2901 (progn (skip-chars-forward " \t\n")
2902 (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]\\|=[a-zA-Z]"))
2903 ;; Skip over comments and labels following openbrace.
2904 (cond ((= (following-char) ?\#)
2906 ((= (following-char) ?\=)
2908 (or (next-single-property-change (point) 'in-pod)
2909 (point-max)))) ; do not loop if no syntaxification
2912 (save-excursion (end-of-line)
2913 (setq colon-line-end (point)))
2914 (search-forward ":"))))
2915 ;; We are at beginning of code (NOT label or comment)
2916 ;; First, the following code counts
2917 ;; if it is before the line we want to indent.
2918 (and (< (point) indent-point)
2919 (vector 'have-prev-sibling (point) colon-line-end
2922 ;; If no previous statement,
2923 ;; indent it relative to line brace is on.
2925 ;; For open-braces not the first thing in a line,
2926 ;; add in cperl-brace-imaginary-offset.
2928 ;; If first thing on a line: ?????
2929 ;; Move back over whitespace before the openbrace.
2930 (setq ; brace first thing on a line
2931 old-indent (progn (skip-chars-backward " \t") (bolp)))
2932 ;; Should we indent w.r.t. earlier than start?
2933 ;; Move to start of control group, possibly on a different line
2934 (or cperl-indent-wrt-brace
2935 (cperl-backward-to-noncomment (point-min)))
2936 ;; If the openbrace is preceded by a parenthesized exp,
2937 ;; move to the beginning of that;
2938 (if (eq (preceding-char) ?\))
2941 (cperl-backward-to-noncomment (point-min))))
2942 ;; In the case it starts a subroutine, indent with
2943 ;; respect to `sub', not with respect to the
2944 ;; first thing on the line, say in the case of
2945 ;; anonymous sub in a hash.
2946 (if (and;; Is it a sub in group starting on this line?
2947 (cond ((get-text-property (point) 'attrib-group)
2948 (goto-char (cperl-beginning-of-property
2949 (point) 'attrib-group)))
2950 ((eq (preceding-char) ?b)
2952 (looking-at "sub\\>")))
2953 (setq p (nth 1 ; start of innermost containing list
2955 (save-excursion (beginning-of-line)
2959 (goto-char (1+ p)) ; enclosing block on the same line
2960 (skip-chars-forward " \t")
2961 (vector 'code-start-in-block containing-sexp char-after
2962 (and delim (not is-block)) ; is a HASH
2963 old-indent ; brace first thing on a line
2964 t (point) ; have something before...
2968 ;; Get initial indentation of the line we are on.
2969 ;; If line starts with label, calculate label indentation
2970 (vector 'code-start-in-block containing-sexp char-after
2971 (and delim (not is-block)) ; is a HASH
2972 old-indent ; brace first thing on a line
2973 nil (point) ; nothing interesting before
2976 (defvar cperl-indent-rules-alist
2977 '((pod nil) ; via `syntax-type' property
2978 (here-doc nil) ; via `syntax-type' property
2979 (here-doc-delim nil) ; via `syntax-type' property
2980 (format nil) ; via `syntax-type' property
2981 (in-pod nil) ; via `in-pod' property
2982 (comment-special:at-beginning-of-line nil)
2985 "Alist of indentation rules for CPerl mode.
2988 number: add this amount of indentation.
2992 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
2993 "Return appropriate indentation for current line as Perl code.
2994 In usual case returns an integer: the column to indent to.
2995 Returns nil if line starts inside a string, t if in a comment.
2997 Will not correct the indentation for labels, but will correct it for braces
2998 and closing parentheses and brackets."
2999 ;; This code is still a broken architecture: in some cases we need to
3000 ;; compensate for some modifications which `cperl-indent-line' will add later
3002 (let ((i (cperl-sniff-for-indent parse-data)) what p)
3004 ;;((or (null i) (eq i t) (numberp i))
3007 (setq what (assoc (elt i 0) cperl-indent-rules-alist))
3009 (what (cadr what)) ; Load from table
3011 ;; Indenters for regular expressions with //x and qw()
3013 ((eq 'REx-part2 (elt i 0)) ;; [self start] start of /REP in s//REP/x
3014 (goto-char (elt i 1))
3015 (condition-case nil ; Use indentation of the 1st part
3018 ((eq 'indentable (elt i 0)) ; Indenter for REGEXP qw() etc
3019 (cond ;;; [indentable terminator start-pos is-block]
3020 ((eq 'terminator (elt i 1)) ; Lone terminator of "indentable string"
3021 (goto-char (elt i 2)) ; After opening parens
3022 (1- (current-column)))
3023 ((eq 'first-line (elt i 1)); [indentable first-line start-pos]
3024 (goto-char (elt i 2))
3025 (+ (or cperl-regexp-indent-step cperl-indent-level)
3028 ((eq 'cont-line (elt i 1)); [indentable cont-line pos prev-pos first-char start-pos]
3029 ;; Indent as the level after closing parens
3030 (goto-char (elt i 2)) ; indent line
3031 (skip-chars-forward " \t)") ; Skip closing parens
3033 (goto-char (elt i 3)) ; previous line
3034 (skip-chars-forward " \t)") ; Skip closing parens
3035 ;; Number of parens in between:
3036 (setq p (nth 0 (parse-partial-sexp (point) p))
3037 what (elt i 4)) ; First char on current line
3038 (goto-char (elt i 3)) ; previous line
3039 (+ (* p (or cperl-regexp-indent-step cperl-indent-level))
3040 (cond ((eq what ?\) )
3041 (- cperl-close-paren-offset)) ; compensate
3043 (- (or cperl-regexp-indent-step cperl-indent-level)))
3045 (if (eq (following-char) ?\| )
3046 (or cperl-regexp-indent-step cperl-indent-level)
3050 (error "Unrecognized value of indent: %s" i))))
3052 ;; Indenter for stuff at toplevel
3054 ((eq 'toplevel (elt i 0)) ;; [toplevel start char-after state immed-after-block]
3055 (+ (save-excursion ; To beg-of-defun, or end of last sexp
3056 (goto-char (elt i 1)) ; start = Good place to start parsing
3057 (- (current-indentation) ;
3058 (if (elt i 4) cperl-indent-level 0))) ; immed-after-block
3059 (if (eq (elt i 2) ?{) cperl-continued-brace-offset 0) ; char-after
3060 ;; Look at previous line that's at column 0
3061 ;; to determine whether we are in top-level decls
3062 ;; or function's arg decls. Set basic-indent accordingly.
3063 ;; Now add a little if this is a continuation line.
3064 (if (elt i 3) ; state (XXX What is the semantic???)
3066 cperl-continued-statement-offset)))
3068 ;; Indenter for stuff in "parentheses" (or brackets, braces-as-hash)
3070 ((eq 'in-parens (elt i 0))
3071 ;; in-parens char-after old-indent-point is-brace containing-sexp
3073 ;; group is an expression, not a block:
3074 ;; indent to just after the surrounding open parens,
3075 ;; skip blanks if we do not close the expression.
3077 (goto-char (elt i 2)) ; old-indent-point
3079 (if (and (elt i 3) ; is-brace
3080 (eq (elt i 1) ?\})) ; char-after
3081 ;; Correct indentation of trailing ?\}
3082 (+ cperl-indent-level cperl-close-paren-offset)
3085 ;; Indenter for continuation lines
3087 ((eq 'continuation (elt i 0))
3088 ;; [continuation statement-start char-after is-block is-brace]
3089 (goto-char (elt i 1)) ; statement-start
3090 (+ (if (memq (elt i 2) (append "}])" nil)) ; char-after
3092 cperl-continued-statement-offset)
3093 (if (or (elt i 3) ; is-block
3094 (not (elt i 4)) ; is-brace
3095 (not (eq (elt i 2) ?\}))) ; char-after
3097 ;; Now it is a hash reference
3098 (+ cperl-indent-level cperl-close-paren-offset))
3099 ;; Labels do not take :: ...
3100 (if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
3101 (if (> (current-indentation) cperl-min-label-indent)
3102 (- (current-indentation) cperl-label-offset)
3103 ;; Do not move `parse-data', this should
3104 ;; be quick anyway (this comment comes
3105 ;; from different location):
3106 (cperl-calculate-indent))
3108 (if (eq (elt i 2) ?\{) ; char-after
3109 cperl-continued-brace-offset 0)))
3111 ;; Indenter for lines in a block which are not leading lines
3113 ((eq 'have-prev-sibling (elt i 0))
3114 ;; [have-prev-sibling sibling-beg colon-line-end block-start]
3115 (goto-char (elt i 1))
3116 (if (> (elt i 2) (point)) ; colon-line-end; After-label, same line
3117 (if (> (current-indentation)
3118 cperl-min-label-indent)
3119 (- (current-indentation) cperl-label-offset)
3120 ;; Do not believe: `max' was involved in calculation of indent
3121 (+ cperl-indent-level
3123 (goto-char (elt i 3)) ; block-start
3124 (current-indentation))))
3127 ;; Indenter for the first line in a block
3129 ((eq 'code-start-in-block (elt i 0))
3130 ;;[code-start-in-block before-brace char-after
3131 ;; is-a-HASH-ref brace-is-first-thing-on-a-line
3132 ;; group-starts-before-start-of-sub start-of-control-group]
3133 (goto-char (elt i 1))
3134 ;; For open brace in column zero, don't let statement
3135 ;; start there too. If cperl-indent-level=0,
3136 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3137 (+ (if (and (bolp) (zerop cperl-indent-level))
3138 (+ cperl-brace-offset cperl-continued-statement-offset)
3140 (if (and (elt i 3) ; is-a-HASH-ref
3141 (eq (elt i 2) ?\})) ; char-after: End of a hash reference
3142 (+ cperl-indent-level cperl-close-paren-offset)
3144 ;; Unless openbrace is the first nonwhite thing on the line,
3145 ;; add the cperl-brace-imaginary-offset.
3146 (if (elt i 4) 0 ; brace-is-first-thing-on-a-line
3147 cperl-brace-imaginary-offset)
3149 (goto-char (elt i 6)) ; start-of-control-group
3150 (if (elt i 5) ; group-starts-before-start-of-sub
3152 ;; Get initial indentation of the line we are on.
3153 ;; If line starts with label, calculate label indentation
3156 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3157 (if (> (current-indentation) cperl-min-label-indent)
3158 (- (current-indentation) cperl-label-offset)
3159 ;; Do not move `parse-data', this should
3161 (cperl-calculate-indent))
3162 (current-indentation))))))
3164 (error "Unrecognized value of indent: %s" i))))
3166 (error "Got strange value of indent: %s" i))))))
3168 (defvar cperl-indent-alist
3172 (toplevel-after-parenth 2)
3173 (toplevel-continued 2)
3175 "Alist of indentation rules for CPerl mode.
3178 number: add this amount of indentation.
3180 Not finished, not used.")
3182 (defun cperl-where-am-i (&optional parse-start start-state)
3184 "Return a list of lists ((TYPE POS)...) of good points before the point.
3185 POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'.
3187 Not finished, not used."
3189 (let* ((start-point (point)) unused
3190 (s-s (cperl-get-state))
3193 (prestart (nth 3 s-s))
3194 (containing-sexp (car (cdr state)))
3195 (case-fold-search nil)
3196 (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
3197 (cond ((nth 3 state) ; In string
3198 (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
3199 ((nth 4 state) ; In comment
3200 (setq res (cons '(comment) res)))
3201 ((null containing-sexp)
3202 ;; Line is at top level.
3203 ;; Indent like the previous top level line
3204 ;; unless that ends in a closeparen without semicolon,
3205 ;; in which case this line is the first argument decl.
3206 (cperl-backward-to-noncomment (or parse-start (point-min)))
3207 ;;(skip-chars-backward " \t\f\n")
3210 (memq (preceding-char) (append ";}" nil)))
3211 (setq res (cons (list 'toplevel start) res)))
3212 ((eq (preceding-char) ?\) )
3213 (setq res (cons (list 'toplevel-after-parenth start) res)))
3215 (setq res (cons (list 'toplevel-continued start) res)))))
3216 ((/= (char-after containing-sexp) ?{)
3217 ;; line is expression, not statement:
3218 ;; indent to just after the surrounding open.
3219 ;; skip blanks if we do not close the expression.
3220 (setq res (cons (list 'expression-blanks
3222 (goto-char (1+ containing-sexp))
3223 (or (looking-at "[ \t]*\\(#\\|$\\)")
3224 (skip-chars-forward " \t"))
3226 (cons (list 'expression containing-sexp) res))))
3228 ;; Containing-expr starts with \{. Check whether it is a hash.
3229 (goto-char containing-sexp)
3230 (not (cperl-block-p)))
3231 (setq res (cons (list 'expression-blanks
3233 (goto-char (1+ containing-sexp))
3234 (or (looking-at "[ \t]*\\(#\\|$\\)")
3235 (skip-chars-forward " \t"))
3237 (cons (list 'expression containing-sexp) res))))
3240 (setq res (cons (list 'in-block containing-sexp) res))
3241 ;; Is it a continuation or a new statement?
3242 ;; Find previous non-comment character.
3243 (cperl-backward-to-noncomment containing-sexp)
3244 ;; Back up over label lines, since they don't
3245 ;; affect whether our line is a continuation.
3246 ;; Back up comma-delimited lines too ?????
3247 (while (or (eq (preceding-char) ?\,)
3248 (save-excursion (cperl-after-label)))
3249 (if (eq (preceding-char) ?\,)
3250 ;; Will go to beginning of line, essentially
3251 ;; Will ignore embedded sexpr XXXX.
3252 (cperl-backward-to-start-of-continued-exp containing-sexp))
3254 (cperl-backward-to-noncomment containing-sexp))
3255 ;; Now we get the answer.
3256 (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
3257 ;; This line is continuation of preceding line's statement.
3258 (list (list 'statement-continued containing-sexp))
3259 ;; This line starts a new statement.
3260 ;; Position following last unclosed open.
3261 (goto-char containing-sexp)
3262 ;; Is line first statement after an open-brace?
3264 ;; If no, find that first statement and indent like
3265 ;; it. If the first statement begins with label, do
3266 ;; not believe when the indentation of the label is too
3270 (let ((colon-line-end 0))
3271 (while (progn (skip-chars-forward " \t\n" start-point)
3272 (and (< (point) start-point)
3274 "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
3275 ;; Skip over comments and labels following openbrace.
3276 (cond ((= (following-char) ?\#)
3281 (save-excursion (end-of-line)
3282 (setq colon-line-end (point)))
3283 (search-forward ":"))))
3284 ;; Now at the point, after label, or at start
3285 ;; of first statement in the block.
3286 (and (< (point) start-point)
3287 (if (> colon-line-end (point))
3288 ;; Before statement after label
3289 (if (> (current-indentation)
3290 cperl-min-label-indent)
3291 (list (list 'label-in-block (point)))
3292 ;; Do not believe: `max' is involved
3294 (list 'label-in-block-min-indent (point))))
3296 (list 'statement-in-block (point))))))
3297 ;; If no previous statement,
3298 ;; indent it relative to line brace is on.
3299 ;; For open brace in column zero, don't let statement
3300 ;; start there too. If cperl-indent-level is zero,
3301 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3302 ;; For open-braces not the first thing in a line,
3303 ;; add in cperl-brace-imaginary-offset.
3305 ;; If first thing on a line: ?????
3306 (setq unused ; This is not finished...
3307 (+ (if (and (bolp) (zerop cperl-indent-level))
3308 (+ cperl-brace-offset cperl-continued-statement-offset)
3310 ;; Move back over whitespace before the openbrace.
3311 ;; If openbrace is not first nonwhite thing on the line,
3312 ;; add the cperl-brace-imaginary-offset.
3313 (progn (skip-chars-backward " \t")
3314 (if (bolp) 0 cperl-brace-imaginary-offset))
3315 ;; If the openbrace is preceded by a parenthesized exp,
3316 ;; move to the beginning of that;
3317 ;; possibly a different line
3319 (if (eq (preceding-char) ?\))
3321 ;; Get initial indentation of the line we are on.
3322 ;; If line starts with label, calculate label indentation
3325 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3326 (if (> (current-indentation) cperl-min-label-indent)
3327 (- (current-indentation) cperl-label-offset)
3328 (cperl-calculate-indent))
3329 (current-indentation)))))))))
3332 (defun cperl-calculate-indent-within-comment ()
3333 "Return the indentation amount for line, assuming that
3334 the current line is to be regarded as part of a block comment."
3335 (let (end star-start)
3338 (skip-chars-forward " \t")
3340 (and (= (following-char) ?#)
3342 (cperl-to-comment-or-eol)
3348 (defun cperl-to-comment-or-eol ()
3349 "Go to position before comment on the current line, or to end of line.
3350 Returns true if comment is found. In POD will not move the point."
3351 ;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
3352 ;; then looks for literal # or end-of-line.
3353 (let (state stop-in cpoint (lim (progn (end-of-line) (point))) pr e)
3354 (or cperl-font-locking
3355 (cperl-update-syntaxification lim lim))
3357 (if (setq pr (get-text-property (point) 'syntax-type))
3358 (setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
3359 (if (or (eq pr 'pod)
3360 (if (or (not e) (> e lim)) ; deep inside a group
3361 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
3362 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
3363 ;; Else - need to do it the hard way
3364 (and (and e (<= e lim))
3366 (while (not stop-in)
3367 (setq state (parse-partial-sexp (point) lim nil nil nil t))
3369 ;; If fails (beginning-of-line inside sexp), then contains not-comment
3370 (if (nth 4 state) ; After `#';
3371 ; (nth 2 state) can be
3372 ; beginning of m,s,qq and so
3376 (setq cpoint (point))
3377 (goto-char (nth 2 state))
3379 ((looking-at "\\(s\\|tr\\)\\>")
3380 (or (re-search-forward
3381 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
3384 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
3385 (or (re-search-forward
3386 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
3389 (t ; It was fair comment
3390 (setq stop-in t) ; Finish
3391 (goto-char (1- cpoint)))))
3392 (setq stop-in t) ; Finish
3394 (setq stop-in t))) ; Finish
3397 (defsubst cperl-modify-syntax-type (at how)
3398 (if (< at (point-max))
3400 (put-text-property at (1+ at) 'syntax-table how)
3401 (put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
3403 (defun cperl-protect-defun-start (s e)
3404 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
3407 (while (re-search-forward "^\\s(" e 'to-end)
3408 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
3410 (defun cperl-commentify (bb e string &optional noface)
3411 (if cperl-use-syntax-table-text-property
3412 (if (eq noface 'n) ; Only immediate
3414 ;; We suppose that e is _after_ the end of construction, as after eol.
3415 (setq string (if string cperl-st-sfence cperl-st-cfence))
3417 ;; one-char string/comment?!
3418 (cperl-modify-syntax-type bb cperl-st-punct)
3419 (cperl-modify-syntax-type bb string)
3420 (cperl-modify-syntax-type (1- e) string))
3421 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
3422 (put-text-property (1+ bb) (1- e)
3423 'syntax-table cperl-string-syntax-table))
3424 (cperl-protect-defun-start bb e))
3427 (not cperl-pod-here-fontify)
3428 (put-text-property bb e 'face (if string 'font-lock-string-face
3429 'font-lock-comment-face)))))
3431 (defvar cperl-starters '(( ?\( . ?\) )
3436 (defun cperl-cached-syntax-table (st)
3437 "Get a syntax table cached in ST, or create and cache into ST a syntax table.
3438 All the entries of the syntax table are \".\", except for a backslash, which
3442 (setcar st (make-syntax-table))
3446 (modify-syntax-entry i "." st)
3448 (modify-syntax-entry ?\\ "\\" st)
3451 (defun cperl-forward-re (lim end is-2arg st-l err-l argument
3452 &optional ostart oend)
3453 "Find the end of a regular expression or a stringish construct (q[] etc).
3454 The point should be before the starting delimiter.
3456 Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
3457 is s/// or tr/// like expression. If END is nil, generates an error
3458 message if needed. If SET-ST is non-nil, will use (or generate) a
3459 cached syntax table in ST-L. If ERR-L is non-nil, will store the
3460 error message in its CAR (unless it already contains some error
3461 message). ARGUMENT should be the name of the construct (used in error
3462 messages). OSTART, OEND may be set in recursive calls when processing
3463 the second argument of 2ARG construct.
3465 Works *before* syntax recognition is done. In IS-2ARG situation may
3466 modify syntax-type text property if the situation is too hard."
3467 (let (b starter ender st i i2 go-forward reset-st set-st)
3468 (skip-chars-forward " \t")
3469 ;; ender means matching-char matcher.
3471 starter (if (eobp) 0 (char-after b))
3472 ender (cdr (assoc starter cperl-starters)))
3473 ;; What if starter == ?\\ ????
3474 (setq st (cperl-cached-syntax-table st-l))
3476 ;; Whether we have an intermediate point
3478 ;; Prepare the syntax table:
3479 (if (not ender) ; m/blah/, s/x//, s/x/y/
3480 (modify-syntax-entry starter "$" st)
3481 (modify-syntax-entry starter (concat "(" (list ender)) st)
3482 (modify-syntax-entry ender (concat ")" (list starter)) st))
3485 ;; We use `$' syntax class to find matching stuff, but $$
3486 ;; is recognized the same as $, so we need to check this manually.
3487 (if (and (eq starter (char-after (cperl-1+ b)))
3489 ;; $ has TeXish matching rules, so $$ equiv $...
3491 (setq reset-st (syntax-table))
3492 (set-syntax-table st)
3494 (if (<= (point) (1+ b))
3495 (error "Unfinished regular expression"))
3496 (set-syntax-table reset-st)
3498 ;; Now the problem is with m;blah;;
3500 (eq (preceding-char)
3501 (char-after (- (point) 2)))
3504 (= 0 (% (skip-chars-backward "\\\\") 2)))
3506 ;; Now we are after the first part.
3507 (and is-2arg ; Have trailing part
3509 (eq (following-char) starter) ; Empty trailing part
3511 (or (eq (char-syntax (following-char)) ?.)
3512 ;; Make trailing letter into punctuation
3513 (cperl-modify-syntax-type (point) cperl-st-punct))
3514 (setq is-2arg nil go-forward t))) ; Ignore the tail
3515 (if is-2arg ; Not number => have second part
3517 (setq i (point) i2 i)
3519 (if (memq (following-char) '(?\s ?\t ?\n ?\f))
3521 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3522 (goto-char (match-end 0))
3523 (skip-chars-forward " \t\n\f"))
3526 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3527 (if ender (modify-syntax-entry ender "." st))
3529 (setq ender (cperl-forward-re lim end nil st-l err-l
3530 argument starter ender)
3531 ender (nth 2 ender)))))
3532 (error (goto-char lim)
3535 (set-syntax-table reset-st))
3538 "End of `%s%s%c ... %c' string/RE not found: %s"
3540 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
3541 starter (or ender starter) bb)
3542 (or (car err-l) (setcar err-l b)))))
3545 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3546 (if ender (modify-syntax-entry ender "." st))))
3547 ;; i: have 2 args, after end of the first arg
3548 ;; i2: start of the second arg, if any (before delim iff `ender').
3549 ;; ender: the last arg bounded by parens-like chars, the second one of them
3550 ;; starter: the starting delimiter of the first arg
3551 ;; go-forward: has 2 args, and the second part is empty
3552 (list i i2 ender starter go-forward)))
3554 (defun cperl-forward-group-in-re (&optional st-l)
3555 "Find the end of a group in a REx.
3556 Return the error message (if any). Does not work if delimiter is `)'.
3557 Works before syntax recognition is done."
3558 ;; Works *before* syntax recognition is done
3559 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3560 (let (st b reset-st)
3563 (setq st (cperl-cached-syntax-table st-l))
3564 (modify-syntax-entry ?\( "()" st)
3565 (modify-syntax-entry ?\) ")(" st)
3566 (setq reset-st (syntax-table))
3567 (set-syntax-table st)
3570 "cperl-forward-group-in-re: error %s" b)))
3571 ;; now restore the initial state
3574 (modify-syntax-entry ?\( "." st)
3575 (modify-syntax-entry ?\) "." st)))
3577 (set-syntax-table reset-st))
3581 (defvar font-lock-string-face)
3582 ;;(defvar font-lock-reference-face)
3583 (defvar font-lock-constant-face)
3584 (defsubst cperl-postpone-fontification (b e type val &optional now)
3585 ;; Do after syntactic fontification?
3586 (if cperl-syntaxify-by-font-lock
3587 (or now (put-text-property b e 'cperl-postpone (cons type val)))
3588 (put-text-property b e type val)))
3590 ;;; Here is how the global structures (those which cannot be
3591 ;;; recognized locally) are marked:
3593 ;; Start-to-end is marked `in-pod' ==> t
3594 ;; Each non-literal part is marked `syntax-type' ==> `pod'
3595 ;; Each literal part is marked `syntax-type' ==> `in-pod'
3597 ;; Start-to-end is marked `here-doc-group' ==> t
3598 ;; The body is marked `syntax-type' ==> `here-doc'
3599 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
3601 ;; First line (to =) marked `first-format-line' ==> t
3602 ;; After-this--to-end is marked `syntax-type' ==> `format'
3603 ;; d) 'Q'uoted string:
3604 ;; part between markers inclusive is marked `syntax-type' ==> `string'
3605 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
3606 ;; second part of s///e is marked `syntax-type' ==> `multiline'
3607 ;; e) Attributes of subroutines: `attrib-group' ==> t
3608 ;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
3609 ;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
3611 ;;; In addition, some parts of RExes may be marked as `REx-interpolated'
3612 ;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
3614 (defun cperl-unwind-to-safe (before &optional end)
3615 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
3616 (let ((pos (point)) opos)
3617 (while (and pos (progn
3619 (get-text-property (setq pos (point)) 'syntax-type)))
3621 pos (cperl-beginning-of-property pos 'syntax-type))
3622 (if (eq pos (point-min))
3627 (goto-char (cperl-1- pos))
3630 (goto-char (setq pos (cperl-1- pos))))
3632 (goto-char (point-min))))
3634 (and (looking-at "\n*=")
3635 (/= 0 (skip-chars-backward "\n"))
3639 ;; Do the same for end, going small steps
3641 (while (and end (get-text-property end 'syntax-type))
3643 end (next-single-property-change end 'syntax-type nil (point-max)))
3644 (if end (progn (goto-char end)
3645 (or (bolp) (forward-line 1))
3646 (setq end (point)))))
3649 ;;; These are needed for byte-compile (at least with v19)
3650 (defvar cperl-nonoverridable-face)
3651 (defvar font-lock-variable-name-face)
3652 (defvar font-lock-function-name-face)
3653 (defvar font-lock-keyword-face)
3654 (defvar font-lock-builtin-face)
3655 (defvar font-lock-type-face)
3656 (defvar font-lock-comment-face)
3657 (defvar font-lock-warning-face)
3659 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
3660 "Syntaxically mark (and fontify) attributes of a subroutine.
3661 Should be called with the point before leading colon of an attribute."
3662 ;; Works *before* syntax recognition is done
3663 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3664 (let (st b p reset-st after-first (start (point)) start1 end1)
3668 "\\(" ; 1=optional? colon
3669 ":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
3671 (if after-first "?" "")
3672 ;; No space between name and paren allowed...
3673 "\\(\\sw+\\)" ; 3=name
3674 "\\((\\)?")) ; 4=optional paren
3675 (and (match-beginning 1)
3676 (cperl-postpone-fontification
3677 (match-beginning 0) (cperl-1+ (match-beginning 0))
3678 'face font-lock-constant-face))
3679 (setq start1 (match-beginning 3) end1 (match-end 3))
3680 (cperl-postpone-fontification start1 end1
3681 'face font-lock-constant-face)
3682 (goto-char end1) ; end or before `('
3683 (if (match-end 4) ; Have attribute arguments...
3686 (setq st (cperl-cached-syntax-table st-l))
3687 (modify-syntax-entry ?\( "()" st)
3688 (modify-syntax-entry ?\) ")(" st))
3689 (setq reset-st (syntax-table) p (point))
3690 (set-syntax-table st)
3692 (set-syntax-table reset-st)
3694 (cperl-commentify p (point) t))) ; mark as string
3695 (forward-comment (buffer-size))
3696 (setq after-first t))
3698 "L%d: attribute `%s': %s"
3699 (count-lines (point-min) (point))
3700 (and start1 end1 (buffer-substring start1 end1)) b)
3704 (put-text-property start (point)
3705 'attrib-group (if (looking-at "{") t 0))
3707 (< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
3708 ;; Apparently, we do not need `multiline': faces added now
3709 (put-text-property (+ 3 pos) (cperl-1+ (point))
3710 'syntax-type 'sub-decl))
3711 (and b-fname ; Fontify here: the following condition
3712 (cperl-postpone-fontification ; is too hard to determine by
3713 b-fname e-fname 'face ; a REx, so do it here
3714 (if (looking-at "{")
3715 font-lock-function-name-face
3716 font-lock-variable-name-face)))))
3717 ;; now restore the initial state
3720 (modify-syntax-entry ?\( "." st)
3721 (modify-syntax-entry ?\) "." st)))
3723 (set-syntax-table reset-st))))
3725 (defsubst cperl-look-at-leading-count (is-x-REx e)
3726 (if (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
3727 (1- e) t) ; return nil on failure, no moving
3728 (if (eq ?\{ (preceding-char)) nil
3729 (cperl-postpone-fontification
3730 (1- (point)) (point)
3731 'face font-lock-warning-face))))
3733 ;;; Debugging this may require (setq max-specpdl-size 2000)...
3734 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc)
3735 "Scans the buffer for hard-to-parse Perl constructions.
3736 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
3737 the sections using `cperl-pod-head-face', `cperl-pod-face',
3740 (or min (setq min (point-min)
3741 cperl-syntax-state nil
3742 cperl-syntax-done-to min))
3743 (or max (setq max (point-max)))
3744 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
3745 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
3746 is-REx is-x-REx REx-subgr-start REx-subgr-end was-subgr i2 hairy-RE
3747 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
3748 (modified (buffer-modified-p)) overshoot is-o-REx
3749 (after-change-functions nil)
3750 (cperl-font-locking t)
3751 (use-syntax-state (and cperl-syntax-state
3752 (>= min (car cperl-syntax-state))))
3753 (state-point (if use-syntax-state
3754 (car cperl-syntax-state)
3756 (state (if use-syntax-state
3757 (cdr cperl-syntax-state)))
3758 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
3759 (st-l (list nil)) (err-l (list nil))
3760 ;; Somehow font-lock may be not loaded yet...
3761 ;; (e.g., when building TAGS via command-line call)
3762 (font-lock-string-face (if (boundp 'font-lock-string-face)
3763 font-lock-string-face
3764 'font-lock-string-face))
3765 (my-cperl-delimiters-face (if (boundp 'font-lock-constant-face)
3766 font-lock-constant-face
3767 'font-lock-constant-face))
3768 (my-cperl-REx-spec-char-face ; [] ^.$ and wrapper-of ({})
3769 (if (boundp 'font-lock-function-name-face)
3770 font-lock-function-name-face
3771 'font-lock-function-name-face))
3772 (font-lock-variable-name-face ; interpolated vars and ({})-code
3773 (if (boundp 'font-lock-variable-name-face)
3774 font-lock-variable-name-face
3775 'font-lock-variable-name-face))
3776 (font-lock-function-name-face ; used in `cperl-find-sub-attrs'
3777 (if (boundp 'font-lock-function-name-face)
3778 font-lock-function-name-face
3779 'font-lock-function-name-face))
3780 (font-lock-constant-face ; used in `cperl-find-sub-attrs'
3781 (if (boundp 'font-lock-constant-face)
3782 font-lock-constant-face
3783 'font-lock-constant-face))
3784 (my-cperl-REx-0length-face ; 0-length, (?:)etc, non-literal \
3785 (if (boundp 'font-lock-builtin-face)
3786 font-lock-builtin-face
3787 'font-lock-builtin-face))
3788 (font-lock-comment-face
3789 (if (boundp 'font-lock-comment-face)
3790 font-lock-comment-face
3791 'font-lock-comment-face))
3792 (font-lock-warning-face
3793 (if (boundp 'font-lock-warning-face)
3794 font-lock-warning-face
3795 'font-lock-warning-face))
3796 (my-cperl-REx-ctl-face ; (|)
3797 (if (boundp 'font-lock-keyword-face)
3798 font-lock-keyword-face
3799 'font-lock-keyword-face))
3800 (my-cperl-REx-modifiers-face ; //gims
3801 (if (boundp 'cperl-nonoverridable-face)
3802 cperl-nonoverridable-face
3803 'cperl-nonoverridable-face))
3804 (my-cperl-REx-length1-face ; length=1 escaped chars, POSIX classes
3805 (if (boundp 'font-lock-type-face)
3807 'font-lock-type-face))
3808 (stop-point (if ignore-max
3813 "\\(\\`\n?\\|^\n\\)=" ; POD
3815 ;; One extra () before this:
3818 ;; First variant "BLAH" or just ``.
3819 "[ \t]*" ; Yes, whitespace is allowed!
3820 "\\([\"'`]\\)" ; 2 + 1 = 3
3821 "\\([^\"'`\n]*\\)" ; 3 + 1
3824 ;; Second variant: Identifier or \ID (same as 'ID') or empty
3825 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3826 ;; Do not have <<= or << 30 or <<30 or << $blah.
3827 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3828 "\\(\\)" ; To preserve count of pars :-( 6 + 1
3831 ;; 1+6 extra () before this:
3832 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" ;FRMAT
3833 (if cperl-use-syntax-table-text-property
3836 ;; 1+6+2=9 extra () before this:
3837 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT
3839 ;; 1+6+2+1=10 extra () before this:
3840 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3842 ;; 1+6+2+1+1=11 extra () before this
3843 "\\<sub\\>" ; sub with proto/attr
3845 cperl-white-and-comment-rex
3846 "\\(::[a-zA-Z_:'0-9]*\\|[a-zA-Z_'][a-zA-Z_:'0-9]*\\)\\)?" ; name
3848 cperl-maybe-white-and-comment-rex
3849 "\\(([^()]*)\\|:[^:]\\)\\)" ; prototype or attribute start
3851 ;; 1+6+2+1+1+6=17 extra () before this:
3852 "\\$\\(['{]\\)" ; $' or ${foo}
3854 ;; 1+6+2+1+1+6+1=18 extra () before this (old pack'var syntax;
3855 ;; we do not support intervening comments...):
3856 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
3857 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
3859 "__\\(END\\|DATA\\)__" ; __END__ or __DATA__
3860 ;; 1+6+2+1+1+6+1+1+1=20 extra () before this:
3862 "\\\\\\(['`\"($]\\)") ; BACKWACKED something-hairy
3868 (message "Scanning for \"hard\" Perl constructions..."))
3869 ;;(message "find: %s --> %s" min max)
3870 (and cperl-pod-here-fontify
3871 ;; We had evals here, do not know why...
3872 (setq face cperl-pod-face
3873 head-face cperl-pod-head-face
3874 here-face cperl-here-face))
3875 (remove-text-properties min max
3876 '(syntax-type t in-pod t syntax-table t
3887 ;; Need to remove face as well...
3889 (and (eq system-type 'emx)
3891 (let ((case-fold-search t))
3892 (looking-at "extproc[ \t]")) ; Analogue of #!
3893 (cperl-commentify min
3894 (save-excursion (end-of-line) (point))
3898 (re-search-forward search max t))
3899 (setq tmpend nil) ; Valid for most cases
3900 (setq b (match-beginning 0)
3901 state (save-excursion (parse-partial-sexp
3902 state-point b nil nil state))
3905 ;; 1+6+2+1+1+6=17 extra () before this:
3907 ((match-beginning 18) ; $' or ${foo}
3908 (if (eq (preceding-char) ?\') ; $'
3910 (setq b (1- (point))
3911 state (parse-partial-sexp
3912 state-point (1- b) nil nil state)
3914 (if (nth 3 state) ; in string
3915 (cperl-modify-syntax-type (1- b) cperl-st-punct))
3918 (setq bb (match-beginning 0))
3919 (cperl-modify-syntax-type bb cperl-st-punct)))
3920 ;; No processing in strings/comments beyond this point:
3921 ((or (nth 3 state) (nth 4 state))
3922 t) ; Do nothing in comment/string
3923 ((match-beginning 1) ; POD section
3924 ;; "\\(\\`\n?\\|^\n\\)="
3925 (setq b (match-beginning 0)
3926 state (parse-partial-sexp
3927 state-point b nil nil state)
3929 (if (or (nth 3 state) (nth 4 state)
3930 (looking-at "cut\\>"))
3931 (if (or (nth 3 state) (nth 4 state) ignore-max)
3932 nil ; Doing a chunk only
3933 (message "=cut is not preceded by a POD section")
3934 (or (car err-l) (setcar err-l (point))))
3939 tb (match-beginning 0)
3940 b1 nil) ; error condition
3941 ;; We do not search to max, since we may be called from
3942 ;; some hook of fontification, and max is random
3943 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
3946 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
3948 (message "=cut is not preceded by an empty line")
3950 (or (car err-l) (setcar err-l b))))))
3951 (beginning-of-line 2) ; An empty line after =cut is not POD!
3955 (remove-text-properties
3956 max e '(syntax-type t in-pod t syntax-table t
3968 (put-text-property b e 'in-pod t)
3969 (put-text-property b e 'syntax-type 'in-pod)
3971 (while (re-search-forward "\n\n[ \t]" e t)
3972 ;; We start 'pod 1 char earlier to include the preceding line
3974 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
3975 (cperl-put-do-not-fontify b (point) t)
3976 ;; mark the non-literal parts as PODs
3977 (if cperl-pod-here-fontify
3978 (cperl-postpone-fontification b (point) 'face face t))
3979 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
3982 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
3983 (cperl-put-do-not-fontify (point) e t)
3984 (if cperl-pod-here-fontify
3986 ;; mark the non-literal parts as PODs
3987 (cperl-postpone-fontification (point) e 'face face t)
3990 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
3992 (cperl-postpone-fontification
3993 (match-beginning 1) (match-end 1)
3995 (while (re-search-forward
3997 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
4000 (cperl-postpone-fontification
4001 (match-beginning 1) (match-end 1)
4003 (cperl-commentify bb e nil)
4005 (or (eq e (point-max))
4006 (forward-char -1)))) ; Prepare for immediate POD start.
4008 ;; We can do many here-per-line;
4009 ;; but multiline quote on the same line as <<HERE confuses us...
4010 ;; ;; One extra () before this:
4013 ;; ;; First variant "BLAH" or just ``.
4014 ;; "[ \t]*" ; Yes, whitespace is allowed!
4015 ;; "\\([\"'`]\\)" ; 2 + 1
4016 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
4019 ;; ;; Second variant: Identifier or \ID or empty
4020 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
4021 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
4022 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
4023 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
4025 ((match-beginning 2) ; 1 + 1
4027 tb (match-beginning 0)
4028 c (and ; not HERE-DOC
4031 (or (looking-at "[ \t]*(") ; << function_call()
4032 (save-excursion ; 1 << func_name, or $foo << 10
4036 ;;; XXX What to do: foo <<bar ???
4037 ;;; XXX Need to support print {a} <<B ???
4040 ; $foo << b; $f .= <<B;
4041 ; ($f+1) << b; a($f) . <<B;
4042 ; foo 1, <<B; $x{a} <<b;
4044 ((looking-at "[0-9$({]")
4047 (looking-at "[ \t]*<<")
4053 (looking-at "\\(printf?\\|system\\|exec\\|sort\\)\\>")))
4055 (error nil))) ; func(<<EOF)
4056 (and (not (match-beginning 6)) ; Empty
4058 "[ \t]*[=0-9$@%&(]"))))))
4059 (if c ; Not here-doc
4061 (setq c (match-end 2)) ; 1 + 1
4062 (if (match-beginning 5) ;4 + 1
4063 (setq b1 (match-beginning 5) ; 4 + 1
4064 e1 (match-end 5)) ; 4 + 1
4065 (setq b1 (match-beginning 4) ; 3 + 1
4066 e1 (match-end 4))) ; 3 + 1
4067 (setq tag (buffer-substring b1 e1)
4068 qtag (regexp-quote tag))
4069 (cond (cperl-pod-here-fontify
4070 ;; Highlight the starting delimiter
4071 (cperl-postpone-fontification
4072 b1 e1 'face my-cperl-delimiters-face)
4073 (cperl-put-do-not-fontify b1 e1 t)))
4077 (goto-char end-of-here-doc))
4079 ;; We do not search to max, since we may be called from
4080 ;; some hook of fontification, and max is random
4081 (or (and (re-search-forward (concat "^" qtag "$")
4083 ;;;(eq (following-char) ?\n) ; XXXX WHY???
4085 (progn ; Pretend we matched at the end
4086 (goto-char (point-max))
4087 (re-search-forward "\\'")
4088 (message "End of here-document `%s' not found." tag)
4089 (or (car err-l) (setcar err-l b))))
4090 (if cperl-pod-here-fontify
4092 ;; Highlight the ending delimiter
4093 (cperl-postpone-fontification
4094 (match-beginning 0) (match-end 0)
4095 'face my-cperl-delimiters-face)
4096 (cperl-put-do-not-fontify b (match-end 0) t)
4097 ;; Highlight the HERE-DOC
4098 (cperl-postpone-fontification b (match-beginning 0)
4100 (setq e1 (cperl-1+ (match-end 0)))
4101 (put-text-property b (match-beginning 0)
4102 'syntax-type 'here-doc)
4103 (put-text-property (match-beginning 0) e1
4104 'syntax-type 'here-doc-delim)
4105 (put-text-property b e1 'here-doc-group t)
4106 ;; This makes insertion at the start of HERE-DOC update
4107 ;; the whole construct:
4108 (put-text-property b (cperl-1+ b) 'front-sticky '(syntax-type))
4109 (cperl-commentify b e1 nil)
4110 (cperl-put-do-not-fontify b (match-end 0) t)
4111 ;; Cache the syntax info...
4112 (setq cperl-syntax-state (cons state-point state))
4113 ;; ... and process the rest of the line...
4115 (elt ; non-inter ignore-max
4116 (cperl-find-pods-heres c i t end t e1) 1))
4117 (if (and overshoot (> overshoot (point)))
4118 (goto-char overshoot)
4119 (setq overshoot e1))
4123 ((match-beginning 8)
4124 ;; 1+6=7 extra () before this:
4125 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
4127 name (if (match-beginning 8) ; 7 + 1
4128 (buffer-substring (match-beginning 8) ; 7 + 1
4129 (match-end 8)) ; 7 + 1
4131 tb (match-beginning 0))
4133 (put-text-property (save-excursion
4136 b 'first-format-line 't)
4137 (if cperl-pod-here-fontify
4138 (while (and (eq (forward-line) 0)
4139 (not (looking-at "^[.;]$")))
4141 ((looking-at "^#")) ; Skip comments
4142 ((and argument ; Skip argument multi-lines
4143 (looking-at "^[ \t]*{"))
4145 (setq argument nil))
4146 (argument ; Skip argument lines
4147 (setq argument nil))
4150 (setq argument (looking-at "^[^\n]*[@^]"))
4152 ;; Highlight the format line
4153 (cperl-postpone-fontification b1 (point)
4154 'face font-lock-string-face)
4155 (cperl-commentify b1 (point) nil)
4156 (cperl-put-do-not-fontify b1 (point) t))))
4157 ;; We do not search to max, since we may be called from
4158 ;; some hook of fontification, and max is random
4159 (re-search-forward "^[.;]$" stop-point 'toend))
4161 (if (looking-at "^\\.$") ; ";" is not supported yet
4163 ;; Highlight the ending delimiter
4164 (cperl-postpone-fontification (point) (+ (point) 2)
4165 'face font-lock-string-face)
4166 (cperl-commentify (point) (+ (point) 2) nil)
4167 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
4168 (message "End of format `%s' not found." name)
4169 (or (car err-l) (setcar err-l b)))
4173 (put-text-property b (point) 'syntax-type 'format))
4174 ;; qq-like String or Regexp:
4175 ((or (match-beginning 10) (match-beginning 11))
4176 ;; 1+6+2=9 extra () before this:
4177 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
4179 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
4180 (setq b1 (if (match-beginning 10) 10 11)
4181 argument (buffer-substring
4182 (match-beginning b1) (match-end b1))
4183 b (point) ; end of qq etc
4185 c (char-after (match-beginning b1))
4186 bb (char-after (1- (match-beginning b1))) ; tmp holder
4187 ;; bb == "Not a stringy"
4188 bb (if (eq b1 10) ; user variables/whatever
4189 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
4190 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
4191 ((eq bb ?\:) ; $opt::s
4193 (- (match-beginning b1) 2))
4195 ((eq bb ?\>) ; $foo->s
4197 (- (match-beginning b1) 2))
4200 (not (eq (char-after ; &&m/blah/
4201 (- (match-beginning b1) 2))
4204 ;; <file> or <$file>
4206 ;; Do not stringify <FH>, <$fh> :
4209 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
4210 tb (match-beginning 0))
4211 (goto-char (match-beginning b1))
4212 (cperl-backward-to-noncomment (point-min))
4214 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
4219 ;; What is below: regexp-p?
4221 (or (memq (preceding-char)
4222 (append (if (memq c '(?\? ?\<))
4225 "~{(=|&+-*!,;:[") nil))
4226 (and (eq (preceding-char) ?\})
4227 (cperl-after-block-p (point-min)))
4228 (and (eq (char-syntax (preceding-char)) ?w)
4231 ;; After these keywords `/' starts a RE. One should add all the
4232 ;; functions/builtins which expect an argument, but ...
4233 (if (eq (preceding-char) ?-)
4235 (looking-at "[a-zA-Z]\\>")
4237 (not (memq (preceding-char)
4240 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
4241 (and (eq (preceding-char) ?.)
4242 (eq (char-after (- (point) 2)) ?.))
4244 ;; m|blah| ? foo : bar;
4247 cperl-use-syntax-table-text-property
4251 (looking-at "\\s|"))))))
4254 ;; Check for $a -> y
4255 (setq b1 (preceding-char)
4258 (eq (char-after (- go 2)) ?-))
4264 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4265 (goto-char (match-end 0))
4266 (skip-chars-forward " \t\n\f"))
4267 (cond ((and (eq (following-char) ?\})
4269 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
4271 (skip-chars-backward " \t\n\f")
4272 (if (memq (preceding-char) (append "$@%&*" nil))
4278 (looking-at ; $foo -> {s}
4279 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
4280 (and ; $foo[12] -> {s}
4281 (memq (following-char) '(?\{ ?\[))
4284 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
4287 ((and (eq (following-char) ?=)
4288 (eq (char-after (1+ (point))) ?\>))
4289 ;; Check for { foo => 1, s => 2 }
4290 ;; Apparently s=> is never a substitution...
4292 ((and (eq (following-char) ?:)
4293 (eq b1 ?\{) ; Check for $ { s::bar }
4294 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
4297 (skip-chars-backward " \t\n\f")
4298 (memq (preceding-char)
4299 (append "$@%&*" nil))))
4305 ;; Skip whitespace and comments...
4306 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4307 (goto-char (match-end 0))
4308 (skip-chars-forward " \t\n\f"))
4310 (put-text-property b (point) 'syntax-type 'prestring))
4311 ;; qtag means two-arg matcher, may be reset to
4312 ;; 2 or 3 later if some special quoting is needed.
4313 ;; e1 means matching-char matcher.
4314 (setq b (point) ; before the first delimiter
4316 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
4317 ;; We do not search to max, since we may be called from
4318 ;; some hook of fontification, and max is random
4319 i (cperl-forward-re stop-point end
4321 st-l err-l argument)
4322 ;; If `go', then it is considered as 1-arg, `b1' is nil
4323 ;; as in s/foo//x; the point is before final "slash"
4324 b1 (nth 1 i) ; start of the second part
4325 tag (nth 2 i) ; ender-char, true if second part
4326 ; is with matching chars []
4327 go (nth 4 i) ; There is a 1-char part after the end
4328 i (car i) ; intermediate point
4330 ;; Before end of the second part if non-matching: ///
4331 tail (if (and i (not tag))
4333 e (if i i e1) ; end of the first part
4334 qtag nil ; need to preserve backslashitis
4335 is-x-REx nil is-o-REx nil); REx has //x //o modifiers
4336 ;; If s{} (), then b/b1 are at "{", "(", e1/i after ")", "}"
4337 ;; Commenting \\ is dangerous, what about ( ?
4339 (eq (char-after i) ?\\)
4341 (and (if go (looking-at ".\\sw*x")
4342 (looking-at "\\sw*x")) ; qr//x
4344 (and (if go (looking-at ".\\sw*o")
4345 (looking-at "\\sw*o")) ; //o
4348 ;; Considered as 1arg form
4350 (cperl-commentify b (point) t)
4351 (put-text-property b (point) 'syntax-type 'string)
4353 ;; ignore other text properties:
4354 (string-match "^qw$" argument))
4355 (put-text-property b (point) 'indentable t))
4357 (setq e1 (cperl-1+ e1))
4360 (cperl-commentify b i t)
4361 (if (looking-at "\\sw*e") ; s///e
4363 ;; Cache the syntax info...
4364 (setq cperl-syntax-state (cons state-point state))
4367 (car (cperl-find-pods-heres b1 (1- (point)) t end))
4369 (goto-char (1+ max)))
4370 (if (and tag (eq (preceding-char) ?\>))
4372 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
4373 (cperl-modify-syntax-type i cperl-st-bra)))
4374 (put-text-property b i 'syntax-type 'string)
4375 (put-text-property i (point) 'syntax-type 'multiline)
4377 (put-text-property b i 'indentable t)))
4378 (cperl-commentify b1 (point) t)
4379 (put-text-property b (point) 'syntax-type 'string)
4381 (put-text-property b i 'indentable t))
4383 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
4385 ;; Now: tail: if the second part is non-matching without ///e
4386 (if (eq (char-syntax (following-char)) ?w)
4388 (forward-word 1) ; skip modifiers s///s
4389 (if tail (cperl-commentify tail (point) t))
4390 (cperl-postpone-fontification
4391 e1 (point) 'face my-cperl-REx-modifiers-face)))
4392 ;; Check whether it is m// which means "previous match"
4393 ;; and highlight differently
4395 (and (string-match "^\\([sm]?\\|qr\\)$" argument)
4396 (or (not (= (length argument) 0))
4400 ;; split // *is* using zero-pattern
4406 (not (looking-at "split\\>")))
4408 (cperl-postpone-fontification
4409 b e 'face font-lock-warning-face)
4410 (if (or i2 ; Has 2 args
4411 (and cperl-fontify-m-as-s
4413 (string-match "^\\(m\\|qr\\)$" argument)
4414 (and (eq 0 (length argument))
4415 (not (eq ?\< (char-after b)))))))
4417 (cperl-postpone-fontification
4418 b (cperl-1+ b) 'face my-cperl-delimiters-face)
4419 (cperl-postpone-fontification
4420 (1- e) e 'face my-cperl-delimiters-face)))
4421 (if (and is-REx cperl-regexp-scan)
4422 ;; Process RExen: embedded comments, charclasses and ]
4423 ;;;/\3333\xFg\x{FFF}a\ppp\PPP\qqq\C\99f(?{ foo })(??{ foo })/;
4424 ;;;/a\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
4425 ;;;/(?<=foo)(?<!bar)(x)(?:$ab|\$\/)$|\\\b\x888\776\[\:$/xxx;
4426 ;;;m?(\?\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
4427 ;;;m$(^ab[c]\$)$ + m+(^ab[c]\$\+)+ + m](^ab[c\]$|.+)] + m)(^ab[c]$|.+\));
4428 ;;;m^a[\^b]c^ + m.a[^b]\.c.;
4432 (cperl-look-at-leading-count is-x-REx e)
4436 (if (eq (char-after b) ?\#)
4437 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
4438 "\\((\\?#\\)\\|\\(#\\)")
4439 ;; keep the same count: add a fake group
4440 (if (eq (char-after b) ?\#)
4441 "\\((\\?\\\\#\\)\\(\\)"
4442 "\\((\\?#\\)\\(\\)"))
4448 ;; XXXX Will not be able to use it in s)))
4449 (if (eq (char-after b) ?\) )
4450 "\\())))\\)" ; Will never match
4451 (if (eq (char-after b) ?? )
4452 ;;"\\((\\\\\\?\\(\\\\\\?\\)?{\\)"
4453 "\\((\\\\\\?\\\\\\?{\\|()\\\\\\?{\\)"
4454 "\\((\\?\\??{\\)")) ; 5= (??{ (?{
4455 "\\|" ; 6= 0-length, 7: name, 8,9:code, 10:group
4456 "\\(" ;; XXXX 1-char variables, exc. |()\s
4459 "[_a-zA-Z:][_a-zA-Z0-9:]*"
4461 "{[^{}]*}" ; only one-level allowed
4465 "\\(" ;;8,9:code part of array/hash elt
4471 ;; XXXX: what if u is delim?
4479 "\\\\[luLUEQbBAzZG]"
4482 "\\(" ; 10 group opener follower
4483 "\\?\\((\\?\\)" ; 11: in (?(?=C)A|B)
4485 "\\?[:=!>?{]" ; "?" something
4487 "\\?[-imsx]+[:)]" ; (?i) (?-s:.)
4489 "\\?([0-9]+)" ; (?(1)foo|bar)
4497 "\\\\\\(.\\)" ; 12=\SYMBOL
4500 (and (< (point) (1- e))
4501 (re-search-forward hairy-RE (1- e) 'to-end))
4502 (goto-char (match-beginning 0))
4503 (setq REx-subgr-start (point)
4504 was-subgr (following-char))
4506 ((match-beginning 6) ; 0-length builtins, groups
4507 (goto-char (match-end 0))
4508 (if (match-beginning 11)
4509 (goto-char (match-beginning 11)))
4512 (cperl-postpone-fontification
4513 (match-beginning 0) (point)
4516 ((eq was-subgr ?\) )
4521 (if (if (eq (char-after b) ?? )
4522 (looking-at "(\\\\\\?")
4523 (eq (char-after (1+ (point))) ?\?))
4524 my-cperl-REx-0length-face
4525 my-cperl-REx-ctl-face)
4526 font-lock-warning-face))
4527 (error font-lock-warning-face)))
4528 ((eq was-subgr ?\| )
4529 my-cperl-REx-ctl-face)
4530 ((eq was-subgr ?\$ )
4531 (if (> (point) (1+ REx-subgr-start))
4534 (match-beginning 0) (point)
4537 (if (and (eq (match-beginning 0)
4541 font-lock-variable-name-face)
4542 my-cperl-REx-spec-char-face))
4543 ((memq was-subgr (append "^." nil) )
4544 my-cperl-REx-spec-char-face)
4545 ((eq was-subgr ?\( )
4546 (if (not (match-beginning 10))
4547 my-cperl-REx-ctl-face
4548 my-cperl-REx-0length-face))
4549 (t my-cperl-REx-0length-face)))
4550 (if (and (memq was-subgr (append "(|" nil))
4551 (not (string-match "(\\?[-imsx]+)"
4553 (cperl-look-at-leading-count is-x-REx e))
4554 (setq was-subgr nil)) ; We do stuff here
4555 ((match-beginning 12) ; \SYMBOL
4559 ;; How many chars to not highlight:
4560 ;; 0-len special-alnums in other branch =>
4561 ;; Generic: \non-alnum (1), \alnum (1+face)
4562 ;; Is-delim: \non-alnum (1/spec-2) alnum-1 (=what hai)
4563 (setq REx-subgr-start (point)
4564 qtag (preceding-char))
4565 (cperl-postpone-fontification
4566 (- (point) 2) (- (point) 1) 'face
4568 (append "ghijkmoqvFHIJKMORTVY" nil))
4569 font-lock-warning-face
4570 my-cperl-REx-0length-face))
4571 (if (and (eq (char-after b) qtag)
4572 (memq qtag (append ".])^$|*?+" nil)))
4574 (if (and cperl-use-syntax-table-text-property
4577 REx-subgr-start (1- (point))
4578 'syntax-table cperl-st-punct))
4579 (cperl-postpone-fontification
4580 (1- (point)) (point) 'face
4581 ; \] can't appear below
4582 (if (memq qtag (append ".]^$" nil))
4583 'my-cperl-REx-spec-char-face
4584 (if (memq qtag (append "*?+" nil))
4585 'my-cperl-REx-0length-face
4586 'my-cperl-REx-ctl-face))))) ; )|
4587 ;; Test for arguments:
4589 ;; This is not pretty: the 5.8.7 logic:
4590 ;; \0numx -> octal (up to total 3 dig)
4591 ;; \DIGIT -> backref unless \0
4592 ;; \DIGITs -> backref if legal
4593 ;; otherwise up to 3 -> octal
4594 ;; Do not try to distinguish, we guess
4595 ((or (and (memq qtag (append "01234567" nil))
4597 "\\=[01234567]?[01234567]?"
4599 (and (memq qtag (append "89" nil))
4601 "\\=[0123456789]*" (1- e) 'to-end))
4604 "\\=[0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}"
4606 (and (memq qtag (append "pPN" nil))
4607 (re-search-forward "\\={[^{}]+}\\|."
4609 (eq (char-syntax qtag) ?w))
4610 (cperl-postpone-fontification
4611 (1- REx-subgr-start) (point)
4612 'face my-cperl-REx-length1-face))))
4613 (setq was-subgr nil)) ; We do stuff here
4614 ((match-beginning 3) ; [charclass]
4616 (if (eq (char-after b) ?^ )
4617 (and (eq (following-char) ?\\ )
4618 (eq (char-after (cperl-1+ (point)))
4621 (and (eq (following-char) ?^ )
4623 (setq argument b ; continue?
4624 tag nil ; list of POSIX classes
4626 (if (eq (char-after b) ?\] )
4627 (and (eq (following-char) ?\\ )
4628 (eq (char-after (cperl-1+ (point)))
4630 (setq qtag (1+ qtag))
4632 (and (eq (following-char) ?\] )
4634 ;; Apparently, I can't put \] into a charclass
4635 ;; in m]]: m][\\\]\]] produces [\\]]
4636 ;;; POSIX? [:word:] [:^word:] only inside []
4637 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]")
4641 (if (eq (char-after b) ?\] )
4642 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]"
4643 "\\=\\(\\\\.\\|[^]\\\\]\\)*]")
4645 ;; Is this ] an end of POSIX class?
4648 (search-backward "[" argument t)
4649 (< REx-subgr-start (point))
4651 (and ; Should work with delim = \
4652 (eq (preceding-char) ?\\ )
4653 (= (% (skip-chars-backward
4657 ((eq (char-after b) ?\] )
4658 "\\\\*\\[:\\^?\\sw+:\\\\\\]")
4659 ((eq (char-after b) ?\: )
4660 "\\\\*\\[\\\\:\\^?\\sw+\\\\:]")
4661 ((eq (char-after b) ?^ )
4662 "\\\\*\\[:\\(\\\\\\^\\)?\\sw+:\]")
4663 ((eq (char-syntax (char-after b))
4666 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\"
4667 (char-to-string (char-after b))
4669 (t "\\\\*\\[:\\^?\\sw*:]")))
4670 (setq argument (point))))
4671 (setq tag (cons (cons argument (point))
4673 argument (point)) ; continue
4674 (setq argument nil)))
4676 (message "Couldn't find end of charclass in a REx, pos=%s"
4678 (if (and cperl-use-syntax-table-text-property
4679 (> (- (point) 2) REx-subgr-start))
4681 (1+ REx-subgr-start) (1- (point))
4682 'syntax-table cperl-st-punct))
4683 (cperl-postpone-fontification
4684 REx-subgr-start qtag
4685 'face my-cperl-REx-spec-char-face)
4686 (cperl-postpone-fontification
4687 (1- (point)) (point) 'face
4688 my-cperl-REx-spec-char-face)
4689 (if (eq (char-after b) ?\] )
4690 (cperl-postpone-fontification
4691 (- (point) 2) (1- (point))
4692 'face my-cperl-REx-0length-face))
4694 (cperl-postpone-fontification
4695 (car (car tag)) (cdr (car tag))
4696 'face my-cperl-REx-length1-face)
4697 (setq tag (cdr tag)))
4698 (setq was-subgr nil)) ; did facing already
4700 ((and (match-beginning 2) ; #-comment
4701 (/= (match-beginning 2) (match-end 2)))
4702 (beginning-of-line 2)
4704 (goto-char (1- e))))
4705 ((match-beginning 4) ; character "]"
4706 (setq was-subgr nil) ; We do stuff here
4707 (goto-char (match-end 0))
4708 (if cperl-use-syntax-table-text-property
4710 (1- (point)) (point)
4711 'syntax-table cperl-st-punct))
4712 (cperl-postpone-fontification
4713 (1- (point)) (point)
4714 'face font-lock-warning-face))
4715 ((match-beginning 5) ; before (?{}) (??{})
4716 (setq tag (match-end 0))
4718 (cperl-forward-group-in-re st-l))
4720 (setq qtag "no matching `)' found"))
4721 (and (not (eq (char-after (- (point) 2))
4723 (setq qtag "Can't find })")))
4727 (cperl-postpone-fontification
4728 (1- tag) (1- (point))
4729 'face font-lock-variable-name-face)
4730 (cperl-postpone-fontification
4731 REx-subgr-start (1- tag)
4732 'face my-cperl-REx-spec-char-face)
4733 (cperl-postpone-fontification
4734 (1- (point)) (point)
4735 'face my-cperl-REx-spec-char-face)
4736 (if cperl-use-syntax-table-text-property
4739 (- (point) 2) (1- (point))
4740 'syntax-table cperl-st-cfence)
4742 (+ REx-subgr-start 2)
4743 (+ REx-subgr-start 3)
4744 'syntax-table cperl-st-cfence))))
4745 (setq was-subgr nil))
4747 ;; Inside "(" and "\" arn't special in any way
4748 ;; Works also if the outside delimiters are ().
4749 (or;;(if (eq (char-after b) ?\) )
4750 ;;(re-search-forward
4751 ;; "[^\\\\]\\(\\\\\\\\\\)*\\\\)"
4753 (search-forward ")" (1- e) 'toend)
4756 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
4762 (setq REx-subgr-end (point))
4764 REx-subgr-start REx-subgr-end nil)
4765 (cperl-postpone-fontification
4766 REx-subgr-start REx-subgr-end
4767 'face font-lock-comment-face))))))
4768 (if (and is-REx is-x-REx)
4769 (put-text-property (1+ b) (1- e)
4770 'syntax-subtype 'x-REx)))
4773 (cperl-postpone-fontification
4774 (1- e1) e1 'face my-cperl-delimiters-face)
4775 (if (assoc (char-after b) cperl-starters)
4777 (cperl-postpone-fontification
4778 b1 (1+ b1) 'face my-cperl-delimiters-face)
4779 (put-text-property b1 (1+ b1)
4783 ((match-beginning 17) ; sub with prototype or attribute
4784 ;; 1+6+2+1+1=11 extra () before this (sub with proto/attr):
4785 ;;"\\<sub\\>\\(" ;12
4786 ;; cperl-white-and-comment-rex ;13
4787 ;; "\\([a-zA-Z_:'0-9]+\\)\\)?" ; name ;14
4788 ;;"\\(" cperl-maybe-white-and-comment-rex ;15,16
4789 ;; "\\(([^()]*)\\|:[^:]\\)\\)" ; 17:proto or attribute start
4790 (setq b1 (match-beginning 14) e1 (match-end 14))
4791 (if (memq (char-after (1- b))
4792 '(?\$ ?\@ ?\% ?\& ?\*))
4795 (if (eq (char-after (match-beginning 17)) ?\( )
4797 (cperl-commentify ; Prototypes; mark as string
4798 (match-beginning 17) (match-end 17) t)
4799 (goto-char (match-end 0))
4800 ;; Now look for attributes after prototype:
4801 (forward-comment (buffer-size))
4802 (and (looking-at ":[^:]")
4803 (cperl-find-sub-attrs st-l b1 e1 b)))
4804 ;; treat attributes without prototype
4805 (goto-char (match-beginning 17))
4806 (cperl-find-sub-attrs st-l b1 e1 b))))
4807 ;; 1+6+2+1+1+6+1=18 extra () before this:
4808 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
4809 ((match-beginning 19) ; old $abc'efg syntax
4810 (setq bb (match-end 0))
4811 ;;;(if (nth 3 state) nil ; in string
4812 (put-text-property (1- bb) bb 'syntax-table cperl-st-word)
4814 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
4815 ;; "__\\(END\\|DATA\\)__"
4816 ((match-beginning 20) ; __END__, __DATA__
4817 (setq bb (match-end 0))
4818 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
4819 (cperl-commentify b bb nil)
4821 ;; "\\\\\\(['`\"($]\\)"
4822 ((match-beginning 21)
4823 ;; Trailing backslash; make non-quoting outside string/comment
4824 (setq bb (match-end 0))
4826 (skip-chars-backward "\\\\")
4827 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
4828 (cperl-modify-syntax-type b cperl-st-punct)
4830 (t (error "Error in regexp of the sniffer")))
4831 (if (> (point) stop-point)
4834 (message "Garbage after __END__/__DATA__ ignored")
4835 (message "Unbalanced syntax found while scanning")
4836 (or (car err-l) (setcar err-l b)))
4837 (goto-char stop-point))))
4838 (setq cperl-syntax-state (cons state-point state)
4839 ;; Do not mark syntax as done past tmpend???
4840 cperl-syntax-done-to (or tmpend (max (point) max)))
4841 ;;(message "state-at=%s, done-to=%s" state-point cperl-syntax-done-to)
4843 (if (car err-l) (goto-char (car err-l))
4845 (message "Scanning for \"hard\" Perl constructions... done"))))
4846 (and (buffer-modified-p)
4848 (set-buffer-modified-p nil))
4849 ;; I do not understand what this is doing here. It breaks font-locking
4850 ;; because it resets the syntax-table from font-lock-syntax-table to
4851 ;; cperl-mode-syntax-table.
4852 ;; (set-syntax-table cperl-mode-syntax-table)
4854 (list (car err-l) overshoot)))
4856 (defun cperl-find-pods-heres-region (min max)
4858 (cperl-find-pods-heres min max))
4860 (defun cperl-backward-to-noncomment (lim)
4861 ;; Stops at lim or after non-whitespace that is not in comment
4862 ;; XXXX Wrongly understands end-of-multiline strings with # as comment
4864 (while (and (not stop) (> (point) (or lim (point-min))))
4865 (skip-chars-backward " \t\n\f" lim)
4868 (if (memq (setq pr (get-text-property (point) 'syntax-type))
4869 '(pod here-doc here-doc-delim))
4870 (cperl-unwind-to-safe nil)
4871 (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
4872 (not (memq pr '(string prestring))))
4873 (progn (cperl-to-comment-or-eol) (bolp))
4875 (skip-chars-backward " \t")
4876 (if (< p (point)) (goto-char p))
4879 ;; Used only in `cperl-calculate-indent'...
4880 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
4881 ;; Positions is before ?\{. Checks whether it starts a block.
4882 ;; No save-excursion! This is more a distinguisher of a block/hash ref...
4883 (cperl-backward-to-noncomment (point-min))
4884 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
4885 ; Label may be mixed up with `$blah :'
4886 (save-excursion (cperl-after-label))
4887 (get-text-property (cperl-1- (point)) 'attrib-group)
4888 (and (memq (char-syntax (preceding-char)) '(?w ?_))
4891 ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
4892 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
4893 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
4894 ;; sub bless::foo {}
4896 (cperl-backward-to-noncomment (point-min))
4897 (and (eq (preceding-char) ?b)
4900 (looking-at "sub[ \t\n\f#]")))))))))
4902 ;;; What is the difference of (cperl-after-block-p lim t) and (cperl-block-p)?
4903 ;;; No save-excursion; condition-case ... In (cperl-block-p) the block
4904 ;;; may be a part of an in-statement construct, such as
4905 ;;; ${something()}, print {FH} $data.
4906 ;;; Moreover, one takes positive approach (looks for else,grep etc)
4907 ;;; another negative (looks for bless,tr etc)
4908 (defun cperl-after-block-p (lim &optional pre-block)
4909 "Return true if the preceeding } (if PRE-BLOCK, following {) delimits a block.
4910 Would not look before LIM. Assumes that LIM is a good place to begin a
4911 statement. The kind of block we treat here is one after which a new
4912 statement would start; thus the block in ${func()} does not count."
4916 (or pre-block (forward-sexp -1))
4917 (cperl-backward-to-noncomment lim)
4918 (or (eq (point) lim)
4919 ;; if () {} // sub f () {} // sub f :a(') {}
4920 (eq (preceding-char) ?\) )
4922 (save-excursion (cperl-after-label))
4924 (get-text-property (cperl-1- (point)) 'attrib-group)
4925 (if (memq (char-syntax (preceding-char)) '(?w ?_)) ; else {}
4928 ;; else {} but not else::func {}
4929 (or (and (looking-at "\\(else\\|continue\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
4930 (not (looking-at "\\(\\sw\\|_\\)+::")))
4933 (cperl-backward-to-noncomment lim)
4934 (and (eq (preceding-char) ?b)
4937 (looking-at "sub[ \t\n\f#]"))))))
4938 ;; What preceeds is not word... XXXX Last statement in sub???
4939 (cperl-after-expr-p lim))))
4942 (defun cperl-after-expr-p (&optional lim chars test)
4943 "Return true if the position is good for start of expression.
4944 TEST is the expression to evaluate at the found position. If absent,
4945 CHARS is a string that contains good characters to have before us (however,
4946 `}' is treated \"smartly\" if it is not in the list)."
4947 (let ((lim (or lim (point-min)))
4949 (cperl-update-syntaxification (point) (point))
4951 (while (and (not stop) (> (point) lim))
4952 (skip-chars-backward " \t\n\f" lim)
4955 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
4956 ;; '(pod here-doc here-doc-delim))
4957 (if (get-text-property (point) 'here-doc-group)
4960 (cperl-beginning-of-property (point) 'here-doc-group))
4961 (beginning-of-line 0)))
4962 (if (get-text-property (point) 'in-pod)
4965 (cperl-beginning-of-property (point) 'in-pod))
4966 (beginning-of-line 0)))
4967 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
4968 ;; Else: last iteration, or a label
4969 (cperl-to-comment-or-eol) ; Will not move past "." after a format
4970 (skip-chars-backward " \t")
4971 (if (< p (point)) (goto-char p))
4973 (if (and (eq (preceding-char) ?:)
4976 (skip-chars-backward " \t\n\f" lim)
4977 (memq (char-syntax (preceding-char)) '(?w ?_))))
4978 (forward-sexp -1) ; Possibly label. Skip it
4981 (or (bobp) ; ???? Needed
4983 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
4985 (if test (eval test)
4986 (or (memq (preceding-char) (append (or chars "{;") nil))
4987 (and (eq (preceding-char) ?\})
4988 (cperl-after-block-p lim))
4989 (and (eq (following-char) ?.) ; in format: see comment above
4990 (eq (get-text-property (point) 'syntax-type)
4993 (defun cperl-backward-to-start-of-expr (&optional lim)
4996 (while (and (or (not lim)
4998 (not (cperl-after-expr-p lim)))
5000 ;; May be after $, @, $# etc of a variable
5001 (skip-chars-backward "$@%#")))
5004 (defun cperl-at-end-of-expr (&optional lim)
5005 ;; Since the SEXP approach below is very fragile, do some overengineering
5006 (or (looking-at (concat cperl-maybe-white-and-comment-rex "[;}]"))
5009 ;; If nothing interesting after, does as (forward-sexp -1);
5010 ;; otherwise fails, or ends at a start of following sexp.
5011 ;; XXXX PROBLEMS: if what follows (after ";") @FOO, or ${bar}
5012 ;; may be stuck after @ or $; just put some stupid workaround now:
5016 (while (memq (preceding-char) (append "%&@$*" nil))
5019 (cperl-after-expr-p lim))))
5022 (defun cperl-forward-to-end-of-expr (&optional lim)
5026 (while (and (< (point) (or lim (point-max)))
5027 (not (cperl-at-end-of-expr)))
5031 (defun cperl-backward-to-start-of-continued-exp (lim)
5032 (if (memq (preceding-char) (append ")]}\"'`" nil))
5035 (if (<= (point) lim)
5036 (goto-char (1+ lim)))
5037 (skip-chars-forward " \t"))
5039 (defun cperl-after-block-and-statement-beg (lim)
5040 ;; We assume that we are after ?\}
5042 (cperl-after-block-p lim)
5045 (cperl-backward-to-noncomment (point-min))
5048 (not (= (char-syntax (preceding-char)) ?w))
5053 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
5056 (defun cperl-indent-exp ()
5057 "Simple variant of indentation of continued-sexp.
5059 Will not indent comment if it starts at `comment-indent' or looks like
5060 continuation of the comment on the previous line.
5062 If `cperl-indent-region-fix-constructs', will improve spacing on
5063 conditional/loop constructs."
5066 (let ((tmp-end (progn (end-of-line) (point))) top done)
5071 ;; Plan A: if line has an unfinished paren-group, go to end-of-group
5072 (while (= -1 (nth 0 (parse-partial-sexp (point) tmp-end -1)))
5073 (setq top (point))) ; Get the outermost parenths in line
5075 (while (< (point) tmp-end)
5076 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
5077 (or (eolp) (forward-sexp 1)))
5078 (if (> (point) tmp-end) ; Yes, there an unfinished block
5080 (if (eq ?\) (preceding-char))
5081 (progn ;; Plan B: find by REGEXP block followup this line
5086 (if (eq (following-char) ?$ ) ; for my $var (list)
5089 (if (looking-at "\\(my\\|local\\|our\\)\\>")
5090 (forward-sexp -1))))
5092 (concat "\\(\\elsif\\|if\\|unless\\|while\\|until"
5093 "\\|for\\(each\\)?\\>\\(\\("
5094 cperl-maybe-white-and-comment-rex
5095 "\\(my\\|local\\|our\\)\\)?"
5096 cperl-maybe-white-and-comment-rex
5097 "\\$[_a-zA-Z0-9]+\\)?\\)\\>"))
5101 (setq top (point)))))
5102 (error (setq done t)))
5104 (if (looking-at ; Try Plan C: continuation block
5105 (concat cperl-maybe-white-and-comment-rex
5106 "\\<\\(else\\|elsif\|continue\\)\\>"))
5108 (goto-char (match-end 0))
5111 (setq tmp-end (point))))
5115 (setq tmp-end (point))))
5117 (setq tmp-end (point-marker)))
5118 (if cperl-indent-region-fix-constructs
5119 (cperl-fix-line-spacing tmp-end))
5120 (cperl-indent-region (point) tmp-end))))
5122 (defun cperl-fix-line-spacing (&optional end parse-data)
5123 "Improve whitespace in a conditional/loop construct.
5124 Returns some position at the last line."
5127 (setq end (point-max)))
5128 (let ((ee (save-excursion (end-of-line) (point)))
5129 (cperl-indent-region-fix-constructs
5130 (or cperl-indent-region-fix-constructs 1))
5131 p pp ml have-brace ret)
5138 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
5139 (setq have-brace (save-excursion (search-forward "}" ee t)))))
5140 nil ; Do not need to do anything
5144 (if cperl-merge-trailing-else
5146 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5148 (search-forward "}")
5150 (skip-chars-forward " \t\n")
5151 (delete-region p (point))
5152 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5153 (beginning-of-line)))
5154 (if (looking-at "[ \t]*}[ \t]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5156 (search-forward "}")
5157 (delete-horizontal-space)
5160 (if (cperl-indent-line parse-data)
5162 (cperl-fix-line-spacing end parse-data)
5163 (setq ret (point)))))))
5166 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
5168 (search-forward "}")
5169 (delete-horizontal-space)
5170 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5171 (beginning-of-line)))
5175 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5178 (delete-horizontal-space)
5179 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5180 (beginning-of-line)))
5184 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
5187 (delete-horizontal-space)
5188 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5189 (beginning-of-line)))
5191 ;; foreach my $var (
5193 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5196 (delete-horizontal-space)
5198 (make-string cperl-indent-region-fix-constructs ?\s))
5199 (beginning-of-line)))
5200 ;; Looking at (with or without "}" at start, ending after "({"):
5201 ;; } foreach my $var () OR {
5203 "[ \t]*\\(}[ \t]*\\)?\\<\\(\\els\\(e\\|if\\)\\|continue\\|if\\|unless\\|while\\|for\\(each\\)?\\(\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\$[_a-zA-Z0-9]+\\)?\\|until\\)\\>\\([ \t]*(\\|[ \t\n]*{\\)\\|[ \t]*{")
5205 (setq ml (match-beginning 8)) ; "(" or "{" after control word
5206 (re-search-forward "[({]")
5209 (if (eq (following-char) ?\( )
5212 (setq pp (point))) ; past parenth-group
5213 ;; after `else' or nothing
5214 (if ml ; after `else'
5215 (skip-chars-backward " \t\n")
5216 (beginning-of-line))
5218 ;; Now after the sexp before the brace
5219 ;; Multiline expr should be special
5220 (setq ml (and pp (save-excursion (goto-char p)
5221 (search-forward "\n" pp t))))
5222 (if (and (or (not pp) (< pp end)) ; Do not go too far...
5223 (looking-at "[ \t\n]*{"))
5226 ((bolp) ; Were before `{', no if/else/etc
5228 ((looking-at "\\(\t*\\| [ \t]+\\){") ; Not exactly 1 SPACE
5229 (delete-horizontal-space)
5231 cperl-extra-newline-before-brace-multiline
5232 cperl-extra-newline-before-brace)
5234 (delete-horizontal-space)
5237 (if (cperl-indent-line parse-data)
5239 (cperl-fix-line-spacing end parse-data)
5240 (setq ret (point)))))
5242 (make-string cperl-indent-region-fix-constructs ?\s))))
5243 ((and (looking-at "[ \t]*\n")
5245 cperl-extra-newline-before-brace-multiline
5246 cperl-extra-newline-before-brace)))
5248 (skip-chars-forward " \t\n")
5249 (delete-region pp (point))
5251 (make-string cperl-indent-region-fix-constructs ?\ )))
5252 ((and (looking-at "[\t ]*{")
5253 (if ml cperl-extra-newline-before-brace-multiline
5254 cperl-extra-newline-before-brace))
5255 (delete-horizontal-space)
5258 (if (cperl-indent-line parse-data)
5260 (cperl-fix-line-spacing end parse-data)
5261 (setq ret (point))))))
5262 ;; Now we are before `{'
5263 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
5265 (skip-chars-forward " \t\n")
5270 (setq ml (search-forward "\n" p t))
5271 (if (or cperl-break-one-line-blocks-when-indent ml)
5272 ;; not good: multi-line BLOCK
5275 (delete-horizontal-space)
5278 (if (cperl-indent-line parse-data)
5279 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
5281 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
5282 ;; Now check whether there is a hanging `}'
5286 cperl-fix-hanging-brace-when-indent
5288 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
5292 (if (and (<= (point) pp)
5293 (eq (preceding-char) ?\} )
5294 (cperl-after-block-and-statement-beg (point-min)))
5301 (skip-chars-backward " \t")
5303 ;; `}' was the first thing on the line, insert NL *after* it.
5305 (cperl-indent-line parse-data)
5306 (search-forward "}")
5307 (delete-horizontal-space)
5309 (delete-horizontal-space)
5310 (or (eq (preceding-char) ?\;)
5312 (and (eq (preceding-char) ?\} )
5313 (cperl-after-block-p (point-min)))
5317 (if (cperl-indent-line parse-data)
5318 (setq ret (cperl-fix-line-spacing end parse-data)))
5319 (beginning-of-line)))))
5322 (defvar cperl-update-start) ; Do not need to make them local
5323 (defvar cperl-update-end)
5324 (defun cperl-delay-update-hook (beg end old-len)
5325 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
5326 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
5328 (defun cperl-indent-region (start end)
5329 "Simple variant of indentation of region in CPerl mode.
5330 Should be slow. Will not indent comment if it starts at `comment-indent'
5331 or looks like continuation of the comment on the previous line.
5332 Indents all the lines whose first character is between START and END
5335 If `cperl-indent-region-fix-constructs', will improve spacing on
5336 conditional/loop constructs."
5338 (cperl-update-syntaxification end end)
5340 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
5341 (let ((indent-info (if cperl-emacs-can-parse
5342 (list nil nil nil) ; Cannot use '(), since will modify
5345 after-change-functions ; Speed it up!
5346 st comm old-comm-indent new-comm-indent p pp i empty)
5347 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
5349 (setq old-comm-indent (and (cperl-to-comment-or-eol)
5351 new-comm-indent old-comm-indent)
5353 (setq end (set-marker (make-marker) end)) ; indentation changes pos
5354 (or (bolp) (beginning-of-line 2))
5355 (while (and (<= (point) end) (not (eobp))) ; bol to check start
5358 (setq empty (looking-at "[ \t]*\n"))
5359 (and (setq comm (looking-at "[ \t]*#"))
5360 (or (eq (current-indentation) (or old-comm-indent
5362 (setq old-comm-indent nil))))
5363 (if (and old-comm-indent
5365 (= (current-indentation) old-comm-indent)
5366 (not (eq (get-text-property (point) 'syntax-type) 'pod))
5367 (not (eq (get-text-property (point) 'syntax-table)
5369 (let ((comment-column new-comm-indent))
5370 (indent-for-comment)))
5372 (setq i (cperl-indent-line indent-info))
5376 (if cperl-indent-region-fix-constructs
5377 (goto-char (cperl-fix-line-spacing end indent-info)))
5378 (if (setq old-comm-indent
5379 (and (cperl-to-comment-or-eol)
5380 (not (memq (get-text-property (point)
5383 (not (eq (get-text-property (point)
5387 (progn (indent-for-comment)
5388 (skip-chars-backward " \t")
5389 (skip-chars-backward "#")
5390 (setq new-comm-indent (current-column))))))))
5391 (beginning-of-line 2)))
5392 ;; Now run the update hooks
5393 (and after-change-functions
5396 (goto-char cperl-update-end)
5399 (goto-char cperl-update-start)
5401 (delete-char -1))))))
5403 ;; Stolen from lisp-mode with a lot of improvements
5405 (defun cperl-fill-paragraph (&optional justify iteration)
5406 "Like `fill-paragraph', but handle CPerl comments.
5407 If any of the current line is a comment, fill the comment or the
5408 block of it that point is in, preserving the comment's initial
5409 indentation and initial hashes. Behaves usually outside of comment."
5410 ;; (interactive "P") ; Only works when called from fill-paragraph. -stef
5411 (let (;; Non-nil if the current line contains a comment.
5413 fill-paragraph-function ; do not recurse
5414 ;; If has-comment, the appropriate fill-prefix for the comment.
5416 ;; Line that contains code and comment (or nil)
5418 c spaces len dc (comment-column comment-column))
5419 ;; Figure out what kind of comment we are looking at.
5424 ;; A line with nothing but a comment on it?
5425 ((looking-at "[ \t]*#[# \t]*")
5427 comment-fill-prefix (buffer-substring (match-beginning 0)
5430 ;; A line with some code, followed by a comment? Remember that the
5431 ;; semi which starts the comment shouldn't be part of a string or
5433 ((cperl-to-comment-or-eol)
5434 (setq has-comment t)
5435 (looking-at "#+[ \t]*")
5436 (setq start (point) c (current-column)
5438 (concat (make-string (current-column) ?\s)
5439 (buffer-substring (match-beginning 0) (match-end 0)))
5440 spaces (progn (skip-chars-backward " \t")
5441 (buffer-substring (point) start))
5442 dc (- c (current-column)) len (- start (point))
5443 start (point-marker))
5445 (insert (make-string dc ?-))))) ; Placeholder (to avoid splitting???)
5446 (if (not has-comment)
5447 (fill-paragraph justify) ; Do the usual thing outside of comment
5448 ;; Narrow to include only the comment, and then fill the region.
5451 ;; Find the first line we should include in the region to fill.
5452 (if start (progn (beginning-of-line) (point))
5454 (while (and (zerop (forward-line -1))
5455 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5456 ;; We may have gone to far. Go forward again.
5457 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
5460 ;; Find the beginning of the first line past the region to fill.
5462 (while (progn (forward-line 1)
5463 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5465 ;; Remove existing hashes
5467 (goto-char (point-min))
5468 (while (progn (forward-line 1) (< (point) (point-max)))
5469 (skip-chars-forward " \t")
5470 (if (looking-at "#+")
5472 (if (and (eq (point) (match-beginning 0))
5473 (not (eq (point) (match-end 0)))) nil
5475 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage"))
5476 (delete-char (- (match-end 0) (match-beginning 0)))))))
5478 ;; Lines with only hashes on them can be paragraph boundaries.
5479 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
5480 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
5481 (fill-prefix comment-fill-prefix))
5482 (fill-paragraph justify)))
5487 (progn (delete-char dc) (insert spaces)))
5488 (if (or (= (current-column) c) iteration) nil
5489 (setq comment-column c)
5490 (indent-for-comment)
5491 ;; Repeat once more, flagging as iteration
5492 (cperl-fill-paragraph justify t))))))
5495 (defun cperl-do-auto-fill ()
5496 ;; Break out if the line is short enough
5497 (if (> (save-excursion
5501 (let ((c (save-excursion (beginning-of-line)
5502 (cperl-to-comment-or-eol) (point)))
5503 (s (memq (following-char) '(?\s ?\t))) marker)
5505 ;; Don't break line inside code: only inside comment.
5507 (setq marker (point-marker))
5508 (fill-paragraph nil)
5510 ;; Is not enough, sometimes marker is a start of line
5511 (if (bolp) (progn (re-search-forward "#+[ \t]*")
5512 (goto-char (match-end 0))))
5513 ;; Following space could have gone:
5514 (if (or (not s) (memq (following-char) '(?\s ?\t))) nil
5517 ;; Previous space could have gone:
5518 (or (memq (preceding-char) '(?\s ?\t)) (insert " "))))))
5520 (defun cperl-imenu-addback (lst &optional isback name)
5521 ;; We suppose that the lst is a DAG, unless the first element only
5522 ;; loops back, and ISBACK is set. Thus this function cannot be
5523 ;; applied twice without ISBACK set.
5524 (cond ((not cperl-imenu-addback) lst)
5527 (setq name "+++BACK+++"))
5528 (mapcar (lambda (elt)
5529 (if (and (listp elt) (listp (cdr elt)))
5531 ;; In the other order it goes up
5532 ;; one level only ;-(
5533 (setcdr elt (cons (cons name lst)
5535 (cperl-imenu-addback (cdr elt) t name))))
5536 (if isback (cdr lst) lst))
5539 (defun cperl-imenu--create-perl-index (&optional regexp)
5540 (require 'imenu) ; May be called from TAGS creator
5541 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
5542 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
5543 (index-meth-alist '()) meth
5544 packages ends-ranges p marker is-proto
5545 (prev-pos 0) is-pack index index1 name (end-range 0) package)
5546 (goto-char (point-min))
5547 (cperl-update-syntaxification (point-max) (point-max))
5548 ;; Search for the function
5549 (progn ;;save-match-data
5550 (while (re-search-forward
5551 (or regexp cperl-imenu--function-name-regexp-perl)
5553 ;; 2=package-group, 5=package-name 8=sub-name
5555 ((and ; Skip some noise if building tags
5556 (match-beginning 5) ; package name
5557 ;;(eq (char-after (match-beginning 2)) ?p) ; package
5558 (not (save-match-data
5559 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
5562 (or (match-beginning 2)
5563 (match-beginning 8)) ; package or sub
5564 ;; Skip if quoted (will not skip multi-line ''-strings :-():
5565 (null (get-text-property (match-beginning 1) 'syntax-table))
5566 (null (get-text-property (match-beginning 1) 'syntax-type))
5567 (null (get-text-property (match-beginning 1) 'in-pod)))
5568 (setq is-pack (match-beginning 2))
5569 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
5570 ;; (goto-char (match-end 0))) ; Messes what follows
5573 (while (and ends-ranges (>= p (car ends-ranges)))
5574 ;; delete obsolete entries
5575 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
5576 (setq package (or (car packages) "")
5577 end-range (or (car ends-ranges) 0))
5578 (if is-pack ; doing "package"
5580 (if (match-beginning 5) ; named package
5581 (setq name (buffer-substring (match-beginning 5)
5584 (set-text-properties 0 (length name) nil name)
5586 package (concat name "::")
5587 name (concat "package " name))
5588 ;; Support nameless packages
5589 (setq name "package;" package ""))
5592 (parse-partial-sexp (point) (point-max) -1) (point))
5593 ends-ranges (cons end-range ends-ranges)
5594 packages (cons package packages)))
5596 (or (eq (following-char) ?\;)
5597 (eq 0 (get-text-property (point) 'attrib-group)))))
5598 ;; Skip this function name if it is a prototype declaration.
5599 (if (and is-proto (not is-pack)) nil
5602 (buffer-substring (match-beginning 8) (match-end 8)))
5603 (set-text-properties 0 (length name) nil name))
5604 (setq marker (make-marker))
5605 (set-marker marker (match-end (if is-pack 2 8)))
5607 ((string-match "[:']" name)
5609 ((> p end-range) nil)
5611 (setq name (concat package name) meth t)))
5612 (setq index (cons name marker))
5614 (push index index-pack-alist)
5615 (push index index-alist))
5616 (if meth (push index index-meth-alist))
5617 (push index index-unsorted-alist)))
5618 ((match-beginning 16) ; POD section
5619 (setq name (buffer-substring (match-beginning 17) (match-end 17))
5620 marker (make-marker))
5621 (set-marker marker (match-beginning 17))
5622 (set-text-properties 0 (length name) nil name)
5623 (setq name (concat (make-string
5624 (* 3 (- (char-after (match-beginning 16)) ?1))
5627 index (cons name marker))
5628 (setq index1 (cons (concat "=" name) (cdr index)))
5629 (push index index-pod-alist)
5630 (push index1 index-unsorted-alist)))))
5632 (if (default-value 'imenu-sort-function)
5633 (sort index-alist (default-value 'imenu-sort-function))
5634 (nreverse index-alist)))
5635 (and index-pod-alist
5636 (push (cons "+POD headers+..."
5637 (nreverse index-pod-alist))
5639 (and (or index-pack-alist index-meth-alist)
5640 (let ((lst index-pack-alist) hier-list pack elt group name)
5641 ;; Remove "package ", reverse and uniquify.
5643 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
5644 (if (assoc name hier-list) nil
5645 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
5646 (setq lst index-meth-alist)
5648 (setq elt (car lst) lst (cdr lst))
5649 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
5650 (setq pack (substring (car elt) 0 (match-beginning 0)))
5651 (if (setq group (assoc pack hier-list))
5652 (if (listp (cdr group))
5653 ;; Have some functions already
5655 (cons (cons (substring
5657 (+ 2 (match-beginning 0)))
5660 (setcdr group (list (cons (substring
5662 (+ 2 (match-beginning 0)))
5666 (list (cons (substring
5668 (+ 2 (match-beginning 0)))
5671 (push (cons "+Hierarchy+..."
5674 (and index-pack-alist
5675 (push (cons "+Packages+..."
5676 (nreverse index-pack-alist))
5678 (and (or index-pack-alist index-pod-alist
5679 (default-value 'imenu-sort-function))
5680 index-unsorted-alist
5681 (push (cons "+Unsorted List+..."
5682 (nreverse index-unsorted-alist))
5684 (cperl-imenu-addback index-alist)))
5687 ;; Suggested by Mark A. Hershberger
5688 (defun cperl-outline-level ()
5689 (looking-at outline-regexp)
5690 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
5691 ;;;; 2=package-group, 5=package-name 8=sub-name 16=head-level
5692 ((match-beginning 2) 0) ; package
5693 ((match-beginning 8) 1) ; sub
5694 ((match-beginning 16)
5695 (- (char-after (match-beginning 16)) ?0)) ; headN ==> N
5696 (t 5))) ; should not happen
5699 (defvar cperl-compilation-error-regexp-alist
5700 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
5701 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
5703 "Alist that specifies how to match errors in perl output.")
5706 (defun cperl-windowed-init ()
5707 "Initialization under windowed version."
5708 (cond ((featurep 'ps-print)
5709 (unless cperl-faces-init
5710 (if (boundp 'font-lock-multiline)
5711 (setq cperl-font-lock-multiline t))
5712 (cperl-init-faces)))
5713 ((not cperl-faces-init)
5714 (add-hook 'font-lock-mode-hook
5717 (if (memq major-mode '(perl-mode cperl-mode))
5719 (or cperl-faces-init (cperl-init-faces)))))))
5720 (if (fboundp 'eval-after-load)
5723 '(or cperl-faces-init (cperl-init-faces)))))))
5725 (defvar cperl-font-lock-keywords-1 nil
5726 "Additional expressions to highlight in Perl mode. Minimal set.")
5727 (defvar cperl-font-lock-keywords nil
5728 "Additional expressions to highlight in Perl mode. Default set.")
5729 (defvar cperl-font-lock-keywords-2 nil
5730 "Additional expressions to highlight in Perl mode. Maximal set")
5732 (defun cperl-load-font-lock-keywords ()
5733 (or cperl-faces-init (cperl-init-faces))
5734 cperl-font-lock-keywords)
5736 (defun cperl-load-font-lock-keywords-1 ()
5737 (or cperl-faces-init (cperl-init-faces))
5738 cperl-font-lock-keywords-1)
5740 (defun cperl-load-font-lock-keywords-2 ()
5741 (or cperl-faces-init (cperl-init-faces))
5742 cperl-font-lock-keywords-2)
5744 (defun cperl-init-faces-weak ()
5745 ;; Allow `cperl-find-pods-heres' to run.
5746 (or (boundp 'font-lock-constant-face)
5747 (cperl-force-face font-lock-constant-face
5748 "Face for constant and label names"))
5749 (or (boundp 'font-lock-warning-face)
5750 (cperl-force-face font-lock-warning-face
5751 "Face for things which should stand out"))
5752 ;;(setq font-lock-constant-face 'font-lock-constant-face)
5755 (defun cperl-init-faces ()
5756 (condition-case errs
5758 (require 'font-lock)
5759 (and (fboundp 'font-lock-fontify-anchored-keywords)
5760 (featurep 'font-lock-extra)
5761 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
5762 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
5763 (if (fboundp 'font-lock-fontify-anchored-keywords)
5764 (setq font-lock-anchored t))
5766 t-font-lock-keywords
5768 `("[ \t]+$" 0 ',cperl-invalid-face t)
5771 "\\(^\\|[^$@%&\\]\\)\\<\\("
5774 '("if" "until" "while" "elsif" "else" "unless" "for"
5775 "foreach" "continue" "exit" "die" "last" "goto" "next"
5776 "redo" "return" "local" "exec" "sub" "do" "dump" "use" "our"
5777 "require" "package" "eval" "my" "BEGIN" "END" "CHECK" "INIT")
5778 "\\|") ; Flow control
5779 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
5780 ; In what follows we use `type' style
5781 ; for overwritable builtins
5784 "\\(^\\|[^$@%&\\]\\)\\<\\("
5785 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
5786 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
5787 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
5788 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
5789 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
5790 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
5791 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
5792 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
5793 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
5794 ;; "gethostbyname" "gethostent" "getlogin"
5795 ;; "getnetbyaddr" "getnetbyname" "getnetent"
5796 ;; "getpeername" "getpgrp" "getppid" "getpriority"
5797 ;; "getprotobyname" "getprotobynumber" "getprotoent"
5798 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
5799 ;; "getservbyport" "getservent" "getsockname"
5800 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
5801 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
5802 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
5803 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
5804 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
5805 ;; "quotemeta" "rand" "read" "readdir" "readline"
5806 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
5807 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
5808 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
5809 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
5810 ;; "setpriority" "setprotoent" "setpwent" "setservent"
5811 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
5812 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
5813 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
5814 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
5815 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
5816 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
5817 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
5818 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
5819 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
5820 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
5821 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
5822 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
5823 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
5824 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
5825 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
5826 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
5827 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
5828 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
5829 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
5830 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
5831 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
5832 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
5833 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
5834 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
5835 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
5836 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
5837 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
5838 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
5839 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
5840 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
5841 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
5842 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
5843 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
5844 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
5845 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
5846 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
5847 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
5848 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
5849 "\\)\\>") 2 'font-lock-type-face)
5850 ;; In what follows we use `other' style
5851 ;; for nonoverwritable builtins
5852 ;; Somehow 's', 'm' are not auto-generated???
5855 "\\(^\\|[^$@%&\\]\\)\\<\\("
5856 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "chomp"
5857 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
5858 ;; "eval" "exists" "for" "foreach" "format" "goto"
5859 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
5860 ;; "no" "our" "package" "pop" "pos" "print" "printf" "push"
5861 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
5862 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
5863 ;; "undef" "unless" "unshift" "untie" "until" "use"
5865 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
5866 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
5867 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|INIT\\|if\\|keys\\|"
5868 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
5869 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
5870 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
5871 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
5872 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
5873 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
5874 "\\|[sm]" ; Added manually
5875 "\\)\\>") 2 'cperl-nonoverridable-face)
5876 ;; (mapconcat 'identity
5877 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
5878 ;; "#include" "#define" "#undef")
5880 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
5881 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
5882 ;; This highlights declarations and definitions differenty.
5883 ;; We do not try to highlight in the case of attributes:
5884 ;; it is already done by `cperl-find-pods-heres'
5885 (list (concat "\\<sub"
5886 cperl-white-and-comment-rex ; whitespace/comments
5887 "\\([^ \n\t{;()]+\\)" ; 2=name (assume non-anonymous)
5889 cperl-maybe-white-and-comment-rex ;whitespace/comments?
5890 "([^()]*)\\)?" ; prototype
5891 cperl-maybe-white-and-comment-rex ; whitespace/comments?
5893 2 (if cperl-font-lock-multiline
5894 '(if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5895 'font-lock-function-name-face
5896 'font-lock-variable-name-face)
5897 ;; need to manually set 'multiline' for older font-locks
5899 (if (< 1 (count-lines (match-beginning 0)
5902 (+ 3 (match-beginning 0)) (match-end 0)
5903 'syntax-type 'multiline))
5904 (if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5905 'font-lock-function-name-face
5906 'font-lock-variable-name-face))))
5907 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
5908 2 font-lock-function-name-face)
5909 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
5910 1 font-lock-function-name-face)
5911 (cond ((featurep 'font-lock-extra)
5912 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5913 (2 font-lock-string-face t)
5914 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
5916 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5917 (2 font-lock-string-face t)
5918 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5920 (1 font-lock-string-face t))))
5921 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5922 2 font-lock-string-face t)))
5923 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
5924 font-lock-string-face t)
5925 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
5926 font-lock-constant-face) ; labels
5927 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
5928 2 font-lock-constant-face)
5929 ;; Uncomment to get perl-mode-like vars
5930 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
5931 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
5932 ;;; (2 (cons font-lock-variable-name-face '(underline))))
5933 (cond ((featurep 'font-lock-extra)
5934 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5935 (3 font-lock-variable-name-face)
5937 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5938 (1 font-lock-variable-name-face)
5939 (2 '(restart 2 nil) nil t)))
5940 nil t))) ; local variables, multiple
5942 ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
5943 (` ((, (concat "\\<\\(my\\|local\\|our\\)"
5944 cperl-maybe-white-and-comment-rex
5946 cperl-maybe-white-and-comment-rex
5947 "\\)?\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
5948 (5 (, (if cperl-font-lock-multiline
5949 'font-lock-variable-name-face
5950 '(progn (setq cperl-font-lock-multiline-start
5951 (match-beginning 0))
5952 'font-lock-variable-name-face))))
5954 cperl-maybe-white-and-comment-rex
5956 cperl-maybe-white-and-comment-rex
5957 "\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
5958 ;; Bug in font-lock: limit is used not only to limit
5959 ;; searches, but to set the "extend window for
5960 ;; facification" property. Thus we need to minimize.
5961 (, (if cperl-font-lock-multiline
5962 '(if (match-beginning 3)
5964 (goto-char (match-beginning 3))
5970 (error nil)))) ; typeahead
5971 (1- (point))) ; report limit
5972 (forward-char -2)) ; disable continued expr
5973 '(if (match-beginning 3)
5974 (point-max) ; No limit for continuation
5975 (forward-char -2)))) ; disable continued expr
5976 (, (if cperl-font-lock-multiline
5979 ;; "my" may be already fontified (POD),
5980 ;; so cperl-font-lock-multiline-start is nil
5981 (if (or (not cperl-font-lock-multiline-start)
5983 cperl-font-lock-multiline-start
5987 (1+ cperl-font-lock-multiline-start) (point)
5988 'syntax-type 'multiline))
5989 (setq cperl-font-lock-multiline-start nil))))
5990 (3 font-lock-variable-name-face)))))
5991 (t '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
5992 3 font-lock-variable-name-face)))
5993 '("\\<for\\(each\\)?\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
5994 4 font-lock-variable-name-face)
5995 ;; Avoid $!, and s!!, qq!! etc. when not fontifying syntaxically
5996 '("\\(?:^\\|[^smywqrx$]\\)\\(!\\)" 1 font-lock-negation-char-face)
5997 '("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)))
5999 t-font-lock-keywords-1
6000 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
6001 ;; not yet as of XEmacs 19.12, works with 21.1.11
6003 (not cperl-xemacs-p)
6004 (string< "21.1.9" emacs-version)
6005 (and (string< "21.1.10" emacs-version)
6006 (string< emacs-version "21.1.2")))
6008 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
6009 (if (eq (char-after (match-beginning 2)) ?%)
6012 t) ; arrays and hashes
6013 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
6015 (if (= (- (match-end 2) (match-beginning 2)) 1)
6016 (if (eq (char-after (match-beginning 3)) ?{)
6018 'cperl-array-face) ; arrays and hashes
6019 font-lock-variable-name-face) ; Just to put something
6021 ("\\(@\\|\\$#\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
6022 (1 cperl-array-face)
6023 (2 font-lock-variable-name-face))
6024 ("\\(%\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
6026 (2 font-lock-variable-name-face))
6027 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
6028 ;;; Too much noise from \s* @s[ and friends
6029 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
6030 ;;(3 font-lock-function-name-face t t)
6032 ;; (if (cperl-slash-is-regexp)
6033 ;; font-lock-function-name-face 'default) nil t))
6035 (if cperl-highlight-variables-indiscriminately
6036 (setq t-font-lock-keywords-1
6037 (append t-font-lock-keywords-1
6038 (list '("\\([$*]{?\\sw+\\)" 1
6039 font-lock-variable-name-face)))))
6040 (setq cperl-font-lock-keywords-1
6041 (if cperl-syntaxify-by-font-lock
6042 (cons 'cperl-fontify-update
6043 t-font-lock-keywords)
6044 t-font-lock-keywords)
6045 cperl-font-lock-keywords cperl-font-lock-keywords-1
6046 cperl-font-lock-keywords-2 (append
6047 cperl-font-lock-keywords-1
6048 t-font-lock-keywords-1)))
6049 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
6050 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
6051 (eval ; Avoid a warning
6052 '(font-lock-require-faces
6054 ;; Color-light Color-dark Gray-light Gray-dark Mono
6055 (list 'font-lock-comment-face
6056 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
6061 (list 'font-lock-string-face
6062 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
6067 (list 'font-lock-function-name-face
6069 "Blue" "LightSkyBlue" "Gray50" "LightGray"
6070 (cdr (assq 'background-color ; if mono
6071 (frame-parameters))))
6074 (cdr (assq 'foreground-color ; if mono
6075 (frame-parameters))))
6079 (list 'font-lock-variable-name-face
6080 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
6085 (list 'font-lock-type-face
6086 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
6091 (list 'font-lock-warning-face
6092 ["Pink" "Red" "Gray50" "LightGray"]
6099 (list 'font-lock-constant-face
6100 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
6105 (list 'cperl-nonoverridable-face
6106 ["chartreuse3" ("orchid1" "orange")
6112 (list 'cperl-array-face
6113 ["blue" "yellow" nil "Gray80"]
6114 ["lightyellow2" ("navy" "os2blue" "darkgreen")
6119 (list 'cperl-hash-face
6120 ["red" "red" nil "Gray80"]
6121 ["lightyellow2" ("navy" "os2blue" "darkgreen")
6126 ;; Do it the dull way, without choose-color
6127 (defvar cperl-guessed-background nil
6128 "Display characteristics as guessed by cperl.")
6129 ;; (or (fboundp 'x-color-defined-p)
6130 ;; (defalias 'x-color-defined-p
6131 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
6132 ;; ;; XEmacs >= 19.12
6133 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
6135 ;; (t 'x-valid-color-name-p))))
6136 (cperl-force-face font-lock-constant-face
6137 "Face for constant and label names")
6138 (cperl-force-face font-lock-variable-name-face
6139 "Face for variable names")
6140 (cperl-force-face font-lock-type-face
6141 "Face for data types")
6142 (cperl-force-face cperl-nonoverridable-face
6143 "Face for data types from another group")
6144 (cperl-force-face font-lock-warning-face
6145 "Face for things which should stand out")
6146 (cperl-force-face font-lock-comment-face
6147 "Face for comments")
6148 (cperl-force-face font-lock-function-name-face
6149 "Face for function names")
6150 (cperl-force-face cperl-hash-face
6152 (cperl-force-face cperl-array-face
6154 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
6155 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
6156 ;;(or (boundp 'font-lock-type-face)
6157 ;; (defconst font-lock-type-face
6158 ;; 'font-lock-type-face
6159 ;; "Face to use for data types."))
6160 ;;(or (boundp 'cperl-nonoverridable-face)
6161 ;; (defconst cperl-nonoverridable-face
6162 ;; 'cperl-nonoverridable-face
6163 ;; "Face to use for data types from another group."))
6164 ;;(if (not cperl-xemacs-p) nil
6165 ;; (or (boundp 'font-lock-comment-face)
6166 ;; (defconst font-lock-comment-face
6167 ;; 'font-lock-comment-face
6168 ;; "Face to use for comments."))
6169 ;; (or (boundp 'font-lock-keyword-face)
6170 ;; (defconst font-lock-keyword-face
6171 ;; 'font-lock-keyword-face
6172 ;; "Face to use for keywords."))
6173 ;; (or (boundp 'font-lock-function-name-face)
6174 ;; (defconst font-lock-function-name-face
6175 ;; 'font-lock-function-name-face
6176 ;; "Face to use for function names.")))
6178 (not (cperl-is-face 'cperl-array-face))
6179 (cperl-is-face 'font-lock-emphasized-face))
6180 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
6182 (not (cperl-is-face 'cperl-hash-face))
6183 (cperl-is-face 'font-lock-other-emphasized-face))
6184 (copy-face 'font-lock-other-emphasized-face 'cperl-hash-face))
6186 (not (cperl-is-face 'cperl-nonoverridable-face))
6187 (cperl-is-face 'font-lock-other-type-face))
6188 (copy-face 'font-lock-other-type-face 'cperl-nonoverridable-face))
6189 ;;(or (boundp 'cperl-hash-face)
6190 ;; (defconst cperl-hash-face
6192 ;; "Face to use for hashes."))
6193 ;;(or (boundp 'cperl-array-face)
6194 ;; (defconst cperl-array-face
6195 ;; 'cperl-array-face
6196 ;; "Face to use for arrays."))
6197 ;; Here we try to guess background
6199 (if (boundp 'font-lock-background-mode)
6200 font-lock-background-mode
6202 (face-list (and (fboundp 'face-list) (face-list))))
6203 ;;;; (fset 'cperl-is-face
6204 ;;;; (cond ((fboundp 'find-face)
6205 ;;;; (symbol-function 'find-face))
6207 ;;;; (function (lambda (face) (member face face-list))))
6209 ;;;; (function (lambda (face) (boundp face))))))
6210 (defvar cperl-guessed-background
6211 (if (and (boundp 'font-lock-display-type)
6212 (eq font-lock-display-type 'grayscale))
6215 "Background as guessed by CPerl mode")
6216 (and (not (cperl-is-face 'font-lock-constant-face))
6217 (cperl-is-face 'font-lock-reference-face)
6218 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
6219 (if (cperl-is-face 'font-lock-type-face) nil
6220 (copy-face 'default 'font-lock-type-face)
6222 ((eq background 'light)
6223 (set-face-foreground 'font-lock-type-face
6224 (if (x-color-defined-p "seagreen")
6227 ((eq background 'dark)
6228 (set-face-foreground 'font-lock-type-face
6229 (if (x-color-defined-p "os2pink")
6233 (set-face-background 'font-lock-type-face "gray90"))))
6234 (if (cperl-is-face 'cperl-nonoverridable-face)
6236 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
6238 ((eq background 'light)
6239 (set-face-foreground 'cperl-nonoverridable-face
6240 (if (x-color-defined-p "chartreuse3")
6243 ((eq background 'dark)
6244 (set-face-foreground 'cperl-nonoverridable-face
6245 (if (x-color-defined-p "orchid1")
6248 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
6249 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
6251 ;;; ((eq background 'light)
6252 ;;; (set-face-background 'font-lock-other-emphasized-face
6253 ;;; (if (x-color-defined-p "lightyellow2")
6255 ;;; (if (x-color-defined-p "lightyellow")
6257 ;;; "light yellow"))))
6258 ;;; ((eq background 'dark)
6259 ;;; (set-face-background 'font-lock-other-emphasized-face
6260 ;;; (if (x-color-defined-p "navy")
6262 ;;; (if (x-color-defined-p "darkgreen")
6264 ;;; "dark green"))))
6265 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
6266 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
6267 ;;; (copy-face 'bold 'font-lock-emphasized-face)
6269 ;;; ((eq background 'light)
6270 ;;; (set-face-background 'font-lock-emphasized-face
6271 ;;; (if (x-color-defined-p "lightyellow2")
6273 ;;; "lightyellow")))
6274 ;;; ((eq background 'dark)
6275 ;;; (set-face-background 'font-lock-emphasized-face
6276 ;;; (if (x-color-defined-p "navy")
6278 ;;; (if (x-color-defined-p "darkgreen")
6280 ;;; "dark green"))))
6281 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
6282 (if (cperl-is-face 'font-lock-variable-name-face) nil
6283 (copy-face 'italic 'font-lock-variable-name-face))
6284 (if (cperl-is-face 'font-lock-constant-face) nil
6285 (copy-face 'italic 'font-lock-constant-face))))
6286 (setq cperl-faces-init t))
6287 (error (message "cperl-init-faces (ignored): %s" errs))))
6290 (defun cperl-ps-print-init ()
6291 "Initialization of `ps-print' components for faces used in CPerl."
6292 (eval-after-load "ps-print"
6293 '(setq ps-bold-faces
6294 ;; font-lock-variable-name-face
6295 ;; font-lock-constant-face
6296 (append '(cperl-array-face cperl-hash-face)
6299 ;; font-lock-constant-face
6300 (append '(cperl-nonoverridable-face cperl-hash-face)
6303 ;; font-lock-type-face
6304 (append '(cperl-array-face cperl-hash-face underline cperl-nonoverridable-face)
6305 ps-underlined-faces))))
6307 (defvar ps-print-face-extension-alist)
6309 (defun cperl-ps-print (&optional file)
6310 "Pretty-print in CPerl style.
6311 If optional argument FILE is an empty string, prints to printer, otherwise
6312 to the file FILE. If FILE is nil, prompts for a file name.
6314 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
6317 (setq file (read-from-minibuffer
6318 "Print to file (if empty - to printer): "
6319 (concat (buffer-file-name) ".ps")
6320 nil nil 'file-name-history)))
6321 (or (> (length file) 0)
6323 (require 'ps-print) ; To get ps-print-face-extension-alist
6324 (let ((ps-print-color-p t)
6325 (ps-print-face-extension-alist ps-print-face-extension-alist))
6326 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
6327 (ps-print-buffer-with-faces file)))
6329 ;;; (defun cperl-ps-print-init ()
6330 ;;; "Initialization of `ps-print' components for faces used in CPerl."
6331 ;;; ;; Guard against old versions
6332 ;;; (defvar ps-underlined-faces nil)
6333 ;;; (defvar ps-bold-faces nil)
6334 ;;; (defvar ps-italic-faces nil)
6335 ;;; (setq ps-bold-faces
6336 ;;; (append '(font-lock-emphasized-face
6337 ;;; cperl-array-face
6338 ;;; font-lock-keyword-face
6339 ;;; font-lock-variable-name-face
6340 ;;; font-lock-constant-face
6341 ;;; font-lock-reference-face
6342 ;;; font-lock-other-emphasized-face
6343 ;;; cperl-hash-face)
6345 ;;; (setq ps-italic-faces
6346 ;;; (append '(cperl-nonoverridable-face
6347 ;;; font-lock-constant-face
6348 ;;; font-lock-reference-face
6349 ;;; font-lock-other-emphasized-face
6350 ;;; cperl-hash-face)
6351 ;;; ps-italic-faces))
6352 ;;; (setq ps-underlined-faces
6353 ;;; (append '(font-lock-emphasized-face
6354 ;;; cperl-array-face
6355 ;;; font-lock-other-emphasized-face
6357 ;;; cperl-nonoverridable-face font-lock-type-face)
6358 ;;; ps-underlined-faces))
6359 ;;; (cons 'font-lock-type-face ps-underlined-faces))
6362 (if (cperl-enable-font-lock) (cperl-windowed-init))
6364 (defconst cperl-styles-entries
6365 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
6366 cperl-label-offset cperl-extra-newline-before-brace
6367 cperl-extra-newline-before-brace-multiline
6368 cperl-merge-trailing-else
6369 cperl-continued-statement-offset))
6371 (defconst cperl-style-examples
6372 "##### Numbers etc are: cperl-indent-level cperl-brace-offset
6373 ##### cperl-continued-brace-offset cperl-label-offset
6374 ##### cperl-continued-statement-offset
6375 ##### cperl-merge-trailing-else cperl-extra-newline-before-brace
6377 ########### (Do not forget cperl-extra-newline-before-brace-multiline)
6379 ### CPerl (=GNU - extra-newline-before-brace + merge-trailing-else) 2/0/0/-2/2/t/nil
6391 ### PerlStyle (=CPerl with 4 as indent) 4/0/0/-4/4/t/nil
6403 ### GNU 2/0/0/-2/2/nil/t
6418 ### C++ (=PerlStyle with braces aligned with control words) 4/0/-4/-4/4/nil/t
6433 ### BSD (=C++, but will not change preexisting merge-trailing-else
6434 ### and extra-newline-before-brace ) 4/0/-4/-4/4
6449 ### K&R (=C++ with indent 5 - merge-trailing-else, but will not
6450 ### change preexisting extra-newline-before-brace) 5/0/-5/-5/5/nil
6465 ### Whitesmith (=PerlStyle, but will not change preexisting
6466 ### extra-newline-before-brace and merge-trailing-else) 4/0/0/-4/4
6481 "Examples of if/else with different indent styles (with v4.23).")
6483 (defconst cperl-style-alist
6484 '(("CPerl" ;; =GNU - extra-newline-before-brace + cperl-merge-trailing-else
6485 (cperl-indent-level . 2)
6486 (cperl-brace-offset . 0)
6487 (cperl-continued-brace-offset . 0)
6488 (cperl-label-offset . -2)
6489 (cperl-continued-statement-offset . 2)
6490 (cperl-extra-newline-before-brace . nil)
6491 (cperl-extra-newline-before-brace-multiline . nil)
6492 (cperl-merge-trailing-else . t))
6494 ("PerlStyle" ; CPerl with 4 as indent
6495 (cperl-indent-level . 4)
6496 (cperl-brace-offset . 0)
6497 (cperl-continued-brace-offset . 0)
6498 (cperl-label-offset . -4)
6499 (cperl-continued-statement-offset . 4)
6500 (cperl-extra-newline-before-brace . nil)
6501 (cperl-extra-newline-before-brace-multiline . nil)
6502 (cperl-merge-trailing-else . t))
6505 (cperl-indent-level . 2)
6506 (cperl-brace-offset . 0)
6507 (cperl-continued-brace-offset . 0)
6508 (cperl-label-offset . -2)
6509 (cperl-continued-statement-offset . 2)
6510 (cperl-extra-newline-before-brace . t)
6511 (cperl-extra-newline-before-brace-multiline . t)
6512 (cperl-merge-trailing-else . nil))
6515 (cperl-indent-level . 5)
6516 (cperl-brace-offset . 0)
6517 (cperl-continued-brace-offset . -5)
6518 (cperl-label-offset . -5)
6519 (cperl-continued-statement-offset . 5)
6520 ;;(cperl-extra-newline-before-brace . nil) ; ???
6521 ;;(cperl-extra-newline-before-brace-multiline . nil)
6522 (cperl-merge-trailing-else . nil))
6525 (cperl-indent-level . 4)
6526 (cperl-brace-offset . 0)
6527 (cperl-continued-brace-offset . -4)
6528 (cperl-label-offset . -4)
6529 (cperl-continued-statement-offset . 4)
6530 ;;(cperl-extra-newline-before-brace . nil) ; ???
6531 ;;(cperl-extra-newline-before-brace-multiline . nil)
6532 ;;(cperl-merge-trailing-else . nil) ; ???
6536 (cperl-indent-level . 4)
6537 (cperl-brace-offset . 0)
6538 (cperl-continued-brace-offset . -4)
6539 (cperl-label-offset . -4)
6540 (cperl-continued-statement-offset . 4)
6541 (cperl-extra-newline-before-brace . t)
6542 (cperl-extra-newline-before-brace-multiline . t)
6543 (cperl-merge-trailing-else . nil))
6546 (cperl-indent-level . 4)
6547 (cperl-brace-offset . 0)
6548 (cperl-continued-brace-offset . 0)
6549 (cperl-label-offset . -4)
6550 (cperl-continued-statement-offset . 4)
6551 ;;(cperl-extra-newline-before-brace . nil) ; ???
6552 ;;(cperl-extra-newline-before-brace-multiline . nil)
6553 ;;(cperl-merge-trailing-else . nil) ; ???
6556 "List of variables to set to get a particular indentation style.
6557 Should be used via `cperl-set-style' or via Perl menu.
6559 See examples in `cperl-style-examples'.")
6561 (defun cperl-set-style (style)
6562 "Set CPerl mode variables to use one of several different indentation styles.
6563 The arguments are a string representing the desired style.
6564 The list of styles is in `cperl-style-alist', available styles
6565 are CPerl, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith.
6567 The current value of style is memorized (unless there is a memorized
6568 data already), may be restored by `cperl-set-style-back'.
6570 Chosing \"Current\" style will not change style, so this may be used for
6571 side-effect of memorizing only. Examples in `cperl-style-examples'."
6573 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
6574 cperl-style-alist)))
6575 (list (completing-read "Enter style: " list nil 'insist))))
6577 (setq cperl-old-style
6580 (cons name (eval name))))
6581 cperl-styles-entries)))
6582 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
6584 (setq setting (car style) style (cdr style))
6585 (set (car setting) (cdr setting)))))
6587 (defun cperl-set-style-back ()
6588 "Restore a style memorized by `cperl-set-style'."
6590 (or cperl-old-style (error "The style was not changed"))
6592 (while cperl-old-style
6593 (setq setting (car cperl-old-style)
6594 cperl-old-style (cdr cperl-old-style))
6595 (set (car setting) (cdr setting)))))
6597 (defun cperl-check-syntax ()
6599 (require 'mode-compile)
6600 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
6601 (eval '(mode-compile)))) ; Avoid a warning
6603 (defun cperl-info-buffer (type)
6604 ;; Returns buffer with documentation. Creates if missing.
6605 ;; If TYPE, this vars buffer.
6606 ;; Special care is taken to not stomp over an existing info buffer
6607 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
6608 (info (get-buffer bname))
6609 (oldbuf (get-buffer "*info*")))
6611 (save-window-excursion
6616 (rename-buffer "*info-perl-tmp*")))
6617 (save-window-excursion
6619 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
6620 (set-buffer "*info*")
6621 (rename-buffer bname)
6623 (set-buffer "*info-perl-tmp*")
6624 (rename-buffer "*info*")
6625 (set-buffer bname)))
6626 (make-local-variable 'window-min-height)
6627 (setq window-min-height 2)
6628 (current-buffer)))))
6630 (defun cperl-word-at-point (&optional p)
6631 "Return the word at point or at P."
6633 (if p (goto-char p))
6634 (or (cperl-word-at-point-hard)
6637 (funcall (or (and (boundp 'find-tag-default-function)
6638 find-tag-default-function)
6639 (get major-mode 'find-tag-default-function)
6640 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
6641 ;; automatically used within `find-tag-default':
6642 'find-tag-default))))))
6644 (defun cperl-info-on-command (command)
6645 "Show documentation for Perl command COMMAND in other window.
6646 If perl-info buffer is shown in some frame, uses this frame.
6647 Customized by setting variables `cperl-shrink-wrap-info-frame',
6648 `cperl-max-help-size'."
6650 (let* ((default (cperl-word-at-point))
6652 (format "Find doc for Perl function (default %s): "
6654 (list (if (equal read "")
6658 (let ((buffer (current-buffer))
6659 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
6660 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
6661 max-height char-height buf-list)
6662 (if (string-match "^-[a-zA-Z]$" command)
6663 (setq cmd-desc "^-X[ \t\n]"))
6664 (setq isvar (string-match "^[$@%]" command)
6665 buf (cperl-info-buffer isvar)
6666 iniwin (selected-window)
6667 fr1 (window-frame iniwin))
6669 (goto-char (point-min))
6671 (progn (re-search-forward "^-X[ \t\n]")
6673 (if (re-search-forward cmd-desc nil t)
6675 ;; Go back to beginning of the group (ex, for qq)
6676 (if (re-search-backward "^[ \t\n\f]")
6681 buf-list (list buf "*info-perl-var*" "*info-perl*"))
6682 (while (and (not win) buf-list)
6683 (setq win (get-buffer-window (car buf-list) t))
6684 (setq buf-list (cdr buf-list)))
6686 (eq (window-buffer win) buf)
6687 (set-window-buffer win buf))
6688 (and win (setq fr2 (window-frame win)))
6689 (if (or (not fr2) (eq fr1 fr2))
6691 (special-display-popup-frame buf) ; Make it visible
6692 (select-window win))
6693 (goto-char pos) ; Needed (?!).
6695 (setq iniheight (window-height)
6696 frheight (frame-height)
6697 not-loner (< iniheight (1- frheight))) ; Are not alone
6698 (cond ((if not-loner cperl-max-help-size
6699 cperl-shrink-wrap-info-frame)
6705 (if (re-search-forward
6706 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
6707 (match-beginning 0) (point-max)))))
6710 (/ (* (- frheight 3) cperl-max-help-size) 100)
6711 (setq char-height (frame-char-height))
6712 ;; Non-functioning under OS/2:
6713 (if (eq char-height 1) (setq char-height 18))
6714 ;; Title, menubar, + 2 for slack
6715 (- (/ (x-display-pixel-height) char-height) 4)))
6716 (if (> height max-height) (setq height max-height))
6717 ;;(message "was %s doing %s" iniheight height)
6719 (enlarge-window (- height iniheight))
6720 (set-frame-height (window-frame win) (1+ height)))))
6721 (set-window-start (selected-window) pos))
6722 (message "No entry for %s found." command))
6723 ;;(pop-to-buffer buffer)
6724 (select-window iniwin)))
6726 (defun cperl-info-on-current-command ()
6727 "Show documentation for Perl command at point in other window."
6729 (cperl-info-on-command (cperl-word-at-point)))
6731 (defun cperl-imenu-info-imenu-search ()
6732 (if (looking-at "^-X[ \t\n]") nil
6734 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
6737 (defun cperl-imenu-info-imenu-name ()
6739 (match-beginning 1) (match-end 1)))
6741 (defun cperl-imenu-on-info ()
6742 "Shows imenu for Perl Info Buffer.
6743 Opens Perl Info buffer if needed."
6745 (let* ((buffer (current-buffer))
6746 imenu-create-index-function
6747 imenu-prev-index-position-function
6748 imenu-extract-index-name-function
6749 (index-item (save-restriction
6750 (save-window-excursion
6751 (set-buffer (cperl-info-buffer nil))
6752 (setq imenu-create-index-function
6753 'imenu-default-create-index-function
6754 imenu-prev-index-position-function
6755 'cperl-imenu-info-imenu-search
6756 imenu-extract-index-name-function
6757 'cperl-imenu-info-imenu-name)
6758 (imenu-choose-buffer-index)))))
6762 (pop-to-buffer "*info-perl*")
6764 ((markerp (cdr index-item))
6765 (goto-char (marker-position (cdr index-item))))
6767 (goto-char (cdr index-item))))
6768 (set-window-start (selected-window) (point))
6769 (pop-to-buffer buffer)))))
6771 (defun cperl-lineup (beg end &optional step minshift)
6772 "Lineup construction in a region.
6773 Beginning of region should be at the start of a construction.
6774 All first occurrences of this construction in the lines that are
6775 partially contained in the region are lined up at the same column.
6777 MINSHIFT is the minimal amount of space to insert before the construction.
6778 STEP is the tabwidth to position constructions.
6779 If STEP is nil, `cperl-lineup-step' will be used
6780 \(or `cperl-indent-level', if `cperl-lineup-step' is nil).
6781 Will not move the position at the start to the left."
6783 (let (search col tcol seen b)
6787 (setq end (point-marker))
6789 (skip-chars-forward " \t\f")
6790 (setq beg (point-marker))
6791 (indent-region beg end nil)
6793 (setq col (current-column))
6794 (if (looking-at "[a-zA-Z0-9_]")
6795 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
6799 (buffer-substring (match-beginning 0)
6800 (match-end 0))) "\\>"))
6801 (error "Cannot line up in a middle of the word"))
6802 (if (looking-at "$")
6803 (error "Cannot line up end of line"))
6804 (setq search (regexp-quote (char-to-string (following-char)))))
6805 (setq step (or step cperl-lineup-step cperl-indent-level))
6806 (or minshift (setq minshift 1))
6808 (beginning-of-line 2)
6809 (and (< (point) end)
6810 (re-search-forward search end t)
6811 (goto-char (match-beginning 0))))
6812 (setq tcol (current-column) seen t)
6813 (if (> tcol col) (setq col tcol)))
6815 (error "The construction to line up occurred only once"))
6817 (setq col (+ col minshift))
6818 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
6821 (cperl-make-indent col)
6822 (beginning-of-line 2)
6823 (and (< (point) end)
6824 (re-search-forward search end t)
6825 (goto-char (match-beginning 0)))))))) ; No body
6827 (defun cperl-etags (&optional add all files) ;; NOT USED???
6828 "Run etags with appropriate options for Perl files.
6829 If optional argument ALL is `recursive', will process Perl files
6830 in subdirectories too."
6833 (args '("-l" "none" "-r"
6834 ;; 1=fullname 2=package? 3=name 4=proto? 5=attrs? (VERY APPROX!)
6835 "/\\<sub[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([ \t]*:[^#{;]*\\)?\\([{#]\\|$\\)/\\3/"
6837 "/\\<package[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\([#;]\\|$\\)/\\1/"
6839 "/\\<\\(package\\)[ \\t]*;/\\1;/"))
6841 (if add (setq args (cons "-a" args)))
6842 (or files (setq files (list buffer-file-name)))
6844 ((eq all 'recursive)
6845 ;;(error "Not implemented: recursive")
6846 (setq args (append (list "-e"
6847 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
6849 find(\\&wanted, '.');
6854 ;;(error "Not implemented: all")
6855 (setq args (append (list "-e"
6856 "push @ARGV, <*.PL *.pl *.pm>;
6861 (setq args (append args files))))
6862 (setq res (apply 'call-process cmd nil nil nil args))
6864 (message "etags returned \"%s\"" res))))
6866 (defun cperl-toggle-auto-newline ()
6867 "Toggle the state of `cperl-auto-newline'."
6869 (setq cperl-auto-newline (not cperl-auto-newline))
6870 (message "Newlines will %sbe auto-inserted now."
6871 (if cperl-auto-newline "" "not ")))
6873 (defun cperl-toggle-abbrev ()
6874 "Toggle the state of automatic keyword expansion in CPerl mode."
6876 (abbrev-mode (if abbrev-mode 0 1))
6877 (message "Perl control structure will %sbe auto-inserted now."
6878 (if abbrev-mode "" "not ")))
6881 (defun cperl-toggle-electric ()
6882 "Toggle the state of parentheses doubling in CPerl mode."
6884 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
6885 (message "Parentheses will %sbe auto-doubled now."
6886 (if (cperl-val 'cperl-electric-parens) "" "not ")))
6888 (defun cperl-toggle-autohelp ()
6889 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
6890 Delay of auto-help controlled by `cperl-lazy-help-time'."
6892 (if (fboundp 'run-with-idle-timer)
6894 (if cperl-lazy-installed
6895 (cperl-lazy-unstall)
6896 (cperl-lazy-install))
6897 (message "Perl help messages will %sbe automatically shown now."
6898 (if cperl-lazy-installed "" "not ")))
6899 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
6901 (defun cperl-toggle-construct-fix ()
6902 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
6904 (setq cperl-indent-region-fix-constructs
6905 (if cperl-indent-region-fix-constructs
6908 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
6909 (if cperl-indent-region-fix-constructs "" "not ")))
6911 (defun cperl-toggle-set-debug-unwind (arg &optional backtrace)
6912 "Toggle (or, with numeric argument, set) debugging state of syntaxification.
6913 Nonpositive numeric argument disables debugging messages. The message
6914 summarizes which regions it was decided to rescan for syntactic constructs.
6916 The message looks like this:
6918 Syxify req=123..138 actual=101..146 done-to: 112=>146 statepos: 73=>117
6920 Numbers are character positions in the buffer. REQ provides the range to
6921 rescan requested by `font-lock'. ACTUAL is the range actually resyntaxified;
6922 for correct operation it should start and end outside any special syntactic
6923 construct. DONE-TO and STATEPOS indicate changes to internal caches maintained
6927 (setq arg (if (eq cperl-syntaxify-by-font-lock
6928 (if backtrace 'backtrace 'message)) 0 1)))
6929 (setq arg (if (> arg 0) (if backtrace 'backtrace 'message) t))
6930 (setq cperl-syntaxify-by-font-lock arg)
6931 (message "Debugging messages of syntax unwind %sabled."
6932 (if (eq arg t) "dis" "en")))
6934 ;;;; Tags file creation.
6936 (defvar cperl-tmp-buffer " *cperl-tmp*")
6938 (defun cperl-setup-tmp-buf ()
6939 (set-buffer (get-buffer-create cperl-tmp-buffer))
6940 (set-syntax-table cperl-mode-syntax-table)
6941 (buffer-disable-undo)
6943 (if cperl-use-syntax-table-text-property-for-tags
6945 (make-local-variable 'parse-sexp-lookup-properties)
6946 ;; Do not introduce variable if not needed, we check it!
6947 (set 'parse-sexp-lookup-properties t))))
6949 (defun cperl-xsub-scan ()
6951 (let ((index-alist '())
6952 (prev-pos 0) index index1 name package prefix)
6953 (goto-char (point-min))
6954 ;; Search for the function
6955 (progn ;;save-match-data
6956 (while (re-search-forward
6957 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
6960 ((match-beginning 2) ; SECTION
6961 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
6962 (goto-char (match-beginning 0))
6963 (skip-chars-forward " \t")
6965 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
6966 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
6968 ((not package) nil) ; C language section
6969 ((match-beginning 3) ; XSUB
6970 (goto-char (1+ (match-beginning 3)))
6971 (setq index (imenu-example--name-and-position))
6972 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
6973 (if (and prefix (string-match (concat "^" prefix) name))
6974 (setq name (substring name (length prefix))))
6975 (cond ((string-match "::" name) nil)
6977 (setq index1 (cons (concat package "::" name) (cdr index)))
6978 (push index1 index-alist)))
6980 (push index index-alist))
6982 ;; (beginning-of-line)
6983 (setq index (imenu-example--name-and-position))
6984 (setcar index (concat package "::BOOT:"))
6985 (push index index-alist)))))
6988 (defvar cperl-unreadable-ok nil)
6990 (defun cperl-find-tags (ifile xs topdir)
6991 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
6992 (cperl-pod-here-fontify nil) f file)
6994 (if b (set-buffer b)
6995 (cperl-setup-tmp-buf))
6998 (setq file (car (insert-file-contents ifile)))
6999 (error (if cperl-unreadable-ok nil
7001 (format "File %s unreadable. Continue? " ifile))
7002 (setq cperl-unreadable-ok t)
7003 (error "Aborting: unreadable file %s" ifile)))))
7005 (message "Unreadable file %s" ifile)
7006 (message "Scanning file %s ..." file)
7007 (if (and cperl-use-syntax-table-text-property-for-tags
7009 (condition-case err ; after __END__ may have garbage
7010 (cperl-find-pods-heres nil nil noninteractive)
7011 (error (message "While scanning for syntax: %s" err))))
7013 (setq lst (cperl-xsub-scan))
7014 (setq ind (cperl-imenu--create-perl-index))
7015 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
7020 (cond ((string-match "^[_a-zA-Z]" (car elt))
7021 (goto-char (cdr elt))
7022 (beginning-of-line) ; pos should be of the start of the line
7025 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
7026 (buffer-substring (progn
7027 (goto-char (cdr elt))
7028 ;; After name now...
7029 (or (eolp) (forward-char 1))
7037 (setq elt (car lst) lst (cdr lst))
7042 (if (string-match "^package " (car elt))
7043 (substring (car elt) 8)
7046 (number-to-string (elt elt 2)) ; Line
7048 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
7050 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
7051 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
7053 ;; Need to insert the name without package as well
7054 (setq lst (cons (cons (substring (elt elt 3)
7062 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
7063 (set-text-properties 0 (length rel) nil rel)
7064 (and (equal topdir (substring rel 0 (length topdir)))
7065 (setq rel (substring file (length topdir))))
7066 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
7067 (setq ret (buffer-substring 1 (point-max)))
7070 (message "Scanning file %s finished" file))
7073 (defun cperl-add-tags-recurse-noxs ()
7074 "Add to TAGS data for \"pure\" Perl files in the current directory and kids.
7076 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7077 -f cperl-add-tags-recurse-noxs
7079 (cperl-write-tags nil nil t t nil t))
7081 (defun cperl-add-tags-recurse-noxs-fullpath ()
7082 "Add to TAGS data for \"pure\" Perl in the current directory and kids.
7083 Writes down fullpath, so TAGS is relocatable (but if the build directory
7084 is relocated, the file TAGS inside it breaks). Use as
7085 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7086 -f cperl-add-tags-recurse-noxs-fullpath
7088 (cperl-write-tags nil nil t t nil t ""))
7090 (defun cperl-add-tags-recurse ()
7091 "Add to TAGS file data for Perl files in the current directory and kids.
7093 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7094 -f cperl-add-tags-recurse
7096 (cperl-write-tags nil nil t t))
7098 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
7099 ;; If INBUFFER, do not select buffer, and do not save
7100 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
7103 (setq file (if dir default-directory (buffer-file-name)))
7104 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
7106 (setq topdir default-directory))
7107 (let ((tags-file-name "TAGS")
7108 (case-fold-search (eq system-type 'emx))
7111 (cond (inbuffer nil) ; Already there
7112 ((file-exists-p tags-file-name)
7114 (visit-tags-table-buffer)
7115 (visit-tags-table-buffer tags-file-name)))
7116 (t (set-buffer (find-file-noselect tags-file-name))))
7119 (cond ((eq erase 'ignore))
7122 (setq erase 'ignore)))
7125 (directory-files file t
7126 (if recurse nil cperl-scan-files-regexp)
7129 (if cperl-unreadable-ok nil
7131 (format "Directory %s unreadable. Continue? " file))
7132 (setq cperl-unreadable-ok t
7133 tm nil) ; Return empty list
7134 (error "Aborting: unreadable directory %s" file)))))))
7138 ((string-match cperl-noscan-files-regexp file)
7140 ((not (file-directory-p file))
7141 (if (string-match cperl-scan-files-regexp file)
7142 (cperl-write-tags file erase recurse nil t noxs topdir)))
7144 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
7147 (setq xs (string-match "\\.xs$" file))
7148 (if (not (and xs noxs))
7150 (cond ((eq erase 'ignore) (goto-char (point-max)))
7151 (erase (erase-buffer))
7155 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
7156 (set-text-properties 0 (length rel) nil rel)
7157 (and (equal topdir (substring rel 0 (length topdir)))
7158 (setq rel (substring file (length topdir))))
7159 (if (search-forward (concat "\f\n" rel ",") nil t)
7161 (search-backward "\f\n")
7162 (delete-region (point)
7165 (if (search-forward "\f\n"
7169 (goto-char (point-max)))))
7170 (insert (cperl-find-tags file xs topdir))))))
7171 (if inbuffer nil ; Delegate to the caller
7172 (save-buffer 0) ; No backup
7173 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
7174 (initialize-new-tags-table))))))
7176 (defvar cperl-tags-hier-regexp-list
7183 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
7185 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
7188 (defvar cperl-hierarchy '(() ())
7189 "Global hierarchy of classes.")
7191 (defun cperl-tags-hier-fill ()
7192 ;; Suppose we are in a tag table cooked by cperl.
7194 (let (type pack name pos line chunk ord cons1 file str info fileind)
7195 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
7196 (setq pos (match-beginning 0)
7197 pack (match-beginning 2))
7199 (if (looking-at (concat
7208 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
7209 name (buffer-substring (match-beginning 2) (match-end 2))
7210 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
7211 line (buffer-substring (match-beginning 3) (match-end 3))
7214 fileind (format "%s:%s" file line)
7215 ;; Moves to beginning of the next line:
7216 info (cperl-etags-snarf-tag file line))
7219 ;; Make new member of hierarchy name ==> file ==> pos if needed
7220 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
7222 (setcdr cons1 (cons (cons fileind (vector file info))
7224 ;; First occurrence of the name, start alist
7225 (setq cons1 (cons name (list (cons fileind (vector file info)))))
7227 (setcar (cdr cperl-hierarchy)
7228 (cons cons1 (nth 1 cperl-hierarchy)))
7229 (setcar cperl-hierarchy
7230 (cons cons1 (car cperl-hierarchy)))))))
7233 (defun cperl-tags-hier-init (&optional update)
7234 "Show hierarchical menu of classes and methods.
7235 Finds info about classes by a scan of loaded TAGS files.
7236 Supposes that the TAGS files contain fully qualified function names.
7237 One may build such TAGS files from CPerl mode menu."
7241 (if (or update (null (nth 2 cperl-hierarchy)))
7242 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
7245 (setcdr elt (cdr (nth 1 elt)))))))
7246 pack name cons1 to l1 l2 l3 l4 b)
7247 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
7248 (setq cperl-hierarchy (list l1 l2 l3))
7249 (if cperl-xemacs-p ; Not checked
7252 ;; Does this work in XEmacs?
7253 (call-interactively 'visit-tags-table))
7254 (message "Updating list of classes...")
7255 (set-buffer (get-file-buffer tags-file-name))
7256 (cperl-tags-hier-fill))
7258 (call-interactively 'visit-tags-table))
7262 (message "Updating list of classes... %s" tagsfile)
7263 (set-buffer (get-file-buffer tagsfile))
7264 (cperl-tags-hier-fill)))
7266 (message "Updating list of classes... postprocessing..."))
7267 (mapcar remover (car cperl-hierarchy))
7268 (mapcar remover (nth 1 cperl-hierarchy))
7269 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
7270 (cons "Methods: " (car cperl-hierarchy))))
7271 (cperl-tags-treeify to 1)
7272 (setcar (nthcdr 2 cperl-hierarchy)
7273 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
7274 (message "Updating list of classes: done, requesting display...")
7275 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
7277 (or (nth 2 cperl-hierarchy)
7278 (error "No items found"))
7280 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
7281 (if (if (fboundp 'display-popup-menus-p)
7282 (let ((f 'display-popup-menus-p))
7285 (x-popup-menu t (nth 2 cperl-hierarchy))
7287 (tmm-prompt (nth 2 cperl-hierarchy))))
7288 (if (and update (listp update))
7289 (progn (while (cdr update) (setq update (cdr update)))
7290 (setq update (car update)))) ; Get the last from the list
7291 (if (vectorp update)
7293 (find-file (elt update 0))
7294 (cperl-etags-goto-tag-location (elt update 1))))
7295 (if (eq update -999) (cperl-tags-hier-init t)))
7297 (defun cperl-tags-treeify (to level)
7298 ;; cadr of `to' is read-write. On start it is a cons
7299 (let* ((regexp (concat "^\\(" (mapconcat
7301 (make-list level "[_a-zA-Z0-9]+")
7304 (packages (cdr (nth 1 to)))
7305 (methods (cdr (nth 2 to)))
7306 l1 head tail cons1 cons2 ord writeto packs recurse
7307 root-packages root-functions ms many_ms same_name ps
7311 (cond ((and (string-match regexp (car elt))
7312 (or (eq ord 1) (match-end 2)))
7313 (setq head (substring (car elt) 0 (match-end 1))
7314 tail (if (match-end 2) (substring (car elt)
7317 (if (setq cons1 (assoc head writeto)) nil
7318 ;; Need to init new head
7319 (setcdr writeto (cons (list head (list "Packages: ")
7322 (setq cons1 (nth 1 writeto)))
7323 (setq cons2 (nth ord cons1)) ; Either packs or meths
7324 (setcdr cons2 (cons elt (cdr cons2))))
7326 (setq root-functions (cons elt root-functions)))
7328 (setq root-packages (cons elt root-packages))))))))
7329 (setcdr to l1) ; Init to dynamic space
7332 (mapcar move-deeper packages)
7334 (mapcar move-deeper methods)
7336 (mapcar (function (lambda (elt)
7337 (cperl-tags-treeify elt (1+ level))))
7339 ;;Now clean up leaders with one child only
7340 (mapcar (function (lambda (elt)
7341 (if (not (and (listp (cdr elt))
7342 (eq (length elt) 2))) nil
7343 (setcar elt (car (nth 1 elt)))
7344 (setcdr elt (cdr (nth 1 elt))))))
7346 ;; Sort the roots of subtrees
7347 (if (default-value 'imenu-sort-function)
7349 (sort (cdr to) (default-value 'imenu-sort-function))))
7350 ;; Now add back functions removed from display
7351 (mapcar (function (lambda (elt)
7352 (setcdr to (cons elt (cdr to)))))
7353 (if (default-value 'imenu-sort-function)
7355 (sort root-functions (default-value 'imenu-sort-function)))
7357 ;; Now add back packages removed from display
7358 (mapcar (function (lambda (elt)
7359 (setcdr to (cons (cons (concat "package " (car elt))
7362 (if (default-value 'imenu-sort-function)
7364 (sort root-packages (default-value 'imenu-sort-function)))
7368 ;;; '(keymap "Name1"
7372 ;;; ("Tail1" "x") ("Tail2" "y"))))
7374 (defun cperl-list-fold (list name limit)
7375 (let (list1 list2 elt1 (num 0))
7376 (if (<= (length list) limit) list
7377 (setq list1 nil list2 nil)
7382 (if (<= num imenu-max-items)
7383 (setq list2 (cons elt1 list2))
7384 (setq list1 (cons (cons name
7389 (nreverse (cons (cons name
7393 (defun cperl-menu-to-keymap (menu &optional name)
7399 (cond ((listp (cdr elt))
7400 (setq list (cperl-list-fold
7401 (cdr elt) (car elt) imenu-max-items))
7404 (cperl-menu-to-keymap list))))
7406 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
7407 (cperl-list-fold menu "Root" imenu-max-items)))))
7410 (defvar cperl-bad-style-regexp
7411 (mapconcat 'identity
7412 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
7413 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
7415 "Finds places such that insertion of a whitespace may help a lot.")
7417 (defvar cperl-not-bad-style-regexp
7420 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
7421 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
7422 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
7423 "<\\$?\\sw+\\(\\.\\(\\sw\\|_\\)+\\)?>" ; <IN> <stdin.h>
7424 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
7431 "\\\\[&$@*\\\\]" ; \&func
7434 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
7437 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
7438 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
7439 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
7443 "If matches at the start of match found by `my-bad-c-style-regexp',
7444 insertion of a whitespace will not help.")
7448 (defun cperl-find-bad-style ()
7449 "Find places in the buffer where insertion of a whitespace may help.
7450 Prompts user for insertion of spaces.
7451 Currently it is tuned to C and Perl syntax."
7453 (let (found-bad (p (point)))
7454 (setq last-nonmenu-event 13) ; To disable popup
7455 (goto-char (point-min))
7456 (map-y-or-n-p "Insert space here? "
7457 (lambda (arg) (insert " "))
7458 'cperl-next-bad-style
7459 '("location" "locations" "insert a space into")
7460 '((?\C-r (lambda (arg)
7461 (let ((buffer-quit-function
7462 'exit-recursive-edit))
7463 (message "Exit with Esc Esc")
7465 t)) ; Consider acted upon
7466 "edit, exit with Esc Esc")
7468 (let ((buffer-quit-function
7469 'exit-recursive-edit))
7470 (message "Exit with Esc Esc")
7472 t)) ; Consider acted upon
7473 "edit, exit with Esc Esc"))
7475 (if found-bad (goto-char found-bad)
7477 (message "No appropriate place found"))))
7479 (defun cperl-next-bad-style ()
7480 (let (p (not-found t) (point (point)) found)
7481 (while (and not-found
7482 (re-search-forward cperl-bad-style-regexp nil 'to-end))
7484 (goto-char (match-beginning 0))
7486 (looking-at cperl-not-bad-style-regexp)
7487 ;; Check for a < -b and friends
7488 (and (eq (following-char) ?\-)
7490 (skip-chars-backward " \t\n")
7491 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
7492 ;; Now check for syntax type
7494 (setq found (point))
7495 (beginning-of-defun)
7496 (let ((pps (parse-partial-sexp (point) found)))
7497 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
7498 (goto-char (match-end 0))
7506 (defvar cperl-have-help-regexp
7510 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
7511 "[$@]\\^[a-zA-Z]" ; Special variable
7512 "[$@][^ \n\t]" ; Special variable
7513 "-[a-zA-Z]" ; File test
7514 "\\\\[a-zA-Z0]" ; Special chars
7515 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
7516 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
7517 "[a-zA-Z_0-9:]+" ; symbol or number
7524 "Matches places in the buffer we can find help for.")
7526 (defvar cperl-message-on-help-error t)
7527 (defvar cperl-help-from-timer nil)
7529 (defun cperl-word-at-point-hard ()
7530 ;; Does not save-excursion
7531 ;; Get to the something meaningful
7532 (or (eobp) (eolp) (forward-char 1))
7533 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
7534 (save-excursion (beginning-of-line) (point))
7537 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
7538 ;; (skip-chars-backward " \n\t\r({[]});,")
7539 ;; (or (bobp) (backward-char 1))))
7542 ((looking-at "[a-zA-Z0-9_:]") ; symbol
7543 (skip-chars-backward "a-zA-Z0-9_:")
7545 ((and (eq (preceding-char) ?^) ; $^I
7546 (eq (char-after (- (point) 2)) ?\$))
7548 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
7550 ((and (eq (preceding-char) ?\=)
7551 (eq (current-column) 1))
7552 (forward-char -1))) ; =head1
7553 (if (and (eq (preceding-char) ?\<)
7554 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
7556 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
7558 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
7560 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
7561 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
7563 ((and (eq (preceding-char) ?\$)
7564 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
7566 ((and (eq (following-char) ?\>)
7567 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
7570 (and (eq (preceding-char) ?\<)
7571 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
7572 (search-backward "<"))))
7573 ((and (eq (following-char) ?\$)
7574 (eq (preceding-char) ?\<)
7575 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
7577 (if (looking-at cperl-have-help-regexp)
7578 (buffer-substring (match-beginning 0) (match-end 0))))
7580 (defun cperl-get-help ()
7581 "Get one-line docs on the symbol at the point.
7582 The data for these docs is a little bit obsolete and may be in fact longer
7583 than a line. Your contribution to update/shorten it is appreciated."
7585 (save-match-data ; May be called "inside" query-replace
7587 (let ((word (cperl-word-at-point-hard)))
7589 (if (and cperl-help-from-timer ; Bail out if not in mainland
7590 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
7591 (or (memq (get-text-property (point) 'face)
7592 '(font-lock-comment-face font-lock-string-face))
7593 (memq (get-text-property (point) 'syntax-type)
7594 '(pod here-doc format))))
7596 (cperl-describe-perl-symbol word))
7597 (if cperl-message-on-help-error
7598 (message "Nothing found for %s..."
7599 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
7601 ;;; Stolen from perl-descr.el by Johan Vromans:
7603 (defvar cperl-doc-buffer " *perl-doc*"
7604 "Where the documentation can be found.")
7606 (defun cperl-describe-perl-symbol (val)
7607 "Display the documentation of symbol at point, a Perl operator."
7608 (let ((enable-recursive-minibuffers t)
7611 ((string-match "^[&*][a-zA-Z_]" val)
7612 (setq val (concat (substring val 0 1) "NAME")))
7613 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
7614 (setq val (concat "@" (substring val 1 (match-end 1)))))
7615 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
7616 (setq val (concat "%" (substring val 1 (match-end 1)))))
7617 ((and (string= val "x") (string-match "^x=" val))
7619 ((string-match "^\\$[\C-a-\C-z]" val)
7620 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
7621 ((string-match "^CORE::" val)
7622 (setq val "CORE::"))
7623 ((string-match "^SUPER::" val)
7624 (setq val "SUPER::"))
7625 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
7626 (setq val "<NAME>")))
7627 (setq regexp (concat "^"
7628 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
7630 "\\([ \t([/]\\|$\\)"))
7632 ;; get the buffer with the documentation text
7633 (cperl-switch-to-doc-buffer)
7635 ;; lookup in the doc
7636 (goto-char (point-min))
7637 (let ((case-fold-search nil))
7639 (if (re-search-forward regexp (point-max) t)
7641 (beginning-of-line 1)
7642 (let ((lnstart (point)))
7644 (message "%s" (buffer-substring lnstart (point)))))
7645 (if cperl-message-on-help-error
7646 (message "No definition for %s" val)))))))
7648 (defvar cperl-short-docs 'please-ignore-this-line
7649 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
7650 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
7651 ... Range (list context); flip/flop [no flop when flip] (scalar context).
7652 ! ... Logical negation.
7653 ... != ... Numeric inequality.
7654 ... !~ ... Search pattern, substitution, or translation (negated).
7655 $! In numeric context: errno. In a string context: error string.
7656 $\" The separator which joins elements of arrays interpolated in strings.
7657 $# The output format for printed numbers. Default is %.15g or close.
7658 $$ Process number of this script. Changes in the fork()ed child process.
7659 $% The current page number of the currently selected output channel.
7661 The following variables are always local to the current block:
7663 $1 Match of the 1st set of parentheses in the last match (auto-local).
7664 $2 Match of the 2nd set of parentheses in the last match (auto-local).
7665 $3 Match of the 3rd set of parentheses in the last match (auto-local).
7666 $4 Match of the 4th set of parentheses in the last match (auto-local).
7667 $5 Match of the 5th set of parentheses in the last match (auto-local).
7668 $6 Match of the 6th set of parentheses in the last match (auto-local).
7669 $7 Match of the 7th set of parentheses in the last match (auto-local).
7670 $8 Match of the 8th set of parentheses in the last match (auto-local).
7671 $9 Match of the 9th set of parentheses in the last match (auto-local).
7672 $& The string matched by the last pattern match (auto-local).
7673 $' The string after what was matched by the last match (auto-local).
7674 $` The string before what was matched by the last match (auto-local).
7676 $( The real gid of this process.
7677 $) The effective gid of this process.
7678 $* Deprecated: Set to 1 to do multiline matching within a string.
7679 $+ The last bracket matched by the last search pattern.
7680 $, The output field separator for the print operator.
7681 $- The number of lines left on the page.
7682 $. The current input line number of the last filehandle that was read.
7683 $/ The input record separator, newline by default.
7684 $0 Name of the file containing the current perl script (read/write).
7685 $: String may be broken after these characters to fill ^-lines in a format.
7686 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
7687 $< The real uid of this process.
7688 $= The page length of the current output channel. Default is 60 lines.
7689 $> The effective uid of this process.
7690 $? The status returned by the last ``, pipe close or `system'.
7691 $@ The perl error message from the last eval or do @var{EXPR} command.
7692 $ARGV The name of the current file used with <> .
7693 $[ Deprecated: The index of the first element/char in an array/string.
7694 $\\ The output record separator for the print operator.
7695 $] The perl version string as displayed with perl -v.
7696 $^ The name of the current top-of-page format.
7697 $^A The current value of the write() accumulator for format() lines.
7698 $^D The value of the perl debug (-D) flags.
7699 $^E Information about the last system error other than that provided by $!.
7700 $^F The highest system file descriptor, ordinarily 2.
7701 $^H The current set of syntax checks enabled by `use strict'.
7702 $^I The value of the in-place edit extension (perl -i option).
7703 $^L What formats output to perform a formfeed. Default is \\f.
7704 $^M A buffer for emergency memory allocation when running out of memory.
7705 $^O The operating system name under which this copy of Perl was built.
7706 $^P Internal debugging flag.
7707 $^T The time the script was started. Used by -A/-M/-C file tests.
7708 $^W True if warnings are requested (perl -w flag).
7709 $^X The name under which perl was invoked (argv[0] in C-speech).
7710 $_ The default input and pattern-searching space.
7711 $| Auto-flush after write/print on current output channel? Default 0.
7712 $~ The name of the current report format.
7713 ... % ... Modulo division.
7714 ... %= ... Modulo division assignment.
7715 %ENV Contains the current environment.
7716 %INC List of files that have been require-d or do-ne.
7717 %SIG Used to set signal handlers for various signals.
7718 ... & ... Bitwise and.
7719 ... && ... Logical and.
7720 ... &&= ... Logical and assignment.
7721 ... &= ... Bitwise and assignment.
7722 ... * ... Multiplication.
7723 ... ** ... Exponentiation.
7724 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
7725 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
7726 ... + ... Addition. +EXPR Makes EXPR into scalar context.
7727 ++ Auto-increment (magical on strings). ++EXPR EXPR++
7728 ... += ... Addition assignment.
7730 ... - ... Subtraction.
7731 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
7732 ... -= ... Subtraction assignment.
7733 -A Access time in days since script started.
7734 -B File is a non-text (binary) file.
7735 -C Inode change time in days since script started.
7736 -M Age in days since script started.
7737 -O File is owned by real uid.
7738 -R File is readable by real uid.
7739 -S File is a socket .
7740 -T File is a text file.
7741 -W File is writable by real uid.
7742 -X File is executable by real uid.
7743 -b File is a block special file.
7744 -c File is a character special file.
7745 -d File is a directory.
7747 -f File is a plain file.
7748 -g File has setgid bit set.
7749 -k File has sticky bit set.
7750 -l File is a symbolic link.
7751 -o File is owned by effective uid.
7752 -p File is a named pipe (FIFO).
7753 -r File is readable by effective uid.
7754 -s File has non-zero size.
7755 -t Tests if filehandle (STDIN by default) is opened to a tty.
7756 -u File has setuid bit set.
7757 -w File is writable by effective uid.
7758 -x File is executable by effective uid.
7759 -z File has zero size.
7760 . Concatenate strings.
7761 .. Range (list context); flip/flop (scalar context) operator.
7762 .= Concatenate assignment strings
7763 ... / ... Division. /PATTERN/ioxsmg Pattern match
7764 ... /= ... Division assignment.
7765 /PATTERN/ioxsmg Pattern match.
7766 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
7767 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
7768 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
7769 <> Reads line from union of files in @ARGV (= command line) and STDIN.
7770 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
7771 ... <= ... Numeric less than or equal to.
7772 ... <=> ... Numeric compare.
7773 ... = ... Assignment.
7774 ... == ... Numeric equality.
7775 ... =~ ... Search pattern, substitution, or translation
7776 ... > ... Numeric greater than.
7777 ... >= ... Numeric greater than or equal to.
7778 ... >> ... Bitwise shift right.
7779 ... >>= ... Bitwise shift right assignment.
7780 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
7781 ?PATTERN? One-time pattern match.
7782 @ARGV Command line arguments (not including the command name - see $0).
7783 @INC List of places to look for perl scripts during do/include/use.
7784 @_ Parameter array for subroutines; result of split() unless in list context.
7785 \\ Creates reference to what follows, like \\$var, or quotes non-\\w in strings.
7786 \\0 Octal char, e.g. \\033.
7787 \\E Case modification terminator. See \\Q, \\L, and \\U.
7788 \\L Lowercase until \\E . See also \\l, lc.
7789 \\U Upcase until \\E . See also \\u, uc.
7790 \\Q Quote metacharacters until \\E . See also quotemeta.
7791 \\a Alarm character (octal 007).
7792 \\b Backspace character (octal 010).
7793 \\c Control character, e.g. \\c[ .
7794 \\e Escape character (octal 033).
7795 \\f Formfeed character (octal 014).
7796 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
7797 \\n Newline character (octal 012 on most systems).
7798 \\r Return character (octal 015 on most systems).
7799 \\t Tab character (octal 011).
7800 \\u Upcase the next character. See also \\U and \\l, ucfirst.
7801 \\x Hex character, e.g. \\x1b.
7802 ... ^ ... Bitwise exclusive or.
7803 __END__ Ends program source.
7804 __DATA__ Ends program source.
7805 __FILE__ Current (source) filename.
7806 __LINE__ Current line in current source.
7807 __PACKAGE__ Current package.
7808 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
7809 ARGVOUT Output filehandle with -i flag.
7810 BEGIN { ... } Immediately executed (during compilation) piece of code.
7811 END { ... } Pseudo-subroutine executed after the script finishes.
7812 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
7813 INIT { ... } Pseudo-subroutine executed before the script starts running.
7814 DATA Input filehandle for what follows after __END__ or __DATA__.
7815 accept(NEWSOCKET,GENERICSOCKET)
7828 ... cmp ... String compare.
7829 connect(SOCKET,NAME)
7830 continue of { block } continue { block }. Is executed after `next' or at end.
7832 crypt(PLAINTEXT,SALT)
7834 dbmopen(%HASH,DBNAME,MODE)
7838 do { ... }|SUBR while|until EXPR executes at least once
7839 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
7849 ... eq ... String equality.
7850 eval(EXPR) or eval { BLOCK }
7851 exec([TRUENAME] ARGV0, ARGVs) or exec(SHELL_COMMAND_LINE)
7854 fcntl(FILEHANDLE,FUNCTION,SCALAR)
7856 flock(FILEHANDLE,OPERATION)
7857 for (EXPR;EXPR;EXPR) { ... }
7858 foreach [VAR] (@ARRAY) { ... }
7860 ... ge ... String greater than or equal.
7865 gethostbyaddr(ADDR,ADDRTYPE)
7869 getnetbyaddr(ADDR,ADDRTYPE)
7875 getpriority(WHICH,WHO)
7876 getprotobyname(NAME)
7877 getprotobynumber(NUMBER)
7882 getservbyname(NAME,PROTO)
7883 getservbyport(PORT,PROTO)
7886 getsockopt(SOCKET,LEVEL,OPTNAME)
7889 ... gt ... String greater than.
7891 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
7892 index(STR,SUBSTR[,OFFSET])
7894 ioctl(FILEHANDLE,FUNCTION,SCALAR)
7899 ... le ... String less than or equal.
7901 link(OLDFILE,NEWFILE)
7902 listen(SOCKET,QUEUESIZE)
7906 lstat(EXPR|FILEHANDLE|VAR)
7907 ... lt ... String less than.
7909 mkdir(FILENAME,MODE)
7912 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
7913 msgsnd(ID,MSG,FLAGS)
7914 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
7915 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
7916 ... ne ... String inequality.
7919 open(FILEHANDLE[,EXPR])
7920 opendir(DIRHANDLE,EXPR)
7921 ord(EXPR) ASCII value of the first char of the string.
7923 package NAME Introduces package context.
7924 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
7926 print [FILEHANDLE] [(LIST)]
7927 printf [FILEHANDLE] (FORMAT,LIST)
7929 q/STRING/ Synonym for 'STRING'
7930 qq/STRING/ Synonym for \"STRING\"
7931 qx/STRING/ Synonym for `STRING`
7933 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7936 recv(SOCKET,SCALAR,LEN,FLAGS)
7938 rename(OLDNAME,NEWNAME)
7939 require [FILENAME | PERL_VERSION]
7943 rewinddir(DIRHANDLE)
7944 rindex(STR,SUBSTR[,OFFSET])
7946 s/PATTERN/REPLACEMENT/gieoxsm
7948 seek(FILEHANDLE,POSITION,WHENCE)
7949 seekdir(DIRHANDLE,POS)
7950 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
7951 semctl(ID,SEMNUM,CMD,ARG)
7952 semget(KEY,NSEMS,SIZE,FLAGS)
7954 send(SOCKET,MSG,FLAGS[,TO])
7956 sethostent(STAYOPEN)
7959 setpriority(WHICH,WHO,PRIORITY)
7960 setprotoent(STAYOPEN)
7962 setservent(STAYOPEN)
7963 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
7966 shmget(KEY,SIZE,FLAGS)
7967 shmread(ID,VAR,POS,SIZE)
7968 shmwrite(ID,STRING,POS,SIZE)
7969 shutdown(SOCKET,HOW)
7972 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
7973 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
7974 sort [SUBROUTINE] (LIST)
7975 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
7976 split[(/PATTERN/[,EXPR[,LIMIT]])]
7977 sprintf(FORMAT,LIST)
7980 stat(EXPR|FILEHANDLE|VAR)
7982 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
7983 substr(EXPR,OFFSET[,LEN])
7984 symlink(OLDFILE,NEWFILE)
7986 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7987 system([TRUENAME] ARGV0 [,ARGV]) or system(SHELL_COMMAND_LINE)
7988 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7993 tr/SEARCHLIST/REPLACEMENTLIST/cds
7994 truncate(FILE|EXPR,LENGTH)
7997 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
7999 unpack(TEMPLATE,EXPR)
8001 until (EXPR) { ... } EXPR until EXPR
8004 vec(EXPR,OFFSET,BITS)
8007 wantarray Returns true if the sub/eval is called in list context.
8009 while (EXPR) { ... } EXPR while EXPR
8010 write[(EXPR|FILEHANDLE)]
8011 ... x ... Repeat string or array.
8012 x= ... Repetition assignment.
8013 y/SEARCHLIST/REPLACEMENTLIST/
8014 ... | ... Bitwise or.
8015 ... || ... Logical or.
8016 ~ ... Unary bitwise complement.
8017 #! OS interpreter indicator. If contains `perl', used for options, and -x.
8018 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
8019 CORE:: Prefix to access builtin function if imported sub obscures it.
8020 SUPER:: Prefix to lookup for a method in @ISA classes.
8021 DESTROY Shorthand for `sub DESTROY {...}'.
8022 ... EQ ... Obsolete synonym of `eq'.
8023 ... GE ... Obsolete synonym of `ge'.
8024 ... GT ... Obsolete synonym of `gt'.
8025 ... LE ... Obsolete synonym of `le'.
8026 ... LT ... Obsolete synonym of `lt'.
8027 ... NE ... Obsolete synonym of `ne'.
8028 abs [ EXPR ] absolute value
8029 ... and ... Low-precedence synonym for &&.
8030 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
8031 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
8032 chr Converts a number to char with the same ordinal.
8033 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
8034 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
8035 exists $HASH{KEY} True if the key exists.
8036 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
8037 formline PICTURE, LIST Backdoor into \"format\" processing.
8038 glob EXPR Synonym of <EXPR>.
8039 lc [ EXPR ] Returns lowercased EXPR.
8040 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
8041 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
8042 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
8043 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
8044 not ... Low-precedence synonym for ! - negation.
8045 ... or ... Low-precedence synonym for ||.
8046 pos STRING Set/Get end-position of the last match over this string, see \\G.
8047 quotemeta [ EXPR ] Quote regexp metacharacters.
8048 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
8049 readline FH Synonym of <FH>.
8050 readpipe CMD Synonym of `CMD`.
8051 ref [ EXPR ] Type of EXPR when dereferenced.
8052 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
8053 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
8054 tied Returns internal object for a tied data.
8055 uc [ EXPR ] Returns upcased EXPR.
8056 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
8057 untie VAR Unlink an object from a simple Perl variable.
8058 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
8059 ... xor ... Low-precedence synonym for exclusive or.
8060 prototype \\&SUB Returns prototype of the function given a reference.
8061 =head1 Top-level heading.
8062 =head2 Second-level heading.
8063 =head3 Third-level heading (is there such?).
8064 =over [ NUMBER ] Start list.
8065 =item [ TITLE ] Start new item in the list.
8067 =cut Switch from POD to Perl.
8068 =pod Switch from Perl to POD.
8071 (defun cperl-switch-to-doc-buffer (&optional interactive)
8072 "Go to the perl documentation buffer and insert the documentation."
8074 (let ((buf (get-buffer-create cperl-doc-buffer)))
8076 (switch-to-buffer-other-window buf)
8078 (if (= (buffer-size) 0)
8080 (insert (documentation-property 'cperl-short-docs
8081 'variable-documentation))
8082 (setq buffer-read-only t)))))
8084 (defun cperl-beautify-regexp-piece (b e embed level)
8085 ;; b is before the starting delimiter, e before the ending
8086 ;; e should be a marker, may be changed, but remains "correct".
8087 ;; EMBED is nil iff we process the whole REx.
8088 ;; The REx is guaranteed to have //x
8089 ;; LEVEL shows how many levels deep to go
8090 ;; position at enter and at leave is not defined
8091 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
8095 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
8099 ((looking-at "(\\?[^a-zA-Z]")
8101 ((looking-at "(\\?") ; (?i)
8105 (setq c (if embed (current-indentation) (1- (current-column)))
8106 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
8107 (or (looking-at "[ \t]*[\n#]")
8112 (if (re-search-forward "[^ \t]" e t)
8113 (progn ; Something before the ending delimiter
8115 (delete-horizontal-space)
8117 (cperl-make-indent c)
8118 (set-marker e (point))))
8121 (while (< (point) (marker-position e))
8125 (skip-chars-forward " \t")
8126 (delete-region s (point))
8127 (cperl-make-indent c1)
8131 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
8132 "\\|" ; Embedded variable
8133 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
8136 "\\|" ; simple-code simple-code*?
8137 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
8141 "\\((\\(\\?\\)?\\)" ; 7 8
8144 (goto-char (match-end 0))
8146 (cond ((match-beginning 1) ; Alphanum word + junk
8148 ((or (match-beginning 3) ; $ab[12]
8149 (and (match-beginning 5) ; X* X+ X{2,3}
8150 (eq (preceding-char) ?\{)))
8153 ((and ; [], already syntaxified
8156 cperl-use-syntax-table-text-property)
8159 (or (eq (preceding-char) ?\])
8160 (error "[]-group not terminated"))
8162 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8163 ((match-beginning 6) ; []
8165 (if (looking-at "\\^?\\]")
8166 (goto-char (match-end 0)))
8167 ;; XXXX POSIX classes?!
8168 (while (and (not pos)
8169 (re-search-forward "\\[:\\|\\]" e t))
8170 (if (eq (preceding-char) ?:)
8171 (or (re-search-forward ":\\]" e t)
8172 (error "[:POSIX:]-group in []-group not terminated"))
8174 (or (eq (preceding-char) ?\])
8175 (error "[]-group not terminated"))
8177 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8178 ((match-beginning 7) ; ()
8179 (goto-char (match-beginning 0))
8180 (setq pos (current-column))
8183 (delete-horizontal-space)
8185 (cperl-make-indent c1)))
8188 ;; (or (forward-sexp 1)
8191 ;; (error "()-group not terminated")))
8192 (set-marker m (1- (point)))
8193 (set-marker m1 (point))
8195 (if (progn ; indent rigidly if multiline
8196 ;; In fact does not make a lot of sense, since
8197 ;; the starting position can be already lost due
8198 ;; to insertion of "\n" and " "
8200 (search-forward "\n" m1 t))
8201 (indent-rigidly (point) m1 (- c1 pos)))
8202 (setq level (1- level))
8204 ((not (match-beginning 8))
8205 (cperl-beautify-regexp-piece tmp m t level))
8206 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
8208 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
8209 (goto-char (+ 2 tmp))
8211 (cperl-beautify-regexp-piece (point) m t level))
8212 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
8213 (goto-char (+ 3 tmp))
8214 (cperl-beautify-regexp-piece (point) m t level))
8216 (cperl-beautify-regexp-piece tmp m t level))))
8218 (cond ((looking-at "[*+?]\\??")
8219 (goto-char (match-end 0)))
8220 ((eq (following-char) ?\{)
8222 (if (eq (following-char) ?\?)
8224 (skip-chars-forward " \t")
8226 (if (looking-at "[#\n]")
8228 (or (eolp) (indent-for-comment))
8229 (beginning-of-line 2))
8230 (delete-horizontal-space)
8234 ((match-beginning 9) ; |
8238 (if (re-search-forward "[^ \t]" tmp t)
8241 (delete-horizontal-space)
8244 (delete-region (point) tmp))
8245 (cperl-make-indent c)
8247 (skip-chars-forward " \t")
8249 (if (looking-at "[#\n]")
8250 (beginning-of-line 2)
8251 (delete-horizontal-space)
8255 (or (looking-at "[ \t\n]")
8258 (skip-chars-forward " \t"))
8259 (or (looking-at "[#\n]")
8260 (error "Unknown code `%s' in a regexp"
8261 (buffer-substring (point) (1+ (point)))))
8262 (and inline (end-of-line 2)))
8263 ;; Special-case the last line of group
8264 (if (and (>= (point) (marker-position e))
8265 (/= (current-indentation) c))
8268 (cperl-make-indent c)))))
8270 (defun cperl-make-regexp-x ()
8271 ;; Returns position of the start
8272 ;; XXX this is called too often! Need to cache the result!
8274 (or cperl-use-syntax-table-text-property
8275 (error "I need to have a regexp marked!"))
8277 (if (looking-at "\\s|")
8279 (if (looking-at "\\([smy]\\|qr\\)\\s|")
8281 (re-search-backward "\\s|"))) ; Assume it is scanned already.
8283 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
8284 (sub-p (eq (preceding-char) ?s)) s)
8286 (set-marker e (1- (point)))
8287 (setq delim (preceding-char))
8288 (if (and sub-p (eq delim (char-after (- (point) 2))))
8289 (error "Possible s/blah// - do not know how to deal with"))
8290 (if sub-p (forward-sexp 1))
8291 (if (looking-at "\\sw*x")
8294 ;; Protect fragile " ", "#"
8297 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
8303 (defun cperl-beautify-regexp (&optional deep)
8304 "Do it. (Experimental, may change semantics, recheck the result.)
8305 We suppose that the regexp is scanned already."
8307 (setq deep (if deep (prefix-numeric-value deep) -1))
8309 (goto-char (cperl-make-regexp-x))
8310 (let ((b (point)) (e (make-marker)))
8312 (set-marker e (1- (point)))
8313 (cperl-beautify-regexp-piece b e nil deep))))
8315 (defun cperl-regext-to-level-start ()
8316 "Goto start of an enclosing group in regexp.
8317 We suppose that the regexp is scanned already."
8319 (let ((limit (cperl-make-regexp-x)) done)
8321 (or (eq (following-char) ?\()
8322 (search-backward "(" (1+ limit) t)
8323 (error "Cannot find `(' which starts a group"))
8326 (skip-chars-backward "\\")
8327 (looking-at "\\(\\\\\\\\\\)*(")))
8328 (or done (forward-char -1)))))
8330 (defun cperl-contract-level ()
8331 "Find an enclosing group in regexp and contract it.
8332 \(Experimental, may change semantics, recheck the result.)
8333 We suppose that the regexp is scanned already."
8335 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
8336 (cperl-regext-to-level-start)
8337 (let ((b (point)) (e (make-marker)) c)
8339 (set-marker e (1- (point)))
8341 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
8343 ((match-beginning 1) ; #-comment
8344 (or c (setq c (current-indentation)))
8345 (beginning-of-line 2) ; Skip
8346 (cperl-make-indent c))
8349 (just-one-space))))))
8351 (defun cperl-contract-levels ()
8352 "Find an enclosing group in regexp and contract all the kids.
8353 \(Experimental, may change semantics, recheck the result.)
8354 We suppose that the regexp is scanned already."
8358 (cperl-regext-to-level-start)
8359 (error ; We are outside outermost group
8360 (goto-char (cperl-make-regexp-x))))
8361 (let ((b (point)) (e (make-marker)) s c)
8363 (set-marker e (1- (point)))
8365 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
8367 ((match-beginning 1) ; Skip
8370 (cperl-contract-level)))))))
8372 (defun cperl-beautify-level (&optional deep)
8373 "Find an enclosing group in regexp and beautify it.
8374 \(Experimental, may change semantics, recheck the result.)
8375 We suppose that the regexp is scanned already."
8377 (setq deep (if deep (prefix-numeric-value deep) -1))
8379 (cperl-regext-to-level-start)
8380 (let ((b (point)) (e (make-marker)))
8382 (set-marker e (1- (point)))
8383 (cperl-beautify-regexp-piece b e nil deep))))
8385 (defun cperl-invert-if-unless-modifiers ()
8386 "Change `B if A;' into `if (A) {B}' etc if possible.
8389 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string
8390 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>"))
8391 (and (= (char-syntax (preceding-char)) ?w)
8393 (setq pre-if (point))
8394 (cperl-backward-to-start-of-expr)
8395 (setq pre-B (point))
8396 (forward-sexp 1) ; otherwise forward-to-end-of-expr is NOP
8397 (cperl-forward-to-end-of-expr)
8398 (setq post-A (point))
8400 (or (looking-at w-rex)
8401 ;; Find the position
8402 (progn (goto-char post-A)
8404 (not (looking-at w-rex))
8407 (setq pre-if (point))))
8408 (or (looking-at w-rex)
8409 (error "Can't find `if', `unless', `while', `until', `for' or `foreach'"))
8410 ;; 1 B 2 ... 3 B-com ... 4 if 5 ... if-com 6 ... 7 A 8
8411 (setq if-string (buffer-substring (match-beginning 0) (match-end 0)))
8412 ;; First, simple part: find code boundaries
8414 (setq post-if (point))
8417 (setq post-B (point))
8418 (cperl-backward-to-start-of-expr)
8419 (setq pre-B (point))
8420 (setq B (buffer-substring pre-B post-B))
8424 ;; May be after $, @, $# etc of a variable
8425 (skip-chars-backward "$@%#")
8426 (setq pre-A (point))
8427 (cperl-forward-to-end-of-expr)
8428 (setq post-A (point))
8429 (setq A (buffer-substring pre-A post-A))
8430 ;; Now modify (from end, to not break the stuff)
8431 (skip-chars-forward " \t;")
8432 (delete-region pre-A (point)) ; we move to pre-A
8433 (insert "\n" B ";\n}")
8434 (and (looking-at "[ \t]*#") (cperl-indent-for-comment))
8435 (delete-region pre-if post-if)
8436 (delete-region pre-B post-B)
8438 (insert if-string " (" A ") {")
8439 (setq post-B (point))
8440 (if (looking-at "[ \t]+$")
8441 (delete-horizontal-space)
8442 (if (looking-at "[ \t]*#")
8443 (cperl-indent-for-comment)
8446 (if (looking-at "[ \t]*$")
8447 (progn ; delete line
8448 (delete-horizontal-space)
8449 (delete-region (point) (1+ (point)))))
8451 (goto-char (1- post-B))
8456 (defun cperl-invert-if-unless ()
8457 "Change `if (A) {B}' into `B if A;' etc (or visa versa) if possible.
8458 If the cursor is not on the leading keyword of the BLOCK flavor of
8459 construct, will assume it is the STATEMENT flavor, so will try to find
8460 the appropriate statement modifier."
8462 (and (= (char-syntax (preceding-char)) ?w)
8464 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
8465 (let ((pre-if (point))
8466 pre-A post-A pre-B post-B A B state p end-B-code is-block B-comment
8467 (if-string (buffer-substring (match-beginning 0) (match-end 0))))
8469 (setq post-A (point))
8471 (setq pre-A (point))
8472 (setq is-block (and (eq (following-char) ?\( )
8478 (eq (following-char) ?\{ ))
8484 (setq post-B (point))
8486 (setq pre-B (point))
8487 (if (and (eq (following-char) ?\{ )
8489 (cperl-backward-to-noncomment post-A)
8490 (eq (preceding-char) ?\) )))
8491 (if (condition-case nil
8496 (looking-at "\\<els\\(e\\|if\\)\\>"))
8499 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" if-string)
8500 (goto-char (1- post-B))
8501 (cperl-backward-to-noncomment pre-B)
8502 (if (eq (preceding-char) ?\;)
8504 (setq end-B-code (point))
8506 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" end-B-code t)
8507 (setq p (match-beginning 0)
8508 A (buffer-substring p (match-end 0))
8509 state (parse-partial-sexp pre-B p))
8513 (error "`%s' inside `%s' BLOCK" A if-string))
8514 (goto-char (match-end 0)))
8516 (goto-char (1+ pre-B))
8517 (skip-chars-forward " \t\n")
8518 (setq B (buffer-substring (point) end-B-code))
8519 (goto-char end-B-code)
8520 (or (looking-at ";?[ \t\n]*}")
8522 (skip-chars-forward "; \t\n")
8524 (buffer-substring (point) (1- post-B)))))
8527 (goto-char (1- post-A))
8528 (cperl-backward-to-noncomment pre-A)
8529 (or (looking-at "[ \t\n]*)")
8530 (goto-char (1- post-A)))
8532 (goto-char (1+ pre-A))
8533 (skip-chars-forward " \t\n")
8534 (setq A (buffer-substring (point) p))
8535 (delete-region pre-B post-B)
8536 (delete-region pre-A post-A)
8539 (and B-comment (insert B-comment " "))
8542 (setq pre-A (point))
8544 (delete-horizontal-space)
8545 (setq post-B (point))
8546 (if (looking-at "#")
8547 (indent-for-comment))
8550 (delete-horizontal-space)
8554 (setq pre-A (set-marker (make-marker) pre-A))
8555 (while (<= (point) (marker-position pre-A))
8558 (goto-char (marker-position pre-A))
8562 (indent-for-comment)
8563 (goto-char (marker-position pre-A)))))
8564 (error "`%s' (EXPR) not with an {BLOCK}" if-string)))
8565 ;; (error "`%s' not with an (EXPR)" if-string)
8567 (cperl-invert-if-unless-modifiers)))
8568 ;;(error "Not at `if', `unless', `while', `until', `for' or `foreach'")
8569 (cperl-invert-if-unless-modifiers)))
8571 ;;; By Anthony Foiani <afoiani@uswest.com>
8572 ;;; Getting help on modules in C-h f ?
8573 ;;; This is a modified version of `man'.
8574 ;;; Need to teach it how to lookup functions
8576 (defun cperl-perldoc (word)
8577 "Run `perldoc' on WORD."
8579 (list (let* ((default-entry (cperl-word-at-point))
8581 (format "perldoc entry%s: "
8582 (if (string= default-entry "")
8584 (format " (default %s)" default-entry))))))
8585 (if (string= input "")
8586 (if (string= default-entry "")
8587 (error "No perldoc args given")
8591 (let* ((case-fold-search nil)
8593 (string-match "^[a-z]+$" word)
8594 (string-match (concat "^" word "\\>")
8595 (documentation-property
8597 'variable-documentation))))
8598 (manual-program (if is-func "perldoc -f" "perldoc")))
8601 (let ((Manual-program "perldoc")
8602 (Manual-switches (if is-func (list "-f"))))
8603 (manual-entry word)))
8605 (Man-getpage-in-background word)))))
8608 (defun cperl-perldoc-at-point ()
8609 "Run a `perldoc' on the word around point."
8611 (cperl-perldoc (cperl-word-at-point)))
8613 (defcustom pod2man-program "pod2man"
8614 "*File name for `pod2man'."
8618 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
8619 (defun cperl-pod-to-manpage ()
8620 "Create a virtual manpage in Emacs from the Perl Online Documentation."
8623 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
8624 (bufname (concat "Man " buffer-file-name))
8625 (buffer (generate-new-buffer bufname)))
8628 (let ((process-environment (copy-sequence process-environment)))
8629 ;; Prevent any attempt to use display terminal fanciness.
8630 (setenv "TERM" "dumb")
8631 (set-process-sentinel
8632 (start-process pod2man-program buffer "sh" "-c"
8633 (format (cperl-pod2man-build-command) pod2man-args))
8634 'Man-bgproc-sentinel)))))
8636 ;;; Updated version by him too
8637 (defun cperl-build-manpage ()
8638 "Create a virtual manpage in Emacs from the POD in the file."
8643 (let ((Manual-program "perldoc"))
8644 (manual-entry buffer-file-name)))
8646 (let* ((manual-program "perldoc"))
8647 (Man-getpage-in-background buffer-file-name)))))
8649 (defun cperl-pod2man-build-command ()
8650 "Builds the entire background manpage and cleaning command."
8651 (let ((command (concat pod2man-program " %s 2>/dev/null"))
8652 (flist (and (boundp 'Man-filter-list) Man-filter-list)))
8653 (while (and flist (car flist))
8654 (let ((pcom (car (car flist)))
8655 (pargs (cdr (car flist))))
8657 (concat command " | " pcom " "
8658 (mapconcat '(lambda (phrase)
8659 (if (not (stringp phrase))
8660 (error "Malformed Man-filter-list"))
8663 (setq flist (cdr flist))))
8667 (defun cperl-next-interpolated-REx-1 ()
8668 "Move point to next REx which has interpolated parts without //o.
8669 Skips RExes consisting of one interpolated variable.
8671 Note that skipped RExen are not performance hits."
8673 (cperl-next-interpolated-REx 1))
8675 (defun cperl-next-interpolated-REx-0 ()
8676 "Move point to next REx which has interpolated parts without //o."
8678 (cperl-next-interpolated-REx 0))
8680 (defun cperl-next-interpolated-REx (&optional skip beg limit)
8681 "Move point to next REx which has interpolated parts.
8682 SKIP is a list of possible types to skip, BEG and LIMIT are the starting
8683 point and the limit of search (default to point and end of buffer).
8685 SKIP may be a number, then it behaves as list of numbers up to SKIP; this
8686 semantic may be used as a numeric argument.
8688 Types are 0 for / $rex /o (interpolated once), 1 for /$rex/ (if $rex is
8689 a result of qr//, this is not a performance hit), t for the rest."
8691 (if (numberp skip) (setq skip (list 0 skip)))
8692 (or beg (setq beg (point)))
8693 (or limit (setq limit (point-max))) ; needed for n-s-p-c
8695 (and (eq (get-text-property beg 'syntax-type) 'string)
8696 (setq beg (next-single-property-change beg 'syntax-type nil limit)))
8697 (cperl-map-pods-heres
8698 (function (lambda (s e p)
8699 (if (memq (get-text-property s 'REx-interpolated) skip)
8703 'REx-interpolated beg limit)
8704 (if pp (goto-char pp)
8705 (message "No more interpolated REx"))))
8707 ;;; Initial version contributed by Trey Belew
8708 (defun cperl-here-doc-spell (&optional beg end)
8709 "Spell-check HERE-documents in the Perl buffer.
8710 If a region is highlighted, restricts to the region."
8712 (cperl-pod-spell t beg end))
8714 (defun cperl-pod-spell (&optional do-heres beg end)
8715 "Spell-check POD documentation.
8716 If invoked with prefix argument, will do HERE-DOCs instead.
8717 If a region is highlighted, restricts to the region."
8721 (if (cperl-mark-active)
8722 (setq beg (min (mark) (point))
8723 end (max (mark) (point)))
8724 (setq beg (point-min)
8726 (cperl-map-pods-heres (function
8729 (setq e (save-excursion
8735 (if do-heres 'here-doc-group 'in-pod)
8738 (defun cperl-map-pods-heres (func &optional prop s end)
8739 "Executes a function over regions of pods or here-documents.
8740 PROP is the text-property to search for; default to `in-pod'. Stop when
8741 function returns nil."
8742 (let (pos posend has-prop (cont t))
8743 (or prop (setq prop 'in-pod))
8744 (or s (setq s (point-min)))
8745 (or end (setq end (point-max)))
8746 (cperl-update-syntaxification end end)
8748 (goto-char (setq pos s))
8749 (while (and cont (< pos end))
8750 (setq has-prop (get-text-property pos prop))
8751 (setq posend (next-single-property-change pos prop nil end))
8753 (setq cont (funcall func pos posend prop)))
8754 (setq pos posend)))))
8756 ;;; Based on code by Masatake YAMATO:
8757 (defun cperl-get-here-doc-region (&optional pos pod)
8758 "Return HERE document region around the point.
8759 Return nil if the point is not in a HERE document region. If POD is non-nil,
8760 will return a POD section if point is in a POD section."
8761 (or pos (setq pos (point)))
8762 (cperl-update-syntaxification pos pos)
8763 (if (or (eq 'here-doc (get-text-property pos 'syntax-type))
8765 (eq 'pod (get-text-property pos 'syntax-type))))
8766 (let ((b (cperl-beginning-of-property pos 'syntax-type))
8767 (e (next-single-property-change pos 'syntax-type)))
8768 (cons b (or e (point-max))))))
8770 (defun cperl-narrow-to-here-doc (&optional pos)
8771 "Narrows editing region to the HERE-DOC at POS.
8772 POS defaults to the point."
8774 (or pos (setq pos (point)))
8775 (let ((p (cperl-get-here-doc-region pos)))
8776 (or p (error "Not inside a HERE document"))
8777 (narrow-to-region (car p) (cdr p))
8779 "When you are finished with narrow editing, type C-x n w")))
8781 (defun cperl-select-this-pod-or-here-doc (&optional pos)
8782 "Select the HERE-DOC (or POD section) at POS.
8783 POS defaults to the point."
8785 (let ((p (cperl-get-here-doc-region pos t)))
8789 (push-mark (cdr p) nil t)) ; Message, activate in transient-mode
8790 (message "I do not think POS is in POD or a HERE-doc..."))))
8792 (defun cperl-facemenu-add-face-function (face end)
8793 "A callback to process user-initiated font-change requests.
8794 Translates `bold', `italic', and `bold-italic' requests to insertion of
8795 corresponding POD directives, and `underline' to C<> POD directive.
8797 Such requests are usually bound to M-o LETTER."
8798 (or (get-text-property (point) 'in-pod)
8799 (error "Faces can only be set within POD"))
8800 (setq facemenu-end-add-face (if (eq face 'bold-italic) ">>" ">"))
8801 (cdr (or (assq face '((bold . "B<")
8803 (bold-italic . "B<I<")
8804 (underline . "C<")))
8805 (error "Face %s not configured for cperl-mode"
8808 (defun cperl-time-fontification (&optional l step lim)
8809 "Times how long it takes to do incremental fontification in a region.
8810 L is the line to start at, STEP is the number of lines to skip when
8811 doing next incremental fontification, LIM is the maximal number of
8812 incremental fontification to perform. Messages are accumulated in
8815 May be used for pinpointing which construct slows down buffer fontification:
8816 start with default arguments, then refine the slowdown regions."
8817 (interactive "nLine to start at: \nnStep to do incremental fontification: ")
8819 (or step (setq step 500))
8820 (or lim (setq lim 40))
8821 (let* ((timems (function (lambda ()
8822 (let ((tt (current-time)))
8823 (+ (* 1000 (nth 1 tt)) (/ (nth 2 tt) 1000))))))
8824 (tt (funcall timems)) (c 0) delta tot)
8827 (setq tot (- (- tt (setq tt (funcall timems)))))
8828 (message "cperl-mode at %s: %s" l tot)
8829 (while (and (< c lim) (not (eobp)))
8833 (cperl-update-syntaxification (point) (point))
8834 (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
8835 (message "to %s:%6s,%7s" l delta tot))
8838 (defun cperl-emulate-lazy-lock (&optional window-size)
8839 "Emulate `lazy-lock' without `condition-case', so `debug-on-error' works.
8840 Start fontifying the buffer from the start (or end) using the given
8841 WINDOW-SIZE (units is lines). Negative WINDOW-SIZE starts at end, and
8842 goes backwards; default is -50. This function is not CPerl-specific; it
8843 may be used to debug problems with delayed incremental fontification."
8845 "nSize of window for incremental fontification, negative goes backwards: ")
8846 (or window-size (setq window-size -50))
8847 (let ((pos (if (> window-size 0)
8853 ;; Why needed??? With older font-locks???
8854 (set (make-local-variable 'font-lock-cache-position) (make-marker))
8855 (while (if (> window-size 0)
8857 (> pos (point-min)))
8859 (forward-line window-size)
8861 (font-lock-fontify-region (min p pos) (max p pos))
8865 (defun cperl-lazy-install ()) ; Avoid a warning
8866 (defun cperl-lazy-unstall ()) ; Avoid a warning
8868 (if (fboundp 'run-with-idle-timer)
8870 (defvar cperl-help-shown nil
8871 "Non-nil means that the help was already shown now.")
8873 (defvar cperl-lazy-installed nil
8874 "Non-nil means that the lazy-help handlers are installed now.")
8876 (defun cperl-lazy-install ()
8877 "Switches on Auto-Help on Perl constructs (put in the message area).
8878 Delay of auto-help controlled by `cperl-lazy-help-time'."
8880 (make-local-variable 'cperl-help-shown)
8881 (if (and (cperl-val 'cperl-lazy-help-time)
8882 (not cperl-lazy-installed))
8884 (add-hook 'post-command-hook 'cperl-lazy-hook)
8885 (run-with-idle-timer
8886 (cperl-val 'cperl-lazy-help-time 1000000 5)
8888 'cperl-get-help-defer)
8889 (setq cperl-lazy-installed t))))
8891 (defun cperl-lazy-unstall ()
8892 "Switches off Auto-Help on Perl constructs (put in the message area).
8893 Delay of auto-help controlled by `cperl-lazy-help-time'."
8895 (remove-hook 'post-command-hook 'cperl-lazy-hook)
8896 (cancel-function-timers 'cperl-get-help-defer)
8897 (setq cperl-lazy-installed nil))
8899 (defun cperl-lazy-hook ()
8900 (setq cperl-help-shown nil))
8902 (defun cperl-get-help-defer ()
8903 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
8904 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
8906 (setq cperl-help-shown t))))
8907 (cperl-lazy-install)))
8910 ;;; Plug for wrong font-lock:
8912 (defun cperl-font-lock-unfontify-region-function (beg end)
8913 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
8914 (inhibit-read-only t) (inhibit-point-motion-hooks t)
8915 before-change-functions after-change-functions
8916 deactivate-mark buffer-file-name buffer-file-truename)
8917 (remove-text-properties beg end '(face nil))
8918 (if (and (not modified) (buffer-modified-p))
8919 (set-buffer-modified-p nil))))
8921 (defun cperl-font-lock-fontify-region-function (beg end loudly)
8922 "Extends the region to safe positions, then calls the default function.
8923 Newer `font-lock's can do it themselves.
8924 We unwind only as far as needed for fontification. Syntaxification may
8925 do extra unwind via `cperl-unwind-to-safe'."
8931 (eq (get-text-property (setq beg (point)) 'syntax-type)
8933 (if (setq beg (cperl-beginning-of-property beg 'syntax-type))
8939 (or (bolp) (condition-case nil
8942 (eq (get-text-property (setq end (point)) 'syntax-type)
8944 (setq end (next-single-property-change end 'syntax-type nil (point-max)))
8947 (font-lock-default-fontify-region beg end loudly))
8949 (defvar cperl-d-l nil)
8950 (defun cperl-fontify-syntaxically (end)
8951 ;; Some vars for debugging only
8952 ;; (message "Syntaxifying...")
8953 (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
8954 (istate (car cperl-syntax-state))
8955 start from-start edebug-backtrace-buffer)
8956 (if (eq cperl-syntaxify-by-font-lock 'backtrace)
8959 (let ((f 'edebug-backtrace))
8960 (funcall f)))) ; Avoid compile-time warning
8961 (or cperl-syntax-done-to
8962 (setq cperl-syntax-done-to (point-min)
8964 (setq start (if (and cperl-hook-after-change
8966 cperl-syntax-done-to ; Fontify without change; ignore start
8967 ;; Need to forget what is after `start'
8968 (min cperl-syntax-done-to (point))))
8971 (setq start (point))
8972 (and cperl-syntaxify-unwind
8973 (setq end (cperl-unwind-to-safe t end)
8976 (setq cperl-syntax-done-to start) ; In case what follows fails
8977 (cperl-find-pods-heres start end t nil t))
8978 (if (memq cperl-syntaxify-by-font-lock '(backtrace message))
8979 (message "Syxify req=%s..%s actual=%s..%s done-to: %s=>%s statepos: %s=>%s"
8980 dbg iend start end idone cperl-syntax-done-to
8981 istate (car cperl-syntax-state))) ; For debugging
8982 nil)) ; Do not iterate
8984 (defun cperl-fontify-update (end)
8985 (let ((pos (point-min)) prop posend)
8986 (setq end (point-max))
8988 (setq prop (get-text-property pos 'cperl-postpone)
8989 posend (next-single-property-change pos 'cperl-postpone nil end))
8990 (and prop (put-text-property pos posend (car prop) (cdr prop)))
8992 nil) ; Do not iterate
8994 (defun cperl-fontify-update-bad (end)
8995 ;; Since fontification happens with different region than syntaxification,
8996 ;; do to the end of buffer, not to END;;; likewise, start earlier if needed
8997 (let* ((pos (point)) (prop (get-text-property pos 'cperl-postpone)) posend)
8999 (setq pos (or (cperl-beginning-of-property
9000 (cperl-1+ pos) 'cperl-postpone)
9003 (setq posend (next-single-property-change pos 'cperl-postpone))
9004 (and prop (put-text-property pos posend (car prop) (cdr prop)))
9006 (setq prop (get-text-property pos 'cperl-postpone))))
9007 nil) ; Do not iterate
9009 ;; Called when any modification is made to buffer text.
9010 (defun cperl-after-change-function (beg end old-len)
9011 ;; We should have been informed about changes by `font-lock'. Since it
9012 ;; does not inform as which calls are defered, do it ourselves
9013 (if cperl-syntax-done-to
9014 (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
9016 (defun cperl-update-syntaxification (from to)
9017 (if (and cperl-use-syntax-table-text-property
9018 cperl-syntaxify-by-font-lock
9019 (or (null cperl-syntax-done-to)
9020 (< cperl-syntax-done-to to)))
9024 (cperl-fontify-syntaxically to)))))
9026 (defvar cperl-version
9027 (let ((v "Revision: 5.22"))
9028 (string-match ":\\s *\\([0-9.]+\\)" v)
9029 (substring v (match-beginning 1) (match-end 1)))
9030 "Version of IZ-supported CPerl package this file is based on.")
9032 (provide 'cperl-mode)
9034 ;;; arch-tag: 42e5b19b-e187-4537-929f-1a7408980ce6
9035 ;;; cperl-mode.el ends here