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
5 ;; Free Software Foundation, Inc.
7 ;; Author: Ilya Zakharevich and Bob Olson
8 ;; Maintainer: Ilya Zakharevich <ilyaz@cpan.org>
9 ;; Keywords: languages, Perl
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
28 ;;; Corrections made by Ilya Zakharevich ilyaz@cpan.org
32 ;; You can either fine-tune the bells and whistles of this mode or
33 ;; bulk enable them by putting
35 ;; (setq cperl-hairy t)
37 ;; in your .emacs file. (Emacs rulers do not consider it politically
38 ;; correct to make whistles enabled by default.)
40 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
41 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
42 ;; `cperl-praise', `cperl-speed'. <<<<<<
44 ;; The mode information (on C-h m) provides some customization help.
45 ;; If you use font-lock feature of this mode, it is advisable to use
46 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
48 ;; Faces used now: three faces for first-class and second-class keywords
49 ;; and control flow words, one for each: comments, string, labels,
50 ;; functions definitions and packages, arrays, hashes, and variable
51 ;; definitions. If you do not see all these faces, your font-lock does
52 ;; not define them, so you need to define them manually.
54 ;; This mode supports font-lock, imenu and mode-compile. In the
55 ;; hairy version font-lock is on, but you should activate imenu
56 ;; yourself (note that mode-compile is not standard yet). Well, you
57 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
58 ;; to bind it like that:
60 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
62 ;;; Font lock bugs as of v4.32:
64 ;; The following kinds of Perl code erroneously start strings:
66 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
67 ;; likewise with m, tr, y, q, qX instead of s
71 (defvar vc-rcs-header
)
72 (defvar vc-sccs-header
)
81 (defconst cperl-xemacs-p
(string-match "XEmacs\\|Lucid" emacs-version
))
82 (defvar cperl-can-font-lock
84 (and (boundp 'emacs-major-version
)
86 (> emacs-major-version
20)))))
87 (if cperl-can-font-lock
89 (defvar msb-menu-cond
)
90 (defvar gud-perldb-history
)
91 (defvar font-lock-background-mode
) ; not in Emacs
92 (defvar font-lock-display-type
) ; ditto
93 (defvar paren-backwards-message
) ; Not in newer XEmacs?
94 (or (fboundp 'defgroup
)
95 (defmacro defgroup
(name val doc
&rest arr
)
97 (or (fboundp 'custom-declare-variable
)
98 (defmacro defcustom
(name val doc
&rest arr
)
99 (` (defvar (, name
) (, val
) (, doc
)))))
100 (or (and (fboundp 'custom-declare-variable
)
101 (string< "19.31" emacs-version
)) ; Checked with 19.30: defface does not work
102 (defmacro defface
(&rest arr
)
104 ;; Avoid warning (tmp definitions)
105 (or (fboundp 'x-color-defined-p
)
106 (defmacro x-color-defined-p
(col)
107 (cond ((fboundp 'color-defined-p
) (` (color-defined-p (, col
))))
109 ((fboundp 'valid-color-name-p
) (` (valid-color-name-p (, col
))))
111 ((fboundp 'x-valid-color-name-p
) (` (x-valid-color-name-p (, col
))))
112 (t '(error "Cannot implement color-defined-p")))))
113 (defmacro cperl-is-face
(arg) ; Takes quoted arg
114 (cond ((fboundp 'find-face
)
115 (` (find-face (, arg
))))
116 (;;(and (fboundp 'face-list)
119 (` (member (, arg
) (and (fboundp 'face-list
)
122 (` (boundp (, arg
))))))
123 (defmacro cperl-make-face
(arg descr
) ; Takes unquoted arg
124 (cond ((fboundp 'make-face
)
125 (` (make-face (quote (, arg
)))))
127 (` (defvar (, arg
) (quote (, arg
)) (, descr
))))))
128 (defmacro cperl-force-face
(arg descr
) ; Takes unquoted arg
130 (or (cperl-is-face (quote (, arg
)))
131 (cperl-make-face (, arg
) (, descr
)))
132 (or (boundp (quote (, arg
))) ; We use unquoted variants too
133 (defvar (, arg
) (quote (, arg
)) (, descr
))))))
135 (defmacro cperl-etags-snarf-tag
(file line
)
137 (beginning-of-line 2)
138 (list (, file
) (, line
)))))
139 (defmacro cperl-etags-snarf-tag
(file line
)
140 (` (etags-snarf-tag))))
142 (defmacro cperl-etags-goto-tag-location
(elt)
144 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
145 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
146 ;; Probably will not work due to some save-excursion???
147 ;; Or save-file-position?
148 ;; (message "Did I get to line %s?" (elt (, elt) 1))
149 (goto-line (string-to-int (elt (, elt
) 1)))))
151 (defmacro cperl-etags-goto-tag-location
(elt)
152 (` (etags-goto-tag-location (, elt
))))))
154 (defconst cperl-xemacs-p
(string-match "XEmacs\\|Lucid" emacs-version
))
156 (defvar cperl-can-font-lock
158 (and (boundp 'emacs-major-version
)
160 (> emacs-major-version
20)))))
162 (defun cperl-choose-color (&rest list
)
166 (if (or (x-color-defined-p (car list
))
168 (setq answer
(car list
))))
169 (setq list
(cdr list
)))
173 "Major mode for editing Perl code."
178 (defgroup cperl-indentation-details nil
183 (defgroup cperl-affected-by-hairy nil
184 "Variables affected by `cperl-hairy'."
188 (defgroup cperl-autoinsert-details nil
189 "Auto-insert tuneup."
193 (defgroup cperl-faces nil
194 "Fontification colors."
195 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
199 (defgroup cperl-speed nil
200 "Speed vs. validity tuneup."
204 (defgroup cperl-help-system nil
205 "Help system tuneup."
210 (defcustom cperl-extra-newline-before-brace nil
211 "*Non-nil means that if, elsif, while, until, else, for, foreach
212 and do constructs look like:
223 :group
'cperl-autoinsert-details
)
225 (defcustom cperl-extra-newline-before-brace-multiline
226 cperl-extra-newline-before-brace
227 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
228 for constructs with multiline if/unless/while/until/for/foreach condition."
230 :group
'cperl-autoinsert-details
)
232 (defcustom cperl-indent-level
2
233 "*Indentation of CPerl statements with respect to containing block."
235 :group
'cperl-indentation-details
)
237 (defcustom cperl-lineup-step nil
238 "*`cperl-lineup' will always lineup at multiple of this number.
239 If nil, the value of `cperl-indent-level' will be used."
240 :type
'(choice (const nil
) integer
)
241 :group
'cperl-indentation-details
)
243 (defcustom cperl-brace-imaginary-offset
0
244 "*Imagined indentation of a Perl open brace that actually follows a statement.
245 An open brace following other text is treated as if it were this far
246 to the right of the start of its line."
248 :group
'cperl-indentation-details
)
250 (defcustom cperl-brace-offset
0
251 "*Extra indentation for braces, compared with other text in same context."
253 :group
'cperl-indentation-details
)
254 (defcustom cperl-label-offset -
2
255 "*Offset of CPerl label lines relative to usual indentation."
257 :group
'cperl-indentation-details
)
258 (defcustom cperl-min-label-indent
1
259 "*Minimal offset of CPerl label lines."
261 :group
'cperl-indentation-details
)
262 (defcustom cperl-continued-statement-offset
2
263 "*Extra indent for lines not starting new statements."
265 :group
'cperl-indentation-details
)
266 (defcustom cperl-continued-brace-offset
0
267 "*Extra indent for substatements that start with open-braces.
268 This is in addition to cperl-continued-statement-offset."
270 :group
'cperl-indentation-details
)
271 (defcustom cperl-close-paren-offset -
1
272 "*Extra indent for substatements that start with close-parenthesis."
274 :group
'cperl-indentation-details
)
276 (defcustom cperl-indent-wrt-brace t
277 "*Non-nil means indent statements in if/etc block relative brace, not if/etc.
278 Versions 5.2 ... 5.20 behaved as if this were `nil'."
280 :group
'cperl-indentation-details
)
282 (defcustom cperl-auto-newline nil
283 "*Non-nil means automatically newline before and after braces,
284 and after colons and semicolons, inserted in CPerl code. The following
285 \\[cperl-electric-backspace] will remove the inserted whitespace.
286 Insertion after colons requires both this variable and
287 `cperl-auto-newline-after-colon' set."
289 :group
'cperl-autoinsert-details
)
291 (defcustom cperl-autoindent-on-semi nil
292 "*Non-nil means automatically indent after insertion of (semi)colon.
293 Active if `cperl-auto-newline' is false."
295 :group
'cperl-autoinsert-details
)
297 (defcustom cperl-auto-newline-after-colon nil
298 "*Non-nil means automatically newline even after colons.
299 Subject to `cperl-auto-newline' setting."
301 :group
'cperl-autoinsert-details
)
303 (defcustom cperl-tab-always-indent t
304 "*Non-nil means TAB in CPerl mode should always reindent the current line,
305 regardless of where in the line point is when the TAB command is used."
307 :group
'cperl-indentation-details
)
309 (defcustom cperl-font-lock nil
310 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
311 Can be overwritten by `cperl-hairy' if nil."
312 :type
'(choice (const null
) boolean
)
313 :group
'cperl-affected-by-hairy
)
315 (defcustom cperl-electric-lbrace-space nil
316 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
317 Can be overwritten by `cperl-hairy' if nil."
318 :type
'(choice (const null
) boolean
)
319 :group
'cperl-affected-by-hairy
)
321 (defcustom cperl-electric-parens-string
"({[]})<"
322 "*String of parentheses that should be electric in CPerl.
323 Closing ones are electric only if the region is highlighted."
325 :group
'cperl-affected-by-hairy
)
327 (defcustom cperl-electric-parens nil
328 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
329 Can be overwritten by `cperl-hairy' if nil."
330 :type
'(choice (const null
) boolean
)
331 :group
'cperl-affected-by-hairy
)
333 (defvar zmacs-regions
) ; Avoid warning
335 (defcustom cperl-electric-parens-mark
337 (or (and (boundp 'transient-mark-mode
) ; For Emacs
339 (and (boundp 'zmacs-regions
) ; For XEmacs
341 "*Not-nil means that electric parens look for active mark.
342 Default is yes if there is visual feedback on mark."
344 :group
'cperl-autoinsert-details
)
346 (defcustom cperl-electric-linefeed nil
347 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
348 In any case these two mean plain and hairy linefeeds together.
349 Can be overwritten by `cperl-hairy' if nil."
350 :type
'(choice (const null
) boolean
)
351 :group
'cperl-affected-by-hairy
)
353 (defcustom cperl-electric-keywords nil
354 "*Not-nil (and non-null) means keywords are electric in CPerl.
355 Can be overwritten by `cperl-hairy' if nil.
357 Uses `abbrev-mode' to do the expansion. If you want to use your
358 own abbrevs in cperl-mode, but do not want keywords to be
359 electric, you must redefine `cperl-mode-abbrev-table': do
360 \\[edit-abbrevs], search for `cperl-mode-abbrev-table', and, in
361 that paragraph, delete the words that appear at the ends of lines and
362 that begin with \"cperl-electric\".
364 :type
'(choice (const null
) boolean
)
365 :group
'cperl-affected-by-hairy
)
367 (defcustom cperl-electric-backspace-untabify t
368 "*Not-nil means electric-backspace will untabify in CPerl."
370 :group
'cperl-autoinsert-details
)
372 (defcustom cperl-hairy nil
373 "*Not-nil means most of the bells and whistles are enabled in CPerl.
374 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
375 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
376 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
377 `cperl-lazy-help-time'."
379 :group
'cperl-affected-by-hairy
)
381 (defcustom cperl-comment-column
32
382 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
384 :group
'cperl-indentation-details
)
386 (defcustom cperl-indent-comment-at-column-0 nil
387 "*Non-nil means that comment started at column 0 should be indentable."
389 :group
'cperl-indentation-details
)
391 (defcustom cperl-vc-sccs-header
'("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
392 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
393 :type
'(repeat string
)
396 (defcustom cperl-vc-rcs-header
'("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
397 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
398 :type
'(repeat string
)
401 ;; This became obsolete...
402 (defvar cperl-vc-header-alist nil
)
403 (make-obsolete-variable
404 'cperl-vc-header-alist
405 "use cperl-vc-rcs-header or cperl-vc-sccs-header instead.")
407 (defcustom cperl-clobber-mode-lists
410 (boundp 'interpreter-mode-alist
)
411 (assoc "miniperl" interpreter-mode-alist
)
412 (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist
)))
413 "*Whether to install us into `interpreter-' and `extension' mode lists."
417 (defcustom cperl-info-on-command-no-prompt nil
418 "*Not-nil (and non-null) means not to prompt on C-h f.
419 The opposite behavior is always available if prefixed with C-c.
420 Can be overwritten by `cperl-hairy' if nil."
421 :type
'(choice (const null
) boolean
)
422 :group
'cperl-affected-by-hairy
)
424 (defcustom cperl-clobber-lisp-bindings nil
425 "*Not-nil (and non-null) means not overwrite C-h f.
426 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
427 Can be overwritten by `cperl-hairy' if nil."
428 :type
'(choice (const null
) boolean
)
429 :group
'cperl-affected-by-hairy
)
431 (defcustom cperl-lazy-help-time nil
432 "*Not-nil (and non-null) means to show lazy help after given idle time.
433 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
434 :type
'(choice (const null
) (const nil
) integer
)
435 :group
'cperl-affected-by-hairy
)
437 (defcustom cperl-pod-face
'font-lock-comment-face
438 "*Face for POD highlighting."
442 (defcustom cperl-pod-head-face
'font-lock-variable-name-face
443 "*Face for POD highlighting.
444 Font for POD headers."
448 (defcustom cperl-here-face
'font-lock-string-face
449 "*Face for here-docs highlighting."
453 ;;; Some double-evaluation happened with font-locks... Needed with 21.2...
454 (defvar cperl-singly-quote-face cperl-xemacs-p
)
456 (defcustom cperl-invalid-face
'underline
457 "*Face for highlighting trailing whitespace."
462 (defcustom cperl-pod-here-fontify
'(featurep 'font-lock
)
463 "*Not-nil after evaluation means to highlight POD and here-docs sections."
467 (defcustom cperl-fontify-m-as-s t
468 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
472 (defcustom cperl-highlight-variables-indiscriminately nil
473 "*Non-nil means perform additional highlighting on variables.
474 Currently only changes how scalar variables are highlighted.
475 Note that that variable is only read at initialization time for
476 the variable `cperl-font-lock-keywords-2', so changing it after you've
477 entered CPerl mode the first time will have no effect."
481 (defcustom cperl-pod-here-scan t
482 "*Not-nil means look for POD and here-docs sections during startup.
483 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
487 (defcustom cperl-regexp-scan t
488 "*Not-nil means make marking of regular expression more thorough.
489 Effective only with `cperl-pod-here-scan'."
493 (defcustom cperl-hook-after-change t
494 "*Not-nil means install hook to know which regions of buffer are changed.
495 May significantly speed up delayed fontification. Changes take effect
500 (defcustom cperl-imenu-addback nil
501 "*Not-nil means add backreferences to generated `imenu's.
502 May require patched `imenu' and `imenu-go'. Obsolete."
504 :group
'cperl-help-system
)
506 (defcustom cperl-max-help-size
66
507 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
508 :type
'(choice integer
(const nil
))
509 :group
'cperl-help-system
)
511 (defcustom cperl-shrink-wrap-info-frame t
512 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
514 :group
'cperl-help-system
)
516 (defcustom cperl-info-page
"perl"
517 "*Name of the info page containing perl docs.
518 Older version of this page was called `perl5', newer `perl'."
520 :group
'cperl-help-system
)
522 (defcustom cperl-use-syntax-table-text-property
523 (boundp 'parse-sexp-lookup-properties
)
524 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
528 (defcustom cperl-use-syntax-table-text-property-for-tags
529 cperl-use-syntax-table-text-property
530 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
534 (defcustom cperl-scan-files-regexp
"\\.\\([pP][Llm]\\|xs\\)$"
535 "*Regexp to match files to scan when generating TAGS."
539 (defcustom cperl-noscan-files-regexp
540 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
541 "*Regexp to match files/dirs to skip when generating TAGS."
545 (defcustom cperl-regexp-indent-step nil
546 "*Indentation used when beautifying regexps.
547 If nil, the value of `cperl-indent-level' will be used."
548 :type
'(choice integer
(const nil
))
549 :group
'cperl-indentation-details
)
551 (defcustom cperl-indent-left-aligned-comments t
552 "*Non-nil means that the comment starting in leftmost column should indent."
554 :group
'cperl-indentation-details
)
556 (defcustom cperl-under-as-char nil
557 "*Non-nil means that the _ (underline) should be treated as word char."
561 (defcustom cperl-extra-perl-args
""
562 "*Extra arguments to use when starting Perl.
563 Currently used with `cperl-check-syntax' only."
567 (defcustom cperl-message-electric-keyword t
568 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
570 :group
'cperl-help-system
)
572 (defcustom cperl-indent-region-fix-constructs
1
573 "*Amount of space to insert between `}' and `else' or `elsif'
574 in `cperl-indent-region'. Set to nil to leave as is. Values other
575 than 1 and nil will probably not work."
576 :type
'(choice (const nil
) (const 1))
577 :group
'cperl-indentation-details
)
579 (defcustom cperl-break-one-line-blocks-when-indent t
580 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
581 need to be reformatted into multiline ones when indenting a region."
583 :group
'cperl-indentation-details
)
585 (defcustom cperl-fix-hanging-brace-when-indent t
586 "*Non-nil means that BLOCK-end `}' may be put on a separate line
587 when indenting a region.
588 Braces followed by else/elsif/while/until are excepted."
590 :group
'cperl-indentation-details
)
592 (defcustom cperl-merge-trailing-else t
593 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
594 may be merged to be on the same line when indenting a region."
596 :group
'cperl-indentation-details
)
598 (defcustom cperl-indent-parens-as-block nil
599 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
600 but for trailing \",\" inside the group, which won't increase indentation.
601 One should tune up `cperl-close-paren-offset' as well."
603 :group
'cperl-indentation-details
)
605 (defcustom cperl-syntaxify-by-font-lock
606 (and cperl-can-font-lock
607 (boundp 'parse-sexp-lookup-properties
))
608 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
609 :type
'(choice (const message
) boolean
)
612 (defcustom cperl-syntaxify-unwind
614 "*Non-nil means that CPerl unwinds to a start of a long construction
615 when syntaxifying a chunk of buffer."
619 (defcustom cperl-syntaxify-for-menu
621 "*Non-nil means that CPerl syntaxifies up to the point before showing menu.
622 This way enabling/disabling of menu items is more correct."
626 (defcustom cperl-ps-print-face-properties
627 '((font-lock-keyword-face nil nil bold shadow
)
628 (font-lock-variable-name-face nil nil bold
)
629 (font-lock-function-name-face nil nil bold italic box
)
630 (font-lock-constant-face nil
"LightGray" bold
)
631 (cperl-array-face nil
"LightGray" bold underline
)
632 (cperl-hash-face nil
"LightGray" bold italic underline
)
633 (font-lock-comment-face nil
"LightGray" italic
)
634 (font-lock-string-face nil nil italic underline
)
635 (cperl-nonoverridable-face nil nil italic underline
)
636 (font-lock-type-face nil nil underline
)
637 (font-lock-warning-face nil
"LightGray" bold italic box
)
638 (underline nil
"LightGray" strikeout
))
639 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
640 :type
'(repeat (cons symbol
641 (cons (choice (const nil
) string
)
642 (cons (choice (const nil
) string
)
646 (defvar cperl-dark-background
647 (cperl-choose-color "navy" "os2blue" "darkgreen"))
648 (defvar cperl-dark-foreground
649 (cperl-choose-color "orchid1" "orange"))
651 (defface cperl-nonoverridable-face
652 `((((class grayscale
) (background light
))
653 (:background
"Gray90" :slant italic
:underline t
))
654 (((class grayscale
) (background dark
))
655 (:foreground
"Gray80" :slant italic
:underline t
:weight bold
))
656 (((class color
) (background light
))
657 (:foreground
"chartreuse3"))
658 (((class color
) (background dark
))
659 (:foreground
,cperl-dark-foreground
))
660 (t (:weight bold
:underline t
)))
661 "Font Lock mode face used non-overridable keywords and modifiers of regexps."
664 (defface cperl-array-face
665 `((((class grayscale
) (background light
))
666 (:background
"Gray90" :weight bold
))
667 (((class grayscale
) (background dark
))
668 (:foreground
"Gray80" :weight bold
))
669 (((class color
) (background light
))
670 (:foreground
"Blue" :background
"lightyellow2" :weight bold
))
671 (((class color
) (background dark
))
672 (:foreground
"yellow" :background
,cperl-dark-background
:weight bold
))
674 "Font Lock mode face used to highlight array names."
677 (defface cperl-hash-face
678 `((((class grayscale
) (background light
))
679 (:background
"Gray90" :weight bold
:slant italic
))
680 (((class grayscale
) (background dark
))
681 (:foreground
"Gray80" :weight bold
:slant italic
))
682 (((class color
) (background light
))
683 (:foreground
"Red" :background
"lightyellow2" :weight bold
:slant italic
))
684 (((class color
) (background dark
))
685 (:foreground
"Red" :background
,cperl-dark-background
:weight bold
:slant italic
))
686 (t (:weight bold
:slant italic
)))
687 "Font Lock mode face used to highlight hash names."
692 ;;; Short extra-docs.
694 (defvar cperl-tips
'please-ignore-this-line
695 "Get maybe newer version of this package from
696 http://ilyaz.org/software/emacs
697 Subdirectory `cperl-mode' may contain yet newer development releases and/or
698 patches to related files.
700 For best results apply to an older Emacs the patches from
701 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
702 \(this upgrades syntax-parsing abilities of Emacsen v19.34 and
703 v20.2 up to the level of Emacs v20.3 - a must for a good Perl
704 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
706 Get support packages choose-color.el (or font-lock-extra.el before
707 19.30), imenu-go.el from the same place. \(Look for other files there
708 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
709 later you should use choose-color.el *instead* of font-lock-extra.el
710 \(and you will not get smart highlighting in C :-().
712 Note that to enable Compile choices in the menu you need to install
715 If your Emacs does not default to `cperl-mode' on Perl files, and you
716 want it to: put the following into your .emacs file:
718 (defalias 'perl-mode 'cperl-mode)
721 $CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
722 Also, one can generate a newer documentation running `pod2texi' converter
723 $CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
725 If you use imenu-go, run imenu on perl5-info buffer (you can do it
726 from Perl menu). If many files are related, generate TAGS files from
727 Tools/Tags submenu in Perl menu.
729 If some class structure is too complicated, use Tools/Hierarchy-view
730 from Perl menu, or hierarchic view of imenu. The second one uses the
731 current buffer only, the first one requires generation of TAGS from
732 Perl/Tools/Tags menu beforehand.
734 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
736 Switch auto-help on/off with Perl/Tools/Auto-help.
738 Though with contemporary Emaxen CPerl mode should maintain the correct
739 parsing of Perl even when editing, sometimes it may be lost. Fix this by
743 In cases of more severe confusion sometimes it is helpful to do
745 \\[load-library] cperl-mode RET
748 Before reporting (non-)problems look in the problem section of online
749 micro-docs on what I know about CPerl problems.")
751 (defvar cperl-problems
'please-ignore-this-line
752 "Description of problems in CPerl mode.
753 Some faces will not be shown on some versions of Emacs unless you
754 install choose-color.el, available from
755 http://ilyaz.org/software/emacs
757 `fill-paragraph' on a comment may leave the point behind the
758 paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
759 to detect it and bulk out).
761 See documentation of a variable `cperl-problems-old-emaxen' for the
762 problems which disappear if you upgrade Emacs to a reasonably new
763 version (20.3 for Emacs, and those of 2004 for XEmacs).")
765 (defvar cperl-problems-old-emaxen
'please-ignore-this-line
766 "Description of problems in CPerl mode specific for older Emacs versions.
768 Emacs had a _very_ restricted syntax parsing engine until version
769 20.1. Most problems below are corrected starting from this version of
770 Emacs, and all of them should be fixed in version 20.3. (Or apply
771 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
772 this respect (until 2003).
774 Note that even with newer Emacsen in some very rare cases the details
775 of interaction of `font-lock' and syntaxification may be not cleaned
776 up yet. You may get slightly different colors basing on the order of
777 fontification and syntaxification. Say, the initial faces is correct,
778 but editing the buffer breaks this.
780 Even with older Emacsen CPerl mode tries to corrects some Emacs
781 misunderstandings, however, for efficiency reasons the degree of
782 correction is different for different operations. The partially
783 corrected problems are: POD sections, here-documents, regexps. The
784 operations are: highlighting, indentation, electric keywords, electric
787 This may be confusing, since the regexp s#//#/#\; may be highlighted
788 as a comment, but it will be recognized as a regexp by the indentation
789 code. Or the opposite case, when a POD section is highlighted, but
790 may break the indentation of the following code (though indentation
791 should work if the balance of delimiters is not broken by POD).
793 The main trick (to make $ a \"backslash\") makes constructions like
794 ${aaa} look like unbalanced braces. The only trick I can think of is
795 to insert it as $ {aaa} (valid in perl5, not in perl4).
797 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
798 as /($|\\s)/. Note that such a transposition is not always possible.
800 The solution is to upgrade your Emacs or patch an older one. Note
801 that Emacs 20.2 has some bugs related to `syntax-table' text
802 properties. Patches are available on the main CPerl download site,
805 If these bugs cannot be fixed on your machine (say, you have an inferior
806 environment and cannot recompile), you may still disable all the fancy stuff
807 via `cperl-use-syntax-table-text-property'.")
809 (defvar cperl-praise
'please-ignore-this-line
810 "Advantages of CPerl mode.
812 0) It uses the newest `syntax-table' property ;-);
814 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
815 mode - but the latter number may have improved too in last years) even
816 with old Emaxen which do not support `syntax-table' property.
818 When using `syntax-table' property for syntax assist hints, it should
819 handle 99.995% of lines correct - or somesuch. It automatically
820 updates syntax assist hints when you edit your script.
822 2) It is generally believed to be \"the most user-friendly Emacs
823 package\" whatever it may mean (I doubt that the people who say similar
824 things tried _all_ the rest of Emacs ;-), but this was not a lonely
827 3) Everything is customizable, one-by-one or in a big sweep;
829 4) It has many easily-accessable \"tools\":
830 a) Can run program, check syntax, start debugger;
831 b) Can lineup vertically \"middles\" of rows, like `=' in
834 c) Can insert spaces where this impoves readability (in one
835 interactive sweep over the buffer);
836 d) Has support for imenu, including:
837 1) Separate unordered list of \"interesting places\";
838 2) Separate TOC of POD sections;
839 3) Separate list of packages;
840 4) Hierarchical view of methods in (sub)packages;
841 5) and functions (by the full name - with package);
842 e) Has an interface to INFO docs for Perl; The interface is
843 very flexible, including shrink-wrapping of
844 documentation buffer/frame;
845 f) Has a builtin list of one-line explanations for perl constructs.
846 g) Can show these explanations if you stay long enough at the
847 corresponding place (or on demand);
848 h) Has an enhanced fontification (using 3 or 4 additional faces
849 comparing to font-lock - basically, different
850 namespaces in Perl have different colors);
851 i) Can construct TAGS basing on its knowledge of Perl syntax,
852 the standard menu has 6 different way to generate
853 TAGS (if \"by directory\", .xs files - with C-language
854 bindings - are included in the scan);
855 j) Can build a hierarchical view of classes (via imenu) basing
856 on generated TAGS file;
857 k) Has electric parentheses, electric newlines, uses Abbrev
858 for electric logical constructs
860 with different styles of expansion (context sensitive
861 to be not so bothering). Electric parentheses behave
862 \"as they should\" in a presence of a visible region.
863 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
869 n) Highlights (by user-choice) either 3-delimiters constructs
870 (such as tr/a/b/), or regular expressions and `y/tr';
871 o) Highlights trailing whitespace;
872 p) Is able to manipulate Perl Regular Expressions to ease
873 conversion to a more readable form.
874 q) Can ispell POD sections and HERE-DOCs.
875 r) Understands comments and character classes inside regular
876 expressions; can find matching () and [] in a regular expression.
877 s) Allows indentation of //x-style regular expressions;
878 t) Highlights different symbols in regular expressions according
879 to their function; much less problems with backslashitis;
880 u) Allows to find regular expressions which contain interpolated parts.
882 5) The indentation engine was very smart, but most of tricks may be
883 not needed anymore with the support for `syntax-table' property. Has
884 progress indicator for indentation (with `imenu' loaded).
886 6) Indent-region improves inline-comments as well; also corrects
887 whitespace *inside* the conditional/loop constructs.
889 7) Fill-paragraph correctly handles multi-line comments;
891 8) Can switch to different indentation styles by one command, and restore
892 the settings present before the switch.
894 9) When doing indentation of control constructs, may correct
895 line-breaks/spacing between elements of the construct.
897 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
898 capable syntax engines).
900 11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
903 (defvar cperl-speed
'please-ignore-this-line
904 "This is an incomplete compendium of what is available in other parts
905 of CPerl documentation. (Please inform me if I skept anything.)
907 There is a perception that CPerl is slower than alternatives. This part
908 of documentation is designed to overcome this misconception.
910 *By default* CPerl tries to enable the most comfortable settings.
911 From most points of view, correctly working package is infinitely more
912 comfortable than a non-correctly working one, thus by default CPerl
913 prefers correctness over speed. Below is the guide how to change
914 settings if your preferences are different.
916 A) Speed of loading the file. When loading file, CPerl may perform a
917 scan which indicates places which cannot be parsed by primitive Emacs
918 syntax-parsing routines, and marks them up so that either
920 A1) CPerl may work around these deficiencies (for big chunks, mostly
921 PODs and HERE-documents), or
922 A2) On capable Emaxen CPerl will use improved syntax-handlings
923 which reads mark-up hints directly.
925 The scan in case A2 is much more comprehensive, thus may be slower.
927 User can disable syntax-engine-helping scan of A2 by setting
928 `cperl-use-syntax-table-text-property'
929 variable to nil (if it is set to t).
931 One can disable the scan altogether (both A1 and A2) by setting
932 `cperl-pod-here-scan'
935 B) Speed of editing operations.
937 One can add a (minor) speedup to editing operations by setting
938 `cperl-use-syntax-table-text-property'
939 variable to nil (if it is set to t). This will disable
940 syntax-engine-helping scan, thus will make many more Perl
941 constructs be wrongly recognized by CPerl, thus may lead to
942 wrongly matched parentheses, wrong indentation, etc.
944 One can unset `cperl-syntaxify-unwind'. This might speed up editing
945 of, say, long POD sections.")
947 (defvar cperl-tips-faces
'please-ignore-this-line
948 "CPerl mode uses following faces for highlighting:
950 `cperl-array-face' Array names
951 `cperl-hash-face' Hash names
952 `font-lock-comment-face' Comments, PODs and whatever is considered
953 syntaxically to be not code
954 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
955 2-arg operators s/y/tr/ or of RExen,
956 `font-lock-warning-face' Special-cased m// and s//foo/,
957 `font-lock-function-name-face' _ as a target of a file tests, file tests,
958 subroutine names at the moment of definition
959 (except those conflicting with Perl operators),
960 package names (when recognized), format names
961 `font-lock-keyword-face' Control flow switch constructs, declarators
962 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
963 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
964 literal parts and the terminator of formats
965 and whatever is syntaxically considered
967 `font-lock-type-face' Overridable keywords
968 `font-lock-variable-name-face' Variable declarations, indirect array and
969 hash names, POD headers/item names
970 `cperl-invalid' Trailing whitespace
972 Note that in several situations the highlighting tries to inform about
973 possible confusion, such as different colors for function names in
974 declarations depending on what they (do not) override, or special cases
975 m// and s/// which do not do what one would expect them to do.
977 Help with best setup of these faces for printout requested (for each of
978 the faces: please specify bold, italic, underline, shadow and box.)
980 In regular expressions (except character classes):
981 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs
982 `font-lock-constant-face': Delimiters
983 `font-lock-warning-face' Special-cased m// and s//foo/,
984 Mismatched closing delimiters, parens
985 we couldn't match, misplaced quantifiers,
986 unrecognized escape sequences
987 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
988 `font-lock-type-face' POSIX classes inside charclasses,
989 escape sequences with arguments (\x \23 \p \N)
990 and others match-a-char escape sequences
991 `font-lock-keyword-face' Capturing parens, and |
992 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
993 `font-lock-builtin-face' \"Remaining\" 0-length constructs, executable
994 parts of a REx, not-capturing parens
995 `font-lock-variable-name-face' Interpolated constructs, embedded code
996 `font-lock-comment-face' Embedded comments
1002 ;;; Portability stuff:
1004 (defmacro cperl-define-key
(emacs-key definition
&optional xemacs-key
)
1005 `(define-key cperl-mode-map
1007 `(if cperl-xemacs-p
,xemacs-key
,emacs-key
)
1011 (defvar cperl-del-back-ch
1012 (car (append (where-is-internal 'delete-backward-char
)
1013 (where-is-internal 'backward-delete-char-untabify
)))
1014 "Character generated by key bound to `delete-backward-char'.")
1016 (and (vectorp cperl-del-back-ch
) (= (length cperl-del-back-ch
) 1)
1017 (setq cperl-del-back-ch
(aref cperl-del-back-ch
0)))
1019 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
1022 ;; "Active regions" are on: use region only if active
1023 ;; "Active regions" are off: use region unconditionally
1024 (defun cperl-use-region-p ()
1025 (if zmacs-regions
(mark) t
)))
1026 (defun cperl-use-region-p ()
1027 (if transient-mark-mode mark-active t
))
1028 (defun cperl-mark-active () mark-active
))
1030 (defsubst cperl-enable-font-lock
()
1031 cperl-can-font-lock
)
1033 (defun cperl-putback-char (c) ; Emacs 19
1034 (set 'unread-command-events
(list c
))) ; Avoid undefined warning
1037 (defun cperl-putback-char (c) ; XEmacs >= 19.12
1038 (setq unread-command-events
(list (eval '(character-to-event c
))))))
1040 (or (fboundp 'uncomment-region
)
1041 (defun uncomment-region (beg end
)
1043 (comment-region beg end -
1)))
1045 (defvar cperl-do-not-fontify
1046 (if (string< emacs-version
"19.30")
1049 "Text property which inhibits refontification.")
1051 (defsubst cperl-put-do-not-fontify
(from to
&optional post
)
1052 ;; If POST, do not do it with postponed fontification
1053 (if (and post cperl-syntaxify-by-font-lock
)
1055 (put-text-property (max (point-min) (1- from
))
1056 to cperl-do-not-fontify t
)))
1058 (defcustom cperl-mode-hook nil
1059 "Hook run by CPerl mode."
1063 (defvar cperl-syntax-state nil
)
1064 (defvar cperl-syntax-done-to nil
)
1065 (defvar cperl-emacs-can-parse
(> (length (save-excursion
1066 (parse-partial-sexp (point) (point)))) 9))
1068 ;; Make customization possible "in reverse"
1069 (defsubst cperl-val
(symbol &optional default hairy
)
1071 ((eq (symbol-value symbol
) 'null
) default
)
1072 (cperl-hairy (or hairy t
))
1073 (t (symbol-value symbol
))))
1076 (defun cperl-make-indent (column &optional minimum keep
)
1077 "Makes indent of the current line the requested amount.
1078 Unless KEEP, removes the old indentation. Works around a bug in ancient
1080 (let ((prop (get-text-property (point) 'syntax-type
)))
1082 (delete-horizontal-space))
1083 (indent-to column minimum
)
1084 ;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
1086 (> (current-column) 0)
1089 (or (get-text-property (point) 'syntax-type
)
1090 (and (looking-at "\\=[ \t]")
1091 (put-text-property (point) (match-end 0)
1092 'syntax-type prop
)))))))
1094 ;;; Probably it is too late to set these guys already, but it can help later:
1096 ;;;(and cperl-clobber-mode-lists
1097 ;;;(setq auto-mode-alist
1098 ;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
1099 ;;;(and (boundp 'interpreter-mode-alist)
1100 ;;; (setq interpreter-mode-alist (append interpreter-mode-alist
1101 ;;; '(("miniperl" . perl-mode))))))
1107 '(imenu easymenu etags timer man info
))
1108 (if (fboundp 'ps-extend-face-list
)
1109 (defmacro cperl-ps-extend-face-list
(arg)
1110 `(ps-extend-face-list ,arg
))
1111 (defmacro cperl-ps-extend-face-list
(arg)
1112 `(error "This version of Emacs has no `ps-extend-face-list'")))
1113 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
1114 ;; macros instead of defsubsts don't work on Emacs, so we do the
1115 ;; expansion manually. Any other suggestions?
1118 (defvar cperl-mode-abbrev-table nil
1119 "Abbrev table in use in CPerl mode buffers.")
1121 (add-hook 'edit-var-mode-alist
'(perl-mode (regexp .
"^cperl-")))
1123 (defvar cperl-mode-map
() "Keymap used in CPerl mode.")
1125 (if cperl-mode-map nil
1126 (setq cperl-mode-map
(make-sparse-keymap))
1127 (cperl-define-key "{" 'cperl-electric-lbrace
)
1128 (cperl-define-key "[" 'cperl-electric-paren
)
1129 (cperl-define-key "(" 'cperl-electric-paren
)
1130 (cperl-define-key "<" 'cperl-electric-paren
)
1131 (cperl-define-key "}" 'cperl-electric-brace
)
1132 (cperl-define-key "]" 'cperl-electric-rparen
)
1133 (cperl-define-key ")" 'cperl-electric-rparen
)
1134 (cperl-define-key ";" 'cperl-electric-semi
)
1135 (cperl-define-key ":" 'cperl-electric-terminator
)
1136 (cperl-define-key "\C-j" 'newline-and-indent
)
1137 (cperl-define-key "\C-c\C-j" 'cperl-linefeed
)
1138 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless
)
1139 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline
)
1140 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev
)
1141 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix
)
1142 (cperl-define-key "\C-c\C-f" 'auto-fill-mode
)
1143 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric
)
1144 (cperl-define-key "\C-c\C-b" 'cperl-find-bad-style
)
1145 (cperl-define-key "\C-c\C-p" 'cperl-pod-spell
)
1146 (cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell
)
1147 (cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc
)
1148 (cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx
)
1149 (cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0
)
1150 (cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1
)
1151 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp
)
1152 (cperl-define-key "\C-c\C-hp" 'cperl-perldoc
)
1153 (cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point
)
1154 (cperl-define-key "\e\C-q" 'cperl-indent-exp
) ; Usually not bound
1155 (cperl-define-key [?\C-\M-\|
] 'cperl-lineup
1157 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1158 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
1159 (cperl-define-key "\177" 'cperl-electric-backspace
)
1160 (cperl-define-key "\t" 'cperl-indent-command
)
1161 ;; don't clobber the backspace binding:
1162 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
1163 [(control c
) (control h
) F
])
1164 (if (cperl-val 'cperl-clobber-lisp-bindings
)
1166 (cperl-define-key "\C-hf"
1167 ;;(concat (char-to-string help-char) "f") ; does not work
1168 'cperl-info-on-command
1170 (cperl-define-key "\C-hv"
1171 ;;(concat (char-to-string help-char) "v") ; does not work
1174 (cperl-define-key "\C-c\C-hf"
1175 ;;(concat (char-to-string help-char) "f") ; does not work
1176 (key-binding "\C-hf")
1177 [(control c
) (control h
) f
])
1178 (cperl-define-key "\C-c\C-hv"
1179 ;;(concat (char-to-string help-char) "v") ; does not work
1180 (key-binding "\C-hv")
1181 [(control c
) (control h
) v
]))
1182 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
1183 [(control c
) (control h
) f
])
1184 (cperl-define-key "\C-c\C-hv"
1185 ;;(concat (char-to-string help-char) "v") ; does not work
1187 [(control c
) (control h
) v
]))
1188 (if (and cperl-xemacs-p
1189 (<= emacs-minor-version
11) (<= emacs-major-version
19))
1191 ;; substitute-key-definition is usefulness-deenhanced...
1192 ;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1193 (cperl-define-key "\e;" 'cperl-indent-for-comment
)
1194 (cperl-define-key "\e\C-\\" 'cperl-indent-region
))
1195 (or (boundp 'fill-paragraph-function
)
1196 (substitute-key-definition
1197 'fill-paragraph
'cperl-fill-paragraph
1198 cperl-mode-map global-map
))
1199 (substitute-key-definition
1200 'indent-sexp
'cperl-indent-exp
1201 cperl-mode-map global-map
)
1202 (substitute-key-definition
1203 'indent-region
'cperl-indent-region
1204 cperl-mode-map global-map
)
1205 (substitute-key-definition
1206 'indent-for-comment
'cperl-indent-for-comment
1207 cperl-mode-map global-map
)))
1210 (defvar cperl-lazy-installed
)
1211 (defvar cperl-old-style nil
)
1216 cperl-menu cperl-mode-map
"Menu for CPerl mode"
1218 ["Beginning of function" beginning-of-defun
t]
1219 ["End of function" end-of-defun
t]
1220 ["Mark function" mark-defun
t]
1221 ["Indent expression" cperl-indent-exp t
]
1222 ["Fill paragraph/comment" fill-paragraph t
]
1224 ["Line up a construction" cperl-lineup
(cperl-use-region-p)]
1225 ["Invert if/unless/while etc" cperl-invert-if-unless t
]
1227 ["Beautify" cperl-beautify-regexp
1228 cperl-use-syntax-table-text-property
]
1229 ["Beautify one level deep" (cperl-beautify-regexp 1)
1230 cperl-use-syntax-table-text-property
]
1231 ["Beautify a group" cperl-beautify-level
1232 cperl-use-syntax-table-text-property
]
1233 ["Beautify a group one level deep" (cperl-beautify-level 1)
1234 cperl-use-syntax-table-text-property
]
1235 ["Contract a group" cperl-contract-level
1236 cperl-use-syntax-table-text-property
]
1237 ["Contract groups" cperl-contract-levels
1238 cperl-use-syntax-table-text-property
]
1240 ["Find next interpolated" cperl-next-interpolated-REx
1241 (next-single-property-change (point-min) 'REx-interpolated
)]
1242 ["Find next interpolated (no //o)"
1243 cperl-next-interpolated-REx-0
1244 (or (text-property-any (point-min) (point-max) 'REx-interpolated t
)
1245 (text-property-any (point-min) (point-max) 'REx-interpolated
1))]
1246 ["Find next interpolated (neither //o nor whole-REx)"
1247 cperl-next-interpolated-REx-1
1248 (text-property-any (point-min) (point-max) 'REx-interpolated t
)])
1249 ["Insert spaces if needed to fix style" cperl-find-bad-style t
]
1250 ["Refresh \"hard\" constructions" cperl-find-pods-heres t
]
1252 ["Indent region" cperl-indent-region
(cperl-use-region-p)]
1253 ["Comment region" cperl-comment-region
(cperl-use-region-p)]
1254 ["Uncomment region" cperl-uncomment-region
(cperl-use-region-p)]
1256 ["Run" mode-compile
(fboundp 'mode-compile
)]
1257 ["Kill" mode-compile-kill
(and (fboundp 'mode-compile-kill
)
1258 (get-buffer "*compilation*"))]
1259 ["Next error" next-error
(get-buffer "*compilation*")]
1260 ["Check syntax" cperl-check-syntax
(fboundp 'mode-compile
)]
1262 ["Debugger" cperl-db t
]
1265 ["Imenu" imenu
(fboundp 'imenu
)]
1266 ["Imenu on Perl Info" cperl-imenu-on-info
(featurep 'imenu
)]
1268 ["Ispell PODs" cperl-pod-spell
1269 ;; Better not to update syntaxification here:
1270 ;; debugging syntaxificatio can be broken by this???
1272 (get-text-property (point-min) 'in-pod
)
1274 (and cperl-syntaxify-for-menu
1275 (cperl-update-syntaxification (point-max) (point-max)))
1276 (next-single-property-change (point-min) 'in-pod nil
(point-max)))
1278 ["Ispell HERE-DOCs" cperl-here-doc-spell
1280 (and cperl-syntaxify-for-menu
1281 (cperl-update-syntaxification (point-max) (point-max)))
1282 (next-single-property-change (point-min) 'here-doc-group nil
(point-max)))
1284 ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
1285 (eq 'here-doc
(progn
1286 (and cperl-syntaxify-for-menu
1287 (cperl-update-syntaxification (point) (point)))
1288 (get-text-property (point) 'syntax-type
)))]
1289 ["Select this HERE-DOC or POD section"
1290 cperl-select-this-pod-or-here-doc
1292 (and cperl-syntaxify-for-menu
1293 (cperl-update-syntaxification (point) (point)))
1294 (get-text-property (point) 'syntax-type
))
1297 ["CPerl pretty print (exprmntl)" cperl-ps-print
1298 (fboundp 'ps-extend-face-list
)]
1300 ["Syntaxify region" cperl-find-pods-heres-region
1301 (cperl-use-region-p)]
1302 ["Profile syntaxification" cperl-time-fontification t
]
1303 ["Debug errors in delayed fontification" cperl-emulate-lazy-lock t
]
1304 ["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t
]
1305 ["Debug backtrace on syntactic scan (BEWARE!!!)"
1306 (cperl-toggle-set-debug-unwind nil t
) t
]
1308 ["Class Hierarchy from TAGS" cperl-tags-hier-init t
]
1309 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
1311 ;;; ["Create tags for current file" cperl-etags t]
1312 ;;; ["Add tags for current file" (cperl-etags t) t]
1313 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
1314 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
1315 ;;; ["Create tags for Perl files in (sub)directories"
1316 ;;; (cperl-etags nil 'recursive) t]
1317 ;;; ["Add tags for Perl files in (sub)directories"
1318 ;;; (cperl-etags t 'recursive) t])
1319 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
1320 ["Create tags for current file" (cperl-write-tags nil t
) t
]
1321 ["Add tags for current file" (cperl-write-tags) t
]
1322 ["Create tags for Perl files in directory"
1323 (cperl-write-tags nil t nil t
) t
]
1324 ["Add tags for Perl files in directory"
1325 (cperl-write-tags nil nil nil t
) t
]
1326 ["Create tags for Perl files in (sub)directories"
1327 (cperl-write-tags nil t t t
) t
]
1328 ["Add tags for Perl files in (sub)directories"
1329 (cperl-write-tags nil nil t t
) t
]))
1331 ["Define word at point" imenu-go-find-at-position
1332 (fboundp 'imenu-go-find-at-position
)]
1333 ["Help on function" cperl-info-on-command t
]
1334 ["Help on function at point" cperl-info-on-current-command t
]
1335 ["Help on symbol at point" cperl-get-help t
]
1336 ["Perldoc" cperl-perldoc t
]
1337 ["Perldoc on word at point" cperl-perldoc-at-point t
]
1338 ["View manpage of POD in this file" cperl-build-manpage t
]
1339 ["Auto-help on" cperl-lazy-install
1340 (and (fboundp 'run-with-idle-timer
)
1341 (not cperl-lazy-installed
))]
1342 ["Auto-help off" cperl-lazy-unstall
1343 (and (fboundp 'run-with-idle-timer
)
1344 cperl-lazy-installed
)])
1346 ["Auto newline" cperl-toggle-auto-newline t
]
1347 ["Electric parens" cperl-toggle-electric t
]
1348 ["Electric keywords" cperl-toggle-abbrev t
]
1349 ["Fix whitespace on indent" cperl-toggle-construct-fix t
]
1350 ["Auto-help on Perl constructs" cperl-toggle-autohelp t
]
1351 ["Auto fill" auto-fill-mode t
])
1353 ["CPerl" (cperl-set-style "CPerl") t
]
1354 ["PerlStyle" (cperl-set-style "PerlStyle") t
]
1355 ["GNU" (cperl-set-style "GNU") t
]
1356 ["C++" (cperl-set-style "C++") t
]
1357 ["K&R" (cperl-set-style "K&R") t
]
1358 ["BSD" (cperl-set-style "BSD") t
]
1359 ["Whitesmith" (cperl-set-style "Whitesmith") t
]
1360 ["Memorize Current" (cperl-set-style "Current") t
]
1361 ["Memorized" (cperl-set-style-back) cperl-old-style
])
1363 ["Tips" (describe-variable 'cperl-tips
) t
]
1364 ["Problems" (describe-variable 'cperl-problems
) t
]
1365 ["Speed" (describe-variable 'cperl-speed
) t
]
1366 ["Praise" (describe-variable 'cperl-praise
) t
]
1367 ["Faces" (describe-variable 'cperl-tips-faces
) t
]
1368 ["CPerl mode" (describe-function 'cperl-mode
) t
]
1370 (message "The version of master-file for this CPerl is %s-Emacs"
1371 cperl-version
) t
]))))
1374 (autoload 'c-macro-expand
"cmacexp"
1375 "Display the result of expanding all C macros occurring in the region.
1376 The expansion is entirely correct because it uses the C preprocessor."
1379 ;;; These two must be unwound, otherwise take exponential time
1380 (defconst cperl-maybe-white-and-comment-rex
"[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
1381 "Regular expression to match optional whitespace with interpspersed comments.
1382 Should contain exactly one group.")
1384 ;;; This one is tricky to unwind; still very inefficient...
1385 (defconst cperl-white-and-comment-rex
"\\([ \t\n]\\|#[^\n]*\n\\)+"
1386 "Regular expression to match whitespace with interpspersed comments.
1387 Should contain exactly one group.")
1390 ;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
1391 ;;; `cperl-outline-regexp', `defun-prompt-regexp'.
1392 ;;; Details of groups in this may be used in several functions; see comments
1393 ;;; near mentioned above variable(s)...
1394 ;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
1395 (defsubst cperl-after-sub-regexp
(named attr
) ; 9 groups without attr...
1396 "Match the text after `sub' in a subroutine declaration.
1397 If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
1398 of attributes (if present), or end of the name or prototype (whatever is
1400 (concat ; Assume n groups before this...
1401 "\\(" ; n+1=name-group
1402 cperl-white-and-comment-rex
; n+2=pre-name
1403 "\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
1404 "\\)" ; END n+1=name-group
1406 "\\(" ; n+4=proto-group
1407 cperl-maybe-white-and-comment-rex
; n+5=pre-proto
1408 "\\(([^()]*)\\)" ; n+6=prototype
1409 "\\)?" ; END n+4=proto-group
1410 "\\(" ; n+7=attr-group
1411 cperl-maybe-white-and-comment-rex
; n+8=pre-attr
1412 "\\(" ; n+9=start-attr
1416 cperl-maybe-white-and-comment-rex
; whitespace-comments
1417 "\\(\\sw\\|_\\)+" ; attr-name
1418 ;; attr-arg (1 level of internal parens allowed!)
1419 "\\((\\(\\\\.\\|[^\\\\()]\\|([^\\\\()]*)\\)*)\\)?"
1420 "\\(" ; optional : (XXX allows trailing???)
1421 cperl-maybe-white-and-comment-rex
; whitespace-comments
1426 "\\)?" ; END n+6=proto-group
1429 ;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
1430 ;;; and `cperl-outline-level'.
1431 ;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 8=sub-name (+3)
1432 (defvar cperl-imenu--function-name-regexp-perl
1435 "\\([ \t]*package" ; 2 = package-group
1436 "\\(" ; 3 = package-name-group
1437 cperl-white-and-comment-rex
; 4 = pre-package-name
1438 "\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
1441 (cperl-after-sub-regexp 'named nil
) ; 8=name 11=proto 14=attr-start
1442 cperl-maybe-white-and-comment-rex
; 15=pre-block
1444 "=head\\([1-4]\\)[ \t]+" ; 16=level
1445 "\\([^\n]+\\)$" ; 17=text
1448 (defvar cperl-outline-regexp
1449 (concat cperl-imenu--function-name-regexp-perl
"\\|" "\\`"))
1451 (defvar cperl-mode-syntax-table nil
1452 "Syntax table in use in CPerl mode buffers.")
1454 (defvar cperl-string-syntax-table nil
1455 "Syntax table in use in CPerl mode string-like chunks.")
1457 (defsubst cperl-1-
(p)
1458 (max (point-min) (1- p
)))
1460 (defsubst cperl-1
+ (p)
1461 (min (point-max) (1+ p
)))
1463 (if cperl-mode-syntax-table
1465 (setq cperl-mode-syntax-table
(make-syntax-table))
1466 (modify-syntax-entry ?
\\ "\\" cperl-mode-syntax-table
)
1467 (modify-syntax-entry ?
/ "." cperl-mode-syntax-table
)
1468 (modify-syntax-entry ?
* "." cperl-mode-syntax-table
)
1469 (modify-syntax-entry ?
+ "." cperl-mode-syntax-table
)
1470 (modify-syntax-entry ?-
"." cperl-mode-syntax-table
)
1471 (modify-syntax-entry ?
= "." cperl-mode-syntax-table
)
1472 (modify-syntax-entry ?%
"." cperl-mode-syntax-table
)
1473 (modify-syntax-entry ?
< "." cperl-mode-syntax-table
)
1474 (modify-syntax-entry ?
> "." cperl-mode-syntax-table
)
1475 (modify-syntax-entry ?
& "." cperl-mode-syntax-table
)
1476 (modify-syntax-entry ?$
"\\" cperl-mode-syntax-table
)
1477 (modify-syntax-entry ?
\n ">" 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 (if cperl-under-as-char
1482 (modify-syntax-entry ?_
"w" cperl-mode-syntax-table
))
1483 (modify-syntax-entry ?
: "_" cperl-mode-syntax-table
)
1484 (modify-syntax-entry ?|
"." cperl-mode-syntax-table
)
1485 (setq cperl-string-syntax-table
(copy-syntax-table cperl-mode-syntax-table
))
1486 (modify-syntax-entry ?$
"." cperl-string-syntax-table
)
1487 (modify-syntax-entry ?\
{ "." cperl-string-syntax-table
)
1488 (modify-syntax-entry ?\
} "." cperl-string-syntax-table
)
1489 (modify-syntax-entry ?
# "." cperl-string-syntax-table
)) ; (?# comment )
1493 (defvar cperl-faces-init nil
)
1495 (defvar cperl-msb-fixed nil
)
1496 (defvar cperl-use-major-mode
'cperl-mode
)
1497 (defvar cperl-font-lock-multiline-start nil
)
1498 (defvar cperl-font-lock-multiline nil
)
1499 (defvar cperl-compilation-error-regexp-alist nil
)
1500 (defvar cperl-font-locking nil
)
1503 (defun cperl-mode ()
1504 "Major mode for editing Perl code.
1505 Expression and list commands understand all C brackets.
1506 Tab indents for Perl code.
1507 Paragraphs are separated by blank lines only.
1508 Delete converts tabs to spaces as it moves back.
1510 Various characters in Perl almost always come in pairs: {}, (), [],
1511 sometimes <>. When the user types the first, she gets the second as
1512 well, with optional special formatting done on {}. (Disabled by
1513 default.) You can always quote (with \\[quoted-insert]) the left
1514 \"paren\" to avoid the expansion. The processing of < is special,
1515 since most the time you mean \"less\". CPerl mode tries to guess
1516 whether you want to type pair <>, and inserts is if it
1517 appropriate. You can set `cperl-electric-parens-string' to the string that
1518 contains the parenths from the above list you want to be electrical.
1519 Electricity of parenths is controlled by `cperl-electric-parens'.
1520 You may also set `cperl-electric-parens-mark' to have electric parens
1521 look for active mark and \"embrace\" a region if possible.'
1523 CPerl mode provides expansion of the Perl control constructs:
1525 if, else, elsif, unless, while, until, continue, do,
1526 for, foreach, formy and foreachmy.
1528 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
1530 The user types the keyword immediately followed by a space, which
1531 causes the construct to be expanded, and the point is positioned where
1532 she is most likely to want to be. eg. when the user types a space
1533 following \"if\" the following appears in the buffer: if () { or if ()
1534 } { } and the cursor is between the parentheses. The user can then
1535 type some boolean expression within the parens. Having done that,
1536 typing \\[cperl-linefeed] places you - appropriately indented - on a
1537 new line between the braces (if you typed \\[cperl-linefeed] in a POD
1538 directive line, then appropriate number of new lines is inserted).
1540 If CPerl decides that you want to insert \"English\" style construct like
1544 it will not do any expansion. See also help on variable
1545 `cperl-extra-newline-before-brace'. (Note that one can switch the
1546 help message on expansion by setting `cperl-message-electric-keyword'
1549 \\[cperl-linefeed] is a convenience replacement for typing carriage
1550 return. It places you in the next line with proper indentation, or if
1551 you type it inside the inline block of control construct, like
1553 foreach (@lines) {print; print}
1555 and you are on a boundary of a statement inside braces, it will
1556 transform the construct into a multiline and will place you into an
1557 appropriately indented blank line. If you need a usual
1558 `newline-and-indent' behavior, it is on \\[newline-and-indent],
1559 see documentation on `cperl-electric-linefeed'.
1561 Use \\[cperl-invert-if-unless] to change a construction of the form
1571 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
1572 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
1573 on electric space between $ and {, `cperl-electric-parens-string' is
1574 the string that contains parentheses that should be electric in CPerl
1575 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
1576 setting `cperl-electric-keywords' enables electric expansion of
1577 control structures in CPerl. `cperl-electric-linefeed' governs which
1578 one of two linefeed behavior is preferable. You can enable all these
1579 options simultaneously (recommended mode of use) by setting
1580 `cperl-hairy' to t. In this case you can switch separate options off
1581 by setting them to `null'. Note that one may undo the extra
1582 whitespace inserted by semis and braces in `auto-newline'-mode by
1583 consequent \\[cperl-electric-backspace].
1585 If your site has perl5 documentation in info format, you can use commands
1586 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
1587 These keys run commands `cperl-info-on-current-command' and
1588 `cperl-info-on-command', which one is which is controlled by variable
1589 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
1590 \(in turn affected by `cperl-hairy').
1592 Even if you have no info-format documentation, short one-liner-style
1593 help is available on \\[cperl-get-help], and one can run perldoc or
1596 It is possible to show this help automatically after some idle time.
1597 This is regulated by variable `cperl-lazy-help-time'. Default with
1598 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
1599 secs idle time . It is also possible to switch this on/off from the
1600 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
1602 Use \\[cperl-lineup] to vertically lineup some construction - put the
1603 beginning of the region at the start of construction, and make region
1604 span the needed amount of lines.
1606 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
1607 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
1608 here-docs sections. With capable Emaxen results of scan are used
1609 for indentation too, otherwise they are used for highlighting only.
1611 Variables controlling indentation style:
1612 `cperl-tab-always-indent'
1613 Non-nil means TAB in CPerl mode should always reindent the current line,
1614 regardless of where in the line point is when the TAB command is used.
1615 `cperl-indent-left-aligned-comments'
1616 Non-nil means that the comment starting in leftmost column should indent.
1617 `cperl-auto-newline'
1618 Non-nil means automatically newline before and after braces,
1619 and after colons and semicolons, inserted in Perl code. The following
1620 \\[cperl-electric-backspace] will remove the inserted whitespace.
1621 Insertion after colons requires both this variable and
1622 `cperl-auto-newline-after-colon' set.
1623 `cperl-auto-newline-after-colon'
1624 Non-nil means automatically newline even after colons.
1625 Subject to `cperl-auto-newline' setting.
1626 `cperl-indent-level'
1627 Indentation of Perl statements within surrounding block.
1628 The surrounding block's indentation is the indentation
1629 of the line on which the open-brace appears.
1630 `cperl-continued-statement-offset'
1631 Extra indentation given to a substatement, such as the
1632 then-clause of an if, or body of a while, or just a statement continuation.
1633 `cperl-continued-brace-offset'
1634 Extra indentation given to a brace that starts a substatement.
1635 This is in addition to `cperl-continued-statement-offset'.
1636 `cperl-brace-offset'
1637 Extra indentation for line if it starts with an open brace.
1638 `cperl-brace-imaginary-offset'
1639 An open brace following other text is treated as if it the line started
1640 this far to the right of the actual line indentation.
1641 `cperl-label-offset'
1642 Extra indentation for line that is a label.
1643 `cperl-min-label-indent'
1644 Minimal indentation for line that is a label.
1646 Settings for classic indent-styles: K&R BSD=C++ GNU PerlStyle=Whitesmith
1647 `cperl-indent-level' 5 4 2 4
1648 `cperl-brace-offset' 0 0 0 0
1649 `cperl-continued-brace-offset' -5 -4 0 0
1650 `cperl-label-offset' -5 -4 -2 -4
1651 `cperl-continued-statement-offset' 5 4 2 4
1653 CPerl knows several indentation styles, and may bulk set the
1654 corresponding variables. Use \\[cperl-set-style] to do this. Use
1655 \\[cperl-set-style-back] to restore the memorized preexisting values
1656 \(both available from menu). See examples in `cperl-style-examples'.
1658 Part of the indentation style is how different parts of if/elsif/else
1659 statements are broken into lines; in CPerl, this is reflected on how
1660 templates for these constructs are created (controlled by
1661 `cperl-extra-newline-before-brace'), and how reflow-logic should treat \"continuation\" blocks of else/elsif/continue, controlled by the same variable,
1662 and by `cperl-extra-newline-before-brace-multiline',
1663 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'.
1665 If `cperl-indent-level' is 0, the statement after opening brace in
1666 column 0 is indented on
1667 `cperl-brace-offset'+`cperl-continued-statement-offset'.
1669 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
1672 DO NOT FORGET to read micro-docs (available from `Perl' menu)
1673 or as help on variables `cperl-tips', `cperl-problems',
1674 `cperl-praise', `cperl-speed'."
1676 (kill-all-local-variables)
1677 (use-local-map cperl-mode-map
)
1678 (if (cperl-val 'cperl-electric-linefeed
)
1680 (local-set-key "\C-J" 'cperl-linefeed
)
1681 (local-set-key "\C-C\C-J" 'newline-and-indent
)))
1683 (cperl-val 'cperl-clobber-lisp-bindings
)
1684 (cperl-val 'cperl-info-on-command-no-prompt
))
1686 ;; don't clobber the backspace binding:
1687 (cperl-define-key "\C-hf" 'cperl-info-on-current-command
[(control h
) f
])
1688 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
1689 [(control c
) (control h
) f
])))
1690 (setq major-mode cperl-use-major-mode
)
1691 (setq mode-name
"CPerl")
1692 (let ((prev-a-c abbrevs-changed
))
1693 (define-abbrev-table 'cperl-mode-abbrev-table
'(
1694 ("if" "if" cperl-electric-keyword
0)
1695 ("elsif" "elsif" cperl-electric-keyword
0)
1696 ("while" "while" cperl-electric-keyword
0)
1697 ("until" "until" cperl-electric-keyword
0)
1698 ("unless" "unless" cperl-electric-keyword
0)
1699 ("else" "else" cperl-electric-else
0)
1700 ("continue" "continue" cperl-electric-else
0)
1701 ("for" "for" cperl-electric-keyword
0)
1702 ("foreach" "foreach" cperl-electric-keyword
0)
1703 ("formy" "formy" cperl-electric-keyword
0)
1704 ("foreachmy" "foreachmy" cperl-electric-keyword
0)
1705 ("do" "do" cperl-electric-keyword
0)
1706 ("=pod" "=pod" cperl-electric-pod
0)
1707 ("=over" "=over" cperl-electric-pod
0)
1708 ("=head1" "=head1" cperl-electric-pod
0)
1709 ("=head2" "=head2" cperl-electric-pod
0)
1710 ("pod" "pod" cperl-electric-pod
0)
1711 ("over" "over" cperl-electric-pod
0)
1712 ("head1" "head1" cperl-electric-pod
0)
1713 ("head2" "head2" cperl-electric-pod
0)))
1714 (setq abbrevs-changed prev-a-c
))
1715 (setq local-abbrev-table cperl-mode-abbrev-table
)
1716 (if (cperl-val 'cperl-electric-keywords
)
1718 (set-syntax-table cperl-mode-syntax-table
)
1719 ;; Until Emacs is multi-threaded, we do not actually need it local:
1720 (make-local-variable 'cperl-font-lock-multiline-start
)
1721 (make-local-variable 'cperl-font-locking
)
1722 (make-local-variable 'outline-regexp
)
1723 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
1724 (setq outline-regexp cperl-outline-regexp
)
1725 (make-local-variable 'outline-level
)
1726 (setq outline-level
'cperl-outline-level
)
1727 (make-local-variable 'paragraph-start
)
1728 (setq paragraph-start
(concat "^$\\|" page-delimiter
))
1729 (make-local-variable 'paragraph-separate
)
1730 (setq paragraph-separate paragraph-start
)
1731 (make-local-variable 'paragraph-ignore-fill-prefix
)
1732 (setq paragraph-ignore-fill-prefix t
)
1735 (make-local-variable 'paren-backwards-message
)
1736 (set 'paren-backwards-message t
)))
1737 (make-local-variable 'indent-line-function
)
1738 (setq indent-line-function
'cperl-indent-line
)
1739 (make-local-variable 'require-final-newline
)
1740 (setq require-final-newline mode-require-final-newline
)
1741 (make-local-variable 'comment-start
)
1742 (setq comment-start
"# ")
1743 (make-local-variable 'comment-end
)
1744 (setq comment-end
"")
1745 (make-local-variable 'comment-column
)
1746 (setq comment-column cperl-comment-column
)
1747 (make-local-variable 'comment-start-skip
)
1748 (setq comment-start-skip
"#+ *")
1749 (make-local-variable 'defun-prompt-regexp
)
1751 ;;; (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
1752 ;;; cperl-maybe-white-and-comment-rex ; 15=pre-block
1753 (setq defun-prompt-regexp
1754 (concat "^[ \t]*\\(sub"
1755 (cperl-after-sub-regexp 'named
'attr-groups
)
1757 "\\(BEGIN\\|CHECK\\|INIT\\|END\\|AUTOLOAD\\|DESTROY\\)"
1759 cperl-maybe-white-and-comment-rex
))
1760 (make-local-variable 'comment-indent-function
)
1761 (setq comment-indent-function
'cperl-comment-indent
)
1762 (and (boundp 'fill-paragraph-function
)
1764 (make-local-variable 'fill-paragraph-function
)
1765 (set 'fill-paragraph-function
'cperl-fill-paragraph
)))
1766 (make-local-variable 'parse-sexp-ignore-comments
)
1767 (setq parse-sexp-ignore-comments t
)
1768 (make-local-variable 'indent-region-function
)
1769 (setq indent-region-function
'cperl-indent-region
)
1770 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
1771 (make-local-variable 'imenu-create-index-function
)
1772 (setq imenu-create-index-function
1773 (function cperl-imenu--create-perl-index
))
1774 (make-local-variable 'imenu-sort-function
)
1775 (setq imenu-sort-function nil
)
1776 (make-local-variable 'vc-rcs-header
)
1777 (set 'vc-rcs-header cperl-vc-rcs-header
)
1778 (make-local-variable 'vc-sccs-header
)
1779 (set 'vc-sccs-header cperl-vc-sccs-header
)
1780 ;; This one is obsolete...
1781 (make-local-variable 'vc-header-alist
)
1782 (set 'vc-header-alist
(or cperl-vc-header-alist
; Avoid warning
1783 (` ((SCCS (, (car cperl-vc-sccs-header
)))
1784 (RCS (, (car cperl-vc-rcs-header
)))))))
1785 (cond ((boundp 'compilation-error-regexp-alist-alist
);; xemacs 20.x
1786 (make-local-variable 'compilation-error-regexp-alist-alist
)
1787 (set 'compilation-error-regexp-alist-alist
1788 (cons (cons 'cperl cperl-compilation-error-regexp-alist
)
1789 (symbol-value 'compilation-error-regexp-alist-alist
)))
1790 (if (fboundp 'compilation-build-compilation-error-regexp-alist
)
1791 (let ((f 'compilation-build-compilation-error-regexp-alist
))
1793 (make-local-variable 'compilation-error-regexp-alist
)
1794 (push 'cperl compilation-error-regexp-alist
)))
1795 ((boundp 'compilation-error-regexp-alist
);; xmeacs 19.x
1796 (make-local-variable 'compilation-error-regexp-alist
)
1797 (set 'compilation-error-regexp-alist
1798 (append cperl-compilation-error-regexp-alist
1799 (symbol-value 'compilation-error-regexp-alist
)))))
1800 (make-local-variable 'font-lock-defaults
)
1801 (setq font-lock-defaults
1803 ((string< emacs-version
"19.30")
1804 '(cperl-font-lock-keywords-2 nil nil
((?_ .
"w"))))
1805 ((string< emacs-version
"19.33") ; Which one to use?
1806 '((cperl-font-lock-keywords
1807 cperl-font-lock-keywords-1
1808 cperl-font-lock-keywords-2
) nil nil
((?_ .
"w"))))
1810 '((cperl-load-font-lock-keywords
1811 cperl-load-font-lock-keywords-1
1812 cperl-load-font-lock-keywords-2
) nil nil
((?_ .
"w"))))))
1813 (make-local-variable 'cperl-syntax-state
)
1814 (setq cperl-syntax-state nil
) ; reset syntaxification cache
1815 (if cperl-use-syntax-table-text-property
1817 (make-local-variable 'parse-sexp-lookup-properties
)
1818 ;; Do not introduce variable if not needed, we check it!
1819 (set 'parse-sexp-lookup-properties t
)
1820 ;; Fix broken font-lock:
1821 (or (boundp 'font-lock-unfontify-region-function
)
1822 (set 'font-lock-unfontify-region-function
1823 'font-lock-default-unfontify-region
))
1824 (unless cperl-xemacs-p
; Our: just a plug for wrong font-lock
1825 (make-local-variable 'font-lock-unfontify-region-function
)
1826 (set 'font-lock-unfontify-region-function
; not present with old Emacs
1827 'cperl-font-lock-unfontify-region-function
))
1828 (make-local-variable 'cperl-syntax-done-to
)
1829 (setq cperl-syntax-done-to nil
) ; reset syntaxification cache
1830 (make-local-variable 'font-lock-syntactic-keywords
)
1831 (setq font-lock-syntactic-keywords
1832 (if cperl-syntaxify-by-font-lock
1833 '((cperl-fontify-syntaxically))
1834 ;; unless font-lock-syntactic-keywords, font-lock (pre-22.1)
1835 ;; used to ignore syntax-table text-properties. (t) is a hack
1836 ;; to make font-lock think that font-lock-syntactic-keywords
1839 (if (boundp 'font-lock-multiline
) ; Newer font-lock; use its facilities
1841 (setq cperl-font-lock-multiline t
) ; Not localized...
1842 (set (make-local-variable 'font-lock-multiline
) t
))
1843 (make-local-variable 'font-lock-fontify-region-function
)
1844 (set 'font-lock-fontify-region-function
; not present with old Emacs
1845 'cperl-font-lock-fontify-region-function
))
1846 (make-local-variable 'font-lock-fontify-region-function
)
1847 (set 'font-lock-fontify-region-function
; not present with old Emacs
1848 'cperl-font-lock-fontify-region-function
)
1849 (make-local-variable 'cperl-old-style
)
1850 (if (boundp 'normal-auto-fill-function
) ; 19.33 and later
1851 (set (make-local-variable 'normal-auto-fill-function
)
1852 'cperl-do-auto-fill
)
1853 (or (fboundp 'cperl-old-auto-fill-mode
)
1855 (fset 'cperl-old-auto-fill-mode
(symbol-function 'auto-fill-mode
))
1856 (defun auto-fill-mode (&optional arg
)
1858 (eval '(cperl-old-auto-fill-mode arg
)) ; Avoid a warning
1859 (and auto-fill-function
(memq major-mode
'(perl-mode cperl-mode
))
1860 (setq auto-fill-function
'cperl-do-auto-fill
))))))
1861 (if (cperl-enable-font-lock)
1862 (if (cperl-val 'cperl-font-lock
)
1863 (progn (or cperl-faces-init
(cperl-init-faces))
1864 (font-lock-mode 1))))
1865 (set (make-local-variable 'facemenu-add-face-function
)
1866 'cperl-facemenu-add-face-function
) ; XXXX What this guy is for???
1867 (and (boundp 'msb-menu-cond
)
1868 (not cperl-msb-fixed
)
1870 (if (featurep 'easymenu
)
1871 (easy-menu-add cperl-menu
)) ; A NOP in Emacs.
1872 (run-mode-hooks 'cperl-mode-hook
)
1873 (if cperl-hook-after-change
1875 (make-local-hook 'after-change-functions
)
1876 (add-hook 'after-change-functions
'cperl-after-change-function nil t
)))
1877 ;; After hooks since fontification will break this
1878 (if cperl-pod-here-scan
1879 (or cperl-syntaxify-by-font-lock
1880 (progn (or cperl-faces-init
(cperl-init-faces-weak))
1881 (cperl-find-pods-heres)))))
1883 ;; Fix for perldb - make default reasonable
1887 (perldb (read-from-minibuffer "Run perldb (like this): "
1888 (if (consp gud-perldb-history
)
1889 (car gud-perldb-history
)
1890 (concat "perl " ;;(file-name-nondirectory
1894 (buffer-file-name)))
1896 '(gud-perldb-history .
1))))
1898 (defun cperl-msb-fix ()
1899 ;; Adds perl files to msb menu, supposes that msb is already loaded
1900 (setq cperl-msb-fixed t
)
1901 (let* ((l (length msb-menu-cond
))
1902 (last (nth (1- l
) msb-menu-cond
))
1903 (precdr (nthcdr (- l
2) msb-menu-cond
)) ; cdr of this is last
1904 (handle (1- (nth 1 last
))))
1905 (setcdr precdr
(list
1907 '(memq major-mode
'(cperl-mode perl-mode
))
1912 ;; This is used by indent-for-comment
1913 ;; to decide how much to indent a comment in CPerl code
1914 ;; based on its context. Do fallback if comment is found wrong.
1916 (defvar cperl-wrong-comment
)
1917 (defvar cperl-st-cfence
'(14)) ; Comment-fence
1918 (defvar cperl-st-sfence
'(15)) ; String-fence
1919 (defvar cperl-st-punct
'(1))
1920 (defvar cperl-st-word
'(2))
1921 (defvar cperl-st-bra
'(4 . ?\
>))
1922 (defvar cperl-st-ket
'(5 . ?\
<))
1925 (defun cperl-comment-indent () ; called at point at supposed comment
1926 (let ((p (point)) (c (current-column)) was phony
)
1927 (if (and (not cperl-indent-comment-at-column-0
)
1929 0 ; Existing comment at bol stays there.
1930 ;; Wrong comment found
1932 (setq was
(cperl-to-comment-or-eol)
1933 phony
(eq (get-text-property (point) 'syntax-table
)
1936 (progn ; Too naive???
1937 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
1938 (if (eq (preceding-char) ?\
#)
1941 (if (= (point) p
) ; Our caller found a correct place
1943 (skip-chars-backward " \t")
1944 (setq was
(current-column))
1947 (max (1+ was
) ; Else indent at comment column
1949 ;; No, the caller found a random place; we need to edit ourselves
1951 (insert comment-start
)
1952 (backward-char (length comment-start
)))
1953 (setq cperl-wrong-comment t
)
1954 (cperl-make-indent comment-column
1) ; Indent min 1
1957 ;;;(defun cperl-comment-indent-fallback ()
1958 ;;; "Is called if the standard comment-search procedure fails.
1959 ;;;Point is at start of real comment."
1960 ;;; (let ((c (current-column)) target cnt prevc)
1961 ;;; (if (= c comment-column) nil
1962 ;;; (setq cnt (skip-chars-backward "[ \t]"))
1963 ;;; (setq target (max (1+ (setq prevc
1964 ;;; (current-column))) ; Else indent at comment column
1965 ;;; comment-column))
1966 ;;; (if (= c comment-column) nil
1967 ;;; (delete-backward-char cnt)
1968 ;;; (while (< prevc target)
1970 ;;; (setq prevc (current-column)))
1971 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
1972 ;;; (while (< prevc target)
1974 ;;; (setq prevc (current-column)))))))
1976 (defun cperl-indent-for-comment ()
1977 "Substitute for `indent-for-comment' in CPerl."
1979 (let (cperl-wrong-comment)
1980 (indent-for-comment)
1981 (if cperl-wrong-comment
; set by `cperl-comment-indent'
1982 (progn (cperl-to-comment-or-eol)
1983 (forward-char (length comment-start
))))))
1985 (defun cperl-comment-region (b e arg
)
1986 "Comment or uncomment each line in the region in CPerl mode.
1987 See `comment-region'."
1988 (interactive "r\np")
1989 (let ((comment-start "#"))
1990 (comment-region b e arg
)))
1992 (defun cperl-uncomment-region (b e arg
)
1993 "Uncomment or comment each line in the region in CPerl mode.
1994 See `comment-region'."
1995 (interactive "r\np")
1996 (let ((comment-start "#"))
1997 (comment-region b e
(- arg
))))
1999 (defvar cperl-brace-recursing nil
)
2001 (defun cperl-electric-brace (arg &optional only-before
)
2002 "Insert character and correct line's indentation.
2003 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
2004 place (even in empty line), but not after. If after \")\" and the inserted
2005 char is \"{\", insert extra newline before only if
2006 `cperl-extra-newline-before-brace'."
2009 (other-end (if (and cperl-electric-parens-mark
2015 (not cperl-brace-recursing
)
2016 (cperl-val 'cperl-electric-parens
)
2017 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
2018 ;; Need to insert a matching pair
2021 (setq insertpos
(point-marker))
2022 (goto-char other-end
)
2023 (setq last-command-char ?\
{)
2024 (cperl-electric-lbrace arg insertpos
))
2026 ;; Check whether we close something "usual" with `}'
2027 (if (and (eq last-command-char ?\
})
2031 (up-list (- (prefix-numeric-value arg
)))
2032 ;;(cperl-after-block-p (point-min))
2033 (or (cperl-after-expr-p nil
"{;)")
2034 ;; after sub, else, continue
2035 (cperl-after-block-p nil
'pre
)))
2037 ;; Just insert the guy
2038 (self-insert-command (prefix-numeric-value arg
))
2039 (if (and (not arg
) ; No args, end (of empty line or auto)
2041 (or (and (null only-before
)
2043 (skip-chars-backward " \t")
2045 (and (eq last-command-char ?\
{) ; Do not insert newline
2046 ;; if after ")" and `cperl-extra-newline-before-brace'
2047 ;; is nil, do not insert extra newline.
2048 (not cperl-extra-newline-before-brace
)
2050 (skip-chars-backward " \t")
2051 (eq (preceding-char) ?\
))))
2052 (if cperl-auto-newline
2053 (progn (cperl-indent-line) (newline) t
) nil
)))
2055 (self-insert-command (prefix-numeric-value arg
))
2057 (if cperl-auto-newline
2058 (setq insertpos
(1- (point))))
2059 (if (and cperl-auto-newline
(null only-before
))
2062 (cperl-indent-line)))
2064 (if insertpos
(progn (goto-char insertpos
)
2065 (search-forward (make-string
2066 1 last-command-char
))
2067 (setq insertpos
(1- (point)))))
2071 (goto-char insertpos
)
2072 (self-insert-command (prefix-numeric-value arg
)))
2073 (self-insert-command (prefix-numeric-value arg
)))))))
2075 (defun cperl-electric-lbrace (arg &optional end
)
2076 "Insert character, correct line's indentation, correct quoting by space."
2078 (let ((cperl-brace-recursing t
)
2079 (cperl-auto-newline cperl-auto-newline
)
2081 (if (and cperl-electric-parens-mark
2089 (and (cperl-val 'cperl-electric-lbrace-space
)
2090 (eq (preceding-char) ?$
)
2092 (skip-chars-backward "$")
2093 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
2095 ;; Check whether we are in comment
2099 (not (looking-at "[ \t]*#")))
2100 (cperl-after-expr-p nil
"{;)"))
2102 (setq cperl-auto-newline nil
))
2103 (cperl-electric-brace arg
)
2104 (and (cperl-val 'cperl-electric-parens
)
2105 (eq last-command-char ?
{)
2106 (memq last-command-char
2107 (append cperl-electric-parens-string nil
))
2108 (or (if other-end
(goto-char (marker-position other-end
)))
2110 (setq last-command-char ?
} pos
(point))
2111 (progn (cperl-electric-brace arg t
)
2114 (defun cperl-electric-paren (arg)
2115 "Insert an opening parenthesis or a matching pair of parentheses.
2116 See `cperl-electric-parens'."
2118 (let ((beg (save-excursion (beginning-of-line) (point)))
2119 (other-end (if (and cperl-electric-parens-mark
2126 (if (and (cperl-val 'cperl-electric-parens
)
2127 (memq last-command-char
2128 (append cperl-electric-parens-string nil
))
2129 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2130 ;;(not (save-excursion (search-backward "#" beg t)))
2131 (if (eq last-command-char ?
<)
2133 (and abbrev-mode
; later it is too late, may be after `for'
2135 (cperl-after-expr-p nil
"{;(,:="))
2138 (self-insert-command (prefix-numeric-value arg
))
2139 (if other-end
(goto-char (marker-position other-end
)))
2140 (insert (make-string
2141 (prefix-numeric-value arg
)
2142 (cdr (assoc last-command-char
'((?
{ .?
})
2146 (forward-char (- (prefix-numeric-value arg
))))
2147 (self-insert-command (prefix-numeric-value arg
)))))
2149 (defun cperl-electric-rparen (arg)
2150 "Insert a matching pair of parentheses if marking is active.
2151 If not, or if we are not at the end of marking range, would self-insert.
2152 Affected by `cperl-electric-parens'."
2154 (let ((beg (save-excursion (beginning-of-line) (point)))
2155 (other-end (if (and cperl-electric-parens-mark
2156 (cperl-val 'cperl-electric-parens
)
2157 (memq last-command-char
2158 (append cperl-electric-parens-string nil
))
2165 (cperl-val 'cperl-electric-parens
)
2166 (memq last-command-char
'( ?\
) ?\
] ?\
} ?\
> ))
2167 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2168 ;;(not (save-excursion (search-backward "#" beg t)))
2171 (self-insert-command (prefix-numeric-value arg
))
2173 (if other-end
(goto-char other-end
))
2174 (insert (make-string
2175 (prefix-numeric-value arg
)
2176 (cdr (assoc last-command-char
'((?\
} . ?\
{)
2181 (self-insert-command (prefix-numeric-value arg
)))))
2183 (defun cperl-electric-keyword ()
2184 "Insert a construction appropriate after a keyword.
2185 Help message may be switched off by setting `cperl-message-electric-keyword'
2187 (let ((beg (save-excursion (beginning-of-line) (point)))
2188 (dollar (and (eq last-command-char ?$
)
2189 (eq this-command
'self-insert-command
)))
2190 (delete (and (memq last-command-char
'(?\s ?
\n ?
\t ?
\f))
2191 (memq this-command
'(self-insert-command newline
))))
2193 (and (save-excursion
2197 (setq do
(looking-at "do\\>")))
2199 (cperl-after-expr-p nil
"{;:"))
2203 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2205 (save-excursion (or (not (re-search-backward "^=" nil t
))
2208 (and cperl-use-syntax-table-text-property
2209 (not (eq (get-text-property (point)
2212 (save-excursion (forward-sexp -
1)
2213 (not (memq (following-char) (append "$@%&*" nil
))))
2215 (and (eq (preceding-char) ?y
)
2216 (progn ; "foreachmy"
2222 (memq this-command
'(self-insert-command newline
)))))
2223 (and dollar
(insert " $"))
2225 ;;(insert " () {\n}")
2227 (cperl-extra-newline-before-brace
2228 (insert (if do
"\n" " ()\n"))
2234 (and do
(insert " while ();")))
2236 (insert (if do
" {\n} while ();" " () {\n}"))))
2237 (or (looking-at "[ \t]\\|$") (insert " "))
2239 (if dollar
(progn (search-backward "$")
2243 (search-backward ")")
2244 (if (eq last-command-char ?\
()
2245 (progn ; Avoid "if (())"
2246 (delete-backward-char 1)
2247 (delete-backward-char -
1))))
2249 (cperl-putback-char cperl-del-back-ch
))
2250 (if cperl-message-electric-keyword
2251 (message "Precede char by C-q to avoid expansion"))))))
2253 (defun cperl-ensure-newlines (n &optional pos
)
2254 "Make sure there are N newlines after the point."
2255 (or pos
(setq pos
(point)))
2256 (if (looking-at "\n")
2260 (cperl-ensure-newlines (1- n
) pos
)
2263 (defun cperl-electric-pod ()
2264 "Insert a POD chunk appropriate after a =POD directive."
2265 (let ((delete (and (memq last-command-char
'(?\s ?
\n ?
\t ?
\f))
2266 (memq this-command
'(self-insert-command newline
))))
2267 head1 notlast name p really-delete over
)
2268 (and (save-excursion
2271 (eq (preceding-char) ?
=)
2273 (setq head1
(looking-at "head1\\>[ \t]*$"))
2274 (setq over
(and (looking-at "over\\>[ \t]*$")
2275 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
2279 (get-text-property (point) 'in-pod
)
2280 (cperl-after-expr-p nil
"{;:")
2281 (and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t
)
2282 (not (looking-at "\n*=cut"))
2283 (or (not cperl-use-syntax-table-text-property
)
2284 (eq (get-text-property (point) 'syntax-type
) 'pod
))))))
2287 (setq notlast
(re-search-forward "^\n=" nil t
)))
2291 (cperl-ensure-newlines 2)
2297 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
2298 nil t
)))) ; Only one
2301 (setq name
(file-name-sans-extension
2302 (file-name-nondirectory (buffer-file-name)))
2304 (insert " NAME\n\n" name
2305 " - \n\n=head1 SYNOPSIS\n\n\n\n"
2306 "=head1 DESCRIPTION")
2307 (cperl-ensure-newlines 4)
2311 (setq really-delete t
))
2316 (insert "\n\n=item \n\n\n\n"
2318 (cperl-ensure-newlines 2)
2322 (setq really-delete t
)))
2323 (if (and delete really-delete
)
2324 (cperl-putback-char cperl-del-back-ch
))))))
2326 (defun cperl-electric-else ()
2327 "Insert a construction appropriate after a keyword.
2328 Help message may be switched off by setting `cperl-message-electric-keyword'
2330 (let ((beg (save-excursion (beginning-of-line) (point))))
2331 (and (save-excursion
2333 (cperl-after-expr-p nil
"{;:"))
2337 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2339 (save-excursion (or (not (re-search-backward "^=" nil t
))
2341 (and cperl-use-syntax-table-text-property
2342 (not (eq (get-text-property (point)
2347 ;;(insert " {\n\n}")
2349 (cperl-extra-newline-before-brace
2355 (insert " {\n\n}")))
2356 (or (looking-at "[ \t]\\|$") (insert " "))
2360 (cperl-putback-char cperl-del-back-ch
)
2361 (setq this-command
'cperl-electric-else
)
2362 (if cperl-message-electric-keyword
2363 (message "Precede char by C-q to avoid expansion"))))))
2365 (defun cperl-linefeed ()
2366 "Go to end of line, open a new line and indent appropriately.
2367 If in POD, insert appropriate lines."
2369 (let ((beg (save-excursion (beginning-of-line) (point)))
2370 (end (save-excursion (end-of-line) (point)))
2371 (pos (point)) start over cut res
)
2372 (if (and ; Check if we need to split:
2373 ; i.e., on a boundary and inside "{...}"
2374 (save-excursion (cperl-to-comment-or-eol)
2375 (>= (point) pos
)) ; Not in a comment
2377 (skip-chars-backward " \t" beg
)
2379 (looking-at "[;{]")) ; After { or ; + spaces
2380 (looking-at "[ \t]*}") ; Before }
2381 (re-search-forward "\\=[ \t]*;" end t
)) ; Before spaces + ;
2384 (eq (car (parse-partial-sexp pos end -
1)) -
1)
2385 ; Leave the level of parens
2386 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
2388 (cperl-after-block-p (point-min))
2391 (setq start
(point-marker))
2392 (<= start pos
))))) ; Redundant? Are after the
2393 ; start of parens group.
2395 (skip-chars-backward " \t")
2396 (or (memq (preceding-char) (append ";{" nil
))
2402 (or (looking-at "{[ \t]*$") ; If there is a statement
2403 ; before, move it to separate line
2407 (cperl-indent-line)))
2408 (forward-line 1) ; We are on the target line
2411 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
2412 ; after, move it to separate line
2415 (search-backward "}" beg
)
2416 (skip-chars-backward " \t")
2417 (or (memq (preceding-char) (append ";{" nil
))
2422 (forward-line -
1) ; We are on the line before target
2424 (newline-and-indent))
2425 (end-of-line) ; else - no splitting
2427 ((and (looking-at "\n[ \t]*{$")
2429 (skip-chars-backward " \t")
2430 (eq (preceding-char) ?\
)))) ; Probably if () {} group
2431 ; with an extra newline.
2433 (cperl-indent-line))
2434 ((save-excursion ; In POD header
2435 (forward-paragraph -
1)
2436 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
2437 ;; We are after \n now, so look for the rest
2438 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
2440 (setq cut
(looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
2441 (setq over
(looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
2445 (forward-paragraph -
1)
2448 (setq cut
(buffer-substring (point)
2452 (delete-char (- (save-excursion (end-of-line) (point))
2454 (setq res
(expand-abbrev))
2460 (cperl-ensure-newlines (if cut
2 4))
2462 ((get-text-property (point) 'in-pod
) ; In POD section
2463 (cperl-ensure-newlines 4)
2465 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
2467 (cperl-indent-line))
2469 (newline-and-indent))))))
2471 (defun cperl-electric-semi (arg)
2472 "Insert character and correct line's indentation."
2474 (if cperl-auto-newline
2475 (cperl-electric-terminator arg
)
2476 (self-insert-command (prefix-numeric-value arg
))
2477 (if cperl-autoindent-on-semi
2478 (cperl-indent-line))))
2480 (defun cperl-electric-terminator (arg)
2481 "Insert character and correct line's indentation."
2484 (auto (and cperl-auto-newline
2485 (or (not (eq last-command-char ?
:))
2486 cperl-auto-newline-after-colon
)))
2488 (if (and ;;(not arg)
2490 (not (save-excursion
2492 (skip-chars-forward " \t")
2494 ;; Ignore in comment lines
2495 (= (following-char) ?
#)
2496 ;; Colon is special only after a label
2497 ;; So quickly rule out most other uses of colon
2498 ;; and do no indentation for them.
2499 (and (eq last-command-char ?
:)
2502 (skip-chars-forward " \t")
2503 (and (< (point) end
)
2504 (progn (goto-char (- end
1))
2505 (not (looking-at ":"))))))
2507 (beginning-of-defun)
2508 (let ((pps (parse-partial-sexp (point) end
)))
2509 (or (nth 3 pps
) (nth 4 pps
) (nth 5 pps
))))))))
2511 (self-insert-command (prefix-numeric-value arg
))
2513 (if auto
(setq insertpos
(point-marker)))
2519 (cperl-indent-line)))
2521 (if insertpos
(goto-char (1- (marker-position insertpos
)))
2526 (goto-char insertpos
)
2527 (self-insert-command (prefix-numeric-value arg
)))
2528 (self-insert-command (prefix-numeric-value arg
)))))
2530 (defun cperl-electric-backspace (arg)
2531 "Backspace, or remove the whitespace around the point inserted by an electric
2532 key. Will untabify if `cperl-electric-backspace-untabify' is non-nil."
2534 (if (and cperl-auto-newline
2535 (memq last-command
'(cperl-electric-semi
2536 cperl-electric-terminator
2537 cperl-electric-lbrace
))
2538 (memq (preceding-char) '(?\s ?
\t ?
\n)))
2540 (if (eq last-command
'cperl-electric-lbrace
)
2541 (skip-chars-forward " \t\n"))
2543 (skip-chars-backward " \t\n")
2544 (delete-region (point) p
))
2545 (and (eq last-command
'cperl-electric-else
)
2546 ;; We are removing the whitespace *inside* cperl-electric-else
2547 (setq this-command
'cperl-electric-else-really
))
2548 (if (and cperl-auto-newline
2549 (eq last-command
'cperl-electric-else-really
)
2550 (memq (preceding-char) '(?\s ?
\t ?
\n)))
2552 (skip-chars-forward " \t\n")
2554 (skip-chars-backward " \t\n")
2555 (delete-region (point) p
))
2556 (if cperl-electric-backspace-untabify
2557 (backward-delete-char-untabify arg
)
2558 (delete-backward-char arg
)))))
2560 (put 'cperl-electric-backspace
'delete-selection
'supersede
)
2562 (defun cperl-inside-parens-p () ;; NOT USED????
2566 (narrow-to-region (point)
2567 (progn (beginning-of-defun) (point)))
2568 (goto-char (point-max))
2569 (= (char-after (or (scan-lists (point) -
1 1) (point-min))) ?\
()))
2572 (defun cperl-indent-command (&optional whole-exp
)
2573 "Indent current line as Perl code, or in some cases insert a tab character.
2574 If `cperl-tab-always-indent' is non-nil (the default), always indent current
2575 line. Otherwise, indent the current line only if point is at the left margin
2576 or in the line's indentation; otherwise insert a tab.
2578 A numeric argument, regardless of its value,
2579 means indent rigidly all the lines of the expression starting after point
2580 so that this line becomes properly indented.
2581 The relative indentation among the lines of the expression are preserved."
2583 (cperl-update-syntaxification (point) (point))
2585 ;; If arg, always indent this line as Perl
2586 ;; and shift remaining lines of expression the same amount.
2587 (let ((shift-amt (cperl-indent-line))
2590 (if cperl-tab-always-indent
2591 (beginning-of-line))
2598 (if (and shift-amt
(> end beg
))
2599 (indent-code-rigidly beg end shift-amt
"#")))
2600 (if (and (not cperl-tab-always-indent
)
2602 (skip-chars-backward " \t")
2605 (cperl-indent-line))))
2607 (defun cperl-indent-line (&optional parse-data
)
2608 "Indent current line as Perl code.
2609 Return the amount the indentation changed by."
2610 (let ((case-fold-search nil
)
2611 (pos (- (point-max) (point)))
2612 indent i beg shift-amt
)
2613 (setq indent
(cperl-calculate-indent parse-data
)
2617 (cond ((or (eq indent nil
) (eq indent t
))
2618 (setq indent
(current-indentation) i nil
))
2619 ;;((eq indent t) ; Never?
2620 ;; (setq indent (cperl-calculate-indent-within-comment)))
2621 ;;((looking-at "[ \t]*#")
2624 (skip-chars-forward " \t")
2625 (if (listp indent
) (setq indent
(car indent
)))
2626 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
2628 (setq indent
(max cperl-min-label-indent
2629 (+ indent cperl-label-offset
)))))
2630 ((= (following-char) ?
})
2631 (setq indent
(- indent cperl-indent-level
)))
2632 ((memq (following-char) '(?\
) ?\
])) ; To line up with opening paren.
2633 (setq indent
(+ indent cperl-close-paren-offset
)))
2634 ((= (following-char) ?
{)
2635 (setq indent
(+ indent cperl-brace-offset
))))))
2636 (skip-chars-forward " \t")
2637 (setq shift-amt
(and i
(- indent
(current-column))))
2638 (if (or (not shift-amt
)
2640 (if (> (- (point-max) pos
) (point))
2641 (goto-char (- (point-max) pos
)))
2642 ;;;(delete-region beg (point))
2643 ;;;(indent-to indent)
2644 (cperl-make-indent indent
)
2645 ;; If initial point was within line's indentation,
2646 ;; position after the indentation. Else stay at same point in text.
2647 (if (> (- (point-max) pos
) (point))
2648 (goto-char (- (point-max) pos
))))
2651 (defun cperl-after-label ()
2652 ;; Returns true if the point is after label. Does not do save-excursion.
2653 (and (eq (preceding-char) ?
:)
2654 (memq (char-syntax (char-after (- (point) 2)))
2658 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
2660 (defun cperl-get-state (&optional parse-start start-state
)
2661 ;; returns list (START STATE DEPTH PRESTART),
2662 ;; START is a good place to start parsing, or equal to
2663 ;; PARSE-START if preset,
2664 ;; STATE is what is returned by `parse-partial-sexp'.
2665 ;; DEPTH is true is we are immediately after end of block
2666 ;; which contains START.
2667 ;; PRESTART is the position basing on which START was found.
2669 (let ((start-point (point)) depth state start prestart
)
2670 (if (and parse-start
2671 (<= parse-start start-point
))
2672 (goto-char parse-start
)
2673 (beginning-of-defun)
2674 (setq start-state nil
))
2675 (setq prestart
(point))
2677 ;; Try to go out, if sub is not on the outermost level
2678 (while (< (point) start-point
)
2679 (setq start
(point) parse-start start depth nil
2680 state
(parse-partial-sexp start start-point -
1))
2681 (if (> (car state
) -
1) nil
2682 ;; The current line could start like }}}, so the indentation
2683 ;; corresponds to a different level than what we reached
2685 (beginning-of-line 2))) ; Go to the next line.
2686 (if start
(goto-char start
))) ; Not at the start of file
2687 (setq start
(point))
2688 (or state
(setq state
(parse-partial-sexp start start-point -
1 nil start-state
)))
2689 (list start state depth prestart
))))
2691 (defvar cperl-look-for-prop
'((pod in-pod
) (here-doc-delim here-doc-group
)))
2693 (defun cperl-beginning-of-property (p prop
&optional lim
)
2694 "Given that P has a property PROP, find where the property starts.
2695 Will not look before LIM."
2696 ;;; XXXX What to do at point-max???
2697 (or (previous-single-property-change (cperl-1+ p
) prop lim
)
2699 ;;; (cond ((eq p (point-min))
2701 ;;; ((and lim (<= p lim))
2703 ;;; ((not (get-text-property (1- p) prop))
2705 ;;; (t (or (previous-single-property-change p look-prop lim)
2709 (defun cperl-sniff-for-indent (&optional parse-data
) ; was parse-start
2710 ;; Old workhorse for calculation of indentation; the major problem
2711 ;; is that it mixes the sniffer logic to understand what the current line
2712 ;; MEANS with the logic to actually calculate where to indent it.
2713 ;; The latter part should be eventually moved to `cperl-calculate-indent';
2714 ;; actually, this is mostly done now...
2715 (cperl-update-syntaxification (point) (point))
2716 (let ((res (get-text-property (point) 'syntax-type
)))
2719 ((and (memq res
'(pod here-doc here-doc-delim format
))
2720 (not (get-text-property (point) 'indentable
)))
2722 ;; before start of POD - whitespace found since do not have 'pod!
2723 ((looking-at "[ \t]*\n=")
2724 (error "Spaces before POD section!"))
2725 ((and (not cperl-indent-left-aligned-comments
)
2727 [comment-special
:at-beginning-of-line
])
2728 ((get-text-property (point) 'in-pod
)
2732 (let* ((indent-point (point))
2733 (char-after-pos (save-excursion
2734 (skip-chars-forward " \t")
2736 (char-after (char-after char-after-pos
))
2737 (pre-indent-point (point))
2738 p prop look-prop is-block delim
)
2739 (save-excursion ; Know we are not in POD, find appropriate pos before
2740 (cperl-backward-to-noncomment nil
)
2741 (setq p
(max (point-min) (1- (point)))
2742 prop
(get-text-property p
'syntax-type
)
2743 look-prop
(or (nth 1 (assoc prop cperl-look-for-prop
))
2745 (if (memq prop
'(pod here-doc format here-doc-delim
))
2747 (goto-char (cperl-beginning-of-property p look-prop
))
2749 (setq pre-indent-point
(point)))))
2750 (goto-char pre-indent-point
) ; Orig line skipping preceeding pod/etc
2751 (let* ((case-fold-search nil
)
2752 (s-s (cperl-get-state (car parse-data
) (nth 1 parse-data
)))
2753 (start (or (nth 2 parse-data
) ; last complete sexp terminated
2754 (nth 0 s-s
))) ; Good place to start parsing
2756 (containing-sexp (car (cdr state
)))
2759 ;;containing-sexp ;; We are buggy at toplevel :-(
2762 (setcar parse-data pre-indent-point
)
2763 (setcar (cdr parse-data
) state
)
2764 (or (nth 2 parse-data
)
2765 (setcar (cddr parse-data
) start
))
2766 ;; Before this point: end of statement
2767 (setq old-indent
(nth 3 parse-data
))))
2768 (cond ((get-text-property (point) 'indentable
)
2769 ;; indent to "after" the surrounding open
2770 ;; (same offset as `cperl-beautify-regexp-piece'),
2771 ;; skip blanks if we do not close the expression.
2772 (setq delim
; We do not close the expression
2774 (cperl-1+ char-after-pos
) 'indentable
)
2775 p
(1+ (cperl-beginning-of-property
2776 (point) 'indentable
))
2777 is-block
; misused for: preceeding line in REx
2778 (save-excursion ; Find preceeding line
2779 (cperl-backward-to-noncomment p
)
2782 (progn ; get indent from the first line
2784 (skip-chars-forward " \t")
2785 (if (memq (char-after (point))
2787 nil
; Can't use intentation of this line...
2789 (skip-chars-forward " \t")
2791 prop
(parse-partial-sexp p char-after-pos
))
2792 (cond ((not delim
) ; End the REx, ignore is-block
2793 (vector 'indentable
'terminator p is-block
))
2794 (is-block ; Indent w.r.t. preceeding line
2795 (vector 'indentable
'cont-line char-after-pos
2796 is-block char-after p
))
2797 (t ; No preceeding line...
2798 (vector 'indentable
'first-line p
))))
2799 ((get-text-property char-after-pos
'REx-part2
)
2800 (vector 'REx-part2
(point)))
2805 ;; XXXX Do we need to special-case this?
2806 ((null containing-sexp)
2807 ;; Line is at top level. May be data or function definition,
2808 ;; or may be function argument declaration.
2809 ;; Indent like the previous top level line
2810 ;; unless that ends in a closeparen without semicolon,
2811 ;; in which case this line is the first argument decl.
2812 (skip-chars-forward " \t")
2813 (cperl-backward-to-noncomment (or old-indent (point-min)))
2816 (eq (point) old-indent) ; old-indent was at comment
2817 (eq (preceding-char) ?\;)
2819 (and (eq (preceding-char) ?\})
2820 (cperl-after-block-and-statement-beg
2821 (point-min))) ; Was start - too close
2822 (memq char-after (append ")]}" nil))
2823 (and (eq (preceding-char) ?\:) ; label
2826 (skip-chars-backward " \t")
2827 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
2828 (get-text-property (point) 'first-format-line)))
2830 ;; Look at previous line that's at column 0
2831 ;; to determine whether we are in top-level decls
2832 ;; or function's arg decls. Set basic-indent accordingly.
2833 ;; Now add a little if this is a continuation line.
2836 (not (eq char-after ?\C-j))
2837 (setcdr (cddr parse-data)
2838 (list pre-indent-point)))
2839 (vector 'toplevel start char-after state (nth 2 s-s)))
2842 (and (setq delim (= (char-after containing-sexp) ?{))
2843 (save-excursion ; Is it a hash?
2844 (goto-char containing-sexp)
2846 cperl-indent-parens-as-block))
2847 ;; group is an expression, not a block:
2848 ;; indent to just after the surrounding open parens,
2849 ;; skip blanks if we do not close the expression.
2850 (goto-char (1+ containing-sexp))
2851 (or (memq char-after
2852 (append (if delim "}" ")]}") nil))
2853 (looking-at "[ \t]*\\(#\\|$\\)")
2854 (skip-chars-forward " \t"))
2855 (setq old-indent (point)) ; delim=is-brace
2856 (vector 'in-parens char-after (point) delim containing-sexp))
2858 ;; Statement level. Is it a continuation or a new statement?
2859 ;; Find previous non-comment character.
2860 (goto-char pre-indent-point) ; Skip one level of POD/etc
2861 (cperl-backward-to-noncomment containing-sexp)
2862 ;; Back up over label lines, since they don't
2863 ;; affect whether our line is a continuation.
2865 (while;;(or (eq (preceding-char) ?\,)
2866 (and (eq (preceding-char) ?:)
2867 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
2868 (memq (char-syntax (char-after (- (point) 2)))
2871 ;; This is always FALSE?
2872 (if (eq (preceding-char) ?\,)
2873 ;; Will go to beginning of line, essentially.
2874 ;; Will ignore embedded sexpr XXXX.
2875 (cperl-backward-to-start-of-continued-exp containing-sexp))
2877 (cperl-backward-to-noncomment containing-sexp))
2878 ;; Now we get non-label preceeding the indent point
2879 (if (not (or (eq (1- (point)) containing-sexp)
2880 (memq (preceding-char)
2881 (append (if is-block " ;{" " ,;{") '(nil)))
2882 (and (eq (preceding-char) ?\})
2883 (cperl-after-block-and-statement-beg
2885 (get-text-property (point) 'first-format-line)))
2886 ;; This line is continuation of preceding line's statement;
2887 ;; indent `cperl-continued-statement-offset' more than the
2888 ;; previous line of the statement.
2890 ;; There might be a label on this line, just
2891 ;; consider it bad style and ignore it.
2893 (cperl-backward-to-start-of-continued-exp containing-sexp)
2894 (vector 'continuation (point) char-after is-block delim))
2895 ;; This line starts a new statement.
2896 ;; Position following last unclosed open brace
2897 (goto-char containing-sexp)
2898 ;; Is line first statement after an open-brace?
2900 ;; If no, find that first statement and indent like
2901 ;; it. If the first statement begins with label, do
2902 ;; not believe when the indentation of the label is too
2906 (let ((colon-line-end 0))
2908 (progn (skip-chars-forward " \t\n")
2909 (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]\\|=[a-zA-Z]"))
2910 ;; Skip over comments and labels following openbrace.
2911 (cond ((= (following-char) ?\#)
2913 ((= (following-char) ?\=)
2915 (or (next-single-property-change (point) 'in-pod)
2916 (point-max)))) ; do not loop if no syntaxification
2919 (save-excursion (end-of-line)
2920 (setq colon-line-end (point)))
2921 (search-forward ":"))))
2922 ;; We are at beginning of code (NOT label or comment)
2923 ;; First, the following code counts
2924 ;; if it is before the line we want to indent.
2925 (and (< (point) indent-point)
2926 (vector 'have-prev-sibling (point) colon-line-end
2929 ;; If no previous statement,
2930 ;; indent it relative to line brace is on.
2932 ;; For open-braces not the first thing in a line,
2933 ;; add in cperl-brace-imaginary-offset.
2935 ;; If first thing on a line: ?????
2936 ;; Move back over whitespace before the openbrace.
2937 (setq ; brace first thing on a line
2938 old-indent (progn (skip-chars-backward " \t") (bolp)))
2939 ;; Should we indent w.r.t. earlier than start?
2940 ;; Move to start of control group, possibly on a different line
2941 (or cperl-indent-wrt-brace
2942 (cperl-backward-to-noncomment (point-min)))
2943 ;; If the openbrace is preceded by a parenthesized exp,
2944 ;; move to the beginning of that;
2945 (if (eq (preceding-char) ?\))
2948 (cperl-backward-to-noncomment (point-min))))
2949 ;; In the case it starts a subroutine, indent with
2950 ;; respect to `sub', not with respect to the
2951 ;; first thing on the line, say in the case of
2952 ;; anonymous sub in a hash.
2953 (if (and;; Is it a sub in group starting on this line?
2954 (cond ((get-text-property (point) 'attrib-group)
2955 (goto-char (cperl-beginning-of-property
2956 (point) 'attrib-group)))
2957 ((eq (preceding-char) ?b)
2959 (looking-at "sub\\>")))
2960 (setq p (nth 1 ; start of innermost containing list
2962 (save-excursion (beginning-of-line)
2966 (goto-char (1+ p)) ; enclosing block on the same line
2967 (skip-chars-forward " \t")
2968 (vector 'code-start-in-block containing-sexp char-after
2969 (and delim (not is-block)) ; is a HASH
2970 old-indent ; brace first thing on a line
2971 t (point) ; have something before...
2975 ;; Get initial indentation of the line we are on.
2976 ;; If line starts with label, calculate label indentation
2977 (vector 'code-start-in-block containing-sexp char-after
2978 (and delim (not is-block)) ; is a HASH
2979 old-indent ; brace first thing on a line
2980 nil (point) ; nothing interesting before
2983 (defvar cperl-indent-rules-alist
2984 '((pod nil) ; via `syntax-type' property
2985 (here-doc nil) ; via `syntax-type' property
2986 (here-doc-delim nil) ; via `syntax-type' property
2987 (format nil) ; via `syntax-type' property
2988 (in-pod nil) ; via `in-pod' property
2989 (comment-special:at-beginning-of-line nil)
2992 "Alist of indentation rules for CPerl mode.
2995 number: add this amount of indentation.
2999 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
3000 "Return appropriate indentation for current line as Perl code.
3001 In usual case returns an integer: the column to indent to.
3002 Returns nil if line starts inside a string, t if in a comment.
3004 Will not correct the indentation for labels, but will correct it for braces
3005 and closing parentheses and brackets."
3006 ;; This code is still a broken architecture: in some cases we need to
3007 ;; compensate for some modifications which `cperl-indent-line' will add later
3009 (let ((i (cperl-sniff-for-indent parse-data)) what p)
3011 ;;((or (null i) (eq i t) (numberp i))
3014 (setq what (assoc (elt i 0) cperl-indent-rules-alist))
3016 (what (cadr what)) ; Load from table
3018 ;; Indenters for regular expressions with //x and qw()
3020 ((eq 'REx-part2 (elt i 0)) ;; [self start] start of /REP in s//REP/x
3021 (goto-char (elt i 1))
3022 (condition-case nil ; Use indentation of the 1st part
3025 ((eq 'indentable (elt i 0)) ; Indenter for REGEXP qw() etc
3026 (cond ;;; [indentable terminator start-pos is-block]
3027 ((eq 'terminator (elt i 1)) ; Lone terminator of "indentable string"
3028 (goto-char (elt i 2)) ; After opening parens
3029 (1- (current-column)))
3030 ((eq 'first-line (elt i 1)); [indentable first-line start-pos]
3031 (goto-char (elt i 2))
3032 (+ (or cperl-regexp-indent-step cperl-indent-level)
3035 ((eq 'cont-line (elt i 1)); [indentable cont-line pos prev-pos first-char start-pos]
3036 ;; Indent as the level after closing parens
3037 (goto-char (elt i 2)) ; indent line
3038 (skip-chars-forward " \t)") ; Skip closing parens
3040 (goto-char (elt i 3)) ; previous line
3041 (skip-chars-forward " \t)") ; Skip closing parens
3042 ;; Number of parens in between:
3043 (setq p (nth 0 (parse-partial-sexp (point) p))
3044 what (elt i 4)) ; First char on current line
3045 (goto-char (elt i 3)) ; previous line
3046 (+ (* p (or cperl-regexp-indent-step cperl-indent-level))
3047 (cond ((eq what ?\) )
3048 (- cperl-close-paren-offset)) ; compensate
3050 (- (or cperl-regexp-indent-step cperl-indent-level)))
3052 (if (eq (following-char) ?\| )
3053 (or cperl-regexp-indent-step cperl-indent-level)
3057 (error "Unrecognized value of indent: %s" i))))
3059 ;; Indenter for stuff at toplevel
3061 ((eq 'toplevel (elt i 0)) ;; [toplevel start char-after state immed-after-block]
3062 (+ (save-excursion ; To beg-of-defun, or end of last sexp
3063 (goto-char (elt i 1)) ; start = Good place to start parsing
3064 (- (current-indentation) ;
3065 (if (elt i 4) cperl-indent-level 0))) ; immed-after-block
3066 (if (eq (elt i 2) ?{) cperl-continued-brace-offset 0) ; char-after
3067 ;; Look at previous line that's at column 0
3068 ;; to determine whether we are in top-level decls
3069 ;; or function's arg decls. Set basic-indent accordingly.
3070 ;; Now add a little if this is a continuation line.
3071 (if (elt i 3) ; state (XXX What is the semantic???)
3073 cperl-continued-statement-offset)))
3075 ;; Indenter for stuff in "parentheses" (or brackets, braces-as-hash)
3077 ((eq 'in-parens (elt i 0))
3078 ;; in-parens char-after old-indent-point is-brace containing-sexp
3080 ;; group is an expression, not a block:
3081 ;; indent to just after the surrounding open parens,
3082 ;; skip blanks if we do not close the expression.
3084 (goto-char (elt i 2)) ; old-indent-point
3086 (if (and (elt i 3) ; is-brace
3087 (eq (elt i 1) ?\})) ; char-after
3088 ;; Correct indentation of trailing ?\}
3089 (+ cperl-indent-level cperl-close-paren-offset)
3092 ;; Indenter for continuation lines
3094 ((eq 'continuation (elt i 0))
3095 ;; [continuation statement-start char-after is-block is-brace]
3096 (goto-char (elt i 1)) ; statement-start
3097 (+ (if (memq (elt i 2) (append "}])" nil)) ; char-after
3099 cperl-continued-statement-offset)
3100 (if (or (elt i 3) ; is-block
3101 (not (elt i 4)) ; is-brace
3102 (not (eq (elt i 2) ?\}))) ; char-after
3104 ;; Now it is a hash reference
3105 (+ cperl-indent-level cperl-close-paren-offset))
3106 ;; Labels do not take :: ...
3107 (if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
3108 (if (> (current-indentation) cperl-min-label-indent)
3109 (- (current-indentation) cperl-label-offset)
3110 ;; Do not move `parse-data', this should
3111 ;; be quick anyway (this comment comes
3112 ;; from different location):
3113 (cperl-calculate-indent))
3115 (if (eq (elt i 2) ?\{) ; char-after
3116 cperl-continued-brace-offset 0)))
3118 ;; Indenter for lines in a block which are not leading lines
3120 ((eq 'have-prev-sibling (elt i 0))
3121 ;; [have-prev-sibling sibling-beg colon-line-end block-start]
3122 (goto-char (elt i 1))
3123 (if (> (elt i 2) (point)) ; colon-line-end; After-label, same line
3124 (if (> (current-indentation)
3125 cperl-min-label-indent)
3126 (- (current-indentation) cperl-label-offset)
3127 ;; Do not believe: `max' was involved in calculation of indent
3128 (+ cperl-indent-level
3130 (goto-char (elt i 3)) ; block-start
3131 (current-indentation))))
3134 ;; Indenter for the first line in a block
3136 ((eq 'code-start-in-block (elt i 0))
3137 ;;[code-start-in-block before-brace char-after
3138 ;; is-a-HASH-ref brace-is-first-thing-on-a-line
3139 ;; group-starts-before-start-of-sub start-of-control-group]
3140 (goto-char (elt i 1))
3141 ;; For open brace in column zero, don't let statement
3142 ;; start there too. If cperl-indent-level=0,
3143 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3144 (+ (if (and (bolp) (zerop cperl-indent-level))
3145 (+ cperl-brace-offset cperl-continued-statement-offset)
3147 (if (and (elt i 3) ; is-a-HASH-ref
3148 (eq (elt i 2) ?\})) ; char-after: End of a hash reference
3149 (+ cperl-indent-level cperl-close-paren-offset)
3151 ;; Unless openbrace is the first nonwhite thing on the line,
3152 ;; add the cperl-brace-imaginary-offset.
3153 (if (elt i 4) 0 ; brace-is-first-thing-on-a-line
3154 cperl-brace-imaginary-offset)
3156 (goto-char (elt i 6)) ; start-of-control-group
3157 (if (elt i 5) ; group-starts-before-start-of-sub
3159 ;; Get initial indentation of the line we are on.
3160 ;; If line starts with label, calculate label indentation
3163 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3164 (if (> (current-indentation) cperl-min-label-indent)
3165 (- (current-indentation) cperl-label-offset)
3166 ;; Do not move `parse-data', this should
3168 (cperl-calculate-indent))
3169 (current-indentation))))))
3171 (error "Unrecognized value of indent: %s" i))))
3173 (error "Got strange value of indent: %s" i))))))
3175 (defvar cperl-indent-alist
3179 (toplevel-after-parenth 2)
3180 (toplevel-continued 2)
3182 "Alist of indentation rules for CPerl mode.
3185 number: add this amount of indentation.
3187 Not finished, not used.")
3189 (defun cperl-where-am-i (&optional parse-start start-state)
3191 "Return a list of lists ((TYPE POS)...) of good points before the point.
3192 POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'.
3194 Not finished, not used."
3196 (let* ((start-point (point)) unused
3197 (s-s (cperl-get-state))
3200 (prestart (nth 3 s-s))
3201 (containing-sexp (car (cdr state)))
3202 (case-fold-search nil)
3203 (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
3204 (cond ((nth 3 state) ; In string
3205 (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
3206 ((nth 4 state) ; In comment
3207 (setq res (cons '(comment) res)))
3208 ((null containing-sexp)
3209 ;; Line is at top level.
3210 ;; Indent like the previous top level line
3211 ;; unless that ends in a closeparen without semicolon,
3212 ;; in which case this line is the first argument decl.
3213 (cperl-backward-to-noncomment (or parse-start (point-min)))
3214 ;;(skip-chars-backward " \t\f\n")
3217 (memq (preceding-char) (append ";}" nil)))
3218 (setq res (cons (list 'toplevel start) res)))
3219 ((eq (preceding-char) ?\) )
3220 (setq res (cons (list 'toplevel-after-parenth start) res)))
3222 (setq res (cons (list 'toplevel-continued start) res)))))
3223 ((/= (char-after containing-sexp) ?{)
3224 ;; line is expression, not statement:
3225 ;; indent to just after the surrounding open.
3226 ;; skip blanks if we do not close the expression.
3227 (setq res (cons (list 'expression-blanks
3229 (goto-char (1+ containing-sexp))
3230 (or (looking-at "[ \t]*\\(#\\|$\\)")
3231 (skip-chars-forward " \t"))
3233 (cons (list 'expression containing-sexp) res))))
3235 ;; Containing-expr starts with \{. Check whether it is a hash.
3236 (goto-char containing-sexp)
3237 (not (cperl-block-p)))
3238 (setq res (cons (list 'expression-blanks
3240 (goto-char (1+ containing-sexp))
3241 (or (looking-at "[ \t]*\\(#\\|$\\)")
3242 (skip-chars-forward " \t"))
3244 (cons (list 'expression containing-sexp) res))))
3247 (setq res (cons (list 'in-block containing-sexp) res))
3248 ;; Is it a continuation or a new statement?
3249 ;; Find previous non-comment character.
3250 (cperl-backward-to-noncomment containing-sexp)
3251 ;; Back up over label lines, since they don't
3252 ;; affect whether our line is a continuation.
3253 ;; Back up comma-delimited lines too ?????
3254 (while (or (eq (preceding-char) ?\,)
3255 (save-excursion (cperl-after-label)))
3256 (if (eq (preceding-char) ?\,)
3257 ;; Will go to beginning of line, essentially
3258 ;; Will ignore embedded sexpr XXXX.
3259 (cperl-backward-to-start-of-continued-exp containing-sexp))
3261 (cperl-backward-to-noncomment containing-sexp))
3262 ;; Now we get the answer.
3263 (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
3264 ;; This line is continuation of preceding line's statement.
3265 (list (list 'statement-continued containing-sexp))
3266 ;; This line starts a new statement.
3267 ;; Position following last unclosed open.
3268 (goto-char containing-sexp)
3269 ;; Is line first statement after an open-brace?
3271 ;; If no, find that first statement and indent like
3272 ;; it. If the first statement begins with label, do
3273 ;; not believe when the indentation of the label is too
3277 (let ((colon-line-end 0))
3278 (while (progn (skip-chars-forward " \t\n" start-point)
3279 (and (< (point) start-point)
3281 "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
3282 ;; Skip over comments and labels following openbrace.
3283 (cond ((= (following-char) ?\#)
3288 (save-excursion (end-of-line)
3289 (setq colon-line-end (point)))
3290 (search-forward ":"))))
3291 ;; Now at the point, after label, or at start
3292 ;; of first statement in the block.
3293 (and (< (point) start-point)
3294 (if (> colon-line-end (point))
3295 ;; Before statement after label
3296 (if (> (current-indentation)
3297 cperl-min-label-indent)
3298 (list (list 'label-in-block (point)))
3299 ;; Do not believe: `max' is involved
3301 (list 'label-in-block-min-indent (point))))
3303 (list 'statement-in-block (point))))))
3304 ;; If no previous statement,
3305 ;; indent it relative to line brace is on.
3306 ;; For open brace in column zero, don't let statement
3307 ;; start there too. If cperl-indent-level is zero,
3308 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3309 ;; For open-braces not the first thing in a line,
3310 ;; add in cperl-brace-imaginary-offset.
3312 ;; If first thing on a line: ?????
3313 (setq unused ; This is not finished...
3314 (+ (if (and (bolp) (zerop cperl-indent-level))
3315 (+ cperl-brace-offset cperl-continued-statement-offset)
3317 ;; Move back over whitespace before the openbrace.
3318 ;; If openbrace is not first nonwhite thing on the line,
3319 ;; add the cperl-brace-imaginary-offset.
3320 (progn (skip-chars-backward " \t")
3321 (if (bolp) 0 cperl-brace-imaginary-offset))
3322 ;; If the openbrace is preceded by a parenthesized exp,
3323 ;; move to the beginning of that;
3324 ;; possibly a different line
3326 (if (eq (preceding-char) ?\))
3328 ;; Get initial indentation of the line we are on.
3329 ;; If line starts with label, calculate label indentation
3332 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3333 (if (> (current-indentation) cperl-min-label-indent)
3334 (- (current-indentation) cperl-label-offset)
3335 (cperl-calculate-indent))
3336 (current-indentation)))))))))
3339 (defun cperl-calculate-indent-within-comment ()
3340 "Return the indentation amount for line, assuming that
3341 the current line is to be regarded as part of a block comment."
3342 (let (end star-start)
3345 (skip-chars-forward " \t")
3347 (and (= (following-char) ?#)
3349 (cperl-to-comment-or-eol)
3355 (defun cperl-to-comment-or-eol ()
3356 "Go to position before comment on the current line, or to end of line.
3357 Returns true if comment is found. In POD will not move the point."
3358 ;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
3359 ;; then looks for literal # or end-of-line.
3360 (let (state stop-in cpoint (lim (progn (end-of-line) (point))) pr e)
3361 (or cperl-font-locking
3362 (cperl-update-syntaxification lim lim))
3364 (if (setq pr (get-text-property (point) 'syntax-type))
3365 (setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
3366 (if (or (eq pr 'pod)
3367 (if (or (not e) (> e lim)) ; deep inside a group
3368 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
3369 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
3370 ;; Else - need to do it the hard way
3371 (and (and e (<= e lim))
3373 (while (not stop-in)
3374 (setq state (parse-partial-sexp (point) lim nil nil nil t))
3376 ;; If fails (beginning-of-line inside sexp), then contains not-comment
3377 (if (nth 4 state) ; After `#';
3378 ; (nth 2 state) can be
3379 ; beginning of m,s,qq and so
3383 (setq cpoint (point))
3384 (goto-char (nth 2 state))
3386 ((looking-at "\\(s\\|tr\\)\\>")
3387 (or (re-search-forward
3388 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
3391 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
3392 (or (re-search-forward
3393 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
3396 (t ; It was fair comment
3397 (setq stop-in t) ; Finish
3398 (goto-char (1- cpoint)))))
3399 (setq stop-in t) ; Finish
3401 (setq stop-in t))) ; Finish
3404 (defsubst cperl-modify-syntax-type (at how)
3405 (if (< at (point-max))
3407 (put-text-property at (1+ at) 'syntax-table how)
3408 (put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
3410 (defun cperl-protect-defun-start (s e)
3411 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
3414 (while (re-search-forward "^\\s(" e 'to-end)
3415 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
3417 (defun cperl-commentify (bb e string &optional noface)
3418 (if cperl-use-syntax-table-text-property
3419 (if (eq noface 'n) ; Only immediate
3421 ;; We suppose that e is _after_ the end of construction, as after eol.
3422 (setq string (if string cperl-st-sfence cperl-st-cfence))
3424 ;; one-char string/comment?!
3425 (cperl-modify-syntax-type bb cperl-st-punct)
3426 (cperl-modify-syntax-type bb string)
3427 (cperl-modify-syntax-type (1- e) string))
3428 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
3429 (put-text-property (1+ bb) (1- e)
3430 'syntax-table cperl-string-syntax-table))
3431 (cperl-protect-defun-start bb e))
3434 (not cperl-pod-here-fontify)
3435 (put-text-property bb e 'face (if string 'font-lock-string-face
3436 'font-lock-comment-face)))))
3438 (defvar cperl-starters '(( ?\( . ?\) )
3443 (defun cperl-cached-syntax-table (st)
3444 "Get a syntax table cached in ST, or create and cache into ST a syntax table.
3445 All the entries of the syntax table are \".\", except for a backslash, which
3449 (setcar st (make-syntax-table))
3453 (modify-syntax-entry i "." st)
3455 (modify-syntax-entry ?\\ "\\" st)
3458 (defun cperl-forward-re (lim end is-2arg st-l err-l argument
3459 &optional ostart oend)
3460 "Find the end of a regular expression or a stringish construct (q[] etc).
3461 The point should be before the starting delimiter.
3463 Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
3464 is s/// or tr/// like expression. If END is nil, generates an error
3465 message if needed. If SET-ST is non-nil, will use (or generate) a
3466 cached syntax table in ST-L. If ERR-L is non-nil, will store the
3467 error message in its CAR (unless it already contains some error
3468 message). ARGUMENT should be the name of the construct (used in error
3469 messages). OSTART, OEND may be set in recursive calls when processing
3470 the second argument of 2ARG construct.
3472 Works *before* syntax recognition is done. In IS-2ARG situation may
3473 modify syntax-type text property if the situation is too hard."
3474 (let (b starter ender st i i2 go-forward reset-st set-st)
3475 (skip-chars-forward " \t")
3476 ;; ender means matching-char matcher.
3478 starter (if (eobp) 0 (char-after b))
3479 ender (cdr (assoc starter cperl-starters)))
3480 ;; What if starter == ?\\ ????
3481 (setq st (cperl-cached-syntax-table st-l))
3483 ;; Whether we have an intermediate point
3485 ;; Prepare the syntax table:
3486 (if (not ender) ; m/blah/, s/x//, s/x/y/
3487 (modify-syntax-entry starter "$" st)
3488 (modify-syntax-entry starter (concat "(" (list ender)) st)
3489 (modify-syntax-entry ender (concat ")" (list starter)) st))
3492 ;; We use `$' syntax class to find matching stuff, but $$
3493 ;; is recognized the same as $, so we need to check this manually.
3494 (if (and (eq starter (char-after (cperl-1+ b)))
3496 ;; $ has TeXish matching rules, so $$ equiv $...
3498 (setq reset-st (syntax-table))
3499 (set-syntax-table st)
3501 (if (<= (point) (1+ b))
3502 (error "Unfinished regular expression"))
3503 (set-syntax-table reset-st)
3505 ;; Now the problem is with m;blah;;
3507 (eq (preceding-char)
3508 (char-after (- (point) 2)))
3511 (= 0 (% (skip-chars-backward "\\\\") 2)))
3513 ;; Now we are after the first part.
3514 (and is-2arg ; Have trailing part
3516 (eq (following-char) starter) ; Empty trailing part
3518 (or (eq (char-syntax (following-char)) ?.)
3519 ;; Make trailing letter into punctuation
3520 (cperl-modify-syntax-type (point) cperl-st-punct))
3521 (setq is-2arg nil go-forward t))) ; Ignore the tail
3522 (if is-2arg ; Not number => have second part
3524 (setq i (point) i2 i)
3526 (if (memq (following-char) '(?\s ?\t ?\n ?\f))
3528 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3529 (goto-char (match-end 0))
3530 (skip-chars-forward " \t\n\f"))
3533 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3534 (if ender (modify-syntax-entry ender "." st))
3536 (setq ender (cperl-forward-re lim end nil st-l err-l
3537 argument starter ender)
3538 ender (nth 2 ender)))))
3539 (error (goto-char lim)
3542 (set-syntax-table reset-st))
3545 "End of `%s%s%c ... %c' string/RE not found: %s"
3547 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
3548 starter (or ender starter) bb)
3549 (or (car err-l) (setcar err-l b)))))
3552 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3553 (if ender (modify-syntax-entry ender "." st))))
3554 ;; i: have 2 args, after end of the first arg
3555 ;; i2: start of the second arg, if any (before delim iff `ender').
3556 ;; ender: the last arg bounded by parens-like chars, the second one of them
3557 ;; starter: the starting delimiter of the first arg
3558 ;; go-forward: has 2 args, and the second part is empty
3559 (list i i2 ender starter go-forward)))
3561 (defun cperl-forward-group-in-re (&optional st-l)
3562 "Find the end of a group in a REx.
3563 Return the error message (if any). Does not work if delimiter is `)'.
3564 Works before syntax recognition is done."
3565 ;; Works *before* syntax recognition is done
3566 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3567 (let (st b reset-st)
3570 (setq st (cperl-cached-syntax-table st-l))
3571 (modify-syntax-entry ?\( "()" st)
3572 (modify-syntax-entry ?\) ")(" st)
3573 (setq reset-st (syntax-table))
3574 (set-syntax-table st)
3577 "cperl-forward-group-in-re: error %s" b)))
3578 ;; now restore the initial state
3581 (modify-syntax-entry ?\( "." st)
3582 (modify-syntax-entry ?\) "." st)))
3584 (set-syntax-table reset-st))
3588 (defvar font-lock-string-face)
3589 ;;(defvar font-lock-reference-face)
3590 (defvar font-lock-constant-face)
3591 (defsubst cperl-postpone-fontification (b e type val &optional now)
3592 ;; Do after syntactic fontification?
3593 (if cperl-syntaxify-by-font-lock
3594 (or now (put-text-property b e 'cperl-postpone (cons type val)))
3595 (put-text-property b e type val)))
3597 ;;; Here is how the global structures (those which cannot be
3598 ;;; recognized locally) are marked:
3600 ;; Start-to-end is marked `in-pod' ==> t
3601 ;; Each non-literal part is marked `syntax-type' ==> `pod'
3602 ;; Each literal part is marked `syntax-type' ==> `in-pod'
3604 ;; Start-to-end is marked `here-doc-group' ==> t
3605 ;; The body is marked `syntax-type' ==> `here-doc'
3606 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
3608 ;; First line (to =) marked `first-format-line' ==> t
3609 ;; After-this--to-end is marked `syntax-type' ==> `format'
3610 ;; d) 'Q'uoted string:
3611 ;; part between markers inclusive is marked `syntax-type' ==> `string'
3612 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
3613 ;; second part of s///e is marked `syntax-type' ==> `multiline'
3614 ;; e) Attributes of subroutines: `attrib-group' ==> t
3615 ;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
3616 ;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
3618 ;;; In addition, some parts of RExes may be marked as `REx-interpolated'
3619 ;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
3621 (defun cperl-unwind-to-safe (before &optional end)
3622 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
3623 (let ((pos (point)) opos)
3624 (while (and pos (progn
3626 (get-text-property (setq pos (point)) 'syntax-type)))
3628 pos (cperl-beginning-of-property pos 'syntax-type))
3629 (if (eq pos (point-min))
3634 (goto-char (cperl-1- pos))
3637 (goto-char (setq pos (cperl-1- pos))))
3639 (goto-char (point-min))))
3641 (and (looking-at "\n*=")
3642 (/= 0 (skip-chars-backward "\n"))
3646 ;; Do the same for end, going small steps
3648 (while (and end (get-text-property end 'syntax-type))
3650 end (next-single-property-change end 'syntax-type nil (point-max)))
3651 (if end (progn (goto-char end)
3652 (or (bolp) (forward-line 1))
3653 (setq end (point)))))
3656 ;;; These are needed for byte-compile (at least with v19)
3657 (defvar cperl-nonoverridable-face)
3658 (defvar font-lock-variable-name-face)
3659 (defvar font-lock-function-name-face)
3660 (defvar font-lock-keyword-face)
3661 (defvar font-lock-builtin-face)
3662 (defvar font-lock-type-face)
3663 (defvar font-lock-comment-face)
3664 (defvar font-lock-warning-face)
3666 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
3667 "Syntaxically mark (and fontify) attributes of a subroutine.
3668 Should be called with the point before leading colon of an attribute."
3669 ;; Works *before* syntax recognition is done
3670 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3671 (let (st b p reset-st after-first (start (point)) start1 end1)
3675 "\\(" ; 1=optional? colon
3676 ":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
3678 (if after-first "?" "")
3679 ;; No space between name and paren allowed...
3680 "\\(\\sw+\\)" ; 3=name
3681 "\\((\\)?")) ; 4=optional paren
3682 (and (match-beginning 1)
3683 (cperl-postpone-fontification
3684 (match-beginning 0) (cperl-1+ (match-beginning 0))
3685 'face font-lock-constant-face))
3686 (setq start1 (match-beginning 3) end1 (match-end 3))
3687 (cperl-postpone-fontification start1 end1
3688 'face font-lock-constant-face)
3689 (goto-char end1) ; end or before `('
3690 (if (match-end 4) ; Have attribute arguments...
3693 (setq st (cperl-cached-syntax-table st-l))
3694 (modify-syntax-entry ?\( "()" st)
3695 (modify-syntax-entry ?\) ")(" st))
3696 (setq reset-st (syntax-table) p (point))
3697 (set-syntax-table st)
3699 (set-syntax-table reset-st)
3701 (cperl-commentify p (point) t))) ; mark as string
3702 (forward-comment (buffer-size))
3703 (setq after-first t))
3705 "L%d: attribute `%s': %s"
3706 (count-lines (point-min) (point))
3707 (and start1 end1 (buffer-substring start1 end1)) b)
3711 (put-text-property start (point)
3712 'attrib-group (if (looking-at "{") t 0))
3714 (< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
3715 ;; Apparently, we do not need `multiline': faces added now
3716 (put-text-property (+ 3 pos) (cperl-1+ (point))
3717 'syntax-type 'sub-decl))
3718 (and b-fname ; Fontify here: the following condition
3719 (cperl-postpone-fontification ; is too hard to determine by
3720 b-fname e-fname 'face ; a REx, so do it here
3721 (if (looking-at "{")
3722 font-lock-function-name-face
3723 font-lock-variable-name-face)))))
3724 ;; now restore the initial state
3727 (modify-syntax-entry ?\( "." st)
3728 (modify-syntax-entry ?\) "." st)))
3730 (set-syntax-table reset-st))))
3732 (defsubst cperl-look-at-leading-count (is-x-REx e)
3733 (if (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
3734 (1- e) t) ; return nil on failure, no moving
3735 (if (eq ?\{ (preceding-char)) nil
3736 (cperl-postpone-fontification
3737 (1- (point)) (point)
3738 'face font-lock-warning-face))))
3740 ;;; Debugging this may require (setq max-specpdl-size 2000)...
3741 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc)
3742 "Scans the buffer for hard-to-parse Perl constructions.
3743 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
3744 the sections using `cperl-pod-head-face', `cperl-pod-face',
3747 (or min (setq min (point-min)
3748 cperl-syntax-state nil
3749 cperl-syntax-done-to min))
3750 (or max (setq max (point-max)))
3751 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
3752 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
3753 is-REx is-x-REx REx-subgr-start REx-subgr-end was-subgr i2 hairy-RE
3754 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
3755 (modified (buffer-modified-p)) overshoot is-o-REx
3756 (after-change-functions nil)
3757 (cperl-font-locking t)
3758 (use-syntax-state (and cperl-syntax-state
3759 (>= min (car cperl-syntax-state))))
3760 (state-point (if use-syntax-state
3761 (car cperl-syntax-state)
3763 (state (if use-syntax-state
3764 (cdr cperl-syntax-state)))
3765 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
3766 (st-l (list nil)) (err-l (list nil))
3767 ;; Somehow font-lock may be not loaded yet...
3768 ;; (e.g., when building TAGS via command-line call)
3769 (font-lock-string-face (if (boundp 'font-lock-string-face)
3770 font-lock-string-face
3771 'font-lock-string-face))
3772 (my-cperl-delimiters-face (if (boundp 'font-lock-constant-face)
3773 font-lock-constant-face
3774 'font-lock-constant-face))
3775 (my-cperl-REx-spec-char-face ; [] ^.$ and wrapper-of ({})
3776 (if (boundp 'font-lock-function-name-face)
3777 font-lock-function-name-face
3778 'font-lock-function-name-face))
3779 (font-lock-variable-name-face ; interpolated vars and ({})-code
3780 (if (boundp 'font-lock-variable-name-face)
3781 font-lock-variable-name-face
3782 'font-lock-variable-name-face))
3783 (font-lock-function-name-face ; used in `cperl-find-sub-attrs'
3784 (if (boundp 'font-lock-function-name-face)
3785 font-lock-function-name-face
3786 'font-lock-function-name-face))
3787 (font-lock-constant-face ; used in `cperl-find-sub-attrs'
3788 (if (boundp 'font-lock-constant-face)
3789 font-lock-constant-face
3790 'font-lock-constant-face))
3791 (my-cperl-REx-0length-face ; 0-length, (?:)etc, non-literal \
3792 (if (boundp 'font-lock-builtin-face)
3793 font-lock-builtin-face
3794 'font-lock-builtin-face))
3795 (font-lock-comment-face
3796 (if (boundp 'font-lock-comment-face)
3797 font-lock-comment-face
3798 'font-lock-comment-face))
3799 (font-lock-warning-face
3800 (if (boundp 'font-lock-warning-face)
3801 font-lock-warning-face
3802 'font-lock-warning-face))
3803 (my-cperl-REx-ctl-face ; (|)
3804 (if (boundp 'font-lock-keyword-face)
3805 font-lock-keyword-face
3806 'font-lock-keyword-face))
3807 (my-cperl-REx-modifiers-face ; //gims
3808 (if (boundp 'cperl-nonoverridable-face)
3809 cperl-nonoverridable-face
3810 'cperl-nonoverridable-face))
3811 (my-cperl-REx-length1-face ; length=1 escaped chars, POSIX classes
3812 (if (boundp 'font-lock-type-face)
3814 'font-lock-type-face))
3815 (stop-point (if ignore-max
3820 "\\(\\`\n?\\|^\n\\)=" ; POD
3822 ;; One extra () before this:
3825 ;; First variant "BLAH" or just ``.
3826 "[ \t]*" ; Yes, whitespace is allowed!
3827 "\\([\"'`]\\)" ; 2 + 1 = 3
3828 "\\([^\"'`\n]*\\)" ; 3 + 1
3831 ;; Second variant: Identifier or \ID (same as 'ID') or empty
3832 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3833 ;; Do not have <<= or << 30 or <<30 or << $blah.
3834 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3835 "\\(\\)" ; To preserve count of pars :-( 6 + 1
3838 ;; 1+6 extra () before this:
3839 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" ;FRMAT
3840 (if cperl-use-syntax-table-text-property
3843 ;; 1+6+2=9 extra () before this:
3844 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT
3846 ;; 1+6+2+1=10 extra () before this:
3847 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3849 ;; 1+6+2+1+1=11 extra () before this
3850 "\\<sub\\>" ; sub with proto/attr
3852 cperl-white-and-comment-rex
3853 "\\(::[a-zA-Z_:'0-9]*\\|[a-zA-Z_'][a-zA-Z_:'0-9]*\\)\\)?" ; name
3855 cperl-maybe-white-and-comment-rex
3856 "\\(([^()]*)\\|:[^:]\\)\\)" ; prototype or attribute start
3858 ;; 1+6+2+1+1+6=17 extra () before this:
3859 "\\$\\(['{]\\)" ; $' or ${foo}
3861 ;; 1+6+2+1+1+6+1=18 extra () before this (old pack'var syntax;
3862 ;; we do not support intervening comments...):
3863 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
3864 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
3866 "__\\(END\\|DATA\\)__" ; __END__ or __DATA__
3867 ;; 1+6+2+1+1+6+1+1+1=20 extra () before this:
3869 "\\\\\\(['`\"($]\\)") ; BACKWACKED something-hairy
3875 (message "Scanning for \"hard\" Perl constructions..."))
3876 ;;(message "find: %s --> %s" min max)
3877 (and cperl-pod-here-fontify
3878 ;; We had evals here, do not know why...
3879 (setq face cperl-pod-face
3880 head-face cperl-pod-head-face
3881 here-face cperl-here-face))
3882 (remove-text-properties min max
3883 '(syntax-type t in-pod t syntax-table t
3894 ;; Need to remove face as well...
3896 (and (eq system-type 'emx)
3898 (let ((case-fold-search t))
3899 (looking-at "extproc[ \t]")) ; Analogue of #!
3900 (cperl-commentify min
3901 (save-excursion (end-of-line) (point))
3905 (re-search-forward search max t))
3906 (setq tmpend nil) ; Valid for most cases
3907 (setq b (match-beginning 0)
3908 state (save-excursion (parse-partial-sexp
3909 state-point b nil nil state))
3912 ;; 1+6+2+1+1+6=17 extra () before this:
3914 ((match-beginning 18) ; $' or ${foo}
3915 (if (eq (preceding-char) ?\') ; $'
3917 (setq b (1- (point))
3918 state (parse-partial-sexp
3919 state-point (1- b) nil nil state)
3921 (if (nth 3 state) ; in string
3922 (cperl-modify-syntax-type (1- b) cperl-st-punct))
3925 (setq bb (match-beginning 0))
3926 (cperl-modify-syntax-type bb cperl-st-punct)))
3927 ;; No processing in strings/comments beyond this point:
3928 ((or (nth 3 state) (nth 4 state))
3929 t) ; Do nothing in comment/string
3930 ((match-beginning 1) ; POD section
3931 ;; "\\(\\`\n?\\|^\n\\)="
3932 (setq b (match-beginning 0)
3933 state (parse-partial-sexp
3934 state-point b nil nil state)
3936 (if (or (nth 3 state) (nth 4 state)
3937 (looking-at "cut\\>"))
3938 (if (or (nth 3 state) (nth 4 state) ignore-max)
3939 nil ; Doing a chunk only
3940 (message "=cut is not preceded by a POD section")
3941 (or (car err-l) (setcar err-l (point))))
3946 tb (match-beginning 0)
3947 b1 nil) ; error condition
3948 ;; We do not search to max, since we may be called from
3949 ;; some hook of fontification, and max is random
3950 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
3953 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
3955 (message "=cut is not preceded by an empty line")
3957 (or (car err-l) (setcar err-l b))))))
3958 (beginning-of-line 2) ; An empty line after =cut is not POD!
3962 (remove-text-properties
3963 max e '(syntax-type t in-pod t syntax-table t
3975 (put-text-property b e 'in-pod t)
3976 (put-text-property b e 'syntax-type 'in-pod)
3978 (while (re-search-forward "\n\n[ \t]" e t)
3979 ;; We start 'pod 1 char earlier to include the preceding line
3981 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
3982 (cperl-put-do-not-fontify b (point) t)
3983 ;; mark the non-literal parts as PODs
3984 (if cperl-pod-here-fontify
3985 (cperl-postpone-fontification b (point) 'face face t))
3986 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
3989 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
3990 (cperl-put-do-not-fontify (point) e t)
3991 (if cperl-pod-here-fontify
3993 ;; mark the non-literal parts as PODs
3994 (cperl-postpone-fontification (point) e 'face face t)
3997 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
3999 (cperl-postpone-fontification
4000 (match-beginning 1) (match-end 1)
4002 (while (re-search-forward
4004 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
4007 (cperl-postpone-fontification
4008 (match-beginning 1) (match-end 1)
4010 (cperl-commentify bb e nil)
4012 (or (eq e (point-max))
4013 (forward-char -1)))) ; Prepare for immediate POD start.
4015 ;; We can do many here-per-line;
4016 ;; but multiline quote on the same line as <<HERE confuses us...
4017 ;; ;; One extra () before this:
4020 ;; ;; First variant "BLAH" or just ``.
4021 ;; "[ \t]*" ; Yes, whitespace is allowed!
4022 ;; "\\([\"'`]\\)" ; 2 + 1
4023 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
4026 ;; ;; Second variant: Identifier or \ID or empty
4027 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
4028 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
4029 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
4030 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
4032 ((match-beginning 2) ; 1 + 1
4034 tb (match-beginning 0)
4035 c (and ; not HERE-DOC
4038 (or (looking-at "[ \t]*(") ; << function_call()
4039 (save-excursion ; 1 << func_name, or $foo << 10
4043 ;;; XXX What to do: foo <<bar ???
4044 ;;; XXX Need to support print {a} <<B ???
4047 ; $foo << b; $f .= <<B;
4048 ; ($f+1) << b; a($f) . <<B;
4049 ; foo 1, <<B; $x{a} <<b;
4051 ((looking-at "[0-9$({]")
4054 (looking-at "[ \t]*<<")
4060 (looking-at "\\(printf?\\|system\\|exec\\|sort\\)\\>")))
4062 (error nil))) ; func(<<EOF)
4063 (and (not (match-beginning 6)) ; Empty
4065 "[ \t]*[=0-9$@%&(]"))))))
4066 (if c ; Not here-doc
4068 (setq c (match-end 2)) ; 1 + 1
4069 (if (match-beginning 5) ;4 + 1
4070 (setq b1 (match-beginning 5) ; 4 + 1
4071 e1 (match-end 5)) ; 4 + 1
4072 (setq b1 (match-beginning 4) ; 3 + 1
4073 e1 (match-end 4))) ; 3 + 1
4074 (setq tag (buffer-substring b1 e1)
4075 qtag (regexp-quote tag))
4076 (cond (cperl-pod-here-fontify
4077 ;; Highlight the starting delimiter
4078 (cperl-postpone-fontification
4079 b1 e1 'face my-cperl-delimiters-face)
4080 (cperl-put-do-not-fontify b1 e1 t)))
4084 (goto-char end-of-here-doc))
4086 ;; We do not search to max, since we may be called from
4087 ;; some hook of fontification, and max is random
4088 (or (and (re-search-forward (concat "^" qtag "$")
4090 ;;;(eq (following-char) ?\n) ; XXXX WHY???
4092 (progn ; Pretend we matched at the end
4093 (goto-char (point-max))
4094 (re-search-forward "\\'")
4095 (message "End of here-document `%s' not found." tag)
4096 (or (car err-l) (setcar err-l b))))
4097 (if cperl-pod-here-fontify
4099 ;; Highlight the ending delimiter
4100 (cperl-postpone-fontification
4101 (match-beginning 0) (match-end 0)
4102 'face my-cperl-delimiters-face)
4103 (cperl-put-do-not-fontify b (match-end 0) t)
4104 ;; Highlight the HERE-DOC
4105 (cperl-postpone-fontification b (match-beginning 0)
4107 (setq e1 (cperl-1+ (match-end 0)))
4108 (put-text-property b (match-beginning 0)
4109 'syntax-type 'here-doc)
4110 (put-text-property (match-beginning 0) e1
4111 'syntax-type 'here-doc-delim)
4112 (put-text-property b e1 'here-doc-group t)
4113 ;; This makes insertion at the start of HERE-DOC update
4114 ;; the whole construct:
4115 (put-text-property b (cperl-1+ b) 'front-sticky '(syntax-type))
4116 (cperl-commentify b e1 nil)
4117 (cperl-put-do-not-fontify b (match-end 0) t)
4118 ;; Cache the syntax info...
4119 (setq cperl-syntax-state (cons state-point state))
4120 ;; ... and process the rest of the line...
4122 (elt ; non-inter ignore-max
4123 (cperl-find-pods-heres c i t end t e1) 1))
4124 (if (and overshoot (> overshoot (point)))
4125 (goto-char overshoot)
4126 (setq overshoot e1))
4130 ((match-beginning 8)
4131 ;; 1+6=7 extra () before this:
4132 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
4134 name (if (match-beginning 8) ; 7 + 1
4135 (buffer-substring (match-beginning 8) ; 7 + 1
4136 (match-end 8)) ; 7 + 1
4138 tb (match-beginning 0))
4140 (put-text-property (save-excursion
4143 b 'first-format-line 't)
4144 (if cperl-pod-here-fontify
4145 (while (and (eq (forward-line) 0)
4146 (not (looking-at "^[.;]$")))
4148 ((looking-at "^#")) ; Skip comments
4149 ((and argument ; Skip argument multi-lines
4150 (looking-at "^[ \t]*{"))
4152 (setq argument nil))
4153 (argument ; Skip argument lines
4154 (setq argument nil))
4157 (setq argument (looking-at "^[^\n]*[@^]"))
4159 ;; Highlight the format line
4160 (cperl-postpone-fontification b1 (point)
4161 'face font-lock-string-face)
4162 (cperl-commentify b1 (point) nil)
4163 (cperl-put-do-not-fontify b1 (point) t))))
4164 ;; We do not search to max, since we may be called from
4165 ;; some hook of fontification, and max is random
4166 (re-search-forward "^[.;]$" stop-point 'toend))
4168 (if (looking-at "^\\.$") ; ";" is not supported yet
4170 ;; Highlight the ending delimiter
4171 (cperl-postpone-fontification (point) (+ (point) 2)
4172 'face font-lock-string-face)
4173 (cperl-commentify (point) (+ (point) 2) nil)
4174 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
4175 (message "End of format `%s' not found." name)
4176 (or (car err-l) (setcar err-l b)))
4180 (put-text-property b (point) 'syntax-type 'format))
4181 ;; qq-like String or Regexp:
4182 ((or (match-beginning 10) (match-beginning 11))
4183 ;; 1+6+2=9 extra () before this:
4184 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
4186 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
4187 (setq b1 (if (match-beginning 10) 10 11)
4188 argument (buffer-substring
4189 (match-beginning b1) (match-end b1))
4190 b (point) ; end of qq etc
4192 c (char-after (match-beginning b1))
4193 bb (char-after (1- (match-beginning b1))) ; tmp holder
4194 ;; bb == "Not a stringy"
4195 bb (if (eq b1 10) ; user variables/whatever
4196 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
4197 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
4198 ((eq bb ?\:) ; $opt::s
4200 (- (match-beginning b1) 2))
4202 ((eq bb ?\>) ; $foo->s
4204 (- (match-beginning b1) 2))
4207 (not (eq (char-after ; &&m/blah/
4208 (- (match-beginning b1) 2))
4211 ;; <file> or <$file>
4213 ;; Do not stringify <FH>, <$fh> :
4216 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
4217 tb (match-beginning 0))
4218 (goto-char (match-beginning b1))
4219 (cperl-backward-to-noncomment (point-min))
4221 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
4226 ;; What is below: regexp-p?
4228 (or (memq (preceding-char)
4229 (append (if (memq c '(?\? ?\<))
4232 "~{(=|&+-*!,;:[") nil))
4233 (and (eq (preceding-char) ?\})
4234 (cperl-after-block-p (point-min)))
4235 (and (eq (char-syntax (preceding-char)) ?w)
4238 ;; After these keywords `/' starts a RE. One should add all the
4239 ;; functions/builtins which expect an argument, but ...
4240 (if (eq (preceding-char) ?-)
4242 (looking-at "[a-zA-Z]\\>")
4244 (not (memq (preceding-char)
4247 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
4248 (and (eq (preceding-char) ?.)
4249 (eq (char-after (- (point) 2)) ?.))
4251 ;; m|blah| ? foo : bar;
4254 cperl-use-syntax-table-text-property
4258 (looking-at "\\s|"))))))
4261 ;; Check for $a -> y
4262 (setq b1 (preceding-char)
4265 (eq (char-after (- go 2)) ?-))
4271 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4272 (goto-char (match-end 0))
4273 (skip-chars-forward " \t\n\f"))
4274 (cond ((and (eq (following-char) ?\})
4276 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
4278 (skip-chars-backward " \t\n\f")
4279 (if (memq (preceding-char) (append "$@%&*" nil))
4285 (looking-at ; $foo -> {s}
4286 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
4287 (and ; $foo[12] -> {s}
4288 (memq (following-char) '(?\{ ?\[))
4291 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
4294 ((and (eq (following-char) ?=)
4295 (eq (char-after (1+ (point))) ?\>))
4296 ;; Check for { foo => 1, s => 2 }
4297 ;; Apparently s=> is never a substitution...
4299 ((and (eq (following-char) ?:)
4300 (eq b1 ?\{) ; Check for $ { s::bar }
4301 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
4304 (skip-chars-backward " \t\n\f")
4305 (memq (preceding-char)
4306 (append "$@%&*" nil))))
4312 ;; Skip whitespace and comments...
4313 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4314 (goto-char (match-end 0))
4315 (skip-chars-forward " \t\n\f"))
4317 (put-text-property b (point) 'syntax-type 'prestring))
4318 ;; qtag means two-arg matcher, may be reset to
4319 ;; 2 or 3 later if some special quoting is needed.
4320 ;; e1 means matching-char matcher.
4321 (setq b (point) ; before the first delimiter
4323 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
4324 ;; We do not search to max, since we may be called from
4325 ;; some hook of fontification, and max is random
4326 i (cperl-forward-re stop-point end
4328 st-l err-l argument)
4329 ;; If `go', then it is considered as 1-arg, `b1' is nil
4330 ;; as in s/foo//x; the point is before final "slash"
4331 b1 (nth 1 i) ; start of the second part
4332 tag (nth 2 i) ; ender-char, true if second part
4333 ; is with matching chars []
4334 go (nth 4 i) ; There is a 1-char part after the end
4335 i (car i) ; intermediate point
4337 ;; Before end of the second part if non-matching: ///
4338 tail (if (and i (not tag))
4340 e (if i i e1) ; end of the first part
4341 qtag nil ; need to preserve backslashitis
4342 is-x-REx nil is-o-REx nil); REx has //x //o modifiers
4343 ;; If s{} (), then b/b1 are at "{", "(", e1/i after ")", "}"
4344 ;; Commenting \\ is dangerous, what about ( ?
4346 (eq (char-after i) ?\\)
4348 (and (if go (looking-at ".\\sw*x")
4349 (looking-at "\\sw*x")) ; qr//x
4351 (and (if go (looking-at ".\\sw*o")
4352 (looking-at "\\sw*o")) ; //o
4355 ;; Considered as 1arg form
4357 (cperl-commentify b (point) t)
4358 (put-text-property b (point) 'syntax-type 'string)
4360 ;; ignore other text properties:
4361 (string-match "^qw$" argument))
4362 (put-text-property b (point) 'indentable t))
4364 (setq e1 (cperl-1+ e1))
4367 (cperl-commentify b i t)
4368 (if (looking-at "\\sw*e") ; s///e
4370 ;; Cache the syntax info...
4371 (setq cperl-syntax-state (cons state-point state))
4374 (car (cperl-find-pods-heres b1 (1- (point)) t end))
4376 (goto-char (1+ max)))
4377 (if (and tag (eq (preceding-char) ?\>))
4379 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
4380 (cperl-modify-syntax-type i cperl-st-bra)))
4381 (put-text-property b i 'syntax-type 'string)
4382 (put-text-property i (point) 'syntax-type 'multiline)
4384 (put-text-property b i 'indentable t)))
4385 (cperl-commentify b1 (point) t)
4386 (put-text-property b (point) 'syntax-type 'string)
4388 (put-text-property b i 'indentable t))
4390 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
4392 ;; Now: tail: if the second part is non-matching without ///e
4393 (if (eq (char-syntax (following-char)) ?w)
4395 (forward-word 1) ; skip modifiers s///s
4396 (if tail (cperl-commentify tail (point) t))
4397 (cperl-postpone-fontification
4398 e1 (point) 'face my-cperl-REx-modifiers-face)))
4399 ;; Check whether it is m// which means "previous match"
4400 ;; and highlight differently
4402 (and (string-match "^\\([sm]?\\|qr\\)$" argument)
4403 (or (not (= (length argument) 0))
4407 ;; split // *is* using zero-pattern
4413 (not (looking-at "split\\>")))
4415 (cperl-postpone-fontification
4416 b e 'face font-lock-warning-face)
4417 (if (or i2 ; Has 2 args
4418 (and cperl-fontify-m-as-s
4420 (string-match "^\\(m\\|qr\\)$" argument)
4421 (and (eq 0 (length argument))
4422 (not (eq ?\< (char-after b)))))))
4424 (cperl-postpone-fontification
4425 b (cperl-1+ b) 'face my-cperl-delimiters-face)
4426 (cperl-postpone-fontification
4427 (1- e) e 'face my-cperl-delimiters-face)))
4428 (if (and is-REx cperl-regexp-scan)
4429 ;; Process RExen: embedded comments, charclasses and ]
4430 ;;;/\3333\xFg\x{FFF}a\ppp\PPP\qqq\C\99f(?{ foo })(??{ foo })/;
4431 ;;;/a\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
4432 ;;;/(?<=foo)(?<!bar)(x)(?:$ab|\$\/)$|\\\b\x888\776\[\:$/xxx;
4433 ;;;m?(\?\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
4434 ;;;m$(^ab[c]\$)$ + m+(^ab[c]\$\+)+ + m](^ab[c\]$|.+)] + m)(^ab[c]$|.+\));
4435 ;;;m^a[\^b]c^ + m.a[^b]\.c.;
4439 (cperl-look-at-leading-count is-x-REx e)
4443 (if (eq (char-after b) ?\#)
4444 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
4445 "\\((\\?#\\)\\|\\(#\\)")
4446 ;; keep the same count: add a fake group
4447 (if (eq (char-after b) ?\#)
4448 "\\((\\?\\\\#\\)\\(\\)"
4449 "\\((\\?#\\)\\(\\)"))
4455 ;; XXXX Will not be able to use it in s)))
4456 (if (eq (char-after b) ?\) )
4457 "\\())))\\)" ; Will never match
4458 (if (eq (char-after b) ?? )
4459 ;;"\\((\\\\\\?\\(\\\\\\?\\)?{\\)"
4460 "\\((\\\\\\?\\\\\\?{\\|()\\\\\\?{\\)"
4461 "\\((\\?\\??{\\)")) ; 5= (??{ (?{
4462 "\\|" ; 6= 0-length, 7: name, 8,9:code, 10:group
4463 "\\(" ;; XXXX 1-char variables, exc. |()\s
4466 "[_a-zA-Z:][_a-zA-Z0-9:]*"
4468 "{[^{}]*}" ; only one-level allowed
4472 "\\(" ;;8,9:code part of array/hash elt
4478 ;; XXXX: what if u is delim?
4486 "\\\\[luLUEQbBAzZG]"
4489 "\\(" ; 10 group opener follower
4490 "\\?\\((\\?\\)" ; 11: in (?(?=C)A|B)
4492 "\\?[:=!>?{]" ; "?" something
4494 "\\?[-imsx]+[:)]" ; (?i) (?-s:.)
4496 "\\?([0-9]+)" ; (?(1)foo|bar)
4504 "\\\\\\(.\\)" ; 12=\SYMBOL
4507 (and (< (point) (1- e))
4508 (re-search-forward hairy-RE (1- e) 'to-end))
4509 (goto-char (match-beginning 0))
4510 (setq REx-subgr-start (point)
4511 was-subgr (following-char))
4513 ((match-beginning 6) ; 0-length builtins, groups
4514 (goto-char (match-end 0))
4515 (if (match-beginning 11)
4516 (goto-char (match-beginning 11)))
4519 (cperl-postpone-fontification
4520 (match-beginning 0) (point)
4523 ((eq was-subgr ?\) )
4528 (if (if (eq (char-after b) ?? )
4529 (looking-at "(\\\\\\?")
4530 (eq (char-after (1+ (point))) ?\?))
4531 my-cperl-REx-0length-face
4532 my-cperl-REx-ctl-face)
4533 font-lock-warning-face))
4534 (error font-lock-warning-face)))
4535 ((eq was-subgr ?\| )
4536 my-cperl-REx-ctl-face)
4537 ((eq was-subgr ?\$ )
4538 (if (> (point) (1+ REx-subgr-start))
4541 (match-beginning 0) (point)
4544 (if (and (eq (match-beginning 0)
4548 font-lock-variable-name-face)
4549 my-cperl-REx-spec-char-face))
4550 ((memq was-subgr (append "^." nil) )
4551 my-cperl-REx-spec-char-face)
4552 ((eq was-subgr ?\( )
4553 (if (not (match-beginning 10))
4554 my-cperl-REx-ctl-face
4555 my-cperl-REx-0length-face))
4556 (t my-cperl-REx-0length-face)))
4557 (if (and (memq was-subgr (append "(|" nil))
4558 (not (string-match "(\\?[-imsx]+)"
4560 (cperl-look-at-leading-count is-x-REx e))
4561 (setq was-subgr nil)) ; We do stuff here
4562 ((match-beginning 12) ; \SYMBOL
4566 ;; How many chars to not highlight:
4567 ;; 0-len special-alnums in other branch =>
4568 ;; Generic: \non-alnum (1), \alnum (1+face)
4569 ;; Is-delim: \non-alnum (1/spec-2) alnum-1 (=what hai)
4570 (setq REx-subgr-start (point)
4571 qtag (preceding-char))
4572 (cperl-postpone-fontification
4573 (- (point) 2) (- (point) 1) 'face
4575 (append "ghijkmoqvFHIJKMORTVY" nil))
4576 font-lock-warning-face
4577 my-cperl-REx-0length-face))
4578 (if (and (eq (char-after b) qtag)
4579 (memq qtag (append ".])^$|*?+" nil)))
4581 (if (and cperl-use-syntax-table-text-property
4584 REx-subgr-start (1- (point))
4585 'syntax-table cperl-st-punct))
4586 (cperl-postpone-fontification
4587 (1- (point)) (point) 'face
4588 ; \] can't appear below
4589 (if (memq qtag (append ".]^$" nil))
4590 'my-cperl-REx-spec-char-face
4591 (if (memq qtag (append "*?+" nil))
4592 'my-cperl-REx-0length-face
4593 'my-cperl-REx-ctl-face))))) ; )|
4594 ;; Test for arguments:
4596 ;; This is not pretty: the 5.8.7 logic:
4597 ;; \0numx -> octal (up to total 3 dig)
4598 ;; \DIGIT -> backref unless \0
4599 ;; \DIGITs -> backref if legal
4600 ;; otherwise up to 3 -> octal
4601 ;; Do not try to distinguish, we guess
4602 ((or (and (memq qtag (append "01234567" nil))
4604 "\\=[01234567]?[01234567]?"
4606 (and (memq qtag (append "89" nil))
4608 "\\=[0123456789]*" (1- e) 'to-end))
4611 "\\=[0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}"
4613 (and (memq qtag (append "pPN" nil))
4614 (re-search-forward "\\={[^{}]+}\\|."
4616 (eq (char-syntax qtag) ?w))
4617 (cperl-postpone-fontification
4618 (1- REx-subgr-start) (point)
4619 'face my-cperl-REx-length1-face))))
4620 (setq was-subgr nil)) ; We do stuff here
4621 ((match-beginning 3) ; [charclass]
4623 (if (eq (char-after b) ?^ )
4624 (and (eq (following-char) ?\\ )
4625 (eq (char-after (cperl-1+ (point)))
4628 (and (eq (following-char) ?^ )
4630 (setq argument b ; continue?
4631 tag nil ; list of POSIX classes
4633 (if (eq (char-after b) ?\] )
4634 (and (eq (following-char) ?\\ )
4635 (eq (char-after (cperl-1+ (point)))
4637 (setq qtag (1+ qtag))
4639 (and (eq (following-char) ?\] )
4641 ;; Apparently, I can't put \] into a charclass
4642 ;; in m]]: m][\\\]\]] produces [\\]]
4643 ;;; POSIX? [:word:] [:^word:] only inside []
4644 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]")
4648 (if (eq (char-after b) ?\] )
4649 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]"
4650 "\\=\\(\\\\.\\|[^]\\\\]\\)*]")
4652 ;; Is this ] an end of POSIX class?
4655 (search-backward "[" argument t)
4656 (< REx-subgr-start (point))
4658 (and ; Should work with delim = \
4659 (eq (preceding-char) ?\\ )
4660 (= (% (skip-chars-backward
4664 ((eq (char-after b) ?\] )
4665 "\\\\*\\[:\\^?\\sw+:\\\\\\]")
4666 ((eq (char-after b) ?\: )
4667 "\\\\*\\[\\\\:\\^?\\sw+\\\\:]")
4668 ((eq (char-after b) ?^ )
4669 "\\\\*\\[:\\(\\\\\\^\\)?\\sw+:\]")
4670 ((eq (char-syntax (char-after b))
4673 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\"
4674 (char-to-string (char-after b))
4676 (t "\\\\*\\[:\\^?\\sw*:]")))
4677 (setq argument (point))))
4678 (setq tag (cons (cons argument (point))
4680 argument (point)) ; continue
4681 (setq argument nil)))
4683 (message "Couldn't find end of charclass in a REx, pos=%s"
4685 (if (and cperl-use-syntax-table-text-property
4686 (> (- (point) 2) REx-subgr-start))
4688 (1+ REx-subgr-start) (1- (point))
4689 'syntax-table cperl-st-punct))
4690 (cperl-postpone-fontification
4691 REx-subgr-start qtag
4692 'face my-cperl-REx-spec-char-face)
4693 (cperl-postpone-fontification
4694 (1- (point)) (point) 'face
4695 my-cperl-REx-spec-char-face)
4696 (if (eq (char-after b) ?\] )
4697 (cperl-postpone-fontification
4698 (- (point) 2) (1- (point))
4699 'face my-cperl-REx-0length-face))
4701 (cperl-postpone-fontification
4702 (car (car tag)) (cdr (car tag))
4703 'face my-cperl-REx-length1-face)
4704 (setq tag (cdr tag)))
4705 (setq was-subgr nil)) ; did facing already
4707 ((and (match-beginning 2) ; #-comment
4708 (/= (match-beginning 2) (match-end 2)))
4709 (beginning-of-line 2)
4711 (goto-char (1- e))))
4712 ((match-beginning 4) ; character "]"
4713 (setq was-subgr nil) ; We do stuff here
4714 (goto-char (match-end 0))
4715 (if cperl-use-syntax-table-text-property
4717 (1- (point)) (point)
4718 'syntax-table cperl-st-punct))
4719 (cperl-postpone-fontification
4720 (1- (point)) (point)
4721 'face font-lock-warning-face))
4722 ((match-beginning 5) ; before (?{}) (??{})
4723 (setq tag (match-end 0))
4725 (cperl-forward-group-in-re st-l))
4727 (setq qtag "no matching `)' found"))
4728 (and (not (eq (char-after (- (point) 2))
4730 (setq qtag "Can't find })")))
4734 (cperl-postpone-fontification
4735 (1- tag) (1- (point))
4736 'face font-lock-variable-name-face)
4737 (cperl-postpone-fontification
4738 REx-subgr-start (1- tag)
4739 'face my-cperl-REx-spec-char-face)
4740 (cperl-postpone-fontification
4741 (1- (point)) (point)
4742 'face my-cperl-REx-spec-char-face)
4743 (if cperl-use-syntax-table-text-property
4746 (- (point) 2) (1- (point))
4747 'syntax-table cperl-st-cfence)
4749 (+ REx-subgr-start 2)
4750 (+ REx-subgr-start 3)
4751 'syntax-table cperl-st-cfence))))
4752 (setq was-subgr nil))
4754 ;; Inside "(" and "\" arn't special in any way
4755 ;; Works also if the outside delimiters are ().
4756 (or;;(if (eq (char-after b) ?\) )
4757 ;;(re-search-forward
4758 ;; "[^\\\\]\\(\\\\\\\\\\)*\\\\)"
4760 (search-forward ")" (1- e) 'toend)
4763 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
4769 (setq REx-subgr-end (point))
4771 REx-subgr-start REx-subgr-end nil)
4772 (cperl-postpone-fontification
4773 REx-subgr-start REx-subgr-end
4774 'face font-lock-comment-face))))))
4775 (if (and is-REx is-x-REx)
4776 (put-text-property (1+ b) (1- e)
4777 'syntax-subtype 'x-REx)))
4780 (cperl-postpone-fontification
4781 (1- e1) e1 'face my-cperl-delimiters-face)
4782 (if (assoc (char-after b) cperl-starters)
4784 (cperl-postpone-fontification
4785 b1 (1+ b1) 'face my-cperl-delimiters-face)
4786 (put-text-property b1 (1+ b1)
4790 ((match-beginning 17) ; sub with prototype or attribute
4791 ;; 1+6+2+1+1=11 extra () before this (sub with proto/attr):
4792 ;;"\\<sub\\>\\(" ;12
4793 ;; cperl-white-and-comment-rex ;13
4794 ;; "\\([a-zA-Z_:'0-9]+\\)\\)?" ; name ;14
4795 ;;"\\(" cperl-maybe-white-and-comment-rex ;15,16
4796 ;; "\\(([^()]*)\\|:[^:]\\)\\)" ; 17:proto or attribute start
4797 (setq b1 (match-beginning 14) e1 (match-end 14))
4798 (if (memq (char-after (1- b))
4799 '(?\$ ?\@ ?\% ?\& ?\*))
4802 (if (eq (char-after (match-beginning 17)) ?\( )
4804 (cperl-commentify ; Prototypes; mark as string
4805 (match-beginning 17) (match-end 17) t)
4806 (goto-char (match-end 0))
4807 ;; Now look for attributes after prototype:
4808 (forward-comment (buffer-size))
4809 (and (looking-at ":[^:]")
4810 (cperl-find-sub-attrs st-l b1 e1 b)))
4811 ;; treat attributes without prototype
4812 (goto-char (match-beginning 17))
4813 (cperl-find-sub-attrs st-l b1 e1 b))))
4814 ;; 1+6+2+1+1+6+1=18 extra () before this:
4815 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
4816 ((match-beginning 19) ; old $abc'efg syntax
4817 (setq bb (match-end 0))
4818 ;;;(if (nth 3 state) nil ; in string
4819 (put-text-property (1- bb) bb 'syntax-table cperl-st-word)
4821 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
4822 ;; "__\\(END\\|DATA\\)__"
4823 ((match-beginning 20) ; __END__, __DATA__
4824 (setq bb (match-end 0))
4825 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
4826 (cperl-commentify b bb nil)
4828 ;; "\\\\\\(['`\"($]\\)"
4829 ((match-beginning 21)
4830 ;; Trailing backslash; make non-quoting outside string/comment
4831 (setq bb (match-end 0))
4833 (skip-chars-backward "\\\\")
4834 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
4835 (cperl-modify-syntax-type b cperl-st-punct)
4837 (t (error "Error in regexp of the sniffer")))
4838 (if (> (point) stop-point)
4841 (message "Garbage after __END__/__DATA__ ignored")
4842 (message "Unbalanced syntax found while scanning")
4843 (or (car err-l) (setcar err-l b)))
4844 (goto-char stop-point))))
4845 (setq cperl-syntax-state (cons state-point state)
4846 ;; Do not mark syntax as done past tmpend???
4847 cperl-syntax-done-to (or tmpend (max (point) max)))
4848 ;;(message "state-at=%s, done-to=%s" state-point cperl-syntax-done-to)
4850 (if (car err-l) (goto-char (car err-l))
4852 (message "Scanning for \"hard\" Perl constructions... done"))))
4853 (and (buffer-modified-p)
4855 (set-buffer-modified-p nil))
4856 ;; I do not understand what this is doing here. It breaks font-locking
4857 ;; because it resets the syntax-table from font-lock-syntax-table to
4858 ;; cperl-mode-syntax-table.
4859 ;; (set-syntax-table cperl-mode-syntax-table)
4861 (list (car err-l) overshoot)))
4863 (defun cperl-find-pods-heres-region (min max)
4865 (cperl-find-pods-heres min max))
4867 (defun cperl-backward-to-noncomment (lim)
4868 ;; Stops at lim or after non-whitespace that is not in comment
4869 ;; XXXX Wrongly understands end-of-multiline strings with # as comment
4871 (while (and (not stop) (> (point) (or lim (point-min))))
4872 (skip-chars-backward " \t\n\f" lim)
4875 (if (memq (setq pr (get-text-property (point) 'syntax-type))
4876 '(pod here-doc here-doc-delim))
4877 (cperl-unwind-to-safe nil)
4878 (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
4879 (not (memq pr '(string prestring))))
4880 (progn (cperl-to-comment-or-eol) (bolp))
4882 (skip-chars-backward " \t")
4883 (if (< p (point)) (goto-char p))
4886 ;; Used only in `cperl-calculate-indent'...
4887 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
4888 ;; Positions is before ?\{. Checks whether it starts a block.
4889 ;; No save-excursion! This is more a distinguisher of a block/hash ref...
4890 (cperl-backward-to-noncomment (point-min))
4891 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
4892 ; Label may be mixed up with `$blah :'
4893 (save-excursion (cperl-after-label))
4894 (get-text-property (cperl-1- (point)) 'attrib-group)
4895 (and (memq (char-syntax (preceding-char)) '(?w ?_))
4898 ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
4899 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
4900 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
4901 ;; sub bless::foo {}
4903 (cperl-backward-to-noncomment (point-min))
4904 (and (eq (preceding-char) ?b)
4907 (looking-at "sub[ \t\n\f#]")))))))))
4909 ;;; What is the difference of (cperl-after-block-p lim t) and (cperl-block-p)?
4910 ;;; No save-excursion; condition-case ... In (cperl-block-p) the block
4911 ;;; may be a part of an in-statement construct, such as
4912 ;;; ${something()}, print {FH} $data.
4913 ;;; Moreover, one takes positive approach (looks for else,grep etc)
4914 ;;; another negative (looks for bless,tr etc)
4915 (defun cperl-after-block-p (lim &optional pre-block)
4916 "Return true if the preceeding } (if PRE-BLOCK, following {) delimits a block.
4917 Would not look before LIM. Assumes that LIM is a good place to begin a
4918 statement. The kind of block we treat here is one after which a new
4919 statement would start; thus the block in ${func()} does not count."
4923 (or pre-block (forward-sexp -1))
4924 (cperl-backward-to-noncomment lim)
4925 (or (eq (point) lim)
4926 ;; if () {} // sub f () {} // sub f :a(') {}
4927 (eq (preceding-char) ?\) )
4929 (save-excursion (cperl-after-label))
4931 (get-text-property (cperl-1- (point)) 'attrib-group)
4932 (if (memq (char-syntax (preceding-char)) '(?w ?_)) ; else {}
4935 ;; else {} but not else::func {}
4936 (or (and (looking-at "\\(else\\|continue\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
4937 (not (looking-at "\\(\\sw\\|_\\)+::")))
4940 (cperl-backward-to-noncomment lim)
4941 (and (eq (preceding-char) ?b)
4944 (looking-at "sub[ \t\n\f#]"))))))
4945 ;; What preceeds is not word... XXXX Last statement in sub???
4946 (cperl-after-expr-p lim))))
4949 (defun cperl-after-expr-p (&optional lim chars test)
4950 "Return true if the position is good for start of expression.
4951 TEST is the expression to evaluate at the found position. If absent,
4952 CHARS is a string that contains good characters to have before us (however,
4953 `}' is treated \"smartly\" if it is not in the list)."
4954 (let ((lim (or lim (point-min)))
4956 (cperl-update-syntaxification (point) (point))
4958 (while (and (not stop) (> (point) lim))
4959 (skip-chars-backward " \t\n\f" lim)
4962 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
4963 ;; '(pod here-doc here-doc-delim))
4964 (if (get-text-property (point) 'here-doc-group)
4967 (cperl-beginning-of-property (point) 'here-doc-group))
4968 (beginning-of-line 0)))
4969 (if (get-text-property (point) 'in-pod)
4972 (cperl-beginning-of-property (point) 'in-pod))
4973 (beginning-of-line 0)))
4974 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
4975 ;; Else: last iteration, or a label
4976 (cperl-to-comment-or-eol) ; Will not move past "." after a format
4977 (skip-chars-backward " \t")
4978 (if (< p (point)) (goto-char p))
4980 (if (and (eq (preceding-char) ?:)
4983 (skip-chars-backward " \t\n\f" lim)
4984 (memq (char-syntax (preceding-char)) '(?w ?_))))
4985 (forward-sexp -1) ; Possibly label. Skip it
4988 (or (bobp) ; ???? Needed
4990 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
4992 (if test (eval test)
4993 (or (memq (preceding-char) (append (or chars "{;") nil))
4994 (and (eq (preceding-char) ?\})
4995 (cperl-after-block-p lim))
4996 (and (eq (following-char) ?.) ; in format: see comment above
4997 (eq (get-text-property (point) 'syntax-type)
5000 (defun cperl-backward-to-start-of-expr (&optional lim)
5003 (while (and (or (not lim)
5005 (not (cperl-after-expr-p lim)))
5007 ;; May be after $, @, $# etc of a variable
5008 (skip-chars-backward "$@%#")))
5011 (defun cperl-at-end-of-expr (&optional lim)
5012 ;; Since the SEXP approach below is very fragile, do some overengineering
5013 (or (looking-at (concat cperl-maybe-white-and-comment-rex "[;}]"))
5016 ;; If nothing interesting after, does as (forward-sexp -1);
5017 ;; otherwise fails, or ends at a start of following sexp.
5018 ;; XXXX PROBLEMS: if what follows (after ";") @FOO, or ${bar}
5019 ;; may be stuck after @ or $; just put some stupid workaround now:
5023 (while (memq (preceding-char) (append "%&@$*" nil))
5026 (cperl-after-expr-p lim))))
5029 (defun cperl-forward-to-end-of-expr (&optional lim)
5033 (while (and (< (point) (or lim (point-max)))
5034 (not (cperl-at-end-of-expr)))
5038 (defun cperl-backward-to-start-of-continued-exp (lim)
5039 (if (memq (preceding-char) (append ")]}\"'`" nil))
5042 (if (<= (point) lim)
5043 (goto-char (1+ lim)))
5044 (skip-chars-forward " \t"))
5046 (defun cperl-after-block-and-statement-beg (lim)
5047 ;; We assume that we are after ?\}
5049 (cperl-after-block-p lim)
5052 (cperl-backward-to-noncomment (point-min))
5055 (not (= (char-syntax (preceding-char)) ?w))
5060 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
5063 (defun cperl-indent-exp ()
5064 "Simple variant of indentation of continued-sexp.
5066 Will not indent comment if it starts at `comment-indent' or looks like
5067 continuation of the comment on the previous line.
5069 If `cperl-indent-region-fix-constructs', will improve spacing on
5070 conditional/loop constructs."
5073 (let ((tmp-end (progn (end-of-line) (point))) top done)
5078 ;; Plan A: if line has an unfinished paren-group, go to end-of-group
5079 (while (= -1 (nth 0 (parse-partial-sexp (point) tmp-end -1)))
5080 (setq top (point))) ; Get the outermost parenths in line
5082 (while (< (point) tmp-end)
5083 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
5084 (or (eolp) (forward-sexp 1)))
5085 (if (> (point) tmp-end) ; Yes, there an unfinished block
5087 (if (eq ?\) (preceding-char))
5088 (progn ;; Plan B: find by REGEXP block followup this line
5093 (if (eq (following-char) ?$ ) ; for my $var (list)
5096 (if (looking-at "\\(my\\|local\\|our\\)\\>")
5097 (forward-sexp -1))))
5099 (concat "\\(\\elsif\\|if\\|unless\\|while\\|until"
5100 "\\|for\\(each\\)?\\>\\(\\("
5101 cperl-maybe-white-and-comment-rex
5102 "\\(my\\|local\\|our\\)\\)?"
5103 cperl-maybe-white-and-comment-rex
5104 "\\$[_a-zA-Z0-9]+\\)?\\)\\>"))
5108 (setq top (point)))))
5109 (error (setq done t)))
5111 (if (looking-at ; Try Plan C: continuation block
5112 (concat cperl-maybe-white-and-comment-rex
5113 "\\<\\(else\\|elsif\|continue\\)\\>"))
5115 (goto-char (match-end 0))
5118 (setq tmp-end (point))))
5122 (setq tmp-end (point))))
5124 (setq tmp-end (point-marker)))
5125 (if cperl-indent-region-fix-constructs
5126 (cperl-fix-line-spacing tmp-end))
5127 (cperl-indent-region (point) tmp-end))))
5129 (defun cperl-fix-line-spacing (&optional end parse-data)
5130 "Improve whitespace in a conditional/loop construct.
5131 Returns some position at the last line."
5134 (setq end (point-max)))
5135 (let ((ee (save-excursion (end-of-line) (point)))
5136 (cperl-indent-region-fix-constructs
5137 (or cperl-indent-region-fix-constructs 1))
5138 p pp ml have-brace ret)
5145 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
5146 (setq have-brace (save-excursion (search-forward "}" ee t)))))
5147 nil ; Do not need to do anything
5151 (if cperl-merge-trailing-else
5153 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5155 (search-forward "}")
5157 (skip-chars-forward " \t\n")
5158 (delete-region p (point))
5159 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5160 (beginning-of-line)))
5161 (if (looking-at "[ \t]*}[ \t]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5163 (search-forward "}")
5164 (delete-horizontal-space)
5167 (if (cperl-indent-line parse-data)
5169 (cperl-fix-line-spacing end parse-data)
5170 (setq ret (point)))))))
5173 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
5175 (search-forward "}")
5176 (delete-horizontal-space)
5177 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5178 (beginning-of-line)))
5182 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5185 (delete-horizontal-space)
5186 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5187 (beginning-of-line)))
5191 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
5194 (delete-horizontal-space)
5195 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5196 (beginning-of-line)))
5198 ;; foreach my $var (
5200 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5203 (delete-horizontal-space)
5205 (make-string cperl-indent-region-fix-constructs ?\s))
5206 (beginning-of-line)))
5207 ;; Looking at (with or without "}" at start, ending after "({"):
5208 ;; } foreach my $var () OR {
5210 "[ \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]*{")
5212 (setq ml (match-beginning 8)) ; "(" or "{" after control word
5213 (re-search-forward "[({]")
5216 (if (eq (following-char) ?\( )
5219 (setq pp (point))) ; past parenth-group
5220 ;; after `else' or nothing
5221 (if ml ; after `else'
5222 (skip-chars-backward " \t\n")
5223 (beginning-of-line))
5225 ;; Now after the sexp before the brace
5226 ;; Multiline expr should be special
5227 (setq ml (and pp (save-excursion (goto-char p)
5228 (search-forward "\n" pp t))))
5229 (if (and (or (not pp) (< pp end)) ; Do not go too far...
5230 (looking-at "[ \t\n]*{"))
5233 ((bolp) ; Were before `{', no if/else/etc
5235 ((looking-at "\\(\t*\\| [ \t]+\\){") ; Not exactly 1 SPACE
5236 (delete-horizontal-space)
5238 cperl-extra-newline-before-brace-multiline
5239 cperl-extra-newline-before-brace)
5241 (delete-horizontal-space)
5244 (if (cperl-indent-line parse-data)
5246 (cperl-fix-line-spacing end parse-data)
5247 (setq ret (point)))))
5249 (make-string cperl-indent-region-fix-constructs ?\s))))
5250 ((and (looking-at "[ \t]*\n")
5252 cperl-extra-newline-before-brace-multiline
5253 cperl-extra-newline-before-brace)))
5255 (skip-chars-forward " \t\n")
5256 (delete-region pp (point))
5258 (make-string cperl-indent-region-fix-constructs ?\ )))
5259 ((and (looking-at "[\t ]*{")
5260 (if ml cperl-extra-newline-before-brace-multiline
5261 cperl-extra-newline-before-brace))
5262 (delete-horizontal-space)
5265 (if (cperl-indent-line parse-data)
5267 (cperl-fix-line-spacing end parse-data)
5268 (setq ret (point))))))
5269 ;; Now we are before `{'
5270 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
5272 (skip-chars-forward " \t\n")
5277 (setq ml (search-forward "\n" p t))
5278 (if (or cperl-break-one-line-blocks-when-indent ml)
5279 ;; not good: multi-line BLOCK
5282 (delete-horizontal-space)
5285 (if (cperl-indent-line parse-data)
5286 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
5288 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
5289 ;; Now check whether there is a hanging `}'
5293 cperl-fix-hanging-brace-when-indent
5295 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
5299 (if (and (<= (point) pp)
5300 (eq (preceding-char) ?\} )
5301 (cperl-after-block-and-statement-beg (point-min)))
5308 (skip-chars-backward " \t")
5310 ;; `}' was the first thing on the line, insert NL *after* it.
5312 (cperl-indent-line parse-data)
5313 (search-forward "}")
5314 (delete-horizontal-space)
5316 (delete-horizontal-space)
5317 (or (eq (preceding-char) ?\;)
5319 (and (eq (preceding-char) ?\} )
5320 (cperl-after-block-p (point-min)))
5324 (if (cperl-indent-line parse-data)
5325 (setq ret (cperl-fix-line-spacing end parse-data)))
5326 (beginning-of-line)))))
5329 (defvar cperl-update-start) ; Do not need to make them local
5330 (defvar cperl-update-end)
5331 (defun cperl-delay-update-hook (beg end old-len)
5332 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
5333 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
5335 (defun cperl-indent-region (start end)
5336 "Simple variant of indentation of region in CPerl mode.
5337 Should be slow. Will not indent comment if it starts at `comment-indent'
5338 or looks like continuation of the comment on the previous line.
5339 Indents all the lines whose first character is between START and END
5342 If `cperl-indent-region-fix-constructs', will improve spacing on
5343 conditional/loop constructs."
5345 (cperl-update-syntaxification end end)
5347 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
5348 (let ((indent-info (if cperl-emacs-can-parse
5349 (list nil nil nil) ; Cannot use '(), since will modify
5352 after-change-functions ; Speed it up!
5353 st comm old-comm-indent new-comm-indent p pp i empty)
5354 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
5356 (setq old-comm-indent (and (cperl-to-comment-or-eol)
5358 new-comm-indent old-comm-indent)
5360 (setq end (set-marker (make-marker) end)) ; indentation changes pos
5361 (or (bolp) (beginning-of-line 2))
5362 (while (and (<= (point) end) (not (eobp))) ; bol to check start
5365 (setq empty (looking-at "[ \t]*\n"))
5366 (and (setq comm (looking-at "[ \t]*#"))
5367 (or (eq (current-indentation) (or old-comm-indent
5369 (setq old-comm-indent nil))))
5370 (if (and old-comm-indent
5372 (= (current-indentation) old-comm-indent)
5373 (not (eq (get-text-property (point) 'syntax-type) 'pod))
5374 (not (eq (get-text-property (point) 'syntax-table)
5376 (let ((comment-column new-comm-indent))
5377 (indent-for-comment)))
5379 (setq i (cperl-indent-line indent-info))
5383 (if cperl-indent-region-fix-constructs
5384 (goto-char (cperl-fix-line-spacing end indent-info)))
5385 (if (setq old-comm-indent
5386 (and (cperl-to-comment-or-eol)
5387 (not (memq (get-text-property (point)
5390 (not (eq (get-text-property (point)
5394 (progn (indent-for-comment)
5395 (skip-chars-backward " \t")
5396 (skip-chars-backward "#")
5397 (setq new-comm-indent (current-column))))))))
5398 (beginning-of-line 2)))
5399 ;; Now run the update hooks
5400 (and after-change-functions
5403 (goto-char cperl-update-end)
5406 (goto-char cperl-update-start)
5408 (delete-char -1))))))
5410 ;; Stolen from lisp-mode with a lot of improvements
5412 (defun cperl-fill-paragraph (&optional justify iteration)
5413 "Like `fill-paragraph', but handle CPerl comments.
5414 If any of the current line is a comment, fill the comment or the
5415 block of it that point is in, preserving the comment's initial
5416 indentation and initial hashes. Behaves usually outside of comment."
5417 ;; (interactive "P") ; Only works when called from fill-paragraph. -stef
5418 (let (;; Non-nil if the current line contains a comment.
5420 fill-paragraph-function ; do not recurse
5421 ;; If has-comment, the appropriate fill-prefix for the comment.
5423 ;; Line that contains code and comment (or nil)
5425 c spaces len dc (comment-column comment-column))
5426 ;; Figure out what kind of comment we are looking at.
5431 ;; A line with nothing but a comment on it?
5432 ((looking-at "[ \t]*#[# \t]*")
5434 comment-fill-prefix (buffer-substring (match-beginning 0)
5437 ;; A line with some code, followed by a comment? Remember that the
5438 ;; semi which starts the comment shouldn't be part of a string or
5440 ((cperl-to-comment-or-eol)
5441 (setq has-comment t)
5442 (looking-at "#+[ \t]*")
5443 (setq start (point) c (current-column)
5445 (concat (make-string (current-column) ?\s)
5446 (buffer-substring (match-beginning 0) (match-end 0)))
5447 spaces (progn (skip-chars-backward " \t")
5448 (buffer-substring (point) start))
5449 dc (- c (current-column)) len (- start (point))
5450 start (point-marker))
5452 (insert (make-string dc ?-))))) ; Placeholder (to avoid splitting???)
5453 (if (not has-comment)
5454 (fill-paragraph justify) ; Do the usual thing outside of comment
5455 ;; Narrow to include only the comment, and then fill the region.
5458 ;; Find the first line we should include in the region to fill.
5459 (if start (progn (beginning-of-line) (point))
5461 (while (and (zerop (forward-line -1))
5462 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5463 ;; We may have gone to far. Go forward again.
5464 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
5467 ;; Find the beginning of the first line past the region to fill.
5469 (while (progn (forward-line 1)
5470 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5472 ;; Remove existing hashes
5474 (goto-char (point-min))
5475 (while (progn (forward-line 1) (< (point) (point-max)))
5476 (skip-chars-forward " \t")
5477 (if (looking-at "#+")
5479 (if (and (eq (point) (match-beginning 0))
5480 (not (eq (point) (match-end 0)))) nil
5482 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage"))
5483 (delete-char (- (match-end 0) (match-beginning 0)))))))
5485 ;; Lines with only hashes on them can be paragraph boundaries.
5486 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
5487 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
5488 (fill-prefix comment-fill-prefix))
5489 (fill-paragraph justify)))
5494 (progn (delete-char dc) (insert spaces)))
5495 (if (or (= (current-column) c) iteration) nil
5496 (setq comment-column c)
5497 (indent-for-comment)
5498 ;; Repeat once more, flagging as iteration
5499 (cperl-fill-paragraph justify t))))))
5502 (defun cperl-do-auto-fill ()
5503 ;; Break out if the line is short enough
5504 (if (> (save-excursion
5508 (let ((c (save-excursion (beginning-of-line)
5509 (cperl-to-comment-or-eol) (point)))
5510 (s (memq (following-char) '(?\s ?\t))) marker)
5512 ;; Don't break line inside code: only inside comment.
5514 (setq marker (point-marker))
5515 (fill-paragraph nil)
5517 ;; Is not enough, sometimes marker is a start of line
5518 (if (bolp) (progn (re-search-forward "#+[ \t]*")
5519 (goto-char (match-end 0))))
5520 ;; Following space could have gone:
5521 (if (or (not s) (memq (following-char) '(?\s ?\t))) nil
5524 ;; Previous space could have gone:
5525 (or (memq (preceding-char) '(?\s ?\t)) (insert " "))))))
5527 (defun cperl-imenu-addback (lst &optional isback name)
5528 ;; We suppose that the lst is a DAG, unless the first element only
5529 ;; loops back, and ISBACK is set. Thus this function cannot be
5530 ;; applied twice without ISBACK set.
5531 (cond ((not cperl-imenu-addback) lst)
5534 (setq name "+++BACK+++"))
5535 (mapcar (lambda (elt)
5536 (if (and (listp elt) (listp (cdr elt)))
5538 ;; In the other order it goes up
5539 ;; one level only ;-(
5540 (setcdr elt (cons (cons name lst)
5542 (cperl-imenu-addback (cdr elt) t name))))
5543 (if isback (cdr lst) lst))
5546 (defun cperl-imenu--create-perl-index (&optional regexp)
5547 (require 'imenu) ; May be called from TAGS creator
5548 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
5549 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
5550 (index-meth-alist '()) meth
5551 packages ends-ranges p marker is-proto
5552 (prev-pos 0) is-pack index index1 name (end-range 0) package)
5553 (goto-char (point-min))
5554 (cperl-update-syntaxification (point-max) (point-max))
5555 ;; Search for the function
5556 (progn ;;save-match-data
5557 (while (re-search-forward
5558 (or regexp cperl-imenu--function-name-regexp-perl)
5560 ;; 2=package-group, 5=package-name 8=sub-name
5562 ((and ; Skip some noise if building tags
5563 (match-beginning 5) ; package name
5564 ;;(eq (char-after (match-beginning 2)) ?p) ; package
5565 (not (save-match-data
5566 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
5569 (or (match-beginning 2)
5570 (match-beginning 8)) ; package or sub
5571 ;; Skip if quoted (will not skip multi-line ''-strings :-():
5572 (null (get-text-property (match-beginning 1) 'syntax-table))
5573 (null (get-text-property (match-beginning 1) 'syntax-type))
5574 (null (get-text-property (match-beginning 1) 'in-pod)))
5575 (setq is-pack (match-beginning 2))
5576 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
5577 ;; (goto-char (match-end 0))) ; Messes what follows
5580 (while (and ends-ranges (>= p (car ends-ranges)))
5581 ;; delete obsolete entries
5582 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
5583 (setq package (or (car packages) "")
5584 end-range (or (car ends-ranges) 0))
5585 (if is-pack ; doing "package"
5587 (if (match-beginning 5) ; named package
5588 (setq name (buffer-substring (match-beginning 5)
5591 (set-text-properties 0 (length name) nil name)
5593 package (concat name "::")
5594 name (concat "package " name))
5595 ;; Support nameless packages
5596 (setq name "package;" package ""))
5599 (parse-partial-sexp (point) (point-max) -1) (point))
5600 ends-ranges (cons end-range ends-ranges)
5601 packages (cons package packages)))
5603 (or (eq (following-char) ?\;)
5604 (eq 0 (get-text-property (point) 'attrib-group)))))
5605 ;; Skip this function name if it is a prototype declaration.
5606 (if (and is-proto (not is-pack)) nil
5609 (buffer-substring (match-beginning 8) (match-end 8)))
5610 (set-text-properties 0 (length name) nil name))
5611 (setq marker (make-marker))
5612 (set-marker marker (match-end (if is-pack 2 8)))
5614 ((string-match "[:']" name)
5616 ((> p end-range) nil)
5618 (setq name (concat package name) meth t)))
5619 (setq index (cons name marker))
5621 (push index index-pack-alist)
5622 (push index index-alist))
5623 (if meth (push index index-meth-alist))
5624 (push index index-unsorted-alist)))
5625 ((match-beginning 16) ; POD section
5626 (setq name (buffer-substring (match-beginning 17) (match-end 17))
5627 marker (make-marker))
5628 (set-marker marker (match-beginning 17))
5629 (set-text-properties 0 (length name) nil name)
5630 (setq name (concat (make-string
5631 (* 3 (- (char-after (match-beginning 16)) ?1))
5634 index (cons name marker))
5635 (setq index1 (cons (concat "=" name) (cdr index)))
5636 (push index index-pod-alist)
5637 (push index1 index-unsorted-alist)))))
5639 (if (default-value 'imenu-sort-function)
5640 (sort index-alist (default-value 'imenu-sort-function))
5641 (nreverse index-alist)))
5642 (and index-pod-alist
5643 (push (cons "+POD headers+..."
5644 (nreverse index-pod-alist))
5646 (and (or index-pack-alist index-meth-alist)
5647 (let ((lst index-pack-alist) hier-list pack elt group name)
5648 ;; Remove "package ", reverse and uniquify.
5650 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
5651 (if (assoc name hier-list) nil
5652 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
5653 (setq lst index-meth-alist)
5655 (setq elt (car lst) lst (cdr lst))
5656 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
5657 (setq pack (substring (car elt) 0 (match-beginning 0)))
5658 (if (setq group (assoc pack hier-list))
5659 (if (listp (cdr group))
5660 ;; Have some functions already
5662 (cons (cons (substring
5664 (+ 2 (match-beginning 0)))
5667 (setcdr group (list (cons (substring
5669 (+ 2 (match-beginning 0)))
5673 (list (cons (substring
5675 (+ 2 (match-beginning 0)))
5678 (push (cons "+Hierarchy+..."
5681 (and index-pack-alist
5682 (push (cons "+Packages+..."
5683 (nreverse index-pack-alist))
5685 (and (or index-pack-alist index-pod-alist
5686 (default-value 'imenu-sort-function))
5687 index-unsorted-alist
5688 (push (cons "+Unsorted List+..."
5689 (nreverse index-unsorted-alist))
5691 (cperl-imenu-addback index-alist)))
5694 ;; Suggested by Mark A. Hershberger
5695 (defun cperl-outline-level ()
5696 (looking-at outline-regexp)
5697 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
5698 ;;;; 2=package-group, 5=package-name 8=sub-name 16=head-level
5699 ((match-beginning 2) 0) ; package
5700 ((match-beginning 8) 1) ; sub
5701 ((match-beginning 16)
5702 (- (char-after (match-beginning 16)) ?0)) ; headN ==> N
5703 (t 5))) ; should not happen
5706 (defvar cperl-compilation-error-regexp-alist
5707 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
5708 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
5710 "Alist that specifies how to match errors in perl output.")
5713 (defun cperl-windowed-init ()
5714 "Initialization under windowed version."
5715 (cond ((featurep 'ps-print)
5716 (unless cperl-faces-init
5717 (if (boundp 'font-lock-multiline)
5718 (setq cperl-font-lock-multiline t))
5719 (cperl-init-faces)))
5720 ((not cperl-faces-init)
5721 (add-hook 'font-lock-mode-hook
5724 (if (memq major-mode '(perl-mode cperl-mode))
5726 (or cperl-faces-init (cperl-init-faces)))))))
5727 (if (fboundp 'eval-after-load)
5730 '(or cperl-faces-init (cperl-init-faces)))))))
5732 (defvar cperl-font-lock-keywords-1 nil
5733 "Additional expressions to highlight in Perl mode. Minimal set.")
5734 (defvar cperl-font-lock-keywords nil
5735 "Additional expressions to highlight in Perl mode. Default set.")
5736 (defvar cperl-font-lock-keywords-2 nil
5737 "Additional expressions to highlight in Perl mode. Maximal set")
5739 (defun cperl-load-font-lock-keywords ()
5740 (or cperl-faces-init (cperl-init-faces))
5741 cperl-font-lock-keywords)
5743 (defun cperl-load-font-lock-keywords-1 ()
5744 (or cperl-faces-init (cperl-init-faces))
5745 cperl-font-lock-keywords-1)
5747 (defun cperl-load-font-lock-keywords-2 ()
5748 (or cperl-faces-init (cperl-init-faces))
5749 cperl-font-lock-keywords-2)
5751 (defun cperl-init-faces-weak ()
5752 ;; Allow `cperl-find-pods-heres' to run.
5753 (or (boundp 'font-lock-constant-face)
5754 (cperl-force-face font-lock-constant-face
5755 "Face for constant and label names"))
5756 (or (boundp 'font-lock-warning-face)
5757 (cperl-force-face font-lock-warning-face
5758 "Face for things which should stand out"))
5759 ;;(setq font-lock-constant-face 'font-lock-constant-face)
5762 (defun cperl-init-faces ()
5763 (condition-case errs
5765 (require 'font-lock)
5766 (and (fboundp 'font-lock-fontify-anchored-keywords)
5767 (featurep 'font-lock-extra)
5768 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
5769 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
5770 (if (fboundp 'font-lock-fontify-anchored-keywords)
5771 (setq font-lock-anchored t))
5773 t-font-lock-keywords
5775 `("[ \t]+$" 0 ',cperl-invalid-face t)
5778 "\\(^\\|[^$@%&\\]\\)\\<\\("
5781 '("if" "until" "while" "elsif" "else" "unless" "for"
5782 "foreach" "continue" "exit" "die" "last" "goto" "next"
5783 "redo" "return" "local" "exec" "sub" "do" "dump" "use" "our"
5784 "require" "package" "eval" "my" "BEGIN" "END" "CHECK" "INIT")
5785 "\\|") ; Flow control
5786 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
5787 ; In what follows we use `type' style
5788 ; for overwritable builtins
5791 "\\(^\\|[^$@%&\\]\\)\\<\\("
5792 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
5793 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
5794 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
5795 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
5796 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
5797 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
5798 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
5799 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
5800 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
5801 ;; "gethostbyname" "gethostent" "getlogin"
5802 ;; "getnetbyaddr" "getnetbyname" "getnetent"
5803 ;; "getpeername" "getpgrp" "getppid" "getpriority"
5804 ;; "getprotobyname" "getprotobynumber" "getprotoent"
5805 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
5806 ;; "getservbyport" "getservent" "getsockname"
5807 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
5808 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
5809 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
5810 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
5811 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
5812 ;; "quotemeta" "rand" "read" "readdir" "readline"
5813 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
5814 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
5815 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
5816 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
5817 ;; "setpriority" "setprotoent" "setpwent" "setservent"
5818 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
5819 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
5820 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
5821 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
5822 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
5823 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
5824 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
5825 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
5826 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
5827 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
5828 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
5829 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
5830 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
5831 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
5832 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
5833 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
5834 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
5835 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
5836 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
5837 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
5838 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
5839 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
5840 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
5841 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
5842 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
5843 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
5844 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
5845 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
5846 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
5847 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
5848 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
5849 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
5850 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
5851 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
5852 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
5853 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
5854 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
5855 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
5856 "\\)\\>") 2 'font-lock-type-face)
5857 ;; In what follows we use `other' style
5858 ;; for nonoverwritable builtins
5859 ;; Somehow 's', 'm' are not auto-generated???
5862 "\\(^\\|[^$@%&\\]\\)\\<\\("
5863 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "chomp"
5864 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
5865 ;; "eval" "exists" "for" "foreach" "format" "goto"
5866 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
5867 ;; "no" "our" "package" "pop" "pos" "print" "printf" "push"
5868 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
5869 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
5870 ;; "undef" "unless" "unshift" "untie" "until" "use"
5872 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
5873 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
5874 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|INIT\\|if\\|keys\\|"
5875 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
5876 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
5877 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
5878 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
5879 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
5880 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
5881 "\\|[sm]" ; Added manually
5882 "\\)\\>") 2 'cperl-nonoverridable-face)
5883 ;; (mapconcat 'identity
5884 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
5885 ;; "#include" "#define" "#undef")
5887 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
5888 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
5889 ;; This highlights declarations and definitions differenty.
5890 ;; We do not try to highlight in the case of attributes:
5891 ;; it is already done by `cperl-find-pods-heres'
5892 (list (concat "\\<sub"
5893 cperl-white-and-comment-rex ; whitespace/comments
5894 "\\([^ \n\t{;()]+\\)" ; 2=name (assume non-anonymous)
5896 cperl-maybe-white-and-comment-rex ;whitespace/comments?
5897 "([^()]*)\\)?" ; prototype
5898 cperl-maybe-white-and-comment-rex ; whitespace/comments?
5900 2 (if cperl-font-lock-multiline
5901 '(if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5902 'font-lock-function-name-face
5903 'font-lock-variable-name-face)
5904 ;; need to manually set 'multiline' for older font-locks
5906 (if (< 1 (count-lines (match-beginning 0)
5909 (+ 3 (match-beginning 0)) (match-end 0)
5910 'syntax-type 'multiline))
5911 (if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5912 'font-lock-function-name-face
5913 'font-lock-variable-name-face))))
5914 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
5915 2 font-lock-function-name-face)
5916 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
5917 1 font-lock-function-name-face)
5918 (cond ((featurep 'font-lock-extra)
5919 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5920 (2 font-lock-string-face t)
5921 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
5923 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5924 (2 font-lock-string-face t)
5925 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5927 (1 font-lock-string-face t))))
5928 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5929 2 font-lock-string-face t)))
5930 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
5931 font-lock-string-face t)
5932 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
5933 font-lock-constant-face) ; labels
5934 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
5935 2 font-lock-constant-face)
5936 ;; Uncomment to get perl-mode-like vars
5937 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
5938 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
5939 ;;; (2 (cons font-lock-variable-name-face '(underline))))
5940 (cond ((featurep 'font-lock-extra)
5941 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5942 (3 font-lock-variable-name-face)
5944 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5945 (1 font-lock-variable-name-face)
5946 (2 '(restart 2 nil) nil t)))
5947 nil t))) ; local variables, multiple
5949 ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
5950 (` ((, (concat "\\<\\(my\\|local\\|our\\)"
5951 cperl-maybe-white-and-comment-rex
5953 cperl-maybe-white-and-comment-rex
5954 "\\)?\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
5955 (5 (, (if cperl-font-lock-multiline
5956 'font-lock-variable-name-face
5957 '(progn (setq cperl-font-lock-multiline-start
5958 (match-beginning 0))
5959 'font-lock-variable-name-face))))
5961 cperl-maybe-white-and-comment-rex
5963 cperl-maybe-white-and-comment-rex
5964 "\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
5965 ;; Bug in font-lock: limit is used not only to limit
5966 ;; searches, but to set the "extend window for
5967 ;; facification" property. Thus we need to minimize.
5968 (, (if cperl-font-lock-multiline
5969 '(if (match-beginning 3)
5971 (goto-char (match-beginning 3))
5977 (error nil)))) ; typeahead
5978 (1- (point))) ; report limit
5979 (forward-char -2)) ; disable continued expr
5980 '(if (match-beginning 3)
5981 (point-max) ; No limit for continuation
5982 (forward-char -2)))) ; disable continued expr
5983 (, (if cperl-font-lock-multiline
5986 ;; "my" may be already fontified (POD),
5987 ;; so cperl-font-lock-multiline-start is nil
5988 (if (or (not cperl-font-lock-multiline-start)
5990 cperl-font-lock-multiline-start
5994 (1+ cperl-font-lock-multiline-start) (point)
5995 'syntax-type 'multiline))
5996 (setq cperl-font-lock-multiline-start nil))))
5997 (3 font-lock-variable-name-face)))))
5998 (t '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
5999 3 font-lock-variable-name-face)))
6000 '("\\<for\\(each\\)?\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
6001 4 font-lock-variable-name-face)
6002 ;; Avoid $!, and s!!, qq!! etc. when not fontifying syntaxically
6003 '("\\(?:^\\|[^smywqrx$]\\)\\(!\\)" 1 font-lock-negation-char-face)
6004 '("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)))
6006 t-font-lock-keywords-1
6007 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
6008 ;; not yet as of XEmacs 19.12, works with 21.1.11
6010 (not cperl-xemacs-p)
6011 (string< "21.1.9" emacs-version)
6012 (and (string< "21.1.10" emacs-version)
6013 (string< emacs-version "21.1.2")))
6015 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
6016 (if (eq (char-after (match-beginning 2)) ?%)
6019 t) ; arrays and hashes
6020 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
6022 (if (= (- (match-end 2) (match-beginning 2)) 1)
6023 (if (eq (char-after (match-beginning 3)) ?{)
6025 'cperl-array-face) ; arrays and hashes
6026 font-lock-variable-name-face) ; Just to put something
6028 ("\\(@\\|\\$#\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
6029 (1 cperl-array-face)
6030 (2 font-lock-variable-name-face))
6031 ("\\(%\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
6033 (2 font-lock-variable-name-face))
6034 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
6035 ;;; Too much noise from \s* @s[ and friends
6036 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
6037 ;;(3 font-lock-function-name-face t t)
6039 ;; (if (cperl-slash-is-regexp)
6040 ;; font-lock-function-name-face 'default) nil t))
6042 (if cperl-highlight-variables-indiscriminately
6043 (setq t-font-lock-keywords-1
6044 (append t-font-lock-keywords-1
6045 (list '("\\([$*]{?\\sw+\\)" 1
6046 font-lock-variable-name-face)))))
6047 (setq cperl-font-lock-keywords-1
6048 (if cperl-syntaxify-by-font-lock
6049 (cons 'cperl-fontify-update
6050 t-font-lock-keywords)
6051 t-font-lock-keywords)
6052 cperl-font-lock-keywords cperl-font-lock-keywords-1
6053 cperl-font-lock-keywords-2 (append
6054 cperl-font-lock-keywords-1
6055 t-font-lock-keywords-1)))
6056 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
6057 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
6058 (eval ; Avoid a warning
6059 '(font-lock-require-faces
6061 ;; Color-light Color-dark Gray-light Gray-dark Mono
6062 (list 'font-lock-comment-face
6063 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
6068 (list 'font-lock-string-face
6069 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
6074 (list 'font-lock-function-name-face
6076 "Blue" "LightSkyBlue" "Gray50" "LightGray"
6077 (cdr (assq 'background-color ; if mono
6078 (frame-parameters))))
6081 (cdr (assq 'foreground-color ; if mono
6082 (frame-parameters))))
6086 (list 'font-lock-variable-name-face
6087 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
6092 (list 'font-lock-type-face
6093 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
6098 (list 'font-lock-warning-face
6099 ["Pink" "Red" "Gray50" "LightGray"]
6106 (list 'font-lock-constant-face
6107 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
6112 (list 'cperl-nonoverridable-face
6113 ["chartreuse3" ("orchid1" "orange")
6119 (list 'cperl-array-face
6120 ["blue" "yellow" nil "Gray80"]
6121 ["lightyellow2" ("navy" "os2blue" "darkgreen")
6126 (list 'cperl-hash-face
6127 ["red" "red" nil "Gray80"]
6128 ["lightyellow2" ("navy" "os2blue" "darkgreen")
6133 ;; Do it the dull way, without choose-color
6134 (defvar cperl-guessed-background nil
6135 "Display characteristics as guessed by cperl.")
6136 ;; (or (fboundp 'x-color-defined-p)
6137 ;; (defalias 'x-color-defined-p
6138 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
6139 ;; ;; XEmacs >= 19.12
6140 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
6142 ;; (t 'x-valid-color-name-p))))
6143 (cperl-force-face font-lock-constant-face
6144 "Face for constant and label names")
6145 (cperl-force-face font-lock-variable-name-face
6146 "Face for variable names")
6147 (cperl-force-face font-lock-type-face
6148 "Face for data types")
6149 (cperl-force-face cperl-nonoverridable-face
6150 "Face for data types from another group")
6151 (cperl-force-face font-lock-warning-face
6152 "Face for things which should stand out")
6153 (cperl-force-face font-lock-comment-face
6154 "Face for comments")
6155 (cperl-force-face font-lock-function-name-face
6156 "Face for function names")
6157 (cperl-force-face cperl-hash-face
6159 (cperl-force-face cperl-array-face
6161 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
6162 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
6163 ;;(or (boundp 'font-lock-type-face)
6164 ;; (defconst font-lock-type-face
6165 ;; 'font-lock-type-face
6166 ;; "Face to use for data types."))
6167 ;;(or (boundp 'cperl-nonoverridable-face)
6168 ;; (defconst cperl-nonoverridable-face
6169 ;; 'cperl-nonoverridable-face
6170 ;; "Face to use for data types from another group."))
6171 ;;(if (not cperl-xemacs-p) nil
6172 ;; (or (boundp 'font-lock-comment-face)
6173 ;; (defconst font-lock-comment-face
6174 ;; 'font-lock-comment-face
6175 ;; "Face to use for comments."))
6176 ;; (or (boundp 'font-lock-keyword-face)
6177 ;; (defconst font-lock-keyword-face
6178 ;; 'font-lock-keyword-face
6179 ;; "Face to use for keywords."))
6180 ;; (or (boundp 'font-lock-function-name-face)
6181 ;; (defconst font-lock-function-name-face
6182 ;; 'font-lock-function-name-face
6183 ;; "Face to use for function names.")))
6185 (not (cperl-is-face 'cperl-array-face))
6186 (cperl-is-face 'font-lock-emphasized-face))
6187 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
6189 (not (cperl-is-face 'cperl-hash-face))
6190 (cperl-is-face 'font-lock-other-emphasized-face))
6191 (copy-face 'font-lock-other-emphasized-face 'cperl-hash-face))
6193 (not (cperl-is-face 'cperl-nonoverridable-face))
6194 (cperl-is-face 'font-lock-other-type-face))
6195 (copy-face 'font-lock-other-type-face 'cperl-nonoverridable-face))
6196 ;;(or (boundp 'cperl-hash-face)
6197 ;; (defconst cperl-hash-face
6199 ;; "Face to use for hashes."))
6200 ;;(or (boundp 'cperl-array-face)
6201 ;; (defconst cperl-array-face
6202 ;; 'cperl-array-face
6203 ;; "Face to use for arrays."))
6204 ;; Here we try to guess background
6206 (if (boundp 'font-lock-background-mode)
6207 font-lock-background-mode
6209 (face-list (and (fboundp 'face-list) (face-list))))
6210 ;;;; (fset 'cperl-is-face
6211 ;;;; (cond ((fboundp 'find-face)
6212 ;;;; (symbol-function 'find-face))
6214 ;;;; (function (lambda (face) (member face face-list))))
6216 ;;;; (function (lambda (face) (boundp face))))))
6217 (defvar cperl-guessed-background
6218 (if (and (boundp 'font-lock-display-type)
6219 (eq font-lock-display-type 'grayscale))
6222 "Background as guessed by CPerl mode")
6223 (and (not (cperl-is-face 'font-lock-constant-face))
6224 (cperl-is-face 'font-lock-reference-face)
6225 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
6226 (if (cperl-is-face 'font-lock-type-face) nil
6227 (copy-face 'default 'font-lock-type-face)
6229 ((eq background 'light)
6230 (set-face-foreground 'font-lock-type-face
6231 (if (x-color-defined-p "seagreen")
6234 ((eq background 'dark)
6235 (set-face-foreground 'font-lock-type-face
6236 (if (x-color-defined-p "os2pink")
6240 (set-face-background 'font-lock-type-face "gray90"))))
6241 (if (cperl-is-face 'cperl-nonoverridable-face)
6243 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
6245 ((eq background 'light)
6246 (set-face-foreground 'cperl-nonoverridable-face
6247 (if (x-color-defined-p "chartreuse3")
6250 ((eq background 'dark)
6251 (set-face-foreground 'cperl-nonoverridable-face
6252 (if (x-color-defined-p "orchid1")
6255 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
6256 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
6258 ;;; ((eq background 'light)
6259 ;;; (set-face-background 'font-lock-other-emphasized-face
6260 ;;; (if (x-color-defined-p "lightyellow2")
6262 ;;; (if (x-color-defined-p "lightyellow")
6264 ;;; "light yellow"))))
6265 ;;; ((eq background 'dark)
6266 ;;; (set-face-background 'font-lock-other-emphasized-face
6267 ;;; (if (x-color-defined-p "navy")
6269 ;;; (if (x-color-defined-p "darkgreen")
6271 ;;; "dark green"))))
6272 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
6273 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
6274 ;;; (copy-face 'bold 'font-lock-emphasized-face)
6276 ;;; ((eq background 'light)
6277 ;;; (set-face-background 'font-lock-emphasized-face
6278 ;;; (if (x-color-defined-p "lightyellow2")
6280 ;;; "lightyellow")))
6281 ;;; ((eq background 'dark)
6282 ;;; (set-face-background 'font-lock-emphasized-face
6283 ;;; (if (x-color-defined-p "navy")
6285 ;;; (if (x-color-defined-p "darkgreen")
6287 ;;; "dark green"))))
6288 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
6289 (if (cperl-is-face 'font-lock-variable-name-face) nil
6290 (copy-face 'italic 'font-lock-variable-name-face))
6291 (if (cperl-is-face 'font-lock-constant-face) nil
6292 (copy-face 'italic 'font-lock-constant-face))))
6293 (setq cperl-faces-init t))
6294 (error (message "cperl-init-faces (ignored): %s" errs))))
6297 (defun cperl-ps-print-init ()
6298 "Initialization of `ps-print' components for faces used in CPerl."
6299 (eval-after-load "ps-print"
6300 '(setq ps-bold-faces
6301 ;; font-lock-variable-name-face
6302 ;; font-lock-constant-face
6303 (append '(cperl-array-face cperl-hash-face)
6306 ;; font-lock-constant-face
6307 (append '(cperl-nonoverridable-face cperl-hash-face)
6310 ;; font-lock-type-face
6311 (append '(cperl-array-face cperl-hash-face underline cperl-nonoverridable-face)
6312 ps-underlined-faces))))
6314 (defvar ps-print-face-extension-alist)
6316 (defun cperl-ps-print (&optional file)
6317 "Pretty-print in CPerl style.
6318 If optional argument FILE is an empty string, prints to printer, otherwise
6319 to the file FILE. If FILE is nil, prompts for a file name.
6321 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
6324 (setq file (read-from-minibuffer
6325 "Print to file (if empty - to printer): "
6326 (concat (buffer-file-name) ".ps")
6327 nil nil 'file-name-history)))
6328 (or (> (length file) 0)
6330 (require 'ps-print) ; To get ps-print-face-extension-alist
6331 (let ((ps-print-color-p t)
6332 (ps-print-face-extension-alist ps-print-face-extension-alist))
6333 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
6334 (ps-print-buffer-with-faces file)))
6336 ;;; (defun cperl-ps-print-init ()
6337 ;;; "Initialization of `ps-print' components for faces used in CPerl."
6338 ;;; ;; Guard against old versions
6339 ;;; (defvar ps-underlined-faces nil)
6340 ;;; (defvar ps-bold-faces nil)
6341 ;;; (defvar ps-italic-faces nil)
6342 ;;; (setq ps-bold-faces
6343 ;;; (append '(font-lock-emphasized-face
6344 ;;; cperl-array-face
6345 ;;; font-lock-keyword-face
6346 ;;; font-lock-variable-name-face
6347 ;;; font-lock-constant-face
6348 ;;; font-lock-reference-face
6349 ;;; font-lock-other-emphasized-face
6350 ;;; cperl-hash-face)
6352 ;;; (setq ps-italic-faces
6353 ;;; (append '(cperl-nonoverridable-face
6354 ;;; font-lock-constant-face
6355 ;;; font-lock-reference-face
6356 ;;; font-lock-other-emphasized-face
6357 ;;; cperl-hash-face)
6358 ;;; ps-italic-faces))
6359 ;;; (setq ps-underlined-faces
6360 ;;; (append '(font-lock-emphasized-face
6361 ;;; cperl-array-face
6362 ;;; font-lock-other-emphasized-face
6364 ;;; cperl-nonoverridable-face font-lock-type-face)
6365 ;;; ps-underlined-faces))
6366 ;;; (cons 'font-lock-type-face ps-underlined-faces))
6369 (if (cperl-enable-font-lock) (cperl-windowed-init))
6371 (defconst cperl-styles-entries
6372 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
6373 cperl-label-offset cperl-extra-newline-before-brace
6374 cperl-extra-newline-before-brace-multiline
6375 cperl-merge-trailing-else
6376 cperl-continued-statement-offset))
6378 (defconst cperl-style-examples
6379 "##### Numbers etc are: cperl-indent-level cperl-brace-offset
6380 ##### cperl-continued-brace-offset cperl-label-offset
6381 ##### cperl-continued-statement-offset
6382 ##### cperl-merge-trailing-else cperl-extra-newline-before-brace
6384 ########### (Do not forget cperl-extra-newline-before-brace-multiline)
6386 ### CPerl (=GNU - extra-newline-before-brace + merge-trailing-else) 2/0/0/-2/2/t/nil
6398 ### PerlStyle (=CPerl with 4 as indent) 4/0/0/-4/4/t/nil
6410 ### GNU 2/0/0/-2/2/nil/t
6425 ### C++ (=PerlStyle with braces aligned with control words) 4/0/-4/-4/4/nil/t
6440 ### BSD (=C++, but will not change preexisting merge-trailing-else
6441 ### and extra-newline-before-brace ) 4/0/-4/-4/4
6456 ### K&R (=C++ with indent 5 - merge-trailing-else, but will not
6457 ### change preexisting extra-newline-before-brace) 5/0/-5/-5/5/nil
6472 ### Whitesmith (=PerlStyle, but will not change preexisting
6473 ### extra-newline-before-brace and merge-trailing-else) 4/0/0/-4/4
6488 "Examples of if/else with different indent styles (with v4.23).")
6490 (defconst cperl-style-alist
6491 '(("CPerl" ;; =GNU - extra-newline-before-brace + cperl-merge-trailing-else
6492 (cperl-indent-level . 2)
6493 (cperl-brace-offset . 0)
6494 (cperl-continued-brace-offset . 0)
6495 (cperl-label-offset . -2)
6496 (cperl-continued-statement-offset . 2)
6497 (cperl-extra-newline-before-brace . nil)
6498 (cperl-extra-newline-before-brace-multiline . nil)
6499 (cperl-merge-trailing-else . t))
6501 ("PerlStyle" ; CPerl with 4 as indent
6502 (cperl-indent-level . 4)
6503 (cperl-brace-offset . 0)
6504 (cperl-continued-brace-offset . 0)
6505 (cperl-label-offset . -4)
6506 (cperl-continued-statement-offset . 4)
6507 (cperl-extra-newline-before-brace . nil)
6508 (cperl-extra-newline-before-brace-multiline . nil)
6509 (cperl-merge-trailing-else . t))
6512 (cperl-indent-level . 2)
6513 (cperl-brace-offset . 0)
6514 (cperl-continued-brace-offset . 0)
6515 (cperl-label-offset . -2)
6516 (cperl-continued-statement-offset . 2)
6517 (cperl-extra-newline-before-brace . t)
6518 (cperl-extra-newline-before-brace-multiline . t)
6519 (cperl-merge-trailing-else . nil))
6522 (cperl-indent-level . 5)
6523 (cperl-brace-offset . 0)
6524 (cperl-continued-brace-offset . -5)
6525 (cperl-label-offset . -5)
6526 (cperl-continued-statement-offset . 5)
6527 ;;(cperl-extra-newline-before-brace . nil) ; ???
6528 ;;(cperl-extra-newline-before-brace-multiline . nil)
6529 (cperl-merge-trailing-else . nil))
6532 (cperl-indent-level . 4)
6533 (cperl-brace-offset . 0)
6534 (cperl-continued-brace-offset . -4)
6535 (cperl-label-offset . -4)
6536 (cperl-continued-statement-offset . 4)
6537 ;;(cperl-extra-newline-before-brace . nil) ; ???
6538 ;;(cperl-extra-newline-before-brace-multiline . nil)
6539 ;;(cperl-merge-trailing-else . nil) ; ???
6543 (cperl-indent-level . 4)
6544 (cperl-brace-offset . 0)
6545 (cperl-continued-brace-offset . -4)
6546 (cperl-label-offset . -4)
6547 (cperl-continued-statement-offset . 4)
6548 (cperl-extra-newline-before-brace . t)
6549 (cperl-extra-newline-before-brace-multiline . t)
6550 (cperl-merge-trailing-else . nil))
6553 (cperl-indent-level . 4)
6554 (cperl-brace-offset . 0)
6555 (cperl-continued-brace-offset . 0)
6556 (cperl-label-offset . -4)
6557 (cperl-continued-statement-offset . 4)
6558 ;;(cperl-extra-newline-before-brace . nil) ; ???
6559 ;;(cperl-extra-newline-before-brace-multiline . nil)
6560 ;;(cperl-merge-trailing-else . nil) ; ???
6563 "List of variables to set to get a particular indentation style.
6564 Should be used via `cperl-set-style' or via Perl menu.
6566 See examples in `cperl-style-examples'.")
6568 (defun cperl-set-style (style)
6569 "Set CPerl mode variables to use one of several different indentation styles.
6570 The arguments are a string representing the desired style.
6571 The list of styles is in `cperl-style-alist', available styles
6572 are CPerl, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith.
6574 The current value of style is memorized (unless there is a memorized
6575 data already), may be restored by `cperl-set-style-back'.
6577 Chosing \"Current\" style will not change style, so this may be used for
6578 side-effect of memorizing only. Examples in `cperl-style-examples'."
6580 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
6581 cperl-style-alist)))
6582 (list (completing-read "Enter style: " list nil 'insist))))
6584 (setq cperl-old-style
6587 (cons name (eval name))))
6588 cperl-styles-entries)))
6589 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
6591 (setq setting (car style) style (cdr style))
6592 (set (car setting) (cdr setting)))))
6594 (defun cperl-set-style-back ()
6595 "Restore a style memorized by `cperl-set-style'."
6597 (or cperl-old-style (error "The style was not changed"))
6599 (while cperl-old-style
6600 (setq setting (car cperl-old-style)
6601 cperl-old-style (cdr cperl-old-style))
6602 (set (car setting) (cdr setting)))))
6604 (defun cperl-check-syntax ()
6606 (require 'mode-compile)
6607 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
6608 (eval '(mode-compile)))) ; Avoid a warning
6610 (defun cperl-info-buffer (type)
6611 ;; Returns buffer with documentation. Creates if missing.
6612 ;; If TYPE, this vars buffer.
6613 ;; Special care is taken to not stomp over an existing info buffer
6614 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
6615 (info (get-buffer bname))
6616 (oldbuf (get-buffer "*info*")))
6618 (save-window-excursion
6623 (rename-buffer "*info-perl-tmp*")))
6624 (save-window-excursion
6626 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
6627 (set-buffer "*info*")
6628 (rename-buffer bname)
6630 (set-buffer "*info-perl-tmp*")
6631 (rename-buffer "*info*")
6632 (set-buffer bname)))
6633 (make-local-variable 'window-min-height)
6634 (setq window-min-height 2)
6635 (current-buffer)))))
6637 (defun cperl-word-at-point (&optional p)
6638 "Return the word at point or at P."
6640 (if p (goto-char p))
6641 (or (cperl-word-at-point-hard)
6644 (funcall (or (and (boundp 'find-tag-default-function)
6645 find-tag-default-function)
6646 (get major-mode 'find-tag-default-function)
6647 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
6648 ;; automatically used within `find-tag-default':
6649 'find-tag-default))))))
6651 (defun cperl-info-on-command (command)
6652 "Show documentation for Perl command COMMAND in other window.
6653 If perl-info buffer is shown in some frame, uses this frame.
6654 Customized by setting variables `cperl-shrink-wrap-info-frame',
6655 `cperl-max-help-size'."
6657 (let* ((default (cperl-word-at-point))
6659 (format "Find doc for Perl function (default %s): "
6661 (list (if (equal read "")
6665 (let ((buffer (current-buffer))
6666 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
6667 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
6668 max-height char-height buf-list)
6669 (if (string-match "^-[a-zA-Z]$" command)
6670 (setq cmd-desc "^-X[ \t\n]"))
6671 (setq isvar (string-match "^[$@%]" command)
6672 buf (cperl-info-buffer isvar)
6673 iniwin (selected-window)
6674 fr1 (window-frame iniwin))
6676 (goto-char (point-min))
6678 (progn (re-search-forward "^-X[ \t\n]")
6680 (if (re-search-forward cmd-desc nil t)
6682 ;; Go back to beginning of the group (ex, for qq)
6683 (if (re-search-backward "^[ \t\n\f]")
6688 buf-list (list buf "*info-perl-var*" "*info-perl*"))
6689 (while (and (not win) buf-list)
6690 (setq win (get-buffer-window (car buf-list) t))
6691 (setq buf-list (cdr buf-list)))
6693 (eq (window-buffer win) buf)
6694 (set-window-buffer win buf))
6695 (and win (setq fr2 (window-frame win)))
6696 (if (or (not fr2) (eq fr1 fr2))
6698 (special-display-popup-frame buf) ; Make it visible
6699 (select-window win))
6700 (goto-char pos) ; Needed (?!).
6702 (setq iniheight (window-height)
6703 frheight (frame-height)
6704 not-loner (< iniheight (1- frheight))) ; Are not alone
6705 (cond ((if not-loner cperl-max-help-size
6706 cperl-shrink-wrap-info-frame)
6712 (if (re-search-forward
6713 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
6714 (match-beginning 0) (point-max)))))
6717 (/ (* (- frheight 3) cperl-max-help-size) 100)
6718 (setq char-height (frame-char-height))
6719 ;; Non-functioning under OS/2:
6720 (if (eq char-height 1) (setq char-height 18))
6721 ;; Title, menubar, + 2 for slack
6722 (- (/ (x-display-pixel-height) char-height) 4)))
6723 (if (> height max-height) (setq height max-height))
6724 ;;(message "was %s doing %s" iniheight height)
6726 (enlarge-window (- height iniheight))
6727 (set-frame-height (window-frame win) (1+ height)))))
6728 (set-window-start (selected-window) pos))
6729 (message "No entry for %s found." command))
6730 ;;(pop-to-buffer buffer)
6731 (select-window iniwin)))
6733 (defun cperl-info-on-current-command ()
6734 "Show documentation for Perl command at point in other window."
6736 (cperl-info-on-command (cperl-word-at-point)))
6738 (defun cperl-imenu-info-imenu-search ()
6739 (if (looking-at "^-X[ \t\n]") nil
6741 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
6744 (defun cperl-imenu-info-imenu-name ()
6746 (match-beginning 1) (match-end 1)))
6748 (defun cperl-imenu-on-info ()
6749 "Shows imenu for Perl Info Buffer.
6750 Opens Perl Info buffer if needed."
6752 (let* ((buffer (current-buffer))
6753 imenu-create-index-function
6754 imenu-prev-index-position-function
6755 imenu-extract-index-name-function
6756 (index-item (save-restriction
6757 (save-window-excursion
6758 (set-buffer (cperl-info-buffer nil))
6759 (setq imenu-create-index-function
6760 'imenu-default-create-index-function
6761 imenu-prev-index-position-function
6762 'cperl-imenu-info-imenu-search
6763 imenu-extract-index-name-function
6764 'cperl-imenu-info-imenu-name)
6765 (imenu-choose-buffer-index)))))
6769 (pop-to-buffer "*info-perl*")
6771 ((markerp (cdr index-item))
6772 (goto-char (marker-position (cdr index-item))))
6774 (goto-char (cdr index-item))))
6775 (set-window-start (selected-window) (point))
6776 (pop-to-buffer buffer)))))
6778 (defun cperl-lineup (beg end &optional step minshift)
6779 "Lineup construction in a region.
6780 Beginning of region should be at the start of a construction.
6781 All first occurrences of this construction in the lines that are
6782 partially contained in the region are lined up at the same column.
6784 MINSHIFT is the minimal amount of space to insert before the construction.
6785 STEP is the tabwidth to position constructions.
6786 If STEP is nil, `cperl-lineup-step' will be used
6787 \(or `cperl-indent-level', if `cperl-lineup-step' is nil).
6788 Will not move the position at the start to the left."
6790 (let (search col tcol seen b)
6794 (setq end (point-marker))
6796 (skip-chars-forward " \t\f")
6797 (setq beg (point-marker))
6798 (indent-region beg end nil)
6800 (setq col (current-column))
6801 (if (looking-at "[a-zA-Z0-9_]")
6802 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
6806 (buffer-substring (match-beginning 0)
6807 (match-end 0))) "\\>"))
6808 (error "Cannot line up in a middle of the word"))
6809 (if (looking-at "$")
6810 (error "Cannot line up end of line"))
6811 (setq search (regexp-quote (char-to-string (following-char)))))
6812 (setq step (or step cperl-lineup-step cperl-indent-level))
6813 (or minshift (setq minshift 1))
6815 (beginning-of-line 2)
6816 (and (< (point) end)
6817 (re-search-forward search end t)
6818 (goto-char (match-beginning 0))))
6819 (setq tcol (current-column) seen t)
6820 (if (> tcol col) (setq col tcol)))
6822 (error "The construction to line up occurred only once"))
6824 (setq col (+ col minshift))
6825 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
6828 (cperl-make-indent col)
6829 (beginning-of-line 2)
6830 (and (< (point) end)
6831 (re-search-forward search end t)
6832 (goto-char (match-beginning 0)))))))) ; No body
6834 (defun cperl-etags (&optional add all files) ;; NOT USED???
6835 "Run etags with appropriate options for Perl files.
6836 If optional argument ALL is `recursive', will process Perl files
6837 in subdirectories too."
6840 (args '("-l" "none" "-r"
6841 ;; 1=fullname 2=package? 3=name 4=proto? 5=attrs? (VERY APPROX!)
6842 "/\\<sub[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([ \t]*:[^#{;]*\\)?\\([{#]\\|$\\)/\\3/"
6844 "/\\<package[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\([#;]\\|$\\)/\\1/"
6846 "/\\<\\(package\\)[ \\t]*;/\\1;/"))
6848 (if add (setq args (cons "-a" args)))
6849 (or files (setq files (list buffer-file-name)))
6851 ((eq all 'recursive)
6852 ;;(error "Not implemented: recursive")
6853 (setq args (append (list "-e"
6854 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
6856 find(\\&wanted, '.');
6861 ;;(error "Not implemented: all")
6862 (setq args (append (list "-e"
6863 "push @ARGV, <*.PL *.pl *.pm>;
6868 (setq args (append args files))))
6869 (setq res (apply 'call-process cmd nil nil nil args))
6871 (message "etags returned \"%s\"" res))))
6873 (defun cperl-toggle-auto-newline ()
6874 "Toggle the state of `cperl-auto-newline'."
6876 (setq cperl-auto-newline (not cperl-auto-newline))
6877 (message "Newlines will %sbe auto-inserted now."
6878 (if cperl-auto-newline "" "not ")))
6880 (defun cperl-toggle-abbrev ()
6881 "Toggle the state of automatic keyword expansion in CPerl mode."
6883 (abbrev-mode (if abbrev-mode 0 1))
6884 (message "Perl control structure will %sbe auto-inserted now."
6885 (if abbrev-mode "" "not ")))
6888 (defun cperl-toggle-electric ()
6889 "Toggle the state of parentheses doubling in CPerl mode."
6891 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
6892 (message "Parentheses will %sbe auto-doubled now."
6893 (if (cperl-val 'cperl-electric-parens) "" "not ")))
6895 (defun cperl-toggle-autohelp ()
6896 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
6897 Delay of auto-help controlled by `cperl-lazy-help-time'."
6899 (if (fboundp 'run-with-idle-timer)
6901 (if cperl-lazy-installed
6902 (cperl-lazy-unstall)
6903 (cperl-lazy-install))
6904 (message "Perl help messages will %sbe automatically shown now."
6905 (if cperl-lazy-installed "" "not ")))
6906 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
6908 (defun cperl-toggle-construct-fix ()
6909 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
6911 (setq cperl-indent-region-fix-constructs
6912 (if cperl-indent-region-fix-constructs
6915 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
6916 (if cperl-indent-region-fix-constructs "" "not ")))
6918 (defun cperl-toggle-set-debug-unwind (arg &optional backtrace)
6919 "Toggle (or, with numeric argument, set) debugging state of syntaxification.
6920 Nonpositive numeric argument disables debugging messages. The message
6921 summarizes which regions it was decided to rescan for syntactic constructs.
6923 The message looks like this:
6925 Syxify req=123..138 actual=101..146 done-to: 112=>146 statepos: 73=>117
6927 Numbers are character positions in the buffer. REQ provides the range to
6928 rescan requested by `font-lock'. ACTUAL is the range actually resyntaxified;
6929 for correct operation it should start and end outside any special syntactic
6930 construct. DONE-TO and STATEPOS indicate changes to internal caches maintained
6934 (setq arg (if (eq cperl-syntaxify-by-font-lock
6935 (if backtrace 'backtrace 'message)) 0 1)))
6936 (setq arg (if (> arg 0) (if backtrace 'backtrace 'message) t))
6937 (setq cperl-syntaxify-by-font-lock arg)
6938 (message "Debugging messages of syntax unwind %sabled."
6939 (if (eq arg t) "dis" "en")))
6941 ;;;; Tags file creation.
6943 (defvar cperl-tmp-buffer " *cperl-tmp*")
6945 (defun cperl-setup-tmp-buf ()
6946 (set-buffer (get-buffer-create cperl-tmp-buffer))
6947 (set-syntax-table cperl-mode-syntax-table)
6948 (buffer-disable-undo)
6950 (if cperl-use-syntax-table-text-property-for-tags
6952 (make-local-variable 'parse-sexp-lookup-properties)
6953 ;; Do not introduce variable if not needed, we check it!
6954 (set 'parse-sexp-lookup-properties t))))
6956 (defun cperl-xsub-scan ()
6958 (let ((index-alist '())
6959 (prev-pos 0) index index1 name package prefix)
6960 (goto-char (point-min))
6961 ;; Search for the function
6962 (progn ;;save-match-data
6963 (while (re-search-forward
6964 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
6967 ((match-beginning 2) ; SECTION
6968 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
6969 (goto-char (match-beginning 0))
6970 (skip-chars-forward " \t")
6972 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
6973 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
6975 ((not package) nil) ; C language section
6976 ((match-beginning 3) ; XSUB
6977 (goto-char (1+ (match-beginning 3)))
6978 (setq index (imenu-example--name-and-position))
6979 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
6980 (if (and prefix (string-match (concat "^" prefix) name))
6981 (setq name (substring name (length prefix))))
6982 (cond ((string-match "::" name) nil)
6984 (setq index1 (cons (concat package "::" name) (cdr index)))
6985 (push index1 index-alist)))
6987 (push index index-alist))
6989 ;; (beginning-of-line)
6990 (setq index (imenu-example--name-and-position))
6991 (setcar index (concat package "::BOOT:"))
6992 (push index index-alist)))))
6995 (defvar cperl-unreadable-ok nil)
6997 (defun cperl-find-tags (ifile xs topdir)
6998 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
6999 (cperl-pod-here-fontify nil) f file)
7001 (if b (set-buffer b)
7002 (cperl-setup-tmp-buf))
7005 (setq file (car (insert-file-contents ifile)))
7006 (error (if cperl-unreadable-ok nil
7008 (format "File %s unreadable. Continue? " ifile))
7009 (setq cperl-unreadable-ok t)
7010 (error "Aborting: unreadable file %s" ifile)))))
7012 (message "Unreadable file %s" ifile)
7013 (message "Scanning file %s ..." file)
7014 (if (and cperl-use-syntax-table-text-property-for-tags
7016 (condition-case err ; after __END__ may have garbage
7017 (cperl-find-pods-heres nil nil noninteractive)
7018 (error (message "While scanning for syntax: %s" err))))
7020 (setq lst (cperl-xsub-scan))
7021 (setq ind (cperl-imenu--create-perl-index))
7022 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
7027 (cond ((string-match "^[_a-zA-Z]" (car elt))
7028 (goto-char (cdr elt))
7029 (beginning-of-line) ; pos should be of the start of the line
7032 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
7033 (buffer-substring (progn
7034 (goto-char (cdr elt))
7035 ;; After name now...
7036 (or (eolp) (forward-char 1))
7044 (setq elt (car lst) lst (cdr lst))
7049 (if (string-match "^package " (car elt))
7050 (substring (car elt) 8)
7053 (number-to-string (elt elt 2)) ; Line
7055 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
7057 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
7058 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
7060 ;; Need to insert the name without package as well
7061 (setq lst (cons (cons (substring (elt elt 3)
7069 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
7070 (set-text-properties 0 (length rel) nil rel)
7071 (and (equal topdir (substring rel 0 (length topdir)))
7072 (setq rel (substring file (length topdir))))
7073 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
7074 (setq ret (buffer-substring 1 (point-max)))
7077 (message "Scanning file %s finished" file))
7080 (defun cperl-add-tags-recurse-noxs ()
7081 "Add to TAGS data for \"pure\" Perl files in the current directory and kids.
7083 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7084 -f cperl-add-tags-recurse-noxs
7086 (cperl-write-tags nil nil t t nil t))
7088 (defun cperl-add-tags-recurse-noxs-fullpath ()
7089 "Add to TAGS data for \"pure\" Perl in the current directory and kids.
7090 Writes down fullpath, so TAGS is relocatable (but if the build directory
7091 is relocated, the file TAGS inside it breaks). Use as
7092 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7093 -f cperl-add-tags-recurse-noxs-fullpath
7095 (cperl-write-tags nil nil t t nil t ""))
7097 (defun cperl-add-tags-recurse ()
7098 "Add to TAGS file data for Perl files in the current directory and kids.
7100 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7101 -f cperl-add-tags-recurse
7103 (cperl-write-tags nil nil t t))
7105 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
7106 ;; If INBUFFER, do not select buffer, and do not save
7107 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
7110 (setq file (if dir default-directory (buffer-file-name)))
7111 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
7113 (setq topdir default-directory))
7114 (let ((tags-file-name "TAGS")
7115 (case-fold-search (eq system-type 'emx))
7118 (cond (inbuffer nil) ; Already there
7119 ((file-exists-p tags-file-name)
7121 (visit-tags-table-buffer)
7122 (visit-tags-table-buffer tags-file-name)))
7123 (t (set-buffer (find-file-noselect tags-file-name))))
7126 (cond ((eq erase 'ignore))
7129 (setq erase 'ignore)))
7132 (directory-files file t
7133 (if recurse nil cperl-scan-files-regexp)
7136 (if cperl-unreadable-ok nil
7138 (format "Directory %s unreadable. Continue? " file))
7139 (setq cperl-unreadable-ok t
7140 tm nil) ; Return empty list
7141 (error "Aborting: unreadable directory %s" file)))))))
7145 ((string-match cperl-noscan-files-regexp file)
7147 ((not (file-directory-p file))
7148 (if (string-match cperl-scan-files-regexp file)
7149 (cperl-write-tags file erase recurse nil t noxs topdir)))
7151 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
7154 (setq xs (string-match "\\.xs$" file))
7155 (if (not (and xs noxs))
7157 (cond ((eq erase 'ignore) (goto-char (point-max)))
7158 (erase (erase-buffer))
7162 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
7163 (set-text-properties 0 (length rel) nil rel)
7164 (and (equal topdir (substring rel 0 (length topdir)))
7165 (setq rel (substring file (length topdir))))
7166 (if (search-forward (concat "\f\n" rel ",") nil t)
7168 (search-backward "\f\n")
7169 (delete-region (point)
7172 (if (search-forward "\f\n"
7176 (goto-char (point-max)))))
7177 (insert (cperl-find-tags file xs topdir))))))
7178 (if inbuffer nil ; Delegate to the caller
7179 (save-buffer 0) ; No backup
7180 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
7181 (initialize-new-tags-table))))))
7183 (defvar cperl-tags-hier-regexp-list
7190 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
7192 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
7195 (defvar cperl-hierarchy '(() ())
7196 "Global hierarchy of classes.")
7198 (defun cperl-tags-hier-fill ()
7199 ;; Suppose we are in a tag table cooked by cperl.
7201 (let (type pack name pos line chunk ord cons1 file str info fileind)
7202 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
7203 (setq pos (match-beginning 0)
7204 pack (match-beginning 2))
7206 (if (looking-at (concat
7215 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
7216 name (buffer-substring (match-beginning 2) (match-end 2))
7217 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
7218 line (buffer-substring (match-beginning 3) (match-end 3))
7221 fileind (format "%s:%s" file line)
7222 ;; Moves to beginning of the next line:
7223 info (cperl-etags-snarf-tag file line))
7226 ;; Make new member of hierarchy name ==> file ==> pos if needed
7227 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
7229 (setcdr cons1 (cons (cons fileind (vector file info))
7231 ;; First occurrence of the name, start alist
7232 (setq cons1 (cons name (list (cons fileind (vector file info)))))
7234 (setcar (cdr cperl-hierarchy)
7235 (cons cons1 (nth 1 cperl-hierarchy)))
7236 (setcar cperl-hierarchy
7237 (cons cons1 (car cperl-hierarchy)))))))
7240 (defun cperl-tags-hier-init (&optional update)
7241 "Show hierarchical menu of classes and methods.
7242 Finds info about classes by a scan of loaded TAGS files.
7243 Supposes that the TAGS files contain fully qualified function names.
7244 One may build such TAGS files from CPerl mode menu."
7248 (if (or update (null (nth 2 cperl-hierarchy)))
7249 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
7252 (setcdr elt (cdr (nth 1 elt)))))))
7253 pack name cons1 to l1 l2 l3 l4 b)
7254 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
7255 (setq cperl-hierarchy (list l1 l2 l3))
7256 (if cperl-xemacs-p ; Not checked
7259 ;; Does this work in XEmacs?
7260 (call-interactively 'visit-tags-table))
7261 (message "Updating list of classes...")
7262 (set-buffer (get-file-buffer tags-file-name))
7263 (cperl-tags-hier-fill))
7265 (call-interactively 'visit-tags-table))
7269 (message "Updating list of classes... %s" tagsfile)
7270 (set-buffer (get-file-buffer tagsfile))
7271 (cperl-tags-hier-fill)))
7273 (message "Updating list of classes... postprocessing..."))
7274 (mapcar remover (car cperl-hierarchy))
7275 (mapcar remover (nth 1 cperl-hierarchy))
7276 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
7277 (cons "Methods: " (car cperl-hierarchy))))
7278 (cperl-tags-treeify to 1)
7279 (setcar (nthcdr 2 cperl-hierarchy)
7280 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
7281 (message "Updating list of classes: done, requesting display...")
7282 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
7284 (or (nth 2 cperl-hierarchy)
7285 (error "No items found"))
7287 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
7288 (if (if (fboundp 'display-popup-menus-p)
7289 (let ((f 'display-popup-menus-p))
7292 (x-popup-menu t (nth 2 cperl-hierarchy))
7294 (tmm-prompt (nth 2 cperl-hierarchy))))
7295 (if (and update (listp update))
7296 (progn (while (cdr update) (setq update (cdr update)))
7297 (setq update (car update)))) ; Get the last from the list
7298 (if (vectorp update)
7300 (find-file (elt update 0))
7301 (cperl-etags-goto-tag-location (elt update 1))))
7302 (if (eq update -999) (cperl-tags-hier-init t)))
7304 (defun cperl-tags-treeify (to level)
7305 ;; cadr of `to' is read-write. On start it is a cons
7306 (let* ((regexp (concat "^\\(" (mapconcat
7308 (make-list level "[_a-zA-Z0-9]+")
7311 (packages (cdr (nth 1 to)))
7312 (methods (cdr (nth 2 to)))
7313 l1 head tail cons1 cons2 ord writeto packs recurse
7314 root-packages root-functions ms many_ms same_name ps
7318 (cond ((and (string-match regexp (car elt))
7319 (or (eq ord 1) (match-end 2)))
7320 (setq head (substring (car elt) 0 (match-end 1))
7321 tail (if (match-end 2) (substring (car elt)
7324 (if (setq cons1 (assoc head writeto)) nil
7325 ;; Need to init new head
7326 (setcdr writeto (cons (list head (list "Packages: ")
7329 (setq cons1 (nth 1 writeto)))
7330 (setq cons2 (nth ord cons1)) ; Either packs or meths
7331 (setcdr cons2 (cons elt (cdr cons2))))
7333 (setq root-functions (cons elt root-functions)))
7335 (setq root-packages (cons elt root-packages))))))))
7336 (setcdr to l1) ; Init to dynamic space
7339 (mapcar move-deeper packages)
7341 (mapcar move-deeper methods)
7343 (mapcar (function (lambda (elt)
7344 (cperl-tags-treeify elt (1+ level))))
7346 ;;Now clean up leaders with one child only
7347 (mapcar (function (lambda (elt)
7348 (if (not (and (listp (cdr elt))
7349 (eq (length elt) 2))) nil
7350 (setcar elt (car (nth 1 elt)))
7351 (setcdr elt (cdr (nth 1 elt))))))
7353 ;; Sort the roots of subtrees
7354 (if (default-value 'imenu-sort-function)
7356 (sort (cdr to) (default-value 'imenu-sort-function))))
7357 ;; Now add back functions removed from display
7358 (mapcar (function (lambda (elt)
7359 (setcdr to (cons elt (cdr to)))))
7360 (if (default-value 'imenu-sort-function)
7362 (sort root-functions (default-value 'imenu-sort-function)))
7364 ;; Now add back packages removed from display
7365 (mapcar (function (lambda (elt)
7366 (setcdr to (cons (cons (concat "package " (car elt))
7369 (if (default-value 'imenu-sort-function)
7371 (sort root-packages (default-value 'imenu-sort-function)))
7375 ;;; '(keymap "Name1"
7379 ;;; ("Tail1" "x") ("Tail2" "y"))))
7381 (defun cperl-list-fold (list name limit)
7382 (let (list1 list2 elt1 (num 0))
7383 (if (<= (length list) limit) list
7384 (setq list1 nil list2 nil)
7389 (if (<= num imenu-max-items)
7390 (setq list2 (cons elt1 list2))
7391 (setq list1 (cons (cons name
7396 (nreverse (cons (cons name
7400 (defun cperl-menu-to-keymap (menu &optional name)
7406 (cond ((listp (cdr elt))
7407 (setq list (cperl-list-fold
7408 (cdr elt) (car elt) imenu-max-items))
7411 (cperl-menu-to-keymap list))))
7413 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
7414 (cperl-list-fold menu "Root" imenu-max-items)))))
7417 (defvar cperl-bad-style-regexp
7418 (mapconcat 'identity
7419 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
7420 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
7422 "Finds places such that insertion of a whitespace may help a lot.")
7424 (defvar cperl-not-bad-style-regexp
7427 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
7428 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
7429 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
7430 "<\\$?\\sw+\\(\\.\\(\\sw\\|_\\)+\\)?>" ; <IN> <stdin.h>
7431 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
7438 "\\\\[&$@*\\\\]" ; \&func
7441 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
7444 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
7445 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
7446 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
7450 "If matches at the start of match found by `my-bad-c-style-regexp',
7451 insertion of a whitespace will not help.")
7455 (defun cperl-find-bad-style ()
7456 "Find places in the buffer where insertion of a whitespace may help.
7457 Prompts user for insertion of spaces.
7458 Currently it is tuned to C and Perl syntax."
7460 (let (found-bad (p (point)))
7461 (setq last-nonmenu-event 13) ; To disable popup
7462 (goto-char (point-min))
7463 (map-y-or-n-p "Insert space here? "
7464 (lambda (arg) (insert " "))
7465 'cperl-next-bad-style
7466 '("location" "locations" "insert a space into")
7467 '((?\C-r (lambda (arg)
7468 (let ((buffer-quit-function
7469 'exit-recursive-edit))
7470 (message "Exit with Esc Esc")
7472 t)) ; Consider acted upon
7473 "edit, exit with Esc Esc")
7475 (let ((buffer-quit-function
7476 'exit-recursive-edit))
7477 (message "Exit with Esc Esc")
7479 t)) ; Consider acted upon
7480 "edit, exit with Esc Esc"))
7482 (if found-bad (goto-char found-bad)
7484 (message "No appropriate place found"))))
7486 (defun cperl-next-bad-style ()
7487 (let (p (not-found t) (point (point)) found)
7488 (while (and not-found
7489 (re-search-forward cperl-bad-style-regexp nil 'to-end))
7491 (goto-char (match-beginning 0))
7493 (looking-at cperl-not-bad-style-regexp)
7494 ;; Check for a < -b and friends
7495 (and (eq (following-char) ?\-)
7497 (skip-chars-backward " \t\n")
7498 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
7499 ;; Now check for syntax type
7501 (setq found (point))
7502 (beginning-of-defun)
7503 (let ((pps (parse-partial-sexp (point) found)))
7504 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
7505 (goto-char (match-end 0))
7513 (defvar cperl-have-help-regexp
7517 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
7518 "[$@]\\^[a-zA-Z]" ; Special variable
7519 "[$@][^ \n\t]" ; Special variable
7520 "-[a-zA-Z]" ; File test
7521 "\\\\[a-zA-Z0]" ; Special chars
7522 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
7523 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
7524 "[a-zA-Z_0-9:]+" ; symbol or number
7531 "Matches places in the buffer we can find help for.")
7533 (defvar cperl-message-on-help-error t)
7534 (defvar cperl-help-from-timer nil)
7536 (defun cperl-word-at-point-hard ()
7537 ;; Does not save-excursion
7538 ;; Get to the something meaningful
7539 (or (eobp) (eolp) (forward-char 1))
7540 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
7541 (save-excursion (beginning-of-line) (point))
7544 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
7545 ;; (skip-chars-backward " \n\t\r({[]});,")
7546 ;; (or (bobp) (backward-char 1))))
7549 ((looking-at "[a-zA-Z0-9_:]") ; symbol
7550 (skip-chars-backward "a-zA-Z0-9_:")
7552 ((and (eq (preceding-char) ?^) ; $^I
7553 (eq (char-after (- (point) 2)) ?\$))
7555 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
7557 ((and (eq (preceding-char) ?\=)
7558 (eq (current-column) 1))
7559 (forward-char -1))) ; =head1
7560 (if (and (eq (preceding-char) ?\<)
7561 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
7563 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
7565 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
7567 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
7568 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
7570 ((and (eq (preceding-char) ?\$)
7571 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
7573 ((and (eq (following-char) ?\>)
7574 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
7577 (and (eq (preceding-char) ?\<)
7578 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
7579 (search-backward "<"))))
7580 ((and (eq (following-char) ?\$)
7581 (eq (preceding-char) ?\<)
7582 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
7584 (if (looking-at cperl-have-help-regexp)
7585 (buffer-substring (match-beginning 0) (match-end 0))))
7587 (defun cperl-get-help ()
7588 "Get one-line docs on the symbol at the point.
7589 The data for these docs is a little bit obsolete and may be in fact longer
7590 than a line. Your contribution to update/shorten it is appreciated."
7592 (save-match-data ; May be called "inside" query-replace
7594 (let ((word (cperl-word-at-point-hard)))
7596 (if (and cperl-help-from-timer ; Bail out if not in mainland
7597 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
7598 (or (memq (get-text-property (point) 'face)
7599 '(font-lock-comment-face font-lock-string-face))
7600 (memq (get-text-property (point) 'syntax-type)
7601 '(pod here-doc format))))
7603 (cperl-describe-perl-symbol word))
7604 (if cperl-message-on-help-error
7605 (message "Nothing found for %s..."
7606 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
7608 ;;; Stolen from perl-descr.el by Johan Vromans:
7610 (defvar cperl-doc-buffer " *perl-doc*"
7611 "Where the documentation can be found.")
7613 (defun cperl-describe-perl-symbol (val)
7614 "Display the documentation of symbol at point, a Perl operator."
7615 (let ((enable-recursive-minibuffers t)
7618 ((string-match "^[&*][a-zA-Z_]" val)
7619 (setq val (concat (substring val 0 1) "NAME")))
7620 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
7621 (setq val (concat "@" (substring val 1 (match-end 1)))))
7622 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
7623 (setq val (concat "%" (substring val 1 (match-end 1)))))
7624 ((and (string= val "x") (string-match "^x=" val))
7626 ((string-match "^\\$[\C-a-\C-z]" val)
7627 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
7628 ((string-match "^CORE::" val)
7629 (setq val "CORE::"))
7630 ((string-match "^SUPER::" val)
7631 (setq val "SUPER::"))
7632 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
7633 (setq val "<NAME>")))
7634 (setq regexp (concat "^"
7635 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
7637 "\\([ \t([/]\\|$\\)"))
7639 ;; get the buffer with the documentation text
7640 (cperl-switch-to-doc-buffer)
7642 ;; lookup in the doc
7643 (goto-char (point-min))
7644 (let ((case-fold-search nil))
7646 (if (re-search-forward regexp (point-max) t)
7648 (beginning-of-line 1)
7649 (let ((lnstart (point)))
7651 (message "%s" (buffer-substring lnstart (point)))))
7652 (if cperl-message-on-help-error
7653 (message "No definition for %s" val)))))))
7655 (defvar cperl-short-docs 'please-ignore-this-line
7656 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
7657 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
7658 ... Range (list context); flip/flop [no flop when flip] (scalar context).
7659 ! ... Logical negation.
7660 ... != ... Numeric inequality.
7661 ... !~ ... Search pattern, substitution, or translation (negated).
7662 $! In numeric context: errno. In a string context: error string.
7663 $\" The separator which joins elements of arrays interpolated in strings.
7664 $# The output format for printed numbers. Default is %.15g or close.
7665 $$ Process number of this script. Changes in the fork()ed child process.
7666 $% The current page number of the currently selected output channel.
7668 The following variables are always local to the current block:
7670 $1 Match of the 1st set of parentheses in the last match (auto-local).
7671 $2 Match of the 2nd set of parentheses in the last match (auto-local).
7672 $3 Match of the 3rd set of parentheses in the last match (auto-local).
7673 $4 Match of the 4th set of parentheses in the last match (auto-local).
7674 $5 Match of the 5th set of parentheses in the last match (auto-local).
7675 $6 Match of the 6th set of parentheses in the last match (auto-local).
7676 $7 Match of the 7th set of parentheses in the last match (auto-local).
7677 $8 Match of the 8th set of parentheses in the last match (auto-local).
7678 $9 Match of the 9th set of parentheses in the last match (auto-local).
7679 $& The string matched by the last pattern match (auto-local).
7680 $' The string after what was matched by the last match (auto-local).
7681 $` The string before what was matched by the last match (auto-local).
7683 $( The real gid of this process.
7684 $) The effective gid of this process.
7685 $* Deprecated: Set to 1 to do multiline matching within a string.
7686 $+ The last bracket matched by the last search pattern.
7687 $, The output field separator for the print operator.
7688 $- The number of lines left on the page.
7689 $. The current input line number of the last filehandle that was read.
7690 $/ The input record separator, newline by default.
7691 $0 Name of the file containing the current perl script (read/write).
7692 $: String may be broken after these characters to fill ^-lines in a format.
7693 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
7694 $< The real uid of this process.
7695 $= The page length of the current output channel. Default is 60 lines.
7696 $> The effective uid of this process.
7697 $? The status returned by the last ``, pipe close or `system'.
7698 $@ The perl error message from the last eval or do @var{EXPR} command.
7699 $ARGV The name of the current file used with <> .
7700 $[ Deprecated: The index of the first element/char in an array/string.
7701 $\\ The output record separator for the print operator.
7702 $] The perl version string as displayed with perl -v.
7703 $^ The name of the current top-of-page format.
7704 $^A The current value of the write() accumulator for format() lines.
7705 $^D The value of the perl debug (-D) flags.
7706 $^E Information about the last system error other than that provided by $!.
7707 $^F The highest system file descriptor, ordinarily 2.
7708 $^H The current set of syntax checks enabled by `use strict'.
7709 $^I The value of the in-place edit extension (perl -i option).
7710 $^L What formats output to perform a formfeed. Default is \\f.
7711 $^M A buffer for emergency memory allocation when running out of memory.
7712 $^O The operating system name under which this copy of Perl was built.
7713 $^P Internal debugging flag.
7714 $^T The time the script was started. Used by -A/-M/-C file tests.
7715 $^W True if warnings are requested (perl -w flag).
7716 $^X The name under which perl was invoked (argv[0] in C-speech).
7717 $_ The default input and pattern-searching space.
7718 $| Auto-flush after write/print on current output channel? Default 0.
7719 $~ The name of the current report format.
7720 ... % ... Modulo division.
7721 ... %= ... Modulo division assignment.
7722 %ENV Contains the current environment.
7723 %INC List of files that have been require-d or do-ne.
7724 %SIG Used to set signal handlers for various signals.
7725 ... & ... Bitwise and.
7726 ... && ... Logical and.
7727 ... &&= ... Logical and assignment.
7728 ... &= ... Bitwise and assignment.
7729 ... * ... Multiplication.
7730 ... ** ... Exponentiation.
7731 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
7732 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
7733 ... + ... Addition. +EXPR Makes EXPR into scalar context.
7734 ++ Auto-increment (magical on strings). ++EXPR EXPR++
7735 ... += ... Addition assignment.
7737 ... - ... Subtraction.
7738 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
7739 ... -= ... Subtraction assignment.
7740 -A Access time in days since script started.
7741 -B File is a non-text (binary) file.
7742 -C Inode change time in days since script started.
7743 -M Age in days since script started.
7744 -O File is owned by real uid.
7745 -R File is readable by real uid.
7746 -S File is a socket .
7747 -T File is a text file.
7748 -W File is writable by real uid.
7749 -X File is executable by real uid.
7750 -b File is a block special file.
7751 -c File is a character special file.
7752 -d File is a directory.
7754 -f File is a plain file.
7755 -g File has setgid bit set.
7756 -k File has sticky bit set.
7757 -l File is a symbolic link.
7758 -o File is owned by effective uid.
7759 -p File is a named pipe (FIFO).
7760 -r File is readable by effective uid.
7761 -s File has non-zero size.
7762 -t Tests if filehandle (STDIN by default) is opened to a tty.
7763 -u File has setuid bit set.
7764 -w File is writable by effective uid.
7765 -x File is executable by effective uid.
7766 -z File has zero size.
7767 . Concatenate strings.
7768 .. Range (list context); flip/flop (scalar context) operator.
7769 .= Concatenate assignment strings
7770 ... / ... Division. /PATTERN/ioxsmg Pattern match
7771 ... /= ... Division assignment.
7772 /PATTERN/ioxsmg Pattern match.
7773 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
7774 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
7775 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
7776 <> Reads line from union of files in @ARGV (= command line) and STDIN.
7777 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
7778 ... <= ... Numeric less than or equal to.
7779 ... <=> ... Numeric compare.
7780 ... = ... Assignment.
7781 ... == ... Numeric equality.
7782 ... =~ ... Search pattern, substitution, or translation
7783 ... > ... Numeric greater than.
7784 ... >= ... Numeric greater than or equal to.
7785 ... >> ... Bitwise shift right.
7786 ... >>= ... Bitwise shift right assignment.
7787 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
7788 ?PATTERN? One-time pattern match.
7789 @ARGV Command line arguments (not including the command name - see $0).
7790 @INC List of places to look for perl scripts during do/include/use.
7791 @_ Parameter array for subroutines; result of split() unless in list context.
7792 \\ Creates reference to what follows, like \\$var, or quotes non-\\w in strings.
7793 \\0 Octal char, e.g. \\033.
7794 \\E Case modification terminator. See \\Q, \\L, and \\U.
7795 \\L Lowercase until \\E . See also \\l, lc.
7796 \\U Upcase until \\E . See also \\u, uc.
7797 \\Q Quote metacharacters until \\E . See also quotemeta.
7798 \\a Alarm character (octal 007).
7799 \\b Backspace character (octal 010).
7800 \\c Control character, e.g. \\c[ .
7801 \\e Escape character (octal 033).
7802 \\f Formfeed character (octal 014).
7803 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
7804 \\n Newline character (octal 012 on most systems).
7805 \\r Return character (octal 015 on most systems).
7806 \\t Tab character (octal 011).
7807 \\u Upcase the next character. See also \\U and \\l, ucfirst.
7808 \\x Hex character, e.g. \\x1b.
7809 ... ^ ... Bitwise exclusive or.
7810 __END__ Ends program source.
7811 __DATA__ Ends program source.
7812 __FILE__ Current (source) filename.
7813 __LINE__ Current line in current source.
7814 __PACKAGE__ Current package.
7815 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
7816 ARGVOUT Output filehandle with -i flag.
7817 BEGIN { ... } Immediately executed (during compilation) piece of code.
7818 END { ... } Pseudo-subroutine executed after the script finishes.
7819 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
7820 INIT { ... } Pseudo-subroutine executed before the script starts running.
7821 DATA Input filehandle for what follows after __END__ or __DATA__.
7822 accept(NEWSOCKET,GENERICSOCKET)
7835 ... cmp ... String compare.
7836 connect(SOCKET,NAME)
7837 continue of { block } continue { block }. Is executed after `next' or at end.
7839 crypt(PLAINTEXT,SALT)
7841 dbmopen(%HASH,DBNAME,MODE)
7845 do { ... }|SUBR while|until EXPR executes at least once
7846 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
7856 ... eq ... String equality.
7857 eval(EXPR) or eval { BLOCK }
7858 exec([TRUENAME] ARGV0, ARGVs) or exec(SHELL_COMMAND_LINE)
7861 fcntl(FILEHANDLE,FUNCTION,SCALAR)
7863 flock(FILEHANDLE,OPERATION)
7864 for (EXPR;EXPR;EXPR) { ... }
7865 foreach [VAR] (@ARRAY) { ... }
7867 ... ge ... String greater than or equal.
7872 gethostbyaddr(ADDR,ADDRTYPE)
7876 getnetbyaddr(ADDR,ADDRTYPE)
7882 getpriority(WHICH,WHO)
7883 getprotobyname(NAME)
7884 getprotobynumber(NUMBER)
7889 getservbyname(NAME,PROTO)
7890 getservbyport(PORT,PROTO)
7893 getsockopt(SOCKET,LEVEL,OPTNAME)
7896 ... gt ... String greater than.
7898 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
7899 index(STR,SUBSTR[,OFFSET])
7901 ioctl(FILEHANDLE,FUNCTION,SCALAR)
7906 ... le ... String less than or equal.
7908 link(OLDFILE,NEWFILE)
7909 listen(SOCKET,QUEUESIZE)
7913 lstat(EXPR|FILEHANDLE|VAR)
7914 ... lt ... String less than.
7916 mkdir(FILENAME,MODE)
7919 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
7920 msgsnd(ID,MSG,FLAGS)
7921 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
7922 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
7923 ... ne ... String inequality.
7926 open(FILEHANDLE[,EXPR])
7927 opendir(DIRHANDLE,EXPR)
7928 ord(EXPR) ASCII value of the first char of the string.
7930 package NAME Introduces package context.
7931 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
7933 print [FILEHANDLE] [(LIST)]
7934 printf [FILEHANDLE] (FORMAT,LIST)
7936 q/STRING/ Synonym for 'STRING'
7937 qq/STRING/ Synonym for \"STRING\"
7938 qx/STRING/ Synonym for `STRING`
7940 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7943 recv(SOCKET,SCALAR,LEN,FLAGS)
7945 rename(OLDNAME,NEWNAME)
7946 require [FILENAME | PERL_VERSION]
7950 rewinddir(DIRHANDLE)
7951 rindex(STR,SUBSTR[,OFFSET])
7953 s/PATTERN/REPLACEMENT/gieoxsm
7955 seek(FILEHANDLE,POSITION,WHENCE)
7956 seekdir(DIRHANDLE,POS)
7957 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
7958 semctl(ID,SEMNUM,CMD,ARG)
7959 semget(KEY,NSEMS,SIZE,FLAGS)
7961 send(SOCKET,MSG,FLAGS[,TO])
7963 sethostent(STAYOPEN)
7966 setpriority(WHICH,WHO,PRIORITY)
7967 setprotoent(STAYOPEN)
7969 setservent(STAYOPEN)
7970 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
7973 shmget(KEY,SIZE,FLAGS)
7974 shmread(ID,VAR,POS,SIZE)
7975 shmwrite(ID,STRING,POS,SIZE)
7976 shutdown(SOCKET,HOW)
7979 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
7980 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
7981 sort [SUBROUTINE] (LIST)
7982 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
7983 split[(/PATTERN/[,EXPR[,LIMIT]])]
7984 sprintf(FORMAT,LIST)
7987 stat(EXPR|FILEHANDLE|VAR)
7989 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
7990 substr(EXPR,OFFSET[,LEN])
7991 symlink(OLDFILE,NEWFILE)
7993 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7994 system([TRUENAME] ARGV0 [,ARGV]) or system(SHELL_COMMAND_LINE)
7995 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
8000 tr/SEARCHLIST/REPLACEMENTLIST/cds
8001 truncate(FILE|EXPR,LENGTH)
8004 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
8006 unpack(TEMPLATE,EXPR)
8008 until (EXPR) { ... } EXPR until EXPR
8011 vec(EXPR,OFFSET,BITS)
8014 wantarray Returns true if the sub/eval is called in list context.
8016 while (EXPR) { ... } EXPR while EXPR
8017 write[(EXPR|FILEHANDLE)]
8018 ... x ... Repeat string or array.
8019 x= ... Repetition assignment.
8020 y/SEARCHLIST/REPLACEMENTLIST/
8021 ... | ... Bitwise or.
8022 ... || ... Logical or.
8023 ~ ... Unary bitwise complement.
8024 #! OS interpreter indicator. If contains `perl', used for options, and -x.
8025 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
8026 CORE:: Prefix to access builtin function if imported sub obscures it.
8027 SUPER:: Prefix to lookup for a method in @ISA classes.
8028 DESTROY Shorthand for `sub DESTROY {...}'.
8029 ... EQ ... Obsolete synonym of `eq'.
8030 ... GE ... Obsolete synonym of `ge'.
8031 ... GT ... Obsolete synonym of `gt'.
8032 ... LE ... Obsolete synonym of `le'.
8033 ... LT ... Obsolete synonym of `lt'.
8034 ... NE ... Obsolete synonym of `ne'.
8035 abs [ EXPR ] absolute value
8036 ... and ... Low-precedence synonym for &&.
8037 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
8038 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
8039 chr Converts a number to char with the same ordinal.
8040 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
8041 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
8042 exists $HASH{KEY} True if the key exists.
8043 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
8044 formline PICTURE, LIST Backdoor into \"format\" processing.
8045 glob EXPR Synonym of <EXPR>.
8046 lc [ EXPR ] Returns lowercased EXPR.
8047 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
8048 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
8049 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
8050 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
8051 not ... Low-precedence synonym for ! - negation.
8052 ... or ... Low-precedence synonym for ||.
8053 pos STRING Set/Get end-position of the last match over this string, see \\G.
8054 quotemeta [ EXPR ] Quote regexp metacharacters.
8055 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
8056 readline FH Synonym of <FH>.
8057 readpipe CMD Synonym of `CMD`.
8058 ref [ EXPR ] Type of EXPR when dereferenced.
8059 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
8060 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
8061 tied Returns internal object for a tied data.
8062 uc [ EXPR ] Returns upcased EXPR.
8063 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
8064 untie VAR Unlink an object from a simple Perl variable.
8065 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
8066 ... xor ... Low-precedence synonym for exclusive or.
8067 prototype \\&SUB Returns prototype of the function given a reference.
8068 =head1 Top-level heading.
8069 =head2 Second-level heading.
8070 =head3 Third-level heading (is there such?).
8071 =over [ NUMBER ] Start list.
8072 =item [ TITLE ] Start new item in the list.
8074 =cut Switch from POD to Perl.
8075 =pod Switch from Perl to POD.
8078 (defun cperl-switch-to-doc-buffer (&optional interactive)
8079 "Go to the perl documentation buffer and insert the documentation."
8081 (let ((buf (get-buffer-create cperl-doc-buffer)))
8083 (switch-to-buffer-other-window buf)
8085 (if (= (buffer-size) 0)
8087 (insert (documentation-property 'cperl-short-docs
8088 'variable-documentation))
8089 (setq buffer-read-only t)))))
8091 (defun cperl-beautify-regexp-piece (b e embed level)
8092 ;; b is before the starting delimiter, e before the ending
8093 ;; e should be a marker, may be changed, but remains "correct".
8094 ;; EMBED is nil iff we process the whole REx.
8095 ;; The REx is guaranteed to have //x
8096 ;; LEVEL shows how many levels deep to go
8097 ;; position at enter and at leave is not defined
8098 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
8102 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
8106 ((looking-at "(\\?[^a-zA-Z]")
8108 ((looking-at "(\\?") ; (?i)
8112 (setq c (if embed (current-indentation) (1- (current-column)))
8113 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
8114 (or (looking-at "[ \t]*[\n#]")
8119 (if (re-search-forward "[^ \t]" e t)
8120 (progn ; Something before the ending delimiter
8122 (delete-horizontal-space)
8124 (cperl-make-indent c)
8125 (set-marker e (point))))
8128 (while (< (point) (marker-position e))
8132 (skip-chars-forward " \t")
8133 (delete-region s (point))
8134 (cperl-make-indent c1)
8138 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
8139 "\\|" ; Embedded variable
8140 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
8143 "\\|" ; simple-code simple-code*?
8144 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
8148 "\\((\\(\\?\\)?\\)" ; 7 8
8151 (goto-char (match-end 0))
8153 (cond ((match-beginning 1) ; Alphanum word + junk
8155 ((or (match-beginning 3) ; $ab[12]
8156 (and (match-beginning 5) ; X* X+ X{2,3}
8157 (eq (preceding-char) ?\{)))
8160 ((and ; [], already syntaxified
8163 cperl-use-syntax-table-text-property)
8166 (or (eq (preceding-char) ?\])
8167 (error "[]-group not terminated"))
8169 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8170 ((match-beginning 6) ; []
8172 (if (looking-at "\\^?\\]")
8173 (goto-char (match-end 0)))
8174 ;; XXXX POSIX classes?!
8175 (while (and (not pos)
8176 (re-search-forward "\\[:\\|\\]" e t))
8177 (if (eq (preceding-char) ?:)
8178 (or (re-search-forward ":\\]" e t)
8179 (error "[:POSIX:]-group in []-group not terminated"))
8181 (or (eq (preceding-char) ?\])
8182 (error "[]-group not terminated"))
8184 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8185 ((match-beginning 7) ; ()
8186 (goto-char (match-beginning 0))
8187 (setq pos (current-column))
8190 (delete-horizontal-space)
8192 (cperl-make-indent c1)))
8195 ;; (or (forward-sexp 1)
8198 ;; (error "()-group not terminated")))
8199 (set-marker m (1- (point)))
8200 (set-marker m1 (point))
8202 (if (progn ; indent rigidly if multiline
8203 ;; In fact does not make a lot of sense, since
8204 ;; the starting position can be already lost due
8205 ;; to insertion of "\n" and " "
8207 (search-forward "\n" m1 t))
8208 (indent-rigidly (point) m1 (- c1 pos)))
8209 (setq level (1- level))
8211 ((not (match-beginning 8))
8212 (cperl-beautify-regexp-piece tmp m t level))
8213 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
8215 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
8216 (goto-char (+ 2 tmp))
8218 (cperl-beautify-regexp-piece (point) m t level))
8219 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
8220 (goto-char (+ 3 tmp))
8221 (cperl-beautify-regexp-piece (point) m t level))
8223 (cperl-beautify-regexp-piece tmp m t level))))
8225 (cond ((looking-at "[*+?]\\??")
8226 (goto-char (match-end 0)))
8227 ((eq (following-char) ?\{)
8229 (if (eq (following-char) ?\?)
8231 (skip-chars-forward " \t")
8233 (if (looking-at "[#\n]")
8235 (or (eolp) (indent-for-comment))
8236 (beginning-of-line 2))
8237 (delete-horizontal-space)
8241 ((match-beginning 9) ; |
8245 (if (re-search-forward "[^ \t]" tmp t)
8248 (delete-horizontal-space)
8251 (delete-region (point) tmp))
8252 (cperl-make-indent c)
8254 (skip-chars-forward " \t")
8256 (if (looking-at "[#\n]")
8257 (beginning-of-line 2)
8258 (delete-horizontal-space)
8262 (or (looking-at "[ \t\n]")
8265 (skip-chars-forward " \t"))
8266 (or (looking-at "[#\n]")
8267 (error "Unknown code `%s' in a regexp"
8268 (buffer-substring (point) (1+ (point)))))
8269 (and inline (end-of-line 2)))
8270 ;; Special-case the last line of group
8271 (if (and (>= (point) (marker-position e))
8272 (/= (current-indentation) c))
8275 (cperl-make-indent c)))))
8277 (defun cperl-make-regexp-x ()
8278 ;; Returns position of the start
8279 ;; XXX this is called too often! Need to cache the result!
8281 (or cperl-use-syntax-table-text-property
8282 (error "I need to have a regexp marked!"))
8284 (if (looking-at "\\s|")
8286 (if (looking-at "\\([smy]\\|qr\\)\\s|")
8288 (re-search-backward "\\s|"))) ; Assume it is scanned already.
8290 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
8291 (sub-p (eq (preceding-char) ?s)) s)
8293 (set-marker e (1- (point)))
8294 (setq delim (preceding-char))
8295 (if (and sub-p (eq delim (char-after (- (point) 2))))
8296 (error "Possible s/blah// - do not know how to deal with"))
8297 (if sub-p (forward-sexp 1))
8298 (if (looking-at "\\sw*x")
8301 ;; Protect fragile " ", "#"
8304 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
8310 (defun cperl-beautify-regexp (&optional deep)
8311 "Do it. (Experimental, may change semantics, recheck the result.)
8312 We suppose that the regexp is scanned already."
8314 (setq deep (if deep (prefix-numeric-value deep) -1))
8316 (goto-char (cperl-make-regexp-x))
8317 (let ((b (point)) (e (make-marker)))
8319 (set-marker e (1- (point)))
8320 (cperl-beautify-regexp-piece b e nil deep))))
8322 (defun cperl-regext-to-level-start ()
8323 "Goto start of an enclosing group in regexp.
8324 We suppose that the regexp is scanned already."
8326 (let ((limit (cperl-make-regexp-x)) done)
8328 (or (eq (following-char) ?\()
8329 (search-backward "(" (1+ limit) t)
8330 (error "Cannot find `(' which starts a group"))
8333 (skip-chars-backward "\\")
8334 (looking-at "\\(\\\\\\\\\\)*(")))
8335 (or done (forward-char -1)))))
8337 (defun cperl-contract-level ()
8338 "Find an enclosing group in regexp and contract it.
8339 \(Experimental, may change semantics, recheck the result.)
8340 We suppose that the regexp is scanned already."
8342 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
8343 (cperl-regext-to-level-start)
8344 (let ((b (point)) (e (make-marker)) c)
8346 (set-marker e (1- (point)))
8348 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
8350 ((match-beginning 1) ; #-comment
8351 (or c (setq c (current-indentation)))
8352 (beginning-of-line 2) ; Skip
8353 (cperl-make-indent c))
8356 (just-one-space))))))
8358 (defun cperl-contract-levels ()
8359 "Find an enclosing group in regexp and contract all the kids.
8360 \(Experimental, may change semantics, recheck the result.)
8361 We suppose that the regexp is scanned already."
8365 (cperl-regext-to-level-start)
8366 (error ; We are outside outermost group
8367 (goto-char (cperl-make-regexp-x))))
8368 (let ((b (point)) (e (make-marker)) s c)
8370 (set-marker e (1- (point)))
8372 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
8374 ((match-beginning 1) ; Skip
8377 (cperl-contract-level)))))))
8379 (defun cperl-beautify-level (&optional deep)
8380 "Find an enclosing group in regexp and beautify it.
8381 \(Experimental, may change semantics, recheck the result.)
8382 We suppose that the regexp is scanned already."
8384 (setq deep (if deep (prefix-numeric-value deep) -1))
8386 (cperl-regext-to-level-start)
8387 (let ((b (point)) (e (make-marker)))
8389 (set-marker e (1- (point)))
8390 (cperl-beautify-regexp-piece b e nil deep))))
8392 (defun cperl-invert-if-unless-modifiers ()
8393 "Change `B if A;' into `if (A) {B}' etc if possible.
8396 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string
8397 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>"))
8398 (and (= (char-syntax (preceding-char)) ?w)
8400 (setq pre-if (point))
8401 (cperl-backward-to-start-of-expr)
8402 (setq pre-B (point))
8403 (forward-sexp 1) ; otherwise forward-to-end-of-expr is NOP
8404 (cperl-forward-to-end-of-expr)
8405 (setq post-A (point))
8407 (or (looking-at w-rex)
8408 ;; Find the position
8409 (progn (goto-char post-A)
8411 (not (looking-at w-rex))
8414 (setq pre-if (point))))
8415 (or (looking-at w-rex)
8416 (error "Can't find `if', `unless', `while', `until', `for' or `foreach'"))
8417 ;; 1 B 2 ... 3 B-com ... 4 if 5 ... if-com 6 ... 7 A 8
8418 (setq if-string (buffer-substring (match-beginning 0) (match-end 0)))
8419 ;; First, simple part: find code boundaries
8421 (setq post-if (point))
8424 (setq post-B (point))
8425 (cperl-backward-to-start-of-expr)
8426 (setq pre-B (point))
8427 (setq B (buffer-substring pre-B post-B))
8431 ;; May be after $, @, $# etc of a variable
8432 (skip-chars-backward "$@%#")
8433 (setq pre-A (point))
8434 (cperl-forward-to-end-of-expr)
8435 (setq post-A (point))
8436 (setq A (buffer-substring pre-A post-A))
8437 ;; Now modify (from end, to not break the stuff)
8438 (skip-chars-forward " \t;")
8439 (delete-region pre-A (point)) ; we move to pre-A
8440 (insert "\n" B ";\n}")
8441 (and (looking-at "[ \t]*#") (cperl-indent-for-comment))
8442 (delete-region pre-if post-if)
8443 (delete-region pre-B post-B)
8445 (insert if-string " (" A ") {")
8446 (setq post-B (point))
8447 (if (looking-at "[ \t]+$")
8448 (delete-horizontal-space)
8449 (if (looking-at "[ \t]*#")
8450 (cperl-indent-for-comment)
8453 (if (looking-at "[ \t]*$")
8454 (progn ; delete line
8455 (delete-horizontal-space)
8456 (delete-region (point) (1+ (point)))))
8458 (goto-char (1- post-B))
8463 (defun cperl-invert-if-unless ()
8464 "Change `if (A) {B}' into `B if A;' etc (or visa versa) if possible.
8465 If the cursor is not on the leading keyword of the BLOCK flavor of
8466 construct, will assume it is the STATEMENT flavor, so will try to find
8467 the appropriate statement modifier."
8469 (and (= (char-syntax (preceding-char)) ?w)
8471 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
8472 (let ((pre-if (point))
8473 pre-A post-A pre-B post-B A B state p end-B-code is-block B-comment
8474 (if-string (buffer-substring (match-beginning 0) (match-end 0))))
8476 (setq post-A (point))
8478 (setq pre-A (point))
8479 (setq is-block (and (eq (following-char) ?\( )
8485 (eq (following-char) ?\{ ))
8491 (setq post-B (point))
8493 (setq pre-B (point))
8494 (if (and (eq (following-char) ?\{ )
8496 (cperl-backward-to-noncomment post-A)
8497 (eq (preceding-char) ?\) )))
8498 (if (condition-case nil
8503 (looking-at "\\<els\\(e\\|if\\)\\>"))
8506 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" if-string)
8507 (goto-char (1- post-B))
8508 (cperl-backward-to-noncomment pre-B)
8509 (if (eq (preceding-char) ?\;)
8511 (setq end-B-code (point))
8513 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" end-B-code t)
8514 (setq p (match-beginning 0)
8515 A (buffer-substring p (match-end 0))
8516 state (parse-partial-sexp pre-B p))
8520 (error "`%s' inside `%s' BLOCK" A if-string))
8521 (goto-char (match-end 0)))
8523 (goto-char (1+ pre-B))
8524 (skip-chars-forward " \t\n")
8525 (setq B (buffer-substring (point) end-B-code))
8526 (goto-char end-B-code)
8527 (or (looking-at ";?[ \t\n]*}")
8529 (skip-chars-forward "; \t\n")
8531 (buffer-substring (point) (1- post-B)))))
8534 (goto-char (1- post-A))
8535 (cperl-backward-to-noncomment pre-A)
8536 (or (looking-at "[ \t\n]*)")
8537 (goto-char (1- post-A)))
8539 (goto-char (1+ pre-A))
8540 (skip-chars-forward " \t\n")
8541 (setq A (buffer-substring (point) p))
8542 (delete-region pre-B post-B)
8543 (delete-region pre-A post-A)
8546 (and B-comment (insert B-comment " "))
8549 (setq pre-A (point))
8551 (delete-horizontal-space)
8552 (setq post-B (point))
8553 (if (looking-at "#")
8554 (indent-for-comment))
8557 (delete-horizontal-space)
8561 (setq pre-A (set-marker (make-marker) pre-A))
8562 (while (<= (point) (marker-position pre-A))
8565 (goto-char (marker-position pre-A))
8569 (indent-for-comment)
8570 (goto-char (marker-position pre-A)))))
8571 (error "`%s' (EXPR) not with an {BLOCK}" if-string)))
8572 ;; (error "`%s' not with an (EXPR)" if-string)
8574 (cperl-invert-if-unless-modifiers)))
8575 ;;(error "Not at `if', `unless', `while', `until', `for' or `foreach'")
8576 (cperl-invert-if-unless-modifiers)))
8578 ;;; By Anthony Foiani <afoiani@uswest.com>
8579 ;;; Getting help on modules in C-h f ?
8580 ;;; This is a modified version of `man'.
8581 ;;; Need to teach it how to lookup functions
8583 (defun cperl-perldoc (word)
8584 "Run `perldoc' on WORD."
8586 (list (let* ((default-entry (cperl-word-at-point))
8588 (format "perldoc entry%s: "
8589 (if (string= default-entry "")
8591 (format " (default %s)" default-entry))))))
8592 (if (string= input "")
8593 (if (string= default-entry "")
8594 (error "No perldoc args given")
8598 (let* ((case-fold-search nil)
8600 (string-match "^[a-z]+$" word)
8601 (string-match (concat "^" word "\\>")
8602 (documentation-property
8604 'variable-documentation))))
8605 (manual-program (if is-func "perldoc -f" "perldoc")))
8608 (let ((Manual-program "perldoc")
8609 (Manual-switches (if is-func (list "-f"))))
8610 (manual-entry word)))
8612 (Man-getpage-in-background word)))))
8615 (defun cperl-perldoc-at-point ()
8616 "Run a `perldoc' on the word around point."
8618 (cperl-perldoc (cperl-word-at-point)))
8620 (defcustom pod2man-program "pod2man"
8621 "*File name for `pod2man'."
8625 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
8626 (defun cperl-pod-to-manpage ()
8627 "Create a virtual manpage in Emacs from the Perl Online Documentation."
8630 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
8631 (bufname (concat "Man " buffer-file-name))
8632 (buffer (generate-new-buffer bufname)))
8635 (let ((process-environment (copy-sequence process-environment)))
8636 ;; Prevent any attempt to use display terminal fanciness.
8637 (setenv "TERM" "dumb")
8638 (set-process-sentinel
8639 (start-process pod2man-program buffer "sh" "-c"
8640 (format (cperl-pod2man-build-command) pod2man-args))
8641 'Man-bgproc-sentinel)))))
8643 ;;; Updated version by him too
8644 (defun cperl-build-manpage ()
8645 "Create a virtual manpage in Emacs from the POD in the file."
8650 (let ((Manual-program "perldoc"))
8651 (manual-entry buffer-file-name)))
8653 (let* ((manual-program "perldoc"))
8654 (Man-getpage-in-background buffer-file-name)))))
8656 (defun cperl-pod2man-build-command ()
8657 "Builds the entire background manpage and cleaning command."
8658 (let ((command (concat pod2man-program " %s 2>/dev/null"))
8659 (flist (and (boundp 'Man-filter-list) Man-filter-list)))
8660 (while (and flist (car flist))
8661 (let ((pcom (car (car flist)))
8662 (pargs (cdr (car flist))))
8664 (concat command " | " pcom " "
8665 (mapconcat '(lambda (phrase)
8666 (if (not (stringp phrase))
8667 (error "Malformed Man-filter-list"))
8670 (setq flist (cdr flist))))
8674 (defun cperl-next-interpolated-REx-1 ()
8675 "Move point to next REx which has interpolated parts without //o.
8676 Skips RExes consisting of one interpolated variable.
8678 Note that skipped RExen are not performance hits."
8680 (cperl-next-interpolated-REx 1))
8682 (defun cperl-next-interpolated-REx-0 ()
8683 "Move point to next REx which has interpolated parts without //o."
8685 (cperl-next-interpolated-REx 0))
8687 (defun cperl-next-interpolated-REx (&optional skip beg limit)
8688 "Move point to next REx which has interpolated parts.
8689 SKIP is a list of possible types to skip, BEG and LIMIT are the starting
8690 point and the limit of search (default to point and end of buffer).
8692 SKIP may be a number, then it behaves as list of numbers up to SKIP; this
8693 semantic may be used as a numeric argument.
8695 Types are 0 for / $rex /o (interpolated once), 1 for /$rex/ (if $rex is
8696 a result of qr//, this is not a performance hit), t for the rest."
8698 (if (numberp skip) (setq skip (list 0 skip)))
8699 (or beg (setq beg (point)))
8700 (or limit (setq limit (point-max))) ; needed for n-s-p-c
8702 (and (eq (get-text-property beg 'syntax-type) 'string)
8703 (setq beg (next-single-property-change beg 'syntax-type nil limit)))
8704 (cperl-map-pods-heres
8705 (function (lambda (s e p)
8706 (if (memq (get-text-property s 'REx-interpolated) skip)
8710 'REx-interpolated beg limit)
8711 (if pp (goto-char pp)
8712 (message "No more interpolated REx"))))
8714 ;;; Initial version contributed by Trey Belew
8715 (defun cperl-here-doc-spell (&optional beg end)
8716 "Spell-check HERE-documents in the Perl buffer.
8717 If a region is highlighted, restricts to the region."
8719 (cperl-pod-spell t beg end))
8721 (defun cperl-pod-spell (&optional do-heres beg end)
8722 "Spell-check POD documentation.
8723 If invoked with prefix argument, will do HERE-DOCs instead.
8724 If a region is highlighted, restricts to the region."
8728 (if (cperl-mark-active)
8729 (setq beg (min (mark) (point))
8730 end (max (mark) (point)))
8731 (setq beg (point-min)
8733 (cperl-map-pods-heres (function
8736 (setq e (save-excursion
8742 (if do-heres 'here-doc-group 'in-pod)
8745 (defun cperl-map-pods-heres (func &optional prop s end)
8746 "Executes a function over regions of pods or here-documents.
8747 PROP is the text-property to search for; default to `in-pod'. Stop when
8748 function returns nil."
8749 (let (pos posend has-prop (cont t))
8750 (or prop (setq prop 'in-pod))
8751 (or s (setq s (point-min)))
8752 (or end (setq end (point-max)))
8753 (cperl-update-syntaxification end end)
8755 (goto-char (setq pos s))
8756 (while (and cont (< pos end))
8757 (setq has-prop (get-text-property pos prop))
8758 (setq posend (next-single-property-change pos prop nil end))
8760 (setq cont (funcall func pos posend prop)))
8761 (setq pos posend)))))
8763 ;;; Based on code by Masatake YAMATO:
8764 (defun cperl-get-here-doc-region (&optional pos pod)
8765 "Return HERE document region around the point.
8766 Return nil if the point is not in a HERE document region. If POD is non-nil,
8767 will return a POD section if point is in a POD section."
8768 (or pos (setq pos (point)))
8769 (cperl-update-syntaxification pos pos)
8770 (if (or (eq 'here-doc (get-text-property pos 'syntax-type))
8772 (eq 'pod (get-text-property pos 'syntax-type))))
8773 (let ((b (cperl-beginning-of-property pos 'syntax-type))
8774 (e (next-single-property-change pos 'syntax-type)))
8775 (cons b (or e (point-max))))))
8777 (defun cperl-narrow-to-here-doc (&optional pos)
8778 "Narrows editing region to the HERE-DOC at POS.
8779 POS defaults to the point."
8781 (or pos (setq pos (point)))
8782 (let ((p (cperl-get-here-doc-region pos)))
8783 (or p (error "Not inside a HERE document"))
8784 (narrow-to-region (car p) (cdr p))
8786 "When you are finished with narrow editing, type C-x n w")))
8788 (defun cperl-select-this-pod-or-here-doc (&optional pos)
8789 "Select the HERE-DOC (or POD section) at POS.
8790 POS defaults to the point."
8792 (let ((p (cperl-get-here-doc-region pos t)))
8796 (push-mark (cdr p) nil t)) ; Message, activate in transient-mode
8797 (message "I do not think POS is in POD or a HERE-doc..."))))
8799 (defun cperl-facemenu-add-face-function (face end)
8800 "A callback to process user-initiated font-change requests.
8801 Translates `bold', `italic', and `bold-italic' requests to insertion of
8802 corresponding POD directives, and `underline' to C<> POD directive.
8804 Such requests are usually bound to M-o LETTER."
8805 (or (get-text-property (point) 'in-pod)
8806 (error "Faces can only be set within POD"))
8807 (setq facemenu-end-add-face (if (eq face 'bold-italic) ">>" ">"))
8808 (cdr (or (assq face '((bold . "B<")
8810 (bold-italic . "B<I<")
8811 (underline . "C<")))
8812 (error "Face %s not configured for cperl-mode"
8815 (defun cperl-time-fontification (&optional l step lim)
8816 "Times how long it takes to do incremental fontification in a region.
8817 L is the line to start at, STEP is the number of lines to skip when
8818 doing next incremental fontification, LIM is the maximal number of
8819 incremental fontification to perform. Messages are accumulated in
8822 May be used for pinpointing which construct slows down buffer fontification:
8823 start with default arguments, then refine the slowdown regions."
8824 (interactive "nLine to start at: \nnStep to do incremental fontification: ")
8826 (or step (setq step 500))
8827 (or lim (setq lim 40))
8828 (let* ((timems (function (lambda ()
8829 (let ((tt (current-time)))
8830 (+ (* 1000 (nth 1 tt)) (/ (nth 2 tt) 1000))))))
8831 (tt (funcall timems)) (c 0) delta tot)
8834 (setq tot (- (- tt (setq tt (funcall timems)))))
8835 (message "cperl-mode at %s: %s" l tot)
8836 (while (and (< c lim) (not (eobp)))
8840 (cperl-update-syntaxification (point) (point))
8841 (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
8842 (message "to %s:%6s,%7s" l delta tot))
8845 (defun cperl-emulate-lazy-lock (&optional window-size)
8846 "Emulate `lazy-lock' without `condition-case', so `debug-on-error' works.
8847 Start fontifying the buffer from the start (or end) using the given
8848 WINDOW-SIZE (units is lines). Negative WINDOW-SIZE starts at end, and
8849 goes backwards; default is -50. This function is not CPerl-specific; it
8850 may be used to debug problems with delayed incremental fontification."
8852 "nSize of window for incremental fontification, negative goes backwards: ")
8853 (or window-size (setq window-size -50))
8854 (let ((pos (if (> window-size 0)
8860 ;; Why needed??? With older font-locks???
8861 (set (make-local-variable 'font-lock-cache-position) (make-marker))
8862 (while (if (> window-size 0)
8864 (> pos (point-min)))
8866 (forward-line window-size)
8868 (font-lock-fontify-region (min p pos) (max p pos))
8872 (defun cperl-lazy-install ()) ; Avoid a warning
8873 (defun cperl-lazy-unstall ()) ; Avoid a warning
8875 (if (fboundp 'run-with-idle-timer)
8877 (defvar cperl-help-shown nil
8878 "Non-nil means that the help was already shown now.")
8880 (defvar cperl-lazy-installed nil
8881 "Non-nil means that the lazy-help handlers are installed now.")
8883 (defun cperl-lazy-install ()
8884 "Switches on Auto-Help on Perl constructs (put in the message area).
8885 Delay of auto-help controlled by `cperl-lazy-help-time'."
8887 (make-local-variable 'cperl-help-shown)
8888 (if (and (cperl-val 'cperl-lazy-help-time)
8889 (not cperl-lazy-installed))
8891 (add-hook 'post-command-hook 'cperl-lazy-hook)
8892 (run-with-idle-timer
8893 (cperl-val 'cperl-lazy-help-time 1000000 5)
8895 'cperl-get-help-defer)
8896 (setq cperl-lazy-installed t))))
8898 (defun cperl-lazy-unstall ()
8899 "Switches off Auto-Help on Perl constructs (put in the message area).
8900 Delay of auto-help controlled by `cperl-lazy-help-time'."
8902 (remove-hook 'post-command-hook 'cperl-lazy-hook)
8903 (cancel-function-timers 'cperl-get-help-defer)
8904 (setq cperl-lazy-installed nil))
8906 (defun cperl-lazy-hook ()
8907 (setq cperl-help-shown nil))
8909 (defun cperl-get-help-defer ()
8910 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
8911 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
8913 (setq cperl-help-shown t))))
8914 (cperl-lazy-install)))
8917 ;;; Plug for wrong font-lock:
8919 (defun cperl-font-lock-unfontify-region-function (beg end)
8920 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
8921 (inhibit-read-only t) (inhibit-point-motion-hooks t)
8922 before-change-functions after-change-functions
8923 deactivate-mark buffer-file-name buffer-file-truename)
8924 (remove-text-properties beg end '(face nil))
8925 (if (and (not modified) (buffer-modified-p))
8926 (set-buffer-modified-p nil))))
8928 (defun cperl-font-lock-fontify-region-function (beg end loudly)
8929 "Extends the region to safe positions, then calls the default function.
8930 Newer `font-lock's can do it themselves.
8931 We unwind only as far as needed for fontification. Syntaxification may
8932 do extra unwind via `cperl-unwind-to-safe'."
8938 (eq (get-text-property (setq beg (point)) 'syntax-type)
8940 (if (setq beg (cperl-beginning-of-property beg 'syntax-type))
8946 (or (bolp) (condition-case nil
8949 (eq (get-text-property (setq end (point)) 'syntax-type)
8951 (setq end (next-single-property-change end 'syntax-type nil (point-max)))
8954 (font-lock-default-fontify-region beg end loudly))
8956 (defvar cperl-d-l nil)
8957 (defun cperl-fontify-syntaxically (end)
8958 ;; Some vars for debugging only
8959 ;; (message "Syntaxifying...")
8960 (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
8961 (istate (car cperl-syntax-state))
8962 start from-start edebug-backtrace-buffer)
8963 (if (eq cperl-syntaxify-by-font-lock 'backtrace)
8966 (let ((f 'edebug-backtrace))
8967 (funcall f)))) ; Avoid compile-time warning
8968 (or cperl-syntax-done-to
8969 (setq cperl-syntax-done-to (point-min)
8971 (setq start (if (and cperl-hook-after-change
8973 cperl-syntax-done-to ; Fontify without change; ignore start
8974 ;; Need to forget what is after `start'
8975 (min cperl-syntax-done-to (point))))
8978 (setq start (point))
8979 (and cperl-syntaxify-unwind
8980 (setq end (cperl-unwind-to-safe t end)
8983 (setq cperl-syntax-done-to start) ; In case what follows fails
8984 (cperl-find-pods-heres start end t nil t))
8985 (if (memq cperl-syntaxify-by-font-lock '(backtrace message))
8986 (message "Syxify req=%s..%s actual=%s..%s done-to: %s=>%s statepos: %s=>%s"
8987 dbg iend start end idone cperl-syntax-done-to
8988 istate (car cperl-syntax-state))) ; For debugging
8989 nil)) ; Do not iterate
8991 (defun cperl-fontify-update (end)
8992 (let ((pos (point-min)) prop posend)
8993 (setq end (point-max))
8995 (setq prop (get-text-property pos 'cperl-postpone)
8996 posend (next-single-property-change pos 'cperl-postpone nil end))
8997 (and prop (put-text-property pos posend (car prop) (cdr prop)))
8999 nil) ; Do not iterate
9001 (defun cperl-fontify-update-bad (end)
9002 ;; Since fontification happens with different region than syntaxification,
9003 ;; do to the end of buffer, not to END;;; likewise, start earlier if needed
9004 (let* ((pos (point)) (prop (get-text-property pos 'cperl-postpone)) posend)
9006 (setq pos (or (cperl-beginning-of-property
9007 (cperl-1+ pos) 'cperl-postpone)
9010 (setq posend (next-single-property-change pos 'cperl-postpone))
9011 (and prop (put-text-property pos posend (car prop) (cdr prop)))
9013 (setq prop (get-text-property pos 'cperl-postpone))))
9014 nil) ; Do not iterate
9016 ;; Called when any modification is made to buffer text.
9017 (defun cperl-after-change-function (beg end old-len)
9018 ;; We should have been informed about changes by `font-lock'. Since it
9019 ;; does not inform as which calls are defered, do it ourselves
9020 (if cperl-syntax-done-to
9021 (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
9023 (defun cperl-update-syntaxification (from to)
9024 (if (and cperl-use-syntax-table-text-property
9025 cperl-syntaxify-by-font-lock
9026 (or (null cperl-syntax-done-to)
9027 (< cperl-syntax-done-to to)))
9031 (cperl-fontify-syntaxically to)))))
9033 (defvar cperl-version
9034 (let ((v "Revision: 5.22"))
9035 (string-match ":\\s *\\([0-9.]+\\)" v)
9036 (substring v (match-beginning 1) (match-end 1)))
9037 "Version of IZ-supported CPerl package this file is based on.")
9039 (provide 'cperl-mode)
9041 ;;; arch-tag: 42e5b19b-e187-4537-929f-1a7408980ce6
9042 ;;; cperl-mode.el ends here