1 ;;; cperl-mode.el --- Perl code editing commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 ;; 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
5 ;; Free Software Foundation, Inc.
7 ;; Author: Ilya Zakharevich and Bob Olson
8 ;; Maintainer: Ilya Zakharevich <ilyaz@cpan.org>
9 ;; Keywords: languages, Perl
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
28 ;;; Corrections made by Ilya Zakharevich ilyaz@cpan.org
32 ;; You can either fine-tune the bells and whistles of this mode or
33 ;; bulk enable them by putting
35 ;; (setq cperl-hairy t)
37 ;; in your .emacs file. (Emacs rulers do not consider it politically
38 ;; correct to make whistles enabled by default.)
40 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
41 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
42 ;; `cperl-praise', `cperl-speed'. <<<<<<
44 ;; The mode information (on C-h m) provides some customization help.
45 ;; If you use font-lock feature of this mode, it is advisable to use
46 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
48 ;; Faces used now: three faces for first-class and second-class keywords
49 ;; and control flow words, one for each: comments, string, labels,
50 ;; functions definitions and packages, arrays, hashes, and variable
51 ;; definitions. If you do not see all these faces, your font-lock does
52 ;; not define them, so you need to define them manually.
54 ;; This mode supports font-lock, imenu and mode-compile. In the
55 ;; hairy version font-lock is on, but you should activate imenu
56 ;; yourself (note that mode-compile is not standard yet). Well, you
57 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
58 ;; to bind it like that:
60 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
62 ;;; Font lock bugs as of v4.32:
64 ;; The following kinds of Perl code erroneously start strings:
66 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
67 ;; likewise with m, tr, y, q, qX instead of s
71 (defvar vc-rcs-header
)
72 (defvar vc-sccs-header
)
81 (defconst cperl-xemacs-p
(string-match "XEmacs\\|Lucid" emacs-version
))
82 (defvar cperl-can-font-lock
84 (and (boundp 'emacs-major-version
)
86 (> emacs-major-version
20)))))
87 (if cperl-can-font-lock
89 (defvar msb-menu-cond
)
90 (defvar gud-perldb-history
)
91 (defvar font-lock-background-mode
) ; not in Emacs
92 (defvar font-lock-display-type
) ; ditto
93 (defvar paren-backwards-message
) ; Not in newer XEmacs?
94 (or (fboundp 'defgroup
)
95 (defmacro defgroup
(name val doc
&rest arr
)
97 (or (fboundp 'custom-declare-variable
)
98 (defmacro defcustom
(name val doc
&rest arr
)
99 (` (defvar (, name
) (, val
) (, doc
)))))
100 (or (and (fboundp 'custom-declare-variable
)
101 (string< "19.31" emacs-version
)) ; Checked with 19.30: defface does not work
102 (defmacro defface
(&rest arr
)
104 ;; Avoid warning (tmp definitions)
105 (or (fboundp 'x-color-defined-p
)
106 (defmacro x-color-defined-p
(col)
107 (cond ((fboundp 'color-defined-p
) (` (color-defined-p (, col
))))
109 ((fboundp 'valid-color-name-p
) (` (valid-color-name-p (, col
))))
111 ((fboundp 'x-valid-color-name-p
) (` (x-valid-color-name-p (, col
))))
112 (t '(error "Cannot implement color-defined-p")))))
113 (defmacro cperl-is-face
(arg) ; Takes quoted arg
114 (cond ((fboundp 'find-face
)
115 (` (find-face (, arg
))))
116 (;;(and (fboundp 'face-list)
119 (` (member (, arg
) (and (fboundp 'face-list
)
122 (` (boundp (, arg
))))))
123 (defmacro cperl-make-face
(arg descr
) ; Takes unquoted arg
124 (cond ((fboundp 'make-face
)
125 (` (make-face (quote (, arg
)))))
127 (` (defvar (, arg
) (quote (, arg
)) (, descr
))))))
128 (defmacro cperl-force-face
(arg descr
) ; Takes unquoted arg
130 (or (cperl-is-face (quote (, arg
)))
131 (cperl-make-face (, arg
) (, descr
)))
132 (or (boundp (quote (, arg
))) ; We use unquoted variants too
133 (defvar (, arg
) (quote (, arg
)) (, descr
))))))
135 (defmacro cperl-etags-snarf-tag
(file line
)
137 (beginning-of-line 2)
138 (list (, file
) (, line
)))))
139 (defmacro cperl-etags-snarf-tag
(file line
)
140 (` (etags-snarf-tag))))
142 (defmacro cperl-etags-goto-tag-location
(elt)
144 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
145 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
146 ;; Probably will not work due to some save-excursion???
147 ;; Or save-file-position?
148 ;; (message "Did I get to line %s?" (elt (, elt) 1))
149 (goto-line (string-to-int (elt (, elt
) 1)))))
151 (defmacro cperl-etags-goto-tag-location
(elt)
152 (` (etags-goto-tag-location (, elt
))))))
154 (defconst cperl-xemacs-p
(string-match "XEmacs\\|Lucid" emacs-version
))
156 (defvar cperl-can-font-lock
158 (and (boundp 'emacs-major-version
)
160 (> emacs-major-version
20)))))
162 (defun cperl-choose-color (&rest list
)
166 (if (or (x-color-defined-p (car list
))
168 (setq answer
(car list
))))
169 (setq list
(cdr list
)))
173 "Major mode for editing Perl code."
178 (defgroup cperl-indentation-details nil
183 (defgroup cperl-affected-by-hairy nil
184 "Variables affected by `cperl-hairy'."
188 (defgroup cperl-autoinsert-details nil
189 "Auto-insert tuneup."
193 (defgroup cperl-faces nil
194 "Fontification colors."
195 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
199 (defgroup cperl-speed nil
200 "Speed vs. validity tuneup."
204 (defgroup cperl-help-system nil
205 "Help system tuneup."
210 (defcustom cperl-extra-newline-before-brace nil
211 "*Non-nil means that if, elsif, while, until, else, for, foreach
212 and do constructs look like:
223 :group
'cperl-autoinsert-details
)
225 (defcustom cperl-extra-newline-before-brace-multiline
226 cperl-extra-newline-before-brace
227 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
228 for constructs with multiline if/unless/while/until/for/foreach condition."
230 :group
'cperl-autoinsert-details
)
232 (defcustom cperl-indent-level
2
233 "*Indentation of CPerl statements with respect to containing block."
235 :group
'cperl-indentation-details
)
237 (defcustom cperl-lineup-step nil
238 "*`cperl-lineup' will always lineup at multiple of this number.
239 If nil, the value of `cperl-indent-level' will be used."
240 :type
'(choice (const nil
) integer
)
241 :group
'cperl-indentation-details
)
243 (defcustom cperl-brace-imaginary-offset
0
244 "*Imagined indentation of a Perl open brace that actually follows a statement.
245 An open brace following other text is treated as if it were this far
246 to the right of the start of its line."
248 :group
'cperl-indentation-details
)
250 (defcustom cperl-brace-offset
0
251 "*Extra indentation for braces, compared with other text in same context."
253 :group
'cperl-indentation-details
)
254 (defcustom cperl-label-offset -
2
255 "*Offset of CPerl label lines relative to usual indentation."
257 :group
'cperl-indentation-details
)
258 (defcustom cperl-min-label-indent
1
259 "*Minimal offset of CPerl label lines."
261 :group
'cperl-indentation-details
)
262 (defcustom cperl-continued-statement-offset
2
263 "*Extra indent for lines not starting new statements."
265 :group
'cperl-indentation-details
)
266 (defcustom cperl-continued-brace-offset
0
267 "*Extra indent for substatements that start with open-braces.
268 This is in addition to cperl-continued-statement-offset."
270 :group
'cperl-indentation-details
)
271 (defcustom cperl-close-paren-offset -
1
272 "*Extra indent for substatements that start with close-parenthesis."
274 :group
'cperl-indentation-details
)
276 (defcustom cperl-indent-wrt-brace t
277 "*Non-nil means indent statements in if/etc block relative brace, not if/etc.
278 Versions 5.2 ... 5.20 behaved as if this were `nil'."
280 :group
'cperl-indentation-details
)
282 (defcustom cperl-auto-newline nil
283 "*Non-nil means automatically newline before and after braces,
284 and after colons and semicolons, inserted in CPerl code. The following
285 \\[cperl-electric-backspace] will remove the inserted whitespace.
286 Insertion after colons requires both this variable and
287 `cperl-auto-newline-after-colon' set."
289 :group
'cperl-autoinsert-details
)
291 (defcustom cperl-autoindent-on-semi nil
292 "*Non-nil means automatically indent after insertion of (semi)colon.
293 Active if `cperl-auto-newline' is false."
295 :group
'cperl-autoinsert-details
)
297 (defcustom cperl-auto-newline-after-colon nil
298 "*Non-nil means automatically newline even after colons.
299 Subject to `cperl-auto-newline' setting."
301 :group
'cperl-autoinsert-details
)
303 (defcustom cperl-tab-always-indent t
304 "*Non-nil means TAB in CPerl mode should always reindent the current line,
305 regardless of where in the line point is when the TAB command is used."
307 :group
'cperl-indentation-details
)
309 (defcustom cperl-font-lock nil
310 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
311 Can be overwritten by `cperl-hairy' if nil."
312 :type
'(choice (const null
) boolean
)
313 :group
'cperl-affected-by-hairy
)
315 (defcustom cperl-electric-lbrace-space nil
316 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
317 Can be overwritten by `cperl-hairy' if nil."
318 :type
'(choice (const null
) boolean
)
319 :group
'cperl-affected-by-hairy
)
321 (defcustom cperl-electric-parens-string
"({[]})<"
322 "*String of parentheses that should be electric in CPerl.
323 Closing ones are electric only if the region is highlighted."
325 :group
'cperl-affected-by-hairy
)
327 (defcustom cperl-electric-parens nil
328 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
329 Can be overwritten by `cperl-hairy' if nil."
330 :type
'(choice (const null
) boolean
)
331 :group
'cperl-affected-by-hairy
)
333 (defvar zmacs-regions
) ; Avoid warning
335 (defcustom cperl-electric-parens-mark
337 (or (and (boundp 'transient-mark-mode
) ; For Emacs
339 (and (boundp 'zmacs-regions
) ; For XEmacs
341 "*Not-nil means that electric parens look for active mark.
342 Default is yes if there is visual feedback on mark."
344 :group
'cperl-autoinsert-details
)
346 (defcustom cperl-electric-linefeed nil
347 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
348 In any case these two mean plain and hairy linefeeds together.
349 Can be overwritten by `cperl-hairy' if nil."
350 :type
'(choice (const null
) boolean
)
351 :group
'cperl-affected-by-hairy
)
353 (defcustom cperl-electric-keywords nil
354 "*Not-nil (and non-null) means keywords are electric in CPerl.
355 Can be overwritten by `cperl-hairy' if nil."
356 :type
'(choice (const null
) boolean
)
357 :group
'cperl-affected-by-hairy
)
359 (defcustom cperl-electric-backspace-untabify t
360 "*Not-nil means electric-backspace will untabify in CPerl."
362 :group
'cperl-autoinsert-details
)
364 (defcustom cperl-hairy nil
365 "*Not-nil means most of the bells and whistles are enabled in CPerl.
366 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
367 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
368 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
369 `cperl-lazy-help-time'."
371 :group
'cperl-affected-by-hairy
)
373 (defcustom cperl-comment-column
32
374 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
376 :group
'cperl-indentation-details
)
378 (defcustom cperl-indent-comment-at-column-0 nil
379 "*Non-nil means that comment started at column 0 should be indentable."
381 :group
'cperl-indentation-details
)
383 (defcustom cperl-vc-sccs-header
'("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
384 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
385 :type
'(repeat string
)
388 (defcustom cperl-vc-rcs-header
'("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
389 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
390 :type
'(repeat string
)
393 ;; This became obsolete...
394 (defvar cperl-vc-header-alist nil
)
395 (make-obsolete-variable
396 'cperl-vc-header-alist
397 "use cperl-vc-rcs-header or cperl-vc-sccs-header instead.")
399 (defcustom cperl-clobber-mode-lists
402 (boundp 'interpreter-mode-alist
)
403 (assoc "miniperl" interpreter-mode-alist
)
404 (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist
)))
405 "*Whether to install us into `interpreter-' and `extension' mode lists."
409 (defcustom cperl-info-on-command-no-prompt nil
410 "*Not-nil (and non-null) means not to prompt on C-h f.
411 The opposite behavior is always available if prefixed with C-c.
412 Can be overwritten by `cperl-hairy' if nil."
413 :type
'(choice (const null
) boolean
)
414 :group
'cperl-affected-by-hairy
)
416 (defcustom cperl-clobber-lisp-bindings nil
417 "*Not-nil (and non-null) means not overwrite C-h f.
418 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
419 Can be overwritten by `cperl-hairy' if nil."
420 :type
'(choice (const null
) boolean
)
421 :group
'cperl-affected-by-hairy
)
423 (defcustom cperl-lazy-help-time nil
424 "*Not-nil (and non-null) means to show lazy help after given idle time.
425 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
426 :type
'(choice (const null
) (const nil
) integer
)
427 :group
'cperl-affected-by-hairy
)
429 (defcustom cperl-pod-face
'font-lock-comment-face
430 "*Face for POD highlighting."
434 (defcustom cperl-pod-head-face
'font-lock-variable-name-face
435 "*Face for POD highlighting.
436 Font for POD headers."
440 (defcustom cperl-here-face
'font-lock-string-face
441 "*Face for here-docs highlighting."
445 ;;; Some double-evaluation happened with font-locks... Needed with 21.2...
446 (defvar cperl-singly-quote-face cperl-xemacs-p
)
448 (defcustom cperl-invalid-face
; Does not customize with '' on XEmacs
449 (if cperl-singly-quote-face
450 'underline
''underline
) ; On older Emacsen was evaluated by `font-lock'
451 (if cperl-singly-quote-face
452 "*This face is used for highlighting trailing whitespace."
453 "*Face for highlighting trailing whitespace.")
458 (defcustom cperl-pod-here-fontify
'(featurep 'font-lock
)
459 "*Not-nil after evaluation means to highlight POD and here-docs sections."
463 (defcustom cperl-fontify-m-as-s t
464 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
468 (defcustom cperl-highlight-variables-indiscriminately nil
469 "*Non-nil means perform additional highlighting on variables.
470 Currently only changes how scalar variables are highlighted.
471 Note that that variable is only read at initialization time for
472 the variable `cperl-font-lock-keywords-2', so changing it after you've
473 entered CPerl mode the first time will have no effect."
477 (defcustom cperl-pod-here-scan t
478 "*Not-nil means look for POD and here-docs sections during startup.
479 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
483 (defcustom cperl-regexp-scan t
484 "*Not-nil means make marking of regular expression more thorough.
485 Effective only with `cperl-pod-here-scan'."
489 (defcustom cperl-hook-after-change t
490 "*Not-nil means install hook to know which regions of buffer are changed.
491 May significantly speed up delayed fontification. Changes take effect
496 (defcustom cperl-imenu-addback nil
497 "*Not-nil means add backreferences to generated `imenu's.
498 May require patched `imenu' and `imenu-go'. Obsolete."
500 :group
'cperl-help-system
)
502 (defcustom cperl-max-help-size
66
503 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
504 :type
'(choice integer
(const nil
))
505 :group
'cperl-help-system
)
507 (defcustom cperl-shrink-wrap-info-frame t
508 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
510 :group
'cperl-help-system
)
512 (defcustom cperl-info-page
"perl"
513 "*Name of the info page containing perl docs.
514 Older version of this page was called `perl5', newer `perl'."
516 :group
'cperl-help-system
)
518 (defcustom cperl-use-syntax-table-text-property
519 (boundp 'parse-sexp-lookup-properties
)
520 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
524 (defcustom cperl-use-syntax-table-text-property-for-tags
525 cperl-use-syntax-table-text-property
526 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
530 (defcustom cperl-scan-files-regexp
"\\.\\([pP][Llm]\\|xs\\)$"
531 "*Regexp to match files to scan when generating TAGS."
535 (defcustom cperl-noscan-files-regexp
536 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
537 "*Regexp to match files/dirs to skip when generating TAGS."
541 (defcustom cperl-regexp-indent-step nil
542 "*Indentation used when beautifying regexps.
543 If nil, the value of `cperl-indent-level' will be used."
544 :type
'(choice integer
(const nil
))
545 :group
'cperl-indentation-details
)
547 (defcustom cperl-indent-left-aligned-comments t
548 "*Non-nil means that the comment starting in leftmost column should indent."
550 :group
'cperl-indentation-details
)
552 (defcustom cperl-under-as-char nil
553 "*Non-nil means that the _ (underline) should be treated as word char."
557 (defcustom cperl-extra-perl-args
""
558 "*Extra arguments to use when starting Perl.
559 Currently used with `cperl-check-syntax' only."
563 (defcustom cperl-message-electric-keyword t
564 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
566 :group
'cperl-help-system
)
568 (defcustom cperl-indent-region-fix-constructs
1
569 "*Amount of space to insert between `}' and `else' or `elsif'
570 in `cperl-indent-region'. Set to nil to leave as is. Values other
571 than 1 and nil will probably not work."
572 :type
'(choice (const nil
) (const 1))
573 :group
'cperl-indentation-details
)
575 (defcustom cperl-break-one-line-blocks-when-indent t
576 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
577 need to be reformatted into multiline ones when indenting a region."
579 :group
'cperl-indentation-details
)
581 (defcustom cperl-fix-hanging-brace-when-indent t
582 "*Non-nil means that BLOCK-end `}' may be put on a separate line
583 when indenting a region.
584 Braces followed by else/elsif/while/until are excepted."
586 :group
'cperl-indentation-details
)
588 (defcustom cperl-merge-trailing-else t
589 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
590 may be merged to be on the same line when indenting a region."
592 :group
'cperl-indentation-details
)
594 (defcustom cperl-indent-parens-as-block nil
595 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
596 but for trailing \",\" inside the group, which won't increase indentation.
597 One should tune up `cperl-close-paren-offset' as well."
599 :group
'cperl-indentation-details
)
601 (defcustom cperl-syntaxify-by-font-lock
602 (and cperl-can-font-lock
603 (boundp 'parse-sexp-lookup-properties
))
604 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
605 :type
'(choice (const message
) boolean
)
608 (defcustom cperl-syntaxify-unwind
610 "*Non-nil means that CPerl unwinds to a start of a long construction
611 when syntaxifying a chunk of buffer."
615 (defcustom cperl-syntaxify-for-menu
617 "*Non-nil means that CPerl syntaxifies up to the point before showing menu.
618 This way enabling/disabling of menu items is more correct."
622 (defcustom cperl-ps-print-face-properties
623 '((font-lock-keyword-face nil nil bold shadow
)
624 (font-lock-variable-name-face nil nil bold
)
625 (font-lock-function-name-face nil nil bold italic box
)
626 (font-lock-constant-face nil
"LightGray" bold
)
627 (cperl-array-face nil
"LightGray" bold underline
)
628 (cperl-hash-face nil
"LightGray" bold italic underline
)
629 (font-lock-comment-face nil
"LightGray" italic
)
630 (font-lock-string-face nil nil italic underline
)
631 (cperl-nonoverridable-face nil nil italic underline
)
632 (font-lock-type-face nil nil underline
)
633 (font-lock-warning-face nil
"LightGray" bold italic box
)
634 (underline nil
"LightGray" strikeout
))
635 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
636 :type
'(repeat (cons symbol
637 (cons (choice (const nil
) string
)
638 (cons (choice (const nil
) string
)
642 (defvar cperl-dark-background
643 (cperl-choose-color "navy" "os2blue" "darkgreen"))
644 (defvar cperl-dark-foreground
645 (cperl-choose-color "orchid1" "orange"))
647 (defface cperl-nonoverridable-face
648 `((((class grayscale
) (background light
))
649 (:background
"Gray90" :slant italic
:underline t
))
650 (((class grayscale
) (background dark
))
651 (:foreground
"Gray80" :slant italic
:underline t
:weight bold
))
652 (((class color
) (background light
))
653 (:foreground
"chartreuse3"))
654 (((class color
) (background dark
))
655 (:foreground
,cperl-dark-foreground
))
656 (t (:weight bold
:underline t
)))
657 "Font Lock mode face used non-overridable keywords and modifiers of regexps."
660 (defface cperl-array-face
661 `((((class grayscale
) (background light
))
662 (:background
"Gray90" :weight bold
))
663 (((class grayscale
) (background dark
))
664 (:foreground
"Gray80" :weight bold
))
665 (((class color
) (background light
))
666 (:foreground
"Blue" :background
"lightyellow2" :weight bold
))
667 (((class color
) (background dark
))
668 (:foreground
"yellow" :background
,cperl-dark-background
:weight bold
))
670 "Font Lock mode face used to highlight array names."
673 (defface cperl-hash-face
674 `((((class grayscale
) (background light
))
675 (:background
"Gray90" :weight bold
:slant italic
))
676 (((class grayscale
) (background dark
))
677 (:foreground
"Gray80" :weight bold
:slant italic
))
678 (((class color
) (background light
))
679 (:foreground
"Red" :background
"lightyellow2" :weight bold
:slant italic
))
680 (((class color
) (background dark
))
681 (:foreground
"Red" :background
,cperl-dark-background
:weight bold
:slant italic
))
682 (t (:weight bold
:slant italic
)))
683 "Font Lock mode face used to highlight hash names."
688 ;;; Short extra-docs.
690 (defvar cperl-tips
'please-ignore-this-line
691 "Get maybe newer version of this package from
692 http://ilyaz.org/software/emacs
693 Subdirectory `cperl-mode' may contain yet newer development releases and/or
694 patches to related files.
696 For best results apply to an older Emacs the patches from
697 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
698 \(this upgrades syntax-parsing abilities of Emacsen v19.34 and
699 v20.2 up to the level of Emacs v20.3 - a must for a good Perl
700 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
702 Get support packages choose-color.el (or font-lock-extra.el before
703 19.30), imenu-go.el from the same place. \(Look for other files there
704 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
705 later you should use choose-color.el *instead* of font-lock-extra.el
706 \(and you will not get smart highlighting in C :-().
708 Note that to enable Compile choices in the menu you need to install
711 If your Emacs does not default to `cperl-mode' on Perl files, and you
712 want it to: put the following into your .emacs file:
714 (defalias 'perl-mode 'cperl-mode)
717 $CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
718 Also, one can generate a newer documentation running `pod2texi' converter
719 $CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
721 If you use imenu-go, run imenu on perl5-info buffer (you can do it
722 from Perl menu). If many files are related, generate TAGS files from
723 Tools/Tags submenu in Perl menu.
725 If some class structure is too complicated, use Tools/Hierarchy-view
726 from Perl menu, or hierarchic view of imenu. The second one uses the
727 current buffer only, the first one requires generation of TAGS from
728 Perl/Tools/Tags menu beforehand.
730 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
732 Switch auto-help on/off with Perl/Tools/Auto-help.
734 Though with contemporary Emaxen CPerl mode should maintain the correct
735 parsing of Perl even when editing, sometimes it may be lost. Fix this by
739 In cases of more severe confusion sometimes it is helpful to do
741 \\[load-library] cperl-mode RET
744 Before reporting (non-)problems look in the problem section of online
745 micro-docs on what I know about CPerl problems.")
747 (defvar cperl-problems
'please-ignore-this-line
748 "Description of problems in CPerl mode.
749 Some faces will not be shown on some versions of Emacs unless you
750 install choose-color.el, available from
751 http://ilyaz.org/software/emacs
753 `fill-paragraph' on a comment may leave the point behind the
754 paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
755 to detect it and bulk out).
757 See documentation of a variable `cperl-problems-old-emaxen' for the
758 problems which disappear if you upgrade Emacs to a reasonably new
759 version (20.3 for Emacs, and those of 2004 for XEmacs).")
761 (defvar cperl-problems-old-emaxen
'please-ignore-this-line
762 "Description of problems in CPerl mode specific for older Emacs versions.
764 Emacs had a _very_ restricted syntax parsing engine until version
765 20.1. Most problems below are corrected starting from this version of
766 Emacs, and all of them should be fixed in version 20.3. (Or apply
767 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
768 this respect (until 2003).
770 Note that even with newer Emacsen in some very rare cases the details
771 of interaction of `font-lock' and syntaxification may be not cleaned
772 up yet. You may get slightly different colors basing on the order of
773 fontification and syntaxification. Say, the initial faces is correct,
774 but editing the buffer breaks this.
776 Even with older Emacsen CPerl mode tries to corrects some Emacs
777 misunderstandings, however, for efficiency reasons the degree of
778 correction is different for different operations. The partially
779 corrected problems are: POD sections, here-documents, regexps. The
780 operations are: highlighting, indentation, electric keywords, electric
783 This may be confusing, since the regexp s#//#/#\; may be highlighted
784 as a comment, but it will be recognized as a regexp by the indentation
785 code. Or the opposite case, when a POD section is highlighted, but
786 may break the indentation of the following code (though indentation
787 should work if the balance of delimiters is not broken by POD).
789 The main trick (to make $ a \"backslash\") makes constructions like
790 ${aaa} look like unbalanced braces. The only trick I can think of is
791 to insert it as $ {aaa} (valid in perl5, not in perl4).
793 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
794 as /($|\\s)/. Note that such a transposition is not always possible.
796 The solution is to upgrade your Emacs or patch an older one. Note
797 that Emacs 20.2 has some bugs related to `syntax-table' text
798 properties. Patches are available on the main CPerl download site,
801 If these bugs cannot be fixed on your machine (say, you have an inferior
802 environment and cannot recompile), you may still disable all the fancy stuff
803 via `cperl-use-syntax-table-text-property'.")
805 (defvar cperl-praise
'please-ignore-this-line
806 "Advantages of CPerl mode.
808 0) It uses the newest `syntax-table' property ;-);
810 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
811 mode - but the latter number may have improved too in last years) even
812 with old Emaxen which do not support `syntax-table' property.
814 When using `syntax-table' property for syntax assist hints, it should
815 handle 99.995% of lines correct - or somesuch. It automatically
816 updates syntax assist hints when you edit your script.
818 2) It is generally believed to be \"the most user-friendly Emacs
819 package\" whatever it may mean (I doubt that the people who say similar
820 things tried _all_ the rest of Emacs ;-), but this was not a lonely
823 3) Everything is customizable, one-by-one or in a big sweep;
825 4) It has many easily-accessable \"tools\":
826 a) Can run program, check syntax, start debugger;
827 b) Can lineup vertically \"middles\" of rows, like `=' in
830 c) Can insert spaces where this impoves readability (in one
831 interactive sweep over the buffer);
832 d) Has support for imenu, including:
833 1) Separate unordered list of \"interesting places\";
834 2) Separate TOC of POD sections;
835 3) Separate list of packages;
836 4) Hierarchical view of methods in (sub)packages;
837 5) and functions (by the full name - with package);
838 e) Has an interface to INFO docs for Perl; The interface is
839 very flexible, including shrink-wrapping of
840 documentation buffer/frame;
841 f) Has a builtin list of one-line explanations for perl constructs.
842 g) Can show these explanations if you stay long enough at the
843 corresponding place (or on demand);
844 h) Has an enhanced fontification (using 3 or 4 additional faces
845 comparing to font-lock - basically, different
846 namespaces in Perl have different colors);
847 i) Can construct TAGS basing on its knowledge of Perl syntax,
848 the standard menu has 6 different way to generate
849 TAGS (if \"by directory\", .xs files - with C-language
850 bindings - are included in the scan);
851 j) Can build a hierarchical view of classes (via imenu) basing
852 on generated TAGS file;
853 k) Has electric parentheses, electric newlines, uses Abbrev
854 for electric logical constructs
856 with different styles of expansion (context sensitive
857 to be not so bothering). Electric parentheses behave
858 \"as they should\" in a presence of a visible region.
859 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
865 n) Highlights (by user-choice) either 3-delimiters constructs
866 (such as tr/a/b/), or regular expressions and `y/tr';
867 o) Highlights trailing whitespace;
868 p) Is able to manipulate Perl Regular Expressions to ease
869 conversion to a more readable form.
870 q) Can ispell POD sections and HERE-DOCs.
871 r) Understands comments and character classes inside regular
872 expressions; can find matching () and [] in a regular expression.
873 s) Allows indentation of //x-style regular expressions;
874 t) Highlights different symbols in regular expressions according
875 to their function; much less problems with backslashitis;
876 u) Allows to find regular expressions which contain interpolated parts.
878 5) The indentation engine was very smart, but most of tricks may be
879 not needed anymore with the support for `syntax-table' property. Has
880 progress indicator for indentation (with `imenu' loaded).
882 6) Indent-region improves inline-comments as well; also corrects
883 whitespace *inside* the conditional/loop constructs.
885 7) Fill-paragraph correctly handles multi-line comments;
887 8) Can switch to different indentation styles by one command, and restore
888 the settings present before the switch.
890 9) When doing indentation of control constructs, may correct
891 line-breaks/spacing between elements of the construct.
893 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
894 capable syntax engines).
896 11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
899 (defvar cperl-speed
'please-ignore-this-line
900 "This is an incomplete compendium of what is available in other parts
901 of CPerl documentation. (Please inform me if I skept anything.)
903 There is a perception that CPerl is slower than alternatives. This part
904 of documentation is designed to overcome this misconception.
906 *By default* CPerl tries to enable the most comfortable settings.
907 From most points of view, correctly working package is infinitely more
908 comfortable than a non-correctly working one, thus by default CPerl
909 prefers correctness over speed. Below is the guide how to change
910 settings if your preferences are different.
912 A) Speed of loading the file. When loading file, CPerl may perform a
913 scan which indicates places which cannot be parsed by primitive Emacs
914 syntax-parsing routines, and marks them up so that either
916 A1) CPerl may work around these deficiencies (for big chunks, mostly
917 PODs and HERE-documents), or
918 A2) On capable Emaxen CPerl will use improved syntax-handlings
919 which reads mark-up hints directly.
921 The scan in case A2 is much more comprehensive, thus may be slower.
923 User can disable syntax-engine-helping scan of A2 by setting
924 `cperl-use-syntax-table-text-property'
925 variable to nil (if it is set to t).
927 One can disable the scan altogether (both A1 and A2) by setting
928 `cperl-pod-here-scan'
931 B) Speed of editing operations.
933 One can add a (minor) speedup to editing operations by setting
934 `cperl-use-syntax-table-text-property'
935 variable to nil (if it is set to t). This will disable
936 syntax-engine-helping scan, thus will make many more Perl
937 constructs be wrongly recognized by CPerl, thus may lead to
938 wrongly matched parentheses, wrong indentation, etc.
940 One can unset `cperl-syntaxify-unwind'. This might speed up editing
941 of, say, long POD sections.")
943 (defvar cperl-tips-faces
'please-ignore-this-line
944 "CPerl mode uses following faces for highlighting:
946 `cperl-array-face' Array names
947 `cperl-hash-face' Hash names
948 `font-lock-comment-face' Comments, PODs and whatever is considered
949 syntaxically to be not code
950 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
951 2-arg operators s/y/tr/ or of RExen,
952 `font-lock-warning-face' Special-cased m// and s//foo/,
953 `font-lock-function-name-face' _ as a target of a file tests, file tests,
954 subroutine names at the moment of definition
955 (except those conflicting with Perl operators),
956 package names (when recognized), format names
957 `font-lock-keyword-face' Control flow switch constructs, declarators
958 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
959 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
960 literal parts and the terminator of formats
961 and whatever is syntaxically considered
963 `font-lock-type-face' Overridable keywords
964 `font-lock-variable-name-face' Variable declarations, indirect array and
965 hash names, POD headers/item names
966 `cperl-invalid' Trailing whitespace
968 Note that in several situations the highlighting tries to inform about
969 possible confusion, such as different colors for function names in
970 declarations depending on what they (do not) override, or special cases
971 m// and s/// which do not do what one would expect them to do.
973 Help with best setup of these faces for printout requested (for each of
974 the faces: please specify bold, italic, underline, shadow and box.)
976 In regular expressions (except character classes):
977 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs
978 `font-lock-constant-face': Delimiters
979 `font-lock-warning-face' Special-cased m// and s//foo/,
980 Mismatched closing delimiters, parens
981 we couldn't match, misplaced quantifiers,
982 unrecognized escape sequences
983 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
984 `font-lock-type-face' POSIX classes inside charclasses,
985 escape sequences with arguments (\x \23 \p \N)
986 and others match-a-char escape sequences
987 `font-lock-keyword-face' Capturing parens, and |
988 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
989 `font-lock-builtin-face' \"Remaining\" 0-length constructs, executable
990 parts of a REx, not-capturing parens
991 `font-lock-variable-name-face' Interpolated constructs, embedded code
992 `font-lock-comment-face' Embedded comments
998 ;;; Portability stuff:
1000 (defmacro cperl-define-key
(emacs-key definition
&optional xemacs-key
)
1001 `(define-key cperl-mode-map
1003 `(if cperl-xemacs-p
,xemacs-key
,emacs-key
)
1007 (defvar cperl-del-back-ch
1008 (car (append (where-is-internal 'delete-backward-char
)
1009 (where-is-internal 'backward-delete-char-untabify
)))
1010 "Character generated by key bound to `delete-backward-char'.")
1012 (and (vectorp cperl-del-back-ch
) (= (length cperl-del-back-ch
) 1)
1013 (setq cperl-del-back-ch
(aref cperl-del-back-ch
0)))
1015 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
1018 ;; "Active regions" are on: use region only if active
1019 ;; "Active regions" are off: use region unconditionally
1020 (defun cperl-use-region-p ()
1021 (if zmacs-regions
(mark) t
)))
1022 (defun cperl-use-region-p ()
1023 (if transient-mark-mode mark-active t
))
1024 (defun cperl-mark-active () mark-active
))
1026 (defsubst cperl-enable-font-lock
()
1027 cperl-can-font-lock
)
1029 (defun cperl-putback-char (c) ; Emacs 19
1030 (set 'unread-command-events
(list c
))) ; Avoid undefined warning
1033 (defun cperl-putback-char (c) ; XEmacs >= 19.12
1034 (setq unread-command-events
(list (eval '(character-to-event c
))))))
1036 (or (fboundp 'uncomment-region
)
1037 (defun uncomment-region (beg end
)
1039 (comment-region beg end -
1)))
1041 (defvar cperl-do-not-fontify
1042 (if (string< emacs-version
"19.30")
1045 "Text property which inhibits refontification.")
1047 (defsubst cperl-put-do-not-fontify
(from to
&optional post
)
1048 ;; If POST, do not do it with postponed fontification
1049 (if (and post cperl-syntaxify-by-font-lock
)
1051 (put-text-property (max (point-min) (1- from
))
1052 to cperl-do-not-fontify t
)))
1054 (defcustom cperl-mode-hook nil
1055 "Hook run by CPerl mode."
1059 (defvar cperl-syntax-state nil
)
1060 (defvar cperl-syntax-done-to nil
)
1061 (defvar cperl-emacs-can-parse
(> (length (save-excursion
1062 (parse-partial-sexp (point) (point)))) 9))
1064 ;; Make customization possible "in reverse"
1065 (defsubst cperl-val
(symbol &optional default hairy
)
1067 ((eq (symbol-value symbol
) 'null
) default
)
1068 (cperl-hairy (or hairy t
))
1069 (t (symbol-value symbol
))))
1072 (defun cperl-make-indent (column &optional minimum keep
)
1073 "Makes indent of the current line the requested amount.
1074 Unless KEEP, removes the old indentation. Works around a bug in ancient
1076 (let ((prop (get-text-property (point) 'syntax-type
)))
1078 (delete-horizontal-space))
1079 (indent-to column minimum
)
1080 ;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
1082 (> (current-column) 0)
1085 (or (get-text-property (point) 'syntax-type
)
1086 (and (looking-at "\\=[ \t]")
1087 (put-text-property (point) (match-end 0)
1088 'syntax-type prop
)))))))
1090 ;;; Probably it is too late to set these guys already, but it can help later:
1092 ;;;(and cperl-clobber-mode-lists
1093 ;;;(setq auto-mode-alist
1094 ;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
1095 ;;;(and (boundp 'interpreter-mode-alist)
1096 ;;; (setq interpreter-mode-alist (append interpreter-mode-alist
1097 ;;; '(("miniperl" . perl-mode))))))
1103 '(imenu easymenu etags timer man info
))
1104 (if (fboundp 'ps-extend-face-list
)
1105 (defmacro cperl-ps-extend-face-list
(arg)
1106 `(ps-extend-face-list ,arg
))
1107 (defmacro cperl-ps-extend-face-list
(arg)
1108 `(error "This version of Emacs has no `ps-extend-face-list'")))
1109 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
1110 ;; macros instead of defsubsts don't work on Emacs, so we do the
1111 ;; expansion manually. Any other suggestions?
1114 (defvar cperl-mode-abbrev-table nil
1115 "Abbrev table in use in CPerl mode buffers.")
1117 (add-hook 'edit-var-mode-alist
'(perl-mode (regexp .
"^cperl-")))
1119 (defvar cperl-mode-map
() "Keymap used in CPerl mode.")
1121 (if cperl-mode-map nil
1122 (setq cperl-mode-map
(make-sparse-keymap))
1123 (cperl-define-key "{" 'cperl-electric-lbrace
)
1124 (cperl-define-key "[" 'cperl-electric-paren
)
1125 (cperl-define-key "(" 'cperl-electric-paren
)
1126 (cperl-define-key "<" 'cperl-electric-paren
)
1127 (cperl-define-key "}" 'cperl-electric-brace
)
1128 (cperl-define-key "]" 'cperl-electric-rparen
)
1129 (cperl-define-key ")" 'cperl-electric-rparen
)
1130 (cperl-define-key ";" 'cperl-electric-semi
)
1131 (cperl-define-key ":" 'cperl-electric-terminator
)
1132 (cperl-define-key "\C-j" 'newline-and-indent
)
1133 (cperl-define-key "\C-c\C-j" 'cperl-linefeed
)
1134 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless
)
1135 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline
)
1136 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev
)
1137 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix
)
1138 (cperl-define-key "\C-c\C-f" 'auto-fill-mode
)
1139 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric
)
1140 (cperl-define-key "\C-c\C-b" 'cperl-find-bad-style
)
1141 (cperl-define-key "\C-c\C-p" 'cperl-pod-spell
)
1142 (cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell
)
1143 (cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc
)
1144 (cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx
)
1145 (cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0
)
1146 (cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1
)
1147 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp
)
1148 (cperl-define-key "\C-c\C-hp" 'cperl-perldoc
)
1149 (cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point
)
1150 (cperl-define-key "\e\C-q" 'cperl-indent-exp
) ; Usually not bound
1151 (cperl-define-key [?\C-\M-\|
] 'cperl-lineup
1153 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1154 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
1155 (cperl-define-key "\177" 'cperl-electric-backspace
)
1156 (cperl-define-key "\t" 'cperl-indent-command
)
1157 ;; don't clobber the backspace binding:
1158 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
1159 [(control c
) (control h
) F
])
1160 (if (cperl-val 'cperl-clobber-lisp-bindings
)
1162 (cperl-define-key "\C-hf"
1163 ;;(concat (char-to-string help-char) "f") ; does not work
1164 'cperl-info-on-command
1166 (cperl-define-key "\C-hv"
1167 ;;(concat (char-to-string help-char) "v") ; does not work
1170 (cperl-define-key "\C-c\C-hf"
1171 ;;(concat (char-to-string help-char) "f") ; does not work
1172 (key-binding "\C-hf")
1173 [(control c
) (control h
) f
])
1174 (cperl-define-key "\C-c\C-hv"
1175 ;;(concat (char-to-string help-char) "v") ; does not work
1176 (key-binding "\C-hv")
1177 [(control c
) (control h
) v
]))
1178 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
1179 [(control c
) (control h
) f
])
1180 (cperl-define-key "\C-c\C-hv"
1181 ;;(concat (char-to-string help-char) "v") ; does not work
1183 [(control c
) (control h
) v
]))
1184 (if (and cperl-xemacs-p
1185 (<= emacs-minor-version
11) (<= emacs-major-version
19))
1187 ;; substitute-key-definition is usefulness-deenhanced...
1188 ;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1189 (cperl-define-key "\e;" 'cperl-indent-for-comment
)
1190 (cperl-define-key "\e\C-\\" 'cperl-indent-region
))
1191 (or (boundp 'fill-paragraph-function
)
1192 (substitute-key-definition
1193 'fill-paragraph
'cperl-fill-paragraph
1194 cperl-mode-map global-map
))
1195 (substitute-key-definition
1196 'indent-sexp
'cperl-indent-exp
1197 cperl-mode-map global-map
)
1198 (substitute-key-definition
1199 'indent-region
'cperl-indent-region
1200 cperl-mode-map global-map
)
1201 (substitute-key-definition
1202 'indent-for-comment
'cperl-indent-for-comment
1203 cperl-mode-map global-map
)))
1206 (defvar cperl-lazy-installed
)
1207 (defvar cperl-old-style nil
)
1212 cperl-menu cperl-mode-map
"Menu for CPerl mode"
1214 ["Beginning of function" beginning-of-defun
t]
1215 ["End of function" end-of-defun
t]
1216 ["Mark function" mark-defun
t]
1217 ["Indent expression" cperl-indent-exp t
]
1218 ["Fill paragraph/comment" fill-paragraph t
]
1220 ["Line up a construction" cperl-lineup
(cperl-use-region-p)]
1221 ["Invert if/unless/while etc" cperl-invert-if-unless t
]
1223 ["Beautify" cperl-beautify-regexp
1224 cperl-use-syntax-table-text-property
]
1225 ["Beautify one level deep" (cperl-beautify-regexp 1)
1226 cperl-use-syntax-table-text-property
]
1227 ["Beautify a group" cperl-beautify-level
1228 cperl-use-syntax-table-text-property
]
1229 ["Beautify a group one level deep" (cperl-beautify-level 1)
1230 cperl-use-syntax-table-text-property
]
1231 ["Contract a group" cperl-contract-level
1232 cperl-use-syntax-table-text-property
]
1233 ["Contract groups" cperl-contract-levels
1234 cperl-use-syntax-table-text-property
]
1236 ["Find next interpolated" cperl-next-interpolated-REx
1237 (next-single-property-change (point-min) 'REx-interpolated
)]
1238 ["Find next interpolated (no //o)"
1239 cperl-next-interpolated-REx-0
1240 (or (text-property-any (point-min) (point-max) 'REx-interpolated t
)
1241 (text-property-any (point-min) (point-max) 'REx-interpolated
1))]
1242 ["Find next interpolated (neither //o nor whole-REx)"
1243 cperl-next-interpolated-REx-1
1244 (text-property-any (point-min) (point-max) 'REx-interpolated t
)])
1245 ["Insert spaces if needed to fix style" cperl-find-bad-style t
]
1246 ["Refresh \"hard\" constructions" cperl-find-pods-heres t
]
1248 ["Indent region" cperl-indent-region
(cperl-use-region-p)]
1249 ["Comment region" cperl-comment-region
(cperl-use-region-p)]
1250 ["Uncomment region" cperl-uncomment-region
(cperl-use-region-p)]
1252 ["Run" mode-compile
(fboundp 'mode-compile
)]
1253 ["Kill" mode-compile-kill
(and (fboundp 'mode-compile-kill
)
1254 (get-buffer "*compilation*"))]
1255 ["Next error" next-error
(get-buffer "*compilation*")]
1256 ["Check syntax" cperl-check-syntax
(fboundp 'mode-compile
)]
1258 ["Debugger" cperl-db t
]
1261 ["Imenu" imenu
(fboundp 'imenu
)]
1262 ["Imenu on Perl Info" cperl-imenu-on-info
(featurep 'imenu
)]
1264 ["Ispell PODs" cperl-pod-spell
1265 ;; Better not to update syntaxification here:
1266 ;; debugging syntaxificatio can be broken by this???
1268 (get-text-property (point-min) 'in-pod
)
1270 (and cperl-syntaxify-for-menu
1271 (cperl-update-syntaxification (point-max) (point-max)))
1272 (next-single-property-change (point-min) 'in-pod nil
(point-max)))
1274 ["Ispell HERE-DOCs" cperl-here-doc-spell
1276 (and cperl-syntaxify-for-menu
1277 (cperl-update-syntaxification (point-max) (point-max)))
1278 (next-single-property-change (point-min) 'here-doc-group nil
(point-max)))
1280 ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
1281 (eq 'here-doc
(progn
1282 (and cperl-syntaxify-for-menu
1283 (cperl-update-syntaxification (point) (point)))
1284 (get-text-property (point) 'syntax-type
)))]
1285 ["Select this HERE-DOC or POD section"
1286 cperl-select-this-pod-or-here-doc
1288 (and cperl-syntaxify-for-menu
1289 (cperl-update-syntaxification (point) (point)))
1290 (get-text-property (point) 'syntax-type
))
1293 ["CPerl pretty print (exprmntl)" cperl-ps-print
1294 (fboundp 'ps-extend-face-list
)]
1296 ["Syntaxify region" cperl-find-pods-heres-region
1297 (cperl-use-region-p)]
1298 ["Profile syntaxification" cperl-time-fontification t
]
1299 ["Debug errors in delayed fontification" cperl-emulate-lazy-lock t
]
1300 ["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t
]
1301 ["Debug backtrace on syntactic scan (BEWARE!!!)"
1302 (cperl-toggle-set-debug-unwind nil t
) t
]
1304 ["Class Hierarchy from TAGS" cperl-tags-hier-init t
]
1305 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
1307 ;;; ["Create tags for current file" cperl-etags t]
1308 ;;; ["Add tags for current file" (cperl-etags t) t]
1309 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
1310 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
1311 ;;; ["Create tags for Perl files in (sub)directories"
1312 ;;; (cperl-etags nil 'recursive) t]
1313 ;;; ["Add tags for Perl files in (sub)directories"
1314 ;;; (cperl-etags t 'recursive) t])
1315 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
1316 ["Create tags for current file" (cperl-write-tags nil t
) t
]
1317 ["Add tags for current file" (cperl-write-tags) t
]
1318 ["Create tags for Perl files in directory"
1319 (cperl-write-tags nil t nil t
) t
]
1320 ["Add tags for Perl files in directory"
1321 (cperl-write-tags nil nil nil t
) t
]
1322 ["Create tags for Perl files in (sub)directories"
1323 (cperl-write-tags nil t t t
) t
]
1324 ["Add tags for Perl files in (sub)directories"
1325 (cperl-write-tags nil nil t t
) t
]))
1327 ["Define word at point" imenu-go-find-at-position
1328 (fboundp 'imenu-go-find-at-position
)]
1329 ["Help on function" cperl-info-on-command t
]
1330 ["Help on function at point" cperl-info-on-current-command t
]
1331 ["Help on symbol at point" cperl-get-help t
]
1332 ["Perldoc" cperl-perldoc t
]
1333 ["Perldoc on word at point" cperl-perldoc-at-point t
]
1334 ["View manpage of POD in this file" cperl-build-manpage t
]
1335 ["Auto-help on" cperl-lazy-install
1336 (and (fboundp 'run-with-idle-timer
)
1337 (not cperl-lazy-installed
))]
1338 ["Auto-help off" cperl-lazy-unstall
1339 (and (fboundp 'run-with-idle-timer
)
1340 cperl-lazy-installed
)])
1342 ["Auto newline" cperl-toggle-auto-newline t
]
1343 ["Electric parens" cperl-toggle-electric t
]
1344 ["Electric keywords" cperl-toggle-abbrev t
]
1345 ["Fix whitespace on indent" cperl-toggle-construct-fix t
]
1346 ["Auto-help on Perl constructs" cperl-toggle-autohelp t
]
1347 ["Auto fill" auto-fill-mode t
])
1349 ["CPerl" (cperl-set-style "CPerl") t
]
1350 ["PerlStyle" (cperl-set-style "PerlStyle") t
]
1351 ["GNU" (cperl-set-style "GNU") t
]
1352 ["C++" (cperl-set-style "C++") t
]
1353 ["K&R" (cperl-set-style "K&R") t
]
1354 ["BSD" (cperl-set-style "BSD") t
]
1355 ["Whitesmith" (cperl-set-style "Whitesmith") t
]
1356 ["Memorize Current" (cperl-set-style "Current") t
]
1357 ["Memorized" (cperl-set-style-back) cperl-old-style
])
1359 ["Tips" (describe-variable 'cperl-tips
) t
]
1360 ["Problems" (describe-variable 'cperl-problems
) t
]
1361 ["Speed" (describe-variable 'cperl-speed
) t
]
1362 ["Praise" (describe-variable 'cperl-praise
) t
]
1363 ["Faces" (describe-variable 'cperl-tips-faces
) t
]
1364 ["CPerl mode" (describe-function 'cperl-mode
) t
]
1366 (message "The version of master-file for this CPerl is %s-Emacs"
1367 cperl-version
) t
]))))
1370 (autoload 'c-macro-expand
"cmacexp"
1371 "Display the result of expanding all C macros occurring in the region.
1372 The expansion is entirely correct because it uses the C preprocessor."
1375 ;;; These two must be unwound, otherwise take exponential time
1376 (defconst cperl-maybe-white-and-comment-rex
"[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
1377 "Regular expression to match optional whitespace with interpspersed comments.
1378 Should contain exactly one group.")
1380 ;;; This one is tricky to unwind; still very inefficient...
1381 (defconst cperl-white-and-comment-rex
"\\([ \t\n]\\|#[^\n]*\n\\)+"
1382 "Regular expression to match whitespace with interpspersed comments.
1383 Should contain exactly one group.")
1386 ;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
1387 ;;; `cperl-outline-regexp', `defun-prompt-regexp'.
1388 ;;; Details of groups in this may be used in several functions; see comments
1389 ;;; near mentioned above variable(s)...
1390 ;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
1391 (defsubst cperl-after-sub-regexp
(named attr
) ; 9 groups without attr...
1392 "Match the text after `sub' in a subroutine declaration.
1393 If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
1394 of attributes (if present), or end of the name or prototype (whatever is
1396 (concat ; Assume n groups before this...
1397 "\\(" ; n+1=name-group
1398 cperl-white-and-comment-rex
; n+2=pre-name
1399 "\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
1400 "\\)" ; END n+1=name-group
1402 "\\(" ; n+4=proto-group
1403 cperl-maybe-white-and-comment-rex
; n+5=pre-proto
1404 "\\(([^()]*)\\)" ; n+6=prototype
1405 "\\)?" ; END n+4=proto-group
1406 "\\(" ; n+7=attr-group
1407 cperl-maybe-white-and-comment-rex
; n+8=pre-attr
1408 "\\(" ; n+9=start-attr
1412 cperl-maybe-white-and-comment-rex
; whitespace-comments
1413 "\\(\\sw\\|_\\)+" ; attr-name
1414 ;; attr-arg (1 level of internal parens allowed!)
1415 "\\((\\(\\\\.\\|[^\\\\()]\\|([^\\\\()]*)\\)*)\\)?"
1416 "\\(" ; optional : (XXX allows trailing???)
1417 cperl-maybe-white-and-comment-rex
; whitespace-comments
1422 "\\)?" ; END n+6=proto-group
1425 ;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
1426 ;;; and `cperl-outline-level'.
1427 ;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 8=sub-name (+3)
1428 (defvar cperl-imenu--function-name-regexp-perl
1431 "\\([ \t]*package" ; 2 = package-group
1432 "\\(" ; 3 = package-name-group
1433 cperl-white-and-comment-rex
; 4 = pre-package-name
1434 "\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
1437 (cperl-after-sub-regexp 'named nil
) ; 8=name 11=proto 14=attr-start
1438 cperl-maybe-white-and-comment-rex
; 15=pre-block
1440 "=head\\([1-4]\\)[ \t]+" ; 16=level
1441 "\\([^\n]+\\)$" ; 17=text
1444 (defvar cperl-outline-regexp
1445 (concat cperl-imenu--function-name-regexp-perl
"\\|" "\\`"))
1447 (defvar cperl-mode-syntax-table nil
1448 "Syntax table in use in CPerl mode buffers.")
1450 (defvar cperl-string-syntax-table nil
1451 "Syntax table in use in CPerl mode string-like chunks.")
1453 (defsubst cperl-1-
(p)
1454 (max (point-min) (1- p
)))
1456 (defsubst cperl-1
+ (p)
1457 (min (point-max) (1+ p
)))
1459 (if cperl-mode-syntax-table
1461 (setq cperl-mode-syntax-table
(make-syntax-table))
1462 (modify-syntax-entry ?
\\ "\\" cperl-mode-syntax-table
)
1463 (modify-syntax-entry ?
/ "." cperl-mode-syntax-table
)
1464 (modify-syntax-entry ?
* "." cperl-mode-syntax-table
)
1465 (modify-syntax-entry ?
+ "." cperl-mode-syntax-table
)
1466 (modify-syntax-entry ?-
"." cperl-mode-syntax-table
)
1467 (modify-syntax-entry ?
= "." cperl-mode-syntax-table
)
1468 (modify-syntax-entry ?%
"." cperl-mode-syntax-table
)
1469 (modify-syntax-entry ?
< "." 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 ?
\n ">" 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 (if cperl-under-as-char
1478 (modify-syntax-entry ?_
"w" cperl-mode-syntax-table
))
1479 (modify-syntax-entry ?
: "_" cperl-mode-syntax-table
)
1480 (modify-syntax-entry ?|
"." cperl-mode-syntax-table
)
1481 (setq cperl-string-syntax-table
(copy-syntax-table cperl-mode-syntax-table
))
1482 (modify-syntax-entry ?$
"." cperl-string-syntax-table
)
1483 (modify-syntax-entry ?\
{ "." cperl-string-syntax-table
)
1484 (modify-syntax-entry ?\
} "." cperl-string-syntax-table
)
1485 (modify-syntax-entry ?
# "." cperl-string-syntax-table
)) ; (?# comment )
1489 (defvar cperl-faces-init nil
)
1491 (defvar cperl-msb-fixed nil
)
1492 (defvar cperl-use-major-mode
'cperl-mode
)
1493 (defvar cperl-font-lock-multiline-start nil
)
1494 (defvar cperl-font-lock-multiline nil
)
1495 (defvar cperl-compilation-error-regexp-alist nil
)
1496 (defvar cperl-font-locking nil
)
1499 (defun cperl-mode ()
1500 "Major mode for editing Perl code.
1501 Expression and list commands understand all C brackets.
1502 Tab indents for Perl code.
1503 Paragraphs are separated by blank lines only.
1504 Delete converts tabs to spaces as it moves back.
1506 Various characters in Perl almost always come in pairs: {}, (), [],
1507 sometimes <>. When the user types the first, she gets the second as
1508 well, with optional special formatting done on {}. (Disabled by
1509 default.) You can always quote (with \\[quoted-insert]) the left
1510 \"paren\" to avoid the expansion. The processing of < is special,
1511 since most the time you mean \"less\". CPerl mode tries to guess
1512 whether you want to type pair <>, and inserts is if it
1513 appropriate. You can set `cperl-electric-parens-string' to the string that
1514 contains the parenths from the above list you want to be electrical.
1515 Electricity of parenths is controlled by `cperl-electric-parens'.
1516 You may also set `cperl-electric-parens-mark' to have electric parens
1517 look for active mark and \"embrace\" a region if possible.'
1519 CPerl mode provides expansion of the Perl control constructs:
1521 if, else, elsif, unless, while, until, continue, do,
1522 for, foreach, formy and foreachmy.
1524 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
1526 The user types the keyword immediately followed by a space, which
1527 causes the construct to be expanded, and the point is positioned where
1528 she is most likely to want to be. eg. when the user types a space
1529 following \"if\" the following appears in the buffer: if () { or if ()
1530 } { } and the cursor is between the parentheses. The user can then
1531 type some boolean expression within the parens. Having done that,
1532 typing \\[cperl-linefeed] places you - appropriately indented - on a
1533 new line between the braces (if you typed \\[cperl-linefeed] in a POD
1534 directive line, then appropriate number of new lines is inserted).
1536 If CPerl decides that you want to insert \"English\" style construct like
1540 it will not do any expansion. See also help on variable
1541 `cperl-extra-newline-before-brace'. (Note that one can switch the
1542 help message on expansion by setting `cperl-message-electric-keyword'
1545 \\[cperl-linefeed] is a convenience replacement for typing carriage
1546 return. It places you in the next line with proper indentation, or if
1547 you type it inside the inline block of control construct, like
1549 foreach (@lines) {print; print}
1551 and you are on a boundary of a statement inside braces, it will
1552 transform the construct into a multiline and will place you into an
1553 appropriately indented blank line. If you need a usual
1554 `newline-and-indent' behavior, it is on \\[newline-and-indent],
1555 see documentation on `cperl-electric-linefeed'.
1557 Use \\[cperl-invert-if-unless] to change a construction of the form
1567 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
1568 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
1569 on electric space between $ and {, `cperl-electric-parens-string' is
1570 the string that contains parentheses that should be electric in CPerl
1571 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
1572 setting `cperl-electric-keywords' enables electric expansion of
1573 control structures in CPerl. `cperl-electric-linefeed' governs which
1574 one of two linefeed behavior is preferable. You can enable all these
1575 options simultaneously (recommended mode of use) by setting
1576 `cperl-hairy' to t. In this case you can switch separate options off
1577 by setting them to `null'. Note that one may undo the extra
1578 whitespace inserted by semis and braces in `auto-newline'-mode by
1579 consequent \\[cperl-electric-backspace].
1581 If your site has perl5 documentation in info format, you can use commands
1582 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
1583 These keys run commands `cperl-info-on-current-command' and
1584 `cperl-info-on-command', which one is which is controlled by variable
1585 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
1586 \(in turn affected by `cperl-hairy').
1588 Even if you have no info-format documentation, short one-liner-style
1589 help is available on \\[cperl-get-help], and one can run perldoc or
1592 It is possible to show this help automatically after some idle time.
1593 This is regulated by variable `cperl-lazy-help-time'. Default with
1594 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
1595 secs idle time . It is also possible to switch this on/off from the
1596 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
1598 Use \\[cperl-lineup] to vertically lineup some construction - put the
1599 beginning of the region at the start of construction, and make region
1600 span the needed amount of lines.
1602 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
1603 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
1604 here-docs sections. With capable Emaxen results of scan are used
1605 for indentation too, otherwise they are used for highlighting only.
1607 Variables controlling indentation style:
1608 `cperl-tab-always-indent'
1609 Non-nil means TAB in CPerl mode should always reindent the current line,
1610 regardless of where in the line point is when the TAB command is used.
1611 `cperl-indent-left-aligned-comments'
1612 Non-nil means that the comment starting in leftmost column should indent.
1613 `cperl-auto-newline'
1614 Non-nil means automatically newline before and after braces,
1615 and after colons and semicolons, inserted in Perl code. The following
1616 \\[cperl-electric-backspace] will remove the inserted whitespace.
1617 Insertion after colons requires both this variable and
1618 `cperl-auto-newline-after-colon' set.
1619 `cperl-auto-newline-after-colon'
1620 Non-nil means automatically newline even after colons.
1621 Subject to `cperl-auto-newline' setting.
1622 `cperl-indent-level'
1623 Indentation of Perl statements within surrounding block.
1624 The surrounding block's indentation is the indentation
1625 of the line on which the open-brace appears.
1626 `cperl-continued-statement-offset'
1627 Extra indentation given to a substatement, such as the
1628 then-clause of an if, or body of a while, or just a statement continuation.
1629 `cperl-continued-brace-offset'
1630 Extra indentation given to a brace that starts a substatement.
1631 This is in addition to `cperl-continued-statement-offset'.
1632 `cperl-brace-offset'
1633 Extra indentation for line if it starts with an open brace.
1634 `cperl-brace-imaginary-offset'
1635 An open brace following other text is treated as if it the line started
1636 this far to the right of the actual line indentation.
1637 `cperl-label-offset'
1638 Extra indentation for line that is a label.
1639 `cperl-min-label-indent'
1640 Minimal indentation for line that is a label.
1642 Settings for classic indent-styles: K&R BSD=C++ GNU PerlStyle=Whitesmith
1643 `cperl-indent-level' 5 4 2 4
1644 `cperl-brace-offset' 0 0 0 0
1645 `cperl-continued-brace-offset' -5 -4 0 0
1646 `cperl-label-offset' -5 -4 -2 -4
1647 `cperl-continued-statement-offset' 5 4 2 4
1649 CPerl knows several indentation styles, and may bulk set the
1650 corresponding variables. Use \\[cperl-set-style] to do this. Use
1651 \\[cperl-set-style-back] to restore the memorized preexisting values
1652 \(both available from menu). See examples in `cperl-style-examples'.
1654 Part of the indentation style is how different parts of if/elsif/else
1655 statements are broken into lines; in CPerl, this is reflected on how
1656 templates for these constructs are created (controlled by
1657 `cperl-extra-newline-before-brace'), and how reflow-logic should treat \"continuation\" blocks of else/elsif/continue, controlled by the same variable,
1658 and by `cperl-extra-newline-before-brace-multiline',
1659 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'.
1661 If `cperl-indent-level' is 0, the statement after opening brace in
1662 column 0 is indented on
1663 `cperl-brace-offset'+`cperl-continued-statement-offset'.
1665 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
1668 DO NOT FORGET to read micro-docs (available from `Perl' menu)
1669 or as help on variables `cperl-tips', `cperl-problems',
1670 `cperl-praise', `cperl-speed'."
1672 (kill-all-local-variables)
1673 (use-local-map cperl-mode-map
)
1674 (if (cperl-val 'cperl-electric-linefeed
)
1676 (local-set-key "\C-J" 'cperl-linefeed
)
1677 (local-set-key "\C-C\C-J" 'newline-and-indent
)))
1679 (cperl-val 'cperl-clobber-lisp-bindings
)
1680 (cperl-val 'cperl-info-on-command-no-prompt
))
1682 ;; don't clobber the backspace binding:
1683 (cperl-define-key "\C-hf" 'cperl-info-on-current-command
[(control h
) f
])
1684 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
1685 [(control c
) (control h
) f
])))
1686 (setq major-mode cperl-use-major-mode
)
1687 (setq mode-name
"CPerl")
1688 (if (not cperl-mode-abbrev-table
)
1689 (let ((prev-a-c abbrevs-changed
))
1690 (define-abbrev-table 'cperl-mode-abbrev-table
'(
1691 ("if" "if" cperl-electric-keyword
0)
1692 ("elsif" "elsif" cperl-electric-keyword
0)
1693 ("while" "while" cperl-electric-keyword
0)
1694 ("until" "until" cperl-electric-keyword
0)
1695 ("unless" "unless" cperl-electric-keyword
0)
1696 ("else" "else" cperl-electric-else
0)
1697 ("continue" "continue" cperl-electric-else
0)
1698 ("for" "for" cperl-electric-keyword
0)
1699 ("foreach" "foreach" cperl-electric-keyword
0)
1700 ("formy" "formy" cperl-electric-keyword
0)
1701 ("foreachmy" "foreachmy" cperl-electric-keyword
0)
1702 ("do" "do" cperl-electric-keyword
0)
1703 ("=pod" "=pod" cperl-electric-pod
0)
1704 ("=over" "=over" cperl-electric-pod
0)
1705 ("=head1" "=head1" cperl-electric-pod
0)
1706 ("=head2" "=head2" cperl-electric-pod
0)
1707 ("pod" "pod" cperl-electric-pod
0)
1708 ("over" "over" cperl-electric-pod
0)
1709 ("head1" "head1" cperl-electric-pod
0)
1710 ("head2" "head2" cperl-electric-pod
0)))
1711 (setq abbrevs-changed prev-a-c
)))
1712 (setq local-abbrev-table cperl-mode-abbrev-table
)
1713 (if (cperl-val 'cperl-electric-keywords
)
1715 (set-syntax-table cperl-mode-syntax-table
)
1716 ;; Until Emacs is multi-threaded, we do not actually need it local:
1717 (make-local-variable 'cperl-font-lock-multiline-start
)
1718 (make-local-variable 'cperl-font-locking
)
1719 (make-local-variable 'outline-regexp
)
1720 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
1721 (setq outline-regexp cperl-outline-regexp
)
1722 (make-local-variable 'outline-level
)
1723 (setq outline-level
'cperl-outline-level
)
1724 (make-local-variable 'paragraph-start
)
1725 (setq paragraph-start
(concat "^$\\|" page-delimiter
))
1726 (make-local-variable 'paragraph-separate
)
1727 (setq paragraph-separate paragraph-start
)
1728 (make-local-variable 'paragraph-ignore-fill-prefix
)
1729 (setq paragraph-ignore-fill-prefix t
)
1732 (make-local-variable 'paren-backwards-message
)
1733 (set 'paren-backwards-message t
)))
1734 (make-local-variable 'indent-line-function
)
1735 (setq indent-line-function
'cperl-indent-line
)
1736 (make-local-variable 'require-final-newline
)
1737 (setq require-final-newline mode-require-final-newline
)
1738 (make-local-variable 'comment-start
)
1739 (setq comment-start
"# ")
1740 (make-local-variable 'comment-end
)
1741 (setq comment-end
"")
1742 (make-local-variable 'comment-column
)
1743 (setq comment-column cperl-comment-column
)
1744 (make-local-variable 'comment-start-skip
)
1745 (setq comment-start-skip
"#+ *")
1746 (make-local-variable 'defun-prompt-regexp
)
1748 ;;; (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
1749 ;;; cperl-maybe-white-and-comment-rex ; 15=pre-block
1750 (setq defun-prompt-regexp
1751 (concat "^[ \t]*\\(sub"
1752 (cperl-after-sub-regexp 'named
'attr-groups
)
1754 "\\(BEGIN\\|CHECK\\|INIT\\|END\\|AUTOLOAD\\|DESTROY\\)"
1756 cperl-maybe-white-and-comment-rex
))
1757 (make-local-variable 'comment-indent-function
)
1758 (setq comment-indent-function
'cperl-comment-indent
)
1759 (and (boundp 'fill-paragraph-function
)
1761 (make-local-variable 'fill-paragraph-function
)
1762 (set 'fill-paragraph-function
'cperl-fill-paragraph
)))
1763 (make-local-variable 'parse-sexp-ignore-comments
)
1764 (setq parse-sexp-ignore-comments t
)
1765 (make-local-variable 'indent-region-function
)
1766 (setq indent-region-function
'cperl-indent-region
)
1767 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
1768 (make-local-variable 'imenu-create-index-function
)
1769 (setq imenu-create-index-function
1770 (function cperl-imenu--create-perl-index
))
1771 (make-local-variable 'imenu-sort-function
)
1772 (setq imenu-sort-function nil
)
1773 (make-local-variable 'vc-rcs-header
)
1774 (set 'vc-rcs-header cperl-vc-rcs-header
)
1775 (make-local-variable 'vc-sccs-header
)
1776 (set 'vc-sccs-header cperl-vc-sccs-header
)
1777 ;; This one is obsolete...
1778 (make-local-variable 'vc-header-alist
)
1779 (set 'vc-header-alist
(or cperl-vc-header-alist
; Avoid warning
1780 (` ((SCCS (, (car cperl-vc-sccs-header
)))
1781 (RCS (, (car cperl-vc-rcs-header
)))))))
1782 (cond ((boundp 'compilation-error-regexp-alist-alist
);; xemacs 20.x
1783 (make-local-variable 'compilation-error-regexp-alist-alist
)
1784 (set 'compilation-error-regexp-alist-alist
1785 (cons (cons 'cperl cperl-compilation-error-regexp-alist
)
1786 (symbol-value 'compilation-error-regexp-alist-alist
)))
1787 (if (fboundp 'compilation-build-compilation-error-regexp-alist
)
1788 (let ((f 'compilation-build-compilation-error-regexp-alist
))
1790 (push 'cperl compilation-error-regexp-alist
)))
1791 ((boundp 'compilation-error-regexp-alist
);; xmeacs 19.x
1792 (make-local-variable 'compilation-error-regexp-alist
)
1793 (set 'compilation-error-regexp-alist
1794 (cons cperl-compilation-error-regexp-alist
1795 (symbol-value 'compilation-error-regexp-alist
)))))
1796 (make-local-variable 'font-lock-defaults
)
1797 (setq font-lock-defaults
1799 ((string< emacs-version
"19.30")
1800 '(cperl-font-lock-keywords-2 nil nil
((?_ .
"w"))))
1801 ((string< emacs-version
"19.33") ; Which one to use?
1802 '((cperl-font-lock-keywords
1803 cperl-font-lock-keywords-1
1804 cperl-font-lock-keywords-2
) nil nil
((?_ .
"w"))))
1806 '((cperl-load-font-lock-keywords
1807 cperl-load-font-lock-keywords-1
1808 cperl-load-font-lock-keywords-2
) nil nil
((?_ .
"w"))))))
1809 (make-local-variable 'cperl-syntax-state
)
1810 (setq cperl-syntax-state nil
) ; reset syntaxification cache
1811 (if cperl-use-syntax-table-text-property
1813 (make-local-variable 'parse-sexp-lookup-properties
)
1814 ;; Do not introduce variable if not needed, we check it!
1815 (set 'parse-sexp-lookup-properties t
)
1816 ;; Fix broken font-lock:
1817 (or (boundp 'font-lock-unfontify-region-function
)
1818 (set 'font-lock-unfontify-region-function
1819 'font-lock-default-unfontify-region
))
1820 (unless cperl-xemacs-p
; Our: just a plug for wrong font-lock
1821 (make-local-variable 'font-lock-unfontify-region-function
)
1822 (set 'font-lock-unfontify-region-function
; not present with old Emacs
1823 'cperl-font-lock-unfontify-region-function
))
1824 (make-local-variable 'cperl-syntax-done-to
)
1825 (setq cperl-syntax-done-to nil
) ; reset syntaxification cache
1826 (make-local-variable 'font-lock-syntactic-keywords
)
1827 (setq font-lock-syntactic-keywords
1828 (if cperl-syntaxify-by-font-lock
1829 '((cperl-fontify-syntaxically))
1830 ;; unless font-lock-syntactic-keywords, font-lock (pre-22.1)
1831 ;; used to ignore syntax-table text-properties. (t) is a hack
1832 ;; to make font-lock think that font-lock-syntactic-keywords
1835 (if (boundp 'font-lock-multiline
) ; Newer font-lock; use its facilities
1837 (setq cperl-font-lock-multiline t
) ; Not localized...
1838 (set 'font-lock-multiline t
)) ; not present with old Emacs; auto-local
1839 (make-local-variable 'font-lock-fontify-region-function
)
1840 (set 'font-lock-fontify-region-function
; not present with old Emacs
1841 'cperl-font-lock-fontify-region-function
))
1842 (make-local-variable 'font-lock-fontify-region-function
)
1843 (set 'font-lock-fontify-region-function
; not present with old Emacs
1844 'cperl-font-lock-fontify-region-function
)
1845 (make-local-variable 'cperl-old-style
)
1846 (if (boundp 'normal-auto-fill-function
) ; 19.33 and later
1847 (set (make-local-variable 'normal-auto-fill-function
)
1848 'cperl-do-auto-fill
)
1849 (or (fboundp 'cperl-old-auto-fill-mode
)
1851 (fset 'cperl-old-auto-fill-mode
(symbol-function 'auto-fill-mode
))
1852 (defun auto-fill-mode (&optional arg
)
1854 (eval '(cperl-old-auto-fill-mode arg
)) ; Avoid a warning
1855 (and auto-fill-function
(memq major-mode
'(perl-mode cperl-mode
))
1856 (setq auto-fill-function
'cperl-do-auto-fill
))))))
1857 (if (cperl-enable-font-lock)
1858 (if (cperl-val 'cperl-font-lock
)
1859 (progn (or cperl-faces-init
(cperl-init-faces))
1860 (font-lock-mode 1))))
1861 (set (make-local-variable 'facemenu-add-face-function
)
1862 'cperl-facemenu-add-face-function
) ; XXXX What this guy is for???
1863 (and (boundp 'msb-menu-cond
)
1864 (not cperl-msb-fixed
)
1866 (if (featurep 'easymenu
)
1867 (easy-menu-add cperl-menu
)) ; A NOP in Emacs.
1868 (run-mode-hooks 'cperl-mode-hook
)
1869 (if cperl-hook-after-change
1871 (make-local-hook 'after-change-functions
)
1872 (add-hook 'after-change-functions
'cperl-after-change-function nil t
)))
1873 ;; After hooks since fontification will break this
1874 (if cperl-pod-here-scan
1875 (or cperl-syntaxify-by-font-lock
1876 (progn (or cperl-faces-init
(cperl-init-faces-weak))
1877 (cperl-find-pods-heres)))))
1879 ;; Fix for perldb - make default reasonable
1883 (perldb (read-from-minibuffer "Run perldb (like this): "
1884 (if (consp gud-perldb-history
)
1885 (car gud-perldb-history
)
1886 (concat "perl " ;;(file-name-nondirectory
1890 (buffer-file-name)))
1892 '(gud-perldb-history .
1))))
1894 (defun cperl-msb-fix ()
1895 ;; Adds perl files to msb menu, supposes that msb is already loaded
1896 (setq cperl-msb-fixed t
)
1897 (let* ((l (length msb-menu-cond
))
1898 (last (nth (1- l
) msb-menu-cond
))
1899 (precdr (nthcdr (- l
2) msb-menu-cond
)) ; cdr of this is last
1900 (handle (1- (nth 1 last
))))
1901 (setcdr precdr
(list
1903 '(memq major-mode
'(cperl-mode perl-mode
))
1908 ;; This is used by indent-for-comment
1909 ;; to decide how much to indent a comment in CPerl code
1910 ;; based on its context. Do fallback if comment is found wrong.
1912 (defvar cperl-wrong-comment
)
1913 (defvar cperl-st-cfence
'(14)) ; Comment-fence
1914 (defvar cperl-st-sfence
'(15)) ; String-fence
1915 (defvar cperl-st-punct
'(1))
1916 (defvar cperl-st-word
'(2))
1917 (defvar cperl-st-bra
'(4 . ?\
>))
1918 (defvar cperl-st-ket
'(5 . ?\
<))
1921 (defun cperl-comment-indent () ; called at point at supposed comment
1922 (let ((p (point)) (c (current-column)) was phony
)
1923 (if (and (not cperl-indent-comment-at-column-0
)
1925 0 ; Existing comment at bol stays there.
1926 ;; Wrong comment found
1928 (setq was
(cperl-to-comment-or-eol)
1929 phony
(eq (get-text-property (point) 'syntax-table
)
1932 (progn ; Too naive???
1933 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
1934 (if (eq (preceding-char) ?\
#)
1937 (if (= (point) p
) ; Our caller found a correct place
1939 (skip-chars-backward " \t")
1940 (setq was
(current-column))
1943 (max (1+ was
) ; Else indent at comment column
1945 ;; No, the caller found a random place; we need to edit ourselves
1947 (insert comment-start
)
1948 (backward-char (length comment-start
)))
1949 (setq cperl-wrong-comment t
)
1950 (cperl-make-indent comment-column
1) ; Indent min 1
1953 ;;;(defun cperl-comment-indent-fallback ()
1954 ;;; "Is called if the standard comment-search procedure fails.
1955 ;;;Point is at start of real comment."
1956 ;;; (let ((c (current-column)) target cnt prevc)
1957 ;;; (if (= c comment-column) nil
1958 ;;; (setq cnt (skip-chars-backward "[ \t]"))
1959 ;;; (setq target (max (1+ (setq prevc
1960 ;;; (current-column))) ; Else indent at comment column
1961 ;;; comment-column))
1962 ;;; (if (= c comment-column) nil
1963 ;;; (delete-backward-char cnt)
1964 ;;; (while (< prevc target)
1966 ;;; (setq prevc (current-column)))
1967 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
1968 ;;; (while (< prevc target)
1970 ;;; (setq prevc (current-column)))))))
1972 (defun cperl-indent-for-comment ()
1973 "Substitute for `indent-for-comment' in CPerl."
1975 (let (cperl-wrong-comment)
1976 (indent-for-comment)
1977 (if cperl-wrong-comment
; set by `cperl-comment-indent'
1978 (progn (cperl-to-comment-or-eol)
1979 (forward-char (length comment-start
))))))
1981 (defun cperl-comment-region (b e arg
)
1982 "Comment or uncomment each line in the region in CPerl mode.
1983 See `comment-region'."
1984 (interactive "r\np")
1985 (let ((comment-start "#"))
1986 (comment-region b e arg
)))
1988 (defun cperl-uncomment-region (b e arg
)
1989 "Uncomment or comment each line in the region in CPerl mode.
1990 See `comment-region'."
1991 (interactive "r\np")
1992 (let ((comment-start "#"))
1993 (comment-region b e
(- arg
))))
1995 (defvar cperl-brace-recursing nil
)
1997 (defun cperl-electric-brace (arg &optional only-before
)
1998 "Insert character and correct line's indentation.
1999 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
2000 place (even in empty line), but not after. If after \")\" and the inserted
2001 char is \"{\", insert extra newline before only if
2002 `cperl-extra-newline-before-brace'."
2005 (other-end (if (and cperl-electric-parens-mark
2011 (not cperl-brace-recursing
)
2012 (cperl-val 'cperl-electric-parens
)
2013 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
2014 ;; Need to insert a matching pair
2017 (setq insertpos
(point-marker))
2018 (goto-char other-end
)
2019 (setq last-command-char ?\
{)
2020 (cperl-electric-lbrace arg insertpos
))
2022 ;; Check whether we close something "usual" with `}'
2023 (if (and (eq last-command-char ?\
})
2027 (up-list (- (prefix-numeric-value arg
)))
2028 ;;(cperl-after-block-p (point-min))
2029 (or (cperl-after-expr-p nil
"{;)")
2030 ;; after sub, else, continue
2031 (cperl-after-block-p nil
'pre
)))
2033 ;; Just insert the guy
2034 (self-insert-command (prefix-numeric-value arg
))
2035 (if (and (not arg
) ; No args, end (of empty line or auto)
2037 (or (and (null only-before
)
2039 (skip-chars-backward " \t")
2041 (and (eq last-command-char ?\
{) ; Do not insert newline
2042 ;; if after ")" and `cperl-extra-newline-before-brace'
2043 ;; is nil, do not insert extra newline.
2044 (not cperl-extra-newline-before-brace
)
2046 (skip-chars-backward " \t")
2047 (eq (preceding-char) ?\
))))
2048 (if cperl-auto-newline
2049 (progn (cperl-indent-line) (newline) t
) nil
)))
2051 (self-insert-command (prefix-numeric-value arg
))
2053 (if cperl-auto-newline
2054 (setq insertpos
(1- (point))))
2055 (if (and cperl-auto-newline
(null only-before
))
2058 (cperl-indent-line)))
2060 (if insertpos
(progn (goto-char insertpos
)
2061 (search-forward (make-string
2062 1 last-command-char
))
2063 (setq insertpos
(1- (point)))))
2067 (goto-char insertpos
)
2068 (self-insert-command (prefix-numeric-value arg
)))
2069 (self-insert-command (prefix-numeric-value arg
)))))))
2071 (defun cperl-electric-lbrace (arg &optional end
)
2072 "Insert character, correct line's indentation, correct quoting by space."
2074 (let ((cperl-brace-recursing t
)
2075 (cperl-auto-newline cperl-auto-newline
)
2077 (if (and cperl-electric-parens-mark
2085 (and (cperl-val 'cperl-electric-lbrace-space
)
2086 (eq (preceding-char) ?$
)
2088 (skip-chars-backward "$")
2089 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
2091 ;; Check whether we are in comment
2095 (not (looking-at "[ \t]*#")))
2096 (cperl-after-expr-p nil
"{;)"))
2098 (setq cperl-auto-newline nil
))
2099 (cperl-electric-brace arg
)
2100 (and (cperl-val 'cperl-electric-parens
)
2101 (eq last-command-char ?
{)
2102 (memq last-command-char
2103 (append cperl-electric-parens-string nil
))
2104 (or (if other-end
(goto-char (marker-position other-end
)))
2106 (setq last-command-char ?
} pos
(point))
2107 (progn (cperl-electric-brace arg t
)
2110 (defun cperl-electric-paren (arg)
2111 "Insert an opening parenthesis or a matching pair of parentheses.
2112 See `cperl-electric-parens'."
2114 (let ((beg (save-excursion (beginning-of-line) (point)))
2115 (other-end (if (and cperl-electric-parens-mark
2122 (if (and (cperl-val 'cperl-electric-parens
)
2123 (memq last-command-char
2124 (append cperl-electric-parens-string nil
))
2125 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2126 ;;(not (save-excursion (search-backward "#" beg t)))
2127 (if (eq last-command-char ?
<)
2129 (and abbrev-mode
; later it is too late, may be after `for'
2131 (cperl-after-expr-p nil
"{;(,:="))
2134 (self-insert-command (prefix-numeric-value arg
))
2135 (if other-end
(goto-char (marker-position other-end
)))
2136 (insert (make-string
2137 (prefix-numeric-value arg
)
2138 (cdr (assoc last-command-char
'((?
{ .?
})
2142 (forward-char (- (prefix-numeric-value arg
))))
2143 (self-insert-command (prefix-numeric-value arg
)))))
2145 (defun cperl-electric-rparen (arg)
2146 "Insert a matching pair of parentheses if marking is active.
2147 If not, or if we are not at the end of marking range, would self-insert.
2148 Affected by `cperl-electric-parens'."
2150 (let ((beg (save-excursion (beginning-of-line) (point)))
2151 (other-end (if (and cperl-electric-parens-mark
2152 (cperl-val 'cperl-electric-parens
)
2153 (memq last-command-char
2154 (append cperl-electric-parens-string nil
))
2161 (cperl-val 'cperl-electric-parens
)
2162 (memq last-command-char
'( ?\
) ?\
] ?\
} ?\
> ))
2163 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2164 ;;(not (save-excursion (search-backward "#" beg t)))
2167 (self-insert-command (prefix-numeric-value arg
))
2169 (if other-end
(goto-char other-end
))
2170 (insert (make-string
2171 (prefix-numeric-value arg
)
2172 (cdr (assoc last-command-char
'((?\
} . ?\
{)
2177 (self-insert-command (prefix-numeric-value arg
)))))
2179 (defun cperl-electric-keyword ()
2180 "Insert a construction appropriate after a keyword.
2181 Help message may be switched off by setting `cperl-message-electric-keyword'
2183 (let ((beg (save-excursion (beginning-of-line) (point)))
2184 (dollar (and (eq last-command-char ?$
)
2185 (eq this-command
'self-insert-command
)))
2186 (delete (and (memq last-command-char
'(?\s ?
\n ?
\t ?
\f))
2187 (memq this-command
'(self-insert-command newline
))))
2189 (and (save-excursion
2193 (setq do
(looking-at "do\\>")))
2195 (cperl-after-expr-p nil
"{;:"))
2199 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2201 (save-excursion (or (not (re-search-backward "^=" nil t
))
2204 (and cperl-use-syntax-table-text-property
2205 (not (eq (get-text-property (point)
2208 (save-excursion (forward-sexp -
1)
2209 (not (memq (following-char) (append "$@%&*" nil
))))
2211 (and (eq (preceding-char) ?y
)
2212 (progn ; "foreachmy"
2218 (memq this-command
'(self-insert-command newline
)))))
2219 (and dollar
(insert " $"))
2221 ;;(insert " () {\n}")
2223 (cperl-extra-newline-before-brace
2224 (insert (if do
"\n" " ()\n"))
2230 (and do
(insert " while ();")))
2232 (insert (if do
" {\n} while ();" " () {\n}"))))
2233 (or (looking-at "[ \t]\\|$") (insert " "))
2235 (if dollar
(progn (search-backward "$")
2239 (search-backward ")")
2240 (if (eq last-command-char ?\
()
2241 (progn ; Avoid "if (())"
2242 (delete-backward-char 1)
2243 (delete-backward-char -
1))))
2245 (cperl-putback-char cperl-del-back-ch
))
2246 (if cperl-message-electric-keyword
2247 (message "Precede char by C-q to avoid expansion"))))))
2249 (defun cperl-ensure-newlines (n &optional pos
)
2250 "Make sure there are N newlines after the point."
2251 (or pos
(setq pos
(point)))
2252 (if (looking-at "\n")
2256 (cperl-ensure-newlines (1- n
) pos
)
2259 (defun cperl-electric-pod ()
2260 "Insert a POD chunk appropriate after a =POD directive."
2261 (let ((delete (and (memq last-command-char
'(?\s ?
\n ?
\t ?
\f))
2262 (memq this-command
'(self-insert-command newline
))))
2263 head1 notlast name p really-delete over
)
2264 (and (save-excursion
2267 (eq (preceding-char) ?
=)
2269 (setq head1
(looking-at "head1\\>[ \t]*$"))
2270 (setq over
(and (looking-at "over\\>[ \t]*$")
2271 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
2275 (get-text-property (point) 'in-pod
)
2276 (cperl-after-expr-p nil
"{;:")
2277 (and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t
)
2278 (not (looking-at "\n*=cut"))
2279 (or (not cperl-use-syntax-table-text-property
)
2280 (eq (get-text-property (point) 'syntax-type
) 'pod
))))))
2283 (setq notlast
(re-search-forward "^\n=" nil t
)))
2287 (cperl-ensure-newlines 2)
2293 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
2294 nil t
)))) ; Only one
2297 (setq name
(file-name-sans-extension
2298 (file-name-nondirectory (buffer-file-name)))
2300 (insert " NAME\n\n" name
2301 " - \n\n=head1 SYNOPSIS\n\n\n\n"
2302 "=head1 DESCRIPTION")
2303 (cperl-ensure-newlines 4)
2307 (setq really-delete t
))
2312 (insert "\n\n=item \n\n\n\n"
2314 (cperl-ensure-newlines 2)
2318 (setq really-delete t
)))
2319 (if (and delete really-delete
)
2320 (cperl-putback-char cperl-del-back-ch
))))))
2322 (defun cperl-electric-else ()
2323 "Insert a construction appropriate after a keyword.
2324 Help message may be switched off by setting `cperl-message-electric-keyword'
2326 (let ((beg (save-excursion (beginning-of-line) (point))))
2327 (and (save-excursion
2329 (cperl-after-expr-p nil
"{;:"))
2333 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2335 (save-excursion (or (not (re-search-backward "^=" nil t
))
2337 (and cperl-use-syntax-table-text-property
2338 (not (eq (get-text-property (point)
2343 ;;(insert " {\n\n}")
2345 (cperl-extra-newline-before-brace
2351 (insert " {\n\n}")))
2352 (or (looking-at "[ \t]\\|$") (insert " "))
2356 (cperl-putback-char cperl-del-back-ch
)
2357 (setq this-command
'cperl-electric-else
)
2358 (if cperl-message-electric-keyword
2359 (message "Precede char by C-q to avoid expansion"))))))
2361 (defun cperl-linefeed ()
2362 "Go to end of line, open a new line and indent appropriately.
2363 If in POD, insert appropriate lines."
2365 (let ((beg (save-excursion (beginning-of-line) (point)))
2366 (end (save-excursion (end-of-line) (point)))
2367 (pos (point)) start over cut res
)
2368 (if (and ; Check if we need to split:
2369 ; i.e., on a boundary and inside "{...}"
2370 (save-excursion (cperl-to-comment-or-eol)
2371 (>= (point) pos
)) ; Not in a comment
2373 (skip-chars-backward " \t" beg
)
2375 (looking-at "[;{]")) ; After { or ; + spaces
2376 (looking-at "[ \t]*}") ; Before }
2377 (re-search-forward "\\=[ \t]*;" end t
)) ; Before spaces + ;
2380 (eq (car (parse-partial-sexp pos end -
1)) -
1)
2381 ; Leave the level of parens
2382 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
2384 (cperl-after-block-p (point-min))
2387 (setq start
(point-marker))
2388 (<= start pos
))))) ; Redundant? Are after the
2389 ; start of parens group.
2391 (skip-chars-backward " \t")
2392 (or (memq (preceding-char) (append ";{" nil
))
2398 (or (looking-at "{[ \t]*$") ; If there is a statement
2399 ; before, move it to separate line
2403 (cperl-indent-line)))
2404 (forward-line 1) ; We are on the target line
2407 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
2408 ; after, move it to separate line
2411 (search-backward "}" beg
)
2412 (skip-chars-backward " \t")
2413 (or (memq (preceding-char) (append ";{" nil
))
2418 (forward-line -
1) ; We are on the line before target
2420 (newline-and-indent))
2421 (end-of-line) ; else - no splitting
2423 ((and (looking-at "\n[ \t]*{$")
2425 (skip-chars-backward " \t")
2426 (eq (preceding-char) ?\
)))) ; Probably if () {} group
2427 ; with an extra newline.
2429 (cperl-indent-line))
2430 ((save-excursion ; In POD header
2431 (forward-paragraph -
1)
2432 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
2433 ;; We are after \n now, so look for the rest
2434 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
2436 (setq cut
(looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
2437 (setq over
(looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
2441 (forward-paragraph -
1)
2444 (setq cut
(buffer-substring (point)
2448 (delete-char (- (save-excursion (end-of-line) (point))
2450 (setq res
(expand-abbrev))
2456 (cperl-ensure-newlines (if cut
2 4))
2458 ((get-text-property (point) 'in-pod
) ; In POD section
2459 (cperl-ensure-newlines 4)
2461 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
2463 (cperl-indent-line))
2465 (newline-and-indent))))))
2467 (defun cperl-electric-semi (arg)
2468 "Insert character and correct line's indentation."
2470 (if cperl-auto-newline
2471 (cperl-electric-terminator arg
)
2472 (self-insert-command (prefix-numeric-value arg
))
2473 (if cperl-autoindent-on-semi
2474 (cperl-indent-line))))
2476 (defun cperl-electric-terminator (arg)
2477 "Insert character and correct line's indentation."
2480 (auto (and cperl-auto-newline
2481 (or (not (eq last-command-char ?
:))
2482 cperl-auto-newline-after-colon
)))
2484 (if (and ;;(not arg)
2486 (not (save-excursion
2488 (skip-chars-forward " \t")
2490 ;; Ignore in comment lines
2491 (= (following-char) ?
#)
2492 ;; Colon is special only after a label
2493 ;; So quickly rule out most other uses of colon
2494 ;; and do no indentation for them.
2495 (and (eq last-command-char ?
:)
2498 (skip-chars-forward " \t")
2499 (and (< (point) end
)
2500 (progn (goto-char (- end
1))
2501 (not (looking-at ":"))))))
2503 (beginning-of-defun)
2504 (let ((pps (parse-partial-sexp (point) end
)))
2505 (or (nth 3 pps
) (nth 4 pps
) (nth 5 pps
))))))))
2507 (self-insert-command (prefix-numeric-value arg
))
2509 (if auto
(setq insertpos
(point-marker)))
2515 (cperl-indent-line)))
2517 (if insertpos
(goto-char (1- (marker-position insertpos
)))
2522 (goto-char insertpos
)
2523 (self-insert-command (prefix-numeric-value arg
)))
2524 (self-insert-command (prefix-numeric-value arg
)))))
2526 (defun cperl-electric-backspace (arg)
2527 "Backspace, or remove the whitespace around the point inserted by an electric
2528 key. Will untabify if `cperl-electric-backspace-untabify' is non-nil."
2530 (if (and cperl-auto-newline
2531 (memq last-command
'(cperl-electric-semi
2532 cperl-electric-terminator
2533 cperl-electric-lbrace
))
2534 (memq (preceding-char) '(?\s ?
\t ?
\n)))
2536 (if (eq last-command
'cperl-electric-lbrace
)
2537 (skip-chars-forward " \t\n"))
2539 (skip-chars-backward " \t\n")
2540 (delete-region (point) p
))
2541 (and (eq last-command
'cperl-electric-else
)
2542 ;; We are removing the whitespace *inside* cperl-electric-else
2543 (setq this-command
'cperl-electric-else-really
))
2544 (if (and cperl-auto-newline
2545 (eq last-command
'cperl-electric-else-really
)
2546 (memq (preceding-char) '(?\s ?
\t ?
\n)))
2548 (skip-chars-forward " \t\n")
2550 (skip-chars-backward " \t\n")
2551 (delete-region (point) p
))
2552 (if cperl-electric-backspace-untabify
2553 (backward-delete-char-untabify arg
)
2554 (delete-backward-char arg
)))))
2556 (put 'cperl-electric-backspace
'delete-selection
'supersede
)
2558 (defun cperl-inside-parens-p () ;; NOT USED????
2562 (narrow-to-region (point)
2563 (progn (beginning-of-defun) (point)))
2564 (goto-char (point-max))
2565 (= (char-after (or (scan-lists (point) -
1 1) (point-min))) ?\
()))
2568 (defun cperl-indent-command (&optional whole-exp
)
2569 "Indent current line as Perl code, or in some cases insert a tab character.
2570 If `cperl-tab-always-indent' is non-nil (the default), always indent current
2571 line. Otherwise, indent the current line only if point is at the left margin
2572 or in the line's indentation; otherwise insert a tab.
2574 A numeric argument, regardless of its value,
2575 means indent rigidly all the lines of the expression starting after point
2576 so that this line becomes properly indented.
2577 The relative indentation among the lines of the expression are preserved."
2579 (cperl-update-syntaxification (point) (point))
2581 ;; If arg, always indent this line as Perl
2582 ;; and shift remaining lines of expression the same amount.
2583 (let ((shift-amt (cperl-indent-line))
2586 (if cperl-tab-always-indent
2587 (beginning-of-line))
2594 (if (and shift-amt
(> end beg
))
2595 (indent-code-rigidly beg end shift-amt
"#")))
2596 (if (and (not cperl-tab-always-indent
)
2598 (skip-chars-backward " \t")
2601 (cperl-indent-line))))
2603 (defun cperl-indent-line (&optional parse-data
)
2604 "Indent current line as Perl code.
2605 Return the amount the indentation changed by."
2606 (let ((case-fold-search nil
)
2607 (pos (- (point-max) (point)))
2608 indent i beg shift-amt
)
2609 (setq indent
(cperl-calculate-indent parse-data
)
2613 (cond ((or (eq indent nil
) (eq indent t
))
2614 (setq indent
(current-indentation) i nil
))
2615 ;;((eq indent t) ; Never?
2616 ;; (setq indent (cperl-calculate-indent-within-comment)))
2617 ;;((looking-at "[ \t]*#")
2620 (skip-chars-forward " \t")
2621 (if (listp indent
) (setq indent
(car indent
)))
2622 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
2624 (setq indent
(max cperl-min-label-indent
2625 (+ indent cperl-label-offset
)))))
2626 ((= (following-char) ?
})
2627 (setq indent
(- indent cperl-indent-level
)))
2628 ((memq (following-char) '(?\
) ?\
])) ; To line up with opening paren.
2629 (setq indent
(+ indent cperl-close-paren-offset
)))
2630 ((= (following-char) ?
{)
2631 (setq indent
(+ indent cperl-brace-offset
))))))
2632 (skip-chars-forward " \t")
2633 (setq shift-amt
(and i
(- indent
(current-column))))
2634 (if (or (not shift-amt
)
2636 (if (> (- (point-max) pos
) (point))
2637 (goto-char (- (point-max) pos
)))
2638 ;;;(delete-region beg (point))
2639 ;;;(indent-to indent)
2640 (cperl-make-indent indent
)
2641 ;; If initial point was within line's indentation,
2642 ;; position after the indentation. Else stay at same point in text.
2643 (if (> (- (point-max) pos
) (point))
2644 (goto-char (- (point-max) pos
))))
2647 (defun cperl-after-label ()
2648 ;; Returns true if the point is after label. Does not do save-excursion.
2649 (and (eq (preceding-char) ?
:)
2650 (memq (char-syntax (char-after (- (point) 2)))
2654 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
2656 (defun cperl-get-state (&optional parse-start start-state
)
2657 ;; returns list (START STATE DEPTH PRESTART),
2658 ;; START is a good place to start parsing, or equal to
2659 ;; PARSE-START if preset,
2660 ;; STATE is what is returned by `parse-partial-sexp'.
2661 ;; DEPTH is true is we are immediately after end of block
2662 ;; which contains START.
2663 ;; PRESTART is the position basing on which START was found.
2665 (let ((start-point (point)) depth state start prestart
)
2666 (if (and parse-start
2667 (<= parse-start start-point
))
2668 (goto-char parse-start
)
2669 (beginning-of-defun)
2670 (setq start-state nil
))
2671 (setq prestart
(point))
2673 ;; Try to go out, if sub is not on the outermost level
2674 (while (< (point) start-point
)
2675 (setq start
(point) parse-start start depth nil
2676 state
(parse-partial-sexp start start-point -
1))
2677 (if (> (car state
) -
1) nil
2678 ;; The current line could start like }}}, so the indentation
2679 ;; corresponds to a different level than what we reached
2681 (beginning-of-line 2))) ; Go to the next line.
2682 (if start
(goto-char start
))) ; Not at the start of file
2683 (setq start
(point))
2684 (or state
(setq state
(parse-partial-sexp start start-point -
1 nil start-state
)))
2685 (list start state depth prestart
))))
2687 (defvar cperl-look-for-prop
'((pod in-pod
) (here-doc-delim here-doc-group
)))
2689 (defun cperl-beginning-of-property (p prop
&optional lim
)
2690 "Given that P has a property PROP, find where the property starts.
2691 Will not look before LIM."
2692 ;;; XXXX What to do at point-max???
2693 (or (previous-single-property-change (cperl-1+ p
) prop lim
)
2695 ;;; (cond ((eq p (point-min))
2697 ;;; ((and lim (<= p lim))
2699 ;;; ((not (get-text-property (1- p) prop))
2701 ;;; (t (or (previous-single-property-change p look-prop lim)
2705 (defun cperl-sniff-for-indent (&optional parse-data
) ; was parse-start
2706 ;; Old workhorse for calculation of indentation; the major problem
2707 ;; is that it mixes the sniffer logic to understand what the current line
2708 ;; MEANS with the logic to actually calculate where to indent it.
2709 ;; The latter part should be eventually moved to `cperl-calculate-indent';
2710 ;; actually, this is mostly done now...
2711 (cperl-update-syntaxification (point) (point))
2712 (let ((res (get-text-property (point) 'syntax-type
)))
2715 ((and (memq res
'(pod here-doc here-doc-delim format
))
2716 (not (get-text-property (point) 'indentable
)))
2718 ;; before start of POD - whitespace found since do not have 'pod!
2719 ((looking-at "[ \t]*\n=")
2720 (error "Spaces before POD section!"))
2721 ((and (not cperl-indent-left-aligned-comments
)
2723 [comment-special
:at-beginning-of-line
])
2724 ((get-text-property (point) 'in-pod
)
2728 (let* ((indent-point (point))
2729 (char-after-pos (save-excursion
2730 (skip-chars-forward " \t")
2732 (char-after (char-after char-after-pos
))
2733 (pre-indent-point (point))
2734 p prop look-prop is-block delim
)
2735 (save-excursion ; Know we are not in POD, find appropriate pos before
2736 (cperl-backward-to-noncomment nil
)
2737 (setq p
(max (point-min) (1- (point)))
2738 prop
(get-text-property p
'syntax-type
)
2739 look-prop
(or (nth 1 (assoc prop cperl-look-for-prop
))
2741 (if (memq prop
'(pod here-doc format here-doc-delim
))
2743 (goto-char (cperl-beginning-of-property p look-prop
))
2745 (setq pre-indent-point
(point)))))
2746 (goto-char pre-indent-point
) ; Orig line skipping preceeding pod/etc
2747 (let* ((case-fold-search nil
)
2748 (s-s (cperl-get-state (car parse-data
) (nth 1 parse-data
)))
2749 (start (or (nth 2 parse-data
) ; last complete sexp terminated
2750 (nth 0 s-s
))) ; Good place to start parsing
2752 (containing-sexp (car (cdr state
)))
2755 ;;containing-sexp ;; We are buggy at toplevel :-(
2758 (setcar parse-data pre-indent-point
)
2759 (setcar (cdr parse-data
) state
)
2760 (or (nth 2 parse-data
)
2761 (setcar (cddr parse-data
) start
))
2762 ;; Before this point: end of statement
2763 (setq old-indent
(nth 3 parse-data
))))
2764 (cond ((get-text-property (point) 'indentable
)
2765 ;; indent to "after" the surrounding open
2766 ;; (same offset as `cperl-beautify-regexp-piece'),
2767 ;; skip blanks if we do not close the expression.
2768 (setq delim
; We do not close the expression
2770 (cperl-1+ char-after-pos
) 'indentable
)
2771 p
(1+ (cperl-beginning-of-property
2772 (point) 'indentable
))
2773 is-block
; misused for: preceeding line in REx
2774 (save-excursion ; Find preceeding line
2775 (cperl-backward-to-noncomment p
)
2778 (progn ; get indent from the first line
2780 (skip-chars-forward " \t")
2781 (if (memq (char-after (point))
2783 nil
; Can't use intentation of this line...
2785 (skip-chars-forward " \t")
2787 prop
(parse-partial-sexp p char-after-pos
))
2788 (cond ((not delim
) ; End the REx, ignore is-block
2789 (vector 'indentable
'terminator p is-block
))
2790 (is-block ; Indent w.r.t. preceeding line
2791 (vector 'indentable
'cont-line char-after-pos
2792 is-block char-after p
))
2793 (t ; No preceeding line...
2794 (vector 'indentable
'first-line p
))))
2795 ((get-text-property char-after-pos
'REx-part2
)
2796 (vector 'REx-part2
(point)))
2801 ;; XXXX Do we need to special-case this?
2802 ((null containing-sexp)
2803 ;; Line is at top level. May be data or function definition,
2804 ;; or may be function argument declaration.
2805 ;; Indent like the previous top level line
2806 ;; unless that ends in a closeparen without semicolon,
2807 ;; in which case this line is the first argument decl.
2808 (skip-chars-forward " \t")
2809 (cperl-backward-to-noncomment (or old-indent (point-min)))
2812 (eq (point) old-indent) ; old-indent was at comment
2813 (eq (preceding-char) ?\;)
2815 (and (eq (preceding-char) ?\})
2816 (cperl-after-block-and-statement-beg
2817 (point-min))) ; Was start - too close
2818 (memq char-after (append ")]}" nil))
2819 (and (eq (preceding-char) ?\:) ; label
2822 (skip-chars-backward " \t")
2823 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
2824 (get-text-property (point) 'first-format-line)))
2826 ;; Look at previous line that's at column 0
2827 ;; to determine whether we are in top-level decls
2828 ;; or function's arg decls. Set basic-indent accordingly.
2829 ;; Now add a little if this is a continuation line.
2832 (not (eq char-after ?\C-j))
2833 (setcdr (cddr parse-data)
2834 (list pre-indent-point)))
2835 (vector 'toplevel start char-after state (nth 2 s-s)))
2838 (and (setq delim (= (char-after containing-sexp) ?{))
2839 (save-excursion ; Is it a hash?
2840 (goto-char containing-sexp)
2842 cperl-indent-parens-as-block))
2843 ;; group is an expression, not a block:
2844 ;; indent to just after the surrounding open parens,
2845 ;; skip blanks if we do not close the expression.
2846 (goto-char (1+ containing-sexp))
2847 (or (memq char-after
2848 (append (if delim "}" ")]}") nil))
2849 (looking-at "[ \t]*\\(#\\|$\\)")
2850 (skip-chars-forward " \t"))
2851 (setq old-indent (point)) ; delim=is-brace
2852 (vector 'in-parens char-after (point) delim containing-sexp))
2854 ;; Statement level. Is it a continuation or a new statement?
2855 ;; Find previous non-comment character.
2856 (goto-char pre-indent-point) ; Skip one level of POD/etc
2857 (cperl-backward-to-noncomment containing-sexp)
2858 ;; Back up over label lines, since they don't
2859 ;; affect whether our line is a continuation.
2861 (while;;(or (eq (preceding-char) ?\,)
2862 (and (eq (preceding-char) ?:)
2863 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
2864 (memq (char-syntax (char-after (- (point) 2)))
2867 ;; This is always FALSE?
2868 (if (eq (preceding-char) ?\,)
2869 ;; Will go to beginning of line, essentially.
2870 ;; Will ignore embedded sexpr XXXX.
2871 (cperl-backward-to-start-of-continued-exp containing-sexp))
2873 (cperl-backward-to-noncomment containing-sexp))
2874 ;; Now we get non-label preceeding the indent point
2875 (if (not (or (eq (1- (point)) containing-sexp)
2876 (memq (preceding-char)
2877 (append (if is-block " ;{" " ,;{") '(nil)))
2878 (and (eq (preceding-char) ?\})
2879 (cperl-after-block-and-statement-beg
2881 (get-text-property (point) 'first-format-line)))
2882 ;; This line is continuation of preceding line's statement;
2883 ;; indent `cperl-continued-statement-offset' more than the
2884 ;; previous line of the statement.
2886 ;; There might be a label on this line, just
2887 ;; consider it bad style and ignore it.
2889 (cperl-backward-to-start-of-continued-exp containing-sexp)
2890 (vector 'continuation (point) char-after is-block delim))
2891 ;; This line starts a new statement.
2892 ;; Position following last unclosed open brace
2893 (goto-char containing-sexp)
2894 ;; Is line first statement after an open-brace?
2896 ;; If no, find that first statement and indent like
2897 ;; it. If the first statement begins with label, do
2898 ;; not believe when the indentation of the label is too
2902 (let ((colon-line-end 0))
2904 (progn (skip-chars-forward " \t\n")
2905 (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]\\|=[a-zA-Z]"))
2906 ;; Skip over comments and labels following openbrace.
2907 (cond ((= (following-char) ?\#)
2909 ((= (following-char) ?\=)
2911 (or (next-single-property-change (point) 'in-pod)
2912 (point-max)))) ; do not loop if no syntaxification
2915 (save-excursion (end-of-line)
2916 (setq colon-line-end (point)))
2917 (search-forward ":"))))
2918 ;; We are at beginning of code (NOT label or comment)
2919 ;; First, the following code counts
2920 ;; if it is before the line we want to indent.
2921 (and (< (point) indent-point)
2922 (vector 'have-prev-sibling (point) colon-line-end
2925 ;; If no previous statement,
2926 ;; indent it relative to line brace is on.
2928 ;; For open-braces not the first thing in a line,
2929 ;; add in cperl-brace-imaginary-offset.
2931 ;; If first thing on a line: ?????
2932 ;; Move back over whitespace before the openbrace.
2933 (setq ; brace first thing on a line
2934 old-indent (progn (skip-chars-backward " \t") (bolp)))
2935 ;; Should we indent w.r.t. earlier than start?
2936 ;; Move to start of control group, possibly on a different line
2937 (or cperl-indent-wrt-brace
2938 (cperl-backward-to-noncomment (point-min)))
2939 ;; If the openbrace is preceded by a parenthesized exp,
2940 ;; move to the beginning of that;
2941 (if (eq (preceding-char) ?\))
2944 (cperl-backward-to-noncomment (point-min))))
2945 ;; In the case it starts a subroutine, indent with
2946 ;; respect to `sub', not with respect to the
2947 ;; first thing on the line, say in the case of
2948 ;; anonymous sub in a hash.
2949 (if (and;; Is it a sub in group starting on this line?
2950 (cond ((get-text-property (point) 'attrib-group)
2951 (goto-char (cperl-beginning-of-property
2952 (point) 'attrib-group)))
2953 ((eq (preceding-char) ?b)
2955 (looking-at "sub\\>")))
2956 (setq p (nth 1 ; start of innermost containing list
2958 (save-excursion (beginning-of-line)
2962 (goto-char (1+ p)) ; enclosing block on the same line
2963 (skip-chars-forward " \t")
2964 (vector 'code-start-in-block containing-sexp char-after
2965 (and delim (not is-block)) ; is a HASH
2966 old-indent ; brace first thing on a line
2967 t (point) ; have something before...
2971 ;; Get initial indentation of the line we are on.
2972 ;; If line starts with label, calculate label indentation
2973 (vector 'code-start-in-block containing-sexp char-after
2974 (and delim (not is-block)) ; is a HASH
2975 old-indent ; brace first thing on a line
2976 nil (point) ; nothing interesting before
2979 (defvar cperl-indent-rules-alist
2980 '((pod nil) ; via `syntax-type' property
2981 (here-doc nil) ; via `syntax-type' property
2982 (here-doc-delim nil) ; via `syntax-type' property
2983 (format nil) ; via `syntax-type' property
2984 (in-pod nil) ; via `in-pod' property
2985 (comment-special:at-beginning-of-line nil)
2988 "Alist of indentation rules for CPerl mode.
2991 number: add this amount of indentation.
2995 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
2996 "Return appropriate indentation for current line as Perl code.
2997 In usual case returns an integer: the column to indent to.
2998 Returns nil if line starts inside a string, t if in a comment.
3000 Will not correct the indentation for labels, but will correct it for braces
3001 and closing parentheses and brackets."
3002 ;; This code is still a broken architecture: in some cases we need to
3003 ;; compensate for some modifications which `cperl-indent-line' will add later
3005 (let ((i (cperl-sniff-for-indent parse-data)) what p)
3007 ;;((or (null i) (eq i t) (numberp i))
3010 (setq what (assoc (elt i 0) cperl-indent-rules-alist))
3012 (what (cadr what)) ; Load from table
3014 ;; Indenters for regular expressions with //x and qw()
3016 ((eq 'REx-part2 (elt i 0)) ;; [self start] start of /REP in s//REP/x
3017 (goto-char (elt i 1))
3018 (condition-case nil ; Use indentation of the 1st part
3021 ((eq 'indentable (elt i 0)) ; Indenter for REGEXP qw() etc
3022 (cond ;;; [indentable terminator start-pos is-block]
3023 ((eq 'terminator (elt i 1)) ; Lone terminator of "indentable string"
3024 (goto-char (elt i 2)) ; After opening parens
3025 (1- (current-column)))
3026 ((eq 'first-line (elt i 1)); [indentable first-line start-pos]
3027 (goto-char (elt i 2))
3028 (+ (or cperl-regexp-indent-step cperl-indent-level)
3031 ((eq 'cont-line (elt i 1)); [indentable cont-line pos prev-pos first-char start-pos]
3032 ;; Indent as the level after closing parens
3033 (goto-char (elt i 2)) ; indent line
3034 (skip-chars-forward " \t)") ; Skip closing parens
3036 (goto-char (elt i 3)) ; previous line
3037 (skip-chars-forward " \t)") ; Skip closing parens
3038 ;; Number of parens in between:
3039 (setq p (nth 0 (parse-partial-sexp (point) p))
3040 what (elt i 4)) ; First char on current line
3041 (goto-char (elt i 3)) ; previous line
3042 (+ (* p (or cperl-regexp-indent-step cperl-indent-level))
3043 (cond ((eq what ?\) )
3044 (- cperl-close-paren-offset)) ; compensate
3046 (- (or cperl-regexp-indent-step cperl-indent-level)))
3048 (if (eq (following-char) ?\| )
3049 (or cperl-regexp-indent-step cperl-indent-level)
3053 (error "Unrecognized value of indent: %s" i))))
3055 ;; Indenter for stuff at toplevel
3057 ((eq 'toplevel (elt i 0)) ;; [toplevel start char-after state immed-after-block]
3058 (+ (save-excursion ; To beg-of-defun, or end of last sexp
3059 (goto-char (elt i 1)) ; start = Good place to start parsing
3060 (- (current-indentation) ;
3061 (if (elt i 4) cperl-indent-level 0))) ; immed-after-block
3062 (if (eq (elt i 2) ?{) cperl-continued-brace-offset 0) ; char-after
3063 ;; Look at previous line that's at column 0
3064 ;; to determine whether we are in top-level decls
3065 ;; or function's arg decls. Set basic-indent accordingly.
3066 ;; Now add a little if this is a continuation line.
3067 (if (elt i 3) ; state (XXX What is the semantic???)
3069 cperl-continued-statement-offset)))
3071 ;; Indenter for stuff in "parentheses" (or brackets, braces-as-hash)
3073 ((eq 'in-parens (elt i 0))
3074 ;; in-parens char-after old-indent-point is-brace containing-sexp
3076 ;; group is an expression, not a block:
3077 ;; indent to just after the surrounding open parens,
3078 ;; skip blanks if we do not close the expression.
3080 (goto-char (elt i 2)) ; old-indent-point
3082 (if (and (elt i 3) ; is-brace
3083 (eq (elt i 1) ?\})) ; char-after
3084 ;; Correct indentation of trailing ?\}
3085 (+ cperl-indent-level cperl-close-paren-offset)
3088 ;; Indenter for continuation lines
3090 ((eq 'continuation (elt i 0))
3091 ;; [continuation statement-start char-after is-block is-brace]
3092 (goto-char (elt i 1)) ; statement-start
3093 (+ (if (memq (elt i 2) (append "}])" nil)) ; char-after
3095 cperl-continued-statement-offset)
3096 (if (or (elt i 3) ; is-block
3097 (not (elt i 4)) ; is-brace
3098 (not (eq (elt i 2) ?\}))) ; char-after
3100 ;; Now it is a hash reference
3101 (+ cperl-indent-level cperl-close-paren-offset))
3102 ;; Labels do not take :: ...
3103 (if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
3104 (if (> (current-indentation) cperl-min-label-indent)
3105 (- (current-indentation) cperl-label-offset)
3106 ;; Do not move `parse-data', this should
3107 ;; be quick anyway (this comment comes
3108 ;; from different location):
3109 (cperl-calculate-indent))
3111 (if (eq (elt i 2) ?\{) ; char-after
3112 cperl-continued-brace-offset 0)))
3114 ;; Indenter for lines in a block which are not leading lines
3116 ((eq 'have-prev-sibling (elt i 0))
3117 ;; [have-prev-sibling sibling-beg colon-line-end block-start]
3118 (goto-char (elt i 1))
3119 (if (> (elt i 2) (point)) ; colon-line-end; After-label, same line
3120 (if (> (current-indentation)
3121 cperl-min-label-indent)
3122 (- (current-indentation) cperl-label-offset)
3123 ;; Do not believe: `max' was involved in calculation of indent
3124 (+ cperl-indent-level
3126 (goto-char (elt i 3)) ; block-start
3127 (current-indentation))))
3130 ;; Indenter for the first line in a block
3132 ((eq 'code-start-in-block (elt i 0))
3133 ;;[code-start-in-block before-brace char-after
3134 ;; is-a-HASH-ref brace-is-first-thing-on-a-line
3135 ;; group-starts-before-start-of-sub start-of-control-group]
3136 (goto-char (elt i 1))
3137 ;; For open brace in column zero, don't let statement
3138 ;; start there too. If cperl-indent-level=0,
3139 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3140 (+ (if (and (bolp) (zerop cperl-indent-level))
3141 (+ cperl-brace-offset cperl-continued-statement-offset)
3143 (if (and (elt i 3) ; is-a-HASH-ref
3144 (eq (elt i 2) ?\})) ; char-after: End of a hash reference
3145 (+ cperl-indent-level cperl-close-paren-offset)
3147 ;; Unless openbrace is the first nonwhite thing on the line,
3148 ;; add the cperl-brace-imaginary-offset.
3149 (if (elt i 4) 0 ; brace-is-first-thing-on-a-line
3150 cperl-brace-imaginary-offset)
3152 (goto-char (elt i 6)) ; start-of-control-group
3153 (if (elt i 5) ; group-starts-before-start-of-sub
3155 ;; Get initial indentation of the line we are on.
3156 ;; If line starts with label, calculate label indentation
3159 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3160 (if (> (current-indentation) cperl-min-label-indent)
3161 (- (current-indentation) cperl-label-offset)
3162 ;; Do not move `parse-data', this should
3164 (cperl-calculate-indent))
3165 (current-indentation))))))
3167 (error "Unrecognized value of indent: %s" i))))
3169 (error "Got strange value of indent: %s" i))))))
3171 (defvar cperl-indent-alist
3175 (toplevel-after-parenth 2)
3176 (toplevel-continued 2)
3178 "Alist of indentation rules for CPerl mode.
3181 number: add this amount of indentation.
3183 Not finished, not used.")
3185 (defun cperl-where-am-i (&optional parse-start start-state)
3187 "Return a list of lists ((TYPE POS)...) of good points before the point.
3188 POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'.
3190 Not finished, not used."
3192 (let* ((start-point (point)) unused
3193 (s-s (cperl-get-state))
3196 (prestart (nth 3 s-s))
3197 (containing-sexp (car (cdr state)))
3198 (case-fold-search nil)
3199 (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
3200 (cond ((nth 3 state) ; In string
3201 (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
3202 ((nth 4 state) ; In comment
3203 (setq res (cons '(comment) res)))
3204 ((null containing-sexp)
3205 ;; Line is at top level.
3206 ;; Indent like the previous top level line
3207 ;; unless that ends in a closeparen without semicolon,
3208 ;; in which case this line is the first argument decl.
3209 (cperl-backward-to-noncomment (or parse-start (point-min)))
3210 ;;(skip-chars-backward " \t\f\n")
3213 (memq (preceding-char) (append ";}" nil)))
3214 (setq res (cons (list 'toplevel start) res)))
3215 ((eq (preceding-char) ?\) )
3216 (setq res (cons (list 'toplevel-after-parenth start) res)))
3218 (setq res (cons (list 'toplevel-continued start) res)))))
3219 ((/= (char-after containing-sexp) ?{)
3220 ;; line is expression, not statement:
3221 ;; indent to just after the surrounding open.
3222 ;; skip blanks if we do not close the expression.
3223 (setq res (cons (list 'expression-blanks
3225 (goto-char (1+ containing-sexp))
3226 (or (looking-at "[ \t]*\\(#\\|$\\)")
3227 (skip-chars-forward " \t"))
3229 (cons (list 'expression containing-sexp) res))))
3231 ;; Containing-expr starts with \{. Check whether it is a hash.
3232 (goto-char containing-sexp)
3233 (not (cperl-block-p)))
3234 (setq res (cons (list 'expression-blanks
3236 (goto-char (1+ containing-sexp))
3237 (or (looking-at "[ \t]*\\(#\\|$\\)")
3238 (skip-chars-forward " \t"))
3240 (cons (list 'expression containing-sexp) res))))
3243 (setq res (cons (list 'in-block containing-sexp) res))
3244 ;; Is it a continuation or a new statement?
3245 ;; Find previous non-comment character.
3246 (cperl-backward-to-noncomment containing-sexp)
3247 ;; Back up over label lines, since they don't
3248 ;; affect whether our line is a continuation.
3249 ;; Back up comma-delimited lines too ?????
3250 (while (or (eq (preceding-char) ?\,)
3251 (save-excursion (cperl-after-label)))
3252 (if (eq (preceding-char) ?\,)
3253 ;; Will go to beginning of line, essentially
3254 ;; Will ignore embedded sexpr XXXX.
3255 (cperl-backward-to-start-of-continued-exp containing-sexp))
3257 (cperl-backward-to-noncomment containing-sexp))
3258 ;; Now we get the answer.
3259 (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
3260 ;; This line is continuation of preceding line's statement.
3261 (list (list 'statement-continued containing-sexp))
3262 ;; This line starts a new statement.
3263 ;; Position following last unclosed open.
3264 (goto-char containing-sexp)
3265 ;; Is line first statement after an open-brace?
3267 ;; If no, find that first statement and indent like
3268 ;; it. If the first statement begins with label, do
3269 ;; not believe when the indentation of the label is too
3273 (let ((colon-line-end 0))
3274 (while (progn (skip-chars-forward " \t\n" start-point)
3275 (and (< (point) start-point)
3277 "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
3278 ;; Skip over comments and labels following openbrace.
3279 (cond ((= (following-char) ?\#)
3284 (save-excursion (end-of-line)
3285 (setq colon-line-end (point)))
3286 (search-forward ":"))))
3287 ;; Now at the point, after label, or at start
3288 ;; of first statement in the block.
3289 (and (< (point) start-point)
3290 (if (> colon-line-end (point))
3291 ;; Before statement after label
3292 (if (> (current-indentation)
3293 cperl-min-label-indent)
3294 (list (list 'label-in-block (point)))
3295 ;; Do not believe: `max' is involved
3297 (list 'label-in-block-min-indent (point))))
3299 (list 'statement-in-block (point))))))
3300 ;; If no previous statement,
3301 ;; indent it relative to line brace is on.
3302 ;; For open brace in column zero, don't let statement
3303 ;; start there too. If cperl-indent-level is zero,
3304 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3305 ;; For open-braces not the first thing in a line,
3306 ;; add in cperl-brace-imaginary-offset.
3308 ;; If first thing on a line: ?????
3309 (setq unused ; This is not finished...
3310 (+ (if (and (bolp) (zerop cperl-indent-level))
3311 (+ cperl-brace-offset cperl-continued-statement-offset)
3313 ;; Move back over whitespace before the openbrace.
3314 ;; If openbrace is not first nonwhite thing on the line,
3315 ;; add the cperl-brace-imaginary-offset.
3316 (progn (skip-chars-backward " \t")
3317 (if (bolp) 0 cperl-brace-imaginary-offset))
3318 ;; If the openbrace is preceded by a parenthesized exp,
3319 ;; move to the beginning of that;
3320 ;; possibly a different line
3322 (if (eq (preceding-char) ?\))
3324 ;; Get initial indentation of the line we are on.
3325 ;; If line starts with label, calculate label indentation
3328 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3329 (if (> (current-indentation) cperl-min-label-indent)
3330 (- (current-indentation) cperl-label-offset)
3331 (cperl-calculate-indent))
3332 (current-indentation)))))))))
3335 (defun cperl-calculate-indent-within-comment ()
3336 "Return the indentation amount for line, assuming that
3337 the current line is to be regarded as part of a block comment."
3338 (let (end star-start)
3341 (skip-chars-forward " \t")
3343 (and (= (following-char) ?#)
3345 (cperl-to-comment-or-eol)
3351 (defun cperl-to-comment-or-eol ()
3352 "Go to position before comment on the current line, or to end of line.
3353 Returns true if comment is found. In POD will not move the point."
3354 ;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
3355 ;; then looks for literal # or end-of-line.
3356 (let (state stop-in cpoint (lim (progn (end-of-line) (point))) pr e)
3357 (or cperl-font-locking
3358 (cperl-update-syntaxification lim lim))
3360 (if (setq pr (get-text-property (point) 'syntax-type))
3361 (setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
3362 (if (or (eq pr 'pod)
3363 (if (or (not e) (> e lim)) ; deep inside a group
3364 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
3365 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
3366 ;; Else - need to do it the hard way
3367 (and (and e (<= e lim))
3369 (while (not stop-in)
3370 (setq state (parse-partial-sexp (point) lim nil nil nil t))
3372 ;; If fails (beginning-of-line inside sexp), then contains not-comment
3373 (if (nth 4 state) ; After `#';
3374 ; (nth 2 state) can be
3375 ; beginning of m,s,qq and so
3379 (setq cpoint (point))
3380 (goto-char (nth 2 state))
3382 ((looking-at "\\(s\\|tr\\)\\>")
3383 (or (re-search-forward
3384 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
3387 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
3388 (or (re-search-forward
3389 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
3392 (t ; It was fair comment
3393 (setq stop-in t) ; Finish
3394 (goto-char (1- cpoint)))))
3395 (setq stop-in t) ; Finish
3397 (setq stop-in t))) ; Finish
3400 (defsubst cperl-modify-syntax-type (at how)
3401 (if (< at (point-max))
3403 (put-text-property at (1+ at) 'syntax-table how)
3404 (put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
3406 (defun cperl-protect-defun-start (s e)
3407 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
3410 (while (re-search-forward "^\\s(" e 'to-end)
3411 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
3413 (defun cperl-commentify (bb e string &optional noface)
3414 (if cperl-use-syntax-table-text-property
3415 (if (eq noface 'n) ; Only immediate
3417 ;; We suppose that e is _after_ the end of construction, as after eol.
3418 (setq string (if string cperl-st-sfence cperl-st-cfence))
3420 ;; one-char string/comment?!
3421 (cperl-modify-syntax-type bb cperl-st-punct)
3422 (cperl-modify-syntax-type bb string)
3423 (cperl-modify-syntax-type (1- e) string))
3424 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
3425 (put-text-property (1+ bb) (1- e)
3426 'syntax-table cperl-string-syntax-table))
3427 (cperl-protect-defun-start bb e))
3430 (not cperl-pod-here-fontify)
3431 (put-text-property bb e 'face (if string 'font-lock-string-face
3432 'font-lock-comment-face)))))
3434 (defvar cperl-starters '(( ?\( . ?\) )
3439 (defun cperl-cached-syntax-table (st)
3440 "Get a syntax table cached in ST, or create and cache into ST a syntax table.
3441 All the entries of the syntax table are \".\", except for a backslash, which
3445 (setcar st (make-syntax-table))
3449 (modify-syntax-entry i "." st)
3451 (modify-syntax-entry ?\\ "\\" st)
3454 (defun cperl-forward-re (lim end is-2arg st-l err-l argument
3455 &optional ostart oend)
3456 "Find the end of a regular expression or a stringish construct (q[] etc).
3457 The point should be before the starting delimiter.
3459 Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
3460 is s/// or tr/// like expression. If END is nil, generates an error
3461 message if needed. If SET-ST is non-nil, will use (or generate) a
3462 cached syntax table in ST-L. If ERR-L is non-nil, will store the
3463 error message in its CAR (unless it already contains some error
3464 message). ARGUMENT should be the name of the construct (used in error
3465 messages). OSTART, OEND may be set in recursive calls when processing
3466 the second argument of 2ARG construct.
3468 Works *before* syntax recognition is done. In IS-2ARG situation may
3469 modify syntax-type text property if the situation is too hard."
3470 (let (b starter ender st i i2 go-forward reset-st set-st)
3471 (skip-chars-forward " \t")
3472 ;; ender means matching-char matcher.
3474 starter (if (eobp) 0 (char-after b))
3475 ender (cdr (assoc starter cperl-starters)))
3476 ;; What if starter == ?\\ ????
3477 (setq st (cperl-cached-syntax-table st-l))
3479 ;; Whether we have an intermediate point
3481 ;; Prepare the syntax table:
3482 (if (not ender) ; m/blah/, s/x//, s/x/y/
3483 (modify-syntax-entry starter "$" st)
3484 (modify-syntax-entry starter (concat "(" (list ender)) st)
3485 (modify-syntax-entry ender (concat ")" (list starter)) st))
3488 ;; We use `$' syntax class to find matching stuff, but $$
3489 ;; is recognized the same as $, so we need to check this manually.
3490 (if (and (eq starter (char-after (cperl-1+ b)))
3492 ;; $ has TeXish matching rules, so $$ equiv $...
3494 (setq reset-st (syntax-table))
3495 (set-syntax-table st)
3497 (if (<= (point) (1+ b))
3498 (error "Unfinished regular expression"))
3499 (set-syntax-table reset-st)
3501 ;; Now the problem is with m;blah;;
3503 (eq (preceding-char)
3504 (char-after (- (point) 2)))
3507 (= 0 (% (skip-chars-backward "\\\\") 2)))
3509 ;; Now we are after the first part.
3510 (and is-2arg ; Have trailing part
3512 (eq (following-char) starter) ; Empty trailing part
3514 (or (eq (char-syntax (following-char)) ?.)
3515 ;; Make trailing letter into punctuation
3516 (cperl-modify-syntax-type (point) cperl-st-punct))
3517 (setq is-2arg nil go-forward t))) ; Ignore the tail
3518 (if is-2arg ; Not number => have second part
3520 (setq i (point) i2 i)
3522 (if (memq (following-char) '(?\s ?\t ?\n ?\f))
3524 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3525 (goto-char (match-end 0))
3526 (skip-chars-forward " \t\n\f"))
3529 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3530 (if ender (modify-syntax-entry ender "." st))
3532 (setq ender (cperl-forward-re lim end nil st-l err-l
3533 argument starter ender)
3534 ender (nth 2 ender)))))
3535 (error (goto-char lim)
3538 (set-syntax-table reset-st))
3541 "End of `%s%s%c ... %c' string/RE not found: %s"
3543 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
3544 starter (or ender starter) bb)
3545 (or (car err-l) (setcar err-l b)))))
3548 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3549 (if ender (modify-syntax-entry ender "." st))))
3550 ;; i: have 2 args, after end of the first arg
3551 ;; i2: start of the second arg, if any (before delim iff `ender').
3552 ;; ender: the last arg bounded by parens-like chars, the second one of them
3553 ;; starter: the starting delimiter of the first arg
3554 ;; go-forward: has 2 args, and the second part is empty
3555 (list i i2 ender starter go-forward)))
3557 (defun cperl-forward-group-in-re (&optional st-l)
3558 "Find the end of a group in a REx.
3559 Return the error message (if any). Does not work if delimiter is `)'.
3560 Works before syntax recognition is done."
3561 ;; Works *before* syntax recognition is done
3562 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3563 (let (st b reset-st)
3566 (setq st (cperl-cached-syntax-table st-l))
3567 (modify-syntax-entry ?\( "()" st)
3568 (modify-syntax-entry ?\) ")(" st)
3569 (setq reset-st (syntax-table))
3570 (set-syntax-table st)
3573 "cperl-forward-group-in-re: error %s" b)))
3574 ;; now restore the initial state
3577 (modify-syntax-entry ?\( "." st)
3578 (modify-syntax-entry ?\) "." st)))
3580 (set-syntax-table reset-st))
3584 (defvar font-lock-string-face)
3585 ;;(defvar font-lock-reference-face)
3586 (defvar font-lock-constant-face)
3587 (defsubst cperl-postpone-fontification (b e type val &optional now)
3588 ;; Do after syntactic fontification?
3589 (if cperl-syntaxify-by-font-lock
3590 (or now (put-text-property b e 'cperl-postpone (cons type val)))
3591 (put-text-property b e type val)))
3593 ;;; Here is how the global structures (those which cannot be
3594 ;;; recognized locally) are marked:
3596 ;; Start-to-end is marked `in-pod' ==> t
3597 ;; Each non-literal part is marked `syntax-type' ==> `pod'
3598 ;; Each literal part is marked `syntax-type' ==> `in-pod'
3600 ;; Start-to-end is marked `here-doc-group' ==> t
3601 ;; The body is marked `syntax-type' ==> `here-doc'
3602 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
3604 ;; First line (to =) marked `first-format-line' ==> t
3605 ;; After-this--to-end is marked `syntax-type' ==> `format'
3606 ;; d) 'Q'uoted string:
3607 ;; part between markers inclusive is marked `syntax-type' ==> `string'
3608 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
3609 ;; second part of s///e is marked `syntax-type' ==> `multiline'
3610 ;; e) Attributes of subroutines: `attrib-group' ==> t
3611 ;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
3612 ;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
3614 ;;; In addition, some parts of RExes may be marked as `REx-interpolated'
3615 ;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
3617 (defun cperl-unwind-to-safe (before &optional end)
3618 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
3619 (let ((pos (point)) opos)
3620 (while (and pos (progn
3622 (get-text-property (setq pos (point)) 'syntax-type)))
3624 pos (cperl-beginning-of-property pos 'syntax-type))
3625 (if (eq pos (point-min))
3630 (goto-char (cperl-1- pos))
3633 (goto-char (setq pos (cperl-1- pos))))
3635 (goto-char (point-min))))
3637 (and (looking-at "\n*=")
3638 (/= 0 (skip-chars-backward "\n"))
3642 ;; Do the same for end, going small steps
3644 (while (and end (get-text-property end 'syntax-type))
3646 end (next-single-property-change end 'syntax-type nil (point-max)))
3647 (if end (progn (goto-char end)
3648 (or (bolp) (forward-line 1))
3649 (setq end (point)))))
3652 ;;; These are needed for byte-compile (at least with v19)
3653 (defvar cperl-nonoverridable-face)
3654 (defvar font-lock-variable-name-face)
3655 (defvar font-lock-function-name-face)
3656 (defvar font-lock-keyword-face)
3657 (defvar font-lock-builtin-face)
3658 (defvar font-lock-type-face)
3659 (defvar font-lock-comment-face)
3660 (defvar font-lock-warning-face)
3662 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
3663 "Syntaxically mark (and fontify) attributes of a subroutine.
3664 Should be called with the point before leading colon of an attribute."
3665 ;; Works *before* syntax recognition is done
3666 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3667 (let (st b p reset-st after-first (start (point)) start1 end1)
3671 "\\(" ; 1=optional? colon
3672 ":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
3674 (if after-first "?" "")
3675 ;; No space between name and paren allowed...
3676 "\\(\\sw+\\)" ; 3=name
3677 "\\((\\)?")) ; 4=optional paren
3678 (and (match-beginning 1)
3679 (cperl-postpone-fontification
3680 (match-beginning 0) (cperl-1+ (match-beginning 0))
3681 'face font-lock-constant-face))
3682 (setq start1 (match-beginning 3) end1 (match-end 3))
3683 (cperl-postpone-fontification start1 end1
3684 'face font-lock-constant-face)
3685 (goto-char end1) ; end or before `('
3686 (if (match-end 4) ; Have attribute arguments...
3689 (setq st (cperl-cached-syntax-table st-l))
3690 (modify-syntax-entry ?\( "()" st)
3691 (modify-syntax-entry ?\) ")(" st))
3692 (setq reset-st (syntax-table) p (point))
3693 (set-syntax-table st)
3695 (set-syntax-table reset-st)
3697 (cperl-commentify p (point) t))) ; mark as string
3698 (forward-comment (buffer-size))
3699 (setq after-first t))
3701 "L%d: attribute `%s': %s"
3702 (count-lines (point-min) (point))
3703 (and start1 end1 (buffer-substring start1 end1)) b)
3707 (put-text-property start (point)
3708 'attrib-group (if (looking-at "{") t 0))
3710 (< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
3711 ;; Apparently, we do not need `multiline': faces added now
3712 (put-text-property (+ 3 pos) (cperl-1+ (point))
3713 'syntax-type 'sub-decl))
3714 (and b-fname ; Fontify here: the following condition
3715 (cperl-postpone-fontification ; is too hard to determine by
3716 b-fname e-fname 'face ; a REx, so do it here
3717 (if (looking-at "{")
3718 font-lock-function-name-face
3719 font-lock-variable-name-face)))))
3720 ;; now restore the initial state
3723 (modify-syntax-entry ?\( "." st)
3724 (modify-syntax-entry ?\) "." st)))
3726 (set-syntax-table reset-st))))
3728 (defsubst cperl-look-at-leading-count (is-x-REx e)
3729 (if (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
3730 (1- e) t) ; return nil on failure, no moving
3731 (if (eq ?\{ (preceding-char)) nil
3732 (cperl-postpone-fontification
3733 (1- (point)) (point)
3734 'face font-lock-warning-face))))
3736 ;;; Debugging this may require (setq max-specpdl-size 2000)...
3737 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc)
3738 "Scans the buffer for hard-to-parse Perl constructions.
3739 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
3740 the sections using `cperl-pod-head-face', `cperl-pod-face',
3743 (or min (setq min (point-min)
3744 cperl-syntax-state nil
3745 cperl-syntax-done-to min))
3746 (or max (setq max (point-max)))
3747 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
3748 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
3749 is-REx is-x-REx REx-subgr-start REx-subgr-end was-subgr i2 hairy-RE
3750 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
3751 (modified (buffer-modified-p)) overshoot is-o-REx
3752 (after-change-functions nil)
3753 (cperl-font-locking t)
3754 (use-syntax-state (and cperl-syntax-state
3755 (>= min (car cperl-syntax-state))))
3756 (state-point (if use-syntax-state
3757 (car cperl-syntax-state)
3759 (state (if use-syntax-state
3760 (cdr cperl-syntax-state)))
3761 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
3762 (st-l (list nil)) (err-l (list nil))
3763 ;; Somehow font-lock may be not loaded yet...
3764 ;; (e.g., when building TAGS via command-line call)
3765 (font-lock-string-face (if (boundp 'font-lock-string-face)
3766 font-lock-string-face
3767 'font-lock-string-face))
3768 (my-cperl-delimiters-face (if (boundp 'font-lock-constant-face)
3769 font-lock-constant-face
3770 'font-lock-constant-face))
3771 (my-cperl-REx-spec-char-face ; [] ^.$ and wrapper-of ({})
3772 (if (boundp 'font-lock-function-name-face)
3773 font-lock-function-name-face
3774 'font-lock-function-name-face))
3775 (font-lock-variable-name-face ; interpolated vars and ({})-code
3776 (if (boundp 'font-lock-variable-name-face)
3777 font-lock-variable-name-face
3778 'font-lock-variable-name-face))
3779 (font-lock-function-name-face ; used in `cperl-find-sub-attrs'
3780 (if (boundp 'font-lock-function-name-face)
3781 font-lock-function-name-face
3782 'font-lock-function-name-face))
3783 (font-lock-constant-face ; used in `cperl-find-sub-attrs'
3784 (if (boundp 'font-lock-constant-face)
3785 font-lock-constant-face
3786 'font-lock-constant-face))
3787 (my-cperl-REx-0length-face ; 0-length, (?:)etc, non-literal \
3788 (if (boundp 'font-lock-builtin-face)
3789 font-lock-builtin-face
3790 'font-lock-builtin-face))
3791 (font-lock-comment-face
3792 (if (boundp 'font-lock-comment-face)
3793 font-lock-comment-face
3794 'font-lock-comment-face))
3795 (font-lock-warning-face
3796 (if (boundp 'font-lock-warning-face)
3797 font-lock-warning-face
3798 'font-lock-warning-face))
3799 (my-cperl-REx-ctl-face ; (|)
3800 (if (boundp 'font-lock-keyword-face)
3801 font-lock-keyword-face
3802 'font-lock-keyword-face))
3803 (my-cperl-REx-modifiers-face ; //gims
3804 (if (boundp 'cperl-nonoverridable-face)
3805 cperl-nonoverridable-face
3806 'cperl-nonoverridable-face))
3807 (my-cperl-REx-length1-face ; length=1 escaped chars, POSIX classes
3808 (if (boundp 'font-lock-type-face)
3810 'font-lock-type-face))
3811 (stop-point (if ignore-max
3816 "\\(\\`\n?\\|^\n\\)=" ; POD
3818 ;; One extra () before this:
3821 ;; First variant "BLAH" or just ``.
3822 "[ \t]*" ; Yes, whitespace is allowed!
3823 "\\([\"'`]\\)" ; 2 + 1 = 3
3824 "\\([^\"'`\n]*\\)" ; 3 + 1
3827 ;; Second variant: Identifier or \ID (same as 'ID') or empty
3828 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3829 ;; Do not have <<= or << 30 or <<30 or << $blah.
3830 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3831 "\\(\\)" ; To preserve count of pars :-( 6 + 1
3834 ;; 1+6 extra () before this:
3835 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" ;FRMAT
3836 (if cperl-use-syntax-table-text-property
3839 ;; 1+6+2=9 extra () before this:
3840 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT
3842 ;; 1+6+2+1=10 extra () before this:
3843 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3845 ;; 1+6+2+1+1=11 extra () before this
3846 "\\<sub\\>" ; sub with proto/attr
3848 cperl-white-and-comment-rex
3849 "\\(::[a-zA-Z_:'0-9]*\\|[a-zA-Z_'][a-zA-Z_:'0-9]*\\)\\)?" ; name
3851 cperl-maybe-white-and-comment-rex
3852 "\\(([^()]*)\\|:[^:]\\)\\)" ; prototype or attribute start
3854 ;; 1+6+2+1+1+6=17 extra () before this:
3855 "\\$\\(['{]\\)" ; $' or ${foo}
3857 ;; 1+6+2+1+1+6+1=18 extra () before this (old pack'var syntax;
3858 ;; we do not support intervening comments...):
3859 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
3860 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
3862 "__\\(END\\|DATA\\)__" ; __END__ or __DATA__
3863 ;; 1+6+2+1+1+6+1+1+1=20 extra () before this:
3865 "\\\\\\(['`\"($]\\)") ; BACKWACKED something-hairy
3871 (message "Scanning for \"hard\" Perl constructions..."))
3872 ;;(message "find: %s --> %s" min max)
3873 (and cperl-pod-here-fontify
3874 ;; We had evals here, do not know why...
3875 (setq face cperl-pod-face
3876 head-face cperl-pod-head-face
3877 here-face cperl-here-face))
3878 (remove-text-properties min max
3879 '(syntax-type t in-pod t syntax-table t
3890 ;; Need to remove face as well...
3892 (and (eq system-type 'emx)
3894 (let ((case-fold-search t))
3895 (looking-at "extproc[ \t]")) ; Analogue of #!
3896 (cperl-commentify min
3897 (save-excursion (end-of-line) (point))
3901 (re-search-forward search max t))
3902 (setq tmpend nil) ; Valid for most cases
3903 (setq b (match-beginning 0)
3904 state (save-excursion (parse-partial-sexp
3905 state-point b nil nil state))
3908 ;; 1+6+2+1+1+6=17 extra () before this:
3910 ((match-beginning 18) ; $' or ${foo}
3911 (if (eq (preceding-char) ?\') ; $'
3913 (setq b (1- (point))
3914 state (parse-partial-sexp
3915 state-point (1- b) nil nil state)
3917 (if (nth 3 state) ; in string
3918 (cperl-modify-syntax-type (1- b) cperl-st-punct))
3921 (setq bb (match-beginning 0))
3922 (cperl-modify-syntax-type bb cperl-st-punct)))
3923 ;; No processing in strings/comments beyond this point:
3924 ((or (nth 3 state) (nth 4 state))
3925 t) ; Do nothing in comment/string
3926 ((match-beginning 1) ; POD section
3927 ;; "\\(\\`\n?\\|^\n\\)="
3928 (setq b (match-beginning 0)
3929 state (parse-partial-sexp
3930 state-point b nil nil state)
3932 (if (or (nth 3 state) (nth 4 state)
3933 (looking-at "cut\\>"))
3934 (if (or (nth 3 state) (nth 4 state) ignore-max)
3935 nil ; Doing a chunk only
3936 (message "=cut is not preceded by a POD section")
3937 (or (car err-l) (setcar err-l (point))))
3942 tb (match-beginning 0)
3943 b1 nil) ; error condition
3944 ;; We do not search to max, since we may be called from
3945 ;; some hook of fontification, and max is random
3946 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
3949 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
3951 (message "=cut is not preceded by an empty line")
3953 (or (car err-l) (setcar err-l b))))))
3954 (beginning-of-line 2) ; An empty line after =cut is not POD!
3958 (remove-text-properties
3959 max e '(syntax-type t in-pod t syntax-table t
3971 (put-text-property b e 'in-pod t)
3972 (put-text-property b e 'syntax-type 'in-pod)
3974 (while (re-search-forward "\n\n[ \t]" e t)
3975 ;; We start 'pod 1 char earlier to include the preceding line
3977 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
3978 (cperl-put-do-not-fontify b (point) t)
3979 ;; mark the non-literal parts as PODs
3980 (if cperl-pod-here-fontify
3981 (cperl-postpone-fontification b (point) 'face face t))
3982 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
3985 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
3986 (cperl-put-do-not-fontify (point) e t)
3987 (if cperl-pod-here-fontify
3989 ;; mark the non-literal parts as PODs
3990 (cperl-postpone-fontification (point) e 'face face t)
3993 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
3995 (cperl-postpone-fontification
3996 (match-beginning 1) (match-end 1)
3998 (while (re-search-forward
4000 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
4003 (cperl-postpone-fontification
4004 (match-beginning 1) (match-end 1)
4006 (cperl-commentify bb e nil)
4008 (or (eq e (point-max))
4009 (forward-char -1)))) ; Prepare for immediate POD start.
4011 ;; We can do many here-per-line;
4012 ;; but multiline quote on the same line as <<HERE confuses us...
4013 ;; ;; One extra () before this:
4016 ;; ;; First variant "BLAH" or just ``.
4017 ;; "[ \t]*" ; Yes, whitespace is allowed!
4018 ;; "\\([\"'`]\\)" ; 2 + 1
4019 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
4022 ;; ;; Second variant: Identifier or \ID or empty
4023 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
4024 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
4025 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
4026 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
4028 ((match-beginning 2) ; 1 + 1
4030 tb (match-beginning 0)
4031 c (and ; not HERE-DOC
4034 (or (looking-at "[ \t]*(") ; << function_call()
4035 (save-excursion ; 1 << func_name, or $foo << 10
4039 ;;; XXX What to do: foo <<bar ???
4040 ;;; XXX Need to support print {a} <<B ???
4043 ; $foo << b; $f .= <<B;
4044 ; ($f+1) << b; a($f) . <<B;
4045 ; foo 1, <<B; $x{a} <<b;
4047 ((looking-at "[0-9$({]")
4050 (looking-at "[ \t]*<<")
4056 (looking-at "\\(printf?\\|system\\|exec\\|sort\\)\\>")))
4058 (error nil))) ; func(<<EOF)
4059 (and (not (match-beginning 6)) ; Empty
4061 "[ \t]*[=0-9$@%&(]"))))))
4062 (if c ; Not here-doc
4064 (setq c (match-end 2)) ; 1 + 1
4065 (if (match-beginning 5) ;4 + 1
4066 (setq b1 (match-beginning 5) ; 4 + 1
4067 e1 (match-end 5)) ; 4 + 1
4068 (setq b1 (match-beginning 4) ; 3 + 1
4069 e1 (match-end 4))) ; 3 + 1
4070 (setq tag (buffer-substring b1 e1)
4071 qtag (regexp-quote tag))
4072 (cond (cperl-pod-here-fontify
4073 ;; Highlight the starting delimiter
4074 (cperl-postpone-fontification
4075 b1 e1 'face my-cperl-delimiters-face)
4076 (cperl-put-do-not-fontify b1 e1 t)))
4080 (goto-char end-of-here-doc))
4082 ;; We do not search to max, since we may be called from
4083 ;; some hook of fontification, and max is random
4084 (or (and (re-search-forward (concat "^" qtag "$")
4086 ;;;(eq (following-char) ?\n) ; XXXX WHY???
4088 (progn ; Pretend we matched at the end
4089 (goto-char (point-max))
4090 (re-search-forward "\\'")
4091 (message "End of here-document `%s' not found." tag)
4092 (or (car err-l) (setcar err-l b))))
4093 (if cperl-pod-here-fontify
4095 ;; Highlight the ending delimiter
4096 (cperl-postpone-fontification
4097 (match-beginning 0) (match-end 0)
4098 'face my-cperl-delimiters-face)
4099 (cperl-put-do-not-fontify b (match-end 0) t)
4100 ;; Highlight the HERE-DOC
4101 (cperl-postpone-fontification b (match-beginning 0)
4103 (setq e1 (cperl-1+ (match-end 0)))
4104 (put-text-property b (match-beginning 0)
4105 'syntax-type 'here-doc)
4106 (put-text-property (match-beginning 0) e1
4107 'syntax-type 'here-doc-delim)
4108 (put-text-property b e1 'here-doc-group t)
4109 ;; This makes insertion at the start of HERE-DOC update
4110 ;; the whole construct:
4111 (put-text-property b (cperl-1+ b) 'front-sticky '(syntax-type))
4112 (cperl-commentify b e1 nil)
4113 (cperl-put-do-not-fontify b (match-end 0) t)
4114 ;; Cache the syntax info...
4115 (setq cperl-syntax-state (cons state-point state))
4116 ;; ... and process the rest of the line...
4118 (elt ; non-inter ignore-max
4119 (cperl-find-pods-heres c i t end t e1) 1))
4120 (if (and overshoot (> overshoot (point)))
4121 (goto-char overshoot)
4122 (setq overshoot e1))
4126 ((match-beginning 8)
4127 ;; 1+6=7 extra () before this:
4128 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
4130 name (if (match-beginning 8) ; 7 + 1
4131 (buffer-substring (match-beginning 8) ; 7 + 1
4132 (match-end 8)) ; 7 + 1
4134 tb (match-beginning 0))
4136 (put-text-property (save-excursion
4139 b 'first-format-line 't)
4140 (if cperl-pod-here-fontify
4141 (while (and (eq (forward-line) 0)
4142 (not (looking-at "^[.;]$")))
4144 ((looking-at "^#")) ; Skip comments
4145 ((and argument ; Skip argument multi-lines
4146 (looking-at "^[ \t]*{"))
4148 (setq argument nil))
4149 (argument ; Skip argument lines
4150 (setq argument nil))
4153 (setq argument (looking-at "^[^\n]*[@^]"))
4155 ;; Highlight the format line
4156 (cperl-postpone-fontification b1 (point)
4157 'face font-lock-string-face)
4158 (cperl-commentify b1 (point) nil)
4159 (cperl-put-do-not-fontify b1 (point) t))))
4160 ;; We do not search to max, since we may be called from
4161 ;; some hook of fontification, and max is random
4162 (re-search-forward "^[.;]$" stop-point 'toend))
4164 (if (looking-at "^\\.$") ; ";" is not supported yet
4166 ;; Highlight the ending delimiter
4167 (cperl-postpone-fontification (point) (+ (point) 2)
4168 'face font-lock-string-face)
4169 (cperl-commentify (point) (+ (point) 2) nil)
4170 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
4171 (message "End of format `%s' not found." name)
4172 (or (car err-l) (setcar err-l b)))
4176 (put-text-property b (point) 'syntax-type 'format))
4177 ;; qq-like String or Regexp:
4178 ((or (match-beginning 10) (match-beginning 11))
4179 ;; 1+6+2=9 extra () before this:
4180 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
4182 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
4183 (setq b1 (if (match-beginning 10) 10 11)
4184 argument (buffer-substring
4185 (match-beginning b1) (match-end b1))
4186 b (point) ; end of qq etc
4188 c (char-after (match-beginning b1))
4189 bb (char-after (1- (match-beginning b1))) ; tmp holder
4190 ;; bb == "Not a stringy"
4191 bb (if (eq b1 10) ; user variables/whatever
4192 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
4193 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
4194 ((eq bb ?\:) ; $opt::s
4196 (- (match-beginning b1) 2))
4198 ((eq bb ?\>) ; $foo->s
4200 (- (match-beginning b1) 2))
4203 (not (eq (char-after ; &&m/blah/
4204 (- (match-beginning b1) 2))
4207 ;; <file> or <$file>
4209 ;; Do not stringify <FH>, <$fh> :
4212 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
4213 tb (match-beginning 0))
4214 (goto-char (match-beginning b1))
4215 (cperl-backward-to-noncomment (point-min))
4217 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
4222 ;; What is below: regexp-p?
4224 (or (memq (preceding-char)
4225 (append (if (memq c '(?\? ?\<))
4228 "~{(=|&+-*!,;:[") nil))
4229 (and (eq (preceding-char) ?\})
4230 (cperl-after-block-p (point-min)))
4231 (and (eq (char-syntax (preceding-char)) ?w)
4234 ;; After these keywords `/' starts a RE. One should add all the
4235 ;; functions/builtins which expect an argument, but ...
4236 (if (eq (preceding-char) ?-)
4238 (looking-at "[a-zA-Z]\\>")
4240 (not (memq (preceding-char)
4243 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
4244 (and (eq (preceding-char) ?.)
4245 (eq (char-after (- (point) 2)) ?.))
4247 ;; m|blah| ? foo : bar;
4250 cperl-use-syntax-table-text-property
4254 (looking-at "\\s|"))))))
4257 ;; Check for $a -> y
4258 (setq b1 (preceding-char)
4261 (eq (char-after (- go 2)) ?-))
4267 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4268 (goto-char (match-end 0))
4269 (skip-chars-forward " \t\n\f"))
4270 (cond ((and (eq (following-char) ?\})
4272 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
4274 (skip-chars-backward " \t\n\f")
4275 (if (memq (preceding-char) (append "$@%&*" nil))
4281 (looking-at ; $foo -> {s}
4282 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
4283 (and ; $foo[12] -> {s}
4284 (memq (following-char) '(?\{ ?\[))
4287 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
4290 ((and (eq (following-char) ?=)
4291 (eq (char-after (1+ (point))) ?\>))
4292 ;; Check for { foo => 1, s => 2 }
4293 ;; Apparently s=> is never a substitution...
4295 ((and (eq (following-char) ?:)
4296 (eq b1 ?\{) ; Check for $ { s::bar }
4297 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
4300 (skip-chars-backward " \t\n\f")
4301 (memq (preceding-char)
4302 (append "$@%&*" nil))))
4308 ;; Skip whitespace and comments...
4309 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4310 (goto-char (match-end 0))
4311 (skip-chars-forward " \t\n\f"))
4313 (put-text-property b (point) 'syntax-type 'prestring))
4314 ;; qtag means two-arg matcher, may be reset to
4315 ;; 2 or 3 later if some special quoting is needed.
4316 ;; e1 means matching-char matcher.
4317 (setq b (point) ; before the first delimiter
4319 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
4320 ;; We do not search to max, since we may be called from
4321 ;; some hook of fontification, and max is random
4322 i (cperl-forward-re stop-point end
4324 st-l err-l argument)
4325 ;; If `go', then it is considered as 1-arg, `b1' is nil
4326 ;; as in s/foo//x; the point is before final "slash"
4327 b1 (nth 1 i) ; start of the second part
4328 tag (nth 2 i) ; ender-char, true if second part
4329 ; is with matching chars []
4330 go (nth 4 i) ; There is a 1-char part after the end
4331 i (car i) ; intermediate point
4333 ;; Before end of the second part if non-matching: ///
4334 tail (if (and i (not tag))
4336 e (if i i e1) ; end of the first part
4337 qtag nil ; need to preserve backslashitis
4338 is-x-REx nil is-o-REx nil); REx has //x //o modifiers
4339 ;; If s{} (), then b/b1 are at "{", "(", e1/i after ")", "}"
4340 ;; Commenting \\ is dangerous, what about ( ?
4342 (eq (char-after i) ?\\)
4344 (and (if go (looking-at ".\\sw*x")
4345 (looking-at "\\sw*x")) ; qr//x
4347 (and (if go (looking-at ".\\sw*o")
4348 (looking-at "\\sw*o")) ; //o
4351 ;; Considered as 1arg form
4353 (cperl-commentify b (point) t)
4354 (put-text-property b (point) 'syntax-type 'string)
4356 ;; ignore other text properties:
4357 (string-match "^qw$" argument))
4358 (put-text-property b (point) 'indentable t))
4360 (setq e1 (cperl-1+ e1))
4363 (cperl-commentify b i t)
4364 (if (looking-at "\\sw*e") ; s///e
4366 ;; Cache the syntax info...
4367 (setq cperl-syntax-state (cons state-point state))
4370 (car (cperl-find-pods-heres b1 (1- (point)) t end))
4372 (goto-char (1+ max)))
4373 (if (and tag (eq (preceding-char) ?\>))
4375 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
4376 (cperl-modify-syntax-type i cperl-st-bra)))
4377 (put-text-property b i 'syntax-type 'string)
4378 (put-text-property i (point) 'syntax-type 'multiline)
4380 (put-text-property b i 'indentable t)))
4381 (cperl-commentify b1 (point) t)
4382 (put-text-property b (point) 'syntax-type 'string)
4384 (put-text-property b i 'indentable t))
4386 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
4388 ;; Now: tail: if the second part is non-matching without ///e
4389 (if (eq (char-syntax (following-char)) ?w)
4391 (forward-word 1) ; skip modifiers s///s
4392 (if tail (cperl-commentify tail (point) t))
4393 (cperl-postpone-fontification
4394 e1 (point) 'face my-cperl-REx-modifiers-face)))
4395 ;; Check whether it is m// which means "previous match"
4396 ;; and highlight differently
4398 (and (string-match "^\\([sm]?\\|qr\\)$" argument)
4399 (or (not (= (length argument) 0))
4403 ;; split // *is* using zero-pattern
4409 (not (looking-at "split\\>")))
4411 (cperl-postpone-fontification
4412 b e 'face font-lock-warning-face)
4413 (if (or i2 ; Has 2 args
4414 (and cperl-fontify-m-as-s
4416 (string-match "^\\(m\\|qr\\)$" argument)
4417 (and (eq 0 (length argument))
4418 (not (eq ?\< (char-after b)))))))
4420 (cperl-postpone-fontification
4421 b (cperl-1+ b) 'face my-cperl-delimiters-face)
4422 (cperl-postpone-fontification
4423 (1- e) e 'face my-cperl-delimiters-face)))
4424 (if (and is-REx cperl-regexp-scan)
4425 ;; Process RExen: embedded comments, charclasses and ]
4426 ;;;/\3333\xFg\x{FFF}a\ppp\PPP\qqq\C\99f(?{ foo })(??{ foo })/;
4427 ;;;/a\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
4428 ;;;/(?<=foo)(?<!bar)(x)(?:$ab|\$\/)$|\\\b\x888\776\[\:$/xxx;
4429 ;;;m?(\?\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
4430 ;;;m$(^ab[c]\$)$ + m+(^ab[c]\$\+)+ + m](^ab[c\]$|.+)] + m)(^ab[c]$|.+\));
4431 ;;;m^a[\^b]c^ + m.a[^b]\.c.;
4435 (cperl-look-at-leading-count is-x-REx e)
4439 (if (eq (char-after b) ?\#)
4440 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
4441 "\\((\\?#\\)\\|\\(#\\)")
4442 ;; keep the same count: add a fake group
4443 (if (eq (char-after b) ?\#)
4444 "\\((\\?\\\\#\\)\\(\\)"
4445 "\\((\\?#\\)\\(\\)"))
4451 ;; XXXX Will not be able to use it in s)))
4452 (if (eq (char-after b) ?\) )
4453 "\\())))\\)" ; Will never match
4454 (if (eq (char-after b) ?? )
4455 ;;"\\((\\\\\\?\\(\\\\\\?\\)?{\\)"
4456 "\\((\\\\\\?\\\\\\?{\\|()\\\\\\?{\\)"
4457 "\\((\\?\\??{\\)")) ; 5= (??{ (?{
4458 "\\|" ; 6= 0-length, 7: name, 8,9:code, 10:group
4459 "\\(" ;; XXXX 1-char variables, exc. |()\s
4462 "[_a-zA-Z:][_a-zA-Z0-9:]*"
4464 "{[^{}]*}" ; only one-level allowed
4468 "\\(" ;;8,9:code part of array/hash elt
4474 ;; XXXX: what if u is delim?
4482 "\\\\[luLUEQbBAzZG]"
4485 "\\(" ; 10 group opener follower
4486 "\\?\\((\\?\\)" ; 11: in (?(?=C)A|B)
4488 "\\?[:=!>?{]" ; "?" something
4490 "\\?[-imsx]+[:)]" ; (?i) (?-s:.)
4492 "\\?([0-9]+)" ; (?(1)foo|bar)
4500 "\\\\\\(.\\)" ; 12=\SYMBOL
4503 (and (< (point) (1- e))
4504 (re-search-forward hairy-RE (1- e) 'to-end))
4505 (goto-char (match-beginning 0))
4506 (setq REx-subgr-start (point)
4507 was-subgr (following-char))
4509 ((match-beginning 6) ; 0-length builtins, groups
4510 (goto-char (match-end 0))
4511 (if (match-beginning 11)
4512 (goto-char (match-beginning 11)))
4515 (cperl-postpone-fontification
4516 (match-beginning 0) (point)
4519 ((eq was-subgr ?\) )
4524 (if (if (eq (char-after b) ?? )
4525 (looking-at "(\\\\\\?")
4526 (eq (char-after (1+ (point))) ?\?))
4527 my-cperl-REx-0length-face
4528 my-cperl-REx-ctl-face)
4529 font-lock-warning-face))
4530 (error font-lock-warning-face)))
4531 ((eq was-subgr ?\| )
4532 my-cperl-REx-ctl-face)
4533 ((eq was-subgr ?\$ )
4534 (if (> (point) (1+ REx-subgr-start))
4537 (match-beginning 0) (point)
4540 (if (and (eq (match-beginning 0)
4544 font-lock-variable-name-face)
4545 my-cperl-REx-spec-char-face))
4546 ((memq was-subgr (append "^." nil) )
4547 my-cperl-REx-spec-char-face)
4548 ((eq was-subgr ?\( )
4549 (if (not (match-beginning 10))
4550 my-cperl-REx-ctl-face
4551 my-cperl-REx-0length-face))
4552 (t my-cperl-REx-0length-face)))
4553 (if (and (memq was-subgr (append "(|" nil))
4554 (not (string-match "(\\?[-imsx]+)"
4556 (cperl-look-at-leading-count is-x-REx e))
4557 (setq was-subgr nil)) ; We do stuff here
4558 ((match-beginning 12) ; \SYMBOL
4562 ;; How many chars to not highlight:
4563 ;; 0-len special-alnums in other branch =>
4564 ;; Generic: \non-alnum (1), \alnum (1+face)
4565 ;; Is-delim: \non-alnum (1/spec-2) alnum-1 (=what hai)
4566 (setq REx-subgr-start (point)
4567 qtag (preceding-char))
4568 (cperl-postpone-fontification
4569 (- (point) 2) (- (point) 1) 'face
4571 (append "ghijkmoqvFHIJKMORTVY" nil))
4572 font-lock-warning-face
4573 my-cperl-REx-0length-face))
4574 (if (and (eq (char-after b) qtag)
4575 (memq qtag (append ".])^$|*?+" nil)))
4577 (if (and cperl-use-syntax-table-text-property
4580 REx-subgr-start (1- (point))
4581 'syntax-table cperl-st-punct))
4582 (cperl-postpone-fontification
4583 (1- (point)) (point) 'face
4584 ; \] can't appear below
4585 (if (memq qtag (append ".]^$" nil))
4586 'my-cperl-REx-spec-char-face
4587 (if (memq qtag (append "*?+" nil))
4588 'my-cperl-REx-0length-face
4589 'my-cperl-REx-ctl-face))))) ; )|
4590 ;; Test for arguments:
4592 ;; This is not pretty: the 5.8.7 logic:
4593 ;; \0numx -> octal (up to total 3 dig)
4594 ;; \DIGIT -> backref unless \0
4595 ;; \DIGITs -> backref if legal
4596 ;; otherwise up to 3 -> octal
4597 ;; Do not try to distinguish, we guess
4598 ((or (and (memq qtag (append "01234567" nil))
4600 "\\=[01234567]?[01234567]?"
4602 (and (memq qtag (append "89" nil))
4604 "\\=[0123456789]*" (1- e) 'to-end))
4607 "\\=[0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}"
4609 (and (memq qtag (append "pPN" nil))
4610 (re-search-forward "\\={[^{}]+}\\|."
4612 (eq (char-syntax qtag) ?w))
4613 (cperl-postpone-fontification
4614 (1- REx-subgr-start) (point)
4615 'face my-cperl-REx-length1-face))))
4616 (setq was-subgr nil)) ; We do stuff here
4617 ((match-beginning 3) ; [charclass]
4619 (if (eq (char-after b) ?^ )
4620 (and (eq (following-char) ?\\ )
4621 (eq (char-after (cperl-1+ (point)))
4624 (and (eq (following-char) ?^ )
4626 (setq argument b ; continue?
4627 tag nil ; list of POSIX classes
4629 (if (eq (char-after b) ?\] )
4630 (and (eq (following-char) ?\\ )
4631 (eq (char-after (cperl-1+ (point)))
4633 (setq qtag (1+ qtag))
4635 (and (eq (following-char) ?\] )
4637 ;; Apparently, I can't put \] into a charclass
4638 ;; in m]]: m][\\\]\]] produces [\\]]
4639 ;;; POSIX? [:word:] [:^word:] only inside []
4640 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]")
4644 (if (eq (char-after b) ?\] )
4645 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]"
4646 "\\=\\(\\\\.\\|[^]\\\\]\\)*]")
4648 ;; Is this ] an end of POSIX class?
4651 (search-backward "[" argument t)
4652 (< REx-subgr-start (point))
4654 (and ; Should work with delim = \
4655 (eq (preceding-char) ?\\ )
4656 (= (% (skip-chars-backward
4660 ((eq (char-after b) ?\] )
4661 "\\\\*\\[:\\^?\\sw+:\\\\\\]")
4662 ((eq (char-after b) ?\: )
4663 "\\\\*\\[\\\\:\\^?\\sw+\\\\:]")
4664 ((eq (char-after b) ?^ )
4665 "\\\\*\\[:\\(\\\\\\^\\)?\\sw+:\]")
4666 ((eq (char-syntax (char-after b))
4669 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\"
4670 (char-to-string (char-after b))
4672 (t "\\\\*\\[:\\^?\\sw*:]")))
4673 (setq argument (point))))
4674 (setq tag (cons (cons argument (point))
4676 argument (point)) ; continue
4677 (setq argument nil)))
4679 (message "Couldn't find end of charclass in a REx, pos=%s"
4681 (if (and cperl-use-syntax-table-text-property
4682 (> (- (point) 2) REx-subgr-start))
4684 (1+ REx-subgr-start) (1- (point))
4685 'syntax-table cperl-st-punct))
4686 (cperl-postpone-fontification
4687 REx-subgr-start qtag
4688 'face my-cperl-REx-spec-char-face)
4689 (cperl-postpone-fontification
4690 (1- (point)) (point) 'face
4691 my-cperl-REx-spec-char-face)
4692 (if (eq (char-after b) ?\] )
4693 (cperl-postpone-fontification
4694 (- (point) 2) (1- (point))
4695 'face my-cperl-REx-0length-face))
4697 (cperl-postpone-fontification
4698 (car (car tag)) (cdr (car tag))
4699 'face my-cperl-REx-length1-face)
4700 (setq tag (cdr tag)))
4701 (setq was-subgr nil)) ; did facing already
4703 ((and (match-beginning 2) ; #-comment
4704 (/= (match-beginning 2) (match-end 2)))
4705 (beginning-of-line 2)
4707 (goto-char (1- e))))
4708 ((match-beginning 4) ; character "]"
4709 (setq was-subgr nil) ; We do stuff here
4710 (goto-char (match-end 0))
4711 (if cperl-use-syntax-table-text-property
4713 (1- (point)) (point)
4714 'syntax-table cperl-st-punct))
4715 (cperl-postpone-fontification
4716 (1- (point)) (point)
4717 'face font-lock-warning-face))
4718 ((match-beginning 5) ; before (?{}) (??{})
4719 (setq tag (match-end 0))
4721 (cperl-forward-group-in-re st-l))
4723 (setq qtag "no matching `)' found"))
4724 (and (not (eq (char-after (- (point) 2))
4726 (setq qtag "Can't find })")))
4730 (cperl-postpone-fontification
4731 (1- tag) (1- (point))
4732 'face font-lock-variable-name-face)
4733 (cperl-postpone-fontification
4734 REx-subgr-start (1- tag)
4735 'face my-cperl-REx-spec-char-face)
4736 (cperl-postpone-fontification
4737 (1- (point)) (point)
4738 'face my-cperl-REx-spec-char-face)
4739 (if cperl-use-syntax-table-text-property
4742 (- (point) 2) (1- (point))
4743 'syntax-table cperl-st-cfence)
4745 (+ REx-subgr-start 2)
4746 (+ REx-subgr-start 3)
4747 'syntax-table cperl-st-cfence))))
4748 (setq was-subgr nil))
4750 ;; Inside "(" and "\" arn't special in any way
4751 ;; Works also if the outside delimiters are ().
4752 (or;;(if (eq (char-after b) ?\) )
4753 ;;(re-search-forward
4754 ;; "[^\\\\]\\(\\\\\\\\\\)*\\\\)"
4756 (search-forward ")" (1- e) 'toend)
4759 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
4765 (setq REx-subgr-end (point))
4767 REx-subgr-start REx-subgr-end nil)
4768 (cperl-postpone-fontification
4769 REx-subgr-start REx-subgr-end
4770 'face font-lock-comment-face))))))
4771 (if (and is-REx is-x-REx)
4772 (put-text-property (1+ b) (1- e)
4773 'syntax-subtype 'x-REx)))
4776 (cperl-postpone-fontification
4777 (1- e1) e1 'face my-cperl-delimiters-face)
4778 (if (assoc (char-after b) cperl-starters)
4780 (cperl-postpone-fontification
4781 b1 (1+ b1) 'face my-cperl-delimiters-face)
4782 (put-text-property b1 (1+ b1)
4786 ((match-beginning 17) ; sub with prototype or attribute
4787 ;; 1+6+2+1+1=11 extra () before this (sub with proto/attr):
4788 ;;"\\<sub\\>\\(" ;12
4789 ;; cperl-white-and-comment-rex ;13
4790 ;; "\\([a-zA-Z_:'0-9]+\\)\\)?" ; name ;14
4791 ;;"\\(" cperl-maybe-white-and-comment-rex ;15,16
4792 ;; "\\(([^()]*)\\|:[^:]\\)\\)" ; 17:proto or attribute start
4793 (setq b1 (match-beginning 14) e1 (match-end 14))
4794 (if (memq (char-after (1- b))
4795 '(?\$ ?\@ ?\% ?\& ?\*))
4798 (if (eq (char-after (match-beginning 17)) ?\( )
4800 (cperl-commentify ; Prototypes; mark as string
4801 (match-beginning 17) (match-end 17) t)
4802 (goto-char (match-end 0))
4803 ;; Now look for attributes after prototype:
4804 (forward-comment (buffer-size))
4805 (and (looking-at ":[^:]")
4806 (cperl-find-sub-attrs st-l b1 e1 b)))
4807 ;; treat attributes without prototype
4808 (goto-char (match-beginning 17))
4809 (cperl-find-sub-attrs st-l b1 e1 b))))
4810 ;; 1+6+2+1+1+6+1=18 extra () before this:
4811 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
4812 ((match-beginning 19) ; old $abc'efg syntax
4813 (setq bb (match-end 0))
4814 ;;;(if (nth 3 state) nil ; in string
4815 (put-text-property (1- bb) bb 'syntax-table cperl-st-word)
4817 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
4818 ;; "__\\(END\\|DATA\\)__"
4819 ((match-beginning 20) ; __END__, __DATA__
4820 (setq bb (match-end 0))
4821 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
4822 (cperl-commentify b bb nil)
4824 ;; "\\\\\\(['`\"($]\\)"
4825 ((match-beginning 21)
4826 ;; Trailing backslash; make non-quoting outside string/comment
4827 (setq bb (match-end 0))
4829 (skip-chars-backward "\\\\")
4830 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
4831 (cperl-modify-syntax-type b cperl-st-punct)
4833 (t (error "Error in regexp of the sniffer")))
4834 (if (> (point) stop-point)
4837 (message "Garbage after __END__/__DATA__ ignored")
4838 (message "Unbalanced syntax found while scanning")
4839 (or (car err-l) (setcar err-l b)))
4840 (goto-char stop-point))))
4841 (setq cperl-syntax-state (cons state-point state)
4842 ;; Do not mark syntax as done past tmpend???
4843 cperl-syntax-done-to (or tmpend (max (point) max)))
4844 ;;(message "state-at=%s, done-to=%s" state-point cperl-syntax-done-to)
4846 (if (car err-l) (goto-char (car err-l))
4848 (message "Scanning for \"hard\" Perl constructions... done"))))
4849 (and (buffer-modified-p)
4851 (set-buffer-modified-p nil))
4852 ;; I do not understand what this is doing here. It breaks font-locking
4853 ;; because it resets the syntax-table from font-lock-syntax-table to
4854 ;; cperl-mode-syntax-table.
4855 ;; (set-syntax-table cperl-mode-syntax-table)
4857 (list (car err-l) overshoot)))
4859 (defun cperl-find-pods-heres-region (min max)
4861 (cperl-find-pods-heres min max))
4863 (defun cperl-backward-to-noncomment (lim)
4864 ;; Stops at lim or after non-whitespace that is not in comment
4865 ;; XXXX Wrongly understands end-of-multiline strings with # as comment
4867 (while (and (not stop) (> (point) (or lim (point-min))))
4868 (skip-chars-backward " \t\n\f" lim)
4871 (if (memq (setq pr (get-text-property (point) 'syntax-type))
4872 '(pod here-doc here-doc-delim))
4873 (cperl-unwind-to-safe nil)
4874 (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
4875 (not (memq pr '(string prestring))))
4876 (progn (cperl-to-comment-or-eol) (bolp))
4878 (skip-chars-backward " \t")
4879 (if (< p (point)) (goto-char p))
4882 ;; Used only in `cperl-calculate-indent'...
4883 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
4884 ;; Positions is before ?\{. Checks whether it starts a block.
4885 ;; No save-excursion! This is more a distinguisher of a block/hash ref...
4886 (cperl-backward-to-noncomment (point-min))
4887 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
4888 ; Label may be mixed up with `$blah :'
4889 (save-excursion (cperl-after-label))
4890 (get-text-property (cperl-1- (point)) 'attrib-group)
4891 (and (memq (char-syntax (preceding-char)) '(?w ?_))
4894 ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
4895 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
4896 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
4897 ;; sub bless::foo {}
4899 (cperl-backward-to-noncomment (point-min))
4900 (and (eq (preceding-char) ?b)
4903 (looking-at "sub[ \t\n\f#]")))))))))
4905 ;;; What is the difference of (cperl-after-block-p lim t) and (cperl-block-p)?
4906 ;;; No save-excursion; condition-case ... In (cperl-block-p) the block
4907 ;;; may be a part of an in-statement construct, such as
4908 ;;; ${something()}, print {FH} $data.
4909 ;;; Moreover, one takes positive approach (looks for else,grep etc)
4910 ;;; another negative (looks for bless,tr etc)
4911 (defun cperl-after-block-p (lim &optional pre-block)
4912 "Return true if the preceeding } (if PRE-BLOCK, following {) delimits a block.
4913 Would not look before LIM. Assumes that LIM is a good place to begin a
4914 statement. The kind of block we treat here is one after which a new
4915 statement would start; thus the block in ${func()} does not count."
4919 (or pre-block (forward-sexp -1))
4920 (cperl-backward-to-noncomment lim)
4921 (or (eq (point) lim)
4922 ;; if () {} // sub f () {} // sub f :a(') {}
4923 (eq (preceding-char) ?\) )
4925 (save-excursion (cperl-after-label))
4927 (get-text-property (cperl-1- (point)) 'attrib-group)
4928 (if (memq (char-syntax (preceding-char)) '(?w ?_)) ; else {}
4931 ;; else {} but not else::func {}
4932 (or (and (looking-at "\\(else\\|continue\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
4933 (not (looking-at "\\(\\sw\\|_\\)+::")))
4936 (cperl-backward-to-noncomment lim)
4937 (and (eq (preceding-char) ?b)
4940 (looking-at "sub[ \t\n\f#]"))))))
4941 ;; What preceeds is not word... XXXX Last statement in sub???
4942 (cperl-after-expr-p lim))))
4945 (defun cperl-after-expr-p (&optional lim chars test)
4946 "Return true if the position is good for start of expression.
4947 TEST is the expression to evaluate at the found position. If absent,
4948 CHARS is a string that contains good characters to have before us (however,
4949 `}' is treated \"smartly\" if it is not in the list)."
4950 (let ((lim (or lim (point-min)))
4952 (cperl-update-syntaxification (point) (point))
4954 (while (and (not stop) (> (point) lim))
4955 (skip-chars-backward " \t\n\f" lim)
4958 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
4959 ;; '(pod here-doc here-doc-delim))
4960 (if (get-text-property (point) 'here-doc-group)
4963 (cperl-beginning-of-property (point) 'here-doc-group))
4964 (beginning-of-line 0)))
4965 (if (get-text-property (point) 'in-pod)
4968 (cperl-beginning-of-property (point) 'in-pod))
4969 (beginning-of-line 0)))
4970 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
4971 ;; Else: last iteration, or a label
4972 (cperl-to-comment-or-eol) ; Will not move past "." after a format
4973 (skip-chars-backward " \t")
4974 (if (< p (point)) (goto-char p))
4976 (if (and (eq (preceding-char) ?:)
4979 (skip-chars-backward " \t\n\f" lim)
4980 (memq (char-syntax (preceding-char)) '(?w ?_))))
4981 (forward-sexp -1) ; Possibly label. Skip it
4984 (or (bobp) ; ???? Needed
4986 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
4988 (if test (eval test)
4989 (or (memq (preceding-char) (append (or chars "{;") nil))
4990 (and (eq (preceding-char) ?\})
4991 (cperl-after-block-p lim))
4992 (and (eq (following-char) ?.) ; in format: see comment above
4993 (eq (get-text-property (point) 'syntax-type)
4996 (defun cperl-backward-to-start-of-expr (&optional lim)
4999 (while (and (or (not lim)
5001 (not (cperl-after-expr-p lim)))
5003 ;; May be after $, @, $# etc of a variable
5004 (skip-chars-backward "$@%#")))
5007 (defun cperl-at-end-of-expr (&optional lim)
5008 ;; Since the SEXP approach below is very fragile, do some overengineering
5009 (or (looking-at (concat cperl-maybe-white-and-comment-rex "[;}]"))
5012 ;; If nothing interesting after, does as (forward-sexp -1);
5013 ;; otherwise fails, or ends at a start of following sexp.
5014 ;; XXXX PROBLEMS: if what follows (after ";") @FOO, or ${bar}
5015 ;; may be stuck after @ or $; just put some stupid workaround now:
5019 (while (memq (preceding-char) (append "%&@$*" nil))
5022 (cperl-after-expr-p lim))))
5025 (defun cperl-forward-to-end-of-expr (&optional lim)
5029 (while (and (< (point) (or lim (point-max)))
5030 (not (cperl-at-end-of-expr)))
5034 (defun cperl-backward-to-start-of-continued-exp (lim)
5035 (if (memq (preceding-char) (append ")]}\"'`" nil))
5038 (if (<= (point) lim)
5039 (goto-char (1+ lim)))
5040 (skip-chars-forward " \t"))
5042 (defun cperl-after-block-and-statement-beg (lim)
5043 ;; We assume that we are after ?\}
5045 (cperl-after-block-p lim)
5048 (cperl-backward-to-noncomment (point-min))
5051 (not (= (char-syntax (preceding-char)) ?w))
5056 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
5059 (defun cperl-indent-exp ()
5060 "Simple variant of indentation of continued-sexp.
5062 Will not indent comment if it starts at `comment-indent' or looks like
5063 continuation of the comment on the previous line.
5065 If `cperl-indent-region-fix-constructs', will improve spacing on
5066 conditional/loop constructs."
5069 (let ((tmp-end (progn (end-of-line) (point))) top done)
5074 ;; Plan A: if line has an unfinished paren-group, go to end-of-group
5075 (while (= -1 (nth 0 (parse-partial-sexp (point) tmp-end -1)))
5076 (setq top (point))) ; Get the outermost parenths in line
5078 (while (< (point) tmp-end)
5079 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
5080 (or (eolp) (forward-sexp 1)))
5081 (if (> (point) tmp-end) ; Yes, there an unfinished block
5083 (if (eq ?\) (preceding-char))
5084 (progn ;; Plan B: find by REGEXP block followup this line
5089 (if (eq (following-char) ?$ ) ; for my $var (list)
5092 (if (looking-at "\\(my\\|local\\|our\\)\\>")
5093 (forward-sexp -1))))
5095 (concat "\\(\\elsif\\|if\\|unless\\|while\\|until"
5096 "\\|for\\(each\\)?\\>\\(\\("
5097 cperl-maybe-white-and-comment-rex
5098 "\\(my\\|local\\|our\\)\\)?"
5099 cperl-maybe-white-and-comment-rex
5100 "\\$[_a-zA-Z0-9]+\\)?\\)\\>"))
5104 (setq top (point)))))
5105 (error (setq done t)))
5107 (if (looking-at ; Try Plan C: continuation block
5108 (concat cperl-maybe-white-and-comment-rex
5109 "\\<\\(else\\|elsif\|continue\\)\\>"))
5111 (goto-char (match-end 0))
5114 (setq tmp-end (point))))
5118 (setq tmp-end (point))))
5120 (setq tmp-end (point-marker)))
5121 (if cperl-indent-region-fix-constructs
5122 (cperl-fix-line-spacing tmp-end))
5123 (cperl-indent-region (point) tmp-end))))
5125 (defun cperl-fix-line-spacing (&optional end parse-data)
5126 "Improve whitespace in a conditional/loop construct.
5127 Returns some position at the last line."
5130 (setq end (point-max)))
5131 (let ((ee (save-excursion (end-of-line) (point)))
5132 (cperl-indent-region-fix-constructs
5133 (or cperl-indent-region-fix-constructs 1))
5134 p pp ml have-brace ret)
5141 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
5142 (setq have-brace (save-excursion (search-forward "}" ee t)))))
5143 nil ; Do not need to do anything
5147 (if cperl-merge-trailing-else
5149 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5151 (search-forward "}")
5153 (skip-chars-forward " \t\n")
5154 (delete-region p (point))
5155 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5156 (beginning-of-line)))
5157 (if (looking-at "[ \t]*}[ \t]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5159 (search-forward "}")
5160 (delete-horizontal-space)
5163 (if (cperl-indent-line parse-data)
5165 (cperl-fix-line-spacing end parse-data)
5166 (setq ret (point)))))))
5169 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
5171 (search-forward "}")
5172 (delete-horizontal-space)
5173 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5174 (beginning-of-line)))
5178 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5181 (delete-horizontal-space)
5182 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5183 (beginning-of-line)))
5187 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
5190 (delete-horizontal-space)
5191 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5192 (beginning-of-line)))
5194 ;; foreach my $var (
5196 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5199 (delete-horizontal-space)
5201 (make-string cperl-indent-region-fix-constructs ?\s))
5202 (beginning-of-line)))
5203 ;; Looking at (with or without "}" at start, ending after "({"):
5204 ;; } foreach my $var () OR {
5206 "[ \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]*{")
5208 (setq ml (match-beginning 8)) ; "(" or "{" after control word
5209 (re-search-forward "[({]")
5212 (if (eq (following-char) ?\( )
5215 (setq pp (point))) ; past parenth-group
5216 ;; after `else' or nothing
5217 (if ml ; after `else'
5218 (skip-chars-backward " \t\n")
5219 (beginning-of-line))
5221 ;; Now after the sexp before the brace
5222 ;; Multiline expr should be special
5223 (setq ml (and pp (save-excursion (goto-char p)
5224 (search-forward "\n" pp t))))
5225 (if (and (or (not pp) (< pp end)) ; Do not go too far...
5226 (looking-at "[ \t\n]*{"))
5229 ((bolp) ; Were before `{', no if/else/etc
5231 ((looking-at "\\(\t*\\| [ \t]+\\){") ; Not exactly 1 SPACE
5232 (delete-horizontal-space)
5234 cperl-extra-newline-before-brace-multiline
5235 cperl-extra-newline-before-brace)
5237 (delete-horizontal-space)
5240 (if (cperl-indent-line parse-data)
5242 (cperl-fix-line-spacing end parse-data)
5243 (setq ret (point)))))
5245 (make-string cperl-indent-region-fix-constructs ?\s))))
5246 ((and (looking-at "[ \t]*\n")
5248 cperl-extra-newline-before-brace-multiline
5249 cperl-extra-newline-before-brace)))
5251 (skip-chars-forward " \t\n")
5252 (delete-region pp (point))
5254 (make-string cperl-indent-region-fix-constructs ?\ )))
5255 ((and (looking-at "[\t ]*{")
5256 (if ml cperl-extra-newline-before-brace-multiline
5257 cperl-extra-newline-before-brace))
5258 (delete-horizontal-space)
5261 (if (cperl-indent-line parse-data)
5263 (cperl-fix-line-spacing end parse-data)
5264 (setq ret (point))))))
5265 ;; Now we are before `{'
5266 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
5268 (skip-chars-forward " \t\n")
5273 (setq ml (search-forward "\n" p t))
5274 (if (or cperl-break-one-line-blocks-when-indent ml)
5275 ;; not good: multi-line BLOCK
5278 (delete-horizontal-space)
5281 (if (cperl-indent-line parse-data)
5282 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
5284 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
5285 ;; Now check whether there is a hanging `}'
5289 cperl-fix-hanging-brace-when-indent
5291 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
5295 (if (and (<= (point) pp)
5296 (eq (preceding-char) ?\} )
5297 (cperl-after-block-and-statement-beg (point-min)))
5304 (skip-chars-backward " \t")
5306 ;; `}' was the first thing on the line, insert NL *after* it.
5308 (cperl-indent-line parse-data)
5309 (search-forward "}")
5310 (delete-horizontal-space)
5312 (delete-horizontal-space)
5313 (or (eq (preceding-char) ?\;)
5315 (and (eq (preceding-char) ?\} )
5316 (cperl-after-block-p (point-min)))
5320 (if (cperl-indent-line parse-data)
5321 (setq ret (cperl-fix-line-spacing end parse-data)))
5322 (beginning-of-line)))))
5325 (defvar cperl-update-start) ; Do not need to make them local
5326 (defvar cperl-update-end)
5327 (defun cperl-delay-update-hook (beg end old-len)
5328 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
5329 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
5331 (defun cperl-indent-region (start end)
5332 "Simple variant of indentation of region in CPerl mode.
5333 Should be slow. Will not indent comment if it starts at `comment-indent'
5334 or looks like continuation of the comment on the previous line.
5335 Indents all the lines whose first character is between START and END
5338 If `cperl-indent-region-fix-constructs', will improve spacing on
5339 conditional/loop constructs."
5341 (cperl-update-syntaxification end end)
5343 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
5344 (let ((indent-info (if cperl-emacs-can-parse
5345 (list nil nil nil) ; Cannot use '(), since will modify
5348 after-change-functions ; Speed it up!
5349 st comm old-comm-indent new-comm-indent p pp i empty)
5350 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
5352 (setq old-comm-indent (and (cperl-to-comment-or-eol)
5354 new-comm-indent old-comm-indent)
5356 (setq end (set-marker (make-marker) end)) ; indentation changes pos
5357 (or (bolp) (beginning-of-line 2))
5358 (while (and (<= (point) end) (not (eobp))) ; bol to check start
5361 (setq empty (looking-at "[ \t]*\n"))
5362 (and (setq comm (looking-at "[ \t]*#"))
5363 (or (eq (current-indentation) (or old-comm-indent
5365 (setq old-comm-indent nil))))
5366 (if (and old-comm-indent
5368 (= (current-indentation) old-comm-indent)
5369 (not (eq (get-text-property (point) 'syntax-type) 'pod))
5370 (not (eq (get-text-property (point) 'syntax-table)
5372 (let ((comment-column new-comm-indent))
5373 (indent-for-comment)))
5375 (setq i (cperl-indent-line indent-info))
5379 (if cperl-indent-region-fix-constructs
5380 (goto-char (cperl-fix-line-spacing end indent-info)))
5381 (if (setq old-comm-indent
5382 (and (cperl-to-comment-or-eol)
5383 (not (memq (get-text-property (point)
5386 (not (eq (get-text-property (point)
5390 (progn (indent-for-comment)
5391 (skip-chars-backward " \t")
5392 (skip-chars-backward "#")
5393 (setq new-comm-indent (current-column))))))))
5394 (beginning-of-line 2)))
5395 ;; Now run the update hooks
5396 (and after-change-functions
5399 (goto-char cperl-update-end)
5402 (goto-char cperl-update-start)
5404 (delete-char -1))))))
5406 ;; Stolen from lisp-mode with a lot of improvements
5408 (defun cperl-fill-paragraph (&optional justify iteration)
5409 "Like `fill-paragraph', but handle CPerl comments.
5410 If any of the current line is a comment, fill the comment or the
5411 block of it that point is in, preserving the comment's initial
5412 indentation and initial hashes. Behaves usually outside of comment."
5413 ;; (interactive "P") ; Only works when called from fill-paragraph. -stef
5414 (let (;; Non-nil if the current line contains a comment.
5416 fill-paragraph-function ; do not recurse
5417 ;; If has-comment, the appropriate fill-prefix for the comment.
5419 ;; Line that contains code and comment (or nil)
5421 c spaces len dc (comment-column comment-column))
5422 ;; Figure out what kind of comment we are looking at.
5427 ;; A line with nothing but a comment on it?
5428 ((looking-at "[ \t]*#[# \t]*")
5430 comment-fill-prefix (buffer-substring (match-beginning 0)
5433 ;; A line with some code, followed by a comment? Remember that the
5434 ;; semi which starts the comment shouldn't be part of a string or
5436 ((cperl-to-comment-or-eol)
5437 (setq has-comment t)
5438 (looking-at "#+[ \t]*")
5439 (setq start (point) c (current-column)
5441 (concat (make-string (current-column) ?\s)
5442 (buffer-substring (match-beginning 0) (match-end 0)))
5443 spaces (progn (skip-chars-backward " \t")
5444 (buffer-substring (point) start))
5445 dc (- c (current-column)) len (- start (point))
5446 start (point-marker))
5448 (insert (make-string dc ?-))))) ; Placeholder (to avoid splitting???)
5449 (if (not has-comment)
5450 (fill-paragraph justify) ; Do the usual thing outside of comment
5451 ;; Narrow to include only the comment, and then fill the region.
5454 ;; Find the first line we should include in the region to fill.
5455 (if start (progn (beginning-of-line) (point))
5457 (while (and (zerop (forward-line -1))
5458 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5459 ;; We may have gone to far. Go forward again.
5460 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
5463 ;; Find the beginning of the first line past the region to fill.
5465 (while (progn (forward-line 1)
5466 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5468 ;; Remove existing hashes
5470 (goto-char (point-min))
5471 (while (progn (forward-line 1) (< (point) (point-max)))
5472 (skip-chars-forward " \t")
5473 (if (looking-at "#+")
5475 (if (and (eq (point) (match-beginning 0))
5476 (not (eq (point) (match-end 0)))) nil
5478 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage"))
5479 (delete-char (- (match-end 0) (match-beginning 0)))))))
5481 ;; Lines with only hashes on them can be paragraph boundaries.
5482 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
5483 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
5484 (fill-prefix comment-fill-prefix))
5485 (fill-paragraph justify)))
5490 (progn (delete-char dc) (insert spaces)))
5491 (if (or (= (current-column) c) iteration) nil
5492 (setq comment-column c)
5493 (indent-for-comment)
5494 ;; Repeat once more, flagging as iteration
5495 (cperl-fill-paragraph justify t))))))
5498 (defun cperl-do-auto-fill ()
5499 ;; Break out if the line is short enough
5500 (if (> (save-excursion
5504 (let ((c (save-excursion (beginning-of-line)
5505 (cperl-to-comment-or-eol) (point)))
5506 (s (memq (following-char) '(?\s ?\t))) marker)
5508 ;; Don't break line inside code: only inside comment.
5510 (setq marker (point-marker))
5511 (fill-paragraph nil)
5513 ;; Is not enough, sometimes marker is a start of line
5514 (if (bolp) (progn (re-search-forward "#+[ \t]*")
5515 (goto-char (match-end 0))))
5516 ;; Following space could have gone:
5517 (if (or (not s) (memq (following-char) '(?\s ?\t))) nil
5520 ;; Previous space could have gone:
5521 (or (memq (preceding-char) '(?\s ?\t)) (insert " "))))))
5523 (defun cperl-imenu-addback (lst &optional isback name)
5524 ;; We suppose that the lst is a DAG, unless the first element only
5525 ;; loops back, and ISBACK is set. Thus this function cannot be
5526 ;; applied twice without ISBACK set.
5527 (cond ((not cperl-imenu-addback) lst)
5530 (setq name "+++BACK+++"))
5531 (mapcar (lambda (elt)
5532 (if (and (listp elt) (listp (cdr elt)))
5534 ;; In the other order it goes up
5535 ;; one level only ;-(
5536 (setcdr elt (cons (cons name lst)
5538 (cperl-imenu-addback (cdr elt) t name))))
5539 (if isback (cdr lst) lst))
5542 (defun cperl-imenu--create-perl-index (&optional regexp)
5543 (require 'imenu) ; May be called from TAGS creator
5544 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
5545 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
5546 (index-meth-alist '()) meth
5547 packages ends-ranges p marker is-proto
5548 (prev-pos 0) is-pack index index1 name (end-range 0) package)
5549 (goto-char (point-min))
5550 (cperl-update-syntaxification (point-max) (point-max))
5551 ;; Search for the function
5552 (progn ;;save-match-data
5553 (while (re-search-forward
5554 (or regexp cperl-imenu--function-name-regexp-perl)
5556 ;; 2=package-group, 5=package-name 8=sub-name
5558 ((and ; Skip some noise if building tags
5559 (match-beginning 5) ; package name
5560 ;;(eq (char-after (match-beginning 2)) ?p) ; package
5561 (not (save-match-data
5562 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
5565 (or (match-beginning 2)
5566 (match-beginning 8)) ; package or sub
5567 ;; Skip if quoted (will not skip multi-line ''-strings :-():
5568 (null (get-text-property (match-beginning 1) 'syntax-table))
5569 (null (get-text-property (match-beginning 1) 'syntax-type))
5570 (null (get-text-property (match-beginning 1) 'in-pod)))
5571 (setq is-pack (match-beginning 2))
5572 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
5573 ;; (goto-char (match-end 0))) ; Messes what follows
5576 (while (and ends-ranges (>= p (car ends-ranges)))
5577 ;; delete obsolete entries
5578 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
5579 (setq package (or (car packages) "")
5580 end-range (or (car ends-ranges) 0))
5581 (if is-pack ; doing "package"
5583 (if (match-beginning 5) ; named package
5584 (setq name (buffer-substring (match-beginning 5)
5587 (set-text-properties 0 (length name) nil name)
5589 package (concat name "::")
5590 name (concat "package " name))
5591 ;; Support nameless packages
5592 (setq name "package;" package ""))
5595 (parse-partial-sexp (point) (point-max) -1) (point))
5596 ends-ranges (cons end-range ends-ranges)
5597 packages (cons package packages)))
5599 (or (eq (following-char) ?\;)
5600 (eq 0 (get-text-property (point) 'attrib-group)))))
5601 ;; Skip this function name if it is a prototype declaration.
5602 (if (and is-proto (not is-pack)) nil
5605 (buffer-substring (match-beginning 8) (match-end 8)))
5606 (set-text-properties 0 (length name) nil name))
5607 (setq marker (make-marker))
5608 (set-marker marker (match-end (if is-pack 2 8)))
5610 ((string-match "[:']" name)
5612 ((> p end-range) nil)
5614 (setq name (concat package name) meth t)))
5615 (setq index (cons name marker))
5617 (push index index-pack-alist)
5618 (push index index-alist))
5619 (if meth (push index index-meth-alist))
5620 (push index index-unsorted-alist)))
5621 ((match-beginning 16) ; POD section
5622 (setq name (buffer-substring (match-beginning 17) (match-end 17))
5623 marker (make-marker))
5624 (set-marker marker (match-beginning 17))
5625 (set-text-properties 0 (length name) nil name)
5626 (setq name (concat (make-string
5627 (* 3 (- (char-after (match-beginning 16)) ?1))
5630 index (cons name marker))
5631 (setq index1 (cons (concat "=" name) (cdr index)))
5632 (push index index-pod-alist)
5633 (push index1 index-unsorted-alist)))))
5635 (if (default-value 'imenu-sort-function)
5636 (sort index-alist (default-value 'imenu-sort-function))
5637 (nreverse index-alist)))
5638 (and index-pod-alist
5639 (push (cons "+POD headers+..."
5640 (nreverse index-pod-alist))
5642 (and (or index-pack-alist index-meth-alist)
5643 (let ((lst index-pack-alist) hier-list pack elt group name)
5644 ;; Remove "package ", reverse and uniquify.
5646 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
5647 (if (assoc name hier-list) nil
5648 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
5649 (setq lst index-meth-alist)
5651 (setq elt (car lst) lst (cdr lst))
5652 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
5653 (setq pack (substring (car elt) 0 (match-beginning 0)))
5654 (if (setq group (assoc pack hier-list))
5655 (if (listp (cdr group))
5656 ;; Have some functions already
5658 (cons (cons (substring
5660 (+ 2 (match-beginning 0)))
5663 (setcdr group (list (cons (substring
5665 (+ 2 (match-beginning 0)))
5669 (list (cons (substring
5671 (+ 2 (match-beginning 0)))
5674 (push (cons "+Hierarchy+..."
5677 (and index-pack-alist
5678 (push (cons "+Packages+..."
5679 (nreverse index-pack-alist))
5681 (and (or index-pack-alist index-pod-alist
5682 (default-value 'imenu-sort-function))
5683 index-unsorted-alist
5684 (push (cons "+Unsorted List+..."
5685 (nreverse index-unsorted-alist))
5687 (cperl-imenu-addback index-alist)))
5690 ;; Suggested by Mark A. Hershberger
5691 (defun cperl-outline-level ()
5692 (looking-at outline-regexp)
5693 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
5694 ;;;; 2=package-group, 5=package-name 8=sub-name 16=head-level
5695 ((match-beginning 2) 0) ; package
5696 ((match-beginning 8) 1) ; sub
5697 ((match-beginning 16)
5698 (- (char-after (match-beginning 16)) ?0)) ; headN ==> N
5699 (t 5))) ; should not happen
5702 (defvar cperl-compilation-error-regexp-alist
5703 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
5704 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
5706 "Alist that specifies how to match errors in perl output.")
5709 (defun cperl-windowed-init ()
5710 "Initialization under windowed version."
5711 (if (or (featurep 'ps-print) cperl-faces-init)
5712 ;; Need to init anyway:
5713 (or cperl-faces-init (cperl-init-faces))
5714 (add-hook 'font-lock-mode-hook
5717 (if (memq major-mode '(perl-mode cperl-mode))
5719 (or cperl-faces-init (cperl-init-faces)))))))
5720 (if (fboundp 'eval-after-load)
5723 '(or cperl-faces-init (cperl-init-faces))))))
5725 (defvar cperl-font-lock-keywords-1 nil
5726 "Additional expressions to highlight in Perl mode. Minimal set.")
5727 (defvar cperl-font-lock-keywords nil
5728 "Additional expressions to highlight in Perl mode. Default set.")
5729 (defvar cperl-font-lock-keywords-2 nil
5730 "Additional expressions to highlight in Perl mode. Maximal set")
5732 (defun cperl-load-font-lock-keywords ()
5733 (or cperl-faces-init (cperl-init-faces))
5734 cperl-font-lock-keywords)
5736 (defun cperl-load-font-lock-keywords-1 ()
5737 (or cperl-faces-init (cperl-init-faces))
5738 cperl-font-lock-keywords-1)
5740 (defun cperl-load-font-lock-keywords-2 ()
5741 (or cperl-faces-init (cperl-init-faces))
5742 cperl-font-lock-keywords-2)
5744 (defun cperl-init-faces-weak ()
5745 ;; Allow `cperl-find-pods-heres' to run.
5746 (or (boundp 'font-lock-constant-face)
5747 (cperl-force-face font-lock-constant-face
5748 "Face for constant and label names"))
5749 (or (boundp 'font-lock-warning-face)
5750 (cperl-force-face font-lock-warning-face
5751 "Face for things which should stand out"))
5752 ;;(setq font-lock-constant-face 'font-lock-constant-face)
5755 (defun cperl-init-faces ()
5756 (condition-case errs
5758 (require 'font-lock)
5759 (and (fboundp 'font-lock-fontify-anchored-keywords)
5760 (featurep 'font-lock-extra)
5761 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
5762 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
5763 (if (fboundp 'font-lock-fontify-anchored-keywords)
5764 (setq font-lock-anchored t))
5766 t-font-lock-keywords
5768 `("[ \t]+$" 0 ',cperl-invalid-face t)
5771 "\\(^\\|[^$@%&\\]\\)\\<\\("
5774 '("if" "until" "while" "elsif" "else" "unless" "for"
5775 "foreach" "continue" "exit" "die" "last" "goto" "next"
5776 "redo" "return" "local" "exec" "sub" "do" "dump" "use" "our"
5777 "require" "package" "eval" "my" "BEGIN" "END" "CHECK" "INIT")
5778 "\\|") ; Flow control
5779 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
5780 ; In what follows we use `type' style
5781 ; for overwritable builtins
5784 "\\(^\\|[^$@%&\\]\\)\\<\\("
5785 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
5786 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
5787 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
5788 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
5789 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
5790 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
5791 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
5792 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
5793 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
5794 ;; "gethostbyname" "gethostent" "getlogin"
5795 ;; "getnetbyaddr" "getnetbyname" "getnetent"
5796 ;; "getpeername" "getpgrp" "getppid" "getpriority"
5797 ;; "getprotobyname" "getprotobynumber" "getprotoent"
5798 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
5799 ;; "getservbyport" "getservent" "getsockname"
5800 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
5801 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
5802 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
5803 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
5804 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
5805 ;; "quotemeta" "rand" "read" "readdir" "readline"
5806 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
5807 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
5808 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
5809 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
5810 ;; "setpriority" "setprotoent" "setpwent" "setservent"
5811 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
5812 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
5813 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
5814 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
5815 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
5816 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
5817 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
5818 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
5819 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
5820 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
5821 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
5822 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
5823 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
5824 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
5825 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
5826 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
5827 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
5828 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
5829 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
5830 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
5831 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
5832 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
5833 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
5834 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
5835 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
5836 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
5837 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
5838 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
5839 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
5840 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
5841 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
5842 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
5843 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
5844 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
5845 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
5846 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
5847 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
5848 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
5849 "\\)\\>") 2 'font-lock-type-face)
5850 ;; In what follows we use `other' style
5851 ;; for nonoverwritable builtins
5852 ;; Somehow 's', 'm' are not auto-generated???
5855 "\\(^\\|[^$@%&\\]\\)\\<\\("
5856 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "chomp"
5857 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
5858 ;; "eval" "exists" "for" "foreach" "format" "goto"
5859 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
5860 ;; "no" "our" "package" "pop" "pos" "print" "printf" "push"
5861 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
5862 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
5863 ;; "undef" "unless" "unshift" "untie" "until" "use"
5865 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
5866 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
5867 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|INIT\\|if\\|keys\\|"
5868 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
5869 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
5870 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
5871 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
5872 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
5873 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
5874 "\\|[sm]" ; Added manually
5875 "\\)\\>") 2 'cperl-nonoverridable-face)
5876 ;; (mapconcat 'identity
5877 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
5878 ;; "#include" "#define" "#undef")
5880 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
5881 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
5882 ;; This highlights declarations and definitions differenty.
5883 ;; We do not try to highlight in the case of attributes:
5884 ;; it is already done by `cperl-find-pods-heres'
5885 (list (concat "\\<sub"
5886 cperl-white-and-comment-rex ; whitespace/comments
5887 "\\([^ \n\t{;()]+\\)" ; 2=name (assume non-anonymous)
5889 cperl-maybe-white-and-comment-rex ;whitespace/comments?
5890 "([^()]*)\\)?" ; prototype
5891 cperl-maybe-white-and-comment-rex ; whitespace/comments?
5893 2 (if cperl-font-lock-multiline
5894 '(if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5895 'font-lock-function-name-face
5896 'font-lock-variable-name-face)
5897 ;; need to manually set 'multiline' for older font-locks
5899 (if (< 1 (count-lines (match-beginning 0)
5902 (+ 3 (match-beginning 0)) (match-end 0)
5903 'syntax-type 'multiline))
5904 (if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5905 'font-lock-function-name-face
5906 'font-lock-variable-name-face))))
5907 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
5908 2 font-lock-function-name-face)
5909 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
5910 1 font-lock-function-name-face)
5911 (cond ((featurep 'font-lock-extra)
5912 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5913 (2 font-lock-string-face t)
5914 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
5916 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5917 (2 font-lock-string-face t)
5918 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5920 (1 font-lock-string-face t))))
5921 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5922 2 font-lock-string-face t)))
5923 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
5924 font-lock-string-face t)
5925 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
5926 font-lock-constant-face) ; labels
5927 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
5928 2 font-lock-constant-face)
5929 ;; Uncomment to get perl-mode-like vars
5930 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
5931 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
5932 ;;; (2 (cons font-lock-variable-name-face '(underline))))
5933 (cond ((featurep 'font-lock-extra)
5934 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5935 (3 font-lock-variable-name-face)
5937 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5938 (1 font-lock-variable-name-face)
5939 (2 '(restart 2 nil) nil t)))
5940 nil t))) ; local variables, multiple
5942 ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
5943 (` ((, (concat "\\<\\(my\\|local\\|our\\)"
5944 cperl-maybe-white-and-comment-rex
5946 cperl-maybe-white-and-comment-rex
5947 "\\)?\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
5948 (5 (, (if cperl-font-lock-multiline
5949 'font-lock-variable-name-face
5950 '(progn (setq cperl-font-lock-multiline-start
5951 (match-beginning 0))
5952 'font-lock-variable-name-face))))
5954 cperl-maybe-white-and-comment-rex
5956 cperl-maybe-white-and-comment-rex
5957 "\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
5958 ;; Bug in font-lock: limit is used not only to limit
5959 ;; searches, but to set the "extend window for
5960 ;; facification" property. Thus we need to minimize.
5961 (, (if cperl-font-lock-multiline
5962 '(if (match-beginning 3)
5964 (goto-char (match-beginning 3))
5970 (error nil)))) ; typeahead
5971 (1- (point))) ; report limit
5972 (forward-char -2)) ; disable continued expr
5973 '(if (match-beginning 3)
5974 (point-max) ; No limit for continuation
5975 (forward-char -2)))) ; disable continued expr
5976 (, (if cperl-font-lock-multiline
5979 ;; "my" may be already fontified (POD),
5980 ;; so cperl-font-lock-multiline-start is nil
5981 (if (or (not cperl-font-lock-multiline-start)
5983 cperl-font-lock-multiline-start
5987 (1+ cperl-font-lock-multiline-start) (point)
5988 'syntax-type 'multiline))
5989 (setq cperl-font-lock-multiline-start nil))))
5990 (3 font-lock-variable-name-face)))))
5991 (t '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
5992 3 font-lock-variable-name-face)))
5993 '("\\<for\\(each\\)?\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
5994 4 font-lock-variable-name-face)
5995 ;; Avoid $!, and s!!, qq!! etc. when not fontifying syntaxically
5996 '("\\(?:^\\|[^smywqrx$]\\)\\(!\\)" 1 font-lock-negation-char-face)
5997 '("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)))
5999 t-font-lock-keywords-1
6000 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
6001 ;; not yet as of XEmacs 19.12, works with 21.1.11
6003 (not cperl-xemacs-p)
6004 (string< "21.1.9" emacs-version)
6005 (and (string< "21.1.10" emacs-version)
6006 (string< emacs-version "21.1.2")))
6008 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
6009 (if (eq (char-after (match-beginning 2)) ?%)
6012 t) ; arrays and hashes
6013 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
6015 (if (= (- (match-end 2) (match-beginning 2)) 1)
6016 (if (eq (char-after (match-beginning 3)) ?{)
6018 'cperl-array-face) ; arrays and hashes
6019 font-lock-variable-name-face) ; Just to put something
6021 ("\\(@\\|\\$#\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
6022 (1 cperl-array-face)
6023 (2 font-lock-variable-name-face))
6024 ("\\(%\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
6026 (2 font-lock-variable-name-face))
6027 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
6028 ;;; Too much noise from \s* @s[ and friends
6029 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
6030 ;;(3 font-lock-function-name-face t t)
6032 ;; (if (cperl-slash-is-regexp)
6033 ;; font-lock-function-name-face 'default) nil t))
6035 (if cperl-highlight-variables-indiscriminately
6036 (setq t-font-lock-keywords-1
6037 (append t-font-lock-keywords-1
6038 (list '("\\([$*]{?\\sw+\\)" 1
6039 font-lock-variable-name-face)))))
6040 (setq cperl-font-lock-keywords-1
6041 (if cperl-syntaxify-by-font-lock
6042 (cons 'cperl-fontify-update
6043 t-font-lock-keywords)
6044 t-font-lock-keywords)
6045 cperl-font-lock-keywords cperl-font-lock-keywords-1
6046 cperl-font-lock-keywords-2 (append
6047 cperl-font-lock-keywords-1
6048 t-font-lock-keywords-1)))
6049 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
6050 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
6051 (eval ; Avoid a warning
6052 '(font-lock-require-faces
6054 ;; Color-light Color-dark Gray-light Gray-dark Mono
6055 (list 'font-lock-comment-face
6056 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
6061 (list 'font-lock-string-face
6062 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
6067 (list 'font-lock-function-name-face
6069 "Blue" "LightSkyBlue" "Gray50" "LightGray"
6070 (cdr (assq 'background-color ; if mono
6071 (frame-parameters))))
6074 (cdr (assq 'foreground-color ; if mono
6075 (frame-parameters))))
6079 (list 'font-lock-variable-name-face
6080 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
6085 (list 'font-lock-type-face
6086 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
6091 (list 'font-lock-warning-face
6092 ["Pink" "Red" "Gray50" "LightGray"]
6099 (list 'font-lock-constant-face
6100 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
6105 (list 'cperl-nonoverridable-face
6106 ["chartreuse3" ("orchid1" "orange")
6112 (list 'cperl-array-face
6113 ["blue" "yellow" nil "Gray80"]
6114 ["lightyellow2" ("navy" "os2blue" "darkgreen")
6119 (list 'cperl-hash-face
6120 ["red" "red" nil "Gray80"]
6121 ["lightyellow2" ("navy" "os2blue" "darkgreen")
6126 ;; Do it the dull way, without choose-color
6127 (defvar cperl-guessed-background nil
6128 "Display characteristics as guessed by cperl.")
6129 ;; (or (fboundp 'x-color-defined-p)
6130 ;; (defalias 'x-color-defined-p
6131 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
6132 ;; ;; XEmacs >= 19.12
6133 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
6135 ;; (t 'x-valid-color-name-p))))
6136 (cperl-force-face font-lock-constant-face
6137 "Face for constant and label names")
6138 (cperl-force-face font-lock-variable-name-face
6139 "Face for variable names")
6140 (cperl-force-face font-lock-type-face
6141 "Face for data types")
6142 (cperl-force-face cperl-nonoverridable-face
6143 "Face for data types from another group")
6144 (cperl-force-face font-lock-warning-face
6145 "Face for things which should stand out")
6146 (cperl-force-face font-lock-comment-face
6147 "Face for comments")
6148 (cperl-force-face font-lock-function-name-face
6149 "Face for function names")
6150 (cperl-force-face cperl-hash-face
6152 (cperl-force-face cperl-array-face
6154 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
6155 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
6156 ;;(or (boundp 'font-lock-type-face)
6157 ;; (defconst font-lock-type-face
6158 ;; 'font-lock-type-face
6159 ;; "Face to use for data types."))
6160 ;;(or (boundp 'cperl-nonoverridable-face)
6161 ;; (defconst cperl-nonoverridable-face
6162 ;; 'cperl-nonoverridable-face
6163 ;; "Face to use for data types from another group."))
6164 ;;(if (not cperl-xemacs-p) nil
6165 ;; (or (boundp 'font-lock-comment-face)
6166 ;; (defconst font-lock-comment-face
6167 ;; 'font-lock-comment-face
6168 ;; "Face to use for comments."))
6169 ;; (or (boundp 'font-lock-keyword-face)
6170 ;; (defconst font-lock-keyword-face
6171 ;; 'font-lock-keyword-face
6172 ;; "Face to use for keywords."))
6173 ;; (or (boundp 'font-lock-function-name-face)
6174 ;; (defconst font-lock-function-name-face
6175 ;; 'font-lock-function-name-face
6176 ;; "Face to use for function names.")))
6178 (not (cperl-is-face 'cperl-array-face))
6179 (cperl-is-face 'font-lock-emphasized-face))
6180 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
6182 (not (cperl-is-face 'cperl-hash-face))
6183 (cperl-is-face 'font-lock-other-emphasized-face))
6184 (copy-face 'font-lock-other-emphasized-face 'cperl-hash-face))
6186 (not (cperl-is-face 'cperl-nonoverridable-face))
6187 (cperl-is-face 'font-lock-other-type-face))
6188 (copy-face 'font-lock-other-type-face 'cperl-nonoverridable-face))
6189 ;;(or (boundp 'cperl-hash-face)
6190 ;; (defconst cperl-hash-face
6192 ;; "Face to use for hashes."))
6193 ;;(or (boundp 'cperl-array-face)
6194 ;; (defconst cperl-array-face
6195 ;; 'cperl-array-face
6196 ;; "Face to use for arrays."))
6197 ;; Here we try to guess background
6199 (if (boundp 'font-lock-background-mode)
6200 font-lock-background-mode
6202 (face-list (and (fboundp 'face-list) (face-list))))
6203 ;;;; (fset 'cperl-is-face
6204 ;;;; (cond ((fboundp 'find-face)
6205 ;;;; (symbol-function 'find-face))
6207 ;;;; (function (lambda (face) (member face face-list))))
6209 ;;;; (function (lambda (face) (boundp face))))))
6210 (defvar cperl-guessed-background
6211 (if (and (boundp 'font-lock-display-type)
6212 (eq font-lock-display-type 'grayscale))
6215 "Background as guessed by CPerl mode")
6216 (and (not (cperl-is-face 'font-lock-constant-face))
6217 (cperl-is-face 'font-lock-reference-face)
6218 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
6219 (if (cperl-is-face 'font-lock-type-face) nil
6220 (copy-face 'default 'font-lock-type-face)
6222 ((eq background 'light)
6223 (set-face-foreground 'font-lock-type-face
6224 (if (x-color-defined-p "seagreen")
6227 ((eq background 'dark)
6228 (set-face-foreground 'font-lock-type-face
6229 (if (x-color-defined-p "os2pink")
6233 (set-face-background 'font-lock-type-face "gray90"))))
6234 (if (cperl-is-face 'cperl-nonoverridable-face)
6236 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
6238 ((eq background 'light)
6239 (set-face-foreground 'cperl-nonoverridable-face
6240 (if (x-color-defined-p "chartreuse3")
6243 ((eq background 'dark)
6244 (set-face-foreground 'cperl-nonoverridable-face
6245 (if (x-color-defined-p "orchid1")
6248 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
6249 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
6251 ;;; ((eq background 'light)
6252 ;;; (set-face-background 'font-lock-other-emphasized-face
6253 ;;; (if (x-color-defined-p "lightyellow2")
6255 ;;; (if (x-color-defined-p "lightyellow")
6257 ;;; "light yellow"))))
6258 ;;; ((eq background 'dark)
6259 ;;; (set-face-background 'font-lock-other-emphasized-face
6260 ;;; (if (x-color-defined-p "navy")
6262 ;;; (if (x-color-defined-p "darkgreen")
6264 ;;; "dark green"))))
6265 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
6266 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
6267 ;;; (copy-face 'bold 'font-lock-emphasized-face)
6269 ;;; ((eq background 'light)
6270 ;;; (set-face-background 'font-lock-emphasized-face
6271 ;;; (if (x-color-defined-p "lightyellow2")
6273 ;;; "lightyellow")))
6274 ;;; ((eq background 'dark)
6275 ;;; (set-face-background 'font-lock-emphasized-face
6276 ;;; (if (x-color-defined-p "navy")
6278 ;;; (if (x-color-defined-p "darkgreen")
6280 ;;; "dark green"))))
6281 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
6282 (if (cperl-is-face 'font-lock-variable-name-face) nil
6283 (copy-face 'italic 'font-lock-variable-name-face))
6284 (if (cperl-is-face 'font-lock-constant-face) nil
6285 (copy-face 'italic 'font-lock-constant-face))))
6286 (setq cperl-faces-init t))
6287 (error (message "cperl-init-faces (ignored): %s" errs))))
6290 (defun cperl-ps-print-init ()
6291 "Initialization of `ps-print' components for faces used in CPerl."
6292 (eval-after-load "ps-print"
6293 '(setq ps-bold-faces
6294 ;; font-lock-variable-name-face
6295 ;; font-lock-constant-face
6296 (append '(cperl-array-face cperl-hash-face)
6299 ;; font-lock-constant-face
6300 (append '(cperl-nonoverridable-face cperl-hash-face)
6303 ;; font-lock-type-face
6304 (append '(cperl-array-face cperl-hash-face underline cperl-nonoverridable-face)
6305 ps-underlined-faces))))
6307 (defvar ps-print-face-extension-alist)
6309 (defun cperl-ps-print (&optional file)
6310 "Pretty-print in CPerl style.
6311 If optional argument FILE is an empty string, prints to printer, otherwise
6312 to the file FILE. If FILE is nil, prompts for a file name.
6314 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
6317 (setq file (read-from-minibuffer
6318 "Print to file (if empty - to printer): "
6319 (concat (buffer-file-name) ".ps")
6320 nil nil 'file-name-history)))
6321 (or (> (length file) 0)
6323 (require 'ps-print) ; To get ps-print-face-extension-alist
6324 (let ((ps-print-color-p t)
6325 (ps-print-face-extension-alist ps-print-face-extension-alist))
6326 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
6327 (ps-print-buffer-with-faces file)))
6329 ;;; (defun cperl-ps-print-init ()
6330 ;;; "Initialization of `ps-print' components for faces used in CPerl."
6331 ;;; ;; Guard against old versions
6332 ;;; (defvar ps-underlined-faces nil)
6333 ;;; (defvar ps-bold-faces nil)
6334 ;;; (defvar ps-italic-faces nil)
6335 ;;; (setq ps-bold-faces
6336 ;;; (append '(font-lock-emphasized-face
6337 ;;; cperl-array-face
6338 ;;; font-lock-keyword-face
6339 ;;; font-lock-variable-name-face
6340 ;;; font-lock-constant-face
6341 ;;; font-lock-reference-face
6342 ;;; font-lock-other-emphasized-face
6343 ;;; cperl-hash-face)
6345 ;;; (setq ps-italic-faces
6346 ;;; (append '(cperl-nonoverridable-face
6347 ;;; font-lock-constant-face
6348 ;;; font-lock-reference-face
6349 ;;; font-lock-other-emphasized-face
6350 ;;; cperl-hash-face)
6351 ;;; ps-italic-faces))
6352 ;;; (setq ps-underlined-faces
6353 ;;; (append '(font-lock-emphasized-face
6354 ;;; cperl-array-face
6355 ;;; font-lock-other-emphasized-face
6357 ;;; cperl-nonoverridable-face font-lock-type-face)
6358 ;;; ps-underlined-faces))
6359 ;;; (cons 'font-lock-type-face ps-underlined-faces))
6362 (if (cperl-enable-font-lock) (cperl-windowed-init))
6364 (defconst cperl-styles-entries
6365 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
6366 cperl-label-offset cperl-extra-newline-before-brace
6367 cperl-extra-newline-before-brace-multiline
6368 cperl-merge-trailing-else
6369 cperl-continued-statement-offset))
6371 (defconst cperl-style-examples
6372 "##### Numbers etc are: cperl-indent-level cperl-brace-offset
6373 ##### cperl-continued-brace-offset cperl-label-offset
6374 ##### cperl-continued-statement-offset
6375 ##### cperl-merge-trailing-else cperl-extra-newline-before-brace
6377 ########### (Do not forget cperl-extra-newline-before-brace-multiline)
6379 ### CPerl (=GNU - extra-newline-before-brace + merge-trailing-else) 2/0/0/-2/2/t/nil
6391 ### PerlStyle (=CPerl with 4 as indent) 4/0/0/-4/4/t/nil
6403 ### GNU 2/0/0/-2/2/nil/t
6418 ### C++ (=PerlStyle with braces aligned with control words) 4/0/-4/-4/4/nil/t
6433 ### BSD (=C++, but will not change preexisting merge-trailing-else
6434 ### and extra-newline-before-brace ) 4/0/-4/-4/4
6449 ### K&R (=C++ with indent 5 - merge-trailing-else, but will not
6450 ### change preexisting extra-newline-before-brace) 5/0/-5/-5/5/nil
6465 ### Whitesmith (=PerlStyle, but will not change preexisting
6466 ### extra-newline-before-brace and merge-trailing-else) 4/0/0/-4/4
6481 "Examples of if/else with different indent styles (with v4.23).")
6483 (defconst cperl-style-alist
6484 '(("CPerl" ;; =GNU - extra-newline-before-brace + cperl-merge-trailing-else
6485 (cperl-indent-level . 2)
6486 (cperl-brace-offset . 0)
6487 (cperl-continued-brace-offset . 0)
6488 (cperl-label-offset . -2)
6489 (cperl-continued-statement-offset . 2)
6490 (cperl-extra-newline-before-brace . nil)
6491 (cperl-extra-newline-before-brace-multiline . nil)
6492 (cperl-merge-trailing-else . t))
6494 ("PerlStyle" ; CPerl with 4 as indent
6495 (cperl-indent-level . 4)
6496 (cperl-brace-offset . 0)
6497 (cperl-continued-brace-offset . 0)
6498 (cperl-label-offset . -4)
6499 (cperl-continued-statement-offset . 4)
6500 (cperl-extra-newline-before-brace . nil)
6501 (cperl-extra-newline-before-brace-multiline . nil)
6502 (cperl-merge-trailing-else . t))
6505 (cperl-indent-level . 2)
6506 (cperl-brace-offset . 0)
6507 (cperl-continued-brace-offset . 0)
6508 (cperl-label-offset . -2)
6509 (cperl-continued-statement-offset . 2)
6510 (cperl-extra-newline-before-brace . t)
6511 (cperl-extra-newline-before-brace-multiline . t)
6512 (cperl-merge-trailing-else . nil))
6515 (cperl-indent-level . 5)
6516 (cperl-brace-offset . 0)
6517 (cperl-continued-brace-offset . -5)
6518 (cperl-label-offset . -5)
6519 (cperl-continued-statement-offset . 5)
6520 ;;(cperl-extra-newline-before-brace . nil) ; ???
6521 ;;(cperl-extra-newline-before-brace-multiline . nil)
6522 (cperl-merge-trailing-else . nil))
6525 (cperl-indent-level . 4)
6526 (cperl-brace-offset . 0)
6527 (cperl-continued-brace-offset . -4)
6528 (cperl-label-offset . -4)
6529 (cperl-continued-statement-offset . 4)
6530 ;;(cperl-extra-newline-before-brace . nil) ; ???
6531 ;;(cperl-extra-newline-before-brace-multiline . nil)
6532 ;;(cperl-merge-trailing-else . nil) ; ???
6536 (cperl-indent-level . 4)
6537 (cperl-brace-offset . 0)
6538 (cperl-continued-brace-offset . -4)
6539 (cperl-label-offset . -4)
6540 (cperl-continued-statement-offset . 4)
6541 (cperl-extra-newline-before-brace . t)
6542 (cperl-extra-newline-before-brace-multiline . t)
6543 (cperl-merge-trailing-else . nil))
6546 (cperl-indent-level . 4)
6547 (cperl-brace-offset . 0)
6548 (cperl-continued-brace-offset . 0)
6549 (cperl-label-offset . -4)
6550 (cperl-continued-statement-offset . 4)
6551 ;;(cperl-extra-newline-before-brace . nil) ; ???
6552 ;;(cperl-extra-newline-before-brace-multiline . nil)
6553 ;;(cperl-merge-trailing-else . nil) ; ???
6556 "List of variables to set to get a particular indentation style.
6557 Should be used via `cperl-set-style' or via Perl menu.
6559 See examples in `cperl-style-examples'.")
6561 (defun cperl-set-style (style)
6562 "Set CPerl mode variables to use one of several different indentation styles.
6563 The arguments are a string representing the desired style.
6564 The list of styles is in `cperl-style-alist', available styles
6565 are CPerl, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith.
6567 The current value of style is memorized (unless there is a memorized
6568 data already), may be restored by `cperl-set-style-back'.
6570 Chosing \"Current\" style will not change style, so this may be used for
6571 side-effect of memorizing only. Examples in `cperl-style-examples'."
6573 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
6574 cperl-style-alist)))
6575 (list (completing-read "Enter style: " list nil 'insist))))
6577 (setq cperl-old-style
6580 (cons name (eval name))))
6581 cperl-styles-entries)))
6582 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
6584 (setq setting (car style) style (cdr style))
6585 (set (car setting) (cdr setting)))))
6587 (defun cperl-set-style-back ()
6588 "Restore a style memorized by `cperl-set-style'."
6590 (or cperl-old-style (error "The style was not changed"))
6592 (while cperl-old-style
6593 (setq setting (car cperl-old-style)
6594 cperl-old-style (cdr cperl-old-style))
6595 (set (car setting) (cdr setting)))))
6597 (defun cperl-check-syntax ()
6599 (require 'mode-compile)
6600 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
6601 (eval '(mode-compile)))) ; Avoid a warning
6603 (defun cperl-info-buffer (type)
6604 ;; Returns buffer with documentation. Creates if missing.
6605 ;; If TYPE, this vars buffer.
6606 ;; Special care is taken to not stomp over an existing info buffer
6607 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
6608 (info (get-buffer bname))
6609 (oldbuf (get-buffer "*info*")))
6611 (save-window-excursion
6616 (rename-buffer "*info-perl-tmp*")))
6617 (save-window-excursion
6619 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
6620 (set-buffer "*info*")
6621 (rename-buffer bname)
6623 (set-buffer "*info-perl-tmp*")
6624 (rename-buffer "*info*")
6625 (set-buffer bname)))
6626 (make-local-variable 'window-min-height)
6627 (setq window-min-height 2)
6628 (current-buffer)))))
6630 (defun cperl-word-at-point (&optional p)
6631 "Return the word at point or at P."
6633 (if p (goto-char p))
6634 (or (cperl-word-at-point-hard)
6637 (funcall (or (and (boundp 'find-tag-default-function)
6638 find-tag-default-function)
6639 (get major-mode 'find-tag-default-function)
6640 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
6641 ;; automatically used within `find-tag-default':
6642 'find-tag-default))))))
6644 (defun cperl-info-on-command (command)
6645 "Show documentation for Perl command COMMAND in other window.
6646 If perl-info buffer is shown in some frame, uses this frame.
6647 Customized by setting variables `cperl-shrink-wrap-info-frame',
6648 `cperl-max-help-size'."
6650 (let* ((default (cperl-word-at-point))
6652 (format "Find doc for Perl function (default %s): "
6654 (list (if (equal read "")
6658 (let ((buffer (current-buffer))
6659 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
6660 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
6661 max-height char-height buf-list)
6662 (if (string-match "^-[a-zA-Z]$" command)
6663 (setq cmd-desc "^-X[ \t\n]"))
6664 (setq isvar (string-match "^[$@%]" command)
6665 buf (cperl-info-buffer isvar)
6666 iniwin (selected-window)
6667 fr1 (window-frame iniwin))
6669 (goto-char (point-min))
6671 (progn (re-search-forward "^-X[ \t\n]")
6673 (if (re-search-forward cmd-desc nil t)
6675 ;; Go back to beginning of the group (ex, for qq)
6676 (if (re-search-backward "^[ \t\n\f]")
6681 buf-list (list buf "*info-perl-var*" "*info-perl*"))
6682 (while (and (not win) buf-list)
6683 (setq win (get-buffer-window (car buf-list) t))
6684 (setq buf-list (cdr buf-list)))
6686 (eq (window-buffer win) buf)
6687 (set-window-buffer win buf))
6688 (and win (setq fr2 (window-frame win)))
6689 (if (or (not fr2) (eq fr1 fr2))
6691 (special-display-popup-frame buf) ; Make it visible
6692 (select-window win))
6693 (goto-char pos) ; Needed (?!).
6695 (setq iniheight (window-height)
6696 frheight (frame-height)
6697 not-loner (< iniheight (1- frheight))) ; Are not alone
6698 (cond ((if not-loner cperl-max-help-size
6699 cperl-shrink-wrap-info-frame)
6705 (if (re-search-forward
6706 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
6707 (match-beginning 0) (point-max)))))
6710 (/ (* (- frheight 3) cperl-max-help-size) 100)
6711 (setq char-height (frame-char-height))
6712 ;; Non-functioning under OS/2:
6713 (if (eq char-height 1) (setq char-height 18))
6714 ;; Title, menubar, + 2 for slack
6715 (- (/ (x-display-pixel-height) char-height) 4)))
6716 (if (> height max-height) (setq height max-height))
6717 ;;(message "was %s doing %s" iniheight height)
6719 (enlarge-window (- height iniheight))
6720 (set-frame-height (window-frame win) (1+ height)))))
6721 (set-window-start (selected-window) pos))
6722 (message "No entry for %s found." command))
6723 ;;(pop-to-buffer buffer)
6724 (select-window iniwin)))
6726 (defun cperl-info-on-current-command ()
6727 "Show documentation for Perl command at point in other window."
6729 (cperl-info-on-command (cperl-word-at-point)))
6731 (defun cperl-imenu-info-imenu-search ()
6732 (if (looking-at "^-X[ \t\n]") nil
6734 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
6737 (defun cperl-imenu-info-imenu-name ()
6739 (match-beginning 1) (match-end 1)))
6741 (defun cperl-imenu-on-info ()
6742 "Shows imenu for Perl Info Buffer.
6743 Opens Perl Info buffer if needed."
6745 (let* ((buffer (current-buffer))
6746 imenu-create-index-function
6747 imenu-prev-index-position-function
6748 imenu-extract-index-name-function
6749 (index-item (save-restriction
6750 (save-window-excursion
6751 (set-buffer (cperl-info-buffer nil))
6752 (setq imenu-create-index-function
6753 'imenu-default-create-index-function
6754 imenu-prev-index-position-function
6755 'cperl-imenu-info-imenu-search
6756 imenu-extract-index-name-function
6757 'cperl-imenu-info-imenu-name)
6758 (imenu-choose-buffer-index)))))
6762 (pop-to-buffer "*info-perl*")
6764 ((markerp (cdr index-item))
6765 (goto-char (marker-position (cdr index-item))))
6767 (goto-char (cdr index-item))))
6768 (set-window-start (selected-window) (point))
6769 (pop-to-buffer buffer)))))
6771 (defun cperl-lineup (beg end &optional step minshift)
6772 "Lineup construction in a region.
6773 Beginning of region should be at the start of a construction.
6774 All first occurrences of this construction in the lines that are
6775 partially contained in the region are lined up at the same column.
6777 MINSHIFT is the minimal amount of space to insert before the construction.
6778 STEP is the tabwidth to position constructions.
6779 If STEP is nil, `cperl-lineup-step' will be used
6780 \(or `cperl-indent-level', if `cperl-lineup-step' is nil).
6781 Will not move the position at the start to the left."
6783 (let (search col tcol seen b)
6787 (setq end (point-marker))
6789 (skip-chars-forward " \t\f")
6790 (setq beg (point-marker))
6791 (indent-region beg end nil)
6793 (setq col (current-column))
6794 (if (looking-at "[a-zA-Z0-9_]")
6795 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
6799 (buffer-substring (match-beginning 0)
6800 (match-end 0))) "\\>"))
6801 (error "Cannot line up in a middle of the word"))
6802 (if (looking-at "$")
6803 (error "Cannot line up end of line"))
6804 (setq search (regexp-quote (char-to-string (following-char)))))
6805 (setq step (or step cperl-lineup-step cperl-indent-level))
6806 (or minshift (setq minshift 1))
6808 (beginning-of-line 2)
6809 (and (< (point) end)
6810 (re-search-forward search end t)
6811 (goto-char (match-beginning 0))))
6812 (setq tcol (current-column) seen t)
6813 (if (> tcol col) (setq col tcol)))
6815 (error "The construction to line up occurred only once"))
6817 (setq col (+ col minshift))
6818 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
6821 (cperl-make-indent col)
6822 (beginning-of-line 2)
6823 (and (< (point) end)
6824 (re-search-forward search end t)
6825 (goto-char (match-beginning 0)))))))) ; No body
6827 (defun cperl-etags (&optional add all files) ;; NOT USED???
6828 "Run etags with appropriate options for Perl files.
6829 If optional argument ALL is `recursive', will process Perl files
6830 in subdirectories too."
6833 (args '("-l" "none" "-r"
6834 ;; 1=fullname 2=package? 3=name 4=proto? 5=attrs? (VERY APPROX!)
6835 "/\\<sub[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([ \t]*:[^#{;]*\\)?\\([{#]\\|$\\)/\\3/"
6837 "/\\<package[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\([#;]\\|$\\)/\\1/"
6839 "/\\<\\(package\\)[ \\t]*;/\\1;/"))
6841 (if add (setq args (cons "-a" args)))
6842 (or files (setq files (list buffer-file-name)))
6844 ((eq all 'recursive)
6845 ;;(error "Not implemented: recursive")
6846 (setq args (append (list "-e"
6847 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
6849 find(\\&wanted, '.');
6854 ;;(error "Not implemented: all")
6855 (setq args (append (list "-e"
6856 "push @ARGV, <*.PL *.pl *.pm>;
6861 (setq args (append args files))))
6862 (setq res (apply 'call-process cmd nil nil nil args))
6864 (message "etags returned \"%s\"" res))))
6866 (defun cperl-toggle-auto-newline ()
6867 "Toggle the state of `cperl-auto-newline'."
6869 (setq cperl-auto-newline (not cperl-auto-newline))
6870 (message "Newlines will %sbe auto-inserted now."
6871 (if cperl-auto-newline "" "not ")))
6873 (defun cperl-toggle-abbrev ()
6874 "Toggle the state of automatic keyword expansion in CPerl mode."
6876 (abbrev-mode (if abbrev-mode 0 1))
6877 (message "Perl control structure will %sbe auto-inserted now."
6878 (if abbrev-mode "" "not ")))
6881 (defun cperl-toggle-electric ()
6882 "Toggle the state of parentheses doubling in CPerl mode."
6884 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
6885 (message "Parentheses will %sbe auto-doubled now."
6886 (if (cperl-val 'cperl-electric-parens) "" "not ")))
6888 (defun cperl-toggle-autohelp ()
6889 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
6890 Delay of auto-help controlled by `cperl-lazy-help-time'."
6892 (if (fboundp 'run-with-idle-timer)
6894 (if cperl-lazy-installed
6895 (cperl-lazy-unstall)
6896 (cperl-lazy-install))
6897 (message "Perl help messages will %sbe automatically shown now."
6898 (if cperl-lazy-installed "" "not ")))
6899 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
6901 (defun cperl-toggle-construct-fix ()
6902 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
6904 (setq cperl-indent-region-fix-constructs
6905 (if cperl-indent-region-fix-constructs
6908 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
6909 (if cperl-indent-region-fix-constructs "" "not ")))
6911 (defun cperl-toggle-set-debug-unwind (arg &optional backtrace)
6912 "Toggle (or, with numeric argument, set) debugging state of syntaxification.
6913 Nonpositive numeric argument disables debugging messages. The message
6914 summarizes which regions it was decided to rescan for syntactic constructs.
6916 The message looks like this:
6918 Syxify req=123..138 actual=101..146 done-to: 112=>146 statepos: 73=>117
6920 Numbers are character positions in the buffer. REQ provides the range to
6921 rescan requested by `font-lock'. ACTUAL is the range actually resyntaxified;
6922 for correct operation it should start and end outside any special syntactic
6923 construct. DONE-TO and STATEPOS indicate changes to internal caches maintained
6927 (setq arg (if (eq cperl-syntaxify-by-font-lock
6928 (if backtrace 'backtrace 'message)) 0 1)))
6929 (setq arg (if (> arg 0) (if backtrace 'backtrace 'message) t))
6930 (setq cperl-syntaxify-by-font-lock arg)
6931 (message "Debugging messages of syntax unwind %sabled."
6932 (if (eq arg t) "dis" "en")))
6934 ;;;; Tags file creation.
6936 (defvar cperl-tmp-buffer " *cperl-tmp*")
6938 (defun cperl-setup-tmp-buf ()
6939 (set-buffer (get-buffer-create cperl-tmp-buffer))
6940 (set-syntax-table cperl-mode-syntax-table)
6941 (buffer-disable-undo)
6943 (if cperl-use-syntax-table-text-property-for-tags
6945 (make-local-variable 'parse-sexp-lookup-properties)
6946 ;; Do not introduce variable if not needed, we check it!
6947 (set 'parse-sexp-lookup-properties t))))
6949 (defun cperl-xsub-scan ()
6951 (let ((index-alist '())
6952 (prev-pos 0) index index1 name package prefix)
6953 (goto-char (point-min))
6954 ;; Search for the function
6955 (progn ;;save-match-data
6956 (while (re-search-forward
6957 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
6960 ((match-beginning 2) ; SECTION
6961 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
6962 (goto-char (match-beginning 0))
6963 (skip-chars-forward " \t")
6965 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
6966 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
6968 ((not package) nil) ; C language section
6969 ((match-beginning 3) ; XSUB
6970 (goto-char (1+ (match-beginning 3)))
6971 (setq index (imenu-example--name-and-position))
6972 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
6973 (if (and prefix (string-match (concat "^" prefix) name))
6974 (setq name (substring name (length prefix))))
6975 (cond ((string-match "::" name) nil)
6977 (setq index1 (cons (concat package "::" name) (cdr index)))
6978 (push index1 index-alist)))
6980 (push index index-alist))
6982 ;; (beginning-of-line)
6983 (setq index (imenu-example--name-and-position))
6984 (setcar index (concat package "::BOOT:"))
6985 (push index index-alist)))))
6988 (defvar cperl-unreadable-ok nil)
6990 (defun cperl-find-tags (ifile xs topdir)
6991 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
6992 (cperl-pod-here-fontify nil) f file)
6994 (if b (set-buffer b)
6995 (cperl-setup-tmp-buf))
6998 (setq file (car (insert-file-contents ifile)))
6999 (error (if cperl-unreadable-ok nil
7001 (format "File %s unreadable. Continue? " ifile))
7002 (setq cperl-unreadable-ok t)
7003 (error "Aborting: unreadable file %s" ifile)))))
7005 (message "Unreadable file %s" ifile)
7006 (message "Scanning file %s ..." file)
7007 (if (and cperl-use-syntax-table-text-property-for-tags
7009 (condition-case err ; after __END__ may have garbage
7010 (cperl-find-pods-heres nil nil noninteractive)
7011 (error (message "While scanning for syntax: %s" err))))
7013 (setq lst (cperl-xsub-scan))
7014 (setq ind (cperl-imenu--create-perl-index))
7015 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
7020 (cond ((string-match "^[_a-zA-Z]" (car elt))
7021 (goto-char (cdr elt))
7022 (beginning-of-line) ; pos should be of the start of the line
7025 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
7026 (buffer-substring (progn
7027 (goto-char (cdr elt))
7028 ;; After name now...
7029 (or (eolp) (forward-char 1))
7037 (setq elt (car lst) lst (cdr lst))
7042 (if (string-match "^package " (car elt))
7043 (substring (car elt) 8)
7046 (number-to-string (elt elt 2)) ; Line
7048 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
7050 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
7051 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
7053 ;; Need to insert the name without package as well
7054 (setq lst (cons (cons (substring (elt elt 3)
7062 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
7063 (set-text-properties 0 (length rel) nil rel)
7064 (and (equal topdir (substring rel 0 (length topdir)))
7065 (setq rel (substring file (length topdir))))
7066 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
7067 (setq ret (buffer-substring 1 (point-max)))
7070 (message "Scanning file %s finished" file))
7073 (defun cperl-add-tags-recurse-noxs ()
7074 "Add to TAGS data for \"pure\" Perl files in the current directory and kids.
7076 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7077 -f cperl-add-tags-recurse-noxs
7079 (cperl-write-tags nil nil t t nil t))
7081 (defun cperl-add-tags-recurse-noxs-fullpath ()
7082 "Add to TAGS data for \"pure\" Perl in the current directory and kids.
7083 Writes down fullpath, so TAGS is relocatable (but if the build directory
7084 is relocated, the file TAGS inside it breaks). Use as
7085 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7086 -f cperl-add-tags-recurse-noxs-fullpath
7088 (cperl-write-tags nil nil t t nil t ""))
7090 (defun cperl-add-tags-recurse ()
7091 "Add to TAGS file data for Perl files in the current directory and kids.
7093 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7094 -f cperl-add-tags-recurse
7096 (cperl-write-tags nil nil t t))
7098 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
7099 ;; If INBUFFER, do not select buffer, and do not save
7100 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
7103 (setq file (if dir default-directory (buffer-file-name)))
7104 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
7106 (setq topdir default-directory))
7107 (let ((tags-file-name "TAGS")
7108 (case-fold-search (eq system-type 'emx))
7111 (cond (inbuffer nil) ; Already there
7112 ((file-exists-p tags-file-name)
7114 (visit-tags-table-buffer)
7115 (visit-tags-table-buffer tags-file-name)))
7116 (t (set-buffer (find-file-noselect tags-file-name))))
7119 (cond ((eq erase 'ignore))
7122 (setq erase 'ignore)))
7125 (directory-files file t
7126 (if recurse nil cperl-scan-files-regexp)
7129 (if cperl-unreadable-ok nil
7131 (format "Directory %s unreadable. Continue? " file))
7132 (setq cperl-unreadable-ok t
7133 tm nil) ; Return empty list
7134 (error "Aborting: unreadable directory %s" file)))))))
7138 ((string-match cperl-noscan-files-regexp file)
7140 ((not (file-directory-p file))
7141 (if (string-match cperl-scan-files-regexp file)
7142 (cperl-write-tags file erase recurse nil t noxs topdir)))
7144 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
7147 (setq xs (string-match "\\.xs$" file))
7148 (if (not (and xs noxs))
7150 (cond ((eq erase 'ignore) (goto-char (point-max)))
7151 (erase (erase-buffer))
7155 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
7156 (set-text-properties 0 (length rel) nil rel)
7157 (and (equal topdir (substring rel 0 (length topdir)))
7158 (setq rel (substring file (length topdir))))
7159 (if (search-forward (concat "\f\n" rel ",") nil t)
7161 (search-backward "\f\n")
7162 (delete-region (point)
7165 (if (search-forward "\f\n"
7169 (goto-char (point-max)))))
7170 (insert (cperl-find-tags file xs topdir))))))
7171 (if inbuffer nil ; Delegate to the caller
7172 (save-buffer 0) ; No backup
7173 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
7174 (initialize-new-tags-table))))))
7176 (defvar cperl-tags-hier-regexp-list
7183 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
7185 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
7188 (defvar cperl-hierarchy '(() ())
7189 "Global hierarchy of classes.")
7191 (defun cperl-tags-hier-fill ()
7192 ;; Suppose we are in a tag table cooked by cperl.
7194 (let (type pack name pos line chunk ord cons1 file str info fileind)
7195 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
7196 (setq pos (match-beginning 0)
7197 pack (match-beginning 2))
7199 (if (looking-at (concat
7208 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
7209 name (buffer-substring (match-beginning 2) (match-end 2))
7210 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
7211 line (buffer-substring (match-beginning 3) (match-end 3))
7214 fileind (format "%s:%s" file line)
7215 ;; Moves to beginning of the next line:
7216 info (cperl-etags-snarf-tag file line))
7219 ;; Make new member of hierarchy name ==> file ==> pos if needed
7220 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
7222 (setcdr cons1 (cons (cons fileind (vector file info))
7224 ;; First occurrence of the name, start alist
7225 (setq cons1 (cons name (list (cons fileind (vector file info)))))
7227 (setcar (cdr cperl-hierarchy)
7228 (cons cons1 (nth 1 cperl-hierarchy)))
7229 (setcar cperl-hierarchy
7230 (cons cons1 (car cperl-hierarchy)))))))
7233 (defun cperl-tags-hier-init (&optional update)
7234 "Show hierarchical menu of classes and methods.
7235 Finds info about classes by a scan of loaded TAGS files.
7236 Supposes that the TAGS files contain fully qualified function names.
7237 One may build such TAGS files from CPerl mode menu."
7241 (if (or update (null (nth 2 cperl-hierarchy)))
7242 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
7245 (setcdr elt (cdr (nth 1 elt)))))))
7246 pack name cons1 to l1 l2 l3 l4 b)
7247 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
7248 (setq cperl-hierarchy (list l1 l2 l3))
7249 (if cperl-xemacs-p ; Not checked
7252 ;; Does this work in XEmacs?
7253 (call-interactively 'visit-tags-table))
7254 (message "Updating list of classes...")
7255 (set-buffer (get-file-buffer tags-file-name))
7256 (cperl-tags-hier-fill))
7258 (call-interactively 'visit-tags-table))
7262 (message "Updating list of classes... %s" tagsfile)
7263 (set-buffer (get-file-buffer tagsfile))
7264 (cperl-tags-hier-fill)))
7266 (message "Updating list of classes... postprocessing..."))
7267 (mapcar remover (car cperl-hierarchy))
7268 (mapcar remover (nth 1 cperl-hierarchy))
7269 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
7270 (cons "Methods: " (car cperl-hierarchy))))
7271 (cperl-tags-treeify to 1)
7272 (setcar (nthcdr 2 cperl-hierarchy)
7273 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
7274 (message "Updating list of classes: done, requesting display...")
7275 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
7277 (or (nth 2 cperl-hierarchy)
7278 (error "No items found"))
7280 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
7281 (if (if (fboundp 'display-popup-menus-p)
7282 (let ((f 'display-popup-menus-p))
7285 (x-popup-menu t (nth 2 cperl-hierarchy))
7287 (tmm-prompt (nth 2 cperl-hierarchy))))
7288 (if (and update (listp update))
7289 (progn (while (cdr update) (setq update (cdr update)))
7290 (setq update (car update)))) ; Get the last from the list
7291 (if (vectorp update)
7293 (find-file (elt update 0))
7294 (cperl-etags-goto-tag-location (elt update 1))))
7295 (if (eq update -999) (cperl-tags-hier-init t)))
7297 (defun cperl-tags-treeify (to level)
7298 ;; cadr of `to' is read-write. On start it is a cons
7299 (let* ((regexp (concat "^\\(" (mapconcat
7301 (make-list level "[_a-zA-Z0-9]+")
7304 (packages (cdr (nth 1 to)))
7305 (methods (cdr (nth 2 to)))
7306 l1 head tail cons1 cons2 ord writeto packs recurse
7307 root-packages root-functions ms many_ms same_name ps
7311 (cond ((and (string-match regexp (car elt))
7312 (or (eq ord 1) (match-end 2)))
7313 (setq head (substring (car elt) 0 (match-end 1))
7314 tail (if (match-end 2) (substring (car elt)
7317 (if (setq cons1 (assoc head writeto)) nil
7318 ;; Need to init new head
7319 (setcdr writeto (cons (list head (list "Packages: ")
7322 (setq cons1 (nth 1 writeto)))
7323 (setq cons2 (nth ord cons1)) ; Either packs or meths
7324 (setcdr cons2 (cons elt (cdr cons2))))
7326 (setq root-functions (cons elt root-functions)))
7328 (setq root-packages (cons elt root-packages))))))))
7329 (setcdr to l1) ; Init to dynamic space
7332 (mapcar move-deeper packages)
7334 (mapcar move-deeper methods)
7336 (mapcar (function (lambda (elt)
7337 (cperl-tags-treeify elt (1+ level))))
7339 ;;Now clean up leaders with one child only
7340 (mapcar (function (lambda (elt)
7341 (if (not (and (listp (cdr elt))
7342 (eq (length elt) 2))) nil
7343 (setcar elt (car (nth 1 elt)))
7344 (setcdr elt (cdr (nth 1 elt))))))
7346 ;; Sort the roots of subtrees
7347 (if (default-value 'imenu-sort-function)
7349 (sort (cdr to) (default-value 'imenu-sort-function))))
7350 ;; Now add back functions removed from display
7351 (mapcar (function (lambda (elt)
7352 (setcdr to (cons elt (cdr to)))))
7353 (if (default-value 'imenu-sort-function)
7355 (sort root-functions (default-value 'imenu-sort-function)))
7357 ;; Now add back packages removed from display
7358 (mapcar (function (lambda (elt)
7359 (setcdr to (cons (cons (concat "package " (car elt))
7362 (if (default-value 'imenu-sort-function)
7364 (sort root-packages (default-value 'imenu-sort-function)))
7368 ;;; '(keymap "Name1"
7372 ;;; ("Tail1" "x") ("Tail2" "y"))))
7374 (defun cperl-list-fold (list name limit)
7375 (let (list1 list2 elt1 (num 0))
7376 (if (<= (length list) limit) list
7377 (setq list1 nil list2 nil)
7382 (if (<= num imenu-max-items)
7383 (setq list2 (cons elt1 list2))
7384 (setq list1 (cons (cons name
7389 (nreverse (cons (cons name
7393 (defun cperl-menu-to-keymap (menu &optional name)
7399 (cond ((listp (cdr elt))
7400 (setq list (cperl-list-fold
7401 (cdr elt) (car elt) imenu-max-items))
7404 (cperl-menu-to-keymap list))))
7406 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
7407 (cperl-list-fold menu "Root" imenu-max-items)))))
7410 (defvar cperl-bad-style-regexp
7411 (mapconcat 'identity
7412 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
7413 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
7415 "Finds places such that insertion of a whitespace may help a lot.")
7417 (defvar cperl-not-bad-style-regexp
7420 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
7421 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
7422 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
7423 "<\\$?\\sw+\\(\\.\\(\\sw\\|_\\)+\\)?>" ; <IN> <stdin.h>
7424 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
7431 "\\\\[&$@*\\\\]" ; \&func
7434 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
7437 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
7438 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
7439 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
7443 "If matches at the start of match found by `my-bad-c-style-regexp',
7444 insertion of a whitespace will not help.")
7448 (defun cperl-find-bad-style ()
7449 "Find places in the buffer where insertion of a whitespace may help.
7450 Prompts user for insertion of spaces.
7451 Currently it is tuned to C and Perl syntax."
7453 (let (found-bad (p (point)))
7454 (setq last-nonmenu-event 13) ; To disable popup
7455 (goto-char (point-min))
7456 (map-y-or-n-p "Insert space here? "
7457 (lambda (arg) (insert " "))
7458 'cperl-next-bad-style
7459 '("location" "locations" "insert a space into")
7460 '((?\C-r (lambda (arg)
7461 (let ((buffer-quit-function
7462 'exit-recursive-edit))
7463 (message "Exit with Esc Esc")
7465 t)) ; Consider acted upon
7466 "edit, exit with Esc Esc")
7468 (let ((buffer-quit-function
7469 'exit-recursive-edit))
7470 (message "Exit with Esc Esc")
7472 t)) ; Consider acted upon
7473 "edit, exit with Esc Esc"))
7475 (if found-bad (goto-char found-bad)
7477 (message "No appropriate place found"))))
7479 (defun cperl-next-bad-style ()
7480 (let (p (not-found t) (point (point)) found)
7481 (while (and not-found
7482 (re-search-forward cperl-bad-style-regexp nil 'to-end))
7484 (goto-char (match-beginning 0))
7486 (looking-at cperl-not-bad-style-regexp)
7487 ;; Check for a < -b and friends
7488 (and (eq (following-char) ?\-)
7490 (skip-chars-backward " \t\n")
7491 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
7492 ;; Now check for syntax type
7494 (setq found (point))
7495 (beginning-of-defun)
7496 (let ((pps (parse-partial-sexp (point) found)))
7497 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
7498 (goto-char (match-end 0))
7506 (defvar cperl-have-help-regexp
7510 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
7511 "[$@]\\^[a-zA-Z]" ; Special variable
7512 "[$@][^ \n\t]" ; Special variable
7513 "-[a-zA-Z]" ; File test
7514 "\\\\[a-zA-Z0]" ; Special chars
7515 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
7516 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
7517 "[a-zA-Z_0-9:]+" ; symbol or number
7524 "Matches places in the buffer we can find help for.")
7526 (defvar cperl-message-on-help-error t)
7527 (defvar cperl-help-from-timer nil)
7529 (defun cperl-word-at-point-hard ()
7530 ;; Does not save-excursion
7531 ;; Get to the something meaningful
7532 (or (eobp) (eolp) (forward-char 1))
7533 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
7534 (save-excursion (beginning-of-line) (point))
7537 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
7538 ;; (skip-chars-backward " \n\t\r({[]});,")
7539 ;; (or (bobp) (backward-char 1))))
7542 ((looking-at "[a-zA-Z0-9_:]") ; symbol
7543 (skip-chars-backward "a-zA-Z0-9_:")
7545 ((and (eq (preceding-char) ?^) ; $^I
7546 (eq (char-after (- (point) 2)) ?\$))
7548 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
7550 ((and (eq (preceding-char) ?\=)
7551 (eq (current-column) 1))
7552 (forward-char -1))) ; =head1
7553 (if (and (eq (preceding-char) ?\<)
7554 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
7556 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
7558 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
7560 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
7561 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
7563 ((and (eq (preceding-char) ?\$)
7564 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
7566 ((and (eq (following-char) ?\>)
7567 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
7570 (and (eq (preceding-char) ?\<)
7571 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
7572 (search-backward "<"))))
7573 ((and (eq (following-char) ?\$)
7574 (eq (preceding-char) ?\<)
7575 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
7577 (if (looking-at cperl-have-help-regexp)
7578 (buffer-substring (match-beginning 0) (match-end 0))))
7580 (defun cperl-get-help ()
7581 "Get one-line docs on the symbol at the point.
7582 The data for these docs is a little bit obsolete and may be in fact longer
7583 than a line. Your contribution to update/shorten it is appreciated."
7585 (save-match-data ; May be called "inside" query-replace
7587 (let ((word (cperl-word-at-point-hard)))
7589 (if (and cperl-help-from-timer ; Bail out if not in mainland
7590 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
7591 (or (memq (get-text-property (point) 'face)
7592 '(font-lock-comment-face font-lock-string-face))
7593 (memq (get-text-property (point) 'syntax-type)
7594 '(pod here-doc format))))
7596 (cperl-describe-perl-symbol word))
7597 (if cperl-message-on-help-error
7598 (message "Nothing found for %s..."
7599 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
7601 ;;; Stolen from perl-descr.el by Johan Vromans:
7603 (defvar cperl-doc-buffer " *perl-doc*"
7604 "Where the documentation can be found.")
7606 (defun cperl-describe-perl-symbol (val)
7607 "Display the documentation of symbol at point, a Perl operator."
7608 (let ((enable-recursive-minibuffers t)
7611 ((string-match "^[&*][a-zA-Z_]" val)
7612 (setq val (concat (substring val 0 1) "NAME")))
7613 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
7614 (setq val (concat "@" (substring val 1 (match-end 1)))))
7615 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
7616 (setq val (concat "%" (substring val 1 (match-end 1)))))
7617 ((and (string= val "x") (string-match "^x=" val))
7619 ((string-match "^\\$[\C-a-\C-z]" val)
7620 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
7621 ((string-match "^CORE::" val)
7622 (setq val "CORE::"))
7623 ((string-match "^SUPER::" val)
7624 (setq val "SUPER::"))
7625 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
7626 (setq val "<NAME>")))
7627 (setq regexp (concat "^"
7628 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
7630 "\\([ \t([/]\\|$\\)"))
7632 ;; get the buffer with the documentation text
7633 (cperl-switch-to-doc-buffer)
7635 ;; lookup in the doc
7636 (goto-char (point-min))
7637 (let ((case-fold-search nil))
7639 (if (re-search-forward regexp (point-max) t)
7641 (beginning-of-line 1)
7642 (let ((lnstart (point)))
7644 (message "%s" (buffer-substring lnstart (point)))))
7645 (if cperl-message-on-help-error
7646 (message "No definition for %s" val)))))))
7648 (defvar cperl-short-docs 'please-ignore-this-line
7649 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
7650 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
7651 ... Range (list context); flip/flop [no flop when flip] (scalar context).
7652 ! ... Logical negation.
7653 ... != ... Numeric inequality.
7654 ... !~ ... Search pattern, substitution, or translation (negated).
7655 $! In numeric context: errno. In a string context: error string.
7656 $\" The separator which joins elements of arrays interpolated in strings.
7657 $# The output format for printed numbers. Default is %.15g or close.
7658 $$ Process number of this script. Changes in the fork()ed child process.
7659 $% The current page number of the currently selected output channel.
7661 The following variables are always local to the current block:
7663 $1 Match of the 1st set of parentheses in the last match (auto-local).
7664 $2 Match of the 2nd set of parentheses in the last match (auto-local).
7665 $3 Match of the 3rd set of parentheses in the last match (auto-local).
7666 $4 Match of the 4th set of parentheses in the last match (auto-local).
7667 $5 Match of the 5th set of parentheses in the last match (auto-local).
7668 $6 Match of the 6th set of parentheses in the last match (auto-local).
7669 $7 Match of the 7th set of parentheses in the last match (auto-local).
7670 $8 Match of the 8th set of parentheses in the last match (auto-local).
7671 $9 Match of the 9th set of parentheses in the last match (auto-local).
7672 $& The string matched by the last pattern match (auto-local).
7673 $' The string after what was matched by the last match (auto-local).
7674 $` The string before what was matched by the last match (auto-local).
7676 $( The real gid of this process.
7677 $) The effective gid of this process.
7678 $* Deprecated: Set to 1 to do multiline matching within a string.
7679 $+ The last bracket matched by the last search pattern.
7680 $, The output field separator for the print operator.
7681 $- The number of lines left on the page.
7682 $. The current input line number of the last filehandle that was read.
7683 $/ The input record separator, newline by default.
7684 $0 Name of the file containing the current perl script (read/write).
7685 $: String may be broken after these characters to fill ^-lines in a format.
7686 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
7687 $< The real uid of this process.
7688 $= The page length of the current output channel. Default is 60 lines.
7689 $> The effective uid of this process.
7690 $? The status returned by the last ``, pipe close or `system'.
7691 $@ The perl error message from the last eval or do @var{EXPR} command.
7692 $ARGV The name of the current file used with <> .
7693 $[ Deprecated: The index of the first element/char in an array/string.
7694 $\\ The output record separator for the print operator.
7695 $] The perl version string as displayed with perl -v.
7696 $^ The name of the current top-of-page format.
7697 $^A The current value of the write() accumulator for format() lines.
7698 $^D The value of the perl debug (-D) flags.
7699 $^E Information about the last system error other than that provided by $!.
7700 $^F The highest system file descriptor, ordinarily 2.
7701 $^H The current set of syntax checks enabled by `use strict'.
7702 $^I The value of the in-place edit extension (perl -i option).
7703 $^L What formats output to perform a formfeed. Default is \\f.
7704 $^M A buffer for emergency memory allocation when running out of memory.
7705 $^O The operating system name under which this copy of Perl was built.
7706 $^P Internal debugging flag.
7707 $^T The time the script was started. Used by -A/-M/-C file tests.
7708 $^W True if warnings are requested (perl -w flag).
7709 $^X The name under which perl was invoked (argv[0] in C-speech).
7710 $_ The default input and pattern-searching space.
7711 $| Auto-flush after write/print on current output channel? Default 0.
7712 $~ The name of the current report format.
7713 ... % ... Modulo division.
7714 ... %= ... Modulo division assignment.
7715 %ENV Contains the current environment.
7716 %INC List of files that have been require-d or do-ne.
7717 %SIG Used to set signal handlers for various signals.
7718 ... & ... Bitwise and.
7719 ... && ... Logical and.
7720 ... &&= ... Logical and assignment.
7721 ... &= ... Bitwise and assignment.
7722 ... * ... Multiplication.
7723 ... ** ... Exponentiation.
7724 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
7725 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
7726 ... + ... Addition. +EXPR Makes EXPR into scalar context.
7727 ++ Auto-increment (magical on strings). ++EXPR EXPR++
7728 ... += ... Addition assignment.
7730 ... - ... Subtraction.
7731 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
7732 ... -= ... Subtraction assignment.
7733 -A Access time in days since script started.
7734 -B File is a non-text (binary) file.
7735 -C Inode change time in days since script started.
7736 -M Age in days since script started.
7737 -O File is owned by real uid.
7738 -R File is readable by real uid.
7739 -S File is a socket .
7740 -T File is a text file.
7741 -W File is writable by real uid.
7742 -X File is executable by real uid.
7743 -b File is a block special file.
7744 -c File is a character special file.
7745 -d File is a directory.
7747 -f File is a plain file.
7748 -g File has setgid bit set.
7749 -k File has sticky bit set.
7750 -l File is a symbolic link.
7751 -o File is owned by effective uid.
7752 -p File is a named pipe (FIFO).
7753 -r File is readable by effective uid.
7754 -s File has non-zero size.
7755 -t Tests if filehandle (STDIN by default) is opened to a tty.
7756 -u File has setuid bit set.
7757 -w File is writable by effective uid.
7758 -x File is executable by effective uid.
7759 -z File has zero size.
7760 . Concatenate strings.
7761 .. Range (list context); flip/flop (scalar context) operator.
7762 .= Concatenate assignment strings
7763 ... / ... Division. /PATTERN/ioxsmg Pattern match
7764 ... /= ... Division assignment.
7765 /PATTERN/ioxsmg Pattern match.
7766 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
7767 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
7768 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
7769 <> Reads line from union of files in @ARGV (= command line) and STDIN.
7770 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
7771 ... <= ... Numeric less than or equal to.
7772 ... <=> ... Numeric compare.
7773 ... = ... Assignment.
7774 ... == ... Numeric equality.
7775 ... =~ ... Search pattern, substitution, or translation
7776 ... > ... Numeric greater than.
7777 ... >= ... Numeric greater than or equal to.
7778 ... >> ... Bitwise shift right.
7779 ... >>= ... Bitwise shift right assignment.
7780 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
7781 ?PATTERN? One-time pattern match.
7782 @ARGV Command line arguments (not including the command name - see $0).
7783 @INC List of places to look for perl scripts during do/include/use.
7784 @_ Parameter array for subroutines; result of split() unless in list context.
7785 \\ Creates reference to what follows, like \\$var, or quotes non-\\w in strings.
7786 \\0 Octal char, e.g. \\033.
7787 \\E Case modification terminator. See \\Q, \\L, and \\U.
7788 \\L Lowercase until \\E . See also \\l, lc.
7789 \\U Upcase until \\E . See also \\u, uc.
7790 \\Q Quote metacharacters until \\E . See also quotemeta.
7791 \\a Alarm character (octal 007).
7792 \\b Backspace character (octal 010).
7793 \\c Control character, e.g. \\c[ .
7794 \\e Escape character (octal 033).
7795 \\f Formfeed character (octal 014).
7796 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
7797 \\n Newline character (octal 012 on most systems).
7798 \\r Return character (octal 015 on most systems).
7799 \\t Tab character (octal 011).
7800 \\u Upcase the next character. See also \\U and \\l, ucfirst.
7801 \\x Hex character, e.g. \\x1b.
7802 ... ^ ... Bitwise exclusive or.
7803 __END__ Ends program source.
7804 __DATA__ Ends program source.
7805 __FILE__ Current (source) filename.
7806 __LINE__ Current line in current source.
7807 __PACKAGE__ Current package.
7808 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
7809 ARGVOUT Output filehandle with -i flag.
7810 BEGIN { ... } Immediately executed (during compilation) piece of code.
7811 END { ... } Pseudo-subroutine executed after the script finishes.
7812 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
7813 INIT { ... } Pseudo-subroutine executed before the script starts running.
7814 DATA Input filehandle for what follows after __END__ or __DATA__.
7815 accept(NEWSOCKET,GENERICSOCKET)
7828 ... cmp ... String compare.
7829 connect(SOCKET,NAME)
7830 continue of { block } continue { block }. Is executed after `next' or at end.
7832 crypt(PLAINTEXT,SALT)
7834 dbmopen(%HASH,DBNAME,MODE)
7838 do { ... }|SUBR while|until EXPR executes at least once
7839 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
7849 ... eq ... String equality.
7850 eval(EXPR) or eval { BLOCK }
7851 exec([TRUENAME] ARGV0, ARGVs) or exec(SHELL_COMMAND_LINE)
7854 fcntl(FILEHANDLE,FUNCTION,SCALAR)
7856 flock(FILEHANDLE,OPERATION)
7857 for (EXPR;EXPR;EXPR) { ... }
7858 foreach [VAR] (@ARRAY) { ... }
7860 ... ge ... String greater than or equal.
7865 gethostbyaddr(ADDR,ADDRTYPE)
7869 getnetbyaddr(ADDR,ADDRTYPE)
7875 getpriority(WHICH,WHO)
7876 getprotobyname(NAME)
7877 getprotobynumber(NUMBER)
7882 getservbyname(NAME,PROTO)
7883 getservbyport(PORT,PROTO)
7886 getsockopt(SOCKET,LEVEL,OPTNAME)
7889 ... gt ... String greater than.
7891 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
7892 index(STR,SUBSTR[,OFFSET])
7894 ioctl(FILEHANDLE,FUNCTION,SCALAR)
7899 ... le ... String less than or equal.
7901 link(OLDFILE,NEWFILE)
7902 listen(SOCKET,QUEUESIZE)
7906 lstat(EXPR|FILEHANDLE|VAR)
7907 ... lt ... String less than.
7909 mkdir(FILENAME,MODE)
7912 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
7913 msgsnd(ID,MSG,FLAGS)
7914 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
7915 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
7916 ... ne ... String inequality.
7919 open(FILEHANDLE[,EXPR])
7920 opendir(DIRHANDLE,EXPR)
7921 ord(EXPR) ASCII value of the first char of the string.
7923 package NAME Introduces package context.
7924 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
7926 print [FILEHANDLE] [(LIST)]
7927 printf [FILEHANDLE] (FORMAT,LIST)
7929 q/STRING/ Synonym for 'STRING'
7930 qq/STRING/ Synonym for \"STRING\"
7931 qx/STRING/ Synonym for `STRING`
7933 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7936 recv(SOCKET,SCALAR,LEN,FLAGS)
7938 rename(OLDNAME,NEWNAME)
7939 require [FILENAME | PERL_VERSION]
7943 rewinddir(DIRHANDLE)
7944 rindex(STR,SUBSTR[,OFFSET])
7946 s/PATTERN/REPLACEMENT/gieoxsm
7948 seek(FILEHANDLE,POSITION,WHENCE)
7949 seekdir(DIRHANDLE,POS)
7950 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
7951 semctl(ID,SEMNUM,CMD,ARG)
7952 semget(KEY,NSEMS,SIZE,FLAGS)
7954 send(SOCKET,MSG,FLAGS[,TO])
7956 sethostent(STAYOPEN)
7959 setpriority(WHICH,WHO,PRIORITY)
7960 setprotoent(STAYOPEN)
7962 setservent(STAYOPEN)
7963 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
7966 shmget(KEY,SIZE,FLAGS)
7967 shmread(ID,VAR,POS,SIZE)
7968 shmwrite(ID,STRING,POS,SIZE)
7969 shutdown(SOCKET,HOW)
7972 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
7973 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
7974 sort [SUBROUTINE] (LIST)
7975 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
7976 split[(/PATTERN/[,EXPR[,LIMIT]])]
7977 sprintf(FORMAT,LIST)
7980 stat(EXPR|FILEHANDLE|VAR)
7982 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
7983 substr(EXPR,OFFSET[,LEN])
7984 symlink(OLDFILE,NEWFILE)
7986 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7987 system([TRUENAME] ARGV0 [,ARGV]) or system(SHELL_COMMAND_LINE)
7988 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7993 tr/SEARCHLIST/REPLACEMENTLIST/cds
7994 truncate(FILE|EXPR,LENGTH)
7997 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
7999 unpack(TEMPLATE,EXPR)
8001 until (EXPR) { ... } EXPR until EXPR
8004 vec(EXPR,OFFSET,BITS)
8007 wantarray Returns true if the sub/eval is called in list context.
8009 while (EXPR) { ... } EXPR while EXPR
8010 write[(EXPR|FILEHANDLE)]
8011 ... x ... Repeat string or array.
8012 x= ... Repetition assignment.
8013 y/SEARCHLIST/REPLACEMENTLIST/
8014 ... | ... Bitwise or.
8015 ... || ... Logical or.
8016 ~ ... Unary bitwise complement.
8017 #! OS interpreter indicator. If contains `perl', used for options, and -x.
8018 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
8019 CORE:: Prefix to access builtin function if imported sub obscures it.
8020 SUPER:: Prefix to lookup for a method in @ISA classes.
8021 DESTROY Shorthand for `sub DESTROY {...}'.
8022 ... EQ ... Obsolete synonym of `eq'.
8023 ... GE ... Obsolete synonym of `ge'.
8024 ... GT ... Obsolete synonym of `gt'.
8025 ... LE ... Obsolete synonym of `le'.
8026 ... LT ... Obsolete synonym of `lt'.
8027 ... NE ... Obsolete synonym of `ne'.
8028 abs [ EXPR ] absolute value
8029 ... and ... Low-precedence synonym for &&.
8030 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
8031 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
8032 chr Converts a number to char with the same ordinal.
8033 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
8034 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
8035 exists $HASH{KEY} True if the key exists.
8036 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
8037 formline PICTURE, LIST Backdoor into \"format\" processing.
8038 glob EXPR Synonym of <EXPR>.
8039 lc [ EXPR ] Returns lowercased EXPR.
8040 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
8041 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
8042 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
8043 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
8044 not ... Low-precedence synonym for ! - negation.
8045 ... or ... Low-precedence synonym for ||.
8046 pos STRING Set/Get end-position of the last match over this string, see \\G.
8047 quotemeta [ EXPR ] Quote regexp metacharacters.
8048 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
8049 readline FH Synonym of <FH>.
8050 readpipe CMD Synonym of `CMD`.
8051 ref [ EXPR ] Type of EXPR when dereferenced.
8052 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
8053 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
8054 tied Returns internal object for a tied data.
8055 uc [ EXPR ] Returns upcased EXPR.
8056 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
8057 untie VAR Unlink an object from a simple Perl variable.
8058 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
8059 ... xor ... Low-precedence synonym for exclusive or.
8060 prototype \\&SUB Returns prototype of the function given a reference.
8061 =head1 Top-level heading.
8062 =head2 Second-level heading.
8063 =head3 Third-level heading (is there such?).
8064 =over [ NUMBER ] Start list.
8065 =item [ TITLE ] Start new item in the list.
8067 =cut Switch from POD to Perl.
8068 =pod Switch from Perl to POD.
8071 (defun cperl-switch-to-doc-buffer (&optional interactive)
8072 "Go to the perl documentation buffer and insert the documentation."
8074 (let ((buf (get-buffer-create cperl-doc-buffer)))
8076 (switch-to-buffer-other-window buf)
8078 (if (= (buffer-size) 0)
8080 (insert (documentation-property 'cperl-short-docs
8081 'variable-documentation))
8082 (setq buffer-read-only t)))))
8084 (defun cperl-beautify-regexp-piece (b e embed level)
8085 ;; b is before the starting delimiter, e before the ending
8086 ;; e should be a marker, may be changed, but remains "correct".
8087 ;; EMBED is nil iff we process the whole REx.
8088 ;; The REx is guaranteed to have //x
8089 ;; LEVEL shows how many levels deep to go
8090 ;; position at enter and at leave is not defined
8091 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
8095 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
8099 ((looking-at "(\\?[^a-zA-Z]")
8101 ((looking-at "(\\?") ; (?i)
8105 (setq c (if embed (current-indentation) (1- (current-column)))
8106 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
8107 (or (looking-at "[ \t]*[\n#]")
8112 (if (re-search-forward "[^ \t]" e t)
8113 (progn ; Something before the ending delimiter
8115 (delete-horizontal-space)
8117 (cperl-make-indent c)
8118 (set-marker e (point))))
8121 (while (< (point) (marker-position e))
8125 (skip-chars-forward " \t")
8126 (delete-region s (point))
8127 (cperl-make-indent c1)
8131 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
8132 "\\|" ; Embedded variable
8133 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
8136 "\\|" ; simple-code simple-code*?
8137 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
8141 "\\((\\(\\?\\)?\\)" ; 7 8
8144 (goto-char (match-end 0))
8146 (cond ((match-beginning 1) ; Alphanum word + junk
8148 ((or (match-beginning 3) ; $ab[12]
8149 (and (match-beginning 5) ; X* X+ X{2,3}
8150 (eq (preceding-char) ?\{)))
8153 ((and ; [], already syntaxified
8156 cperl-use-syntax-table-text-property)
8159 (or (eq (preceding-char) ?\])
8160 (error "[]-group not terminated"))
8162 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8163 ((match-beginning 6) ; []
8165 (if (looking-at "\\^?\\]")
8166 (goto-char (match-end 0)))
8167 ;; XXXX POSIX classes?!
8168 (while (and (not pos)
8169 (re-search-forward "\\[:\\|\\]" e t))
8170 (if (eq (preceding-char) ?:)
8171 (or (re-search-forward ":\\]" e t)
8172 (error "[:POSIX:]-group in []-group not terminated"))
8174 (or (eq (preceding-char) ?\])
8175 (error "[]-group not terminated"))
8177 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8178 ((match-beginning 7) ; ()
8179 (goto-char (match-beginning 0))
8180 (setq pos (current-column))
8183 (delete-horizontal-space)
8185 (cperl-make-indent c1)))
8188 ;; (or (forward-sexp 1)
8191 ;; (error "()-group not terminated")))
8192 (set-marker m (1- (point)))
8193 (set-marker m1 (point))
8195 (if (progn ; indent rigidly if multiline
8196 ;; In fact does not make a lot of sense, since
8197 ;; the starting position can be already lost due
8198 ;; to insertion of "\n" and " "
8200 (search-forward "\n" m1 t))
8201 (indent-rigidly (point) m1 (- c1 pos)))
8202 (setq level (1- level))
8204 ((not (match-beginning 8))
8205 (cperl-beautify-regexp-piece tmp m t level))
8206 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
8208 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
8209 (goto-char (+ 2 tmp))
8211 (cperl-beautify-regexp-piece (point) m t level))
8212 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
8213 (goto-char (+ 3 tmp))
8214 (cperl-beautify-regexp-piece (point) m t level))
8216 (cperl-beautify-regexp-piece tmp m t level))))
8218 (cond ((looking-at "[*+?]\\??")
8219 (goto-char (match-end 0)))
8220 ((eq (following-char) ?\{)
8222 (if (eq (following-char) ?\?)
8224 (skip-chars-forward " \t")
8226 (if (looking-at "[#\n]")
8228 (or (eolp) (indent-for-comment))
8229 (beginning-of-line 2))
8230 (delete-horizontal-space)
8234 ((match-beginning 9) ; |
8238 (if (re-search-forward "[^ \t]" tmp t)
8241 (delete-horizontal-space)
8244 (delete-region (point) tmp))
8245 (cperl-make-indent c)
8247 (skip-chars-forward " \t")
8249 (if (looking-at "[#\n]")
8250 (beginning-of-line 2)
8251 (delete-horizontal-space)
8255 (or (looking-at "[ \t\n]")
8258 (skip-chars-forward " \t"))
8259 (or (looking-at "[#\n]")
8260 (error "Unknown code `%s' in a regexp"
8261 (buffer-substring (point) (1+ (point)))))
8262 (and inline (end-of-line 2)))
8263 ;; Special-case the last line of group
8264 (if (and (>= (point) (marker-position e))
8265 (/= (current-indentation) c))
8268 (cperl-make-indent c)))))
8270 (defun cperl-make-regexp-x ()
8271 ;; Returns position of the start
8272 ;; XXX this is called too often! Need to cache the result!
8274 (or cperl-use-syntax-table-text-property
8275 (error "I need to have a regexp marked!"))
8277 (if (looking-at "\\s|")
8279 (if (looking-at "\\([smy]\\|qr\\)\\s|")
8281 (re-search-backward "\\s|"))) ; Assume it is scanned already.
8283 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
8284 (sub-p (eq (preceding-char) ?s)) s)
8286 (set-marker e (1- (point)))
8287 (setq delim (preceding-char))
8288 (if (and sub-p (eq delim (char-after (- (point) 2))))
8289 (error "Possible s/blah// - do not know how to deal with"))
8290 (if sub-p (forward-sexp 1))
8291 (if (looking-at "\\sw*x")
8294 ;; Protect fragile " ", "#"
8297 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
8303 (defun cperl-beautify-regexp (&optional deep)
8304 "Do it. (Experimental, may change semantics, recheck the result.)
8305 We suppose that the regexp is scanned already."
8307 (setq deep (if deep (prefix-numeric-value deep) -1))
8309 (goto-char (cperl-make-regexp-x))
8310 (let ((b (point)) (e (make-marker)))
8312 (set-marker e (1- (point)))
8313 (cperl-beautify-regexp-piece b e nil deep))))
8315 (defun cperl-regext-to-level-start ()
8316 "Goto start of an enclosing group in regexp.
8317 We suppose that the regexp is scanned already."
8319 (let ((limit (cperl-make-regexp-x)) done)
8321 (or (eq (following-char) ?\()
8322 (search-backward "(" (1+ limit) t)
8323 (error "Cannot find `(' which starts a group"))
8326 (skip-chars-backward "\\")
8327 (looking-at "\\(\\\\\\\\\\)*(")))
8328 (or done (forward-char -1)))))
8330 (defun cperl-contract-level ()
8331 "Find an enclosing group in regexp and contract it.
8332 \(Experimental, may change semantics, recheck the result.)
8333 We suppose that the regexp is scanned already."
8335 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
8336 (cperl-regext-to-level-start)
8337 (let ((b (point)) (e (make-marker)) c)
8339 (set-marker e (1- (point)))
8341 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
8343 ((match-beginning 1) ; #-comment
8344 (or c (setq c (current-indentation)))
8345 (beginning-of-line 2) ; Skip
8346 (cperl-make-indent c))
8349 (just-one-space))))))
8351 (defun cperl-contract-levels ()
8352 "Find an enclosing group in regexp and contract all the kids.
8353 \(Experimental, may change semantics, recheck the result.)
8354 We suppose that the regexp is scanned already."
8358 (cperl-regext-to-level-start)
8359 (error ; We are outside outermost group
8360 (goto-char (cperl-make-regexp-x))))
8361 (let ((b (point)) (e (make-marker)) s c)
8363 (set-marker e (1- (point)))
8365 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
8367 ((match-beginning 1) ; Skip
8370 (cperl-contract-level)))))))
8372 (defun cperl-beautify-level (&optional deep)
8373 "Find an enclosing group in regexp and beautify it.
8374 \(Experimental, may change semantics, recheck the result.)
8375 We suppose that the regexp is scanned already."
8377 (setq deep (if deep (prefix-numeric-value deep) -1))
8379 (cperl-regext-to-level-start)
8380 (let ((b (point)) (e (make-marker)))
8382 (set-marker e (1- (point)))
8383 (cperl-beautify-regexp-piece b e nil deep))))
8385 (defun cperl-invert-if-unless-modifiers ()
8386 "Change `B if A;' into `if (A) {B}' etc if possible.
8389 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string
8390 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>"))
8391 (and (= (char-syntax (preceding-char)) ?w)
8393 (setq pre-if (point))
8394 (cperl-backward-to-start-of-expr)
8395 (setq pre-B (point))
8396 (forward-sexp 1) ; otherwise forward-to-end-of-expr is NOP
8397 (cperl-forward-to-end-of-expr)
8398 (setq post-A (point))
8400 (or (looking-at w-rex)
8401 ;; Find the position
8402 (progn (goto-char post-A)
8404 (not (looking-at w-rex))
8407 (setq pre-if (point))))
8408 (or (looking-at w-rex)
8409 (error "Can't find `if', `unless', `while', `until', `for' or `foreach'"))
8410 ;; 1 B 2 ... 3 B-com ... 4 if 5 ... if-com 6 ... 7 A 8
8411 (setq if-string (buffer-substring (match-beginning 0) (match-end 0)))
8412 ;; First, simple part: find code boundaries
8414 (setq post-if (point))
8417 (setq post-B (point))
8418 (cperl-backward-to-start-of-expr)
8419 (setq pre-B (point))
8420 (setq B (buffer-substring pre-B post-B))
8424 ;; May be after $, @, $# etc of a variable
8425 (skip-chars-backward "$@%#")
8426 (setq pre-A (point))
8427 (cperl-forward-to-end-of-expr)
8428 (setq post-A (point))
8429 (setq A (buffer-substring pre-A post-A))
8430 ;; Now modify (from end, to not break the stuff)
8431 (skip-chars-forward " \t;")
8432 (delete-region pre-A (point)) ; we move to pre-A
8433 (insert "\n" B ";\n}")
8434 (and (looking-at "[ \t]*#") (cperl-indent-for-comment))
8435 (delete-region pre-if post-if)
8436 (delete-region pre-B post-B)
8438 (insert if-string " (" A ") {")
8439 (setq post-B (point))
8440 (if (looking-at "[ \t]+$")
8441 (delete-horizontal-space)
8442 (if (looking-at "[ \t]*#")
8443 (cperl-indent-for-comment)
8446 (if (looking-at "[ \t]*$")
8447 (progn ; delete line
8448 (delete-horizontal-space)
8449 (delete-region (point) (1+ (point)))))
8451 (goto-char (1- post-B))
8456 (defun cperl-invert-if-unless ()
8457 "Change `if (A) {B}' into `B if A;' etc (or visa versa) if possible.
8458 If the cursor is not on the leading keyword of the BLOCK flavor of
8459 construct, will assume it is the STATEMENT flavor, so will try to find
8460 the appropriate statement modifier."
8462 (and (= (char-syntax (preceding-char)) ?w)
8464 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
8465 (let ((pre-if (point))
8466 pre-A post-A pre-B post-B A B state p end-B-code is-block B-comment
8467 (if-string (buffer-substring (match-beginning 0) (match-end 0))))
8469 (setq post-A (point))
8471 (setq pre-A (point))
8472 (setq is-block (and (eq (following-char) ?\( )
8478 (eq (following-char) ?\{ ))
8484 (setq post-B (point))
8486 (setq pre-B (point))
8487 (if (and (eq (following-char) ?\{ )
8489 (cperl-backward-to-noncomment post-A)
8490 (eq (preceding-char) ?\) )))
8491 (if (condition-case nil
8496 (looking-at "\\<els\\(e\\|if\\)\\>"))
8499 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" if-string)
8500 (goto-char (1- post-B))
8501 (cperl-backward-to-noncomment pre-B)
8502 (if (eq (preceding-char) ?\;)
8504 (setq end-B-code (point))
8506 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" end-B-code t)
8507 (setq p (match-beginning 0)
8508 A (buffer-substring p (match-end 0))
8509 state (parse-partial-sexp pre-B p))
8513 (error "`%s' inside `%s' BLOCK" A if-string))
8514 (goto-char (match-end 0)))
8516 (goto-char (1+ pre-B))
8517 (skip-chars-forward " \t\n")
8518 (setq B (buffer-substring (point) end-B-code))
8519 (goto-char end-B-code)
8520 (or (looking-at ";?[ \t\n]*}")
8522 (skip-chars-forward "; \t\n")
8524 (buffer-substring (point) (1- post-B)))))
8527 (goto-char (1- post-A))
8528 (cperl-backward-to-noncomment pre-A)
8529 (or (looking-at "[ \t\n]*)")
8530 (goto-char (1- post-A)))
8532 (goto-char (1+ pre-A))
8533 (skip-chars-forward " \t\n")
8534 (setq A (buffer-substring (point) p))
8535 (delete-region pre-B post-B)
8536 (delete-region pre-A post-A)
8539 (and B-comment (insert B-comment " "))
8542 (setq pre-A (point))
8544 (delete-horizontal-space)
8545 (setq post-B (point))
8546 (if (looking-at "#")
8547 (indent-for-comment))
8550 (delete-horizontal-space)
8554 (setq pre-A (set-marker (make-marker) pre-A))
8555 (while (<= (point) (marker-position pre-A))
8558 (goto-char (marker-position pre-A))
8562 (indent-for-comment)
8563 (goto-char (marker-position pre-A)))))
8564 (error "`%s' (EXPR) not with an {BLOCK}" if-string)))
8565 ;; (error "`%s' not with an (EXPR)" if-string)
8567 (cperl-invert-if-unless-modifiers)))
8568 ;;(error "Not at `if', `unless', `while', `until', `for' or `foreach'")
8569 (cperl-invert-if-unless-modifiers)))
8571 ;;; By Anthony Foiani <afoiani@uswest.com>
8572 ;;; Getting help on modules in C-h f ?
8573 ;;; This is a modified version of `man'.
8574 ;;; Need to teach it how to lookup functions
8576 (defun cperl-perldoc (word)
8577 "Run `perldoc' on WORD."
8579 (list (let* ((default-entry (cperl-word-at-point))
8581 (format "perldoc entry%s: "
8582 (if (string= default-entry "")
8584 (format " (default %s)" default-entry))))))
8585 (if (string= input "")
8586 (if (string= default-entry "")
8587 (error "No perldoc args given")
8591 (let* ((case-fold-search nil)
8593 (string-match "^[a-z]+$" word)
8594 (string-match (concat "^" word "\\>")
8595 (documentation-property
8597 'variable-documentation))))
8598 (manual-program (if is-func "perldoc -f" "perldoc")))
8601 (let ((Manual-program "perldoc")
8602 (Manual-switches (if is-func (list "-f"))))
8603 (manual-entry word)))
8605 (Man-getpage-in-background word)))))
8608 (defun cperl-perldoc-at-point ()
8609 "Run a `perldoc' on the word around point."
8611 (cperl-perldoc (cperl-word-at-point)))
8613 (defcustom pod2man-program "pod2man"
8614 "*File name for `pod2man'."
8618 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
8619 (defun cperl-pod-to-manpage ()
8620 "Create a virtual manpage in Emacs from the Perl Online Documentation."
8623 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
8624 (bufname (concat "Man " buffer-file-name))
8625 (buffer (generate-new-buffer bufname)))
8628 (let ((process-environment (copy-sequence process-environment)))
8629 ;; Prevent any attempt to use display terminal fanciness.
8630 (setenv "TERM" "dumb")
8631 (set-process-sentinel
8632 (start-process pod2man-program buffer "sh" "-c"
8633 (format (cperl-pod2man-build-command) pod2man-args))
8634 'Man-bgproc-sentinel)))))
8636 ;;; Updated version by him too
8637 (defun cperl-build-manpage ()
8638 "Create a virtual manpage in Emacs from the POD in the file."
8643 (let ((Manual-program "perldoc"))
8644 (manual-entry buffer-file-name)))
8646 (let* ((manual-program "perldoc"))
8647 (Man-getpage-in-background buffer-file-name)))))
8649 (defun cperl-pod2man-build-command ()
8650 "Builds the entire background manpage and cleaning command."
8651 (let ((command (concat pod2man-program " %s 2>/dev/null"))
8652 (flist (and (boundp 'Man-filter-list) Man-filter-list)))
8653 (while (and flist (car flist))
8654 (let ((pcom (car (car flist)))
8655 (pargs (cdr (car flist))))
8657 (concat command " | " pcom " "
8658 (mapconcat '(lambda (phrase)
8659 (if (not (stringp phrase))
8660 (error "Malformed Man-filter-list"))
8663 (setq flist (cdr flist))))
8667 (defun cperl-next-interpolated-REx-1 ()
8668 "Move point to next REx which has interpolated parts without //o.
8669 Skips RExes consisting of one interpolated variable.
8671 Note that skipped RExen are not performance hits."
8673 (cperl-next-interpolated-REx 1))
8675 (defun cperl-next-interpolated-REx-0 ()
8676 "Move point to next REx which has interpolated parts without //o."
8678 (cperl-next-interpolated-REx 0))
8680 (defun cperl-next-interpolated-REx (&optional skip beg limit)
8681 "Move point to next REx which has interpolated parts.
8682 SKIP is a list of possible types to skip, BEG and LIMIT are the starting
8683 point and the limit of search (default to point and end of buffer).
8685 SKIP may be a number, then it behaves as list of numbers up to SKIP; this
8686 semantic may be used as a numeric argument.
8688 Types are 0 for / $rex /o (interpolated once), 1 for /$rex/ (if $rex is
8689 a result of qr//, this is not a performance hit), t for the rest."
8691 (if (numberp skip) (setq skip (list 0 skip)))
8692 (or beg (setq beg (point)))
8693 (or limit (setq limit (point-max))) ; needed for n-s-p-c
8695 (and (eq (get-text-property beg 'syntax-type) 'string)
8696 (setq beg (next-single-property-change beg 'syntax-type nil limit)))
8697 (cperl-map-pods-heres
8698 (function (lambda (s e p)
8699 (if (memq (get-text-property s 'REx-interpolated) skip)
8703 'REx-interpolated beg limit)
8704 (if pp (goto-char pp)
8705 (message "No more interpolated REx"))))
8707 ;;; Initial version contributed by Trey Belew
8708 (defun cperl-here-doc-spell (&optional beg end)
8709 "Spell-check HERE-documents in the Perl buffer.
8710 If a region is highlighted, restricts to the region."
8712 (cperl-pod-spell t beg end))
8714 (defun cperl-pod-spell (&optional do-heres beg end)
8715 "Spell-check POD documentation.
8716 If invoked with prefix argument, will do HERE-DOCs instead.
8717 If a region is highlighted, restricts to the region."
8721 (if (cperl-mark-active)
8722 (setq beg (min (mark) (point))
8723 end (max (mark) (point)))
8724 (setq beg (point-min)
8726 (cperl-map-pods-heres (function
8729 (setq e (save-excursion
8735 (if do-heres 'here-doc-group 'in-pod)
8738 (defun cperl-map-pods-heres (func &optional prop s end)
8739 "Executes a function over regions of pods or here-documents.
8740 PROP is the text-property to search for; default to `in-pod'. Stop when
8741 function returns nil."
8742 (let (pos posend has-prop (cont t))
8743 (or prop (setq prop 'in-pod))
8744 (or s (setq s (point-min)))
8745 (or end (setq end (point-max)))
8746 (cperl-update-syntaxification end end)
8748 (goto-char (setq pos s))
8749 (while (and cont (< pos end))
8750 (setq has-prop (get-text-property pos prop))
8751 (setq posend (next-single-property-change pos prop nil end))
8753 (setq cont (funcall func pos posend prop)))
8754 (setq pos posend)))))
8756 ;;; Based on code by Masatake YAMATO:
8757 (defun cperl-get-here-doc-region (&optional pos pod)
8758 "Return HERE document region around the point.
8759 Return nil if the point is not in a HERE document region. If POD is non-nil,
8760 will return a POD section if point is in a POD section."
8761 (or pos (setq pos (point)))
8762 (cperl-update-syntaxification pos pos)
8763 (if (or (eq 'here-doc (get-text-property pos 'syntax-type))
8765 (eq 'pod (get-text-property pos 'syntax-type))))
8766 (let ((b (cperl-beginning-of-property pos 'syntax-type))
8767 (e (next-single-property-change pos 'syntax-type)))
8768 (cons b (or e (point-max))))))
8770 (defun cperl-narrow-to-here-doc (&optional pos)
8771 "Narrows editing region to the HERE-DOC at POS.
8772 POS defaults to the point."
8774 (or pos (setq pos (point)))
8775 (let ((p (cperl-get-here-doc-region pos)))
8776 (or p (error "Not inside a HERE document"))
8777 (narrow-to-region (car p) (cdr p))
8779 "When you are finished with narrow editing, type C-x n w")))
8781 (defun cperl-select-this-pod-or-here-doc (&optional pos)
8782 "Select the HERE-DOC (or POD section) at POS.
8783 POS defaults to the point."
8785 (let ((p (cperl-get-here-doc-region pos t)))
8789 (push-mark (cdr p) nil t)) ; Message, activate in transient-mode
8790 (message "I do not think POS is in POD or a HERE-doc..."))))
8792 (defun cperl-facemenu-add-face-function (face end)
8793 "A callback to process user-initiated font-change requests.
8794 Translates `bold', `italic', and `bold-italic' requests to insertion of
8795 corresponding POD directives, and `underline' to C<> POD directive.
8797 Such requests are usually bound to M-o LETTER."
8798 (or (get-text-property (point) 'in-pod)
8799 (error "Faces can only be set within POD"))
8800 (setq facemenu-end-add-face (if (eq face 'bold-italic) ">>" ">"))
8801 (cdr (or (assq face '((bold . "B<")
8803 (bold-italic . "B<I<")
8804 (underline . "C<")))
8805 (error "Face %s not configured for cperl-mode"
8808 (defun cperl-time-fontification (&optional l step lim)
8809 "Times how long it takes to do incremental fontification in a region.
8810 L is the line to start at, STEP is the number of lines to skip when
8811 doing next incremental fontification, LIM is the maximal number of
8812 incremental fontification to perform. Messages are accumulated in
8815 May be used for pinpointing which construct slows down buffer fontification:
8816 start with default arguments, then refine the slowdown regions."
8817 (interactive "nLine to start at: \nnStep to do incremental fontification: ")
8819 (or step (setq step 500))
8820 (or lim (setq lim 40))
8821 (let* ((timems (function (lambda ()
8822 (let ((tt (current-time)))
8823 (+ (* 1000 (nth 1 tt)) (/ (nth 2 tt) 1000))))))
8824 (tt (funcall timems)) (c 0) delta tot)
8827 (setq tot (- (- tt (setq tt (funcall timems)))))
8828 (message "cperl-mode at %s: %s" l tot)
8829 (while (and (< c lim) (not (eobp)))
8833 (cperl-update-syntaxification (point) (point))
8834 (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
8835 (message "to %s:%6s,%7s" l delta tot))
8838 (defun cperl-emulate-lazy-lock (&optional window-size)
8839 "Emulate `lazy-lock' without `condition-case', so `debug-on-error' works.
8840 Start fontifying the buffer from the start (or end) using the given
8841 WINDOW-SIZE (units is lines). Negative WINDOW-SIZE starts at end, and
8842 goes backwards; default is -50. This function is not CPerl-specific; it
8843 may be used to debug problems with delayed incremental fontification."
8845 "nSize of window for incremental fontification, negative goes backwards: ")
8846 (or window-size (setq window-size -50))
8847 (let ((pos (if (> window-size 0)
8853 ;; Why needed??? With older font-locks???
8854 (set (make-local-variable 'font-lock-cache-position) (make-marker))
8855 (while (if (> window-size 0)
8857 (> pos (point-min)))
8859 (forward-line window-size)
8861 (font-lock-fontify-region (min p pos) (max p pos))
8865 (defun cperl-lazy-install ()) ; Avoid a warning
8866 (defun cperl-lazy-unstall ()) ; Avoid a warning
8868 (if (fboundp 'run-with-idle-timer)
8870 (defvar cperl-help-shown nil
8871 "Non-nil means that the help was already shown now.")
8873 (defvar cperl-lazy-installed nil
8874 "Non-nil means that the lazy-help handlers are installed now.")
8876 (defun cperl-lazy-install ()
8877 "Switches on Auto-Help on Perl constructs (put in the message area).
8878 Delay of auto-help controlled by `cperl-lazy-help-time'."
8880 (make-local-variable 'cperl-help-shown)
8881 (if (and (cperl-val 'cperl-lazy-help-time)
8882 (not cperl-lazy-installed))
8884 (add-hook 'post-command-hook 'cperl-lazy-hook)
8885 (run-with-idle-timer
8886 (cperl-val 'cperl-lazy-help-time 1000000 5)
8888 'cperl-get-help-defer)
8889 (setq cperl-lazy-installed t))))
8891 (defun cperl-lazy-unstall ()
8892 "Switches off Auto-Help on Perl constructs (put in the message area).
8893 Delay of auto-help controlled by `cperl-lazy-help-time'."
8895 (remove-hook 'post-command-hook 'cperl-lazy-hook)
8896 (cancel-function-timers 'cperl-get-help-defer)
8897 (setq cperl-lazy-installed nil))
8899 (defun cperl-lazy-hook ()
8900 (setq cperl-help-shown nil))
8902 (defun cperl-get-help-defer ()
8903 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
8904 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
8906 (setq cperl-help-shown t))))
8907 (cperl-lazy-install)))
8910 ;;; Plug for wrong font-lock:
8912 (defun cperl-font-lock-unfontify-region-function (beg end)
8913 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
8914 (inhibit-read-only t) (inhibit-point-motion-hooks t)
8915 before-change-functions after-change-functions
8916 deactivate-mark buffer-file-name buffer-file-truename)
8917 (remove-text-properties beg end '(face nil))
8918 (if (and (not modified) (buffer-modified-p))
8919 (set-buffer-modified-p nil))))
8921 (defun cperl-font-lock-fontify-region-function (beg end loudly)
8922 "Extends the region to safe positions, then calls the default function.
8923 Newer `font-lock's can do it themselves.
8924 We unwind only as far as needed for fontification. Syntaxification may
8925 do extra unwind via `cperl-unwind-to-safe'."
8931 (eq (get-text-property (setq beg (point)) 'syntax-type)
8933 (if (setq beg (cperl-beginning-of-property beg 'syntax-type))
8939 (or (bolp) (condition-case nil
8942 (eq (get-text-property (setq end (point)) 'syntax-type)
8944 (setq end (next-single-property-change end 'syntax-type nil (point-max)))
8947 (font-lock-default-fontify-region beg end loudly))
8949 (defvar cperl-d-l nil)
8950 (defun cperl-fontify-syntaxically (end)
8951 ;; Some vars for debugging only
8952 ;; (message "Syntaxifying...")
8953 (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
8954 (istate (car cperl-syntax-state))
8955 start from-start edebug-backtrace-buffer)
8956 (if (eq cperl-syntaxify-by-font-lock 'backtrace)
8959 (let ((f 'edebug-backtrace))
8960 (funcall f)))) ; Avoid compile-time warning
8961 (or cperl-syntax-done-to
8962 (setq cperl-syntax-done-to (point-min)
8964 (setq start (if (and cperl-hook-after-change
8966 cperl-syntax-done-to ; Fontify without change; ignore start
8967 ;; Need to forget what is after `start'
8968 (min cperl-syntax-done-to (point))))
8971 (setq start (point))
8972 (and cperl-syntaxify-unwind
8973 (setq end (cperl-unwind-to-safe t end)
8976 (setq cperl-syntax-done-to start) ; In case what follows fails
8977 (cperl-find-pods-heres start end t nil t))
8978 (if (memq cperl-syntaxify-by-font-lock '(backtrace message))
8979 (message "Syxify req=%s..%s actual=%s..%s done-to: %s=>%s statepos: %s=>%s"
8980 dbg iend start end idone cperl-syntax-done-to
8981 istate (car cperl-syntax-state))) ; For debugging
8982 nil)) ; Do not iterate
8984 (defun cperl-fontify-update (end)
8985 (let ((pos (point-min)) prop posend)
8986 (setq end (point-max))
8988 (setq prop (get-text-property pos 'cperl-postpone)
8989 posend (next-single-property-change pos 'cperl-postpone nil end))
8990 (and prop (put-text-property pos posend (car prop) (cdr prop)))
8992 nil) ; Do not iterate
8994 (defun cperl-fontify-update-bad (end)
8995 ;; Since fontification happens with different region than syntaxification,
8996 ;; do to the end of buffer, not to END;;; likewise, start earlier if needed
8997 (let* ((pos (point)) (prop (get-text-property pos 'cperl-postpone)) posend)
8999 (setq pos (or (cperl-beginning-of-property
9000 (cperl-1+ pos) 'cperl-postpone)
9003 (setq posend (next-single-property-change pos 'cperl-postpone))
9004 (and prop (put-text-property pos posend (car prop) (cdr prop)))
9006 (setq prop (get-text-property pos 'cperl-postpone))))
9007 nil) ; Do not iterate
9009 ;; Called when any modification is made to buffer text.
9010 (defun cperl-after-change-function (beg end old-len)
9011 ;; We should have been informed about changes by `font-lock'. Since it
9012 ;; does not inform as which calls are defered, do it ourselves
9013 (if cperl-syntax-done-to
9014 (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
9016 (defun cperl-update-syntaxification (from to)
9017 (if (and cperl-use-syntax-table-text-property
9018 cperl-syntaxify-by-font-lock
9019 (or (null cperl-syntax-done-to)
9020 (< cperl-syntax-done-to to)))
9024 (cperl-fontify-syntaxically to)))))
9026 (defvar cperl-version
9027 (let ((v "Revision: 5.22"))
9028 (string-match ":\\s *\\([0-9.]+\\)" v)
9029 (substring v (match-beginning 1) (match-end 1)))
9030 "Version of IZ-supported CPerl package this file is based on.")
9032 (provide 'cperl-mode)
9034 ;;; arch-tag: 42e5b19b-e187-4537-929f-1a7408980ce6
9035 ;;; cperl-mode.el ends here