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 `(defvar ,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 (defvar ,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" :slant italic
:underline t
))
556 (((class grayscale
) (background dark
))
557 (:foreground
"Gray80" :slant italic
:underline t
:weight bold
))
558 (((class color
) (background light
))
559 (:foreground
"chartreuse3"))
560 (((class color
) (background dark
))
561 (:foreground
,cperl-dark-foreground
))
562 (t (:weight bold
: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" :weight bold
))
569 (((class grayscale
) (background dark
))
570 (:foreground
"Gray80" :weight bold
))
571 (((class color
) (background light
))
572 (:foreground
"Blue" :background
"lightyellow2" :weight bold
))
573 (((class color
) (background dark
))
574 (:foreground
"yellow" :background
,cperl-dark-background
:weight bold
))
576 "Font Lock mode face used to highlight array names."
579 (defface cperl-hash-face
580 `((((class grayscale
) (background light
))
581 (:background
"Gray90" :weight bold
:slant italic
))
582 (((class grayscale
) (background dark
))
583 (:foreground
"Gray80" :weight bold
:slant italic
))
584 (((class color
) (background light
))
585 (:foreground
"Red" :background
"lightyellow2" :weight bold
:slant italic
))
586 (((class color
) (background dark
))
587 (:foreground
"Red" :background
,cperl-dark-background
:weight bold
:slant italic
))
588 (t (:weight bold
:slant italic
)))
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 (point) (point)))) 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-emacs"
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-imenu--function-name-regexp-perl
1247 "[ \t]*\\(sub\\|package\\)[ \t\n]+\\([a-zA-Z_0-9:']+\\)[ \t]*\\(([^()]*)[ \t]*\\)?"
1249 "=head\\([12]\\)[ \t]+\\([^\n]+\\)$"
1252 (defvar cperl-outline-regexp
1253 (concat cperl-imenu--function-name-regexp-perl
"\\|" "\\`"))
1255 (defvar cperl-mode-syntax-table nil
1256 "Syntax table in use in Cperl-mode buffers.")
1258 (defvar cperl-string-syntax-table nil
1259 "Syntax table in use in Cperl-mode string-like chunks.")
1261 (if cperl-mode-syntax-table
1263 (setq cperl-mode-syntax-table
(make-syntax-table))
1264 (modify-syntax-entry ?
\\ "\\" 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 (modify-syntax-entry ?-
"." cperl-mode-syntax-table
)
1269 (modify-syntax-entry ?
= "." cperl-mode-syntax-table
)
1270 (modify-syntax-entry ?%
"." cperl-mode-syntax-table
)
1271 (modify-syntax-entry ?
< "." cperl-mode-syntax-table
)
1272 (modify-syntax-entry ?
> "." cperl-mode-syntax-table
)
1273 (modify-syntax-entry ?
& "." cperl-mode-syntax-table
)
1274 (modify-syntax-entry ?$
"\\" cperl-mode-syntax-table
)
1275 (modify-syntax-entry ?
\n ">" cperl-mode-syntax-table
)
1276 (modify-syntax-entry ?
# "<" cperl-mode-syntax-table
)
1277 (modify-syntax-entry ?
' "\"" cperl-mode-syntax-table
)
1278 (modify-syntax-entry ?
` "\"" cperl-mode-syntax-table
)
1279 (if cperl-under-as-char
1280 (modify-syntax-entry ?_
"w" cperl-mode-syntax-table
))
1281 (modify-syntax-entry ?
: "_" cperl-mode-syntax-table
)
1282 (modify-syntax-entry ?|
"." cperl-mode-syntax-table
)
1283 (setq cperl-string-syntax-table
(copy-syntax-table cperl-mode-syntax-table
))
1284 (modify-syntax-entry ?$
"." cperl-string-syntax-table
)
1285 (modify-syntax-entry ?
# "." cperl-string-syntax-table
) ; (?# comment )
1290 (defvar cperl-faces-init nil
)
1292 (defvar cperl-msb-fixed nil
)
1294 (defun cperl-mode ()
1295 "Major mode for editing Perl code.
1296 Expression and list commands understand all C brackets.
1297 Tab indents for Perl code.
1298 Paragraphs are separated by blank lines only.
1299 Delete converts tabs to spaces as it moves back.
1301 Various characters in Perl almost always come in pairs: {}, (), [],
1302 sometimes <>. When the user types the first, she gets the second as
1303 well, with optional special formatting done on {}. (Disabled by
1304 default.) You can always quote (with \\[quoted-insert]) the left
1305 \"paren\" to avoid the expansion. The processing of < is special,
1306 since most the time you mean \"less\". Cperl mode tries to guess
1307 whether you want to type pair <>, and inserts is if it
1308 appropriate. You can set `cperl-electric-parens-string' to the string that
1309 contains the parenths from the above list you want to be electrical.
1310 Electricity of parenths is controlled by `cperl-electric-parens'.
1311 You may also set `cperl-electric-parens-mark' to have electric parens
1312 look for active mark and \"embrace\" a region if possible.'
1314 CPerl mode provides expansion of the Perl control constructs:
1316 if, else, elsif, unless, while, until, continue, do,
1317 for, foreach, formy and foreachmy.
1319 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
1321 The user types the keyword immediately followed by a space, which
1322 causes the construct to be expanded, and the point is positioned where
1323 she is most likely to want to be. eg. when the user types a space
1324 following \"if\" the following appears in the buffer: if () { or if ()
1325 } { } and the cursor is between the parentheses. The user can then
1326 type some boolean expression within the parens. Having done that,
1327 typing \\[cperl-linefeed] places you - appropriately indented - on a
1328 new line between the braces (if you typed \\[cperl-linefeed] in a POD
1329 directive line, then appropriate number of new lines is inserted).
1331 If CPerl decides that you want to insert \"English\" style construct like
1335 it will not do any expansion. See also help on variable
1336 `cperl-extra-newline-before-brace'. (Note that one can switch the
1337 help message on expansion by setting `cperl-message-electric-keyword'
1340 \\[cperl-linefeed] is a convenience replacement for typing carriage
1341 return. It places you in the next line with proper indentation, or if
1342 you type it inside the inline block of control construct, like
1344 foreach (@lines) {print; print}
1346 and you are on a boundary of a statement inside braces, it will
1347 transform the construct into a multiline and will place you into an
1348 appropriately indented blank line. If you need a usual
1349 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
1350 see documentation on `cperl-electric-linefeed'.
1352 Use \\[cperl-invert-if-unless] to change a construction of the form
1362 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
1363 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
1364 on electric space between $ and {, `cperl-electric-parens-string' is
1365 the string that contains parentheses that should be electric in CPerl
1366 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
1367 setting `cperl-electric-keywords' enables electric expansion of
1368 control structures in CPerl. `cperl-electric-linefeed' governs which
1369 one of two linefeed behavior is preferable. You can enable all these
1370 options simultaneously (recommended mode of use) by setting
1371 `cperl-hairy' to t. In this case you can switch separate options off
1372 by setting them to `null'. Note that one may undo the extra
1373 whitespace inserted by semis and braces in `auto-newline'-mode by
1374 consequent \\[cperl-electric-backspace].
1376 If your site has perl5 documentation in info format, you can use commands
1377 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
1378 These keys run commands `cperl-info-on-current-command' and
1379 `cperl-info-on-command', which one is which is controlled by variable
1380 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
1381 \(in turn affected by `cperl-hairy').
1383 Even if you have no info-format documentation, short one-liner-style
1384 help is available on \\[cperl-get-help], and one can run perldoc or
1387 It is possible to show this help automatically after some idle time.
1388 This is regulated by variable `cperl-lazy-help-time'. Default with
1389 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
1390 secs idle time . It is also possible to switch this on/off from the
1391 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
1393 Use \\[cperl-lineup] to vertically lineup some construction - put the
1394 beginning of the region at the start of construction, and make region
1395 span the needed amount of lines.
1397 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
1398 `cperl-pod-face', `cperl-pod-head-face' control processing of pod and
1399 here-docs sections. With capable Emaxen results of scan are used
1400 for indentation too, otherwise they are used for highlighting only.
1402 Variables controlling indentation style:
1403 `cperl-tab-always-indent'
1404 Non-nil means TAB in CPerl mode should always reindent the current line,
1405 regardless of where in the line point is when the TAB command is used.
1406 `cperl-indent-left-aligned-comments'
1407 Non-nil means that the comment starting in leftmost column should indent.
1408 `cperl-auto-newline'
1409 Non-nil means automatically newline before and after braces,
1410 and after colons and semicolons, inserted in Perl code. The following
1411 \\[cperl-electric-backspace] will remove the inserted whitespace.
1412 Insertion after colons requires both this variable and
1413 `cperl-auto-newline-after-colon' set.
1414 `cperl-auto-newline-after-colon'
1415 Non-nil means automatically newline even after colons.
1416 Subject to `cperl-auto-newline' setting.
1417 `cperl-indent-level'
1418 Indentation of Perl statements within surrounding block.
1419 The surrounding block's indentation is the indentation
1420 of the line on which the open-brace appears.
1421 `cperl-continued-statement-offset'
1422 Extra indentation given to a substatement, such as the
1423 then-clause of an if, or body of a while, or just a statement continuation.
1424 `cperl-continued-brace-offset'
1425 Extra indentation given to a brace that starts a substatement.
1426 This is in addition to `cperl-continued-statement-offset'.
1427 `cperl-brace-offset'
1428 Extra indentation for line if it starts with an open brace.
1429 `cperl-brace-imaginary-offset'
1430 An open brace following other text is treated as if it the line started
1431 this far to the right of the actual line indentation.
1432 `cperl-label-offset'
1433 Extra indentation for line that is a label.
1434 `cperl-min-label-indent'
1435 Minimal indentation for line that is a label.
1437 Settings for K&R and BSD indentation styles are
1438 `cperl-indent-level' 5 8
1439 `cperl-continued-statement-offset' 5 8
1440 `cperl-brace-offset' -5 -8
1441 `cperl-label-offset' -5 -8
1443 CPerl knows several indentation styles, and may bulk set the
1444 corresponding variables. Use \\[cperl-set-style] to do this. Use
1445 \\[cperl-set-style-back] to restore the memorized preexisting values
1446 \(both available from menu).
1448 If `cperl-indent-level' is 0, the statement after opening brace in
1449 column 0 is indented on
1450 `cperl-brace-offset'+`cperl-continued-statement-offset'.
1452 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
1455 DO NOT FORGET to read micro-docs (available from `Perl' menu)
1456 or as help on variables `cperl-tips', `cperl-problems',
1457 `cperl-non-problems', `cperl-praise', `cperl-speed'."
1459 (kill-all-local-variables)
1460 (use-local-map cperl-mode-map
)
1461 (if (cperl-val 'cperl-electric-linefeed
)
1463 (local-set-key "\C-J" 'cperl-linefeed
)
1464 (local-set-key "\C-C\C-J" 'newline-and-indent
)))
1466 (cperl-val 'cperl-clobber-lisp-bindings
)
1467 (cperl-val 'cperl-info-on-command-no-prompt
))
1469 ;; don't clobber the backspace binding:
1470 (cperl-define-key "\C-hf" 'cperl-info-on-current-command
[(control h
) f
])
1471 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
1472 [(control c
) (control h
) f
])))
1473 (setq major-mode
'cperl-mode
)
1474 (setq mode-name
"CPerl")
1475 (if (not cperl-mode-abbrev-table
)
1476 (let ((prev-a-c abbrevs-changed
))
1477 (define-abbrev-table 'cperl-mode-abbrev-table
'(
1478 ("if" "if" cperl-electric-keyword
0)
1479 ("elsif" "elsif" cperl-electric-keyword
0)
1480 ("while" "while" cperl-electric-keyword
0)
1481 ("until" "until" cperl-electric-keyword
0)
1482 ("unless" "unless" cperl-electric-keyword
0)
1483 ("else" "else" cperl-electric-else
0)
1484 ("continue" "continue" cperl-electric-else
0)
1485 ("for" "for" cperl-electric-keyword
0)
1486 ("foreach" "foreach" cperl-electric-keyword
0)
1487 ("formy" "formy" cperl-electric-keyword
0)
1488 ("foreachmy" "foreachmy" cperl-electric-keyword
0)
1489 ("do" "do" cperl-electric-keyword
0)
1490 ("=pod" "=pod" cperl-electric-pod
0)
1491 ("=over" "=over" cperl-electric-pod
0)
1492 ("=head1" "=head1" cperl-electric-pod
0)
1493 ("=head2" "=head2" cperl-electric-pod
0)
1494 ("pod" "pod" cperl-electric-pod
0)
1495 ("over" "over" cperl-electric-pod
0)
1496 ("head1" "head1" cperl-electric-pod
0)
1497 ("head2" "head2" cperl-electric-pod
0)))
1498 (setq abbrevs-changed prev-a-c
)))
1499 (setq local-abbrev-table cperl-mode-abbrev-table
)
1500 (abbrev-mode (if (cperl-val 'cperl-electric-keywords
) 1 0))
1501 (set-syntax-table cperl-mode-syntax-table
)
1502 (make-local-variable 'outline-regexp
)
1503 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
1504 (setq outline-regexp cperl-outline-regexp
)
1505 (make-local-variable 'outline-level
)
1506 (setq outline-level
'cperl-outline-level
)
1507 (make-local-variable 'paragraph-start
)
1508 (setq paragraph-start
(concat "^$\\|" page-delimiter
))
1509 (make-local-variable 'paragraph-separate
)
1510 (setq paragraph-separate paragraph-start
)
1511 (make-local-variable 'paragraph-ignore-fill-prefix
)
1512 (setq paragraph-ignore-fill-prefix t
)
1513 (make-local-variable 'indent-line-function
)
1514 (setq indent-line-function
'cperl-indent-line
)
1515 (make-local-variable 'require-final-newline
)
1516 (setq require-final-newline t
)
1517 (make-local-variable 'comment-start
)
1518 (setq comment-start
"# ")
1519 (make-local-variable 'comment-end
)
1520 (setq comment-end
"")
1521 (make-local-variable 'comment-column
)
1522 (setq comment-column cperl-comment-column
)
1523 (make-local-variable 'comment-start-skip
)
1524 (setq comment-start-skip
"#+ *")
1525 (make-local-variable 'defun-prompt-regexp
)
1526 (setq defun-prompt-regexp
"^[ \t]*sub[ \t]+\\([^ \t\n{(;]+\\)[ \t]*")
1527 (make-local-variable 'comment-indent-function
)
1528 (setq comment-indent-function
'cperl-comment-indent
)
1529 (make-local-variable 'parse-sexp-ignore-comments
)
1530 (setq parse-sexp-ignore-comments t
)
1531 (make-local-variable 'indent-region-function
)
1532 (setq indent-region-function
'cperl-indent-region
)
1533 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
1534 (make-local-variable 'imenu-create-index-function
)
1535 (setq imenu-create-index-function
1536 (function cperl-imenu--create-perl-index
))
1537 (make-local-variable 'imenu-sort-function
)
1538 (setq imenu-sort-function nil
)
1539 (make-local-variable 'vc-header-alist
)
1540 (set 'vc-header-alist cperl-vc-header-alist
) ; Avoid warning
1541 (make-local-variable 'font-lock-defaults
)
1542 (setq font-lock-defaults
1544 ((string< emacs-version
"19.30")
1545 '(cperl-font-lock-keywords-2))
1546 ((string< emacs-version
"19.33") ; Which one to use?
1547 '((cperl-font-lock-keywords
1548 cperl-font-lock-keywords-1
1549 cperl-font-lock-keywords-2
)))
1551 '((cperl-load-font-lock-keywords
1552 cperl-load-font-lock-keywords-1
1553 cperl-load-font-lock-keywords-2
)))))
1554 (make-local-variable 'cperl-syntax-state
)
1555 (if cperl-use-syntax-table-text-property
1557 (make-local-variable 'parse-sexp-lookup-properties
)
1558 ;; Do not introduce variable if not needed, we check it!
1559 (set 'parse-sexp-lookup-properties t
)
1560 ;; Fix broken font-lock:
1561 (or (boundp 'font-lock-unfontify-region-function
)
1562 (set 'font-lock-unfontify-region-function
1563 'font-lock-default-unfontify-region
))
1564 (make-local-variable 'font-lock-unfontify-region-function
)
1565 (set 'font-lock-unfontify-region-function
1566 'cperl-font-lock-unfontify-region-function
)
1567 (make-local-variable 'cperl-syntax-done-to
)
1568 ;; Another bug: unless font-lock-syntactic-keywords, font-lock
1569 ;; ignores syntax-table text-property. (t) is a hack
1570 ;; to make font-lock think that font-lock-syntactic-keywords
1572 (make-local-variable 'font-lock-syntactic-keywords
)
1573 (setq font-lock-syntactic-keywords
1574 (if cperl-syntaxify-by-font-lock
1575 '(t (cperl-fontify-syntaxically))
1577 (make-local-variable 'cperl-old-style
)
1578 (set (make-local-variable 'normal-auto-fill-function
)
1579 #'cperl-do-auto-fill
)
1580 (if (cperl-enable-font-lock)
1581 (if (cperl-val 'cperl-font-lock
)
1582 (progn (or cperl-faces-init
(cperl-init-faces))
1583 (font-lock-mode 1))))
1584 (and (boundp 'msb-menu-cond
)
1585 (not cperl-msb-fixed
)
1587 (if (featurep 'easymenu
)
1588 (easy-menu-add cperl-menu
)) ; A NOP in Emacs.
1589 (run-hooks 'cperl-mode-hook
)
1590 ;; After hooks since fontification will break this
1591 (if cperl-pod-here-scan
1592 (or ;;(and (boundp 'font-lock-mode)
1593 ;; (eval 'font-lock-mode) ; Avoid warning
1594 ;; (boundp 'font-lock-hot-pass) ; Newer font-lock
1595 cperl-syntaxify-by-font-lock
;;)
1596 (progn (or cperl-faces-init
(cperl-init-faces-weak))
1597 (cperl-find-pods-heres)))))
1599 ;; Fix for perldb - make default reasonable
1603 (perldb (read-from-minibuffer "Run perldb (like this): "
1604 (if (consp gud-perldb-history
)
1605 (car gud-perldb-history
)
1606 (concat "perl " ;;(file-name-nondirectory
1610 (buffer-file-name)))
1612 '(gud-perldb-history .
1))))
1614 (defun cperl-msb-fix ()
1615 ;; Adds perl files to msb menu, supposes that msb is already loaded
1616 (setq cperl-msb-fixed t
)
1617 (let* ((l (length msb-menu-cond
))
1618 (last (nth (1- l
) msb-menu-cond
))
1619 (precdr (nthcdr (- l
2) msb-menu-cond
)) ; cdr of this is last
1620 (handle (1- (nth 1 last
))))
1621 (setcdr precdr
(list
1623 '(memq major-mode
'(cperl-mode perl-mode
))
1628 ;; This is used by indent-for-comment
1629 ;; to decide how much to indent a comment in CPerl code
1630 ;; based on its context. Do fallback if comment is found wrong.
1632 (defvar cperl-wrong-comment
)
1633 (defvar cperl-st-cfence
'(14)) ; Comment-fence
1634 (defvar cperl-st-sfence
'(15)) ; String-fence
1635 (defvar cperl-st-punct
'(1))
1636 (defvar cperl-st-word
'(2))
1637 (defvar cperl-st-bra
'(4 . ?\
>))
1638 (defvar cperl-st-ket
'(5 . ?\
<))
1641 (defun cperl-comment-indent ()
1642 (let ((p (point)) (c (current-column)) was phony
)
1643 (if (looking-at "^#") 0 ; Existing comment at bol stays there.
1644 ;; Wrong comment found
1646 (setq was
(cperl-to-comment-or-eol)
1647 phony
(eq (get-text-property (point) 'syntax-table
)
1651 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
1652 (if (eq (preceding-char) ?\
#)
1657 (skip-chars-backward " \t")
1658 (max (1+ (current-column)) ; Else indent at comment column
1661 (insert comment-start
)
1662 (backward-char (length comment-start
)))
1663 (setq cperl-wrong-comment t
)
1664 (indent-to comment-column
1) ; Indent minimum 1
1665 c
))))) ; except leave at least one space.
1667 ;;;(defun cperl-comment-indent-fallback ()
1668 ;;; "Is called if the standard comment-search procedure fails.
1669 ;;;Point is at start of real comment."
1670 ;;; (let ((c (current-column)) target cnt prevc)
1671 ;;; (if (= c comment-column) nil
1672 ;;; (setq cnt (skip-chars-backward "[ \t]"))
1673 ;;; (setq target (max (1+ (setq prevc
1674 ;;; (current-column))) ; Else indent at comment column
1675 ;;; comment-column))
1676 ;;; (if (= c comment-column) nil
1677 ;;; (delete-backward-char cnt)
1678 ;;; (while (< prevc target)
1680 ;;; (setq prevc (current-column)))
1681 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
1682 ;;; (while (< prevc target)
1684 ;;; (setq prevc (current-column)))))))
1686 (defun cperl-indent-for-comment ()
1687 "Substitute for `indent-for-comment' in CPerl."
1689 (let (cperl-wrong-comment)
1690 (indent-for-comment)
1691 (if cperl-wrong-comment
1692 (progn (cperl-to-comment-or-eol)
1693 (forward-char (length comment-start
))))))
1695 (defun cperl-comment-region (b e arg
)
1696 "Comment or uncomment each line in the region in CPerl mode.
1697 See `comment-region'."
1698 (interactive "r\np")
1699 (let ((comment-start "#"))
1700 (comment-region b e arg
)))
1702 (defun cperl-uncomment-region (b e arg
)
1703 "Uncomment or comment each line in the region in CPerl mode.
1704 See `comment-region'."
1705 (interactive "r\np")
1706 (let ((comment-start "#"))
1707 (comment-region b e
(- arg
))))
1709 (defvar cperl-brace-recursing nil
)
1711 (defun cperl-electric-brace (arg &optional only-before
)
1712 "Insert character and correct line's indentation.
1713 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
1714 place (even in empty line), but not after. If after \")\" and the inserted
1715 char is \"{\", insert extra newline before only if
1716 `cperl-extra-newline-before-brace'."
1719 (other-end (if (and cperl-electric-parens-mark
1725 (not cperl-brace-recursing
)
1726 (cperl-val 'cperl-electric-parens
)
1727 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
1728 ;; Need to insert a matching pair
1731 (setq insertpos
(point-marker))
1732 (goto-char other-end
)
1733 (setq last-command-char ?\
{)
1734 (cperl-electric-lbrace arg insertpos
))
1736 ;: Check whether we close something "usual" with `}'
1737 (if (and (eq last-command-char ?\
})
1741 (up-list (- (prefix-numeric-value arg
)))
1742 ;;(cperl-after-block-p (point-min))
1743 (cperl-after-expr-p nil
"{;)"))
1745 ;; Just insert the guy
1746 (self-insert-command (prefix-numeric-value arg
))
1747 (if (and (not arg
) ; No args, end (of empty line or auto)
1749 (or (and (null only-before
)
1751 (skip-chars-backward " \t")
1753 (and (eq last-command-char ?\
{) ; Do not insert newline
1754 ;; if after ")" and `cperl-extra-newline-before-brace'
1755 ;; is nil, do not insert extra newline.
1756 (not cperl-extra-newline-before-brace
)
1758 (skip-chars-backward " \t")
1759 (eq (preceding-char) ?\
))))
1760 (if cperl-auto-newline
1761 (progn (cperl-indent-line) (newline) t
) nil
)))
1763 (self-insert-command (prefix-numeric-value arg
))
1765 (if cperl-auto-newline
1766 (setq insertpos
(1- (point))))
1767 (if (and cperl-auto-newline
(null only-before
))
1770 (cperl-indent-line)))
1772 (if insertpos
(progn (goto-char insertpos
)
1773 (search-forward (make-string
1774 1 last-command-char
))
1775 (setq insertpos
(1- (point)))))
1779 (goto-char insertpos
)
1780 (self-insert-command (prefix-numeric-value arg
)))
1781 (self-insert-command (prefix-numeric-value arg
)))))))
1783 (defun cperl-electric-lbrace (arg &optional end
)
1784 "Insert character, correct line's indentation, correct quoting by space."
1787 (cperl-brace-recursing t
)
1788 (cperl-auto-newline cperl-auto-newline
)
1790 (if (and cperl-electric-parens-mark
1797 (and (cperl-val 'cperl-electric-lbrace-space
)
1798 (eq (preceding-char) ?$
)
1800 (skip-chars-backward "$")
1801 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
1803 ;; Check whether we are in comment
1807 (not (looking-at "[ \t]*#")))
1808 (cperl-after-expr-p nil
"{;)"))
1810 (setq cperl-auto-newline nil
))
1811 (cperl-electric-brace arg
)
1812 (and (cperl-val 'cperl-electric-parens
)
1813 (eq last-command-char ?
{)
1814 (memq last-command-char
1815 (append cperl-electric-parens-string nil
))
1816 (or (if other-end
(goto-char (marker-position other-end
)))
1818 (setq last-command-char ?
} pos
(point))
1819 (progn (cperl-electric-brace arg t
)
1822 (defun cperl-electric-paren (arg)
1823 "Insert a matching pair of parentheses."
1825 (let ((beg (save-excursion (beginning-of-line) (point)))
1826 (other-end (if (and cperl-electric-parens-mark
1833 (if (and (cperl-val 'cperl-electric-parens
)
1834 (memq last-command-char
1835 (append cperl-electric-parens-string nil
))
1836 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
1837 ;;(not (save-excursion (search-backward "#" beg t)))
1838 (if (eq last-command-char ?
<)
1840 (and abbrev-mode
; later it is too late, may be after `for'
1842 (cperl-after-expr-p nil
"{;(,:="))
1845 (self-insert-command (prefix-numeric-value arg
))
1846 (if other-end
(goto-char (marker-position other-end
)))
1847 (insert (make-string
1848 (prefix-numeric-value arg
)
1849 (cdr (assoc last-command-char
'((?
{ .?
})
1853 (forward-char (- (prefix-numeric-value arg
))))
1854 (self-insert-command (prefix-numeric-value arg
)))))
1856 (defun cperl-electric-rparen (arg)
1857 "Insert a matching pair of parentheses if marking is active.
1858 If not, or if we are not at the end of marking range, would self-insert."
1860 (let ((beg (save-excursion (beginning-of-line) (point)))
1861 (other-end (if (and cperl-electric-parens-mark
1862 (cperl-val 'cperl-electric-parens
)
1863 (memq last-command-char
1864 (append cperl-electric-parens-string nil
))
1871 (cperl-val 'cperl-electric-parens
)
1872 (memq last-command-char
'( ?\
) ?\
] ?\
} ?\
> ))
1873 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
1874 ;;(not (save-excursion (search-backward "#" beg t)))
1877 (self-insert-command (prefix-numeric-value arg
))
1879 (if other-end
(goto-char other-end
))
1880 (insert (make-string
1881 (prefix-numeric-value arg
)
1882 (cdr (assoc last-command-char
'((?\
} . ?\
{)
1887 (self-insert-command (prefix-numeric-value arg
)))))
1889 (defun cperl-electric-keyword ()
1890 "Insert a construction appropriate after a keyword.
1891 Help message may be switched off by setting `cperl-message-electric-keyword'
1893 (let ((beg (save-excursion (beginning-of-line) (point)))
1894 (dollar (and (eq last-command-char ?$
)
1895 (eq this-command
'self-insert-command
)))
1896 (delete (and (memq last-command-char
'(?\ ?
\n ?
\t ?
\f))
1897 (memq this-command
'(self-insert-command newline
))))
1899 (and (save-excursion
1903 (setq do
(looking-at "do\\>")))
1905 (cperl-after-expr-p nil
"{;:"))
1909 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
1911 (save-excursion (or (not (re-search-backward "^=" nil t
))
1914 (and cperl-use-syntax-table-text-property
1915 (not (eq (get-text-property (point)
1919 (and (eq (preceding-char) ?y
)
1920 (progn ; "foreachmy"
1926 (memq this-command
'(self-insert-command newline
)))))
1927 (and dollar
(insert " $"))
1929 ;;(insert " () {\n}")
1931 (cperl-extra-newline-before-brace
1932 (insert (if do
"\n" " ()\n"))
1938 (and do
(insert " while ();")))
1940 (insert (if do
" {\n} while ();" " () {\n}")))
1942 (or (looking-at "[ \t]\\|$") (insert " "))
1944 (if dollar
(progn (search-backward "$")
1948 (search-backward ")"))
1950 (cperl-putback-char cperl-del-back-ch
))
1951 (if cperl-message-electric-keyword
1952 (message "Precede char by C-q to avoid expansion"))))))
1954 (defun cperl-ensure-newlines (n &optional pos
)
1955 "Make sure there are N newlines after the point."
1956 (or pos
(setq pos
(point)))
1957 (if (looking-at "\n")
1961 (cperl-ensure-newlines (1- n
) pos
)
1964 (defun cperl-electric-pod ()
1965 "Insert a POD chunk appropriate after a =POD directive."
1966 (let ((delete (and (memq last-command-char
'(?\ ?
\n ?
\t ?
\f))
1967 (memq this-command
'(self-insert-command newline
))))
1968 head1 notlast name p really-delete over
)
1969 (and (save-excursion
1972 (eq (preceding-char) ?
=)
1974 (setq head1
(looking-at "head1\\>[ \t]*$"))
1975 (setq over
(and (looking-at "over\\>[ \t]*$")
1976 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
1980 (get-text-property (point) 'in-pod
)
1981 (cperl-after-expr-p nil
"{;:")
1982 (and (re-search-backward
1983 ;; "\\(\\`\n?\\|\n\n\\)=\\sw+"
1984 "\\(\\`\n?\\|^\n\\)=\\sw+"
1988 (and cperl-use-syntax-table-text-property
1989 (not (eq (get-text-property (point) 'syntax-type
)
1993 (setq notlast
(re-search-forward "^\n=" nil t
)))
1997 (cperl-ensure-newlines 2)
2003 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
2004 nil t
)))) ; Only one
2007 (setq name
(file-name-sans-extension
2008 (file-name-nondirectory (buffer-file-name)))
2010 (insert " NAME\n\n" name
2011 " - \n\n=head1 SYNOPSIS\n\n\n\n"
2012 "=head1 DESCRIPTION")
2013 (cperl-ensure-newlines 4)
2017 (setq really-delete t
))
2022 (insert "\n\n=item \n\n\n\n"
2024 (cperl-ensure-newlines 2)
2028 (setq really-delete t
)))
2029 (if (and delete really-delete
)
2030 (cperl-putback-char cperl-del-back-ch
))))))
2032 (defun cperl-electric-else ()
2033 "Insert a construction appropriate after a keyword.
2034 Help message may be switched off by setting `cperl-message-electric-keyword'
2036 (let ((beg (save-excursion (beginning-of-line) (point))))
2037 (and (save-excursion
2039 (cperl-after-expr-p nil
"{;:"))
2043 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2045 (save-excursion (or (not (re-search-backward "^=" nil t
))
2047 (and cperl-use-syntax-table-text-property
2048 (not (eq (get-text-property (point)
2053 ;;(insert " {\n\n}")
2055 (cperl-extra-newline-before-brace
2063 (or (looking-at "[ \t]\\|$") (insert " "))
2067 (cperl-putback-char cperl-del-back-ch
)
2068 (setq this-command
'cperl-electric-else
)
2069 (if cperl-message-electric-keyword
2070 (message "Precede char by C-q to avoid expansion"))))))
2072 (defun cperl-linefeed ()
2073 "Go to end of line, open a new line and indent appropriately.
2074 If in POD, insert appropriate lines."
2076 (let ((beg (save-excursion (beginning-of-line) (point)))
2077 (end (save-excursion (end-of-line) (point)))
2078 (pos (point)) start over cut res
)
2079 (if (and ; Check if we need to split:
2080 ; i.e., on a boundary and inside "{...}"
2081 (save-excursion (cperl-to-comment-or-eol)
2082 (>= (point) pos
)) ; Not in a comment
2084 (skip-chars-backward " \t" beg
)
2086 (looking-at "[;{]")) ; After { or ; + spaces
2087 (looking-at "[ \t]*}") ; Before }
2088 (re-search-forward "\\=[ \t]*;" end t
)) ; Before spaces + ;
2091 (eq (car (parse-partial-sexp pos end -
1)) -
1)
2092 ; Leave the level of parens
2093 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
2095 (cperl-after-block-p (point-min))
2098 (setq start
(point-marker))
2099 (<= start pos
))))) ; Redundant? Are after the
2100 ; start of parens group.
2102 (skip-chars-backward " \t")
2103 (or (memq (preceding-char) (append ";{" nil
))
2109 (or (looking-at "{[ \t]*$") ; If there is a statement
2110 ; before, move it to separate line
2114 (cperl-indent-line)))
2115 (forward-line 1) ; We are on the target line
2118 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
2119 ; after, move it to separate line
2122 (search-backward "}" beg
)
2123 (skip-chars-backward " \t")
2124 (or (memq (preceding-char) (append ";{" nil
))
2129 (forward-line -
1) ; We are on the line before target
2131 (newline-and-indent))
2132 (end-of-line) ; else - no splitting
2134 ((and (looking-at "\n[ \t]*{$")
2136 (skip-chars-backward " \t")
2137 (eq (preceding-char) ?\
)))) ; Probably if () {} group
2138 ; with an extra newline.
2140 (cperl-indent-line))
2141 ((save-excursion ; In POD header
2142 (forward-paragraph -
1)
2143 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
2144 ;; We are after \n now, so look for the rest
2145 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
2147 (setq cut
(looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
2148 (setq over
(looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
2152 (forward-paragraph -
1)
2155 (setq cut
(buffer-substring (point)
2159 (delete-char (- (save-excursion (end-of-line) (point))
2161 (setq res
(expand-abbrev))
2167 (cperl-ensure-newlines (if cut
2 4))
2169 ((get-text-property (point) 'in-pod
) ; In POD section
2170 (cperl-ensure-newlines 4)
2172 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
2174 (cperl-indent-line))
2176 (newline-and-indent))))))
2178 (defun cperl-electric-semi (arg)
2179 "Insert character and correct line's indentation."
2181 (if cperl-auto-newline
2182 (cperl-electric-terminator arg
)
2183 (self-insert-command (prefix-numeric-value arg
))
2184 (if cperl-autoindent-on-semi
2185 (cperl-indent-line))))
2187 (defun cperl-electric-terminator (arg)
2188 "Insert character and correct line's indentation."
2190 (let (insertpos (end (point))
2191 (auto (and cperl-auto-newline
2192 (or (not (eq last-command-char ?
:))
2193 cperl-auto-newline-after-colon
))))
2194 (if (and ;;(not arg)
2196 (not (save-excursion
2198 (skip-chars-forward " \t")
2200 ;; Ignore in comment lines
2201 (= (following-char) ?
#)
2202 ;; Colon is special only after a label
2203 ;; So quickly rule out most other uses of colon
2204 ;; and do no indentation for them.
2205 (and (eq last-command-char ?
:)
2208 (skip-chars-forward " \t")
2209 (and (< (point) end
)
2210 (progn (goto-char (- end
1))
2211 (not (looking-at ":"))))))
2213 (beginning-of-defun)
2214 (let ((pps (parse-partial-sexp (point) end
)))
2215 (or (nth 3 pps
) (nth 4 pps
) (nth 5 pps
))))))))
2217 (self-insert-command (prefix-numeric-value arg
))
2219 (if auto
(setq insertpos
(point-marker)))
2225 (cperl-indent-line)))
2227 (if insertpos
(goto-char (1- (marker-position insertpos
)))
2232 (goto-char insertpos
)
2233 (self-insert-command (prefix-numeric-value arg
)))
2234 (self-insert-command (prefix-numeric-value arg
)))))
2236 (defun cperl-electric-backspace (arg)
2237 "Backspace-untabify, or remove the whitespace around the point inserted
2238 by an electric key."
2240 (if (and cperl-auto-newline
2241 (memq last-command
'(cperl-electric-semi
2242 cperl-electric-terminator
2243 cperl-electric-lbrace
))
2244 (memq (preceding-char) '(?\ ?
\t ?
\n)))
2246 (if (eq last-command
'cperl-electric-lbrace
)
2247 (skip-chars-forward " \t\n"))
2249 (skip-chars-backward " \t\n")
2250 (delete-region (point) p
))
2251 (and (eq last-command
'cperl-electric-else
)
2252 ;; We are removing the whitespace *inside* cperl-electric-else
2253 (setq this-command
'cperl-electric-else-really
))
2254 (if (and cperl-auto-newline
2255 (eq last-command
'cperl-electric-else-really
)
2256 (memq (preceding-char) '(?\ ?
\t ?
\n)))
2258 (skip-chars-forward " \t\n")
2260 (skip-chars-backward " \t\n")
2261 (delete-region (point) p
))
2262 (backward-delete-char-untabify arg
))))
2264 (defun cperl-inside-parens-p ()
2268 (narrow-to-region (point)
2269 (progn (beginning-of-defun) (point)))
2270 (goto-char (point-max))
2271 (= (char-after (or (scan-lists (point) -
1 1) (point-min))) ?\
()))
2274 (defun cperl-indent-command (&optional whole-exp
)
2275 "Indent current line as Perl code, or in some cases insert a tab character.
2276 If `cperl-tab-always-indent' is non-nil (the default), always indent current
2277 line. Otherwise, indent the current line only if point is at the left margin
2278 or in the line's indentation; otherwise insert a tab.
2280 A numeric argument, regardless of its value,
2281 means indent rigidly all the lines of the expression starting after point
2282 so that this line becomes properly indented.
2283 The relative indentation among the lines of the expression are preserved."
2285 (cperl-update-syntaxification (point) (point))
2287 ;; If arg, always indent this line as Perl
2288 ;; and shift remaining lines of expression the same amount.
2289 (let ((shift-amt (cperl-indent-line))
2292 (if cperl-tab-always-indent
2293 (beginning-of-line))
2300 (if (and shift-amt
(> end beg
))
2301 (indent-code-rigidly beg end shift-amt
"#")))
2302 (if (and (not cperl-tab-always-indent
)
2304 (skip-chars-backward " \t")
2307 (cperl-indent-line))))
2309 (defun cperl-indent-line (&optional parse-data
)
2310 "Indent current line as Perl code.
2311 Return the amount the indentation changed by."
2312 (let (indent i beg shift-amt
2313 (case-fold-search nil
)
2314 (pos (- (point-max) (point))))
2315 (setq indent
(cperl-calculate-indent parse-data
)
2319 (cond ((or (eq indent nil
) (eq indent t
))
2320 (setq indent
(current-indentation) i nil
))
2321 ;;((eq indent t) ; Never?
2322 ;; (setq indent (cperl-calculate-indent-within-comment)))
2323 ;;((looking-at "[ \t]*#")
2326 (skip-chars-forward " \t")
2327 (if (listp indent
) (setq indent
(car indent
)))
2328 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
2330 (setq indent
(max cperl-min-label-indent
2331 (+ indent cperl-label-offset
)))))
2332 ((= (following-char) ?
})
2333 (setq indent
(- indent cperl-indent-level
)))
2334 ((memq (following-char) '(?\
) ?\
])) ; To line up with opening paren.
2335 (setq indent
(+ indent cperl-close-paren-offset
)))
2336 ((= (following-char) ?
{)
2337 (setq indent
(+ indent cperl-brace-offset
))))))
2338 (skip-chars-forward " \t")
2339 (setq shift-amt
(and i
(- indent
(current-column))))
2340 (if (or (not shift-amt
)
2342 (if (> (- (point-max) pos
) (point))
2343 (goto-char (- (point-max) pos
)))
2344 (delete-region beg
(point))
2346 ;; If initial point was within line's indentation,
2347 ;; position after the indentation. Else stay at same point in text.
2348 (if (> (- (point-max) pos
) (point))
2349 (goto-char (- (point-max) pos
))))
2352 (defun cperl-after-label ()
2353 ;; Returns true if the point is after label. Does not do save-excursion.
2354 (and (eq (preceding-char) ?
:)
2355 (memq (char-syntax (char-after (- (point) 2)))
2359 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
2361 (defun cperl-get-state (&optional parse-start start-state
)
2362 ;; returns list (START STATE DEPTH PRESTART),
2363 ;; START is a good place to start parsing, or equal to
2364 ;; PARSE-START if preset,
2365 ;; STATE is what is returned by `parse-partial-sexp'.
2366 ;; DEPTH is true is we are immediately after end of block
2367 ;; which contains START.
2368 ;; PRESTART is the position basing on which START was found.
2370 (let ((start-point (point)) depth state start prestart
)
2371 (if (and parse-start
2372 (<= parse-start start-point
))
2373 (goto-char parse-start
)
2374 (beginning-of-defun)
2375 (setq start-state nil
))
2376 (setq prestart
(point))
2378 ;; Try to go out, if sub is not on the outermost level
2379 (while (< (point) start-point
)
2380 (setq start
(point) parse-start start depth nil
2381 state
(parse-partial-sexp start start-point -
1))
2382 (if (> (car state
) -
1) nil
2383 ;; The current line could start like }}}, so the indentation
2384 ;; corresponds to a different level than what we reached
2386 (beginning-of-line 2))) ; Go to the next line.
2387 (if start
(goto-char start
))) ; Not at the start of file
2388 (setq start
(point))
2389 (or state
(setq state
(parse-partial-sexp start start-point -
1 nil start-state
)))
2390 (list start state depth prestart
))))
2392 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
2393 ;; Positions is before ?\{. Checks whether it starts a block.
2394 ;; No save-excursion!
2395 (cperl-backward-to-noncomment (point-min))
2396 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil
)) ; Or label! \C-@ at bobp
2397 ; Label may be mixed up with `$blah :'
2398 (save-excursion (cperl-after-label))
2399 (and (memq (char-syntax (preceding-char)) '(?w ?_
))
2402 ;; Need take into account `bless', `return', `tr',...
2403 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
2404 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
2406 (skip-chars-backward " \t\n\f")
2407 (and (memq (char-syntax (preceding-char)) '(?w ?_
))
2411 "sub[ \t]+[a-zA-Z0-9_:]+[ \t\n\f]*\\(([^()]*)[ \t\n\f]*\\)?[#{]")))))))))
2413 (defvar cperl-look-for-prop
'((pod in-pod
) (here-doc-delim here-doc-group
)))
2415 (defun cperl-calculate-indent (&optional parse-data
) ; was parse-start
2416 "Return appropriate indentation for current line as Perl code.
2417 In usual case returns an integer: the column to indent to.
2418 Returns nil if line starts inside a string, t if in a comment.
2420 Will not correct the indentation for labels, but will correct it for braces
2421 and closing parentheses and brackets.."
2424 (and (memq (get-text-property (point) 'syntax-type
)
2425 '(pod here-doc here-doc-delim format
))
2426 (not (get-text-property (point) 'indentable
)))
2427 ;; before start of POD - whitespace found since do not have 'pod!
2428 (and (looking-at "[ \t]*\n=")
2429 (error "Spaces before pod section!"))
2430 (and (not cperl-indent-left-aligned-comments
)
2434 (let ((indent-point (point))
2435 (char-after (save-excursion
2436 (skip-chars-forward " \t")
2438 (in-pod (get-text-property (point) 'in-pod
))
2439 (pre-indent-point (point))
2440 p prop look-prop is-block delim
)
2443 ;; In the verbatim part, probably code example. What to do???
2448 (cperl-backward-to-noncomment nil
)
2449 (setq p
(max (point-min) (1- (point)))
2450 prop
(get-text-property p
'syntax-type
)
2451 look-prop
(or (nth 1 (assoc prop cperl-look-for-prop
))
2453 (if (memq prop
'(pod here-doc format here-doc-delim
))
2455 (goto-char (or (previous-single-property-change p look-prop
)
2458 (setq pre-indent-point
(point)))))))
2459 (goto-char pre-indent-point
)
2460 (let* ((case-fold-search nil
)
2461 (s-s (cperl-get-state (car parse-data
) (nth 1 parse-data
)))
2462 (start (or (nth 2 parse-data
)
2465 (containing-sexp (car (cdr state
)))
2468 ;;containing-sexp ;; We are buggy at toplevel :-(
2471 (setcar parse-data pre-indent-point
)
2472 (setcar (cdr parse-data
) state
)
2473 (or (nth 2 parse-data
)
2474 (setcar (cddr parse-data
) start
))
2475 ;; Before this point: end of statement
2476 (setq old-indent
(nth 3 parse-data
))))
2477 (cond ((get-text-property (point) 'indentable
)
2478 ;; indent to just after the surrounding open,
2479 ;; skip blanks if we do not close the expression.
2480 (goto-char (1+ (previous-single-property-change (point) 'indentable
)))
2481 (or (memq char-after
(append ")]}" nil
))
2482 (looking-at "[ \t]*\\(#\\|$\\)")
2483 (skip-chars-forward " \t"))
2485 ((or (nth 3 state
) (nth 4 state
))
2486 ;; return nil or t if should not change this line
2488 ;; XXXX Do we need to special-case this?
2489 ((null containing-sexp
)
2490 ;; Line is at top level. May be data or function definition,
2491 ;; or may be function argument declaration.
2492 ;; Indent like the previous top level line
2493 ;; unless that ends in a closeparen without semicolon,
2494 ;; in which case this line is the first argument decl.
2495 (skip-chars-forward " \t")
2498 (- (current-indentation)
2499 (if (nth 2 s-s
) cperl-indent-level
0)))
2500 (if (= char-after ?
{) cperl-continued-brace-offset
0)
2502 (cperl-backward-to-noncomment (or old-indent
(point-min)))
2503 ;; Look at previous line that's at column 0
2504 ;; to determine whether we are in top-level decls
2505 ;; or function's arg decls. Set basic-indent accordingly.
2506 ;; Now add a little if this is a continuation line.
2508 (eq (point) old-indent
) ; old-indent was at comment
2509 (eq (preceding-char) ?\
;)
2511 (and (eq (preceding-char) ?\
})
2512 (cperl-after-block-and-statement-beg
2513 (point-min))) ; Was start - too close
2514 (memq char-after
(append ")]}" nil
))
2515 (and (eq (preceding-char) ?\
:) ; label
2518 (skip-chars-backward " \t")
2519 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:"))))
2522 (not (eq char-after ?\C-j
)))
2523 (setcdr (cddr parse-data
)
2524 (list pre-indent-point
)))
2526 cperl-continued-statement-offset
))))
2529 (and (setq delim
(= (char-after containing-sexp
) ?
{))
2530 (save-excursion ; Is it a hash?
2531 (goto-char containing-sexp
)
2533 cperl-indent-parens-as-block
))
2534 ;; group is an expression, not a block:
2535 ;; indent to just after the surrounding open parens,
2536 ;; skip blanks if we do not close the expression.
2537 (goto-char (1+ containing-sexp
))
2538 (or (memq char-after
(append ")]}" nil
))
2539 (looking-at "[ \t]*\\(#\\|$\\)")
2540 (skip-chars-forward " \t"))
2543 ;; Containing-expr starts with \{. Check whether it is a hash.
2544 (goto-char containing-sexp
)
2545 (not (cperl-block-p)))
2546 (goto-char (1+ containing-sexp
))
2547 (or (memq char-after
2548 (append (if delim
"}" ")]}") nil
))
2549 (looking-at "[ \t]*\\(#\\|$\\)")
2550 (skip-chars-forward " \t"))
2553 (eq char-after ?\
}))
2554 ;; Correct indentation of trailing ?\}
2555 (+ cperl-indent-level cperl-close-paren-offset
)
2557 ;;; ((and (/= (char-after containing-sexp) ?{)
2558 ;;; (not cperl-indent-parens-as-block))
2559 ;;; ;; line is expression, not statement:
2560 ;;; ;; indent to just after the surrounding open,
2561 ;;; ;; skip blanks if we do not close the expression.
2562 ;;; (goto-char (1+ containing-sexp))
2563 ;;; (or (memq char-after (append ")]}" nil))
2564 ;;; (looking-at "[ \t]*\\(#\\|$\\)")
2565 ;;; (skip-chars-forward " \t"))
2566 ;;; (current-column))
2568 ;;; ;; Containing-expr starts with \{. Check whether it is a hash.
2569 ;;; (goto-char containing-sexp)
2570 ;;; (and (not (cperl-block-p))
2571 ;;; (not cperl-indent-parens-as-block)))
2572 ;;; (goto-char (1+ containing-sexp))
2573 ;;; (or (eq char-after ?\})
2574 ;;; (looking-at "[ \t]*\\(#\\|$\\)")
2575 ;;; (skip-chars-forward " \t"))
2576 ;;; (+ (current-column) ; Correct indentation of trailing ?\}
2577 ;;; (if (eq char-after ?\}) (+ cperl-indent-level
2578 ;;; cperl-close-paren-offset)
2581 ;; Statement level. Is it a continuation or a new statement?
2582 ;; Find previous non-comment character.
2583 (goto-char pre-indent-point
)
2584 (cperl-backward-to-noncomment containing-sexp
)
2585 ;; Back up over label lines, since they don't
2586 ;; affect whether our line is a continuation.
2588 (while ;;(or (eq (preceding-char) ?\,)
2589 (and (eq (preceding-char) ?
:)
2590 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
2591 (memq (char-syntax (char-after (- (point) 2)))
2594 (if (eq (preceding-char) ?\
,)
2595 ;; Will go to beginning of line, essentially.
2596 ;; Will ignore embedded sexpr XXXX.
2597 (cperl-backward-to-start-of-continued-exp containing-sexp
))
2599 (cperl-backward-to-noncomment containing-sexp
))
2600 ;; Now we get the answer.
2601 (if (not (or (eq (1- (point)) containing-sexp
)
2602 (memq (preceding-char)
2603 (append (if is-block
" ;{" " ,;{") '(nil)))
2604 (and (eq (preceding-char) ?\
})
2605 (cperl-after-block-and-statement-beg
2607 ;; This line is continuation of preceding line's statement;
2608 ;; indent `cperl-continued-statement-offset' more than the
2609 ;; previous line of the statement.
2611 ;; There might be a label on this line, just
2612 ;; consider it bad style and ignore it.
2614 (cperl-backward-to-start-of-continued-exp containing-sexp
)
2615 (+ (if (memq char-after
(append "}])" nil
))
2617 cperl-continued-statement-offset
)
2620 (not (eq char-after ?\
})))
2622 ;; Now it is a hash reference
2623 (+ cperl-indent-level cperl-close-paren-offset
))
2624 (if (looking-at "\\w+[ \t]*:")
2625 (if (> (current-indentation) cperl-min-label-indent
)
2626 (- (current-indentation) cperl-label-offset
)
2627 ;; Do not move `parse-data', this should
2628 ;; be quick anyway (this comment comes
2629 ;;from different location):
2630 (cperl-calculate-indent))
2632 (if (eq char-after ?\
{)
2633 cperl-continued-brace-offset
0)))
2634 ;; This line starts a new statement.
2635 ;; Position following last unclosed open.
2636 (goto-char containing-sexp
)
2637 ;; Is line first statement after an open-brace?
2639 ;; If no, find that first statement and indent like
2640 ;; it. If the first statement begins with label, do
2641 ;; not believe when the indentation of the label is too
2645 (setq old-indent
(current-indentation))
2646 (let ((colon-line-end 0))
2647 (while (progn (skip-chars-forward " \t\n")
2648 (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]"))
2649 ;; Skip over comments and labels following openbrace.
2650 (cond ((= (following-char) ?\
#)
2654 (save-excursion (end-of-line)
2655 (setq colon-line-end
(point)))
2656 (search-forward ":"))))
2657 ;; The first following code counts
2658 ;; if it is before the line we want to indent.
2659 (and (< (point) indent-point
)
2660 (if (> colon-line-end
(point)) ; After label
2661 (if (> (current-indentation)
2662 cperl-min-label-indent
)
2663 (- (current-indentation) cperl-label-offset
)
2664 ;; Do not believe: `max' is involved
2665 (+ old-indent cperl-indent-level
))
2666 (current-column)))))
2667 ;; If no previous statement,
2668 ;; indent it relative to line brace is on.
2669 ;; For open brace in column zero, don't let statement
2670 ;; start there too. If cperl-indent-level is zero,
2671 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
2672 ;; For open-braces not the first thing in a line,
2673 ;; add in cperl-brace-imaginary-offset.
2675 ;; If first thing on a line: ?????
2676 (+ (if (and (bolp) (zerop cperl-indent-level
))
2677 (+ cperl-brace-offset cperl-continued-statement-offset
)
2681 (not (eq char-after ?\
})))
2683 ;; Now it is a hash reference
2684 (+ cperl-indent-level cperl-close-paren-offset
))
2685 ;; Move back over whitespace before the openbrace.
2686 ;; If openbrace is not first nonwhite thing on the line,
2687 ;; add the cperl-brace-imaginary-offset.
2688 (progn (skip-chars-backward " \t")
2689 (if (bolp) 0 cperl-brace-imaginary-offset
))
2690 ;; If the openbrace is preceded by a parenthesized exp,
2691 ;; move to the beginning of that;
2692 ;; possibly a different line
2694 (if (eq (preceding-char) ?\
))
2696 ;; In the case it starts a subroutine, indent with
2697 ;; respect to `sub', not with respect to the
2698 ;; first thing on the line, say in the case of
2699 ;; anonymous sub in a hash.
2701 (skip-chars-backward " \t")
2702 (if (and (eq (preceding-char) ?b
)
2705 (looking-at "sub\\>"))
2709 (save-excursion (beginning-of-line) (point))
2711 (progn (goto-char (1+ old-indent
))
2712 (skip-chars-forward " \t")
2714 ;; Get initial indentation of the line we are on.
2715 ;; If line starts with label, calculate label indentation
2718 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
2719 (if (> (current-indentation) cperl-min-label-indent
)
2720 (- (current-indentation) cperl-label-offset
)
2721 ;; Do not move `parse-data', this should
2723 (cperl-calculate-indent))
2724 (current-indentation))))))))))))))
2726 (defvar cperl-indent-alist
2730 (toplevel-after-parenth 2)
2731 (toplevel-continued 2)
2733 "Alist of indentation rules for CPerl mode.
2736 number: add this amount of indentation.
2738 Not finished, not used.")
2740 (defun cperl-where-am-i (&optional parse-start start-state
)
2742 "Return a list of lists ((TYPE POS)...) of good points before the point.
2743 POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'.
2745 Not finished, not used."
2747 (let* ((start-point (point))
2748 (s-s (cperl-get-state))
2751 (prestart (nth 3 s-s
))
2752 (containing-sexp (car (cdr state
)))
2753 (case-fold-search nil
)
2754 (res (list (list 'parse-start start
) (list 'parse-prestart prestart
))))
2755 (cond ((nth 3 state
) ; In string
2756 (setq res
(cons (list 'string nil
(nth 3 state
)) res
))) ; What started string
2757 ((nth 4 state
) ; In comment
2758 (setq res
(cons '(comment) res
)))
2759 ((null containing-sexp
)
2760 ;; Line is at top level.
2761 ;; Indent like the previous top level line
2762 ;; unless that ends in a closeparen without semicolon,
2763 ;; in which case this line is the first argument decl.
2764 (cperl-backward-to-noncomment (or parse-start
(point-min)))
2765 ;;(skip-chars-backward " \t\f\n")
2768 (memq (preceding-char) (append ";}" nil
)))
2769 (setq res
(cons (list 'toplevel start
) res
)))
2770 ((eq (preceding-char) ?\
) )
2771 (setq res
(cons (list 'toplevel-after-parenth start
) res
)))
2773 (setq res
(cons (list 'toplevel-continued start
) res
)))))
2774 ((/= (char-after containing-sexp
) ?
{)
2775 ;; line is expression, not statement:
2776 ;; indent to just after the surrounding open.
2777 ;; skip blanks if we do not close the expression.
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
))))
2786 ;; Containing-expr starts with \{. Check whether it is a hash.
2787 (goto-char containing-sexp
)
2788 (not (cperl-block-p)))
2789 (setq res
(cons (list 'expression-blanks
2791 (goto-char (1+ containing-sexp
))
2792 (or (looking-at "[ \t]*\\(#\\|$\\)")
2793 (skip-chars-forward " \t"))
2795 (cons (list 'expression containing-sexp
) res
))))
2798 (setq res
(cons (list 'in-block containing-sexp
) res
))
2799 ;; Is it a continuation or a new statement?
2800 ;; Find previous non-comment character.
2801 (cperl-backward-to-noncomment containing-sexp
)
2802 ;; Back up over label lines, since they don't
2803 ;; affect whether our line is a continuation.
2804 ;; Back up comma-delimited lines too ?????
2805 (while (or (eq (preceding-char) ?\
,)
2806 (save-excursion (cperl-after-label)))
2807 (if (eq (preceding-char) ?\
,)
2808 ;; Will go to beginning of line, essentially
2809 ;; Will ignore embedded sexpr XXXX.
2810 (cperl-backward-to-start-of-continued-exp containing-sexp
))
2812 (cperl-backward-to-noncomment containing-sexp
))
2813 ;; Now we get the answer.
2814 (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
2815 ;; This line is continuation of preceding line's statement.
2816 (list (list 'statement-continued containing-sexp
))
2817 ;; This line starts a new statement.
2818 ;; Position following last unclosed open.
2819 (goto-char containing-sexp
)
2820 ;; Is line first statement after an open-brace?
2822 ;; If no, find that first statement and indent like
2823 ;; it. If the first statement begins with label, do
2824 ;; not believe when the indentation of the label is too
2828 (let ((colon-line-end 0))
2829 (while (progn (skip-chars-forward " \t\n" start-point
)
2830 (and (< (point) start-point
)
2832 "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
2833 ;; Skip over comments and labels following openbrace.
2834 (cond ((= (following-char) ?\
#)
2839 (save-excursion (end-of-line)
2840 (setq colon-line-end
(point)))
2841 (search-forward ":"))))
2842 ;; Now at the point, after label, or at start
2843 ;; of first statement in the block.
2844 (and (< (point) start-point
)
2845 (if (> colon-line-end
(point))
2846 ;; Before statement after label
2847 (if (> (current-indentation)
2848 cperl-min-label-indent
)
2849 (list (list 'label-in-block
(point)))
2850 ;; Do not believe: `max' is involved
2852 (list 'label-in-block-min-indent
(point))))
2854 (list 'statement-in-block
(point))))))
2855 ;; If no previous statement,
2856 ;; indent it relative to line brace is on.
2857 ;; For open brace in column zero, don't let statement
2858 ;; start there too. If cperl-indent-level is zero,
2859 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
2860 ;; For open-braces not the first thing in a line,
2861 ;; add in cperl-brace-imaginary-offset.
2863 ;; If first thing on a line: ?????
2864 (+ (if (and (bolp) (zerop cperl-indent-level
))
2865 (+ cperl-brace-offset cperl-continued-statement-offset
)
2867 ;; Move back over whitespace before the openbrace.
2868 ;; If openbrace is not first nonwhite thing on the line,
2869 ;; add the cperl-brace-imaginary-offset.
2870 (progn (skip-chars-backward " \t")
2871 (if (bolp) 0 cperl-brace-imaginary-offset
))
2872 ;; If the openbrace is preceded by a parenthesized exp,
2873 ;; move to the beginning of that;
2874 ;; possibly a different line
2876 (if (eq (preceding-char) ?\
))
2878 ;; Get initial indentation of the line we are on.
2879 ;; If line starts with label, calculate label indentation
2882 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
2883 (if (> (current-indentation) cperl-min-label-indent
)
2884 (- (current-indentation) cperl-label-offset
)
2885 (cperl-calculate-indent))
2886 (current-indentation))))))))
2889 (defun cperl-calculate-indent-within-comment ()
2890 "Return the indentation amount for line, assuming that
2891 the current line is to be regarded as part of a block comment."
2892 (let (end star-start
)
2895 (skip-chars-forward " \t")
2897 (and (= (following-char) ?
#)
2899 (cperl-to-comment-or-eol)
2905 (defun cperl-to-comment-or-eol ()
2906 "Go to position before comment on the current line, or to end of line.
2907 Returns true if comment is found."
2908 (let (state stop-in cpoint
(lim (progn (end-of-line) (point))))
2911 (eq (get-text-property (point) 'syntax-type
) 'pod
)
2912 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t
))
2913 (if (eq (preceding-char) ?\
#) (progn (backward-char 1) t
))
2915 (while (not stop-in
)
2916 (setq state
(parse-partial-sexp (point) lim nil nil nil t
))
2918 ;; If fails (beginning-of-line inside sexp), then contains not-comment
2919 (if (nth 4 state
) ; After `#';
2920 ; (nth 2 state) can be
2921 ; beginning of m,s,qq and so
2925 (setq cpoint
(point))
2926 (goto-char (nth 2 state
))
2928 ((looking-at "\\(s\\|tr\\)\\>")
2929 (or (re-search-forward
2930 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
2933 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
2934 (or (re-search-forward
2935 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
2938 (t ; It was fair comment
2939 (setq stop-in t
) ; Finish
2940 (goto-char (1- cpoint
)))))
2941 (setq stop-in t
) ; Finish
2943 (setq stop-in t
)) ; Finish
2947 (defsubst cperl-1-
(p)
2948 (max (point-min) (1- p
)))
2950 (defsubst cperl-1
+ (p)
2951 (min (point-max) (1+ p
)))
2953 (defsubst cperl-modify-syntax-type
(at how
)
2954 (if (< at
(point-max))
2956 (put-text-property at
(1+ at
) 'syntax-table how
)
2957 (put-text-property at
(1+ at
) 'rear-nonsticky t
))))
2959 (defun cperl-protect-defun-start (s e
)
2960 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
2963 (while (re-search-forward "^\\s(" e
'to-end
)
2964 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct
))))
2966 (defun cperl-commentify (bb e string
&optional noface
)
2967 (if cperl-use-syntax-table-text-property
2968 (if (eq noface
'n
) ; Only immediate
2970 ;; We suppose that e is _after_ the end of construction, as after eol.
2971 (setq string
(if string cperl-st-sfence cperl-st-cfence
))
2973 ;; one-char string/comment?!
2974 (cperl-modify-syntax-type bb cperl-st-punct
)
2975 (cperl-modify-syntax-type bb string
)
2976 (cperl-modify-syntax-type (1- e
) string
))
2977 (if (and (eq string cperl-st-sfence
) (> (- e
2) bb
))
2978 (put-text-property (1+ bb
) (1- e
)
2979 'syntax-table cperl-string-syntax-table
))
2980 (cperl-protect-defun-start bb e
))
2983 (not cperl-pod-here-fontify
)
2984 (put-text-property bb e
'face
(if string
'font-lock-string-face
2985 'font-lock-comment-face
)))))
2987 (defvar cperl-starters
'(( ?\
( . ?\
) )
2992 (defun cperl-forward-re (lim end is-2arg set-st st-l err-l argument
2993 &optional ostart oend
)
2994 ;; Works *before* syntax recognition is done
2995 ;; May modify syntax-type text property if the situation is too hard
2996 (let (b starter ender st i i2 go-forward reset-st
)
2997 (skip-chars-forward " \t")
2998 ;; ender means matching-char matcher.
3000 starter
(if (eobp) 0 (char-after b
))
3001 ender
(cdr (assoc starter cperl-starters
)))
3002 ;; What if starter == ?\\ ????
3005 (setq st
(car st-l
))
3006 (setcar st-l
(make-syntax-table))
3007 (setq i
0 st
(car st-l
))
3009 (modify-syntax-entry i
"." st
)
3011 (modify-syntax-entry ?
\\ "\\" st
)))
3013 ;; Whether we have an intermediate point
3015 ;; Prepare the syntax table:
3017 (if (not ender
) ; m/blah/, s/x//, s/x/y/
3018 (modify-syntax-entry starter
"$" st
)
3019 (modify-syntax-entry starter
(concat "(" (list ender
)) st
)
3020 (modify-syntax-entry ender
(concat ")" (list starter
)) st
)))
3023 ;; We use `$' syntax class to find matching stuff, but $$
3024 ;; is recognized the same as $, so we need to check this manually.
3025 (if (and (eq starter
(char-after (cperl-1+ b
)))
3027 ;; $ has TeXish matching rules, so $$ equiv $...
3029 (setq reset-st
(syntax-table))
3030 (set-syntax-table st
)
3032 (if (<= (point) (1+ b
))
3033 (error "Unfinished regular expression"))
3034 (set-syntax-table reset-st
)
3036 ;; Now the problem is with m;blah;;
3038 (eq (preceding-char)
3039 (char-after (- (point) 2)))
3042 (= 0 (%
(skip-chars-backward "\\\\") 2)))
3044 ;; Now we are after the first part.
3045 (and is-2arg
; Have trailing part
3047 (eq (following-char) starter
) ; Empty trailing part
3049 (or (eq (char-syntax (following-char)) ?.
)
3050 ;; Make trailing letter into punctuation
3051 (cperl-modify-syntax-type (point) cperl-st-punct
))
3052 (setq is-2arg nil go-forward t
))) ; Ignore the tail
3053 (if is-2arg
; Not number => have second part
3055 (setq i
(point) i2 i
)
3057 (if (memq (following-char) '(?\ ?
\t ?
\n ?
\f))
3059 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3060 (goto-char (match-end 0))
3061 (skip-chars-forward " \t\n\f"))
3064 (modify-syntax-entry starter
(if (eq starter ?
\\) "\\" ".") st
)
3065 (if ender
(modify-syntax-entry ender
"." st
))
3067 (setq ender
(cperl-forward-re lim end nil t st-l err-l
3068 argument starter ender
)
3069 ender
(nth 2 ender
)))))
3070 (error (goto-char lim
)
3073 (set-syntax-table reset-st
))
3076 "End of `%s%s%c ... %c' string/RE not found: %s"
3078 (if ostart
(format "%c ... %c" ostart
(or oend ostart
)) "")
3079 starter
(or ender starter
) bb
)
3080 (or (car err-l
) (setcar err-l b
)))))
3083 (modify-syntax-entry starter
(if (eq starter ?
\\) "\\" ".") st
)
3084 (if ender
(modify-syntax-entry ender
"." st
))))
3085 ;; i: have 2 args, after end of the first arg
3086 ;; i2: start of the second arg, if any (before delim iff `ender').
3087 ;; ender: the last arg bounded by parens-like chars, the second one of them
3088 ;; starter: the starting delimiter of the first arg
3089 ;; go-forward: has 2 args, and the second part is empty
3090 (list i i2 ender starter go-forward
)))
3092 (defsubst cperl-postpone-fontification
(b e type val
&optional now
)
3093 ;; Do after syntactic fontification?
3094 (if cperl-syntaxify-by-font-lock
3095 (or now
(put-text-property b e
'cperl-postpone
(cons type val
)))
3096 (put-text-property b e type val
)))
3098 ;;; Here is how the global structures (those which cannot be
3099 ;;; recognized locally) are marked:
3101 ;; Start-to-end is marked `in-pod' ==> t
3102 ;; Each non-literal part is marked `syntax-type' ==> `pod'
3103 ;; Each literal part is marked `syntax-type' ==> `in-pod'
3105 ;; Start-to-end is marked `here-doc-group' ==> t
3106 ;; The body is marked `syntax-type' ==> `here-doc'
3107 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
3109 ;; After-initial-line--to-end is marked `syntax-type' ==> `format'
3110 ;; d) 'Q'uoted string:
3111 ;; part between markers inclusive is marked `syntax-type' ==> `string'
3112 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
3114 (defun cperl-unwind-to-safe (before &optional end
)
3115 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
3116 (let ((pos (point)) opos
)
3118 (while (and pos
(get-text-property pos
'syntax-type
))
3119 (setq pos
(previous-single-property-change pos
'syntax-type
))
3123 (goto-char (cperl-1- pos
))
3126 (goto-char (setq pos
(cperl-1- pos
))))
3128 (goto-char (point-min))))
3130 (and (looking-at "\n*=")
3131 (/= 0 (skip-chars-backward "\n"))
3135 ;; Do the same for end, going small steps
3137 (while (and end
(get-text-property end
'syntax-type
))
3139 end
(next-single-property-change end
'syntax-type
)))
3142 (defvar cperl-nonoverridable-face
)
3143 (defvar font-lock-function-name-face
)
3144 (defvar font-lock-comment-face
)
3146 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max
)
3147 "Scans the buffer for hard-to-parse Perl constructions.
3148 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
3149 the sections using `cperl-pod-head-face', `cperl-pod-face',
3152 (or min
(setq min
(point-min)
3153 cperl-syntax-state nil
3154 cperl-syntax-done-to min
))
3155 (or max
(setq max
(point-max)))
3156 (let* (face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
3157 is-REx is-x-REx REx-comment-start REx-comment-end was-comment i2
3158 (cperl-pod-here-fontify (eval cperl-pod-here-fontify
)) go tmpend
3159 (case-fold-search nil
) (inhibit-read-only t
) (buffer-undo-list t
)
3160 (modified (buffer-modified-p))
3161 (after-change-functions nil
)
3162 (use-syntax-state (and cperl-syntax-state
3163 (>= min
(car cperl-syntax-state
))))
3164 (state-point (if use-syntax-state
3165 (car cperl-syntax-state
)
3167 (state (if use-syntax-state
3168 (cdr cperl-syntax-state
)))
3169 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
3170 (st-l (list nil
)) (err-l (list nil
))
3171 ;; Somehow font-lock may be not loaded yet...
3172 (font-lock-string-face (if (boundp 'font-lock-string-face
)
3173 font-lock-string-face
3174 'font-lock-string-face
))
3175 (font-lock-constant-face (if (boundp 'font-lock-constant-face
)
3176 font-lock-constant-face
3177 'font-lock-constant-face
))
3178 (font-lock-function-name-face
3179 (if (boundp 'font-lock-function-name-face
)
3180 font-lock-function-name-face
3181 'font-lock-function-name-face
))
3182 (font-lock-comment-face
3183 (if (boundp 'font-lock-comment-face
)
3184 font-lock-comment-face
3185 'font-lock-comment-face
))
3186 (cperl-nonoverridable-face
3187 (if (boundp 'cperl-nonoverridable-face
)
3188 cperl-nonoverridable-face
3189 'cperl-nonoverridable-face
))
3190 (stop-point (if ignore-max
3195 "\\(\\`\n?\\|^\n\\)="
3197 ;; One extra () before this:
3200 ;; First variant "BLAH" or just ``.
3201 "[ \t]*" ; Yes, whitespace is allowed!
3202 "\\([\"'`]\\)" ; 2 + 1 = 3
3203 "\\([^\"'`\n]*\\)" ; 3 + 1
3206 ;; Second variant: Identifier or \ID or empty
3207 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3208 ;; Do not have <<= or << 30 or <<30 or << $blah.
3209 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3210 "\\(\\)" ; To preserve count of pars :-( 6 + 1
3213 ;; 1+6 extra () before this:
3214 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
3215 (if cperl-use-syntax-table-text-property
3218 ;; 1+6+2=9 extra () before this:
3219 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
3221 ;; 1+6+2+1=10 extra () before this:
3222 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3224 ;; 1+6+2+1+1=11 extra () before this:
3225 "\\<sub\\>[ \t]*\\([a-zA-Z_:'0-9]+[ \t]*\\)?\\(([^()]*)\\)"
3227 ;; 1+6+2+1+1+2=13 extra () before this:
3230 ;; 1+6+2+1+1+2+1=14 extra () before this:
3231 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
3232 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
3234 "__\\(END\\|DATA\\)__"
3235 ;; 1+6+2+1+1+2+1+1+1=16 extra () before this:
3244 (message "Scanning for \"hard\" Perl constructions..."))
3245 (and cperl-pod-here-fontify
3246 ;; We had evals here, do not know why...
3247 (setq face cperl-pod-face
3248 head-face cperl-pod-head-face
3249 here-face cperl-here-face
))
3250 (remove-text-properties min max
3251 '(syntax-type t in-pod t syntax-table t
3256 ;; Need to remove face as well...
3258 (and (eq system-type
'emx
)
3259 (looking-at "extproc[ \t]") ; Analogue of #!
3260 (cperl-commentify min
3261 (save-excursion (end-of-line) (point))
3265 (re-search-forward search max t
))
3266 (setq tmpend nil
) ; Valid for most cases
3268 ((match-beginning 1) ; POD section
3269 ;; "\\(\\`\n?\\|^\n\\)="
3270 (if (looking-at "cut\\>")
3272 nil
; Doing a chunk only
3273 (message "=cut is not preceded by a POD section")
3274 (or (car err-l
) (setcar err-l
(point))))
3279 tb
(match-beginning 0)
3280 b1 nil
) ; error condition
3281 ;; We do not search to max, since we may be called from
3282 ;; some hook of fontification, and max is random
3283 (or (re-search-forward "^\n=cut\\>" stop-point
'toend
)
3286 (if (re-search-forward "\n=cut\\>" stop-point
'toend
)
3288 (message "=cut is not preceded by an empty line")
3290 (or (car err-l
) (setcar err-l b
))))))
3291 (beginning-of-line 2) ; An empty line after =cut is not POD!
3295 (remove-text-properties
3296 max e
'(syntax-type t in-pod t syntax-table t
3302 (put-text-property b e
'in-pod t
)
3303 (put-text-property b e
'syntax-type
'in-pod
)
3305 (while (re-search-forward "\n\n[ \t]" e t
)
3306 ;; We start 'pod 1 char earlier to include the preceding line
3308 (put-text-property (cperl-1- b
) (point) 'syntax-type
'pod
)
3309 (cperl-put-do-not-fontify b
(point) t
)
3310 ;; mark the non-literal parts as PODs
3311 (if cperl-pod-here-fontify
3312 (cperl-postpone-fontification b
(point) 'face face t
))
3313 (re-search-forward "\n\n[^ \t\f\n]" e
'toend
)
3316 (put-text-property (cperl-1- (point)) e
'syntax-type
'pod
)
3317 (cperl-put-do-not-fontify (point) e t
)
3318 (if cperl-pod-here-fontify
3320 ;; mark the non-literal parts as PODs
3321 (cperl-postpone-fontification (point) e
'face face t
)
3324 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
3326 (cperl-postpone-fontification
3327 (match-beginning 1) (match-end 1)
3329 (while (re-search-forward
3331 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
3334 (cperl-postpone-fontification
3335 (match-beginning 1) (match-end 1)
3337 (cperl-commentify bb e nil
)
3339 (or (eq e
(point-max))
3340 (forward-char -
1)))) ; Prepare for immediate pod start.
3342 ;; We do only one here-per-line
3343 ;; ;; One extra () before this:
3346 ;; ;; First variant "BLAH" or just ``.
3347 ;; "\\([\"'`]\\)" ; 2 + 1
3348 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
3351 ;; ;; Second variant: Identifier or \ID or empty
3352 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3353 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
3354 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3355 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
3357 ((match-beginning 2) ; 1 + 1
3358 ;; Abort in comment:
3360 (setq state
(parse-partial-sexp state-point b nil nil state
)
3362 tb
(match-beginning 0)
3363 i
(or (nth 3 state
) (nth 4 state
)))
3368 (not (match-beginning 6)) ; Empty
3370 "[ \t]*[=0-9$@%&(]"))))
3371 (if c
; Not here-doc
3373 (if (match-beginning 5) ;4 + 1
3374 (setq b1
(match-beginning 5) ; 4 + 1
3375 e1
(match-end 5)) ; 4 + 1
3376 (setq b1
(match-beginning 4) ; 3 + 1
3377 e1
(match-end 4))) ; 3 + 1
3378 (setq tag
(buffer-substring b1 e1
)
3379 qtag
(regexp-quote tag
))
3380 (cond (cperl-pod-here-fontify
3381 ;; Highlight the starting delimiter
3382 (cperl-postpone-fontification b1 e1
'face font-lock-constant-face
)
3383 (cperl-put-do-not-fontify b1 e1 t
)))
3386 ;; We do not search to max, since we may be called from
3387 ;; some hook of fontification, and max is random
3388 (cond ((re-search-forward (concat "^" qtag
"$")
3390 (if cperl-pod-here-fontify
3392 ;; Highlight the ending delimiter
3393 (cperl-postpone-fontification (match-beginning 0) (match-end 0)
3394 'face font-lock-constant-face
)
3395 (cperl-put-do-not-fontify b
(match-end 0) t
)
3396 ;; Highlight the HERE-DOC
3397 (cperl-postpone-fontification b
(match-beginning 0)
3399 (setq e1
(cperl-1+ (match-end 0)))
3400 (put-text-property b
(match-beginning 0)
3401 'syntax-type
'here-doc
)
3402 (put-text-property (match-beginning 0) e1
3403 'syntax-type
'here-doc-delim
)
3404 (put-text-property b e1
3406 (cperl-commentify b e1 nil
)
3407 (cperl-put-do-not-fontify b
(match-end 0) t
)
3410 (t (message "End of here-document `%s' not found." tag
)
3411 (or (car err-l
) (setcar err-l b
))))))
3413 ((match-beginning 8)
3414 ;; 1+6=7 extra () before this:
3415 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
3417 name
(if (match-beginning 8) ; 7 + 1
3418 (buffer-substring (match-beginning 8) ; 7 + 1
3419 (match-end 8)) ; 7 + 1
3421 tb
(match-beginning 0))
3423 (if cperl-pod-here-fontify
3424 (while (and (eq (forward-line) 0)
3425 (not (looking-at "^[.;]$")))
3427 ((looking-at "^#")) ; Skip comments
3428 ((and argument
; Skip argument multi-lines
3429 (looking-at "^[ \t]*{"))
3431 (setq argument nil
))
3432 (argument ; Skip argument lines
3433 (setq argument nil
))
3436 (setq argument
(looking-at "^[^\n]*[@^]"))
3438 ;; Highlight the format line
3439 (cperl-postpone-fontification b1
(point)
3440 'face font-lock-string-face
)
3441 (cperl-commentify b1
(point) nil
)
3442 (cperl-put-do-not-fontify b1
(point) t
))))
3443 ;; We do not search to max, since we may be called from
3444 ;; some hook of fontification, and max is random
3445 (re-search-forward "^[.;]$" stop-point
'toend
))
3447 (if (looking-at "^\\.$") ; ";" is not supported yet
3449 ;; Highlight the ending delimiter
3450 (cperl-postpone-fontification (point) (+ (point) 2)
3451 'face font-lock-string-face
)
3452 (cperl-commentify (point) (+ (point) 2) nil
)
3453 (cperl-put-do-not-fontify (point) (+ (point) 2) t
))
3454 (message "End of format `%s' not found." name
)
3455 (or (car err-l
) (setcar err-l b
)))
3459 (put-text-property b
(point) 'syntax-type
'format
))
3461 ((or (match-beginning 10) (match-beginning 11))
3462 ;; 1+6+2=9 extra () before this:
3463 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
3465 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3466 (setq b1
(if (match-beginning 10) 10 11)
3467 argument
(buffer-substring
3468 (match-beginning b1
) (match-end b1
))
3471 c
(char-after (match-beginning b1
))
3472 bb
(char-after (1- (match-beginning b1
))) ; tmp holder
3473 ;; bb == "Not a stringy"
3474 bb
(if (eq b1
10) ; user variables/whatever
3476 (memq bb
'(?\$ ?\
@ ?\% ?\
* ?\
#)) ; $#y
3477 (and (eq bb ?-
) (eq c ?s
)) ; -s file test
3479 (not (eq (char-after ; &&m/blah/
3480 (- (match-beginning b1
) 2))
3482 ;; <file> or <$file>
3484 ;; Do not stringify <FH>, <$fh> :
3487 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
3488 tb
(match-beginning 0))
3489 (goto-char (match-beginning b1
))
3490 (cperl-backward-to-noncomment (point-min))
3492 (if (eq b1
11) ; bare /blah/ or ?blah? or <foo>
3497 ;; What is below: regexp-p?
3499 (or (memq (preceding-char)
3500 (append (if (memq c
'(?
\? ?\
<))
3503 "~{(=|&+-*!,;:") nil
))
3504 (and (eq (preceding-char) ?\
})
3505 (cperl-after-block-p (point-min)))
3506 (and (eq (char-syntax (preceding-char)) ?w
)
3509 ;; After these keywords `/' starts a RE. One should add all the
3510 ;; functions/builtins which expect an argument, but ...
3511 (if (eq (preceding-char) ?-
)
3513 (looking-at "[a-zA-Z]\\>")
3515 (not (memq (preceding-char)
3518 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
3519 (and (eq (preceding-char) ?.
)
3520 (eq (char-after (- (point) 2)) ?.
))
3522 ;; m|blah| ? foo : bar;
3525 cperl-use-syntax-table-text-property
3529 (looking-at "\\s|")))))))
3533 (if (and (eq (preceding-char) ?
>)
3534 (eq (char-after (- (point) 2)) ?-
))
3537 (or bb
(setq state
(parse-partial-sexp
3538 state-point b nil nil state
)
3541 (if (or bb
(nth 3 state
) (nth 4 state
))
3543 ;; Skip whitespace and comments...
3544 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3545 (goto-char (match-end 0))
3546 (skip-chars-forward " \t\n\f"))
3548 (put-text-property b
(point) 'syntax-type
'prestring
))
3549 ;; qtag means two-arg matcher, may be reset to
3550 ;; 2 or 3 later if some special quoting is needed.
3551 ;; e1 means matching-char matcher.
3554 i2
(string-match "^\\([sy]\\|tr\\)$" argument
)
3555 ;; We do not search to max, since we may be called from
3556 ;; some hook of fontification, and max is random
3557 i
(cperl-forward-re stop-point end
3559 t st-l err-l argument
)
3560 ;; Note that if `go', then it is considered as 1-arg
3561 b1
(nth 1 i
) ; start of the second part
3562 tag
(nth 2 i
) ; ender-char, true if second part
3563 ; is with matching chars []
3564 go
(nth 4 i
) ; There is a 1-char part after the end
3565 i
(car i
) ; intermediate point
3567 ;; Before end of the second part if non-matching: ///
3568 tail
(if (and i
(not tag
))
3570 e
(if i i e1
) ; end of the first part
3571 qtag nil
; need to preserve backslashitis
3572 is-x-REx nil
) ; REx has //x modifier
3573 ;; Commenting \\ is dangerous, what about ( ?
3575 (eq (char-after i
) ?
\\)
3577 (if (looking-at "\\sw*x") ; qr//x
3580 ;; Considered as 1arg form
3582 (cperl-commentify b
(point) t
)
3583 (put-text-property b
(point) 'syntax-type
'string
)
3585 ;; ignore other text properties:
3586 (string-match "^qw$" argument
))
3587 (put-text-property b
(point) 'indentable t
))
3589 (setq e1
(cperl-1+ e1
))
3592 (cperl-commentify b i t
)
3593 (if (looking-at "\\sw*e") ; s///e
3597 (cperl-find-pods-heres b1
(1- (point)) t end
)
3599 (goto-char (1+ max
)))
3600 (if (and tag
(eq (preceding-char) ?\
>))
3602 (cperl-modify-syntax-type (1- (point)) cperl-st-ket
)
3603 (cperl-modify-syntax-type i cperl-st-bra
)))
3604 (put-text-property b i
'syntax-type
'string
)
3606 (put-text-property b i
'indentable t
)))
3607 (cperl-commentify b1
(point) t
)
3608 (put-text-property b
(point) 'syntax-type
'string
)
3610 (put-text-property b i
'indentable t
))
3612 (cperl-modify-syntax-type (1+ i
) cperl-st-punct
))
3614 ;; Now: tail: if the second part is non-matching without ///e
3615 (if (eq (char-syntax (following-char)) ?w
)
3617 (forward-word 1) ; skip modifiers s///s
3618 (if tail
(cperl-commentify tail
(point) t
))
3619 (cperl-postpone-fontification
3620 e1
(point) 'face
'cperl-nonoverridable-face
)))
3621 ;; Check whether it is m// which means "previous match"
3622 ;; and highlight differently
3624 (and (string-match "^\\([sm]?\\|qr\\)$" argument
)
3625 (or (not (= (length argument
) 0))
3629 ;; split // *is* using zero-pattern
3635 (not (looking-at "split\\>")))
3637 (cperl-postpone-fontification
3638 b e
'face font-lock-function-name-face
)
3639 (if (or i2
; Has 2 args
3640 (and cperl-fontify-m-as-s
3642 (string-match "^\\(m\\|qr\\)$" argument
)
3643 (and (eq 0 (length argument
))
3644 (not (eq ?\
< (char-after b
)))))))
3646 (cperl-postpone-fontification
3647 b
(cperl-1+ b
) 'face font-lock-constant-face
)
3648 (cperl-postpone-fontification
3649 (1- e
) e
'face font-lock-constant-face
)))
3650 (if (and is-REx cperl-regexp-scan
)
3651 ;; Process RExen better
3658 (if (eq (char-after b
) ?\
#)
3659 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
3660 "\\((\\?#\\)\\|\\(#\\)")
3661 (if (eq (char-after b
) ?\
#)
3665 (goto-char (match-beginning 0))
3666 (setq REx-comment-start
(point)
3670 ;; XXX not working if outside delimiter is #
3671 (eq (preceding-char) ?
\\)
3672 (= (%
(skip-chars-backward "$\\\\") 2) -
1)))
3673 ;; Not a comment, avoid loop:
3674 (progn (setq was-comment nil
)
3676 (if (match-beginning 2)
3678 (beginning-of-line 2)
3680 (goto-char (1- e
))))
3681 ;; Works also if the outside delimiters are ().
3682 (or (search-forward ")" (1- e
) 'toend
)
3684 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
3685 REx-comment-start
))))
3690 (setq REx-comment-end
(point))
3692 REx-comment-start REx-comment-end nil
)
3693 (cperl-postpone-fontification
3694 REx-comment-start REx-comment-end
3695 'face font-lock-comment-face
))))))
3696 (if (and is-REx is-x-REx
)
3697 (put-text-property (1+ b
) (1- e
)
3698 'syntax-subtype
'x-REx
)))
3701 (cperl-postpone-fontification
3702 (1- e1
) e1
'face font-lock-constant-face
)
3703 (if (assoc (char-after b
) cperl-starters
)
3704 (cperl-postpone-fontification
3705 b1
(1+ b1
) 'face font-lock-constant-face
))))
3708 ((match-beginning 13) ; sub with prototypes
3709 (setq b
(match-beginning 0))
3710 (if (memq (char-after (1- b
))
3711 '(?\$ ?\
@ ?\% ?\
& ?\
*))
3713 (setq state
(parse-partial-sexp
3714 state-point b nil nil state
)
3716 (if (or (nth 3 state
) (nth 4 state
))
3719 (cperl-commentify (match-beginning 13) (match-end 13) t
))
3720 (goto-char (match-end 0))))
3721 ;; 1+6+2+1+1+2=13 extra () before this:
3723 ((and (match-beginning 14)
3724 (eq (preceding-char) ?
\')) ; $'
3725 (setq b
(1- (point))
3726 state
(parse-partial-sexp
3727 state-point
(1- b
) nil nil state
)
3729 (if (nth 3 state
) ; in string
3730 (cperl-modify-syntax-type (1- b
) cperl-st-punct
))
3732 ;; 1+6+2+1+1+2=13 extra () before this:
3734 ((match-beginning 14) ; ${
3735 (setq bb
(match-beginning 0))
3736 (cperl-modify-syntax-type bb cperl-st-punct
))
3737 ;; 1+6+2+1+1+2+1=14 extra () before this:
3738 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
3739 ((match-beginning 15) ; old $abc'efg syntax
3740 (setq bb
(match-end 0)
3741 b
(match-beginning 0)
3742 state
(parse-partial-sexp
3743 state-point b nil nil state
)
3745 (if (nth 3 state
) ; in string
3747 (put-text-property (1- bb
) bb
'syntax-table cperl-st-word
))
3749 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
3750 ;; "__\\(END\\|DATA\\)__"
3751 ((match-beginning 16) ; __END__, __DATA__
3752 (setq bb
(match-end 0)
3753 b
(match-beginning 0)
3754 state
(parse-partial-sexp
3755 state-point b nil nil state
)
3757 (if (or (nth 3 state
) (nth 4 state
))
3759 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
3760 (cperl-commentify b bb nil
)
3763 ((match-beginning 17) ; "\\\\\\(['`\"]\\)"
3764 (setq bb
(match-end 0)
3765 b
(match-beginning 0))
3767 (skip-chars-backward "\\\\")
3768 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
3769 (setq state
(parse-partial-sexp
3770 state-point b nil nil state
)
3772 (if (or (nth 3 state
) (nth 4 state
) )
3774 (cperl-modify-syntax-type b cperl-st-punct
))
3776 (t (error "Error in regexp of the sniffer")))
3777 (if (> (point) stop-point
)
3780 (message "Garbage after __END__/__DATA__ ignored")
3781 (message "Unbalanced syntax found while scanning")
3782 (or (car err-l
) (setcar err-l b
)))
3783 (goto-char stop-point
))))
3784 (setq cperl-syntax-state
(cons state-point state
)
3785 cperl-syntax-done-to
(or tmpend
(max (point) max
))))
3786 (if (car err-l
) (goto-char (car err-l
))
3788 (message "Scanning for \"hard\" Perl constructions... done"))))
3789 (and (buffer-modified-p)
3791 (set-buffer-modified-p nil
))
3792 (set-syntax-table cperl-mode-syntax-table
))
3795 (defun cperl-backward-to-noncomment (lim)
3796 ;; Stops at lim or after non-whitespace that is not in comment
3798 (while (and (not stop
) (> (point) (or lim
1)))
3799 (skip-chars-backward " \t\n\f" lim
)
3802 (if (memq (setq pr
(get-text-property (point) 'syntax-type
))
3803 '(pod here-doc here-doc-delim
))
3804 (cperl-unwind-to-safe nil
)
3805 (if (or (looking-at "^[ \t]*\\(#\\|$\\)")
3806 (progn (cperl-to-comment-or-eol) (bolp)))
3807 nil
; Only comment, skip
3809 (skip-chars-backward " \t")
3810 (if (< p
(point)) (goto-char p
))
3813 (defun cperl-after-block-p (lim)
3814 ;; We suppose that the preceding char is }.
3819 (cperl-backward-to-noncomment lim
)
3820 (or (eq (point) lim
)
3821 (eq (preceding-char) ?\
) ) ; if () {} sub f () {}
3822 (if (eq (char-syntax (preceding-char)) ?w
) ; else {}
3825 (or (looking-at "\\(else\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
3828 (cperl-backward-to-noncomment lim
)
3829 (and (eq (char-syntax (preceding-char)) ?w
)
3832 (looking-at "sub\\>"))))))
3833 (cperl-after-expr-p lim
))))
3836 (defun cperl-after-expr-p (&optional lim chars test
)
3837 "Return true if the position is good for start of expression.
3838 TEST is the expression to evaluate at the found position. If absent,
3839 CHARS is a string that contains good characters to have before us (however,
3840 `}' is treated \"smartly\" if it is not in the list)."
3842 (lim (or lim
(point-min))))
3844 (while (and (not stop
) (> (point) lim
))
3845 (skip-chars-backward " \t\n\f" lim
)
3848 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil
; Only comment, skip
3849 ;; Else: last iteration, or a label
3850 (cperl-to-comment-or-eol)
3851 (skip-chars-backward " \t")
3852 (if (< p
(point)) (goto-char p
))
3854 (if (and (eq (preceding-char) ?
:)
3857 (skip-chars-backward " \t\n\f" lim
)
3858 (eq (char-syntax (preceding-char)) ?w
)))
3859 (forward-sexp -
1) ; Possibly label. Skip it
3862 (or (bobp) ; ???? Needed
3864 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
3866 (if test
(eval test
)
3867 (or (memq (preceding-char) (append (or chars
"{;") nil
))
3868 (and (eq (preceding-char) ?\
})
3869 (cperl-after-block-p lim
)))))))))
3871 (defun cperl-backward-to-start-of-continued-exp (lim)
3872 (if (memq (preceding-char) (append ")]}\"'`" nil
))
3875 (if (<= (point) lim
)
3876 (goto-char (1+ lim
)))
3877 (skip-chars-forward " \t"))
3879 (defun cperl-after-block-and-statement-beg (lim)
3880 ;; We assume that we are after ?\}
3882 (cperl-after-block-p lim
)
3885 (cperl-backward-to-noncomment (point-min))
3888 (not (= (char-syntax (preceding-char)) ?w
))
3893 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
3896 (defun cperl-indent-exp ()
3897 "Simple variant of indentation of continued-sexp.
3899 Will not indent comment if it starts at `comment-indent' or looks like
3900 continuation of the comment on the previous line.
3902 If `cperl-indent-region-fix-constructs', will improve spacing on
3903 conditional/loop constructs."
3906 (let ((tmp-end (progn (end-of-line) (point))) top done
)
3911 (while (= (nth 0 (parse-partial-sexp (point) tmp-end
3913 (setq top
(point))) ; Get the outermost parenths in line
3915 (while (< (point) tmp-end
)
3916 (parse-partial-sexp (point) tmp-end nil t
) ; To start-sexp or eol
3917 (or (eolp) (forward-sexp 1)))
3918 (if (> (point) tmp-end
)
3921 (setq tmp-end
(point)))
3924 (setq tmp-end
(point-marker)))
3925 (if cperl-indent-region-fix-constructs
3926 (cperl-fix-line-spacing tmp-end
))
3927 (cperl-indent-region (point) tmp-end
))))
3929 (defun cperl-fix-line-spacing (&optional end parse-data
)
3930 "Improve whitespace in a conditional/loop construct.
3931 Returns some position at the last line."
3934 (setq end
(point-max)))
3935 (let (p pp ml have-brace ret
3936 (ee (save-excursion (end-of-line) (point)))
3937 (cperl-indent-region-fix-constructs
3938 (or cperl-indent-region-fix-constructs
1)))
3945 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
3946 (setq have-brace
(save-excursion (search-forward "}" ee t
)))))
3947 nil
; Do not need to do anything
3951 (if (and cperl-merge-trailing-else
3953 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>"))
3955 (search-forward "}")
3957 (skip-chars-forward " \t\n")
3958 (delete-region p
(point))
3959 (insert (make-string cperl-indent-region-fix-constructs ?\
))
3960 (beginning-of-line)))
3963 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
3965 (search-forward "}")
3966 (delete-horizontal-space)
3967 (insert (make-string cperl-indent-region-fix-constructs ?\
))
3968 (beginning-of-line)))
3972 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
3975 (delete-horizontal-space)
3976 (insert (make-string cperl-indent-region-fix-constructs ?\
))
3977 (beginning-of-line)))
3981 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
3984 (delete-horizontal-space)
3985 (insert (make-string cperl-indent-region-fix-constructs ?\
))
3986 (beginning-of-line)))
3988 ;; foreach my $var (
3990 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
3993 (delete-horizontal-space)
3995 (make-string cperl-indent-region-fix-constructs ?\
))
3996 (beginning-of-line)))
3998 ;; } foreach my $var () {
4000 "[ \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]*{")
4002 (setq ml
(match-beginning 8))
4003 (re-search-forward "[({]")
4006 (if (eq (following-char) ?\
( )
4010 ;; after `else' or nothing
4011 (if ml
; after `else'
4012 (skip-chars-backward " \t\n")
4013 (beginning-of-line))
4015 ;; Now after the sexp before the brace
4016 ;; Multiline expr should be special
4017 (setq ml
(and pp
(save-excursion (goto-char p
)
4018 (search-forward "\n" pp t
))))
4019 (if (and (or (not pp
) (< pp end
))
4020 (looking-at "[ \t\n]*{"))
4023 ((bolp) ; Were before `{', no if/else/etc
4025 ((looking-at "\\(\t*\\| [ \t]+\\){")
4026 (delete-horizontal-space)
4028 cperl-extra-newline-before-brace-multiline
4029 cperl-extra-newline-before-brace
)
4031 (delete-horizontal-space)
4034 (if (cperl-indent-line parse-data
)
4036 (cperl-fix-line-spacing end parse-data
)
4037 (setq ret
(point)))))
4039 (make-string cperl-indent-region-fix-constructs ?\
))))
4040 ((and (looking-at "[ \t]*\n")
4042 cperl-extra-newline-before-brace-multiline
4043 cperl-extra-newline-before-brace
)))
4045 (skip-chars-forward " \t\n")
4046 (delete-region pp
(point))
4048 (make-string cperl-indent-region-fix-constructs ?\
))))
4049 ;; Now we are before `{'
4050 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
4052 (skip-chars-forward " \t\n")
4057 (setq ml
(search-forward "\n" p t
))
4058 (if (or cperl-break-one-line-blocks-when-indent ml
)
4059 ;; not good: multi-line BLOCK
4062 (delete-horizontal-space)
4065 (if (cperl-indent-line parse-data
)
4066 (setq ret
(cperl-fix-line-spacing end parse-data
)))))))))))
4068 (setq p
(point) pp
(save-excursion (end-of-line) (point))) ; May be different from ee.
4069 ;; Now check whether there is a hanging `}'
4073 cperl-fix-hanging-brace-when-indent
4075 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
4079 (if (and (<= (point) pp
)
4080 (eq (preceding-char) ?\
} )
4081 (cperl-after-block-and-statement-beg (point-min)))
4088 (skip-chars-backward " \t")
4090 ;; `}' was the first thing on the line, insert NL *after* it.
4092 (cperl-indent-line parse-data
)
4093 (search-forward "}")
4094 (delete-horizontal-space)
4096 (delete-horizontal-space)
4097 (or (eq (preceding-char) ?\
;)
4099 (and (eq (preceding-char) ?\
} )
4100 (cperl-after-block-p (point-min)))
4104 (if (cperl-indent-line parse-data
)
4105 (setq ret
(cperl-fix-line-spacing end parse-data
)))
4106 (beginning-of-line)))))
4109 (defvar cperl-update-start
) ; Do not need to make them local
4110 (defvar cperl-update-end
)
4111 (defun cperl-delay-update-hook (beg end old-len
)
4112 (setq cperl-update-start
(min beg
(or cperl-update-start
(point-max))))
4113 (setq cperl-update-end
(max end
(or cperl-update-end
(point-min)))))
4115 (defun cperl-indent-region (start end
)
4116 "Simple variant of indentation of region in CPerl mode.
4117 Should be slow. Will not indent comment if it starts at `comment-indent'
4118 or looks like continuation of the comment on the previous line.
4119 Indents all the lines whose first character is between START and END
4122 If `cperl-indent-region-fix-constructs', will improve spacing on
4123 conditional/loop constructs."
4125 (cperl-update-syntaxification end end
)
4127 (let (cperl-update-start cperl-update-end
(h-a-c after-change-functions
))
4128 (let (st comm old-comm-indent new-comm-indent p pp i empty
4129 (indent-info (if cperl-emacs-can-parse
4130 (list nil nil nil
) ; Cannot use '(), since will modify
4132 after-change-functions
; Speed it up!
4133 (pm 0) (imenu-scanning-message "Indenting... (%3d%%)"))
4134 (if h-a-c
(add-hook 'after-change-functions
'cperl-delay-update-hook
))
4136 (setq old-comm-indent
(and (cperl-to-comment-or-eol)
4138 new-comm-indent old-comm-indent
)
4140 (setq end
(set-marker (make-marker) end
)) ; indentation changes pos
4141 (or (bolp) (beginning-of-line 2))
4142 (or (fboundp 'imenu-progress-message
)
4143 (message "Indenting... For feedback load `imenu'..."))
4144 (while (and (<= (point) end
) (not (eobp))) ; bol to check start
4145 (and (fboundp 'imenu-progress-message
)
4146 (imenu-progress-message
4147 pm
(/ (* 100 (- (point) start
)) (- end start -
1))))
4150 (setq empty
(looking-at "[ \t]*\n"))
4151 (and (setq comm
(looking-at "[ \t]*#"))
4152 (or (eq (current-indentation) (or old-comm-indent
4154 (setq old-comm-indent nil
))))
4155 (if (and old-comm-indent
4157 (= (current-indentation) old-comm-indent
)
4158 (not (eq (get-text-property (point) 'syntax-type
) 'pod
))
4159 (not (eq (get-text-property (point) 'syntax-table
)
4161 (let ((comment-column new-comm-indent
))
4162 (indent-for-comment)))
4164 (setq i
(cperl-indent-line indent-info
))
4168 (if cperl-indent-region-fix-constructs
4169 (goto-char (cperl-fix-line-spacing end indent-info
)))
4170 (if (setq old-comm-indent
4171 (and (cperl-to-comment-or-eol)
4172 (not (memq (get-text-property (point)
4175 (not (eq (get-text-property (point)
4179 (progn (indent-for-comment)
4180 (skip-chars-backward " \t")
4181 (skip-chars-backward "#")
4182 (setq new-comm-indent
(current-column))))))))
4183 (beginning-of-line 2))
4184 (if (fboundp 'imenu-progress-message
)
4185 (imenu-progress-message pm
100)
4187 ;; Now run the update hooks
4188 (if after-change-functions
4190 (if cperl-update-end
4192 (goto-char cperl-update-end
)
4195 (goto-char cperl-update-start
)
4197 (delete-char -
1))))))))
4199 ;; Stolen from lisp-mode with a lot of improvements
4201 (defun cperl-fill-paragraph (&optional justify iteration
)
4202 "Like \\[fill-paragraph], but handle CPerl comments.
4203 If any of the current line is a comment, fill the comment or the
4204 block of it that point is in, preserving the comment's initial
4205 indentation and initial hashes. Behaves usually outside of comment."
4208 ;; Non-nil if the current line contains a comment.
4211 ;; If has-comment, the appropriate fill-prefix for the comment.
4213 ;; Line that contains code and comment (or nil)
4215 c spaces len dc
(comment-column comment-column
))
4216 ;; Figure out what kind of comment we are looking at.
4221 ;; A line with nothing but a comment on it?
4222 ((looking-at "[ \t]*#[# \t]*")
4224 comment-fill-prefix
(buffer-substring (match-beginning 0)
4227 ;; A line with some code, followed by a comment? Remember that the
4228 ;; semi which starts the comment shouldn't be part of a string or
4230 ((cperl-to-comment-or-eol)
4231 (setq has-comment t
)
4232 (looking-at "#+[ \t]*")
4233 (setq start
(point) c
(current-column)
4235 (concat (make-string (current-column) ?\
)
4236 (buffer-substring (match-beginning 0) (match-end 0)))
4237 spaces
(progn (skip-chars-backward " \t")
4238 (buffer-substring (point) start
))
4239 dc
(- c
(current-column)) len
(- start
(point))
4240 start
(point-marker))
4242 (insert (make-string dc ?-
)))))
4243 (if (not has-comment
)
4244 (fill-paragraph justify
) ; Do the usual thing outside of comment
4245 ;; Narrow to include only the comment, and then fill the region.
4248 ;; Find the first line we should include in the region to fill.
4249 (if start
(progn (beginning-of-line) (point))
4251 (while (and (zerop (forward-line -
1))
4252 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
4253 ;; We may have gone to far. Go forward again.
4254 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
4257 ;; Find the beginning of the first line past the region to fill.
4259 (while (progn (forward-line 1)
4260 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
4262 ;; Remove existing hashes
4263 (goto-char (point-min))
4264 (while (progn (forward-line 1) (< (point) (point-max)))
4265 (skip-chars-forward " \t")
4266 (and (looking-at "#+")
4267 (delete-char (- (match-end 0) (match-beginning 0)))))
4269 ;; Lines with only hashes on them can be paragraph boundaries.
4270 (let ((paragraph-start (concat paragraph-start
"\\|^[ \t#]*$"))
4271 (paragraph-separate (concat paragraph-start
"\\|^[ \t#]*$"))
4272 (fill-prefix comment-fill-prefix
))
4273 (fill-paragraph justify
)))
4278 (progn (delete-char dc
) (insert spaces
)))
4279 (if (or (= (current-column) c
) iteration
) nil
4280 (setq comment-column c
)
4281 (indent-for-comment)
4282 ;; Repeat once more, flagging as iteration
4283 (cperl-fill-paragraph justify t
)))))))
4285 (defun cperl-do-auto-fill ()
4286 ;; Break out if the line is short enough
4287 (if (> (save-excursion
4291 (let ((c (save-excursion (beginning-of-line)
4292 (cperl-to-comment-or-eol) (point)))
4293 (s (memq (following-char) '(?\ ?
\t))) marker
)
4294 (if (>= c
(point)) nil
4295 (setq marker
(point-marker))
4296 (cperl-fill-paragraph)
4298 ;; Is not enough, sometimes marker is a start of line
4299 (if (bolp) (progn (re-search-forward "#+[ \t]*")
4300 (goto-char (match-end 0))))
4301 ;; Following space could have gone:
4302 (if (or (not s
) (memq (following-char) '(?\ ?
\t))) nil
4305 ;; Previous space could have gone:
4306 (or (memq (preceding-char) '(?\ ?
\t)) (insert " "))))))
4308 (defun cperl-imenu-addback (lst &optional isback name
)
4309 ;; We suppose that the lst is a DAG, unless the first element only
4310 ;; loops back, and ISBACK is set. Thus this function cannot be
4311 ;; applied twice without ISBACK set.
4312 (cond ((not cperl-imenu-addback
) lst
)
4315 (setq name
"+++BACK+++"))
4316 (mapcar (function (lambda (elt)
4317 (if (and (listp elt
) (listp (cdr elt
)))
4319 ;; In the other order it goes up
4320 ;; one level only ;-(
4321 (setcdr elt
(cons (cons name lst
)
4323 (cperl-imenu-addback (cdr elt
) t name
)
4325 (if isback
(cdr lst
) lst
))
4328 (defun cperl-imenu--create-perl-index (&optional regexp
)
4329 (require 'imenu
) ; May be called from TAGS creator
4330 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
4331 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function
))
4332 (index-meth-alist '()) meth
4333 packages ends-ranges p marker
4334 (prev-pos 0) char fchar index index1 name
(end-range 0) package
)
4335 (goto-char (point-min))
4337 (message "Scanning Perl for index")
4338 (imenu-progress-message prev-pos
0))
4339 (cperl-update-syntaxification (point-max) (point-max))
4340 ;; Search for the function
4341 (progn ;;save-match-data
4342 (while (re-search-forward
4343 (or regexp cperl-imenu--function-name-regexp-perl
)
4346 (imenu-progress-message prev-pos
))
4348 ((and ; Skip some noise if building tags
4349 (match-beginning 2) ; package or sub
4350 (eq (char-after (match-beginning 2)) ?p
) ; package
4351 (not (save-match-data
4352 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
4355 (match-beginning 2) ; package or sub
4356 ;; Skip if quoted (will not skip multi-line ''-strings :-():
4357 (null (get-text-property (match-beginning 1) 'syntax-table
))
4358 (null (get-text-property (match-beginning 1) 'syntax-type
))
4359 (null (get-text-property (match-beginning 1) 'in-pod
)))
4361 (goto-char (match-beginning 2))
4362 (setq fchar
(following-char))
4364 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
4365 ;; (goto-char (match-end 0))) ; Messes what follows
4366 (setq char
(following-char) ; ?\; for "sub foo () ;"
4369 (while (and ends-ranges
(>= p
(car ends-ranges
)))
4370 ;; delete obsolete entries
4371 (setq ends-ranges
(cdr ends-ranges
) packages
(cdr packages
)))
4372 (setq package
(or (car packages
) "")
4373 end-range
(or (car ends-ranges
) 0))
4375 (setq name
(buffer-substring (match-beginning 3) (match-end 3))
4377 (set-text-properties 0 (length name
) nil name
)
4379 package
(concat name
"::")
4380 name
(concat "package " name
)
4383 (parse-partial-sexp (point) (point-max) -
1) (point))
4384 ends-ranges
(cons end-range ends-ranges
)
4385 packages
(cons package packages
)))
4387 ;; Skip this function name if it is a prototype declaration.
4388 (if (and (eq fchar ?s
) (eq char ?\
;)) nil
4389 (setq name
(buffer-substring (match-beginning 3) (match-end 3))
4390 marker
(make-marker))
4391 (set-text-properties 0 (length name
) nil name
)
4392 (set-marker marker
(match-end 3))
4394 (setq name
(concat "package " name
))
4395 (cond ((string-match "[:']" name
)
4397 ((> p end-range
) nil
)
4399 (setq name
(concat package name
) meth t
))))
4400 (setq index
(cons name marker
))
4402 (push index index-pack-alist
)
4403 (push index index-alist
))
4404 (if meth
(push index index-meth-alist
))
4405 (push index index-unsorted-alist
)))
4406 ((match-beginning 5) ; Pod section
4407 ;; (beginning-of-line)
4408 (setq index
(imenu-example--name-and-position)
4409 name
(buffer-substring (match-beginning 6) (match-end 6)))
4410 (set-text-properties 0 (length name
) nil name
)
4411 (if (eq (char-after (match-beginning 5)) ?
2)
4412 (setq name
(concat " " name
)))
4414 (setq index1
(cons (concat "=" name
) (cdr index
)))
4415 (push index index-pod-alist
)
4416 (push index1 index-unsorted-alist
)))))
4418 (imenu-progress-message prev-pos
100))
4420 (if (default-value 'imenu-sort-function
)
4421 (sort index-alist
(default-value 'imenu-sort-function
))
4422 (nreverse index-alist
)))
4423 (and index-pod-alist
4424 (push (cons "+POD headers+..."
4425 (nreverse index-pod-alist
))
4427 (and (or index-pack-alist index-meth-alist
)
4428 (let ((lst index-pack-alist
) hier-list pack elt group name
)
4429 ;; Remove "package ", reverse and uniquify.
4431 (setq elt
(car lst
) lst
(cdr lst
) name
(substring (car elt
) 8))
4432 (if (assoc name hier-list
) nil
4433 (setq hier-list
(cons (cons name
(cdr elt
)) hier-list
))))
4434 (setq lst index-meth-alist
)
4436 (setq elt
(car lst
) lst
(cdr lst
))
4437 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt
))
4438 (setq pack
(substring (car elt
) 0 (match-beginning 0)))
4439 (if (setq group
(assoc pack hier-list
))
4440 (if (listp (cdr group
))
4441 ;; Have some functions already
4443 (cons (cons (substring
4445 (+ 2 (match-beginning 0)))
4448 (setcdr group
(list (cons (substring
4450 (+ 2 (match-beginning 0)))
4454 (list (cons (substring
4456 (+ 2 (match-beginning 0)))
4459 (push (cons "+Hierarchy+..."
4462 (and index-pack-alist
4463 (push (cons "+Packages+..."
4464 (nreverse index-pack-alist
))
4466 (and (or index-pack-alist index-pod-alist
4467 (default-value 'imenu-sort-function
))
4468 index-unsorted-alist
4469 (push (cons "+Unsorted List+..."
4470 (nreverse index-unsorted-alist
))
4472 (cperl-imenu-addback index-alist
)))
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