1 ;;; cperl-mode.el --- Perl code editing commands for Emacs
3 ;; Copyright (C) 1985, 86, 87, 91, 92, 93, 94, 95, 96, 1997
4 ;; Free Software Foundation, Inc.
6 ;; Author: Ilya Zakharevich and Bob Olson
7 ;; Maintainer: Ilya Zakharevich <ilya@math.ohio-state.edu>
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 2, or (at your option)
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; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Corrections made by Ilya Zakharevich ilya@math.mps.ohio-state.edu
31 ;;; You can either fine-tune the bells and whistles of this mode or
32 ;;; bulk enable them by putting
34 ;; (setq cperl-hairy t)
36 ;;; in your .emacs file. (Emacs rulers do not consider it politically
37 ;;; correct to make whistles enabled by default.)
39 ;;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
40 ;;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
41 ;;; `cperl-non-problems', `cperl-praise', `cperl-speed'. <<<<<<
43 ;;; The mode information (on C-h m) provides some customization help.
44 ;;; If you use font-lock feature of this mode, it is advisable to use
45 ;;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
47 ;;; Faces used now: three faces for first-class and second-class keywords
48 ;;; and control flow words, one for each: comments, string, labels,
49 ;;; functions definitions and packages, arrays, hashes, and variable
50 ;;; definitions. If you do not see all these faces, your font-lock does
51 ;;; not define them, so you need to define them manually.
53 ;;; into your .emacs file.
55 ;;;; This mode supports font-lock, imenu and mode-compile. In the
56 ;;;; hairy version font-lock is on, but you should activate imenu
57 ;;;; yourself (note that mode-compile is not standard yet). Well, you
58 ;;;; can use imenu from keyboard anyway (M-x imenu), but it is better
59 ;;;; to bind it like that:
61 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
65 ;; Some macros are needed for `defcustom'
68 (defvar msb-menu-cond)
69 (defvar gud-perldb-history)
70 (defvar font-lock-background-mode) ; not in Emacs
71 (defvar font-lock-display-type) ; ditto
72 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
73 (defmacro cperl-is-face (arg) ; Takes quoted arg
74 (cond ((fboundp 'find-face)
76 (;;(and (fboundp 'face-list)
79 `(member ,arg (and (fboundp 'face-list)
83 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
84 (cond ((fboundp 'make-face)
85 `(make-face (quote ,arg)))
87 `(defconst ,arg (quote ,arg) ,descr))))
88 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
90 (or (cperl-is-face (quote ,arg))
91 (cperl-make-face ,arg ,descr))
92 (or (boundp (quote ,arg)) ; We use unquoted variants too
93 (defconst ,arg (quote ,arg) ,descr))))
95 (defmacro cperl-etags-snarf-tag (file line)
99 (defmacro cperl-etags-snarf-tag (file line)
102 (defmacro cperl-etags-goto-tag-location (elt)
104 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
105 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
106 ;; Probably will not work due to some save-excursion???
107 ;; Or save-file-position?
108 ;; (message "Did I get to line %s?" (elt (, elt) 1))
109 `(goto-line (string-to-int (elt ,elt 1))))
111 (defmacro cperl-etags-goto-tag-location (elt)
112 `(etags-goto-tag-location ,elt)))
113 (autoload 'tmm-prompt "tmm"))
115 (defun cperl-choose-color (&rest list)
119 (if (or (x-color-defined-p (car list))
121 (setq answer (car list))))
122 (setq list (cdr list)))
126 "Major mode for editing Perl code."
131 (defgroup cperl-indentation-details nil
136 (defgroup cperl-affected-by-hairy nil
137 "Variables affected by `cperl-hairy'."
141 (defgroup cperl-autoinsert-details nil
142 "Auto-insert tuneup."
146 (defgroup cperl-faces nil
147 "Fontification colors."
151 (defgroup cperl-speed nil
152 "Speed vs. validity tuneup."
156 (defgroup cperl-help-system nil
157 "Help system tuneup."
162 (defcustom cperl-extra-newline-before-brace nil
163 "*Non-nil means that if, elsif, while, until, else, for, foreach
164 and do constructs look like:
176 :group 'cperl-autoinsert-details)
178 (defcustom cperl-extra-newline-before-brace-multiline
179 cperl-extra-newline-before-brace
180 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
181 for constructs with multiline if/unless/while/until/for/foreach condition."
183 :group 'cperl-autoinsert-details)
185 (defcustom cperl-indent-level 2
186 "*Indentation of CPerl statements with respect to containing block."
188 :group 'cperl-indentation-details)
190 (defcustom cperl-lineup-step nil
191 "*`cperl-lineup' will always lineup at multiple of this number.
192 If nil, the value of `cperl-indent-level' will be used."
193 :type '(choice (const nil) integer)
194 :group 'cperl-indentation-details)
196 (defcustom cperl-brace-imaginary-offset 0
197 "*Imagined indentation of a Perl open brace that actually follows a statement.
198 An open brace following other text is treated as if it were this far
199 to the right of the start of its line."
201 :group 'cperl-indentation-details)
203 (defcustom cperl-brace-offset 0
204 "*Extra indentation for braces, compared with other text in same context."
206 :group 'cperl-indentation-details)
207 (defcustom cperl-label-offset -2
208 "*Offset of CPerl label lines relative to usual indentation."
210 :group 'cperl-indentation-details)
211 (defcustom cperl-min-label-indent 1
212 "*Minimal offset of CPerl label lines."
214 :group 'cperl-indentation-details)
215 (defcustom cperl-continued-statement-offset 2
216 "*Extra indent for lines not starting new statements."
218 :group 'cperl-indentation-details)
219 (defcustom cperl-continued-brace-offset 0
220 "*Extra indent for substatements that start with open-braces.
221 This is in addition to cperl-continued-statement-offset."
223 :group 'cperl-indentation-details)
224 (defcustom cperl-close-paren-offset -1
225 "*Extra indent for substatements that start with close-parenthesis."
227 :group 'cperl-indentation-details)
229 (defcustom cperl-auto-newline nil
230 "*Non-nil means automatically newline before and after braces,
231 and after colons and semicolons, inserted in CPerl code. The following
232 \\[cperl-electric-backspace] will remove the inserted whitespace.
233 Insertion after colons requires both this variable and
234 `cperl-auto-newline-after-colon' set."
236 :group 'cperl-autoinsert-details)
238 (defcustom cperl-autoindent-on-semi nil
239 "*Non-nil means automatically indent after insertion of (semi)colon.
240 Active if `cperl-auto-newline' is false."
242 :group 'cperl-autoinsert-details)
244 (defcustom cperl-auto-newline-after-colon nil
245 "*Non-nil means automatically newline even after colons.
246 Subject to `cperl-auto-newline' setting."
248 :group 'cperl-autoinsert-details)
250 (defcustom cperl-tab-always-indent t
251 "*Non-nil means TAB in CPerl mode should always reindent the current line,
252 regardless of where in the line point is when the TAB command is used."
254 :group 'cperl-indentation-details)
256 (defcustom cperl-font-lock nil
257 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
258 Can be overwritten by `cperl-hairy' if nil."
259 :type '(choice (const null) boolean)
260 :group 'cperl-affected-by-hairy)
262 (defcustom cperl-electric-lbrace-space nil
263 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
264 Can be overwritten by `cperl-hairy' if nil."
265 :type '(choice (const null) boolean)
266 :group 'cperl-affected-by-hairy)
268 (defcustom cperl-electric-parens-string "({[]})<"
269 "*String of parentheses that should be electric in CPerl.
270 Closing ones are electric only if the region is highlighted."
272 :group 'cperl-affected-by-hairy)
274 (defcustom cperl-electric-parens nil
275 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
276 Can be overwritten by `cperl-hairy' if nil."
277 :type '(choice (const null) boolean)
278 :group 'cperl-affected-by-hairy)
280 (defvar zmacs-regions) ; Avoid warning
282 (defcustom cperl-electric-parens-mark
284 (or (and (boundp 'transient-mark-mode) ; For Emacs
286 (and (boundp 'zmacs-regions) ; For XEmacs
288 "*Not-nil means that electric parens look for active mark.
289 Default is yes if there is visual feedback on mark."
291 :group 'cperl-autoinsert-details)
293 (defcustom cperl-electric-linefeed nil
294 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
295 In any case these two mean plain and hairy linefeeds together.
296 Can be overwritten by `cperl-hairy' if nil."
297 :type '(choice (const null) boolean)
298 :group 'cperl-affected-by-hairy)
300 (defcustom cperl-electric-keywords nil
301 "*Not-nil (and non-null) means keywords are electric in CPerl.
302 Can be overwritten by `cperl-hairy' if nil."
303 :type '(choice (const null) boolean)
304 :group 'cperl-affected-by-hairy)
306 (defcustom cperl-hairy nil
307 "*Not-nil means most of the bells and whistles are enabled in CPerl.
308 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
309 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
310 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
311 `cperl-lazy-help-time'."
313 :group 'cperl-affected-by-hairy)
315 (defcustom cperl-comment-column 32
316 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
318 :group 'cperl-indentation-details)
320 (defcustom cperl-vc-header-alist '((SCCS "$sccs = '%W\%' ;")
321 (RCS "$rcs = ' $Id\$ ' ;"))
322 "*What to use as `vc-header-alist' in CPerl."
323 :type '(repeat (list symbol string))
326 (defcustom cperl-clobber-mode-lists
329 (boundp 'interpreter-mode-alist)
330 (assoc "miniperl" interpreter-mode-alist)
331 (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
332 "*Whether to install us into `interpreter-' and `extension' mode lists."
336 (defcustom cperl-info-on-command-no-prompt nil
337 "*Not-nil (and non-null) means not to prompt on C-h f.
338 The opposite behaviour is always available if prefixed with C-c.
339 Can be overwritten by `cperl-hairy' if nil."
340 :type '(choice (const null) boolean)
341 :group 'cperl-affected-by-hairy)
343 (defcustom cperl-clobber-lisp-bindings nil
344 "*Not-nil (and non-null) means not overwrite C-h f.
345 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
346 Can be overwritten by `cperl-hairy' if nil."
347 :type '(choice (const null) boolean)
348 :group 'cperl-affected-by-hairy)
350 (defcustom cperl-lazy-help-time nil
351 "*Not-nil (and non-null) means to show lazy help after given idle time.
352 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
353 :type '(choice (const null) (const nil) integer)
354 :group 'cperl-affected-by-hairy)
356 (defcustom cperl-pod-face 'font-lock-comment-face
357 "*Face for pod highlighting."
361 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
362 "*Face for pod highlighting.
363 Font for POD headers."
367 (defcustom cperl-here-face 'font-lock-string-face
368 "*Face for here-docs highlighting."
372 (defcustom cperl-invalid-face 'underline
373 "*Face for highlighting trailing whitespace."
378 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
379 "*Not-nil after evaluation means to highlight pod and here-docs sections."
383 (defcustom cperl-fontify-m-as-s t
384 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
388 (defcustom cperl-highlight-variables-indiscriminately nil
389 "*Non-nil means perform additional highlighting on variables.
390 Currently only changes how scalar variables are highlighted.
391 Note that that variable is only read at initialization time for
392 the variable `cperl-font-lock-keywords-2', so changing it after you've
393 entered `cperl-mode' the first time will have no effect."
397 (defcustom cperl-pod-here-scan t
398 "*Not-nil means look for pod and here-docs sections during startup.
399 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
403 (defcustom cperl-regexp-scan t
404 "*Not-nil means make marking of regular expression more thorough.
405 Effective only with `cperl-pod-here-scan'. Not implemented yet."
409 (defcustom cperl-imenu-addback nil
410 "*Not-nil means add backreferences to generated `imenu's.
411 May require patched `imenu' and `imenu-go'. Obsolete."
413 :group 'cperl-help-system)
415 (defcustom cperl-max-help-size 66
416 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
417 :type '(choice integer (const nil))
418 :group 'cperl-help-system)
420 (defcustom cperl-shrink-wrap-info-frame t
421 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
423 :group 'cperl-help-system)
425 (defcustom cperl-info-page "perl"
426 "*Name of the info page containing perl docs.
427 Older version of this page was called `perl5', newer `perl'."
429 :group 'cperl-help-system)
431 (defcustom cperl-use-syntax-table-text-property
432 (boundp 'parse-sexp-lookup-properties)
433 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
437 (defcustom cperl-use-syntax-table-text-property-for-tags
438 cperl-use-syntax-table-text-property
439 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
443 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
444 "*Regexp to match files to scan when generating TAGS."
448 (defcustom cperl-noscan-files-regexp "/\\(\\.\\.?\\|SCCS\\|RCS\\|blib\\)$"
449 "*Regexp to match files/dirs to skip when generating TAGS."
453 (defcustom cperl-regexp-indent-step nil
454 "*Indentation used when beautifying regexps.
455 If nil, the value of `cperl-indent-level' will be used."
456 :type '(choice integer (const nil))
457 :group 'cperl-indentation-details)
459 (defcustom cperl-indent-left-aligned-comments t
460 "*Non-nil means that the comment starting in leftmost column should indent."
462 :group 'cperl-indentation-details)
464 (defcustom cperl-under-as-char nil
465 "*Non-nil means that the _ (underline) should be treated as word char."
469 (defcustom cperl-extra-perl-args ""
470 "*Extra arguments to use when starting Perl.
471 Currently used with `cperl-check-syntax' only."
475 (defcustom cperl-message-electric-keyword t
476 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
478 :group 'cperl-help-system)
480 (defcustom cperl-indent-region-fix-constructs 1
481 "*Amount of space to insert between `}' and `else' or `elsif'
482 in `cperl-indent-region'. Set to nil to leave as is. Values other
483 than 1 and nil will probably not work."
484 :type '(choice (const nil) (const 1))
485 :group 'cperl-indentation-details)
487 (defcustom cperl-break-one-line-blocks-when-indent t
488 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
489 need to be reformated into multiline ones when indenting a region."
491 :group 'cperl-indentation-details)
493 (defcustom cperl-fix-hanging-brace-when-indent t
494 "*Non-nil means that BLOCK-end `}' may be put on a separate line
495 when indenting a region.
496 Braces followed by else/elsif/while/until are excepted."
498 :group 'cperl-indentation-details)
500 (defcustom cperl-merge-trailing-else t
501 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
502 may be merged to be on the same line when indenting a region."
504 :group 'cperl-indentation-details)
506 (defcustom cperl-indent-parens-as-block nil
507 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
508 but for trailing \",\" inside the group, which won't increase indentation.
509 One should tune up `cperl-close-paren-offset' as well."
511 :group 'cperl-indentation-details)
513 (defcustom cperl-syntaxify-by-font-lock
515 (boundp 'parse-sexp-lookup-properties))
516 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
517 :type '(choice (const message) boolean)
520 (defcustom cperl-syntaxify-unwind
522 "*Non-nil means that CPerl unwinds to a start of along construction
523 when syntaxifying a chunk of buffer."
527 (defcustom cperl-ps-print-face-properties
528 '((font-lock-keyword-face nil nil bold shadow)
529 (font-lock-variable-name-face nil nil bold)
530 (font-lock-function-name-face nil nil bold italic box)
531 (font-lock-constant-face nil "LightGray" bold)
532 (cperl-array-face nil "LightGray" bold underline)
533 (cperl-hash-face nil "LightGray" bold italic underline)
534 (font-lock-comment-face nil "LightGray" italic)
535 (font-lock-string-face nil nil italic underline)
536 (cperl-nonoverridable-face nil nil italic underline)
537 (font-lock-type-face nil nil underline)
538 (underline nil "LightGray" strikeout))
539 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
540 :type '(repeat (cons symbol
541 (cons (choice (const nil) string)
542 (cons (choice (const nil) string)
548 (defvar cperl-dark-background
549 (cperl-choose-color "navy" "os2blue" "darkgreen"))
550 (defvar cperl-dark-foreground
551 (cperl-choose-color "orchid1" "orange"))
553 (defface cperl-nonoverridable-face
554 `((((class grayscale) (background light))
555 (:background "Gray90" :italic t :underline t))
556 (((class grayscale) (background dark))
557 (:foreground "Gray80" :italic t :underline t :bold t))
558 (((class color) (background light))
559 (:foreground "chartreuse3"))
560 (((class color) (background dark))
561 (:foreground ,cperl-dark-foreground))
562 (t (:bold t :underline t)))
563 "Font Lock mode face used to highlight array names."
566 (defface cperl-array-face
567 `((((class grayscale) (background light))
568 (:background "Gray90" :bold t))
569 (((class grayscale) (background dark))
570 (:foreground "Gray80" :bold t))
571 (((class color) (background light))
572 (:foreground "Blue" :background "lightyellow2" :bold t))
573 (((class color) (background dark))
574 (:foreground "yellow" :background ,cperl-dark-background :bold t))
576 "Font Lock mode face used to highlight array names."
579 (defface cperl-hash-face
580 `((((class grayscale) (background light))
581 (:background "Gray90" :bold t :italic t))
582 (((class grayscale) (background dark))
583 (:foreground "Gray80" :bold t :italic t))
584 (((class color) (background light))
585 (:foreground "Red" :background "lightyellow2" :bold t :italic t))
586 (((class color) (background dark))
587 (:foreground "Red" :background ,cperl-dark-background :bold t :italic t))
588 (t (:bold t :italic t)))
589 "Font Lock mode face used to highlight hash names."
590 :group 'cperl-faces)))
594 ;;; Short extra-docs.
596 (defvar cperl-tips 'please-ignore-this-line
597 "Get newest version of this package from
598 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs
600 ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
601 Subdirectory `cperl-mode' may contain yet newer development releases and/or
602 patches to related files.
604 For best results apply to an older Emacs the patches from
605 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
606 \(this upgrades syntax-parsing abilities of Emaxen v19.34 and
607 v20.2 up to the level of Emacs v20.3 - a must for a good Perl
610 Get support packages choose-color.el (or font-lock-extra.el before
611 19.30), imenu-go.el from the same place. \(Look for other files there
612 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
613 later you should use choose-color.el *instead* of font-lock-extra.el
614 \(and you will not get smart highlighting in C :-().
616 Note that to enable Compile choices in the menu you need to install
619 If your Emacs does not default to `cperl-mode' on Perl files, and you
620 want it to: put the following into your .emacs file:
622 (defalias 'perl-mode 'cperl-mode)
625 $CPAN/doc/manual/info/perl-info.tar.gz
627 http://www.metronet.com:70/9/perlinfo/perl5/manual/perl5-info.tar.gz
629 If you use imenu-go, run imenu on perl5-info buffer (you can do it
630 from Perl menu). If many files are related, generate TAGS files from
631 Tools/Tags submenu in Perl menu.
633 If some class structure is too complicated, use Tools/Hierarchy-view
634 from Perl menu, or hierarchic view of imenu. The second one uses the
635 current buffer only, the first one requires generation of TAGS from
636 Perl/Tools/Tags menu beforehand.
638 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
640 Switch auto-help on/off with Perl/Tools/Auto-help.
642 Though with contemporary Emaxen CPerl mode should maintain the correct
643 parsing of Perl even when editing, sometimes it may be lost. Fix this by
647 In cases of more severe confusion sometimes it is helpful to do
649 \\[load-library] cperl-mode RET
652 Before reporting (non-)problems look in the problem section of online
653 micro-docs on what I know about CPerl problems.")
655 (defvar cperl-problems 'please-ignore-this-line
656 "Some faces will not be shown on some versions of Emacs unless you
657 install choose-color.el, available from
658 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs/
660 `fill-paragraph' on a comment may leave the point behind the
661 paragraph. Parsing of lines with several <<EOF is not implemented
664 Emacs had a _very_ restricted syntax parsing engine until version
665 20.1. Most problems below are corrected starting from this version of
666 Emacs, and all of them should be fixed in version 20.3. (Or apply
667 patches to Emacs 19.33/34 - see tips.)
669 Note that even with newer Emacsen in some very rare cases the details
670 of interaction of `font-lock' and syntaxification may be not cleaned
671 up yet. You may get slightly different colors basing on the order of
672 fontification and syntaxification. Say, the initial faces is correct,
673 but editing the buffer breaks this.
675 Even with older Emacsen CPerl mode tries to corrects some Emacs
676 misunderstandings, however, for efficiency reasons the degree of
677 correction is different for different operations. The partially
678 corrected problems are: POD sections, here-documents, regexps. The
679 operations are: highlighting, indentation, electric keywords, electric
682 This may be confusing, since the regexp s#//#/#\; may be highlighted
683 as a comment, but it will be recognized as a regexp by the indentation
684 code. Or the opposite case, when a pod section is highlighted, but
685 may break the indentation of the following code (though indentation
686 should work if the balance of delimiters is not broken by POD).
688 The main trick (to make $ a \"backslash\") makes constructions like
689 ${aaa} look like unbalanced braces. The only trick I can think of is
690 to insert it as $ {aaa} (legal in perl5, not in perl4).
692 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
693 as /($|\\s)/. Note that such a transposition is not always possible.
695 The solution is to upgrade your Emacs or patch an older one. Note
696 that Emacs 20.2 has some bugs related to `syntax-table' text
697 properties. Patches are available on the main CPerl download site,
700 If these bugs cannot be fixed on your machine (say, you have an inferior
701 environment and cannot recompile), you may still disable all the fancy stuff
702 via `cperl-use-syntax-table-text-property'." )
704 (defvar cperl-non-problems 'please-ignore-this-line
705 "As you know from `problems' section, Perl syntax is too hard for CPerl on
706 older Emacsen. Here is what you can do if you cannot upgrade, or if
707 you want to switch off these capabilities on Emacs 20.2 (+patches) or 20.3
708 or better. Please skip this docs if you run a capable Emacs already.
710 Most of the time, if you write your own code, you may find an equivalent
711 \(and almost as readable) expression (what is discussed below is usually
712 not relevant on newer Emacsen, since they can do it automatically).
714 Try to help CPerl: add comments with embedded quotes to fix CPerl
715 misunderstandings about the end of quotation:
719 You won't need it too often. The reason: $ \"quotes\" the following
720 character (this saves a life a lot of times in CPerl), thus due to
721 Emacs parsing rules it does not consider tick (i.e., ' ) after a
722 dollar as a closing one, but as a usual character. This is usually
723 correct, but not in the above context.
725 Even with older Emacsen the indentation code is pretty wise. The only
726 drawback is that it relied on Emacs parsing to find matching
727 parentheses. And Emacs *could not* match parentheses in Perl 100%
730 would not break indentation, but
736 could confuse CPerl a lot.
738 If you still get wrong indentation in situation that you think the
739 code should be able to parse, try:
741 a) Check what Emacs thinks about balance of your parentheses.
742 b) Supply the code to me (IZ).
744 Pods were treated _very_ rudimentally. Here-documents were not
745 treated at all (except highlighting and inhibiting indentation). Upgrade.
747 To speed up coloring the following compromises exist:
748 a) sub in $mypackage::sub may be highlighted.
749 b) -z in [a-z] may be highlighted.
750 c) if your regexp contains a keyword (like \"s\"), it may be highlighted.
753 Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove
754 `car' before `imenu-choose-buffer-index' in `imenu'.
755 `imenu-add-to-menubar' in 20.2 is broken.
757 A lot of things on XEmacs may be broken too, judging by bug reports I
758 receive. Note that some releases of XEmacs are better than the others
759 as far as bugs reports I see are concerned.")
761 (defvar cperl-praise 'please-ignore-this-line
762 "Advantages of CPerl mode.
764 0) It uses the newest `syntax-table' property ;-);
766 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
767 mode - but the latter number may have improved too in last years) even
768 with old Emaxen which do not support `syntax-table' property.
770 When using `syntax-table' property for syntax assist hints, it should
771 handle 99.995% of lines correct - or somesuch. It automatically
772 updates syntax assist hints when you edit your script.
774 2) It is generally believed to be \"the most user-friendly Emacs
775 package\" whatever it may mean (I doubt that the people who say similar
776 things tried _all_ the rest of Emacs ;-), but this was not a lonely
779 3) Everything is customizable, one-by-one or in a big sweep;
781 4) It has many easily-accessable \"tools\":
782 a) Can run program, check syntax, start debugger;
783 b) Can lineup vertically \"middles\" of rows, like `=' in
786 c) Can insert spaces where this impoves readability (in one
787 interactive sweep over the buffer);
788 d) Has support for imenu, including:
789 1) Separate unordered list of \"interesting places\";
790 2) Separate TOC of POD sections;
791 3) Separate list of packages;
792 4) Hierarchical view of methods in (sub)packages;
793 5) and functions (by the full name - with package);
794 e) Has an interface to INFO docs for Perl; The interface is
795 very flexible, including shrink-wrapping of
796 documentation buffer/frame;
797 f) Has a builtin list of one-line explanations for perl constructs.
798 g) Can show these explanations if you stay long enough at the
799 corresponding place (or on demand);
800 h) Has an enhanced fontification (using 3 or 4 additional faces
801 comparing to font-lock - basically, different
802 namespaces in Perl have different colors);
803 i) Can construct TAGS basing on its knowledge of Perl syntax,
804 the standard menu has 6 different way to generate
805 TAGS (if \"by directory\", .xs files - with C-language
806 bindings - are included in the scan);
807 j) Can build a hierarchical view of classes (via imenu) basing
808 on generated TAGS file;
809 k) Has electric parentheses, electric newlines, uses Abbrev
810 for electric logical constructs
812 with different styles of expansion (context sensitive
813 to be not so bothering). Electric parentheses behave
814 \"as they should\" in a presence of a visible region.
815 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
821 n) Highlights (by user-choice) either 3-delimiters constructs
822 (such as tr/a/b/), or regular expressions and `y/tr';
823 o) Highlights trailing whitespace;
824 p) Is able to manipulate Perl Regular Expressions to ease
825 conversion to a more readable form.
827 5) The indentation engine was very smart, but most of tricks may be
828 not needed anymore with the support for `syntax-table' property. Has
829 progress indicator for indentation (with `imenu' loaded).
831 6) Indent-region improves inline-comments as well; also corrects
832 whitespace *inside* the conditional/loop constructs.
834 7) Fill-paragraph correctly handles multi-line comments;
836 8) Can switch to different indentation styles by one command, and restore
837 the settings present before the switch.
839 9) When doing indentation of control constructs, may correct
840 line-breaks/spacing between elements of the construct.
842 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
843 capable syntax engines).
846 (defvar cperl-speed 'please-ignore-this-line
847 "This is an incomplete compendium of what is available in other parts
848 of CPerl documentation. (Please inform me if I skept anything.)
850 There is a perception that CPerl is slower than alternatives. This part
851 of documentation is designed to overcome this misconception.
853 *By default* CPerl tries to enable the most comfortable settings.
854 From most points of view, correctly working package is infinitely more
855 comfortable than a non-correctly working one, thus by default CPerl
856 prefers correctness over speed. Below is the guide how to change
857 settings if your preferences are different.
859 A) Speed of loading the file. When loading file, CPerl may perform a
860 scan which indicates places which cannot be parsed by primitive Emacs
861 syntax-parsing routines, and marks them up so that either
863 A1) CPerl may work around these deficiencies (for big chunks, mostly
864 PODs and HERE-documents), or
865 A2) On capable Emaxen CPerl will use improved syntax-handlings
866 which reads mark-up hints directly.
868 The scan in case A2 is much more comprehensive, thus may be slower.
870 User can disable syntax-engine-helping scan of A2 by setting
871 `cperl-use-syntax-table-text-property'
872 variable to nil (if it is set to t).
874 One can disable the scan altogether (both A1 and A2) by setting
875 `cperl-pod-here-scan'
878 B) Speed of editing operations.
880 One can add a (minor) speedup to editing operations by setting
881 `cperl-use-syntax-table-text-property'
882 variable to nil (if it is set to t). This will disable
883 syntax-engine-helping scan, thus will make many more Perl
884 constructs be wrongly recognized by CPerl, thus may lead to
885 wrongly matched parentheses, wrong indentation, etc.
887 One can unset `cperl-syntaxify-unwind'. This might speed up editing
888 of, say, long POD sections.
891 (defvar cperl-tips-faces 'please-ignore-this-line
892 "CPerl mode uses following faces for highlighting:
894 `cperl-array-face' Array names
895 `cperl-hash-face' Hash names
896 `font-lock-comment-face' Comments, PODs and whatever is considered
897 syntaxically to be not code
898 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
899 2-arg operators s/y/tr/ or of RExen,
900 `font-lock-function-name-face' Special-cased m// and s//foo/, _ as
901 a target of a file tests, file tests,
902 subroutine names at the moment of definition
903 (except those conflicting with Perl operators),
904 package names (when recognized), format names
905 `font-lock-keyword-face' Control flow switch constructs, declarators
906 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
907 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
908 literal parts and the terminator of formats
909 and whatever is syntaxically considered
911 `font-lock-type-face' Overridable keywords
912 `font-lock-variable-name-face' Variable declarations, indirect array and
913 hash names, POD headers/item names
914 `cperl-invalid-face' Trailing whitespace
916 Note that in several situations the highlighting tries to inform about
917 possible confusion, such as different colors for function names in
918 declarations depending on what they (do not) override, or special cases
919 m// and s/// which do not do what one would expect them to do.
921 Help with best setup of these faces for printout requested (for each of
922 the faces: please specify bold, italic, underline, shadow and box.)
928 ;;; Portability stuff:
930 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
932 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
933 `(define-key cperl-mode-map
935 `(if cperl-xemacs-p ,xemacs-key ,emacs-key)
939 (defvar cperl-del-back-ch
940 (car (append (where-is-internal 'delete-backward-char)
941 (where-is-internal 'backward-delete-char-untabify)))
942 "Character generated by key bound to `delete-backward-char'.")
944 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
945 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
947 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
950 ;; "Active regions" are on: use region only if active
951 ;; "Active regions" are off: use region unconditionally
952 (defun cperl-use-region-p ()
953 (if zmacs-regions (mark) t)))
954 (defun cperl-use-region-p ()
955 (if transient-mark-mode mark-active t))
956 (defun cperl-mark-active () mark-active))
958 (defsubst cperl-enable-font-lock ()
959 (or cperl-xemacs-p window-system))
961 (defun cperl-putback-char (c) ; Emacs 19
962 (set 'unread-command-events (list c))) ; Avoid undefined warning
964 (if (boundp 'unread-command-events)
966 (defun cperl-putback-char (c) ; XEmacs >= 19.12
967 (setq unread-command-events (list (eval '(character-to-event c))))))
968 (defun cperl-putback-char (c) ; XEmacs <= 19.11
969 (set 'unread-command-event (eval '(character-to-event c))))) ; Avoid warnings
971 (or (fboundp 'uncomment-region)
972 (defun uncomment-region (beg end)
974 (comment-region beg end -1)))
976 (defvar cperl-do-not-fontify
977 (if (string< emacs-version "19.30")
980 "Text property which inhibits refontification.")
982 (defsubst cperl-put-do-not-fontify (from to &optional post)
983 ;; If POST, do not do it with postponed fontification
984 (if (and post cperl-syntaxify-by-font-lock)
986 (put-text-property (max (point-min) (1- from))
987 to cperl-do-not-fontify t)))
989 (defcustom cperl-mode-hook nil
990 "Hook run by `cperl-mode'."
994 (defvar cperl-syntax-state nil)
995 (defvar cperl-syntax-done-to nil)
996 (defvar cperl-emacs-can-parse (> (length (save-excursion
997 (parse-partial-sexp 1 1))) 9))
999 ;; Make customization possible "in reverse"
1000 (defsubst cperl-val (symbol &optional default hairy)
1002 ((eq (symbol-value symbol) 'null) default)
1003 (cperl-hairy (or hairy t))
1004 (t (symbol-value symbol))))
1006 ;;; Probably it is too late to set these guys already, but it can help later:
1008 ;;;(and cperl-clobber-mode-lists
1009 ;;;(setq auto-mode-alist
1010 ;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
1011 ;;;(and (boundp 'interpreter-mode-alist)
1012 ;;; (setq interpreter-mode-alist (append interpreter-mode-alist
1013 ;;; '(("miniperl" . perl-mode))))))
1033 (if (fboundp 'ps-extend-face-list)
1034 (defmacro cperl-ps-extend-face-list (arg)
1035 `(ps-extend-face-list ,arg))
1036 (defmacro cperl-ps-extend-face-list (arg)
1037 `(error "This version of Emacs has no `ps-extend-face-list'")))
1038 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
1039 ;; macros instead of defsubsts don't work on Emacs, so we do the
1040 ;; expansion manually. Any other suggestions?
1043 (defvar cperl-mode-abbrev-table nil
1044 "Abbrev table in use in Cperl-mode buffers.")
1046 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
1048 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
1050 (if cperl-mode-map nil
1051 (setq cperl-mode-map (make-sparse-keymap))
1052 (cperl-define-key "{" 'cperl-electric-lbrace)
1053 (cperl-define-key "[" 'cperl-electric-paren)
1054 (cperl-define-key "(" 'cperl-electric-paren)
1055 (cperl-define-key "<" 'cperl-electric-paren)
1056 (cperl-define-key "}" 'cperl-electric-brace)
1057 (cperl-define-key "]" 'cperl-electric-rparen)
1058 (cperl-define-key ")" 'cperl-electric-rparen)
1059 (cperl-define-key ";" 'cperl-electric-semi)
1060 (cperl-define-key ":" 'cperl-electric-terminator)
1061 (cperl-define-key "\C-j" 'newline-and-indent)
1062 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
1063 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
1064 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
1065 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
1066 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
1067 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
1068 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
1069 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
1070 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
1071 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
1073 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1074 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
1075 (cperl-define-key "\177" 'cperl-electric-backspace)
1076 (cperl-define-key "\t" 'cperl-indent-command)
1077 ;; don't clobber the backspace binding:
1078 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
1079 [(control c) (control h) F])
1080 (if (cperl-val 'cperl-clobber-lisp-bindings)
1082 (cperl-define-key "\C-hf"
1083 ;;(concat (char-to-string help-char) "f") ; does not work
1084 'cperl-info-on-command
1086 (cperl-define-key "\C-hv"
1087 ;;(concat (char-to-string help-char) "v") ; does not work
1090 (cperl-define-key "\C-c\C-hf"
1091 ;;(concat (char-to-string help-char) "f") ; does not work
1092 (key-binding "\C-hf")
1093 [(control c) (control h) f])
1094 (cperl-define-key "\C-c\C-hv"
1095 ;;(concat (char-to-string help-char) "v") ; does not work
1096 (key-binding "\C-hv")
1097 [(control c) (control h) v]))
1098 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
1099 [(control c) (control h) f])
1100 (cperl-define-key "\C-c\C-hv"
1101 ;;(concat (char-to-string help-char) "v") ; does not work
1103 [(control c) (control h) v]))
1104 (if (and cperl-xemacs-p
1105 (<= emacs-minor-version 11) (<= emacs-major-version 19))
1107 ;; substitute-key-definition is usefulness-deenhanced...
1108 (cperl-define-key "\M-q" 'cperl-fill-paragraph)
1109 (cperl-define-key "\e;" 'cperl-indent-for-comment)
1110 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
1111 (substitute-key-definition
1112 'indent-sexp 'cperl-indent-exp
1113 cperl-mode-map global-map)
1114 (substitute-key-definition
1115 'fill-paragraph 'cperl-fill-paragraph
1116 cperl-mode-map global-map)
1117 (substitute-key-definition
1118 'indent-region 'cperl-indent-region
1119 cperl-mode-map global-map)
1120 (substitute-key-definition
1121 'indent-for-comment 'cperl-indent-for-comment
1122 cperl-mode-map global-map)))
1125 (defvar cperl-lazy-installed)
1126 (defvar cperl-old-style nil)
1130 (easy-menu-define cperl-menu cperl-mode-map "Menu for CPerl mode"
1132 ["Beginning of function" beginning-of-defun t]
1133 ["End of function" end-of-defun t]
1134 ["Mark function" mark-defun t]
1135 ["Indent expression" cperl-indent-exp t]
1136 ["Fill paragraph/comment" cperl-fill-paragraph t]
1138 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
1139 ["Invert if/unless/while etc" cperl-invert-if-unless t]
1141 ["Beautify" cperl-beautify-regexp
1142 cperl-use-syntax-table-text-property]
1143 ["Beautify one level deep" (cperl-beautify-regexp 1)
1144 cperl-use-syntax-table-text-property]
1145 ["Beautify a group" cperl-beautify-level
1146 cperl-use-syntax-table-text-property]
1147 ["Beautify a group one level deep" (cperl-beautify-level 1)
1148 cperl-use-syntax-table-text-property]
1149 ["Contract a group" cperl-contract-level
1150 cperl-use-syntax-table-text-property]
1151 ["Contract groups" cperl-contract-levels
1152 cperl-use-syntax-table-text-property])
1153 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
1155 ["Indent region" cperl-indent-region (cperl-use-region-p)]
1156 ["Comment region" cperl-comment-region (cperl-use-region-p)]
1157 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
1159 ["Run" mode-compile (fboundp 'mode-compile)]
1160 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
1161 (get-buffer "*compilation*"))]
1162 ["Next error" next-error (get-buffer "*compilation*")]
1163 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
1165 ["Debugger" cperl-db t]
1168 ["Imenu" imenu (fboundp 'imenu)]
1169 ["Insert spaces if needed" cperl-find-bad-style t]
1170 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
1171 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
1172 ["CPerl pretty print (exprmntl)" cperl-ps-print
1173 (fboundp 'ps-extend-face-list)]
1174 ["Imenu on info" cperl-imenu-on-info (featurep 'imenu)]
1176 ;;; ["Create tags for current file" cperl-etags t]
1177 ;;; ["Add tags for current file" (cperl-etags t) t]
1178 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
1179 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
1180 ;;; ["Create tags for Perl files in (sub)directories"
1181 ;;; (cperl-etags nil 'recursive) t]
1182 ;;; ["Add tags for Perl files in (sub)directories"
1183 ;;; (cperl-etags t 'recursive) t])
1184 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
1185 ["Create tags for current file" (cperl-write-tags nil t) t]
1186 ["Add tags for current file" (cperl-write-tags) t]
1187 ["Create tags for Perl files in directory"
1188 (cperl-write-tags nil t nil t) t]
1189 ["Add tags for Perl files in directory"
1190 (cperl-write-tags nil nil nil t) t]
1191 ["Create tags for Perl files in (sub)directories"
1192 (cperl-write-tags nil t t t) t]
1193 ["Add tags for Perl files in (sub)directories"
1194 (cperl-write-tags nil nil t t) t]))
1196 ["Define word at point" imenu-go-find-at-position
1197 (fboundp 'imenu-go-find-at-position)]
1198 ["Help on function" cperl-info-on-command t]
1199 ["Help on function at point" cperl-info-on-current-command t]
1200 ["Help on symbol at point" cperl-get-help t]
1201 ["Perldoc" cperl-perldoc t]
1202 ["Perldoc on word at point" cperl-perldoc-at-point t]
1203 ["View manpage of POD in this file" cperl-pod-to-manpage t]
1204 ["Auto-help on" cperl-lazy-install
1205 (and (fboundp 'run-with-idle-timer)
1206 (not cperl-lazy-installed))]
1207 ["Auto-help off" (eval '(cperl-lazy-unstall))
1208 (and (fboundp 'run-with-idle-timer)
1209 cperl-lazy-installed)])
1211 ["Auto newline" cperl-toggle-auto-newline t]
1212 ["Electric parens" cperl-toggle-electric t]
1213 ["Electric keywords" cperl-toggle-abbrev t]
1214 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
1215 ["Auto fill" auto-fill-mode t])
1217 ["CPerl" (cperl-set-style "CPerl") t]
1218 ["PerlStyle" (cperl-set-style "PerlStyle") t]
1219 ["GNU" (cperl-set-style "GNU") t]
1220 ["C++" (cperl-set-style "C++") t]
1221 ["FSF" (cperl-set-style "FSF") t]
1222 ["BSD" (cperl-set-style "BSD") t]
1223 ["Whitesmith" (cperl-set-style "Whitesmith") t]
1224 ["Current" (cperl-set-style "Current") t]
1225 ["Memorized" (cperl-set-style-back) cperl-old-style])
1227 ["Tips" (describe-variable 'cperl-tips) t]
1228 ["Problems" (describe-variable 'cperl-problems) t]
1229 ["Non-problems" (describe-variable 'cperl-non-problems) t]
1230 ["Speed" (describe-variable 'cperl-speed) t]
1231 ["Praise" (describe-variable 'cperl-praise) t]
1232 ["Faces" (describe-variable 'cperl-tips-faces) t]
1233 ["CPerl mode" (describe-function 'cperl-mode) t]
1235 (message "The version of master-file for this CPerl is %s"
1236 cperl-version) t]))))
1239 (autoload 'c-macro-expand "cmacexp"
1240 "Display the result of expanding all C macros occurring in the region.
1241 The expansion is entirely correct because it uses the C preprocessor."
1244 (defvar cperl-mode-syntax-table nil
1245 "Syntax table in use in Cperl-mode buffers.")
1247 (defvar cperl-string-syntax-table nil
1248 "Syntax table in use in Cperl-mode string-like chunks.")
1250 (if cperl-mode-syntax-table
1252 (setq cperl-mode-syntax-table (make-syntax-table))
1253 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
1254 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
1255 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
1256 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
1257 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
1258 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
1259 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
1260 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
1261 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
1262 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
1263 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
1264 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
1265 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
1266 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
1267 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
1268 (if cperl-under-as-char
1269 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
1270 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
1271 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
1272 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
1273 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
1274 (modify-syntax-entry ?# "." cperl-string-syntax-table) ; (?# comment )
1279 (defvar cperl-faces-init nil)
1281 (defvar cperl-msb-fixed nil)
1283 (defun cperl-mode ()
1284 "Major mode for editing Perl code.
1285 Expression and list commands understand all C brackets.
1286 Tab indents for Perl code.
1287 Paragraphs are separated by blank lines only.
1288 Delete converts tabs to spaces as it moves back.
1290 Various characters in Perl almost always come in pairs: {}, (), [],
1291 sometimes <>. When the user types the first, she gets the second as
1292 well, with optional special formatting done on {}. (Disabled by
1293 default.) You can always quote (with \\[quoted-insert]) the left
1294 \"paren\" to avoid the expansion. The processing of < is special,
1295 since most the time you mean \"less\". Cperl mode tries to guess
1296 whether you want to type pair <>, and inserts is if it
1297 appropriate. You can set `cperl-electric-parens-string' to the string that
1298 contains the parenths from the above list you want to be electrical.
1299 Electricity of parenths is controlled by `cperl-electric-parens'.
1300 You may also set `cperl-electric-parens-mark' to have electric parens
1301 look for active mark and \"embrace\" a region if possible.'
1303 CPerl mode provides expansion of the Perl control constructs:
1305 if, else, elsif, unless, while, until, continue, do,
1306 for, foreach, formy and foreachmy.
1308 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
1310 The user types the keyword immediately followed by a space, which
1311 causes the construct to be expanded, and the point is positioned where
1312 she is most likely to want to be. eg. when the user types a space
1313 following \"if\" the following appears in the buffer: if () { or if ()
1314 } { } and the cursor is between the parentheses. The user can then
1315 type some boolean expression within the parens. Having done that,
1316 typing \\[cperl-linefeed] places you - appropriately indented - on a
1317 new line between the braces (if you typed \\[cperl-linefeed] in a POD
1318 directive line, then appropriate number of new lines is inserted).
1320 If CPerl decides that you want to insert \"English\" style construct like
1324 it will not do any expansion. See also help on variable
1325 `cperl-extra-newline-before-brace'. (Note that one can switch the
1326 help message on expansion by setting `cperl-message-electric-keyword'
1329 \\[cperl-linefeed] is a convenience replacement for typing carriage
1330 return. It places you in the next line with proper indentation, or if
1331 you type it inside the inline block of control construct, like
1333 foreach (@lines) {print; print}
1335 and you are on a boundary of a statement inside braces, it will
1336 transform the construct into a multiline and will place you into an
1337 appropriately indented blank line. If you need a usual
1338 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
1339 see documentation on `cperl-electric-linefeed'.
1341 Use \\[cperl-invert-if-unless] to change a construction of the form
1351 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
1352 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
1353 on electric space between $ and {, `cperl-electric-parens-string' is
1354 the string that contains parentheses that should be electric in CPerl
1355 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
1356 setting `cperl-electric-keywords' enables electric expansion of
1357 control structures in CPerl. `cperl-electric-linefeed' governs which
1358 one of two linefeed behavior is preferable. You can enable all these
1359 options simultaneously (recommended mode of use) by setting
1360 `cperl-hairy' to t. In this case you can switch separate options off
1361 by setting them to `null'. Note that one may undo the extra
1362 whitespace inserted by semis and braces in `auto-newline'-mode by
1363 consequent \\[cperl-electric-backspace].
1365 If your site has perl5 documentation in info format, you can use commands
1366 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
1367 These keys run commands `cperl-info-on-current-command' and
1368 `cperl-info-on-command', which one is which is controlled by variable
1369 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
1370 \(in turn affected by `cperl-hairy').
1372 Even if you have no info-format documentation, short one-liner-style
1373 help is available on \\[cperl-get-help], and one can run perldoc or
1376 It is possible to show this help automatically after some idle time.
1377 This is regulated by variable `cperl-lazy-help-time'. Default with
1378 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
1379 secs idle time . It is also possible to switch this on/off from the
1380 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
1382 Use \\[cperl-lineup] to vertically lineup some construction - put the
1383 beginning of the region at the start of construction, and make region
1384 span the needed amount of lines.
1386 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
1387 `cperl-pod-face', `cperl-pod-head-face' control processing of pod and
1388 here-docs sections. With capable Emaxen results of scan are used
1389 for indentation too, otherwise they are used for highlighting only.
1391 Variables controlling indentation style:
1392 `cperl-tab-always-indent'
1393 Non-nil means TAB in CPerl mode should always reindent the current line,
1394 regardless of where in the line point is when the TAB command is used.
1395 `cperl-indent-left-aligned-comments'
1396 Non-nil means that the comment starting in leftmost column should indent.
1397 `cperl-auto-newline'
1398 Non-nil means automatically newline before and after braces,
1399 and after colons and semicolons, inserted in Perl code. The following
1400 \\[cperl-electric-backspace] will remove the inserted whitespace.
1401 Insertion after colons requires both this variable and
1402 `cperl-auto-newline-after-colon' set.
1403 `cperl-auto-newline-after-colon'
1404 Non-nil means automatically newline even after colons.
1405 Subject to `cperl-auto-newline' setting.
1406 `cperl-indent-level'
1407 Indentation of Perl statements within surrounding block.
1408 The surrounding block's indentation is the indentation
1409 of the line on which the open-brace appears.
1410 `cperl-continued-statement-offset'
1411 Extra indentation given to a substatement, such as the
1412 then-clause of an if, or body of a while, or just a statement continuation.
1413 `cperl-continued-brace-offset'
1414 Extra indentation given to a brace that starts a substatement.
1415 This is in addition to `cperl-continued-statement-offset'.
1416 `cperl-brace-offset'
1417 Extra indentation for line if it starts with an open brace.
1418 `cperl-brace-imaginary-offset'
1419 An open brace following other text is treated as if it the line started
1420 this far to the right of the actual line indentation.
1421 `cperl-label-offset'
1422 Extra indentation for line that is a label.
1423 `cperl-min-label-indent'
1424 Minimal indentation for line that is a label.
1426 Settings for K&R and BSD indentation styles are
1427 `cperl-indent-level' 5 8
1428 `cperl-continued-statement-offset' 5 8
1429 `cperl-brace-offset' -5 -8
1430 `cperl-label-offset' -5 -8
1432 CPerl knows several indentation styles, and may bulk set the
1433 corresponding variables. Use \\[cperl-set-style] to do this. Use
1434 \\[cperl-set-style-back] to restore the memorized preexisting values
1435 \(both available from menu).
1437 If `cperl-indent-level' is 0, the statement after opening brace in
1438 column 0 is indented on
1439 `cperl-brace-offset'+`cperl-continued-statement-offset'.
1441 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
1444 DO NOT FORGET to read micro-docs (available from `Perl' menu)
1445 or as help on variables `cperl-tips', `cperl-problems',
1446 `cperl-non-problems', `cperl-praise', `cperl-speed'."
1448 (kill-all-local-variables)
1449 (use-local-map cperl-mode-map)
1450 (if (cperl-val 'cperl-electric-linefeed)
1452 (local-set-key "\C-J" 'cperl-linefeed)
1453 (local-set-key "\C-C\C-J" 'newline-and-indent)))
1455 (cperl-val 'cperl-clobber-lisp-bindings)
1456 (cperl-val 'cperl-info-on-command-no-prompt))
1458 ;; don't clobber the backspace binding:
1459 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
1460 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
1461 [(control c) (control h) f])))
1462 (setq major-mode 'cperl-mode)
1463 (setq mode-name "CPerl")
1464 (if (not cperl-mode-abbrev-table)
1465 (let ((prev-a-c abbrevs-changed))
1466 (define-abbrev-table 'cperl-mode-abbrev-table '(
1467 ("if" "if" cperl-electric-keyword 0)
1468 ("elsif" "elsif" cperl-electric-keyword 0)
1469 ("while" "while" cperl-electric-keyword 0)
1470 ("until" "until" cperl-electric-keyword 0)
1471 ("unless" "unless" cperl-electric-keyword 0)
1472 ("else" "else" cperl-electric-else 0)
1473 ("continue" "continue" cperl-electric-else 0)
1474 ("for" "for" cperl-electric-keyword 0)
1475 ("foreach" "foreach" cperl-electric-keyword 0)
1476 ("formy" "formy" cperl-electric-keyword 0)
1477 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
1478 ("do" "do" cperl-electric-keyword 0)
1479 ("=pod" "=pod" cperl-electric-pod 0)
1480 ("=over" "=over" cperl-electric-pod 0)
1481 ("=head1" "=head1" cperl-electric-pod 0)
1482 ("=head2" "=head2" cperl-electric-pod 0)
1483 ("pod" "pod" cperl-electric-pod 0)
1484 ("over" "over" cperl-electric-pod 0)
1485 ("head1" "head1" cperl-electric-pod 0)
1486 ("head2" "head2" cperl-electric-pod 0)))
1487 (setq abbrevs-changed prev-a-c)))
1488 (setq local-abbrev-table cperl-mode-abbrev-table)
1489 (abbrev-mode (if (cperl-val 'cperl-electric-keywords) 1 0))
1490 (set-syntax-table cperl-mode-syntax-table)
1491 (make-local-variable 'outline-regexp)
1492 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
1493 (setq outline-regexp cperl-outline-regexp)
1494 (make-local-variable 'outline-level)
1495 (setq outline-level 'cperl-outline-level)
1496 (make-local-variable 'paragraph-start)
1497 (setq paragraph-start (concat "^$\\|" page-delimiter))
1498 (make-local-variable 'paragraph-separate)
1499 (setq paragraph-separate paragraph-start)
1500 (make-local-variable 'paragraph-ignore-fill-prefix)
1501 (setq paragraph-ignore-fill-prefix t)
1502 (make-local-variable 'indent-line-function)
1503 (setq indent-line-function 'cperl-indent-line)
1504 (make-local-variable 'require-final-newline)
1505 (setq require-final-newline t)
1506 (make-local-variable 'comment-start)
1507 (setq comment-start "# ")
1508 (make-local-variable 'comment-end)
1509 (setq comment-end "")
1510 (make-local-variable 'comment-column)
1511 (setq comment-column cperl-comment-column)
1512 (make-local-variable 'comment-start-skip)
1513 (setq comment-start-skip "#+ *")
1514 (make-local-variable 'defun-prompt-regexp)
1515 (setq defun-prompt-regexp "^[ \t]*sub[ \t]+\\([^ \t\n{(;]+\\)[ \t]*")
1516 (make-local-variable 'comment-indent-function)
1517 (setq comment-indent-function 'cperl-comment-indent)
1518 (make-local-variable 'parse-sexp-ignore-comments)
1519 (setq parse-sexp-ignore-comments t)
1520 (make-local-variable 'indent-region-function)
1521 (setq indent-region-function 'cperl-indent-region)
1522 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
1523 (make-local-variable 'imenu-create-index-function)
1524 (setq imenu-create-index-function
1525 (function cperl-imenu--create-perl-index))
1526 (make-local-variable 'imenu-sort-function)
1527 (setq imenu-sort-function nil)
1528 (make-local-variable 'vc-header-alist)
1529 (set 'vc-header-alist cperl-vc-header-alist) ; Avoid warning
1530 (make-local-variable 'font-lock-defaults)
1531 (setq font-lock-defaults
1533 ((string< emacs-version "19.30")
1534 '(cperl-font-lock-keywords-2))
1535 ((string< emacs-version "19.33") ; Which one to use?
1536 '((cperl-font-lock-keywords
1537 cperl-font-lock-keywords-1
1538 cperl-font-lock-keywords-2)))
1540 '((cperl-load-font-lock-keywords
1541 cperl-load-font-lock-keywords-1
1542 cperl-load-font-lock-keywords-2)))))
1543 (make-local-variable 'cperl-syntax-state)
1544 (if cperl-use-syntax-table-text-property
1546 (make-local-variable 'parse-sexp-lookup-properties)
1547 ;; Do not introduce variable if not needed, we check it!
1548 (set 'parse-sexp-lookup-properties t)
1549 ;; Fix broken font-lock:
1550 (or (boundp 'font-lock-unfontify-region-function)
1551 (set 'font-lock-unfontify-region-function
1552 'font-lock-default-unfontify-region))
1553 (make-local-variable 'font-lock-unfontify-region-function)
1554 (set 'font-lock-unfontify-region-function
1555 'cperl-font-lock-unfontify-region-function)
1556 (make-local-variable 'cperl-syntax-done-to)
1557 ;; Another bug: unless font-lock-syntactic-keywords, font-lock
1558 ;; ignores syntax-table text-property. (t) is a hack
1559 ;; to make font-lock think that font-lock-syntactic-keywords
1561 (make-local-variable 'font-lock-syntactic-keywords)
1562 (setq font-lock-syntactic-keywords
1563 (if cperl-syntaxify-by-font-lock
1564 '(t (cperl-fontify-syntaxically))
1566 (make-local-variable 'cperl-old-style)
1567 (set (make-local-variable 'normal-auto-fill-function)
1568 #'cperl-do-auto-fill)
1569 (if (cperl-enable-font-lock)
1570 (if (cperl-val 'cperl-font-lock)
1571 (progn (or cperl-faces-init (cperl-init-faces))
1572 (font-lock-mode 1))))
1573 (and (boundp 'msb-menu-cond)
1574 (not cperl-msb-fixed)
1576 (if (featurep 'easymenu)
1577 (easy-menu-add cperl-menu)) ; A NOP in Emacs.
1578 (run-hooks 'cperl-mode-hook)
1579 ;; After hooks since fontification will break this
1580 (if cperl-pod-here-scan
1581 (or ;;(and (boundp 'font-lock-mode)
1582 ;; (eval 'font-lock-mode) ; Avoid warning
1583 ;; (boundp 'font-lock-hot-pass) ; Newer font-lock
1584 cperl-syntaxify-by-font-lock ;;)
1585 (progn (or cperl-faces-init (cperl-init-faces-weak))
1586 (cperl-find-pods-heres)))))
1588 ;; Fix for perldb - make default reasonable
1592 (perldb (read-from-minibuffer "Run perldb (like this): "
1593 (if (consp gud-perldb-history)
1594 (car gud-perldb-history)
1595 (concat "perl " ;;(file-name-nondirectory
1599 (buffer-file-name)))
1601 '(gud-perldb-history . 1))))
1603 (defun cperl-msb-fix ()
1604 ;; Adds perl files to msb menu, supposes that msb is already loaded
1605 (setq cperl-msb-fixed t)
1606 (let* ((l (length msb-menu-cond))
1607 (last (nth (1- l) msb-menu-cond))
1608 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
1609 (handle (1- (nth 1 last))))
1610 (setcdr precdr (list
1612 '(memq major-mode '(cperl-mode perl-mode))
1617 ;; This is used by indent-for-comment
1618 ;; to decide how much to indent a comment in CPerl code
1619 ;; based on its context. Do fallback if comment is found wrong.
1621 (defvar cperl-wrong-comment)
1622 (defvar cperl-st-cfence '(14)) ; Comment-fence
1623 (defvar cperl-st-sfence '(15)) ; String-fence
1624 (defvar cperl-st-punct '(1))
1625 (defvar cperl-st-word '(2))
1626 (defvar cperl-st-bra '(4 . ?\>))
1627 (defvar cperl-st-ket '(5 . ?\<))
1630 (defun cperl-comment-indent ()
1631 (let ((p (point)) (c (current-column)) was phony)
1632 (if (looking-at "^#") 0 ; Existing comment at bol stays there.
1633 ;; Wrong comment found
1635 (setq was (cperl-to-comment-or-eol)
1636 phony (eq (get-text-property (point) 'syntax-table)
1640 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
1641 (if (eq (preceding-char) ?\#)
1646 (skip-chars-backward " \t")
1647 (max (1+ (current-column)) ; Else indent at comment column
1650 (insert comment-start)
1651 (backward-char (length comment-start)))
1652 (setq cperl-wrong-comment t)
1653 (indent-to comment-column 1) ; Indent minimum 1
1654 c))))) ; except leave at least one space.
1656 ;;;(defun cperl-comment-indent-fallback ()
1657 ;;; "Is called if the standard comment-search procedure fails.
1658 ;;;Point is at start of real comment."
1659 ;;; (let ((c (current-column)) target cnt prevc)
1660 ;;; (if (= c comment-column) nil
1661 ;;; (setq cnt (skip-chars-backward "[ \t]"))
1662 ;;; (setq target (max (1+ (setq prevc
1663 ;;; (current-column))) ; Else indent at comment column
1664 ;;; comment-column))
1665 ;;; (if (= c comment-column) nil
1666 ;;; (delete-backward-char cnt)
1667 ;;; (while (< prevc target)
1669 ;;; (setq prevc (current-column)))
1670 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
1671 ;;; (while (< prevc target)
1673 ;;; (setq prevc (current-column)))))))
1675 (defun cperl-indent-for-comment ()
1676 "Substitute for `indent-for-comment' in CPerl."
1678 (let (cperl-wrong-comment)
1679 (indent-for-comment)
1680 (if cperl-wrong-comment
1681 (progn (cperl-to-comment-or-eol)
1682 (forward-char (length comment-start))))))
1684 (defun cperl-comment-region (b e arg)
1685 "Comment or uncomment each line in the region in CPerl mode.
1686 See `comment-region'."
1687 (interactive "r\np")
1688 (let ((comment-start "#"))
1689 (comment-region b e arg)))
1691 (defun cperl-uncomment-region (b e arg)
1692 "Uncomment or comment each line in the region in CPerl mode.
1693 See `comment-region'."
1694 (interactive "r\np")
1695 (let ((comment-start "#"))
1696 (comment-region b e (- arg))))
1698 (defvar cperl-brace-recursing nil)
1700 (defun cperl-electric-brace (arg &optional only-before)
1701 "Insert character and correct line's indentation.
1702 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
1703 place (even in empty line), but not after. If after \")\" and the inserted
1704 char is \"{\", insert extra newline before only if
1705 `cperl-extra-newline-before-brace'."
1708 (other-end (if (and cperl-electric-parens-mark
1714 (not cperl-brace-recursing)
1715 (cperl-val 'cperl-electric-parens)
1716 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
1717 ;; Need to insert a matching pair
1720 (setq insertpos (point-marker))
1721 (goto-char other-end)
1722 (setq last-command-char ?\{)
1723 (cperl-electric-lbrace arg insertpos))
1725 ;: Check whether we close something "usual" with `}'
1726 (if (and (eq last-command-char ?\})
1730 (up-list (- (prefix-numeric-value arg)))
1731 ;;(cperl-after-block-p (point-min))
1732 (cperl-after-expr-p nil "{;)"))
1734 ;; Just insert the guy
1735 (self-insert-command (prefix-numeric-value arg))
1736 (if (and (not arg) ; No args, end (of empty line or auto)
1738 (or (and (null only-before)
1740 (skip-chars-backward " \t")
1742 (and (eq last-command-char ?\{) ; Do not insert newline
1743 ;; if after ")" and `cperl-extra-newline-before-brace'
1744 ;; is nil, do not insert extra newline.
1745 (not cperl-extra-newline-before-brace)
1747 (skip-chars-backward " \t")
1748 (eq (preceding-char) ?\))))
1749 (if cperl-auto-newline
1750 (progn (cperl-indent-line) (newline) t) nil)))
1752 (self-insert-command (prefix-numeric-value arg))
1754 (if cperl-auto-newline
1755 (setq insertpos (1- (point))))
1756 (if (and cperl-auto-newline (null only-before))
1759 (cperl-indent-line)))
1761 (if insertpos (progn (goto-char insertpos)
1762 (search-forward (make-string
1763 1 last-command-char))
1764 (setq insertpos (1- (point)))))
1768 (goto-char insertpos)
1769 (self-insert-command (prefix-numeric-value arg)))
1770 (self-insert-command (prefix-numeric-value arg)))))))
1772 (defun cperl-electric-lbrace (arg &optional end)
1773 "Insert character, correct line's indentation, correct quoting by space."
1776 (cperl-brace-recursing t)
1777 (cperl-auto-newline cperl-auto-newline)
1779 (if (and cperl-electric-parens-mark
1786 (and (cperl-val 'cperl-electric-lbrace-space)
1787 (eq (preceding-char) ?$)
1789 (skip-chars-backward "$")
1790 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
1792 ;; Check whether we are in comment
1796 (not (looking-at "[ \t]*#")))
1797 (cperl-after-expr-p nil "{;)"))
1799 (setq cperl-auto-newline nil))
1800 (cperl-electric-brace arg)
1801 (and (cperl-val 'cperl-electric-parens)
1802 (eq last-command-char ?{)
1803 (memq last-command-char
1804 (append cperl-electric-parens-string nil))
1805 (or (if other-end (goto-char (marker-position other-end)))
1807 (setq last-command-char ?} pos (point))
1808 (progn (cperl-electric-brace arg t)
1811 (defun cperl-electric-paren (arg)
1812 "Insert a matching pair of parentheses."
1814 (let ((beg (save-excursion (beginning-of-line) (point)))
1815 (other-end (if (and cperl-electric-parens-mark
1822 (if (and (cperl-val 'cperl-electric-parens)
1823 (memq last-command-char
1824 (append cperl-electric-parens-string nil))
1825 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
1826 ;;(not (save-excursion (search-backward "#" beg t)))
1827 (if (eq last-command-char ?<)
1829 (and abbrev-mode ; later it is too late, may be after `for'
1831 (cperl-after-expr-p nil "{;(,:="))
1834 (self-insert-command (prefix-numeric-value arg))
1835 (if other-end (goto-char (marker-position other-end)))
1836 (insert (make-string
1837 (prefix-numeric-value arg)
1838 (cdr (assoc last-command-char '((?{ .?})
1842 (forward-char (- (prefix-numeric-value arg))))
1843 (self-insert-command (prefix-numeric-value arg)))))
1845 (defun cperl-electric-rparen (arg)
1846 "Insert a matching pair of parentheses if marking is active.
1847 If not, or if we are not at the end of marking range, would self-insert."
1849 (let ((beg (save-excursion (beginning-of-line) (point)))
1850 (other-end (if (and cperl-electric-parens-mark
1851 (cperl-val 'cperl-electric-parens)
1852 (memq last-command-char
1853 (append cperl-electric-parens-string nil))
1860 (cperl-val 'cperl-electric-parens)
1861 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
1862 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
1863 ;;(not (save-excursion (search-backward "#" beg t)))
1866 (self-insert-command (prefix-numeric-value arg))
1868 (if other-end (goto-char other-end))
1869 (insert (make-string
1870 (prefix-numeric-value arg)
1871 (cdr (assoc last-command-char '((?\} . ?\{)
1876 (self-insert-command (prefix-numeric-value arg)))))
1878 (defun cperl-electric-keyword ()
1879 "Insert a construction appropriate after a keyword.
1880 Help message may be switched off by setting `cperl-message-electric-keyword'
1882 (let ((beg (save-excursion (beginning-of-line) (point)))
1883 (dollar (and (eq last-command-char ?$)
1884 (eq this-command 'self-insert-command)))
1885 (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
1886 (memq this-command '(self-insert-command newline))))
1888 (and (save-excursion
1892 (setq do (looking-at "do\\>")))
1894 (cperl-after-expr-p nil "{;:"))
1898 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
1900 (save-excursion (or (not (re-search-backward "^=" nil t))
1903 (and cperl-use-syntax-table-text-property
1904 (not (eq (get-text-property (point)
1908 (and (eq (preceding-char) ?y)
1909 (progn ; "foreachmy"
1915 (memq this-command '(self-insert-command newline)))))
1916 (and dollar (insert " $"))
1918 ;;(insert " () {\n}")
1920 (cperl-extra-newline-before-brace
1921 (insert (if do "\n" " ()\n"))
1927 (and do (insert " while ();")))
1929 (insert (if do " {\n} while ();" " () {\n}")))
1931 (or (looking-at "[ \t]\\|$") (insert " "))
1933 (if dollar (progn (search-backward "$")
1937 (search-backward ")"))
1939 (cperl-putback-char cperl-del-back-ch))
1940 (if cperl-message-electric-keyword
1941 (message "Precede char by C-q to avoid expansion"))))))
1943 (defun cperl-ensure-newlines (n &optional pos)
1944 "Make sure there are N newlines after the point."
1945 (or pos (setq pos (point)))
1946 (if (looking-at "\n")
1950 (cperl-ensure-newlines (1- n) pos)
1953 (defun cperl-electric-pod ()
1954 "Insert a POD chunk appropriate after a =POD directive."
1955 (let ((delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
1956 (memq this-command '(self-insert-command newline))))
1957 head1 notlast name p really-delete over)
1958 (and (save-excursion
1961 (eq (preceding-char) ?=)
1963 (setq head1 (looking-at "head1\\>[ \t]*$"))
1964 (setq over (and (looking-at "over\\>[ \t]*$")
1965 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
1969 (get-text-property (point) 'in-pod)
1970 (cperl-after-expr-p nil "{;:")
1971 (and (re-search-backward
1972 ;; "\\(\\`\n?\\|\n\n\\)=\\sw+"
1973 "\\(\\`\n?\\|^\n\\)=\\sw+"
1977 (and cperl-use-syntax-table-text-property
1978 (not (eq (get-text-property (point) 'syntax-type)
1982 (setq notlast (re-search-forward "^\n=" nil t)))
1986 (cperl-ensure-newlines 2)
1992 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
1993 nil t)))) ; Only one
1996 (setq name (file-name-sans-extension
1997 (file-name-nondirectory (buffer-file-name)))
1999 (insert " NAME\n\n" name
2000 " - \n\n=head1 SYNOPSIS\n\n\n\n"
2001 "=head1 DESCRIPTION")
2002 (cperl-ensure-newlines 4)
2006 (setq really-delete t))
2011 (insert "\n\n=item \n\n\n\n"
2013 (cperl-ensure-newlines 2)
2017 (setq really-delete t)))
2018 (if (and delete really-delete)
2019 (cperl-putback-char cperl-del-back-ch))))))
2021 (defun cperl-electric-else ()
2022 "Insert a construction appropriate after a keyword.
2023 Help message may be switched off by setting `cperl-message-electric-keyword'
2025 (let ((beg (save-excursion (beginning-of-line) (point))))
2026 (and (save-excursion
2028 (cperl-after-expr-p nil "{;:"))
2032 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2034 (save-excursion (or (not (re-search-backward "^=" nil t))
2036 (and cperl-use-syntax-table-text-property
2037 (not (eq (get-text-property (point)
2042 ;;(insert " {\n\n}")
2044 (cperl-extra-newline-before-brace
2052 (or (looking-at "[ \t]\\|$") (insert " "))
2056 (cperl-putback-char cperl-del-back-ch)
2057 (setq this-command 'cperl-electric-else)
2058 (if cperl-message-electric-keyword
2059 (message "Precede char by C-q to avoid expansion"))))))
2061 (defun cperl-linefeed ()
2062 "Go to end of line, open a new line and indent appropriately.
2063 If in POD, insert appropriate lines."
2065 (let ((beg (save-excursion (beginning-of-line) (point)))
2066 (end (save-excursion (end-of-line) (point)))
2067 (pos (point)) start over cut res)
2068 (if (and ; Check if we need to split:
2069 ; i.e., on a boundary and inside "{...}"
2070 (save-excursion (cperl-to-comment-or-eol)
2071 (>= (point) pos)) ; Not in a comment
2073 (skip-chars-backward " \t" beg)
2075 (looking-at "[;{]")) ; After { or ; + spaces
2076 (looking-at "[ \t]*}") ; Before }
2077 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
2080 (eq (car (parse-partial-sexp pos end -1)) -1)
2081 ; Leave the level of parens
2082 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
2084 (cperl-after-block-p (point-min))
2087 (setq start (point-marker))
2088 (<= start pos))))) ; Redundant? Are after the
2089 ; start of parens group.
2091 (skip-chars-backward " \t")
2092 (or (memq (preceding-char) (append ";{" nil))
2098 (or (looking-at "{[ \t]*$") ; If there is a statement
2099 ; before, move it to separate line
2103 (cperl-indent-line)))
2104 (forward-line 1) ; We are on the target line
2107 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
2108 ; after, move it to separate line
2111 (search-backward "}" beg)
2112 (skip-chars-backward " \t")
2113 (or (memq (preceding-char) (append ";{" nil))
2118 (forward-line -1) ; We are on the line before target
2120 (newline-and-indent))
2121 (end-of-line) ; else - no splitting
2123 ((and (looking-at "\n[ \t]*{$")
2125 (skip-chars-backward " \t")
2126 (eq (preceding-char) ?\)))) ; Probably if () {} group
2127 ; with an extra newline.
2129 (cperl-indent-line))
2130 ((save-excursion ; In POD header
2131 (forward-paragraph -1)
2132 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
2133 ;; We are after \n now, so look for the rest
2134 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
2136 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
2137 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
2141 (forward-paragraph -1)
2144 (setq cut (buffer-substring (point)
2148 (delete-char (- (save-excursion (end-of-line) (point))
2150 (setq res (expand-abbrev))
2156 (cperl-ensure-newlines (if cut 2 4))
2158 ((get-text-property (point) 'in-pod) ; In POD section
2159 (cperl-ensure-newlines 4)
2161 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
2163 (cperl-indent-line))
2165 (newline-and-indent))))))
2167 (defun cperl-electric-semi (arg)
2168 "Insert character and correct line's indentation."
2170 (if cperl-auto-newline
2171 (cperl-electric-terminator arg)
2172 (self-insert-command (prefix-numeric-value arg))
2173 (if cperl-autoindent-on-semi
2174 (cperl-indent-line))))
2176 (defun cperl-electric-terminator (arg)
2177 "Insert character and correct line's indentation."
2179 (let (insertpos (end (point))
2180 (auto (and cperl-auto-newline
2181 (or (not (eq last-command-char ?:))
2182 cperl-auto-newline-after-colon))))
2183 (if (and ;;(not arg)
2185 (not (save-excursion
2187 (skip-chars-forward " \t")
2189 ;; Ignore in comment lines
2190 (= (following-char) ?#)
2191 ;; Colon is special only after a label
2192 ;; So quickly rule out most other uses of colon
2193 ;; and do no indentation for them.
2194 (and (eq last-command-char ?:)
2197 (skip-chars-forward " \t")
2198 (and (< (point) end)
2199 (progn (goto-char (- end 1))
2200 (not (looking-at ":"))))))
2202 (beginning-of-defun)
2203 (let ((pps (parse-partial-sexp (point) end)))
2204 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
2206 (self-insert-command (prefix-numeric-value arg))
2208 (if auto (setq insertpos (point-marker)))
2214 (cperl-indent-line)))
2216 (if insertpos (goto-char (1- (marker-position insertpos)))
2221 (goto-char insertpos)
2222 (self-insert-command (prefix-numeric-value arg)))
2223 (self-insert-command (prefix-numeric-value arg)))))
2225 (defun cperl-electric-backspace (arg)
2226 "Backspace-untabify, or remove the whitespace around the point inserted
2227 by an electric key."
2229 (if (and cperl-auto-newline
2230 (memq last-command '(cperl-electric-semi
2231 cperl-electric-terminator
2232 cperl-electric-lbrace))
2233 (memq (preceding-char) '(?\ ?\t ?\n)))
2235 (if (eq last-command 'cperl-electric-lbrace)
2236 (skip-chars-forward " \t\n"))
2238 (skip-chars-backward " \t\n")
2239 (delete-region (point) p))
2240 (and (eq last-command 'cperl-electric-else)
2241 ;; We are removing the whitespace *inside* cperl-electric-else
2242 (setq this-command 'cperl-electric-else-really))
2243 (if (and cperl-auto-newline
2244 (eq last-command 'cperl-electric-else-really)
2245 (memq (preceding-char) '(?\ ?\t ?\n)))
2247 (skip-chars-forward " \t\n")
2249 (skip-chars-backward " \t\n")
2250 (delete-region (point) p))
2251 (backward-delete-char-untabify arg))))
2253 (defun cperl-inside-parens-p ()
2257 (narrow-to-region (point)
2258 (progn (beginning-of-defun) (point)))
2259 (goto-char (point-max))
2260 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
2263 (defun cperl-indent-command (&optional whole-exp)
2264 "Indent current line as Perl code, or in some cases insert a tab character.
2265 If `cperl-tab-always-indent' is non-nil (the default), always indent current
2266 line. Otherwise, indent the current line only if point is at the left margin
2267 or in the line's indentation; otherwise insert a tab.
2269 A numeric argument, regardless of its value,
2270 means indent rigidly all the lines of the expression starting after point
2271 so that this line becomes properly indented.
2272 The relative indentation among the lines of the expression are preserved."
2274 (cperl-update-syntaxification (point) (point))
2276 ;; If arg, always indent this line as Perl
2277 ;; and shift remaining lines of expression the same amount.
2278 (let ((shift-amt (cperl-indent-line))
2281 (if cperl-tab-always-indent
2282 (beginning-of-line))
2289 (if (and shift-amt (> end beg))
2290 (indent-code-rigidly beg end shift-amt "#")))
2291 (if (and (not cperl-tab-always-indent)
2293 (skip-chars-backward " \t")
2296 (cperl-indent-line))))
2298 (defun cperl-indent-line (&optional parse-data)
2299 "Indent current line as Perl code.
2300 Return the amount the indentation changed by."
2301 (let (indent i beg shift-amt
2302 (case-fold-search nil)
2303 (pos (- (point-max) (point))))
2304 (setq indent (cperl-calculate-indent parse-data)
2308 (cond ((or (eq indent nil) (eq indent t))
2309 (setq indent (current-indentation) i nil))
2310 ;;((eq indent t) ; Never?
2311 ;; (setq indent (cperl-calculate-indent-within-comment)))
2312 ;;((looking-at "[ \t]*#")
2315 (skip-chars-forward " \t")
2316 (if (listp indent) (setq indent (car indent)))
2317 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
2319 (setq indent (max cperl-min-label-indent
2320 (+ indent cperl-label-offset)))))
2321 ((= (following-char) ?})
2322 (setq indent (- indent cperl-indent-level)))
2323 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
2324 (setq indent (+ indent cperl-close-paren-offset)))
2325 ((= (following-char) ?{)
2326 (setq indent (+ indent cperl-brace-offset))))))
2327 (skip-chars-forward " \t")
2328 (setq shift-amt (and i (- indent (current-column))))
2329 (if (or (not shift-amt)
2331 (if (> (- (point-max) pos) (point))
2332 (goto-char (- (point-max) pos)))
2333 (delete-region beg (point))
2335 ;; If initial point was within line's indentation,
2336 ;; position after the indentation. Else stay at same point in text.
2337 (if (> (- (point-max) pos) (point))
2338 (goto-char (- (point-max) pos))))
2341 (defun cperl-after-label ()
2342 ;; Returns true if the point is after label. Does not do save-excursion.
2343 (and (eq (preceding-char) ?:)
2344 (memq (char-syntax (char-after (- (point) 2)))
2348 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
2350 (defun cperl-get-state (&optional parse-start start-state)
2351 ;; returns list (START STATE DEPTH PRESTART),
2352 ;; START is a good place to start parsing, or equal to
2353 ;; PARSE-START if preset,
2354 ;; STATE is what is returned by `parse-partial-sexp'.
2355 ;; DEPTH is true is we are immediately after end of block
2356 ;; which contains START.
2357 ;; PRESTART is the position basing on which START was found.
2359 (let ((start-point (point)) depth state start prestart)
2360 (if (and parse-start
2361 (<= parse-start start-point))
2362 (goto-char parse-start)
2363 (beginning-of-defun)
2364 (setq start-state nil))
2365 (setq prestart (point))
2367 ;; Try to go out, if sub is not on the outermost level
2368 (while (< (point) start-point)
2369 (setq start (point) parse-start start depth nil
2370 state (parse-partial-sexp start start-point -1))
2371 (if (> (car state) -1) nil
2372 ;; The current line could start like }}}, so the indentation
2373 ;; corresponds to a different level than what we reached
2375 (beginning-of-line 2))) ; Go to the next line.
2376 (if start (goto-char start))) ; Not at the start of file
2377 (setq start (point))
2378 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
2379 (list start state depth prestart))))
2381 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
2382 ;; Positions is before ?\{. Checks whether it starts a block.
2383 ;; No save-excursion!
2384 (cperl-backward-to-noncomment (point-min))
2385 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
2386 ; Label may be mixed up with `$blah :'
2387 (save-excursion (cperl-after-label))
2388 (and (memq (char-syntax (preceding-char)) '(?w ?_))
2391 ;; Need take into account `bless', `return', `tr',...
2392 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
2393 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
2395 (skip-chars-backward " \t\n\f")
2396 (and (memq (char-syntax (preceding-char)) '(?w ?_))
2400 "sub[ \t]+[a-zA-Z0-9_:]+[ \t\n\f]*\\(([^()]*)[ \t\n\f]*\\)?[#{]")))))))))
2402 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
2404 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
2405 "Return appropriate indentation for current line as Perl code.
2406 In usual case returns an integer: the column to indent to.
2407 Returns nil if line starts inside a string, t if in a comment.
2409 Will not correct the indentation for labels, but will correct it for braces
2410 and closing parentheses and brackets.."
2413 (and (memq (get-text-property (point) 'syntax-type)
2414 '(pod here-doc here-doc-delim format))
2415 (not (get-text-property (point) 'indentable)))
2416 ;; before start of POD - whitespace found since do not have 'pod!
2417 (and (looking-at "[ \t]*\n=")
2418 (error "Spaces before pod section!"))
2419 (and (not cperl-indent-left-aligned-comments)
2423 (let ((indent-point (point))
2424 (char-after (save-excursion
2425 (skip-chars-forward " \t")
2427 (in-pod (get-text-property (point) 'in-pod))
2428 (pre-indent-point (point))
2429 p prop look-prop is-block delim)
2432 ;; In the verbatim part, probably code example. What to do???
2437 (cperl-backward-to-noncomment nil)
2438 (setq p (max (point-min) (1- (point)))
2439 prop (get-text-property p 'syntax-type)
2440 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
2442 (if (memq prop '(pod here-doc format here-doc-delim))
2444 (goto-char (or (previous-single-property-change p look-prop)
2447 (setq pre-indent-point (point)))))))
2448 (goto-char pre-indent-point)
2449 (let* ((case-fold-search nil)
2450 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
2451 (start (or (nth 2 parse-data)
2454 (containing-sexp (car (cdr state)))
2457 ;;containing-sexp ;; We are buggy at toplevel :-(
2460 (setcar parse-data pre-indent-point)
2461 (setcar (cdr parse-data) state)
2462 (or (nth 2 parse-data)
2463 (setcar (cddr parse-data) start))
2464 ;; Before this point: end of statement
2465 (setq old-indent (nth 3 parse-data))))
2466 (cond ((get-text-property (point) 'indentable)
2467 ;; indent to just after the surrounding open,
2468 ;; skip blanks if we do not close the expression.
2469 (goto-char (1+ (previous-single-property-change (point) 'indentable)))
2470 (or (memq char-after (append ")]}" nil))
2471 (looking-at "[ \t]*\\(#\\|$\\)")
2472 (skip-chars-forward " \t"))
2474 ((or (nth 3 state) (nth 4 state))
2475 ;; return nil or t if should not change this line
2477 ;; XXXX Do we need to special-case this?
2478 ((null containing-sexp)
2479 ;; Line is at top level. May be data or function definition,
2480 ;; or may be function argument declaration.
2481 ;; Indent like the previous top level line
2482 ;; unless that ends in a closeparen without semicolon,
2483 ;; in which case this line is the first argument decl.
2484 (skip-chars-forward " \t")
2487 (- (current-indentation)
2488 (if (nth 2 s-s) cperl-indent-level 0)))
2489 (if (= char-after ?{) cperl-continued-brace-offset 0)
2491 (cperl-backward-to-noncomment (or old-indent (point-min)))
2492 ;; Look at previous line that's at column 0
2493 ;; to determine whether we are in top-level decls
2494 ;; or function's arg decls. Set basic-indent accordingly.
2495 ;; Now add a little if this is a continuation line.
2497 (eq (point) old-indent) ; old-indent was at comment
2498 (eq (preceding-char) ?\;)
2500 (and (eq (preceding-char) ?\})
2501 (cperl-after-block-and-statement-beg
2502 (point-min))) ; Was start - too close
2503 (memq char-after (append ")]}" nil))
2504 (and (eq (preceding-char) ?\:) ; label
2507 (skip-chars-backward " \t")
2508 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:"))))
2511 (not (eq char-after ?\C-j)))
2512 (setcdr (cddr parse-data)
2513 (list pre-indent-point)))
2515 cperl-continued-statement-offset))))
2518 (and (setq delim (= (char-after containing-sexp) ?{))
2519 (save-excursion ; Is it a hash?
2520 (goto-char containing-sexp)
2522 cperl-indent-parens-as-block))
2523 ;; group is an expression, not a block:
2524 ;; indent to just after the surrounding open parens,
2525 ;; skip blanks if we do not close the expression.
2526 (goto-char (1+ containing-sexp))
2527 (or (memq char-after (append ")]}" nil))
2528 (looking-at "[ \t]*\\(#\\|$\\)")
2529 (skip-chars-forward " \t"))
2532 ;; Containing-expr starts with \{. Check whether it is a hash.
2533 (goto-char containing-sexp)
2534 (not (cperl-block-p)))
2535 (goto-char (1+ containing-sexp))
2536 (or (memq char-after
2537 (append (if delim "}" ")]}") nil))
2538 (looking-at "[ \t]*\\(#\\|$\\)")
2539 (skip-chars-forward " \t"))
2542 (eq char-after ?\}))
2543 ;; Correct indentation of trailing ?\}
2544 (+ cperl-indent-level cperl-close-paren-offset)
2546 ;;; ((and (/= (char-after containing-sexp) ?{)
2547 ;;; (not cperl-indent-parens-as-block))
2548 ;;; ;; line is expression, not statement:
2549 ;;; ;; indent to just after the surrounding open,
2550 ;;; ;; skip blanks if we do not close the expression.
2551 ;;; (goto-char (1+ containing-sexp))
2552 ;;; (or (memq char-after (append ")]}" nil))
2553 ;;; (looking-at "[ \t]*\\(#\\|$\\)")
2554 ;;; (skip-chars-forward " \t"))
2555 ;;; (current-column))
2557 ;;; ;; Containing-expr starts with \{. Check whether it is a hash.
2558 ;;; (goto-char containing-sexp)
2559 ;;; (and (not (cperl-block-p))
2560 ;;; (not cperl-indent-parens-as-block)))
2561 ;;; (goto-char (1+ containing-sexp))
2562 ;;; (or (eq char-after ?\})
2563 ;;; (looking-at "[ \t]*\\(#\\|$\\)")
2564 ;;; (skip-chars-forward " \t"))
2565 ;;; (+ (current-column) ; Correct indentation of trailing ?\}
2566 ;;; (if (eq char-after ?\}) (+ cperl-indent-level
2567 ;;; cperl-close-paren-offset)
2570 ;; Statement level. Is it a continuation or a new statement?
2571 ;; Find previous non-comment character.
2572 (goto-char pre-indent-point)
2573 (cperl-backward-to-noncomment containing-sexp)
2574 ;; Back up over label lines, since they don't
2575 ;; affect whether our line is a continuation.
2577 (while ;;(or (eq (preceding-char) ?\,)
2578 (and (eq (preceding-char) ?:)
2579 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
2580 (memq (char-syntax (char-after (- (point) 2)))
2583 (if (eq (preceding-char) ?\,)
2584 ;; Will go to beginning of line, essentially.
2585 ;; Will ignore embedded sexpr XXXX.
2586 (cperl-backward-to-start-of-continued-exp containing-sexp))
2588 (cperl-backward-to-noncomment containing-sexp))
2589 ;; Now we get the answer.
2590 (if (not (or (eq (1- (point)) containing-sexp)
2591 (memq (preceding-char)
2592 (append (if is-block " ;{" " ,;{") '(nil)))
2593 (and (eq (preceding-char) ?\})
2594 (cperl-after-block-and-statement-beg
2596 ;; This line is continuation of preceding line's statement;
2597 ;; indent `cperl-continued-statement-offset' more than the
2598 ;; previous line of the statement.
2600 ;; There might be a label on this line, just
2601 ;; consider it bad style and ignore it.
2603 (cperl-backward-to-start-of-continued-exp containing-sexp)
2604 (+ (if (memq char-after (append "}])" nil))
2606 cperl-continued-statement-offset)
2609 (not (eq char-after ?\})))
2611 ;; Now it is a hash reference
2612 (+ cperl-indent-level cperl-close-paren-offset))
2613 (if (looking-at "\\w+[ \t]*:")
2614 (if (> (current-indentation) cperl-min-label-indent)
2615 (- (current-indentation) cperl-label-offset)
2616 ;; Do not move `parse-data', this should
2617 ;; be quick anyway (this comment comes
2618 ;;from different location):
2619 (cperl-calculate-indent))
2621 (if (eq char-after ?\{)
2622 cperl-continued-brace-offset 0)))
2623 ;; This line starts a new statement.
2624 ;; Position following last unclosed open.
2625 (goto-char containing-sexp)
2626 ;; Is line first statement after an open-brace?
2628 ;; If no, find that first statement and indent like
2629 ;; it. If the first statement begins with label, do
2630 ;; not believe when the indentation of the label is too
2634 (setq old-indent (current-indentation))
2635 (let ((colon-line-end 0))
2636 (while (progn (skip-chars-forward " \t\n")
2637 (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]"))
2638 ;; Skip over comments and labels following openbrace.
2639 (cond ((= (following-char) ?\#)
2643 (save-excursion (end-of-line)
2644 (setq colon-line-end (point)))
2645 (search-forward ":"))))
2646 ;; The first following code counts
2647 ;; if it is before the line we want to indent.
2648 (and (< (point) indent-point)
2649 (if (> colon-line-end (point)) ; After label
2650 (if (> (current-indentation)
2651 cperl-min-label-indent)
2652 (- (current-indentation) cperl-label-offset)
2653 ;; Do not believe: `max' is involved
2654 (+ old-indent cperl-indent-level))
2655 (current-column)))))
2656 ;; If no previous statement,
2657 ;; indent it relative to line brace is on.
2658 ;; For open brace in column zero, don't let statement
2659 ;; start there too. If cperl-indent-level is zero,
2660 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
2661 ;; For open-braces not the first thing in a line,
2662 ;; add in cperl-brace-imaginary-offset.
2664 ;; If first thing on a line: ?????
2665 (+ (if (and (bolp) (zerop cperl-indent-level))
2666 (+ cperl-brace-offset cperl-continued-statement-offset)
2670 (not (eq char-after ?\})))
2672 ;; Now it is a hash reference
2673 (+ cperl-indent-level cperl-close-paren-offset))
2674 ;; Move back over whitespace before the openbrace.
2675 ;; If openbrace is not first nonwhite thing on the line,
2676 ;; add the cperl-brace-imaginary-offset.
2677 (progn (skip-chars-backward " \t")
2678 (if (bolp) 0 cperl-brace-imaginary-offset))
2679 ;; If the openbrace is preceded by a parenthesized exp,
2680 ;; move to the beginning of that;
2681 ;; possibly a different line
2683 (if (eq (preceding-char) ?\))
2685 ;; In the case it starts a subroutine, indent with
2686 ;; respect to `sub', not with respect to the the
2687 ;; first thing on the line, say in the case of
2688 ;; anonymous sub in a hash.
2690 (skip-chars-backward " \t")
2691 (if (and (eq (preceding-char) ?b)
2694 (looking-at "sub\\>"))
2698 (save-excursion (beginning-of-line) (point))
2700 (progn (goto-char (1+ old-indent))
2701 (skip-chars-forward " \t")
2703 ;; Get initial indentation of the line we are on.
2704 ;; If line starts with label, calculate label indentation
2707 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
2708 (if (> (current-indentation) cperl-min-label-indent)
2709 (- (current-indentation) cperl-label-offset)
2710 ;; Do not move `parse-data', this should
2712 (cperl-calculate-indent))
2713 (current-indentation))))))))))))))
2715 (defvar cperl-indent-alist
2719 (toplevel-after-parenth 2)
2720 (toplevel-continued 2)
2722 "Alist of indentation rules for CPerl mode.
2725 number: add this amount of indentation.
2727 Not finished, not used.")
2729 (defun cperl-where-am-i (&optional parse-start start-state)
2731 "Return a list of lists ((TYPE POS)...) of good points before the point.
2732 POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'.
2734 Not finished, not used."
2736 (let* ((start-point (point))
2737 (s-s (cperl-get-state))
2740 (prestart (nth 3 s-s))
2741 (containing-sexp (car (cdr state)))
2742 (case-fold-search nil)
2743 (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
2744 (cond ((nth 3 state) ; In string
2745 (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
2746 ((nth 4 state) ; In comment
2747 (setq res (cons '(comment) res)))
2748 ((null containing-sexp)
2749 ;; Line is at top level.
2750 ;; Indent like the previous top level line
2751 ;; unless that ends in a closeparen without semicolon,
2752 ;; in which case this line is the first argument decl.
2753 (cperl-backward-to-noncomment (or parse-start (point-min)))
2754 ;;(skip-chars-backward " \t\f\n")
2757 (memq (preceding-char) (append ";}" nil)))
2758 (setq res (cons (list 'toplevel start) res)))
2759 ((eq (preceding-char) ?\) )
2760 (setq res (cons (list 'toplevel-after-parenth start) res)))
2762 (setq res (cons (list 'toplevel-continued start) res)))))
2763 ((/= (char-after containing-sexp) ?{)
2764 ;; line is expression, not statement:
2765 ;; indent to just after the surrounding open.
2766 ;; skip blanks if we do not close the expression.
2767 (setq res (cons (list 'expression-blanks
2769 (goto-char (1+ containing-sexp))
2770 (or (looking-at "[ \t]*\\(#\\|$\\)")
2771 (skip-chars-forward " \t"))
2773 (cons (list 'expression containing-sexp) res))))
2775 ;; Containing-expr starts with \{. Check whether it is a hash.
2776 (goto-char containing-sexp)
2777 (not (cperl-block-p)))
2778 (setq res (cons (list 'expression-blanks
2780 (goto-char (1+ containing-sexp))
2781 (or (looking-at "[ \t]*\\(#\\|$\\)")
2782 (skip-chars-forward " \t"))
2784 (cons (list 'expression containing-sexp) res))))
2787 (setq res (cons (list 'in-block containing-sexp) res))
2788 ;; Is it a continuation or a new statement?
2789 ;; Find previous non-comment character.
2790 (cperl-backward-to-noncomment containing-sexp)
2791 ;; Back up over label lines, since they don't
2792 ;; affect whether our line is a continuation.
2793 ;; Back up comma-delimited lines too ?????
2794 (while (or (eq (preceding-char) ?\,)
2795 (save-excursion (cperl-after-label)))
2796 (if (eq (preceding-char) ?\,)
2797 ;; Will go to beginning of line, essentially
2798 ;; Will ignore embedded sexpr XXXX.
2799 (cperl-backward-to-start-of-continued-exp containing-sexp))
2801 (cperl-backward-to-noncomment containing-sexp))
2802 ;; Now we get the answer.
2803 (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
2804 ;; This line is continuation of preceding line's statement.
2805 (list (list 'statement-continued containing-sexp))
2806 ;; This line starts a new statement.
2807 ;; Position following last unclosed open.
2808 (goto-char containing-sexp)
2809 ;; Is line first statement after an open-brace?
2811 ;; If no, find that first statement and indent like
2812 ;; it. If the first statement begins with label, do
2813 ;; not believe when the indentation of the label is too
2817 (let ((colon-line-end 0))
2818 (while (progn (skip-chars-forward " \t\n" start-point)
2819 (and (< (point) start-point)
2821 "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
2822 ;; Skip over comments and labels following openbrace.
2823 (cond ((= (following-char) ?\#)
2828 (save-excursion (end-of-line)
2829 (setq colon-line-end (point)))
2830 (search-forward ":"))))
2831 ;; Now at the point, after label, or at start
2832 ;; of first statement in the block.
2833 (and (< (point) start-point)
2834 (if (> colon-line-end (point))
2835 ;; Before statement after label
2836 (if (> (current-indentation)
2837 cperl-min-label-indent)
2838 (list (list 'label-in-block (point)))
2839 ;; Do not believe: `max' is involved
2841 (list 'label-in-block-min-indent (point))))
2843 (list 'statement-in-block (point))))))
2844 ;; If no previous statement,
2845 ;; indent it relative to line brace is on.
2846 ;; For open brace in column zero, don't let statement
2847 ;; start there too. If cperl-indent-level is zero,
2848 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
2849 ;; For open-braces not the first thing in a line,
2850 ;; add in cperl-brace-imaginary-offset.
2852 ;; If first thing on a line: ?????
2853 (+ (if (and (bolp) (zerop cperl-indent-level))
2854 (+ cperl-brace-offset cperl-continued-statement-offset)
2856 ;; Move back over whitespace before the openbrace.
2857 ;; If openbrace is not first nonwhite thing on the line,
2858 ;; add the cperl-brace-imaginary-offset.
2859 (progn (skip-chars-backward " \t")
2860 (if (bolp) 0 cperl-brace-imaginary-offset))
2861 ;; If the openbrace is preceded by a parenthesized exp,
2862 ;; move to the beginning of that;
2863 ;; possibly a different line
2865 (if (eq (preceding-char) ?\))
2867 ;; Get initial indentation of the line we are on.
2868 ;; If line starts with label, calculate label indentation
2871 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
2872 (if (> (current-indentation) cperl-min-label-indent)
2873 (- (current-indentation) cperl-label-offset)
2874 (cperl-calculate-indent))
2875 (current-indentation))))))))
2878 (defun cperl-calculate-indent-within-comment ()
2879 "Return the indentation amount for line, assuming that
2880 the current line is to be regarded as part of a block comment."
2881 (let (end star-start)
2884 (skip-chars-forward " \t")
2886 (and (= (following-char) ?#)
2888 (cperl-to-comment-or-eol)
2894 (defun cperl-to-comment-or-eol ()
2895 "Go to position before comment on the current line, or to end of line.
2896 Returns true if comment is found."
2897 (let (state stop-in cpoint (lim (progn (end-of-line) (point))))
2900 (eq (get-text-property (point) 'syntax-type) 'pod)
2901 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t))
2902 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
2904 (while (not stop-in)
2905 (setq state (parse-partial-sexp (point) lim nil nil nil t))
2907 ;; If fails (beginning-of-line inside sexp), then contains not-comment
2908 (if (nth 4 state) ; After `#';
2909 ; (nth 2 state) can be
2910 ; beginning of m,s,qq and so
2914 (setq cpoint (point))
2915 (goto-char (nth 2 state))
2917 ((looking-at "\\(s\\|tr\\)\\>")
2918 (or (re-search-forward
2919 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
2922 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
2923 (or (re-search-forward
2924 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
2927 (t ; It was fair comment
2928 (setq stop-in t) ; Finish
2929 (goto-char (1- cpoint)))))
2930 (setq stop-in t) ; Finish
2932 (setq stop-in t)) ; Finish
2936 (defsubst cperl-1- (p)
2937 (max (point-min) (1- p)))
2939 (defsubst cperl-1+ (p)
2940 (min (point-max) (1+ p)))
2942 (defsubst cperl-modify-syntax-type (at how)
2943 (if (< at (point-max))
2945 (put-text-property at (1+ at) 'syntax-table how)
2946 (put-text-property at (1+ at) 'rear-nonsticky t))))
2948 (defun cperl-protect-defun-start (s e)
2949 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
2952 (while (re-search-forward "^\\s(" e 'to-end)
2953 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
2955 (defun cperl-commentify (bb e string &optional noface)
2956 (if cperl-use-syntax-table-text-property
2957 (if (eq noface 'n) ; Only immediate
2959 ;; We suppose that e is _after_ the end of construction, as after eol.
2960 (setq string (if string cperl-st-sfence cperl-st-cfence))
2962 ;; one-char string/comment?!
2963 (cperl-modify-syntax-type bb cperl-st-punct)
2964 (cperl-modify-syntax-type bb string)
2965 (cperl-modify-syntax-type (1- e) string))
2966 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
2967 (put-text-property (1+ bb) (1- e)
2968 'syntax-table cperl-string-syntax-table))
2969 (cperl-protect-defun-start bb e))
2972 (not cperl-pod-here-fontify)
2973 (put-text-property bb e 'face (if string 'font-lock-string-face
2974 'font-lock-comment-face)))))
2976 (defvar cperl-starters '(( ?\( . ?\) )
2981 (defun cperl-forward-re (lim end is-2arg set-st st-l err-l argument
2982 &optional ostart oend)
2983 ;; Works *before* syntax recognition is done
2984 ;; May modify syntax-type text property if the situation is too hard
2985 (let (b starter ender st i i2 go-forward reset-st)
2986 (skip-chars-forward " \t")
2987 ;; ender means matching-char matcher.
2989 starter (if (eobp) 0 (char-after b))
2990 ender (cdr (assoc starter cperl-starters)))
2991 ;; What if starter == ?\\ ????
2994 (setq st (car st-l))
2995 (setcar st-l (make-syntax-table))
2996 (setq i 0 st (car st-l))
2998 (modify-syntax-entry i "." st)
3000 (modify-syntax-entry ?\\ "\\" st)))
3002 ;; Whether we have an intermediate point
3004 ;; Prepare the syntax table:
3006 (if (not ender) ; m/blah/, s/x//, s/x/y/
3007 (modify-syntax-entry starter "$" st)
3008 (modify-syntax-entry starter (concat "(" (list ender)) st)
3009 (modify-syntax-entry ender (concat ")" (list starter)) st)))
3012 ;; We use `$' syntax class to find matching stuff, but $$
3013 ;; is recognized the same as $, so we need to check this manually.
3014 (if (and (eq starter (char-after (cperl-1+ b)))
3016 ;; $ has TeXish matching rules, so $$ equiv $...
3018 (setq reset-st (syntax-table))
3019 (set-syntax-table st)
3021 (if (<= (point) (1+ b))
3022 (error "Unfinished regular expression"))
3023 (set-syntax-table reset-st)
3025 ;; Now the problem is with m;blah;;
3027 (eq (preceding-char)
3028 (char-after (- (point) 2)))
3031 (= 0 (% (skip-chars-backward "\\\\") 2)))
3033 ;; Now we are after the first part.
3034 (and is-2arg ; Have trailing part
3036 (eq (following-char) starter) ; Empty trailing part
3038 (or (eq (char-syntax (following-char)) ?.)
3039 ;; Make trailing letter into punctuation
3040 (cperl-modify-syntax-type (point) cperl-st-punct))
3041 (setq is-2arg nil go-forward t))) ; Ignore the tail
3042 (if is-2arg ; Not number => have second part
3044 (setq i (point) i2 i)
3046 (if (memq (following-char) '(?\ ?\t ?\n ?\f))
3048 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3049 (goto-char (match-end 0))
3050 (skip-chars-forward " \t\n\f"))
3053 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3054 (if ender (modify-syntax-entry ender "." st))
3056 (setq ender (cperl-forward-re lim end nil t st-l err-l
3057 argument starter ender)
3058 ender (nth 2 ender)))))
3059 (error (goto-char lim)
3062 (set-syntax-table reset-st))
3065 "End of `%s%s%c ... %c' string/RE not found: %s"
3067 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
3068 starter (or ender starter) bb)
3069 (or (car err-l) (setcar err-l b)))))
3072 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3073 (if ender (modify-syntax-entry ender "." st))))
3074 ;; i: have 2 args, after end of the first arg
3075 ;; i2: start of the second arg, if any (before delim iff `ender').
3076 ;; ender: the last arg bounded by parens-like chars, the second one of them
3077 ;; starter: the starting delimiter of the first arg
3078 ;; go-forward: has 2 args, and the second part is empty
3079 (list i i2 ender starter go-forward)))
3081 (defsubst cperl-postpone-fontification (b e type val &optional now)
3082 ;; Do after syntactic fontification?
3083 (if cperl-syntaxify-by-font-lock
3084 (or now (put-text-property b e 'cperl-postpone (cons type val)))
3085 (put-text-property b e type val)))
3087 ;;; Here is how the global structures (those which cannot be
3088 ;;; recognized locally) are marked:
3090 ;; Start-to-end is marked `in-pod' ==> t
3091 ;; Each non-literal part is marked `syntax-type' ==> `pod'
3092 ;; Each literal part is marked `syntax-type' ==> `in-pod'
3094 ;; Start-to-end is marked `here-doc-group' ==> t
3095 ;; The body is marked `syntax-type' ==> `here-doc'
3096 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
3098 ;; After-initial-line--to-end is marked `syntax-type' ==> `format'
3099 ;; d) 'Q'uoted string:
3100 ;; part between markers inclusive is marked `syntax-type' ==> `string'
3101 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
3103 (defun cperl-unwind-to-safe (before &optional end)
3104 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
3105 (let ((pos (point)) opos)
3107 (while (and pos (get-text-property pos 'syntax-type))
3108 (setq pos (previous-single-property-change pos 'syntax-type))
3112 (goto-char (cperl-1- pos))
3115 (goto-char (setq pos (cperl-1- pos))))
3117 (goto-char (point-min))))
3119 (and (looking-at "\n*=")
3120 (/= 0 (skip-chars-backward "\n"))
3124 ;; Do the same for end, going small steps
3126 (while (and end (get-text-property end 'syntax-type))
3128 end (next-single-property-change end 'syntax-type)))
3131 (defvar cperl-nonoverridable-face)
3132 (defvar font-lock-function-name-face)
3133 (defvar font-lock-comment-face)
3135 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max)
3136 "Scans the buffer for hard-to-parse Perl constructions.
3137 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
3138 the sections using `cperl-pod-head-face', `cperl-pod-face',
3141 (or min (setq min (point-min)
3142 cperl-syntax-state nil
3143 cperl-syntax-done-to min))
3144 (or max (setq max (point-max)))
3145 (let* (face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
3146 is-REx is-x-REx REx-comment-start REx-comment-end was-comment i2
3147 (cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
3148 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
3149 (modified (buffer-modified-p))
3150 (after-change-functions nil)
3151 (use-syntax-state (and cperl-syntax-state
3152 (>= min (car cperl-syntax-state))))
3153 (state-point (if use-syntax-state
3154 (car cperl-syntax-state)
3156 (state (if use-syntax-state
3157 (cdr cperl-syntax-state)))
3158 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
3159 (st-l (list nil)) (err-l (list nil))
3160 ;; Somehow font-lock may be not loaded yet...
3161 (font-lock-string-face (if (boundp 'font-lock-string-face)
3162 font-lock-string-face
3163 'font-lock-string-face))
3164 (font-lock-constant-face (if (boundp 'font-lock-constant-face)
3165 font-lock-constant-face
3166 'font-lock-constant-face))
3167 (font-lock-function-name-face
3168 (if (boundp 'font-lock-function-name-face)
3169 font-lock-function-name-face
3170 'font-lock-function-name-face))
3171 (font-lock-comment-face
3172 (if (boundp 'font-lock-comment-face)
3173 font-lock-comment-face
3174 'font-lock-comment-face))
3175 (cperl-nonoverridable-face
3176 (if (boundp 'cperl-nonoverridable-face)
3177 cperl-nonoverridable-face
3178 'cperl-nonoverridable-face))
3179 (stop-point (if ignore-max
3184 "\\(\\`\n?\\|^\n\\)="
3186 ;; One extra () before this:
3189 ;; First variant "BLAH" or just ``.
3190 "[ \t]*" ; Yes, whitespace is allowed!
3191 "\\([\"'`]\\)" ; 2 + 1 = 3
3192 "\\([^\"'`\n]*\\)" ; 3 + 1
3195 ;; Second variant: Identifier or \ID or empty
3196 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3197 ;; Do not have <<= or << 30 or <<30 or << $blah.
3198 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3199 "\\(\\)" ; To preserve count of pars :-( 6 + 1
3202 ;; 1+6 extra () before this:
3203 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
3204 (if cperl-use-syntax-table-text-property
3207 ;; 1+6+2=9 extra () before this:
3208 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
3210 ;; 1+6+2+1=10 extra () before this:
3211 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3213 ;; 1+6+2+1+1=11 extra () before this:
3214 "\\<sub\\>[ \t]*\\([a-zA-Z_:'0-9]+[ \t]*\\)?\\(([^()]*)\\)"
3216 ;; 1+6+2+1+1+2=13 extra () before this:
3219 ;; 1+6+2+1+1+2+1=14 extra () before this:
3220 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
3221 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
3223 "__\\(END\\|DATA\\)__"
3224 ;; 1+6+2+1+1+2+1+1+1=16 extra () before this:
3233 (message "Scanning for \"hard\" Perl constructions..."))
3234 (and cperl-pod-here-fontify
3235 ;; We had evals here, do not know why...
3236 (setq face cperl-pod-face
3237 head-face cperl-pod-head-face
3238 here-face cperl-here-face))
3239 (remove-text-properties min max
3240 '(syntax-type t in-pod t syntax-table t
3245 ;; Need to remove face as well...
3247 (and (eq system-type 'emx)
3248 (looking-at "extproc[ \t]") ; Analogue of #!
3249 (cperl-commentify min
3250 (save-excursion (end-of-line) (point))
3254 (re-search-forward search max t))
3255 (setq tmpend nil) ; Valid for most cases
3257 ((match-beginning 1) ; POD section
3258 ;; "\\(\\`\n?\\|^\n\\)="
3259 (if (looking-at "cut\\>")
3261 nil ; Doing a chunk only
3262 (message "=cut is not preceded by a POD section")
3263 (or (car err-l) (setcar err-l (point))))
3268 tb (match-beginning 0)
3269 b1 nil) ; error condition
3270 ;; We do not search to max, since we may be called from
3271 ;; some hook of fontification, and max is random
3272 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
3275 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
3277 (message "=cut is not preceded by an empty line")
3279 (or (car err-l) (setcar err-l b))))))
3280 (beginning-of-line 2) ; An empty line after =cut is not POD!
3284 (remove-text-properties
3285 max e '(syntax-type t in-pod t syntax-table t
3291 (put-text-property b e 'in-pod t)
3292 (put-text-property b e 'syntax-type 'in-pod)
3294 (while (re-search-forward "\n\n[ \t]" e t)
3295 ;; We start 'pod 1 char earlier to include the preceding line
3297 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
3298 (cperl-put-do-not-fontify b (point) t)
3299 ;; mark the non-literal parts as PODs
3300 (if cperl-pod-here-fontify
3301 (cperl-postpone-fontification b (point) 'face face t))
3302 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
3305 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
3306 (cperl-put-do-not-fontify (point) e t)
3307 (if cperl-pod-here-fontify
3309 ;; mark the non-literal parts as PODs
3310 (cperl-postpone-fontification (point) e 'face face t)
3313 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
3315 (cperl-postpone-fontification
3316 (match-beginning 1) (match-end 1)
3318 (while (re-search-forward
3320 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
3323 (cperl-postpone-fontification
3324 (match-beginning 1) (match-end 1)
3326 (cperl-commentify bb e nil)
3328 (or (eq e (point-max))
3329 (forward-char -1)))) ; Prepare for immediate pod start.
3331 ;; We do only one here-per-line
3332 ;; ;; One extra () before this:
3335 ;; ;; First variant "BLAH" or just ``.
3336 ;; "\\([\"'`]\\)" ; 2 + 1
3337 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
3340 ;; ;; Second variant: Identifier or \ID or empty
3341 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3342 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
3343 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3344 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
3346 ((match-beginning 2) ; 1 + 1
3347 ;; Abort in comment:
3349 (setq state (parse-partial-sexp state-point b nil nil state)
3351 tb (match-beginning 0)
3352 i (or (nth 3 state) (nth 4 state)))
3357 (not (match-beginning 6)) ; Empty
3359 "[ \t]*[=0-9$@%&(]"))))
3360 (if c ; Not here-doc
3362 (if (match-beginning 5) ;4 + 1
3363 (setq b1 (match-beginning 5) ; 4 + 1
3364 e1 (match-end 5)) ; 4 + 1
3365 (setq b1 (match-beginning 4) ; 3 + 1
3366 e1 (match-end 4))) ; 3 + 1
3367 (setq tag (buffer-substring b1 e1)
3368 qtag (regexp-quote tag))
3369 (cond (cperl-pod-here-fontify
3370 ;; Highlight the starting delimiter
3371 (cperl-postpone-fontification b1 e1 'face font-lock-constant-face)
3372 (cperl-put-do-not-fontify b1 e1 t)))
3375 ;; We do not search to max, since we may be called from
3376 ;; some hook of fontification, and max is random
3377 (cond ((re-search-forward (concat "^" qtag "$")
3379 (if cperl-pod-here-fontify
3381 ;; Highlight the ending delimiter
3382 (cperl-postpone-fontification (match-beginning 0) (match-end 0)
3383 'face font-lock-constant-face)
3384 (cperl-put-do-not-fontify b (match-end 0) t)
3385 ;; Highlight the HERE-DOC
3386 (cperl-postpone-fontification b (match-beginning 0)
3388 (setq e1 (cperl-1+ (match-end 0)))
3389 (put-text-property b (match-beginning 0)
3390 'syntax-type 'here-doc)
3391 (put-text-property (match-beginning 0) e1
3392 'syntax-type 'here-doc-delim)
3393 (put-text-property b e1
3395 (cperl-commentify b e1 nil)
3396 (cperl-put-do-not-fontify b (match-end 0) t)
3399 (t (message "End of here-document `%s' not found." tag)
3400 (or (car err-l) (setcar err-l b))))))
3402 ((match-beginning 8)
3403 ;; 1+6=7 extra () before this:
3404 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
3406 name (if (match-beginning 8) ; 7 + 1
3407 (buffer-substring (match-beginning 8) ; 7 + 1
3408 (match-end 8)) ; 7 + 1
3410 tb (match-beginning 0))
3412 (if cperl-pod-here-fontify
3413 (while (and (eq (forward-line) 0)
3414 (not (looking-at "^[.;]$")))
3416 ((looking-at "^#")) ; Skip comments
3417 ((and argument ; Skip argument multi-lines
3418 (looking-at "^[ \t]*{"))
3420 (setq argument nil))
3421 (argument ; Skip argument lines
3422 (setq argument nil))
3425 (setq argument (looking-at "^[^\n]*[@^]"))
3427 ;; Highlight the format line
3428 (cperl-postpone-fontification b1 (point)
3429 'face font-lock-string-face)
3430 (cperl-commentify b1 (point) nil)
3431 (cperl-put-do-not-fontify b1 (point) t))))
3432 ;; We do not search to max, since we may be called from
3433 ;; some hook of fontification, and max is random
3434 (re-search-forward "^[.;]$" stop-point 'toend))
3436 (if (looking-at "^\\.$") ; ";" is not supported yet
3438 ;; Highlight the ending delimiter
3439 (cperl-postpone-fontification (point) (+ (point) 2)
3440 'face font-lock-string-face)
3441 (cperl-commentify (point) (+ (point) 2) nil)
3442 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
3443 (message "End of format `%s' not found." name)
3444 (or (car err-l) (setcar err-l b)))
3448 (put-text-property b (point) 'syntax-type 'format))
3450 ((or (match-beginning 10) (match-beginning 11))
3451 ;; 1+6+2=9 extra () before this:
3452 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
3454 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3455 (setq b1 (if (match-beginning 10) 10 11)
3456 argument (buffer-substring
3457 (match-beginning b1) (match-end b1))
3460 c (char-after (match-beginning b1))
3461 bb (char-after (1- (match-beginning b1))) ; tmp holder
3462 ;; bb == "Not a stringy"
3463 bb (if (eq b1 10) ; user variables/whatever
3465 (memq bb '(?\$ ?\@ ?\% ?\* ?\#)) ; $#y
3466 (and (eq bb ?-) (eq c ?s)) ; -s file test
3468 (not (eq (char-after ; &&m/blah/
3469 (- (match-beginning b1) 2))
3471 ;; <file> or <$file>
3473 ;; Do not stringify <FH>, <$fh> :
3476 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
3477 tb (match-beginning 0))
3478 (goto-char (match-beginning b1))
3479 (cperl-backward-to-noncomment (point-min))
3481 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
3486 ;; What is below: regexp-p?
3488 (or (memq (preceding-char)
3489 (append (if (memq c '(?\? ?\<))
3492 "~{(=|&+-*!,;:") nil))
3493 (and (eq (preceding-char) ?\})
3494 (cperl-after-block-p (point-min)))
3495 (and (eq (char-syntax (preceding-char)) ?w)
3498 ;; After these keywords `/' starts a RE. One should add all the
3499 ;; functions/builtins which expect an argument, but ...
3500 (if (eq (preceding-char) ?-)
3502 (looking-at "[a-zA-Z]\\>")
3504 (not (memq (preceding-char)
3507 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
3508 (and (eq (preceding-char) ?.)
3509 (eq (char-after (- (point) 2)) ?.))
3511 ;; m|blah| ? foo : bar;
3514 cperl-use-syntax-table-text-property
3518 (looking-at "\\s|")))))))
3522 (if (and (eq (preceding-char) ?>)
3523 (eq (char-after (- (point) 2)) ?-))
3526 (or bb (setq state (parse-partial-sexp
3527 state-point b nil nil state)
3530 (if (or bb (nth 3 state) (nth 4 state))
3532 ;; Skip whitespace and comments...
3533 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3534 (goto-char (match-end 0))
3535 (skip-chars-forward " \t\n\f"))
3537 (put-text-property b (point) 'syntax-type 'prestring))
3538 ;; qtag means two-arg matcher, may be reset to
3539 ;; 2 or 3 later if some special quoting is needed.
3540 ;; e1 means matching-char matcher.
3543 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
3544 ;; We do not search to max, since we may be called from
3545 ;; some hook of fontification, and max is random
3546 i (cperl-forward-re stop-point end
3548 t st-l err-l argument)
3549 ;; Note that if `go', then it is considered as 1-arg
3550 b1 (nth 1 i) ; start of the second part
3551 tag (nth 2 i) ; ender-char, true if second part
3552 ; is with matching chars []
3553 go (nth 4 i) ; There is a 1-char part after the end
3554 i (car i) ; intermediate point
3556 ;; Before end of the second part if non-matching: ///
3557 tail (if (and i (not tag))
3559 e (if i i e1) ; end of the first part
3560 qtag nil ; need to preserve backslashitis
3561 is-x-REx nil) ; REx has //x modifier
3562 ;; Commenting \\ is dangerous, what about ( ?
3564 (eq (char-after i) ?\\)
3566 (if (looking-at "\\sw*x") ; qr//x
3569 ;; Considered as 1arg form
3571 (cperl-commentify b (point) t)
3572 (put-text-property b (point) 'syntax-type 'string)
3574 ;; ignore other text properties:
3575 (string-match "^qw$" argument))
3576 (put-text-property b (point) 'indentable t))
3578 (setq e1 (cperl-1+ e1))
3581 (cperl-commentify b i t)
3582 (if (looking-at "\\sw*e") ; s///e
3586 (cperl-find-pods-heres b1 (1- (point)) t end)
3588 (goto-char (1+ max)))
3589 (if (and tag (eq (preceding-char) ?\>))
3591 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
3592 (cperl-modify-syntax-type i cperl-st-bra)))
3593 (put-text-property b i 'syntax-type 'string)
3595 (put-text-property b i 'indentable t)))
3596 (cperl-commentify b1 (point) t)
3597 (put-text-property b (point) 'syntax-type 'string)
3599 (put-text-property b i 'indentable t))
3601 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
3603 ;; Now: tail: if the second part is non-matching without ///e
3604 (if (eq (char-syntax (following-char)) ?w)
3606 (forward-word 1) ; skip modifiers s///s
3607 (if tail (cperl-commentify tail (point) t))
3608 (cperl-postpone-fontification
3609 e1 (point) 'face 'cperl-nonoverridable-face)))
3610 ;; Check whether it is m// which means "previous match"
3611 ;; and highlight differently
3613 (and (string-match "^\\([sm]?\\|qr\\)$" argument)
3614 (or (not (= (length argument) 0))
3618 ;; split // *is* using zero-pattern
3624 (not (looking-at "split\\>")))
3626 (cperl-postpone-fontification
3627 b e 'face font-lock-function-name-face)
3628 (if (or i2 ; Has 2 args
3629 (and cperl-fontify-m-as-s
3631 (string-match "^\\(m\\|qr\\)$" argument)
3632 (and (eq 0 (length argument))
3633 (not (eq ?\< (char-after b)))))))
3635 (cperl-postpone-fontification
3636 b (cperl-1+ b) 'face font-lock-constant-face)
3637 (cperl-postpone-fontification
3638 (1- e) e 'face font-lock-constant-face)))
3639 (if (and is-REx cperl-regexp-scan)
3640 ;; Process RExen better
3647 (if (eq (char-after b) ?\#)
3648 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
3649 "\\((\\?#\\)\\|\\(#\\)")
3650 (if (eq (char-after b) ?\#)
3654 (goto-char (match-beginning 0))
3655 (setq REx-comment-start (point)
3659 ;; XXX not working if outside delimiter is #
3660 (eq (preceding-char) ?\\)
3661 (= (% (skip-chars-backward "$\\\\") 2) -1)))
3662 ;; Not a comment, avoid loop:
3663 (progn (setq was-comment nil)
3665 (if (match-beginning 2)
3667 (beginning-of-line 2)
3669 (goto-char (1- e))))
3670 ;; Works also if the outside delimiters are ().
3671 (or (search-forward ")" (1- e) 'toend)
3673 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
3674 REx-comment-start))))
3679 (setq REx-comment-end (point))
3681 REx-comment-start REx-comment-end nil)
3682 (cperl-postpone-fontification
3683 REx-comment-start REx-comment-end
3684 'face font-lock-comment-face))))))
3685 (if (and is-REx is-x-REx)
3686 (put-text-property (1+ b) (1- e)
3687 'syntax-subtype 'x-REx)))
3690 (cperl-postpone-fontification
3691 (1- e1) e1 'face font-lock-constant-face)
3692 (if (assoc (char-after b) cperl-starters)
3693 (cperl-postpone-fontification
3694 b1 (1+ b1) 'face font-lock-constant-face))))
3697 ((match-beginning 13) ; sub with prototypes
3698 (setq b (match-beginning 0))
3699 (if (memq (char-after (1- b))
3700 '(?\$ ?\@ ?\% ?\& ?\*))
3702 (setq state (parse-partial-sexp
3703 state-point b nil nil state)
3705 (if (or (nth 3 state) (nth 4 state))
3708 (cperl-commentify (match-beginning 13) (match-end 13) t))
3709 (goto-char (match-end 0))))
3710 ;; 1+6+2+1+1+2=13 extra () before this:
3712 ((and (match-beginning 14)
3713 (eq (preceding-char) ?\')) ; $'
3714 (setq b (1- (point))
3715 state (parse-partial-sexp
3716 state-point (1- b) nil nil state)
3718 (if (nth 3 state) ; in string
3719 (cperl-modify-syntax-type (1- b) cperl-st-punct))
3721 ;; 1+6+2+1+1+2=13 extra () before this:
3723 ((match-beginning 14) ; ${
3724 (setq bb (match-beginning 0))
3725 (cperl-modify-syntax-type bb cperl-st-punct))
3726 ;; 1+6+2+1+1+2+1=14 extra () before this:
3727 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
3728 ((match-beginning 15) ; old $abc'efg syntax
3729 (setq bb (match-end 0)
3730 b (match-beginning 0)
3731 state (parse-partial-sexp
3732 state-point b nil nil state)
3734 (if (nth 3 state) ; in string
3736 (put-text-property (1- bb) bb 'syntax-table cperl-st-word))
3738 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
3739 ;; "__\\(END\\|DATA\\)__"
3740 ((match-beginning 16) ; __END__, __DATA__
3741 (setq bb (match-end 0)
3742 b (match-beginning 0)
3743 state (parse-partial-sexp
3744 state-point b nil nil state)
3746 (if (or (nth 3 state) (nth 4 state))
3748 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
3749 (cperl-commentify b bb nil)
3752 ((match-beginning 17) ; "\\\\\\(['`\"]\\)"
3753 (setq bb (match-end 0)
3754 b (match-beginning 0))
3756 (skip-chars-backward "\\\\")
3757 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
3758 (setq state (parse-partial-sexp
3759 state-point b nil nil state)
3761 (if (or (nth 3 state) (nth 4 state) )
3763 (cperl-modify-syntax-type b cperl-st-punct))
3765 (t (error "Error in regexp of the sniffer")))
3766 (if (> (point) stop-point)
3769 (message "Garbage after __END__/__DATA__ ignored")
3770 (message "Unbalanced syntax found while scanning")
3771 (or (car err-l) (setcar err-l b)))
3772 (goto-char stop-point))))
3773 (setq cperl-syntax-state (cons state-point state)
3774 cperl-syntax-done-to (or tmpend (max (point) max))))
3775 (if (car err-l) (goto-char (car err-l))
3777 (message "Scanning for \"hard\" Perl constructions... done"))))
3778 (and (buffer-modified-p)
3780 (set-buffer-modified-p nil))
3781 (set-syntax-table cperl-mode-syntax-table))
3784 (defun cperl-backward-to-noncomment (lim)
3785 ;; Stops at lim or after non-whitespace that is not in comment
3787 (while (and (not stop) (> (point) (or lim 1)))
3788 (skip-chars-backward " \t\n\f" lim)
3791 (if (memq (setq pr (get-text-property (point) 'syntax-type))
3792 '(pod here-doc here-doc-delim))
3793 (cperl-unwind-to-safe nil)
3794 (if (or (looking-at "^[ \t]*\\(#\\|$\\)")
3795 (progn (cperl-to-comment-or-eol) (bolp)))
3796 nil ; Only comment, skip
3798 (skip-chars-backward " \t")
3799 (if (< p (point)) (goto-char p))
3802 (defun cperl-after-block-p (lim)
3803 ;; We suppose that the preceding char is }.
3808 (cperl-backward-to-noncomment lim)
3809 (or (eq (point) lim)
3810 (eq (preceding-char) ?\) ) ; if () {} sub f () {}
3811 (if (eq (char-syntax (preceding-char)) ?w) ; else {}
3814 (or (looking-at "\\(else\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
3817 (cperl-backward-to-noncomment lim)
3818 (and (eq (char-syntax (preceding-char)) ?w)
3821 (looking-at "sub\\>"))))))
3822 (cperl-after-expr-p lim))))
3825 (defun cperl-after-expr-p (&optional lim chars test)
3826 "Return true if the position is good for start of expression.
3827 TEST is the expression to evaluate at the found position. If absent,
3828 CHARS is a string that contains good characters to have before us (however,
3829 `}' is treated \"smartly\" if it is not in the list)."
3831 (lim (or lim (point-min))))
3833 (while (and (not stop) (> (point) lim))
3834 (skip-chars-backward " \t\n\f" lim)
3837 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
3838 ;; Else: last iteration, or a label
3839 (cperl-to-comment-or-eol)
3840 (skip-chars-backward " \t")
3841 (if (< p (point)) (goto-char p))
3843 (if (and (eq (preceding-char) ?:)
3846 (skip-chars-backward " \t\n\f" lim)
3847 (eq (char-syntax (preceding-char)) ?w)))
3848 (forward-sexp -1) ; Possibly label. Skip it
3851 (or (bobp) ; ???? Needed
3853 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
3855 (if test (eval test)
3856 (or (memq (preceding-char) (append (or chars "{;") nil))
3857 (and (eq (preceding-char) ?\})
3858 (cperl-after-block-p lim)))))))))
3860 (defun cperl-backward-to-start-of-continued-exp (lim)
3861 (if (memq (preceding-char) (append ")]}\"'`" nil))
3864 (if (<= (point) lim)
3865 (goto-char (1+ lim)))
3866 (skip-chars-forward " \t"))
3868 (defun cperl-after-block-and-statement-beg (lim)
3869 ;; We assume that we are after ?\}
3871 (cperl-after-block-p lim)
3874 (cperl-backward-to-noncomment (point-min))
3877 (not (= (char-syntax (preceding-char)) ?w))
3882 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
3885 (defun cperl-indent-exp ()
3886 "Simple variant of indentation of continued-sexp.
3888 Will not indent comment if it starts at `comment-indent' or looks like
3889 continuation of the comment on the previous line.
3891 If `cperl-indent-region-fix-constructs', will improve spacing on
3892 conditional/loop constructs."
3895 (let ((tmp-end (progn (end-of-line) (point))) top done)
3900 (while (= (nth 0 (parse-partial-sexp (point) tmp-end
3902 (setq top (point))) ; Get the outermost parenths in line
3904 (while (< (point) tmp-end)
3905 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
3906 (or (eolp) (forward-sexp 1)))
3907 (if (> (point) tmp-end)
3910 (setq tmp-end (point)))
3913 (setq tmp-end (point-marker)))
3914 (if cperl-indent-region-fix-constructs
3915 (cperl-fix-line-spacing tmp-end))
3916 (cperl-indent-region (point) tmp-end))))
3918 (defun cperl-fix-line-spacing (&optional end parse-data)
3919 "Improve whitespace in a conditional/loop construct.
3920 Returns some position at the last line."
3923 (setq end (point-max)))
3924 (let (p pp ml have-brace ret
3925 (ee (save-excursion (end-of-line) (point)))
3926 (cperl-indent-region-fix-constructs
3927 (or cperl-indent-region-fix-constructs 1)))
3934 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
3935 (setq have-brace (save-excursion (search-forward "}" ee t)))))
3936 nil ; Do not need to do anything
3940 (if (and cperl-merge-trailing-else
3942 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>"))
3944 (search-forward "}")
3946 (skip-chars-forward " \t\n")
3947 (delete-region p (point))
3948 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
3949 (beginning-of-line)))
3952 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
3954 (search-forward "}")
3955 (delete-horizontal-space)
3956 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
3957 (beginning-of-line)))
3961 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
3964 (delete-horizontal-space)
3965 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
3966 (beginning-of-line)))
3970 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
3973 (delete-horizontal-space)
3974 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
3975 (beginning-of-line)))
3977 ;; foreach my $var (
3979 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
3982 (delete-horizontal-space)
3984 (make-string cperl-indent-region-fix-constructs ?\ ))
3985 (beginning-of-line)))
3987 ;; } foreach my $var () {
3989 "[ \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]*{")
3991 (setq ml (match-beginning 8))
3992 (re-search-forward "[({]")
3995 (if (eq (following-char) ?\( )
3999 ;; after `else' or nothing
4000 (if ml ; after `else'
4001 (skip-chars-backward " \t\n")
4002 (beginning-of-line))
4004 ;; Now after the sexp before the brace
4005 ;; Multiline expr should be special
4006 (setq ml (and pp (save-excursion (goto-char p)
4007 (search-forward "\n" pp t))))
4008 (if (and (or (not pp) (< pp end))
4009 (looking-at "[ \t\n]*{"))
4012 ((bolp) ; Were before `{', no if/else/etc
4014 ((looking-at "\\(\t*\\| [ \t]+\\){")
4015 (delete-horizontal-space)
4017 cperl-extra-newline-before-brace-multiline
4018 cperl-extra-newline-before-brace)
4020 (delete-horizontal-space)
4023 (if (cperl-indent-line parse-data)
4025 (cperl-fix-line-spacing end parse-data)
4026 (setq ret (point)))))
4028 (make-string cperl-indent-region-fix-constructs ?\ ))))
4029 ((and (looking-at "[ \t]*\n")
4031 cperl-extra-newline-before-brace-multiline
4032 cperl-extra-newline-before-brace)))
4034 (skip-chars-forward " \t\n")
4035 (delete-region pp (point))
4037 (make-string cperl-indent-region-fix-constructs ?\ ))))
4038 ;; Now we are before `{'
4039 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
4041 (skip-chars-forward " \t\n")
4046 (setq ml (search-forward "\n" p t))
4047 (if (or cperl-break-one-line-blocks-when-indent ml)
4048 ;; not good: multi-line BLOCK
4051 (delete-horizontal-space)
4054 (if (cperl-indent-line parse-data)
4055 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
4057 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
4058 ;; Now check whether there is a hanging `}'
4062 cperl-fix-hanging-brace-when-indent
4064 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
4068 (if (and (<= (point) pp)
4069 (eq (preceding-char) ?\} )
4070 (cperl-after-block-and-statement-beg (point-min)))
4077 (skip-chars-backward " \t")
4079 ;; `}' was the first thing on the line, insert NL *after* it.
4081 (cperl-indent-line parse-data)
4082 (search-forward "}")
4083 (delete-horizontal-space)
4085 (delete-horizontal-space)
4086 (or (eq (preceding-char) ?\;)
4088 (and (eq (preceding-char) ?\} )
4089 (cperl-after-block-p (point-min)))
4093 (if (cperl-indent-line parse-data)
4094 (setq ret (cperl-fix-line-spacing end parse-data)))
4095 (beginning-of-line)))))
4098 (defvar cperl-update-start) ; Do not need to make them local
4099 (defvar cperl-update-end)
4100 (defun cperl-delay-update-hook (beg end old-len)
4101 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
4102 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
4104 (defun cperl-indent-region (start end)
4105 "Simple variant of indentation of region in CPerl mode.
4106 Should be slow. Will not indent comment if it starts at `comment-indent'
4107 or looks like continuation of the comment on the previous line.
4108 Indents all the lines whose first character is between START and END
4111 If `cperl-indent-region-fix-constructs', will improve spacing on
4112 conditional/loop constructs."
4114 (cperl-update-syntaxification end end)
4116 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
4117 (let (st comm old-comm-indent new-comm-indent p pp i empty
4118 (indent-info (if cperl-emacs-can-parse
4119 (list nil nil nil) ; Cannot use '(), since will modify
4121 after-change-functions ; Speed it up!
4122 (pm 0) (imenu-scanning-message "Indenting... (%3d%%)"))
4123 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
4125 (setq old-comm-indent (and (cperl-to-comment-or-eol)
4127 new-comm-indent old-comm-indent)
4129 (setq end (set-marker (make-marker) end)) ; indentation changes pos
4130 (or (bolp) (beginning-of-line 2))
4131 (or (fboundp 'imenu-progress-message)
4132 (message "Indenting... For feedback load `imenu'..."))
4133 (while (and (<= (point) end) (not (eobp))) ; bol to check start
4134 (and (fboundp 'imenu-progress-message)
4135 (imenu-progress-message
4136 pm (/ (* 100 (- (point) start)) (- end start -1))))
4139 (setq empty (looking-at "[ \t]*\n"))
4140 (and (setq comm (looking-at "[ \t]*#"))
4141 (or (eq (current-indentation) (or old-comm-indent
4143 (setq old-comm-indent nil))))
4144 (if (and old-comm-indent
4146 (= (current-indentation) old-comm-indent)
4147 (not (eq (get-text-property (point) 'syntax-type) 'pod))
4148 (not (eq (get-text-property (point) 'syntax-table)
4150 (let ((comment-column new-comm-indent))
4151 (indent-for-comment)))
4153 (setq i (cperl-indent-line indent-info))
4157 (if cperl-indent-region-fix-constructs
4158 (goto-char (cperl-fix-line-spacing end indent-info)))
4159 (if (setq old-comm-indent
4160 (and (cperl-to-comment-or-eol)
4161 (not (memq (get-text-property (point)
4164 (not (eq (get-text-property (point)
4168 (progn (indent-for-comment)
4169 (skip-chars-backward " \t")
4170 (skip-chars-backward "#")
4171 (setq new-comm-indent (current-column))))))))
4172 (beginning-of-line 2))
4173 (if (fboundp 'imenu-progress-message)
4174 (imenu-progress-message pm 100)
4176 ;; Now run the update hooks
4177 (if after-change-functions
4179 (if cperl-update-end
4181 (goto-char cperl-update-end)
4184 (goto-char cperl-update-start)
4186 (delete-char -1))))))))
4188 ;; Stolen from lisp-mode with a lot of improvements
4190 (defun cperl-fill-paragraph (&optional justify iteration)
4191 "Like \\[fill-paragraph], but handle CPerl comments.
4192 If any of the current line is a comment, fill the comment or the
4193 block of it that point is in, preserving the comment's initial
4194 indentation and initial hashes. Behaves usually outside of comment."
4197 ;; Non-nil if the current line contains a comment.
4200 ;; If has-comment, the appropriate fill-prefix for the comment.
4202 ;; Line that contains code and comment (or nil)
4204 c spaces len dc (comment-column comment-column))
4205 ;; Figure out what kind of comment we are looking at.
4210 ;; A line with nothing but a comment on it?
4211 ((looking-at "[ \t]*#[# \t]*")
4213 comment-fill-prefix (buffer-substring (match-beginning 0)
4216 ;; A line with some code, followed by a comment? Remember that the
4217 ;; semi which starts the comment shouldn't be part of a string or
4219 ((cperl-to-comment-or-eol)
4220 (setq has-comment t)
4221 (looking-at "#+[ \t]*")
4222 (setq start (point) c (current-column)
4224 (concat (make-string (current-column) ?\ )
4225 (buffer-substring (match-beginning 0) (match-end 0)))
4226 spaces (progn (skip-chars-backward " \t")
4227 (buffer-substring (point) start))
4228 dc (- c (current-column)) len (- start (point))
4229 start (point-marker))
4231 (insert (make-string dc ?-)))))
4232 (if (not has-comment)
4233 (fill-paragraph justify) ; Do the usual thing outside of comment
4234 ;; Narrow to include only the comment, and then fill the region.
4237 ;; Find the first line we should include in the region to fill.
4238 (if start (progn (beginning-of-line) (point))
4240 (while (and (zerop (forward-line -1))
4241 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
4242 ;; We may have gone to far. Go forward again.
4243 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
4246 ;; Find the beginning of the first line past the region to fill.
4248 (while (progn (forward-line 1)
4249 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
4251 ;; Remove existing hashes
4252 (goto-char (point-min))
4253 (while (progn (forward-line 1) (< (point) (point-max)))
4254 (skip-chars-forward " \t")
4255 (and (looking-at "#+")
4256 (delete-char (- (match-end 0) (match-beginning 0)))))
4258 ;; Lines with only hashes on them can be paragraph boundaries.
4259 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
4260 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
4261 (fill-prefix comment-fill-prefix))
4262 (fill-paragraph justify)))
4267 (progn (delete-char dc) (insert spaces)))
4268 (if (or (= (current-column) c) iteration) nil
4269 (setq comment-column c)
4270 (indent-for-comment)
4271 ;; Repeat once more, flagging as iteration
4272 (cperl-fill-paragraph justify t)))))))
4274 (defun cperl-do-auto-fill ()
4275 ;; Break out if the line is short enough
4276 (if (> (save-excursion
4280 (let ((c (save-excursion (beginning-of-line)
4281 (cperl-to-comment-or-eol) (point)))
4282 (s (memq (following-char) '(?\ ?\t))) marker)
4283 (if (>= c (point)) nil
4284 (setq marker (point-marker))
4285 (cperl-fill-paragraph)
4287 ;; Is not enough, sometimes marker is a start of line
4288 (if (bolp) (progn (re-search-forward "#+[ \t]*")
4289 (goto-char (match-end 0))))
4290 ;; Following space could have gone:
4291 (if (or (not s) (memq (following-char) '(?\ ?\t))) nil
4294 ;; Previous space could have gone:
4295 (or (memq (preceding-char) '(?\ ?\t)) (insert " "))))))
4297 (defvar cperl-imenu--function-name-regexp-perl
4300 "[ \t]*\\(sub\\|package\\)[ \t\n]+\\([a-zA-Z_0-9:']+\\)[ \t]*\\(([^()]*)[ \t]*\\)?"
4302 "=head\\([12]\\)[ \t]+\\([^\n]+\\)$"
4305 (defun cperl-imenu-addback (lst &optional isback name)
4306 ;; We suppose that the lst is a DAG, unless the first element only
4307 ;; loops back, and ISBACK is set. Thus this function cannot be
4308 ;; applied twice without ISBACK set.
4309 (cond ((not cperl-imenu-addback) lst)
4312 (setq name "+++BACK+++"))
4313 (mapcar (function (lambda (elt)
4314 (if (and (listp elt) (listp (cdr elt)))
4316 ;; In the other order it goes up
4317 ;; one level only ;-(
4318 (setcdr elt (cons (cons name lst)
4320 (cperl-imenu-addback (cdr elt) t name)
4322 (if isback (cdr lst) lst))
4325 (defun cperl-imenu--create-perl-index (&optional regexp)
4326 (require 'imenu) ; May be called from TAGS creator
4327 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
4328 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
4329 (index-meth-alist '()) meth
4330 packages ends-ranges p marker
4331 (prev-pos 0) char fchar index index1 name (end-range 0) package)
4332 (goto-char (point-min))
4334 (message "Scanning Perl for index")
4335 (imenu-progress-message prev-pos 0))
4336 (cperl-update-syntaxification (point-max) (point-max))
4337 ;; Search for the function
4338 (progn ;;save-match-data
4339 (while (re-search-forward
4340 (or regexp cperl-imenu--function-name-regexp-perl)
4343 (imenu-progress-message prev-pos))
4345 ((and ; Skip some noise if building tags
4346 (match-beginning 2) ; package or sub
4347 (eq (char-after (match-beginning 2)) ?p) ; package
4348 (not (save-match-data
4349 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
4352 (match-beginning 2) ; package or sub
4353 ;; Skip if quoted (will not skip multi-line ''-strings :-():
4354 (null (get-text-property (match-beginning 1) 'syntax-table))
4355 (null (get-text-property (match-beginning 1) 'syntax-type))
4356 (null (get-text-property (match-beginning 1) 'in-pod)))
4358 (goto-char (match-beginning 2))
4359 (setq fchar (following-char))
4361 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
4362 ;; (goto-char (match-end 0))) ; Messes what follows
4363 (setq char (following-char) ; ?\; for "sub foo () ;"
4366 (while (and ends-ranges (>= p (car ends-ranges)))
4367 ;; delete obsolete entries
4368 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
4369 (setq package (or (car packages) "")
4370 end-range (or (car ends-ranges) 0))
4372 (setq name (buffer-substring (match-beginning 3) (match-end 3))
4374 (set-text-properties 0 (length name) nil name)
4376 package (concat name "::")
4377 name (concat "package " name)
4380 (parse-partial-sexp (point) (point-max) -1) (point))
4381 ends-ranges (cons end-range ends-ranges)
4382 packages (cons package packages)))
4384 ;; Skip this function name if it is a prototype declaration.
4385 (if (and (eq fchar ?s) (eq char ?\;)) nil
4386 (setq name (buffer-substring (match-beginning 3) (match-end 3))
4387 marker (make-marker))
4388 (set-text-properties 0 (length name) nil name)
4389 (set-marker marker (match-end 3))
4391 (setq name (concat "package " name))
4392 (cond ((string-match "[:']" name)
4394 ((> p end-range) nil)
4396 (setq name (concat package name) meth t))))
4397 (setq index (cons name marker))
4399 (push index index-pack-alist)
4400 (push index index-alist))
4401 (if meth (push index index-meth-alist))
4402 (push index index-unsorted-alist)))
4403 ((match-beginning 5) ; Pod section
4404 ;; (beginning-of-line)
4405 (setq index (imenu-example--name-and-position)
4406 name (buffer-substring (match-beginning 6) (match-end 6)))
4407 (set-text-properties 0 (length name) nil name)
4408 (if (eq (char-after (match-beginning 5)) ?2)
4409 (setq name (concat " " name)))
4411 (setq index1 (cons (concat "=" name) (cdr index)))
4412 (push index index-pod-alist)
4413 (push index1 index-unsorted-alist)))))
4415 (imenu-progress-message prev-pos 100))
4417 (if (default-value 'imenu-sort-function)
4418 (sort index-alist (default-value 'imenu-sort-function))
4419 (nreverse index-alist)))
4420 (and index-pod-alist
4421 (push (cons "+POD headers+..."
4422 (nreverse index-pod-alist))
4424 (and (or index-pack-alist index-meth-alist)
4425 (let ((lst index-pack-alist) hier-list pack elt group name)
4426 ;; Remove "package ", reverse and uniquify.
4428 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
4429 (if (assoc name hier-list) nil
4430 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
4431 (setq lst index-meth-alist)
4433 (setq elt (car lst) lst (cdr lst))
4434 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
4435 (setq pack (substring (car elt) 0 (match-beginning 0)))
4436 (if (setq group (assoc pack hier-list))
4437 (if (listp (cdr group))
4438 ;; Have some functions already
4440 (cons (cons (substring
4442 (+ 2 (match-beginning 0)))
4445 (setcdr group (list (cons (substring
4447 (+ 2 (match-beginning 0)))
4451 (list (cons (substring
4453 (+ 2 (match-beginning 0)))
4456 (push (cons "+Hierarchy+..."
4459 (and index-pack-alist
4460 (push (cons "+Packages+..."
4461 (nreverse index-pack-alist))
4463 (and (or index-pack-alist index-pod-alist
4464 (default-value 'imenu-sort-function))
4465 index-unsorted-alist
4466 (push (cons "+Unsorted List+..."
4467 (nreverse index-unsorted-alist))
4469 (cperl-imenu-addback index-alist)))
4472 (defvar cperl-outline-regexp
4473 (concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
4475 ;; Suggested by Mark A. Hershberger
4476 (defun cperl-outline-level ()
4477 (looking-at outline-regexp)
4478 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
4479 ((match-beginning 2)
4480 (if (eq (char-after (match-beginning 2)) ?p)
4483 ((match-beginning 5)
4484 (if (eq (char-after (match-beginning 5)) ?1)
4487 (t 3))) ; should not happen
4490 (defvar cperl-compilation-error-regexp-alist
4491 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK).
4492 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
4494 "Alist that specifies how to match errors in perl output.")
4496 (if (fboundp 'eval-after-load)
4499 '(setq perl-compilation-error-regexp-alist
4500 cperl-compilation-error-regexp-alist)))
4503 (defun cperl-windowed-init ()
4504 "Initialization under windowed version."
4505 (if (or (featurep 'ps-print) cperl-faces-init)
4506 ;; Need to init anyway:
4507 (or cperl-faces-init (cperl-init-faces))
4508 (add-hook 'font-lock-mode-hook
4511 (if (memq major-mode '(perl-mode cperl-mode))
4513 (or cperl-faces-init (cperl-init-faces)))))))
4514 (if (fboundp 'eval-after-load)
4517 '(or cperl-faces-init (cperl-init-faces))))))
4519 (defvar cperl-font-lock-keywords-1 nil
4520 "Additional expressions to highlight in Perl mode. Minimal set.")
4521 (defvar cperl-font-lock-keywords nil
4522 "Additional expressions to highlight in Perl mode. Default set.")
4523 (defvar cperl-font-lock-keywords-2 nil
4524 "Additional expressions to highlight in Perl mode. Maximal set")
4526 (defun cperl-load-font-lock-keywords ()
4527 (or cperl-faces-init (cperl-init-faces))
4528 cperl-font-lock-keywords)
4530 (defun cperl-load-font-lock-keywords-1 ()
4531 (or cperl-faces-init (cperl-init-faces))
4532 cperl-font-lock-keywords-1)
4534 (defun cperl-load-font-lock-keywords-2 ()
4535 (or cperl-faces-init (cperl-init-faces))
4536 cperl-font-lock-keywords-2)
4538 (defun cperl-init-faces-weak ()
4539 ;; Allow `cperl-find-pods-heres' to run.
4540 (or (boundp 'font-lock-constant-face)
4541 (cperl-force-face font-lock-constant-face
4542 "Face for constant and label names")
4543 ;;(setq font-lock-constant-face 'font-lock-constant-face)
4546 (defun cperl-init-faces ()
4547 (condition-case errs
4549 (require 'font-lock)
4550 (and (fboundp 'font-lock-fontify-anchored-keywords)
4551 (featurep 'font-lock-extra)
4552 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
4553 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
4554 (if (fboundp 'font-lock-fontify-anchored-keywords)
4555 (setq font-lock-anchored t))
4557 t-font-lock-keywords
4559 `("[ \t]+$" 0 ',cperl-invalid-face t)
4562 "\\(^\\|[^$@%&\\]\\)\\<\\("
4565 '("if" "until" "while" "elsif" "else" "unless" "for"
4566 "foreach" "continue" "exit" "die" "last" "goto" "next"
4567 "redo" "return" "local" "exec" "sub" "do" "dump" "use"
4568 "require" "package" "eval" "my" "BEGIN" "END" "CHECK" "INIT")
4569 "\\|") ; Flow control
4570 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
4571 ; In what follows we use `type' style
4572 ; for overwritable builtins
4575 "\\(^\\|[^$@%&\\]\\)\\<\\("
4576 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
4577 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
4578 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
4579 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
4580 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
4581 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
4582 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
4583 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
4584 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
4585 ;; "gethostbyname" "gethostent" "getlogin"
4586 ;; "getnetbyaddr" "getnetbyname" "getnetent"
4587 ;; "getpeername" "getpgrp" "getppid" "getpriority"
4588 ;; "getprotobyname" "getprotobynumber" "getprotoent"
4589 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
4590 ;; "getservbyport" "getservent" "getsockname"
4591 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
4592 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
4593 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
4594 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
4595 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
4596 ;; "quotemeta" "rand" "read" "readdir" "readline"
4597 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
4598 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
4599 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
4600 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
4601 ;; "setpriority" "setprotoent" "setpwent" "setservent"
4602 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
4603 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
4604 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
4605 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
4606 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
4607 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
4608 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
4609 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
4610 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
4611 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
4612 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
4613 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
4614 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
4615 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
4616 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
4617 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
4618 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
4619 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
4620 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
4621 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
4622 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
4623 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
4624 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
4625 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
4626 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
4627 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
4628 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
4629 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
4630 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
4631 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
4632 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
4633 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
4634 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
4635 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
4636 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
4637 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
4638 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
4639 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
4640 "\\)\\>") 2 'font-lock-type-face)
4641 ;; In what follows we use `other' style
4642 ;; for nonoverwritable builtins
4643 ;; Somehow 's', 'm' are not auto-generated???
4646 "\\(^\\|[^$@%&\\]\\)\\<\\("
4647 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "chomp"
4648 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
4649 ;; "eval" "exists" "for" "foreach" "format" "goto"
4650 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
4651 ;; "no" "package" "pop" "pos" "print" "printf" "push"
4652 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
4653 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
4654 ;; "undef" "unless" "unshift" "untie" "until" "use"
4656 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
4657 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
4658 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|INIT\\|if\\|keys\\|"
4659 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
4660 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
4661 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
4662 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
4663 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
4664 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
4665 "\\|[sm]" ; Added manually
4666 "\\)\\>") 2 'cperl-nonoverridable-face)
4667 ;; (mapconcat 'identity
4668 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
4669 ;; "#include" "#define" "#undef")
4671 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
4672 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
4673 '("\\<sub[ \t]+\\([^ \t{;()]+\\)[ \t]*\\(([^()]*)[ \t]*\\)?[#{\n]" 1
4674 font-lock-function-name-face)
4675 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
4676 2 font-lock-function-name-face)
4677 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
4678 1 font-lock-function-name-face)
4679 (cond ((featurep 'font-lock-extra)
4680 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
4681 (2 font-lock-string-face t)
4682 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
4684 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
4685 (2 font-lock-string-face t)
4686 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
4688 (1 font-lock-string-face t))))
4689 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
4690 2 font-lock-string-face t)))
4691 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
4692 font-lock-string-face t)
4693 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
4694 font-lock-constant-face) ; labels
4695 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
4696 2 font-lock-constant-face)
4697 ;; Uncomment to get perl-mode-like vars
4698 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
4699 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
4700 ;;; (2 (cons font-lock-variable-name-face '(underline))))
4701 (cond ((featurep 'font-lock-extra)
4702 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
4703 (3 font-lock-variable-name-face)
4705 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
4706 (1 font-lock-variable-name-face)
4707 (2 '(restart 2 nil) nil t)))
4708 nil t))) ; local variables, multiple
4710 '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
4711 (3 font-lock-variable-name-face)
4712 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)"
4714 (1 font-lock-variable-name-face))))
4715 (t '("^[ \t{}]*\\(my\\|local\\our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
4716 3 font-lock-variable-name-face)))
4717 '("\\<for\\(each\\)?\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
4718 4 font-lock-variable-name-face)))
4720 t-font-lock-keywords-1
4721 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
4722 (not cperl-xemacs-p) ; not yet as of XEmacs 19.12
4724 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
4725 (if (eq (char-after (match-beginning 2)) ?%)
4728 t) ; arrays and hashes
4729 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
4731 (if (= (- (match-end 2) (match-beginning 2)) 1)
4732 (if (eq (char-after (match-beginning 3)) ?{)
4734 cperl-array-face) ; arrays and hashes
4735 font-lock-variable-name-face) ; Just to put something
4737 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
4738 ;;; Too much noise from \s* @s[ and friends
4739 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
4740 ;;(3 font-lock-function-name-face t t)
4742 ;; (if (cperl-slash-is-regexp)
4743 ;; font-lock-function-name-face 'default) nil t))
4745 (if cperl-highlight-variables-indiscriminately
4746 (setq t-font-lock-keywords-1
4747 (append t-font-lock-keywords-1
4748 (list '("[$*]{?\\(\\sw+\\)" 1
4749 font-lock-variable-name-face)))))
4750 (setq cperl-font-lock-keywords-1
4751 (if cperl-syntaxify-by-font-lock
4752 (cons 'cperl-fontify-update
4753 t-font-lock-keywords)
4754 t-font-lock-keywords)
4755 cperl-font-lock-keywords cperl-font-lock-keywords-1
4756 cperl-font-lock-keywords-2 (append
4757 cperl-font-lock-keywords-1
4758 t-font-lock-keywords-1)))
4759 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
4760 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
4761 (eval ; Avoid a warning
4762 '(font-lock-require-faces
4764 ;; Color-light Color-dark Gray-light Gray-dark Mono
4765 (list 'font-lock-comment-face
4766 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
4771 (list 'font-lock-string-face
4772 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
4777 (list 'font-lock-function-name-face
4779 "Blue" "LightSkyBlue" "Gray50" "LightGray"
4780 (cdr (assq 'background-color ; if mono
4781 (frame-parameters))))
4784 (cdr (assq 'foreground-color ; if mono
4785 (frame-parameters))))
4789 (list 'font-lock-variable-name-face
4790 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
4795 (list 'font-lock-type-face
4796 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
4802 (list 'font-lock-constant-face
4803 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
4809 (list 'cperl-nonoverridable-face
4810 ["chartreuse3" ("orchid1" "orange")
4817 (list 'cperl-array-face
4818 ["blue" "yellow" nil "Gray80"]
4819 ["lightyellow2" ("navy" "os2blue" "darkgreen")
4824 (list 'cperl-hash-face
4825 ["red" "red" nil "Gray80"]
4826 ["lightyellow2" ("navy" "os2blue" "darkgreen")
4831 ;; Do it the dull way, without choose-color
4832 (defvar cperl-guessed-background nil
4833 "Display characteristics as guessed by cperl.")
4834 ;; (or (fboundp 'x-color-defined-p)
4835 ;; (defalias 'x-color-defined-p
4836 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
4837 ;; ;; XEmacs >= 19.12
4838 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
4840 ;; (t 'x-valid-color-name-p))))
4841 (cperl-force-face font-lock-constant-face
4842 "Face for constant and label names")
4843 (cperl-force-face font-lock-variable-name-face
4844 "Face for variable names")
4845 (cperl-force-face font-lock-type-face
4846 "Face for data types")
4847 (cperl-force-face cperl-nonoverridable-face
4848 "Face for data types from another group")
4849 (cperl-force-face font-lock-comment-face
4850 "Face for comments")
4851 (cperl-force-face font-lock-function-name-face
4852 "Face for function names")
4853 (cperl-force-face cperl-hash-face
4855 (cperl-force-face cperl-array-face
4857 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
4858 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
4859 ;;(or (boundp 'font-lock-type-face)
4860 ;; (defconst font-lock-type-face
4861 ;; 'font-lock-type-face
4862 ;; "Face to use for data types."))
4863 ;;(or (boundp 'cperl-nonoverridable-face)
4864 ;; (defconst cperl-nonoverridable-face
4865 ;; 'cperl-nonoverridable-face
4866 ;; "Face to use for data types from another group."))
4867 ;;(if (not cperl-xemacs-p) nil
4868 ;; (or (boundp 'font-lock-comment-face)
4869 ;; (defconst font-lock-comment-face
4870 ;; 'font-lock-comment-face
4871 ;; "Face to use for comments."))
4872 ;; (or (boundp 'font-lock-keyword-face)
4873 ;; (defconst font-lock-keyword-face
4874 ;; 'font-lock-keyword-face
4875 ;; "Face to use for keywords."))
4876 ;; (or (boundp 'font-lock-function-name-face)
4877 ;; (defconst font-lock-function-name-face
4878 ;; 'font-lock-function-name-face
4879 ;; "Face to use for function names.")))
4881 (not (cperl-is-face 'cperl-array-face))
4882 (cperl-is-face 'font-lock-emphasized-face))
4883 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
4885 (not (cperl-is-face 'cperl-hash-face))
4886 (cperl-is-face 'font-lock-other-emphasized-face))
4887 (copy-face 'font-lock-other-emphasized-face
4890 (not (cperl-is-face 'cperl-nonoverridable-face))
4891 (cperl-is-face 'font-lock-other-type-face))
4892 (copy-face 'font-lock-other-type-face
4893 'cperl-nonoverridable-face))
4894 ;;(or (boundp 'cperl-hash-face)
4895 ;; (defconst cperl-hash-face
4897 ;; "Face to use for hashes."))
4898 ;;(or (boundp 'cperl-array-face)
4899 ;; (defconst cperl-array-face
4900 ;; 'cperl-array-face
4901 ;; "Face to use for arrays."))
4902 ;; Here we try to guess background
4904 (if (boundp 'font-lock-background-mode)
4905 font-lock-background-mode
4907 (face-list (and (fboundp 'face-list) (face-list)))
4910 ;;;; (fset 'cperl-is-face
4911 ;;;; (cond ((fboundp 'find-face)
4912 ;;;; (symbol-function 'find-face))
4914 ;;;; (function (lambda (face) (member face face-list))))
4916 ;;;; (function (lambda (face) (boundp face))))))
4917 (defvar cperl-guessed-background
4918 (if (and (boundp 'font-lock-display-type)
4919 (eq font-lock-display-type 'grayscale))
4922 "Background as guessed by CPerl mode")
4924 (not (cperl-is-face 'font-lock-constant-face))
4925 (cperl-is-face 'font-lock-reference-face))
4926 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
4927 (if (cperl-is-face 'font-lock-type-face) nil
4928 (copy-face 'default 'font-lock-type-face)
4930 ((eq background 'light)
4931 (set-face-foreground 'font-lock-type-face
4932 (if (x-color-defined-p "seagreen")
4935 ((eq background 'dark)
4936 (set-face-foreground 'font-lock-type-face
4937 (if (x-color-defined-p "os2pink")
4941 (set-face-background 'font-lock-type-face "gray90"))))
4942 (if (cperl-is-face 'cperl-nonoverridable-face)
4944 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
4946 ((eq background 'light)
4947 (set-face-foreground 'cperl-nonoverridable-face
4948 (if (x-color-defined-p "chartreuse3")
4951 ((eq background 'dark)
4952 (set-face-foreground 'cperl-nonoverridable-face
4953 (if (x-color-defined-p "orchid1")
4956 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
4957 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
4959 ;;; ((eq background 'light)
4960 ;;; (set-face-background 'font-lock-other-emphasized-face
4961 ;;; (if (x-color-defined-p "lightyellow2")
4963 ;;; (if (x-color-defined-p "lightyellow")
4965 ;;; "light yellow"))))
4966 ;;; ((eq background 'dark)
4967 ;;; (set-face-background 'font-lock-other-emphasized-face
4968 ;;; (if (x-color-defined-p "navy")
4970 ;;; (if (x-color-defined-p "darkgreen")
4972 ;;; "dark green"))))
4973 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
4974 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
4975 ;;; (copy-face 'bold 'font-lock-emphasized-face)
4977 ;;; ((eq background 'light)
4978 ;;; (set-face-background 'font-lock-emphasized-face
4979 ;;; (if (x-color-defined-p "lightyellow2")
4981 ;;; "lightyellow")))
4982 ;;; ((eq background 'dark)
4983 ;;; (set-face-background 'font-lock-emphasized-face
4984 ;;; (if (x-color-defined-p "navy")
4986 ;;; (if (x-color-defined-p "darkgreen")
4988 ;;; "dark green"))))
4989 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
4990 (if (cperl-is-face 'font-lock-variable-name-face) nil
4991 (copy-face 'italic 'font-lock-variable-name-face))
4992 (if (cperl-is-face 'font-lock-constant-face) nil
4993 (copy-face 'italic 'font-lock-constant-face))))
4994 (setq cperl-faces-init t))
4995 (error (message "cperl-init-faces (ignored): %s" errs))))
4998 (defun cperl-ps-print-init ()
4999 "Initialization of `ps-print' components for faces used in CPerl."
5000 (eval-after-load "ps-print"
5001 '(setq ps-bold-faces
5002 ;; font-lock-variable-name-face
5003 ;; font-lock-constant-face
5004 (append '(cperl-array-face
5008 ;; font-lock-constant-face
5009 (append '(cperl-nonoverridable-face
5013 ;; font-lock-type-face
5014 (append '(cperl-array-face
5017 cperl-nonoverridable-face)
5018 ps-underlined-faces))))
5020 (defvar ps-print-face-extension-alist)
5022 (defun cperl-ps-print (&optional file)
5023 "Pretty-print in CPerl style.
5024 If optional argument FILE is an empty string, prints to printer, otherwise
5025 to the file FILE. If FILE is nil, prompts for a file name.
5027 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
5030 (setq file (read-from-minibuffer
5031 "Print to file (if empty - to printer): "
5032 (concat (buffer-file-name) ".ps")
5033 nil nil 'file-name-history)))
5034 (or (> (length file) 0)
5036 (require 'ps-print) ; To get ps-print-face-extension-alist
5037 (let ((ps-print-color-p t)
5038 (ps-print-face-extension-alist ps-print-face-extension-alist))
5039 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
5040 (ps-print-buffer-with-faces file)))
5042 ;;; (defun cperl-ps-print-init ()
5043 ;;; "Initialization of `ps-print' components for faces used in CPerl."
5044 ;;; ;; Guard against old versions
5045 ;;; (defvar ps-underlined-faces nil)
5046 ;;; (defvar ps-bold-faces nil)
5047 ;;; (defvar ps-italic-faces nil)
5048 ;;; (setq ps-bold-faces
5049 ;;; (append '(font-lock-emphasized-face
5050 ;;; cperl-array-face
5051 ;;; font-lock-keyword-face
5052 ;;; font-lock-variable-name-face
5053 ;;; font-lock-constant-face
5054 ;;; font-lock-reference-face
5055 ;;; font-lock-other-emphasized-face
5056 ;;; cperl-hash-face)
5058 ;;; (setq ps-italic-faces
5059 ;;; (append '(cperl-nonoverridable-face
5060 ;;; font-lock-constant-face
5061 ;;; font-lock-reference-face
5062 ;;; font-lock-other-emphasized-face
5063 ;;; cperl-hash-face)
5064 ;;; ps-italic-faces))
5065 ;;; (setq ps-underlined-faces
5066 ;;; (append '(font-lock-emphasized-face
5067 ;;; cperl-array-face
5068 ;;; font-lock-other-emphasized-face
5070 ;;; cperl-nonoverridable-face font-lock-type-face)
5071 ;;; ps-underlined-faces))
5072 ;;; (cons 'font-lock-type-face ps-underlined-faces))
5075 (if (cperl-enable-font-lock) (cperl-windowed-init))
5077 (defconst cperl-styles-entries
5078 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
5079 cperl-label-offset cperl-extra-newline-before-brace
5080 cperl-merge-trailing-else
5081 cperl-continued-statement-offset))
5083 (defconst cperl-style-alist
5084 '(("CPerl" ; =GNU without extra-newline-before-brace
5085 (cperl-indent-level . 2)
5086 (cperl-brace-offset . 0)
5087 (cperl-continued-brace-offset . 0)
5088 (cperl-label-offset . -2)
5089 (cperl-extra-newline-before-brace . nil)
5090 (cperl-merge-trailing-else . t)
5091 (cperl-continued-statement-offset . 2))
5092 ("PerlStyle" ; CPerl with 4 as indent
5093 (cperl-indent-level . 4)
5094 (cperl-brace-offset . 0)
5095 (cperl-continued-brace-offset . 0)
5096 (cperl-label-offset . -4)
5097 (cperl-extra-newline-before-brace . nil)
5098 (cperl-merge-trailing-else . t)
5099 (cperl-continued-statement-offset . 4))
5101 (cperl-indent-level . 2)
5102 (cperl-brace-offset . 0)
5103 (cperl-continued-brace-offset . 0)
5104 (cperl-label-offset . -2)
5105 (cperl-extra-newline-before-brace . t)
5106 (cperl-merge-trailing-else . nil)
5107 (cperl-continued-statement-offset . 2))
5109 (cperl-indent-level . 5)
5110 (cperl-brace-offset . 0)
5111 (cperl-continued-brace-offset . -5)
5112 (cperl-label-offset . -5)
5113 ;;(cperl-extra-newline-before-brace . nil) ; ???
5114 (cperl-merge-trailing-else . nil)
5115 (cperl-continued-statement-offset . 5))
5117 (cperl-indent-level . 4)
5118 (cperl-brace-offset . 0)
5119 (cperl-continued-brace-offset . -4)
5120 (cperl-label-offset . -4)
5121 ;;(cperl-extra-newline-before-brace . nil) ; ???
5122 (cperl-continued-statement-offset . 4))
5124 (cperl-indent-level . 4)
5125 (cperl-brace-offset . 0)
5126 (cperl-continued-brace-offset . -4)
5127 (cperl-label-offset . -4)
5128 (cperl-continued-statement-offset . 4)
5129 (cperl-merge-trailing-else . nil)
5130 (cperl-extra-newline-before-brace . t))
5133 (cperl-indent-level . 4)
5134 (cperl-brace-offset . 0)
5135 (cperl-continued-brace-offset . 0)
5136 (cperl-label-offset . -4)
5137 ;;(cperl-extra-newline-before-brace . nil) ; ???
5138 (cperl-continued-statement-offset . 4)))
5139 "(Experimental) list of variables to set to get a particular indentation style.
5140 Should be used via `cperl-set-style' or via Perl menu.")
5142 (defun cperl-set-style (style)
5143 "Set CPerl-mode variables to use one of several different indentation styles.
5144 The arguments are a string representing the desired style.
5145 The list of styles is in `cperl-style-alist', available styles
5146 are GNU, K&R, BSD, C++ and Whitesmith.
5148 The current value of style is memorized (unless there is a memorized
5149 data already), may be restored by `cperl-set-style-back'.
5151 Chosing \"Current\" style will not change style, so this may be used for
5152 side-effect of memorizing only."
5154 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
5155 cperl-style-alist)))
5156 (list (completing-read "Enter style: " list nil 'insist))))
5158 (setq cperl-old-style
5161 (cons name (eval name))))
5162 cperl-styles-entries)))
5163 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
5165 (setq setting (car style) style (cdr style))
5166 (set (car setting) (cdr setting)))))
5168 (defun cperl-set-style-back ()
5169 "Restore a style memorised by `cperl-set-style'."
5171 (or cperl-old-style (error "The style was not changed"))
5173 (while cperl-old-style
5174 (setq setting (car cperl-old-style)
5175 cperl-old-style (cdr cperl-old-style))
5176 (set (car setting) (cdr setting)))))
5178 (defun cperl-check-syntax ()
5180 (require 'mode-compile)
5181 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
5182 (eval '(mode-compile)))) ; Avoid a warning
5184 (defun cperl-info-buffer (type)
5185 ;; Returns buffer with documentation. Creates if missing.
5186 ;; If TYPE, this vars buffer.
5187 ;; Special care is taken to not stomp over an existing info buffer
5188 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
5189 (info (get-buffer bname))
5190 (oldbuf (get-buffer "*info*")))
5192 (save-window-excursion
5197 (rename-buffer "*info-perl-tmp*")))
5198 (save-window-excursion
5200 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
5201 (set-buffer "*info*")
5202 (rename-buffer bname)
5204 (set-buffer "*info-perl-tmp*")
5205 (rename-buffer "*info*")
5206 (set-buffer bname)))
5207 (make-local-variable 'window-min-height)
5208 (setq window-min-height 2)
5209 (current-buffer)))))
5211 (defun cperl-word-at-point (&optional p)
5212 ;; Returns the word at point or at P.
5214 (if p (goto-char p))
5215 (or (cperl-word-at-point-hard)
5218 (funcall (or (and (boundp 'find-tag-default-function)
5219 find-tag-default-function)
5220 (get major-mode 'find-tag-default-function)
5221 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
5222 ;; automatically used within `find-tag-default':
5223 'find-tag-default))))))
5225 (defun cperl-info-on-command (command)
5226 "Show documentation for Perl command in other window.
5227 If perl-info buffer is shown in some frame, uses this frame.
5228 Customized by setting variables `cperl-shrink-wrap-info-frame',
5229 `cperl-max-help-size'."
5231 (let* ((default (cperl-word-at-point))
5233 (format "Find doc for Perl function (default %s): "
5235 (list (if (equal read "")
5239 (let ((buffer (current-buffer))
5240 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
5241 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
5242 max-height char-height buf-list)
5243 (if (string-match "^-[a-zA-Z]$" command)
5244 (setq cmd-desc "^-X[ \t\n]"))
5245 (setq isvar (string-match "^[$@%]" command)
5246 buf (cperl-info-buffer isvar)
5247 iniwin (selected-window)
5248 fr1 (window-frame iniwin))
5250 (beginning-of-buffer)
5252 (progn (re-search-forward "^-X[ \t\n]")
5254 (if (re-search-forward cmd-desc nil t)
5256 ;; Go back to beginning of the group (ex, for qq)
5257 (if (re-search-backward "^[ \t\n\f]")
5262 buf-list (list buf "*info-perl-var*" "*info-perl*"))
5263 (while (and (not win) buf-list)
5264 (setq win (get-buffer-window (car buf-list) t))
5265 (setq buf-list (cdr buf-list)))
5267 (eq (window-buffer win) buf)
5268 (set-window-buffer win buf))
5269 (and win (setq fr2 (window-frame win)))
5270 (if (or (not fr2) (eq fr1 fr2))
5272 (special-display-popup-frame buf) ; Make it visible
5273 (select-window win))
5274 (goto-char pos) ; Needed (?!).
5276 (setq iniheight (window-height)
5277 frheight (frame-height)
5278 not-loner (< iniheight (1- frheight))) ; Are not alone
5279 (cond ((if not-loner cperl-max-help-size
5280 cperl-shrink-wrap-info-frame)
5286 (if (re-search-forward
5287 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
5288 (match-beginning 0) (point-max)))))
5291 (/ (* (- frheight 3) cperl-max-help-size) 100)
5292 (setq char-height (frame-char-height))
5293 ;; Non-functioning under OS/2:
5294 (if (eq char-height 1) (setq char-height 18))
5295 ;; Title, menubar, + 2 for slack
5296 (- (/ (x-display-pixel-height) char-height) 4)
5298 (if (> height max-height) (setq height max-height))
5299 ;;(message "was %s doing %s" iniheight height)
5301 (enlarge-window (- height iniheight))
5302 (set-frame-height (window-frame win) (1+ height)))))
5303 (set-window-start (selected-window) pos))
5304 (message "No entry for %s found." command))
5305 ;;(pop-to-buffer buffer)
5306 (select-window iniwin)))
5308 (defun cperl-info-on-current-command ()
5309 "Show documentation for Perl command at point in other window."
5311 (cperl-info-on-command (cperl-word-at-point)))
5313 (defun cperl-imenu-info-imenu-search ()
5314 (if (looking-at "^-X[ \t\n]") nil
5316 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
5319 (defun cperl-imenu-info-imenu-name ()
5321 (match-beginning 1) (match-end 1)))
5323 (defun cperl-imenu-on-info ()
5325 (let* ((buffer (current-buffer))
5326 imenu-create-index-function
5327 imenu-prev-index-position-function
5328 imenu-extract-index-name-function
5329 (index-item (save-restriction
5330 (save-window-excursion
5331 (set-buffer (cperl-info-buffer nil))
5332 (setq imenu-create-index-function
5333 'imenu-default-create-index-function
5334 imenu-prev-index-position-function
5335 'cperl-imenu-info-imenu-search
5336 imenu-extract-index-name-function
5337 'cperl-imenu-info-imenu-name)
5338 (imenu-choose-buffer-index)))))
5342 (pop-to-buffer "*info-perl*")
5344 ((markerp (cdr index-item))
5345 (goto-char (marker-position (cdr index-item))))
5347 (goto-char (cdr index-item))))
5348 (set-window-start (selected-window) (point))
5349 (pop-to-buffer buffer)))))
5351 (defun cperl-lineup (beg end &optional step minshift)
5352 "Lineup construction in a region.
5353 Beginning of region should be at the start of a construction.
5354 All first occurrences of this construction in the lines that are
5355 partially contained in the region are lined up at the same column.
5357 MINSHIFT is the minimal amount of space to insert before the construction.
5358 STEP is the tabwidth to position constructions.
5359 If STEP is nil, `cperl-lineup-step' will be used
5360 \(or `cperl-indent-level', if `cperl-lineup-step' is `nil').
5361 Will not move the position at the start to the left."
5363 (let (search col tcol seen b e)
5367 (setq end (point-marker))
5369 (skip-chars-forward " \t\f")
5370 (setq beg (point-marker))
5371 (indent-region beg end nil)
5373 (setq col (current-column))
5374 (if (looking-at "[a-zA-Z0-9_]")
5375 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
5379 (buffer-substring (match-beginning 0)
5380 (match-end 0))) "\\>"))
5381 (error "Cannot line up in a middle of the word"))
5382 (if (looking-at "$")
5383 (error "Cannot line up end of line"))
5384 (setq search (regexp-quote (char-to-string (following-char)))))
5385 (setq step (or step cperl-lineup-step cperl-indent-level))
5386 (or minshift (setq minshift 1))
5388 (beginning-of-line 2)
5389 (and (< (point) end)
5390 (re-search-forward search end t)
5391 (goto-char (match-beginning 0))))
5392 (setq tcol (current-column) seen t)
5393 (if (> tcol col) (setq col tcol)))
5395 (error "The construction to line up occurred only once"))
5397 (setq col (+ col minshift))
5398 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
5402 (skip-chars-backward " \t")
5403 (delete-region (point) e)
5404 (indent-to-column col); (make-string (- col (current-column)) ?\ ))
5405 (beginning-of-line 2)
5406 (and (< (point) end)
5407 (re-search-forward search end t)
5408 (goto-char (match-beginning 0)))))))) ; No body
5410 (defun cperl-etags (&optional add all files)
5411 "Run etags with appropriate options for Perl files.
5412 If optional argument ALL is `recursive', will process Perl files
5413 in subdirectories too."
5416 (args '("-l" "none" "-r" "/\\<\\(package\\|sub\\)[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([{#]\\|$\\)\\)/\\4/"))
5418 (if add (setq args (cons "-a" args)))
5419 (or files (setq files (list buffer-file-name)))
5421 ((eq all 'recursive)
5422 ;;(error "Not implemented: recursive")
5423 (setq args (append (list "-e"
5424 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
5426 find(\\&wanted, '.');
5431 ;;(error "Not implemented: all")
5432 (setq args (append (list "-e"
5433 "push @ARGV, <*.PL *.pl *.pm>;
5438 (setq args (append args files))))
5439 (setq res (apply 'call-process cmd nil nil nil args))
5441 (message "etags returned \"%s\"" res))))
5443 (defun cperl-toggle-auto-newline ()
5444 "Toggle the state of `cperl-auto-newline'."
5446 (setq cperl-auto-newline (not cperl-auto-newline))
5447 (message "Newlines will %sbe auto-inserted now."
5448 (if cperl-auto-newline "" "not ")))
5450 (defun cperl-toggle-abbrev ()
5451 "Toggle the state of automatic keyword expansion in CPerl mode."
5453 (abbrev-mode (if abbrev-mode 0 1))
5454 (message "Perl control structure will %sbe auto-inserted now."
5455 (if abbrev-mode "" "not ")))
5458 (defun cperl-toggle-electric ()
5459 "Toggle the state of parentheses doubling in CPerl mode."
5461 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
5462 (message "Parentheses will %sbe auto-doubled now."
5463 (if (cperl-val 'cperl-electric-parens) "" "not ")))
5465 (defun cperl-toggle-autohelp ()
5466 "Toggle the state of automatic help message in CPerl mode.
5467 See `cperl-lazy-help-time' too."
5469 (if (fboundp 'run-with-idle-timer)
5471 (if cperl-lazy-installed
5472 (eval '(cperl-lazy-unstall))
5473 (cperl-lazy-install))
5474 (message "Perl help messages will %sbe automatically shown now."
5475 (if cperl-lazy-installed "" "not ")))
5476 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
5478 (defun cperl-toggle-construct-fix ()
5479 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
5481 (setq cperl-indent-region-fix-constructs
5482 (if cperl-indent-region-fix-constructs
5485 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
5486 (if cperl-indent-region-fix-constructs "" "not ")))
5488 ;;;; Tags file creation.
5490 (defvar cperl-tmp-buffer " *cperl-tmp*")
5492 (defun cperl-setup-tmp-buf ()
5493 (set-buffer (get-buffer-create cperl-tmp-buffer))
5494 (set-syntax-table cperl-mode-syntax-table)
5495 (buffer-disable-undo)
5497 (if cperl-use-syntax-table-text-property-for-tags
5499 (make-local-variable 'parse-sexp-lookup-properties)
5500 ;; Do not introduce variable if not needed, we check it!
5501 (set 'parse-sexp-lookup-properties t))))
5503 (defun cperl-xsub-scan ()
5505 (let ((index-alist '())
5506 (prev-pos 0) index index1 name package prefix)
5507 (goto-char (point-min))
5509 (message "Scanning XSUB for index")
5510 (imenu-progress-message prev-pos 0))
5511 ;; Search for the function
5512 (progn ;;save-match-data
5513 (while (re-search-forward
5514 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
5517 (imenu-progress-message prev-pos))
5519 ((match-beginning 2) ; SECTION
5520 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
5521 (goto-char (match-beginning 0))
5522 (skip-chars-forward " \t")
5524 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
5525 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
5527 ((not package) nil) ; C language section
5528 ((match-beginning 3) ; XSUB
5529 (goto-char (1+ (match-beginning 3)))
5530 (setq index (imenu-example--name-and-position))
5531 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
5532 (if (and prefix (string-match (concat "^" prefix) name))
5533 (setq name (substring name (length prefix))))
5534 (cond ((string-match "::" name) nil)
5536 (setq index1 (cons (concat package "::" name) (cdr index)))
5537 (push index1 index-alist)))
5539 (push index index-alist))
5541 ;; (beginning-of-line)
5542 (setq index (imenu-example--name-and-position))
5543 (setcar index (concat package "::BOOT:"))
5544 (push index index-alist)))))
5546 (imenu-progress-message prev-pos 100))
5549 (defvar cperl-unreadable-ok nil)
5551 (defun cperl-find-tags (ifile xs topdir)
5552 (let (ind (b (get-buffer cperl-tmp-buffer)) lst elt pos ret rel
5553 (cperl-pod-here-fontify nil) f file)
5555 (if b (set-buffer b)
5556 (cperl-setup-tmp-buf))
5559 (setq file (car (insert-file-contents ifile)))
5560 (error (if cperl-unreadable-ok nil
5562 (format "File %s unreadable. Continue? " ifile))
5563 (setq cperl-unreadable-ok t)
5564 (error "Aborting: unreadable file %s" ifile)))))
5566 (message "Unreadable file %s" ifile)
5567 (message "Scanning file %s ..." file)
5568 (if (and cperl-use-syntax-table-text-property-for-tags
5570 (condition-case err ; after __END__ may have garbage
5571 (cperl-find-pods-heres nil nil noninteractive)
5572 (error (message "While scanning for syntax: %s" err))))
5574 (setq lst (cperl-xsub-scan))
5575 (setq ind (cperl-imenu--create-perl-index))
5576 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
5581 (cond ((string-match "^[_a-zA-Z]" (car elt))
5582 (goto-char (cdr elt))
5583 (beginning-of-line) ; pos should be of the start of the line
5586 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
5587 (buffer-substring (progn
5588 (goto-char (cdr elt))
5589 ;; After name now...
5590 (or (eolp) (forward-char 1))
5598 (setq elt (car lst) lst (cdr lst))
5603 (if (string-match "^package " (car elt))
5604 (substring (car elt) 8)
5607 (number-to-string (elt elt 2)) ; Line
5609 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
5611 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
5612 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
5614 ;; Need to insert the name without package as well
5615 (setq lst (cons (cons (substring (elt elt 3)
5623 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
5624 (set-text-properties 0 (length rel) nil rel)
5625 (and (equal topdir (substring rel 0 (length topdir)))
5626 (setq rel (substring file (length topdir))))
5627 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
5628 (setq ret (buffer-substring 1 (point-max)))
5631 (message "Scanning file %s finished" file))
5634 (defun cperl-add-tags-recurse-noxs ()
5635 "Add to TAGS data for Perl and XSUB files in the current directory and kids.
5637 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
5638 -f cperl-add-tags-recurse
5640 (cperl-write-tags nil nil t t nil t))
5642 (defun cperl-add-tags-recurse ()
5643 "Add to TAGS file data for Perl files in the current directory and kids.
5645 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
5646 -f cperl-add-tags-recurse
5648 (cperl-write-tags nil nil t t))
5650 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
5651 ;; If INBUFFER, do not select buffer, and do not save
5652 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
5655 (setq file (if dir default-directory (buffer-file-name)))
5656 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
5658 (setq topdir default-directory))
5659 (let ((tags-file-name "TAGS")
5660 (case-fold-search (eq system-type 'emx))
5663 (cond (inbuffer nil) ; Already there
5664 ((file-exists-p tags-file-name)
5666 (visit-tags-table-buffer)
5667 (visit-tags-table-buffer tags-file-name)))
5668 (t (set-buffer (find-file-noselect tags-file-name))))
5671 (cond ((eq erase 'ignore))
5674 (setq erase 'ignore)))
5677 (directory-files file t
5678 (if recurse nil cperl-scan-files-regexp)
5681 (if cperl-unreadable-ok nil
5683 (format "Directory %s unreadable. Continue? " file))
5684 (setq cperl-unreadable-ok t
5685 tm nil) ; Return empty list
5686 (error "Aborting: unreadable directory %s" file)))))))
5687 (mapcar (function (lambda (file)
5689 ((string-match cperl-noscan-files-regexp file)
5691 ((not (file-directory-p file))
5692 (if (string-match cperl-scan-files-regexp file)
5693 (cperl-write-tags file erase recurse nil t noxs topdir)))
5695 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
5699 (setq xs (string-match "\\.xs$" file))
5700 (if (not (and xs noxs))
5702 (cond ((eq erase 'ignore) (goto-char (point-max)))
5703 (erase (erase-buffer))
5707 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
5708 (set-text-properties 0 (length rel) nil rel)
5709 (and (equal topdir (substring rel 0 (length topdir)))
5710 (setq rel (substring file (length topdir))))
5711 (if (search-forward (concat "\f\n" rel ",") nil t)
5713 (search-backward "\f\n")
5714 (delete-region (point)
5717 (if (search-forward "\f\n"
5721 (goto-char (point-max)))))
5722 (insert (cperl-find-tags file xs topdir))))))
5723 (if inbuffer nil ; Delegate to the caller
5724 (save-buffer 0) ; No backup
5725 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
5726 (initialize-new-tags-table))))))
5728 (defvar cperl-tags-hier-regexp-list
5735 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
5737 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
5740 (defvar cperl-hierarchy '(() ())
5741 "Global hierarchy of classes")
5743 (defun cperl-tags-hier-fill ()
5744 ;; Suppose we are in a tag table cooked by cperl.
5746 (let (type pack name pos line chunk ord cons1 file str info fileind)
5747 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
5748 (setq pos (match-beginning 0)
5749 pack (match-beginning 2))
5751 (if (looking-at (concat
5760 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
5761 name (buffer-substring (match-beginning 2) (match-end 2))
5762 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
5763 line (buffer-substring (match-beginning 3) (match-end 3))
5766 fileind (format "%s:%s" file line)
5767 ;; Moves to beginning of the next line:
5768 info (cperl-etags-snarf-tag file line))
5771 ;; Make new member of hierarchy name ==> file ==> pos if needed
5772 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
5774 (setcdr cons1 (cons (cons fileind (vector file info))
5776 ;; First occurrence of the name, start alist
5777 (setq cons1 (cons name (list (cons fileind (vector file info)))))
5779 (setcar (cdr cperl-hierarchy)
5780 (cons cons1 (nth 1 cperl-hierarchy)))
5781 (setcar cperl-hierarchy
5782 (cons cons1 (car cperl-hierarchy)))))))
5785 (defun cperl-tags-hier-init (&optional update)
5786 "Show hierarchical menu of classes and methods.
5787 Finds info about classes by a scan of loaded TAGS files.
5788 Supposes that the TAGS files contain fully qualified function names.
5789 One may build such TAGS files from CPerl mode menu."
5793 (if (or update (null (nth 2 cperl-hierarchy)))
5794 (let (pack name cons1 to l1 l2 l3 l4 b
5795 (remover (function (lambda (elt) ; (name (file1...) (file2..))
5798 (setcdr elt (cdr (nth 1 elt))))))))
5799 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
5800 (setq cperl-hierarchy (list l1 l2 l3))
5801 (if cperl-xemacs-p ; Not checked
5804 ;; Does this work in XEmacs?
5805 (call-interactively 'visit-tags-table))
5806 (message "Updating list of classes...")
5807 (set-buffer (get-file-buffer tags-file-name))
5808 (cperl-tags-hier-fill))
5810 (call-interactively 'visit-tags-table))
5814 (message "Updating list of classes... %s" tagsfile)
5815 (set-buffer (get-file-buffer tagsfile))
5816 (cperl-tags-hier-fill)))
5818 (message "Updating list of classes... postprocessing..."))
5819 (mapcar remover (car cperl-hierarchy))
5820 (mapcar remover (nth 1 cperl-hierarchy))
5821 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
5822 (cons "Methods: " (car cperl-hierarchy))))
5823 (cperl-tags-treeify to 1)
5824 (setcar (nthcdr 2 cperl-hierarchy)
5825 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
5826 (message "Updating list of classes: done, requesting display...")
5827 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
5829 (or (nth 2 cperl-hierarchy)
5830 (error "No items found"))
5832 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
5834 (x-popup-menu t (nth 2 cperl-hierarchy))
5836 (tmm-prompt (nth 2 cperl-hierarchy))))
5837 (if (and update (listp update))
5838 (progn (while (cdr update) (setq update (cdr update)))
5839 (setq update (car update)))) ; Get the last from the list
5840 (if (vectorp update)
5842 (find-file (elt update 0))
5843 (cperl-etags-goto-tag-location (elt update 1))))
5844 (if (eq update -999) (cperl-tags-hier-init t)))
5846 (defun cperl-tags-treeify (to level)
5847 ;; cadr of `to' is read-write. On start it is a cons
5848 (let* ((regexp (concat "^\\(" (mapconcat
5850 (make-list level "[_a-zA-Z0-9]+")
5853 (packages (cdr (nth 1 to)))
5854 (methods (cdr (nth 2 to)))
5855 l1 head tail cons1 cons2 ord writeto packs recurse
5856 root-packages root-functions ms many_ms same_name ps
5860 (cond ((and (string-match regexp (car elt))
5861 (or (eq ord 1) (match-end 2)))
5862 (setq head (substring (car elt) 0 (match-end 1))
5863 tail (if (match-end 2) (substring (car elt)
5866 (if (setq cons1 (assoc head writeto)) nil
5867 ;; Need to init new head
5868 (setcdr writeto (cons (list head (list "Packages: ")
5871 (setq cons1 (nth 1 writeto)))
5872 (setq cons2 (nth ord cons1)) ; Either packs or meths
5873 (setcdr cons2 (cons elt (cdr cons2))))
5875 (setq root-functions (cons elt root-functions)))
5877 (setq root-packages (cons elt root-packages))))))))
5878 (setcdr to l1) ; Init to dynamic space
5881 (mapcar move-deeper packages)
5883 (mapcar move-deeper methods)
5885 (mapcar (function (lambda (elt)
5886 (cperl-tags-treeify elt (1+ level))))
5888 ;;Now clean up leaders with one child only
5889 (mapcar (function (lambda (elt)
5890 (if (not (and (listp (cdr elt))
5891 (eq (length elt) 2))) nil
5892 (setcar elt (car (nth 1 elt)))
5893 (setcdr elt (cdr (nth 1 elt))))))
5895 ;; Sort the roots of subtrees
5896 (if (default-value 'imenu-sort-function)
5898 (sort (cdr to) (default-value 'imenu-sort-function))))
5899 ;; Now add back functions removed from display
5900 (mapcar (function (lambda (elt)
5901 (setcdr to (cons elt (cdr to)))))
5902 (if (default-value 'imenu-sort-function)
5904 (sort root-functions (default-value 'imenu-sort-function)))
5906 ;; Now add back packages removed from display
5907 (mapcar (function (lambda (elt)
5908 (setcdr to (cons (cons (concat "package " (car elt))
5911 (if (default-value 'imenu-sort-function)
5913 (sort root-packages (default-value 'imenu-sort-function)))
5918 ;;; '(keymap "Name1"
5922 ;;; ("Tail1" "x") ("Tail2" "y"))))
5924 (defun cperl-list-fold (list name limit)
5925 (let (list1 list2 elt1 (num 0))
5926 (if (<= (length list) limit) list
5927 (setq list1 nil list2 nil)
5932 (if (<= num imenu-max-items)
5933 (setq list2 (cons elt1 list2))
5934 (setq list1 (cons (cons name
5939 (nreverse (cons (cons name
5943 (defun cperl-menu-to-keymap (menu &optional name)
5949 (cond ((listp (cdr elt))
5950 (setq list (cperl-list-fold
5951 (cdr elt) (car elt) imenu-max-items))
5954 (cperl-menu-to-keymap list))))
5956 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
5957 (cperl-list-fold menu "Root" imenu-max-items)))))
5960 (defvar cperl-bad-style-regexp
5961 (mapconcat 'identity
5962 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
5963 "[-<>=+^&|]+[^- \t\n=+<>~]" ; sign+ char
5966 "Finds places such that insertion of a whitespace may help a lot.")
5968 (defvar cperl-not-bad-style-regexp
5969 (mapconcat 'identity
5970 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
5971 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
5972 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
5973 "<\\$?\\sw+\\(\\.\\sw+\\)?>" ; <IN> <stdin.h>
5974 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
5981 "\\\\[&$@*\\\\]" ; \&func
5984 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
5987 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
5988 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
5989 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
5993 "If matches at the start of match found by `my-bad-c-style-regexp',
5994 insertion of a whitespace will not help.")
5998 (defun cperl-find-bad-style ()
5999 "Find places in the buffer where insertion of a whitespace may help.
6000 Prompts user for insertion of spaces.
6001 Currently it is tuned to C and Perl syntax."
6003 (let (found-bad (p (point)))
6004 (setq last-nonmenu-event 13) ; To disable popup
6005 (beginning-of-buffer)
6006 (map-y-or-n-p "Insert space here? "
6007 (function (lambda (arg) (insert " ")))
6008 'cperl-next-bad-style
6009 '("location" "locations" "insert a space into")
6010 '((?\C-r (lambda (arg)
6011 (let ((buffer-quit-function
6012 'exit-recursive-edit))
6013 (message "Exit with Esc Esc")
6015 t)) ; Consider acted upon
6016 "edit, exit with Esc Esc")
6018 (let ((buffer-quit-function
6019 'exit-recursive-edit))
6020 (message "Exit with Esc Esc")
6022 t)) ; Consider acted upon
6023 "edit, exit with Esc Esc"))
6025 (if found-bad (goto-char found-bad)
6027 (message "No appropriate place found"))))
6029 (defun cperl-next-bad-style ()
6030 (let (p (not-found t) (point (point)) found)
6031 (while (and not-found
6032 (re-search-forward cperl-bad-style-regexp nil 'to-end))
6034 (goto-char (match-beginning 0))
6036 (looking-at cperl-not-bad-style-regexp)
6037 ;; Check for a < -b and friends
6038 (and (eq (following-char) ?\-)
6040 (skip-chars-backward " \t\n")
6041 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\(, ?\[, ?\{))))
6042 ;; Now check for syntax type
6044 (setq found (point))
6045 (beginning-of-defun)
6046 (let ((pps (parse-partial-sexp (point) found)))
6047 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
6048 (goto-char (match-end 0))
6056 (defvar cperl-have-help-regexp
6060 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
6061 "[$@]\\^[a-zA-Z]" ; Special variable
6062 "[$@][^ \n\t]" ; Special variable
6063 "-[a-zA-Z]" ; File test
6064 "\\\\[a-zA-Z0]" ; Special chars
6065 "^=[a-z][a-zA-Z0-9_]*" ; Pod sections
6066 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
6067 "[a-zA-Z_0-9:]+" ; symbol or number
6076 "Matches places in the buffer we can find help for.")
6078 (defvar cperl-message-on-help-error t)
6079 (defvar cperl-help-from-timer nil)
6081 (defun cperl-word-at-point-hard ()
6082 ;; Does not save-excursion
6083 ;; Get to the something meaningful
6084 (or (eobp) (eolp) (forward-char 1))
6085 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
6086 (save-excursion (beginning-of-line) (point))
6089 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
6090 ;; (skip-chars-backward " \n\t\r({[]});,")
6091 ;; (or (bobp) (backward-char 1))))
6094 ((looking-at "[a-zA-Z0-9_:]") ; symbol
6095 (skip-chars-backward "a-zA-Z0-9_:")
6097 ((and (eq (preceding-char) ?^) ; $^I
6098 (eq (char-after (- (point) 2)) ?\$))
6100 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
6102 ((and (eq (preceding-char) ?\=)
6103 (eq (current-column) 1))
6104 (forward-char -1))) ; =head1
6105 (if (and (eq (preceding-char) ?\<)
6106 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
6108 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
6110 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
6112 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
6113 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
6115 ((and (eq (preceding-char) ?\$)
6116 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
6118 ((and (eq (following-char) ?\>)
6119 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
6122 (and (eq (preceding-char) ?\<)
6123 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
6124 (search-backward "<"))))
6125 ((and (eq (following-char) ?\$)
6126 (eq (preceding-char) ?\<)
6127 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
6129 (if (looking-at cperl-have-help-regexp)
6130 (buffer-substring (match-beginning 0) (match-end 0))))
6132 (defun cperl-get-help ()
6133 "Get one-line docs on the symbol at the point.
6134 The data for these docs is a little bit obsolete and may be in fact longer
6135 than a line. Your contribution to update/shorten it is appreciated."
6137 (save-match-data ; May be called "inside" query-replace
6139 (let ((word (cperl-word-at-point-hard)))
6141 (if (and cperl-help-from-timer ; Bail out if not in mainland
6142 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
6143 (or (memq (get-text-property (point) 'face)
6144 '(font-lock-comment-face font-lock-string-face))
6145 (memq (get-text-property (point) 'syntax-type)
6146 '(pod here-doc format))))
6148 (cperl-describe-perl-symbol word))
6149 (if cperl-message-on-help-error
6150 (message "Nothing found for %s..."
6151 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
6153 ;;; Stolen from perl-descr.el by Johan Vromans:
6155 (defvar cperl-doc-buffer " *perl-doc*"
6156 "Where the documentation can be found.")
6158 (defun cperl-describe-perl-symbol (val)
6159 "Display the documentation of symbol at point, a Perl operator."
6160 (let ((enable-recursive-minibuffers t)
6163 ((string-match "^[&*][a-zA-Z_]" val)
6164 (setq val (concat (substring val 0 1) "NAME")))
6165 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
6166 (setq val (concat "@" (substring val 1 (match-end 1)))))
6167 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
6168 (setq val (concat "%" (substring val 1 (match-end 1)))))
6169 ((and (string= val "x") (string-match "^x=" val))
6171 ((string-match "^\\$[\C-a-\C-z]" val)
6172 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
6173 ((string-match "^CORE::" val)
6174 (setq val "CORE::"))
6175 ((string-match "^SUPER::" val)
6176 (setq val "SUPER::"))
6177 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
6178 (setq val "<NAME>")))
6179 (setq regexp (concat "^"
6180 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
6182 "\\([ \t([/]\\|$\\)"))
6184 ;; get the buffer with the documentation text
6185 (cperl-switch-to-doc-buffer)
6187 ;; lookup in the doc
6188 (goto-char (point-min))
6189 (let ((case-fold-search nil))
6191 (if (re-search-forward regexp (point-max) t)
6193 (beginning-of-line 1)
6194 (let ((lnstart (point)))
6196 (message "%s" (buffer-substring lnstart (point)))))
6197 (if cperl-message-on-help-error
6198 (message "No definition for %s" val)))))))
6200 (defvar cperl-short-docs "Ignore my value"
6201 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
6202 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
6203 ! ... Logical negation.
6204 ... != ... Numeric inequality.
6205 ... !~ ... Search pattern, substitution, or translation (negated).
6206 $! In numeric context: errno. In a string context: error string.
6207 $\" The separator which joins elements of arrays interpolated in strings.
6208 $# The output format for printed numbers. Initial value is %.15g or close.
6209 $$ Process number of this script. Changes in the fork()ed child process.
6210 $% The current page number of the currently selected output channel.
6212 The following variables are always local to the current block:
6214 $1 Match of the 1st set of parentheses in the last match (auto-local).
6215 $2 Match of the 2nd set of parentheses in the last match (auto-local).
6216 $3 Match of the 3rd set of parentheses in the last match (auto-local).
6217 $4 Match of the 4th set of parentheses in the last match (auto-local).
6218 $5 Match of the 5th set of parentheses in the last match (auto-local).
6219 $6 Match of the 6th set of parentheses in the last match (auto-local).
6220 $7 Match of the 7th set of parentheses in the last match (auto-local).
6221 $8 Match of the 8th set of parentheses in the last match (auto-local).
6222 $9 Match of the 9th set of parentheses in the last match (auto-local).
6223 $& The string matched by the last pattern match (auto-local).
6224 $' The string after what was matched by the last match (auto-local).
6225 $` The string before what was matched by the last match (auto-local).
6227 $( The real gid of this process.
6228 $) The effective gid of this process.
6229 $* Deprecated: Set to 1 to do multiline matching within a string.
6230 $+ The last bracket matched by the last search pattern.
6231 $, The output field separator for the print operator.
6232 $- The number of lines left on the page.
6233 $. The current input line number of the last filehandle that was read.
6234 $/ The input record separator, newline by default.
6235 $0 Name of the file containing the perl script being executed. May be set.
6236 $: String may be broken after these characters to fill ^-lines in a format.
6237 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
6238 $< The real uid of this process.
6239 $= The page length of the current output channel. Default is 60 lines.
6240 $> The effective uid of this process.
6241 $? The status returned by the last ``, pipe close or `system'.
6242 $@ The perl error message from the last eval or do @var{EXPR} command.
6243 $ARGV The name of the current file used with <> .
6244 $[ Deprecated: The index of the first element/char in an array/string.
6245 $\\ The output record separator for the print operator.
6246 $] The perl version string as displayed with perl -v.
6247 $^ The name of the current top-of-page format.
6248 $^A The current value of the write() accumulator for format() lines.
6249 $^D The value of the perl debug (-D) flags.
6250 $^E Information about the last system error other than that provided by $!.
6251 $^F The highest system file descriptor, ordinarily 2.
6252 $^H The current set of syntax checks enabled by `use strict'.
6253 $^I The value of the in-place edit extension (perl -i option).
6254 $^L What formats output to perform a formfeed. Default is \f.
6255 $^M A buffer for emergency memory allocation when running out of memory.
6256 $^O The operating system name under which this copy of Perl was built.
6257 $^P Internal debugging flag.
6258 $^T The time the script was started. Used by -A/-M/-C file tests.
6259 $^W True if warnings are requested (perl -w flag).
6260 $^X The name under which perl was invoked (argv[0] in C-speech).
6261 $_ The default input and pattern-searching space.
6262 $| Auto-flush after write/print on current output channel? Default 0.
6263 $~ The name of the current report format.
6264 ... % ... Modulo division.
6265 ... %= ... Modulo division assignment.
6266 %ENV Contains the current environment.
6267 %INC List of files that have been require-d or do-ne.
6268 %SIG Used to set signal handlers for various signals.
6269 ... & ... Bitwise and.
6270 ... && ... Logical and.
6271 ... &&= ... Logical and assignment.
6272 ... &= ... Bitwise and assignment.
6273 ... * ... Multiplication.
6274 ... ** ... Exponentiation.
6275 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
6276 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
6277 ... + ... Addition. +EXPR Makes EXPR into scalar context.
6278 ++ Auto-increment (magical on strings). ++EXPR EXPR++
6279 ... += ... Addition assignment.
6281 ... - ... Subtraction.
6282 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
6283 ... -= ... Subtraction assignment.
6284 -A Access time in days since script started.
6285 -B File is a non-text (binary) file.
6286 -C Inode change time in days since script started.
6287 -M Age in days since script started.
6288 -O File is owned by real uid.
6289 -R File is readable by real uid.
6290 -S File is a socket .
6291 -T File is a text file.
6292 -W File is writable by real uid.
6293 -X File is executable by real uid.
6294 -b File is a block special file.
6295 -c File is a character special file.
6296 -d File is a directory.
6298 -f File is a plain file.
6299 -g File has setgid bit set.
6300 -k File has sticky bit set.
6301 -l File is a symbolic link.
6302 -o File is owned by effective uid.
6303 -p File is a named pipe (FIFO).
6304 -r File is readable by effective uid.
6305 -s File has non-zero size.
6306 -t Tests if filehandle (STDIN by default) is opened to a tty.
6307 -u File has setuid bit set.
6308 -w File is writable by effective uid.
6309 -x File is executable by effective uid.
6310 -z File has zero size.
6311 . Concatenate strings.
6312 .. Alternation, also range operator.
6313 .= Concatenate assignment strings
6314 ... / ... Division. /PATTERN/ioxsmg Pattern match
6315 ... /= ... Division assignment.
6316 /PATTERN/ioxsmg Pattern match.
6317 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
6318 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
6319 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
6320 <> Reads line from union of files in @ARGV (= command line) and STDIN.
6321 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
6322 ... <= ... Numeric less than or equal to.
6323 ... <=> ... Numeric compare.
6324 ... = ... Assignment.
6325 ... == ... Numeric equality.
6326 ... =~ ... Search pattern, substitution, or translation
6327 ... > ... Numeric greater than.
6328 ... >= ... Numeric greater than or equal to.
6329 ... >> ... Bitwise shift right.
6330 ... >>= ... Bitwise shift right assignment.
6331 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
6332 ?PATTERN? One-time pattern match.
6333 @ARGV Command line arguments (not including the command name - see $0).
6334 @INC List of places to look for perl scripts during do/include/use.
6335 @_ Parameter array for subroutines. Also used by split unless in array context.
6336 \\ Creates reference to what follows, like \$var, or quotes non-\w in strings.
6337 \\0 Octal char, e.g. \\033.
6338 \\E Case modification terminator. See \\Q, \\L, and \\U.
6339 \\L Lowercase until \\E . See also \l, lc.
6340 \\U Upcase until \\E . See also \u, uc.
6341 \\Q Quote metacharacters until \\E . See also quotemeta.
6342 \\a Alarm character (octal 007).
6343 \\b Backspace character (octal 010).
6344 \\c Control character, e.g. \\c[ .
6345 \\e Escape character (octal 033).
6346 \\f Formfeed character (octal 014).
6347 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
6348 \\n Newline character (octal 012 on most systems).
6349 \\r Return character (octal 015 on most systems).
6350 \\t Tab character (octal 011).
6351 \\u Upcase the next character. See also \\U and \\l, ucfirst.
6352 \\x Hex character, e.g. \\x1b.
6353 ... ^ ... Bitwise exclusive or.
6354 __END__ Ends program source.
6355 __DATA__ Ends program source.
6356 __FILE__ Current (source) filename.
6357 __LINE__ Current line in current source.
6358 __PACKAGE__ Current package.
6359 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
6360 ARGVOUT Output filehandle with -i flag.
6361 BEGIN { ... } Immediately executed (during compilation) piece of code.
6362 END { ... } Pseudo-subroutine executed after the script finishes.
6363 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
6364 INIT { ... } Pseudo-subroutine executed before the script starts running.
6365 DATA Input filehandle for what follows after __END__ or __DATA__.
6366 accept(NEWSOCKET,GENERICSOCKET)
6379 ... cmp ... String compare.
6380 connect(SOCKET,NAME)
6381 continue of { block } continue { block }. Is executed after `next' or at end.
6383 crypt(PLAINTEXT,SALT)
6385 dbmopen(%HASH,DBNAME,MODE)
6389 do { ... }|SUBR while|until EXPR executes at least once
6390 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
6400 ... eq ... String equality.
6401 eval(EXPR) or eval { BLOCK }
6405 fcntl(FILEHANDLE,FUNCTION,SCALAR)
6407 flock(FILEHANDLE,OPERATION)
6408 for (EXPR;EXPR;EXPR) { ... }
6409 foreach [VAR] (@ARRAY) { ... }
6411 ... ge ... String greater than or equal.
6416 gethostbyaddr(ADDR,ADDRTYPE)
6420 getnetbyaddr(ADDR,ADDRTYPE)
6426 getpriority(WHICH,WHO)
6427 getprotobyname(NAME)
6428 getprotobynumber(NUMBER)
6433 getservbyname(NAME,PROTO)
6434 getservbyport(PORT,PROTO)
6437 getsockopt(SOCKET,LEVEL,OPTNAME)
6440 ... gt ... String greater than.
6442 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
6443 index(STR,SUBSTR[,OFFSET])
6445 ioctl(FILEHANDLE,FUNCTION,SCALAR)
6450 ... le ... String less than or equal.
6452 link(OLDFILE,NEWFILE)
6453 listen(SOCKET,QUEUESIZE)
6457 lstat(EXPR|FILEHANDLE|VAR)
6458 ... lt ... String less than.
6460 mkdir(FILENAME,MODE)
6463 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
6464 msgsnd(ID,MSG,FLAGS)
6465 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
6466 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
6467 ... ne ... String inequality.
6470 open(FILEHANDLE[,EXPR])
6471 opendir(DIRHANDLE,EXPR)
6472 ord(EXPR) ASCII value of the first char of the string.
6474 package NAME Introduces package context.
6475 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
6477 print [FILEHANDLE] [(LIST)]
6478 printf [FILEHANDLE] (FORMAT,LIST)
6480 q/STRING/ Synonym for 'STRING'
6481 qq/STRING/ Synonym for \"STRING\"
6482 qx/STRING/ Synonym for `STRING`
6484 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
6487 recv(SOCKET,SCALAR,LEN,FLAGS)
6489 rename(OLDNAME,NEWNAME)
6490 require [FILENAME | PERL_VERSION]
6494 rewinddir(DIRHANDLE)
6495 rindex(STR,SUBSTR[,OFFSET])
6497 s/PATTERN/REPLACEMENT/gieoxsm
6499 seek(FILEHANDLE,POSITION,WHENCE)
6500 seekdir(DIRHANDLE,POS)
6501 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
6502 semctl(ID,SEMNUM,CMD,ARG)
6503 semget(KEY,NSEMS,SIZE,FLAGS)
6505 send(SOCKET,MSG,FLAGS[,TO])
6507 sethostent(STAYOPEN)
6510 setpriority(WHICH,WHO,PRIORITY)
6511 setprotoent(STAYOPEN)
6513 setservent(STAYOPEN)
6514 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
6517 shmget(KEY,SIZE,FLAGS)
6518 shmread(ID,VAR,POS,SIZE)
6519 shmwrite(ID,STRING,POS,SIZE)
6520 shutdown(SOCKET,HOW)
6523 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
6524 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
6525 sort [SUBROUTINE] (LIST)
6526 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
6527 split[(/PATTERN/[,EXPR[,LIMIT]])]
6528 sprintf(FORMAT,LIST)
6531 stat(EXPR|FILEHANDLE|VAR)
6533 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
6534 substr(EXPR,OFFSET[,LEN])
6535 symlink(OLDFILE,NEWFILE)
6537 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
6539 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
6544 tr/SEARCHLIST/REPLACEMENTLIST/cds
6545 truncate(FILE|EXPR,LENGTH)
6548 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
6550 unpack(TEMPLATE,EXPR)
6552 until (EXPR) { ... } EXPR until EXPR
6555 vec(EXPR,OFFSET,BITS)
6558 wantarray Returns true if the sub/eval is called in list context.
6560 while (EXPR) { ... } EXPR while EXPR
6561 write[(EXPR|FILEHANDLE)]
6562 ... x ... Repeat string or array.
6563 x= ... Repetition assignment.
6564 y/SEARCHLIST/REPLACEMENTLIST/
6565 ... | ... Bitwise or.
6566 ... || ... Logical or.
6567 ~ ... Unary bitwise complement.
6568 #! OS interpreter indicator. If contains `perl', used for options, and -x.
6569 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
6570 CORE:: Prefix to access builtin function if imported sub obscures it.
6571 SUPER:: Prefix to lookup for a method in @ISA classes.
6572 DESTROY Shorthand for `sub DESTROY {...}'.
6573 ... EQ ... Obsolete synonym of `eq'.
6574 ... GE ... Obsolete synonym of `ge'.
6575 ... GT ... Obsolete synonym of `gt'.
6576 ... LE ... Obsolete synonym of `le'.
6577 ... LT ... Obsolete synonym of `lt'.
6578 ... NE ... Obsolete synonym of `ne'.
6579 abs [ EXPR ] absolute value
6580 ... and ... Low-precedence synonym for &&.
6581 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
6582 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
6583 chr Converts a number to char with the same ordinal.
6584 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
6585 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
6586 exists $HASH{KEY} True if the key exists.
6587 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
6588 formline PICTURE, LIST Backdoor into \"format\" processing.
6589 glob EXPR Synonym of <EXPR>.
6590 lc [ EXPR ] Returns lowercased EXPR.
6591 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
6592 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
6593 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
6594 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
6595 not ... Low-precedence synonym for ! - negation.
6596 ... or ... Low-precedence synonym for ||.
6597 pos STRING Set/Get end-position of the last match over this string, see \\G.
6598 quotemeta [ EXPR ] Quote regexp metacharacters.
6599 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
6600 readline FH Synonym of <FH>.
6601 readpipe CMD Synonym of `CMD`.
6602 ref [ EXPR ] Type of EXPR when dereferenced.
6603 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
6604 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
6605 tied Returns internal object for a tied data.
6606 uc [ EXPR ] Returns upcased EXPR.
6607 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
6608 untie VAR Unlink an object from a simple Perl variable.
6609 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
6610 ... xor ... Low-precedence synonym for exclusive or.
6611 prototype \&SUB Returns prototype of the function given a reference.
6612 =head1 Top-level heading.
6613 =head2 Second-level heading.
6614 =head3 Third-level heading (is there such?).
6615 =over [ NUMBER ] Start list.
6616 =item [ TITLE ] Start new item in the list.
6618 =cut Switch from POD to Perl.
6619 =pod Switch from Perl to POD.
6622 (defun cperl-switch-to-doc-buffer ()
6623 "Go to the perl documentation buffer and insert the documentation."
6625 (let ((buf (get-buffer-create cperl-doc-buffer)))
6627 (switch-to-buffer-other-window buf)
6629 (if (= (buffer-size) 0)
6631 (insert (documentation-property 'cperl-short-docs
6632 'variable-documentation))
6633 (setq buffer-read-only t)))))
6635 (defun cperl-beautify-regexp-piece (b e embed level)
6636 ;; b is before the starting delimiter, e before the ending
6637 ;; e should be a marker, may be changed, but remains "correct".
6638 ;; EMBED is nil iff we process the whole REx.
6639 ;; The REx is guarantied to have //x
6640 ;; LEVEL shows how many levels deep to go
6641 ;; position at enter and at leave is not defined
6642 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
6646 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
6650 ((looking-at "(\\?[^a-zA-Z]")
6652 ((looking-at "(\\?") ; (?i)
6656 (setq c (if embed (current-indentation) (1- (current-column)))
6657 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
6658 (or (looking-at "[ \t]*[\n#]")
6663 (if (re-search-forward "[^ \t]" e t)
6664 (progn ; Something before the ending delimiter
6666 (delete-horizontal-space)
6668 (indent-to-column c)
6669 (set-marker e (point))))
6672 (while (< (point) (marker-position e))
6676 (skip-chars-forward " \t")
6677 (delete-region s (point))
6678 (indent-to-column c1)
6682 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
6683 "\\|" ; Embedded variable
6684 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
6687 "\\|" ; simple-code simple-code*?
6688 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
6692 "\\((\\(\\?\\)?\\)" ; 7 8
6696 (goto-char (match-end 0))
6698 (cond ((match-beginning 1) ; Alphanum word + junk
6700 ((or (match-beginning 3) ; $ab[12]
6701 (and (match-beginning 5) ; X* X+ X{2,3}
6702 (eq (preceding-char) ?\{)))
6705 ((match-beginning 6) ; []
6707 (if (looking-at "\\^?\\]")
6708 (goto-char (match-end 0)))
6709 ;; XXXX POSIX classes?!
6710 (while (and (not pos)
6711 (re-search-forward "\\[:\\|\\]" e t))
6712 (if (eq (preceding-char) ?:)
6713 (or (re-search-forward ":\\]" e t)
6714 (error "[:POSIX:]-group in []-group not terminated"))
6716 (or (eq (preceding-char) ?\])
6717 (error "[]-group not terminated"))
6718 (if (eq (following-char) ?\{)
6721 (and (eq (following-char) ??)
6723 (re-search-forward "\\=\\([*+?]\\??\\)" e t)))
6724 ((match-beginning 7) ; ()
6725 (goto-char (match-beginning 0))
6726 (setq pos (current-column))
6729 (delete-horizontal-space)
6731 (indent-to-column c1)))
6734 ;; (or (forward-sexp 1)
6737 ;; (error "()-group not terminated")))
6738 (set-marker m (1- (point)))
6739 (set-marker m1 (point))
6741 (if (progn ; indent rigidly if multiline
6742 ;; In fact does not make a lot of sense, since
6743 ;; the starting position can be already lost due
6744 ;; to insertion of "\n" and " "
6746 (search-forward "\n" m1 t))
6747 (indent-rigidly (point) m1 (- c1 pos)))
6748 (setq level (1- level))
6750 ((not (match-beginning 8))
6751 (cperl-beautify-regexp-piece tmp m t level))
6752 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
6754 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
6755 (goto-char (+ 2 tmp))
6757 (cperl-beautify-regexp-piece (point) m t level))
6758 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
6759 (goto-char (+ 3 tmp))
6760 (cperl-beautify-regexp-piece (point) m t level))
6762 (cperl-beautify-regexp-piece tmp m t level))))
6764 (cond ((looking-at "[*+?]\\??")
6765 (goto-char (match-end 0)))
6766 ((eq (following-char) ?\{)
6768 (if (eq (following-char) ?\?)
6770 (skip-chars-forward " \t")
6772 (if (looking-at "[#\n]")
6774 (or (eolp) (indent-for-comment))
6775 (beginning-of-line 2))
6776 (delete-horizontal-space)
6780 ((match-beginning 9) ; |
6784 (if (re-search-forward "[^ \t]" tmp t)
6787 (delete-horizontal-space)
6790 (delete-region (point) tmp))
6791 (indent-to-column c)
6793 (skip-chars-forward " \t")
6795 (if (looking-at "[#\n]")
6796 (beginning-of-line 2)
6797 (delete-horizontal-space)
6801 (or (looking-at "[ \t\n]")
6804 (skip-chars-forward " \t"))
6805 (or (looking-at "[#\n]")
6806 (error "unknown code \"%s\" in a regexp"
6807 (buffer-substring (point) (1+ (point)))))
6808 (and inline (end-of-line 2)))
6809 ;; Special-case the last line of group
6810 (if (and (>= (point) (marker-position e))
6811 (/= (current-indentation) c))
6815 (skip-chars-forward " \t")
6816 (delete-region s (point))
6817 (indent-to-column c)))
6820 (defun cperl-make-regexp-x ()
6821 ;; Returns position of the start
6822 ;; XXX this is called too often! Need to cache the result!
6824 (or cperl-use-syntax-table-text-property
6825 (error "I need to have a regexp marked!"))
6827 (if (looking-at "\\s|")
6829 (if (looking-at "\\([smy]\\|qr\\)\\s|")
6831 (re-search-backward "\\s|"))) ; Assume it is scanned already.
6833 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
6834 (sub-p (eq (preceding-char) ?s)) s)
6836 (set-marker e (1- (point)))
6837 (setq delim (preceding-char))
6838 (if (and sub-p (eq delim (char-after (- (point) 2))))
6839 (error "Possible s/blah// - do not know how to deal with"))
6840 (if sub-p (forward-sexp 1))
6841 (if (looking-at "\\sw*x")
6844 ;; Protect fragile " ", "#"
6847 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
6853 (defun cperl-beautify-regexp (&optional deep)
6854 "do it. (Experimental, may change semantics, recheck the result.)
6855 We suppose that the regexp is scanned already."
6858 (prefix-numeric-value deep)
6861 (goto-char (cperl-make-regexp-x))
6862 (let ((b (point)) (e (make-marker)))
6864 (set-marker e (1- (point)))
6865 (cperl-beautify-regexp-piece b e nil deep))))
6867 (defun cperl-regext-to-level-start ()
6868 "Goto start of an enclosing group in regexp.
6869 We suppose that the regexp is scanned already."
6871 (let ((limit (cperl-make-regexp-x)) done)
6873 (or (eq (following-char) ?\()
6874 (search-backward "(" (1+ limit) t)
6875 (error "Cannot find `(' which starts a group"))
6878 (skip-chars-backward "\\")
6879 (looking-at "\\(\\\\\\\\\\)*(")))
6880 (or done (forward-char -1)))))
6882 (defun cperl-contract-level ()
6883 "Find an enclosing group in regexp and contract it.
6884 \(Experimental, may change semantics, recheck the result.)
6885 We suppose that the regexp is scanned already."
6887 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
6888 (cperl-regext-to-level-start)
6889 (let ((b (point)) (e (make-marker)) s c)
6891 (set-marker e (1- (point)))
6893 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
6895 ((match-beginning 1) ; #-comment
6896 (or c (setq c (current-indentation)))
6897 (beginning-of-line 2) ; Skip
6899 (skip-chars-forward " \t")
6900 (delete-region s (point))
6901 (indent-to-column c))
6904 (just-one-space))))))
6906 (defun cperl-contract-levels ()
6907 "Find an enclosing group in regexp and contract all the kids.
6908 \(Experimental, may change semantics, recheck the result.)
6909 We suppose that the regexp is scanned already."
6913 (cperl-regext-to-level-start)
6914 (error ; We are outside outermost group
6915 (goto-char (cperl-make-regexp-x))))
6916 (let ((b (point)) (e (make-marker)) s c)
6918 (set-marker e (1- (point)))
6920 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
6922 ((match-beginning 1) ; Skip
6925 (cperl-contract-level)))))))
6927 (defun cperl-beautify-level (&optional deep)
6928 "Find an enclosing group in regexp and beautify it.
6929 \(Experimental, may change semantics, recheck the result.)
6930 We suppose that the regexp is scanned already."
6933 (prefix-numeric-value deep)
6936 (cperl-regext-to-level-start)
6937 (let ((b (point)) (e (make-marker)))
6939 (set-marker e (1- (point)))
6940 (cperl-beautify-regexp-piece b e nil deep))))
6942 (defun cperl-invert-if-unless ()
6943 "Change `if (A) {B}' into `B if A;' etc if possible."
6945 (or (looking-at "\\<")
6947 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
6948 (let ((pos1 (point))
6949 pos2 pos3 pos4 pos5 s1 s2 state p pos45
6950 (s0 (buffer-substring (match-beginning 0) (match-end 0))))
6955 (if (eq (following-char) ?\( )
6962 ;; XXXX In fact may be `A if (B); {C}' ...
6963 (if (and (eq (following-char) ?\{ )
6965 (cperl-backward-to-noncomment pos3)
6966 (eq (preceding-char) ?\) )))
6967 (if (condition-case nil
6972 (looking-at "\\<els\\(e\\|if\\)\\>"))
6975 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" s0)
6976 (goto-char (1- pos5))
6977 (cperl-backward-to-noncomment pos4)
6978 (if (eq (preceding-char) ?\;)
6980 (setq pos45 (point))
6982 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" pos45 t)
6983 (setq p (match-beginning 0)
6984 s1 (buffer-substring p (match-end 0))
6985 state (parse-partial-sexp pos4 p))
6989 (error "`%s' inside `%s' BLOCK" s1 s0))
6990 (goto-char (match-end 0)))
6992 (goto-char (1+ pos4))
6993 (skip-chars-forward " \t\n")
6994 (setq s2 (buffer-substring (point) pos45))
6996 (or (looking-at ";?[ \t\n]*}")
6998 (skip-chars-forward "; \t\n")
6999 (setq s2 (concat s2 "\n" (buffer-substring (point) (1- pos5))))))
7002 (goto-char (1- pos3))
7003 (cperl-backward-to-noncomment pos2)
7004 (or (looking-at "[ \t\n]*)")
7005 (goto-char (1- pos3)))
7007 (goto-char (1+ pos2))
7008 (skip-chars-forward " \t\n")
7009 (setq s1 (buffer-substring (point) p))
7010 (delete-region pos4 pos5)
7011 (delete-region pos2 pos3)
7018 (delete-horizontal-space)
7020 (delete-horizontal-space)
7023 (cperl-indent-line))
7024 (error "`%s' (EXPR) not with an {BLOCK}" s0)))
7025 (error "`%s' not with an (EXPR)" s0)))
7026 (error "Not at `if', `unless', `while', `unless', `for' or `foreach'")))
7028 ;;; By Anthony Foiani <afoiani@uswest.com>
7029 ;;; Getting help on modules in C-h f ?
7030 ;;; This is a modified version of `man'.
7031 ;;; Need to teach it how to lookup functions
7032 (defun cperl-perldoc (word)
7033 "Run `perldoc' on WORD."
7035 (list (let* ((default-entry (cperl-word-at-point))
7037 (format "perldoc entry%s: "
7038 (if (string= default-entry "")
7040 (format " (default %s)" default-entry))))))
7041 (if (string= input "")
7042 (if (string= default-entry "")
7043 (error "No perldoc args given")
7047 (let* ((is-func (and
7048 (string-match "^[a-z]+$" word)
7049 (string-match (concat "^" word "\\>")
7050 (documentation-property
7052 'variable-documentation))))
7053 (manual-program (if is-func "perldoc -f" "perldoc")))
7054 (Man-getpage-in-background word)))
7056 (defun cperl-perldoc-at-point ()
7057 "Run a `perldoc' on the word around point."
7059 (cperl-perldoc (cperl-word-at-point)))
7061 (defcustom pod2man-program "pod2man"
7062 "*File name for `pod2man'."
7066 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
7067 (defun cperl-pod-to-manpage ()
7068 "Create a virtual manpage in Emacs from the Perl Online Documentation."
7071 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
7072 (bufname (concat "Man " buffer-file-name))
7073 (buffer (generate-new-buffer bufname)))
7076 (let ((process-environment (copy-sequence process-environment)))
7077 ;; Prevent any attempt to use display terminal fanciness.
7078 (setenv "TERM" "dumb")
7079 (set-process-sentinel
7080 (start-process pod2man-program buffer "sh" "-c"
7081 (format (cperl-pod2man-build-command) pod2man-args))
7082 'Man-bgproc-sentinel)))))
7084 (defun cperl-pod2man-build-command ()
7085 "Builds the entire background manpage and cleaning command."
7086 (let ((command (concat pod2man-program " %s 2>/dev/null"))
7087 (flist Man-filter-list))
7088 (while (and flist (car flist))
7089 (let ((pcom (car (car flist)))
7090 (pargs (cdr (car flist))))
7092 (concat command " | " pcom " "
7093 (mapconcat '(lambda (phrase)
7094 (if (not (stringp phrase))
7095 (error "Malformed Man-filter-list"))
7098 (setq flist (cdr flist))))
7101 (defun cperl-lazy-install ()) ; Avoid a warning
7103 (if (fboundp 'run-with-idle-timer)
7105 (defvar cperl-help-shown nil
7106 "Non-nil means that the help was already shown now.")
7108 (defvar cperl-lazy-installed nil
7109 "Non-nil means that the lazy-help handlers are installed now.")
7111 (defun cperl-lazy-install ()
7113 (make-variable-buffer-local 'cperl-help-shown)
7114 (if (and (cperl-val 'cperl-lazy-help-time)
7115 (not cperl-lazy-installed))
7117 (add-hook 'post-command-hook 'cperl-lazy-hook)
7118 (run-with-idle-timer
7119 (cperl-val 'cperl-lazy-help-time 1000000 5)
7121 'cperl-get-help-defer)
7122 (setq cperl-lazy-installed t))))
7124 (defun cperl-lazy-unstall ()
7126 (remove-hook 'post-command-hook 'cperl-lazy-hook)
7127 (cancel-function-timers 'cperl-get-help-defer)
7128 (setq cperl-lazy-installed nil))
7130 (defun cperl-lazy-hook ()
7131 (setq cperl-help-shown nil))
7133 (defun cperl-get-help-defer ()
7134 (when (memq major-mode '(perl-mode cperl-mode))
7135 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
7137 (setq cperl-help-shown t))))
7138 (cperl-lazy-install)))
7141 ;;; Plug for wrong font-lock:
7143 (defun cperl-font-lock-unfontify-region-function (beg end)
7144 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
7145 (inhibit-read-only t) (inhibit-point-motion-hooks t)
7146 before-change-functions after-change-functions
7147 deactivate-mark buffer-file-name buffer-file-truename)
7148 (remove-text-properties beg end '(face nil))
7149 (when (and (not modified) (buffer-modified-p))
7150 (set-buffer-modified-p nil))))
7152 (defvar cperl-d-l nil)
7153 (defun cperl-fontify-syntaxically (end)
7154 ;; Some vars for debugging only
7155 ;; (message "Syntaxifying...")
7156 (let (start (dbg (point)) (iend end)
7157 (istate (car cperl-syntax-state)))
7158 (and cperl-syntaxify-unwind
7159 (setq end (cperl-unwind-to-safe t end)))
7160 (setq start (point))
7161 (or cperl-syntax-done-to
7162 (setq cperl-syntax-done-to (point-min)))
7163 (if (or (not (boundp 'font-lock-hot-pass))
7164 (eval 'font-lock-hot-pass)
7165 t) ; Not debugged otherwise
7166 ;; Need to forget what is after `start'
7167 (setq start (min cperl-syntax-done-to start))
7168 ;; Fontification without a change
7169 (setq start (max cperl-syntax-done-to start)))
7171 (setq cperl-syntax-done-to start) ; In case what follows fails
7172 (cperl-find-pods-heres start end t nil t))
7173 (if (eq cperl-syntaxify-by-font-lock 'message)
7174 (message "Syntaxified %s..%s from %s to %s(%s), state %s-->%s"
7176 start end cperl-syntax-done-to
7177 istate (car cperl-syntax-state))) ; For debugging
7178 nil)) ; Do not iterate
7180 (defun cperl-fontify-update (end)
7181 (let ((pos (point)) prop posend)
7183 (setq prop (get-text-property pos 'cperl-postpone))
7184 (setq posend (next-single-property-change pos 'cperl-postpone nil end))
7185 (and prop (put-text-property pos posend (car prop) (cdr prop)))
7187 nil) ; Do not iterate
7189 (defun cperl-update-syntaxification (from to)
7190 (if (and cperl-use-syntax-table-text-property
7191 cperl-syntaxify-by-font-lock
7192 (or (null cperl-syntax-done-to)
7193 (< cperl-syntax-done-to to)))
7197 (cperl-fontify-syntaxically to)))))
7199 (defvar cperl-version
7200 (let ((v "Revision: 4.32"))
7201 (string-match ":\\s *\\([0-9.]+\\)" v)
7202 (substring v (match-beginning 1) (match-end 1)))
7203 "Version of IZ-supported CPerl package this file is based on.")
7205 (provide 'cperl-mode)
7207 ;;; cperl-mode.el ends here