Fix bug #18545 with lack of scrolling a window when point goes out of view.
[emacs.git] / lisp / progmodes / cperl-mode.el
blobc4f2b9ffe517a30845fe10d96f1dc51452b4b76c
1 ;;; cperl-mode.el --- Perl code editing commands for Emacs
3 ;; Copyright (C) 1985-1987, 1991-2014 Free Software Foundation, Inc.
5 ;; Author: Ilya Zakharevich
6 ;; Bob Olson
7 ;; Maintainer: Ilya Zakharevich <ilyaz@cpan.org>
8 ;; Keywords: languages, Perl
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Corrections made by Ilya Zakharevich ilyaz@cpan.org
27 ;;; Commentary:
29 ;; You can either fine-tune the bells and whistles of this mode or
30 ;; bulk enable them by putting
32 ;; (setq cperl-hairy t)
34 ;; in your .emacs file. (Emacs rulers do not consider it politically
35 ;; correct to make whistles enabled by default.)
37 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
38 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
39 ;; `cperl-praise', `cperl-speed'. <<<<<<
41 ;; The mode information (on C-h m) provides some customization help.
42 ;; If you use font-lock feature of this mode, it is advisable to use
43 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
45 ;; Faces used now: three faces for first-class and second-class keywords
46 ;; and control flow words, one for each: comments, string, labels,
47 ;; functions definitions and packages, arrays, hashes, and variable
48 ;; definitions. If you do not see all these faces, your font-lock does
49 ;; not define them, so you need to define them manually.
51 ;; This mode supports font-lock, imenu and mode-compile. In the
52 ;; hairy version font-lock is on, but you should activate imenu
53 ;; yourself (note that mode-compile is not standard yet). Well, you
54 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
55 ;; to bind it like that:
57 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
59 ;;; Font lock bugs as of v4.32:
61 ;; The following kinds of Perl code erroneously start strings:
62 ;; \$` \$' \$"
63 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
64 ;; likewise with m, tr, y, q, qX instead of s
66 ;;; Code:
68 (defvar vc-rcs-header)
69 (defvar vc-sccs-header)
71 (eval-when-compile
72 (condition-case nil
73 (require 'custom)
74 (error nil))
75 (condition-case nil
76 (require 'man)
77 (error nil))
78 (defvar cperl-can-font-lock
79 (or (featurep 'xemacs)
80 (and (boundp 'emacs-major-version)
81 (or window-system
82 (> emacs-major-version 20)))))
83 (if cperl-can-font-lock
84 (require 'font-lock))
85 (defvar msb-menu-cond)
86 (defvar gud-perldb-history)
87 (defvar font-lock-background-mode) ; not in Emacs
88 (defvar font-lock-display-type) ; ditto
89 (defvar paren-backwards-message) ; Not in newer XEmacs?
90 (or (fboundp 'defgroup)
91 (defmacro defgroup (name val doc &rest arr)
92 nil))
93 (or (fboundp 'custom-declare-variable)
94 (defmacro defcustom (name val doc &rest arr)
95 `(defvar ,name ,val ,doc)))
96 (or (and (fboundp 'custom-declare-variable)
97 (string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
98 (defmacro defface (&rest arr)
99 nil))
100 ;; Avoid warning (tmp definitions)
101 (or (fboundp 'x-color-defined-p)
102 (defmacro x-color-defined-p (col)
103 (cond ((fboundp 'color-defined-p) `(color-defined-p ,col))
104 ;; XEmacs >= 19.12
105 ((fboundp 'valid-color-name-p) `(valid-color-name-p ,col))
106 ;; XEmacs 19.11
107 ((fboundp 'x-valid-color-name-p) `(x-valid-color-name-p ,col))
108 (t '(error "Cannot implement color-defined-p")))))
109 (defmacro cperl-is-face (arg) ; Takes quoted arg
110 (cond ((fboundp 'find-face)
111 `(find-face ,arg))
112 (;;(and (fboundp 'face-list)
113 ;; (face-list))
114 (fboundp 'face-list)
115 `(member ,arg (and (fboundp 'face-list)
116 (face-list))))
118 `(boundp ,arg))))
119 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
120 (cond ((fboundp 'make-face)
121 `(make-face (quote ,arg)))
123 `(defvar ,arg (quote ,arg) ,descr))))
124 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
125 `(progn
126 (or (cperl-is-face (quote ,arg))
127 (cperl-make-face ,arg ,descr))
128 (or (boundp (quote ,arg)) ; We use unquoted variants too
129 (defvar ,arg (quote ,arg) ,descr))))
130 (if (featurep 'xemacs)
131 (defmacro cperl-etags-snarf-tag (file line)
132 `(progn
133 (beginning-of-line 2)
134 (list ,file ,line)))
135 (defmacro cperl-etags-snarf-tag (file line)
136 `(etags-snarf-tag)))
137 (if (featurep 'xemacs)
138 (defmacro cperl-etags-goto-tag-location (elt)
139 ;;(progn
140 ;; (switch-to-buffer (get-file-buffer (elt ,elt 0)))
141 ;; (set-buffer (get-file-buffer (elt ,elt 0)))
142 ;; Probably will not work due to some save-excursion???
143 ;; Or save-file-position?
144 ;; (message "Did I get to line %s?" (elt ,elt 1))
145 `(goto-line (string-to-int (elt ,elt 1))))
147 (defmacro cperl-etags-goto-tag-location (elt)
148 `(etags-goto-tag-location ,elt))))
150 (defvar cperl-can-font-lock
151 (or (featurep 'xemacs)
152 (and (boundp 'emacs-major-version)
153 (or window-system
154 (> emacs-major-version 20)))))
156 (defun cperl-choose-color (&rest list)
157 (let (answer)
158 (while list
159 (or answer
160 (if (or (x-color-defined-p (car list))
161 (null (cdr list)))
162 (setq answer (car list))))
163 (setq list (cdr list)))
164 answer))
166 (defgroup cperl nil
167 "Major mode for editing Perl code."
168 :prefix "cperl-"
169 :group 'languages
170 :version "20.3")
172 (defgroup cperl-indentation-details nil
173 "Indentation."
174 :prefix "cperl-"
175 :group 'cperl)
177 (defgroup cperl-affected-by-hairy nil
178 "Variables affected by `cperl-hairy'."
179 :prefix "cperl-"
180 :group 'cperl)
182 (defgroup cperl-autoinsert-details nil
183 "Auto-insert tuneup."
184 :prefix "cperl-"
185 :group 'cperl)
187 (defgroup cperl-faces nil
188 "Fontification colors."
189 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
190 :prefix "cperl-"
191 :group 'cperl)
193 (defgroup cperl-speed nil
194 "Speed vs. validity tuneup."
195 :prefix "cperl-"
196 :group 'cperl)
198 (defgroup cperl-help-system nil
199 "Help system tuneup."
200 :prefix "cperl-"
201 :group 'cperl)
204 (defcustom cperl-extra-newline-before-brace nil
205 "*Non-nil means that if, elsif, while, until, else, for, foreach
206 and do constructs look like:
208 if ()
212 instead of:
214 if () {
216 :type 'boolean
217 :group 'cperl-autoinsert-details)
219 (defcustom cperl-extra-newline-before-brace-multiline
220 cperl-extra-newline-before-brace
221 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
222 for constructs with multiline if/unless/while/until/for/foreach condition."
223 :type 'boolean
224 :group 'cperl-autoinsert-details)
226 (defcustom cperl-indent-level 2
227 "*Indentation of CPerl statements with respect to containing block."
228 :type 'integer
229 :group 'cperl-indentation-details)
231 ;; Is is not unusual to put both things like perl-indent-level and
232 ;; cperl-indent-level in the local variable section of a file. If only
233 ;; one of perl-mode and cperl-mode is in use, a warning will be issued
234 ;; about the variable. Autoload these here, so that no warning is
235 ;; issued when using either perl-mode or cperl-mode.
236 ;;;###autoload(put 'cperl-indent-level 'safe-local-variable 'integerp)
237 ;;;###autoload(put 'cperl-brace-offset 'safe-local-variable 'integerp)
238 ;;;###autoload(put 'cperl-continued-brace-offset 'safe-local-variable 'integerp)
239 ;;;###autoload(put 'cperl-label-offset 'safe-local-variable 'integerp)
240 ;;;###autoload(put 'cperl-continued-statement-offset 'safe-local-variable 'integerp)
241 ;;;###autoload(put 'cperl-extra-newline-before-brace 'safe-local-variable 'booleanp)
242 ;;;###autoload(put 'cperl-merge-trailing-else 'safe-local-variable 'booleanp)
244 (defcustom cperl-lineup-step nil
245 "*`cperl-lineup' will always lineup at multiple of this number.
246 If nil, the value of `cperl-indent-level' will be used."
247 :type '(choice (const nil) integer)
248 :group 'cperl-indentation-details)
250 (defcustom cperl-brace-imaginary-offset 0
251 "*Imagined indentation of a Perl open brace that actually follows a statement.
252 An open brace following other text is treated as if it were this far
253 to the right of the start of its line."
254 :type 'integer
255 :group 'cperl-indentation-details)
257 (defcustom cperl-brace-offset 0
258 "*Extra indentation for braces, compared with other text in same context."
259 :type 'integer
260 :group 'cperl-indentation-details)
261 (defcustom cperl-label-offset -2
262 "*Offset of CPerl label lines relative to usual indentation."
263 :type 'integer
264 :group 'cperl-indentation-details)
265 (defcustom cperl-min-label-indent 1
266 "*Minimal offset of CPerl label lines."
267 :type 'integer
268 :group 'cperl-indentation-details)
269 (defcustom cperl-continued-statement-offset 2
270 "*Extra indent for lines not starting new statements."
271 :type 'integer
272 :group 'cperl-indentation-details)
273 (defcustom cperl-continued-brace-offset 0
274 "*Extra indent for substatements that start with open-braces.
275 This is in addition to cperl-continued-statement-offset."
276 :type 'integer
277 :group 'cperl-indentation-details)
278 (defcustom cperl-close-paren-offset -1
279 "*Extra indent for substatements that start with close-parenthesis."
280 :type 'integer
281 :group 'cperl-indentation-details)
283 (defcustom cperl-indent-wrt-brace t
284 "*Non-nil means indent statements in if/etc block relative brace, not if/etc.
285 Versions 5.2 ... 5.20 behaved as if this were `nil'."
286 :type 'boolean
287 :group 'cperl-indentation-details)
289 (defcustom cperl-auto-newline nil
290 "*Non-nil means automatically newline before and after braces,
291 and after colons and semicolons, inserted in CPerl code. The following
292 \\[cperl-electric-backspace] will remove the inserted whitespace.
293 Insertion after colons requires both this variable and
294 `cperl-auto-newline-after-colon' set."
295 :type 'boolean
296 :group 'cperl-autoinsert-details)
298 (defcustom cperl-autoindent-on-semi nil
299 "*Non-nil means automatically indent after insertion of (semi)colon.
300 Active if `cperl-auto-newline' is false."
301 :type 'boolean
302 :group 'cperl-autoinsert-details)
304 (defcustom cperl-auto-newline-after-colon nil
305 "*Non-nil means automatically newline even after colons.
306 Subject to `cperl-auto-newline' setting."
307 :type 'boolean
308 :group 'cperl-autoinsert-details)
310 (defcustom cperl-tab-always-indent t
311 "*Non-nil means TAB in CPerl mode should always reindent the current line,
312 regardless of where in the line point is when the TAB command is used."
313 :type 'boolean
314 :group 'cperl-indentation-details)
316 (defcustom cperl-font-lock nil
317 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
318 Can be overwritten by `cperl-hairy' if nil."
319 :type '(choice (const null) boolean)
320 :group 'cperl-affected-by-hairy)
322 (defcustom cperl-electric-lbrace-space nil
323 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
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-parens-string "({[]})<"
329 "*String of parentheses that should be electric in CPerl.
330 Closing ones are electric only if the region is highlighted."
331 :type 'string
332 :group 'cperl-affected-by-hairy)
334 (defcustom cperl-electric-parens nil
335 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
336 Can be overwritten by `cperl-hairy' if nil."
337 :type '(choice (const null) boolean)
338 :group 'cperl-affected-by-hairy)
340 (defvar zmacs-regions) ; Avoid warning
342 (defcustom cperl-electric-parens-mark
343 (and window-system
344 (or (and (boundp 'transient-mark-mode) ; For Emacs
345 transient-mark-mode)
346 (and (boundp 'zmacs-regions) ; For XEmacs
347 zmacs-regions)))
348 "*Not-nil means that electric parens look for active mark.
349 Default is yes if there is visual feedback on mark."
350 :type 'boolean
351 :group 'cperl-autoinsert-details)
353 (defcustom cperl-electric-linefeed nil
354 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
355 In any case these two mean plain and hairy linefeeds together.
356 Can be overwritten by `cperl-hairy' if nil."
357 :type '(choice (const null) boolean)
358 :group 'cperl-affected-by-hairy)
360 (defcustom cperl-electric-keywords nil
361 "*Not-nil (and non-null) means keywords are electric in CPerl.
362 Can be overwritten by `cperl-hairy' if nil.
364 Uses `abbrev-mode' to do the expansion. If you want to use your
365 own abbrevs in cperl-mode, but do not want keywords to be
366 electric, you must redefine `cperl-mode-abbrev-table': do
367 \\[edit-abbrevs], search for `cperl-mode-abbrev-table', and, in
368 that paragraph, delete the words that appear at the ends of lines and
369 that begin with \"cperl-electric\".
371 :type '(choice (const null) boolean)
372 :group 'cperl-affected-by-hairy)
374 (defcustom cperl-electric-backspace-untabify t
375 "*Not-nil means electric-backspace will untabify in CPerl."
376 :type 'boolean
377 :group 'cperl-autoinsert-details)
379 (defcustom cperl-hairy nil
380 "*Not-nil means most of the bells and whistles are enabled in CPerl.
381 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
382 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
383 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
384 `cperl-lazy-help-time'."
385 :type 'boolean
386 :group 'cperl-affected-by-hairy)
388 (defcustom cperl-comment-column 32
389 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
390 :type 'integer
391 :group 'cperl-indentation-details)
393 (defcustom cperl-indent-comment-at-column-0 nil
394 "*Non-nil means that comment started at column 0 should be indentable."
395 :type 'boolean
396 :group 'cperl-indentation-details)
398 (defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
399 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
400 :type '(repeat string)
401 :group 'cperl)
403 (defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
404 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
405 :type '(repeat string)
406 :group 'cperl)
408 ;; This became obsolete...
409 (defvar cperl-vc-header-alist nil)
410 (make-obsolete-variable
411 'cperl-vc-header-alist
412 "use cperl-vc-rcs-header or cperl-vc-sccs-header instead."
413 "22.1")
415 ;; (defcustom cperl-clobber-mode-lists
416 ;; (not
417 ;; (and
418 ;; (boundp 'interpreter-mode-alist)
419 ;; (assoc "miniperl" interpreter-mode-alist)
420 ;; (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
421 ;; "*Whether to install us into `interpreter-' and `extension' mode lists."
422 ;; :type 'boolean
423 ;; :group 'cperl)
425 (defcustom cperl-info-on-command-no-prompt nil
426 "*Not-nil (and non-null) means not to prompt on C-h f.
427 The opposite behavior is always available if prefixed with C-c.
428 Can be overwritten by `cperl-hairy' if nil."
429 :type '(choice (const null) boolean)
430 :group 'cperl-affected-by-hairy)
432 (defcustom cperl-clobber-lisp-bindings nil
433 "*Not-nil (and non-null) means not overwrite C-h f.
434 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
435 Can be overwritten by `cperl-hairy' if nil."
436 :type '(choice (const null) boolean)
437 :group 'cperl-affected-by-hairy)
439 (defcustom cperl-lazy-help-time nil
440 "*Not-nil (and non-null) means to show lazy help after given idle time.
441 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
442 :type '(choice (const null) (const nil) integer)
443 :group 'cperl-affected-by-hairy)
445 (defcustom cperl-pod-face 'font-lock-comment-face
446 "*Face for POD highlighting."
447 :type 'face
448 :group 'cperl-faces)
450 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
451 "*Face for POD highlighting.
452 Font for POD headers."
453 :type 'face
454 :group 'cperl-faces)
456 (defcustom cperl-here-face 'font-lock-string-face
457 "*Face for here-docs highlighting."
458 :type 'face
459 :group 'cperl-faces)
461 ;;; Some double-evaluation happened with font-locks... Needed with 21.2...
462 (defvar cperl-singly-quote-face (featurep 'xemacs))
464 (defcustom cperl-invalid-face 'underline
465 "*Face for highlighting trailing whitespace."
466 :type 'face
467 :version "21.1"
468 :group 'cperl-faces)
470 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
471 "*Not-nil after evaluation means to highlight POD and here-docs sections."
472 :type 'boolean
473 :group 'cperl-faces)
475 (defcustom cperl-fontify-m-as-s t
476 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
477 :type 'boolean
478 :group 'cperl-faces)
480 (defcustom cperl-highlight-variables-indiscriminately nil
481 "*Non-nil means perform additional highlighting on variables.
482 Currently only changes how scalar variables are highlighted.
483 Note that that variable is only read at initialization time for
484 the variable `cperl-font-lock-keywords-2', so changing it after you've
485 entered CPerl mode the first time will have no effect."
486 :type 'boolean
487 :group 'cperl)
489 (defcustom cperl-pod-here-scan t
490 "*Not-nil means look for POD and here-docs sections during startup.
491 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
492 :type 'boolean
493 :group 'cperl-speed)
495 (defcustom cperl-regexp-scan t
496 "*Not-nil means make marking of regular expression more thorough.
497 Effective only with `cperl-pod-here-scan'."
498 :type 'boolean
499 :group 'cperl-speed)
501 (defcustom cperl-hook-after-change t
502 "*Not-nil means install hook to know which regions of buffer are changed.
503 May significantly speed up delayed fontification. Changes take effect
504 after reload."
505 :type 'boolean
506 :group 'cperl-speed)
508 (defcustom cperl-imenu-addback nil
509 "*Not-nil means add backreferences to generated `imenu's.
510 May require patched `imenu' and `imenu-go'. Obsolete."
511 :type 'boolean
512 :group 'cperl-help-system)
514 (defcustom cperl-max-help-size 66
515 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
516 :type '(choice integer (const nil))
517 :group 'cperl-help-system)
519 (defcustom cperl-shrink-wrap-info-frame t
520 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
521 :type 'boolean
522 :group 'cperl-help-system)
524 (defcustom cperl-info-page "perl"
525 "*Name of the info page containing perl docs.
526 Older version of this page was called `perl5', newer `perl'."
527 :type 'string
528 :group 'cperl-help-system)
530 (defcustom cperl-use-syntax-table-text-property
531 (boundp 'parse-sexp-lookup-properties)
532 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
533 :type 'boolean
534 :group 'cperl-speed)
536 (defcustom cperl-use-syntax-table-text-property-for-tags
537 cperl-use-syntax-table-text-property
538 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
539 :type 'boolean
540 :group 'cperl-speed)
542 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
543 "*Regexp to match files to scan when generating TAGS."
544 :type 'regexp
545 :group 'cperl)
547 (defcustom cperl-noscan-files-regexp
548 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
549 "*Regexp to match files/dirs to skip when generating TAGS."
550 :type 'regexp
551 :group 'cperl)
553 (defcustom cperl-regexp-indent-step nil
554 "*Indentation used when beautifying regexps.
555 If nil, the value of `cperl-indent-level' will be used."
556 :type '(choice integer (const nil))
557 :group 'cperl-indentation-details)
559 (defcustom cperl-indent-left-aligned-comments t
560 "*Non-nil means that the comment starting in leftmost column should indent."
561 :type 'boolean
562 :group 'cperl-indentation-details)
564 (defcustom cperl-under-as-char nil
565 "*Non-nil means that the _ (underline) should be treated as word char."
566 :type 'boolean
567 :group 'cperl)
568 (make-obsolete-variable 'cperl-under-as-char 'superword-mode "24.4")
570 (defcustom cperl-extra-perl-args ""
571 "*Extra arguments to use when starting Perl.
572 Currently used with `cperl-check-syntax' only."
573 :type 'string
574 :group 'cperl)
576 (defcustom cperl-message-electric-keyword t
577 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
578 :type 'boolean
579 :group 'cperl-help-system)
581 (defcustom cperl-indent-region-fix-constructs 1
582 "*Amount of space to insert between `}' and `else' or `elsif'
583 in `cperl-indent-region'. Set to nil to leave as is. Values other
584 than 1 and nil will probably not work."
585 :type '(choice (const nil) (const 1))
586 :group 'cperl-indentation-details)
588 (defcustom cperl-break-one-line-blocks-when-indent t
589 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
590 need to be reformatted into multiline ones when indenting a region."
591 :type 'boolean
592 :group 'cperl-indentation-details)
594 (defcustom cperl-fix-hanging-brace-when-indent t
595 "*Non-nil means that BLOCK-end `}' may be put on a separate line
596 when indenting a region.
597 Braces followed by else/elsif/while/until are excepted."
598 :type 'boolean
599 :group 'cperl-indentation-details)
601 (defcustom cperl-merge-trailing-else t
602 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
603 may be merged to be on the same line when indenting a region."
604 :type 'boolean
605 :group 'cperl-indentation-details)
607 (defcustom cperl-indent-parens-as-block nil
608 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
609 but for trailing \",\" inside the group, which won't increase indentation.
610 One should tune up `cperl-close-paren-offset' as well."
611 :type 'boolean
612 :group 'cperl-indentation-details)
614 (defcustom cperl-syntaxify-by-font-lock
615 (and cperl-can-font-lock
616 (boundp 'parse-sexp-lookup-properties))
617 "*Non-nil means that CPerl uses the `font-lock' routines for syntaxification."
618 :type '(choice (const message) boolean)
619 :group 'cperl-speed)
621 (defcustom cperl-syntaxify-unwind
623 "*Non-nil means that CPerl unwinds to a start of a long construction
624 when syntaxifying a chunk of buffer."
625 :type 'boolean
626 :group 'cperl-speed)
628 (defcustom cperl-syntaxify-for-menu
630 "*Non-nil means that CPerl syntaxifies up to the point before showing menu.
631 This way enabling/disabling of menu items is more correct."
632 :type 'boolean
633 :group 'cperl-speed)
635 (defcustom cperl-ps-print-face-properties
636 '((font-lock-keyword-face nil nil bold shadow)
637 (font-lock-variable-name-face nil nil bold)
638 (font-lock-function-name-face nil nil bold italic box)
639 (font-lock-constant-face nil "LightGray" bold)
640 (cperl-array-face nil "LightGray" bold underline)
641 (cperl-hash-face nil "LightGray" bold italic underline)
642 (font-lock-comment-face nil "LightGray" italic)
643 (font-lock-string-face nil nil italic underline)
644 (cperl-nonoverridable-face nil nil italic underline)
645 (font-lock-type-face nil nil underline)
646 (font-lock-warning-face nil "LightGray" bold italic box)
647 (underline nil "LightGray" strikeout))
648 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
649 :type '(repeat (cons symbol
650 (cons (choice (const nil) string)
651 (cons (choice (const nil) string)
652 (repeat symbol)))))
653 :group 'cperl-faces)
655 (defvar cperl-dark-background
656 (cperl-choose-color "navy" "os2blue" "darkgreen"))
657 (defvar cperl-dark-foreground
658 (cperl-choose-color "orchid1" "orange"))
660 (defface cperl-nonoverridable-face
661 `((((class grayscale) (background light))
662 (:background "Gray90" :slant italic :underline t))
663 (((class grayscale) (background dark))
664 (:foreground "Gray80" :slant italic :underline t :weight bold))
665 (((class color) (background light))
666 (:foreground "chartreuse3"))
667 (((class color) (background dark))
668 (:foreground ,cperl-dark-foreground))
669 (t (:weight bold :underline t)))
670 "Font Lock mode face used non-overridable keywords and modifiers of regexps."
671 :group 'cperl-faces)
673 (defface cperl-array-face
674 `((((class grayscale) (background light))
675 (:background "Gray90" :weight bold))
676 (((class grayscale) (background dark))
677 (:foreground "Gray80" :weight bold))
678 (((class color) (background light))
679 (:foreground "Blue" :background "lightyellow2" :weight bold))
680 (((class color) (background dark))
681 (:foreground "yellow" :background ,cperl-dark-background :weight bold))
682 (t (:weight bold)))
683 "Font Lock mode face used to highlight array names."
684 :group 'cperl-faces)
686 (defface cperl-hash-face
687 `((((class grayscale) (background light))
688 (:background "Gray90" :weight bold :slant italic))
689 (((class grayscale) (background dark))
690 (:foreground "Gray80" :weight bold :slant italic))
691 (((class color) (background light))
692 (:foreground "Red" :background "lightyellow2" :weight bold :slant italic))
693 (((class color) (background dark))
694 (:foreground "Red" :background ,cperl-dark-background :weight bold :slant italic))
695 (t (:weight bold :slant italic)))
696 "Font Lock mode face used to highlight hash names."
697 :group 'cperl-faces)
701 ;;; Short extra-docs.
703 (defvar cperl-tips 'please-ignore-this-line
704 "Get maybe newer version of this package from
705 http://ilyaz.org/software/emacs
706 Subdirectory `cperl-mode' may contain yet newer development releases and/or
707 patches to related files.
709 For best results apply to an older Emacs the patches from
710 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
711 \(this upgrades syntax-parsing abilities of Emacsen v19.34 and
712 v20.2 up to the level of Emacs v20.3 - a must for a good Perl
713 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
715 Get support packages choose-color.el (or font-lock-extra.el before
716 19.30), imenu-go.el from the same place. \(Look for other files there
717 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
718 later you should use choose-color.el *instead* of font-lock-extra.el
719 \(and you will not get smart highlighting in C :-().
721 Note that to enable Compile choices in the menu you need to install
722 mode-compile.el.
724 If your Emacs does not default to `cperl-mode' on Perl files, and you
725 want it to: put the following into your .emacs file:
727 (defalias 'perl-mode 'cperl-mode)
729 Get perl5-info from
730 $CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
731 Also, one can generate a newer documentation running `pod2texi' converter
732 $CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
734 If you use imenu-go, run imenu on perl5-info buffer (you can do it
735 from Perl menu). If many files are related, generate TAGS files from
736 Tools/Tags submenu in Perl menu.
738 If some class structure is too complicated, use Tools/Hierarchy-view
739 from Perl menu, or hierarchic view of imenu. The second one uses the
740 current buffer only, the first one requires generation of TAGS from
741 Perl/Tools/Tags menu beforehand.
743 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
745 Switch auto-help on/off with Perl/Tools/Auto-help.
747 Though with contemporary Emaxen CPerl mode should maintain the correct
748 parsing of Perl even when editing, sometimes it may be lost. Fix this by
750 \\[normal-mode]
752 In cases of more severe confusion sometimes it is helpful to do
754 \\[load-library] cperl-mode RET
755 \\[normal-mode]
757 Before reporting (non-)problems look in the problem section of online
758 micro-docs on what I know about CPerl problems.")
760 (defvar cperl-problems 'please-ignore-this-line
761 "Description of problems in CPerl mode.
762 Some faces will not be shown on some versions of Emacs unless you
763 install choose-color.el, available from
764 http://ilyaz.org/software/emacs
766 `fill-paragraph' on a comment may leave the point behind the
767 paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
768 to detect it and bulk out).
770 See documentation of a variable `cperl-problems-old-emaxen' for the
771 problems which disappear if you upgrade Emacs to a reasonably new
772 version (20.3 for Emacs, and those of 2004 for XEmacs).")
774 (defvar cperl-problems-old-emaxen 'please-ignore-this-line
775 "Description of problems in CPerl mode specific for older Emacs versions.
777 Emacs had a _very_ restricted syntax parsing engine until version
778 20.1. Most problems below are corrected starting from this version of
779 Emacs, and all of them should be fixed in version 20.3. (Or apply
780 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
781 this respect (until 2003).
783 Note that even with newer Emacsen in some very rare cases the details
784 of interaction of `font-lock' and syntaxification may be not cleaned
785 up yet. You may get slightly different colors basing on the order of
786 fontification and syntaxification. Say, the initial faces is correct,
787 but editing the buffer breaks this.
789 Even with older Emacsen CPerl mode tries to corrects some Emacs
790 misunderstandings, however, for efficiency reasons the degree of
791 correction is different for different operations. The partially
792 corrected problems are: POD sections, here-documents, regexps. The
793 operations are: highlighting, indentation, electric keywords, electric
794 braces.
796 This may be confusing, since the regexp s#//#/#\; may be highlighted
797 as a comment, but it will be recognized as a regexp by the indentation
798 code. Or the opposite case, when a POD section is highlighted, but
799 may break the indentation of the following code (though indentation
800 should work if the balance of delimiters is not broken by POD).
802 The main trick (to make $ a \"backslash\") makes constructions like
803 ${aaa} look like unbalanced braces. The only trick I can think of is
804 to insert it as $ {aaa} (valid in perl5, not in perl4).
806 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
807 as /($|\\s)/. Note that such a transposition is not always possible.
809 The solution is to upgrade your Emacs or patch an older one. Note
810 that Emacs 20.2 has some bugs related to `syntax-table' text
811 properties. Patches are available on the main CPerl download site,
812 and on CPAN.
814 If these bugs cannot be fixed on your machine (say, you have an inferior
815 environment and cannot recompile), you may still disable all the fancy stuff
816 via `cperl-use-syntax-table-text-property'.")
818 (defvar cperl-praise 'please-ignore-this-line
819 "Advantages of CPerl mode.
821 0) It uses the newest `syntax-table' property ;-);
823 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
824 mode - but the latter number may have improved too in last years) even
825 with old Emaxen which do not support `syntax-table' property.
827 When using `syntax-table' property for syntax assist hints, it should
828 handle 99.995% of lines correct - or somesuch. It automatically
829 updates syntax assist hints when you edit your script.
831 2) It is generally believed to be \"the most user-friendly Emacs
832 package\" whatever it may mean (I doubt that the people who say similar
833 things tried _all_ the rest of Emacs ;-), but this was not a lonely
834 voice);
836 3) Everything is customizable, one-by-one or in a big sweep;
838 4) It has many easily-accessible \"tools\":
839 a) Can run program, check syntax, start debugger;
840 b) Can lineup vertically \"middles\" of rows, like `=' in
841 a = b;
842 cc = d;
843 c) Can insert spaces where this improves readability (in one
844 interactive sweep over the buffer);
845 d) Has support for imenu, including:
846 1) Separate unordered list of \"interesting places\";
847 2) Separate TOC of POD sections;
848 3) Separate list of packages;
849 4) Hierarchical view of methods in (sub)packages;
850 5) and functions (by the full name - with package);
851 e) Has an interface to INFO docs for Perl; The interface is
852 very flexible, including shrink-wrapping of
853 documentation buffer/frame;
854 f) Has a builtin list of one-line explanations for perl constructs.
855 g) Can show these explanations if you stay long enough at the
856 corresponding place (or on demand);
857 h) Has an enhanced fontification (using 3 or 4 additional faces
858 comparing to font-lock - basically, different
859 namespaces in Perl have different colors);
860 i) Can construct TAGS basing on its knowledge of Perl syntax,
861 the standard menu has 6 different way to generate
862 TAGS (if \"by directory\", .xs files - with C-language
863 bindings - are included in the scan);
864 j) Can build a hierarchical view of classes (via imenu) basing
865 on generated TAGS file;
866 k) Has electric parentheses, electric newlines, uses Abbrev
867 for electric logical constructs
868 while () {}
869 with different styles of expansion (context sensitive
870 to be not so bothering). Electric parentheses behave
871 \"as they should\" in a presence of a visible region.
872 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
873 m) Can convert from
874 if (A) { B }
876 B if A;
878 n) Highlights (by user-choice) either 3-delimiters constructs
879 (such as tr/a/b/), or regular expressions and `y/tr';
880 o) Highlights trailing whitespace;
881 p) Is able to manipulate Perl Regular Expressions to ease
882 conversion to a more readable form.
883 q) Can ispell POD sections and HERE-DOCs.
884 r) Understands comments and character classes inside regular
885 expressions; can find matching () and [] in a regular expression.
886 s) Allows indentation of //x-style regular expressions;
887 t) Highlights different symbols in regular expressions according
888 to their function; much less problems with backslashitis;
889 u) Allows to find regular expressions which contain interpolated parts.
891 5) The indentation engine was very smart, but most of tricks may be
892 not needed anymore with the support for `syntax-table' property. Has
893 progress indicator for indentation (with `imenu' loaded).
895 6) Indent-region improves inline-comments as well; also corrects
896 whitespace *inside* the conditional/loop constructs.
898 7) Fill-paragraph correctly handles multi-line comments;
900 8) Can switch to different indentation styles by one command, and restore
901 the settings present before the switch.
903 9) When doing indentation of control constructs, may correct
904 line-breaks/spacing between elements of the construct.
906 10) Uses a linear-time algorithm for indentation of regions (on Emaxen with
907 capable syntax engines).
909 11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
912 (defvar cperl-speed 'please-ignore-this-line
913 "This is an incomplete compendium of what is available in other parts
914 of CPerl documentation. (Please inform me if I skept anything.)
916 There is a perception that CPerl is slower than alternatives. This part
917 of documentation is designed to overcome this misconception.
919 *By default* CPerl tries to enable the most comfortable settings.
920 From most points of view, correctly working package is infinitely more
921 comfortable than a non-correctly working one, thus by default CPerl
922 prefers correctness over speed. Below is the guide how to change
923 settings if your preferences are different.
925 A) Speed of loading the file. When loading file, CPerl may perform a
926 scan which indicates places which cannot be parsed by primitive Emacs
927 syntax-parsing routines, and marks them up so that either
929 A1) CPerl may work around these deficiencies (for big chunks, mostly
930 PODs and HERE-documents), or
931 A2) On capable Emaxen CPerl will use improved syntax-handling
932 which reads mark-up hints directly.
934 The scan in case A2 is much more comprehensive, thus may be slower.
936 User can disable syntax-engine-helping scan of A2 by setting
937 `cperl-use-syntax-table-text-property'
938 variable to nil (if it is set to t).
940 One can disable the scan altogether (both A1 and A2) by setting
941 `cperl-pod-here-scan'
942 to nil.
944 B) Speed of editing operations.
946 One can add a (minor) speedup to editing operations by setting
947 `cperl-use-syntax-table-text-property'
948 variable to nil (if it is set to t). This will disable
949 syntax-engine-helping scan, thus will make many more Perl
950 constructs be wrongly recognized by CPerl, thus may lead to
951 wrongly matched parentheses, wrong indentation, etc.
953 One can unset `cperl-syntaxify-unwind'. This might speed up editing
954 of, say, long POD sections.")
956 (defvar cperl-tips-faces 'please-ignore-this-line
957 "CPerl mode uses following faces for highlighting:
959 `cperl-array-face' Array names
960 `cperl-hash-face' Hash names
961 `font-lock-comment-face' Comments, PODs and whatever is considered
962 syntactically to be not code
963 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
964 2-arg operators s/y/tr/ or of RExen,
965 `font-lock-warning-face' Special-cased m// and s//foo/,
966 `font-lock-function-name-face' _ as a target of a file tests, file tests,
967 subroutine names at the moment of definition
968 (except those conflicting with Perl operators),
969 package names (when recognized), format names
970 `font-lock-keyword-face' Control flow switch constructs, declarators
971 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
972 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
973 literal parts and the terminator of formats
974 and whatever is syntactically considered
975 as string literals
976 `font-lock-type-face' Overridable keywords
977 `font-lock-variable-name-face' Variable declarations, indirect array and
978 hash names, POD headers/item names
979 `cperl-invalid-face' Trailing whitespace
981 Note that in several situations the highlighting tries to inform about
982 possible confusion, such as different colors for function names in
983 declarations depending on what they (do not) override, or special cases
984 m// and s/// which do not do what one would expect them to do.
986 Help with best setup of these faces for printout requested (for each of
987 the faces: please specify bold, italic, underline, shadow and box.)
989 In regular expressions (including character classes):
990 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs
991 `font-lock-constant-face': Delimiters
992 `font-lock-warning-face' Special-cased m// and s//foo/,
993 Mismatched closing delimiters, parens
994 we couldn't match, misplaced quantifiers,
995 unrecognized escape sequences
996 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
997 `font-lock-type-face' escape sequences with arguments (\\x \\23 \\p \\N)
998 and others match-a-char escape sequences
999 `font-lock-keyword-face' Capturing parens, and |
1000 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
1001 \"Range -\" in character classes
1002 `font-lock-builtin-face' \"Remaining\" 0-length constructs, multipliers
1003 ?+*{}, not-capturing parens, leading
1004 backslashes of escape sequences
1005 `font-lock-variable-name-face' Interpolated constructs, embedded code,
1006 POSIX classes (inside charclasses)
1007 `font-lock-comment-face' Embedded comments
1013 ;;; Portability stuff:
1015 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
1016 `(define-key cperl-mode-map
1017 ,(if xemacs-key
1018 `(if (featurep 'xemacs) ,xemacs-key ,emacs-key)
1019 emacs-key)
1020 ,definition))
1022 (defvar cperl-del-back-ch
1023 (car (append (where-is-internal 'delete-backward-char)
1024 (where-is-internal 'backward-delete-char-untabify)))
1025 "Character generated by key bound to `delete-backward-char'.")
1027 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
1028 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
1030 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
1031 (if (featurep 'xemacs)
1032 (progn
1033 ;; "Active regions" are on: use region only if active
1034 ;; "Active regions" are off: use region unconditionally
1035 (defun cperl-use-region-p ()
1036 (if zmacs-regions (mark) t)))
1037 (defun cperl-use-region-p ()
1038 (if transient-mark-mode mark-active t))
1039 (defun cperl-mark-active () mark-active))
1041 (defsubst cperl-enable-font-lock ()
1042 cperl-can-font-lock)
1044 (defun cperl-putback-char (c) ; Emacs 19
1045 (set 'unread-command-events (list c))) ; Avoid undefined warning
1047 (if (featurep 'xemacs)
1048 (defun cperl-putback-char (c) ; XEmacs >= 19.12
1049 (setq unread-command-events (list (eval '(character-to-event c))))))
1051 (or (fboundp 'uncomment-region)
1052 (defun uncomment-region (beg end)
1053 (interactive "r")
1054 (comment-region beg end -1)))
1056 (defvar cperl-do-not-fontify
1057 (if (string< emacs-version "19.30")
1058 'fontified
1059 'lazy-lock)
1060 "Text property which inhibits refontification.")
1062 (defsubst cperl-put-do-not-fontify (from to &optional post)
1063 ;; If POST, do not do it with postponed fontification
1064 (if (and post cperl-syntaxify-by-font-lock)
1066 (put-text-property (max (point-min) (1- from))
1067 to cperl-do-not-fontify t)))
1069 (defcustom cperl-mode-hook nil
1070 "Hook run by CPerl mode."
1071 :type 'hook
1072 :group 'cperl)
1074 (defvar cperl-syntax-state nil)
1075 (defvar cperl-syntax-done-to nil)
1076 (defvar cperl-emacs-can-parse (> (length (save-excursion
1077 (parse-partial-sexp (point) (point)))) 9))
1079 ;; Make customization possible "in reverse"
1080 (defsubst cperl-val (symbol &optional default hairy)
1081 (cond
1082 ((eq (symbol-value symbol) 'null) default)
1083 (cperl-hairy (or hairy t))
1084 (t (symbol-value symbol))))
1087 (defun cperl-make-indent (column &optional minimum keep)
1088 "Makes indent of the current line the requested amount.
1089 Unless KEEP, removes the old indentation. Works around a bug in ancient
1090 versions of Emacs."
1091 (let ((prop (get-text-property (point) 'syntax-type)))
1092 (or keep
1093 (delete-horizontal-space))
1094 (indent-to column minimum)
1095 ;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
1096 (and prop
1097 (> (current-column) 0)
1098 (save-excursion
1099 (beginning-of-line)
1100 (or (get-text-property (point) 'syntax-type)
1101 (and (looking-at "\\=[ \t]")
1102 (put-text-property (point) (match-end 0)
1103 'syntax-type prop)))))))
1105 ;;; Probably it is too late to set these guys already, but it can help later:
1107 ;;;(and cperl-clobber-mode-lists
1108 ;;;(setq auto-mode-alist
1109 ;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
1110 ;;;(and (boundp 'interpreter-mode-alist)
1111 ;;; (setq interpreter-mode-alist (append interpreter-mode-alist
1112 ;;; '(("miniperl" . perl-mode))))))
1113 (eval-when-compile
1114 (mapc (lambda (p)
1115 (condition-case nil
1116 (require p)
1117 (error nil)))
1118 '(imenu easymenu etags timer man info))
1119 (if (fboundp 'ps-extend-face-list)
1120 (defmacro cperl-ps-extend-face-list (arg)
1121 `(ps-extend-face-list ,arg))
1122 (defmacro cperl-ps-extend-face-list (arg)
1123 `(error "This version of Emacs has no `ps-extend-face-list'")))
1124 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
1125 ;; macros instead of defsubsts don't work on Emacs, so we do the
1126 ;; expansion manually. Any other suggestions?
1127 (require 'cl))
1129 (defvar cperl-mode-abbrev-table nil
1130 "Abbrev table in use in CPerl mode buffers.")
1132 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
1134 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
1136 (if cperl-mode-map nil
1137 (setq cperl-mode-map (make-sparse-keymap))
1138 (cperl-define-key "{" 'cperl-electric-lbrace)
1139 (cperl-define-key "[" 'cperl-electric-paren)
1140 (cperl-define-key "(" 'cperl-electric-paren)
1141 (cperl-define-key "<" 'cperl-electric-paren)
1142 (cperl-define-key "}" 'cperl-electric-brace)
1143 (cperl-define-key "]" 'cperl-electric-rparen)
1144 (cperl-define-key ")" 'cperl-electric-rparen)
1145 (cperl-define-key ";" 'cperl-electric-semi)
1146 (cperl-define-key ":" 'cperl-electric-terminator)
1147 (cperl-define-key "\C-j" 'newline-and-indent)
1148 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
1149 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
1150 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
1151 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
1152 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
1153 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
1154 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
1155 (cperl-define-key "\C-c\C-b" 'cperl-find-bad-style)
1156 (cperl-define-key "\C-c\C-p" 'cperl-pod-spell)
1157 (cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell)
1158 (cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc)
1159 (cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx)
1160 (cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0)
1161 (cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1)
1162 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
1163 (cperl-define-key "\C-c\C-hp" 'cperl-perldoc)
1164 (cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point)
1165 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
1166 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
1167 [(control meta |)])
1168 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1169 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
1170 (cperl-define-key "\177" 'cperl-electric-backspace)
1171 (cperl-define-key "\t" 'cperl-indent-command)
1172 ;; don't clobber the backspace binding:
1173 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
1174 [(control c) (control h) F])
1175 (if (cperl-val 'cperl-clobber-lisp-bindings)
1176 (progn
1177 (cperl-define-key "\C-hf"
1178 ;;(concat (char-to-string help-char) "f") ; does not work
1179 'cperl-info-on-command
1180 [(control h) f])
1181 (cperl-define-key "\C-hv"
1182 ;;(concat (char-to-string help-char) "v") ; does not work
1183 'cperl-get-help
1184 [(control h) v])
1185 (cperl-define-key "\C-c\C-hf"
1186 ;;(concat (char-to-string help-char) "f") ; does not work
1187 (key-binding "\C-hf")
1188 [(control c) (control h) f])
1189 (cperl-define-key "\C-c\C-hv"
1190 ;;(concat (char-to-string help-char) "v") ; does not work
1191 (key-binding "\C-hv")
1192 [(control c) (control h) v]))
1193 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
1194 [(control c) (control h) f])
1195 (cperl-define-key "\C-c\C-hv"
1196 ;;(concat (char-to-string help-char) "v") ; does not work
1197 'cperl-get-help
1198 [(control c) (control h) v]))
1199 (if (and (featurep 'xemacs)
1200 (<= emacs-minor-version 11) (<= emacs-major-version 19))
1201 (progn
1202 ;; substitute-key-definition is usefulness-deenhanced...
1203 ;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1204 (cperl-define-key "\e;" 'cperl-indent-for-comment)
1205 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
1206 (or (boundp 'fill-paragraph-function)
1207 (substitute-key-definition
1208 'fill-paragraph 'cperl-fill-paragraph
1209 cperl-mode-map global-map))
1210 (substitute-key-definition
1211 'indent-sexp 'cperl-indent-exp
1212 cperl-mode-map global-map)
1213 (substitute-key-definition
1214 'indent-region 'cperl-indent-region
1215 cperl-mode-map global-map)
1216 (substitute-key-definition
1217 'indent-for-comment 'cperl-indent-for-comment
1218 cperl-mode-map global-map)))
1220 (defvar cperl-menu)
1221 (defvar cperl-lazy-installed)
1222 (defvar cperl-old-style nil)
1223 (condition-case nil
1224 (progn
1225 (require 'easymenu)
1226 (easy-menu-define
1227 cperl-menu cperl-mode-map "Menu for CPerl mode"
1228 '("Perl"
1229 ["Beginning of function" beginning-of-defun t]
1230 ["End of function" end-of-defun t]
1231 ["Mark function" mark-defun t]
1232 ["Indent expression" cperl-indent-exp t]
1233 ["Fill paragraph/comment" fill-paragraph t]
1234 "----"
1235 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
1236 ["Invert if/unless/while etc" cperl-invert-if-unless t]
1237 ("Regexp"
1238 ["Beautify" cperl-beautify-regexp
1239 cperl-use-syntax-table-text-property]
1240 ["Beautify one level deep" (cperl-beautify-regexp 1)
1241 cperl-use-syntax-table-text-property]
1242 ["Beautify a group" cperl-beautify-level
1243 cperl-use-syntax-table-text-property]
1244 ["Beautify a group one level deep" (cperl-beautify-level 1)
1245 cperl-use-syntax-table-text-property]
1246 ["Contract a group" cperl-contract-level
1247 cperl-use-syntax-table-text-property]
1248 ["Contract groups" cperl-contract-levels
1249 cperl-use-syntax-table-text-property]
1250 "----"
1251 ["Find next interpolated" cperl-next-interpolated-REx
1252 (next-single-property-change (point-min) 'REx-interpolated)]
1253 ["Find next interpolated (no //o)"
1254 cperl-next-interpolated-REx-0
1255 (or (text-property-any (point-min) (point-max) 'REx-interpolated t)
1256 (text-property-any (point-min) (point-max) 'REx-interpolated 1))]
1257 ["Find next interpolated (neither //o nor whole-REx)"
1258 cperl-next-interpolated-REx-1
1259 (text-property-any (point-min) (point-max) 'REx-interpolated t)])
1260 ["Insert spaces if needed to fix style" cperl-find-bad-style t]
1261 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
1262 "----"
1263 ["Indent region" cperl-indent-region (cperl-use-region-p)]
1264 ["Comment region" cperl-comment-region (cperl-use-region-p)]
1265 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
1266 "----"
1267 ["Run" mode-compile (fboundp 'mode-compile)]
1268 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
1269 (get-buffer "*compilation*"))]
1270 ["Next error" next-error (get-buffer "*compilation*")]
1271 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
1272 "----"
1273 ["Debugger" cperl-db t]
1274 "----"
1275 ("Tools"
1276 ["Imenu" imenu (fboundp 'imenu)]
1277 ["Imenu on Perl Info" cperl-imenu-on-info (featurep 'imenu)]
1278 "----"
1279 ["Ispell PODs" cperl-pod-spell
1280 ;; Better not to update syntaxification here:
1281 ;; debugging syntaxification can be broken by this???
1283 (get-text-property (point-min) 'in-pod)
1284 (< (progn
1285 (and cperl-syntaxify-for-menu
1286 (cperl-update-syntaxification (point-max) (point-max)))
1287 (next-single-property-change (point-min) 'in-pod nil (point-max)))
1288 (point-max)))]
1289 ["Ispell HERE-DOCs" cperl-here-doc-spell
1290 (< (progn
1291 (and cperl-syntaxify-for-menu
1292 (cperl-update-syntaxification (point-max) (point-max)))
1293 (next-single-property-change (point-min) 'here-doc-group nil (point-max)))
1294 (point-max))]
1295 ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
1296 (eq 'here-doc (progn
1297 (and cperl-syntaxify-for-menu
1298 (cperl-update-syntaxification (point) (point)))
1299 (get-text-property (point) 'syntax-type)))]
1300 ["Select this HERE-DOC or POD section"
1301 cperl-select-this-pod-or-here-doc
1302 (memq (progn
1303 (and cperl-syntaxify-for-menu
1304 (cperl-update-syntaxification (point) (point)))
1305 (get-text-property (point) 'syntax-type))
1306 '(here-doc pod))]
1307 "----"
1308 ["CPerl pretty print (experimental)" cperl-ps-print
1309 (fboundp 'ps-extend-face-list)]
1310 "----"
1311 ["Syntaxify region" cperl-find-pods-heres-region
1312 (cperl-use-region-p)]
1313 ["Profile syntaxification" cperl-time-fontification t]
1314 ["Debug errors in delayed fontification" cperl-emulate-lazy-lock t]
1315 ["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t]
1316 ["Debug backtrace on syntactic scan (BEWARE!!!)"
1317 (cperl-toggle-set-debug-unwind nil t) t]
1318 "----"
1319 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
1320 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
1321 ("Tags"
1322 ;;; ["Create tags for current file" cperl-etags t]
1323 ;;; ["Add tags for current file" (cperl-etags t) t]
1324 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
1325 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
1326 ;;; ["Create tags for Perl files in (sub)directories"
1327 ;;; (cperl-etags nil 'recursive) t]
1328 ;;; ["Add tags for Perl files in (sub)directories"
1329 ;;; (cperl-etags t 'recursive) t])
1330 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
1331 ["Create tags for current file" (cperl-write-tags nil t) t]
1332 ["Add tags for current file" (cperl-write-tags) t]
1333 ["Create tags for Perl files in directory"
1334 (cperl-write-tags nil t nil t) t]
1335 ["Add tags for Perl files in directory"
1336 (cperl-write-tags nil nil nil t) t]
1337 ["Create tags for Perl files in (sub)directories"
1338 (cperl-write-tags nil t t t) t]
1339 ["Add tags for Perl files in (sub)directories"
1340 (cperl-write-tags nil nil t t) t]))
1341 ("Perl docs"
1342 ["Define word at point" imenu-go-find-at-position
1343 (fboundp 'imenu-go-find-at-position)]
1344 ["Help on function" cperl-info-on-command t]
1345 ["Help on function at point" cperl-info-on-current-command t]
1346 ["Help on symbol at point" cperl-get-help t]
1347 ["Perldoc" cperl-perldoc t]
1348 ["Perldoc on word at point" cperl-perldoc-at-point t]
1349 ["View manpage of POD in this file" cperl-build-manpage t]
1350 ["Auto-help on" cperl-lazy-install
1351 (and (fboundp 'run-with-idle-timer)
1352 (not cperl-lazy-installed))]
1353 ["Auto-help off" cperl-lazy-unstall
1354 (and (fboundp 'run-with-idle-timer)
1355 cperl-lazy-installed)])
1356 ("Toggle..."
1357 ["Auto newline" cperl-toggle-auto-newline t]
1358 ["Electric parens" cperl-toggle-electric t]
1359 ["Electric keywords" cperl-toggle-abbrev t]
1360 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
1361 ["Auto-help on Perl constructs" cperl-toggle-autohelp t]
1362 ["Auto fill" auto-fill-mode t])
1363 ("Indent styles..."
1364 ["CPerl" (cperl-set-style "CPerl") t]
1365 ["PerlStyle" (cperl-set-style "PerlStyle") t]
1366 ["GNU" (cperl-set-style "GNU") t]
1367 ["C++" (cperl-set-style "C++") t]
1368 ["K&R" (cperl-set-style "K&R") t]
1369 ["BSD" (cperl-set-style "BSD") t]
1370 ["Whitesmith" (cperl-set-style "Whitesmith") t]
1371 ["Memorize Current" (cperl-set-style "Current") t]
1372 ["Memorized" (cperl-set-style-back) cperl-old-style])
1373 ("Micro-docs"
1374 ["Tips" (describe-variable 'cperl-tips) t]
1375 ["Problems" (describe-variable 'cperl-problems) t]
1376 ["Speed" (describe-variable 'cperl-speed) t]
1377 ["Praise" (describe-variable 'cperl-praise) t]
1378 ["Faces" (describe-variable 'cperl-tips-faces) t]
1379 ["CPerl mode" (describe-function 'cperl-mode) t]
1380 ["CPerl version"
1381 (message "The version of master-file for this CPerl is %s-Emacs"
1382 cperl-version) t]))))
1383 (error nil))
1385 (autoload 'c-macro-expand "cmacexp"
1386 "Display the result of expanding all C macros occurring in the region.
1387 The expansion is entirely correct because it uses the C preprocessor."
1390 ;;; These two must be unwound, otherwise take exponential time
1391 (defconst cperl-maybe-white-and-comment-rex "[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
1392 "Regular expression to match optional whitespace with interspersed comments.
1393 Should contain exactly one group.")
1395 ;;; This one is tricky to unwind; still very inefficient...
1396 (defconst cperl-white-and-comment-rex "\\([ \t\n]\\|#[^\n]*\n\\)+"
1397 "Regular expression to match whitespace with interspersed comments.
1398 Should contain exactly one group.")
1401 ;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
1402 ;;; `cperl-outline-regexp', `defun-prompt-regexp'.
1403 ;;; Details of groups in this may be used in several functions; see comments
1404 ;;; near mentioned above variable(s)...
1405 ;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
1406 (defsubst cperl-after-sub-regexp (named attr) ; 9 groups without attr...
1407 "Match the text after `sub' in a subroutine declaration.
1408 If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
1409 of attributes (if present), or end of the name or prototype (whatever is
1410 the last)."
1411 (concat ; Assume n groups before this...
1412 "\\(" ; n+1=name-group
1413 cperl-white-and-comment-rex ; n+2=pre-name
1414 "\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
1415 "\\)" ; END n+1=name-group
1416 (if named "" "?")
1417 "\\(" ; n+4=proto-group
1418 cperl-maybe-white-and-comment-rex ; n+5=pre-proto
1419 "\\(([^()]*)\\)" ; n+6=prototype
1420 "\\)?" ; END n+4=proto-group
1421 "\\(" ; n+7=attr-group
1422 cperl-maybe-white-and-comment-rex ; n+8=pre-attr
1423 "\\(" ; n+9=start-attr
1425 (if attr (concat
1426 "\\("
1427 cperl-maybe-white-and-comment-rex ; whitespace-comments
1428 "\\(\\sw\\|_\\)+" ; attr-name
1429 ;; attr-arg (1 level of internal parens allowed!)
1430 "\\((\\(\\\\.\\|[^\\\\()]\\|([^\\\\()]*)\\)*)\\)?"
1431 "\\(" ; optional : (XXX allows trailing???)
1432 cperl-maybe-white-and-comment-rex ; whitespace-comments
1433 ":\\)?"
1434 "\\)+")
1435 "[^:]")
1436 "\\)"
1437 "\\)?" ; END n+6=proto-group
1440 ;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
1441 ;;; and `cperl-outline-level'.
1442 ;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 8=sub-name (+3)
1443 (defvar cperl-imenu--function-name-regexp-perl
1444 (concat
1445 "^\\(" ; 1 = all
1446 "\\([ \t]*package" ; 2 = package-group
1447 "\\(" ; 3 = package-name-group
1448 cperl-white-and-comment-rex ; 4 = pre-package-name
1449 "\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
1450 "\\|"
1451 "[ \t]*sub"
1452 (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
1453 cperl-maybe-white-and-comment-rex ; 15=pre-block
1454 "\\|"
1455 "=head\\([1-4]\\)[ \t]+" ; 16=level
1456 "\\([^\n]+\\)$" ; 17=text
1457 "\\)"))
1459 (defvar cperl-outline-regexp
1460 (concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
1462 (defvar cperl-mode-syntax-table nil
1463 "Syntax table in use in CPerl mode buffers.")
1465 (defvar cperl-string-syntax-table nil
1466 "Syntax table in use in CPerl mode string-like chunks.")
1468 (defsubst cperl-1- (p)
1469 (max (point-min) (1- p)))
1471 (defsubst cperl-1+ (p)
1472 (min (point-max) (1+ p)))
1474 (if cperl-mode-syntax-table
1476 (setq cperl-mode-syntax-table (make-syntax-table))
1477 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
1478 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
1479 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
1480 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
1481 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
1482 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
1483 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
1484 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
1485 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
1486 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
1487 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
1488 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
1489 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
1490 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
1491 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
1492 (if cperl-under-as-char
1493 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
1494 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
1495 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
1496 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
1497 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
1498 (modify-syntax-entry ?\{ "." cperl-string-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)
1503 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment )
1507 (defvar cperl-faces-init nil)
1508 ;; Fix for msb.el
1509 (defvar cperl-msb-fixed nil)
1510 (defvar cperl-use-major-mode 'cperl-mode)
1511 (defvar cperl-font-lock-multiline-start nil)
1512 (defvar cperl-font-lock-multiline nil)
1513 (defvar cperl-font-locking nil)
1515 ;; NB as it stands the code in cperl-mode assumes this only has one
1516 ;; element. If XEmacs 19 support were dropped, this could all be simplified.
1517 (defvar cperl-compilation-error-regexp-alist
1518 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
1519 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
1520 2 3))
1521 "Alist that specifies how to match errors in perl output.")
1523 (defvar compilation-error-regexp-alist)
1525 ;;;###autoload
1526 (define-derived-mode cperl-mode prog-mode "CPerl"
1527 "Major mode for editing Perl code.
1528 Expression and list commands understand all C brackets.
1529 Tab indents for Perl code.
1530 Paragraphs are separated by blank lines only.
1531 Delete converts tabs to spaces as it moves back.
1533 Various characters in Perl almost always come in pairs: {}, (), [],
1534 sometimes <>. When the user types the first, she gets the second as
1535 well, with optional special formatting done on {}. (Disabled by
1536 default.) You can always quote (with \\[quoted-insert]) the left
1537 \"paren\" to avoid the expansion. The processing of < is special,
1538 since most the time you mean \"less\". CPerl mode tries to guess
1539 whether you want to type pair <>, and inserts is if it
1540 appropriate. You can set `cperl-electric-parens-string' to the string that
1541 contains the parens from the above list you want to be electrical.
1542 Electricity of parens is controlled by `cperl-electric-parens'.
1543 You may also set `cperl-electric-parens-mark' to have electric parens
1544 look for active mark and \"embrace\" a region if possible.'
1546 CPerl mode provides expansion of the Perl control constructs:
1548 if, else, elsif, unless, while, until, continue, do,
1549 for, foreach, formy and foreachmy.
1551 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
1553 The user types the keyword immediately followed by a space, which
1554 causes the construct to be expanded, and the point is positioned where
1555 she is most likely to want to be. E.g., when the user types a space
1556 following \"if\" the following appears in the buffer: if () { or if ()
1557 } { } and the cursor is between the parentheses. The user can then
1558 type some boolean expression within the parens. Having done that,
1559 typing \\[cperl-linefeed] places you - appropriately indented - on a
1560 new line between the braces (if you typed \\[cperl-linefeed] in a POD
1561 directive line, then appropriate number of new lines is inserted).
1563 If CPerl decides that you want to insert \"English\" style construct like
1565 bite if angry;
1567 it will not do any expansion. See also help on variable
1568 `cperl-extra-newline-before-brace'. (Note that one can switch the
1569 help message on expansion by setting `cperl-message-electric-keyword'
1570 to nil.)
1572 \\[cperl-linefeed] is a convenience replacement for typing carriage
1573 return. It places you in the next line with proper indentation, or if
1574 you type it inside the inline block of control construct, like
1576 foreach (@lines) {print; print}
1578 and you are on a boundary of a statement inside braces, it will
1579 transform the construct into a multiline and will place you into an
1580 appropriately indented blank line. If you need a usual
1581 `newline-and-indent' behavior, it is on \\[newline-and-indent],
1582 see documentation on `cperl-electric-linefeed'.
1584 Use \\[cperl-invert-if-unless] to change a construction of the form
1586 if (A) { B }
1588 into
1590 B if A;
1592 \\{cperl-mode-map}
1594 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
1595 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
1596 on electric space between $ and {, `cperl-electric-parens-string' is
1597 the string that contains parentheses that should be electric in CPerl
1598 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
1599 setting `cperl-electric-keywords' enables electric expansion of
1600 control structures in CPerl. `cperl-electric-linefeed' governs which
1601 one of two linefeed behavior is preferable. You can enable all these
1602 options simultaneously (recommended mode of use) by setting
1603 `cperl-hairy' to t. In this case you can switch separate options off
1604 by setting them to `null'. Note that one may undo the extra
1605 whitespace inserted by semis and braces in `auto-newline'-mode by
1606 consequent \\[cperl-electric-backspace].
1608 If your site has perl5 documentation in info format, you can use commands
1609 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
1610 These keys run commands `cperl-info-on-current-command' and
1611 `cperl-info-on-command', which one is which is controlled by variable
1612 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
1613 \(in turn affected by `cperl-hairy').
1615 Even if you have no info-format documentation, short one-liner-style
1616 help is available on \\[cperl-get-help], and one can run perldoc or
1617 man via menu.
1619 It is possible to show this help automatically after some idle time.
1620 This is regulated by variable `cperl-lazy-help-time'. Default with
1621 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
1622 secs idle time . It is also possible to switch this on/off from the
1623 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
1625 Use \\[cperl-lineup] to vertically lineup some construction - put the
1626 beginning of the region at the start of construction, and make region
1627 span the needed amount of lines.
1629 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
1630 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
1631 here-docs sections. With capable Emaxen results of scan are used
1632 for indentation too, otherwise they are used for highlighting only.
1634 Variables controlling indentation style:
1635 `cperl-tab-always-indent'
1636 Non-nil means TAB in CPerl mode should always reindent the current line,
1637 regardless of where in the line point is when the TAB command is used.
1638 `cperl-indent-left-aligned-comments'
1639 Non-nil means that the comment starting in leftmost column should indent.
1640 `cperl-auto-newline'
1641 Non-nil means automatically newline before and after braces,
1642 and after colons and semicolons, inserted in Perl code. The following
1643 \\[cperl-electric-backspace] will remove the inserted whitespace.
1644 Insertion after colons requires both this variable and
1645 `cperl-auto-newline-after-colon' set.
1646 `cperl-auto-newline-after-colon'
1647 Non-nil means automatically newline even after colons.
1648 Subject to `cperl-auto-newline' setting.
1649 `cperl-indent-level'
1650 Indentation of Perl statements within surrounding block.
1651 The surrounding block's indentation is the indentation
1652 of the line on which the open-brace appears.
1653 `cperl-continued-statement-offset'
1654 Extra indentation given to a substatement, such as the
1655 then-clause of an if, or body of a while, or just a statement continuation.
1656 `cperl-continued-brace-offset'
1657 Extra indentation given to a brace that starts a substatement.
1658 This is in addition to `cperl-continued-statement-offset'.
1659 `cperl-brace-offset'
1660 Extra indentation for line if it starts with an open brace.
1661 `cperl-brace-imaginary-offset'
1662 An open brace following other text is treated as if it the line started
1663 this far to the right of the actual line indentation.
1664 `cperl-label-offset'
1665 Extra indentation for line that is a label.
1666 `cperl-min-label-indent'
1667 Minimal indentation for line that is a label.
1669 Settings for classic indent-styles: K&R BSD=C++ GNU PerlStyle=Whitesmith
1670 `cperl-indent-level' 5 4 2 4
1671 `cperl-brace-offset' 0 0 0 0
1672 `cperl-continued-brace-offset' -5 -4 0 0
1673 `cperl-label-offset' -5 -4 -2 -4
1674 `cperl-continued-statement-offset' 5 4 2 4
1676 CPerl knows several indentation styles, and may bulk set the
1677 corresponding variables. Use \\[cperl-set-style] to do this. Use
1678 \\[cperl-set-style-back] to restore the memorized preexisting values
1679 \(both available from menu). See examples in `cperl-style-examples'.
1681 Part of the indentation style is how different parts of if/elsif/else
1682 statements are broken into lines; in CPerl, this is reflected on how
1683 templates for these constructs are created (controlled by
1684 `cperl-extra-newline-before-brace'), and how reflow-logic should treat
1685 \"continuation\" blocks of else/elsif/continue, controlled by the same
1686 variable, and by `cperl-extra-newline-before-brace-multiline',
1687 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'.
1689 If `cperl-indent-level' is 0, the statement after opening brace in
1690 column 0 is indented on
1691 `cperl-brace-offset'+`cperl-continued-statement-offset'.
1693 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
1694 with no args.
1696 DO NOT FORGET to read micro-docs (available from `Perl' menu)
1697 or as help on variables `cperl-tips', `cperl-problems',
1698 `cperl-praise', `cperl-speed'."
1699 (if (cperl-val 'cperl-electric-linefeed)
1700 (progn
1701 (local-set-key "\C-J" 'cperl-linefeed)
1702 (local-set-key "\C-C\C-J" 'newline-and-indent)))
1703 (if (and
1704 (cperl-val 'cperl-clobber-lisp-bindings)
1705 (cperl-val 'cperl-info-on-command-no-prompt))
1706 (progn
1707 ;; don't clobber the backspace binding:
1708 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
1709 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
1710 [(control c) (control h) f])))
1711 (let ((prev-a-c abbrevs-changed))
1712 (define-abbrev-table 'cperl-mode-abbrev-table '(
1713 ("if" "if" cperl-electric-keyword 0)
1714 ("elsif" "elsif" cperl-electric-keyword 0)
1715 ("while" "while" cperl-electric-keyword 0)
1716 ("until" "until" cperl-electric-keyword 0)
1717 ("unless" "unless" cperl-electric-keyword 0)
1718 ("else" "else" cperl-electric-else 0)
1719 ("continue" "continue" cperl-electric-else 0)
1720 ("for" "for" cperl-electric-keyword 0)
1721 ("foreach" "foreach" cperl-electric-keyword 0)
1722 ("formy" "formy" cperl-electric-keyword 0)
1723 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
1724 ("do" "do" cperl-electric-keyword 0)
1725 ("=pod" "=pod" cperl-electric-pod 0)
1726 ("=over" "=over" cperl-electric-pod 0)
1727 ("=head1" "=head1" cperl-electric-pod 0)
1728 ("=head2" "=head2" cperl-electric-pod 0)
1729 ("pod" "pod" cperl-electric-pod 0)
1730 ("over" "over" cperl-electric-pod 0)
1731 ("head1" "head1" cperl-electric-pod 0)
1732 ("head2" "head2" cperl-electric-pod 0)))
1733 (setq abbrevs-changed prev-a-c))
1734 (setq local-abbrev-table cperl-mode-abbrev-table)
1735 (if (cperl-val 'cperl-electric-keywords)
1736 (abbrev-mode 1))
1737 (set-syntax-table cperl-mode-syntax-table)
1738 ;; Until Emacs is multi-threaded, we do not actually need it local:
1739 (make-local-variable 'cperl-font-lock-multiline-start)
1740 (make-local-variable 'cperl-font-locking)
1741 (make-local-variable 'outline-regexp)
1742 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
1743 (setq outline-regexp cperl-outline-regexp)
1744 (make-local-variable 'outline-level)
1745 (setq outline-level 'cperl-outline-level)
1746 (make-local-variable 'add-log-current-defun-function)
1747 (setq add-log-current-defun-function
1748 (lambda ()
1749 (save-excursion
1750 (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t)
1751 (match-string-no-properties 1)))))
1753 (make-local-variable 'paragraph-start)
1754 (setq paragraph-start (concat "^$\\|" page-delimiter))
1755 (make-local-variable 'paragraph-separate)
1756 (setq paragraph-separate paragraph-start)
1757 (make-local-variable 'paragraph-ignore-fill-prefix)
1758 (setq paragraph-ignore-fill-prefix t)
1759 (if (featurep 'xemacs)
1760 (progn
1761 (make-local-variable 'paren-backwards-message)
1762 (set 'paren-backwards-message t)))
1763 (make-local-variable 'indent-line-function)
1764 (setq indent-line-function 'cperl-indent-line)
1765 (make-local-variable 'require-final-newline)
1766 (setq require-final-newline mode-require-final-newline)
1767 (make-local-variable 'comment-start)
1768 (setq comment-start "# ")
1769 (make-local-variable 'comment-end)
1770 (setq comment-end "")
1771 (make-local-variable 'comment-column)
1772 (setq comment-column cperl-comment-column)
1773 (make-local-variable 'comment-start-skip)
1774 (setq comment-start-skip "#+ *")
1775 (make-local-variable 'defun-prompt-regexp)
1776 ;;; "[ \t]*sub"
1777 ;;; (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
1778 ;;; cperl-maybe-white-and-comment-rex ; 15=pre-block
1779 (setq defun-prompt-regexp
1780 (concat "^[ \t]*\\(sub"
1781 (cperl-after-sub-regexp 'named 'attr-groups)
1782 "\\|" ; per toke.c
1783 "\\(BEGIN\\|CHECK\\|INIT\\|END\\|AUTOLOAD\\|DESTROY\\)"
1784 "\\)"
1785 cperl-maybe-white-and-comment-rex))
1786 (make-local-variable 'comment-indent-function)
1787 (setq comment-indent-function 'cperl-comment-indent)
1788 (and (boundp 'fill-paragraph-function)
1789 (progn
1790 (make-local-variable 'fill-paragraph-function)
1791 (set 'fill-paragraph-function 'cperl-fill-paragraph)))
1792 (make-local-variable 'parse-sexp-ignore-comments)
1793 (setq parse-sexp-ignore-comments t)
1794 (make-local-variable 'indent-region-function)
1795 (setq indent-region-function 'cperl-indent-region)
1796 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
1797 (make-local-variable 'imenu-create-index-function)
1798 (setq imenu-create-index-function
1799 (function cperl-imenu--create-perl-index))
1800 (make-local-variable 'imenu-sort-function)
1801 (setq imenu-sort-function nil)
1802 (make-local-variable 'vc-rcs-header)
1803 (set 'vc-rcs-header cperl-vc-rcs-header)
1804 (make-local-variable 'vc-sccs-header)
1805 (set 'vc-sccs-header cperl-vc-sccs-header)
1806 (when (featurep 'xemacs)
1807 ;; This one is obsolete...
1808 (make-local-variable 'vc-header-alist)
1809 (set 'vc-header-alist (or cperl-vc-header-alist ; Avoid warning
1810 `((SCCS ,(car cperl-vc-sccs-header))
1811 (RCS ,(car cperl-vc-rcs-header))))))
1812 (cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x
1813 (make-local-variable 'compilation-error-regexp-alist-alist)
1814 (set 'compilation-error-regexp-alist-alist
1815 (cons (cons 'cperl (car cperl-compilation-error-regexp-alist))
1816 (symbol-value 'compilation-error-regexp-alist-alist)))
1817 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
1818 (let ((f 'compilation-build-compilation-error-regexp-alist))
1819 (funcall f))
1820 (make-local-variable 'compilation-error-regexp-alist)
1821 (push 'cperl compilation-error-regexp-alist)))
1822 ((boundp 'compilation-error-regexp-alist);; xemacs 19.x
1823 (make-local-variable 'compilation-error-regexp-alist)
1824 (set 'compilation-error-regexp-alist
1825 (append cperl-compilation-error-regexp-alist
1826 (symbol-value 'compilation-error-regexp-alist)))))
1827 (make-local-variable 'font-lock-defaults)
1828 (setq font-lock-defaults
1829 (cond
1830 ((string< emacs-version "19.30")
1831 '(cperl-font-lock-keywords-2 nil nil ((?_ . "w"))))
1832 ((string< emacs-version "19.33") ; Which one to use?
1833 '((cperl-font-lock-keywords
1834 cperl-font-lock-keywords-1
1835 cperl-font-lock-keywords-2) nil nil ((?_ . "w"))))
1837 '((cperl-load-font-lock-keywords
1838 cperl-load-font-lock-keywords-1
1839 cperl-load-font-lock-keywords-2) nil nil ((?_ . "w"))))))
1840 (make-local-variable 'cperl-syntax-state)
1841 (setq cperl-syntax-state nil) ; reset syntaxification cache
1842 (if cperl-use-syntax-table-text-property
1843 (if (eval-when-compile (fboundp 'syntax-propertize-rules))
1844 (progn
1845 ;; Reset syntaxification cache.
1846 (set (make-local-variable 'cperl-syntax-done-to) nil)
1847 (set (make-local-variable 'syntax-propertize-function)
1848 (lambda (start end)
1849 (goto-char start)
1850 ;; Even if cperl-fontify-syntaxically has already gone
1851 ;; beyond `start', syntax-propertize has just removed
1852 ;; syntax-table properties between start and end, so we have
1853 ;; to re-apply them.
1854 (setq cperl-syntax-done-to start)
1855 (cperl-fontify-syntaxically end))))
1856 (make-local-variable 'parse-sexp-lookup-properties)
1857 ;; Do not introduce variable if not needed, we check it!
1858 (set 'parse-sexp-lookup-properties t)
1859 ;; Fix broken font-lock:
1860 (or (boundp 'font-lock-unfontify-region-function)
1861 (set 'font-lock-unfontify-region-function
1862 'font-lock-default-unfontify-region))
1863 (unless (featurep 'xemacs) ; Our: just a plug for wrong font-lock
1864 (make-local-variable 'font-lock-unfontify-region-function)
1865 (set 'font-lock-unfontify-region-function ; not present with old Emacs
1866 'cperl-font-lock-unfontify-region-function))
1867 (make-local-variable 'cperl-syntax-done-to)
1868 (setq cperl-syntax-done-to nil) ; reset syntaxification cache
1869 (make-local-variable 'font-lock-syntactic-keywords)
1870 (setq font-lock-syntactic-keywords
1871 (if cperl-syntaxify-by-font-lock
1872 '((cperl-fontify-syntaxically))
1873 ;; unless font-lock-syntactic-keywords, font-lock (pre-22.1)
1874 ;; used to ignore syntax-table text-properties. (t) is a hack
1875 ;; to make font-lock think that font-lock-syntactic-keywords
1876 ;; are defined.
1877 '(t)))))
1878 (if (boundp 'font-lock-multiline) ; Newer font-lock; use its facilities
1879 (progn
1880 (setq cperl-font-lock-multiline t) ; Not localized...
1881 (set (make-local-variable 'font-lock-multiline) t))
1882 (make-local-variable 'font-lock-fontify-region-function)
1883 (set 'font-lock-fontify-region-function ; not present with old Emacs
1884 'cperl-font-lock-fontify-region-function))
1885 (make-local-variable 'font-lock-fontify-region-function)
1886 (set 'font-lock-fontify-region-function ; not present with old Emacs
1887 'cperl-font-lock-fontify-region-function)
1888 (make-local-variable 'cperl-old-style)
1889 (if (boundp 'normal-auto-fill-function) ; 19.33 and later
1890 (set (make-local-variable 'normal-auto-fill-function)
1891 'cperl-do-auto-fill)
1892 (or (fboundp 'cperl-old-auto-fill-mode)
1893 (progn
1894 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
1895 (defun auto-fill-mode (&optional arg)
1896 (interactive "P")
1897 (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
1898 (and auto-fill-function (memq major-mode '(perl-mode cperl-mode))
1899 (setq auto-fill-function 'cperl-do-auto-fill))))))
1900 (if (cperl-enable-font-lock)
1901 (if (cperl-val 'cperl-font-lock)
1902 (progn (or cperl-faces-init (cperl-init-faces))
1903 (font-lock-mode 1))))
1904 (set (make-local-variable 'facemenu-add-face-function)
1905 'cperl-facemenu-add-face-function) ; XXXX What this guy is for???
1906 (and (boundp 'msb-menu-cond)
1907 (not cperl-msb-fixed)
1908 (cperl-msb-fix))
1909 (if (fboundp 'easy-menu-add)
1910 (easy-menu-add cperl-menu)) ; A NOP in Emacs.
1911 (run-mode-hooks 'cperl-mode-hook)
1912 (if cperl-hook-after-change
1913 (add-hook 'after-change-functions 'cperl-after-change-function nil t))
1914 ;; After hooks since fontification will break this
1915 (if cperl-pod-here-scan
1916 (or cperl-syntaxify-by-font-lock
1917 (progn (or cperl-faces-init (cperl-init-faces-weak))
1918 (cperl-find-pods-heres)))))
1920 ;; Fix for perldb - make default reasonable
1921 (defun cperl-db ()
1922 (interactive)
1923 (require 'gud)
1924 (perldb (read-from-minibuffer "Run perldb (like this): "
1925 (if (consp gud-perldb-history)
1926 (car gud-perldb-history)
1927 (concat "perl " ;;(file-name-nondirectory
1928 ;; I have problems
1929 ;; in OS/2
1930 ;; otherwise
1931 (buffer-file-name)))
1932 nil nil
1933 '(gud-perldb-history . 1))))
1935 (defun cperl-msb-fix ()
1936 ;; Adds perl files to msb menu, supposes that msb is already loaded
1937 (setq cperl-msb-fixed t)
1938 (let* ((l (length msb-menu-cond))
1939 (last (nth (1- l) msb-menu-cond))
1940 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
1941 (handle (1- (nth 1 last))))
1942 (setcdr precdr (list
1943 (list
1944 '(memq major-mode '(cperl-mode perl-mode))
1945 handle
1946 "Perl Files (%d)")
1947 last))))
1949 ;; This is used by indent-for-comment
1950 ;; to decide how much to indent a comment in CPerl code
1951 ;; based on its context. Do fallback if comment is found wrong.
1953 (defvar cperl-wrong-comment)
1954 (defvar cperl-st-cfence '(14)) ; Comment-fence
1955 (defvar cperl-st-sfence '(15)) ; String-fence
1956 (defvar cperl-st-punct '(1))
1957 (defvar cperl-st-word '(2))
1958 (defvar cperl-st-bra '(4 . ?\>))
1959 (defvar cperl-st-ket '(5 . ?\<))
1962 (defun cperl-comment-indent () ; called at point at supposed comment
1963 (let ((p (point)) (c (current-column)) was phony)
1964 (if (and (not cperl-indent-comment-at-column-0)
1965 (looking-at "^#"))
1966 0 ; Existing comment at bol stays there.
1967 ;; Wrong comment found
1968 (save-excursion
1969 (setq was (cperl-to-comment-or-eol)
1970 phony (eq (get-text-property (point) 'syntax-table)
1971 cperl-st-cfence))
1972 (if phony
1973 (progn ; Too naive???
1974 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
1975 (if (eq (preceding-char) ?\#)
1976 (forward-char -1))
1977 (setq was nil)))
1978 (if (= (point) p) ; Our caller found a correct place
1979 (progn
1980 (skip-chars-backward " \t")
1981 (setq was (current-column))
1982 (if (eq was 0)
1983 comment-column
1984 (max (1+ was) ; Else indent at comment column
1985 comment-column)))
1986 ;; No, the caller found a random place; we need to edit ourselves
1987 (if was nil
1988 (insert comment-start)
1989 (backward-char (length comment-start)))
1990 (setq cperl-wrong-comment t)
1991 (cperl-make-indent comment-column 1) ; Indent min 1
1992 c)))))
1994 ;;;(defun cperl-comment-indent-fallback ()
1995 ;;; "Is called if the standard comment-search procedure fails.
1996 ;;;Point is at start of real comment."
1997 ;;; (let ((c (current-column)) target cnt prevc)
1998 ;;; (if (= c comment-column) nil
1999 ;;; (setq cnt (skip-chars-backward "[ \t]"))
2000 ;;; (setq target (max (1+ (setq prevc
2001 ;;; (current-column))) ; Else indent at comment column
2002 ;;; comment-column))
2003 ;;; (if (= c comment-column) nil
2004 ;;; (delete-backward-char cnt)
2005 ;;; (while (< prevc target)
2006 ;;; (insert "\t")
2007 ;;; (setq prevc (current-column)))
2008 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
2009 ;;; (while (< prevc target)
2010 ;;; (insert " ")
2011 ;;; (setq prevc (current-column)))))))
2013 (defun cperl-indent-for-comment ()
2014 "Substitute for `indent-for-comment' in CPerl."
2015 (interactive)
2016 (let (cperl-wrong-comment)
2017 (indent-for-comment)
2018 (if cperl-wrong-comment ; set by `cperl-comment-indent'
2019 (progn (cperl-to-comment-or-eol)
2020 (forward-char (length comment-start))))))
2022 (defun cperl-comment-region (b e arg)
2023 "Comment or uncomment each line in the region in CPerl mode.
2024 See `comment-region'."
2025 (interactive "r\np")
2026 (let ((comment-start "#"))
2027 (comment-region b e arg)))
2029 (defun cperl-uncomment-region (b e arg)
2030 "Uncomment or comment each line in the region in CPerl mode.
2031 See `comment-region'."
2032 (interactive "r\np")
2033 (let ((comment-start "#"))
2034 (comment-region b e (- arg))))
2036 (defvar cperl-brace-recursing nil)
2038 (defun cperl-electric-brace (arg &optional only-before)
2039 "Insert character and correct line's indentation.
2040 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
2041 place (even in empty line), but not after. If after \")\" and the inserted
2042 char is \"{\", insert extra newline before only if
2043 `cperl-extra-newline-before-brace'."
2044 (interactive "P")
2045 (let (insertpos
2046 (other-end (if (and cperl-electric-parens-mark
2047 (cperl-mark-active)
2048 (< (mark) (point)))
2049 (mark)
2050 nil)))
2051 (if (and other-end
2052 (not cperl-brace-recursing)
2053 (cperl-val 'cperl-electric-parens)
2054 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
2055 ;; Need to insert a matching pair
2056 (progn
2057 (save-excursion
2058 (setq insertpos (point-marker))
2059 (goto-char other-end)
2060 (setq last-command-event ?\{)
2061 (cperl-electric-lbrace arg insertpos))
2062 (forward-char 1))
2063 ;; Check whether we close something "usual" with `}'
2064 (if (and (eq last-command-event ?\})
2065 (not
2066 (condition-case nil
2067 (save-excursion
2068 (up-list (- (prefix-numeric-value arg)))
2069 ;;(cperl-after-block-p (point-min))
2070 (or (cperl-after-expr-p nil "{;)")
2071 ;; after sub, else, continue
2072 (cperl-after-block-p nil 'pre)))
2073 (error nil))))
2074 ;; Just insert the guy
2075 (self-insert-command (prefix-numeric-value arg))
2076 (if (and (not arg) ; No args, end (of empty line or auto)
2077 (eolp)
2078 (or (and (null only-before)
2079 (save-excursion
2080 (skip-chars-backward " \t")
2081 (bolp)))
2082 (and (eq last-command-event ?\{) ; Do not insert newline
2083 ;; if after ")" and `cperl-extra-newline-before-brace'
2084 ;; is nil, do not insert extra newline.
2085 (not cperl-extra-newline-before-brace)
2086 (save-excursion
2087 (skip-chars-backward " \t")
2088 (eq (preceding-char) ?\))))
2089 (if cperl-auto-newline
2090 (progn (cperl-indent-line) (newline) t) nil)))
2091 (progn
2092 (self-insert-command (prefix-numeric-value arg))
2093 (cperl-indent-line)
2094 (if cperl-auto-newline
2095 (setq insertpos (1- (point))))
2096 (if (and cperl-auto-newline (null only-before))
2097 (progn
2098 (newline)
2099 (cperl-indent-line)))
2100 (save-excursion
2101 (if insertpos (progn (goto-char insertpos)
2102 (search-forward (make-string
2103 1 last-command-event))
2104 (setq insertpos (1- (point)))))
2105 (delete-char -1))))
2106 (if insertpos
2107 (save-excursion
2108 (goto-char insertpos)
2109 (self-insert-command (prefix-numeric-value arg)))
2110 (self-insert-command (prefix-numeric-value arg)))))))
2112 (defun cperl-electric-lbrace (arg &optional end)
2113 "Insert character, correct line's indentation, correct quoting by space."
2114 (interactive "P")
2115 (let ((cperl-brace-recursing t)
2116 (cperl-auto-newline cperl-auto-newline)
2117 (other-end (or end
2118 (if (and cperl-electric-parens-mark
2119 (cperl-mark-active)
2120 (> (mark) (point)))
2121 (save-excursion
2122 (goto-char (mark))
2123 (point-marker))
2124 nil)))
2125 pos after)
2126 (and (cperl-val 'cperl-electric-lbrace-space)
2127 (eq (preceding-char) ?$)
2128 (save-excursion
2129 (skip-chars-backward "$")
2130 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
2131 (insert ?\s))
2132 ;; Check whether we are in comment
2133 (if (and
2134 (save-excursion
2135 (beginning-of-line)
2136 (not (looking-at "[ \t]*#")))
2137 (cperl-after-expr-p nil "{;)"))
2139 (setq cperl-auto-newline nil))
2140 (cperl-electric-brace arg)
2141 (and (cperl-val 'cperl-electric-parens)
2142 (eq last-command-event ?{)
2143 (memq last-command-event
2144 (append cperl-electric-parens-string nil))
2145 (or (if other-end (goto-char (marker-position other-end)))
2147 (setq last-command-event ?} pos (point))
2148 (progn (cperl-electric-brace arg t)
2149 (goto-char pos)))))
2151 (defun cperl-electric-paren (arg)
2152 "Insert an opening parenthesis or a matching pair of parentheses.
2153 See `cperl-electric-parens'."
2154 (interactive "P")
2155 (let ((beg (point-at-bol))
2156 (other-end (if (and cperl-electric-parens-mark
2157 (cperl-mark-active)
2158 (> (mark) (point)))
2159 (save-excursion
2160 (goto-char (mark))
2161 (point-marker))
2162 nil)))
2163 (if (and (cperl-val 'cperl-electric-parens)
2164 (memq last-command-event
2165 (append cperl-electric-parens-string nil))
2166 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2167 ;;(not (save-excursion (search-backward "#" beg t)))
2168 (if (eq last-command-event ?<)
2169 (progn
2170 ;; This code is too electric, see Bug#3943.
2171 ;; (and abbrev-mode ; later it is too late, may be after `for'
2172 ;; (expand-abbrev))
2173 (cperl-after-expr-p nil "{;(,:="))
2175 (progn
2176 (self-insert-command (prefix-numeric-value arg))
2177 (if other-end (goto-char (marker-position other-end)))
2178 (insert (make-string
2179 (prefix-numeric-value arg)
2180 (cdr (assoc last-command-event '((?{ .?})
2181 (?[ . ?])
2182 (?( . ?))
2183 (?< . ?>))))))
2184 (forward-char (- (prefix-numeric-value arg))))
2185 (self-insert-command (prefix-numeric-value arg)))))
2187 (defun cperl-electric-rparen (arg)
2188 "Insert a matching pair of parentheses if marking is active.
2189 If not, or if we are not at the end of marking range, would self-insert.
2190 Affected by `cperl-electric-parens'."
2191 (interactive "P")
2192 (let ((beg (point-at-bol))
2193 (other-end (if (and cperl-electric-parens-mark
2194 (cperl-val 'cperl-electric-parens)
2195 (memq last-command-event
2196 (append cperl-electric-parens-string nil))
2197 (cperl-mark-active)
2198 (< (mark) (point)))
2199 (mark)
2200 nil))
2202 (if (and other-end
2203 (cperl-val 'cperl-electric-parens)
2204 (memq last-command-event '( ?\) ?\] ?\} ?\> ))
2205 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2206 ;;(not (save-excursion (search-backward "#" beg t)))
2208 (progn
2209 (self-insert-command (prefix-numeric-value arg))
2210 (setq p (point))
2211 (if other-end (goto-char other-end))
2212 (insert (make-string
2213 (prefix-numeric-value arg)
2214 (cdr (assoc last-command-event '((?\} . ?\{)
2215 (?\] . ?\[)
2216 (?\) . ?\()
2217 (?\> . ?\<))))))
2218 (goto-char (1+ p)))
2219 (self-insert-command (prefix-numeric-value arg)))))
2221 (defun cperl-electric-keyword ()
2222 "Insert a construction appropriate after a keyword.
2223 Help message may be switched off by setting `cperl-message-electric-keyword'
2224 to nil."
2225 (let ((beg (point-at-bol))
2226 (dollar (and (eq last-command-event ?$)
2227 (eq this-command 'self-insert-command)))
2228 (delete (and (memq last-command-event '(?\s ?\n ?\t ?\f))
2229 (memq this-command '(self-insert-command newline))))
2230 my do)
2231 (and (save-excursion
2232 (condition-case nil
2233 (progn
2234 (backward-sexp 1)
2235 (setq do (looking-at "do\\>")))
2236 (error nil))
2237 (cperl-after-expr-p nil "{;:"))
2238 (save-excursion
2239 (not
2240 (re-search-backward
2241 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2242 beg t)))
2243 (save-excursion (or (not (re-search-backward "^=" nil t))
2245 (looking-at "=cut")
2246 (and cperl-use-syntax-table-text-property
2247 (not (eq (get-text-property (point)
2248 'syntax-type)
2249 'pod))))))
2250 (save-excursion (forward-sexp -1)
2251 (not (memq (following-char) (append "$@%&*" nil))))
2252 (progn
2253 (and (eq (preceding-char) ?y)
2254 (progn ; "foreachmy"
2255 (forward-char -2)
2256 (insert " ")
2257 (forward-char 2)
2258 (setq my t dollar t
2259 delete
2260 (memq this-command '(self-insert-command newline)))))
2261 (and dollar (insert " $"))
2262 (cperl-indent-line)
2263 ;;(insert " () {\n}")
2264 (cond
2265 (cperl-extra-newline-before-brace
2266 (insert (if do "\n" " ()\n"))
2267 (insert "{")
2268 (cperl-indent-line)
2269 (insert "\n")
2270 (cperl-indent-line)
2271 (insert "\n}")
2272 (and do (insert " while ();")))
2274 (insert (if do " {\n} while ();" " () {\n}"))))
2275 (or (looking-at "[ \t]\\|$") (insert " "))
2276 (cperl-indent-line)
2277 (if dollar (progn (search-backward "$")
2278 (if my
2279 (forward-char 1)
2280 (delete-char 1)))
2281 (search-backward ")")
2282 (if (eq last-command-event ?\()
2283 (progn ; Avoid "if (())"
2284 (delete-backward-char 1)
2285 (delete-backward-char -1))))
2286 (if delete
2287 (cperl-putback-char cperl-del-back-ch))
2288 (if cperl-message-electric-keyword
2289 (message "Precede char by C-q to avoid expansion"))))))
2291 (defun cperl-ensure-newlines (n &optional pos)
2292 "Make sure there are N newlines after the point."
2293 (or pos (setq pos (point)))
2294 (if (looking-at "\n")
2295 (forward-char 1)
2296 (insert "\n"))
2297 (if (> n 1)
2298 (cperl-ensure-newlines (1- n) pos)
2299 (goto-char pos)))
2301 (defun cperl-electric-pod ()
2302 "Insert a POD chunk appropriate after a =POD directive."
2303 (let ((delete (and (memq last-command-event '(?\s ?\n ?\t ?\f))
2304 (memq this-command '(self-insert-command newline))))
2305 head1 notlast name p really-delete over)
2306 (and (save-excursion
2307 (forward-word -1)
2308 (and
2309 (eq (preceding-char) ?=)
2310 (progn
2311 (setq head1 (looking-at "head1\\>[ \t]*$"))
2312 (setq over (and (looking-at "over\\>[ \t]*$")
2313 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
2314 (forward-char -1)
2315 (bolp))
2317 (get-text-property (point) 'in-pod)
2318 (cperl-after-expr-p nil "{;:")
2319 (and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t)
2320 (not (looking-at "\n*=cut"))
2321 (or (not cperl-use-syntax-table-text-property)
2322 (eq (get-text-property (point) 'syntax-type) 'pod))))))
2323 (progn
2324 (save-excursion
2325 (setq notlast (re-search-forward "^\n=" nil t)))
2326 (or notlast
2327 (progn
2328 (insert "\n\n=cut")
2329 (cperl-ensure-newlines 2)
2330 (forward-word -2)
2331 (if (and head1
2332 (not
2333 (save-excursion
2334 (forward-char -1)
2335 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
2336 nil t)))) ; Only one
2337 (progn
2338 (forward-word 1)
2339 (setq name (file-name-base)
2340 p (point))
2341 (insert " NAME\n\n" name
2342 " - \n\n=head1 SYNOPSIS\n\n\n\n"
2343 "=head1 DESCRIPTION")
2344 (cperl-ensure-newlines 4)
2345 (goto-char p)
2346 (forward-word 2)
2347 (end-of-line)
2348 (setq really-delete t))
2349 (forward-word 1))))
2350 (if over
2351 (progn
2352 (setq p (point))
2353 (insert "\n\n=item \n\n\n\n"
2354 "=back")
2355 (cperl-ensure-newlines 2)
2356 (goto-char p)
2357 (forward-word 1)
2358 (end-of-line)
2359 (setq really-delete t)))
2360 (if (and delete really-delete)
2361 (cperl-putback-char cperl-del-back-ch))))))
2363 (defun cperl-electric-else ()
2364 "Insert a construction appropriate after a keyword.
2365 Help message may be switched off by setting `cperl-message-electric-keyword'
2366 to nil."
2367 (let ((beg (point-at-bol)))
2368 (and (save-excursion
2369 (backward-sexp 1)
2370 (cperl-after-expr-p nil "{;:"))
2371 (save-excursion
2372 (not
2373 (re-search-backward
2374 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2375 beg t)))
2376 (save-excursion (or (not (re-search-backward "^=" nil t))
2377 (looking-at "=cut")
2378 (and cperl-use-syntax-table-text-property
2379 (not (eq (get-text-property (point)
2380 'syntax-type)
2381 'pod)))))
2382 (progn
2383 (cperl-indent-line)
2384 ;;(insert " {\n\n}")
2385 (cond
2386 (cperl-extra-newline-before-brace
2387 (insert "\n")
2388 (insert "{")
2389 (cperl-indent-line)
2390 (insert "\n\n}"))
2392 (insert " {\n\n}")))
2393 (or (looking-at "[ \t]\\|$") (insert " "))
2394 (cperl-indent-line)
2395 (forward-line -1)
2396 (cperl-indent-line)
2397 (cperl-putback-char cperl-del-back-ch)
2398 (setq this-command 'cperl-electric-else)
2399 (if cperl-message-electric-keyword
2400 (message "Precede char by C-q to avoid expansion"))))))
2402 (defun cperl-linefeed ()
2403 "Go to end of line, open a new line and indent appropriately.
2404 If in POD, insert appropriate lines."
2405 (interactive)
2406 (let ((beg (point-at-bol))
2407 (end (point-at-eol))
2408 (pos (point)) start over cut res)
2409 (if (and ; Check if we need to split:
2410 ; i.e., on a boundary and inside "{...}"
2411 (save-excursion (cperl-to-comment-or-eol)
2412 (>= (point) pos)) ; Not in a comment
2413 (or (save-excursion
2414 (skip-chars-backward " \t" beg)
2415 (forward-char -1)
2416 (looking-at "[;{]")) ; After { or ; + spaces
2417 (looking-at "[ \t]*}") ; Before }
2418 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
2419 (save-excursion
2420 (and
2421 (eq (car (parse-partial-sexp pos end -1)) -1)
2422 ; Leave the level of parens
2423 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
2424 ; Are at end
2425 (cperl-after-block-p (point-min))
2426 (progn
2427 (backward-sexp 1)
2428 (setq start (point-marker))
2429 (<= start pos))))) ; Redundant? Are after the
2430 ; start of parens group.
2431 (progn
2432 (skip-chars-backward " \t")
2433 (or (memq (preceding-char) (append ";{" nil))
2434 (insert ";"))
2435 (insert "\n")
2436 (forward-line -1)
2437 (cperl-indent-line)
2438 (goto-char start)
2439 (or (looking-at "{[ \t]*$") ; If there is a statement
2440 ; before, move it to separate line
2441 (progn
2442 (forward-char 1)
2443 (insert "\n")
2444 (cperl-indent-line)))
2445 (forward-line 1) ; We are on the target line
2446 (cperl-indent-line)
2447 (beginning-of-line)
2448 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
2449 ; after, move it to separate line
2450 (progn
2451 (end-of-line)
2452 (search-backward "}" beg)
2453 (skip-chars-backward " \t")
2454 (or (memq (preceding-char) (append ";{" nil))
2455 (insert ";"))
2456 (insert "\n")
2457 (cperl-indent-line)
2458 (forward-line -1)))
2459 (forward-line -1) ; We are on the line before target
2460 (end-of-line)
2461 (newline-and-indent))
2462 (end-of-line) ; else - no splitting
2463 (cond
2464 ((and (looking-at "\n[ \t]*{$")
2465 (save-excursion
2466 (skip-chars-backward " \t")
2467 (eq (preceding-char) ?\)))) ; Probably if () {} group
2468 ; with an extra newline.
2469 (forward-line 2)
2470 (cperl-indent-line))
2471 ((save-excursion ; In POD header
2472 (forward-paragraph -1)
2473 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
2474 ;; We are after \n now, so look for the rest
2475 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
2476 (progn
2477 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
2478 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
2479 t)))
2480 (if (and over
2481 (progn
2482 (forward-paragraph -1)
2483 (forward-word 1)
2484 (setq pos (point))
2485 (setq cut (buffer-substring (point) (point-at-eol)))
2486 (delete-char (- (point-at-eol) (point)))
2487 (setq res (expand-abbrev))
2488 (save-excursion
2489 (goto-char pos)
2490 (insert cut))
2491 res))
2493 (cperl-ensure-newlines (if cut 2 4))
2494 (forward-line 2)))
2495 ((get-text-property (point) 'in-pod) ; In POD section
2496 (cperl-ensure-newlines 4)
2497 (forward-line 2))
2498 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
2499 (forward-line 1)
2500 (cperl-indent-line))
2502 (newline-and-indent))))))
2504 (defun cperl-electric-semi (arg)
2505 "Insert character and correct line's indentation."
2506 (interactive "P")
2507 (if cperl-auto-newline
2508 (cperl-electric-terminator arg)
2509 (self-insert-command (prefix-numeric-value arg))
2510 (if cperl-autoindent-on-semi
2511 (cperl-indent-line))))
2513 (defun cperl-electric-terminator (arg)
2514 "Insert character and correct line's indentation."
2515 (interactive "P")
2516 (let ((end (point))
2517 (auto (and cperl-auto-newline
2518 (or (not (eq last-command-event ?:))
2519 cperl-auto-newline-after-colon)))
2520 insertpos)
2521 (if (and ;;(not arg)
2522 (eolp)
2523 (not (save-excursion
2524 (beginning-of-line)
2525 (skip-chars-forward " \t")
2527 ;; Ignore in comment lines
2528 (= (following-char) ?#)
2529 ;; Colon is special only after a label
2530 ;; So quickly rule out most other uses of colon
2531 ;; and do no indentation for them.
2532 (and (eq last-command-event ?:)
2533 (save-excursion
2534 (forward-word 1)
2535 (skip-chars-forward " \t")
2536 (and (< (point) end)
2537 (progn (goto-char (- end 1))
2538 (not (looking-at ":"))))))
2539 (progn
2540 (beginning-of-defun)
2541 (let ((pps (parse-partial-sexp (point) end)))
2542 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
2543 (progn
2544 (self-insert-command (prefix-numeric-value arg))
2545 ;;(forward-char -1)
2546 (if auto (setq insertpos (point-marker)))
2547 ;;(forward-char 1)
2548 (cperl-indent-line)
2549 (if auto
2550 (progn
2551 (newline)
2552 (cperl-indent-line)))
2553 (save-excursion
2554 (if insertpos (goto-char (1- (marker-position insertpos)))
2555 (forward-char -1))
2556 (delete-char 1))))
2557 (if insertpos
2558 (save-excursion
2559 (goto-char insertpos)
2560 (self-insert-command (prefix-numeric-value arg)))
2561 (self-insert-command (prefix-numeric-value arg)))))
2563 (defun cperl-electric-backspace (arg)
2564 "Backspace, or remove whitespace around the point inserted by an electric key.
2565 Will untabify if `cperl-electric-backspace-untabify' is non-nil."
2566 (interactive "p")
2567 (if (and cperl-auto-newline
2568 (memq last-command '(cperl-electric-semi
2569 cperl-electric-terminator
2570 cperl-electric-lbrace))
2571 (memq (preceding-char) '(?\s ?\t ?\n)))
2572 (let (p)
2573 (if (eq last-command 'cperl-electric-lbrace)
2574 (skip-chars-forward " \t\n"))
2575 (setq p (point))
2576 (skip-chars-backward " \t\n")
2577 (delete-region (point) p))
2578 (and (eq last-command 'cperl-electric-else)
2579 ;; We are removing the whitespace *inside* cperl-electric-else
2580 (setq this-command 'cperl-electric-else-really))
2581 (if (and cperl-auto-newline
2582 (eq last-command 'cperl-electric-else-really)
2583 (memq (preceding-char) '(?\s ?\t ?\n)))
2584 (let (p)
2585 (skip-chars-forward " \t\n")
2586 (setq p (point))
2587 (skip-chars-backward " \t\n")
2588 (delete-region (point) p))
2589 (if cperl-electric-backspace-untabify
2590 (backward-delete-char-untabify arg)
2591 (delete-backward-char arg)))))
2593 (put 'cperl-electric-backspace 'delete-selection 'supersede)
2595 (defun cperl-inside-parens-p () ;; NOT USED????
2596 (condition-case ()
2597 (save-excursion
2598 (save-restriction
2599 (narrow-to-region (point)
2600 (progn (beginning-of-defun) (point)))
2601 (goto-char (point-max))
2602 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
2603 (error nil)))
2605 (defun cperl-indent-command (&optional whole-exp)
2606 "Indent current line as Perl code, or in some cases insert a tab character.
2607 If `cperl-tab-always-indent' is non-nil (the default), always indent current
2608 line. Otherwise, indent the current line only if point is at the left margin
2609 or in the line's indentation; otherwise insert a tab.
2611 A numeric argument, regardless of its value,
2612 means indent rigidly all the lines of the expression starting after point
2613 so that this line becomes properly indented.
2614 The relative indentation among the lines of the expression are preserved."
2615 (interactive "P")
2616 (cperl-update-syntaxification (point) (point))
2617 (if whole-exp
2618 ;; If arg, always indent this line as Perl
2619 ;; and shift remaining lines of expression the same amount.
2620 (let ((shift-amt (cperl-indent-line))
2621 beg end)
2622 (save-excursion
2623 (if cperl-tab-always-indent
2624 (beginning-of-line))
2625 (setq beg (point))
2626 (forward-sexp 1)
2627 (setq end (point))
2628 (goto-char beg)
2629 (forward-line 1)
2630 (setq beg (point)))
2631 (if (and shift-amt (> end beg))
2632 (indent-code-rigidly beg end shift-amt "#")))
2633 (if (and (not cperl-tab-always-indent)
2634 (save-excursion
2635 (skip-chars-backward " \t")
2636 (not (bolp))))
2637 (insert-tab)
2638 (cperl-indent-line))))
2640 (defun cperl-indent-line (&optional parse-data)
2641 "Indent current line as Perl code.
2642 Return the amount the indentation changed by."
2643 (let ((case-fold-search nil)
2644 (pos (- (point-max) (point)))
2645 indent i beg shift-amt)
2646 (setq indent (cperl-calculate-indent parse-data)
2647 i indent)
2648 (beginning-of-line)
2649 (setq beg (point))
2650 (cond ((or (eq indent nil) (eq indent t))
2651 (setq indent (current-indentation) i nil))
2652 ;;((eq indent t) ; Never?
2653 ;; (setq indent (cperl-calculate-indent-within-comment)))
2654 ;;((looking-at "[ \t]*#")
2655 ;; (setq indent 0))
2657 (skip-chars-forward " \t")
2658 (if (listp indent) (setq indent (car indent)))
2659 (cond ((and (looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
2660 (not (looking-at "[smy]:\\|tr:")))
2661 (and (> indent 0)
2662 (setq indent (max cperl-min-label-indent
2663 (+ indent cperl-label-offset)))))
2664 ((= (following-char) ?})
2665 (setq indent (- indent cperl-indent-level)))
2666 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
2667 (setq indent (+ indent cperl-close-paren-offset)))
2668 ((= (following-char) ?{)
2669 (setq indent (+ indent cperl-brace-offset))))))
2670 (skip-chars-forward " \t")
2671 (setq shift-amt (and i (- indent (current-column))))
2672 (if (or (not shift-amt)
2673 (zerop shift-amt))
2674 (if (> (- (point-max) pos) (point))
2675 (goto-char (- (point-max) pos)))
2676 ;;;(delete-region beg (point))
2677 ;;;(indent-to indent)
2678 (cperl-make-indent indent)
2679 ;; If initial point was within line's indentation,
2680 ;; position after the indentation. Else stay at same point in text.
2681 (if (> (- (point-max) pos) (point))
2682 (goto-char (- (point-max) pos))))
2683 shift-amt))
2685 (defun cperl-after-label ()
2686 ;; Returns true if the point is after label. Does not do save-excursion.
2687 (and (eq (preceding-char) ?:)
2688 (memq (char-syntax (char-after (- (point) 2)))
2689 '(?w ?_))
2690 (progn
2691 (backward-sexp)
2692 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
2694 (defun cperl-get-state (&optional parse-start start-state)
2695 ;; returns list (START STATE DEPTH PRESTART),
2696 ;; START is a good place to start parsing, or equal to
2697 ;; PARSE-START if preset,
2698 ;; STATE is what is returned by `parse-partial-sexp'.
2699 ;; DEPTH is true is we are immediately after end of block
2700 ;; which contains START.
2701 ;; PRESTART is the position basing on which START was found.
2702 (save-excursion
2703 (let ((start-point (point)) depth state start prestart)
2704 (if (and parse-start
2705 (<= parse-start start-point))
2706 (goto-char parse-start)
2707 (beginning-of-defun)
2708 (setq start-state nil))
2709 (setq prestart (point))
2710 (if start-state nil
2711 ;; Try to go out, if sub is not on the outermost level
2712 (while (< (point) start-point)
2713 (setq start (point) parse-start start depth nil
2714 state (parse-partial-sexp start start-point -1))
2715 (if (> (car state) -1) nil
2716 ;; The current line could start like }}}, so the indentation
2717 ;; corresponds to a different level than what we reached
2718 (setq depth t)
2719 (beginning-of-line 2))) ; Go to the next line.
2720 (if start (goto-char start))) ; Not at the start of file
2721 (setq start (point))
2722 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
2723 (list start state depth prestart))))
2725 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
2727 (defun cperl-beginning-of-property (p prop &optional lim)
2728 "Given that P has a property PROP, find where the property starts.
2729 Will not look before LIM."
2730 ;;; XXXX What to do at point-max???
2731 (or (previous-single-property-change (cperl-1+ p) prop lim)
2732 (point-min))
2733 ;;; (cond ((eq p (point-min))
2734 ;;; p)
2735 ;;; ((and lim (<= p lim))
2736 ;;; p)
2737 ;;; ((not (get-text-property (1- p) prop))
2738 ;;; p)
2739 ;;; (t (or (previous-single-property-change p look-prop lim)
2740 ;;; (point-min))))
2743 (defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start
2744 ;; the sniffer logic to understand what the current line MEANS.
2745 (cperl-update-syntaxification (point) (point))
2746 (let ((res (get-text-property (point) 'syntax-type)))
2747 (save-excursion
2748 (cond
2749 ((and (memq res '(pod here-doc here-doc-delim format))
2750 (not (get-text-property (point) 'indentable)))
2751 (vector res))
2752 ;; before start of POD - whitespace found since do not have 'pod!
2753 ((looking-at "[ \t]*\n=")
2754 (error "Spaces before POD section!"))
2755 ((and (not cperl-indent-left-aligned-comments)
2756 (looking-at "^#"))
2757 [comment-special:at-beginning-of-line])
2758 ((get-text-property (point) 'in-pod)
2759 [in-pod])
2761 (beginning-of-line)
2762 (let* ((indent-point (point))
2763 (char-after-pos (save-excursion
2764 (skip-chars-forward " \t")
2765 (point)))
2766 (char-after (char-after char-after-pos))
2767 (pre-indent-point (point))
2768 p prop look-prop is-block delim)
2769 (save-excursion ; Know we are not in POD, find appropriate pos before
2770 (cperl-backward-to-noncomment nil)
2771 (setq p (max (point-min) (1- (point)))
2772 prop (get-text-property p 'syntax-type)
2773 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
2774 'syntax-type))
2775 (if (memq prop '(pod here-doc format here-doc-delim))
2776 (progn
2777 (goto-char (cperl-beginning-of-property p look-prop))
2778 (beginning-of-line)
2779 (setq pre-indent-point (point)))))
2780 (goto-char pre-indent-point) ; Orig line skipping preceding pod/etc
2781 (let* ((case-fold-search nil)
2782 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
2783 (start (or (nth 2 parse-data) ; last complete sexp terminated
2784 (nth 0 s-s))) ; Good place to start parsing
2785 (state (nth 1 s-s))
2786 (containing-sexp (car (cdr state)))
2787 old-indent)
2788 (if (and
2789 ;;containing-sexp ;; We are buggy at toplevel :-(
2790 parse-data)
2791 (progn
2792 (setcar parse-data pre-indent-point)
2793 (setcar (cdr parse-data) state)
2794 (or (nth 2 parse-data)
2795 (setcar (cddr parse-data) start))
2796 ;; Before this point: end of statement
2797 (setq old-indent (nth 3 parse-data))))
2798 (cond ((get-text-property (point) 'indentable)
2799 ;; indent to "after" the surrounding open
2800 ;; (same offset as `cperl-beautify-regexp-piece'),
2801 ;; skip blanks if we do not close the expression.
2802 (setq delim ; We do not close the expression
2803 (get-text-property
2804 (cperl-1+ char-after-pos) 'indentable)
2805 p (1+ (cperl-beginning-of-property
2806 (point) 'indentable))
2807 is-block ; misused for: preceding line in REx
2808 (save-excursion ; Find preceding line
2809 (cperl-backward-to-noncomment p)
2810 (beginning-of-line)
2811 (if (<= (point) p)
2812 (progn ; get indent from the first line
2813 (goto-char p)
2814 (skip-chars-forward " \t")
2815 (if (memq (char-after (point))
2816 (append "#\n" nil))
2817 nil ; Can't use indentation of this line...
2818 (point)))
2819 (skip-chars-forward " \t")
2820 (point)))
2821 prop (parse-partial-sexp p char-after-pos))
2822 (cond ((not delim) ; End the REx, ignore is-block
2823 (vector 'indentable 'terminator p is-block))
2824 (is-block ; Indent w.r.t. preceding line
2825 (vector 'indentable 'cont-line char-after-pos
2826 is-block char-after p))
2827 (t ; No preceding line...
2828 (vector 'indentable 'first-line p))))
2829 ((get-text-property char-after-pos 'REx-part2)
2830 (vector 'REx-part2 (point)))
2831 ((nth 4 state)
2832 [comment])
2833 ((nth 3 state)
2834 [string])
2835 ;; XXXX Do we need to special-case this?
2836 ((null containing-sexp)
2837 ;; Line is at top level. May be data or function definition,
2838 ;; or may be function argument declaration.
2839 ;; Indent like the previous top level line
2840 ;; unless that ends in a closeparen without semicolon,
2841 ;; in which case this line is the first argument decl.
2842 (skip-chars-forward " \t")
2843 (cperl-backward-to-noncomment (or old-indent (point-min)))
2844 (setq state
2845 (or (bobp)
2846 (eq (point) old-indent) ; old-indent was at comment
2847 (eq (preceding-char) ?\;)
2848 ;; Had ?\) too
2849 (and (eq (preceding-char) ?\})
2850 (cperl-after-block-and-statement-beg
2851 (point-min))) ; Was start - too close
2852 (memq char-after (append ")]}" nil))
2853 (and (eq (preceding-char) ?\:) ; label
2854 (progn
2855 (forward-sexp -1)
2856 (skip-chars-backward " \t")
2857 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
2858 (get-text-property (point) 'first-format-line)))
2860 ;; Look at previous line that's at column 0
2861 ;; to determine whether we are in top-level decls
2862 ;; or function's arg decls. Set basic-indent accordingly.
2863 ;; Now add a little if this is a continuation line.
2864 (and state
2865 parse-data
2866 (not (eq char-after ?\C-j))
2867 (setcdr (cddr parse-data)
2868 (list pre-indent-point)))
2869 (vector 'toplevel start char-after state (nth 2 s-s)))
2870 ((not
2871 (or (setq is-block
2872 (and (setq delim (= (char-after containing-sexp) ?{))
2873 (save-excursion ; Is it a hash?
2874 (goto-char containing-sexp)
2875 (cperl-block-p))))
2876 cperl-indent-parens-as-block))
2877 ;; group is an expression, not a block:
2878 ;; indent to just after the surrounding open parens,
2879 ;; skip blanks if we do not close the expression.
2880 (goto-char (1+ containing-sexp))
2881 (or (memq char-after
2882 (append (if delim "}" ")]}") nil))
2883 (looking-at "[ \t]*\\(#\\|$\\)")
2884 (skip-chars-forward " \t"))
2885 (setq old-indent (point)) ; delim=is-brace
2886 (vector 'in-parens char-after (point) delim containing-sexp))
2888 ;; Statement level. Is it a continuation or a new statement?
2889 ;; Find previous non-comment character.
2890 (goto-char pre-indent-point) ; Skip one level of POD/etc
2891 (cperl-backward-to-noncomment containing-sexp)
2892 ;; Back up over label lines, since they don't
2893 ;; affect whether our line is a continuation.
2894 ;; (Had \, too)
2895 (while;;(or (eq (preceding-char) ?\,)
2896 (and (eq (preceding-char) ?:)
2897 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
2898 (memq (char-syntax (char-after (- (point) 2)))
2899 '(?w ?_))))
2901 ;; This is always FALSE?
2902 (if (eq (preceding-char) ?\,)
2903 ;; Will go to beginning of line, essentially.
2904 ;; Will ignore embedded sexpr XXXX.
2905 (cperl-backward-to-start-of-continued-exp containing-sexp))
2906 (beginning-of-line)
2907 (cperl-backward-to-noncomment containing-sexp))
2908 ;; Now we get non-label preceding the indent point
2909 (if (not (or (eq (1- (point)) containing-sexp)
2910 (memq (preceding-char)
2911 (append (if is-block " ;{" " ,;{") '(nil)))
2912 (and (eq (preceding-char) ?\})
2913 (cperl-after-block-and-statement-beg
2914 containing-sexp))
2915 (get-text-property (point) 'first-format-line)))
2916 ;; This line is continuation of preceding line's statement;
2917 ;; indent `cperl-continued-statement-offset' more than the
2918 ;; previous line of the statement.
2920 ;; There might be a label on this line, just
2921 ;; consider it bad style and ignore it.
2922 (progn
2923 (cperl-backward-to-start-of-continued-exp containing-sexp)
2924 (vector 'continuation (point) char-after is-block delim))
2925 ;; This line starts a new statement.
2926 ;; Position following last unclosed open brace
2927 (goto-char containing-sexp)
2928 ;; Is line first statement after an open-brace?
2930 ;; If no, find that first statement and indent like
2931 ;; it. If the first statement begins with label, do
2932 ;; not believe when the indentation of the label is too
2933 ;; small.
2934 (save-excursion
2935 (forward-char 1)
2936 (let ((colon-line-end 0))
2937 (while
2938 (progn (skip-chars-forward " \t\n")
2939 ;; s: foo : bar :x is NOT label
2940 (and (looking-at "#\\|\\([a-zA-Z0-9_$]+\\):[^:]\\|=[a-zA-Z]")
2941 (not (looking-at "[sym]:\\|tr:"))))
2942 ;; Skip over comments and labels following openbrace.
2943 (cond ((= (following-char) ?\#)
2944 (forward-line 1))
2945 ((= (following-char) ?\=)
2946 (goto-char
2947 (or (next-single-property-change (point) 'in-pod)
2948 (point-max)))) ; do not loop if no syntaxification
2949 ;; label:
2951 (setq colon-line-end (point-at-eol))
2952 (search-forward ":"))))
2953 ;; We are at beginning of code (NOT label or comment)
2954 ;; First, the following code counts
2955 ;; if it is before the line we want to indent.
2956 (and (< (point) indent-point)
2957 (vector 'have-prev-sibling (point) colon-line-end
2958 containing-sexp))))
2959 (progn
2960 ;; If no previous statement,
2961 ;; indent it relative to line brace is on.
2963 ;; For open-braces not the first thing in a line,
2964 ;; add in cperl-brace-imaginary-offset.
2966 ;; If first thing on a line: ?????
2967 ;; Move back over whitespace before the openbrace.
2968 (setq ; brace first thing on a line
2969 old-indent (progn (skip-chars-backward " \t") (bolp)))
2970 ;; Should we indent w.r.t. earlier than start?
2971 ;; Move to start of control group, possibly on a different line
2972 (or cperl-indent-wrt-brace
2973 (cperl-backward-to-noncomment (point-min)))
2974 ;; If the openbrace is preceded by a parenthesized exp,
2975 ;; move to the beginning of that;
2976 (if (eq (preceding-char) ?\))
2977 (progn
2978 (forward-sexp -1)
2979 (cperl-backward-to-noncomment (point-min))))
2980 ;; In the case it starts a subroutine, indent with
2981 ;; respect to `sub', not with respect to the
2982 ;; first thing on the line, say in the case of
2983 ;; anonymous sub in a hash.
2984 (if (and;; Is it a sub in group starting on this line?
2985 (cond ((get-text-property (point) 'attrib-group)
2986 (goto-char (cperl-beginning-of-property
2987 (point) 'attrib-group)))
2988 ((eq (preceding-char) ?b)
2989 (forward-sexp -1)
2990 (looking-at "sub\\>")))
2991 (setq p (nth 1 ; start of innermost containing list
2992 (parse-partial-sexp
2993 (point-at-bol)
2994 (point)))))
2995 (progn
2996 (goto-char (1+ p)) ; enclosing block on the same line
2997 (skip-chars-forward " \t")
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 t (point) ; have something before...
3003 ;;(current-column)
3005 ;; Get initial indentation of the line we are on.
3006 ;; If line starts with label, calculate label indentation
3007 (vector 'code-start-in-block containing-sexp char-after
3008 (and delim (not is-block)) ; is a HASH
3009 old-indent ; brace first thing on a line
3010 nil (point))))))))))))))) ; nothing interesting before
3012 (defvar cperl-indent-rules-alist
3013 '((pod nil) ; via `syntax-type' property
3014 (here-doc nil) ; via `syntax-type' property
3015 (here-doc-delim nil) ; via `syntax-type' property
3016 (format nil) ; via `syntax-type' property
3017 (in-pod nil) ; via `in-pod' property
3018 (comment-special:at-beginning-of-line nil)
3019 (string t)
3020 (comment nil))
3021 "Alist of indentation rules for CPerl mode.
3022 The values mean:
3023 nil: do not indent;
3024 number: add this amount of indentation.")
3026 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
3027 "Return appropriate indentation for current line as Perl code.
3028 In usual case returns an integer: the column to indent to.
3029 Returns nil if line starts inside a string, t if in a comment.
3031 Will not correct the indentation for labels, but will correct it for braces
3032 and closing parentheses and brackets."
3033 ;; This code is still a broken architecture: in some cases we need to
3034 ;; compensate for some modifications which `cperl-indent-line' will add later
3035 (save-excursion
3036 (let ((i (cperl-sniff-for-indent parse-data)) what p)
3037 (cond
3038 ;;((or (null i) (eq i t) (numberp i))
3039 ;; i)
3040 ((vectorp i)
3041 (setq what (assoc (elt i 0) cperl-indent-rules-alist))
3042 (cond
3043 (what (cadr what)) ; Load from table
3045 ;; Indenters for regular expressions with //x and qw()
3047 ((eq 'REx-part2 (elt i 0)) ;; [self start] start of /REP in s//REP/x
3048 (goto-char (elt i 1))
3049 (condition-case nil ; Use indentation of the 1st part
3050 (forward-sexp -1))
3051 (current-column))
3052 ((eq 'indentable (elt i 0)) ; Indenter for REGEXP qw() etc
3053 (cond ;;; [indentable terminator start-pos is-block]
3054 ((eq 'terminator (elt i 1)) ; Lone terminator of "indentable string"
3055 (goto-char (elt i 2)) ; After opening parens
3056 (1- (current-column)))
3057 ((eq 'first-line (elt i 1)); [indentable first-line start-pos]
3058 (goto-char (elt i 2))
3059 (+ (or cperl-regexp-indent-step cperl-indent-level)
3061 (current-column)))
3062 ((eq 'cont-line (elt i 1)); [indentable cont-line pos prev-pos first-char start-pos]
3063 ;; Indent as the level after closing parens
3064 (goto-char (elt i 2)) ; indent line
3065 (skip-chars-forward " \t)") ; Skip closing parens
3066 (setq p (point))
3067 (goto-char (elt i 3)) ; previous line
3068 (skip-chars-forward " \t)") ; Skip closing parens
3069 ;; Number of parens in between:
3070 (setq p (nth 0 (parse-partial-sexp (point) p))
3071 what (elt i 4)) ; First char on current line
3072 (goto-char (elt i 3)) ; previous line
3073 (+ (* p (or cperl-regexp-indent-step cperl-indent-level))
3074 (cond ((eq what ?\) )
3075 (- cperl-close-paren-offset)) ; compensate
3076 ((eq what ?\| )
3077 (- (or cperl-regexp-indent-step cperl-indent-level)))
3078 (t 0))
3079 (if (eq (following-char) ?\| )
3080 (or cperl-regexp-indent-step cperl-indent-level)
3082 (current-column)))
3084 (error "Unrecognized value of indent: %s" i))))
3086 ;; Indenter for stuff at toplevel
3088 ((eq 'toplevel (elt i 0)) ;; [toplevel start char-after state immed-after-block]
3089 (+ (save-excursion ; To beg-of-defun, or end of last sexp
3090 (goto-char (elt i 1)) ; start = Good place to start parsing
3091 (- (current-indentation) ;
3092 (if (elt i 4) cperl-indent-level 0))) ; immed-after-block
3093 (if (eq (elt i 2) ?{) cperl-continued-brace-offset 0) ; char-after
3094 ;; Look at previous line that's at column 0
3095 ;; to determine whether we are in top-level decls
3096 ;; or function's arg decls. Set basic-indent accordingly.
3097 ;; Now add a little if this is a continuation line.
3098 (if (elt i 3) ; state (XXX What is the semantic???)
3100 cperl-continued-statement-offset)))
3102 ;; Indenter for stuff in "parentheses" (or brackets, braces-as-hash)
3104 ((eq 'in-parens (elt i 0))
3105 ;; in-parens char-after old-indent-point is-brace containing-sexp
3107 ;; group is an expression, not a block:
3108 ;; indent to just after the surrounding open parens,
3109 ;; skip blanks if we do not close the expression.
3110 (+ (progn
3111 (goto-char (elt i 2)) ; old-indent-point
3112 (current-column))
3113 (if (and (elt i 3) ; is-brace
3114 (eq (elt i 1) ?\})) ; char-after
3115 ;; Correct indentation of trailing ?\}
3116 (+ cperl-indent-level cperl-close-paren-offset)
3117 0)))
3119 ;; Indenter for continuation lines
3121 ((eq 'continuation (elt i 0))
3122 ;; [continuation statement-start char-after is-block is-brace]
3123 (goto-char (elt i 1)) ; statement-start
3124 (+ (if (or (memq (elt i 2) (append "}])" nil)) ; char-after
3125 (eq 'continuation ; do not stagger continuations
3126 (elt (cperl-sniff-for-indent parse-data) 0)))
3127 0 ; Closing parenthesis or continuation of a continuation
3128 cperl-continued-statement-offset)
3129 (if (or (elt i 3) ; is-block
3130 (not (elt i 4)) ; is-brace
3131 (not (eq (elt i 2) ?\}))) ; char-after
3133 ;; Now it is a hash reference
3134 (+ cperl-indent-level cperl-close-paren-offset))
3135 ;; Labels do not take :: ...
3136 (if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
3137 (if (> (current-indentation) cperl-min-label-indent)
3138 (- (current-indentation) cperl-label-offset)
3139 ;; Do not move `parse-data', this should
3140 ;; be quick anyway (this comment comes
3141 ;; from different location):
3142 (cperl-calculate-indent))
3143 (current-column))
3144 (if (eq (elt i 2) ?\{) ; char-after
3145 cperl-continued-brace-offset 0)))
3147 ;; Indenter for lines in a block which are not leading lines
3149 ((eq 'have-prev-sibling (elt i 0))
3150 ;; [have-prev-sibling sibling-beg colon-line-end block-start]
3151 (goto-char (elt i 1)) ; sibling-beg
3152 (if (> (elt i 2) (point)) ; colon-line-end; have label before point
3153 (if (> (current-indentation)
3154 cperl-min-label-indent)
3155 (- (current-indentation) cperl-label-offset)
3156 ;; Do not believe: `max' was involved in calculation of indent
3157 (+ cperl-indent-level
3158 (save-excursion
3159 (goto-char (elt i 3)) ; block-start
3160 (current-indentation))))
3161 (current-column)))
3163 ;; Indenter for the first line in a block
3165 ((eq 'code-start-in-block (elt i 0))
3166 ;;[code-start-in-block before-brace char-after
3167 ;; is-a-HASH-ref brace-is-first-thing-on-a-line
3168 ;; group-starts-before-start-of-sub start-of-control-group]
3169 (goto-char (elt i 1))
3170 ;; For open brace in column zero, don't let statement
3171 ;; start there too. If cperl-indent-level=0,
3172 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3173 (+ (if (and (bolp) (zerop cperl-indent-level))
3174 (+ cperl-brace-offset cperl-continued-statement-offset)
3175 cperl-indent-level)
3176 (if (and (elt i 3) ; is-a-HASH-ref
3177 (eq (elt i 2) ?\})) ; char-after: End of a hash reference
3178 (+ cperl-indent-level cperl-close-paren-offset)
3180 ;; Unless openbrace is the first nonwhite thing on the line,
3181 ;; add the cperl-brace-imaginary-offset.
3182 (if (elt i 4) 0 ; brace-is-first-thing-on-a-line
3183 cperl-brace-imaginary-offset)
3184 (progn
3185 (goto-char (elt i 6)) ; start-of-control-group
3186 (if (elt i 5) ; group-starts-before-start-of-sub
3187 (current-column)
3188 ;; Get initial indentation of the line we are on.
3189 ;; If line starts with label, calculate label indentation
3190 (if (save-excursion
3191 (beginning-of-line)
3192 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3193 (if (> (current-indentation) cperl-min-label-indent)
3194 (- (current-indentation) cperl-label-offset)
3195 ;; Do not move `parse-data', this should
3196 ;; be quick anyway:
3197 (cperl-calculate-indent))
3198 (current-indentation))))))
3200 (error "Unrecognized value of indent: %s" i))))
3202 (error "Got strange value of indent: %s" i))))))
3204 (defun cperl-calculate-indent-within-comment ()
3205 "Return the indentation amount for line, assuming that
3206 the current line is to be regarded as part of a block comment."
3207 (let (end star-start)
3208 (save-excursion
3209 (beginning-of-line)
3210 (skip-chars-forward " \t")
3211 (setq end (point))
3212 (and (= (following-char) ?#)
3213 (forward-line -1)
3214 (cperl-to-comment-or-eol)
3215 (setq end (point)))
3216 (goto-char end)
3217 (current-column))))
3220 (defun cperl-to-comment-or-eol ()
3221 "Go to position before comment on the current line, or to end of line.
3222 Returns true if comment is found. In POD will not move the point."
3223 ;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
3224 ;; then looks for literal # or end-of-line.
3225 (let (state stop-in cpoint (lim (point-at-eol)) pr e)
3226 (or cperl-font-locking
3227 (cperl-update-syntaxification lim lim))
3228 (beginning-of-line)
3229 (if (setq pr (get-text-property (point) 'syntax-type))
3230 (setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
3231 (if (or (eq pr 'pod)
3232 (if (or (not e) (> e lim)) ; deep inside a group
3233 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
3234 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
3235 ;; Else - need to do it the hard way
3236 (and (and e (<= e lim))
3237 (goto-char e))
3238 (while (not stop-in)
3239 (setq state (parse-partial-sexp (point) lim nil nil nil t))
3240 ; stop at comment
3241 ;; If fails (beginning-of-line inside sexp), then contains not-comment
3242 (if (nth 4 state) ; After `#';
3243 ; (nth 2 state) can be
3244 ; beginning of m,s,qq and so
3245 ; on
3246 (if (nth 2 state)
3247 (progn
3248 (setq cpoint (point))
3249 (goto-char (nth 2 state))
3250 (cond
3251 ((looking-at "\\(s\\|tr\\)\\>")
3252 (or (re-search-forward
3253 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
3254 lim 'move)
3255 (setq stop-in t)))
3256 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
3257 (or (re-search-forward
3258 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
3259 lim 'move)
3260 (setq stop-in t)))
3261 (t ; It was fair comment
3262 (setq stop-in t) ; Finish
3263 (goto-char (1- cpoint)))))
3264 (setq stop-in t) ; Finish
3265 (forward-char -1))
3266 (setq stop-in t))) ; Finish
3267 (nth 4 state))))
3269 (defsubst cperl-modify-syntax-type (at how)
3270 (if (< at (point-max))
3271 (progn
3272 (put-text-property at (1+ at) 'syntax-table how)
3273 (put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
3275 (defun cperl-protect-defun-start (s e)
3276 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
3277 (save-excursion
3278 (goto-char s)
3279 (while (re-search-forward "^\\s(" e 'to-end)
3280 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
3282 (defun cperl-commentify (bb e string &optional noface)
3283 (if cperl-use-syntax-table-text-property
3284 (if (eq noface 'n) ; Only immediate
3286 ;; We suppose that e is _after_ the end of construction, as after eol.
3287 (setq string (if string cperl-st-sfence cperl-st-cfence))
3288 (if (> bb (- e 2))
3289 ;; one-char string/comment?!
3290 (cperl-modify-syntax-type bb cperl-st-punct)
3291 (cperl-modify-syntax-type bb string)
3292 (cperl-modify-syntax-type (1- e) string))
3293 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
3294 (put-text-property (1+ bb) (1- e)
3295 'syntax-table cperl-string-syntax-table))
3296 (cperl-protect-defun-start bb e))
3297 ;; Fontify
3298 (or noface
3299 (not cperl-pod-here-fontify)
3300 (put-text-property bb e 'face (if string 'font-lock-string-face
3301 'font-lock-comment-face)))))
3303 (defvar cperl-starters '(( ?\( . ?\) )
3304 ( ?\[ . ?\] )
3305 ( ?\{ . ?\} )
3306 ( ?\< . ?\> )))
3308 (defun cperl-cached-syntax-table (st)
3309 "Get a syntax table cached in ST, or create and cache into ST a syntax table.
3310 All the entries of the syntax table are \".\", except for a backslash, which
3311 is quoting."
3312 (if (car-safe st)
3313 (car st)
3314 (setcar st (make-syntax-table))
3315 (setq st (car st))
3316 (let ((i 0))
3317 (while (< i 256)
3318 (modify-syntax-entry i "." st)
3319 (setq i (1+ i))))
3320 (modify-syntax-entry ?\\ "\\" st)
3321 st))
3323 (defun cperl-forward-re (lim end is-2arg st-l err-l argument
3324 &optional ostart oend)
3325 "Find the end of a regular expression or a stringish construct (q[] etc).
3326 The point should be before the starting delimiter.
3328 Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
3329 is s/// or tr/// like expression. If END is nil, generates an error
3330 message if needed. If SET-ST is non-nil, will use (or generate) a
3331 cached syntax table in ST-L. If ERR-L is non-nil, will store the
3332 error message in its CAR (unless it already contains some error
3333 message). ARGUMENT should be the name of the construct (used in error
3334 messages). OSTART, OEND may be set in recursive calls when processing
3335 the second argument of 2ARG construct.
3337 Works *before* syntax recognition is done. In IS-2ARG situation may
3338 modify syntax-type text property if the situation is too hard."
3339 (let (b starter ender st i i2 go-forward reset-st set-st)
3340 (skip-chars-forward " \t")
3341 ;; ender means matching-char matcher.
3342 (setq b (point)
3343 starter (if (eobp) 0 (char-after b))
3344 ender (cdr (assoc starter cperl-starters)))
3345 ;; What if starter == ?\\ ????
3346 (setq st (cperl-cached-syntax-table st-l))
3347 (setq set-st t)
3348 ;; Whether we have an intermediate point
3349 (setq i nil)
3350 ;; Prepare the syntax table:
3351 (if (not ender) ; m/blah/, s/x//, s/x/y/
3352 (modify-syntax-entry starter "$" st)
3353 (modify-syntax-entry starter (concat "(" (list ender)) st)
3354 (modify-syntax-entry ender (concat ")" (list starter)) st))
3355 (condition-case bb
3356 (progn
3357 ;; We use `$' syntax class to find matching stuff, but $$
3358 ;; is recognized the same as $, so we need to check this manually.
3359 (if (and (eq starter (char-after (cperl-1+ b)))
3360 (not ender))
3361 ;; $ has TeXish matching rules, so $$ equiv $...
3362 (forward-char 2)
3363 (setq reset-st (syntax-table))
3364 (set-syntax-table st)
3365 (forward-sexp 1)
3366 (if (<= (point) (1+ b))
3367 (error "Unfinished regular expression"))
3368 (set-syntax-table reset-st)
3369 (setq reset-st nil)
3370 ;; Now the problem is with m;blah;;
3371 (and (not ender)
3372 (eq (preceding-char)
3373 (char-after (- (point) 2)))
3374 (save-excursion
3375 (forward-char -2)
3376 (= 0 (% (skip-chars-backward "\\\\") 2)))
3377 (forward-char -1)))
3378 ;; Now we are after the first part.
3379 (and is-2arg ; Have trailing part
3380 (not ender)
3381 (eq (following-char) starter) ; Empty trailing part
3382 (progn
3383 (or (eq (char-syntax (following-char)) ?.)
3384 ;; Make trailing letter into punctuation
3385 (cperl-modify-syntax-type (point) cperl-st-punct))
3386 (setq is-2arg nil go-forward t))) ; Ignore the tail
3387 (if is-2arg ; Not number => have second part
3388 (progn
3389 (setq i (point) i2 i)
3390 (if ender
3391 (if (memq (following-char) '(?\s ?\t ?\n ?\f))
3392 (progn
3393 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3394 (goto-char (match-end 0))
3395 (skip-chars-forward " \t\n\f"))
3396 (setq i2 (point))))
3397 (forward-char -1))
3398 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3399 (if ender (modify-syntax-entry ender "." st))
3400 (setq set-st nil)
3401 (setq ender (cperl-forward-re lim end nil st-l err-l
3402 argument starter ender)
3403 ender (nth 2 ender)))))
3404 (error (goto-char lim)
3405 (setq set-st nil)
3406 (if reset-st
3407 (set-syntax-table reset-st))
3408 (or end
3409 (and cperl-brace-recursing
3410 (or (eq ostart ?\{)
3411 (eq starter ?\{)))
3412 (message
3413 "End of `%s%s%c ... %c' string/RE not found: %s"
3414 argument
3415 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
3416 starter (or ender starter) bb)
3417 (or (car err-l) (setcar err-l b)))))
3418 (if set-st
3419 (progn
3420 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3421 (if ender (modify-syntax-entry ender "." st))))
3422 ;; i: have 2 args, after end of the first arg
3423 ;; i2: start of the second arg, if any (before delim if `ender').
3424 ;; ender: the last arg bounded by parens-like chars, the second one of them
3425 ;; starter: the starting delimiter of the first arg
3426 ;; go-forward: has 2 args, and the second part is empty
3427 (list i i2 ender starter go-forward)))
3429 (defun cperl-forward-group-in-re (&optional st-l)
3430 "Find the end of a group in a REx.
3431 Return the error message (if any). Does not work if delimiter is `)'.
3432 Works before syntax recognition is done."
3433 ;; Works *before* syntax recognition is done
3434 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3435 (let (st b reset-st)
3436 (condition-case b
3437 (progn
3438 (setq st (cperl-cached-syntax-table st-l))
3439 (modify-syntax-entry ?\( "()" st)
3440 (modify-syntax-entry ?\) ")(" st)
3441 (setq reset-st (syntax-table))
3442 (set-syntax-table st)
3443 (forward-sexp 1))
3444 (error (message
3445 "cperl-forward-group-in-re: error %s" b)))
3446 ;; now restore the initial state
3447 (if st
3448 (progn
3449 (modify-syntax-entry ?\( "." st)
3450 (modify-syntax-entry ?\) "." st)))
3451 (if reset-st
3452 (set-syntax-table reset-st))
3456 (defvar font-lock-string-face)
3457 ;;(defvar font-lock-reference-face)
3458 (defvar font-lock-constant-face)
3459 (defsubst cperl-postpone-fontification (b e type val &optional now)
3460 ;; Do after syntactic fontification?
3461 (if cperl-syntaxify-by-font-lock
3462 (or now (put-text-property b e 'cperl-postpone (cons type val)))
3463 (put-text-property b e type val)))
3465 ;;; Here is how the global structures (those which cannot be
3466 ;;; recognized locally) are marked:
3467 ;; a) PODs:
3468 ;; Start-to-end is marked `in-pod' ==> t
3469 ;; Each non-literal part is marked `syntax-type' ==> `pod'
3470 ;; Each literal part is marked `syntax-type' ==> `in-pod'
3471 ;; b) HEREs:
3472 ;; Start-to-end is marked `here-doc-group' ==> t
3473 ;; The body is marked `syntax-type' ==> `here-doc'
3474 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
3475 ;; c) FORMATs:
3476 ;; First line (to =) marked `first-format-line' ==> t
3477 ;; After-this--to-end is marked `syntax-type' ==> `format'
3478 ;; d) 'Q'uoted string:
3479 ;; part between markers inclusive is marked `syntax-type' ==> `string'
3480 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
3481 ;; second part of s///e is marked `syntax-type' ==> `multiline'
3482 ;; e) Attributes of subroutines: `attrib-group' ==> t
3483 ;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
3484 ;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
3486 ;;; In addition, some parts of RExes may be marked as `REx-interpolated'
3487 ;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
3489 (defun cperl-unwind-to-safe (before &optional end)
3490 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
3491 (let ((pos (point)) opos)
3492 (while (and pos (progn
3493 (beginning-of-line)
3494 (get-text-property (setq pos (point)) 'syntax-type)))
3495 (setq opos pos
3496 pos (cperl-beginning-of-property pos 'syntax-type))
3497 (if (eq pos (point-min))
3498 (setq pos nil))
3499 (if pos
3500 (if before
3501 (progn
3502 (goto-char (cperl-1- pos))
3503 (beginning-of-line)
3504 (setq pos (point)))
3505 (goto-char (setq pos (cperl-1- pos))))
3506 ;; Up to the start
3507 (goto-char (point-min))))
3508 ;; Skip empty lines
3509 (and (looking-at "\n*=")
3510 (/= 0 (skip-chars-backward "\n"))
3511 (forward-char))
3512 (setq pos (point))
3513 (if end
3514 ;; Do the same for end, going small steps
3515 (save-excursion
3516 (while (and end (< end (point-max))
3517 (get-text-property end 'syntax-type))
3518 (setq pos end
3519 end (next-single-property-change end 'syntax-type nil (point-max)))
3520 (if end (progn (goto-char end)
3521 (or (bolp) (forward-line 1))
3522 (setq end (point)))))
3523 (or end pos)))))
3525 ;;; These are needed for byte-compile (at least with v19)
3526 (defvar cperl-nonoverridable-face)
3527 (defvar font-lock-variable-name-face)
3528 (defvar font-lock-function-name-face)
3529 (defvar font-lock-keyword-face)
3530 (defvar font-lock-builtin-face)
3531 (defvar font-lock-type-face)
3532 (defvar font-lock-comment-face)
3533 (defvar font-lock-warning-face)
3535 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
3536 "Syntactically mark (and fontify) attributes of a subroutine.
3537 Should be called with the point before leading colon of an attribute."
3538 ;; Works *before* syntax recognition is done
3539 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
3540 (let (st b p reset-st after-first (start (point)) start1 end1)
3541 (condition-case b
3542 (while (looking-at
3543 (concat
3544 "\\(" ; 1=optional? colon
3545 ":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
3546 "\\)"
3547 (if after-first "?" "")
3548 ;; No space between name and paren allowed...
3549 "\\(\\sw+\\)" ; 3=name
3550 "\\((\\)?")) ; 4=optional paren
3551 (and (match-beginning 1)
3552 (cperl-postpone-fontification
3553 (match-beginning 0) (cperl-1+ (match-beginning 0))
3554 'face font-lock-constant-face))
3555 (setq start1 (match-beginning 3) end1 (match-end 3))
3556 (cperl-postpone-fontification start1 end1
3557 'face font-lock-constant-face)
3558 (goto-char end1) ; end or before `('
3559 (if (match-end 4) ; Have attribute arguments...
3560 (progn
3561 (if st nil
3562 (setq st (cperl-cached-syntax-table st-l))
3563 (modify-syntax-entry ?\( "()" st)
3564 (modify-syntax-entry ?\) ")(" st))
3565 (setq reset-st (syntax-table) p (point))
3566 (set-syntax-table st)
3567 (forward-sexp 1)
3568 (set-syntax-table reset-st)
3569 (setq reset-st nil)
3570 (cperl-commentify p (point) t))) ; mark as string
3571 (forward-comment (buffer-size))
3572 (setq after-first t))
3573 (error (message
3574 "L%d: attribute `%s': %s"
3575 (count-lines (point-min) (point))
3576 (and start1 end1 (buffer-substring start1 end1)) b)
3577 (setq start nil)))
3578 (and start
3579 (progn
3580 (put-text-property start (point)
3581 'attrib-group (if (looking-at "{") t 0))
3582 (and pos
3583 (< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
3584 ;; Apparently, we do not need `multiline': faces added now
3585 (put-text-property (+ 3 pos) (cperl-1+ (point))
3586 'syntax-type 'sub-decl))
3587 (and b-fname ; Fontify here: the following condition
3588 (cperl-postpone-fontification ; is too hard to determine by
3589 b-fname e-fname 'face ; a REx, so do it here
3590 (if (looking-at "{")
3591 font-lock-function-name-face
3592 font-lock-variable-name-face)))))
3593 ;; now restore the initial state
3594 (if st
3595 (progn
3596 (modify-syntax-entry ?\( "." st)
3597 (modify-syntax-entry ?\) "." st)))
3598 (if reset-st
3599 (set-syntax-table reset-st))))
3601 (defsubst cperl-look-at-leading-count (is-x-REx e)
3602 (if (and
3603 (< (point) e)
3604 (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
3605 (1- e) t)) ; return nil on failure, no moving
3606 (if (eq ?\{ (preceding-char)) nil
3607 (cperl-postpone-fontification
3608 (1- (point)) (point)
3609 'face font-lock-warning-face))))
3611 ;; Do some smarter-highlighting
3612 ;; XXXX Currently ignores alphanum/dash delims,
3613 (defsubst cperl-highlight-charclass (endbracket dashface bsface onec-space)
3614 (let ((l '(1 5 7)) ll lle lll
3615 ;; 2 groups, the first takes the whole match (include \[trnfabe])
3616 (singleChar (concat "\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)")))
3617 (while ; look for unescaped - between non-classes
3618 (re-search-forward
3619 ;; On 19.33, certain simplifications lead
3620 ;; to bugs (as in [^a-z] \\| [trnfabe] )
3621 (concat ; 1: SingleChar (include \[trnfabe])
3622 singleChar
3623 ;;"\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)"
3624 "\\(" ; 3: DASH SingleChar (match optionally)
3625 "\\(-\\)" ; 4: DASH
3626 singleChar ; 5: SingleChar
3627 ;;"\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)"
3628 "\\)?"
3629 "\\|"
3630 "\\(" ; 7: other escapes
3631 "\\\\[pP]" "\\([^{]\\|{[^{}]*}\\)"
3632 "\\|" "\\\\[^pP]" "\\)"
3634 endbracket 'toend)
3635 (if (match-beginning 4)
3636 (cperl-postpone-fontification
3637 (match-beginning 4) (match-end 4)
3638 'face dashface))
3639 ;; save match data (for looking-at)
3640 (setq lll (mapcar (function (lambda (elt) (cons (match-beginning elt)
3641 (match-end elt)))) l))
3642 (while lll
3643 (setq ll (car lll))
3644 (setq lle (cdr ll)
3645 ll (car ll))
3646 ;; (message "Got %s of %s" ll l)
3647 (if (and ll (eq (char-after ll) ?\\ ))
3648 (save-excursion
3649 (goto-char ll)
3650 (cperl-postpone-fontification ll (1+ ll)
3651 'face bsface)
3652 (if (looking-at "\\\\[a-zA-Z0-9]")
3653 (cperl-postpone-fontification (1+ ll) lle
3654 'face onec-space))))
3655 (setq lll (cdr lll))))
3656 (goto-char endbracket) ; just in case something misbehaves???
3659 ;;; Debugging this may require (setq max-specpdl-size 2000)...
3660 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc)
3661 "Scans the buffer for hard-to-parse Perl constructions.
3662 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
3663 the sections using `cperl-pod-head-face', `cperl-pod-face',
3664 `cperl-here-face'."
3665 (interactive)
3666 (or min (setq min (point-min)
3667 cperl-syntax-state nil
3668 cperl-syntax-done-to min))
3669 (or max (setq max (point-max)))
3670 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
3671 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
3672 is-REx is-x-REx REx-subgr-start REx-subgr-end was-subgr i2 hairy-RE
3673 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
3674 (modified (buffer-modified-p)) overshoot is-o-REx name
3675 (after-change-functions nil)
3676 (cperl-font-locking t)
3677 (use-syntax-state (and cperl-syntax-state
3678 (>= min (car cperl-syntax-state))))
3679 (state-point (if use-syntax-state
3680 (car cperl-syntax-state)
3681 (point-min)))
3682 (state (if use-syntax-state
3683 (cdr cperl-syntax-state)))
3684 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
3685 (st-l (list nil)) (err-l (list nil))
3686 ;; Somehow font-lock may be not loaded yet...
3687 ;; (e.g., when building TAGS via command-line call)
3688 (font-lock-string-face (if (boundp 'font-lock-string-face)
3689 font-lock-string-face
3690 'font-lock-string-face))
3691 (my-cperl-delimiters-face (if (boundp 'font-lock-constant-face)
3692 font-lock-constant-face
3693 'font-lock-constant-face))
3694 (my-cperl-REx-spec-char-face ; [] ^.$ and wrapper-of ({})
3695 (if (boundp 'font-lock-function-name-face)
3696 font-lock-function-name-face
3697 'font-lock-function-name-face))
3698 (font-lock-variable-name-face ; interpolated vars and ({})-code
3699 (if (boundp 'font-lock-variable-name-face)
3700 font-lock-variable-name-face
3701 'font-lock-variable-name-face))
3702 (font-lock-function-name-face ; used in `cperl-find-sub-attrs'
3703 (if (boundp 'font-lock-function-name-face)
3704 font-lock-function-name-face
3705 'font-lock-function-name-face))
3706 (font-lock-constant-face ; used in `cperl-find-sub-attrs'
3707 (if (boundp 'font-lock-constant-face)
3708 font-lock-constant-face
3709 'font-lock-constant-face))
3710 (my-cperl-REx-0length-face ; 0-length, (?:)etc, non-literal \
3711 (if (boundp 'font-lock-builtin-face)
3712 font-lock-builtin-face
3713 'font-lock-builtin-face))
3714 (font-lock-comment-face
3715 (if (boundp 'font-lock-comment-face)
3716 font-lock-comment-face
3717 'font-lock-comment-face))
3718 (font-lock-warning-face
3719 (if (boundp 'font-lock-warning-face)
3720 font-lock-warning-face
3721 'font-lock-warning-face))
3722 (my-cperl-REx-ctl-face ; (|)
3723 (if (boundp 'font-lock-keyword-face)
3724 font-lock-keyword-face
3725 'font-lock-keyword-face))
3726 (my-cperl-REx-modifiers-face ; //gims
3727 (if (boundp 'cperl-nonoverridable-face)
3728 cperl-nonoverridable-face
3729 'cperl-nonoverridable-face))
3730 (my-cperl-REx-length1-face ; length=1 escaped chars, POSIX classes
3731 (if (boundp 'font-lock-type-face)
3732 font-lock-type-face
3733 'font-lock-type-face))
3734 (stop-point (if ignore-max
3735 (point-max)
3736 max))
3737 (search
3738 (concat
3739 "\\(\\`\n?\\|^\n\\)=" ; POD
3740 "\\|"
3741 ;; One extra () before this:
3742 "<<" ; HERE-DOC
3743 "\\(" ; 1 + 1
3744 ;; First variant "BLAH" or just ``.
3745 "[ \t]*" ; Yes, whitespace is allowed!
3746 "\\([\"'`]\\)" ; 2 + 1 = 3
3747 "\\([^\"'`\n]*\\)" ; 3 + 1
3748 "\\3"
3749 "\\|"
3750 ;; Second variant: Identifier or \ID (same as 'ID') or empty
3751 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3752 ;; Do not have <<= or << 30 or <<30 or << $blah.
3753 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3754 "\\(\\)" ; To preserve count of pars :-( 6 + 1
3755 "\\)"
3756 "\\|"
3757 ;; 1+6 extra () before this:
3758 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" ;FRMAT
3759 (if cperl-use-syntax-table-text-property
3760 (concat
3761 "\\|"
3762 ;; 1+6+2=9 extra () before this:
3763 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT
3764 "\\|"
3765 ;; 1+6+2+1=10 extra () before this:
3766 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3767 "\\|"
3768 ;; 1+6+2+1+1=11 extra () before this
3769 "\\<sub\\>" ; sub with proto/attr
3770 "\\("
3771 cperl-white-and-comment-rex
3772 "\\(::[a-zA-Z_:'0-9]*\\|[a-zA-Z_'][a-zA-Z_:'0-9]*\\)\\)?" ; name
3773 "\\("
3774 cperl-maybe-white-and-comment-rex
3775 "\\(([^()]*)\\|:[^:]\\)\\)" ; prototype or attribute start
3776 "\\|"
3777 ;; 1+6+2+1+1+6=17 extra () before this:
3778 "\\$\\(['{]\\)" ; $' or ${foo}
3779 "\\|"
3780 ;; 1+6+2+1+1+6+1=18 extra () before this (old pack'var syntax;
3781 ;; we do not support intervening comments...):
3782 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
3783 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
3784 "\\|"
3785 "__\\(END\\|DATA\\)__" ; __END__ or __DATA__
3786 ;; 1+6+2+1+1+6+1+1+1=20 extra () before this:
3787 "\\|"
3788 "\\\\\\(['`\"($]\\)") ; BACKWACKED something-hairy
3789 ""))))
3790 (unwind-protect
3791 (progn
3792 (save-excursion
3793 (or non-inter
3794 (message "Scanning for \"hard\" Perl constructions..."))
3795 ;;(message "find: %s --> %s" min max)
3796 (and cperl-pod-here-fontify
3797 ;; We had evals here, do not know why...
3798 (setq face cperl-pod-face
3799 head-face cperl-pod-head-face
3800 here-face cperl-here-face))
3801 (remove-text-properties min max
3802 '(syntax-type t in-pod t syntax-table t
3803 attrib-group t
3804 REx-interpolated t
3805 cperl-postpone t
3806 syntax-subtype t
3807 rear-nonsticky t
3808 front-sticky t
3809 here-doc-group t
3810 first-format-line t
3811 REx-part2 t
3812 indentable t))
3813 ;; Need to remove face as well...
3814 (goto-char min)
3815 ;; 'emx not supported by Emacs since at least 21.1.
3816 (and (featurep 'xemacs) (eq system-type 'emx)
3817 (eq (point) 1)
3818 (let ((case-fold-search t))
3819 (looking-at "extproc[ \t]")) ; Analogue of #!
3820 (cperl-commentify min
3821 (point-at-eol)
3822 nil))
3823 (while (and
3824 (< (point) max)
3825 (re-search-forward search max t))
3826 (setq tmpend nil) ; Valid for most cases
3827 (setq b (match-beginning 0)
3828 state (save-excursion (parse-partial-sexp
3829 state-point b nil nil state))
3830 state-point b)
3831 (cond
3832 ;; 1+6+2+1+1+6=17 extra () before this:
3833 ;; "\\$\\(['{]\\)"
3834 ((match-beginning 18) ; $' or ${foo}
3835 (if (eq (preceding-char) ?\') ; $'
3836 (progn
3837 (setq b (1- (point))
3838 state (parse-partial-sexp
3839 state-point (1- b) nil nil state)
3840 state-point (1- b))
3841 (if (nth 3 state) ; in string
3842 (cperl-modify-syntax-type (1- b) cperl-st-punct))
3843 (goto-char (1+ b)))
3844 ;; else: ${
3845 (setq bb (match-beginning 0))
3846 (cperl-modify-syntax-type bb cperl-st-punct)))
3847 ;; No processing in strings/comments beyond this point:
3848 ((or (nth 3 state) (nth 4 state))
3849 t) ; Do nothing in comment/string
3850 ((match-beginning 1) ; POD section
3851 ;; "\\(\\`\n?\\|^\n\\)="
3852 (setq b (match-beginning 0)
3853 state (parse-partial-sexp
3854 state-point b nil nil state)
3855 state-point b)
3856 (if (or (nth 3 state) (nth 4 state)
3857 (looking-at "cut\\>"))
3858 (if (or (nth 3 state) (nth 4 state) ignore-max)
3859 nil ; Doing a chunk only
3860 (message "=cut is not preceded by a POD section")
3861 (or (car err-l) (setcar err-l (point))))
3862 (beginning-of-line)
3864 (setq b (point)
3865 bb b
3866 tb (match-beginning 0)
3867 b1 nil) ; error condition
3868 ;; We do not search to max, since we may be called from
3869 ;; some hook of fontification, and max is random
3870 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
3871 (progn
3872 (goto-char b)
3873 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
3874 (progn
3875 (message "=cut is not preceded by an empty line")
3876 (setq b1 t)
3877 (or (car err-l) (setcar err-l b))))))
3878 (beginning-of-line 2) ; An empty line after =cut is not POD!
3879 (setq e (point))
3880 (and (> e max)
3881 (progn
3882 (remove-text-properties
3883 max e '(syntax-type t in-pod t syntax-table t
3884 attrib-group t
3885 REx-interpolated t
3886 cperl-postpone t
3887 syntax-subtype t
3888 here-doc-group t
3889 rear-nonsticky t
3890 front-sticky t
3891 first-format-line t
3892 REx-part2 t
3893 indentable t))
3894 (setq tmpend tb)))
3895 (put-text-property b e 'in-pod t)
3896 (put-text-property b e 'syntax-type 'in-pod)
3897 (goto-char b)
3898 (while (re-search-forward "\n\n[ \t]" e t)
3899 ;; We start 'pod 1 char earlier to include the preceding line
3900 (beginning-of-line)
3901 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
3902 (cperl-put-do-not-fontify b (point) t)
3903 ;; mark the non-literal parts as PODs
3904 (if cperl-pod-here-fontify
3905 (cperl-postpone-fontification b (point) 'face face t))
3906 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
3907 (beginning-of-line)
3908 (setq b (point)))
3909 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
3910 (cperl-put-do-not-fontify (point) e t)
3911 (if cperl-pod-here-fontify
3912 (progn
3913 ;; mark the non-literal parts as PODs
3914 (cperl-postpone-fontification (point) e 'face face t)
3915 (goto-char bb)
3916 (if (looking-at
3917 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
3918 ;; mark the headers
3919 (cperl-postpone-fontification
3920 (match-beginning 1) (match-end 1)
3921 'face head-face))
3922 (while (re-search-forward
3923 ;; One paragraph
3924 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
3925 e 'toend)
3926 ;; mark the headers
3927 (cperl-postpone-fontification
3928 (match-beginning 1) (match-end 1)
3929 'face head-face))))
3930 (cperl-commentify bb e nil)
3931 (goto-char e)
3932 (or (eq e (point-max))
3933 (forward-char -1)))) ; Prepare for immediate POD start.
3934 ;; Here document
3935 ;; We can do many here-per-line;
3936 ;; but multiline quote on the same line as <<HERE confuses us...
3937 ;; ;; One extra () before this:
3938 ;;"<<"
3939 ;; "\\(" ; 1 + 1
3940 ;; ;; First variant "BLAH" or just ``.
3941 ;; "[ \t]*" ; Yes, whitespace is allowed!
3942 ;; "\\([\"'`]\\)" ; 2 + 1
3943 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
3944 ;; "\\3"
3945 ;; "\\|"
3946 ;; ;; Second variant: Identifier or \ID or empty
3947 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3948 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
3949 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3950 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
3951 ;; "\\)"
3952 ((match-beginning 2) ; 1 + 1
3953 (setq b (point)
3954 tb (match-beginning 0)
3955 c (and ; not HERE-DOC
3956 (match-beginning 5)
3957 (save-match-data
3958 (or (looking-at "[ \t]*(") ; << function_call()
3959 (save-excursion ; 1 << func_name, or $foo << 10
3960 (condition-case nil
3961 (progn
3962 (goto-char tb)
3963 ;;; XXX What to do: foo <<bar ???
3964 ;;; XXX Need to support print {a} <<B ???
3965 (forward-sexp -1)
3966 (save-match-data
3967 ; $foo << b; $f .= <<B;
3968 ; ($f+1) << b; a($f) . <<B;
3969 ; foo 1, <<B; $x{a} <<b;
3970 (cond
3971 ((looking-at "[0-9$({]")
3972 (forward-sexp 1)
3973 (and
3974 (looking-at "[ \t]*<<")
3975 (condition-case nil
3976 ;; print $foo <<EOF
3977 (progn
3978 (forward-sexp -2)
3979 (not
3980 (looking-at "\\(printf?\\|system\\|exec\\|sort\\)\\>")))
3981 (error t)))))))
3982 (error nil))) ; func(<<EOF)
3983 (and (not (match-beginning 6)) ; Empty
3984 (looking-at
3985 "[ \t]*[=0-9$@%&(]"))))))
3986 (if c ; Not here-doc
3987 nil ; Skip it.
3988 (setq c (match-end 2)) ; 1 + 1
3989 (if (match-beginning 5) ;4 + 1
3990 (setq b1 (match-beginning 5) ; 4 + 1
3991 e1 (match-end 5)) ; 4 + 1
3992 (setq b1 (match-beginning 4) ; 3 + 1
3993 e1 (match-end 4))) ; 3 + 1
3994 (setq tag (buffer-substring b1 e1)
3995 qtag (regexp-quote tag))
3996 (cond (cperl-pod-here-fontify
3997 ;; Highlight the starting delimiter
3998 (cperl-postpone-fontification
3999 b1 e1 'face my-cperl-delimiters-face)
4000 (cperl-put-do-not-fontify b1 e1 t)))
4001 (forward-line)
4002 (setq i (point))
4003 (if end-of-here-doc
4004 (goto-char end-of-here-doc))
4005 (setq b (point))
4006 ;; We do not search to max, since we may be called from
4007 ;; some hook of fontification, and max is random
4008 (or (and (re-search-forward (concat "^" qtag "$")
4009 stop-point 'toend)
4010 ;;;(eq (following-char) ?\n) ; XXXX WHY???
4012 (progn ; Pretend we matched at the end
4013 (goto-char (point-max))
4014 (re-search-forward "\\'")
4015 (message "End of here-document `%s' not found." tag)
4016 (or (car err-l) (setcar err-l b))))
4017 (if cperl-pod-here-fontify
4018 (progn
4019 ;; Highlight the ending delimiter
4020 (cperl-postpone-fontification
4021 (match-beginning 0) (match-end 0)
4022 'face my-cperl-delimiters-face)
4023 (cperl-put-do-not-fontify b (match-end 0) t)
4024 ;; Highlight the HERE-DOC
4025 (cperl-postpone-fontification b (match-beginning 0)
4026 'face here-face)))
4027 (setq e1 (cperl-1+ (match-end 0)))
4028 (put-text-property b (match-beginning 0)
4029 'syntax-type 'here-doc)
4030 (put-text-property (match-beginning 0) e1
4031 'syntax-type 'here-doc-delim)
4032 (put-text-property b e1 'here-doc-group t)
4033 ;; This makes insertion at the start of HERE-DOC update
4034 ;; the whole construct:
4035 (put-text-property b (cperl-1+ b) 'front-sticky '(syntax-type))
4036 (cperl-commentify b e1 nil)
4037 (cperl-put-do-not-fontify b (match-end 0) t)
4038 ;; Cache the syntax info...
4039 (setq cperl-syntax-state (cons state-point state))
4040 ;; ... and process the rest of the line...
4041 (setq overshoot
4042 (elt ; non-inter ignore-max
4043 (cperl-find-pods-heres c i t end t e1) 1))
4044 (if (and overshoot (> overshoot (point)))
4045 (goto-char overshoot)
4046 (setq overshoot e1))
4047 (if (> e1 max)
4048 (setq tmpend tb))))
4049 ;; format
4050 ((match-beginning 8)
4051 ;; 1+6=7 extra () before this:
4052 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
4053 (setq b (point)
4054 name (if (match-beginning 8) ; 7 + 1
4055 (buffer-substring (match-beginning 8) ; 7 + 1
4056 (match-end 8)) ; 7 + 1
4058 tb (match-beginning 0))
4059 (setq argument nil)
4060 (put-text-property (point-at-bol) b 'first-format-line 't)
4061 (if cperl-pod-here-fontify
4062 (while (and (eq (forward-line) 0)
4063 (not (looking-at "^[.;]$")))
4064 (cond
4065 ((looking-at "^#")) ; Skip comments
4066 ((and argument ; Skip argument multi-lines
4067 (looking-at "^[ \t]*{"))
4068 (forward-sexp 1)
4069 (setq argument nil))
4070 (argument ; Skip argument lines
4071 (setq argument nil))
4072 (t ; Format line
4073 (setq b1 (point))
4074 (setq argument (looking-at "^[^\n]*[@^]"))
4075 (end-of-line)
4076 ;; Highlight the format line
4077 (cperl-postpone-fontification b1 (point)
4078 'face font-lock-string-face)
4079 (cperl-commentify b1 (point) nil)
4080 (cperl-put-do-not-fontify b1 (point) t))))
4081 ;; We do not search to max, since we may be called from
4082 ;; some hook of fontification, and max is random
4083 (re-search-forward "^[.;]$" stop-point 'toend))
4084 (beginning-of-line)
4085 (if (looking-at "^\\.$") ; ";" is not supported yet
4086 (progn
4087 ;; Highlight the ending delimiter
4088 (cperl-postpone-fontification (point) (+ (point) 2)
4089 'face font-lock-string-face)
4090 (cperl-commentify (point) (+ (point) 2) nil)
4091 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
4092 (message "End of format `%s' not found." name)
4093 (or (car err-l) (setcar err-l b)))
4094 (forward-line)
4095 (if (> (point) max)
4096 (setq tmpend tb))
4097 (put-text-property b (point) 'syntax-type 'format))
4098 ;; qq-like String or Regexp:
4099 ((or (match-beginning 10) (match-beginning 11))
4100 ;; 1+6+2=9 extra () before this:
4101 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
4102 ;; "\\|"
4103 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
4104 (setq b1 (if (match-beginning 10) 10 11)
4105 argument (buffer-substring
4106 (match-beginning b1) (match-end b1))
4107 b (point) ; end of qq etc
4109 c (char-after (match-beginning b1))
4110 bb (char-after (1- (match-beginning b1))) ; tmp holder
4111 ;; bb == "Not a stringy"
4112 bb (if (eq b1 10) ; user variables/whatever
4113 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
4114 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
4115 ((eq bb ?\:) ; $opt::s
4116 (eq (char-after
4117 (- (match-beginning b1) 2))
4118 ?\:))
4119 ((eq bb ?\>) ; $foo->s
4120 (eq (char-after
4121 (- (match-beginning b1) 2))
4122 ?\-))
4123 ((eq bb ?\&)
4124 (not (eq (char-after ; &&m/blah/
4125 (- (match-beginning b1) 2))
4126 ?\&)))
4127 (t t)))
4128 ;; <file> or <$file>
4129 (and (eq c ?\<)
4130 ;; Do not stringify <FH>, <$fh> :
4131 (save-match-data
4132 (looking-at
4133 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
4134 tb (match-beginning 0))
4135 (goto-char (match-beginning b1))
4136 (cperl-backward-to-noncomment (point-min))
4137 (or bb
4138 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
4139 (setq argument ""
4140 b1 nil
4141 bb ; Not a regexp?
4142 (not
4143 ;; What is below: regexp-p?
4144 (and
4145 (or (memq (preceding-char)
4146 (append (if (memq c '(?\? ?\<))
4147 ;; $a++ ? 1 : 2
4148 "~{(=|&*!,;:["
4149 "~{(=|&+-*!,;:[") nil))
4150 (and (eq (preceding-char) ?\})
4151 (cperl-after-block-p (point-min)))
4152 (and (eq (char-syntax (preceding-char)) ?w)
4153 (progn
4154 (forward-sexp -1)
4155 ;; After these keywords `/' starts a RE. One should add all the
4156 ;; functions/builtins which expect an argument, but ...
4157 (if (eq (preceding-char) ?-)
4158 ;; -d ?foo? is a RE
4159 (looking-at "[a-zA-Z]\\>")
4160 (and
4161 (not (memq (preceding-char)
4162 '(?$ ?@ ?& ?%)))
4163 (looking-at
4164 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
4165 (and (eq (preceding-char) ?.)
4166 (eq (char-after (- (point) 2)) ?.))
4167 (bobp))
4168 ;; m|blah| ? foo : bar;
4169 (not
4170 (and (eq c ?\?)
4171 cperl-use-syntax-table-text-property
4172 (not (bobp))
4173 (progn
4174 (forward-char -1)
4175 (looking-at "\\s|"))))))
4176 b (1- b))
4177 ;; s y tr m
4178 ;; Check for $a -> y
4179 (setq b1 (preceding-char)
4180 go (point))
4181 (if (and (eq b1 ?>)
4182 (eq (char-after (- go 2)) ?-))
4183 ;; Not a regexp
4184 (setq bb t))))
4185 (or bb
4186 (progn
4187 (goto-char b)
4188 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4189 (goto-char (match-end 0))
4190 (skip-chars-forward " \t\n\f"))
4191 (cond ((and (eq (following-char) ?\})
4192 (eq b1 ?\{))
4193 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
4194 (goto-char (1- go))
4195 (skip-chars-backward " \t\n\f")
4196 (if (memq (preceding-char) (append "$@%&*" nil))
4197 (setq bb t) ; @{y}
4198 (condition-case nil
4199 (forward-sexp -1)
4200 (error nil)))
4201 (if (or bb
4202 (looking-at ; $foo -> {s}
4203 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
4204 (and ; $foo[12] -> {s}
4205 (memq (following-char) '(?\{ ?\[))
4206 (progn
4207 (forward-sexp 1)
4208 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
4209 (setq bb t)
4210 (goto-char b)))
4211 ((and (eq (following-char) ?=)
4212 (eq (char-after (1+ (point))) ?\>))
4213 ;; Check for { foo => 1, s => 2 }
4214 ;; Apparently s=> is never a substitution...
4215 (setq bb t))
4216 ((and (eq (following-char) ?:)
4217 (eq b1 ?\{) ; Check for $ { s::bar }
4218 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
4219 (progn
4220 (goto-char (1- go))
4221 (skip-chars-backward " \t\n\f")
4222 (memq (preceding-char)
4223 (append "$@%&*" nil))))
4224 (setq bb t))
4225 ((eobp)
4226 (setq bb t)))))
4227 (if bb
4228 (goto-char i)
4229 ;; Skip whitespace and comments...
4230 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4231 (goto-char (match-end 0))
4232 (skip-chars-forward " \t\n\f"))
4233 (if (> (point) b)
4234 (put-text-property b (point) 'syntax-type 'prestring))
4235 ;; qtag means two-arg matcher, may be reset to
4236 ;; 2 or 3 later if some special quoting is needed.
4237 ;; e1 means matching-char matcher.
4238 (setq b (point) ; before the first delimiter
4239 ;; has 2 args
4240 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
4241 ;; We do not search to max, since we may be called from
4242 ;; some hook of fontification, and max is random
4243 i (cperl-forward-re stop-point end
4245 st-l err-l argument)
4246 ;; If `go', then it is considered as 1-arg, `b1' is nil
4247 ;; as in s/foo//x; the point is before final "slash"
4248 b1 (nth 1 i) ; start of the second part
4249 tag (nth 2 i) ; ender-char, true if second part
4250 ; is with matching chars []
4251 go (nth 4 i) ; There is a 1-char part after the end
4252 i (car i) ; intermediate point
4253 e1 (point) ; end
4254 ;; Before end of the second part if non-matching: ///
4255 tail (if (and i (not tag))
4256 (1- e1))
4257 e (if i i e1) ; end of the first part
4258 qtag nil ; need to preserve backslashitis
4259 is-x-REx nil is-o-REx nil); REx has //x //o modifiers
4260 ;; If s{} (), then b/b1 are at "{", "(", e1/i after ")", "}"
4261 ;; Commenting \\ is dangerous, what about ( ?
4262 (and i tail
4263 (eq (char-after i) ?\\)
4264 (setq qtag t))
4265 (and (if go (looking-at ".\\sw*x")
4266 (looking-at "\\sw*x")) ; qr//x
4267 (setq is-x-REx t))
4268 (and (if go (looking-at ".\\sw*o")
4269 (looking-at "\\sw*o")) ; //o
4270 (setq is-o-REx t))
4271 (if (null i)
4272 ;; Considered as 1arg form
4273 (progn
4274 (cperl-commentify b (point) t)
4275 (put-text-property b (point) 'syntax-type 'string)
4276 (if (or is-x-REx
4277 ;; ignore other text properties:
4278 (string-match "^qw$" argument))
4279 (put-text-property b (point) 'indentable t))
4280 (and go
4281 (setq e1 (cperl-1+ e1))
4282 (or (eobp)
4283 (forward-char 1))))
4284 (cperl-commentify b i t)
4285 (if (looking-at "\\sw*e") ; s///e
4286 (progn
4287 ;; Cache the syntax info...
4288 (setq cperl-syntax-state (cons state-point state))
4289 (and
4290 ;; silent:
4291 (car (cperl-find-pods-heres b1 (1- (point)) t end))
4292 ;; Error
4293 (goto-char (1+ max)))
4294 (if (and tag (eq (preceding-char) ?\>))
4295 (progn
4296 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
4297 (cperl-modify-syntax-type i cperl-st-bra)))
4298 (put-text-property b i 'syntax-type 'string)
4299 (put-text-property i (point) 'syntax-type 'multiline)
4300 (if is-x-REx
4301 (put-text-property b i 'indentable t)))
4302 (cperl-commentify b1 (point) t)
4303 (put-text-property b (point) 'syntax-type 'string)
4304 (if is-x-REx
4305 (put-text-property b i 'indentable t))
4306 (if qtag
4307 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
4308 (setq tail nil)))
4309 ;; Now: tail: if the second part is non-matching without ///e
4310 (if (eq (char-syntax (following-char)) ?w)
4311 (progn
4312 (forward-word 1) ; skip modifiers s///s
4313 (if tail (cperl-commentify tail (point) t))
4314 (cperl-postpone-fontification
4315 e1 (point) 'face my-cperl-REx-modifiers-face)))
4316 ;; Check whether it is m// which means "previous match"
4317 ;; and highlight differently
4318 (setq is-REx
4319 (and (string-match "^\\([sm]?\\|qr\\)$" argument)
4320 (or (not (= (length argument) 0))
4321 (not (eq c ?\<)))))
4322 (if (and is-REx
4323 (eq e (+ 2 b))
4324 ;; split // *is* using zero-pattern
4325 (save-excursion
4326 (condition-case nil
4327 (progn
4328 (goto-char tb)
4329 (forward-sexp -1)
4330 (not (looking-at "split\\>")))
4331 (error t))))
4332 (cperl-postpone-fontification
4333 b e 'face font-lock-warning-face)
4334 (if (or i2 ; Has 2 args
4335 (and cperl-fontify-m-as-s
4337 (string-match "^\\(m\\|qr\\)$" argument)
4338 (and (eq 0 (length argument))
4339 (not (eq ?\< (char-after b)))))))
4340 (progn
4341 (cperl-postpone-fontification
4342 b (cperl-1+ b) 'face my-cperl-delimiters-face)
4343 (cperl-postpone-fontification
4344 (1- e) e 'face my-cperl-delimiters-face)))
4345 (if (and is-REx cperl-regexp-scan)
4346 ;; Process RExen: embedded comments, charclasses and ]
4347 ;;;/\3333\xFg\x{FFF}a\ppp\PPP\qqq\C\99f(?{ foo })(??{ foo })/;
4348 ;;;/a\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
4349 ;;;/(?<=foo)(?<!bar)(x)(?:$ab|\$\/)$|\\\b\x888\776\[\:$/xxx;
4350 ;;;m?(\?\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
4351 ;;;m$(^ab[c]\$)$ + m+(^ab[c]\$\+)+ + m](^ab[c\]$|.+)] + m)(^ab[c]$|.+\));
4352 ;;;m^a[\^b]c^ + m.a[^b]\.c.;
4353 (save-excursion
4354 (goto-char (1+ b))
4355 ;; First
4356 (cperl-look-at-leading-count is-x-REx e)
4357 (setq hairy-RE
4358 (concat
4359 (if is-x-REx
4360 (if (eq (char-after b) ?\#)
4361 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
4362 "\\((\\?#\\)\\|\\(#\\)")
4363 ;; keep the same count: add a fake group
4364 (if (eq (char-after b) ?\#)
4365 "\\((\\?\\\\#\\)\\(\\)"
4366 "\\((\\?#\\)\\(\\)"))
4367 "\\|"
4368 "\\(\\[\\)" ; 3=[
4369 "\\|"
4370 "\\(]\\)" ; 4=]
4371 "\\|"
4372 ;; XXXX Will not be able to use it in s)))
4373 (if (eq (char-after b) ?\) )
4374 "\\())))\\)" ; Will never match
4375 (if (eq (char-after b) ?? )
4376 ;;"\\((\\\\\\?\\(\\\\\\?\\)?{\\)"
4377 "\\((\\\\\\?\\\\\\?{\\|()\\\\\\?{\\)"
4378 "\\((\\?\\??{\\)")) ; 5= (??{ (?{
4379 "\\|" ; 6= 0-length, 7: name, 8,9:code, 10:group
4380 "\\(" ;; XXXX 1-char variables, exc. |()\s
4381 "[$@]"
4382 "\\("
4383 "[_a-zA-Z:][_a-zA-Z0-9:]*"
4384 "\\|"
4385 "{[^{}]*}" ; only one-level allowed
4386 "\\|"
4387 "[^{(|) \t\r\n\f]"
4388 "\\)"
4389 "\\(" ;;8,9:code part of array/hash elt
4390 "\\(" "->" "\\)?"
4391 "\\[[^][]*\\]"
4392 "\\|"
4393 "{[^{}]*}"
4394 "\\)*"
4395 ;; XXXX: what if u is delim?
4396 "\\|"
4397 "[)^|$.*?+]"
4398 "\\|"
4399 "{[0-9]+}"
4400 "\\|"
4401 "{[0-9]+,[0-9]*}"
4402 "\\|"
4403 "\\\\[luLUEQbBAzZG]"
4404 "\\|"
4405 "(" ; Group opener
4406 "\\(" ; 10 group opener follower
4407 "\\?\\((\\?\\)" ; 11: in (?(?=C)A|B)
4408 "\\|"
4409 "\\?[:=!>?{]" ; "?" something
4410 "\\|"
4411 "\\?[-imsx]+[:)]" ; (?i) (?-s:.)
4412 "\\|"
4413 "\\?([0-9]+)" ; (?(1)foo|bar)
4414 "\\|"
4415 "\\?<[=!]"
4416 ;;;"\\|"
4417 ;;; "\\?"
4418 "\\)?"
4419 "\\)"
4420 "\\|"
4421 "\\\\\\(.\\)" ; 12=\SYMBOL
4423 (while
4424 (and (< (point) (1- e))
4425 (re-search-forward hairy-RE (1- e) 'to-end))
4426 (goto-char (match-beginning 0))
4427 (setq REx-subgr-start (point)
4428 was-subgr (following-char))
4429 (cond
4430 ((match-beginning 6) ; 0-length builtins, groups
4431 (goto-char (match-end 0))
4432 (if (match-beginning 11)
4433 (goto-char (match-beginning 11)))
4434 (if (>= (point) e)
4435 (goto-char (1- e)))
4436 (cperl-postpone-fontification
4437 (match-beginning 0) (point)
4438 'face
4439 (cond
4440 ((eq was-subgr ?\) )
4441 (condition-case nil
4442 (save-excursion
4443 (forward-sexp -1)
4444 (if (> (point) b)
4445 (if (if (eq (char-after b) ?? )
4446 (looking-at "(\\\\\\?")
4447 (eq (char-after (1+ (point))) ?\?))
4448 my-cperl-REx-0length-face
4449 my-cperl-REx-ctl-face)
4450 font-lock-warning-face))
4451 (error font-lock-warning-face)))
4452 ((eq was-subgr ?\| )
4453 my-cperl-REx-ctl-face)
4454 ((eq was-subgr ?\$ )
4455 (if (> (point) (1+ REx-subgr-start))
4456 (progn
4457 (put-text-property
4458 (match-beginning 0) (point)
4459 'REx-interpolated
4460 (if is-o-REx 0
4461 (if (and (eq (match-beginning 0)
4462 (1+ b))
4463 (eq (point)
4464 (1- e))) 1 t)))
4465 font-lock-variable-name-face)
4466 my-cperl-REx-spec-char-face))
4467 ((memq was-subgr (append "^." nil) )
4468 my-cperl-REx-spec-char-face)
4469 ((eq was-subgr ?\( )
4470 (if (not (match-beginning 10))
4471 my-cperl-REx-ctl-face
4472 my-cperl-REx-0length-face))
4473 (t my-cperl-REx-0length-face)))
4474 (if (and (memq was-subgr (append "(|" nil))
4475 (not (string-match "(\\?[-imsx]+)"
4476 (match-string 0))))
4477 (cperl-look-at-leading-count is-x-REx e))
4478 (setq was-subgr nil)) ; We do stuff here
4479 ((match-beginning 12) ; \SYMBOL
4480 (forward-char 2)
4481 (if (>= (point) e)
4482 (goto-char (1- e))
4483 ;; How many chars to not highlight:
4484 ;; 0-len special-alnums in other branch =>
4485 ;; Generic: \non-alnum (1), \alnum (1+face)
4486 ;; Is-delim: \non-alnum (1/spec-2) alnum-1 (=what hai)
4487 (setq REx-subgr-start (point)
4488 qtag (preceding-char))
4489 (cperl-postpone-fontification
4490 (- (point) 2) (- (point) 1) 'face
4491 (if (memq qtag
4492 (append "ghijkmoqvFHIJKMORTVY" nil))
4493 font-lock-warning-face
4494 my-cperl-REx-0length-face))
4495 (if (and (eq (char-after b) qtag)
4496 (memq qtag (append ".])^$|*?+" nil)))
4497 (progn
4498 (if (and cperl-use-syntax-table-text-property
4499 (eq qtag ?\) ))
4500 (put-text-property
4501 REx-subgr-start (1- (point))
4502 'syntax-table cperl-st-punct))
4503 (cperl-postpone-fontification
4504 (1- (point)) (point) 'face
4505 ; \] can't appear below
4506 (if (memq qtag (append ".]^$" nil))
4507 'my-cperl-REx-spec-char-face
4508 (if (memq qtag (append "*?+" nil))
4509 'my-cperl-REx-0length-face
4510 'my-cperl-REx-ctl-face))))) ; )|
4511 ;; Test for arguments:
4512 (cond
4513 ;; This is not pretty: the 5.8.7 logic:
4514 ;; \0numx -> octal (up to total 3 dig)
4515 ;; \DIGIT -> backref unless \0
4516 ;; \DIGITs -> backref if valid
4517 ;; otherwise up to 3 -> octal
4518 ;; Do not try to distinguish, we guess
4519 ((or (and (memq qtag (append "01234567" nil))
4520 (re-search-forward
4521 "\\=[01234567]?[01234567]?"
4522 (1- e) 'to-end))
4523 (and (memq qtag (append "89" nil))
4524 (re-search-forward
4525 "\\=[0123456789]*" (1- e) 'to-end))
4526 (and (eq qtag ?x)
4527 (re-search-forward
4528 "\\=[0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}"
4529 (1- e) 'to-end))
4530 (and (memq qtag (append "pPN" nil))
4531 (re-search-forward "\\={[^{}]+}\\|."
4532 (1- e) 'to-end))
4533 (eq (char-syntax qtag) ?w))
4534 (cperl-postpone-fontification
4535 (1- REx-subgr-start) (point)
4536 'face my-cperl-REx-length1-face))))
4537 (setq was-subgr nil)) ; We do stuff here
4538 ((match-beginning 3) ; [charclass]
4539 ;; Highlight leader, trailer, POSIX classes
4540 (forward-char 1)
4541 (if (eq (char-after b) ?^ )
4542 (and (eq (following-char) ?\\ )
4543 (eq (char-after (cperl-1+ (point)))
4544 ?^ )
4545 (forward-char 2))
4546 (and (eq (following-char) ?^ )
4547 (forward-char 1)))
4548 (setq argument b ; continue? & end of last POSIX
4549 tag nil ; list of POSIX classes
4550 qtag (point)) ; after leading ^ if present
4551 (if (eq (char-after b) ?\] )
4552 (and (eq (following-char) ?\\ )
4553 (eq (char-after (cperl-1+ (point)))
4554 ?\] )
4555 (setq qtag (1+ qtag))
4556 (forward-char 2))
4557 (and (eq (following-char) ?\] )
4558 (forward-char 1)))
4559 (setq REx-subgr-end qtag) ;End smart-highlighted
4560 ;; Apparently, I can't put \] into a charclass
4561 ;; in m]]: m][\\\]\]] produces [\\]]
4562 ;;; POSIX? [:word:] [:^word:] only inside []
4563 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]")
4564 (while ; look for unescaped ]
4565 (and argument
4566 (re-search-forward
4567 (if (eq (char-after b) ?\] )
4568 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]"
4569 "\\=\\(\\\\.\\|[^]\\\\]\\)*]")
4570 (1- e) 'toend))
4571 ;; Is this ] an end of POSIX class?
4572 (if (save-excursion
4573 (and
4574 (search-backward "[" argument t)
4575 (< REx-subgr-start (point))
4576 (setq argument (point)) ; POSIX-start
4577 (or ; Should work with delim = \
4578 (not (eq (preceding-char) ?\\ ))
4579 ;; XXXX Double \\ is needed with 19.33
4580 (= (% (skip-chars-backward "\\\\") 2) 0))
4581 (looking-at
4582 (cond
4583 ((eq (char-after b) ?\] )
4584 "\\\\*\\[:\\^?\\sw+:\\\\\\]")
4585 ((eq (char-after b) ?\: )
4586 "\\\\*\\[\\\\:\\^?\\sw+\\\\:]")
4587 ((eq (char-after b) ?^ )
4588 "\\\\*\\[:\\(\\\\\\^\\)?\\sw+:\]")
4589 ((eq (char-syntax (char-after b))
4591 (concat
4592 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\"
4593 (char-to-string (char-after b))
4594 "\\|\\sw\\)+:\]"))
4595 (t "\\\\*\\[:\\^?\\sw*:]")))
4596 (goto-char REx-subgr-end)
4597 (cperl-highlight-charclass
4598 argument my-cperl-REx-spec-char-face
4599 my-cperl-REx-0length-face my-cperl-REx-length1-face)))
4600 (setq tag (cons (cons argument (point))
4601 tag)
4602 argument (point)
4603 REx-subgr-end argument) ; continue
4604 (setq argument nil)))
4605 (and argument
4606 (message "Couldn't find end of charclass in a REx, pos=%s"
4607 REx-subgr-start))
4608 (setq argument (1- (point)))
4609 (goto-char REx-subgr-end)
4610 (cperl-highlight-charclass
4611 argument my-cperl-REx-spec-char-face
4612 my-cperl-REx-0length-face my-cperl-REx-length1-face)
4613 (forward-char 1)
4614 ;; Highlight starter, trailer, POSIX
4615 (if (and cperl-use-syntax-table-text-property
4616 (> (- (point) 2) REx-subgr-start))
4617 (put-text-property
4618 (1+ REx-subgr-start) (1- (point))
4619 'syntax-table cperl-st-punct))
4620 (cperl-postpone-fontification
4621 REx-subgr-start qtag
4622 'face my-cperl-REx-spec-char-face)
4623 (cperl-postpone-fontification
4624 (1- (point)) (point) 'face
4625 my-cperl-REx-spec-char-face)
4626 (if (eq (char-after b) ?\] )
4627 (cperl-postpone-fontification
4628 (- (point) 2) (1- (point))
4629 'face my-cperl-REx-0length-face))
4630 (while tag
4631 (cperl-postpone-fontification
4632 (car (car tag)) (cdr (car tag))
4633 'face font-lock-variable-name-face) ;my-cperl-REx-length1-face
4634 (setq tag (cdr tag)))
4635 (setq was-subgr nil)) ; did facing already
4636 ;; Now rare stuff:
4637 ((and (match-beginning 2) ; #-comment
4638 (/= (match-beginning 2) (match-end 2)))
4639 (beginning-of-line 2)
4640 (if (> (point) e)
4641 (goto-char (1- e))))
4642 ((match-beginning 4) ; character "]"
4643 (setq was-subgr nil) ; We do stuff here
4644 (goto-char (match-end 0))
4645 (if cperl-use-syntax-table-text-property
4646 (put-text-property
4647 (1- (point)) (point)
4648 'syntax-table cperl-st-punct))
4649 (cperl-postpone-fontification
4650 (1- (point)) (point)
4651 'face font-lock-warning-face))
4652 ((match-beginning 5) ; before (?{}) (??{})
4653 (setq tag (match-end 0))
4654 (if (or (setq qtag
4655 (cperl-forward-group-in-re st-l))
4656 (and (>= (point) e)
4657 (setq qtag "no matching `)' found"))
4658 (and (not (eq (char-after (- (point) 2))
4659 ?\} ))
4660 (setq qtag "Can't find })")))
4661 (progn
4662 (goto-char (1- e))
4663 (message "%s" qtag))
4664 (cperl-postpone-fontification
4665 (1- tag) (1- (point))
4666 'face font-lock-variable-name-face)
4667 (cperl-postpone-fontification
4668 REx-subgr-start (1- tag)
4669 'face my-cperl-REx-spec-char-face)
4670 (cperl-postpone-fontification
4671 (1- (point)) (point)
4672 'face my-cperl-REx-spec-char-face)
4673 (if cperl-use-syntax-table-text-property
4674 (progn
4675 (put-text-property
4676 (- (point) 2) (1- (point))
4677 'syntax-table cperl-st-cfence)
4678 (put-text-property
4679 (+ REx-subgr-start 2)
4680 (+ REx-subgr-start 3)
4681 'syntax-table cperl-st-cfence))))
4682 (setq was-subgr nil))
4683 (t ; (?#)-comment
4684 ;; Inside "(" and "\" arn't special in any way
4685 ;; Works also if the outside delimiters are ().
4686 (or;;(if (eq (char-after b) ?\) )
4687 ;;(re-search-forward
4688 ;; "[^\\\\]\\(\\\\\\\\\\)*\\\\)"
4689 ;; (1- e) 'toend)
4690 (search-forward ")" (1- e) 'toend)
4692 (message
4693 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
4694 REx-subgr-start))))
4695 (if (>= (point) e)
4696 (goto-char (1- e)))
4697 (cond
4698 (was-subgr
4699 (setq REx-subgr-end (point))
4700 (cperl-commentify
4701 REx-subgr-start REx-subgr-end nil)
4702 (cperl-postpone-fontification
4703 REx-subgr-start REx-subgr-end
4704 'face font-lock-comment-face))))))
4705 (if (and is-REx is-x-REx)
4706 (put-text-property (1+ b) (1- e)
4707 'syntax-subtype 'x-REx)))
4708 (if (and i2 e1 (or (not b1) (> e1 b1)))
4709 (progn ; No errors finding the second part...
4710 (cperl-postpone-fontification
4711 (1- e1) e1 'face my-cperl-delimiters-face)
4712 (if (and (not (eobp))
4713 (assoc (char-after b) cperl-starters))
4714 (progn
4715 (cperl-postpone-fontification
4716 b1 (1+ b1) 'face my-cperl-delimiters-face)
4717 (put-text-property b1 (1+ b1)
4718 'REx-part2 t)))))
4719 (if (> (point) max)
4720 (setq tmpend tb))))
4721 ((match-beginning 17) ; sub with prototype or attribute
4722 ;; 1+6+2+1+1=11 extra () before this (sub with proto/attr):
4723 ;;"\\<sub\\>\\(" ;12
4724 ;; cperl-white-and-comment-rex ;13
4725 ;; "\\([a-zA-Z_:'0-9]+\\)\\)?" ; name ;14
4726 ;;"\\(" cperl-maybe-white-and-comment-rex ;15,16
4727 ;; "\\(([^()]*)\\|:[^:]\\)\\)" ; 17:proto or attribute start
4728 (setq b1 (match-beginning 14) e1 (match-end 14))
4729 (if (memq (char-after (1- b))
4730 '(?\$ ?\@ ?\% ?\& ?\*))
4732 (goto-char b)
4733 (if (eq (char-after (match-beginning 17)) ?\( )
4734 (progn
4735 (cperl-commentify ; Prototypes; mark as string
4736 (match-beginning 17) (match-end 17) t)
4737 (goto-char (match-end 0))
4738 ;; Now look for attributes after prototype:
4739 (forward-comment (buffer-size))
4740 (and (looking-at ":[^:]")
4741 (cperl-find-sub-attrs st-l b1 e1 b)))
4742 ;; treat attributes without prototype
4743 (goto-char (match-beginning 17))
4744 (cperl-find-sub-attrs st-l b1 e1 b))))
4745 ;; 1+6+2+1+1+6+1=18 extra () before this:
4746 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
4747 ((match-beginning 19) ; old $abc'efg syntax
4748 (setq bb (match-end 0))
4749 ;;;(if (nth 3 state) nil ; in string
4750 (put-text-property (1- bb) bb 'syntax-table cperl-st-word)
4751 (goto-char bb))
4752 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
4753 ;; "__\\(END\\|DATA\\)__"
4754 ((match-beginning 20) ; __END__, __DATA__
4755 (setq bb (match-end 0))
4756 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
4757 (cperl-commentify b bb nil)
4758 (setq end t))
4759 ;; "\\\\\\(['`\"($]\\)"
4760 ((match-beginning 21)
4761 ;; Trailing backslash; make non-quoting outside string/comment
4762 (setq bb (match-end 0))
4763 (goto-char b)
4764 (skip-chars-backward "\\\\")
4765 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
4766 (cperl-modify-syntax-type b cperl-st-punct)
4767 (goto-char bb))
4768 (t (error "Error in regexp of the sniffer")))
4769 (if (> (point) stop-point)
4770 (progn
4771 (if end
4772 (message "Garbage after __END__/__DATA__ ignored")
4773 (message "Unbalanced syntax found while scanning")
4774 (or (car err-l) (setcar err-l b)))
4775 (goto-char stop-point))))
4776 (setq cperl-syntax-state (cons state-point state)
4777 ;; Do not mark syntax as done past tmpend???
4778 cperl-syntax-done-to (or tmpend (max (point) max)))
4779 ;;(message "state-at=%s, done-to=%s" state-point cperl-syntax-done-to)
4781 (if (car err-l) (goto-char (car err-l))
4782 (or non-inter
4783 (message "Scanning for \"hard\" Perl constructions... done"))))
4784 (and (buffer-modified-p)
4785 (not modified)
4786 (set-buffer-modified-p nil))
4787 ;; I do not understand what this is doing here. It breaks font-locking
4788 ;; because it resets the syntax-table from font-lock-syntax-table to
4789 ;; cperl-mode-syntax-table.
4790 ;; (set-syntax-table cperl-mode-syntax-table)
4792 (list (car err-l) overshoot)))
4794 (defun cperl-find-pods-heres-region (min max)
4795 (interactive "r")
4796 (cperl-find-pods-heres min max))
4798 (defun cperl-backward-to-noncomment (lim)
4799 ;; Stops at lim or after non-whitespace that is not in comment
4800 ;; XXXX Wrongly understands end-of-multiline strings with # as comment
4801 (let (stop p pr)
4802 (while (and (not stop) (> (point) (or lim (point-min))))
4803 (skip-chars-backward " \t\n\f" lim)
4804 (setq p (point))
4805 (beginning-of-line)
4806 (if (memq (setq pr (get-text-property (point) 'syntax-type))
4807 '(pod here-doc here-doc-delim))
4808 (progn
4809 (cperl-unwind-to-safe nil)
4810 (setq pr (get-text-property (point) 'syntax-type))))
4811 (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
4812 (not (memq pr '(string prestring))))
4813 (progn (cperl-to-comment-or-eol) (bolp))
4814 (progn
4815 (skip-chars-backward " \t")
4816 (if (< p (point)) (goto-char p))
4817 (setq stop t))))))
4819 ;; Used only in `cperl-calculate-indent'...
4820 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
4821 ;; Positions is before ?\{. Checks whether it starts a block.
4822 ;; No save-excursion! This is more a distinguisher of a block/hash ref...
4823 (cperl-backward-to-noncomment (point-min))
4824 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
4825 ; Label may be mixed up with `$blah :'
4826 (save-excursion (cperl-after-label))
4827 (get-text-property (cperl-1- (point)) 'attrib-group)
4828 (and (memq (char-syntax (preceding-char)) '(?w ?_))
4829 (progn
4830 (backward-sexp)
4831 ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
4832 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
4833 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
4834 ;; sub bless::foo {}
4835 (progn
4836 (cperl-backward-to-noncomment (point-min))
4837 (and (eq (preceding-char) ?b)
4838 (progn
4839 (forward-sexp -1)
4840 (looking-at "sub[ \t\n\f#]")))))))))
4842 ;;; What is the difference of (cperl-after-block-p lim t) and (cperl-block-p)?
4843 ;;; No save-excursion; condition-case ... In (cperl-block-p) the block
4844 ;;; may be a part of an in-statement construct, such as
4845 ;;; ${something()}, print {FH} $data.
4846 ;;; Moreover, one takes positive approach (looks for else,grep etc)
4847 ;;; another negative (looks for bless,tr etc)
4848 (defun cperl-after-block-p (lim &optional pre-block)
4849 "Return true if the preceding } (if PRE-BLOCK, following {) delimits a block.
4850 Would not look before LIM. Assumes that LIM is a good place to begin a
4851 statement. The kind of block we treat here is one after which a new
4852 statement would start; thus the block in ${func()} does not count."
4853 (save-excursion
4854 (condition-case nil
4855 (progn
4856 (or pre-block (forward-sexp -1))
4857 (cperl-backward-to-noncomment lim)
4858 (or (eq (point) lim)
4859 ;; if () {} // sub f () {} // sub f :a(') {}
4860 (eq (preceding-char) ?\) )
4861 ;; label: {}
4862 (save-excursion (cperl-after-label))
4863 ;; sub :attr {}
4864 (get-text-property (cperl-1- (point)) 'attrib-group)
4865 (if (memq (char-syntax (preceding-char)) '(?w ?_)) ; else {}
4866 (save-excursion
4867 (forward-sexp -1)
4868 ;; else {} but not else::func {}
4869 (or (and (looking-at "\\(else\\|continue\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
4870 (not (looking-at "\\(\\sw\\|_\\)+::")))
4871 ;; sub f {}
4872 (progn
4873 (cperl-backward-to-noncomment lim)
4874 (and (eq (preceding-char) ?b)
4875 (progn
4876 (forward-sexp -1)
4877 (looking-at "sub[ \t\n\f#]"))))))
4878 ;; What precedes is not word... XXXX Last statement in sub???
4879 (cperl-after-expr-p lim))))
4880 (error nil))))
4882 (defun cperl-after-expr-p (&optional lim chars test)
4883 "Return true if the position is good for start of expression.
4884 TEST is the expression to evaluate at the found position. If absent,
4885 CHARS is a string that contains good characters to have before us (however,
4886 `}' is treated \"smartly\" if it is not in the list)."
4887 (let ((lim (or lim (point-min)))
4888 stop p pr)
4889 (cperl-update-syntaxification (point) (point))
4890 (save-excursion
4891 (while (and (not stop) (> (point) lim))
4892 (skip-chars-backward " \t\n\f" lim)
4893 (setq p (point))
4894 (beginning-of-line)
4895 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
4896 ;; '(pod here-doc here-doc-delim))
4897 (if (get-text-property (point) 'here-doc-group)
4898 (progn
4899 (goto-char
4900 (cperl-beginning-of-property (point) 'here-doc-group))
4901 (beginning-of-line 0)))
4902 (if (get-text-property (point) 'in-pod)
4903 (progn
4904 (goto-char
4905 (cperl-beginning-of-property (point) 'in-pod))
4906 (beginning-of-line 0)))
4907 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
4908 ;; Else: last iteration, or a label
4909 (cperl-to-comment-or-eol) ; Will not move past "." after a format
4910 (skip-chars-backward " \t")
4911 (if (< p (point)) (goto-char p))
4912 (setq p (point))
4913 (if (and (eq (preceding-char) ?:)
4914 (progn
4915 (forward-char -1)
4916 (skip-chars-backward " \t\n\f" lim)
4917 (memq (char-syntax (preceding-char)) '(?w ?_))))
4918 (forward-sexp -1) ; Possibly label. Skip it
4919 (goto-char p)
4920 (setq stop t))))
4921 (or (bobp) ; ???? Needed
4922 (eq (point) lim)
4923 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
4924 (progn
4925 (if test (eval test)
4926 (or (memq (preceding-char) (append (or chars "{;") nil))
4927 (and (eq (preceding-char) ?\})
4928 (cperl-after-block-p lim))
4929 (and (eq (following-char) ?.) ; in format: see comment above
4930 (eq (get-text-property (point) 'syntax-type)
4931 'format)))))))))
4933 (defun cperl-backward-to-start-of-expr (&optional lim)
4934 (condition-case nil
4935 (progn
4936 (while (and (or (not lim)
4937 (> (point) lim))
4938 (not (cperl-after-expr-p lim)))
4939 (forward-sexp -1)
4940 ;; May be after $, @, $# etc of a variable
4941 (skip-chars-backward "$@%#")))
4942 (error nil)))
4944 (defun cperl-at-end-of-expr (&optional lim)
4945 ;; Since the SEXP approach below is very fragile, do some overengineering
4946 (or (looking-at (concat cperl-maybe-white-and-comment-rex "[;}]"))
4947 (condition-case nil
4948 (save-excursion
4949 ;; If nothing interesting after, does as (forward-sexp -1);
4950 ;; otherwise fails, or ends at a start of following sexp.
4951 ;; XXXX PROBLEMS: if what follows (after ";") @FOO, or ${bar}
4952 ;; may be stuck after @ or $; just put some stupid workaround now:
4953 (let ((p (point)))
4954 (forward-sexp 1)
4955 (forward-sexp -1)
4956 (while (memq (preceding-char) (append "%&@$*" nil))
4957 (forward-char -1))
4958 (or (< (point) p)
4959 (cperl-after-expr-p lim))))
4960 (error t))))
4962 (defun cperl-forward-to-end-of-expr (&optional lim)
4963 (let ((p (point))))
4964 (condition-case nil
4965 (progn
4966 (while (and (< (point) (or lim (point-max)))
4967 (not (cperl-at-end-of-expr)))
4968 (forward-sexp 1)))
4969 (error nil)))
4971 (defun cperl-backward-to-start-of-continued-exp (lim)
4972 (if (memq (preceding-char) (append ")]}\"'`" nil))
4973 (forward-sexp -1))
4974 (beginning-of-line)
4975 (if (<= (point) lim)
4976 (goto-char (1+ lim)))
4977 (skip-chars-forward " \t"))
4979 (defun cperl-after-block-and-statement-beg (lim)
4980 ;; We assume that we are after ?\}
4981 (and
4982 (cperl-after-block-p lim)
4983 (save-excursion
4984 (forward-sexp -1)
4985 (cperl-backward-to-noncomment (point-min))
4986 (or (bobp)
4987 (eq (point) lim)
4988 (not (= (char-syntax (preceding-char)) ?w))
4989 (progn
4990 (forward-sexp -1)
4991 (not
4992 (looking-at
4993 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
4996 (defun cperl-indent-exp ()
4997 "Simple variant of indentation of continued-sexp.
4999 Will not indent comment if it starts at `comment-indent' or looks like
5000 continuation of the comment on the previous line.
5002 If `cperl-indent-region-fix-constructs', will improve spacing on
5003 conditional/loop constructs."
5004 (interactive)
5005 (save-excursion
5006 (let ((tmp-end (point-at-eol)) top done)
5007 (save-excursion
5008 (beginning-of-line)
5009 (while (null done)
5010 (setq top (point))
5011 ;; Plan A: if line has an unfinished paren-group, go to end-of-group
5012 (while (= -1 (nth 0 (parse-partial-sexp (point) tmp-end -1)))
5013 (setq top (point))) ; Get the outermost parens in line
5014 (goto-char top)
5015 (while (< (point) tmp-end)
5016 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
5017 (or (eolp) (forward-sexp 1)))
5018 (if (> (point) tmp-end) ; Yes, there an unfinished block
5020 (if (eq ?\) (preceding-char))
5021 (progn ;; Plan B: find by REGEXP block followup this line
5022 (setq top (point))
5023 (condition-case nil
5024 (progn
5025 (forward-sexp -2)
5026 (if (eq (following-char) ?$ ) ; for my $var (list)
5027 (progn
5028 (forward-sexp -1)
5029 (if (looking-at "\\(my\\|local\\|our\\)\\>")
5030 (forward-sexp -1))))
5031 (if (looking-at
5032 (concat "\\(\\elsif\\|if\\|unless\\|while\\|until"
5033 "\\|for\\(each\\)?\\>\\(\\("
5034 cperl-maybe-white-and-comment-rex
5035 "\\(my\\|local\\|our\\)\\)?"
5036 cperl-maybe-white-and-comment-rex
5037 "\\$[_a-zA-Z0-9]+\\)?\\)\\>"))
5038 (progn
5039 (goto-char top)
5040 (forward-sexp 1)
5041 (setq top (point)))))
5042 (error (setq done t)))
5043 (goto-char top))
5044 (if (looking-at ; Try Plan C: continuation block
5045 (concat cperl-maybe-white-and-comment-rex
5046 "\\<\\(else\\|elsif\|continue\\)\\>"))
5047 (progn
5048 (goto-char (match-end 0))
5049 (setq tmp-end (point-at-eol)))
5050 (setq done t))))
5051 (setq tmp-end (point-at-eol)))
5052 (goto-char tmp-end)
5053 (setq tmp-end (point-marker)))
5054 (if cperl-indent-region-fix-constructs
5055 (cperl-fix-line-spacing tmp-end))
5056 (cperl-indent-region (point) tmp-end))))
5058 (defun cperl-fix-line-spacing (&optional end parse-data)
5059 "Improve whitespace in a conditional/loop construct.
5060 Returns some position at the last line."
5061 (interactive)
5062 (or end
5063 (setq end (point-max)))
5064 (let ((ee (point-at-eol))
5065 (cperl-indent-region-fix-constructs
5066 (or cperl-indent-region-fix-constructs 1))
5067 p pp ml have-brace ret)
5068 (save-excursion
5069 (beginning-of-line)
5070 (setq ret (point))
5071 ;; }? continue
5072 ;; blah; }
5073 (if (not
5074 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
5075 (setq have-brace (save-excursion (search-forward "}" ee t)))))
5076 nil ; Do not need to do anything
5077 ;; Looking at:
5078 ;; }
5079 ;; else
5080 (if cperl-merge-trailing-else
5081 (if (looking-at
5082 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5083 (progn
5084 (search-forward "}")
5085 (setq p (point))
5086 (skip-chars-forward " \t\n")
5087 (delete-region p (point))
5088 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5089 (beginning-of-line)))
5090 (if (looking-at "[ \t]*}[ \t]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
5091 (save-excursion
5092 (search-forward "}")
5093 (delete-horizontal-space)
5094 (insert "\n")
5095 (setq ret (point))
5096 (if (cperl-indent-line parse-data)
5097 (progn
5098 (cperl-fix-line-spacing end parse-data)
5099 (setq ret (point)))))))
5100 ;; Looking at:
5101 ;; } else
5102 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
5103 (progn
5104 (search-forward "}")
5105 (delete-horizontal-space)
5106 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5107 (beginning-of-line)))
5108 ;; Looking at:
5109 ;; else {
5110 (if (looking-at
5111 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5112 (progn
5113 (forward-word 1)
5114 (delete-horizontal-space)
5115 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5116 (beginning-of-line)))
5117 ;; Looking at:
5118 ;; foreach my $var
5119 (if (looking-at
5120 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
5121 (progn
5122 (forward-word 2)
5123 (delete-horizontal-space)
5124 (insert (make-string cperl-indent-region-fix-constructs ?\s))
5125 (beginning-of-line)))
5126 ;; Looking at:
5127 ;; foreach my $var (
5128 (if (looking-at
5129 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
5130 (progn
5131 (forward-sexp 3)
5132 (delete-horizontal-space)
5133 (insert
5134 (make-string cperl-indent-region-fix-constructs ?\s))
5135 (beginning-of-line)))
5136 ;; Looking at (with or without "}" at start, ending after "({"):
5137 ;; } foreach my $var () OR {
5138 (if (looking-at
5139 "[ \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]*{")
5140 (progn
5141 (setq ml (match-beginning 8)) ; "(" or "{" after control word
5142 (re-search-forward "[({]")
5143 (forward-char -1)
5144 (setq p (point))
5145 (if (eq (following-char) ?\( )
5146 (progn
5147 (forward-sexp 1)
5148 (setq pp (point))) ; past parenthesis-group
5149 ;; after `else' or nothing
5150 (if ml ; after `else'
5151 (skip-chars-backward " \t\n")
5152 (beginning-of-line))
5153 (setq pp nil))
5154 ;; Now after the sexp before the brace
5155 ;; Multiline expr should be special
5156 (setq ml (and pp (save-excursion (goto-char p)
5157 (search-forward "\n" pp t))))
5158 (if (and (or (not pp) (< pp end)) ; Do not go too far...
5159 (looking-at "[ \t\n]*{"))
5160 (progn
5161 (cond
5162 ((bolp) ; Were before `{', no if/else/etc
5163 nil)
5164 ((looking-at "\\(\t*\\| [ \t]+\\){") ; Not exactly 1 SPACE
5165 (delete-horizontal-space)
5166 (if (if ml
5167 cperl-extra-newline-before-brace-multiline
5168 cperl-extra-newline-before-brace)
5169 (progn
5170 (delete-horizontal-space)
5171 (insert "\n")
5172 (setq ret (point))
5173 (if (cperl-indent-line parse-data)
5174 (progn
5175 (cperl-fix-line-spacing end parse-data)
5176 (setq ret (point)))))
5177 (insert
5178 (make-string cperl-indent-region-fix-constructs ?\s))))
5179 ((and (looking-at "[ \t]*\n")
5180 (not (if ml
5181 cperl-extra-newline-before-brace-multiline
5182 cperl-extra-newline-before-brace)))
5183 (setq pp (point))
5184 (skip-chars-forward " \t\n")
5185 (delete-region pp (point))
5186 (insert
5187 (make-string cperl-indent-region-fix-constructs ?\ )))
5188 ((and (looking-at "[\t ]*{")
5189 (if ml cperl-extra-newline-before-brace-multiline
5190 cperl-extra-newline-before-brace))
5191 (delete-horizontal-space)
5192 (insert "\n")
5193 (setq ret (point))
5194 (if (cperl-indent-line parse-data)
5195 (progn
5196 (cperl-fix-line-spacing end parse-data)
5197 (setq ret (point))))))
5198 ;; Now we are before `{'
5199 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
5200 (progn
5201 (skip-chars-forward " \t\n")
5202 (setq pp (point))
5203 (forward-sexp 1)
5204 (setq p (point))
5205 (goto-char pp)
5206 (setq ml (search-forward "\n" p t))
5207 (if (or cperl-break-one-line-blocks-when-indent ml)
5208 ;; not good: multi-line BLOCK
5209 (progn
5210 (goto-char (1+ pp))
5211 (delete-horizontal-space)
5212 (insert "\n")
5213 (setq ret (point))
5214 (if (cperl-indent-line parse-data)
5215 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
5216 (beginning-of-line)
5217 (setq p (point) pp (point-at-eol)) ; May be different from ee.
5218 ;; Now check whether there is a hanging `}'
5219 ;; Looking at:
5220 ;; } blah
5221 (if (and
5222 cperl-fix-hanging-brace-when-indent
5223 have-brace
5224 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
5225 (condition-case nil
5226 (progn
5227 (up-list 1)
5228 (if (and (<= (point) pp)
5229 (eq (preceding-char) ?\} )
5230 (cperl-after-block-and-statement-beg (point-min)))
5232 (goto-char p)
5233 nil))
5234 (error nil)))
5235 (progn
5236 (forward-char -1)
5237 (skip-chars-backward " \t")
5238 (if (bolp)
5239 ;; `}' was the first thing on the line, insert NL *after* it.
5240 (progn
5241 (cperl-indent-line parse-data)
5242 (search-forward "}")
5243 (delete-horizontal-space)
5244 (insert "\n"))
5245 (delete-horizontal-space)
5246 (or (eq (preceding-char) ?\;)
5247 (bolp)
5248 (and (eq (preceding-char) ?\} )
5249 (cperl-after-block-p (point-min)))
5250 (insert ";"))
5251 (insert "\n")
5252 (setq ret (point)))
5253 (if (cperl-indent-line parse-data)
5254 (setq ret (cperl-fix-line-spacing end parse-data)))
5255 (beginning-of-line)))))
5256 ret))
5258 (defvar cperl-update-start) ; Do not need to make them local
5259 (defvar cperl-update-end)
5260 (defun cperl-delay-update-hook (beg end old-len)
5261 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
5262 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
5264 (defun cperl-indent-region (start end)
5265 "Simple variant of indentation of region in CPerl mode.
5266 Should be slow. Will not indent comment if it starts at `comment-indent'
5267 or looks like continuation of the comment on the previous line.
5268 Indents all the lines whose first character is between START and END
5269 inclusive.
5271 If `cperl-indent-region-fix-constructs', will improve spacing on
5272 conditional/loop constructs."
5273 (interactive "r")
5274 (cperl-update-syntaxification end end)
5275 (save-excursion
5276 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
5277 (let ((indent-info (if cperl-emacs-can-parse
5278 (list nil nil nil) ; Cannot use '(), since will modify
5279 nil))
5280 (pm 0)
5281 after-change-functions ; Speed it up!
5282 st comm old-comm-indent new-comm-indent p pp i empty)
5283 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
5284 (goto-char start)
5285 (setq old-comm-indent (and (cperl-to-comment-or-eol)
5286 (current-column))
5287 new-comm-indent old-comm-indent)
5288 (goto-char start)
5289 (setq end (set-marker (make-marker) end)) ; indentation changes pos
5290 (or (bolp) (beginning-of-line 2))
5291 (while (and (<= (point) end) (not (eobp))) ; bol to check start
5292 (setq st (point))
5293 (if (or
5294 (setq empty (looking-at "[ \t]*\n"))
5295 (and (setq comm (looking-at "[ \t]*#"))
5296 (or (eq (current-indentation) (or old-comm-indent
5297 comment-column))
5298 (setq old-comm-indent nil))))
5299 (if (and old-comm-indent
5300 (not empty)
5301 (= (current-indentation) old-comm-indent)
5302 (not (eq (get-text-property (point) 'syntax-type) 'pod))
5303 (not (eq (get-text-property (point) 'syntax-table)
5304 cperl-st-cfence)))
5305 (let ((comment-column new-comm-indent))
5306 (indent-for-comment)))
5307 (progn
5308 (setq i (cperl-indent-line indent-info))
5309 (or comm
5310 (not i)
5311 (progn
5312 (if cperl-indent-region-fix-constructs
5313 (goto-char (cperl-fix-line-spacing end indent-info)))
5314 (if (setq old-comm-indent
5315 (and (cperl-to-comment-or-eol)
5316 (not (memq (get-text-property (point)
5317 'syntax-type)
5318 '(pod here-doc)))
5319 (not (eq (get-text-property (point)
5320 'syntax-table)
5321 cperl-st-cfence))
5322 (current-column)))
5323 (progn (indent-for-comment)
5324 (skip-chars-backward " \t")
5325 (skip-chars-backward "#")
5326 (setq new-comm-indent (current-column))))))))
5327 (beginning-of-line 2)))
5328 ;; Now run the update hooks
5329 (and after-change-functions
5330 cperl-update-end
5331 (save-excursion
5332 (goto-char cperl-update-end)
5333 (insert " ")
5334 (delete-char -1)
5335 (goto-char cperl-update-start)
5336 (insert " ")
5337 (delete-char -1))))))
5339 ;; Stolen from lisp-mode with a lot of improvements
5341 (defun cperl-fill-paragraph (&optional justify iteration)
5342 "Like `fill-paragraph', but handle CPerl comments.
5343 If any of the current line is a comment, fill the comment or the
5344 block of it that point is in, preserving the comment's initial
5345 indentation and initial hashes. Behaves usually outside of comment."
5346 ;; (interactive "P") ; Only works when called from fill-paragraph. -stef
5347 (let (;; Non-nil if the current line contains a comment.
5348 has-comment
5349 fill-paragraph-function ; do not recurse
5350 ;; If has-comment, the appropriate fill-prefix for the comment.
5351 comment-fill-prefix
5352 ;; Line that contains code and comment (or nil)
5353 start
5354 c spaces len dc (comment-column comment-column))
5355 ;; Figure out what kind of comment we are looking at.
5356 (save-excursion
5357 (beginning-of-line)
5358 (cond
5360 ;; A line with nothing but a comment on it?
5361 ((looking-at "[ \t]*#[# \t]*")
5362 (setq has-comment t
5363 comment-fill-prefix (buffer-substring (match-beginning 0)
5364 (match-end 0))))
5366 ;; A line with some code, followed by a comment? Remember that the
5367 ;; semi which starts the comment shouldn't be part of a string or
5368 ;; character.
5369 ((cperl-to-comment-or-eol)
5370 (setq has-comment t)
5371 (looking-at "#+[ \t]*")
5372 (setq start (point) c (current-column)
5373 comment-fill-prefix
5374 (concat (make-string (current-column) ?\s)
5375 (buffer-substring (match-beginning 0) (match-end 0)))
5376 spaces (progn (skip-chars-backward " \t")
5377 (buffer-substring (point) start))
5378 dc (- c (current-column)) len (- start (point))
5379 start (point-marker))
5380 (delete-char len)
5381 (insert (make-string dc ?-))))) ; Placeholder (to avoid splitting???)
5382 (if (not has-comment)
5383 (fill-paragraph justify) ; Do the usual thing outside of comment
5384 ;; Narrow to include only the comment, and then fill the region.
5385 (save-restriction
5386 (narrow-to-region
5387 ;; Find the first line we should include in the region to fill.
5388 (if start (progn (beginning-of-line) (point))
5389 (save-excursion
5390 (while (and (zerop (forward-line -1))
5391 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5392 ;; We may have gone to far. Go forward again.
5393 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
5394 (forward-line 1))
5395 (point)))
5396 ;; Find the beginning of the first line past the region to fill.
5397 (save-excursion
5398 (while (progn (forward-line 1)
5399 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
5400 (point)))
5401 ;; Remove existing hashes
5402 (goto-char (point-min))
5403 (save-excursion
5404 (while (progn (forward-line 1) (< (point) (point-max)))
5405 (skip-chars-forward " \t")
5406 (if (looking-at "#+")
5407 (progn
5408 (if (and (eq (point) (match-beginning 0))
5409 (not (eq (point) (match-end 0)))) nil
5410 (error
5411 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage"))
5412 (delete-char (- (match-end 0) (match-beginning 0)))))))
5414 ;; Lines with only hashes on them can be paragraph boundaries.
5415 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
5416 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
5417 (fill-prefix comment-fill-prefix))
5418 (fill-paragraph justify)))
5419 (if (and start)
5420 (progn
5421 (goto-char start)
5422 (if (> dc 0)
5423 (progn (delete-char dc) (insert spaces)))
5424 (if (or (= (current-column) c) iteration) nil
5425 (setq comment-column c)
5426 (indent-for-comment)
5427 ;; Repeat once more, flagging as iteration
5428 (cperl-fill-paragraph justify t))))))
5431 (defun cperl-do-auto-fill ()
5432 ;; Break out if the line is short enough
5433 (if (> (save-excursion
5434 (end-of-line)
5435 (current-column))
5436 fill-column)
5437 (let ((c (save-excursion (beginning-of-line)
5438 (cperl-to-comment-or-eol) (point)))
5439 (s (memq (following-char) '(?\s ?\t))) marker)
5440 (if (>= c (point))
5441 ;; Don't break line inside code: only inside comment.
5443 (setq marker (point-marker))
5444 (fill-paragraph nil)
5445 (goto-char marker)
5446 ;; Is not enough, sometimes marker is a start of line
5447 (if (bolp) (progn (re-search-forward "#+[ \t]*")
5448 (goto-char (match-end 0))))
5449 ;; Following space could have gone:
5450 (if (or (not s) (memq (following-char) '(?\s ?\t))) nil
5451 (insert " ")
5452 (backward-char 1))
5453 ;; Previous space could have gone:
5454 (or (memq (preceding-char) '(?\s ?\t)) (insert " "))))))
5456 (defun cperl-imenu-addback (lst &optional isback name)
5457 ;; We suppose that the lst is a DAG, unless the first element only
5458 ;; loops back, and ISBACK is set. Thus this function cannot be
5459 ;; applied twice without ISBACK set.
5460 (cond ((not cperl-imenu-addback) lst)
5462 (or name
5463 (setq name "+++BACK+++"))
5464 (mapc (lambda (elt)
5465 (if (and (listp elt) (listp (cdr elt)))
5466 (progn
5467 ;; In the other order it goes up
5468 ;; one level only ;-(
5469 (setcdr elt (cons (cons name lst)
5470 (cdr elt)))
5471 (cperl-imenu-addback (cdr elt) t name))))
5472 (if isback (cdr lst) lst))
5473 lst)))
5475 (defun cperl-imenu--create-perl-index (&optional regexp)
5476 (require 'imenu) ; May be called from TAGS creator
5477 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
5478 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
5479 (index-meth-alist '()) meth
5480 packages ends-ranges p marker is-proto
5481 (prev-pos 0) is-pack index index1 name (end-range 0) package)
5482 (goto-char (point-min))
5483 (cperl-update-syntaxification (point-max) (point-max))
5484 ;; Search for the function
5485 (progn ;;save-match-data
5486 (while (re-search-forward
5487 (or regexp cperl-imenu--function-name-regexp-perl)
5488 nil t)
5489 ;; 2=package-group, 5=package-name 8=sub-name
5490 (cond
5491 ((and ; Skip some noise if building tags
5492 (match-beginning 5) ; package name
5493 ;;(eq (char-after (match-beginning 2)) ?p) ; package
5494 (not (save-match-data
5495 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
5496 nil)
5497 ((and
5498 (or (match-beginning 2)
5499 (match-beginning 8)) ; package or sub
5500 ;; Skip if quoted (will not skip multi-line ''-strings :-():
5501 (null (get-text-property (match-beginning 1) 'syntax-table))
5502 (null (get-text-property (match-beginning 1) 'syntax-type))
5503 (null (get-text-property (match-beginning 1) 'in-pod)))
5504 (setq is-pack (match-beginning 2))
5505 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
5506 ;; (goto-char (match-end 0))) ; Messes what follows
5507 (setq meth nil
5508 p (point))
5509 (while (and ends-ranges (>= p (car ends-ranges)))
5510 ;; delete obsolete entries
5511 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
5512 (setq package (or (car packages) "")
5513 end-range (or (car ends-ranges) 0))
5514 (if is-pack ; doing "package"
5515 (progn
5516 (if (match-beginning 5) ; named package
5517 (setq name (buffer-substring (match-beginning 5)
5518 (match-end 5))
5519 name (progn
5520 (set-text-properties 0 (length name) nil name)
5521 name)
5522 package (concat name "::")
5523 name (concat "package " name))
5524 ;; Support nameless packages
5525 (setq name "package;" package ""))
5526 (setq end-range
5527 (save-excursion
5528 (parse-partial-sexp (point) (point-max) -1) (point))
5529 ends-ranges (cons end-range ends-ranges)
5530 packages (cons package packages)))
5531 (setq is-proto
5532 (or (eq (following-char) ?\;)
5533 (eq 0 (get-text-property (point) 'attrib-group)))))
5534 ;; Skip this function name if it is a prototype declaration.
5535 (if (and is-proto (not is-pack)) nil
5536 (or is-pack
5537 (setq name
5538 (buffer-substring (match-beginning 8) (match-end 8)))
5539 (set-text-properties 0 (length name) nil name))
5540 (setq marker (make-marker))
5541 (set-marker marker (match-end (if is-pack 2 8)))
5542 (cond (is-pack nil)
5543 ((string-match "[:']" name)
5544 (setq meth t))
5545 ((> p end-range) nil)
5547 (setq name (concat package name) meth t)))
5548 (setq index (cons name marker))
5549 (if is-pack
5550 (push index index-pack-alist)
5551 (push index index-alist))
5552 (if meth (push index index-meth-alist))
5553 (push index index-unsorted-alist)))
5554 ((match-beginning 16) ; POD section
5555 (setq name (buffer-substring (match-beginning 17) (match-end 17))
5556 marker (make-marker))
5557 (set-marker marker (match-beginning 17))
5558 (set-text-properties 0 (length name) nil name)
5559 (setq name (concat (make-string
5560 (* 3 (- (char-after (match-beginning 16)) ?1))
5561 ?\ )
5562 name)
5563 index (cons name marker))
5564 (setq index1 (cons (concat "=" name) (cdr index)))
5565 (push index index-pod-alist)
5566 (push index1 index-unsorted-alist)))))
5567 (setq index-alist
5568 (if (default-value 'imenu-sort-function)
5569 (sort index-alist (default-value 'imenu-sort-function))
5570 (nreverse index-alist)))
5571 (and index-pod-alist
5572 (push (cons "+POD headers+..."
5573 (nreverse index-pod-alist))
5574 index-alist))
5575 (and (or index-pack-alist index-meth-alist)
5576 (let ((lst index-pack-alist) hier-list pack elt group name)
5577 ;; Remove "package ", reverse and uniquify.
5578 (while lst
5579 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
5580 (if (assoc name hier-list) nil
5581 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
5582 (setq lst index-meth-alist)
5583 (while lst
5584 (setq elt (car lst) lst (cdr lst))
5585 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
5586 (setq pack (substring (car elt) 0 (match-beginning 0)))
5587 (if (setq group (assoc pack hier-list))
5588 (if (listp (cdr group))
5589 ;; Have some functions already
5590 (setcdr group
5591 (cons (cons (substring
5592 (car elt)
5593 (+ 2 (match-beginning 0)))
5594 (cdr elt))
5595 (cdr group)))
5596 (setcdr group (list (cons (substring
5597 (car elt)
5598 (+ 2 (match-beginning 0)))
5599 (cdr elt)))))
5600 (setq hier-list
5601 (cons (cons pack
5602 (list (cons (substring
5603 (car elt)
5604 (+ 2 (match-beginning 0)))
5605 (cdr elt))))
5606 hier-list))))))
5607 (push (cons "+Hierarchy+..."
5608 hier-list)
5609 index-alist)))
5610 (and index-pack-alist
5611 (push (cons "+Packages+..."
5612 (nreverse index-pack-alist))
5613 index-alist))
5614 (and (or index-pack-alist index-pod-alist
5615 (default-value 'imenu-sort-function))
5616 index-unsorted-alist
5617 (push (cons "+Unsorted List+..."
5618 (nreverse index-unsorted-alist))
5619 index-alist))
5620 (cperl-imenu-addback index-alist)))
5623 ;; Suggested by Mark A. Hershberger
5624 (defun cperl-outline-level ()
5625 (looking-at outline-regexp)
5626 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
5627 ;;;; 2=package-group, 5=package-name 8=sub-name 16=head-level
5628 ((match-beginning 2) 0) ; package
5629 ((match-beginning 8) 1) ; sub
5630 ((match-beginning 16)
5631 (- (char-after (match-beginning 16)) ?0)) ; headN ==> N
5632 (t 5))) ; should not happen
5635 (defun cperl-windowed-init ()
5636 "Initialization under windowed version."
5637 (cond ((featurep 'ps-print)
5638 (or cperl-faces-init
5639 (progn
5640 (and (boundp 'font-lock-multiline)
5641 (setq cperl-font-lock-multiline t))
5642 (cperl-init-faces))))
5643 ((not cperl-faces-init)
5644 (add-hook 'font-lock-mode-hook
5645 (function
5646 (lambda ()
5647 (if (memq major-mode '(perl-mode cperl-mode))
5648 (progn
5649 (or cperl-faces-init (cperl-init-faces)))))))
5650 (if (fboundp 'eval-after-load)
5651 (eval-after-load
5652 "ps-print"
5653 '(or cperl-faces-init (cperl-init-faces)))))))
5655 (defvar cperl-font-lock-keywords-1 nil
5656 "Additional expressions to highlight in Perl mode. Minimal set.")
5657 (defvar cperl-font-lock-keywords nil
5658 "Additional expressions to highlight in Perl mode. Default set.")
5659 (defvar cperl-font-lock-keywords-2 nil
5660 "Additional expressions to highlight in Perl mode. Maximal set")
5662 (defun cperl-load-font-lock-keywords ()
5663 (or cperl-faces-init (cperl-init-faces))
5664 cperl-font-lock-keywords)
5666 (defun cperl-load-font-lock-keywords-1 ()
5667 (or cperl-faces-init (cperl-init-faces))
5668 cperl-font-lock-keywords-1)
5670 (defun cperl-load-font-lock-keywords-2 ()
5671 (or cperl-faces-init (cperl-init-faces))
5672 cperl-font-lock-keywords-2)
5674 (defun cperl-init-faces-weak ()
5675 ;; Allow `cperl-find-pods-heres' to run.
5676 (or (boundp 'font-lock-constant-face)
5677 (cperl-force-face font-lock-constant-face
5678 "Face for constant and label names"))
5679 (or (boundp 'font-lock-warning-face)
5680 (cperl-force-face font-lock-warning-face
5681 "Face for things which should stand out"))
5682 ;;(setq font-lock-constant-face 'font-lock-constant-face)
5685 (defun cperl-init-faces ()
5686 (condition-case errs
5687 (progn
5688 (require 'font-lock)
5689 (and (fboundp 'font-lock-fontify-anchored-keywords)
5690 (featurep 'font-lock-extra)
5691 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
5692 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
5693 (if (fboundp 'font-lock-fontify-anchored-keywords)
5694 (setq font-lock-anchored t))
5695 (setq
5696 t-font-lock-keywords
5697 (list
5698 `("[ \t]+$" 0 ',cperl-invalid-face t)
5699 (cons
5700 (concat
5701 "\\(^\\|[^$@%&\\]\\)\\<\\("
5702 (mapconcat
5703 'identity
5704 '("if" "until" "while" "elsif" "else" "unless" "for"
5705 "foreach" "continue" "exit" "die" "last" "goto" "next"
5706 "redo" "return" "local" "exec" "sub" "do" "dump" "use" "our"
5707 "require" "package" "eval" "my" "BEGIN" "END" "CHECK" "INIT")
5708 "\\|") ; Flow control
5709 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
5710 ; In what follows we use `type' style
5711 ; for overwritable builtins
5712 (list
5713 (concat
5714 "\\(^\\|[^$@%&\\]\\)\\<\\("
5715 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
5716 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
5717 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
5718 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
5719 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
5720 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
5721 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
5722 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
5723 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
5724 ;; "gethostbyname" "gethostent" "getlogin"
5725 ;; "getnetbyaddr" "getnetbyname" "getnetent"
5726 ;; "getpeername" "getpgrp" "getppid" "getpriority"
5727 ;; "getprotobyname" "getprotobynumber" "getprotoent"
5728 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
5729 ;; "getservbyport" "getservent" "getsockname"
5730 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
5731 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
5732 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
5733 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
5734 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
5735 ;; "quotemeta" "rand" "read" "readdir" "readline"
5736 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
5737 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
5738 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
5739 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
5740 ;; "setpriority" "setprotoent" "setpwent" "setservent"
5741 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
5742 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
5743 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
5744 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
5745 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
5746 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
5747 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
5748 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
5749 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
5750 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
5751 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
5752 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
5753 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
5754 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
5755 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
5756 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
5757 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
5758 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
5759 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
5760 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
5761 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
5762 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
5763 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
5764 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
5765 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
5766 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
5767 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
5768 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
5769 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
5770 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
5771 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
5772 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
5773 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
5774 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
5775 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
5776 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
5777 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
5778 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
5779 "\\)\\>") 2 'font-lock-type-face)
5780 ;; In what follows we use `other' style
5781 ;; for nonoverwritable builtins
5782 ;; Somehow 's', 'm' are not auto-generated???
5783 (list
5784 (concat
5785 "\\(^\\|[^$@%&\\]\\)\\<\\("
5786 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "chomp"
5787 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
5788 ;; "eval" "exists" "for" "foreach" "format" "goto"
5789 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
5790 ;; "no" "our" "package" "pop" "pos" "print" "printf" "push"
5791 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
5792 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
5793 ;; "undef" "unless" "unshift" "untie" "until" "use"
5794 ;; "while" "y"
5795 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
5796 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
5797 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|INIT\\|if\\|keys\\|"
5798 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
5799 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
5800 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
5801 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
5802 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
5803 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
5804 "\\|[sm]" ; Added manually
5805 "\\)\\>") 2 'cperl-nonoverridable-face)
5806 ;; (mapconcat 'identity
5807 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
5808 ;; "#include" "#define" "#undef")
5809 ;; "\\|")
5810 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
5811 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
5812 ;; This highlights declarations and definitions differently.
5813 ;; We do not try to highlight in the case of attributes:
5814 ;; it is already done by `cperl-find-pods-heres'
5815 (list (concat "\\<sub"
5816 cperl-white-and-comment-rex ; whitespace/comments
5817 "\\([^ \n\t{;()]+\\)" ; 2=name (assume non-anonymous)
5818 "\\("
5819 cperl-maybe-white-and-comment-rex ;whitespace/comments?
5820 "([^()]*)\\)?" ; prototype
5821 cperl-maybe-white-and-comment-rex ; whitespace/comments?
5822 "[{;]")
5823 2 (if cperl-font-lock-multiline
5824 '(if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5825 'font-lock-function-name-face
5826 'font-lock-variable-name-face)
5827 ;; need to manually set 'multiline' for older font-locks
5828 '(progn
5829 (if (< 1 (count-lines (match-beginning 0)
5830 (match-end 0)))
5831 (put-text-property
5832 (+ 3 (match-beginning 0)) (match-end 0)
5833 'syntax-type 'multiline))
5834 (if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
5835 'font-lock-function-name-face
5836 'font-lock-variable-name-face))))
5837 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
5838 2 font-lock-function-name-face)
5839 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
5840 1 font-lock-function-name-face)
5841 (cond ((featurep 'font-lock-extra)
5842 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5843 (2 font-lock-string-face t)
5844 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
5845 (font-lock-anchored
5846 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5847 (2 font-lock-string-face t)
5848 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5849 nil nil
5850 (1 font-lock-string-face t))))
5851 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5852 2 font-lock-string-face t)))
5853 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
5854 font-lock-string-face t)
5855 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
5856 font-lock-constant-face) ; labels
5857 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
5858 2 font-lock-constant-face)
5859 ;; Uncomment to get perl-mode-like vars
5860 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
5861 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
5862 ;;; (2 (cons font-lock-variable-name-face '(underline))))
5863 (cond ((featurep 'font-lock-extra)
5864 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5865 (3 font-lock-variable-name-face)
5866 (4 '(another 4 nil
5867 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5868 (1 font-lock-variable-name-face)
5869 (2 '(restart 2 nil) nil t)))
5870 nil t))) ; local variables, multiple
5871 (font-lock-anchored
5872 ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
5873 `(,(concat "\\<\\(my\\|local\\|our\\)"
5874 cperl-maybe-white-and-comment-rex
5875 "\\(("
5876 cperl-maybe-white-and-comment-rex
5877 "\\)?\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)")
5878 (5 ,(if cperl-font-lock-multiline
5879 'font-lock-variable-name-face
5880 '(progn (setq cperl-font-lock-multiline-start
5881 (match-beginning 0))
5882 'font-lock-variable-name-face)))
5883 (,(concat "\\="
5884 cperl-maybe-white-and-comment-rex
5886 cperl-maybe-white-and-comment-rex
5887 "\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)")
5888 ;; Bug in font-lock: limit is used not only to limit
5889 ;; searches, but to set the "extend window for
5890 ;; facification" property. Thus we need to minimize.
5891 ,(if cperl-font-lock-multiline
5892 '(if (match-beginning 3)
5893 (save-excursion
5894 (goto-char (match-beginning 3))
5895 (condition-case nil
5896 (forward-sexp 1)
5897 (error
5898 (condition-case nil
5899 (forward-char 200)
5900 (error nil)))) ; typeahead
5901 (1- (point))) ; report limit
5902 (forward-char -2)) ; disable continued expr
5903 '(if (match-beginning 3)
5904 (point-max) ; No limit for continuation
5905 (forward-char -2))) ; disable continued expr
5906 ,(if cperl-font-lock-multiline
5908 '(progn ; Do at end
5909 ;; "my" may be already fontified (POD),
5910 ;; so cperl-font-lock-multiline-start is nil
5911 (if (or (not cperl-font-lock-multiline-start)
5912 (> 2 (count-lines
5913 cperl-font-lock-multiline-start
5914 (point))))
5916 (put-text-property
5917 (1+ cperl-font-lock-multiline-start) (point)
5918 'syntax-type 'multiline))
5919 (setq cperl-font-lock-multiline-start nil)))
5920 (3 font-lock-variable-name-face))))
5921 (t '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
5922 3 font-lock-variable-name-face)))
5923 '("\\<for\\(each\\)?\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
5924 4 font-lock-variable-name-face)
5925 ;; Avoid $!, and s!!, qq!! etc. when not fontifying syntactically
5926 '("\\(?:^\\|[^smywqrx$]\\)\\(!\\)" 1 font-lock-negation-char-face)
5927 '("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)))
5928 (setq
5929 t-font-lock-keywords-1
5930 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
5931 ;; not yet as of XEmacs 19.12, works with 21.1.11
5933 (not (featurep 'xemacs))
5934 (string< "21.1.9" emacs-version)
5935 (and (string< "21.1.10" emacs-version)
5936 (string< emacs-version "21.1.2")))
5938 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
5939 (if (eq (char-after (match-beginning 2)) ?%)
5940 'cperl-hash-face
5941 'cperl-array-face)
5942 t) ; arrays and hashes
5943 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
5945 (if (= (- (match-end 2) (match-beginning 2)) 1)
5946 (if (eq (char-after (match-beginning 3)) ?{)
5947 'cperl-hash-face
5948 'cperl-array-face) ; arrays and hashes
5949 font-lock-variable-name-face) ; Just to put something
5951 ("\\(@\\|\\$#\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
5952 (1 cperl-array-face)
5953 (2 font-lock-variable-name-face))
5954 ("\\(%\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
5955 (1 cperl-hash-face)
5956 (2 font-lock-variable-name-face))
5957 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
5958 ;;; Too much noise from \s* @s[ and friends
5959 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
5960 ;;(3 font-lock-function-name-face t t)
5961 ;;(4
5962 ;; (if (cperl-slash-is-regexp)
5963 ;; font-lock-function-name-face 'default) nil t))
5965 (if cperl-highlight-variables-indiscriminately
5966 (setq t-font-lock-keywords-1
5967 (append t-font-lock-keywords-1
5968 (list '("\\([$*]{?\\sw+\\)" 1
5969 font-lock-variable-name-face)))))
5970 (setq cperl-font-lock-keywords-1
5971 (if cperl-syntaxify-by-font-lock
5972 (cons 'cperl-fontify-update
5973 t-font-lock-keywords)
5974 t-font-lock-keywords)
5975 cperl-font-lock-keywords cperl-font-lock-keywords-1
5976 cperl-font-lock-keywords-2 (append
5977 cperl-font-lock-keywords-1
5978 t-font-lock-keywords-1)))
5979 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
5980 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
5981 (eval ; Avoid a warning
5982 '(font-lock-require-faces
5983 (list
5984 ;; Color-light Color-dark Gray-light Gray-dark Mono
5985 (list 'font-lock-comment-face
5986 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
5988 [nil nil t t t]
5989 [nil nil t t t]
5990 nil)
5991 (list 'font-lock-string-face
5992 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
5995 [nil nil t t t]
5996 nil)
5997 (list 'font-lock-function-name-face
5998 (vector
5999 "Blue" "LightSkyBlue" "Gray50" "LightGray"
6000 (cdr (assq 'background-color ; if mono
6001 (frame-parameters))))
6002 (vector
6003 nil nil nil nil
6004 (cdr (assq 'foreground-color ; if mono
6005 (frame-parameters))))
6006 [nil nil t t t]
6008 nil)
6009 (list 'font-lock-variable-name-face
6010 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
6012 [nil nil t t t]
6013 [nil nil t t t]
6014 nil)
6015 (list 'font-lock-type-face
6016 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
6018 [nil nil t t t]
6020 [nil nil t t t])
6021 (list 'font-lock-warning-face
6022 ["Pink" "Red" "Gray50" "LightGray"]
6023 ["gray20" "gray90"
6024 "gray80" "gray20"]
6025 [nil nil t t t]
6027 [nil nil t t t]
6029 (list 'font-lock-constant-face
6030 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
6032 [nil nil t t t]
6034 [nil nil t t t])
6035 (list 'cperl-nonoverridable-face
6036 ["chartreuse3" ("orchid1" "orange")
6037 nil "Gray80"]
6038 [nil nil "gray90"]
6039 [nil nil nil t t]
6040 [nil nil t t]
6041 [nil nil t t t])
6042 (list 'cperl-array-face
6043 ["blue" "yellow" nil "Gray80"]
6044 ["lightyellow2" ("navy" "os2blue" "darkgreen")
6045 "gray90"]
6048 nil)
6049 (list 'cperl-hash-face
6050 ["red" "red" nil "Gray80"]
6051 ["lightyellow2" ("navy" "os2blue" "darkgreen")
6052 "gray90"]
6055 nil))))
6056 ;; Do it the dull way, without choose-color
6057 (defvar cperl-guessed-background nil
6058 "Display characteristics as guessed by cperl.")
6059 ;; (or (fboundp 'x-color-defined-p)
6060 ;; (defalias 'x-color-defined-p
6061 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
6062 ;; ;; XEmacs >= 19.12
6063 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
6064 ;; ;; XEmacs 19.11
6065 ;; (t 'x-valid-color-name-p))))
6066 (cperl-force-face font-lock-constant-face
6067 "Face for constant and label names")
6068 (cperl-force-face font-lock-variable-name-face
6069 "Face for variable names")
6070 (cperl-force-face font-lock-type-face
6071 "Face for data types")
6072 (cperl-force-face cperl-nonoverridable-face
6073 "Face for data types from another group")
6074 (cperl-force-face font-lock-warning-face
6075 "Face for things which should stand out")
6076 (cperl-force-face font-lock-comment-face
6077 "Face for comments")
6078 (cperl-force-face font-lock-function-name-face
6079 "Face for function names")
6080 (cperl-force-face cperl-hash-face
6081 "Face for hashes")
6082 (cperl-force-face cperl-array-face
6083 "Face for arrays")
6084 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
6085 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
6086 ;;(or (boundp 'font-lock-type-face)
6087 ;; (defconst font-lock-type-face
6088 ;; 'font-lock-type-face
6089 ;; "Face to use for data types."))
6090 ;;(or (boundp 'cperl-nonoverridable-face)
6091 ;; (defconst cperl-nonoverridable-face
6092 ;; 'cperl-nonoverridable-face
6093 ;; "Face to use for data types from another group."))
6094 ;;(if (not (featurep 'xemacs)) nil
6095 ;; (or (boundp 'font-lock-comment-face)
6096 ;; (defconst font-lock-comment-face
6097 ;; 'font-lock-comment-face
6098 ;; "Face to use for comments."))
6099 ;; (or (boundp 'font-lock-keyword-face)
6100 ;; (defconst font-lock-keyword-face
6101 ;; 'font-lock-keyword-face
6102 ;; "Face to use for keywords."))
6103 ;; (or (boundp 'font-lock-function-name-face)
6104 ;; (defconst font-lock-function-name-face
6105 ;; 'font-lock-function-name-face
6106 ;; "Face to use for function names.")))
6107 (if (and
6108 (not (cperl-is-face 'cperl-array-face))
6109 (cperl-is-face 'font-lock-emphasized-face))
6110 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
6111 (if (and
6112 (not (cperl-is-face 'cperl-hash-face))
6113 (cperl-is-face 'font-lock-other-emphasized-face))
6114 (copy-face 'font-lock-other-emphasized-face 'cperl-hash-face))
6115 (if (and
6116 (not (cperl-is-face 'cperl-nonoverridable-face))
6117 (cperl-is-face 'font-lock-other-type-face))
6118 (copy-face 'font-lock-other-type-face 'cperl-nonoverridable-face))
6119 ;;(or (boundp 'cperl-hash-face)
6120 ;; (defconst cperl-hash-face
6121 ;; 'cperl-hash-face
6122 ;; "Face to use for hashes."))
6123 ;;(or (boundp 'cperl-array-face)
6124 ;; (defconst cperl-array-face
6125 ;; 'cperl-array-face
6126 ;; "Face to use for arrays."))
6127 ;; Here we try to guess background
6128 (let ((background
6129 (if (boundp 'font-lock-background-mode)
6130 font-lock-background-mode
6131 'light))
6132 (face-list (and (fboundp 'face-list) (face-list))))
6133 ;;;; (fset 'cperl-is-face
6134 ;;;; (cond ((fboundp 'find-face)
6135 ;;;; (symbol-function 'find-face))
6136 ;;;; (face-list
6137 ;;;; (function (lambda (face) (member face face-list))))
6138 ;;;; (t
6139 ;;;; (function (lambda (face) (boundp face))))))
6140 (defvar cperl-guessed-background
6141 (if (and (boundp 'font-lock-display-type)
6142 (eq font-lock-display-type 'grayscale))
6143 'gray
6144 background)
6145 "Background as guessed by CPerl mode")
6146 (and (not (cperl-is-face 'font-lock-constant-face))
6147 (cperl-is-face 'font-lock-reference-face)
6148 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
6149 (if (cperl-is-face 'font-lock-type-face) nil
6150 (copy-face 'default 'font-lock-type-face)
6151 (cond
6152 ((eq background 'light)
6153 (set-face-foreground 'font-lock-type-face
6154 (if (x-color-defined-p "seagreen")
6155 "seagreen"
6156 "sea green")))
6157 ((eq background 'dark)
6158 (set-face-foreground 'font-lock-type-face
6159 (if (x-color-defined-p "os2pink")
6160 "os2pink"
6161 "pink")))
6163 (set-face-background 'font-lock-type-face "gray90"))))
6164 (if (cperl-is-face 'cperl-nonoverridable-face)
6166 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
6167 (cond
6168 ((eq background 'light)
6169 (set-face-foreground 'cperl-nonoverridable-face
6170 (if (x-color-defined-p "chartreuse3")
6171 "chartreuse3"
6172 "chartreuse")))
6173 ((eq background 'dark)
6174 (set-face-foreground 'cperl-nonoverridable-face
6175 (if (x-color-defined-p "orchid1")
6176 "orchid1"
6177 "orange")))))
6178 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
6179 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
6180 ;;; (cond
6181 ;;; ((eq background 'light)
6182 ;;; (set-face-background 'font-lock-other-emphasized-face
6183 ;;; (if (x-color-defined-p "lightyellow2")
6184 ;;; "lightyellow2"
6185 ;;; (if (x-color-defined-p "lightyellow")
6186 ;;; "lightyellow"
6187 ;;; "light yellow"))))
6188 ;;; ((eq background 'dark)
6189 ;;; (set-face-background 'font-lock-other-emphasized-face
6190 ;;; (if (x-color-defined-p "navy")
6191 ;;; "navy"
6192 ;;; (if (x-color-defined-p "darkgreen")
6193 ;;; "darkgreen"
6194 ;;; "dark green"))))
6195 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
6196 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
6197 ;;; (copy-face 'bold 'font-lock-emphasized-face)
6198 ;;; (cond
6199 ;;; ((eq background 'light)
6200 ;;; (set-face-background 'font-lock-emphasized-face
6201 ;;; (if (x-color-defined-p "lightyellow2")
6202 ;;; "lightyellow2"
6203 ;;; "lightyellow")))
6204 ;;; ((eq background 'dark)
6205 ;;; (set-face-background 'font-lock-emphasized-face
6206 ;;; (if (x-color-defined-p "navy")
6207 ;;; "navy"
6208 ;;; (if (x-color-defined-p "darkgreen")
6209 ;;; "darkgreen"
6210 ;;; "dark green"))))
6211 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
6212 (if (cperl-is-face 'font-lock-variable-name-face) nil
6213 (copy-face 'italic 'font-lock-variable-name-face))
6214 (if (cperl-is-face 'font-lock-constant-face) nil
6215 (copy-face 'italic 'font-lock-constant-face))))
6216 (setq cperl-faces-init t))
6217 (error (message "cperl-init-faces (ignored): %s" errs))))
6220 (defvar ps-bold-faces)
6221 (defvar ps-italic-faces)
6222 (defvar ps-underlined-faces)
6224 (defun cperl-ps-print-init ()
6225 "Initialization of `ps-print' components for faces used in CPerl."
6226 (eval-after-load "ps-print"
6227 '(setq ps-bold-faces
6228 ;; font-lock-variable-name-face
6229 ;; font-lock-constant-face
6230 (append '(cperl-array-face cperl-hash-face)
6231 ps-bold-faces)
6232 ps-italic-faces
6233 ;; font-lock-constant-face
6234 (append '(cperl-nonoverridable-face cperl-hash-face)
6235 ps-italic-faces)
6236 ps-underlined-faces
6237 ;; font-lock-type-face
6238 (append '(cperl-array-face cperl-hash-face underline cperl-nonoverridable-face)
6239 ps-underlined-faces))))
6241 (defvar ps-print-face-extension-alist)
6243 (defun cperl-ps-print (&optional file)
6244 "Pretty-print in CPerl style.
6245 If optional argument FILE is an empty string, prints to printer, otherwise
6246 to the file FILE. If FILE is nil, prompts for a file name.
6248 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
6249 (interactive)
6250 (or file
6251 (setq file (read-from-minibuffer
6252 "Print to file (if empty - to printer): "
6253 (concat (buffer-file-name) ".ps")
6254 nil nil 'file-name-history)))
6255 (or (> (length file) 0)
6256 (setq file nil))
6257 (require 'ps-print) ; To get ps-print-face-extension-alist
6258 (let ((ps-print-color-p t)
6259 (ps-print-face-extension-alist ps-print-face-extension-alist))
6260 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
6261 (ps-print-buffer-with-faces file)))
6263 ;;; (defun cperl-ps-print-init ()
6264 ;;; "Initialization of `ps-print' components for faces used in CPerl."
6265 ;;; ;; Guard against old versions
6266 ;;; (defvar ps-underlined-faces nil)
6267 ;;; (defvar ps-bold-faces nil)
6268 ;;; (defvar ps-italic-faces nil)
6269 ;;; (setq ps-bold-faces
6270 ;;; (append '(font-lock-emphasized-face
6271 ;;; cperl-array-face
6272 ;;; font-lock-keyword-face
6273 ;;; font-lock-variable-name-face
6274 ;;; font-lock-constant-face
6275 ;;; font-lock-reference-face
6276 ;;; font-lock-other-emphasized-face
6277 ;;; cperl-hash-face)
6278 ;;; ps-bold-faces))
6279 ;;; (setq ps-italic-faces
6280 ;;; (append '(cperl-nonoverridable-face
6281 ;;; font-lock-constant-face
6282 ;;; font-lock-reference-face
6283 ;;; font-lock-other-emphasized-face
6284 ;;; cperl-hash-face)
6285 ;;; ps-italic-faces))
6286 ;;; (setq ps-underlined-faces
6287 ;;; (append '(font-lock-emphasized-face
6288 ;;; cperl-array-face
6289 ;;; font-lock-other-emphasized-face
6290 ;;; cperl-hash-face
6291 ;;; cperl-nonoverridable-face font-lock-type-face)
6292 ;;; ps-underlined-faces))
6293 ;;; (cons 'font-lock-type-face ps-underlined-faces))
6296 (if (cperl-enable-font-lock) (cperl-windowed-init))
6298 (defconst cperl-styles-entries
6299 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
6300 cperl-label-offset cperl-extra-newline-before-brace
6301 cperl-extra-newline-before-brace-multiline
6302 cperl-merge-trailing-else
6303 cperl-continued-statement-offset))
6305 (defconst cperl-style-examples
6306 "##### Numbers etc are: cperl-indent-level cperl-brace-offset
6307 ##### cperl-continued-brace-offset cperl-label-offset
6308 ##### cperl-continued-statement-offset
6309 ##### cperl-merge-trailing-else cperl-extra-newline-before-brace
6311 ########### (Do not forget cperl-extra-newline-before-brace-multiline)
6313 ### CPerl (=GNU - extra-newline-before-brace + merge-trailing-else) 2/0/0/-2/2/t/nil
6314 if (foo) {
6316 baz;
6317 label:
6319 boon;
6321 } else {
6322 stop;
6325 ### PerlStyle (=CPerl with 4 as indent) 4/0/0/-4/4/t/nil
6326 if (foo) {
6328 baz;
6329 label:
6331 boon;
6333 } else {
6334 stop;
6337 ### GNU 2/0/0/-2/2/nil/t
6338 if (foo)
6341 baz;
6342 label:
6344 boon;
6347 else
6349 stop;
6352 ### C++ (=PerlStyle with braces aligned with control words) 4/0/-4/-4/4/nil/t
6353 if (foo)
6356 baz;
6357 label:
6359 boon;
6362 else
6364 stop;
6367 ### BSD (=C++, but will not change preexisting merge-trailing-else
6368 ### and extra-newline-before-brace ) 4/0/-4/-4/4
6369 if (foo)
6372 baz;
6373 label:
6375 boon;
6378 else
6380 stop;
6383 ### K&R (=C++ with indent 5 - merge-trailing-else, but will not
6384 ### change preexisting extra-newline-before-brace) 5/0/-5/-5/5/nil
6385 if (foo)
6388 baz;
6389 label:
6391 boon;
6394 else
6396 stop;
6399 ### Whitesmith (=PerlStyle, but will not change preexisting
6400 ### extra-newline-before-brace and merge-trailing-else) 4/0/0/-4/4
6401 if (foo)
6404 baz;
6405 label:
6407 boon;
6410 else
6412 stop;
6415 "Examples of if/else with different indent styles (with v4.23).")
6417 (defconst cperl-style-alist
6418 '(("CPerl" ;; =GNU - extra-newline-before-brace + cperl-merge-trailing-else
6419 (cperl-indent-level . 2)
6420 (cperl-brace-offset . 0)
6421 (cperl-continued-brace-offset . 0)
6422 (cperl-label-offset . -2)
6423 (cperl-continued-statement-offset . 2)
6424 (cperl-extra-newline-before-brace . nil)
6425 (cperl-extra-newline-before-brace-multiline . nil)
6426 (cperl-merge-trailing-else . t))
6428 ("PerlStyle" ; CPerl with 4 as indent
6429 (cperl-indent-level . 4)
6430 (cperl-brace-offset . 0)
6431 (cperl-continued-brace-offset . 0)
6432 (cperl-label-offset . -4)
6433 (cperl-continued-statement-offset . 4)
6434 (cperl-extra-newline-before-brace . nil)
6435 (cperl-extra-newline-before-brace-multiline . nil)
6436 (cperl-merge-trailing-else . t))
6438 ("GNU"
6439 (cperl-indent-level . 2)
6440 (cperl-brace-offset . 0)
6441 (cperl-continued-brace-offset . 0)
6442 (cperl-label-offset . -2)
6443 (cperl-continued-statement-offset . 2)
6444 (cperl-extra-newline-before-brace . t)
6445 (cperl-extra-newline-before-brace-multiline . t)
6446 (cperl-merge-trailing-else . nil))
6448 ("K&R"
6449 (cperl-indent-level . 5)
6450 (cperl-brace-offset . 0)
6451 (cperl-continued-brace-offset . -5)
6452 (cperl-label-offset . -5)
6453 (cperl-continued-statement-offset . 5)
6454 ;;(cperl-extra-newline-before-brace . nil) ; ???
6455 ;;(cperl-extra-newline-before-brace-multiline . nil)
6456 (cperl-merge-trailing-else . nil))
6458 ("BSD"
6459 (cperl-indent-level . 4)
6460 (cperl-brace-offset . 0)
6461 (cperl-continued-brace-offset . -4)
6462 (cperl-label-offset . -4)
6463 (cperl-continued-statement-offset . 4)
6464 ;;(cperl-extra-newline-before-brace . nil) ; ???
6465 ;;(cperl-extra-newline-before-brace-multiline . nil)
6466 ;;(cperl-merge-trailing-else . nil) ; ???
6469 ("C++"
6470 (cperl-indent-level . 4)
6471 (cperl-brace-offset . 0)
6472 (cperl-continued-brace-offset . -4)
6473 (cperl-label-offset . -4)
6474 (cperl-continued-statement-offset . 4)
6475 (cperl-extra-newline-before-brace . t)
6476 (cperl-extra-newline-before-brace-multiline . t)
6477 (cperl-merge-trailing-else . nil))
6479 ("Whitesmith"
6480 (cperl-indent-level . 4)
6481 (cperl-brace-offset . 0)
6482 (cperl-continued-brace-offset . 0)
6483 (cperl-label-offset . -4)
6484 (cperl-continued-statement-offset . 4)
6485 ;;(cperl-extra-newline-before-brace . nil) ; ???
6486 ;;(cperl-extra-newline-before-brace-multiline . nil)
6487 ;;(cperl-merge-trailing-else . nil) ; ???
6489 ("Current"))
6490 "List of variables to set to get a particular indentation style.
6491 Should be used via `cperl-set-style' or via Perl menu.
6493 See examples in `cperl-style-examples'.")
6495 (defun cperl-set-style (style)
6496 "Set CPerl mode variables to use one of several different indentation styles.
6497 The arguments are a string representing the desired style.
6498 The list of styles is in `cperl-style-alist', available styles
6499 are CPerl, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith.
6501 The current value of style is memorized (unless there is a memorized
6502 data already), may be restored by `cperl-set-style-back'.
6504 Choosing \"Current\" style will not change style, so this may be used for
6505 side-effect of memorizing only. Examples in `cperl-style-examples'."
6506 (interactive
6507 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
6508 cperl-style-alist)))
6509 (list (completing-read "Enter style: " list nil 'insist))))
6510 (or cperl-old-style
6511 (setq cperl-old-style
6512 (mapcar (function
6513 (lambda (name)
6514 (cons name (eval name))))
6515 cperl-styles-entries)))
6516 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
6517 (while style
6518 (setq setting (car style) style (cdr style))
6519 (set (car setting) (cdr setting)))))
6521 (defun cperl-set-style-back ()
6522 "Restore a style memorized by `cperl-set-style'."
6523 (interactive)
6524 (or cperl-old-style (error "The style was not changed"))
6525 (let (setting)
6526 (while cperl-old-style
6527 (setq setting (car cperl-old-style)
6528 cperl-old-style (cdr cperl-old-style))
6529 (set (car setting) (cdr setting)))))
6531 (defun cperl-check-syntax ()
6532 (interactive)
6533 (require 'mode-compile)
6534 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
6535 (eval '(mode-compile)))) ; Avoid a warning
6537 (declare-function Info-find-node "info"
6538 (filename nodename &optional no-going-back strict-case))
6540 (defun cperl-info-buffer (type)
6541 ;; Returns buffer with documentation. Creates if missing.
6542 ;; If TYPE, this vars buffer.
6543 ;; Special care is taken to not stomp over an existing info buffer
6544 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
6545 (info (get-buffer bname))
6546 (oldbuf (get-buffer "*info*")))
6547 (if info info
6548 (save-window-excursion
6549 ;; Get Info running
6550 (require 'info)
6551 (cond (oldbuf
6552 (set-buffer oldbuf)
6553 (rename-buffer "*info-perl-tmp*")))
6554 (save-window-excursion
6555 (info))
6556 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
6557 (set-buffer "*info*")
6558 (rename-buffer bname)
6559 (cond (oldbuf
6560 (set-buffer "*info-perl-tmp*")
6561 (rename-buffer "*info*")
6562 (set-buffer bname)))
6563 (make-local-variable 'window-min-height)
6564 (setq window-min-height 2)
6565 (current-buffer)))))
6567 (defun cperl-word-at-point (&optional p)
6568 "Return the word at point or at P."
6569 (save-excursion
6570 (if p (goto-char p))
6571 (or (cperl-word-at-point-hard)
6572 (progn
6573 (require 'etags)
6574 (funcall (or (and (boundp 'find-tag-default-function)
6575 find-tag-default-function)
6576 (get major-mode 'find-tag-default-function)
6577 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
6578 ;; automatically used within `find-tag-default':
6579 'find-tag-default))))))
6581 (defun cperl-info-on-command (command)
6582 "Show documentation for Perl command COMMAND in other window.
6583 If perl-info buffer is shown in some frame, uses this frame.
6584 Customized by setting variables `cperl-shrink-wrap-info-frame',
6585 `cperl-max-help-size'."
6586 (interactive
6587 (let* ((default (cperl-word-at-point))
6588 (read (read-string
6589 (format "Find doc for Perl function (default %s): "
6590 default))))
6591 (list (if (equal read "")
6592 default
6593 read))))
6595 (let ((buffer (current-buffer))
6596 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
6597 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
6598 max-height char-height buf-list)
6599 (if (string-match "^-[a-zA-Z]$" command)
6600 (setq cmd-desc "^-X[ \t\n]"))
6601 (setq isvar (string-match "^[$@%]" command)
6602 buf (cperl-info-buffer isvar)
6603 iniwin (selected-window)
6604 fr1 (window-frame iniwin))
6605 (set-buffer buf)
6606 (goto-char (point-min))
6607 (or isvar
6608 (progn (re-search-forward "^-X[ \t\n]")
6609 (forward-line -1)))
6610 (if (re-search-forward cmd-desc nil t)
6611 (progn
6612 ;; Go back to beginning of the group (ex, for qq)
6613 (if (re-search-backward "^[ \t\n\f]")
6614 (forward-line 1))
6615 (beginning-of-line)
6616 ;; Get some of
6617 (setq pos (point)
6618 buf-list (list buf "*info-perl-var*" "*info-perl*"))
6619 (while (and (not win) buf-list)
6620 (setq win (get-buffer-window (car buf-list) t))
6621 (setq buf-list (cdr buf-list)))
6622 (or (not win)
6623 (eq (window-buffer win) buf)
6624 (set-window-buffer win buf))
6625 (and win (setq fr2 (window-frame win)))
6626 (if (or (not fr2) (eq fr1 fr2))
6627 (pop-to-buffer buf)
6628 (special-display-popup-frame buf) ; Make it visible
6629 (select-window win))
6630 (goto-char pos) ; Needed (?!).
6631 ;; Resize
6632 (setq iniheight (window-height)
6633 frheight (frame-height)
6634 not-loner (< iniheight (1- frheight))) ; Are not alone
6635 (cond ((if not-loner cperl-max-help-size
6636 cperl-shrink-wrap-info-frame)
6637 (setq height
6638 (+ 2
6639 (count-lines
6641 (save-excursion
6642 (if (re-search-forward
6643 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
6644 (match-beginning 0) (point-max)))))
6645 max-height
6646 (if not-loner
6647 (/ (* (- frheight 3) cperl-max-help-size) 100)
6648 (setq char-height (frame-char-height))
6649 ;; Non-functioning under OS/2:
6650 (if (eq char-height 1) (setq char-height 18))
6651 ;; Title, menubar, + 2 for slack
6652 (- (/ (display-pixel-height) char-height) 4)))
6653 (if (> height max-height) (setq height max-height))
6654 ;;(message "was %s doing %s" iniheight height)
6655 (if not-loner
6656 (enlarge-window (- height iniheight))
6657 (set-frame-height (window-frame win) (1+ height)))))
6658 (set-window-start (selected-window) pos))
6659 (message "No entry for %s found." command))
6660 ;;(pop-to-buffer buffer)
6661 (select-window iniwin)))
6663 (defun cperl-info-on-current-command ()
6664 "Show documentation for Perl command at point in other window."
6665 (interactive)
6666 (cperl-info-on-command (cperl-word-at-point)))
6668 (defun cperl-imenu-info-imenu-search ()
6669 (if (looking-at "^-X[ \t\n]") nil
6670 (re-search-backward
6671 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
6672 (forward-line 1)))
6674 (defun cperl-imenu-info-imenu-name ()
6675 (buffer-substring
6676 (match-beginning 1) (match-end 1)))
6678 (declare-function imenu-choose-buffer-index "imenu" (&optional prompt alist))
6680 (defun cperl-imenu-on-info ()
6681 "Shows imenu for Perl Info Buffer.
6682 Opens Perl Info buffer if needed."
6683 (interactive)
6684 (require 'imenu)
6685 (let* ((buffer (current-buffer))
6686 imenu-create-index-function
6687 imenu-prev-index-position-function
6688 imenu-extract-index-name-function
6689 (index-item (save-restriction
6690 (save-window-excursion
6691 (set-buffer (cperl-info-buffer nil))
6692 (setq imenu-create-index-function
6693 'imenu-default-create-index-function
6694 imenu-prev-index-position-function
6695 'cperl-imenu-info-imenu-search
6696 imenu-extract-index-name-function
6697 'cperl-imenu-info-imenu-name)
6698 (imenu-choose-buffer-index)))))
6699 (and index-item
6700 (progn
6701 (push-mark)
6702 (pop-to-buffer "*info-perl*")
6703 (cond
6704 ((markerp (cdr index-item))
6705 (goto-char (marker-position (cdr index-item))))
6707 (goto-char (cdr index-item))))
6708 (set-window-start (selected-window) (point))
6709 (pop-to-buffer buffer)))))
6711 (defun cperl-lineup (beg end &optional step minshift)
6712 "Lineup construction in a region.
6713 Beginning of region should be at the start of a construction.
6714 All first occurrences of this construction in the lines that are
6715 partially contained in the region are lined up at the same column.
6717 MINSHIFT is the minimal amount of space to insert before the construction.
6718 STEP is the tabwidth to position constructions.
6719 If STEP is nil, `cperl-lineup-step' will be used
6720 \(or `cperl-indent-level', if `cperl-lineup-step' is nil).
6721 Will not move the position at the start to the left."
6722 (interactive "r")
6723 (let (search col tcol seen b)
6724 (save-excursion
6725 (goto-char end)
6726 (end-of-line)
6727 (setq end (point-marker))
6728 (goto-char beg)
6729 (skip-chars-forward " \t\f")
6730 (setq beg (point-marker))
6731 (indent-region beg end nil)
6732 (goto-char beg)
6733 (setq col (current-column))
6734 (if (looking-at "[a-zA-Z0-9_]")
6735 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
6736 (setq search
6737 (concat "\\<"
6738 (regexp-quote
6739 (buffer-substring (match-beginning 0)
6740 (match-end 0))) "\\>"))
6741 (error "Cannot line up in a middle of the word"))
6742 (if (looking-at "$")
6743 (error "Cannot line up end of line"))
6744 (setq search (regexp-quote (char-to-string (following-char)))))
6745 (setq step (or step cperl-lineup-step cperl-indent-level))
6746 (or minshift (setq minshift 1))
6747 (while (progn
6748 (beginning-of-line 2)
6749 (and (< (point) end)
6750 (re-search-forward search end t)
6751 (goto-char (match-beginning 0))))
6752 (setq tcol (current-column) seen t)
6753 (if (> tcol col) (setq col tcol)))
6754 (or seen
6755 (error "The construction to line up occurred only once"))
6756 (goto-char beg)
6757 (setq col (+ col minshift))
6758 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
6759 (while
6760 (progn
6761 (cperl-make-indent col)
6762 (beginning-of-line 2)
6763 (and (< (point) end)
6764 (re-search-forward search end t)
6765 (goto-char (match-beginning 0)))))))) ; No body
6767 (defun cperl-etags (&optional add all files) ;; NOT USED???
6768 "Run etags with appropriate options for Perl files.
6769 If optional argument ALL is `recursive', will process Perl files
6770 in subdirectories too."
6771 (interactive)
6772 (let ((cmd "etags")
6773 (args '("-l" "none" "-r"
6774 ;; 1=fullname 2=package? 3=name 4=proto? 5=attrs? (VERY APPROX!)
6775 "/\\<sub[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([ \t]*:[^#{;]*\\)?\\([{#]\\|$\\)/\\3/"
6776 "-r"
6777 "/\\<package[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\([#;]\\|$\\)/\\1/"
6778 "-r"
6779 "/\\<\\(package\\)[ \\t]*;/\\1;/"))
6780 res)
6781 (if add (setq args (cons "-a" args)))
6782 (or files (setq files (list buffer-file-name)))
6783 (cond
6784 ((eq all 'recursive)
6785 ;;(error "Not implemented: recursive")
6786 (setq args (append (list "-e"
6787 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
6788 use File::Find;
6789 find(\\&wanted, '.');
6790 exec @ARGV;"
6791 cmd) args)
6792 cmd "perl"))
6793 (all
6794 ;;(error "Not implemented: all")
6795 (setq args (append (list "-e"
6796 "push @ARGV, <*.PL *.pl *.pm>;
6797 exec @ARGV;"
6798 cmd) args)
6799 cmd "perl"))
6801 (setq args (append args files))))
6802 (setq res (apply 'call-process cmd nil nil nil args))
6803 (or (eq res 0)
6804 (message "etags returned \"%s\"" res))))
6806 (defun cperl-toggle-auto-newline ()
6807 "Toggle the state of `cperl-auto-newline'."
6808 (interactive)
6809 (setq cperl-auto-newline (not cperl-auto-newline))
6810 (message "Newlines will %sbe auto-inserted now."
6811 (if cperl-auto-newline "" "not ")))
6813 (defun cperl-toggle-abbrev ()
6814 "Toggle the state of automatic keyword expansion in CPerl mode."
6815 (interactive)
6816 (abbrev-mode (if abbrev-mode 0 1))
6817 (message "Perl control structure will %sbe auto-inserted now."
6818 (if abbrev-mode "" "not ")))
6821 (defun cperl-toggle-electric ()
6822 "Toggle the state of parentheses doubling in CPerl mode."
6823 (interactive)
6824 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
6825 (message "Parentheses will %sbe auto-doubled now."
6826 (if (cperl-val 'cperl-electric-parens) "" "not ")))
6828 (defun cperl-toggle-autohelp ()
6829 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
6830 Delay of auto-help controlled by `cperl-lazy-help-time'."
6831 (interactive)
6832 (if (fboundp 'run-with-idle-timer)
6833 (progn
6834 (if cperl-lazy-installed
6835 (cperl-lazy-unstall)
6836 (cperl-lazy-install))
6837 (message "Perl help messages will %sbe automatically shown now."
6838 (if cperl-lazy-installed "" "not ")))
6839 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
6841 (defun cperl-toggle-construct-fix ()
6842 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
6843 (interactive)
6844 (setq cperl-indent-region-fix-constructs
6845 (if cperl-indent-region-fix-constructs
6848 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
6849 (if cperl-indent-region-fix-constructs "" "not ")))
6851 (defun cperl-toggle-set-debug-unwind (arg &optional backtrace)
6852 "Toggle (or, with numeric argument, set) debugging state of syntaxification.
6853 Nonpositive numeric argument disables debugging messages. The message
6854 summarizes which regions it was decided to rescan for syntactic constructs.
6856 The message looks like this:
6858 Syxify req=123..138 actual=101..146 done-to: 112=>146 statepos: 73=>117
6860 Numbers are character positions in the buffer. REQ provides the range to
6861 rescan requested by `font-lock'. ACTUAL is the range actually resyntaxified;
6862 for correct operation it should start and end outside any special syntactic
6863 construct. DONE-TO and STATEPOS indicate changes to internal caches maintained
6864 by CPerl."
6865 (interactive "P")
6866 (or arg
6867 (setq arg (if (eq cperl-syntaxify-by-font-lock
6868 (if backtrace 'backtrace 'message)) 0 1)))
6869 (setq arg (if (> arg 0) (if backtrace 'backtrace 'message) t))
6870 (setq cperl-syntaxify-by-font-lock arg)
6871 (message "Debugging messages of syntax unwind %sabled."
6872 (if (eq arg t) "dis" "en")))
6874 ;;;; Tags file creation.
6876 (defvar cperl-tmp-buffer " *cperl-tmp*")
6878 (defun cperl-setup-tmp-buf ()
6879 (set-buffer (get-buffer-create cperl-tmp-buffer))
6880 (set-syntax-table cperl-mode-syntax-table)
6881 (buffer-disable-undo)
6882 (auto-fill-mode 0)
6883 (if cperl-use-syntax-table-text-property-for-tags
6884 (progn
6885 (make-local-variable 'parse-sexp-lookup-properties)
6886 ;; Do not introduce variable if not needed, we check it!
6887 (set 'parse-sexp-lookup-properties t))))
6889 ;; Copied from imenu-example--name-and-position.
6890 (defvar imenu-use-markers)
6892 (defun cperl-imenu-name-and-position ()
6893 "Return the current/previous sexp and its (beginning) location.
6894 Does not move point."
6895 (save-excursion
6896 (forward-sexp -1)
6897 (let ((beg (if imenu-use-markers (point-marker) (point)))
6898 (end (progn (forward-sexp) (point))))
6899 (cons (buffer-substring beg end)
6900 beg))))
6902 (defun cperl-xsub-scan ()
6903 (require 'imenu)
6904 (let ((index-alist '())
6905 (prev-pos 0) index index1 name package prefix)
6906 (goto-char (point-min))
6907 ;; Search for the function
6908 (progn ;;save-match-data
6909 (while (re-search-forward
6910 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
6911 nil t)
6912 (cond
6913 ((match-beginning 2) ; SECTION
6914 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
6915 (goto-char (match-beginning 0))
6916 (skip-chars-forward " \t")
6917 (forward-char 1)
6918 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
6919 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
6920 (setq prefix nil)))
6921 ((not package) nil) ; C language section
6922 ((match-beginning 3) ; XSUB
6923 (goto-char (1+ (match-beginning 3)))
6924 (setq index (cperl-imenu-name-and-position))
6925 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
6926 (if (and prefix (string-match (concat "^" prefix) name))
6927 (setq name (substring name (length prefix))))
6928 (cond ((string-match "::" name) nil)
6930 (setq index1 (cons (concat package "::" name) (cdr index)))
6931 (push index1 index-alist)))
6932 (setcar index name)
6933 (push index index-alist))
6934 (t ; BOOT: section
6935 ;; (beginning-of-line)
6936 (setq index (cperl-imenu-name-and-position))
6937 (setcar index (concat package "::BOOT:"))
6938 (push index index-alist)))))
6939 index-alist))
6941 (defvar cperl-unreadable-ok nil)
6943 (defun cperl-find-tags (ifile xs topdir)
6944 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
6945 (cperl-pod-here-fontify nil) f file)
6946 (save-excursion
6947 (if b (set-buffer b)
6948 (cperl-setup-tmp-buf))
6949 (erase-buffer)
6950 (condition-case err
6951 (setq file (car (insert-file-contents ifile)))
6952 (error (if cperl-unreadable-ok nil
6953 (if (y-or-n-p
6954 (format "File %s unreadable. Continue? " ifile))
6955 (setq cperl-unreadable-ok t)
6956 (error "Aborting: unreadable file %s" ifile)))))
6957 (if (not file)
6958 (message "Unreadable file %s" ifile)
6959 (message "Scanning file %s ..." file)
6960 (if (and cperl-use-syntax-table-text-property-for-tags
6961 (not xs))
6962 (condition-case err ; after __END__ may have garbage
6963 (cperl-find-pods-heres nil nil noninteractive)
6964 (error (message "While scanning for syntax: %s" err))))
6965 (if xs
6966 (setq lst (cperl-xsub-scan))
6967 (setq ind (cperl-imenu--create-perl-index))
6968 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
6969 (setq lst
6970 (mapcar
6971 (function
6972 (lambda (elt)
6973 (cond ((string-match "^[_a-zA-Z]" (car elt))
6974 (goto-char (cdr elt))
6975 (beginning-of-line) ; pos should be of the start of the line
6976 (list (car elt)
6977 (point)
6978 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
6979 (buffer-substring (progn
6980 (goto-char (cdr elt))
6981 ;; After name now...
6982 (or (eolp) (forward-char 1))
6983 (point))
6984 (progn
6985 (beginning-of-line)
6986 (point))))))))
6987 lst))
6988 (erase-buffer)
6989 (while lst
6990 (setq elt (car lst) lst (cdr lst))
6991 (if elt
6992 (progn
6993 (insert (elt elt 3)
6995 (if (string-match "^package " (car elt))
6996 (substring (car elt) 8)
6997 (car elt) )
6999 (number-to-string (elt elt 2)) ; Line
7001 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
7002 "\n")
7003 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
7004 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
7005 (elt elt 3)))
7006 ;; Need to insert the name without package as well
7007 (setq lst (cons (cons (substring (elt elt 3)
7008 (match-beginning 1)
7009 (match-end 1))
7010 (cdr elt))
7011 lst))))))
7012 (setq pos (point))
7013 (goto-char 1)
7014 (setq rel file)
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 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
7020 (setq ret (buffer-substring 1 (point-max)))
7021 (erase-buffer)
7022 (or noninteractive
7023 (message "Scanning file %s finished" file))
7024 ret))))
7026 (defun cperl-add-tags-recurse-noxs ()
7027 "Add to TAGS data for \"pure\" Perl files in the current directory and kids.
7028 Use as
7029 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7030 -f cperl-add-tags-recurse-noxs
7032 (cperl-write-tags nil nil t t nil t))
7034 (defun cperl-add-tags-recurse-noxs-fullpath ()
7035 "Add to TAGS data for \"pure\" Perl in the current directory and kids.
7036 Writes down fullpath, so TAGS is relocatable (but if the build directory
7037 is relocated, the file TAGS inside it breaks). Use as
7038 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7039 -f cperl-add-tags-recurse-noxs-fullpath
7041 (cperl-write-tags nil nil t t nil t ""))
7043 (defun cperl-add-tags-recurse ()
7044 "Add to TAGS file data for Perl files in the current directory and kids.
7045 Use as
7046 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
7047 -f cperl-add-tags-recurse
7049 (cperl-write-tags nil nil t t))
7051 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
7052 ;; If INBUFFER, do not select buffer, and do not save
7053 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
7054 (require 'etags)
7055 (if file nil
7056 (setq file (if dir default-directory (buffer-file-name)))
7057 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
7058 (or topdir
7059 (setq topdir default-directory))
7060 (let ((tags-file-name "TAGS")
7061 (case-fold-search (and (featurep 'xemacs) (eq system-type 'emx)))
7062 xs rel tm)
7063 (save-excursion
7064 (cond (inbuffer nil) ; Already there
7065 ((file-exists-p tags-file-name)
7066 (if (featurep 'xemacs)
7067 (visit-tags-table-buffer)
7068 (visit-tags-table-buffer tags-file-name)))
7069 (t (set-buffer (find-file-noselect tags-file-name))))
7070 (cond
7071 (dir
7072 (cond ((eq erase 'ignore))
7073 (erase
7074 (erase-buffer)
7075 (setq erase 'ignore)))
7076 (let ((files
7077 (condition-case err
7078 (directory-files file t
7079 (if recurse nil cperl-scan-files-regexp)
7081 (error
7082 (if cperl-unreadable-ok nil
7083 (if (y-or-n-p
7084 (format "Directory %s unreadable. Continue? " file))
7085 (setq cperl-unreadable-ok t
7086 tm nil) ; Return empty list
7087 (error "Aborting: unreadable directory %s" file)))))))
7088 (mapc (function
7089 (lambda (file)
7090 (cond
7091 ((string-match cperl-noscan-files-regexp file)
7092 nil)
7093 ((not (file-directory-p file))
7094 (if (string-match cperl-scan-files-regexp file)
7095 (cperl-write-tags file erase recurse nil t noxs topdir)))
7096 ((not recurse) nil)
7097 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
7098 files)))
7100 (setq xs (string-match "\\.xs$" file))
7101 (if (not (and xs noxs))
7102 (progn
7103 (cond ((eq erase 'ignore) (goto-char (point-max)))
7104 (erase (erase-buffer))
7106 (goto-char 1)
7107 (setq rel file)
7108 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
7109 (set-text-properties 0 (length rel) nil rel)
7110 (and (equal topdir (substring rel 0 (length topdir)))
7111 (setq rel (substring file (length topdir))))
7112 (if (search-forward (concat "\f\n" rel ",") nil t)
7113 (progn
7114 (search-backward "\f\n")
7115 (delete-region (point)
7116 (save-excursion
7117 (forward-char 1)
7118 (if (search-forward "\f\n"
7119 nil 'toend)
7120 (- (point) 2)
7121 (point-max)))))
7122 (goto-char (point-max)))))
7123 (insert (cperl-find-tags file xs topdir))))))
7124 (if inbuffer nil ; Delegate to the caller
7125 (save-buffer 0) ; No backup
7126 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
7127 (initialize-new-tags-table))))))
7129 (defvar cperl-tags-hier-regexp-list
7130 (concat
7131 "^\\("
7132 "\\(package\\)\\>"
7133 "\\|"
7134 "sub\\>[^\n]+::"
7135 "\\|"
7136 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
7137 "\\|"
7138 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
7139 "\\)"))
7141 (defvar cperl-hierarchy '(() ())
7142 "Global hierarchy of classes.")
7144 ;; Follows call to (autoloaded) visit-tags-table.
7145 (declare-function file-of-tag "etags" (&optional relative))
7146 (declare-function etags-snarf-tag "etags" (&optional use-explicit))
7148 (defun cperl-tags-hier-fill ()
7149 ;; Suppose we are in a tag table cooked by cperl.
7150 (goto-char 1)
7151 (let (type pack name pos line chunk ord cons1 file str info fileind)
7152 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
7153 (setq pos (match-beginning 0)
7154 pack (match-beginning 2))
7155 (beginning-of-line)
7156 (if (looking-at (concat
7157 "\\([^\n]+\\)"
7158 "\C-?"
7159 "\\([^\n]+\\)"
7160 "\C-a"
7161 "\\([0-9]+\\)"
7163 "\\([0-9]+\\)"))
7164 (progn
7165 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
7166 name (buffer-substring (match-beginning 2) (match-end 2))
7167 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
7168 line (buffer-substring (match-beginning 3) (match-end 3))
7169 ord (if pack 1 0)
7170 file (file-of-tag)
7171 fileind (format "%s:%s" file line)
7172 ;; Moves to beginning of the next line:
7173 info (cperl-etags-snarf-tag file line))
7174 ;; Move back
7175 (forward-char -1)
7176 ;; Make new member of hierarchy name ==> file ==> pos if needed
7177 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
7178 ;; Name known
7179 (setcdr cons1 (cons (cons fileind (vector file info))
7180 (cdr cons1)))
7181 ;; First occurrence of the name, start alist
7182 (setq cons1 (cons name (list (cons fileind (vector file info)))))
7183 (if pack
7184 (setcar (cdr cperl-hierarchy)
7185 (cons cons1 (nth 1 cperl-hierarchy)))
7186 (setcar cperl-hierarchy
7187 (cons cons1 (car cperl-hierarchy)))))))
7188 (end-of-line))))
7190 (declare-function x-popup-menu "menu.c" (position menu))
7191 (declare-function etags-goto-tag-location "etags" (tag-info))
7193 (defun cperl-tags-hier-init (&optional update)
7194 "Show hierarchical menu of classes and methods.
7195 Finds info about classes by a scan of loaded TAGS files.
7196 Supposes that the TAGS files contain fully qualified function names.
7197 One may build such TAGS files from CPerl mode menu."
7198 (interactive)
7199 (require 'etags)
7200 (require 'imenu)
7201 (if (or update (null (nth 2 cperl-hierarchy)))
7202 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
7203 (or (nthcdr 2 elt)
7204 ;; Only in one file
7205 (setcdr elt (cdr (nth 1 elt)))))))
7206 pack name cons1 to l1 l2 l3 l4 b)
7207 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
7208 (setq cperl-hierarchy (list l1 l2 l3))
7209 (if (featurep 'xemacs) ; Not checked
7210 (progn
7211 (or tags-file-name
7212 ;; Does this work in XEmacs?
7213 (call-interactively 'visit-tags-table))
7214 (message "Updating list of classes...")
7215 (set-buffer (get-file-buffer tags-file-name))
7216 (cperl-tags-hier-fill))
7217 (or tags-table-list
7218 (call-interactively 'visit-tags-table))
7219 (mapc
7220 (function
7221 (lambda (tagsfile)
7222 (message "Updating list of classes... %s" tagsfile)
7223 (set-buffer (get-file-buffer tagsfile))
7224 (cperl-tags-hier-fill)))
7225 tags-table-list)
7226 (message "Updating list of classes... postprocessing..."))
7227 (mapc remover (car cperl-hierarchy))
7228 (mapc remover (nth 1 cperl-hierarchy))
7229 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
7230 (cons "Methods: " (car cperl-hierarchy))))
7231 (cperl-tags-treeify to 1)
7232 (setcar (nthcdr 2 cperl-hierarchy)
7233 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
7234 (message "Updating list of classes: done, requesting display...")
7235 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
7237 (or (nth 2 cperl-hierarchy)
7238 (error "No items found"))
7239 (setq update
7240 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
7241 (if (if (fboundp 'display-popup-menus-p)
7242 (let ((f 'display-popup-menus-p))
7243 (funcall f))
7244 window-system)
7245 (x-popup-menu t (nth 2 cperl-hierarchy))
7246 (require 'tmm)
7247 (tmm-prompt (nth 2 cperl-hierarchy))))
7248 (if (and update (listp update))
7249 (progn (while (cdr update) (setq update (cdr update)))
7250 (setq update (car update)))) ; Get the last from the list
7251 (if (vectorp update)
7252 (progn
7253 (find-file (elt update 0))
7254 (cperl-etags-goto-tag-location (elt update 1))))
7255 (if (eq update -999) (cperl-tags-hier-init t)))
7257 (defun cperl-tags-treeify (to level)
7258 ;; cadr of `to' is read-write. On start it is a cons
7259 (let* ((regexp (concat "^\\(" (mapconcat
7260 'identity
7261 (make-list level "[_a-zA-Z0-9]+")
7262 "::")
7263 "\\)\\(::\\)?"))
7264 (packages (cdr (nth 1 to)))
7265 (methods (cdr (nth 2 to)))
7266 l1 head tail cons1 cons2 ord writeto packs recurse
7267 root-packages root-functions ms many_ms same_name ps
7268 (move-deeper
7269 (function
7270 (lambda (elt)
7271 (cond ((and (string-match regexp (car elt))
7272 (or (eq ord 1) (match-end 2)))
7273 (setq head (substring (car elt) 0 (match-end 1))
7274 tail (if (match-end 2) (substring (car elt)
7275 (match-end 2)))
7276 recurse t)
7277 (if (setq cons1 (assoc head writeto)) nil
7278 ;; Need to init new head
7279 (setcdr writeto (cons (list head (list "Packages: ")
7280 (list "Methods: "))
7281 (cdr writeto)))
7282 (setq cons1 (nth 1 writeto)))
7283 (setq cons2 (nth ord cons1)) ; Either packs or meths
7284 (setcdr cons2 (cons elt (cdr cons2))))
7285 ((eq ord 2)
7286 (setq root-functions (cons elt root-functions)))
7288 (setq root-packages (cons elt root-packages))))))))
7289 (setcdr to l1) ; Init to dynamic space
7290 (setq writeto to)
7291 (setq ord 1)
7292 (mapc move-deeper packages)
7293 (setq ord 2)
7294 (mapc move-deeper methods)
7295 (if recurse
7296 (mapc (function (lambda (elt)
7297 (cperl-tags-treeify elt (1+ level))))
7298 (cdr to)))
7299 ;;Now clean up leaders with one child only
7300 (mapc (function (lambda (elt)
7301 (if (not (and (listp (cdr elt))
7302 (eq (length elt) 2))) nil
7303 (setcar elt (car (nth 1 elt)))
7304 (setcdr elt (cdr (nth 1 elt))))))
7305 (cdr to))
7306 ;; Sort the roots of subtrees
7307 (if (default-value 'imenu-sort-function)
7308 (setcdr to
7309 (sort (cdr to) (default-value 'imenu-sort-function))))
7310 ;; Now add back functions removed from display
7311 (mapc (function (lambda (elt)
7312 (setcdr to (cons elt (cdr to)))))
7313 (if (default-value 'imenu-sort-function)
7314 (nreverse
7315 (sort root-functions (default-value 'imenu-sort-function)))
7316 root-functions))
7317 ;; Now add back packages removed from display
7318 (mapc (function (lambda (elt)
7319 (setcdr to (cons (cons (concat "package " (car elt))
7320 (cdr elt))
7321 (cdr to)))))
7322 (if (default-value 'imenu-sort-function)
7323 (nreverse
7324 (sort root-packages (default-value 'imenu-sort-function)))
7325 root-packages))))
7327 ;;;(x-popup-menu t
7328 ;;; '(keymap "Name1"
7329 ;;; ("Ret1" "aa")
7330 ;;; ("Head1" "ab"
7331 ;;; keymap "Name2"
7332 ;;; ("Tail1" "x") ("Tail2" "y"))))
7334 (defun cperl-list-fold (list name limit)
7335 (let (list1 list2 elt1 (num 0))
7336 (if (<= (length list) limit) list
7337 (setq list1 nil list2 nil)
7338 (while list
7339 (setq num (1+ num)
7340 elt1 (car list)
7341 list (cdr list))
7342 (if (<= num imenu-max-items)
7343 (setq list2 (cons elt1 list2))
7344 (setq list1 (cons (cons name
7345 (nreverse list2))
7346 list1)
7347 list2 (list elt1)
7348 num 1)))
7349 (nreverse (cons (cons name
7350 (nreverse list2))
7351 list1)))))
7353 (defun cperl-menu-to-keymap (menu &optional name)
7354 (let (list)
7355 (cons 'keymap
7356 (mapcar
7357 (function
7358 (lambda (elt)
7359 (cond ((listp (cdr elt))
7360 (setq list (cperl-list-fold
7361 (cdr elt) (car elt) imenu-max-items))
7362 (cons nil
7363 (cons (car elt)
7364 (cperl-menu-to-keymap list))))
7366 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
7367 (cperl-list-fold menu "Root" imenu-max-items)))))
7370 (defvar cperl-bad-style-regexp
7371 (mapconcat 'identity
7372 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
7373 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
7374 "\\|")
7375 "Finds places such that insertion of a whitespace may help a lot.")
7377 (defvar cperl-not-bad-style-regexp
7378 (mapconcat
7379 'identity
7380 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
7381 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
7382 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
7383 "<\\$?\\sw+\\(\\.\\(\\sw\\|_\\)+\\)?>" ; <IN> <stdin.h>
7384 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
7385 "-[0-9]" ; -5
7386 "\\+\\+" ; ++var
7387 "--" ; --var
7388 ".->" ; a->b
7389 "->" ; a SPACE ->b
7390 "\\[-" ; a[-1]
7391 "\\\\[&$@*\\\\]" ; \&func
7392 "^=" ; =head
7393 "\\$." ; $|
7394 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
7395 "||"
7396 "&&"
7397 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
7398 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
7399 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
7400 ;;"[*/+-|&<.]+="
7402 "\\|")
7403 "If matches at the start of match found by `my-bad-c-style-regexp',
7404 insertion of a whitespace will not help.")
7406 (defvar found-bad)
7408 (defun cperl-find-bad-style ()
7409 "Find places in the buffer where insertion of a whitespace may help.
7410 Prompts user for insertion of spaces.
7411 Currently it is tuned to C and Perl syntax."
7412 (interactive)
7413 (let (found-bad (p (point)))
7414 (setq last-nonmenu-event 13) ; To disable popup
7415 (goto-char (point-min))
7416 (map-y-or-n-p "Insert space here? "
7417 (lambda (arg) (insert " "))
7418 'cperl-next-bad-style
7419 '("location" "locations" "insert a space into")
7420 '((?\C-r (lambda (arg)
7421 (let ((buffer-quit-function
7422 'exit-recursive-edit))
7423 (message "Exit with Esc Esc")
7424 (recursive-edit)
7425 t)) ; Consider acted upon
7426 "edit, exit with Esc Esc")
7427 (?e (lambda (arg)
7428 (let ((buffer-quit-function
7429 'exit-recursive-edit))
7430 (message "Exit with Esc Esc")
7431 (recursive-edit)
7432 t)) ; Consider acted upon
7433 "edit, exit with Esc Esc"))
7435 (if found-bad (goto-char found-bad)
7436 (goto-char p)
7437 (message "No appropriate place found"))))
7439 (defun cperl-next-bad-style ()
7440 (let (p (not-found t) (point (point)) found)
7441 (while (and not-found
7442 (re-search-forward cperl-bad-style-regexp nil 'to-end))
7443 (setq p (point))
7444 (goto-char (match-beginning 0))
7445 (if (or
7446 (looking-at cperl-not-bad-style-regexp)
7447 ;; Check for a < -b and friends
7448 (and (eq (following-char) ?\-)
7449 (save-excursion
7450 (skip-chars-backward " \t\n")
7451 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
7452 ;; Now check for syntax type
7453 (save-match-data
7454 (setq found (point))
7455 (beginning-of-defun)
7456 (let ((pps (parse-partial-sexp (point) found)))
7457 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
7458 (goto-char (match-end 0))
7459 (goto-char (1- p))
7460 (setq not-found nil
7461 found-bad found)))
7462 (not not-found)))
7465 ;;; Getting help
7466 (defvar cperl-have-help-regexp
7467 ;;(concat "\\("
7468 (mapconcat
7469 'identity
7470 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
7471 "[$@]\\^[a-zA-Z]" ; Special variable
7472 "[$@][^ \n\t]" ; Special variable
7473 "-[a-zA-Z]" ; File test
7474 "\\\\[a-zA-Z0]" ; Special chars
7475 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
7476 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
7477 "[a-zA-Z_0-9:]+" ; symbol or number
7478 "x="
7479 "#!")
7480 ;;"\\)\\|\\("
7481 "\\|")
7482 ;;"\\)"
7484 "Matches places in the buffer we can find help for.")
7486 (defvar cperl-message-on-help-error t)
7487 (defvar cperl-help-from-timer nil)
7489 (defun cperl-word-at-point-hard ()
7490 ;; Does not save-excursion
7491 ;; Get to the something meaningful
7492 (or (eobp) (eolp) (forward-char 1))
7493 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
7494 (point-at-bol)
7495 'to-beg)
7496 ;; (cond
7497 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
7498 ;; (skip-chars-backward " \n\t\r({[]});,")
7499 ;; (or (bobp) (backward-char 1))))
7500 ;; Try to backtrace
7501 (cond
7502 ((looking-at "[a-zA-Z0-9_:]") ; symbol
7503 (skip-chars-backward "a-zA-Z0-9_:")
7504 (cond
7505 ((and (eq (preceding-char) ?^) ; $^I
7506 (eq (char-after (- (point) 2)) ?\$))
7507 (forward-char -2))
7508 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
7509 (forward-char -1))
7510 ((and (eq (preceding-char) ?\=)
7511 (eq (current-column) 1))
7512 (forward-char -1))) ; =head1
7513 (if (and (eq (preceding-char) ?\<)
7514 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
7515 (forward-char -1)))
7516 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
7517 (forward-char -1))
7518 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
7519 (forward-char -1))
7520 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
7521 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
7522 (cond
7523 ((and (eq (preceding-char) ?\$)
7524 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
7525 (forward-char -1))
7526 ((and (eq (following-char) ?\>)
7527 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
7528 (save-excursion
7529 (forward-sexp -1)
7530 (and (eq (preceding-char) ?\<)
7531 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
7532 (search-backward "<"))))
7533 ((and (eq (following-char) ?\$)
7534 (eq (preceding-char) ?\<)
7535 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
7536 (forward-char -1)))
7537 (if (looking-at cperl-have-help-regexp)
7538 (buffer-substring (match-beginning 0) (match-end 0))))
7540 (defun cperl-get-help ()
7541 "Get one-line docs on the symbol at the point.
7542 The data for these docs is a little bit obsolete and may be in fact longer
7543 than a line. Your contribution to update/shorten it is appreciated."
7544 (interactive)
7545 (save-match-data ; May be called "inside" query-replace
7546 (save-excursion
7547 (let ((word (cperl-word-at-point-hard)))
7548 (if word
7549 (if (and cperl-help-from-timer ; Bail out if not in mainland
7550 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
7551 (or (memq (get-text-property (point) 'face)
7552 '(font-lock-comment-face font-lock-string-face))
7553 (memq (get-text-property (point) 'syntax-type)
7554 '(pod here-doc format))))
7556 (cperl-describe-perl-symbol word))
7557 (if cperl-message-on-help-error
7558 (message "Nothing found for %s..."
7559 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
7561 ;;; Stolen from perl-descr.el by Johan Vromans:
7563 (defvar cperl-doc-buffer " *perl-doc*"
7564 "Where the documentation can be found.")
7566 (defun cperl-describe-perl-symbol (val)
7567 "Display the documentation of symbol at point, a Perl operator."
7568 (let ((enable-recursive-minibuffers t)
7569 args-file regexp)
7570 (cond
7571 ((string-match "^[&*][a-zA-Z_]" val)
7572 (setq val (concat (substring val 0 1) "NAME")))
7573 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
7574 (setq val (concat "@" (substring val 1 (match-end 1)))))
7575 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
7576 (setq val (concat "%" (substring val 1 (match-end 1)))))
7577 ((and (string= val "x") (string-match "^x=" val))
7578 (setq val "x="))
7579 ((string-match "^\\$[\C-a-\C-z]" val)
7580 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
7581 ((string-match "^CORE::" val)
7582 (setq val "CORE::"))
7583 ((string-match "^SUPER::" val)
7584 (setq val "SUPER::"))
7585 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
7586 (setq val "<NAME>")))
7587 (setq regexp (concat "^"
7588 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
7589 (regexp-quote val)
7590 "\\([ \t([/]\\|$\\)"))
7592 ;; get the buffer with the documentation text
7593 (cperl-switch-to-doc-buffer)
7595 ;; lookup in the doc
7596 (goto-char (point-min))
7597 (let ((case-fold-search nil))
7598 (list
7599 (if (re-search-forward regexp (point-max) t)
7600 (save-excursion
7601 (beginning-of-line 1)
7602 (let ((lnstart (point)))
7603 (end-of-line)
7604 (message "%s" (buffer-substring lnstart (point)))))
7605 (if cperl-message-on-help-error
7606 (message "No definition for %s" val)))))))
7608 (defvar cperl-short-docs 'please-ignore-this-line
7609 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
7610 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
7611 ... Range (list context); flip/flop [no flop when flip] (scalar context).
7612 ! ... Logical negation.
7613 ... != ... Numeric inequality.
7614 ... !~ ... Search pattern, substitution, or translation (negated).
7615 $! In numeric context: errno. In a string context: error string.
7616 $\" The separator which joins elements of arrays interpolated in strings.
7617 $# The output format for printed numbers. Default is %.15g or close.
7618 $$ Process number of this script. Changes in the fork()ed child process.
7619 $% The current page number of the currently selected output channel.
7621 The following variables are always local to the current block:
7623 $1 Match of the 1st set of parentheses in the last match (auto-local).
7624 $2 Match of the 2nd set of parentheses in the last match (auto-local).
7625 $3 Match of the 3rd set of parentheses in the last match (auto-local).
7626 $4 Match of the 4th set of parentheses in the last match (auto-local).
7627 $5 Match of the 5th set of parentheses in the last match (auto-local).
7628 $6 Match of the 6th set of parentheses in the last match (auto-local).
7629 $7 Match of the 7th set of parentheses in the last match (auto-local).
7630 $8 Match of the 8th set of parentheses in the last match (auto-local).
7631 $9 Match of the 9th set of parentheses in the last match (auto-local).
7632 $& The string matched by the last pattern match (auto-local).
7633 $' The string after what was matched by the last match (auto-local).
7634 $` The string before what was matched by the last match (auto-local).
7636 $( The real gid of this process.
7637 $) The effective gid of this process.
7638 $* Deprecated: Set to 1 to do multiline matching within a string.
7639 $+ The last bracket matched by the last search pattern.
7640 $, The output field separator for the print operator.
7641 $- The number of lines left on the page.
7642 $. The current input line number of the last filehandle that was read.
7643 $/ The input record separator, newline by default.
7644 $0 Name of the file containing the current perl script (read/write).
7645 $: String may be broken after these characters to fill ^-lines in a format.
7646 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
7647 $< The real uid of this process.
7648 $= The page length of the current output channel. Default is 60 lines.
7649 $> The effective uid of this process.
7650 $? The status returned by the last ``, pipe close or `system'.
7651 $@ The perl error message from the last eval or do @var{EXPR} command.
7652 $ARGV The name of the current file used with <> .
7653 $[ Deprecated: The index of the first element/char in an array/string.
7654 $\\ The output record separator for the print operator.
7655 $] The perl version string as displayed with perl -v.
7656 $^ The name of the current top-of-page format.
7657 $^A The current value of the write() accumulator for format() lines.
7658 $^D The value of the perl debug (-D) flags.
7659 $^E Information about the last system error other than that provided by $!.
7660 $^F The highest system file descriptor, ordinarily 2.
7661 $^H The current set of syntax checks enabled by `use strict'.
7662 $^I The value of the in-place edit extension (perl -i option).
7663 $^L What formats output to perform a formfeed. Default is \\f.
7664 $^M A buffer for emergency memory allocation when running out of memory.
7665 $^O The operating system name under which this copy of Perl was built.
7666 $^P Internal debugging flag.
7667 $^T The time the script was started. Used by -A/-M/-C file tests.
7668 $^W True if warnings are requested (perl -w flag).
7669 $^X The name under which perl was invoked (argv[0] in C-speech).
7670 $_ The default input and pattern-searching space.
7671 $| Auto-flush after write/print on current output channel? Default 0.
7672 $~ The name of the current report format.
7673 ... % ... Modulo division.
7674 ... %= ... Modulo division assignment.
7675 %ENV Contains the current environment.
7676 %INC List of files that have been require-d or do-ne.
7677 %SIG Used to set signal handlers for various signals.
7678 ... & ... Bitwise and.
7679 ... && ... Logical and.
7680 ... &&= ... Logical and assignment.
7681 ... &= ... Bitwise and assignment.
7682 ... * ... Multiplication.
7683 ... ** ... Exponentiation.
7684 *NAME Glob: all objects referred by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
7685 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
7686 ... + ... Addition. +EXPR Makes EXPR into scalar context.
7687 ++ Auto-increment (magical on strings). ++EXPR EXPR++
7688 ... += ... Addition assignment.
7689 , Comma operator.
7690 ... - ... Subtraction.
7691 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
7692 ... -= ... Subtraction assignment.
7693 -A Access time in days since script started.
7694 -B File is a non-text (binary) file.
7695 -C Inode change time in days since script started.
7696 -M Age in days since script started.
7697 -O File is owned by real uid.
7698 -R File is readable by real uid.
7699 -S File is a socket .
7700 -T File is a text file.
7701 -W File is writable by real uid.
7702 -X File is executable by real uid.
7703 -b File is a block special file.
7704 -c File is a character special file.
7705 -d File is a directory.
7706 -e File exists .
7707 -f File is a plain file.
7708 -g File has setgid bit set.
7709 -k File has sticky bit set.
7710 -l File is a symbolic link.
7711 -o File is owned by effective uid.
7712 -p File is a named pipe (FIFO).
7713 -r File is readable by effective uid.
7714 -s File has non-zero size.
7715 -t Tests if filehandle (STDIN by default) is opened to a tty.
7716 -u File has setuid bit set.
7717 -w File is writable by effective uid.
7718 -x File is executable by effective uid.
7719 -z File has zero size.
7720 . Concatenate strings.
7721 .. Range (list context); flip/flop (scalar context) operator.
7722 .= Concatenate assignment strings
7723 ... / ... Division. /PATTERN/ioxsmg Pattern match
7724 ... /= ... Division assignment.
7725 /PATTERN/ioxsmg Pattern match.
7726 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
7727 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
7728 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
7729 <> Reads line from union of files in @ARGV (= command line) and STDIN.
7730 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
7731 ... <= ... Numeric less than or equal to.
7732 ... <=> ... Numeric compare.
7733 ... = ... Assignment.
7734 ... == ... Numeric equality.
7735 ... =~ ... Search pattern, substitution, or translation
7736 ... > ... Numeric greater than.
7737 ... >= ... Numeric greater than or equal to.
7738 ... >> ... Bitwise shift right.
7739 ... >>= ... Bitwise shift right assignment.
7740 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
7741 ?PATTERN? One-time pattern match.
7742 @ARGV Command line arguments (not including the command name - see $0).
7743 @INC List of places to look for perl scripts during do/include/use.
7744 @_ Parameter array for subroutines; result of split() unless in list context.
7745 \\ Creates reference to what follows, like \\$var, or quotes non-\\w in strings.
7746 \\0 Octal char, e.g. \\033.
7747 \\E Case modification terminator. See \\Q, \\L, and \\U.
7748 \\L Lowercase until \\E . See also \\l, lc.
7749 \\U Upcase until \\E . See also \\u, uc.
7750 \\Q Quote metacharacters until \\E . See also quotemeta.
7751 \\a Alarm character (octal 007).
7752 \\b Backspace character (octal 010).
7753 \\c Control character, e.g. \\c[ .
7754 \\e Escape character (octal 033).
7755 \\f Formfeed character (octal 014).
7756 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
7757 \\n Newline character (octal 012 on most systems).
7758 \\r Return character (octal 015 on most systems).
7759 \\t Tab character (octal 011).
7760 \\u Upcase the next character. See also \\U and \\l, ucfirst.
7761 \\x Hex character, e.g. \\x1b.
7762 ... ^ ... Bitwise exclusive or.
7763 __END__ Ends program source.
7764 __DATA__ Ends program source.
7765 __FILE__ Current (source) filename.
7766 __LINE__ Current line in current source.
7767 __PACKAGE__ Current package.
7768 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
7769 ARGVOUT Output filehandle with -i flag.
7770 BEGIN { ... } Immediately executed (during compilation) piece of code.
7771 END { ... } Pseudo-subroutine executed after the script finishes.
7772 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
7773 INIT { ... } Pseudo-subroutine executed before the script starts running.
7774 DATA Input filehandle for what follows after __END__ or __DATA__.
7775 accept(NEWSOCKET,GENERICSOCKET)
7776 alarm(SECONDS)
7777 atan2(X,Y)
7778 bind(SOCKET,NAME)
7779 binmode(FILEHANDLE)
7780 caller[(LEVEL)]
7781 chdir(EXPR)
7782 chmod(LIST)
7783 chop[(LIST|VAR)]
7784 chown(LIST)
7785 chroot(FILENAME)
7786 close(FILEHANDLE)
7787 closedir(DIRHANDLE)
7788 ... cmp ... String compare.
7789 connect(SOCKET,NAME)
7790 continue of { block } continue { block }. Is executed after `next' or at end.
7791 cos(EXPR)
7792 crypt(PLAINTEXT,SALT)
7793 dbmclose(%HASH)
7794 dbmopen(%HASH,DBNAME,MODE)
7795 defined(EXPR)
7796 delete($HASH{KEY})
7797 die(LIST)
7798 do { ... }|SUBR while|until EXPR executes at least once
7799 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
7800 dump LABEL
7801 each(%HASH)
7802 endgrent
7803 endhostent
7804 endnetent
7805 endprotoent
7806 endpwent
7807 endservent
7808 eof[([FILEHANDLE])]
7809 ... eq ... String equality.
7810 eval(EXPR) or eval { BLOCK }
7811 exec([TRUENAME] ARGV0, ARGVs) or exec(SHELL_COMMAND_LINE)
7812 exit(EXPR)
7813 exp(EXPR)
7814 fcntl(FILEHANDLE,FUNCTION,SCALAR)
7815 fileno(FILEHANDLE)
7816 flock(FILEHANDLE,OPERATION)
7817 for (EXPR;EXPR;EXPR) { ... }
7818 foreach [VAR] (@ARRAY) { ... }
7819 fork
7820 ... ge ... String greater than or equal.
7821 getc[(FILEHANDLE)]
7822 getgrent
7823 getgrgid(GID)
7824 getgrnam(NAME)
7825 gethostbyaddr(ADDR,ADDRTYPE)
7826 gethostbyname(NAME)
7827 gethostent
7828 getlogin
7829 getnetbyaddr(ADDR,ADDRTYPE)
7830 getnetbyname(NAME)
7831 getnetent
7832 getpeername(SOCKET)
7833 getpgrp(PID)
7834 getppid
7835 getpriority(WHICH,WHO)
7836 getprotobyname(NAME)
7837 getprotobynumber(NUMBER)
7838 getprotoent
7839 getpwent
7840 getpwnam(NAME)
7841 getpwuid(UID)
7842 getservbyname(NAME,PROTO)
7843 getservbyport(PORT,PROTO)
7844 getservent
7845 getsockname(SOCKET)
7846 getsockopt(SOCKET,LEVEL,OPTNAME)
7847 gmtime(EXPR)
7848 goto LABEL
7849 ... gt ... String greater than.
7850 hex(EXPR)
7851 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
7852 index(STR,SUBSTR[,OFFSET])
7853 int(EXPR)
7854 ioctl(FILEHANDLE,FUNCTION,SCALAR)
7855 join(EXPR,LIST)
7856 keys(%HASH)
7857 kill(LIST)
7858 last [LABEL]
7859 ... le ... String less than or equal.
7860 length(EXPR)
7861 link(OLDFILE,NEWFILE)
7862 listen(SOCKET,QUEUESIZE)
7863 local(LIST)
7864 localtime(EXPR)
7865 log(EXPR)
7866 lstat(EXPR|FILEHANDLE|VAR)
7867 ... lt ... String less than.
7868 m/PATTERN/iogsmx
7869 mkdir(FILENAME,MODE)
7870 msgctl(ID,CMD,ARG)
7871 msgget(KEY,FLAGS)
7872 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
7873 msgsnd(ID,MSG,FLAGS)
7874 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
7875 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
7876 ... ne ... String inequality.
7877 next [LABEL]
7878 oct(EXPR)
7879 open(FILEHANDLE[,EXPR])
7880 opendir(DIRHANDLE,EXPR)
7881 ord(EXPR) ASCII value of the first char of the string.
7882 pack(TEMPLATE,LIST)
7883 package NAME Introduces package context.
7884 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
7885 pop(ARRAY)
7886 print [FILEHANDLE] [(LIST)]
7887 printf [FILEHANDLE] (FORMAT,LIST)
7888 push(ARRAY,LIST)
7889 q/STRING/ Synonym for 'STRING'
7890 qq/STRING/ Synonym for \"STRING\"
7891 qx/STRING/ Synonym for `STRING`
7892 rand[(EXPR)]
7893 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7894 readdir(DIRHANDLE)
7895 readlink(EXPR)
7896 recv(SOCKET,SCALAR,LEN,FLAGS)
7897 redo [LABEL]
7898 rename(OLDNAME,NEWNAME)
7899 require [FILENAME | PERL_VERSION]
7900 reset[(EXPR)]
7901 return(LIST)
7902 reverse(LIST)
7903 rewinddir(DIRHANDLE)
7904 rindex(STR,SUBSTR[,OFFSET])
7905 rmdir(FILENAME)
7906 s/PATTERN/REPLACEMENT/gieoxsm
7907 scalar(EXPR)
7908 seek(FILEHANDLE,POSITION,WHENCE)
7909 seekdir(DIRHANDLE,POS)
7910 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
7911 semctl(ID,SEMNUM,CMD,ARG)
7912 semget(KEY,NSEMS,SIZE,FLAGS)
7913 semop(KEY,...)
7914 send(SOCKET,MSG,FLAGS[,TO])
7915 setgrent
7916 sethostent(STAYOPEN)
7917 setnetent(STAYOPEN)
7918 setpgrp(PID,PGRP)
7919 setpriority(WHICH,WHO,PRIORITY)
7920 setprotoent(STAYOPEN)
7921 setpwent
7922 setservent(STAYOPEN)
7923 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
7924 shift[(ARRAY)]
7925 shmctl(ID,CMD,ARG)
7926 shmget(KEY,SIZE,FLAGS)
7927 shmread(ID,VAR,POS,SIZE)
7928 shmwrite(ID,STRING,POS,SIZE)
7929 shutdown(SOCKET,HOW)
7930 sin(EXPR)
7931 sleep[(EXPR)]
7932 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
7933 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
7934 sort [SUBROUTINE] (LIST)
7935 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
7936 split[(/PATTERN/[,EXPR[,LIMIT]])]
7937 sprintf(FORMAT,LIST)
7938 sqrt(EXPR)
7939 srand(EXPR)
7940 stat(EXPR|FILEHANDLE|VAR)
7941 study[(SCALAR)]
7942 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
7943 substr(EXPR,OFFSET[,LEN])
7944 symlink(OLDFILE,NEWFILE)
7945 syscall(LIST)
7946 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7947 system([TRUENAME] ARGV0 [,ARGV]) or system(SHELL_COMMAND_LINE)
7948 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7949 tell[(FILEHANDLE)]
7950 telldir(DIRHANDLE)
7951 time
7952 times
7953 tr/SEARCHLIST/REPLACEMENTLIST/cds
7954 truncate(FILE|EXPR,LENGTH)
7955 umask[(EXPR)]
7956 undef[(EXPR)]
7957 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
7958 unlink(LIST)
7959 unpack(TEMPLATE,EXPR)
7960 unshift(ARRAY,LIST)
7961 until (EXPR) { ... } EXPR until EXPR
7962 utime(LIST)
7963 values(%HASH)
7964 vec(EXPR,OFFSET,BITS)
7965 wait
7966 waitpid(PID,FLAGS)
7967 wantarray Returns true if the sub/eval is called in list context.
7968 warn(LIST)
7969 while (EXPR) { ... } EXPR while EXPR
7970 write[(EXPR|FILEHANDLE)]
7971 ... x ... Repeat string or array.
7972 x= ... Repetition assignment.
7973 y/SEARCHLIST/REPLACEMENTLIST/
7974 ... | ... Bitwise or.
7975 ... || ... Logical or.
7976 ~ ... Unary bitwise complement.
7977 #! OS interpreter indicator. If contains `perl', used for options, and -x.
7978 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
7979 CORE:: Prefix to access builtin function if imported sub obscures it.
7980 SUPER:: Prefix to lookup for a method in @ISA classes.
7981 DESTROY Shorthand for `sub DESTROY {...}'.
7982 ... EQ ... Obsolete synonym of `eq'.
7983 ... GE ... Obsolete synonym of `ge'.
7984 ... GT ... Obsolete synonym of `gt'.
7985 ... LE ... Obsolete synonym of `le'.
7986 ... LT ... Obsolete synonym of `lt'.
7987 ... NE ... Obsolete synonym of `ne'.
7988 abs [ EXPR ] absolute value
7989 ... and ... Low-precedence synonym for &&.
7990 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
7991 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
7992 chr Converts a number to char with the same ordinal.
7993 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
7994 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
7995 exists $HASH{KEY} True if the key exists.
7996 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
7997 formline PICTURE, LIST Backdoor into \"format\" processing.
7998 glob EXPR Synonym of <EXPR>.
7999 lc [ EXPR ] Returns lowercased EXPR.
8000 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
8001 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
8002 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
8003 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
8004 not ... Low-precedence synonym for ! - negation.
8005 ... or ... Low-precedence synonym for ||.
8006 pos STRING Set/Get end-position of the last match over this string, see \\G.
8007 quotemeta [ EXPR ] Quote regexp metacharacters.
8008 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
8009 readline FH Synonym of <FH>.
8010 readpipe CMD Synonym of `CMD`.
8011 ref [ EXPR ] Type of EXPR when dereferenced.
8012 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
8013 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
8014 tied Returns internal object for a tied data.
8015 uc [ EXPR ] Returns upcased EXPR.
8016 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
8017 untie VAR Unlink an object from a simple Perl variable.
8018 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
8019 ... xor ... Low-precedence synonym for exclusive or.
8020 prototype \\&SUB Returns prototype of the function given a reference.
8021 =head1 Top-level heading.
8022 =head2 Second-level heading.
8023 =head3 Third-level heading (is there such?).
8024 =over [ NUMBER ] Start list.
8025 =item [ TITLE ] Start new item in the list.
8026 =back End list.
8027 =cut Switch from POD to Perl.
8028 =pod Switch from Perl to POD.
8031 (defun cperl-switch-to-doc-buffer (&optional interactive)
8032 "Go to the perl documentation buffer and insert the documentation."
8033 (interactive "p")
8034 (let ((buf (get-buffer-create cperl-doc-buffer)))
8035 (if interactive
8036 (switch-to-buffer-other-window buf)
8037 (set-buffer buf))
8038 (if (= (buffer-size) 0)
8039 (progn
8040 (insert (documentation-property 'cperl-short-docs
8041 'variable-documentation))
8042 (setq buffer-read-only t)))))
8044 (defun cperl-beautify-regexp-piece (b e embed level)
8045 ;; b is before the starting delimiter, e before the ending
8046 ;; e should be a marker, may be changed, but remains "correct".
8047 ;; EMBED is nil if we process the whole REx.
8048 ;; The REx is guaranteed to have //x
8049 ;; LEVEL shows how many levels deep to go
8050 ;; position at enter and at leave is not defined
8051 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
8052 (if embed
8053 (progn
8054 (goto-char b)
8055 (setq c (if (eq embed t) (current-indentation) (current-column)))
8056 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
8057 (forward-char 2)
8058 (delete-char 1)
8059 (forward-char 1))
8060 ((looking-at "(\\?[^a-zA-Z]")
8061 (forward-char 3))
8062 ((looking-at "(\\?") ; (?i)
8063 (forward-char 2))
8065 (forward-char 1))))
8066 (goto-char (1+ b))
8067 (setq c (1- (current-column))))
8068 (setq c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
8069 (or (looking-at "[ \t]*[\n#]")
8070 (progn
8071 (insert "\n")))
8072 (goto-char e)
8073 (beginning-of-line)
8074 (if (re-search-forward "[^ \t]" e t)
8075 (progn ; Something before the ending delimiter
8076 (goto-char e)
8077 (delete-horizontal-space)
8078 (insert "\n")
8079 (cperl-make-indent c)
8080 (set-marker e (point))))
8081 (goto-char b)
8082 (end-of-line 2)
8083 (while (< (point) (marker-position e))
8084 (beginning-of-line)
8085 (setq s (point)
8086 inline t)
8087 (skip-chars-forward " \t")
8088 (delete-region s (point))
8089 (cperl-make-indent c1)
8090 (while (and
8091 inline
8092 (looking-at
8093 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
8094 "\\|" ; Embedded variable
8095 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
8096 "\\|" ; $ ^
8097 "[$^]"
8098 "\\|" ; simple-code simple-code*?
8099 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
8100 "\\|" ; Class
8101 "\\(\\[\\)" ; 6
8102 "\\|" ; Grouping
8103 "\\((\\(\\?\\)?\\)" ; 7 8
8104 "\\|" ; |
8105 "\\(|\\)"))) ; 9
8106 (goto-char (match-end 0))
8107 (setq spaces t)
8108 (cond ((match-beginning 1) ; Alphanum word + junk
8109 (forward-char -1))
8110 ((or (match-beginning 3) ; $ab[12]
8111 (and (match-beginning 5) ; X* X+ X{2,3}
8112 (eq (preceding-char) ?\{)))
8113 (forward-char -1)
8114 (forward-sexp 1))
8115 ((and ; [], already syntaxified
8116 (match-beginning 6)
8117 cperl-regexp-scan
8118 cperl-use-syntax-table-text-property)
8119 (forward-char -1)
8120 (forward-sexp 1)
8121 (or (eq (preceding-char) ?\])
8122 (error "[]-group not terminated"))
8123 (re-search-forward
8124 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8125 ((match-beginning 6) ; []
8126 (setq tmp (point))
8127 (if (looking-at "\\^?\\]")
8128 (goto-char (match-end 0)))
8129 ;; XXXX POSIX classes?!
8130 (while (and (not pos)
8131 (re-search-forward "\\[:\\|\\]" e t))
8132 (if (eq (preceding-char) ?:)
8133 (or (re-search-forward ":\\]" e t)
8134 (error "[:POSIX:]-group in []-group not terminated"))
8135 (setq pos t)))
8136 (or (eq (preceding-char) ?\])
8137 (error "[]-group not terminated"))
8138 (re-search-forward
8139 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
8140 ((match-beginning 7) ; ()
8141 (goto-char (match-beginning 0))
8142 (setq pos (current-column))
8143 (or (eq pos c1)
8144 (progn
8145 (delete-horizontal-space)
8146 (insert "\n")
8147 (cperl-make-indent c1)))
8148 (setq tmp (point))
8149 (forward-sexp 1)
8150 ;; (or (forward-sexp 1)
8151 ;; (progn
8152 ;; (goto-char tmp)
8153 ;; (error "()-group not terminated")))
8154 (set-marker m (1- (point)))
8155 (set-marker m1 (point))
8156 (if (= level 1)
8157 (if (progn ; indent rigidly if multiline
8158 ;; In fact does not make a lot of sense, since
8159 ;; the starting position can be already lost due
8160 ;; to insertion of "\n" and " "
8161 (goto-char tmp)
8162 (search-forward "\n" m1 t))
8163 (indent-rigidly (point) m1 (- c1 pos)))
8164 (setq level (1- level))
8165 (cond
8166 ((not (match-beginning 8))
8167 (cperl-beautify-regexp-piece tmp m t level))
8168 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
8170 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
8171 (goto-char (+ 2 tmp))
8172 (forward-sexp 1)
8173 (cperl-beautify-regexp-piece (point) m t level))
8174 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
8175 (goto-char (+ 3 tmp))
8176 (cperl-beautify-regexp-piece (point) m t level))
8178 (cperl-beautify-regexp-piece tmp m t level))))
8179 (goto-char m1)
8180 (cond ((looking-at "[*+?]\\??")
8181 (goto-char (match-end 0)))
8182 ((eq (following-char) ?\{)
8183 (forward-sexp 1)
8184 (if (eq (following-char) ?\?)
8185 (forward-char))))
8186 (skip-chars-forward " \t")
8187 (setq spaces nil)
8188 (if (looking-at "[#\n]")
8189 (progn
8190 (or (eolp) (indent-for-comment))
8191 (beginning-of-line 2))
8192 (delete-horizontal-space)
8193 (insert "\n"))
8194 (end-of-line)
8195 (setq inline nil))
8196 ((match-beginning 9) ; |
8197 (forward-char -1)
8198 (setq tmp (point))
8199 (beginning-of-line)
8200 (if (re-search-forward "[^ \t]" tmp t)
8201 (progn
8202 (goto-char tmp)
8203 (delete-horizontal-space)
8204 (insert "\n"))
8205 ;; first at line
8206 (delete-region (point) tmp))
8207 (cperl-make-indent c)
8208 (forward-char 1)
8209 (skip-chars-forward " \t")
8210 (setq spaces nil)
8211 (if (looking-at "[#\n]")
8212 (beginning-of-line 2)
8213 (delete-horizontal-space)
8214 (insert "\n"))
8215 (end-of-line)
8216 (setq inline nil)))
8217 (or (looking-at "[ \t\n]")
8218 (not spaces)
8219 (insert " "))
8220 (skip-chars-forward " \t"))
8221 (or (looking-at "[#\n]")
8222 (error "Unknown code `%s' in a regexp"
8223 (buffer-substring (point) (1+ (point)))))
8224 (and inline (end-of-line 2)))
8225 ;; Special-case the last line of group
8226 (if (and (>= (point) (marker-position e))
8227 (/= (current-indentation) c))
8228 (progn
8229 (beginning-of-line)
8230 (cperl-make-indent c)))))
8232 (defun cperl-make-regexp-x ()
8233 ;; Returns position of the start
8234 ;; XXX this is called too often! Need to cache the result!
8235 (save-excursion
8236 (or cperl-use-syntax-table-text-property
8237 (error "I need to have a regexp marked!"))
8238 ;; Find the start
8239 (if (looking-at "\\s|")
8240 nil ; good already
8241 (if (or (looking-at "\\([smy]\\|qr\\)\\s|")
8242 (and (eq (preceding-char) ?q)
8243 (looking-at "\\(r\\)\\s|")))
8244 (goto-char (match-end 1))
8245 (re-search-backward "\\s|"))) ; Assume it is scanned already.
8246 ;;(forward-char 1)
8247 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
8248 (sub-p (eq (preceding-char) ?s)) s)
8249 (forward-sexp 1)
8250 (set-marker e (1- (point)))
8251 (setq delim (preceding-char))
8252 (if (and sub-p (eq delim (char-after (- (point) 2))))
8253 (error "Possible s/blah// - do not know how to deal with"))
8254 (if sub-p (forward-sexp 1))
8255 (if (looking-at "\\sw*x")
8256 (setq have-x t)
8257 (insert "x"))
8258 ;; Protect fragile " ", "#"
8259 (if have-x nil
8260 (goto-char (1+ b))
8261 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
8262 (forward-char -1)
8263 (insert "\\")
8264 (forward-char 1)))
8265 b)))
8267 (defun cperl-beautify-regexp (&optional deep)
8268 "Do it. (Experimental, may change semantics, recheck the result.)
8269 We suppose that the regexp is scanned already."
8270 (interactive "P")
8271 (setq deep (if deep (prefix-numeric-value deep) -1))
8272 (save-excursion
8273 (goto-char (cperl-make-regexp-x))
8274 (let ((b (point)) (e (make-marker)))
8275 (forward-sexp 1)
8276 (set-marker e (1- (point)))
8277 (cperl-beautify-regexp-piece b e nil deep))))
8279 (defun cperl-regext-to-level-start ()
8280 "Goto start of an enclosing group in regexp.
8281 We suppose that the regexp is scanned already."
8282 (interactive)
8283 (let ((limit (cperl-make-regexp-x)) done)
8284 (while (not done)
8285 (or (eq (following-char) ?\()
8286 (search-backward "(" (1+ limit) t)
8287 (error "Cannot find `(' which starts a group"))
8288 (setq done
8289 (save-excursion
8290 (skip-chars-backward "\\")
8291 (looking-at "\\(\\\\\\\\\\)*(")))
8292 (or done (forward-char -1)))))
8294 (defun cperl-contract-level ()
8295 "Find an enclosing group in regexp and contract it.
8296 \(Experimental, may change semantics, recheck the result.)
8297 We suppose that the regexp is scanned already."
8298 (interactive)
8299 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
8300 (cperl-regext-to-level-start)
8301 (let ((b (point)) (e (make-marker)) c)
8302 (forward-sexp 1)
8303 (set-marker e (1- (point)))
8304 (goto-char b)
8305 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
8306 (cond
8307 ((match-beginning 1) ; #-comment
8308 (or c (setq c (current-indentation)))
8309 (beginning-of-line 2) ; Skip
8310 (cperl-make-indent c))
8312 (delete-char -1)
8313 (just-one-space))))))
8315 (defun cperl-contract-levels ()
8316 "Find an enclosing group in regexp and contract all the kids.
8317 \(Experimental, may change semantics, recheck the result.)
8318 We suppose that the regexp is scanned already."
8319 (interactive)
8320 (save-excursion
8321 (condition-case nil
8322 (cperl-regext-to-level-start)
8323 (error ; We are outside outermost group
8324 (goto-char (cperl-make-regexp-x))))
8325 (let ((b (point)) (e (make-marker)) s c)
8326 (forward-sexp 1)
8327 (set-marker e (1- (point)))
8328 (goto-char (1+ b))
8329 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
8330 (cond
8331 ((match-beginning 1) ; Skip
8332 nil)
8333 (t ; Group
8334 (cperl-contract-level)))))))
8336 (defun cperl-beautify-level (&optional deep)
8337 "Find an enclosing group in regexp and beautify it.
8338 \(Experimental, may change semantics, recheck the result.)
8339 We suppose that the regexp is scanned already."
8340 (interactive "P")
8341 (setq deep (if deep (prefix-numeric-value deep) -1))
8342 (save-excursion
8343 (cperl-regext-to-level-start)
8344 (let ((b (point)) (e (make-marker)))
8345 (forward-sexp 1)
8346 (set-marker e (1- (point)))
8347 (cperl-beautify-regexp-piece b e 'level deep))))
8349 (defun cperl-invert-if-unless-modifiers ()
8350 "Change `B if A;' into `if (A) {B}' etc if possible.
8351 \(Unfinished.)"
8352 (interactive)
8353 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string
8354 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>"))
8355 (and (= (char-syntax (preceding-char)) ?w)
8356 (forward-sexp -1))
8357 (setq pre-if (point))
8358 (cperl-backward-to-start-of-expr)
8359 (setq pre-B (point))
8360 (forward-sexp 1) ; otherwise forward-to-end-of-expr is NOP
8361 (cperl-forward-to-end-of-expr)
8362 (setq post-A (point))
8363 (goto-char pre-if)
8364 (or (looking-at w-rex)
8365 ;; Find the position
8366 (progn (goto-char post-A)
8367 (while (and
8368 (not (looking-at w-rex))
8369 (> (point) pre-B))
8370 (forward-sexp -1))
8371 (setq pre-if (point))))
8372 (or (looking-at w-rex)
8373 (error "Can't find `if', `unless', `while', `until', `for' or `foreach'"))
8374 ;; 1 B 2 ... 3 B-com ... 4 if 5 ... if-com 6 ... 7 A 8
8375 (setq if-string (buffer-substring (match-beginning 0) (match-end 0)))
8376 ;; First, simple part: find code boundaries
8377 (forward-sexp 1)
8378 (setq post-if (point))
8379 (forward-sexp -2)
8380 (forward-sexp 1)
8381 (setq post-B (point))
8382 (cperl-backward-to-start-of-expr)
8383 (setq pre-B (point))
8384 (setq B (buffer-substring pre-B post-B))
8385 (goto-char pre-if)
8386 (forward-sexp 2)
8387 (forward-sexp -1)
8388 ;; May be after $, @, $# etc of a variable
8389 (skip-chars-backward "$@%#")
8390 (setq pre-A (point))
8391 (cperl-forward-to-end-of-expr)
8392 (setq post-A (point))
8393 (setq A (buffer-substring pre-A post-A))
8394 ;; Now modify (from end, to not break the stuff)
8395 (skip-chars-forward " \t;")
8396 (delete-region pre-A (point)) ; we move to pre-A
8397 (insert "\n" B ";\n}")
8398 (and (looking-at "[ \t]*#") (cperl-indent-for-comment))
8399 (delete-region pre-if post-if)
8400 (delete-region pre-B post-B)
8401 (goto-char pre-B)
8402 (insert if-string " (" A ") {")
8403 (setq post-B (point))
8404 (if (looking-at "[ \t]+$")
8405 (delete-horizontal-space)
8406 (if (looking-at "[ \t]*#")
8407 (cperl-indent-for-comment)
8408 (just-one-space)))
8409 (forward-line 1)
8410 (if (looking-at "[ \t]*$")
8411 (progn ; delete line
8412 (delete-horizontal-space)
8413 (delete-region (point) (1+ (point)))))
8414 (cperl-indent-line)
8415 (goto-char (1- post-B))
8416 (forward-sexp 1)
8417 (cperl-indent-line)
8418 (goto-char pre-B)))
8420 (defun cperl-invert-if-unless ()
8421 "Change `if (A) {B}' into `B if A;' etc (or visa versa) if possible.
8422 If the cursor is not on the leading keyword of the BLOCK flavor of
8423 construct, will assume it is the STATEMENT flavor, so will try to find
8424 the appropriate statement modifier."
8425 (interactive)
8426 (and (= (char-syntax (preceding-char)) ?w)
8427 (forward-sexp -1))
8428 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
8429 (let ((pre-if (point))
8430 pre-A post-A pre-B post-B A B state p end-B-code is-block B-comment
8431 (if-string (buffer-substring (match-beginning 0) (match-end 0))))
8432 (forward-sexp 2)
8433 (setq post-A (point))
8434 (forward-sexp -1)
8435 (setq pre-A (point))
8436 (setq is-block (and (eq (following-char) ?\( )
8437 (save-excursion
8438 (condition-case nil
8439 (progn
8440 (forward-sexp 2)
8441 (forward-sexp -1)
8442 (eq (following-char) ?\{ ))
8443 (error nil)))))
8444 (if is-block
8445 (progn
8446 (goto-char post-A)
8447 (forward-sexp 1)
8448 (setq post-B (point))
8449 (forward-sexp -1)
8450 (setq pre-B (point))
8451 (if (and (eq (following-char) ?\{ )
8452 (progn
8453 (cperl-backward-to-noncomment post-A)
8454 (eq (preceding-char) ?\) )))
8455 (if (condition-case nil
8456 (progn
8457 (goto-char post-B)
8458 (forward-sexp 1)
8459 (forward-sexp -1)
8460 (looking-at "\\<els\\(e\\|if\\)\\>"))
8461 (error nil))
8462 (error
8463 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" if-string)
8464 (goto-char (1- post-B))
8465 (cperl-backward-to-noncomment pre-B)
8466 (if (eq (preceding-char) ?\;)
8467 (forward-char -1))
8468 (setq end-B-code (point))
8469 (goto-char pre-B)
8470 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" end-B-code t)
8471 (setq p (match-beginning 0)
8472 A (buffer-substring p (match-end 0))
8473 state (parse-partial-sexp pre-B p))
8474 (or (nth 3 state)
8475 (nth 4 state)
8476 (nth 5 state)
8477 (error "`%s' inside `%s' BLOCK" A if-string))
8478 (goto-char (match-end 0)))
8479 ;; Finally got it
8480 (goto-char (1+ pre-B))
8481 (skip-chars-forward " \t\n")
8482 (setq B (buffer-substring (point) end-B-code))
8483 (goto-char end-B-code)
8484 (or (looking-at ";?[ \t\n]*}")
8485 (progn
8486 (skip-chars-forward "; \t\n")
8487 (setq B-comment
8488 (buffer-substring (point) (1- post-B)))))
8489 (and (equal B "")
8490 (setq B "1"))
8491 (goto-char (1- post-A))
8492 (cperl-backward-to-noncomment pre-A)
8493 (or (looking-at "[ \t\n]*)")
8494 (goto-char (1- post-A)))
8495 (setq p (point))
8496 (goto-char (1+ pre-A))
8497 (skip-chars-forward " \t\n")
8498 (setq A (buffer-substring (point) p))
8499 (delete-region pre-B post-B)
8500 (delete-region pre-A post-A)
8501 (goto-char pre-if)
8502 (insert B " ")
8503 (and B-comment (insert B-comment " "))
8504 (just-one-space)
8505 (forward-word 1)
8506 (setq pre-A (point))
8507 (insert " " A ";")
8508 (delete-horizontal-space)
8509 (setq post-B (point))
8510 (if (looking-at "#")
8511 (indent-for-comment))
8512 (goto-char post-B)
8513 (forward-char -1)
8514 (delete-horizontal-space)
8515 (goto-char pre-A)
8516 (just-one-space)
8517 (goto-char pre-if)
8518 (setq pre-A (set-marker (make-marker) pre-A))
8519 (while (<= (point) (marker-position pre-A))
8520 (cperl-indent-line)
8521 (forward-line 1))
8522 (goto-char (marker-position pre-A))
8523 (if B-comment
8524 (progn
8525 (forward-line -1)
8526 (indent-for-comment)
8527 (goto-char (marker-position pre-A)))))
8528 (error "`%s' (EXPR) not with an {BLOCK}" if-string)))
8529 ;; (error "`%s' not with an (EXPR)" if-string)
8530 (forward-sexp -1)
8531 (cperl-invert-if-unless-modifiers)))
8532 ;;(error "Not at `if', `unless', `while', `until', `for' or `foreach'")
8533 (cperl-invert-if-unless-modifiers)))
8535 (declare-function Man-getpage-in-background "man" (topic))
8537 ;;; By Anthony Foiani <afoiani@uswest.com>
8538 ;;; Getting help on modules in C-h f ?
8539 ;;; This is a modified version of `man'.
8540 ;;; Need to teach it how to lookup functions
8541 ;;;###autoload
8542 (defun cperl-perldoc (word)
8543 "Run `perldoc' on WORD."
8544 (interactive
8545 (list (let* ((default-entry (cperl-word-at-point))
8546 (input (read-string
8547 (format "perldoc entry%s: "
8548 (if (string= default-entry "")
8550 (format " (default %s)" default-entry))))))
8551 (if (string= input "")
8552 (if (string= default-entry "")
8553 (error "No perldoc args given")
8554 default-entry)
8555 input))))
8556 (require 'man)
8557 (let* ((case-fold-search nil)
8558 (is-func (and
8559 (string-match "^[a-z]+$" word)
8560 (string-match (concat "^" word "\\>")
8561 (documentation-property
8562 'cperl-short-docs
8563 'variable-documentation))))
8564 (Man-switches "")
8565 (manual-program (if is-func "perldoc -f" "perldoc")))
8566 (cond
8567 ((featurep 'xemacs)
8568 (let ((Manual-program "perldoc")
8569 (Manual-switches (if is-func (list "-f"))))
8570 (manual-entry word)))
8572 (Man-getpage-in-background word)))))
8574 ;;;###autoload
8575 (defun cperl-perldoc-at-point ()
8576 "Run a `perldoc' on the word around point."
8577 (interactive)
8578 (cperl-perldoc (cperl-word-at-point)))
8580 (defcustom pod2man-program "pod2man"
8581 "*File name for `pod2man'."
8582 :type 'file
8583 :group 'cperl)
8585 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
8586 (defun cperl-pod-to-manpage ()
8587 "Create a virtual manpage in Emacs from the Perl Online Documentation."
8588 (interactive)
8589 (require 'man)
8590 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
8591 (bufname (concat "Man " buffer-file-name))
8592 (buffer (generate-new-buffer bufname)))
8593 (with-current-buffer buffer
8594 (let ((process-environment (copy-sequence process-environment)))
8595 ;; Prevent any attempt to use display terminal fanciness.
8596 (setenv "TERM" "dumb")
8597 (set-process-sentinel
8598 (start-process pod2man-program buffer "sh" "-c"
8599 (format (cperl-pod2man-build-command) pod2man-args))
8600 'Man-bgproc-sentinel)))))
8602 ;;; Updated version by him too
8603 (defun cperl-build-manpage ()
8604 "Create a virtual manpage in Emacs from the POD in the file."
8605 (interactive)
8606 (require 'man)
8607 (cond
8608 ((featurep 'xemacs)
8609 (let ((Manual-program "perldoc"))
8610 (manual-entry buffer-file-name)))
8612 (let* ((manual-program "perldoc")
8613 (Man-switches ""))
8614 (Man-getpage-in-background buffer-file-name)))))
8616 (defun cperl-pod2man-build-command ()
8617 "Builds the entire background manpage and cleaning command."
8618 (let ((command (concat pod2man-program " %s 2>/dev/null"))
8619 (flist (and (boundp 'Man-filter-list) Man-filter-list)))
8620 (while (and flist (car flist))
8621 (let ((pcom (car (car flist)))
8622 (pargs (cdr (car flist))))
8623 (setq command
8624 (concat command " | " pcom " "
8625 (mapconcat (lambda (phrase)
8626 (if (not (stringp phrase))
8627 (error "Malformed Man-filter-list"))
8628 phrase)
8629 pargs " ")))
8630 (setq flist (cdr flist))))
8631 command))
8634 (defun cperl-next-interpolated-REx-1 ()
8635 "Move point to next REx which has interpolated parts without //o.
8636 Skips RExes consisting of one interpolated variable.
8638 Note that skipped RExen are not performance hits."
8639 (interactive "")
8640 (cperl-next-interpolated-REx 1))
8642 (defun cperl-next-interpolated-REx-0 ()
8643 "Move point to next REx which has interpolated parts without //o."
8644 (interactive "")
8645 (cperl-next-interpolated-REx 0))
8647 (defun cperl-next-interpolated-REx (&optional skip beg limit)
8648 "Move point to next REx which has interpolated parts.
8649 SKIP is a list of possible types to skip, BEG and LIMIT are the starting
8650 point and the limit of search (default to point and end of buffer).
8652 SKIP may be a number, then it behaves as list of numbers up to SKIP; this
8653 semantic may be used as a numeric argument.
8655 Types are 0 for / $rex /o (interpolated once), 1 for /$rex/ (if $rex is
8656 a result of qr//, this is not a performance hit), t for the rest."
8657 (interactive "P")
8658 (if (numberp skip) (setq skip (list 0 skip)))
8659 (or beg (setq beg (point)))
8660 (or limit (setq limit (point-max))) ; needed for n-s-p-c
8661 (let (pp)
8662 (and (eq (get-text-property beg 'syntax-type) 'string)
8663 (setq beg (next-single-property-change beg 'syntax-type nil limit)))
8664 (cperl-map-pods-heres
8665 (function (lambda (s e p)
8666 (if (memq (get-text-property s 'REx-interpolated) skip)
8668 (setq pp s)
8669 nil))) ; nil stops
8670 'REx-interpolated beg limit)
8671 (if pp (goto-char pp)
8672 (message "No more interpolated REx"))))
8674 ;;; Initial version contributed by Trey Belew
8675 (defun cperl-here-doc-spell (&optional beg end)
8676 "Spell-check HERE-documents in the Perl buffer.
8677 If a region is highlighted, restricts to the region."
8678 (interactive "")
8679 (cperl-pod-spell t beg end))
8681 (defun cperl-pod-spell (&optional do-heres beg end)
8682 "Spell-check POD documentation.
8683 If invoked with prefix argument, will do HERE-DOCs instead.
8684 If a region is highlighted, restricts to the region."
8685 (interactive "P")
8686 (save-excursion
8687 (let (beg end)
8688 (if (cperl-mark-active)
8689 (setq beg (min (mark) (point))
8690 end (max (mark) (point)))
8691 (setq beg (point-min)
8692 end (point-max)))
8693 (cperl-map-pods-heres (function
8694 (lambda (s e p)
8695 (if do-heres
8696 (setq e (save-excursion
8697 (goto-char e)
8698 (forward-line -1)
8699 (point))))
8700 (ispell-region s e)
8702 (if do-heres 'here-doc-group 'in-pod)
8703 beg end))))
8705 (defun cperl-map-pods-heres (func &optional prop s end)
8706 "Executes a function over regions of pods or here-documents.
8707 PROP is the text-property to search for; default to `in-pod'. Stop when
8708 function returns nil."
8709 (let (pos posend has-prop (cont t))
8710 (or prop (setq prop 'in-pod))
8711 (or s (setq s (point-min)))
8712 (or end (setq end (point-max)))
8713 (cperl-update-syntaxification end end)
8714 (save-excursion
8715 (goto-char (setq pos s))
8716 (while (and cont (< pos end))
8717 (setq has-prop (get-text-property pos prop))
8718 (setq posend (next-single-property-change pos prop nil end))
8719 (and has-prop
8720 (setq cont (funcall func pos posend prop)))
8721 (setq pos posend)))))
8723 ;;; Based on code by Masatake YAMATO:
8724 (defun cperl-get-here-doc-region (&optional pos pod)
8725 "Return HERE document region around the point.
8726 Return nil if the point is not in a HERE document region. If POD is non-nil,
8727 will return a POD section if point is in a POD section."
8728 (or pos (setq pos (point)))
8729 (cperl-update-syntaxification pos pos)
8730 (if (or (eq 'here-doc (get-text-property pos 'syntax-type))
8731 (and pod
8732 (eq 'pod (get-text-property pos 'syntax-type))))
8733 (let ((b (cperl-beginning-of-property pos 'syntax-type))
8734 (e (next-single-property-change pos 'syntax-type)))
8735 (cons b (or e (point-max))))))
8737 (defun cperl-narrow-to-here-doc (&optional pos)
8738 "Narrows editing region to the HERE-DOC at POS.
8739 POS defaults to the point."
8740 (interactive "d")
8741 (or pos (setq pos (point)))
8742 (let ((p (cperl-get-here-doc-region pos)))
8743 (or p (error "Not inside a HERE document"))
8744 (narrow-to-region (car p) (cdr p))
8745 (message
8746 "When you are finished with narrow editing, type C-x n w")))
8748 (defun cperl-select-this-pod-or-here-doc (&optional pos)
8749 "Select the HERE-DOC (or POD section) at POS.
8750 POS defaults to the point."
8751 (interactive "d")
8752 (let ((p (cperl-get-here-doc-region pos t)))
8753 (if p
8754 (progn
8755 (goto-char (car p))
8756 (push-mark (cdr p) nil t)) ; Message, activate in transient-mode
8757 (message "I do not think POS is in POD or a HERE-doc..."))))
8759 (defun cperl-facemenu-add-face-function (face end)
8760 "A callback to process user-initiated font-change requests.
8761 Translates `bold', `italic', and `bold-italic' requests to insertion of
8762 corresponding POD directives, and `underline' to C<> POD directive.
8764 Such requests are usually bound to M-o LETTER."
8765 (or (get-text-property (point) 'in-pod)
8766 (error "Faces can only be set within POD"))
8767 (setq facemenu-end-add-face (if (eq face 'bold-italic) ">>" ">"))
8768 (cdr (or (assq face '((bold . "B<")
8769 (italic . "I<")
8770 (bold-italic . "B<I<")
8771 (underline . "C<")))
8772 (error "Face %s not configured for cperl-mode"
8773 face))))
8775 (defun cperl-time-fontification (&optional l step lim)
8776 "Times how long it takes to do incremental fontification in a region.
8777 L is the line to start at, STEP is the number of lines to skip when
8778 doing next incremental fontification, LIM is the maximal number of
8779 incremental fontification to perform. Messages are accumulated in
8780 *Messages* buffer.
8782 May be used for pinpointing which construct slows down buffer fontification:
8783 start with default arguments, then refine the slowdown regions."
8784 (interactive "nLine to start at: \nnStep to do incremental fontification: ")
8785 (or l (setq l 1))
8786 (or step (setq step 500))
8787 (or lim (setq lim 40))
8788 (let* ((timems (function (lambda ()
8789 (let ((tt (current-time)))
8790 (+ (* 1000 (nth 1 tt)) (/ (nth 2 tt) 1000))))))
8791 (tt (funcall timems)) (c 0) delta tot)
8792 (goto-char (point-min))
8793 (forward-line (1- l))
8794 (cperl-mode)
8795 (setq tot (- (- tt (setq tt (funcall timems)))))
8796 (message "cperl-mode at %s: %s" l tot)
8797 (while (and (< c lim) (not (eobp)))
8798 (forward-line step)
8799 (setq l (+ l step))
8800 (setq c (1+ c))
8801 (cperl-update-syntaxification (point) (point))
8802 (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
8803 (message "to %s:%6s,%7s" l delta tot))
8804 tot))
8806 (defvar font-lock-cache-position)
8808 (defun cperl-emulate-lazy-lock (&optional window-size)
8809 "Emulate `lazy-lock' without `condition-case', so `debug-on-error' works.
8810 Start fontifying the buffer from the start (or end) using the given
8811 WINDOW-SIZE (units is lines). Negative WINDOW-SIZE starts at end, and
8812 goes backwards; default is -50. This function is not CPerl-specific; it
8813 may be used to debug problems with delayed incremental fontification."
8814 (interactive
8815 "nSize of window for incremental fontification, negative goes backwards: ")
8816 (or window-size (setq window-size -50))
8817 (let ((pos (if (> window-size 0)
8818 (point-min)
8819 (point-max)))
8821 (goto-char pos)
8822 (normal-mode)
8823 ;; Why needed??? With older font-locks???
8824 (set (make-local-variable 'font-lock-cache-position) (make-marker))
8825 (while (if (> window-size 0)
8826 (< pos (point-max))
8827 (> pos (point-min)))
8828 (setq p (progn
8829 (forward-line window-size)
8830 (point)))
8831 (font-lock-fontify-region (min p pos) (max p pos))
8832 (setq pos p))))
8835 (defun cperl-lazy-install ()) ; Avoid a warning
8836 (defun cperl-lazy-unstall ()) ; Avoid a warning
8838 (if (fboundp 'run-with-idle-timer)
8839 (progn
8840 (defvar cperl-help-shown nil
8841 "Non-nil means that the help was already shown now.")
8843 (defvar cperl-lazy-installed nil
8844 "Non-nil means that the lazy-help handlers are installed now.")
8846 (defun cperl-lazy-install ()
8847 "Switches on Auto-Help on Perl constructs (put in the message area).
8848 Delay of auto-help controlled by `cperl-lazy-help-time'."
8849 (interactive)
8850 (make-local-variable 'cperl-help-shown)
8851 (if (and (cperl-val 'cperl-lazy-help-time)
8852 (not cperl-lazy-installed))
8853 (progn
8854 (add-hook 'post-command-hook 'cperl-lazy-hook)
8855 (run-with-idle-timer
8856 (cperl-val 'cperl-lazy-help-time 1000000 5)
8858 'cperl-get-help-defer)
8859 (setq cperl-lazy-installed t))))
8861 (defun cperl-lazy-unstall ()
8862 "Switches off Auto-Help on Perl constructs (put in the message area).
8863 Delay of auto-help controlled by `cperl-lazy-help-time'."
8864 (interactive)
8865 (remove-hook 'post-command-hook 'cperl-lazy-hook)
8866 (cancel-function-timers 'cperl-get-help-defer)
8867 (setq cperl-lazy-installed nil))
8869 (defun cperl-lazy-hook ()
8870 (setq cperl-help-shown nil))
8872 (defun cperl-get-help-defer ()
8873 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
8874 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
8875 (cperl-get-help)
8876 (setq cperl-help-shown t))))
8877 (cperl-lazy-install)))
8880 ;;; Plug for wrong font-lock:
8882 (defun cperl-font-lock-unfontify-region-function (beg end)
8883 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
8884 (inhibit-read-only t) (inhibit-point-motion-hooks t)
8885 before-change-functions after-change-functions
8886 deactivate-mark buffer-file-name buffer-file-truename)
8887 (remove-text-properties beg end '(face nil))
8888 (if (and (not modified) (buffer-modified-p))
8889 (set-buffer-modified-p nil))))
8891 (defun cperl-font-lock-fontify-region-function (beg end loudly)
8892 "Extends the region to safe positions, then calls the default function.
8893 Newer `font-lock's can do it themselves.
8894 We unwind only as far as needed for fontification. Syntaxification may
8895 do extra unwind via `cperl-unwind-to-safe'."
8896 (save-excursion
8897 (goto-char beg)
8898 (while (and beg
8899 (progn
8900 (beginning-of-line)
8901 (eq (get-text-property (setq beg (point)) 'syntax-type)
8902 'multiline)))
8903 (let ((new-beg (cperl-beginning-of-property beg 'syntax-type)))
8904 (setq beg (if (= new-beg beg) nil new-beg))
8905 (goto-char new-beg)))
8906 (setq beg (point))
8907 (goto-char end)
8908 (while (and end
8909 (progn
8910 (or (bolp) (condition-case nil
8911 (forward-line 1)
8912 (error nil)))
8913 (eq (get-text-property (setq end (point)) 'syntax-type)
8914 'multiline)))
8915 (setq end (next-single-property-change end 'syntax-type nil (point-max)))
8916 (goto-char end))
8917 (setq end (point)))
8918 (font-lock-default-fontify-region beg end loudly))
8920 (defvar cperl-d-l nil)
8921 (defun cperl-fontify-syntaxically (end)
8922 ;; Some vars for debugging only
8923 ;; (message "Syntaxifying...")
8924 (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
8925 (istate (car cperl-syntax-state))
8926 start from-start edebug-backtrace-buffer)
8927 (if (eq cperl-syntaxify-by-font-lock 'backtrace)
8928 (progn
8929 (require 'edebug)
8930 (let ((f 'edebug-backtrace))
8931 (funcall f)))) ; Avoid compile-time warning
8932 (or cperl-syntax-done-to
8933 (setq cperl-syntax-done-to (point-min)
8934 from-start t))
8935 (setq start (if (and cperl-hook-after-change
8936 (not from-start))
8937 cperl-syntax-done-to ; Fontify without change; ignore start
8938 ;; Need to forget what is after `start'
8939 (min cperl-syntax-done-to (point))))
8940 (goto-char start)
8941 (beginning-of-line)
8942 (setq start (point))
8943 (and cperl-syntaxify-unwind
8944 (setq end (cperl-unwind-to-safe t end)
8945 start (point)))
8946 (and (> end start)
8947 (setq cperl-syntax-done-to start) ; In case what follows fails
8948 (cperl-find-pods-heres start end t nil t))
8949 (if (memq cperl-syntaxify-by-font-lock '(backtrace message))
8950 (message "Syxify req=%s..%s actual=%s..%s done-to: %s=>%s statepos: %s=>%s"
8951 dbg iend start end idone cperl-syntax-done-to
8952 istate (car cperl-syntax-state))) ; For debugging
8953 nil)) ; Do not iterate
8955 (defun cperl-fontify-update (end)
8956 (let ((pos (point-min)) prop posend)
8957 (setq end (point-max))
8958 (while (< pos end)
8959 (setq prop (get-text-property pos 'cperl-postpone)
8960 posend (next-single-property-change pos 'cperl-postpone nil end))
8961 (and prop (put-text-property pos posend (car prop) (cdr prop)))
8962 (setq pos posend)))
8963 nil) ; Do not iterate
8965 (defun cperl-fontify-update-bad (end)
8966 ;; Since fontification happens with different region than syntaxification,
8967 ;; do to the end of buffer, not to END;;; likewise, start earlier if needed
8968 (let* ((pos (point)) (prop (get-text-property pos 'cperl-postpone)) posend)
8969 (if prop
8970 (setq pos (or (cperl-beginning-of-property
8971 (cperl-1+ pos) 'cperl-postpone)
8972 (point-min))))
8973 (while (< pos end)
8974 (setq posend (next-single-property-change pos 'cperl-postpone))
8975 (and prop (put-text-property pos posend (car prop) (cdr prop)))
8976 (setq pos posend)
8977 (setq prop (get-text-property pos 'cperl-postpone))))
8978 nil) ; Do not iterate
8980 ;; Called when any modification is made to buffer text.
8981 (defun cperl-after-change-function (beg end old-len)
8982 ;; We should have been informed about changes by `font-lock'. Since it
8983 ;; does not inform as which calls are deferred, do it ourselves
8984 (if cperl-syntax-done-to
8985 (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
8987 (defun cperl-update-syntaxification (from to)
8988 (cond
8989 ((not cperl-use-syntax-table-text-property) nil)
8990 ((fboundp 'syntax-propertize) (syntax-propertize to))
8991 ((and cperl-syntaxify-by-font-lock
8992 (or (null cperl-syntax-done-to)
8993 (< cperl-syntax-done-to to)))
8994 (save-excursion
8995 (goto-char from)
8996 (cperl-fontify-syntaxically to)))))
8998 (defvar cperl-version
8999 (let ((v "Revision: 6.2"))
9000 (string-match ":\\s *\\([0-9.]+\\)" v)
9001 (substring v (match-beginning 1) (match-end 1)))
9002 "Version of IZ-supported CPerl package this file is based on.")
9004 (provide 'cperl-mode)
9006 ;;; cperl-mode.el ends here