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, 2007, 2008, 2009
5 ;; Free Software Foundation, Inc.
7 ;; Author: Ilya Zakharevich
9 ;; Maintainer: Ilya Zakharevich <ilyaz@cpan.org>
10 ;; Keywords: languages, Perl
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;;; Corrections made by Ilya Zakharevich ilyaz@cpan.org
31 ;; You can either fine-tune the bells and whistles of this mode or
32 ;; bulk enable them by putting
34 ;; (setq cperl-hairy t)
36 ;; in your .emacs file. (Emacs rulers do not consider it politically
37 ;; correct to make whistles enabled by default.)
39 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
40 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
41 ;; `cperl-praise', `cperl-speed'. <<<<<<
43 ;; The mode information (on C-h m) provides some customization help.
44 ;; If you use font-lock feature of this mode, it is advisable to use
45 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
47 ;; Faces used now: three faces for first-class and second-class keywords
48 ;; and control flow words, one for each: comments, string, labels,
49 ;; functions definitions and packages, arrays, hashes, and variable
50 ;; definitions. If you do not see all these faces, your font-lock does
51 ;; not define them, so you need to define them manually.
53 ;; This mode supports font-lock, imenu and mode-compile. In the
54 ;; hairy version font-lock is on, but you should activate imenu
55 ;; yourself (note that mode-compile is not standard yet). Well, you
56 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
57 ;; to bind it like that:
59 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
61 ;;; Font lock bugs as of v4.32:
63 ;; The following kinds of Perl code erroneously start strings:
65 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
66 ;; likewise with m, tr, y, q, qX instead of s
70 (defvar vc-rcs-header)
71 (defvar vc-sccs-header)
80 (defvar cperl-can-font-lock
81 (or (featurep 'xemacs)
82 (and (boundp 'emacs-major-version)
84 (> emacs-major-version 20)))))
85 (if cperl-can-font-lock
87 (defvar msb-menu-cond)
88 (defvar gud-perldb-history)
89 (defvar font-lock-background-mode) ; not in Emacs
90 (defvar font-lock-display-type) ; ditto
91 (defvar paren-backwards-message) ; Not in newer XEmacs?
92 (or (fboundp 'defgroup)
93 (defmacro defgroup (name val doc &rest arr)
95 (or (fboundp 'custom-declare-variable)
96 (defmacro defcustom (name val doc &rest arr)
97 `(defvar ,name ,val ,doc)))
98 (or (and (fboundp 'custom-declare-variable)
99 (string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
100 (defmacro defface (&rest arr)
102 ;; Avoid warning (tmp definitions)
103 (or (fboundp 'x-color-defined-p)
104 (defmacro x-color-defined-p (col)
105 (cond ((fboundp 'color-defined-p) `(color-defined-p ,col))
107 ((fboundp 'valid-color-name-p) `(valid-color-name-p ,col))
109 ((fboundp 'x-valid-color-name-p) `(x-valid-color-name-p ,col))
110 (t '(error "Cannot implement color-defined-p")))))
111 (defmacro cperl-is-face (arg) ; Takes quoted arg
112 (cond ((fboundp 'find-face)
114 (;;(and (fboundp 'face-list)
117 `(member ,arg (and (fboundp 'face-list)
121 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
122 (cond ((fboundp 'make-face)
123 `(make-face (quote ,arg)))
125 `(defvar ,arg (quote ,arg) ,descr))))
126 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
128 (or (cperl-is-face (quote ,arg))
129 (cperl-make-face ,arg ,descr))
130 (or (boundp (quote ,arg)) ; We use unquoted variants too
131 (defvar ,arg (quote ,arg) ,descr))))
132 (if (featurep 'xemacs)
133 (defmacro cperl-etags-snarf-tag (file line)
135 (beginning-of-line 2)
137 (defmacro cperl-etags-snarf-tag (file line)
139 (if (featurep 'xemacs)
140 (defmacro cperl-etags-goto-tag-location (elt)
142 ;; (switch-to-buffer (get-file-buffer (elt ,elt 0)))
143 ;; (set-buffer (get-file-buffer (elt ,elt 0)))
144 ;; Probably will not work due to some save-excursion???
145 ;; Or save-file-position?
146 ;; (message "Did I get to line %s?" (elt ,elt 1))
147 `(goto-line (string-to-int (elt ,elt 1))))
149 (defmacro cperl-etags-goto-tag-location (elt)
150 `(etags-goto-tag-location ,elt))))
152 (defvar cperl-can-font-lock
153 (or (featurep 'xemacs)
154 (and (boundp 'emacs-major-version)
156 (> emacs-major-version 20)))))
158 (defun cperl-choose-color (&rest list)
162 (if (or (x-color-defined-p (car list))
164 (setq answer (car list))))
165 (setq list (cdr list)))
169 "Major mode for editing Perl code."
174 (defgroup cperl-indentation-details nil
179 (defgroup cperl-affected-by-hairy nil
180 "Variables affected by `cperl-hairy'."
184 (defgroup cperl-autoinsert-details nil
185 "Auto-insert tuneup."
189 (defgroup cperl-faces nil
190 "Fontification colors."
191 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
195 (defgroup cperl-speed nil
196 "Speed vs. validity tuneup."
200 (defgroup cperl-help-system nil
201 "Help system tuneup."
206 (defcustom cperl-extra-newline-before-brace nil
207 "*Non-nil means that if, elsif, while, until, else, for, foreach
208 and do constructs look like:
219 :group 'cperl-autoinsert-details)
221 (defcustom cperl-extra-newline-before-brace-multiline
222 cperl-extra-newline-before-brace
223 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
224 for constructs with multiline if/unless/while/until/for/foreach condition."
226 :group 'cperl-autoinsert-details)
228 (defcustom cperl-indent-level 2
229 "*Indentation of CPerl statements with respect to containing block."
231 :group 'cperl-indentation-details)
233 ;; Is is not unusual to put both things like perl-indent-level and
234 ;; cperl-indent-level in the local variable section of a file. If only
235 ;; one of perl-mode and cperl-mode is in use, a warning will be issued
236 ;; about the variable. Autoload these here, so that no warning is
237 ;; issued when using either perl-mode or cperl-mode.
238 ;;;###autoload(put 'cperl-indent-level 'safe-local-variable 'integerp)
239 ;;;###autoload(put 'cperl-brace-offset 'safe-local-variable 'integerp)
240 ;;;###autoload(put 'cperl-continued-brace-offset 'safe-local-variable 'integerp)
241 ;;;###autoload(put 'cperl-label-offset 'safe-local-variable 'integerp)
242 ;;;###autoload(put 'cperl-continued-statement-offset 'safe-local-variable 'integerp)
243 ;;;###autoload(put 'cperl-extra-newline-before-brace 'safe-local-variable 'booleanp)
244 ;;;###autoload(put 'cperl-merge-trailing-else 'safe-local-variable 'booleanp)
246 (defcustom cperl-lineup-step nil
247 "*`cperl-lineup' will always lineup at multiple of this number.
248 If nil, the value of `cperl-indent-level' will be used."
249 :type '(choice (const nil) integer)
250 :group 'cperl-indentation-details)
252 (defcustom cperl-brace-imaginary-offset 0
253 "*Imagined indentation of a Perl open brace that actually follows a statement.
254 An open brace following other text is treated as if it were this far
255 to the right of the start of its line."
257 :group 'cperl-indentation-details)
259 (defcustom cperl-brace-offset 0
260 "*Extra indentation for braces, compared with other text in same context."
262 :group 'cperl-indentation-details)
263 (defcustom cperl-label-offset -2
264 "*Offset of CPerl label lines relative to usual indentation."
266 :group 'cperl-indentation-details)
267 (defcustom cperl-min-label-indent 1
268 "*Minimal offset of CPerl label lines."
270 :group 'cperl-indentation-details)
271 (defcustom cperl-continued-statement-offset 2
272 "*Extra indent for lines not starting new statements."
274 :group 'cperl-indentation-details)
275 (defcustom cperl-continued-brace-offset 0
276 "*Extra indent for substatements that start with open-braces.
277 This is in addition to cperl-continued-statement-offset."
279 :group 'cperl-indentation-details)
280 (defcustom cperl-close-paren-offset -1
281 "*Extra indent for substatements that start with close-parenthesis."
283 :group 'cperl-indentation-details)
285 (defcustom cperl-indent-wrt-brace t
286 "*Non-nil means indent statements in if/etc block relative brace, not if/etc.
287 Versions 5.2 ... 5.20 behaved as if this were `nil'."
289 :group 'cperl-indentation-details)
291 (defcustom cperl-auto-newline nil
292 "*Non-nil means automatically newline before and after braces,
293 and after colons and semicolons, inserted in CPerl code. The following
294 \\[cperl-electric-backspace] will remove the inserted whitespace.
295 Insertion after colons requires both this variable and
296 `cperl-auto-newline-after-colon' set."
298 :group 'cperl-autoinsert-details)
300 (defcustom cperl-autoindent-on-semi nil
301 "*Non-nil means automatically indent after insertion of (semi)colon.
302 Active if `cperl-auto-newline' is false."
304 :group 'cperl-autoinsert-details)
306 (defcustom cperl-auto-newline-after-colon nil
307 "*Non-nil means automatically newline even after colons.
308 Subject to `cperl-auto-newline' setting."
310 :group 'cperl-autoinsert-details)
312 (defcustom cperl-tab-always-indent t
313 "*Non-nil means TAB in CPerl mode should always reindent the current line,
314 regardless of where in the line point is when the TAB command is used."
316 :group 'cperl-indentation-details)
318 (defcustom cperl-font-lock nil
319 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
320 Can be overwritten by `cperl-hairy' if nil."
321 :type '(choice (const null) boolean)
322 :group 'cperl-affected-by-hairy)
324 (defcustom cperl-electric-lbrace-space nil
325 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
326 Can be overwritten by `cperl-hairy' if nil."
327 :type '(choice (const null) boolean)
328 :group 'cperl-affected-by-hairy)
330 (defcustom cperl-electric-parens-string "({[]})<"
331 "*String of parentheses that should be electric in CPerl.
332 Closing ones are electric only if the region is highlighted."
334 :group 'cperl-affected-by-hairy)
336 (defcustom cperl-electric-parens nil
337 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
338 Can be overwritten by `cperl-hairy' if nil."
339 :type '(choice (const null) boolean)
340 :group 'cperl-affected-by-hairy)
342 (defvar zmacs-regions) ; Avoid warning
344 (defcustom cperl-electric-parens-mark
346 (or (and (boundp 'transient-mark-mode) ; For Emacs
348 (and (boundp 'zmacs-regions) ; For XEmacs
350 "*Not-nil means that electric parens look for active mark.
351 Default is yes if there is visual feedback on mark."
353 :group 'cperl-autoinsert-details)
355 (defcustom cperl-electric-linefeed nil
356 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
357 In any case these two mean plain and hairy linefeeds together.
358 Can be overwritten by `cperl-hairy' if nil."
359 :type '(choice (const null) boolean)
360 :group 'cperl-affected-by-hairy)
362 (defcustom cperl-electric-keywords nil
363 "*Not-nil (and non-null) means keywords are electric in CPerl.
364 Can be overwritten by `cperl-hairy' if nil.
366 Uses `abbrev-mode' to do the expansion. If you want to use your
367 own abbrevs in cperl-mode, but do not want keywords to be
368 electric, you must redefine `cperl-mode-abbrev-table': do
369 \\[edit-abbrevs], search for `cperl-mode-abbrev-table', and, in
370 that paragraph, delete the words that appear at the ends of lines and
371 that begin with \"cperl-electric\".
373 :type '(choice (const null) boolean)
374 :group 'cperl-affected-by-hairy)
376 (defcustom cperl-electric-backspace-untabify t
377 "*Not-nil means electric-backspace will untabify in CPerl."
379 :group 'cperl-autoinsert-details)
381 (defcustom cperl-hairy nil
382 "*Not-nil means most of the bells and whistles are enabled in CPerl.
383 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
384 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
385 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
386 `cperl-lazy-help-time'."
388 :group 'cperl-affected-by-hairy)
390 (defcustom cperl-comment-column 32
391 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
393 :group 'cperl-indentation-details)
395 (defcustom cperl-indent-comment-at-column-0 nil
396 "*Non-nil means that comment started at column 0 should be indentable."
398 :group 'cperl-indentation-details)
400 (defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
401 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
402 :type '(repeat string)
405 (defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
406 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
407 :type '(repeat string)
410 ;; This became obsolete...
411 (defvar cperl-vc-header-alist nil)
412 (make-obsolete-variable
413 'cperl-vc-header-alist
414 "use cperl-vc-rcs-header or cperl-vc-sccs-header instead.")
416 (defcustom cperl-clobber-mode-lists
419 (boundp 'interpreter-mode-alist)
420 (assoc "miniperl" interpreter-mode-alist)
421 (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
422 "*Whether to install us into `interpreter-' and `extension' mode lists."
426 (defcustom cperl-info-on-command-no-prompt nil
427 "*Not-nil (and non-null) means not to prompt on C-h f.
428 The opposite behavior is always available if prefixed with C-c.
429 Can be overwritten by `cperl-hairy' if nil."
430 :type '(choice (const null) boolean)
431 :group 'cperl-affected-by-hairy)
433 (defcustom cperl-clobber-lisp-bindings nil
434 "*Not-nil (and non-null) means not overwrite C-h f.
435 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
436 Can be overwritten by `cperl-hairy' if nil."
437 :type '(choice (const null) boolean)
438 :group 'cperl-affected-by-hairy)
440 (defcustom cperl-lazy-help-time nil
441 "*Not-nil (and non-null) means to show lazy help after given idle time.
442 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
443 :type '(choice (const null) (const nil) integer)
444 :group 'cperl-affected-by-hairy)
446 (defcustom cperl-pod-face 'font-lock-comment-face
447 "*Face for POD highlighting."
451 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
452 "*Face for POD highlighting.
453 Font for POD headers."
457 (defcustom cperl-here-face 'font-lock-string-face
458 "*Face for here-docs highlighting."
462 ;;; Some double-evaluation happened with font-locks... Needed with 21.2...
463 (defvar cperl-singly-quote-face (featurep 'xemacs))
465 (defcustom cperl-invalid-face 'underline
466 "*Face for highlighting trailing whitespace."
471 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
472 "*Not-nil after evaluation means to highlight POD and here-docs sections."
476 (defcustom cperl-fontify-m-as-s t
477 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
481 (defcustom cperl-highlight-variables-indiscriminately nil
482 "*Non-nil means perform additional highlighting on variables.
483 Currently only changes how scalar variables are highlighted.
484 Note that that variable is only read at initialization time for
485 the variable `cperl-font-lock-keywords-2', so changing it after you've
486 entered CPerl mode the first time will have no effect."
490 (defcustom cperl-pod-here-scan t
491 "*Not-nil means look for POD and here-docs sections during startup.
492 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
496 (defcustom cperl-regexp-scan t
497 "*Not-nil means make marking of regular expression more thorough.
498 Effective only with `cperl-pod-here-scan'."
502 (defcustom cperl-hook-after-change t
503 "*Not-nil means install hook to know which regions of buffer are changed.
504 May significantly speed up delayed fontification. Changes take effect
509 (defcustom cperl-imenu-addback nil
510 "*Not-nil means add backreferences to generated `imenu's.
511 May require patched `imenu' and `imenu-go'. Obsolete."
513 :group 'cperl-help-system)
515 (defcustom cperl-max-help-size 66
516 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
517 :type '(choice integer (const nil))
518 :group 'cperl-help-system)
520 (defcustom cperl-shrink-wrap-info-frame t
521 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
523 :group 'cperl-help-system)
525 (defcustom cperl-info-page "perl"
526 "*Name of the info page containing perl docs.
527 Older version of this page was called `perl5', newer `perl'."
529 :group 'cperl-help-system)
531 (defcustom cperl-use-syntax-table-text-property
532 (boundp 'parse-sexp-lookup-properties)
533 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
537 (defcustom cperl-use-syntax-table-text-property-for-tags
538 cperl-use-syntax-table-text-property
539 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
543 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
544 "*Regexp to match files to scan when generating TAGS."
548 (defcustom cperl-noscan-files-regexp
549 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
550 "*Regexp to match files/dirs to skip when generating TAGS."
554 (defcustom cperl-regexp-indent-step nil
555 "*Indentation used when beautifying regexps.
556 If nil, the value of `cperl-indent-level' will be used."
557 :type '(choice integer (const nil))
558 :group 'cperl-indentation-details)
560 (defcustom cperl-indent-left-aligned-comments t
561 "*Non-nil means that the comment starting in leftmost column should indent."
563 :group 'cperl-indentation-details)
565 (defcustom cperl-under-as-char nil
566 "*Non-nil means that the _ (underline) should be treated as word char."
570 (defcustom cperl-extra-perl-args ""
571 "*Extra arguments to use when starting Perl.
572 Currently used with `cperl-check-syntax' only."
576 (defcustom cperl-message-electric-keyword t
577 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
579 :group 'cperl-help-system)
581 (defcustom cperl-indent-region-fix-constructs 1
582 "*Amount of space to insert between `}' and `else' or `elsif'
583 in `cperl-indent-region'. Set to nil to leave as is. Values other
584 than 1 and nil will probably not work."
585 :type '(choice (const nil) (const 1))
586 :group 'cperl-indentation-details)
588 (defcustom cperl-break-one-line-blocks-when-indent t
589 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
590 need to be reformatted into multiline ones when indenting a region."
592 :group 'cperl-indentation-details)
594 (defcustom cperl-fix-hanging-brace-when-indent t
595 "*Non-nil means that BLOCK-end `}' may be put on a separate line
596 when indenting a region.
597 Braces followed by else/elsif/while/until are excepted."
599 :group 'cperl-indentation-details)
601 (defcustom cperl-merge-trailing-else t
602 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
603 may be merged to be on the same line when indenting a region."
605 :group 'cperl-indentation-details)
607 (defcustom cperl-indent-parens-as-block nil
608 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
609 but for trailing \",\" inside the group, which won't increase indentation.
610 One should tune up `cperl-close-paren-offset' as well."
612 :group 'cperl-indentation-details)
614 (defcustom cperl-syntaxify-by-font-lock
615 (and cperl-can-font-lock
616 (boundp 'parse-sexp-lookup-properties))
617 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
618 :type '(choice (const message) boolean)
621 (defcustom cperl-syntaxify-unwind
623 "*Non-nil means that CPerl unwinds to a start of a long construction
624 when syntaxifying a chunk of buffer."
628 (defcustom cperl-syntaxify-for-menu
630 "*Non-nil means that CPerl syntaxifies up to the point before showing menu.
631 This way enabling/disabling of menu items is more correct."
635 (defcustom cperl-ps-print-face-properties
636 '((font-lock-keyword-face nil nil bold shadow)
637 (font-lock-variable-name-face nil nil bold)
638 (font-lock-function-name-face nil nil bold italic box)
639 (font-lock-constant-face nil "LightGray" bold)
640 (cperl-array-face nil "LightGray" bold underline)
641 (cperl-hash-face nil "LightGray" bold italic underline)
642 (font-lock-comment-face nil "LightGray" italic)
643 (font-lock-string-face nil nil italic underline)
644 (cperl-nonoverridable-face nil nil italic underline)
645 (font-lock-type-face nil nil underline)
646 (font-lock-warning-face nil "LightGray" bold italic box)
647 (underline nil "LightGray" strikeout))
648 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
649 :type '(repeat (cons symbol
650 (cons (choice (const nil) string)
651 (cons (choice (const nil) string)
655 (defvar cperl-dark-background
656 (cperl-choose-color "navy" "os2blue" "darkgreen"))
657 (defvar cperl-dark-foreground
658 (cperl-choose-color "orchid1" "orange"))
660 (defface cperl-nonoverridable-face
661 `((((class grayscale) (background light))
662 (:background "Gray90" :slant italic :underline t))
663 (((class grayscale) (background dark))
664 (:foreground "Gray80" :slant italic :underline t :weight bold))
665 (((class color) (background light))
666 (:foreground "chartreuse3"))
667 (((class color) (background dark))
668 (:foreground ,cperl-dark-foreground))
669 (t (:weight bold :underline t)))
670 "Font Lock mode face used non-overridable keywords and modifiers of regexps."
673 (defface cperl-array-face
674 `((((class grayscale) (background light))
675 (:background "Gray90" :weight bold))
676 (((class grayscale) (background dark))
677 (:foreground "Gray80" :weight bold))
678 (((class color) (background light))
679 (:foreground "Blue" :background "lightyellow2" :weight bold))
680 (((class color) (background dark))
681 (:foreground "yellow" :background ,cperl-dark-background :weight bold))
683 "Font Lock mode face used to highlight array names."
686 (defface cperl-hash-face
687 `((((class grayscale) (background light))
688 (:background "Gray90" :weight bold :slant italic))
689 (((class grayscale) (background dark))
690 (:foreground "Gray80" :weight bold :slant italic))
691 (((class color) (background light))
692 (:foreground "Red" :background "lightyellow2" :weight bold :slant italic))
693 (((class color) (background dark))
694 (:foreground "Red" :background ,cperl-dark-background :weight bold :slant italic))
695 (t (:weight bold :slant italic)))
696 "Font Lock mode face used to highlight hash names."
701 ;;; Short extra-docs.
703 (defvar cperl-tips 'please-ignore-this-line
704 "Get maybe newer version of this package from
705 http://ilyaz.org/software/emacs
706 Subdirectory `cperl-mode' may contain yet newer development releases and/or
707 patches to related files.
709 For best results apply to an older Emacs the patches from
710 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
711 \(this upgrades syntax-parsing abilities of Emacsen v19.34 and
712 v20.2 up to the level of Emacs v20.3 - a must for a good Perl
713 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
715 Get support packages choose-color.el (or font-lock-extra.el before
716 19.30), imenu-go.el from the same place. \(Look for other files there
717 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
718 later you should use choose-color.el *instead* of font-lock-extra.el
719 \(and you will not get smart highlighting in C :-().
721 Note that to enable Compile choices in the menu you need to install
724 If your Emacs does not default to `cperl-mode' on Perl files, and you
725 want it to: put the following into your .emacs file:
727 (defalias 'perl-mode 'cperl-mode)
730 $CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
731 Also, one can generate a newer documentation running `pod2texi' converter
732 $CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
734 If you use imenu-go, run imenu on perl5-info buffer (you can do it
735 from Perl menu). If many files are related, generate TAGS files from
736 Tools/Tags submenu in Perl menu.
738 If some class structure is too complicated, use Tools/Hierarchy-view
739 from Perl menu, or hierarchic view of imenu. The second one uses the
740 current buffer only, the first one requires generation of TAGS from
741 Perl/Tools/Tags menu beforehand.
743 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
745 Switch auto-help on/off with Perl/Tools/Auto-help.
747 Though with contemporary Emaxen CPerl mode should maintain the correct
748 parsing of Perl even when editing, sometimes it may be lost. Fix this by
752 In cases of more severe confusion sometimes it is helpful to do
754 \\[load-library] cperl-mode RET
757 Before reporting (non-)problems look in the problem section of online
758 micro-docs on what I know about CPerl problems.")
760 (defvar cperl-problems 'please-ignore-this-line
761 "Description of problems in CPerl mode.
762 Some faces will not be shown on some versions of Emacs unless you
763 install choose-color.el, available from
764 http://ilyaz.org/software/emacs
766 `fill-paragraph' on a comment may leave the point behind the
767 paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
768 to detect it and bulk out).
770 See documentation of a variable `cperl-problems-old-emaxen' for the
771 problems which disappear if you upgrade Emacs to a reasonably new
772 version (20.3 for Emacs, and those of 2004 for XEmacs).")
774 (defvar cperl-problems-old-emaxen 'please-ignore-this-line
775 "Description of problems in CPerl mode specific for older Emacs versions.
777 Emacs had a _very_ restricted syntax parsing engine until version
778 20.1. Most problems below are corrected starting from this version of
779 Emacs, and all of them should be fixed in version 20.3. (Or apply
780 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
781 this respect (until 2003).
783 Note that even with newer Emacsen in some very rare cases the details
784 of interaction of `font-lock' and syntaxification may be not cleaned
785 up yet. You may get slightly different colors basing on the order of
786 fontification and syntaxification. Say, the initial faces is correct,
787 but editing the buffer breaks this.
789 Even with older Emacsen CPerl mode tries to corrects some Emacs
790 misunderstandings, however, for efficiency reasons the degree of
791 correction is different for different operations. The partially
792 corrected problems are: POD sections, here-documents, regexps. The
793 operations are: highlighting, indentation, electric keywords, electric
796 This may be confusing, since the regexp s#//#/#\; may be highlighted
797 as a comment, but it will be recognized as a regexp by the indentation
798 code. Or the opposite case, when a POD section is highlighted, but
799 may break the indentation of the following code (though indentation
800 should work if the balance of delimiters is not broken by POD).
802 The main trick (to make $ a \"backslash\") makes constructions like
803 ${aaa} look like unbalanced braces. The only trick I can think of is
804 to insert it as $ {aaa} (valid in perl5, not in perl4).
806 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
807 as /($|\\s)/. Note that such a transposition is not always possible.
809 The solution is to upgrade your Emacs or patch an older one. Note
810 that Emacs 20.2 has some bugs related to `syntax-table' text
811 properties. Patches are available on the main CPerl download site,
814 If these bugs cannot be fixed on your machine (say, you have an inferior
815 environment and cannot recompile), you may still disable all the fancy stuff
816 via `cperl-use-syntax-table-text-property'.")
818 (defvar cperl-praise 'please-ignore-this-line
819 "Advantages of CPerl mode.
821 0) It uses the newest `syntax-table' property ;-);
823 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
824 mode - but the latter number may have improved too in last years) even
825 with old Emaxen which do not support `syntax-table' property.
827 When using `syntax-table' property for syntax assist hints, it should
828 handle 99.995% of lines correct - or somesuch. It automatically
829 updates syntax assist hints when you edit your script.
831 2) It is generally believed to be \"the most user-friendly Emacs
832 package\" whatever it may mean (I doubt that the people who say similar
833 things tried _all_ the rest of Emacs ;-), but this was not a lonely
836 3) Everything is customizable, one-by-one or in a big sweep;
838 4) It has many easily-accessible \"tools\":
839 a) Can run program, check syntax, start debugger;
840 b) Can lineup vertically \"middles\" of rows, like `=' in
843 c) Can insert spaces where this impoves readability (in one
844 interactive sweep over the buffer);
845 d) Has support for imenu, including:
846 1) Separate unordered list of \"interesting places\";
847 2) Separate TOC of POD sections;
848 3) Separate list of packages;
849 4) Hierarchical view of methods in (sub)packages;
850 5) and functions (by the full name - with package);
851 e) Has an interface to INFO docs for Perl; The interface is
852 very flexible, including shrink-wrapping of
853 documentation buffer/frame;
854 f) Has a builtin list of one-line explanations for perl constructs.
855 g) Can show these explanations if you stay long enough at the
856 corresponding place (or on demand);
857 h) Has an enhanced fontification (using 3 or 4 additional faces
858 comparing to font-lock - basically, different
859 namespaces in Perl have different colors);
860 i) Can construct TAGS basing on its knowledge of Perl syntax,
861 the standard menu has 6 different way to generate
862 TAGS (if \"by directory\", .xs files - with C-language
863 bindings - are included in the scan);
864 j) Can build a hierarchical view of classes (via imenu) basing
865 on generated TAGS file;
866 k) Has electric parentheses, electric newlines, uses Abbrev
867 for electric logical constructs
869 with different styles of expansion (context sensitive
870 to be not so bothering). Electric parentheses behave
871 \"as they should\" in a presence of a visible region.
872 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
878 n) Highlights (by user-choice) either 3-delimiters constructs
879 (such as tr/a/b/), or regular expressions and `y/tr';
880 o) Highlights trailing whitespace;
881 p) Is able to manipulate Perl Regular Expressions to ease
882 conversion to a more readable form.
883 q) Can ispell POD sections and HERE-DOCs.
884 r) Understands comments and character classes inside regular
885 expressions; can find matching () and [] in a regular expression.
886 s) Allows indentation of //x-style regular expressions;
887 t) Highlights different symbols in regular expressions according
888 to their function; much less problems with backslashitis;
889 u) Allows to find regular expressions which contain interpolated parts.
891 5) The indentation engine was very smart, but most of tricks may be
892 not needed anymore with the support for `syntax-table' property. Has
893 progress indicator for indentation (with `imenu' loaded).
895 6) Indent-region improves inline-comments as well; also corrects
896 whitespace *inside* the conditional/loop constructs.
898 7) Fill-paragraph correctly handles multi-line comments;
900 8) Can switch to different indentation styles by one command, and restore
901 the settings present before the switch.
903 9) When doing indentation of control constructs, may correct
904 line-breaks/spacing between elements of the construct.
906 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
907 capable syntax engines).
909 11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
912 (defvar cperl-speed 'please-ignore-this-line
913 "This is an incomplete compendium of what is available in other parts
914 of CPerl documentation. (Please inform me if I skept anything.)
916 There is a perception that CPerl is slower than alternatives. This part
917 of documentation is designed to overcome this misconception.
919 *By default* CPerl tries to enable the most comfortable settings.
920 From most points of view, correctly working package is infinitely more
921 comfortable than a non-correctly working one, thus by default CPerl
922 prefers correctness over speed. Below is the guide how to change
923 settings if your preferences are different.
925 A) Speed of loading the file. When loading file, CPerl may perform a
926 scan which indicates places which cannot be parsed by primitive Emacs
927 syntax-parsing routines, and marks them up so that either
929 A1) CPerl may work around these deficiencies (for big chunks, mostly
930 PODs and HERE-documents), or
931 A2) On capable Emaxen CPerl will use improved syntax-handlings
932 which reads mark-up hints directly.
934 The scan in case A2 is much more comprehensive, thus may be slower.
936 User can disable syntax-engine-helping scan of A2 by setting
937 `cperl-use-syntax-table-text-property'
938 variable to nil (if it is set to t).
940 One can disable the scan altogether (both A1 and A2) by setting
941 `cperl-pod-here-scan'
944 B) Speed of editing operations.
946 One can add a (minor) speedup to editing operations by setting
947 `cperl-use-syntax-table-text-property'
948 variable to nil (if it is set to t). This will disable
949 syntax-engine-helping scan, thus will make many more Perl
950 constructs be wrongly recognized by CPerl, thus may lead to
951 wrongly matched parentheses, wrong indentation, etc.
953 One can unset `cperl-syntaxify-unwind'. This might speed up editing
954 of, say, long POD sections.")
956 (defvar cperl-tips-faces 'please-ignore-this-line
957 "CPerl mode uses following faces for highlighting:
959 `cperl-array-face' Array names
960 `cperl-hash-face' Hash names
961 `font-lock-comment-face' Comments, PODs and whatever is considered
962 syntaxically to be not code
963 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
964 2-arg operators s/y/tr/ or of RExen,
965 `font-lock-warning-face' Special-cased m// and s//foo/,
966 `font-lock-function-name-face' _ as a target of a file tests, file tests,
967 subroutine names at the moment of definition
968 (except those conflicting with Perl operators),
969 package names (when recognized), format names
970 `font-lock-keyword-face' Control flow switch constructs, declarators
971 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
972 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
973 literal parts and the terminator of formats
974 and whatever is syntaxically considered
976 `font-lock-type-face' Overridable keywords
977 `font-lock-variable-name-face' Variable declarations, indirect array and
978 hash names, POD headers/item names
979 `cperl-invalid' Trailing whitespace
981 Note that in several situations the highlighting tries to inform about
982 possible confusion, such as different colors for function names in
983 declarations depending on what they (do not) override, or special cases
984 m// and s/// which do not do what one would expect them to do.
986 Help with best setup of these faces for printout requested (for each of
987 the faces: please specify bold, italic, underline, shadow and box.)
989 In regular expressions (except character classes):
990 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs
991 `font-lock-constant-face': Delimiters
992 `font-lock-warning-face' Special-cased m// and s//foo/,
993 Mismatched closing delimiters, parens
994 we couldn't match, misplaced quantifiers,
995 unrecognized escape sequences
996 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
997 `font-lock-type-face' POSIX classes inside charclasses,
998 escape sequences with arguments (\x \23 \p \N)
999 and others match-a-char escape sequences
1000 `font-lock-keyword-face' Capturing parens, and |
1001 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
1002 `font-lock-builtin-face' \"Remaining\" 0-length constructs, executable
1003 parts of a REx, not-capturing parens
1004 `font-lock-variable-name-face' Interpolated constructs, embedded code
1005 `font-lock-comment-face' Embedded comments
1011 ;;; Portability stuff:
1013 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
1014 `(define-key cperl-mode-map
1016 `(if (featurep 'xemacs) ,xemacs-key ,emacs-key)
1020 (defvar cperl-del-back-ch
1021 (car (append (where-is-internal 'delete-backward-char)
1022 (where-is-internal 'backward-delete-char-untabify)))
1023 "Character generated by key bound to `delete-backward-char'.")
1025 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
1026 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
1028 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
1029 (if (featurep 'xemacs)
1031 ;; "Active regions" are on: use region only if active
1032 ;; "Active regions" are off: use region unconditionally
1033 (defun cperl-use-region-p ()
1034 (if zmacs-regions (mark) t)))
1035 (defun cperl-use-region-p ()
1036 (if transient-mark-mode mark-active t))
1037 (defun cperl-mark-active () mark-active))
1039 (defsubst cperl-enable-font-lock ()
1040 cperl-can-font-lock)
1042 (defun cperl-putback-char (c) ; Emacs 19
1043 (set 'unread-command-events (list c))) ; Avoid undefined warning
1045 (if (featurep 'xemacs)
1046 (defun cperl-putback-char (c) ; XEmacs >= 19.12
1047 (setq unread-command-events (list (eval '(character-to-event c))))))
1049 (or (fboundp 'uncomment-region)
1050 (defun uncomment-region (beg end)
1052 (comment-region beg end -1)))
1054 (defvar cperl-do-not-fontify
1055 (if (string< emacs-version "19.30")
1058 "Text property which inhibits refontification.")
1060 (defsubst cperl-put-do-not-fontify (from to &optional post)
1061 ;; If POST, do not do it with postponed fontification
1062 (if (and post cperl-syntaxify-by-font-lock)
1064 (put-text-property (max (point-min) (1- from))
1065 to cperl-do-not-fontify t)))
1067 (defcustom cperl-mode-hook nil
1068 "Hook run by CPerl mode."
1072 (defvar cperl-syntax-state nil)
1073 (defvar cperl-syntax-done-to nil)
1074 (defvar cperl-emacs-can-parse (> (length (save-excursion
1075 (parse-partial-sexp (point) (point)))) 9))
1077 ;; Make customization possible "in reverse"
1078 (defsubst cperl-val (symbol &optional default hairy)
1080 ((eq (symbol-value symbol) 'null) default)
1081 (cperl-hairy (or hairy t))
1082 (t (symbol-value symbol))))
1085 (defun cperl-make-indent (column &optional minimum keep)
1086 "Makes indent of the current line the requested amount.
1087 Unless KEEP, removes the old indentation. Works around a bug in ancient
1089 (let ((prop (get-text-property (point) 'syntax-type)))
1091 (delete-horizontal-space))
1092 (indent-to column minimum)
1093 ;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
1095 (> (current-column) 0)
1098 (or (get-text-property (point) 'syntax-type)
1099 (and (looking-at "\\=[ \t]")
1100 (put-text-property (point) (match-end 0)
1101 'syntax-type prop)))))))
1103 ;;; Probably it is too late to set these guys already, but it can help later:
1105 ;;;(and cperl-clobber-mode-lists
1106 ;;;(setq auto-mode-alist
1107 ;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
1108 ;;;(and (boundp 'interpreter-mode-alist)
1109 ;;; (setq interpreter-mode-alist (append interpreter-mode-alist
1110 ;;; '(("miniperl" . perl-mode))))))
1116 '(imenu easymenu etags timer man info))
1117 (if (fboundp 'ps-extend-face-list)
1118 (defmacro cperl-ps-extend-face-list (arg)
1119 `(ps-extend-face-list ,arg))
1120 (defmacro cperl-ps-extend-face-list (arg)
1121 `(error "This version of Emacs has no `ps-extend-face-list'")))
1122 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
1123 ;; macros instead of defsubsts don't work on Emacs, so we do the
1124 ;; expansion manually. Any other suggestions?
1127 (defvar cperl-mode-abbrev-table nil
1128 "Abbrev table in use in CPerl mode buffers.")
1130 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
1132 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
1134 (if cperl-mode-map nil
1135 (setq cperl-mode-map (make-sparse-keymap))
1136 (cperl-define-key "{" 'cperl-electric-lbrace)
1137 (cperl-define-key "[" 'cperl-electric-paren)
1138 (cperl-define-key "(" 'cperl-electric-paren)
1139 (cperl-define-key "<" 'cperl-electric-paren)
1140 (cperl-define-key "}" 'cperl-electric-brace)
1141 (cperl-define-key "]" 'cperl-electric-rparen)
1142 (cperl-define-key ")" 'cperl-electric-rparen)
1143 (cperl-define-key ";" 'cperl-electric-semi)
1144 (cperl-define-key ":" 'cperl-electric-terminator)
1145 (cperl-define-key "\C-j" 'newline-and-indent)
1146 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
1147 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
1148 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
1149 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
1150 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
1151 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
1152 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
1153 (cperl-define-key "\C-c\C-b" 'cperl-find-bad-style)
1154 (cperl-define-key "\C-c\C-p" 'cperl-pod-spell)
1155 (cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell)
1156 (cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc)
1157 (cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx)
1158 (cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0)
1159 (cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1)
1160 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
1161 (cperl-define-key "\C-c\C-hp" 'cperl-perldoc)
1162 (cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point)
1163 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
1164 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
1166 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1167 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
1168 (cperl-define-key "\177" 'cperl-electric-backspace)
1169 (cperl-define-key "\t" 'cperl-indent-command)
1170 ;; don't clobber the backspace binding:
1171 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
1172 [(control c) (control h) F])
1173 (if (cperl-val 'cperl-clobber-lisp-bindings)
1175 (cperl-define-key "\C-hf"
1176 ;;(concat (char-to-string help-char) "f") ; does not work
1177 'cperl-info-on-command
1179 (cperl-define-key "\C-hv"
1180 ;;(concat (char-to-string help-char) "v") ; does not work
1183 (cperl-define-key "\C-c\C-hf"
1184 ;;(concat (char-to-string help-char) "f") ; does not work
1185 (key-binding "\C-hf")
1186 [(control c) (control h) f])
1187 (cperl-define-key "\C-c\C-hv"
1188 ;;(concat (char-to-string help-char) "v") ; does not work
1189 (key-binding "\C-hv")
1190 [(control c) (control h) v]))
1191 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
1192 [(control c) (control h) f])
1193 (cperl-define-key "\C-c\C-hv"
1194 ;;(concat (char-to-string help-char) "v") ; does not work
1196 [(control c) (control h) v]))
1197 (if (and (featurep 'xemacs)
1198 (<= emacs-minor-version 11) (<= emacs-major-version 19))
1200 ;; substitute-key-definition is usefulness-deenhanced...
1201 ;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1202 (cperl-define-key "\e;" 'cperl-indent-for-comment)
1203 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
1204 (or (boundp 'fill-paragraph-function)
1205 (substitute-key-definition
1206 'fill-paragraph 'cperl-fill-paragraph
1207 cperl-mode-map global-map))
1208 (substitute-key-definition
1209 'indent-sexp 'cperl-indent-exp
1210 cperl-mode-map global-map)
1211 (substitute-key-definition
1212 'indent-region 'cperl-indent-region
1213 cperl-mode-map global-map)
1214 (substitute-key-definition
1215 'indent-for-comment 'cperl-indent-for-comment
1216 cperl-mode-map global-map)))
1219 (defvar cperl-lazy-installed)
1220 (defvar cperl-old-style nil)
1225 cperl-menu cperl-mode-map "Menu for CPerl mode"
1227 ["Beginning of function" beginning-of-defun t]
1228 ["End of function" end-of-defun t]
1229 ["Mark function" mark-defun t]
1230 ["Indent expression" cperl-indent-exp t]
1231 ["Fill paragraph/comment" fill-paragraph t]
1233 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
1234 ["Invert if/unless/while etc" cperl-invert-if-unless t]
1236 ["Beautify" cperl-beautify-regexp
1237 cperl-use-syntax-table-text-property]
1238 ["Beautify one level deep" (cperl-beautify-regexp 1)
1239 cperl-use-syntax-table-text-property]
1240 ["Beautify a group" cperl-beautify-level
1241 cperl-use-syntax-table-text-property]
1242 ["Beautify a group one level deep" (cperl-beautify-level 1)
1243 cperl-use-syntax-table-text-property]
1244 ["Contract a group" cperl-contract-level
1245 cperl-use-syntax-table-text-property]
1246 ["Contract groups" cperl-contract-levels
1247 cperl-use-syntax-table-text-property]
1249 ["Find next interpolated" cperl-next-interpolated-REx
1250 (next-single-property-change (point-min) 'REx-interpolated)]
1251 ["Find next interpolated (no //o)"
1252 cperl-next-interpolated-REx-0
1253 (or (text-property-any (point-min) (point-max) 'REx-interpolated t)
1254 (text-property-any (point-min) (point-max) 'REx-interpolated 1))]
1255 ["Find next interpolated (neither //o nor whole-REx)"
1256 cperl-next-interpolated-REx-1
1257 (text-property-any (point-min) (point-max) 'REx-interpolated t)])
1258 ["Insert spaces if needed to fix style" cperl-find-bad-style t]
1259 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
1261 ["Indent region" cperl-indent-region (cperl-use-region-p)]
1262 ["Comment region" cperl-comment-region (cperl-use-region-p)]
1263 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
1265 ["Run" mode-compile (fboundp 'mode-compile)]
1266 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
1267 (get-buffer "*compilation*"))]
1268 ["Next error" next-error (get-buffer "*compilation*")]
1269 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
1271 ["Debugger" cperl-db t]
1274 ["Imenu" imenu (fboundp 'imenu)]
1275 ["Imenu on Perl Info" cperl-imenu-on-info (featurep 'imenu)]
1277 ["Ispell PODs" cperl-pod-spell
1278 ;; Better not to update syntaxification here:
1279 ;; debugging syntaxificatio can be broken by this???
1281 (get-text-property (point-min) 'in-pod)
1283 (and cperl-syntaxify-for-menu
1284 (cperl-update-syntaxification (point-max) (point-max)))
1285 (next-single-property-change (point-min) 'in-pod nil (point-max)))
1287 ["Ispell HERE-DOCs" cperl-here-doc-spell
1289 (and cperl-syntaxify-for-menu
1290 (cperl-update-syntaxification (point-max) (point-max)))
1291 (next-single-property-change (point-min) 'here-doc-group nil (point-max)))
1293 ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
1294 (eq 'here-doc (progn
1295 (and cperl-syntaxify-for-menu
1296 (cperl-update-syntaxification (point) (point)))
1297 (get-text-property (point) 'syntax-type)))]
1298 ["Select this HERE-DOC or POD section"
1299 cperl-select-this-pod-or-here-doc
1301 (and cperl-syntaxify-for-menu
1302 (cperl-update-syntaxification (point) (point)))
1303 (get-text-property (point) 'syntax-type))
1306 ["CPerl pretty print (exprmntl)" cperl-ps-print
1307 (fboundp 'ps-extend-face-list)]
1309 ["Syntaxify region" cperl-find-pods-heres-region
1310 (cperl-use-region-p)]
1311 ["Profile syntaxification" cperl-time-fontification t]
1312 ["Debug errors in delayed fontification" cperl-emulate-lazy-lock t]
1313 ["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t]
1314 ["Debug backtrace on syntactic scan (BEWARE!!!)"
1315 (cperl-toggle-set-debug-unwind nil t) t]
1317 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
1318 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
1320 ;;; ["Create tags for current file" cperl-etags t]
1321 ;;; ["Add tags for current file" (cperl-etags t) t]
1322 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
1323 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
1324 ;;; ["Create tags for Perl files in (sub)directories"
1325 ;;; (cperl-etags nil 'recursive) t]
1326 ;;; ["Add tags for Perl files in (sub)directories"
1327 ;;; (cperl-etags t 'recursive) t])
1328 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
1329 ["Create tags for current file" (cperl-write-tags nil t) t]
1330 ["Add tags for current file" (cperl-write-tags) t]
1331 ["Create tags for Perl files in directory"
1332 (cperl-write-tags nil t nil t) t]
1333 ["Add tags for Perl files in directory"
1334 (cperl-write-tags nil nil nil t) t]
1335 ["Create tags for Perl files in (sub)directories"
1336 (cperl-write-tags nil t t t) t]
1337 ["Add tags for Perl files in (sub)directories"
1338 (cperl-write-tags nil nil t t) t]))
1340 ["Define word at point" imenu-go-find-at-position
1341 (fboundp 'imenu-go-find-at-position)]
1342 ["Help on function" cperl-info-on-command t]
1343 ["Help on function at point" cperl-info-on-current-command t]
1344 ["Help on symbol at point" cperl-get-help t]
1345 ["Perldoc" cperl-perldoc t]
1346 ["Perldoc on word at point" cperl-perldoc-at-point t]
1347 ["View manpage of POD in this file" cperl-build-manpage t]
1348 ["Auto-help on" cperl-lazy-install
1349 (and (fboundp 'run-with-idle-timer)
1350 (not cperl-lazy-installed))]
1351 ["Auto-help off" cperl-lazy-unstall
1352 (and (fboundp 'run-with-idle-timer)
1353 cperl-lazy-installed)])
1355 ["Auto newline" cperl-toggle-auto-newline t]
1356 ["Electric parens" cperl-toggle-electric t]
1357 ["Electric keywords" cperl-toggle-abbrev t]
1358 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
1359 ["Auto-help on Perl constructs" cperl-toggle-autohelp t]
1360 ["Auto fill" auto-fill-mode t])
1362 ["CPerl" (cperl-set-style "CPerl") t]
1363 ["PerlStyle" (cperl-set-style "PerlStyle") t]
1364 ["GNU" (cperl-set-style "GNU") t]
1365 ["C++" (cperl-set-style "C++") t]
1366 ["K&R" (cperl-set-style "K&R") t]
1367 ["BSD" (cperl-set-style "BSD") t]
1368 ["Whitesmith" (cperl-set-style "Whitesmith") t]
1369 ["Memorize Current" (cperl-set-style "Current") t]
1370 ["Memorized" (cperl-set-style-back) cperl-old-style])
1372 ["Tips" (describe-variable 'cperl-tips) t]
1373 ["Problems" (describe-variable 'cperl-problems) t]
1374 ["Speed" (describe-variable 'cperl-speed) t]
1375 ["Praise" (describe-variable 'cperl-praise) t]
1376 ["Faces" (describe-variable 'cperl-tips-faces) t]
1377 ["CPerl mode" (describe-function 'cperl-mode) t]
1379 (message "The version of master-file for this CPerl is %s-Emacs"
1380 cperl-version) t]))))
1383 (autoload 'c-macro-expand "cmacexp"
1384 "Display the result of expanding all C macros occurring in the region.
1385 The expansion is entirely correct because it uses the C preprocessor."
1388 ;;; These two must be unwound, otherwise take exponential time
1389 (defconst cperl-maybe-white-and-comment-rex "[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
1390 "Regular expression to match optional whitespace with interpspersed comments.
1391 Should contain exactly one group.")
1393 ;;; This one is tricky to unwind; still very inefficient...
1394 (defconst cperl-white-and-comment-rex "\\([ \t\n]\\|#[^\n]*\n\\)+"
1395 "Regular expression to match whitespace with interpspersed comments.
1396 Should contain exactly one group.")
1399 ;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
1400 ;;; `cperl-outline-regexp', `defun-prompt-regexp'.
1401 ;;; Details of groups in this may be used in several functions; see comments
1402 ;;; near mentioned above variable(s)...
1403 ;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
1404 (defsubst cperl-after-sub-regexp (named attr) ; 9 groups without attr...
1405 "Match the text after `sub' in a subroutine declaration.
1406 If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
1407 of attributes (if present), or end of the name or prototype (whatever is
1409 (concat ; Assume n groups before this...
1410 "\\(" ; n+1=name-group
1411 cperl-white-and-comment-rex ; n+2=pre-name
1412 "\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
1413 "\\)" ; END n+1=name-group
1415 "\\(" ; n+4=proto-group
1416 cperl-maybe-white-and-comment-rex ; n+5=pre-proto
1417 "\\(([^()]*)\\)" ; n+6=prototype
1418 "\\)?" ; END n+4=proto-group
1419 "\\(" ; n+7=attr-group
1420 cperl-maybe-white-and-comment-rex ; n+8=pre-attr
1421 "\\(" ; n+9=start-attr
1425 cperl-maybe-white-and-comment-rex ; whitespace-comments
1426 "\\(\\sw\\|_\\)+" ; attr-name
1427 ;; attr-arg (1 level of internal parens allowed!)
1428 "\\((\\(\\\\.\\|[^\\\\()]\\|([^\\\\()]*)\\)*)\\)?"
1429 "\\(" ; optional : (XXX allows trailing???)
1430 cperl-maybe-white-and-comment-rex ; whitespace-comments
1435 "\\)?" ; END n+6=proto-group
1438 ;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
1439 ;;; and `cperl-outline-level'.
1440 ;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 8=sub-name (+3)
1441 (defvar cperl-imenu--function-name-regexp-perl
1444 "\\([ \t]*package" ; 2 = package-group
1445 "\\(" ; 3 = package-name-group
1446 cperl-white-and-comment-rex ; 4 = pre-package-name
1447 "\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
1450 (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
1451 cperl-maybe-white-and-comment-rex ; 15=pre-block
1453 "=head\\([1-4]\\)[ \t]+" ; 16=level
1454 "\\([^\n]+\\)$" ; 17=text
1457 (defvar cperl-outline-regexp
1458 (concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
1460 (defvar cperl-mode-syntax-table nil
1461 "Syntax table in use in CPerl mode buffers.")
1463 (defvar cperl-string-syntax-table nil
1464 "Syntax table in use in CPerl mode string-like chunks.")
1466 (defsubst cperl-1- (p)
1467 (max (point-min) (1- p)))
1469 (defsubst cperl-1+ (p)
1470 (min (point-max) (1+ p)))
1472 (if cperl-mode-syntax-table
1474 (setq cperl-mode-syntax-table (make-syntax-table))
1475 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
1476 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
1477 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
1478 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
1479 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
1480 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
1481 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
1482 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
1483 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
1484 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
1485 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
1486 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
1487 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
1488 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
1489 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
1490 (if cperl-under-as-char
1491 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
1492 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
1493 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
1494 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
1495 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
1496 (modify-syntax-entry ?\{ "." cperl-string-syntax-table)
1497 (modify-syntax-entry ?\} "." cperl-string-syntax-table)
1498 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment )
1502 (defvar cperl-faces-init nil)
1504 (defvar cperl-msb-fixed nil)
1505 (defvar cperl-use-major-mode 'cperl-mode)
1506 (defvar cperl-font-lock-multiline-start nil)
1507 (defvar cperl-font-lock-multiline nil)
1508 (defvar cperl-font-locking nil)
1510 ;; NB as it stands the code in cperl-mode assumes this only has one
1511 ;; element. If Xemacs 19 support were dropped, this could all be simplified.
1512 (defvar cperl-compilation-error-regexp-alist
1513 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
1514 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
1516 "Alist that specifies how to match errors in perl output.")
1518 (defvar compilation-error-regexp-alist)
1521 (defun cperl-mode ()
1522 "Major mode for editing Perl code.
1523 Expression and list commands understand all C brackets.
1524 Tab indents for Perl code.
1525 Paragraphs are separated by blank lines only.
1526 Delete converts tabs to spaces as it moves back.
1528 Various characters in Perl almost always come in pairs: {}, (), [],
1529 sometimes <>. When the user types the first, she gets the second as
1530 well, with optional special formatting done on {}. (Disabled by
1531 default.) You can always quote (with \\[quoted-insert]) the left
1532 \"paren\" to avoid the expansion. The processing of < is special,
1533 since most the time you mean \"less\". CPerl mode tries to guess
1534 whether you want to type pair <>, and inserts is if it
1535 appropriate. You can set `cperl-electric-parens-string' to the string that
1536 contains the parenths from the above list you want to be electrical.
1537 Electricity of parenths is controlled by `cperl-electric-parens'.
1538 You may also set `cperl-electric-parens-mark' to have electric parens
1539 look for active mark and \"embrace\" a region if possible.'
1541 CPerl mode provides expansion of the Perl control constructs:
1543 if, else, elsif, unless, while, until, continue, do,
1544 for, foreach, formy and foreachmy.
1546 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
1548 The user types the keyword immediately followed by a space, which
1549 causes the construct to be expanded, and the point is positioned where
1550 she is most likely to want to be. eg. when the user types a space
1551 following \"if\" the following appears in the buffer: if () { or if ()
1552 } { } and the cursor is between the parentheses. The user can then
1553 type some boolean expression within the parens. Having done that,
1554 typing \\[cperl-linefeed] places you - appropriately indented - on a
1555 new line between the braces (if you typed \\[cperl-linefeed] in a POD
1556 directive line, then appropriate number of new lines is inserted).
1558 If CPerl decides that you want to insert \"English\" style construct like
1562 it will not do any expansion. See also help on variable
1563 `cperl-extra-newline-before-brace'. (Note that one can switch the
1564 help message on expansion by setting `cperl-message-electric-keyword'
1567 \\[cperl-linefeed] is a convenience replacement for typing carriage
1568 return. It places you in the next line with proper indentation, or if
1569 you type it inside the inline block of control construct, like
1571 foreach (@lines) {print; print}
1573 and you are on a boundary of a statement inside braces, it will
1574 transform the construct into a multiline and will place you into an
1575 appropriately indented blank line. If you need a usual
1576 `newline-and-indent' behavior, it is on \\[newline-and-indent],
1577 see documentation on `cperl-electric-linefeed'.
1579 Use \\[cperl-invert-if-unless] to change a construction of the form
1589 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
1590 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
1591 on electric space between $ and {, `cperl-electric-parens-string' is
1592 the string that contains parentheses that should be electric in CPerl
1593 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
1594 setting `cperl-electric-keywords' enables electric expansion of
1595 control structures in CPerl. `cperl-electric-linefeed' governs which
1596 one of two linefeed behavior is preferable. You can enable all these
1597 options simultaneously (recommended mode of use) by setting
1598 `cperl-hairy' to t. In this case you can switch separate options off
1599 by setting them to `null'. Note that one may undo the extra
1600 whitespace inserted by semis and braces in `auto-newline'-mode by
1601 consequent \\[cperl-electric-backspace].
1603 If your site has perl5 documentation in info format, you can use commands
1604 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
1605 These keys run commands `cperl-info-on-current-command' and
1606 `cperl-info-on-command', which one is which is controlled by variable
1607 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
1608 \(in turn affected by `cperl-hairy').
1610 Even if you have no info-format documentation, short one-liner-style
1611 help is available on \\[cperl-get-help], and one can run perldoc or
1614 It is possible to show this help automatically after some idle time.
1615 This is regulated by variable `cperl-lazy-help-time'. Default with
1616 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
1617 secs idle time . It is also possible to switch this on/off from the
1618 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
1620 Use \\[cperl-lineup] to vertically lineup some construction - put the
1621 beginning of the region at the start of construction, and make region
1622 span the needed amount of lines.
1624 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
1625 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
1626 here-docs sections. With capable Emaxen results of scan are used
1627 for indentation too, otherwise they are used for highlighting only.
1629 Variables controlling indentation style:
1630 `cperl-tab-always-indent'
1631 Non-nil means TAB in CPerl mode should always reindent the current line,
1632 regardless of where in the line point is when the TAB command is used.
1633 `cperl-indent-left-aligned-comments'
1634 Non-nil means that the comment starting in leftmost column should indent.
1635 `cperl-auto-newline'
1636 Non-nil means automatically newline before and after braces,
1637 and after colons and semicolons, inserted in Perl code. The following
1638 \\[cperl-electric-backspace] will remove the inserted whitespace.
1639 Insertion after colons requires both this variable and
1640 `cperl-auto-newline-after-colon' set.
1641 `cperl-auto-newline-after-colon'
1642 Non-nil means automatically newline even after colons.
1643 Subject to `cperl-auto-newline' setting.
1644 `cperl-indent-level'
1645 Indentation of Perl statements within surrounding block.
1646 The surrounding block's indentation is the indentation
1647 of the line on which the open-brace appears.
1648 `cperl-continued-statement-offset'
1649 Extra indentation given to a substatement, such as the
1650 then-clause of an if, or body of a while, or just a statement continuation.
1651 `cperl-continued-brace-offset'
1652 Extra indentation given to a brace that starts a substatement.
1653 This is in addition to `cperl-continued-statement-offset'.
1654 `cperl-brace-offset'
1655 Extra indentation for line if it starts with an open brace.
1656 `cperl-brace-imaginary-offset'
1657 An open brace following other text is treated as if it the line started
1658 this far to the right of the actual line indentation.
1659 `cperl-label-offset'
1660 Extra indentation for line that is a label.
1661 `cperl-min-label-indent'
1662 Minimal indentation for line that is a label.
1664 Settings for classic indent-styles: K&R BSD=C++ GNU PerlStyle=Whitesmith
1665 `cperl-indent-level' 5 4 2 4
1666 `cperl-brace-offset' 0 0 0 0
1667 `cperl-continued-brace-offset' -5 -4 0 0
1668 `cperl-label-offset' -5 -4 -2 -4
1669 `cperl-continued-statement-offset' 5 4 2 4
1671 CPerl knows several indentation styles, and may bulk set the
1672 corresponding variables. Use \\[cperl-set-style] to do this. Use
1673 \\[cperl-set-style-back] to restore the memorized preexisting values
1674 \(both available from menu). See examples in `cperl-style-examples'.
1676 Part of the indentation style is how different parts of if/elsif/else
1677 statements are broken into lines; in CPerl, this is reflected on how
1678 templates for these constructs are created (controlled by
1679 `cperl-extra-newline-before-brace'), and how reflow-logic should treat \"continuation\" blocks of else/elsif/continue, controlled by the same variable,
1680 and by `cperl-extra-newline-before-brace-multiline',
1681 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'.
1683 If `cperl-indent-level' is 0, the statement after opening brace in
1684 column 0 is indented on
1685 `cperl-brace-offset'+`cperl-continued-statement-offset'.
1687 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
1690 DO NOT FORGET to read micro-docs (available from `Perl' menu)
1691 or as help on variables `cperl-tips', `cperl-problems',
1692 `cperl-praise', `cperl-speed'."
1694 (kill-all-local-variables)
1695 (use-local-map cperl-mode-map)
1696 (if (cperl-val 'cperl-electric-linefeed)
1698 (local-set-key "\C-J" 'cperl-linefeed)
1699 (local-set-key "\C-C\C-J" 'newline-and-indent)))
1701 (cperl-val 'cperl-clobber-lisp-bindings)
1702 (cperl-val 'cperl-info-on-command-no-prompt))
1704 ;; don't clobber the backspace binding:
1705 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
1706 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
1707 [(control c) (control h) f])))
1708 (setq major-mode cperl-use-major-mode)
1709 (setq mode-name "CPerl")
1710 (let ((prev-a-c abbrevs-changed))
1711 (define-abbrev-table 'cperl-mode-abbrev-table '(
1712 ("if" "if" cperl-electric-keyword 0)
1713 ("elsif" "elsif" cperl-electric-keyword 0)
1714 ("while" "while" cperl-electric-keyword 0)
1715 ("until" "until" cperl-electric-keyword 0)
1716 ("unless" "unless" cperl-electric-keyword 0)
1717 ("else" "else" cperl-electric-else 0)
1718 ("continue" "continue" cperl-electric-else 0)
1719 ("for" "for" cperl-electric-keyword 0)
1720 ("foreach" "foreach" cperl-electric-keyword 0)
1721 ("formy" "formy" cperl-electric-keyword 0)
1722 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
1723 ("do" "do" cperl-electric-keyword 0)
1724 ("=pod" "=pod" cperl-electric-pod 0)
1725 ("=over" "=over" cperl-electric-pod 0)
1726 ("=head1" "=head1" cperl-electric-pod 0)
1727 ("=head2" "=head2" cperl-electric-pod 0)
1728 ("pod" "pod" cperl-electric-pod 0)
1729 ("over" "over" cperl-electric-pod 0)
1730 ("head1" "head1" cperl-electric-pod 0)
1731 ("head2" "head2" cperl-electric-pod 0)))
1732 (setq abbrevs-changed prev-a-c))
1733 (setq local-abbrev-table cperl-mode-abbrev-table)
1734 (if (cperl-val 'cperl-electric-keywords)
1736 (set-syntax-table cperl-mode-syntax-table)
1737 ;; Until Emacs is multi-threaded, we do not actually need it local:
1738 (make-local-variable 'cperl-font-lock-multiline-start)
1739 (make-local-variable 'cperl-font-locking)
1740 (make-local-variable 'outline-regexp)
1741 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
1742 (setq outline-regexp cperl-outline-regexp)
1743 (make-local-variable 'outline-level)
1744 (setq outline-level 'cperl-outline-level)
1745 (make-local-variable 'paragraph-start)
1746 (setq paragraph-start (concat "^$\\|" page-delimiter))
1747 (make-local-variable 'paragraph-separate)
1748 (setq paragraph-separate paragraph-start)
1749 (make-local-variable 'paragraph-ignore-fill-prefix)
1750 (setq paragraph-ignore-fill-prefix t)
1751 (if (featurep 'xemacs)
1753 (make-local-variable 'paren-backwards-message)
1754 (set 'paren-backwards-message t)))
1755 (make-local-variable 'indent-line-function)
1756 (setq indent-line-function 'cperl-indent-line)
1757 (make-local-variable 'require-final-newline)
1758 (setq require-final-newline mode-require-final-newline)
1759 (make-local-variable 'comment-start)
1760 (setq comment-start "# ")
1761 (make-local-variable 'comment-end)
1762 (setq comment-end "")
1763 (make-local-variable 'comment-column)
1764 (setq comment-column cperl-comment-column)
1765 (make-local-variable 'comment-start-skip)
1766 (setq comment-start-skip "#+ *")
1767 (make-local-variable 'defun-prompt-regexp)
1769 ;;; (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
1770 ;;; cperl-maybe-white-and-comment-rex ; 15=pre-block
1771 (setq defun-prompt-regexp
1772 (concat "^[ \t]*\\(sub"
1773 (cperl-after-sub-regexp 'named 'attr-groups)
1775 "\\(BEGIN\\|CHECK\\|INIT\\|END\\|AUTOLOAD\\|DESTROY\\)"
1777 cperl-maybe-white-and-comment-rex))
1778 (make-local-variable 'comment-indent-function)
1779 (setq comment-indent-function 'cperl-comment-indent)
1780 (and (boundp 'fill-paragraph-function)
1782 (make-local-variable 'fill-paragraph-function)
1783 (set 'fill-paragraph-function 'cperl-fill-paragraph)))
1784 (make-local-variable 'parse-sexp-ignore-comments)
1785 (setq parse-sexp-ignore-comments t)
1786 (make-local-variable 'indent-region-function)
1787 (setq indent-region-function 'cperl-indent-region)
1788 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
1789 (make-local-variable 'imenu-create-index-function)
1790 (setq imenu-create-index-function
1791 (function cperl-imenu--create-perl-index))
1792 (make-local-variable 'imenu-sort-function)
1793 (setq imenu-sort-function nil)
1794 (make-local-variable 'vc-rcs-header)
1795 (set 'vc-rcs-header cperl-vc-rcs-header)
1796 (make-local-variable 'vc-sccs-header)
1797 (set 'vc-sccs-header cperl-vc-sccs-header)
1798 ;; This one is obsolete...
1799 (make-local-variable 'vc-header-alist)
1801 (set 'vc-header-alist (or cperl-vc-header-alist ; Avoid warning
1802 `((SCCS ,(car cperl-vc-sccs-header))
1803 (RCS ,(car cperl-vc-rcs-header)))))
1805 (cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x
1806 (make-local-variable 'compilation-error-regexp-alist-alist)
1807 (set 'compilation-error-regexp-alist-alist
1808 (cons (cons 'cperl (car cperl-compilation-error-regexp-alist))
1809 (symbol-value 'compilation-error-regexp-alist-alist)))
1810 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
1811 (let ((f 'compilation-build-compilation-error-regexp-alist))
1813 (make-local-variable 'compilation-error-regexp-alist)
1814 (push 'cperl compilation-error-regexp-alist)))
1815 ((boundp 'compilation-error-regexp-alist);; xmeacs 19.x
1816 (make-local-variable 'compilation-error-regexp-alist)
1817 (set 'compilation-error-regexp-alist
1818 (append cperl-compilation-error-regexp-alist
1819 (symbol-value 'compilation-error-regexp-alist)))))
1820 (make-local-variable 'font-lock-defaults)
1821 (setq font-lock-defaults
1823 ((string< emacs-version "19.30")
1824 '(cperl-font-lock-keywords-2 nil nil ((?_ . "w"))))
1825 ((string< emacs-version "19.33") ; Which one to use?
1826 '((cperl-font-lock-keywords
1827 cperl-font-lock-keywords-1
1828 cperl-font-lock-keywords-2) nil nil ((?_ . "w"))))
1830 '((cperl-load-font-lock-keywords
1831 cperl-load-font-lock-keywords-1
1832 cperl-load-font-lock-keywords-2) nil nil ((?_ . "w"))))))
1833 (make-local-variable 'cperl-syntax-state)
1834 (setq cperl-syntax-state nil) ; reset syntaxification cache
1835 (if cperl-use-syntax-table-text-property
1837 (make-local-variable 'parse-sexp-lookup-properties)
1838 ;; Do not introduce variable if not needed, we check it!
1839 (set 'parse-sexp-lookup-properties t)
1840 ;; Fix broken font-lock:
1841 (or (boundp 'font-lock-unfontify-region-function)
1842 (set 'font-lock-unfontify-region-function
1843 'font-lock-default-unfontify-region))
1844 (unless (featurep 'xemacs) ; Our: just a plug for wrong font-lock
1845 (make-local-variable 'font-lock-unfontify-region-function)
1846 (set 'font-lock-unfontify-region-function ; not present with old Emacs
1847 'cperl-font-lock-unfontify-region-function))
1848 (make-local-variable 'cperl-syntax-done-to)
1849 (setq cperl-syntax-done-to nil) ; reset syntaxification cache
1850 (make-local-variable 'font-lock-syntactic-keywords)
1851 (setq font-lock-syntactic-keywords
1852 (if cperl-syntaxify-by-font-lock
1853 '((cperl-fontify-syntaxically))
1854 ;; unless font-lock-syntactic-keywords, font-lock (pre-22.1)
1855 ;; used to ignore syntax-table text-properties. (t) is a hack
1856 ;; to make font-lock think that font-lock-syntactic-keywords
1859 (if (boundp 'font-lock-multiline) ; Newer font-lock; use its facilities
1861 (setq cperl-font-lock-multiline t) ; Not localized...
1862 (set (make-local-variable 'font-lock-multiline) t))
1863 (make-local-variable 'font-lock-fontify-region-function)
1864 (set 'font-lock-fontify-region-function ; not present with old Emacs
1865 'cperl-font-lock-fontify-region-function))
1866 (make-local-variable 'font-lock-fontify-region-function)
1867 (set 'font-lock-fontify-region-function ; not present with old Emacs
1868 'cperl-font-lock-fontify-region-function)
1869 (make-local-variable 'cperl-old-style)
1870 (if (boundp 'normal-auto-fill-function) ; 19.33 and later
1871 (set (make-local-variable 'normal-auto-fill-function)
1872 'cperl-do-auto-fill)
1873 (or (fboundp 'cperl-old-auto-fill-mode)
1875 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
1876 (defun auto-fill-mode (&optional arg)
1878 (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
1879 (and auto-fill-function (memq major-mode '(perl-mode cperl-mode))
1880 (setq auto-fill-function 'cperl-do-auto-fill))))))
1881 (if (cperl-enable-font-lock)
1882 (if (cperl-val 'cperl-font-lock)
1883 (progn (or cperl-faces-init (cperl-init-faces))
1884 (font-lock-mode 1))))
1885 (set (make-local-variable 'facemenu-add-face-function)
1886 'cperl-facemenu-add-face-function) ; XXXX What this guy is for???
1887 (and (boundp 'msb-menu-cond)
1888 (not cperl-msb-fixed)
1890 (if (featurep 'easymenu)
1891 (easy-menu-add cperl-menu)) ; A NOP in Emacs.
1892 (run-mode-hooks 'cperl-mode-hook)
1893 (if cperl-hook-after-change
1894 (add-hook 'after-change-functions 'cperl-after-change-function nil t))
1895 ;; After hooks since fontification will break this
1896 (if cperl-pod-here-scan
1897 (or cperl-syntaxify-by-font-lock
1898 (progn (or cperl-faces-init (cperl-init-faces-weak))
1899 (cperl-find-pods-heres)))))
1901 ;; Fix for perldb - make default reasonable
1905 (perldb (read-from-minibuffer "Run perldb (like this): "
1906 (if (consp gud-perldb-history)
1907 (car gud-perldb-history)
1908 (concat "perl " ;;(file-name-nondirectory
1912 (buffer-file-name)))
1914 '(gud-perldb-history . 1))))
1916 (defun cperl-msb-fix ()
1917 ;; Adds perl files to msb menu, supposes that msb is already loaded
1918 (setq cperl-msb-fixed t)
1919 (let* ((l (length msb-menu-cond))
1920 (last (nth (1- l) msb-menu-cond))
1921 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
1922 (handle (1- (nth 1 last))))
1923 (setcdr precdr (list
1925 '(memq major-mode '(cperl-mode perl-mode))
1930 ;; This is used by indent-for-comment
1931 ;; to decide how much to indent a comment in CPerl code
1932 ;; based on its context. Do fallback if comment is found wrong.
1934 (defvar cperl-wrong-comment)
1935 (defvar cperl-st-cfence '(14)) ; Comment-fence
1936 (defvar cperl-st-sfence '(15)) ; String-fence
1937 (defvar cperl-st-punct '(1))
1938 (defvar cperl-st-word '(2))
1939 (defvar cperl-st-bra '(4 . ?\>))
1940 (defvar cperl-st-ket '(5 . ?\<))
1943 (defun cperl-comment-indent () ; called at point at supposed comment
1944 (let ((p (point)) (c (current-column)) was phony)
1945 (if (and (not cperl-indent-comment-at-column-0)
1947 0 ; Existing comment at bol stays there.
1948 ;; Wrong comment found
1950 (setq was (cperl-to-comment-or-eol)
1951 phony (eq (get-text-property (point) 'syntax-table)
1954 (progn ; Too naive???
1955 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
1956 (if (eq (preceding-char) ?\#)
1959 (if (= (point) p) ; Our caller found a correct place
1961 (skip-chars-backward " \t")
1962 (setq was (current-column))
1965 (max (1+ was) ; Else indent at comment column
1967 ;; No, the caller found a random place; we need to edit ourselves
1969 (insert comment-start)
1970 (backward-char (length comment-start)))
1971 (setq cperl-wrong-comment t)
1972 (cperl-make-indent comment-column 1) ; Indent min 1
1975 ;;;(defun cperl-comment-indent-fallback ()
1976 ;;; "Is called if the standard comment-search procedure fails.
1977 ;;;Point is at start of real comment."
1978 ;;; (let ((c (current-column)) target cnt prevc)
1979 ;;; (if (= c comment-column) nil
1980 ;;; (setq cnt (skip-chars-backward "[ \t]"))
1981 ;;; (setq target (max (1+ (setq prevc
1982 ;;; (current-column))) ; Else indent at comment column
1983 ;;; comment-column))
1984 ;;; (if (= c comment-column) nil
1985 ;;; (delete-backward-char cnt)
1986 ;;; (while (< prevc target)
1988 ;;; (setq prevc (current-column)))
1989 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
1990 ;;; (while (< prevc target)
1992 ;;; (setq prevc (current-column)))))))
1994 (defun cperl-indent-for-comment ()
1995 "Substitute for `indent-for-comment' in CPerl."
1997 (let (cperl-wrong-comment)
1998 (indent-for-comment)
1999 (if cperl-wrong-comment ; set by `cperl-comment-indent'
2000 (progn (cperl-to-comment-or-eol)
2001 (forward-char (length comment-start))))))
2003 (defun cperl-comment-region (b e arg)
2004 "Comment or uncomment each line in the region in CPerl mode.
2005 See `comment-region'."
2006 (interactive "r\np")
2007 (let ((comment-start "#"))
2008 (comment-region b e arg)))
2010 (defun cperl-uncomment-region (b e arg)
2011 "Uncomment or comment each line in the region in CPerl mode.
2012 See `comment-region'."
2013 (interactive "r\np")
2014 (let ((comment-start "#"))
2015 (comment-region b e (- arg))))
2017 (defvar cperl-brace-recursing nil)
2019 (defun cperl-electric-brace (arg &optional only-before)
2020 "Insert character and correct line's indentation.
2021 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
2022 place (even in empty line), but not after. If after \")\" and the inserted
2023 char is \"{\", insert extra newline before only if
2024 `cperl-extra-newline-before-brace'."
2027 (other-end (if (and cperl-electric-parens-mark
2033 (not cperl-brace-recursing)
2034 (cperl-val 'cperl-electric-parens)
2035 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
2036 ;; Need to insert a matching pair
2039 (setq insertpos (point-marker))
2040 (goto-char other-end)
2041 (setq last-command-event ?\{)
2042 (cperl-electric-lbrace arg insertpos))
2044 ;; Check whether we close something "usual" with `}'
2045 (if (and (eq last-command-event ?\})
2049 (up-list (- (prefix-numeric-value arg)))
2050 ;;(cperl-after-block-p (point-min))
2051 (or (cperl-after-expr-p nil "{;)")
2052 ;; after sub, else, continue
2053 (cperl-after-block-p nil 'pre)))
2055 ;; Just insert the guy
2056 (self-insert-command (prefix-numeric-value arg))
2057 (if (and (not arg) ; No args, end (of empty line or auto)
2059 (or (and (null only-before)
2061 (skip-chars-backward " \t")
2063 (and (eq last-command-event ?\{) ; Do not insert newline
2064 ;; if after ")" and `cperl-extra-newline-before-brace'
2065 ;; is nil, do not insert extra newline.
2066 (not cperl-extra-newline-before-brace)
2068 (skip-chars-backward " \t")
2069 (eq (preceding-char) ?\))))
2070 (if cperl-auto-newline
2071 (progn (cperl-indent-line) (newline) t) nil)))
2073 (self-insert-command (prefix-numeric-value arg))
2075 (if cperl-auto-newline
2076 (setq insertpos (1- (point))))
2077 (if (and cperl-auto-newline (null only-before))
2080 (cperl-indent-line)))
2082 (if insertpos (progn (goto-char insertpos)
2083 (search-forward (make-string
2084 1 last-command-event))
2085 (setq insertpos (1- (point)))))
2089 (goto-char insertpos)
2090 (self-insert-command (prefix-numeric-value arg)))
2091 (self-insert-command (prefix-numeric-value arg)))))))
2093 (defun cperl-electric-lbrace (arg &optional end)
2094 "Insert character, correct line's indentation, correct quoting by space."
2096 (let ((cperl-brace-recursing t)
2097 (cperl-auto-newline cperl-auto-newline)
2099 (if (and cperl-electric-parens-mark
2107 (and (cperl-val 'cperl-electric-lbrace-space)
2108 (eq (preceding-char) ?$)
2110 (skip-chars-backward "$")
2111 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
2113 ;; Check whether we are in comment
2117 (not (looking-at "[ \t]*#")))
2118 (cperl-after-expr-p nil "{;)"))
2120 (setq cperl-auto-newline nil))
2121 (cperl-electric-brace arg)
2122 (and (cperl-val 'cperl-electric-parens)
2123 (eq last-command-event ?{)
2124 (memq last-command-event
2125 (append cperl-electric-parens-string nil))
2126 (or (if other-end (goto-char (marker-position other-end)))
2128 (setq last-command-event ?} pos (point))
2129 (progn (cperl-electric-brace arg t)
2132 (defun cperl-electric-paren (arg)
2133 "Insert an opening parenthesis or a matching pair of parentheses.
2134 See `cperl-electric-parens'."
2136 (let ((beg (save-excursion (beginning-of-line) (point)))
2137 (other-end (if (and cperl-electric-parens-mark
2144 (if (and (cperl-val 'cperl-electric-parens)
2145 (memq last-command-event
2146 (append cperl-electric-parens-string nil))
2147 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2148 ;;(not (save-excursion (search-backward "#" beg t)))
2149 (if (eq last-command-event ?<)
2151 (and abbrev-mode ; later it is too late, may be after `for'
2153 (cperl-after-expr-p nil "{;(,:="))
2156 (self-insert-command (prefix-numeric-value arg))
2157 (if other-end (goto-char (marker-position other-end)))
2158 (insert (make-string
2159 (prefix-numeric-value arg)
2160 (cdr (assoc last-command-event '((?{ .?})
2164 (forward-char (- (prefix-numeric-value arg))))
2165 (self-insert-command (prefix-numeric-value arg)))))
2167 (defun cperl-electric-rparen (arg)
2168 "Insert a matching pair of parentheses if marking is active.
2169 If not, or if we are not at the end of marking range, would self-insert.
2170 Affected by `cperl-electric-parens'."
2172 (let ((beg (save-excursion (beginning-of-line) (point)))
2173 (other-end (if (and cperl-electric-parens-mark
2174 (cperl-val 'cperl-electric-parens)
2175 (memq last-command-event
2176 (append cperl-electric-parens-string nil))
2183 (cperl-val 'cperl-electric-parens)
2184 (memq last-command-event '( ?\) ?\] ?\} ?\> ))
2185 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2186 ;;(not (save-excursion (search-backward "#" beg t)))
2189 (self-insert-command (prefix-numeric-value arg))
2191 (if other-end (goto-char other-end))
2192 (insert (make-string
2193 (prefix-numeric-value arg)
2194 (cdr (assoc last-command-event '((?\} . ?\{)
2199 (self-insert-command (prefix-numeric-value arg)))))
2201 (defun cperl-electric-keyword ()
2202 "Insert a construction appropriate after a keyword.
2203 Help message may be switched off by setting `cperl-message-electric-keyword'
2205 (let ((beg (save-excursion (beginning-of-line) (point)))
2206 (dollar (and (eq last-command-event ?$)
2207 (eq this-command 'self-insert-command)))
2208 (delete (and (memq last-command-event '(?\s ?\n ?\t ?\f))
2209 (memq this-command '(self-insert-command newline))))
2211 (and (save-excursion
2215 (setq do (looking-at "do\\>")))
2217 (cperl-after-expr-p nil "{;:"))
2221 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2223 (save-excursion (or (not (re-search-backward "^=" nil t))
2226 (and cperl-use-syntax-table-text-property
2227 (not (eq (get-text-property (point)
2230 (save-excursion (forward-sexp -1)
2231 (not (memq (following-char) (append "$@%&*" nil))))
2233 (and (eq (preceding-char) ?y)
2234 (progn ; "foreachmy"
2240 (memq this-command '(self-insert-command newline)))))
2241 (and dollar (insert " $"))
2243 ;;(insert " () {\n}")
2245 (cperl-extra-newline-before-brace
2246 (insert (if do "\n" " ()\n"))
2252 (and do (insert " while ();")))
2254 (insert (if do " {\n} while ();" " () {\n}"))))
2255 (or (looking-at "[ \t]\\|$") (insert " "))
2257 (if dollar (progn (search-backward "$")
2261 (search-backward ")")
2262 (if (eq last-command-event ?\()
2263 (progn ; Avoid "if (())"
2264 (delete-backward-char 1)
2265 (delete-backward-char -1))))
2267 (cperl-putback-char cperl-del-back-ch))
2268 (if cperl-message-electric-keyword
2269 (message "Precede char by C-q to avoid expansion"))))))
2271 (defun cperl-ensure-newlines (n &optional pos)
2272 "Make sure there are N newlines after the point."
2273 (or pos (setq pos (point)))
2274 (if (looking-at "\n")
2278 (cperl-ensure-newlines (1- n) pos)
2281 (defun cperl-electric-pod ()
2282 "Insert a POD chunk appropriate after a =POD directive."
2283 (let ((delete (and (memq last-command-event '(?\s ?\n ?\t ?\f))
2284 (memq this-command '(self-insert-command newline))))
2285 head1 notlast name p really-delete over)
2286 (and (save-excursion
2289 (eq (preceding-char) ?=)
2291 (setq head1 (looking-at "head1\\>[ \t]*$"))
2292 (setq over (and (looking-at "over\\>[ \t]*$")
2293 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
2297 (get-text-property (point) 'in-pod)
2298 (cperl-after-expr-p nil "{;:")
2299 (and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t)
2300 (not (looking-at "\n*=cut"))
2301 (or (not cperl-use-syntax-table-text-property)
2302 (eq (get-text-property (point) 'syntax-type) 'pod))))))
2305 (setq notlast (re-search-forward "^\n=" nil t)))
2309 (cperl-ensure-newlines 2)
2315 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
2316 nil t)))) ; Only one
2319 (setq name (file-name-sans-extension
2320 (file-name-nondirectory (buffer-file-name)))
2322 (insert " NAME\n\n" name
2323 " - \n\n=head1 SYNOPSIS\n\n\n\n"
2324 "=head1 DESCRIPTION")
2325 (cperl-ensure-newlines 4)
2329 (setq really-delete t))
2334 (insert "\n\n=item \n\n\n\n"
2336 (cperl-ensure-newlines 2)
2340 (setq really-delete t)))
2341 (if (and delete really-delete)
2342 (cperl-putback-char cperl-del-back-ch))))))
2344 (defun cperl-electric-else ()
2345 "Insert a construction appropriate after a keyword.
2346 Help message may be switched off by setting `cperl-message-electric-keyword'
2348 (let ((beg (save-excursion (beginning-of-line) (point))))
2349 (and (save-excursion
2351 (cperl-after-expr-p nil "{;:"))
2355 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2357 (save-excursion (or (not (re-search-backward "^=" nil t))
2359 (and cperl-use-syntax-table-text-property
2360 (not (eq (get-text-property (point)
2365 ;;(insert " {\n\n}")
2367 (cperl-extra-newline-before-brace
2373 (insert " {\n\n}")))
2374 (or (looking-at "[ \t]\\|$") (insert " "))
2378 (cperl-putback-char cperl-del-back-ch)
2379 (setq this-command 'cperl-electric-else)
2380 (if cperl-message-electric-keyword
2381 (message "Precede char by C-q to avoid expansion"))))))
2383 (defun cperl-linefeed ()
2384 "Go to end of line, open a new line and indent appropriately.
2385 If in POD, insert appropriate lines."
2387 (let ((beg (save-excursion (beginning-of-line) (point)))
2388 (end (save-excursion (end-of-line) (point)))
2389 (pos (point)) start over cut res)
2390 (if (and ; Check if we need to split:
2391 ; i.e., on a boundary and inside "{...}"
2392 (save-excursion (cperl-to-comment-or-eol)
2393 (>= (point) pos)) ; Not in a comment
2395 (skip-chars-backward " \t" beg)
2397 (looking-at "[;{]")) ; After { or ; + spaces
2398 (looking-at "[ \t]*}") ; Before }
2399 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
2402 (eq (car (parse-partial-sexp pos end -1)) -1)
2403 ; Leave the level of parens
2404 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
2406 (cperl-after-block-p (point-min))
2409 (setq start (point-marker))
2410 (<= start pos))))) ; Redundant? Are after the
2411 ; start of parens group.
2413 (skip-chars-backward " \t")
2414 (or (memq (preceding-char) (append ";{" nil))
2420 (or (looking-at "{[ \t]*$") ; If there is a statement
2421 ; before, move it to separate line
2425 (cperl-indent-line)))
2426 (forward-line 1) ; We are on the target line
2429 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
2430 ; after, move it to separate line
2433 (search-backward "}" beg)
2434 (skip-chars-backward " \t")
2435 (or (memq (preceding-char) (append ";{" nil))
2440 (forward-line -1) ; We are on the line before target
2442 (newline-and-indent))
2443 (end-of-line) ; else - no splitting
2445 ((and (looking-at "\n[ \t]*{$")
2447 (skip-chars-backward " \t")
2448 (eq (preceding-char) ?\)))) ; Probably if () {} group
2449 ; with an extra newline.
2451 (cperl-indent-line))
2452 ((save-excursion ; In POD header
2453 (forward-paragraph -1)
2454 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
2455 ;; We are after \n now, so look for the rest
2456 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
2458 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
2459 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
2463 (forward-paragraph -1)
2466 (setq cut (buffer-substring (point)
2470 (delete-char (- (save-excursion (end-of-line) (point))
2472 (setq res (expand-abbrev))
2478 (cperl-ensure-newlines (if cut 2 4))
2480 ((get-text-property (point) 'in-pod) ; In POD section
2481 (cperl-ensure-newlines 4)
2483 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
2485 (cperl-indent-line))
2487 (newline-and-indent))))))
2489 (defun cperl-electric-semi (arg)
2490 "Insert character and correct line's indentation."
2492 (if cperl-auto-newline
2493 (cperl-electric-terminator arg)
2494 (self-insert-command (prefix-numeric-value arg))
2495 (if cperl-autoindent-on-semi
2496 (cperl-indent-line))))
2498 (defun cperl-electric-terminator (arg)
2499 "Insert character and correct line's indentation."
2502 (auto (and cperl-auto-newline
2503 (or (not (eq last-command-event ?:))
2504 cperl-auto-newline-after-colon)))
2506 (if (and ;;(not arg)
2508 (not (save-excursion
2510 (skip-chars-forward " \t")
2512 ;; Ignore in comment lines
2513 (= (following-char) ?#)
2514 ;; Colon is special only after a label
2515 ;; So quickly rule out most other uses of colon
2516 ;; and do no indentation for them.
2517 (and (eq last-command-event ?:)
2520 (skip-chars-forward " \t")
2521 (and (< (point) end)
2522 (progn (goto-char (- end 1))
2523 (not (looking-at ":"))))))
2525 (beginning-of-defun)
2526 (let ((pps (parse-partial-sexp (point) end)))
2527 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
2529 (self-insert-command (prefix-numeric-value arg))
2531 (if auto (setq insertpos (point-marker)))
2537 (cperl-indent-line)))
2539 (if insertpos (goto-char (1- (marker-position insertpos)))
2544 (goto-char insertpos)
2545 (self-insert-command (prefix-numeric-value arg)))
2546 (self-insert-command (prefix-numeric-value arg)))))
2548 (defun cperl-electric-backspace (arg)
2549 "Backspace, or remove the whitespace around the point inserted by an electric
2550 key. Will untabify if `cperl-electric-backspace-untabify' is non-nil."
2552 (if (and cperl-auto-newline
2553 (memq last-command '(cperl-electric-semi
2554 cperl-electric-terminator
2555 cperl-electric-lbrace))
2556 (memq (preceding-char) '(?\s ?\t ?\n)))
2558 (if (eq last-command 'cperl-electric-lbrace)
2559 (skip-chars-forward " \t\n"))
2561 (skip-chars-backward " \t\n")
2562 (delete-region (point) p))
2563 (and (eq last-command 'cperl-electric-else)
2564 ;; We are removing the whitespace *inside* cperl-electric-else
2565 (setq this-command 'cperl-electric-else-really))
2566 (if (and cperl-auto-newline
2567 (eq last-command 'cperl-electric-else-really)
2568 (memq (preceding-char) '(?\s ?\t ?\n)))
2570 (skip-chars-forward " \t\n")
2572 (skip-chars-backward " \t\n")
2573 (delete-region (point) p))
2574 (if cperl-electric-backspace-untabify
2575 (backward-delete-char-untabify arg)
2576 (delete-backward-char arg)))))
2578 (put 'cperl-electric-backspace 'delete-selection 'supersede)
2580 (defun cperl-inside-parens-p () ;; NOT USED????
2584 (narrow-to-region (point)
2585 (progn (beginning-of-defun) (point)))
2586 (goto-char (point-max))
2587 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
2590 (defun cperl-indent-command (&optional whole-exp)
2591 "Indent current line as Perl code, or in some cases insert a tab character.
2592 If `cperl-tab-always-indent' is non-nil (the default), always indent current
2593 line. Otherwise, indent the current line only if point is at the left margin
2594 or in the line's indentation; otherwise insert a tab.
2596 A numeric argument, regardless of its value,
2597 means indent rigidly all the lines of the expression starting after point
2598 so that this line becomes properly indented.
2599 The relative indentation among the lines of the expression are preserved."
2601 (cperl-update-syntaxification (point) (point))
2603 ;; If arg, always indent this line as Perl
2604 ;; and shift remaining lines of expression the same amount.
2605 (let ((shift-amt (cperl-indent-line))
2608 (if cperl-tab-always-indent
2609 (beginning-of-line))
2616 (if (and shift-amt (> end beg))
2617 (indent-code-rigidly beg end shift-amt "#")))
2618 (if (and (not cperl-tab-always-indent)
2620 (skip-chars-backward " \t")
2623 (cperl-indent-line))))
2625 (defun cperl-indent-line (&optional parse-data)
2626 "Indent current line as Perl code.
2627 Return the amount the indentation changed by."
2628 (let ((case-fold-search nil)
2629 (pos (- (point-max) (point)))
2630 indent i beg shift-amt)
2631 (setq indent (cperl-calculate-indent parse-data)
2635 (cond ((or (eq indent nil) (eq indent t))
2636 (setq indent (current-indentation) i nil))
2637 ;;((eq indent t) ; Never?
2638 ;; (setq indent (cperl-calculate-indent-within-comment)))
2639 ;;((looking-at "[ \t]*#")
2642 (skip-chars-forward " \t")
2643 (if (listp indent) (setq indent (car indent)))
2644 (cond ((and (looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
2645 (not (looking-at "[smy]:\\|tr:")))
2647 (setq indent (max cperl-min-label-indent
2648 (+ indent cperl-label-offset)))))
2649 ((= (following-char) ?})
2650 (setq indent (- indent cperl-indent-level)))
2651 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
2652 (setq indent (+ indent cperl-close-paren-offset)))
2653 ((= (following-char) ?{)
2654 (setq indent (+ indent cperl-brace-offset))))))
2655 (skip-chars-forward " \t")
2656 (setq shift-amt (and i (- indent (current-column))))
2657 (if (or (not shift-amt)
2659 (if (> (- (point-max) pos) (point))
2660 (goto-char (- (point-max) pos)))
2661 ;;;(delete-region beg (point))
2662 ;;;(indent-to indent)
2663 (cperl-make-indent indent)
2664 ;; If initial point was within line's indentation,
2665 ;; position after the indentation. Else stay at same point in text.
2666 (if (> (- (point-max) pos) (point))
2667 (goto-char (- (point-max) pos))))
2670 (defun cperl-after-label ()
2671 ;; Returns true if the point is after label. Does not do save-excursion.
2672 (and (eq (preceding-char) ?:)
2673 (memq (char-syntax (char-after (- (point) 2)))
2677 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
2679 (defun cperl-get-state (&optional parse-start start-state)
2680 ;; returns list (START STATE DEPTH PRESTART),
2681 ;; START is a good place to start parsing, or equal to
2682 ;; PARSE-START if preset,
2683 ;; STATE is what is returned by `parse-partial-sexp'.
2684 ;; DEPTH is true is we are immediately after end of block
2685 ;; which contains START.
2686 ;; PRESTART is the position basing on which START was found.
2688 (let ((start-point (point)) depth state start prestart)
2689 (if (and parse-start
2690 (<= parse-start start-point))
2691 (goto-char parse-start)
2692 (beginning-of-defun)
2693 (setq start-state nil))
2694 (setq prestart (point))
2696 ;; Try to go out, if sub is not on the outermost level
2697 (while (< (point) start-point)
2698 (setq start (point) parse-start start depth nil
2699 state (parse-partial-sexp start start-point -1))
2700 (if (> (car state) -1) nil
2701 ;; The current line could start like }}}, so the indentation
2702 ;; corresponds to a different level than what we reached
2704 (beginning-of-line 2))) ; Go to the next line.
2705 (if start (goto-char start))) ; Not at the start of file
2706 (setq start (point))
2707 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
2708 (list start state depth prestart))))
2710 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
2712 (defun cperl-beginning-of-property (p prop &optional lim)
2713 "Given that P has a property PROP, find where the property starts.
2714 Will not look before LIM."
2715 ;;; XXXX What to do at point-max???
2716 (or (previous-single-property-change (cperl-1+ p) prop lim)
2718 ;;; (cond ((eq p (point-min))
2720 ;;; ((and lim (<= p lim))
2722 ;;; ((not (get-text-property (1- p) prop))
2724 ;;; (t (or (previous-single-property-change p look-prop lim)
2728 (defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start
2729 ;; Old workhorse for calculation of indentation; the major problem
2730 ;; is that it mixes the sniffer logic to understand what the current line
2731 ;; MEANS with the logic to actually calculate where to indent it.
2732 ;; The latter part should be eventually moved to `cperl-calculate-indent';
2733 ;; actually, this is mostly done now...
2734 (cperl-update-syntaxification (point) (point))
2735 (let ((res (get-text-property (point) 'syntax-type)))
2738 ((and (memq res '(pod here-doc here-doc-delim format))
2739 (not (get-text-property (point) 'indentable)))
2741 ;; before start of POD - whitespace found since do not have 'pod!
2742 ((looking-at "[ \t]*\n=")
2743 (error "Spaces before POD section!"))
2744 ((and (not cperl-indent-left-aligned-comments)
2746 [comment-special:at-beginning-of-line])
2747 ((get-text-property (point) 'in-pod)
2751 (let* ((indent-point (point))
2752 (char-after-pos (save-excursion
2753 (skip-chars-forward " \t")
2755 (char-after (char-after char-after-pos))
2756 (pre-indent-point (point))
2757 p prop look-prop is-block delim)
2758 (save-excursion ; Know we are not in POD, find appropriate pos before
2759 (cperl-backward-to-noncomment nil)
2760 (setq p (max (point-min) (1- (point)))
2761 prop (get-text-property p 'syntax-type)
2762 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
2764 (if (memq prop '(pod here-doc format here-doc-delim))
2766 (goto-char (cperl-beginning-of-property p look-prop))
2768 (setq pre-indent-point (point)))))
2769 (goto-char pre-indent-point) ; Orig line skipping preceeding pod/etc
2770 (let* ((case-fold-search nil)
2771 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
2772 (start (or (nth 2 parse-data) ; last complete sexp terminated
2773 (nth 0 s-s))) ; Good place to start parsing
2775 (containing-sexp (car (cdr state)))
2778 ;;containing-sexp ;; We are buggy at toplevel :-(
2781 (setcar parse-data pre-indent-point)
2782 (setcar (cdr parse-data) state)
2783 (or (nth 2 parse-data)
2784 (setcar (cddr parse-data) start))
2785 ;; Before this point: end of statement
2786 (setq old-indent (nth 3 parse-data))))
2787 (cond ((get-text-property (point) 'indentable)
2788 ;; indent to "after" the surrounding open
2789 ;; (same offset as `cperl-beautify-regexp-piece'),
2790 ;; skip blanks if we do not close the expression.
2791 (setq delim ; We do not close the expression
2793 (cperl-1+ char-after-pos) 'indentable)
2794 p (1+ (cperl-beginning-of-property
2795 (point) 'indentable))
2796 is-block ; misused for: preceeding line in REx
2797 (save-excursion ; Find preceeding line
2798 (cperl-backward-to-noncomment p)
2801 (progn ; get indent from the first line
2803 (skip-chars-forward " \t")
2804 (if (memq (char-after (point))
2806 nil ; Can't use intentation of this line...
2808 (skip-chars-forward " \t")
2810 prop (parse-partial-sexp p char-after-pos))
2811 (cond ((not delim) ; End the REx, ignore is-block
2812 (vector 'indentable 'terminator p is-block))
2813 (is-block ; Indent w.r.t. preceeding line
2814 (vector 'indentable 'cont-line char-after-pos
2815 is-block char-after p))
2816 (t ; No preceeding line...
2817 (vector 'indentable 'first-line p))))
2818 ((get-text-property char-after-pos 'REx-part2)
2819 (vector 'REx-part2 (point)))
2824 ;; XXXX Do we need to special-case this?
2825 ((null containing-sexp)
2826 ;; Line is at top level. May be data or function definition,
2827 ;; or may be function argument declaration.
2828 ;; Indent like the previous top level line
2829 ;; unless that ends in a closeparen without semicolon,
2830 ;; in which case this line is the first argument decl.
2831 (skip-chars-forward " \t")
2832 (cperl-backward-to-noncomment (or old-indent (point-min)))
2835 (eq (point) old-indent) ; old-indent was at comment
2836 (eq (preceding-char) ?\;)
2838 (and (eq (preceding-char) ?\})
2839 (cperl-after-block-and-statement-beg
2840 (point-min))) ; Was start - too close
2841 (memq char-after (append ")]}" nil))
2842 (and (eq (preceding-char) ?\:) ; label
2845 (skip-chars-backward " \t")
2846 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
2847 (get-text-property (point) 'first-format-line)))
2849 ;; Look at previous line that's at column 0
2850 ;; to determine whether we are in top-level decls
2851 ;; or function's arg decls. Set basic-indent accordingly.
2852 ;; Now add a little if this is a continuation line.
2855 (not (eq char-after ?\C-j))
2856 (setcdr (cddr parse-data)
2857 (list pre-indent-point)))
2858 (vector 'toplevel start char-after state (nth 2 s-s)))
2861 (and (setq delim (= (char-after containing-sexp) ?{))
2862 (save-excursion ; Is it a hash?
2863 (goto-char containing-sexp)
2865 cperl-indent-parens-as-block))
2866 ;; group is an expression, not a block:
2867 ;; indent to just after the surrounding open parens,
2868 ;; skip blanks if we do not close the expression.
2869 (goto-char (1+ containing-sexp))
2870 (or (memq char-after
2871 (append (if delim "}" ")]}") nil))
2872 (looking-at "[ \t]*\\(#\\|$\\)")
2873 (skip-chars-forward " \t"))
2874 (setq old-indent (point)) ; delim=is-brace
2875 (vector 'in-parens char-after (point) delim containing-sexp))
2877 ;; Statement level. Is it a continuation or a new statement?
2878 ;; Find previous non-comment character.
2879 (goto-char pre-indent-point) ; Skip one level of POD/etc
2880 (cperl-backward-to-noncomment containing-sexp)
2881 ;; Back up over label lines, since they don't
2882 ;; affect whether our line is a continuation.
2884 (while;;(or (eq (preceding-char) ?\,)
2885 (and (eq (preceding-char) ?:)
2886 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
2887 (memq (char-syntax (char-after (- (point) 2)))
2890 ;; This is always FALSE?
2891 (if (eq (preceding-char) ?\,)
2892 ;; Will go to beginning of line, essentially.
2893 ;; Will ignore embedded sexpr XXXX.
2894 (cperl-backward-to-start-of-continued-exp containing-sexp))
2896 (cperl-backward-to-noncomment containing-sexp))
2897 ;; Now we get non-label preceeding the indent point
2898 (if (not (or (eq (1- (point)) containing-sexp)
2899 (memq (preceding-char)
2900 (append (if is-block " ;{" " ,;{") '(nil)))
2901 (and (eq (preceding-char) ?\})
2902 (cperl-after-block-and-statement-beg
2904 (get-text-property (point) 'first-format-line)))
2905 ;; This line is continuation of preceding line's statement;
2906 ;; indent `cperl-continued-statement-offset' more than the
2907 ;; previous line of the statement.
2909 ;; There might be a label on this line, just
2910 ;; consider it bad style and ignore it.
2912 (cperl-backward-to-start-of-continued-exp containing-sexp)
2913 (vector 'continuation (point) char-after is-block delim))
2914 ;; This line starts a new statement.
2915 ;; Position following last unclosed open brace
2916 (goto-char containing-sexp)
2917 ;; Is line first statement after an open-brace?
2919 ;; If no, find that first statement and indent like
2920 ;; it. If the first statement begins with label, do
2921 ;; not believe when the indentation of the label is too
2925 (let ((colon-line-end 0))
2927 (progn (skip-chars-forward " \t\n")
2928 ;; s: foo : bar :x is NOT label
2929 (and (looking-at "#\\|\\([a-zA-Z0-9_$]+\\):[^:]\\|=[a-zA-Z]")
2930 (not (looking-at "[sym]:\\|tr:"))))
2931 ;; Skip over comments and labels following openbrace.
2932 (cond ((= (following-char) ?\#)
2934 ((= (following-char) ?\=)
2936 (or (next-single-property-change (point) 'in-pod)
2937 (point-max)))) ; do not loop if no syntaxification
2940 (save-excursion (end-of-line)
2941 (setq colon-line-end (point)))
2942 (search-forward ":"))))
2943 ;; We are at beginning of code (NOT label or comment)
2944 ;; First, the following code counts
2945 ;; if it is before the line we want to indent.
2946 (and (< (point) indent-point)
2947 (vector 'have-prev-sibling (point) colon-line-end
2950 ;; If no previous statement,
2951 ;; indent it relative to line brace is on.
2953 ;; For open-braces not the first thing in a line,
2954 ;; add in cperl-brace-imaginary-offset.
2956 ;; If first thing on a line: ?????
2957 ;; Move back over whitespace before the openbrace.
2958 (setq ; brace first thing on a line
2959 old-indent (progn (skip-chars-backward " \t") (bolp)))
2960 ;; Should we indent w.r.t. earlier than start?
2961 ;; Move to start of control group, possibly on a different line
2962 (or cperl-indent-wrt-brace
2963 (cperl-backward-to-noncomment (point-min)))
2964 ;; If the openbrace is preceded by a parenthesized exp,
2965 ;; move to the beginning of that;
2966 (if (eq (preceding-char) ?\))
2969 (cperl-backward-to-noncomment (point-min))))
2970 ;; In the case it starts a subroutine, indent with
2971 ;; respect to `sub', not with respect to the
2972 ;; first thing on the line, say in the case of
2973 ;; anonymous sub in a hash.
2974 (if (and;; Is it a sub in group starting on this line?
2975 (cond ((get-text-property (point) 'attrib-group)
2976 (goto-char (cperl-beginning-of-property
2977 (point) 'attrib-group)))
2978 ((eq (preceding-char) ?b)
2980 (looking-at "sub\\>")))
2981 (setq p (nth 1 ; start of innermost containing list
2983 (save-excursion (beginning-of-line)
2987 (goto-char (1+ p)) ; enclosing block on the same line
2988 (skip-chars-forward " \t")
2989 (vector 'code-start-in-block containing-sexp char-after
2990 (and delim (not is-block)) ; is a HASH
2991 old-indent ; brace first thing on a line
2992 t (point) ; have something before...
2996 ;; Get initial indentation of the line we are on.
2997 ;; If line starts with label, calculate label indentation
2998 (vector 'code-start-in-block containing-sexp char-after
2999 (and delim (not is-block)) ; is a HASH
3000 old-indent ; brace first thing on a line
3001 nil (point))))))))))))))) ; nothing interesting before
3003 (defvar cperl-indent-rules-alist
3004 '((pod nil) ; via `syntax-type' property
3005 (here-doc nil) ; via `syntax-type' property
3006 (here-doc-delim nil) ; via `syntax-type' property
3007 (format nil) ; via `syntax-type' property
3008 (in-pod nil) ; via `in-pod' property
3009 (comment-special:at-beginning-of-line nil)
3012 "Alist of indentation rules for CPerl mode.
3015 number: add this amount of indentation.")
3017 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
3018 "Return appropriate indentation for current line as Perl code.
3019 In usual case returns an integer: the column to indent to.
3020 Returns nil if line starts inside a string, t if in a comment.
3022 Will not correct the indentation for labels, but will correct it for braces
3023 and closing parentheses and brackets."
3024 ;; This code is still a broken architecture: in some cases we need to
3025 ;; compensate for some modifications which `cperl-indent-line' will add later
3027 (let ((i (cperl-sniff-for-indent parse-data)) what p)
3029 ;;((or (null i) (eq i t) (numberp i))
3032 (setq what (assoc (elt i 0) cperl-indent-rules-alist))
3034 (what (cadr what)) ; Load from table
3036 ;; Indenters for regular expressions with //x and qw()
3038 ((eq 'REx-part2 (elt i 0)) ;; [self start] start of /REP in s//REP/x
3039 (goto-char (elt i 1))
3040 (condition-case nil ; Use indentation of the 1st part
3043 ((eq 'indentable (elt i 0)) ; Indenter for REGEXP qw() etc
3044 (cond ;;; [indentable terminator start-pos is-block]
3045 ((eq 'terminator (elt i 1)) ; Lone terminator of "indentable string"
3046 (goto-char (elt i 2)) ; After opening parens
3047 (1- (current-column)))
3048 ((eq 'first-line (elt i 1)); [indentable first-line start-pos]
3049 (goto-char (elt i 2))
3050 (+ (or cperl-regexp-indent-step cperl-indent-level)
3053 ((eq 'cont-line (elt i 1)); [indentable cont-line pos prev-pos first-char start-pos]
3054 ;; Indent as the level after closing parens
3055 (goto-char (elt i 2)) ; indent line
3056 (skip-chars-forward " \t)") ; Skip closing parens
3058 (goto-char (elt i 3)) ; previous line
3059 (skip-chars-forward " \t)") ; Skip closing parens
3060 ;; Number of parens in between:
3061 (setq p (nth 0 (parse-partial-sexp (point) p))
3062 what (elt i 4)) ; First char on current line
3063 (goto-char (elt i 3)) ; previous line
3064 (+ (* p (or cperl-regexp-indent-step cperl-indent-level))
3065 (cond ((eq what ?\) )
3066 (- cperl-close-paren-offset)) ; compensate
3068 (- (or cperl-regexp-indent-step cperl-indent-level)))
3070 (if (eq (following-char) ?\| )
3071 (or cperl-regexp-indent-step cperl-indent-level)
3075 (error "Unrecognized value of indent: %s" i))))
3077 ;; Indenter for stuff at toplevel
3079 ((eq 'toplevel (elt i 0)) ;; [toplevel start char-after state immed-after-block]
3080 (+ (save-excursion ; To beg-of-defun, or end of last sexp
3081 (goto-char (elt i 1)) ; start = Good place to start parsing
3082 (- (current-indentation) ;
3083 (if (elt i 4) cperl-indent-level 0))) ; immed-after-block
3084 (if (eq (elt i 2) ?{) cperl-continued-brace-offset 0) ; char-after
3085 ;; Look at previous line that's at column 0
3086 ;; to determine whether we are in top-level decls
3087 ;; or function's arg decls. Set basic-indent accordingly.
3088 ;; Now add a little if this is a continuation line.
3089 (if (elt i 3) ; state (XXX What is the semantic???)
3091 cperl-continued-statement-offset)))
3093 ;; Indenter for stuff in "parentheses" (or brackets, braces-as-hash)
3095 ((eq 'in-parens (elt i 0))
3096 ;; in-parens char-after old-indent-point is-brace containing-sexp
3098 ;; group is an expression, not a block:
3099 ;; indent to just after the surrounding open parens,
3100 ;; skip blanks if we do not close the expression.
3102 (goto-char (elt i 2)) ; old-indent-point
3104 (if (and (elt i 3) ; is-brace
3105 (eq (elt i 1) ?\})) ; char-after
3106 ;; Correct indentation of trailing ?\}
3107 (+ cperl-indent-level cperl-close-paren-offset)
3110 ;; Indenter for continuation lines
3112 ((eq 'continuation (elt i 0))
3113 ;; [continuation statement-start char-after is-block is-brace]
3114 (goto-char (elt i 1)) ; statement-start
3115 (+ (if (memq (elt i 2) (append "}])" nil)) ; char-after
3117 cperl-continued-statement-offset)
3118 (if (or (elt i 3) ; is-block
3119 (not (elt i 4)) ; is-brace
3120 (not (eq (elt i 2) ?\}))) ; char-after
3122 ;; Now it is a hash reference
3123 (+ cperl-indent-level cperl-close-paren-offset))
3124 ;; Labels do not take :: ...
3125 (if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
3126 (if (> (current-indentation) cperl-min-label-indent)
3127 (- (current-indentation) cperl-label-offset)
3128 ;; Do not move `parse-data', this should
3129 ;; be quick anyway (this comment comes
3130 ;; from different location):
3131 (cperl-calculate-indent))
3133 (if (eq (elt i 2) ?\{) ; char-after
3134 cperl-continued-brace-offset 0)))
3136 ;; Indenter for lines in a block which are not leading lines
3138 ((eq 'have-prev-sibling (elt i 0))
3139 ;; [have-prev-sibling sibling-beg colon-line-end block-start]
3140 (goto-char (elt i 1)) ; sibling-beg
3141 (if (> (elt i 2) (point)) ; colon-line-end; have label before point
3142 (if (> (current-indentation)
3143 cperl-min-label-indent)
3144 (- (current-indentation) cperl-label-offset)
3145 ;; Do not believe: `max' was involved in calculation of indent
3146 (+ cperl-indent-level
3148 (goto-char (elt i 3)) ; block-start
3149 (current-indentation))))
3152 ;; Indenter for the first line in a block
3154 ((eq 'code-start-in-block (elt i 0))
3155 ;;[code-start-in-block before-brace char-after
3156 ;; is-a-HASH-ref brace-is-first-thing-on-a-line
3157 ;; group-starts-before-start-of-sub start-of-control-group]
3158 (goto-char (elt i 1))
3159 ;; For open brace in column zero, don't let statement
3160 ;; start there too. If cperl-indent-level=0,
3161 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3162 (+ (if (and (bolp) (zerop cperl-indent-level))
3163 (+ cperl-brace-offset cperl-continued-statement-offset)
3165 (if (and (elt i 3) ; is-a-HASH-ref
3166 (eq (elt i 2) ?\})) ; char-after: End of a hash reference
3167 (+ cperl-indent-level cperl-close-paren-offset)
3169 ;; Unless openbrace is the first nonwhite thing on the line,
3170 ;; add the cperl-brace-imaginary-offset.
3171 (if (elt i 4) 0 ; brace-is-first-thing-on-a-line
3172 cperl-brace-imaginary-offset)
3174 (goto-char (elt i 6)) ; start-of-control-group
3175 (if (elt i 5) ; group-starts-before-start-of-sub
3177 ;; Get initial indentation of the line we are on.
3178 ;; If line starts with label, calculate label indentation
3181 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3182 (if (> (current-indentation) cperl-min-label-indent)
3183 (- (current-indentation) cperl-label-offset)
3184 ;; Do not move `parse-data', this should
3186 (cperl-calculate-indent))
3187 (current-indentation))))))
3189 (error "Unrecognized value of indent: %s" i))))
3191 (error "Got strange value of indent: %s" i))))))
3193 (defun cperl-calculate-indent-within-comment ()
3194 "Return the indentation amount for line, assuming that
3195 the current line is to be regarded as part of a block comment."
3196 (let (end star-start)
3199 (skip-chars-forward " \t")
3201 (and (= (following-char) ?#)
3203 (cperl-to-comment-or-eol)
3209 (defun cperl-to-comment-or-eol ()
3210 "Go to position before comment on the current line, or to end of line.
3211 Returns true if comment is found. In POD will not move the point."
3212 ;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
3213 ;; then looks for literal # or end-of-line.
3214 (let (state stop-in cpoint (lim (progn (end-of-line) (point))) pr e)
3215 (or cperl-font-locking
3216 (cperl-update-syntaxification lim lim))
3218 (if (setq pr (get-text-property (point) 'syntax-type))
3219 (setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
3220 (if (or (eq pr 'pod)
3221 (if (or (not e) (> e lim)) ; deep inside a group
3222 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
3223 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
3224 ;; Else - need to do it the hard way
3225 (and (and e (<= e lim))
3227 (while (not stop-in)
3228 (setq state (parse-partial-sexp (point) lim nil nil nil t))
3230 ;; If fails (beginning-of-line inside sexp), then contains not-comment
3231 (if (nth 4 state) ; After `#';
3232 ; (nth 2 state) can be
3233 ; beginning of m,s,qq and so
3237 (setq cpoint (point))
3238 (goto-char (nth 2 state))
3240 ((looking-at "\\(s\\|tr\\)\\>")
3241 (or (re-search-forward
3242 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
3245 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
3246 (or (re-search-forward
3247 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
3250 (t ; It was fair comment
3251 (setq stop-in t) ; Finish
3252 (goto-char (1- cpoint)))))
3253 (setq stop-in t) ; Finish
3255 (setq stop-in t))) ; Finish
3258 (defsubst cperl-modify-syntax-type (at how)
3259 (if (< at (point-max))
3261 (put-text-property at (1+ at) 'syntax-table how)
3262 (put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
3264 (defun cperl-protect-defun-start (s e)
3265 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
3268 (while (re-search-forward "^\\s(" e 'to-end)
3269 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
3271 (defun cperl-commentify (bb e string &optional noface)
3272 (if cperl-use-syntax-table-text-property
3273 (if (eq noface 'n) ; Only immediate
3275 ;; We suppose that e is _after_ the end of construction, as after eol.
3276 (setq string (if string cperl-st-sfence cperl-st-cfence))
3278 ;; one-char string/comment?!
3279 (cperl-modify-syntax-type bb cperl-st-punct)
3280 (cperl-modify-syntax-type bb string)
3281 (cperl-modify-syntax-type (1- e) string))
3282 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
3283 (put-text-property (1+ bb) (1- e)
3284 'syntax-table cperl-string-syntax-table))
3285 (cperl-protect-defun-start bb e))
3288 (not cperl-pod-here-fontify)
3289 (put-text-property bb e 'face (if string 'font-lock-string-face
3290 'font-lock-comment-face)))))
3292 (defvar cperl-starters '(( ?\( . ?\) )
3297 (defun cperl-cached-syntax-table (st)
3298 "Get a syntax table cached in ST, or create and cache into ST a syntax table.
3299 All the entries of the syntax table are \".\", except for a backslash, which
3303 (setcar st (make-syntax-table))
3307 (modify-syntax-entry i "." st)
3309 (modify-syntax-entry ?\\ "\\" st)
3312 (defun cperl-forward-re (lim end is-2arg st-l err-l argument
3313 &optional ostart oend)
3314 "Find the end of a regular expression or a stringish construct (q[] etc).
3315 The point should be before the starting delimiter.
3317 Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
3318 is s/// or tr/// like expression. If END is nil, generates an error
3319 message if needed. If SET-ST is non-nil, will use (or generate) a
3320 cached syntax table in ST-L. If ERR-L is non-nil, will store the
3321 error message in its CAR (unless it already contains some error
3322 message). ARGUMENT should be the name of the construct (used in error
3323 messages). OSTART, OEND may be set in recursive calls when processing
3324 the second argument of 2ARG construct.
3326 Works *before* syntax recognition is done. In IS-2ARG situation may
3327 modify syntax-type text property if the situation is too hard."
3328 (let (b starter ender st i i2 go-forward reset-st set-st)
3329 (skip-chars-forward " \t")
3330 ;; ender means matching-char matcher.
3332 starter (if (eobp) 0 (char-after b))
3333 ender (cdr (assoc starter cperl-starters)))
3334 ;; What if starter == ?\\ ????
3335 (setq st (cperl-cached-syntax-table st-l))
3337 ;; Whether we have an intermediate point
3339 ;; Prepare the syntax table:
3340 (if (not ender) ; m/blah/, s/x//, s/x/y/
3341 (modify-syntax-entry starter "$" st)
3342 (modify-syntax-entry starter (concat "(" (list ender)) st)
3343 (modify-syntax-entry ender (concat ")" (list starter)) st))
3346 ;; We use `$' syntax class to find matching stuff, but $$
3347 ;; is recognized the same as $, so we need to check this manually.
3348 (if (and (eq starter (char-after (cperl-1+ b)))
3350 ;; $ has TeXish matching rules, so $$ equiv $...
3352 (setq reset-st (syntax-table))
3353 (set-syntax-table st)
3355 (if (<= (point) (1+ b))
3356 (error "Unfinished regular expression"))
3357 (set-syntax-table reset-st)
3359 ;; Now the problem is with m;blah;;
3361 (eq (preceding-char)
3362 (char-after (- (point) 2)))
3365 (= 0 (% (skip-chars-backward "\\\\") 2)))
3367 ;; Now we are after the first part.
3368 (and is-2arg ; Have trailing part
3370 (eq (following-char) starter) ; Empty trailing part
3372 (or (eq (char-syntax (following-char)) ?.)
3373 ;; Make trailing letter into punctuation
3374 (cperl-modify-syntax-type (point) cperl-st-punct))
3375 (setq is-2arg nil go-forward t))) ; Ignore the tail
3376 (if is-2arg ; Not number => have second part
3378 (setq i (point) i2 i)
3380 (if (memq (following-char) '(?\s ?\t ?\n ?\f))
3382 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3383 (goto-char (match-end 0))
3384 (skip-chars-forward " \t\n\f"))
3387 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3388 (if ender (modify-syntax-entry ender "." st))
3390 (setq ender (cperl-forward-re lim end nil st-l err-l
3391 argument starter ender)
3392 ender (nth 2 ender)))))
3393 (error (goto-char lim)
3396 (set-syntax-table reset-st))
3399 "End of `%s%s%c ... %c' string/RE not found: %s"
3401 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
3402 starter (or ender starter) bb)
3403 (or (car err-l) (setcar err-l b)))))
3406 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3407 (if ender (modify-syntax-entry ender "." st))))
3408 ;; i: have 2 args, after end of the first arg
3409 ;; i2: start of the second arg, if any (before delim if `ender').
3410 ;; ender: the last arg bounded by parens-like chars, the second one of them
3411 ;; starter: the starting delimiter of the first arg
3412 ;; go-forward: has 2 args, and the second part is empty
3413 (list i i2 ender starter go-forward)))
3415 (defun cperl-forward-group-in-re (&optional st-l)
3416 "Find the end of a group in a REx.
3417 Return the error message (if any). Does not work if delimiter is `)'.
3418 Works before syntax recognition is done."
3419 ;; Works *before* syntax recognition is done
3420 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3421 (let (st b reset-st)
3424 (setq st (cperl-cached-syntax-table st-l))
3425 (modify-syntax-entry ?\( "()" st)
3426 (modify-syntax-entry ?\) ")(" st)
3427 (setq reset-st (syntax-table))
3428 (set-syntax-table st)
3431 "cperl-forward-group-in-re: error %s" b)))
3432 ;; now restore the initial state
3435 (modify-syntax-entry ?\( "." st)
3436 (modify-syntax-entry ?\) "." st)))
3438 (set-syntax-table reset-st))
3442 (defvar font-lock-string-face)
3443 ;;(defvar font-lock-reference-face)
3444 (defvar font-lock-constant-face)
3445 (defsubst cperl-postpone-fontification (b e type val &optional now)
3446 ;; Do after syntactic fontification?
3447 (if cperl-syntaxify-by-font-lock
3448 (or now (put-text-property b e 'cperl-postpone (cons type val)))
3449 (put-text-property b e type val)))
3451 ;;; Here is how the global structures (those which cannot be
3452 ;;; recognized locally) are marked:
3454 ;; Start-to-end is marked `in-pod' ==> t
3455 ;; Each non-literal part is marked `syntax-type' ==> `pod'
3456 ;; Each literal part is marked `syntax-type' ==> `in-pod'
3458 ;; Start-to-end is marked `here-doc-group' ==> t
3459 ;; The body is marked `syntax-type' ==> `here-doc'
3460 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
3462 ;; First line (to =) marked `first-format-line' ==> t
3463 ;; After-this--to-end is marked `syntax-type' ==> `format'
3464 ;; d) 'Q'uoted string:
3465 ;; part between markers inclusive is marked `syntax-type' ==> `string'
3466 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
3467 ;; second part of s///e is marked `syntax-type' ==> `multiline'
3468 ;; e) Attributes of subroutines: `attrib-group' ==> t
3469 ;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
3470 ;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
3472 ;;; In addition, some parts of RExes may be marked as `REx-interpolated'
3473 ;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
3475 (defun cperl-unwind-to-safe (before &optional end)
3476 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
3477 (let ((pos (point)) opos)
3478 (while (and pos (progn
3480 (get-text-property (setq pos (point)) 'syntax-type)))
3482 pos (cperl-beginning-of-property pos 'syntax-type))
3483 (if (eq pos (point-min))
3488 (goto-char (cperl-1- pos))
3491 (goto-char (setq pos (cperl-1- pos))))
3493 (goto-char (point-min))))
3495 (and (looking-at "\n*=")
3496 (/= 0 (skip-chars-backward "\n"))
3500 ;; Do the same for end, going small steps
3502 (while (and end (get-text-property end 'syntax-type))
3504 end (next-single-property-change end 'syntax-type nil (point-max)))
3505 (if end (progn (goto-char end)
3506 (or (bolp) (forward-line 1))
3507 (setq end (point)))))
3510 ;;; These are needed for byte-compile (at least with v19)
3511 (defvar cperl-nonoverridable-face)
3512 (defvar font-lock-variable-name-face)
3513 (defvar font-lock-function-name-face)
3514 (defvar font-lock-keyword-face)
3515 (defvar font-lock-builtin-face)
3516 (defvar font-lock-type-face)
3517 (defvar font-lock-comment-face)
3518 (defvar font-lock-warning-face)
3520 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
3521 "Syntaxically mark (and fontify) attributes of a subroutine.
3522 Should be called with the point before leading colon of an attribute."
3523 ;; Works *before* syntax recognition is done
3524 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3525 (let (st b p reset-st after-first (start (point)) start1 end1)
3529 "\\(" ; 1=optional? colon
3530 ":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
3532 (if after-first "?" "")
3533 ;; No space between name and paren allowed...
3534 "\\(\\sw+\\)" ; 3=name
3535 "\\((\\)?")) ; 4=optional paren
3536 (and (match-beginning 1)
3537 (cperl-postpone-fontification
3538 (match-beginning 0) (cperl-1+ (match-beginning 0))
3539 'face font-lock-constant-face))
3540 (setq start1 (match-beginning 3) end1 (match-end 3))
3541 (cperl-postpone-fontification start1 end1
3542 'face font-lock-constant-face)
3543 (goto-char end1) ; end or before `('
3544 (if (match-end 4) ; Have attribute arguments...
3547 (setq st (cperl-cached-syntax-table st-l))
3548 (modify-syntax-entry ?\( "()" st)
3549 (modify-syntax-entry ?\) ")(" st))
3550 (setq reset-st (syntax-table) p (point))
3551 (set-syntax-table st)
3553 (set-syntax-table reset-st)
3555 (cperl-commentify p (point) t))) ; mark as string
3556 (forward-comment (buffer-size))
3557 (setq after-first t))
3559 "L%d: attribute `%s': %s"
3560 (count-lines (point-min) (point))
3561 (and start1 end1 (buffer-substring start1 end1)) b)
3565 (put-text-property start (point)
3566 'attrib-group (if (looking-at "{") t 0))
3568 (< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
3569 ;; Apparently, we do not need `multiline': faces added now
3570 (put-text-property (+ 3 pos) (cperl-1+ (point))
3571 'syntax-type 'sub-decl))
3572 (and b-fname ; Fontify here: the following condition
3573 (cperl-postpone-fontification ; is too hard to determine by
3574 b-fname e-fname 'face ; a REx, so do it here
3575 (if (looking-at "{")
3576 font-lock-function-name-face
3577 font-lock-variable-name-face)))))
3578 ;; now restore the initial state
3581 (modify-syntax-entry ?\( "." st)
3582 (modify-syntax-entry ?\) "." st)))
3584 (set-syntax-table reset-st))))
3586 (defsubst cperl-look-at-leading-count (is-x-REx e)
3589 (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
3590 (1- e) t)) ; return nil on failure, no moving
3591 (if (eq ?\{ (preceding-char)) nil
3592 (cperl-postpone-fontification
3593 (1- (point)) (point)
3594 'face font-lock-warning-face))))
3596 ;;; Debugging this may require (setq max-specpdl-size 2000)...
3597 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc)
3598 "Scans the buffer for hard-to-parse Perl constructions.
3599 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
3600 the sections using `cperl-pod-head-face', `cperl-pod-face',
3603 (or min (setq min (point-min)
3604 cperl-syntax-state nil
3605 cperl-syntax-done-to min))
3606 (or max (setq max (point-max)))
3607 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
3608 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
3609 is-REx is-x-REx REx-subgr-start REx-subgr-end was-subgr i2 hairy-RE
3610 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
3611 (modified (buffer-modified-p)) overshoot is-o-REx
3612 (after-change-functions nil)
3613 (cperl-font-locking t)
3614 (use-syntax-state (and cperl-syntax-state
3615 (>= min (car cperl-syntax-state))))
3616 (state-point (if use-syntax-state
3617 (car cperl-syntax-state)
3619 (state (if use-syntax-state
3620 (cdr cperl-syntax-state)))
3621 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
3622 (st-l (list nil)) (err-l (list nil))
3623 ;; Somehow font-lock may be not loaded yet...
3624 ;; (e.g., when building TAGS via command-line call)
3625 (font-lock-string-face (if (boundp 'font-lock-string-face)
3626 font-lock-string-face
3627 'font-lock-string-face))
3628 (my-cperl-delimiters-face (if (boundp 'font-lock-constant-face)
3629 font-lock-constant-face
3630 'font-lock-constant-face))
3631 (my-cperl-REx-spec-char-face ; [] ^.$ and wrapper-of ({})
3632 (if (boundp 'font-lock-function-name-face)
3633 font-lock-function-name-face
3634 'font-lock-function-name-face))
3635 (font-lock-variable-name-face ; interpolated vars and ({})-code
3636 (if (boundp 'font-lock-variable-name-face)
3637 font-lock-variable-name-face
3638 'font-lock-variable-name-face))
3639 (font-lock-function-name-face ; used in `cperl-find-sub-attrs'
3640 (if (boundp 'font-lock-function-name-face)
3641 font-lock-function-name-face
3642 'font-lock-function-name-face))
3643 (font-lock-constant-face ; used in `cperl-find-sub-attrs'
3644 (if (boundp 'font-lock-constant-face)
3645 font-lock-constant-face
3646 'font-lock-constant-face))
3647 (my-cperl-REx-0length-face ; 0-length, (?:)etc, non-literal \
3648 (if (boundp 'font-lock-builtin-face)
3649 font-lock-builtin-face
3650 'font-lock-builtin-face))
3651 (font-lock-comment-face
3652 (if (boundp 'font-lock-comment-face)
3653 font-lock-comment-face
3654 'font-lock-comment-face))
3655 (font-lock-warning-face
3656 (if (boundp 'font-lock-warning-face)
3657 font-lock-warning-face
3658 'font-lock-warning-face))
3659 (my-cperl-REx-ctl-face ; (|)
3660 (if (boundp 'font-lock-keyword-face)
3661 font-lock-keyword-face
3662 'font-lock-keyword-face))
3663 (my-cperl-REx-modifiers-face ; //gims
3664 (if (boundp 'cperl-nonoverridable-face)
3665 cperl-nonoverridable-face
3666 'cperl-nonoverridable-face))
3667 (my-cperl-REx-length1-face ; length=1 escaped chars, POSIX classes
3668 (if (boundp 'font-lock-type-face)
3670 'font-lock-type-face))
3671 (stop-point (if ignore-max
3676 "\\(\\`\n?\\|^\n\\)=" ; POD
3678 ;; One extra () before this:
3681 ;; First variant "BLAH" or just ``.
3682 "[ \t]*" ; Yes, whitespace is allowed!
3683 "\\([\"'`]\\)" ; 2 + 1 = 3
3684 "\\([^\"'`\n]*\\)" ; 3 + 1
3687 ;; Second variant: Identifier or \ID (same as 'ID') or empty
3688 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3689 ;; Do not have <<= or << 30 or <<30 or << $blah.
3690 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3691 "\\(\\)" ; To preserve count of pars :-( 6 + 1
3694 ;; 1+6 extra () before this:
3695 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" ;FRMAT
3696 (if cperl-use-syntax-table-text-property
3699 ;; 1+6+2=9 extra () before this:
3700 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT
3702 ;; 1+6+2+1=10 extra () before this:
3703 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3705 ;; 1+6+2+1+1=11 extra () before this
3706 "\\<sub\\>" ; sub with proto/attr
3708 cperl-white-and-comment-rex
3709 "\\(::[a-zA-Z_:'0-9]*\\|[a-zA-Z_'][a-zA-Z_:'0-9]*\\)\\)?" ; name
3711 cperl-maybe-white-and-comment-rex
3712 "\\(([^()]*)\\|:[^:]\\)\\)" ; prototype or attribute start
3714 ;; 1+6+2+1+1+6=17 extra () before this:
3715 "\\$\\(['{]\\)" ; $' or ${foo}
3717 ;; 1+6+2+1+1+6+1=18 extra () before this (old pack'var syntax;
3718 ;; we do not support intervening comments...):
3719 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
3720 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
3722 "__\\(END\\|DATA\\)__" ; __END__ or __DATA__
3723 ;; 1+6+2+1+1+6+1+1+1=20 extra () before this:
3725 "\\\\\\(['`\"($]\\)") ; BACKWACKED something-hairy
3731 (message "Scanning for \"hard\" Perl constructions..."))
3732 ;;(message "find: %s --> %s" min max)
3733 (and cperl-pod-here-fontify
3734 ;; We had evals here, do not know why...
3735 (setq face cperl-pod-face
3736 head-face cperl-pod-head-face
3737 here-face cperl-here-face))
3738 (remove-text-properties min max
3739 '(syntax-type t in-pod t syntax-table t
3750 ;; Need to remove face as well...
3752 (and (eq system-type 'emx)
3754 (let ((case-fold-search t))
3755 (looking-at "extproc[ \t]")) ; Analogue of #!
3756 (cperl-commentify min
3757 (save-excursion (end-of-line) (point))
3761 (re-search-forward search max t))
3762 (setq tmpend nil) ; Valid for most cases
3763 (setq b (match-beginning 0)
3764 state (save-excursion (parse-partial-sexp
3765 state-point b nil nil state))
3768 ;; 1+6+2+1+1+6=17 extra () before this:
3770 ((match-beginning 18) ; $' or ${foo}
3771 (if (eq (preceding-char) ?\') ; $'
3773 (setq b (1- (point))
3774 state (parse-partial-sexp
3775 state-point (1- b) nil nil state)
3777 (if (nth 3 state) ; in string
3778 (cperl-modify-syntax-type (1- b) cperl-st-punct))
3781 (setq bb (match-beginning 0))
3782 (cperl-modify-syntax-type bb cperl-st-punct)))
3783 ;; No processing in strings/comments beyond this point:
3784 ((or (nth 3 state) (nth 4 state))
3785 t) ; Do nothing in comment/string
3786 ((match-beginning 1) ; POD section
3787 ;; "\\(\\`\n?\\|^\n\\)="
3788 (setq b (match-beginning 0)
3789 state (parse-partial-sexp
3790 state-point b nil nil state)
3792 (if (or (nth 3 state) (nth 4 state)
3793 (looking-at "cut\\>"))
3794 (if (or (nth 3 state) (nth 4 state) ignore-max)
3795 nil ; Doing a chunk only
3796 (message "=cut is not preceded by a POD section")
3797 (or (car err-l) (setcar err-l (point))))
3802 tb (match-beginning 0)
3803 b1 nil) ; error condition
3804 ;; We do not search to max, since we may be called from
3805 ;; some hook of fontification, and max is random
3806 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
3809 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
3811 (message "=cut is not preceded by an empty line")
3813 (or (car err-l) (setcar err-l b))))))
3814 (beginning-of-line 2) ; An empty line after =cut is not POD!
3818 (remove-text-properties
3819 max e '(syntax-type t in-pod t syntax-table t
3831 (put-text-property b e 'in-pod t)
3832 (put-text-property b e 'syntax-type 'in-pod)
3834 (while (re-search-forward "\n\n[ \t]" e t)
3835 ;; We start 'pod 1 char earlier to include the preceding line
3837 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
3838 (cperl-put-do-not-fontify b (point) t)
3839 ;; mark the non-literal parts as PODs
3840 (if cperl-pod-here-fontify
3841 (cperl-postpone-fontification b (point) 'face face t))
3842 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
3845 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
3846 (cperl-put-do-not-fontify (point) e t)
3847 (if cperl-pod-here-fontify
3849 ;; mark the non-literal parts as PODs
3850 (cperl-postpone-fontification (point) e 'face face t)
3853 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
3855 (cperl-postpone-fontification
3856 (match-beginning 1) (match-end 1)
3858 (while (re-search-forward
3860 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
3863 (cperl-postpone-fontification
3864 (match-beginning 1) (match-end 1)
3866 (cperl-commentify bb e nil)
3868 (or (eq e (point-max))
3869 (forward-char -1)))) ; Prepare for immediate POD start.
3871 ;; We can do many here-per-line;
3872 ;; but multiline quote on the same line as <<HERE confuses us...
3873 ;; ;; One extra () before this:
3876 ;; ;; First variant "BLAH" or just ``.
3877 ;; "[ \t]*" ; Yes, whitespace is allowed!
3878 ;; "\\([\"'`]\\)" ; 2 + 1
3879 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
3882 ;; ;; Second variant: Identifier or \ID or empty
3883 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3884 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
3885 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3886 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
3888 ((match-beginning 2) ; 1 + 1
3890 tb (match-beginning 0)
3891 c (and ; not HERE-DOC
3894 (or (looking-at "[ \t]*(") ; << function_call()
3895 (save-excursion ; 1 << func_name, or $foo << 10
3899 ;;; XXX What to do: foo <<bar ???
3900 ;;; XXX Need to support print {a} <<B ???
3903 ; $foo << b; $f .= <<B;
3904 ; ($f+1) << b; a($f) . <<B;
3905 ; foo 1, <<B; $x{a} <<b;
3907 ((looking-at "[0-9$({]")
3910 (looking-at "[ \t]*<<")
3916 (looking-at "\\(printf?\\|system\\|exec\\|sort\\)\\>")))
3918 (error nil))) ; func(<<EOF)
3919 (and (not (match-beginning 6)) ; Empty
3921 "[ \t]*[=0-9$@%&(]"))))))
3922 (if c ; Not here-doc
3924 (setq c (match-end 2)) ; 1 + 1
3925 (if (match-beginning 5) ;4 + 1
3926 (setq b1 (match-beginning 5) ; 4 + 1
3927 e1 (match-end 5)) ; 4 + 1
3928 (setq b1 (match-beginning 4) ; 3 + 1
3929 e1 (match-end 4))) ; 3 + 1
3930 (setq tag (buffer-substring b1 e1)
3931 qtag (regexp-quote tag))
3932 (cond (cperl-pod-here-fontify
3933 ;; Highlight the starting delimiter
3934 (cperl-postpone-fontification
3935 b1 e1 'face my-cperl-delimiters-face)
3936 (cperl-put-do-not-fontify b1 e1 t)))
3940 (goto-char end-of-here-doc))
3942 ;; We do not search to max, since we may be called from
3943 ;; some hook of fontification, and max is random
3944 (or (and (re-search-forward (concat "^" qtag "$")
3946 ;;;(eq (following-char) ?\n) ; XXXX WHY???
3948 (progn ; Pretend we matched at the end
3949 (goto-char (point-max))
3950 (re-search-forward "\\'")
3951 (message "End of here-document `%s' not found." tag)
3952 (or (car err-l) (setcar err-l b))))
3953 (if cperl-pod-here-fontify
3955 ;; Highlight the ending delimiter
3956 (cperl-postpone-fontification
3957 (match-beginning 0) (match-end 0)
3958 'face my-cperl-delimiters-face)
3959 (cperl-put-do-not-fontify b (match-end 0) t)
3960 ;; Highlight the HERE-DOC
3961 (cperl-postpone-fontification b (match-beginning 0)
3963 (setq e1 (cperl-1+ (match-end 0)))
3964 (put-text-property b (match-beginning 0)
3965 'syntax-type 'here-doc)
3966 (put-text-property (match-beginning 0) e1
3967 'syntax-type 'here-doc-delim)
3968 (put-text-property b e1 'here-doc-group t)
3969 ;; This makes insertion at the start of HERE-DOC update
3970 ;; the whole construct:
3971 (put-text-property b (cperl-1+ b) 'front-sticky '(syntax-type))
3972 (cperl-commentify b e1 nil)
3973 (cperl-put-do-not-fontify b (match-end 0) t)
3974 ;; Cache the syntax info...
3975 (setq cperl-syntax-state (cons state-point state))
3976 ;; ... and process the rest of the line...
3978 (elt ; non-inter ignore-max
3979 (cperl-find-pods-heres c i t end t e1) 1))
3980 (if (and overshoot (> overshoot (point)))
3981 (goto-char overshoot)
3982 (setq overshoot e1))
3986 ((match-beginning 8)
3987 ;; 1+6=7 extra () before this:
3988 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
3990 name (if (match-beginning 8) ; 7 + 1
3991 (buffer-substring (match-beginning 8) ; 7 + 1
3992 (match-end 8)) ; 7 + 1
3994 tb (match-beginning 0))
3996 (put-text-property (save-excursion
3999 b 'first-format-line 't)
4000 (if cperl-pod-here-fontify
4001 (while (and (eq (forward-line) 0)
4002 (not (looking-at "^[.;]$")))
4004 ((looking-at "^#")) ; Skip comments
4005 ((and argument ; Skip argument multi-lines
4006 (looking-at "^[ \t]*{"))
4008 (setq argument nil))
4009 (argument ; Skip argument lines
4010 (setq argument nil))
4013 (setq argument (looking-at "^[^\n]*[@^]"))
4015 ;; Highlight the format line
4016 (cperl-postpone-fontification b1 (point)
4017 'face font-lock-string-face)
4018 (cperl-commentify b1 (point) nil)
4019 (cperl-put-do-not-fontify b1 (point) t))))
4020 ;; We do not search to max, since we may be called from
4021 ;; some hook of fontification, and max is random
4022 (re-search-forward "^[.;]$" stop-point 'toend))
4024 (if (looking-at "^\\.$") ; ";" is not supported yet
4026 ;; Highlight the ending delimiter
4027 (cperl-postpone-fontification (point) (+ (point) 2)
4028 'face font-lock-string-face)
4029 (cperl-commentify (point) (+ (point) 2) nil)
4030 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
4031 (message "End of format `%s' not found." name)
4032 (or (car err-l) (setcar err-l b)))
4036 (put-text-property b (point) 'syntax-type 'format))
4037 ;; qq-like String or Regexp:
4038 ((or (match-beginning 10) (match-beginning 11))
4039 ;; 1+6+2=9 extra () before this:
4040 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
4042 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
4043 (setq b1 (if (match-beginning 10) 10 11)
4044 argument (buffer-substring
4045 (match-beginning b1) (match-end b1))
4046 b (point) ; end of qq etc
4048 c (char-after (match-beginning b1))
4049 bb (char-after (1- (match-beginning b1))) ; tmp holder
4050 ;; bb == "Not a stringy"
4051 bb (if (eq b1 10) ; user variables/whatever
4052 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
4053 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
4054 ((eq bb ?\:) ; $opt::s
4056 (- (match-beginning b1) 2))
4058 ((eq bb ?\>) ; $foo->s
4060 (- (match-beginning b1) 2))
4063 (not (eq (char-after ; &&m/blah/
4064 (- (match-beginning b1) 2))
4067 ;; <file> or <$file>
4069 ;; Do not stringify <FH>, <$fh> :
4072 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
4073 tb (match-beginning 0))
4074 (goto-char (match-beginning b1))
4075 (cperl-backward-to-noncomment (point-min))
4077 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
4082 ;; What is below: regexp-p?
4084 (or (memq (preceding-char)
4085 (append (if (memq c '(?\? ?\<))
4088 "~{(=|&+-*!,;:[") nil))
4089 (and (eq (preceding-char) ?\})
4090 (cperl-after-block-p (point-min)))
4091 (and (eq (char-syntax (preceding-char)) ?w)
4094 ;; After these keywords `/' starts a RE. One should add all the
4095 ;; functions/builtins which expect an argument, but ...
4096 (if (eq (preceding-char) ?-)
4098 (looking-at "[a-zA-Z]\\>")
4100 (not (memq (preceding-char)
4103 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
4104 (and (eq (preceding-char) ?.)
4105 (eq (char-after (- (point) 2)) ?.))
4107 ;; m|blah| ? foo : bar;
4110 cperl-use-syntax-table-text-property
4114 (looking-at "\\s|"))))))
4117 ;; Check for $a -> y
4118 (setq b1 (preceding-char)
4121 (eq (char-after (- go 2)) ?-))
4127 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4128 (goto-char (match-end 0))
4129 (skip-chars-forward " \t\n\f"))
4130 (cond ((and (eq (following-char) ?\})
4132 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
4134 (skip-chars-backward " \t\n\f")
4135 (if (memq (preceding-char) (append "$@%&*" nil))
4141 (looking-at ; $foo -> {s}
4142 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
4143 (and ; $foo[12] -> {s}
4144 (memq (following-char) '(?\{ ?\[))
4147 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
4150 ((and (eq (following-char) ?=)
4151 (eq (char-after (1+ (point))) ?\>))
4152 ;; Check for { foo => 1, s => 2 }
4153 ;; Apparently s=> is never a substitution...
4155 ((and (eq (following-char) ?:)
4156 (eq b1 ?\{) ; Check for $ { s::bar }
4157 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
4160 (skip-chars-backward " \t\n\f")
4161 (memq (preceding-char)
4162 (append "$@%&*" nil))))
4168 ;; Skip whitespace and comments...
4169 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4170 (goto-char (match-end 0))
4171 (skip-chars-forward " \t\n\f"))
4173 (put-text-property b (point) 'syntax-type 'prestring))
4174 ;; qtag means two-arg matcher, may be reset to
4175 ;; 2 or 3 later if some special quoting is needed.
4176 ;; e1 means matching-char matcher.
4177 (setq b (point) ; before the first delimiter
4179 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
4180 ;; We do not search to max, since we may be called from
4181 ;; some hook of fontification, and max is random
4182 i (cperl-forward-re stop-point end
4184 st-l err-l argument)
4185 ;; If `go', then it is considered as 1-arg, `b1' is nil
4186 ;; as in s/foo//x; the point is before final "slash"
4187 b1 (nth 1 i) ; start of the second part
4188 tag (nth 2 i) ; ender-char, true if second part
4189 ; is with matching chars []
4190 go (nth 4 i) ; There is a 1-char part after the end
4191 i (car i) ; intermediate point
4193 ;; Before end of the second part if non-matching: ///
4194 tail (if (and i (not tag))
4196 e (if i i e1) ; end of the first part
4197 qtag nil ; need to preserve backslashitis
4198 is-x-REx nil is-o-REx nil); REx has //x //o modifiers
4199 ;; If s{} (), then b/b1 are at "{", "(", e1/i after ")", "}"
4200 ;; Commenting \\ is dangerous, what about ( ?
4202 (eq (char-after i) ?\\)
4204 (and (if go (looking-at ".\\sw*x")
4205 (looking-at "\\sw*x")) ; qr//x
4207 (and (if go (looking-at ".\\sw*o")
4208 (looking-at "\\sw*o")) ; //o
4211 ;; Considered as 1arg form
4213 (cperl-commentify b (point) t)
4214 (put-text-property b (point) 'syntax-type 'string)
4216 ;; ignore other text properties:
4217 (string-match "^qw$" argument))
4218 (put-text-property b (point) 'indentable t))
4220 (setq e1 (cperl-1+ e1))
4223 (cperl-commentify b i t)
4224 (if (looking-at "\\sw*e") ; s///e
4226 ;; Cache the syntax info...
4227 (setq cperl-syntax-state (cons state-point state))
4230 (car (cperl-find-pods-heres b1 (1- (point)) t end))
4232 (goto-char (1+ max)))
4233 (if (and tag (eq (preceding-char) ?\>))
4235 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
4236 (cperl-modify-syntax-type i cperl-st-bra)))
4237 (put-text-property b i 'syntax-type 'string)
4238 (put-text-property i (point) 'syntax-type 'multiline)
4240 (put-text-property b i 'indentable t)))
4241 (cperl-commentify b1 (point) t)
4242 (put-text-property b (point) 'syntax-type 'string)
4244 (put-text-property b i 'indentable t))
4246 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
4248 ;; Now: tail: if the second part is non-matching without ///e
4249 (if (eq (char-syntax (following-char)) ?w)
4251 (forward-word 1) ; skip modifiers s///s
4252 (if tail (cperl-commentify tail (point) t))
4253 (cperl-postpone-fontification
4254 e1 (point) 'face my-cperl-REx-modifiers-face)))
4255 ;; Check whether it is m// which means "previous match"
4256 ;; and highlight differently
4258 (and (string-match "^\\([sm]?\\|qr\\)$" argument)
4259 (or (not (= (length argument) 0))
4263 ;; split // *is* using zero-pattern
4269 (not (looking-at "split\\>")))
4271 (cperl-postpone-fontification
4272 b e 'face font-lock-warning-face)
4273 (if (or i2 ; Has 2 args
4274 (and cperl-fontify-m-as-s
4276 (string-match "^\\(m\\|qr\\)$" argument)
4277 (and (eq 0 (length argument))
4278 (not (eq ?\< (char-after b)))))))
4280 (cperl-postpone-fontification
4281 b (cperl-1+ b) 'face my-cperl-delimiters-face)
4282 (cperl-postpone-fontification
4283 (1- e) e 'face my-cperl-delimiters-face)))
4284 (if (and is-REx cperl-regexp-scan)
4285 ;; Process RExen: embedded comments, charclasses and ]
4286 ;;;/\3333\xFg\x{FFF}a\ppp\PPP\qqq\C\99f(?{ foo })(??{ foo })/;
4287 ;;;/a\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
4288 ;;;/(?<=foo)(?<!bar)(x)(?:$ab|\$\/)$|\\\b\x888\776\[\:$/xxx;
4289 ;;;m?(\?\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
4290 ;;;m$(^ab[c]\$)$ + m+(^ab[c]\$\+)+ + m](^ab[c\]$|.+)] + m)(^ab[c]$|.+\));
4291 ;;;m^a[\^b]c^ + m.a[^b]\.c.;
4295 (cperl-look-at-leading-count is-x-REx e)
4299 (if (eq (char-after b) ?\#)
4300 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
4301 "\\((\\?#\\)\\|\\(#\\)")
4302 ;; keep the same count: add a fake group
4303 (if (eq (char-after b) ?\#)
4304 "\\((\\?\\\\#\\)\\(\\)"
4305 "\\((\\?#\\)\\(\\)"))
4311 ;; XXXX Will not be able to use it in s)))
4312 (if (eq (char-after b) ?\) )
4313 "\\())))\\)" ; Will never match
4314 (if (eq (char-after b) ?? )
4315 ;;"\\((\\\\\\?\\(\\\\\\?\\)?{\\)"
4316 "\\((\\\\\\?\\\\\\?{\\|()\\\\\\?{\\)"
4317 "\\((\\?\\??{\\)")) ; 5= (??{ (?{
4318 "\\|" ; 6= 0-length, 7: name, 8,9:code, 10:group
4319 "\\(" ;; XXXX 1-char variables, exc. |()\s
4322 "[_a-zA-Z:][_a-zA-Z0-9:]*"
4324 "{[^{}]*}" ; only one-level allowed
4328 "\\(" ;;8,9:code part of array/hash elt
4334 ;; XXXX: what if u is delim?
4342 "\\\\[luLUEQbBAzZG]"
4345 "\\(" ; 10 group opener follower
4346 "\\?\\((\\?\\)" ; 11: in (?(?=C)A|B)
4348 "\\?[:=!>?{]" ; "?" something
4350 "\\?[-imsx]+[:)]" ; (?i) (?-s:.)
4352 "\\?([0-9]+)" ; (?(1)foo|bar)
4360 "\\\\\\(.\\)" ; 12=\SYMBOL
4363 (and (< (point) (1- e))
4364 (re-search-forward hairy-RE (1- e) 'to-end))
4365 (goto-char (match-beginning 0))
4366 (setq REx-subgr-start (point)
4367 was-subgr (following-char))
4369 ((match-beginning 6) ; 0-length builtins, groups
4370 (goto-char (match-end 0))
4371 (if (match-beginning 11)
4372 (goto-char (match-beginning 11)))
4375 (cperl-postpone-fontification
4376 (match-beginning 0) (point)
4379 ((eq was-subgr ?\) )
4384 (if (if (eq (char-after b) ?? )
4385 (looking-at "(\\\\\\?")
4386 (eq (char-after (1+ (point))) ?\?))
4387 my-cperl-REx-0length-face
4388 my-cperl-REx-ctl-face)
4389 font-lock-warning-face))
4390 (error font-lock-warning-face)))
4391 ((eq was-subgr ?\| )
4392 my-cperl-REx-ctl-face)
4393 ((eq was-subgr ?\$ )
4394 (if (> (point) (1+ REx-subgr-start))
4397 (match-beginning 0) (point)
4400 (if (and (eq (match-beginning 0)
4404 font-lock-variable-name-face)
4405 my-cperl-REx-spec-char-face))
4406 ((memq was-subgr (append "^." nil) )
4407 my-cperl-REx-spec-char-face)
4408 ((eq was-subgr ?\( )
4409 (if (not (match-beginning 10))
4410 my-cperl-REx-ctl-face
4411 my-cperl-REx-0length-face))
4412 (t my-cperl-REx-0length-face)))
4413 (if (and (memq was-subgr (append "(|" nil))
4414 (not (string-match "(\\?[-imsx]+)"
4416 (cperl-look-at-leading-count is-x-REx e))
4417 (setq was-subgr nil)) ; We do stuff here
4418 ((match-beginning 12) ; \SYMBOL
4422 ;; How many chars to not highlight:
4423 ;; 0-len special-alnums in other branch =>
4424 ;; Generic: \non-alnum (1), \alnum (1+face)
4425 ;; Is-delim: \non-alnum (1/spec-2) alnum-1 (=what hai)
4426 (setq REx-subgr-start (point)
4427 qtag (preceding-char))
4428 (cperl-postpone-fontification
4429 (- (point) 2) (- (point) 1) 'face
4431 (append "ghijkmoqvFHIJKMORTVY" nil))
4432 font-lock-warning-face
4433 my-cperl-REx-0length-face))
4434 (if (and (eq (char-after b) qtag)
4435 (memq qtag (append ".])^$|*?+" nil)))
4437 (if (and cperl-use-syntax-table-text-property
4440 REx-subgr-start (1- (point))
4441 'syntax-table cperl-st-punct))
4442 (cperl-postpone-fontification
4443 (1- (point)) (point) 'face
4444 ; \] can't appear below
4445 (if (memq qtag (append ".]^$" nil))
4446 'my-cperl-REx-spec-char-face
4447 (if (memq qtag (append "*?+" nil))
4448 'my-cperl-REx-0length-face
4449 'my-cperl-REx-ctl-face))))) ; )|
4450 ;; Test for arguments:
4452 ;; This is not pretty: the 5.8.7 logic:
4453 ;; \0numx -> octal (up to total 3 dig)
4454 ;; \DIGIT -> backref unless \0
4455 ;; \DIGITs -> backref if valid
4456 ;; otherwise up to 3 -> octal
4457 ;; Do not try to distinguish, we guess
4458 ((or (and (memq qtag (append "01234567" nil))
4460 "\\=[01234567]?[01234567]?"
4462 (and (memq qtag (append "89" nil))
4464 "\\=[0123456789]*" (1- e) 'to-end))
4467 "\\=[0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}"
4469 (and (memq qtag (append "pPN" nil))
4470 (re-search-forward "\\={[^{}]+}\\|."
4472 (eq (char-syntax qtag) ?w))
4473 (cperl-postpone-fontification
4474 (1- REx-subgr-start) (point)
4475 'face my-cperl-REx-length1-face))))
4476 (setq was-subgr nil)) ; We do stuff here
4477 ((match-beginning 3) ; [charclass]
4479 (if (eq (char-after b) ?^ )
4480 (and (eq (following-char) ?\\ )
4481 (eq (char-after (cperl-1+ (point)))
4484 (and (eq (following-char) ?^ )
4486 (setq argument b ; continue?
4487 tag nil ; list of POSIX classes
4489 (if (eq (char-after b) ?\] )
4490 (and (eq (following-char) ?\\ )
4491 (eq (char-after (cperl-1+ (point)))
4493 (setq qtag (1+ qtag))
4495 (and (eq (following-char) ?\] )
4497 ;; Apparently, I can't put \] into a charclass
4498 ;; in m]]: m][\\\]\]] produces [\\]]
4499 ;;; POSIX? [:word:] [:^word:] only inside []
4500 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]")
4504 (if (eq (char-after b) ?\] )
4505 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]"
4506 "\\=\\(\\\\.\\|[^]\\\\]\\)*]")
4508 ;; Is this ] an end of POSIX class?
4511 (search-backward "[" argument t)
4512 (< REx-subgr-start (point))
4514 (and ; Should work with delim = \
4515 (eq (preceding-char) ?\\ )
4516 (= (% (skip-chars-backward
4520 ((eq (char-after b) ?\] )
4521 "\\\\*\\[:\\^?\\sw+:\\\\\\]")
4522 ((eq (char-after b) ?\: )
4523 "\\\\*\\[\\\\:\\^?\\sw+\\\\:]")
4524 ((eq (char-after b) ?^ )
4525 "\\\\*\\[:\\(\\\\\\^\\)?\\sw+:\]")
4526 ((eq (char-syntax (char-after b))
4529 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\"
4530 (char-to-string (char-after b))
4532 (t "\\\\*\\[:\\^?\\sw*:]")))
4533 (setq argument (point))))
4534 (setq tag (cons (cons argument (point))
4536 argument (point)) ; continue
4537 (setq argument nil)))
4539 (message "Couldn't find end of charclass in a REx, pos=%s"
4541 (if (and cperl-use-syntax-table-text-property
4542 (> (- (point) 2) REx-subgr-start))
4544 (1+ REx-subgr-start) (1- (point))
4545 'syntax-table cperl-st-punct))
4546 (cperl-postpone-fontification
4547 REx-subgr-start qtag
4548 'face my-cperl-REx-spec-char-face)
4549 (cperl-postpone-fontification
4550 (1- (point)) (point) 'face
4551 my-cperl-REx-spec-char-face)
4552 (if (eq (char-after b) ?\] )
4553 (cperl-postpone-fontification
4554 (- (point) 2) (1- (point))
4555 'face my-cperl-REx-0length-face))
4557 (cperl-postpone-fontification
4558 (car (car tag)) (cdr (car tag))
4559 'face my-cperl-REx-length1-face)
4560 (setq tag (cdr tag)))
4561 (setq was-subgr nil)) ; did facing already
4563 ((and (match-beginning 2) ; #-comment
4564 (/= (match-beginning 2) (match-end 2)))
4565 (beginning-of-line 2)
4567 (goto-char (1- e))))
4568 ((match-beginning 4) ; character "]"
4569 (setq was-subgr nil) ; We do stuff here
4570 (goto-char (match-end 0))
4571 (if cperl-use-syntax-table-text-property
4573 (1- (point)) (point)
4574 'syntax-table cperl-st-punct))
4575 (cperl-postpone-fontification
4576 (1- (point)) (point)
4577 'face font-lock-warning-face))
4578 ((match-beginning 5) ; before (?{}) (??{})
4579 (setq tag (match-end 0))
4581 (cperl-forward-group-in-re st-l))
4583 (setq qtag "no matching `)' found"))
4584 (and (not (eq (char-after (- (point) 2))
4586 (setq qtag "Can't find })")))
4589 (message "%s" qtag))
4590 (cperl-postpone-fontification
4591 (1- tag) (1- (point))
4592 'face font-lock-variable-name-face)
4593 (cperl-postpone-fontification
4594 REx-subgr-start (1- tag)
4595 'face my-cperl-REx-spec-char-face)
4596 (cperl-postpone-fontification
4597 (1- (point)) (point)
4598 'face my-cperl-REx-spec-char-face)
4599 (if cperl-use-syntax-table-text-property
4602 (- (point) 2) (1- (point))
4603 'syntax-table cperl-st-cfence)
4605 (+ REx-subgr-start 2)
4606 (+ REx-subgr-start 3)
4607 'syntax-table cperl-st-cfence))))
4608 (setq was-subgr nil))
4610 ;; Inside "(" and "\" arn't special in any way
4611 ;; Works also if the outside delimiters are ().
4612 (or;;(if (eq (char-after b) ?\) )
4613 ;;(re-search-forward
4614 ;; "[^\\\\]\\(\\\\\\\\\\)*\\\\)"
4616 (search-forward ")" (1- e) 'toend)
4619 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
4625 (setq REx-subgr-end (point))
4627 REx-subgr-start REx-subgr-end nil)
4628 (cperl-postpone-fontification
4629 REx-subgr-start REx-subgr-end
4630 'face font-lock-comment-face))))))
4631 (if (and is-REx is-x-REx)
4632 (put-text-property (1+ b) (1- e)
4633 'syntax-subtype 'x-REx)))
4634 (if (and i2 e1 b1 (> e1 b1))
4635 (progn ; No errors finding the second part...
4636 (cperl-postpone-fontification
4637 (1- e1) e1 'face my-cperl-delimiters-face)
4638 (if (and (not (eobp))
4639 (assoc (char-after b) cperl-starters))
4641 (cperl-postpone-fontification
4642 b1 (1+ b1) 'face my-cperl-delimiters-face)
4643 (put-text-property b1 (1+ b1)
4647 ((match-beginning 17) ; sub with prototype or attribute
4648 ;; 1+6+2+1+1=11 extra () before this (sub with proto/attr):
4649 ;;"\\<sub\\>\\(" ;12
4650 ;; cperl-white-and-comment-rex ;13
4651 ;; "\\([a-zA-Z_:'0-9]+\\)\\)?" ; name ;14
4652 ;;"\\(" cperl-maybe-white-and-comment-rex ;15,16
4653 ;; "\\(([^()]*)\\|:[^:]\\)\\)" ; 17:proto or attribute start
4654 (setq b1 (match-beginning 14) e1 (match-end 14))
4655 (if (memq (char-after (1- b))
4656 '(?\$ ?\@ ?\% ?\& ?\*))
4659 (if (eq (char-after (match-beginning 17)) ?\( )
4661 (cperl-commentify ; Prototypes; mark as string
4662 (match-beginning 17) (match-end 17) t)
4663 (goto-char (match-end 0))
4664 ;; Now look for attributes after prototype:
4665 (forward-comment (buffer-size))
4666 (and (looking-at ":[^:]")
4667 (cperl-find-sub-attrs st-l b1 e1 b)))
4668 ;; treat attributes without prototype
4669 (goto-char (match-beginning 17))
4670 (cperl-find-sub-attrs st-l b1 e1 b))))
4671 ;; 1+6+2+1+1+6+1=18 extra () before this:
4672 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
4673 ((match-beginning 19) ; old $abc'efg syntax
4674 (setq bb (match-end 0))
4675 ;;;(if (nth 3 state) nil ; in string
4676 (put-text-property (1- bb) bb 'syntax-table cperl-st-word)
4678 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
4679 ;; "__\\(END\\|DATA\\)__"
4680 ((match-beginning 20) ; __END__, __DATA__
4681 (setq bb (match-end 0))
4682 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
4683 (cperl-commentify b bb nil)
4685 ;; "\\\\\\(['`\"($]\\)"
4686 ((match-beginning 21)
4687 ;; Trailing backslash; make non-quoting outside string/comment
4688 (setq bb (match-end 0))
4690 (skip-chars-backward "\\\\")
4691 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
4692 (cperl-modify-syntax-type b cperl-st-punct)
4694 (t (error "Error in regexp of the sniffer")))
4695 (if (> (point) stop-point)
4698 (message "Garbage after __END__/__DATA__ ignored")
4699 (message "Unbalanced syntax found while scanning")
4700 (or (car err-l) (setcar err-l b)))
4701 (goto-char stop-point))))
4702 (setq cperl-syntax-state (cons state-point state)
4703 ;; Do not mark syntax as done past tmpend???
4704 cperl-syntax-done-to (or tmpend (max (point) max)))
4705 ;;(message "state-at=%s, done-to=%s" state-point cperl-syntax-done-to)
4707 (if (car err-l) (goto-char (car err-l))
4709 (message "Scanning for \"hard\" Perl constructions... done"))))
4710 (and (buffer-modified-p)
4712 (set-buffer-modified-p nil))
4713 ;; I do not understand what this is doing here. It breaks font-locking
4714 ;; because it resets the syntax-table from font-lock-syntax-table to
4715 ;; cperl-mode-syntax-table.
4716 ;; (set-syntax-table cperl-mode-syntax-table)
4718 (list (car err-l) overshoot)))
4720 (defun cperl-find-pods-heres-region (min max)
4722 (cperl-find-pods-heres min max))
4724 (defun cperl-backward-to-noncomment (lim)
4725 ;; Stops at lim or after non-whitespace that is not in comment
4726 ;; XXXX Wrongly understands end-of-multiline strings with # as comment
4728 (while (and (not stop) (> (point) (or lim (point-min))))
4729 (skip-chars-backward " \t\n\f" lim)
4732 (if (memq (setq pr (get-text-property (point) 'syntax-type))
4733 '(pod here-doc here-doc-delim))
4735 (cperl-unwind-to-safe nil)
4736 (setq pr (get-text-property (point) 'syntax-type))))
4737 (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
4738 (not (memq pr '(string prestring))))
4739 (progn (cperl-to-comment-or-eol) (bolp))
4741 (skip-chars-backward " \t")
4742 (if (< p (point)) (goto-char p))
4745 ;; Used only in `cperl-calculate-indent'...
4746 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
4747 ;; Positions is before ?\{. Checks whether it starts a block.
4748 ;; No save-excursion! This is more a distinguisher of a block/hash ref...
4749 (cperl-backward-to-noncomment (point-min))
4750 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
4751 ; Label may be mixed up with `$blah :'
4752 (save-excursion (cperl-after-label))
4753 (get-text-property (cperl-1- (point)) 'attrib-group)
4754 (and (memq (char-syntax (preceding-char)) '(?w ?_))
4757 ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
4758 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
4759 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
4760 ;; sub bless::foo {}
4762 (cperl-backward-to-noncomment (point-min))
4763 (and (eq (preceding-char) ?b)
4766 (looking-at "sub[ \t\n\f#]")))))))))
4768 ;;; What is the difference of (cperl-after-block-p lim t) and (cperl-block-p)?
4769 ;;; No save-excursion; condition-case ... In (cperl-block-p) the block
4770 ;;; may be a part of an in-statement construct, such as
4771 ;;; ${something()}, print {FH} $data.
4772 ;;; Moreover, one takes positive approach (looks for else,grep etc)
4773 ;;; another negative (looks for bless,tr etc)
4774 (defun cperl-after-block-p (lim &optional pre-block)
4775 "Return true if the preceeding } (if PRE-BLOCK, following {) delimits a block.
4776 Would not look before LIM. Assumes that LIM is a good place to begin a
4777 statement. The kind of block we treat here is one after which a new
4778 statement would start; thus the block in ${func()} does not count."
4782 (or pre-block (forward-sexp -1))
4783 (cperl-backward-to-noncomment lim)
4784 (or (eq (point) lim)
4785 ;; if () {} // sub f () {} // sub f :a(') {}
4786 (eq (preceding-char) ?\) )
4788 (save-excursion (cperl-after-label))
4790 (get-text-property (cperl-1- (point)) 'attrib-group)
4791 (if (memq (char-syntax (preceding-char)) '(?w ?_)) ; else {}
4794 ;; else {} but not else::func {}
4795 (or (and (looking-at "\\(else\\|continue\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
4796 (not (looking-at "\\(\\sw\\|_\\)+::")))
4799 (cperl-backward-to-noncomment lim)
4800 (and (eq (preceding-char) ?b)
4803 (looking-at "sub[ \t\n\f#]"))))))
4804 ;; What preceeds is not word... XXXX Last statement in sub???
4805 (cperl-after-expr-p lim))))
4808 (defun cperl-after-expr-p (&optional lim chars test)
4809 "Return true if the position is good for start of expression.
4810 TEST is the expression to evaluate at the found position. If absent,
4811 CHARS is a string that contains good characters to have before us (however,
4812 `}' is treated \"smartly\" if it is not in the list)."
4813 (let ((lim (or lim (point-min)))
4815 (cperl-update-syntaxification (point) (point))
4817 (while (and (not stop) (> (point) lim))
4818 (skip-chars-backward " \t\n\f" lim)
4821 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
4822 ;; '(pod here-doc here-doc-delim))
4823 (if (get-text-property (point) 'here-doc-group)
4826 (cperl-beginning-of-property (point) 'here-doc-group))
4827 (beginning-of-line 0)))
4828 (if (get-text-property (point) 'in-pod)
4831 (cperl-beginning-of-property (point) 'in-pod))
4832 (beginning-of-line 0)))
4833 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
4834 ;; Else: last iteration, or a label
4835 (cperl-to-comment-or-eol) ; Will not move past "." after a format
4836 (skip-chars-backward " \t")
4837 (if (< p (point)) (goto-char p))
4839 (if (and (eq (preceding-char) ?:)
4842 (skip-chars-backward " \t\n\f" lim)
4843 (memq (char-syntax (preceding-char)) '(?w ?_))))
4844 (forward-sexp -1) ; Possibly label. Skip it
4847 (or (bobp) ; ???? Needed
4849 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
4851 (if test (eval test)
4852 (or (memq (preceding-char) (append (or chars "{;") nil))
4853 (and (eq (preceding-char) ?\})
4854 (cperl-after-block-p lim))
4855 (and (eq (following-char) ?.) ; in format: see comment above
4856 (eq (get-text-property (point) 'syntax-type)
4859 (defun cperl-backward-to-start-of-expr (&optional lim)
4862 (while (and (or (not lim)
4864 (not (cperl-after-expr-p lim)))
4866 ;; May be after $, @, $# etc of a variable
4867 (skip-chars-backward "$@%#")))
4870 (defun cperl-at-end-of-expr (&optional lim)
4871 ;; Since the SEXP approach below is very fragile, do some overengineering
4872 (or (looking-at (concat cperl-maybe-white-and-comment-rex "[;}]"))
4875 ;; If nothing interesting after, does as (forward-sexp -1);
4876 ;; otherwise fails, or ends at a start of following sexp.
4877 ;; XXXX PROBLEMS: if what follows (after ";") @FOO, or ${bar}
4878 ;; may be stuck after @ or $; just put some stupid workaround now:
4882 (while (memq (preceding-char) (append "%&@$*" nil))
4885 (cperl-after-expr-p lim))))
4888 (defun cperl-forward-to-end-of-expr (&optional lim)
4892 (while (and (< (point) (or lim (point-max)))
4893 (not (cperl-at-end-of-expr)))
4897 (defun cperl-backward-to-start-of-continued-exp (lim)
4898 (if (memq (preceding-char) (append ")]}\"'`" nil))
4901 (if (<= (point) lim)
4902 (goto-char (1+ lim)))
4903 (skip-chars-forward " \t"))
4905 (defun cperl-after-block-and-statement-beg (lim)
4906 ;; We assume that we are after ?\}
4908 (cperl-after-block-p lim)
4911 (cperl-backward-to-noncomment (point-min))
4914 (not (= (char-syntax (preceding-char)) ?w))
4919 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
4922 (defun cperl-indent-exp ()
4923 "Simple variant of indentation of continued-sexp.
4925 Will not indent comment if it starts at `comment-indent' or looks like
4926 continuation of the comment on the previous line.
4928 If `cperl-indent-region-fix-constructs', will improve spacing on
4929 conditional/loop constructs."
4932 (let ((tmp-end (progn (end-of-line) (point))) top done)
4937 ;; Plan A: if line has an unfinished paren-group, go to end-of-group
4938 (while (= -1 (nth 0 (parse-partial-sexp (point) tmp-end -1)))
4939 (setq top (point))) ; Get the outermost parenths in line
4941 (while (< (point) tmp-end)
4942 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
4943 (or (eolp) (forward-sexp 1)))
4944 (if (> (point) tmp-end) ; Yes, there an unfinished block
4946 (if (eq ?\) (preceding-char))
4947 (progn ;; Plan B: find by REGEXP block followup this line
4952 (if (eq (following-char) ?$ ) ; for my $var (list)
4955 (if (looking-at "\\(my\\|local\\|our\\)\\>")
4956 (forward-sexp -1))))
4958 (concat "\\(\\elsif\\|if\\|unless\\|while\\|until"
4959 "\\|for\\(each\\)?\\>\\(\\("
4960 cperl-maybe-white-and-comment-rex
4961 "\\(my\\|local\\|our\\)\\)?"
4962 cperl-maybe-white-and-comment-rex
4963 "\\$[_a-zA-Z0-9]+\\)?\\)\\>"))
4967 (setq top (point)))))
4968 (error (setq done t)))
4970 (if (looking-at ; Try Plan C: continuation block
4971 (concat cperl-maybe-white-and-comment-rex
4972 "\\<\\(else\\|elsif\|continue\\)\\>"))
4974 (goto-char (match-end 0))
4977 (setq tmp-end (point))))
4981 (setq tmp-end (point))))
4983 (setq tmp-end (point-marker)))
4984 (if cperl-indent-region-fix-constructs
4985 (cperl-fix-line-spacing tmp-end))
4986 (cperl-indent-region (point) tmp-end))))
4988 (defun cperl-fix-line-spacing (&optional end parse-data)
4989 "Improve whitespace in a conditional/loop construct.
4990 Returns some position at the last line."
4993 (setq end (point-max)))
4994 (let ((ee (save-excursion (end-of-line) (point)))
4995 (cperl-indent-region-fix-constructs
4996 (or cperl-indent-region-fix-constructs 1))
4997 p pp ml have-brace ret)
5004 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
5005 (setq have-brace (save-excursion (search-forward "}" ee t)))))
5006 nil ; Do not need to do anything
5010 (if cperl-merge-trailing-else
5012 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5014 (search-forward "}")
5016 (skip-chars-forward " \t\n")
5017 (delete-region p (point))
5018 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5019 (beginning-of-line)))
5020 (if (looking-at "[ \t]*}[ \t]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5022 (search-forward "}")
5023 (delete-horizontal-space)
5026 (if (cperl-indent-line parse-data)
5028 (cperl-fix-line-spacing end parse-data)
5029 (setq ret (point)))))))
5032 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
5034 (search-forward "}")
5035 (delete-horizontal-space)
5036 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5037 (beginning-of-line)))
5041 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5044 (delete-horizontal-space)
5045 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5046 (beginning-of-line)))
5050 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
5053 (delete-horizontal-space)
5054 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5055 (beginning-of-line)))
5057 ;; foreach my $var (
5059 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5062 (delete-horizontal-space)
5064 (make-string cperl-indent-region-fix-constructs ?\s))
5065 (beginning-of-line)))
5066 ;; Looking at (with or without "}" at start, ending after "({"):
5067 ;; } foreach my $var () OR {
5069 "[ \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]*{")
5071 (setq ml (match-beginning 8)) ; "(" or "{" after control word
5072 (re-search-forward "[({]")
5075 (if (eq (following-char) ?\( )
5078 (setq pp (point))) ; past parenth-group
5079 ;; after `else' or nothing
5080 (if ml ; after `else'
5081 (skip-chars-backward " \t\n")
5082 (beginning-of-line))
5084 ;; Now after the sexp before the brace
5085 ;; Multiline expr should be special
5086 (setq ml (and pp (save-excursion (goto-char p)
5087 (search-forward "\n" pp t))))
5088 (if (and (or (not pp) (< pp end)) ; Do not go too far...
5089 (looking-at "[ \t\n]*{"))
5092 ((bolp) ; Were before `{', no if/else/etc
5094 ((looking-at "\\(\t*\\| [ \t]+\\){") ; Not exactly 1 SPACE
5095 (delete-horizontal-space)
5097 cperl-extra-newline-before-brace-multiline
5098 cperl-extra-newline-before-brace)
5100 (delete-horizontal-space)
5103 (if (cperl-indent-line parse-data)
5105 (cperl-fix-line-spacing end parse-data)
5106 (setq ret (point)))))
5108 (make-string cperl-indent-region-fix-constructs ?\s))))
5109 ((and (looking-at "[ \t]*\n")
5111 cperl-extra-newline-before-brace-multiline
5112 cperl-extra-newline-before-brace)))
5114 (skip-chars-forward " \t\n")
5115 (delete-region pp (point))
5117 (make-string cperl-indent-region-fix-constructs ?\ )))
5118 ((and (looking-at "[\t ]*{")
5119 (if ml cperl-extra-newline-before-brace-multiline
5120 cperl-extra-newline-before-brace))
5121 (delete-horizontal-space)
5124 (if (cperl-indent-line parse-data)
5126 (cperl-fix-line-spacing end parse-data)
5127 (setq ret (point))))))
5128 ;; Now we are before `{'
5129 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
5131 (skip-chars-forward " \t\n")
5136 (setq ml (search-forward "\n" p t))
5137 (if (or cperl-break-one-line-blocks-when-indent ml)
5138 ;; not good: multi-line BLOCK
5141 (delete-horizontal-space)
5144 (if (cperl-indent-line parse-data)
5145 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
5147 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
5148 ;; Now check whether there is a hanging `}'
5152 cperl-fix-hanging-brace-when-indent
5154 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
5158 (if (and (<= (point) pp)
5159 (eq (preceding-char) ?\} )
5160 (cperl-after-block-and-statement-beg (point-min)))
5167 (skip-chars-backward " \t")
5169 ;; `}' was the first thing on the line, insert NL *after* it.
5171 (cperl-indent-line parse-data)
5172 (search-forward "}")
5173 (delete-horizontal-space)
5175 (delete-horizontal-space)
5176 (or (eq (preceding-char) ?\;)
5178 (and (eq (preceding-char) ?\} )
5179 (cperl-after-block-p (point-min)))
5183 (if (cperl-indent-line parse-data)
5184 (setq ret (cperl-fix-line-spacing end parse-data)))
5185 (beginning-of-line)))))
5188 (defvar cperl-update-start) ; Do not need to make them local
5189 (defvar cperl-update-end)
5190 (defun cperl-delay-update-hook (beg end old-len)
5191 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
5192 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
5194 (defun cperl-indent-region (start end)
5195 "Simple variant of indentation of region in CPerl mode.
5196 Should be slow. Will not indent comment if it starts at `comment-indent'
5197 or looks like continuation of the comment on the previous line.
5198 Indents all the lines whose first character is between START and END
5201 If `cperl-indent-region-fix-constructs', will improve spacing on
5202 conditional/loop constructs."
5204 (cperl-update-syntaxification end end)
5206 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
5207 (let ((indent-info (if cperl-emacs-can-parse
5208 (list nil nil nil) ; Cannot use '(), since will modify
5211 after-change-functions ; Speed it up!
5212 st comm old-comm-indent new-comm-indent p pp i empty)
5213 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
5215 (setq old-comm-indent (and (cperl-to-comment-or-eol)
5217 new-comm-indent old-comm-indent)
5219 (setq end (set-marker (make-marker) end)) ; indentation changes pos
5220 (or (bolp) (beginning-of-line 2))
5221 (while (and (<= (point) end) (not (eobp))) ; bol to check start
5224 (setq empty (looking-at "[ \t]*\n"))
5225 (and (setq comm (looking-at "[ \t]*#"))
5226 (or (eq (current-indentation) (or old-comm-indent
5228 (setq old-comm-indent nil))))
5229 (if (and old-comm-indent
5231 (= (current-indentation) old-comm-indent)
5232 (not (eq (get-text-property (point) 'syntax-type) 'pod))
5233 (not (eq (get-text-property (point) 'syntax-table)
5235 (let ((comment-column new-comm-indent))
5236 (indent-for-comment)))
5238 (setq i (cperl-indent-line indent-info))
5242 (if cperl-indent-region-fix-constructs
5243 (goto-char (cperl-fix-line-spacing end indent-info)))
5244 (if (setq old-comm-indent
5245 (and (cperl-to-comment-or-eol)
5246 (not (memq (get-text-property (point)
5249 (not (eq (get-text-property (point)
5253 (progn (indent-for-comment)
5254 (skip-chars-backward " \t")
5255 (skip-chars-backward "#")
5256 (setq new-comm-indent (current-column))))))))
5257 (beginning-of-line 2)))
5258 ;; Now run the update hooks
5259 (and after-change-functions
5262 (goto-char cperl-update-end)
5265 (goto-char cperl-update-start)
5267 (delete-char -1))))))
5269 ;; Stolen from lisp-mode with a lot of improvements
5271 (defun cperl-fill-paragraph (&optional justify iteration)
5272 "Like `fill-paragraph', but handle CPerl comments.
5273 If any of the current line is a comment, fill the comment or the
5274 block of it that point is in, preserving the comment's initial
5275 indentation and initial hashes. Behaves usually outside of comment."
5276 ;; (interactive "P") ; Only works when called from fill-paragraph. -stef
5277 (let (;; Non-nil if the current line contains a comment.
5279 fill-paragraph-function ; do not recurse
5280 ;; If has-comment, the appropriate fill-prefix for the comment.
5282 ;; Line that contains code and comment (or nil)
5284 c spaces len dc (comment-column comment-column))
5285 ;; Figure out what kind of comment we are looking at.
5290 ;; A line with nothing but a comment on it?
5291 ((looking-at "[ \t]*#[# \t]*")
5293 comment-fill-prefix (buffer-substring (match-beginning 0)
5296 ;; A line with some code, followed by a comment? Remember that the
5297 ;; semi which starts the comment shouldn't be part of a string or
5299 ((cperl-to-comment-or-eol)
5300 (setq has-comment t)
5301 (looking-at "#+[ \t]*")
5302 (setq start (point) c (current-column)
5304 (concat (make-string (current-column) ?\s)
5305 (buffer-substring (match-beginning 0) (match-end 0)))
5306 spaces (progn (skip-chars-backward " \t")
5307 (buffer-substring (point) start))
5308 dc (- c (current-column)) len (- start (point))
5309 start (point-marker))
5311 (insert (make-string dc ?-))))) ; Placeholder (to avoid splitting???)
5312 (if (not has-comment)
5313 (fill-paragraph justify) ; Do the usual thing outside of comment
5314 ;; Narrow to include only the comment, and then fill the region.
5317 ;; Find the first line we should include in the region to fill.
5318 (if start (progn (beginning-of-line) (point))
5320 (while (and (zerop (forward-line -1))
5321 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5322 ;; We may have gone to far. Go forward again.
5323 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
5326 ;; Find the beginning of the first line past the region to fill.
5328 (while (progn (forward-line 1)
5329 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5331 ;; Remove existing hashes
5333 (goto-char (point-min))
5334 (while (progn (forward-line 1) (< (point) (point-max)))
5335 (skip-chars-forward " \t")
5336 (if (looking-at "#+")
5338 (if (and (eq (point) (match-beginning 0))
5339 (not (eq (point) (match-end 0)))) nil
5341 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage"))
5342 (delete-char (- (match-end 0) (match-beginning 0)))))))
5344 ;; Lines with only hashes on them can be paragraph boundaries.
5345 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
5346 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
5347 (fill-prefix comment-fill-prefix))
5348 (fill-paragraph justify)))
5353 (progn (delete-char dc) (insert spaces)))
5354 (if (or (= (current-column) c) iteration) nil
5355 (setq comment-column c)
5356 (indent-for-comment)
5357 ;; Repeat once more, flagging as iteration
5358 (cperl-fill-paragraph justify t))))))
5361 (defun cperl-do-auto-fill ()
5362 ;; Break out if the line is short enough
5363 (if (> (save-excursion
5367 (let ((c (save-excursion (beginning-of-line)
5368 (cperl-to-comment-or-eol) (point)))
5369 (s (memq (following-char) '(?\s ?\t))) marker)
5371 ;; Don't break line inside code: only inside comment.
5373 (setq marker (point-marker))
5374 (fill-paragraph nil)
5376 ;; Is not enough, sometimes marker is a start of line
5377 (if (bolp) (progn (re-search-forward "#+[ \t]*")
5378 (goto-char (match-end 0))))
5379 ;; Following space could have gone:
5380 (if (or (not s) (memq (following-char) '(?\s ?\t))) nil
5383 ;; Previous space could have gone:
5384 (or (memq (preceding-char) '(?\s ?\t)) (insert " "))))))
5386 (defun cperl-imenu-addback (lst &optional isback name)
5387 ;; We suppose that the lst is a DAG, unless the first element only
5388 ;; loops back, and ISBACK is set. Thus this function cannot be
5389 ;; applied twice without ISBACK set.
5390 (cond ((not cperl-imenu-addback) lst)
5393 (setq name "+++BACK+++"))
5395 (if (and (listp elt) (listp (cdr elt)))
5397 ;; In the other order it goes up
5398 ;; one level only ;-(
5399 (setcdr elt (cons (cons name lst)
5401 (cperl-imenu-addback (cdr elt) t name))))
5402 (if isback (cdr lst) lst))
5405 (defun cperl-imenu--create-perl-index (&optional regexp)
5406 (require 'imenu) ; May be called from TAGS creator
5407 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
5408 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
5409 (index-meth-alist '()) meth
5410 packages ends-ranges p marker is-proto
5411 (prev-pos 0) is-pack index index1 name (end-range 0) package)
5412 (goto-char (point-min))
5413 (cperl-update-syntaxification (point-max) (point-max))
5414 ;; Search for the function
5415 (progn ;;save-match-data
5416 (while (re-search-forward
5417 (or regexp cperl-imenu--function-name-regexp-perl)
5419 ;; 2=package-group, 5=package-name 8=sub-name
5421 ((and ; Skip some noise if building tags
5422 (match-beginning 5) ; package name
5423 ;;(eq (char-after (match-beginning 2)) ?p) ; package
5424 (not (save-match-data
5425 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
5428 (or (match-beginning 2)
5429 (match-beginning 8)) ; package or sub
5430 ;; Skip if quoted (will not skip multi-line ''-strings :-():
5431 (null (get-text-property (match-beginning 1) 'syntax-table))
5432 (null (get-text-property (match-beginning 1) 'syntax-type))
5433 (null (get-text-property (match-beginning 1) 'in-pod)))
5434 (setq is-pack (match-beginning 2))
5435 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
5436 ;; (goto-char (match-end 0))) ; Messes what follows
5439 (while (and ends-ranges (>= p (car ends-ranges)))
5440 ;; delete obsolete entries
5441 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
5442 (setq package (or (car packages) "")
5443 end-range (or (car ends-ranges) 0))
5444 (if is-pack ; doing "package"
5446 (if (match-beginning 5) ; named package
5447 (setq name (buffer-substring (match-beginning 5)
5450 (set-text-properties 0 (length name) nil name)
5452 package (concat name "::")
5453 name (concat "package " name))
5454 ;; Support nameless packages
5455 (setq name "package;" package ""))
5458 (parse-partial-sexp (point) (point-max) -1) (point))
5459 ends-ranges (cons end-range ends-ranges)
5460 packages (cons package packages)))
5462 (or (eq (following-char) ?\;)
5463 (eq 0 (get-text-property (point) 'attrib-group)))))
5464 ;; Skip this function name if it is a prototype declaration.
5465 (if (and is-proto (not is-pack)) nil
5468 (buffer-substring (match-beginning 8) (match-end 8)))
5469 (set-text-properties 0 (length name) nil name))
5470 (setq marker (make-marker))
5471 (set-marker marker (match-end (if is-pack 2 8)))
5473 ((string-match "[:']" name)
5475 ((> p end-range) nil)
5477 (setq name (concat package name) meth t)))
5478 (setq index (cons name marker))
5480 (push index index-pack-alist)
5481 (push index index-alist))
5482 (if meth (push index index-meth-alist))
5483 (push index index-unsorted-alist)))
5484 ((match-beginning 16) ; POD section
5485 (setq name (buffer-substring (match-beginning 17) (match-end 17))
5486 marker (make-marker))
5487 (set-marker marker (match-beginning 17))
5488 (set-text-properties 0 (length name) nil name)
5489 (setq name (concat (make-string
5490 (* 3 (- (char-after (match-beginning 16)) ?1))
5493 index (cons name marker))
5494 (setq index1 (cons (concat "=" name) (cdr index)))
5495 (push index index-pod-alist)
5496 (push index1 index-unsorted-alist)))))
5498 (if (default-value 'imenu-sort-function)
5499 (sort index-alist (default-value 'imenu-sort-function))
5500 (nreverse index-alist)))
5501 (and index-pod-alist
5502 (push (cons "+POD headers+..."
5503 (nreverse index-pod-alist))
5505 (and (or index-pack-alist index-meth-alist)
5506 (let ((lst index-pack-alist) hier-list pack elt group name)
5507 ;; Remove "package ", reverse and uniquify.
5509 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
5510 (if (assoc name hier-list) nil
5511 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
5512 (setq lst index-meth-alist)
5514 (setq elt (car lst) lst (cdr lst))
5515 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
5516 (setq pack (substring (car elt) 0 (match-beginning 0)))
5517 (if (setq group (assoc pack hier-list))
5518 (if (listp (cdr group))
5519 ;; Have some functions already
5521 (cons (cons (substring
5523 (+ 2 (match-beginning 0)))
5526 (setcdr group (list (cons (substring
5528 (+ 2 (match-beginning 0)))
5532 (list (cons (substring
5534 (+ 2 (match-beginning 0)))
5537 (push (cons "+Hierarchy+..."
5540 (and index-pack-alist
5541 (push (cons "+Packages+..."
5542 (nreverse index-pack-alist))
5544 (and (or index-pack-alist index-pod-alist
5545 (default-value 'imenu-sort-function))
5546 index-unsorted-alist
5547 (push (cons "+Unsorted List+..."
5548 (nreverse index-unsorted-alist))
5550 (cperl-imenu-addback index-alist)))
5553 ;; Suggested by Mark A. Hershberger
5554 (defun cperl-outline-level ()
5555 (looking-at outline-regexp)
5556 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
5557 ;;;; 2=package-group, 5=package-name 8=sub-name 16=head-level
5558 ((match-beginning 2) 0) ; package
5559 ((match-beginning 8) 1) ; sub
5560 ((match-beginning 16)
5561 (- (char-after (match-beginning 16)) ?0)) ; headN ==> N
5562 (t 5))) ; should not happen
5565 (defun cperl-windowed-init ()
5566 "Initialization under windowed version."
5567 (cond ((featurep 'ps-print)
5568 (or cperl-faces-init
5570 (and (boundp 'font-lock-multiline)
5571 (setq cperl-font-lock-multiline t))
5572 (cperl-init-faces))))
5573 ((not cperl-faces-init)
5574 (add-hook 'font-lock-mode-hook
5577 (if (memq major-mode '(perl-mode cperl-mode))
5579 (or cperl-faces-init (cperl-init-faces)))))))
5580 (if (fboundp 'eval-after-load)
5583 '(or cperl-faces-init (cperl-init-faces)))))))
5585 (defvar cperl-font-lock-keywords-1 nil
5586 "Additional expressions to highlight in Perl mode. Minimal set.")
5587 (defvar cperl-font-lock-keywords nil
5588 "Additional expressions to highlight in Perl mode. Default set.")
5589 (defvar cperl-font-lock-keywords-2 nil
5590 "Additional expressions to highlight in Perl mode. Maximal set")
5592 (defun cperl-load-font-lock-keywords ()
5593 (or cperl-faces-init (cperl-init-faces))
5594 cperl-font-lock-keywords)
5596 (defun cperl-load-font-lock-keywords-1 ()
5597 (or cperl-faces-init (cperl-init-faces))
5598 cperl-font-lock-keywords-1)
5600 (defun cperl-load-font-lock-keywords-2 ()
5601 (or cperl-faces-init (cperl-init-faces))
5602 cperl-font-lock-keywords-2)
5604 (defun cperl-init-faces-weak ()
5605 ;; Allow `cperl-find-pods-heres' to run.
5606 (or (boundp 'font-lock-constant-face)
5607 (cperl-force-face font-lock-constant-face
5608 "Face for constant and label names"))
5609 (or (boundp 'font-lock-warning-face)
5610 (cperl-force-face font-lock-warning-face
5611 "Face for things which should stand out"))
5612 ;;(setq font-lock-constant-face 'font-lock-constant-face)
5615 (defun cperl-init-faces ()
5616 (condition-case errs
5618 (require 'font-lock)
5619 (and (fboundp 'font-lock-fontify-anchored-keywords)
5620 (featurep 'font-lock-extra)
5621 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
5622 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
5623 (if (fboundp 'font-lock-fontify-anchored-keywords)
5624 (setq font-lock-anchored t))
5626 t-font-lock-keywords
5628 `("[ \t]+$" 0 ',cperl-invalid-face t)
5631 "\\(^\\|[^$@%&\\]\\)\\<\\("
5634 '("if" "until" "while" "elsif" "else" "unless" "for"
5635 "foreach" "continue" "exit" "die" "last" "goto" "next"
5636 "redo" "return" "local" "exec" "sub" "do" "dump" "use" "our"
5637 "require" "package" "eval" "my" "BEGIN" "END" "CHECK" "INIT")
5638 "\\|") ; Flow control
5639 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
5640 ; In what follows we use `type' style
5641 ; for overwritable builtins
5644 "\\(^\\|[^$@%&\\]\\)\\<\\("
5645 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
5646 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
5647 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
5648 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
5649 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
5650 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
5651 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
5652 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
5653 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
5654 ;; "gethostbyname" "gethostent" "getlogin"
5655 ;; "getnetbyaddr" "getnetbyname" "getnetent"
5656 ;; "getpeername" "getpgrp" "getppid" "getpriority"
5657 ;; "getprotobyname" "getprotobynumber" "getprotoent"
5658 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
5659 ;; "getservbyport" "getservent" "getsockname"
5660 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
5661 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
5662 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
5663 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
5664 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
5665 ;; "quotemeta" "rand" "read" "readdir" "readline"
5666 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
5667 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
5668 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
5669 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
5670 ;; "setpriority" "setprotoent" "setpwent" "setservent"
5671 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
5672 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
5673 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
5674 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
5675 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
5676 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
5677 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
5678 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
5679 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
5680 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
5681 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
5682 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
5683 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
5684 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
5685 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
5686 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
5687 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
5688 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
5689 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
5690 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
5691 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
5692 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
5693 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
5694 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
5695 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
5696 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
5697 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
5698 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
5699 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
5700 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
5701 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
5702 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
5703 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
5704 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
5705 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
5706 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
5707 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
5708 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
5709 "\\)\\>") 2 'font-lock-type-face)
5710 ;; In what follows we use `other' style
5711 ;; for nonoverwritable builtins
5712 ;; Somehow 's', 'm' are not auto-generated???
5715 "\\(^\\|[^$@%&\\]\\)\\<\\("
5716 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "chomp"
5717 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
5718 ;; "eval" "exists" "for" "foreach" "format" "goto"
5719 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
5720 ;; "no" "our" "package" "pop" "pos" "print" "printf" "push"
5721 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
5722 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
5723 ;; "undef" "unless" "unshift" "untie" "until" "use"
5725 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
5726 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
5727 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|INIT\\|if\\|keys\\|"
5728 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
5729 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
5730 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
5731 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
5732 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
5733 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
5734 "\\|[sm]" ; Added manually
5735 "\\)\\>") 2 'cperl-nonoverridable-face)
5736 ;; (mapconcat 'identity
5737 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
5738 ;; "#include" "#define" "#undef")
5740 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
5741 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
5742 ;; This highlights declarations and definitions differenty.
5743 ;; We do not try to highlight in the case of attributes:
5744 ;; it is already done by `cperl-find-pods-heres'
5745 (list (concat "\\<sub"
5746 cperl-white-and-comment-rex ; whitespace/comments
5747 "\\([^ \n\t{;()]+\\)" ; 2=name (assume non-anonymous)
5749 cperl-maybe-white-and-comment-rex ;whitespace/comments?
5750 "([^()]*)\\)?" ; prototype
5751 cperl-maybe-white-and-comment-rex ; whitespace/comments?
5753 2 (if cperl-font-lock-multiline
5754 '(if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5755 'font-lock-function-name-face
5756 'font-lock-variable-name-face)
5757 ;; need to manually set 'multiline' for older font-locks
5759 (if (< 1 (count-lines (match-beginning 0)
5762 (+ 3 (match-beginning 0)) (match-end 0)
5763 'syntax-type 'multiline))
5764 (if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5765 'font-lock-function-name-face
5766 'font-lock-variable-name-face))))
5767 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
5768 2 font-lock-function-name-face)
5769 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
5770 1 font-lock-function-name-face)
5771 (cond ((featurep 'font-lock-extra)
5772 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5773 (2 font-lock-string-face t)
5774 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
5776 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5777 (2 font-lock-string-face t)
5778 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5780 (1 font-lock-string-face t))))
5781 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5782 2 font-lock-string-face t)))
5783 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
5784 font-lock-string-face t)
5785 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
5786 font-lock-constant-face) ; labels
5787 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
5788 2 font-lock-constant-face)
5789 ;; Uncomment to get perl-mode-like vars
5790 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
5791 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
5792 ;;; (2 (cons font-lock-variable-name-face '(underline))))
5793 (cond ((featurep 'font-lock-extra)
5794 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5795 (3 font-lock-variable-name-face)
5797 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5798 (1 font-lock-variable-name-face)
5799 (2 '(restart 2 nil) nil t)))
5800 nil t))) ; local variables, multiple
5802 ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
5803 `(,(concat "\\<\\(my\\|local\\|our\\)"
5804 cperl-maybe-white-and-comment-rex
5806 cperl-maybe-white-and-comment-rex
5807 "\\)?\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)")
5808 (5 ,(if cperl-font-lock-multiline
5809 'font-lock-variable-name-face
5810 '(progn (setq cperl-font-lock-multiline-start
5811 (match-beginning 0))
5812 'font-lock-variable-name-face)))
5814 cperl-maybe-white-and-comment-rex
5816 cperl-maybe-white-and-comment-rex
5817 "\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)")
5818 ;; Bug in font-lock: limit is used not only to limit
5819 ;; searches, but to set the "extend window for
5820 ;; facification" property. Thus we need to minimize.
5821 ,(if cperl-font-lock-multiline
5822 '(if (match-beginning 3)
5824 (goto-char (match-beginning 3))
5830 (error nil)))) ; typeahead
5831 (1- (point))) ; report limit
5832 (forward-char -2)) ; disable continued expr
5833 '(if (match-beginning 3)
5834 (point-max) ; No limit for continuation
5835 (forward-char -2))) ; disable continued expr
5836 ,(if cperl-font-lock-multiline
5839 ;; "my" may be already fontified (POD),
5840 ;; so cperl-font-lock-multiline-start is nil
5841 (if (or (not cperl-font-lock-multiline-start)
5843 cperl-font-lock-multiline-start
5847 (1+ cperl-font-lock-multiline-start) (point)
5848 'syntax-type 'multiline))
5849 (setq cperl-font-lock-multiline-start nil)))
5850 (3 font-lock-variable-name-face))))
5851 (t '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
5852 3 font-lock-variable-name-face)))
5853 '("\\<for\\(each\\)?\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
5854 4 font-lock-variable-name-face)
5855 ;; Avoid $!, and s!!, qq!! etc. when not fontifying syntaxically
5856 '("\\(?:^\\|[^smywqrx$]\\)\\(!\\)" 1 font-lock-negation-char-face)
5857 '("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)))
5859 t-font-lock-keywords-1
5860 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
5861 ;; not yet as of XEmacs 19.12, works with 21.1.11
5863 (not (featurep 'xemacs))
5864 (string< "21.1.9" emacs-version)
5865 (and (string< "21.1.10" emacs-version)
5866 (string< emacs-version "21.1.2")))
5868 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
5869 (if (eq (char-after (match-beginning 2)) ?%)
5872 t) ; arrays and hashes
5873 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
5875 (if (= (- (match-end 2) (match-beginning 2)) 1)
5876 (if (eq (char-after (match-beginning 3)) ?{)
5878 'cperl-array-face) ; arrays and hashes
5879 font-lock-variable-name-face) ; Just to put something
5881 ("\\(@\\|\\$#\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
5882 (1 cperl-array-face)
5883 (2 font-lock-variable-name-face))
5884 ("\\(%\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
5886 (2 font-lock-variable-name-face))
5887 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
5888 ;;; Too much noise from \s* @s[ and friends
5889 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
5890 ;;(3 font-lock-function-name-face t t)
5892 ;; (if (cperl-slash-is-regexp)
5893 ;; font-lock-function-name-face 'default) nil t))
5895 (if cperl-highlight-variables-indiscriminately
5896 (setq t-font-lock-keywords-1
5897 (append t-font-lock-keywords-1
5898 (list '("\\([$*]{?\\sw+\\)" 1
5899 font-lock-variable-name-face)))))
5900 (setq cperl-font-lock-keywords-1
5901 (if cperl-syntaxify-by-font-lock
5902 (cons 'cperl-fontify-update
5903 t-font-lock-keywords)
5904 t-font-lock-keywords)
5905 cperl-font-lock-keywords cperl-font-lock-keywords-1
5906 cperl-font-lock-keywords-2 (append
5907 cperl-font-lock-keywords-1
5908 t-font-lock-keywords-1)))
5909 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
5910 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
5911 (eval ; Avoid a warning
5912 '(font-lock-require-faces
5914 ;; Color-light Color-dark Gray-light Gray-dark Mono
5915 (list 'font-lock-comment-face
5916 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
5921 (list 'font-lock-string-face
5922 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
5927 (list 'font-lock-function-name-face
5929 "Blue" "LightSkyBlue" "Gray50" "LightGray"
5930 (cdr (assq 'background-color ; if mono
5931 (frame-parameters))))
5934 (cdr (assq 'foreground-color ; if mono
5935 (frame-parameters))))
5939 (list 'font-lock-variable-name-face
5940 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
5945 (list 'font-lock-type-face
5946 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
5951 (list 'font-lock-warning-face
5952 ["Pink" "Red" "Gray50" "LightGray"]
5959 (list 'font-lock-constant-face
5960 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
5965 (list 'cperl-nonoverridable-face
5966 ["chartreuse3" ("orchid1" "orange")
5972 (list 'cperl-array-face
5973 ["blue" "yellow" nil "Gray80"]
5974 ["lightyellow2" ("navy" "os2blue" "darkgreen")
5979 (list 'cperl-hash-face
5980 ["red" "red" nil "Gray80"]
5981 ["lightyellow2" ("navy" "os2blue" "darkgreen")
5986 ;; Do it the dull way, without choose-color
5987 (defvar cperl-guessed-background nil
5988 "Display characteristics as guessed by cperl.")
5989 ;; (or (fboundp 'x-color-defined-p)
5990 ;; (defalias 'x-color-defined-p
5991 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
5992 ;; ;; XEmacs >= 19.12
5993 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
5995 ;; (t 'x-valid-color-name-p))))
5996 (cperl-force-face font-lock-constant-face
5997 "Face for constant and label names")
5998 (cperl-force-face font-lock-variable-name-face
5999 "Face for variable names")
6000 (cperl-force-face font-lock-type-face
6001 "Face for data types")
6002 (cperl-force-face cperl-nonoverridable-face
6003 "Face for data types from another group")
6004 (cperl-force-face font-lock-warning-face
6005 "Face for things which should stand out")
6006 (cperl-force-face font-lock-comment-face
6007 "Face for comments")
6008 (cperl-force-face font-lock-function-name-face
6009 "Face for function names")
6010 (cperl-force-face cperl-hash-face
6012 (cperl-force-face cperl-array-face
6014 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
6015 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
6016 ;;(or (boundp 'font-lock-type-face)
6017 ;; (defconst font-lock-type-face
6018 ;; 'font-lock-type-face
6019 ;; "Face to use for data types."))
6020 ;;(or (boundp 'cperl-nonoverridable-face)
6021 ;; (defconst cperl-nonoverridable-face
6022 ;; 'cperl-nonoverridable-face
6023 ;; "Face to use for data types from another group."))
6024 ;;(if (not (featurep 'xemacs)) nil
6025 ;; (or (boundp 'font-lock-comment-face)
6026 ;; (defconst font-lock-comment-face
6027 ;; 'font-lock-comment-face
6028 ;; "Face to use for comments."))
6029 ;; (or (boundp 'font-lock-keyword-face)
6030 ;; (defconst font-lock-keyword-face
6031 ;; 'font-lock-keyword-face
6032 ;; "Face to use for keywords."))
6033 ;; (or (boundp 'font-lock-function-name-face)
6034 ;; (defconst font-lock-function-name-face
6035 ;; 'font-lock-function-name-face
6036 ;; "Face to use for function names.")))
6038 (not (cperl-is-face 'cperl-array-face))
6039 (cperl-is-face 'font-lock-emphasized-face))
6040 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
6042 (not (cperl-is-face 'cperl-hash-face))
6043 (cperl-is-face 'font-lock-other-emphasized-face))
6044 (copy-face 'font-lock-other-emphasized-face 'cperl-hash-face))
6046 (not (cperl-is-face 'cperl-nonoverridable-face))
6047 (cperl-is-face 'font-lock-other-type-face))
6048 (copy-face 'font-lock-other-type-face 'cperl-nonoverridable-face))
6049 ;;(or (boundp 'cperl-hash-face)
6050 ;; (defconst cperl-hash-face
6052 ;; "Face to use for hashes."))
6053 ;;(or (boundp 'cperl-array-face)
6054 ;; (defconst cperl-array-face
6055 ;; 'cperl-array-face
6056 ;; "Face to use for arrays."))
6057 ;; Here we try to guess background
6059 (if (boundp 'font-lock-background-mode)
6060 font-lock-background-mode
6062 (face-list (and (fboundp 'face-list) (face-list))))
6063 ;;;; (fset 'cperl-is-face
6064 ;;;; (cond ((fboundp 'find-face)
6065 ;;;; (symbol-function 'find-face))
6067 ;;;; (function (lambda (face) (member face face-list))))
6069 ;;;; (function (lambda (face) (boundp face))))))
6070 (defvar cperl-guessed-background
6071 (if (and (boundp 'font-lock-display-type)
6072 (eq font-lock-display-type 'grayscale))
6075 "Background as guessed by CPerl mode")
6076 (and (not (cperl-is-face 'font-lock-constant-face))
6077 (cperl-is-face 'font-lock-reference-face)
6078 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
6079 (if (cperl-is-face 'font-lock-type-face) nil
6080 (copy-face 'default 'font-lock-type-face)
6082 ((eq background 'light)
6083 (set-face-foreground 'font-lock-type-face
6084 (if (x-color-defined-p "seagreen")
6087 ((eq background 'dark)
6088 (set-face-foreground 'font-lock-type-face
6089 (if (x-color-defined-p "os2pink")
6093 (set-face-background 'font-lock-type-face "gray90"))))
6094 (if (cperl-is-face 'cperl-nonoverridable-face)
6096 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
6098 ((eq background 'light)
6099 (set-face-foreground 'cperl-nonoverridable-face
6100 (if (x-color-defined-p "chartreuse3")
6103 ((eq background 'dark)
6104 (set-face-foreground 'cperl-nonoverridable-face
6105 (if (x-color-defined-p "orchid1")
6108 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
6109 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
6111 ;;; ((eq background 'light)
6112 ;;; (set-face-background 'font-lock-other-emphasized-face
6113 ;;; (if (x-color-defined-p "lightyellow2")
6115 ;;; (if (x-color-defined-p "lightyellow")
6117 ;;; "light yellow"))))
6118 ;;; ((eq background 'dark)
6119 ;;; (set-face-background 'font-lock-other-emphasized-face
6120 ;;; (if (x-color-defined-p "navy")
6122 ;;; (if (x-color-defined-p "darkgreen")
6124 ;;; "dark green"))))
6125 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
6126 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
6127 ;;; (copy-face 'bold 'font-lock-emphasized-face)
6129 ;;; ((eq background 'light)
6130 ;;; (set-face-background 'font-lock-emphasized-face
6131 ;;; (if (x-color-defined-p "lightyellow2")
6133 ;;; "lightyellow")))
6134 ;;; ((eq background 'dark)
6135 ;;; (set-face-background 'font-lock-emphasized-face
6136 ;;; (if (x-color-defined-p "navy")
6138 ;;; (if (x-color-defined-p "darkgreen")
6140 ;;; "dark green"))))
6141 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
6142 (if (cperl-is-face 'font-lock-variable-name-face) nil
6143 (copy-face 'italic 'font-lock-variable-name-face))
6144 (if (cperl-is-face 'font-lock-constant-face) nil
6145 (copy-face 'italic 'font-lock-constant-face))))
6146 (setq cperl-faces-init t))
6147 (error (message "cperl-init-faces (ignored): %s" errs))))
6150 (defun cperl-ps-print-init ()
6151 "Initialization of `ps-print' components for faces used in CPerl."
6152 (eval-after-load "ps-print"
6153 '(setq ps-bold-faces
6154 ;; font-lock-variable-name-face
6155 ;; font-lock-constant-face
6156 (append '(cperl-array-face cperl-hash-face)
6159 ;; font-lock-constant-face
6160 (append '(cperl-nonoverridable-face cperl-hash-face)
6163 ;; font-lock-type-face
6164 (append '(cperl-array-face cperl-hash-face underline cperl-nonoverridable-face)
6165 ps-underlined-faces))))
6167 (defvar ps-print-face-extension-alist)
6169 (defun cperl-ps-print (&optional file)
6170 "Pretty-print in CPerl style.
6171 If optional argument FILE is an empty string, prints to printer, otherwise
6172 to the file FILE. If FILE is nil, prompts for a file name.
6174 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
6177 (setq file (read-from-minibuffer
6178 "Print to file (if empty - to printer): "
6179 (concat (buffer-file-name) ".ps")
6180 nil nil 'file-name-history)))
6181 (or (> (length file) 0)
6183 (require 'ps-print) ; To get ps-print-face-extension-alist
6184 (let ((ps-print-color-p t)
6185 (ps-print-face-extension-alist ps-print-face-extension-alist))
6186 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
6187 (ps-print-buffer-with-faces file)))
6189 ;;; (defun cperl-ps-print-init ()
6190 ;;; "Initialization of `ps-print' components for faces used in CPerl."
6191 ;;; ;; Guard against old versions
6192 ;;; (defvar ps-underlined-faces nil)
6193 ;;; (defvar ps-bold-faces nil)
6194 ;;; (defvar ps-italic-faces nil)
6195 ;;; (setq ps-bold-faces
6196 ;;; (append '(font-lock-emphasized-face
6197 ;;; cperl-array-face
6198 ;;; font-lock-keyword-face
6199 ;;; font-lock-variable-name-face
6200 ;;; font-lock-constant-face
6201 ;;; font-lock-reference-face
6202 ;;; font-lock-other-emphasized-face
6203 ;;; cperl-hash-face)
6205 ;;; (setq ps-italic-faces
6206 ;;; (append '(cperl-nonoverridable-face
6207 ;;; font-lock-constant-face
6208 ;;; font-lock-reference-face
6209 ;;; font-lock-other-emphasized-face
6210 ;;; cperl-hash-face)
6211 ;;; ps-italic-faces))
6212 ;;; (setq ps-underlined-faces
6213 ;;; (append '(font-lock-emphasized-face
6214 ;;; cperl-array-face
6215 ;;; font-lock-other-emphasized-face
6217 ;;; cperl-nonoverridable-face font-lock-type-face)
6218 ;;; ps-underlined-faces))
6219 ;;; (cons 'font-lock-type-face ps-underlined-faces))
6222 (if (cperl-enable-font-lock) (cperl-windowed-init))
6224 (defconst cperl-styles-entries
6225 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
6226 cperl-label-offset cperl-extra-newline-before-brace
6227 cperl-extra-newline-before-brace-multiline
6228 cperl-merge-trailing-else
6229 cperl-continued-statement-offset))
6231 (defconst cperl-style-examples
6232 "##### Numbers etc are: cperl-indent-level cperl-brace-offset
6233 ##### cperl-continued-brace-offset cperl-label-offset
6234 ##### cperl-continued-statement-offset
6235 ##### cperl-merge-trailing-else cperl-extra-newline-before-brace
6237 ########### (Do not forget cperl-extra-newline-before-brace-multiline)
6239 ### CPerl (=GNU - extra-newline-before-brace + merge-trailing-else) 2/0/0/-2/2/t/nil
6251 ### PerlStyle (=CPerl with 4 as indent) 4/0/0/-4/4/t/nil
6263 ### GNU 2/0/0/-2/2/nil/t
6278 ### C++ (=PerlStyle with braces aligned with control words) 4/0/-4/-4/4/nil/t
6293 ### BSD (=C++, but will not change preexisting merge-trailing-else
6294 ### and extra-newline-before-brace ) 4/0/-4/-4/4
6309 ### K&R (=C++ with indent 5 - merge-trailing-else, but will not
6310 ### change preexisting extra-newline-before-brace) 5/0/-5/-5/5/nil
6325 ### Whitesmith (=PerlStyle, but will not change preexisting
6326 ### extra-newline-before-brace and merge-trailing-else) 4/0/0/-4/4
6341 "Examples of if/else with different indent styles (with v4.23).")
6343 (defconst cperl-style-alist
6344 '(("CPerl" ;; =GNU - extra-newline-before-brace + cperl-merge-trailing-else
6345 (cperl-indent-level . 2)
6346 (cperl-brace-offset . 0)
6347 (cperl-continued-brace-offset . 0)
6348 (cperl-label-offset . -2)
6349 (cperl-continued-statement-offset . 2)
6350 (cperl-extra-newline-before-brace . nil)
6351 (cperl-extra-newline-before-brace-multiline . nil)
6352 (cperl-merge-trailing-else . t))
6354 ("PerlStyle" ; CPerl with 4 as indent
6355 (cperl-indent-level . 4)
6356 (cperl-brace-offset . 0)
6357 (cperl-continued-brace-offset . 0)
6358 (cperl-label-offset . -4)
6359 (cperl-continued-statement-offset . 4)
6360 (cperl-extra-newline-before-brace . nil)
6361 (cperl-extra-newline-before-brace-multiline . nil)
6362 (cperl-merge-trailing-else . t))
6365 (cperl-indent-level . 2)
6366 (cperl-brace-offset . 0)
6367 (cperl-continued-brace-offset . 0)
6368 (cperl-label-offset . -2)
6369 (cperl-continued-statement-offset . 2)
6370 (cperl-extra-newline-before-brace . t)
6371 (cperl-extra-newline-before-brace-multiline . t)
6372 (cperl-merge-trailing-else . nil))
6375 (cperl-indent-level . 5)
6376 (cperl-brace-offset . 0)
6377 (cperl-continued-brace-offset . -5)
6378 (cperl-label-offset . -5)
6379 (cperl-continued-statement-offset . 5)
6380 ;;(cperl-extra-newline-before-brace . nil) ; ???
6381 ;;(cperl-extra-newline-before-brace-multiline . nil)
6382 (cperl-merge-trailing-else . nil))
6385 (cperl-indent-level . 4)
6386 (cperl-brace-offset . 0)
6387 (cperl-continued-brace-offset . -4)
6388 (cperl-label-offset . -4)
6389 (cperl-continued-statement-offset . 4)
6390 ;;(cperl-extra-newline-before-brace . nil) ; ???
6391 ;;(cperl-extra-newline-before-brace-multiline . nil)
6392 ;;(cperl-merge-trailing-else . nil) ; ???
6396 (cperl-indent-level . 4)
6397 (cperl-brace-offset . 0)
6398 (cperl-continued-brace-offset . -4)
6399 (cperl-label-offset . -4)
6400 (cperl-continued-statement-offset . 4)
6401 (cperl-extra-newline-before-brace . t)
6402 (cperl-extra-newline-before-brace-multiline . t)
6403 (cperl-merge-trailing-else . nil))
6406 (cperl-indent-level . 4)
6407 (cperl-brace-offset . 0)
6408 (cperl-continued-brace-offset . 0)
6409 (cperl-label-offset . -4)
6410 (cperl-continued-statement-offset . 4)
6411 ;;(cperl-extra-newline-before-brace . nil) ; ???
6412 ;;(cperl-extra-newline-before-brace-multiline . nil)
6413 ;;(cperl-merge-trailing-else . nil) ; ???
6416 "List of variables to set to get a particular indentation style.
6417 Should be used via `cperl-set-style' or via Perl menu.
6419 See examples in `cperl-style-examples'.")
6421 (defun cperl-set-style (style)
6422 "Set CPerl mode variables to use one of several different indentation styles.
6423 The arguments are a string representing the desired style.
6424 The list of styles is in `cperl-style-alist', available styles
6425 are CPerl, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith.
6427 The current value of style is memorized (unless there is a memorized
6428 data already), may be restored by `cperl-set-style-back'.
6430 Chosing \"Current\" style will not change style, so this may be used for
6431 side-effect of memorizing only. Examples in `cperl-style-examples'."
6433 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
6434 cperl-style-alist)))
6435 (list (completing-read "Enter style: " list nil 'insist))))
6437 (setq cperl-old-style
6440 (cons name (eval name))))
6441 cperl-styles-entries)))
6442 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
6444 (setq setting (car style) style (cdr style))
6445 (set (car setting) (cdr setting)))))
6447 (defun cperl-set-style-back ()
6448 "Restore a style memorized by `cperl-set-style'."
6450 (or cperl-old-style (error "The style was not changed"))
6452 (while cperl-old-style
6453 (setq setting (car cperl-old-style)
6454 cperl-old-style (cdr cperl-old-style))
6455 (set (car setting) (cdr setting)))))
6457 (defun cperl-check-syntax ()
6459 (require 'mode-compile)
6460 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
6461 (eval '(mode-compile)))) ; Avoid a warning
6463 (defun cperl-info-buffer (type)
6464 ;; Returns buffer with documentation. Creates if missing.
6465 ;; If TYPE, this vars buffer.
6466 ;; Special care is taken to not stomp over an existing info buffer
6467 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
6468 (info (get-buffer bname))
6469 (oldbuf (get-buffer "*info*")))
6471 (save-window-excursion
6476 (rename-buffer "*info-perl-tmp*")))
6477 (save-window-excursion
6479 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
6480 (set-buffer "*info*")
6481 (rename-buffer bname)
6483 (set-buffer "*info-perl-tmp*")
6484 (rename-buffer "*info*")
6485 (set-buffer bname)))
6486 (make-local-variable 'window-min-height)
6487 (setq window-min-height 2)
6488 (current-buffer)))))
6490 (defun cperl-word-at-point (&optional p)
6491 "Return the word at point or at P."
6493 (if p (goto-char p))
6494 (or (cperl-word-at-point-hard)
6497 (funcall (or (and (boundp 'find-tag-default-function)
6498 find-tag-default-function)
6499 (get major-mode 'find-tag-default-function)
6500 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
6501 ;; automatically used within `find-tag-default':
6502 'find-tag-default))))))
6504 (defun cperl-info-on-command (command)
6505 "Show documentation for Perl command COMMAND in other window.
6506 If perl-info buffer is shown in some frame, uses this frame.
6507 Customized by setting variables `cperl-shrink-wrap-info-frame',
6508 `cperl-max-help-size'."
6510 (let* ((default (cperl-word-at-point))
6512 (format "Find doc for Perl function (default %s): "
6514 (list (if (equal read "")
6518 (let ((buffer (current-buffer))
6519 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
6520 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
6521 max-height char-height buf-list)
6522 (if (string-match "^-[a-zA-Z]$" command)
6523 (setq cmd-desc "^-X[ \t\n]"))
6524 (setq isvar (string-match "^[$@%]" command)
6525 buf (cperl-info-buffer isvar)
6526 iniwin (selected-window)
6527 fr1 (window-frame iniwin))
6529 (goto-char (point-min))
6531 (progn (re-search-forward "^-X[ \t\n]")
6533 (if (re-search-forward cmd-desc nil t)
6535 ;; Go back to beginning of the group (ex, for qq)
6536 (if (re-search-backward "^[ \t\n\f]")
6541 buf-list (list buf "*info-perl-var*" "*info-perl*"))
6542 (while (and (not win) buf-list)
6543 (setq win (get-buffer-window (car buf-list) t))
6544 (setq buf-list (cdr buf-list)))
6546 (eq (window-buffer win) buf)
6547 (set-window-buffer win buf))
6548 (and win (setq fr2 (window-frame win)))
6549 (if (or (not fr2) (eq fr1 fr2))
6551 (special-display-popup-frame buf) ; Make it visible
6552 (select-window win))
6553 (goto-char pos) ; Needed (?!).
6555 (setq iniheight (window-height)
6556 frheight (frame-height)
6557 not-loner (< iniheight (1- frheight))) ; Are not alone
6558 (cond ((if not-loner cperl-max-help-size
6559 cperl-shrink-wrap-info-frame)
6565 (if (re-search-forward
6566 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
6567 (match-beginning 0) (point-max)))))
6570 (/ (* (- frheight 3) cperl-max-help-size) 100)
6571 (setq char-height (frame-char-height))
6572 ;; Non-functioning under OS/2:
6573 (if (eq char-height 1) (setq char-height 18))
6574 ;; Title, menubar, + 2 for slack
6575 (- (/ (display-pixel-height) char-height) 4)))
6576 (if (> height max-height) (setq height max-height))
6577 ;;(message "was %s doing %s" iniheight height)
6579 (enlarge-window (- height iniheight))
6580 (set-frame-height (window-frame win) (1+ height)))))
6581 (set-window-start (selected-window) pos))
6582 (message "No entry for %s found." command))
6583 ;;(pop-to-buffer buffer)
6584 (select-window iniwin)))
6586 (defun cperl-info-on-current-command ()
6587 "Show documentation for Perl command at point in other window."
6589 (cperl-info-on-command (cperl-word-at-point)))
6591 (defun cperl-imenu-info-imenu-search ()
6592 (if (looking-at "^-X[ \t\n]") nil
6594 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
6597 (defun cperl-imenu-info-imenu-name ()
6599 (match-beginning 1) (match-end 1)))
6601 (defun cperl-imenu-on-info ()
6602 "Shows imenu for Perl Info Buffer.
6603 Opens Perl Info buffer if needed."
6605 (let* ((buffer (current-buffer))
6606 imenu-create-index-function
6607 imenu-prev-index-position-function
6608 imenu-extract-index-name-function
6609 (index-item (save-restriction
6610 (save-window-excursion
6611 (set-buffer (cperl-info-buffer nil))
6612 (setq imenu-create-index-function
6613 'imenu-default-create-index-function
6614 imenu-prev-index-position-function
6615 'cperl-imenu-info-imenu-search
6616 imenu-extract-index-name-function
6617 'cperl-imenu-info-imenu-name)
6618 (imenu-choose-buffer-index)))))
6622 (pop-to-buffer "*info-perl*")
6624 ((markerp (cdr index-item))
6625 (goto-char (marker-position (cdr index-item))))
6627 (goto-char (cdr index-item))))
6628 (set-window-start (selected-window) (point))
6629 (pop-to-buffer buffer)))))
6631 (defun cperl-lineup (beg end &optional step minshift)
6632 "Lineup construction in a region.
6633 Beginning of region should be at the start of a construction.
6634 All first occurrences of this construction in the lines that are
6635 partially contained in the region are lined up at the same column.
6637 MINSHIFT is the minimal amount of space to insert before the construction.
6638 STEP is the tabwidth to position constructions.
6639 If STEP is nil, `cperl-lineup-step' will be used
6640 \(or `cperl-indent-level', if `cperl-lineup-step' is nil).
6641 Will not move the position at the start to the left."
6643 (let (search col tcol seen b)
6647 (setq end (point-marker))
6649 (skip-chars-forward " \t\f")
6650 (setq beg (point-marker))
6651 (indent-region beg end nil)
6653 (setq col (current-column))
6654 (if (looking-at "[a-zA-Z0-9_]")
6655 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
6659 (buffer-substring (match-beginning 0)
6660 (match-end 0))) "\\>"))
6661 (error "Cannot line up in a middle of the word"))
6662 (if (looking-at "$")
6663 (error "Cannot line up end of line"))
6664 (setq search (regexp-quote (char-to-string (following-char)))))
6665 (setq step (or step cperl-lineup-step cperl-indent-level))
6666 (or minshift (setq minshift 1))
6668 (beginning-of-line 2)
6669 (and (< (point) end)
6670 (re-search-forward search end t)
6671 (goto-char (match-beginning 0))))
6672 (setq tcol (current-column) seen t)
6673 (if (> tcol col) (setq col tcol)))
6675 (error "The construction to line up occurred only once"))
6677 (setq col (+ col minshift))
6678 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
6681 (cperl-make-indent col)
6682 (beginning-of-line 2)
6683 (and (< (point) end)
6684 (re-search-forward search end t)
6685 (goto-char (match-beginning 0)))))))) ; No body
6687 (defun cperl-etags (&optional add all files) ;; NOT USED???
6688 "Run etags with appropriate options for Perl files.
6689 If optional argument ALL is `recursive', will process Perl files
6690 in subdirectories too."
6693 (args '("-l" "none" "-r"
6694 ;; 1=fullname 2=package? 3=name 4=proto? 5=attrs? (VERY APPROX!)
6695 "/\\<sub[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([ \t]*:[^#{;]*\\)?\\([{#]\\|$\\)/\\3/"
6697 "/\\<package[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\([#;]\\|$\\)/\\1/"
6699 "/\\<\\(package\\)[ \\t]*;/\\1;/"))
6701 (if add (setq args (cons "-a" args)))
6702 (or files (setq files (list buffer-file-name)))
6704 ((eq all 'recursive)
6705 ;;(error "Not implemented: recursive")
6706 (setq args (append (list "-e"
6707 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
6709 find(\\&wanted, '.');
6714 ;;(error "Not implemented: all")
6715 (setq args (append (list "-e"
6716 "push @ARGV, <*.PL *.pl *.pm>;
6721 (setq args (append args files))))
6722 (setq res (apply 'call-process cmd nil nil nil args))
6724 (message "etags returned \"%s\"" res))))
6726 (defun cperl-toggle-auto-newline ()
6727 "Toggle the state of `cperl-auto-newline'."
6729 (setq cperl-auto-newline (not cperl-auto-newline))
6730 (message "Newlines will %sbe auto-inserted now."
6731 (if cperl-auto-newline "" "not ")))
6733 (defun cperl-toggle-abbrev ()
6734 "Toggle the state of automatic keyword expansion in CPerl mode."
6736 (abbrev-mode (if abbrev-mode 0 1))
6737 (message "Perl control structure will %sbe auto-inserted now."
6738 (if abbrev-mode "" "not ")))
6741 (defun cperl-toggle-electric ()
6742 "Toggle the state of parentheses doubling in CPerl mode."
6744 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
6745 (message "Parentheses will %sbe auto-doubled now."
6746 (if (cperl-val 'cperl-electric-parens) "" "not ")))
6748 (defun cperl-toggle-autohelp ()
6749 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
6750 Delay of auto-help controlled by `cperl-lazy-help-time'."
6752 (if (fboundp 'run-with-idle-timer)
6754 (if cperl-lazy-installed
6755 (cperl-lazy-unstall)
6756 (cperl-lazy-install))
6757 (message "Perl help messages will %sbe automatically shown now."
6758 (if cperl-lazy-installed "" "not ")))
6759 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
6761 (defun cperl-toggle-construct-fix ()
6762 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
6764 (setq cperl-indent-region-fix-constructs
6765 (if cperl-indent-region-fix-constructs
6768 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
6769 (if cperl-indent-region-fix-constructs "" "not ")))
6771 (defun cperl-toggle-set-debug-unwind (arg &optional backtrace)
6772 "Toggle (or, with numeric argument, set) debugging state of syntaxification.
6773 Nonpositive numeric argument disables debugging messages. The message
6774 summarizes which regions it was decided to rescan for syntactic constructs.
6776 The message looks like this:
6778 Syxify req=123..138 actual=101..146 done-to: 112=>146 statepos: 73=>117
6780 Numbers are character positions in the buffer. REQ provides the range to
6781 rescan requested by `font-lock'. ACTUAL is the range actually resyntaxified;
6782 for correct operation it should start and end outside any special syntactic
6783 construct. DONE-TO and STATEPOS indicate changes to internal caches maintained
6787 (setq arg (if (eq cperl-syntaxify-by-font-lock
6788 (if backtrace 'backtrace 'message)) 0 1)))
6789 (setq arg (if (> arg 0) (if backtrace 'backtrace 'message) t))
6790 (setq cperl-syntaxify-by-font-lock arg)
6791 (message "Debugging messages of syntax unwind %sabled."
6792 (if (eq arg t) "dis" "en")))
6794 ;;;; Tags file creation.
6796 (defvar cperl-tmp-buffer " *cperl-tmp*")
6798 (defun cperl-setup-tmp-buf ()
6799 (set-buffer (get-buffer-create cperl-tmp-buffer))
6800 (set-syntax-table cperl-mode-syntax-table)
6801 (buffer-disable-undo)
6803 (if cperl-use-syntax-table-text-property-for-tags
6805 (make-local-variable 'parse-sexp-lookup-properties)
6806 ;; Do not introduce variable if not needed, we check it!
6807 (set 'parse-sexp-lookup-properties t))))
6809 (defun cperl-xsub-scan ()
6811 (let ((index-alist '())
6812 (prev-pos 0) index index1 name package prefix)
6813 (goto-char (point-min))
6814 ;; Search for the function
6815 (progn ;;save-match-data
6816 (while (re-search-forward
6817 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
6820 ((match-beginning 2) ; SECTION
6821 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
6822 (goto-char (match-beginning 0))
6823 (skip-chars-forward " \t")
6825 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
6826 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
6828 ((not package) nil) ; C language section
6829 ((match-beginning 3) ; XSUB
6830 (goto-char (1+ (match-beginning 3)))
6831 (setq index (imenu-example--name-and-position))
6832 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
6833 (if (and prefix (string-match (concat "^" prefix) name))
6834 (setq name (substring name (length prefix))))
6835 (cond ((string-match "::" name) nil)
6837 (setq index1 (cons (concat package "::" name) (cdr index)))
6838 (push index1 index-alist)))
6840 (push index index-alist))
6842 ;; (beginning-of-line)
6843 (setq index (imenu-example--name-and-position))
6844 (setcar index (concat package "::BOOT:"))
6845 (push index index-alist)))))
6848 (defvar cperl-unreadable-ok nil)
6850 (defun cperl-find-tags (ifile xs topdir)
6851 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
6852 (cperl-pod-here-fontify nil) f file)
6854 (if b (set-buffer b)
6855 (cperl-setup-tmp-buf))
6858 (setq file (car (insert-file-contents ifile)))
6859 (error (if cperl-unreadable-ok nil
6861 (format "File %s unreadable. Continue? " ifile))
6862 (setq cperl-unreadable-ok t)
6863 (error "Aborting: unreadable file %s" ifile)))))
6865 (message "Unreadable file %s" ifile)
6866 (message "Scanning file %s ..." file)
6867 (if (and cperl-use-syntax-table-text-property-for-tags
6869 (condition-case err ; after __END__ may have garbage
6870 (cperl-find-pods-heres nil nil noninteractive)
6871 (error (message "While scanning for syntax: %s" err))))
6873 (setq lst (cperl-xsub-scan))
6874 (setq ind (cperl-imenu--create-perl-index))
6875 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
6880 (cond ((string-match "^[_a-zA-Z]" (car elt))
6881 (goto-char (cdr elt))
6882 (beginning-of-line) ; pos should be of the start of the line
6885 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
6886 (buffer-substring (progn
6887 (goto-char (cdr elt))
6888 ;; After name now...
6889 (or (eolp) (forward-char 1))
6897 (setq elt (car lst) lst (cdr lst))
6902 (if (string-match "^package " (car elt))
6903 (substring (car elt) 8)
6906 (number-to-string (elt elt 2)) ; Line
6908 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
6910 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
6911 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
6913 ;; Need to insert the name without package as well
6914 (setq lst (cons (cons (substring (elt elt 3)
6922 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
6923 (set-text-properties 0 (length rel) nil rel)
6924 (and (equal topdir (substring rel 0 (length topdir)))
6925 (setq rel (substring file (length topdir))))
6926 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
6927 (setq ret (buffer-substring 1 (point-max)))
6930 (message "Scanning file %s finished" file))
6933 (defun cperl-add-tags-recurse-noxs ()
6934 "Add to TAGS data for \"pure\" Perl files in the current directory and kids.
6936 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
6937 -f cperl-add-tags-recurse-noxs
6939 (cperl-write-tags nil nil t t nil t))
6941 (defun cperl-add-tags-recurse-noxs-fullpath ()
6942 "Add to TAGS data for \"pure\" Perl in the current directory and kids.
6943 Writes down fullpath, so TAGS is relocatable (but if the build directory
6944 is relocated, the file TAGS inside it breaks). Use as
6945 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
6946 -f cperl-add-tags-recurse-noxs-fullpath
6948 (cperl-write-tags nil nil t t nil t ""))
6950 (defun cperl-add-tags-recurse ()
6951 "Add to TAGS file data for Perl files in the current directory and kids.
6953 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
6954 -f cperl-add-tags-recurse
6956 (cperl-write-tags nil nil t t))
6958 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
6959 ;; If INBUFFER, do not select buffer, and do not save
6960 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
6963 (setq file (if dir default-directory (buffer-file-name)))
6964 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
6966 (setq topdir default-directory))
6967 (let ((tags-file-name "TAGS")
6968 (case-fold-search (eq system-type 'emx))
6971 (cond (inbuffer nil) ; Already there
6972 ((file-exists-p tags-file-name)
6973 (if (featurep 'xemacs)
6974 (visit-tags-table-buffer)
6975 (visit-tags-table-buffer tags-file-name)))
6976 (t (set-buffer (find-file-noselect tags-file-name))))
6979 (cond ((eq erase 'ignore))
6982 (setq erase 'ignore)))
6985 (directory-files file t
6986 (if recurse nil cperl-scan-files-regexp)
6989 (if cperl-unreadable-ok nil
6991 (format "Directory %s unreadable. Continue? " file))
6992 (setq cperl-unreadable-ok t
6993 tm nil) ; Return empty list
6994 (error "Aborting: unreadable directory %s" file)))))))
6998 ((string-match cperl-noscan-files-regexp file)
7000 ((not (file-directory-p file))
7001 (if (string-match cperl-scan-files-regexp file)
7002 (cperl-write-tags file erase recurse nil t noxs topdir)))
7004 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
7007 (setq xs (string-match "\\.xs$" file))
7008 (if (not (and xs noxs))
7010 (cond ((eq erase 'ignore) (goto-char (point-max)))
7011 (erase (erase-buffer))
7015 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
7016 (set-text-properties 0 (length rel) nil rel)
7017 (and (equal topdir (substring rel 0 (length topdir)))
7018 (setq rel (substring file (length topdir))))
7019 (if (search-forward (concat "\f\n" rel ",") nil t)
7021 (search-backward "\f\n")
7022 (delete-region (point)
7025 (if (search-forward "\f\n"
7029 (goto-char (point-max)))))
7030 (insert (cperl-find-tags file xs topdir))))))
7031 (if inbuffer nil ; Delegate to the caller
7032 (save-buffer 0) ; No backup
7033 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
7034 (initialize-new-tags-table))))))
7036 (defvar cperl-tags-hier-regexp-list
7043 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
7045 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
7048 (defvar cperl-hierarchy '(() ())
7049 "Global hierarchy of classes.")
7051 (defun cperl-tags-hier-fill ()
7052 ;; Suppose we are in a tag table cooked by cperl.
7054 (let (type pack name pos line chunk ord cons1 file str info fileind)
7055 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
7056 (setq pos (match-beginning 0)
7057 pack (match-beginning 2))
7059 (if (looking-at (concat
7068 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
7069 name (buffer-substring (match-beginning 2) (match-end 2))
7070 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
7071 line (buffer-substring (match-beginning 3) (match-end 3))
7074 fileind (format "%s:%s" file line)
7075 ;; Moves to beginning of the next line:
7076 info (cperl-etags-snarf-tag file line))
7079 ;; Make new member of hierarchy name ==> file ==> pos if needed
7080 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
7082 (setcdr cons1 (cons (cons fileind (vector file info))
7084 ;; First occurrence of the name, start alist
7085 (setq cons1 (cons name (list (cons fileind (vector file info)))))
7087 (setcar (cdr cperl-hierarchy)
7088 (cons cons1 (nth 1 cperl-hierarchy)))
7089 (setcar cperl-hierarchy
7090 (cons cons1 (car cperl-hierarchy)))))))
7093 (declare-function x-popup-menu "xmenu.c" (position menu))
7095 (defun cperl-tags-hier-init (&optional update)
7096 "Show hierarchical menu of classes and methods.
7097 Finds info about classes by a scan of loaded TAGS files.
7098 Supposes that the TAGS files contain fully qualified function names.
7099 One may build such TAGS files from CPerl mode menu."
7103 (if (or update (null (nth 2 cperl-hierarchy)))
7104 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
7107 (setcdr elt (cdr (nth 1 elt)))))))
7108 pack name cons1 to l1 l2 l3 l4 b)
7109 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
7110 (setq cperl-hierarchy (list l1 l2 l3))
7111 (if (featurep 'xemacs) ; Not checked
7114 ;; Does this work in XEmacs?
7115 (call-interactively 'visit-tags-table))
7116 (message "Updating list of classes...")
7117 (set-buffer (get-file-buffer tags-file-name))
7118 (cperl-tags-hier-fill))
7120 (call-interactively 'visit-tags-table))
7124 (message "Updating list of classes... %s" tagsfile)
7125 (set-buffer (get-file-buffer tagsfile))
7126 (cperl-tags-hier-fill)))
7128 (message "Updating list of classes... postprocessing..."))
7129 (mapc remover (car cperl-hierarchy))
7130 (mapc remover (nth 1 cperl-hierarchy))
7131 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
7132 (cons "Methods: " (car cperl-hierarchy))))
7133 (cperl-tags-treeify to 1)
7134 (setcar (nthcdr 2 cperl-hierarchy)
7135 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
7136 (message "Updating list of classes: done, requesting display...")
7137 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
7139 (or (nth 2 cperl-hierarchy)
7140 (error "No items found"))
7142 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
7143 (if (if (fboundp 'display-popup-menus-p)
7144 (let ((f 'display-popup-menus-p))
7147 (x-popup-menu t (nth 2 cperl-hierarchy))
7149 (tmm-prompt (nth 2 cperl-hierarchy))))
7150 (if (and update (listp update))
7151 (progn (while (cdr update) (setq update (cdr update)))
7152 (setq update (car update)))) ; Get the last from the list
7153 (if (vectorp update)
7155 (find-file (elt update 0))
7156 (cperl-etags-goto-tag-location (elt update 1))))
7157 (if (eq update -999) (cperl-tags-hier-init t)))
7159 (defun cperl-tags-treeify (to level)
7160 ;; cadr of `to' is read-write. On start it is a cons
7161 (let* ((regexp (concat "^\\(" (mapconcat
7163 (make-list level "[_a-zA-Z0-9]+")
7166 (packages (cdr (nth 1 to)))
7167 (methods (cdr (nth 2 to)))
7168 l1 head tail cons1 cons2 ord writeto packs recurse
7169 root-packages root-functions ms many_ms same_name ps
7173 (cond ((and (string-match regexp (car elt))
7174 (or (eq ord 1) (match-end 2)))
7175 (setq head (substring (car elt) 0 (match-end 1))
7176 tail (if (match-end 2) (substring (car elt)
7179 (if (setq cons1 (assoc head writeto)) nil
7180 ;; Need to init new head
7181 (setcdr writeto (cons (list head (list "Packages: ")
7184 (setq cons1 (nth 1 writeto)))
7185 (setq cons2 (nth ord cons1)) ; Either packs or meths
7186 (setcdr cons2 (cons elt (cdr cons2))))
7188 (setq root-functions (cons elt root-functions)))
7190 (setq root-packages (cons elt root-packages))))))))
7191 (setcdr to l1) ; Init to dynamic space
7194 (mapc move-deeper packages)
7196 (mapc move-deeper methods)
7198 (mapc (function (lambda (elt)
7199 (cperl-tags-treeify elt (1+ level))))
7201 ;;Now clean up leaders with one child only
7202 (mapc (function (lambda (elt)
7203 (if (not (and (listp (cdr elt))
7204 (eq (length elt) 2))) nil
7205 (setcar elt (car (nth 1 elt)))
7206 (setcdr elt (cdr (nth 1 elt))))))
7208 ;; Sort the roots of subtrees
7209 (if (default-value 'imenu-sort-function)
7211 (sort (cdr to) (default-value 'imenu-sort-function))))
7212 ;; Now add back functions removed from display
7213 (mapc (function (lambda (elt)
7214 (setcdr to (cons elt (cdr to)))))
7215 (if (default-value 'imenu-sort-function)
7217 (sort root-functions (default-value 'imenu-sort-function)))
7219 ;; Now add back packages removed from display
7220 (mapc (function (lambda (elt)
7221 (setcdr to (cons (cons (concat "package " (car elt))
7224 (if (default-value 'imenu-sort-function)
7226 (sort root-packages (default-value 'imenu-sort-function)))
7230 ;;; '(keymap "Name1"
7234 ;;; ("Tail1" "x") ("Tail2" "y"))))
7236 (defun cperl-list-fold (list name limit)
7237 (let (list1 list2 elt1 (num 0))
7238 (if (<= (length list) limit) list
7239 (setq list1 nil list2 nil)
7244 (if (<= num imenu-max-items)
7245 (setq list2 (cons elt1 list2))
7246 (setq list1 (cons (cons name
7251 (nreverse (cons (cons name
7255 (defun cperl-menu-to-keymap (menu &optional name)
7261 (cond ((listp (cdr elt))
7262 (setq list (cperl-list-fold
7263 (cdr elt) (car elt) imenu-max-items))
7266 (cperl-menu-to-keymap list))))
7268 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
7269 (cperl-list-fold menu "Root" imenu-max-items)))))
7272 (defvar cperl-bad-style-regexp
7273 (mapconcat 'identity
7274 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
7275 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
7277 "Finds places such that insertion of a whitespace may help a lot.")
7279 (defvar cperl-not-bad-style-regexp
7282 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
7283 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
7284 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
7285 "<\\$?\\sw+\\(\\.\\(\\sw\\|_\\)+\\)?>" ; <IN> <stdin.h>
7286 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
7293 "\\\\[&$@*\\\\]" ; \&func
7296 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
7299 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
7300 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
7301 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
7305 "If matches at the start of match found by `my-bad-c-style-regexp',
7306 insertion of a whitespace will not help.")
7310 (defun cperl-find-bad-style ()
7311 "Find places in the buffer where insertion of a whitespace may help.
7312 Prompts user for insertion of spaces.
7313 Currently it is tuned to C and Perl syntax."
7315 (let (found-bad (p (point)))
7316 (setq last-nonmenu-event 13) ; To disable popup
7317 (goto-char (point-min))
7318 (map-y-or-n-p "Insert space here? "
7319 (lambda (arg) (insert " "))
7320 'cperl-next-bad-style
7321 '("location" "locations" "insert a space into")
7322 '((?\C-r (lambda (arg)
7323 (let ((buffer-quit-function
7324 'exit-recursive-edit))
7325 (message "Exit with Esc Esc")
7327 t)) ; Consider acted upon
7328 "edit, exit with Esc Esc")
7330 (let ((buffer-quit-function
7331 'exit-recursive-edit))
7332 (message "Exit with Esc Esc")
7334 t)) ; Consider acted upon
7335 "edit, exit with Esc Esc"))
7337 (if found-bad (goto-char found-bad)
7339 (message "No appropriate place found"))))
7341 (defun cperl-next-bad-style ()
7342 (let (p (not-found t) (point (point)) found)
7343 (while (and not-found
7344 (re-search-forward cperl-bad-style-regexp nil 'to-end))
7346 (goto-char (match-beginning 0))
7348 (looking-at cperl-not-bad-style-regexp)
7349 ;; Check for a < -b and friends
7350 (and (eq (following-char) ?\-)
7352 (skip-chars-backward " \t\n")
7353 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
7354 ;; Now check for syntax type
7356 (setq found (point))
7357 (beginning-of-defun)
7358 (let ((pps (parse-partial-sexp (point) found)))
7359 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
7360 (goto-char (match-end 0))
7368 (defvar cperl-have-help-regexp
7372 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
7373 "[$@]\\^[a-zA-Z]" ; Special variable
7374 "[$@][^ \n\t]" ; Special variable
7375 "-[a-zA-Z]" ; File test
7376 "\\\\[a-zA-Z0]" ; Special chars
7377 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
7378 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
7379 "[a-zA-Z_0-9:]+" ; symbol or number
7386 "Matches places in the buffer we can find help for.")
7388 (defvar cperl-message-on-help-error t)
7389 (defvar cperl-help-from-timer nil)
7391 (defun cperl-word-at-point-hard ()
7392 ;; Does not save-excursion
7393 ;; Get to the something meaningful
7394 (or (eobp) (eolp) (forward-char 1))
7395 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
7396 (save-excursion (beginning-of-line) (point))
7399 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
7400 ;; (skip-chars-backward " \n\t\r({[]});,")
7401 ;; (or (bobp) (backward-char 1))))
7404 ((looking-at "[a-zA-Z0-9_:]") ; symbol
7405 (skip-chars-backward "a-zA-Z0-9_:")
7407 ((and (eq (preceding-char) ?^) ; $^I
7408 (eq (char-after (- (point) 2)) ?\$))
7410 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
7412 ((and (eq (preceding-char) ?\=)
7413 (eq (current-column) 1))
7414 (forward-char -1))) ; =head1
7415 (if (and (eq (preceding-char) ?\<)
7416 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
7418 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
7420 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
7422 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
7423 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
7425 ((and (eq (preceding-char) ?\$)
7426 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
7428 ((and (eq (following-char) ?\>)
7429 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
7432 (and (eq (preceding-char) ?\<)
7433 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
7434 (search-backward "<"))))
7435 ((and (eq (following-char) ?\$)
7436 (eq (preceding-char) ?\<)
7437 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
7439 (if (looking-at cperl-have-help-regexp)
7440 (buffer-substring (match-beginning 0) (match-end 0))))
7442 (defun cperl-get-help ()
7443 "Get one-line docs on the symbol at the point.
7444 The data for these docs is a little bit obsolete and may be in fact longer
7445 than a line. Your contribution to update/shorten it is appreciated."
7447 (save-match-data ; May be called "inside" query-replace
7449 (let ((word (cperl-word-at-point-hard)))
7451 (if (and cperl-help-from-timer ; Bail out if not in mainland
7452 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
7453 (or (memq (get-text-property (point) 'face)
7454 '(font-lock-comment-face font-lock-string-face))
7455 (memq (get-text-property (point) 'syntax-type)
7456 '(pod here-doc format))))
7458 (cperl-describe-perl-symbol word))
7459 (if cperl-message-on-help-error
7460 (message "Nothing found for %s..."
7461 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
7463 ;;; Stolen from perl-descr.el by Johan Vromans:
7465 (defvar cperl-doc-buffer " *perl-doc*"
7466 "Where the documentation can be found.")
7468 (defun cperl-describe-perl-symbol (val)
7469 "Display the documentation of symbol at point, a Perl operator."
7470 (let ((enable-recursive-minibuffers t)
7473 ((string-match "^[&*][a-zA-Z_]" val)
7474 (setq val (concat (substring val 0 1) "NAME")))
7475 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
7476 (setq val (concat "@" (substring val 1 (match-end 1)))))
7477 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
7478 (setq val (concat "%" (substring val 1 (match-end 1)))))
7479 ((and (string= val "x") (string-match "^x=" val))
7481 ((string-match "^\\$[\C-a-\C-z]" val)
7482 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
7483 ((string-match "^CORE::" val)
7484 (setq val "CORE::"))
7485 ((string-match "^SUPER::" val)
7486 (setq val "SUPER::"))
7487 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
7488 (setq val "<NAME>")))
7489 (setq regexp (concat "^"
7490 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
7492 "\\([ \t([/]\\|$\\)"))
7494 ;; get the buffer with the documentation text
7495 (cperl-switch-to-doc-buffer)
7497 ;; lookup in the doc
7498 (goto-char (point-min))
7499 (let ((case-fold-search nil))
7501 (if (re-search-forward regexp (point-max) t)
7503 (beginning-of-line 1)
7504 (let ((lnstart (point)))
7506 (message "%s" (buffer-substring lnstart (point)))))
7507 (if cperl-message-on-help-error
7508 (message "No definition for %s" val)))))))
7510 (defvar cperl-short-docs 'please-ignore-this-line
7511 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
7512 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
7513 ... Range (list context); flip/flop [no flop when flip] (scalar context).
7514 ! ... Logical negation.
7515 ... != ... Numeric inequality.
7516 ... !~ ... Search pattern, substitution, or translation (negated).
7517 $! In numeric context: errno. In a string context: error string.
7518 $\" The separator which joins elements of arrays interpolated in strings.
7519 $# The output format for printed numbers. Default is %.15g or close.
7520 $$ Process number of this script. Changes in the fork()ed child process.
7521 $% The current page number of the currently selected output channel.
7523 The following variables are always local to the current block:
7525 $1 Match of the 1st set of parentheses in the last match (auto-local).
7526 $2 Match of the 2nd set of parentheses in the last match (auto-local).
7527 $3 Match of the 3rd set of parentheses in the last match (auto-local).
7528 $4 Match of the 4th set of parentheses in the last match (auto-local).
7529 $5 Match of the 5th set of parentheses in the last match (auto-local).
7530 $6 Match of the 6th set of parentheses in the last match (auto-local).
7531 $7 Match of the 7th set of parentheses in the last match (auto-local).
7532 $8 Match of the 8th set of parentheses in the last match (auto-local).
7533 $9 Match of the 9th set of parentheses in the last match (auto-local).
7534 $& The string matched by the last pattern match (auto-local).
7535 $' The string after what was matched by the last match (auto-local).
7536 $` The string before what was matched by the last match (auto-local).
7538 $( The real gid of this process.
7539 $) The effective gid of this process.
7540 $* Deprecated: Set to 1 to do multiline matching within a string.
7541 $+ The last bracket matched by the last search pattern.
7542 $, The output field separator for the print operator.
7543 $- The number of lines left on the page.
7544 $. The current input line number of the last filehandle that was read.
7545 $/ The input record separator, newline by default.
7546 $0 Name of the file containing the current perl script (read/write).
7547 $: String may be broken after these characters to fill ^-lines in a format.
7548 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
7549 $< The real uid of this process.
7550 $= The page length of the current output channel. Default is 60 lines.
7551 $> The effective uid of this process.
7552 $? The status returned by the last ``, pipe close or `system'.
7553 $@ The perl error message from the last eval or do @var{EXPR} command.
7554 $ARGV The name of the current file used with <> .
7555 $[ Deprecated: The index of the first element/char in an array/string.
7556 $\\ The output record separator for the print operator.
7557 $] The perl version string as displayed with perl -v.
7558 $^ The name of the current top-of-page format.
7559 $^A The current value of the write() accumulator for format() lines.
7560 $^D The value of the perl debug (-D) flags.
7561 $^E Information about the last system error other than that provided by $!.
7562 $^F The highest system file descriptor, ordinarily 2.
7563 $^H The current set of syntax checks enabled by `use strict'.
7564 $^I The value of the in-place edit extension (perl -i option).
7565 $^L What formats output to perform a formfeed. Default is \\f.
7566 $^M A buffer for emergency memory allocation when running out of memory.
7567 $^O The operating system name under which this copy of Perl was built.
7568 $^P Internal debugging flag.
7569 $^T The time the script was started. Used by -A/-M/-C file tests.
7570 $^W True if warnings are requested (perl -w flag).
7571 $^X The name under which perl was invoked (argv[0] in C-speech).
7572 $_ The default input and pattern-searching space.
7573 $| Auto-flush after write/print on current output channel? Default 0.
7574 $~ The name of the current report format.
7575 ... % ... Modulo division.
7576 ... %= ... Modulo division assignment.
7577 %ENV Contains the current environment.
7578 %INC List of files that have been require-d or do-ne.
7579 %SIG Used to set signal handlers for various signals.
7580 ... & ... Bitwise and.
7581 ... && ... Logical and.
7582 ... &&= ... Logical and assignment.
7583 ... &= ... Bitwise and assignment.
7584 ... * ... Multiplication.
7585 ... ** ... Exponentiation.
7586 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
7587 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
7588 ... + ... Addition. +EXPR Makes EXPR into scalar context.
7589 ++ Auto-increment (magical on strings). ++EXPR EXPR++
7590 ... += ... Addition assignment.
7592 ... - ... Subtraction.
7593 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
7594 ... -= ... Subtraction assignment.
7595 -A Access time in days since script started.
7596 -B File is a non-text (binary) file.
7597 -C Inode change time in days since script started.
7598 -M Age in days since script started.
7599 -O File is owned by real uid.
7600 -R File is readable by real uid.
7601 -S File is a socket .
7602 -T File is a text file.
7603 -W File is writable by real uid.
7604 -X File is executable by real uid.
7605 -b File is a block special file.
7606 -c File is a character special file.
7607 -d File is a directory.
7609 -f File is a plain file.
7610 -g File has setgid bit set.
7611 -k File has sticky bit set.
7612 -l File is a symbolic link.
7613 -o File is owned by effective uid.
7614 -p File is a named pipe (FIFO).
7615 -r File is readable by effective uid.
7616 -s File has non-zero size.
7617 -t Tests if filehandle (STDIN by default) is opened to a tty.
7618 -u File has setuid bit set.
7619 -w File is writable by effective uid.
7620 -x File is executable by effective uid.
7621 -z File has zero size.
7622 . Concatenate strings.
7623 .. Range (list context); flip/flop (scalar context) operator.
7624 .= Concatenate assignment strings
7625 ... / ... Division. /PATTERN/ioxsmg Pattern match
7626 ... /= ... Division assignment.
7627 /PATTERN/ioxsmg Pattern match.
7628 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
7629 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
7630 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
7631 <> Reads line from union of files in @ARGV (= command line) and STDIN.
7632 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
7633 ... <= ... Numeric less than or equal to.
7634 ... <=> ... Numeric compare.
7635 ... = ... Assignment.
7636 ... == ... Numeric equality.
7637 ... =~ ... Search pattern, substitution, or translation
7638 ... > ... Numeric greater than.
7639 ... >= ... Numeric greater than or equal to.
7640 ... >> ... Bitwise shift right.
7641 ... >>= ... Bitwise shift right assignment.
7642 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
7643 ?PATTERN? One-time pattern match.
7644 @ARGV Command line arguments (not including the command name - see $0).
7645 @INC List of places to look for perl scripts during do/include/use.
7646 @_ Parameter array for subroutines; result of split() unless in list context.
7647 \\ Creates reference to what follows, like \\$var, or quotes non-\\w in strings.
7648 \\0 Octal char, e.g. \\033.
7649 \\E Case modification terminator. See \\Q, \\L, and \\U.
7650 \\L Lowercase until \\E . See also \\l, lc.
7651 \\U Upcase until \\E . See also \\u, uc.
7652 \\Q Quote metacharacters until \\E . See also quotemeta.
7653 \\a Alarm character (octal 007).
7654 \\b Backspace character (octal 010).
7655 \\c Control character, e.g. \\c[ .
7656 \\e Escape character (octal 033).
7657 \\f Formfeed character (octal 014).
7658 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
7659 \\n Newline character (octal 012 on most systems).
7660 \\r Return character (octal 015 on most systems).
7661 \\t Tab character (octal 011).
7662 \\u Upcase the next character. See also \\U and \\l, ucfirst.
7663 \\x Hex character, e.g. \\x1b.
7664 ... ^ ... Bitwise exclusive or.
7665 __END__ Ends program source.
7666 __DATA__ Ends program source.
7667 __FILE__ Current (source) filename.
7668 __LINE__ Current line in current source.
7669 __PACKAGE__ Current package.
7670 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
7671 ARGVOUT Output filehandle with -i flag.
7672 BEGIN { ... } Immediately executed (during compilation) piece of code.
7673 END { ... } Pseudo-subroutine executed after the script finishes.
7674 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
7675 INIT { ... } Pseudo-subroutine executed before the script starts running.
7676 DATA Input filehandle for what follows after __END__ or __DATA__.
7677 accept(NEWSOCKET,GENERICSOCKET)
7690 ... cmp ... String compare.
7691 connect(SOCKET,NAME)
7692 continue of { block } continue { block }. Is executed after `next' or at end.
7694 crypt(PLAINTEXT,SALT)
7696 dbmopen(%HASH,DBNAME,MODE)
7700 do { ... }|SUBR while|until EXPR executes at least once
7701 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
7711 ... eq ... String equality.
7712 eval(EXPR) or eval { BLOCK }
7713 exec([TRUENAME] ARGV0, ARGVs) or exec(SHELL_COMMAND_LINE)
7716 fcntl(FILEHANDLE,FUNCTION,SCALAR)
7718 flock(FILEHANDLE,OPERATION)
7719 for (EXPR;EXPR;EXPR) { ... }
7720 foreach [VAR] (@ARRAY) { ... }
7722 ... ge ... String greater than or equal.
7727 gethostbyaddr(ADDR,ADDRTYPE)
7731 getnetbyaddr(ADDR,ADDRTYPE)
7737 getpriority(WHICH,WHO)
7738 getprotobyname(NAME)
7739 getprotobynumber(NUMBER)
7744 getservbyname(NAME,PROTO)
7745 getservbyport(PORT,PROTO)
7748 getsockopt(SOCKET,LEVEL,OPTNAME)
7751 ... gt ... String greater than.
7753 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
7754 index(STR,SUBSTR[,OFFSET])
7756 ioctl(FILEHANDLE,FUNCTION,SCALAR)
7761 ... le ... String less than or equal.
7763 link(OLDFILE,NEWFILE)
7764 listen(SOCKET,QUEUESIZE)
7768 lstat(EXPR|FILEHANDLE|VAR)
7769 ... lt ... String less than.
7771 mkdir(FILENAME,MODE)
7774 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
7775 msgsnd(ID,MSG,FLAGS)
7776 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
7777 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
7778 ... ne ... String inequality.
7781 open(FILEHANDLE[,EXPR])
7782 opendir(DIRHANDLE,EXPR)
7783 ord(EXPR) ASCII value of the first char of the string.
7785 package NAME Introduces package context.
7786 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
7788 print [FILEHANDLE] [(LIST)]
7789 printf [FILEHANDLE] (FORMAT,LIST)
7791 q/STRING/ Synonym for 'STRING'
7792 qq/STRING/ Synonym for \"STRING\"
7793 qx/STRING/ Synonym for `STRING`
7795 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7798 recv(SOCKET,SCALAR,LEN,FLAGS)
7800 rename(OLDNAME,NEWNAME)
7801 require [FILENAME | PERL_VERSION]
7805 rewinddir(DIRHANDLE)
7806 rindex(STR,SUBSTR[,OFFSET])
7808 s/PATTERN/REPLACEMENT/gieoxsm
7810 seek(FILEHANDLE,POSITION,WHENCE)
7811 seekdir(DIRHANDLE,POS)
7812 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
7813 semctl(ID,SEMNUM,CMD,ARG)
7814 semget(KEY,NSEMS,SIZE,FLAGS)
7816 send(SOCKET,MSG,FLAGS[,TO])
7818 sethostent(STAYOPEN)
7821 setpriority(WHICH,WHO,PRIORITY)
7822 setprotoent(STAYOPEN)
7824 setservent(STAYOPEN)
7825 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
7828 shmget(KEY,SIZE,FLAGS)
7829 shmread(ID,VAR,POS,SIZE)
7830 shmwrite(ID,STRING,POS,SIZE)
7831 shutdown(SOCKET,HOW)
7834 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
7835 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
7836 sort [SUBROUTINE] (LIST)
7837 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
7838 split[(/PATTERN/[,EXPR[,LIMIT]])]
7839 sprintf(FORMAT,LIST)
7842 stat(EXPR|FILEHANDLE|VAR)
7844 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
7845 substr(EXPR,OFFSET[,LEN])
7846 symlink(OLDFILE,NEWFILE)
7848 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7849 system([TRUENAME] ARGV0 [,ARGV]) or system(SHELL_COMMAND_LINE)
7850 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7855 tr/SEARCHLIST/REPLACEMENTLIST/cds
7856 truncate(FILE|EXPR,LENGTH)
7859 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
7861 unpack(TEMPLATE,EXPR)
7863 until (EXPR) { ... } EXPR until EXPR
7866 vec(EXPR,OFFSET,BITS)
7869 wantarray Returns true if the sub/eval is called in list context.
7871 while (EXPR) { ... } EXPR while EXPR
7872 write[(EXPR|FILEHANDLE)]
7873 ... x ... Repeat string or array.
7874 x= ... Repetition assignment.
7875 y/SEARCHLIST/REPLACEMENTLIST/
7876 ... | ... Bitwise or.
7877 ... || ... Logical or.
7878 ~ ... Unary bitwise complement.
7879 #! OS interpreter indicator. If contains `perl', used for options, and -x.
7880 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
7881 CORE:: Prefix to access builtin function if imported sub obscures it.
7882 SUPER:: Prefix to lookup for a method in @ISA classes.
7883 DESTROY Shorthand for `sub DESTROY {...}'.
7884 ... EQ ... Obsolete synonym of `eq'.
7885 ... GE ... Obsolete synonym of `ge'.
7886 ... GT ... Obsolete synonym of `gt'.
7887 ... LE ... Obsolete synonym of `le'.
7888 ... LT ... Obsolete synonym of `lt'.
7889 ... NE ... Obsolete synonym of `ne'.
7890 abs [ EXPR ] absolute value
7891 ... and ... Low-precedence synonym for &&.
7892 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
7893 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
7894 chr Converts a number to char with the same ordinal.
7895 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
7896 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
7897 exists $HASH{KEY} True if the key exists.
7898 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
7899 formline PICTURE, LIST Backdoor into \"format\" processing.
7900 glob EXPR Synonym of <EXPR>.
7901 lc [ EXPR ] Returns lowercased EXPR.
7902 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
7903 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
7904 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
7905 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
7906 not ... Low-precedence synonym for ! - negation.
7907 ... or ... Low-precedence synonym for ||.
7908 pos STRING Set/Get end-position of the last match over this string, see \\G.
7909 quotemeta [ EXPR ] Quote regexp metacharacters.
7910 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
7911 readline FH Synonym of <FH>.
7912 readpipe CMD Synonym of `CMD`.
7913 ref [ EXPR ] Type of EXPR when dereferenced.
7914 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
7915 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
7916 tied Returns internal object for a tied data.
7917 uc [ EXPR ] Returns upcased EXPR.
7918 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
7919 untie VAR Unlink an object from a simple Perl variable.
7920 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
7921 ... xor ... Low-precedence synonym for exclusive or.
7922 prototype \\&SUB Returns prototype of the function given a reference.
7923 =head1 Top-level heading.
7924 =head2 Second-level heading.
7925 =head3 Third-level heading (is there such?).
7926 =over [ NUMBER ] Start list.
7927 =item [ TITLE ] Start new item in the list.
7929 =cut Switch from POD to Perl.
7930 =pod Switch from Perl to POD.
7933 (defun cperl-switch-to-doc-buffer (&optional interactive)
7934 "Go to the perl documentation buffer and insert the documentation."
7936 (let ((buf (get-buffer-create cperl-doc-buffer)))
7938 (switch-to-buffer-other-window buf)
7940 (if (= (buffer-size) 0)
7942 (insert (documentation-property 'cperl-short-docs
7943 'variable-documentation))
7944 (setq buffer-read-only t)))))
7946 (defun cperl-beautify-regexp-piece (b e embed level)
7947 ;; b is before the starting delimiter, e before the ending
7948 ;; e should be a marker, may be changed, but remains "correct".
7949 ;; EMBED is nil if we process the whole REx.
7950 ;; The REx is guaranteed to have //x
7951 ;; LEVEL shows how many levels deep to go
7952 ;; position at enter and at leave is not defined
7953 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
7957 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
7961 ((looking-at "(\\?[^a-zA-Z]")
7963 ((looking-at "(\\?") ; (?i)
7967 (setq c (if embed (current-indentation) (1- (current-column)))
7968 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
7969 (or (looking-at "[ \t]*[\n#]")
7974 (if (re-search-forward "[^ \t]" e t)
7975 (progn ; Something before the ending delimiter
7977 (delete-horizontal-space)
7979 (cperl-make-indent c)
7980 (set-marker e (point))))
7983 (while (< (point) (marker-position e))
7987 (skip-chars-forward " \t")
7988 (delete-region s (point))
7989 (cperl-make-indent c1)
7993 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
7994 "\\|" ; Embedded variable
7995 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
7998 "\\|" ; simple-code simple-code*?
7999 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
8003 "\\((\\(\\?\\)?\\)" ; 7 8
8006 (goto-char (match-end 0))
8008 (cond ((match-beginning 1) ; Alphanum word + junk
8010 ((or (match-beginning 3) ; $ab[12]
8011 (and (match-beginning 5) ; X* X+ X{2,3}
8012 (eq (preceding-char) ?\{)))
8015 ((and ; [], already syntaxified
8018 cperl-use-syntax-table-text-property)
8021 (or (eq (preceding-char) ?\])
8022 (error "[]-group not terminated"))
8024 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8025 ((match-beginning 6) ; []
8027 (if (looking-at "\\^?\\]")
8028 (goto-char (match-end 0)))
8029 ;; XXXX POSIX classes?!
8030 (while (and (not pos)
8031 (re-search-forward "\\[:\\|\\]" e t))
8032 (if (eq (preceding-char) ?:)
8033 (or (re-search-forward ":\\]" e t)
8034 (error "[:POSIX:]-group in []-group not terminated"))
8036 (or (eq (preceding-char) ?\])
8037 (error "[]-group not terminated"))
8039 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8040 ((match-beginning 7) ; ()
8041 (goto-char (match-beginning 0))
8042 (setq pos (current-column))
8045 (delete-horizontal-space)
8047 (cperl-make-indent c1)))
8050 ;; (or (forward-sexp 1)
8053 ;; (error "()-group not terminated")))
8054 (set-marker m (1- (point)))
8055 (set-marker m1 (point))
8057 (if (progn ; indent rigidly if multiline
8058 ;; In fact does not make a lot of sense, since
8059 ;; the starting position can be already lost due
8060 ;; to insertion of "\n" and " "
8062 (search-forward "\n" m1 t))
8063 (indent-rigidly (point) m1 (- c1 pos)))
8064 (setq level (1- level))
8066 ((not (match-beginning 8))
8067 (cperl-beautify-regexp-piece tmp m t level))
8068 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
8070 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
8071 (goto-char (+ 2 tmp))
8073 (cperl-beautify-regexp-piece (point) m t level))
8074 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
8075 (goto-char (+ 3 tmp))
8076 (cperl-beautify-regexp-piece (point) m t level))
8078 (cperl-beautify-regexp-piece tmp m t level))))
8080 (cond ((looking-at "[*+?]\\??")
8081 (goto-char (match-end 0)))
8082 ((eq (following-char) ?\{)
8084 (if (eq (following-char) ?\?)
8086 (skip-chars-forward " \t")
8088 (if (looking-at "[#\n]")
8090 (or (eolp) (indent-for-comment))
8091 (beginning-of-line 2))
8092 (delete-horizontal-space)
8096 ((match-beginning 9) ; |
8100 (if (re-search-forward "[^ \t]" tmp t)
8103 (delete-horizontal-space)
8106 (delete-region (point) tmp))
8107 (cperl-make-indent c)
8109 (skip-chars-forward " \t")
8111 (if (looking-at "[#\n]")
8112 (beginning-of-line 2)
8113 (delete-horizontal-space)
8117 (or (looking-at "[ \t\n]")
8120 (skip-chars-forward " \t"))
8121 (or (looking-at "[#\n]")
8122 (error "Unknown code `%s' in a regexp"
8123 (buffer-substring (point) (1+ (point)))))
8124 (and inline (end-of-line 2)))
8125 ;; Special-case the last line of group
8126 (if (and (>= (point) (marker-position e))
8127 (/= (current-indentation) c))
8130 (cperl-make-indent c)))))
8132 (defun cperl-make-regexp-x ()
8133 ;; Returns position of the start
8134 ;; XXX this is called too often! Need to cache the result!
8136 (or cperl-use-syntax-table-text-property
8137 (error "I need to have a regexp marked!"))
8139 (if (looking-at "\\s|")
8141 (if (looking-at "\\([smy]\\|qr\\)\\s|")
8143 (re-search-backward "\\s|"))) ; Assume it is scanned already.
8145 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
8146 (sub-p (eq (preceding-char) ?s)) s)
8148 (set-marker e (1- (point)))
8149 (setq delim (preceding-char))
8150 (if (and sub-p (eq delim (char-after (- (point) 2))))
8151 (error "Possible s/blah// - do not know how to deal with"))
8152 (if sub-p (forward-sexp 1))
8153 (if (looking-at "\\sw*x")
8156 ;; Protect fragile " ", "#"
8159 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
8165 (defun cperl-beautify-regexp (&optional deep)
8166 "Do it. (Experimental, may change semantics, recheck the result.)
8167 We suppose that the regexp is scanned already."
8169 (setq deep (if deep (prefix-numeric-value deep) -1))
8171 (goto-char (cperl-make-regexp-x))
8172 (let ((b (point)) (e (make-marker)))
8174 (set-marker e (1- (point)))
8175 (cperl-beautify-regexp-piece b e nil deep))))
8177 (defun cperl-regext-to-level-start ()
8178 "Goto start of an enclosing group in regexp.
8179 We suppose that the regexp is scanned already."
8181 (let ((limit (cperl-make-regexp-x)) done)
8183 (or (eq (following-char) ?\()
8184 (search-backward "(" (1+ limit) t)
8185 (error "Cannot find `(' which starts a group"))
8188 (skip-chars-backward "\\")
8189 (looking-at "\\(\\\\\\\\\\)*(")))
8190 (or done (forward-char -1)))))
8192 (defun cperl-contract-level ()
8193 "Find an enclosing group in regexp and contract it.
8194 \(Experimental, may change semantics, recheck the result.)
8195 We suppose that the regexp is scanned already."
8197 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
8198 (cperl-regext-to-level-start)
8199 (let ((b (point)) (e (make-marker)) c)
8201 (set-marker e (1- (point)))
8203 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
8205 ((match-beginning 1) ; #-comment
8206 (or c (setq c (current-indentation)))
8207 (beginning-of-line 2) ; Skip
8208 (cperl-make-indent c))
8211 (just-one-space))))))
8213 (defun cperl-contract-levels ()
8214 "Find an enclosing group in regexp and contract all the kids.
8215 \(Experimental, may change semantics, recheck the result.)
8216 We suppose that the regexp is scanned already."
8220 (cperl-regext-to-level-start)
8221 (error ; We are outside outermost group
8222 (goto-char (cperl-make-regexp-x))))
8223 (let ((b (point)) (e (make-marker)) s c)
8225 (set-marker e (1- (point)))
8227 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
8229 ((match-beginning 1) ; Skip
8232 (cperl-contract-level)))))))
8234 (defun cperl-beautify-level (&optional deep)
8235 "Find an enclosing group in regexp and beautify it.
8236 \(Experimental, may change semantics, recheck the result.)
8237 We suppose that the regexp is scanned already."
8239 (setq deep (if deep (prefix-numeric-value deep) -1))
8241 (cperl-regext-to-level-start)
8242 (let ((b (point)) (e (make-marker)))
8244 (set-marker e (1- (point)))
8245 (cperl-beautify-regexp-piece b e nil deep))))
8247 (defun cperl-invert-if-unless-modifiers ()
8248 "Change `B if A;' into `if (A) {B}' etc if possible.
8251 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string
8252 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>"))
8253 (and (= (char-syntax (preceding-char)) ?w)
8255 (setq pre-if (point))
8256 (cperl-backward-to-start-of-expr)
8257 (setq pre-B (point))
8258 (forward-sexp 1) ; otherwise forward-to-end-of-expr is NOP
8259 (cperl-forward-to-end-of-expr)
8260 (setq post-A (point))
8262 (or (looking-at w-rex)
8263 ;; Find the position
8264 (progn (goto-char post-A)
8266 (not (looking-at w-rex))
8269 (setq pre-if (point))))
8270 (or (looking-at w-rex)
8271 (error "Can't find `if', `unless', `while', `until', `for' or `foreach'"))
8272 ;; 1 B 2 ... 3 B-com ... 4 if 5 ... if-com 6 ... 7 A 8
8273 (setq if-string (buffer-substring (match-beginning 0) (match-end 0)))
8274 ;; First, simple part: find code boundaries
8276 (setq post-if (point))
8279 (setq post-B (point))
8280 (cperl-backward-to-start-of-expr)
8281 (setq pre-B (point))
8282 (setq B (buffer-substring pre-B post-B))
8286 ;; May be after $, @, $# etc of a variable
8287 (skip-chars-backward "$@%#")
8288 (setq pre-A (point))
8289 (cperl-forward-to-end-of-expr)
8290 (setq post-A (point))
8291 (setq A (buffer-substring pre-A post-A))
8292 ;; Now modify (from end, to not break the stuff)
8293 (skip-chars-forward " \t;")
8294 (delete-region pre-A (point)) ; we move to pre-A
8295 (insert "\n" B ";\n}")
8296 (and (looking-at "[ \t]*#") (cperl-indent-for-comment))
8297 (delete-region pre-if post-if)
8298 (delete-region pre-B post-B)
8300 (insert if-string " (" A ") {")
8301 (setq post-B (point))
8302 (if (looking-at "[ \t]+$")
8303 (delete-horizontal-space)
8304 (if (looking-at "[ \t]*#")
8305 (cperl-indent-for-comment)
8308 (if (looking-at "[ \t]*$")
8309 (progn ; delete line
8310 (delete-horizontal-space)
8311 (delete-region (point) (1+ (point)))))
8313 (goto-char (1- post-B))
8318 (defun cperl-invert-if-unless ()
8319 "Change `if (A) {B}' into `B if A;' etc (or visa versa) if possible.
8320 If the cursor is not on the leading keyword of the BLOCK flavor of
8321 construct, will assume it is the STATEMENT flavor, so will try to find
8322 the appropriate statement modifier."
8324 (and (= (char-syntax (preceding-char)) ?w)
8326 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
8327 (let ((pre-if (point))
8328 pre-A post-A pre-B post-B A B state p end-B-code is-block B-comment
8329 (if-string (buffer-substring (match-beginning 0) (match-end 0))))
8331 (setq post-A (point))
8333 (setq pre-A (point))
8334 (setq is-block (and (eq (following-char) ?\( )
8340 (eq (following-char) ?\{ ))
8346 (setq post-B (point))
8348 (setq pre-B (point))
8349 (if (and (eq (following-char) ?\{ )
8351 (cperl-backward-to-noncomment post-A)
8352 (eq (preceding-char) ?\) )))
8353 (if (condition-case nil
8358 (looking-at "\\<els\\(e\\|if\\)\\>"))
8361 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" if-string)
8362 (goto-char (1- post-B))
8363 (cperl-backward-to-noncomment pre-B)
8364 (if (eq (preceding-char) ?\;)
8366 (setq end-B-code (point))
8368 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" end-B-code t)
8369 (setq p (match-beginning 0)
8370 A (buffer-substring p (match-end 0))
8371 state (parse-partial-sexp pre-B p))
8375 (error "`%s' inside `%s' BLOCK" A if-string))
8376 (goto-char (match-end 0)))
8378 (goto-char (1+ pre-B))
8379 (skip-chars-forward " \t\n")
8380 (setq B (buffer-substring (point) end-B-code))
8381 (goto-char end-B-code)
8382 (or (looking-at ";?[ \t\n]*}")
8384 (skip-chars-forward "; \t\n")
8386 (buffer-substring (point) (1- post-B)))))
8389 (goto-char (1- post-A))
8390 (cperl-backward-to-noncomment pre-A)
8391 (or (looking-at "[ \t\n]*)")
8392 (goto-char (1- post-A)))
8394 (goto-char (1+ pre-A))
8395 (skip-chars-forward " \t\n")
8396 (setq A (buffer-substring (point) p))
8397 (delete-region pre-B post-B)
8398 (delete-region pre-A post-A)
8401 (and B-comment (insert B-comment " "))
8404 (setq pre-A (point))
8406 (delete-horizontal-space)
8407 (setq post-B (point))
8408 (if (looking-at "#")
8409 (indent-for-comment))
8412 (delete-horizontal-space)
8416 (setq pre-A (set-marker (make-marker) pre-A))
8417 (while (<= (point) (marker-position pre-A))
8420 (goto-char (marker-position pre-A))
8424 (indent-for-comment)
8425 (goto-char (marker-position pre-A)))))
8426 (error "`%s' (EXPR) not with an {BLOCK}" if-string)))
8427 ;; (error "`%s' not with an (EXPR)" if-string)
8429 (cperl-invert-if-unless-modifiers)))
8430 ;;(error "Not at `if', `unless', `while', `until', `for' or `foreach'")
8431 (cperl-invert-if-unless-modifiers)))
8433 ;;; By Anthony Foiani <afoiani@uswest.com>
8434 ;;; Getting help on modules in C-h f ?
8435 ;;; This is a modified version of `man'.
8436 ;;; Need to teach it how to lookup functions
8438 (defun cperl-perldoc (word)
8439 "Run `perldoc' on WORD."
8441 (list (let* ((default-entry (cperl-word-at-point))
8443 (format "perldoc entry%s: "
8444 (if (string= default-entry "")
8446 (format " (default %s)" default-entry))))))
8447 (if (string= input "")
8448 (if (string= default-entry "")
8449 (error "No perldoc args given")
8453 (let* ((case-fold-search nil)
8455 (string-match "^[a-z]+$" word)
8456 (string-match (concat "^" word "\\>")
8457 (documentation-property
8459 'variable-documentation))))
8460 (manual-program (if is-func "perldoc -f" "perldoc")))
8463 (let ((Manual-program "perldoc")
8464 (Manual-switches (if is-func (list "-f"))))
8465 (manual-entry word)))
8467 (Man-getpage-in-background word)))))
8470 (defun cperl-perldoc-at-point ()
8471 "Run a `perldoc' on the word around point."
8473 (cperl-perldoc (cperl-word-at-point)))
8475 (defcustom pod2man-program "pod2man"
8476 "*File name for `pod2man'."
8480 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
8481 (defun cperl-pod-to-manpage ()
8482 "Create a virtual manpage in Emacs from the Perl Online Documentation."
8485 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
8486 (bufname (concat "Man " buffer-file-name))
8487 (buffer (generate-new-buffer bufname)))
8490 (let ((process-environment (copy-sequence process-environment)))
8491 ;; Prevent any attempt to use display terminal fanciness.
8492 (setenv "TERM" "dumb")
8493 (set-process-sentinel
8494 (start-process pod2man-program buffer "sh" "-c"
8495 (format (cperl-pod2man-build-command) pod2man-args))
8496 'Man-bgproc-sentinel)))))
8498 ;;; Updated version by him too
8499 (defun cperl-build-manpage ()
8500 "Create a virtual manpage in Emacs from the POD in the file."
8505 (let ((Manual-program "perldoc"))
8506 (manual-entry buffer-file-name)))
8508 (let* ((manual-program "perldoc"))
8509 (Man-getpage-in-background buffer-file-name)))))
8511 (defun cperl-pod2man-build-command ()
8512 "Builds the entire background manpage and cleaning command."
8513 (let ((command (concat pod2man-program " %s 2>/dev/null"))
8514 (flist (and (boundp 'Man-filter-list) Man-filter-list)))
8515 (while (and flist (car flist))
8516 (let ((pcom (car (car flist)))
8517 (pargs (cdr (car flist))))
8519 (concat command " | " pcom " "
8520 (mapconcat '(lambda (phrase)
8521 (if (not (stringp phrase))
8522 (error "Malformed Man-filter-list"))
8525 (setq flist (cdr flist))))
8529 (defun cperl-next-interpolated-REx-1 ()
8530 "Move point to next REx which has interpolated parts without //o.
8531 Skips RExes consisting of one interpolated variable.
8533 Note that skipped RExen are not performance hits."
8535 (cperl-next-interpolated-REx 1))
8537 (defun cperl-next-interpolated-REx-0 ()
8538 "Move point to next REx which has interpolated parts without //o."
8540 (cperl-next-interpolated-REx 0))
8542 (defun cperl-next-interpolated-REx (&optional skip beg limit)
8543 "Move point to next REx which has interpolated parts.
8544 SKIP is a list of possible types to skip, BEG and LIMIT are the starting
8545 point and the limit of search (default to point and end of buffer).
8547 SKIP may be a number, then it behaves as list of numbers up to SKIP; this
8548 semantic may be used as a numeric argument.
8550 Types are 0 for / $rex /o (interpolated once), 1 for /$rex/ (if $rex is
8551 a result of qr//, this is not a performance hit), t for the rest."
8553 (if (numberp skip) (setq skip (list 0 skip)))
8554 (or beg (setq beg (point)))
8555 (or limit (setq limit (point-max))) ; needed for n-s-p-c
8557 (and (eq (get-text-property beg 'syntax-type) 'string)
8558 (setq beg (next-single-property-change beg 'syntax-type nil limit)))
8559 (cperl-map-pods-heres
8560 (function (lambda (s e p)
8561 (if (memq (get-text-property s 'REx-interpolated) skip)
8565 'REx-interpolated beg limit)
8566 (if pp (goto-char pp)
8567 (message "No more interpolated REx"))))
8569 ;;; Initial version contributed by Trey Belew
8570 (defun cperl-here-doc-spell (&optional beg end)
8571 "Spell-check HERE-documents in the Perl buffer.
8572 If a region is highlighted, restricts to the region."
8574 (cperl-pod-spell t beg end))
8576 (defun cperl-pod-spell (&optional do-heres beg end)
8577 "Spell-check POD documentation.
8578 If invoked with prefix argument, will do HERE-DOCs instead.
8579 If a region is highlighted, restricts to the region."
8583 (if (cperl-mark-active)
8584 (setq beg (min (mark) (point))
8585 end (max (mark) (point)))
8586 (setq beg (point-min)
8588 (cperl-map-pods-heres (function
8591 (setq e (save-excursion
8597 (if do-heres 'here-doc-group 'in-pod)
8600 (defun cperl-map-pods-heres (func &optional prop s end)
8601 "Executes a function over regions of pods or here-documents.
8602 PROP is the text-property to search for; default to `in-pod'. Stop when
8603 function returns nil."
8604 (let (pos posend has-prop (cont t))
8605 (or prop (setq prop 'in-pod))
8606 (or s (setq s (point-min)))
8607 (or end (setq end (point-max)))
8608 (cperl-update-syntaxification end end)
8610 (goto-char (setq pos s))
8611 (while (and cont (< pos end))
8612 (setq has-prop (get-text-property pos prop))
8613 (setq posend (next-single-property-change pos prop nil end))
8615 (setq cont (funcall func pos posend prop)))
8616 (setq pos posend)))))
8618 ;;; Based on code by Masatake YAMATO:
8619 (defun cperl-get-here-doc-region (&optional pos pod)
8620 "Return HERE document region around the point.
8621 Return nil if the point is not in a HERE document region. If POD is non-nil,
8622 will return a POD section if point is in a POD section."
8623 (or pos (setq pos (point)))
8624 (cperl-update-syntaxification pos pos)
8625 (if (or (eq 'here-doc (get-text-property pos 'syntax-type))
8627 (eq 'pod (get-text-property pos 'syntax-type))))
8628 (let ((b (cperl-beginning-of-property pos 'syntax-type))
8629 (e (next-single-property-change pos 'syntax-type)))
8630 (cons b (or e (point-max))))))
8632 (defun cperl-narrow-to-here-doc (&optional pos)
8633 "Narrows editing region to the HERE-DOC at POS.
8634 POS defaults to the point."
8636 (or pos (setq pos (point)))
8637 (let ((p (cperl-get-here-doc-region pos)))
8638 (or p (error "Not inside a HERE document"))
8639 (narrow-to-region (car p) (cdr p))
8641 "When you are finished with narrow editing, type C-x n w")))
8643 (defun cperl-select-this-pod-or-here-doc (&optional pos)
8644 "Select the HERE-DOC (or POD section) at POS.
8645 POS defaults to the point."
8647 (let ((p (cperl-get-here-doc-region pos t)))
8651 (push-mark (cdr p) nil t)) ; Message, activate in transient-mode
8652 (message "I do not think POS is in POD or a HERE-doc..."))))
8654 (defun cperl-facemenu-add-face-function (face end)
8655 "A callback to process user-initiated font-change requests.
8656 Translates `bold', `italic', and `bold-italic' requests to insertion of
8657 corresponding POD directives, and `underline' to C<> POD directive.
8659 Such requests are usually bound to M-o LETTER."
8660 (or (get-text-property (point) 'in-pod)
8661 (error "Faces can only be set within POD"))
8662 (setq facemenu-end-add-face (if (eq face 'bold-italic) ">>" ">"))
8663 (cdr (or (assq face '((bold . "B<")
8665 (bold-italic . "B<I<")
8666 (underline . "C<")))
8667 (error "Face %s not configured for cperl-mode"
8670 (defun cperl-time-fontification (&optional l step lim)
8671 "Times how long it takes to do incremental fontification in a region.
8672 L is the line to start at, STEP is the number of lines to skip when
8673 doing next incremental fontification, LIM is the maximal number of
8674 incremental fontification to perform. Messages are accumulated in
8677 May be used for pinpointing which construct slows down buffer fontification:
8678 start with default arguments, then refine the slowdown regions."
8679 (interactive "nLine to start at: \nnStep to do incremental fontification: ")
8681 (or step (setq step 500))
8682 (or lim (setq lim 40))
8683 (let* ((timems (function (lambda ()
8684 (let ((tt (current-time)))
8685 (+ (* 1000 (nth 1 tt)) (/ (nth 2 tt) 1000))))))
8686 (tt (funcall timems)) (c 0) delta tot)
8689 (setq tot (- (- tt (setq tt (funcall timems)))))
8690 (message "cperl-mode at %s: %s" l tot)
8691 (while (and (< c lim) (not (eobp)))
8695 (cperl-update-syntaxification (point) (point))
8696 (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
8697 (message "to %s:%6s,%7s" l delta tot))
8700 (defvar font-lock-cache-position)
8702 (defun cperl-emulate-lazy-lock (&optional window-size)
8703 "Emulate `lazy-lock' without `condition-case', so `debug-on-error' works.
8704 Start fontifying the buffer from the start (or end) using the given
8705 WINDOW-SIZE (units is lines). Negative WINDOW-SIZE starts at end, and
8706 goes backwards; default is -50. This function is not CPerl-specific; it
8707 may be used to debug problems with delayed incremental fontification."
8709 "nSize of window for incremental fontification, negative goes backwards: ")
8710 (or window-size (setq window-size -50))
8711 (let ((pos (if (> window-size 0)
8717 ;; Why needed??? With older font-locks???
8718 (set (make-local-variable 'font-lock-cache-position) (make-marker))
8719 (while (if (> window-size 0)
8721 (> pos (point-min)))
8723 (forward-line window-size)
8725 (font-lock-fontify-region (min p pos) (max p pos))
8729 (defun cperl-lazy-install ()) ; Avoid a warning
8730 (defun cperl-lazy-unstall ()) ; Avoid a warning
8732 (if (fboundp 'run-with-idle-timer)
8734 (defvar cperl-help-shown nil
8735 "Non-nil means that the help was already shown now.")
8737 (defvar cperl-lazy-installed nil
8738 "Non-nil means that the lazy-help handlers are installed now.")
8740 (defun cperl-lazy-install ()
8741 "Switches on Auto-Help on Perl constructs (put in the message area).
8742 Delay of auto-help controlled by `cperl-lazy-help-time'."
8744 (make-local-variable 'cperl-help-shown)
8745 (if (and (cperl-val 'cperl-lazy-help-time)
8746 (not cperl-lazy-installed))
8748 (add-hook 'post-command-hook 'cperl-lazy-hook)
8749 (run-with-idle-timer
8750 (cperl-val 'cperl-lazy-help-time 1000000 5)
8752 'cperl-get-help-defer)
8753 (setq cperl-lazy-installed t))))
8755 (defun cperl-lazy-unstall ()
8756 "Switches off Auto-Help on Perl constructs (put in the message area).
8757 Delay of auto-help controlled by `cperl-lazy-help-time'."
8759 (remove-hook 'post-command-hook 'cperl-lazy-hook)
8760 (cancel-function-timers 'cperl-get-help-defer)
8761 (setq cperl-lazy-installed nil))
8763 (defun cperl-lazy-hook ()
8764 (setq cperl-help-shown nil))
8766 (defun cperl-get-help-defer ()
8767 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
8768 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
8770 (setq cperl-help-shown t))))
8771 (cperl-lazy-install)))
8774 ;;; Plug for wrong font-lock:
8776 (defun cperl-font-lock-unfontify-region-function (beg end)
8777 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
8778 (inhibit-read-only t) (inhibit-point-motion-hooks t)
8779 before-change-functions after-change-functions
8780 deactivate-mark buffer-file-name buffer-file-truename)
8781 (remove-text-properties beg end '(face nil))
8782 (if (and (not modified) (buffer-modified-p))
8783 (set-buffer-modified-p nil))))
8785 (defun cperl-font-lock-fontify-region-function (beg end loudly)
8786 "Extends the region to safe positions, then calls the default function.
8787 Newer `font-lock's can do it themselves.
8788 We unwind only as far as needed for fontification. Syntaxification may
8789 do extra unwind via `cperl-unwind-to-safe'."
8795 (eq (get-text-property (setq beg (point)) 'syntax-type)
8797 (if (setq beg (cperl-beginning-of-property beg 'syntax-type))
8803 (or (bolp) (condition-case nil
8806 (eq (get-text-property (setq end (point)) 'syntax-type)
8808 (setq end (next-single-property-change end 'syntax-type nil (point-max)))
8811 (font-lock-default-fontify-region beg end loudly))
8813 (defvar cperl-d-l nil)
8814 (defun cperl-fontify-syntaxically (end)
8815 ;; Some vars for debugging only
8816 ;; (message "Syntaxifying...")
8817 (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
8818 (istate (car cperl-syntax-state))
8819 start from-start edebug-backtrace-buffer)
8820 (if (eq cperl-syntaxify-by-font-lock 'backtrace)
8823 (let ((f 'edebug-backtrace))
8824 (funcall f)))) ; Avoid compile-time warning
8825 (or cperl-syntax-done-to
8826 (setq cperl-syntax-done-to (point-min)
8828 (setq start (if (and cperl-hook-after-change
8830 cperl-syntax-done-to ; Fontify without change; ignore start
8831 ;; Need to forget what is after `start'
8832 (min cperl-syntax-done-to (point))))
8835 (setq start (point))
8836 (and cperl-syntaxify-unwind
8837 (setq end (cperl-unwind-to-safe t end)
8840 (setq cperl-syntax-done-to start) ; In case what follows fails
8841 (cperl-find-pods-heres start end t nil t))
8842 (if (memq cperl-syntaxify-by-font-lock '(backtrace message))
8843 (message "Syxify req=%s..%s actual=%s..%s done-to: %s=>%s statepos: %s=>%s"
8844 dbg iend start end idone cperl-syntax-done-to
8845 istate (car cperl-syntax-state))) ; For debugging
8846 nil)) ; Do not iterate
8848 (defun cperl-fontify-update (end)
8849 (let ((pos (point-min)) prop posend)
8850 (setq end (point-max))
8852 (setq prop (get-text-property pos 'cperl-postpone)
8853 posend (next-single-property-change pos 'cperl-postpone nil end))
8854 (and prop (put-text-property pos posend (car prop) (cdr prop)))
8856 nil) ; Do not iterate
8858 (defun cperl-fontify-update-bad (end)
8859 ;; Since fontification happens with different region than syntaxification,
8860 ;; do to the end of buffer, not to END;;; likewise, start earlier if needed
8861 (let* ((pos (point)) (prop (get-text-property pos 'cperl-postpone)) posend)
8863 (setq pos (or (cperl-beginning-of-property
8864 (cperl-1+ pos) 'cperl-postpone)
8867 (setq posend (next-single-property-change pos 'cperl-postpone))
8868 (and prop (put-text-property pos posend (car prop) (cdr prop)))
8870 (setq prop (get-text-property pos 'cperl-postpone))))
8871 nil) ; Do not iterate
8873 ;; Called when any modification is made to buffer text.
8874 (defun cperl-after-change-function (beg end old-len)
8875 ;; We should have been informed about changes by `font-lock'. Since it
8876 ;; does not inform as which calls are defered, do it ourselves
8877 (if cperl-syntax-done-to
8878 (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
8880 (defun cperl-update-syntaxification (from to)
8881 (if (and cperl-use-syntax-table-text-property
8882 cperl-syntaxify-by-font-lock
8883 (or (null cperl-syntax-done-to)
8884 (< cperl-syntax-done-to to)))
8888 (cperl-fontify-syntaxically to)))))
8890 (defvar cperl-version
8891 (let ((v "Revision: 5.23"))
8892 (string-match ":\\s *\\([0-9.]+\\)" v)
8893 (substring v (match-beginning 1) (match-end 1)))
8894 "Version of IZ-supported CPerl package this file is based on.")
8896 (provide 'cperl-mode)
8898 ;; arch-tag: 42e5b19b-e187-4537-929f-1a7408980ce6
8899 ;;; cperl-mode.el ends here