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