1 ;;; cperl-mode.el --- Perl code editing commands for Emacs
3 ;; Copyright (C) 1985, 86, 87, 91, 92, 93, 94, 95, 96, 97, 98, 99,
4 ;; 2000, 2003, 2005, 2006
5 ;; Free Software Foundation, Inc.
7 ;; Author: Ilya Zakharevich and Bob Olson
8 ;; Maintainer: Ilya Zakharevich <ilyaz@cpan.org>
9 ;; Keywords: languages, Perl
11 ;; This file is part of GNU Emacs.
13 ;;; This code started from the following message of long time ago
14 ;;; (IZ), but Bob does not maintain this mode any more:
16 ;;; From: olson@mcs.anl.gov (Bob Olson)
17 ;;; Newsgroups: comp.lang.perl
18 ;;; Subject: cperl-mode: Another perl mode for Gnuemacs
19 ;;; Date: 14 Aug 91 15:20:01 GMT
21 ;; Copyright (C) Ilya Zakharevich and Bob Olson
23 ;; This file may be distributed
24 ;; either under the same terms as GNU Emacs, or under the same terms
25 ;; as Perl. You should have received a copy of Perl Artistic license
26 ;; along with the Perl distribution.
28 ;; GNU Emacs is free software; you can redistribute it and/or modify
29 ;; it under the terms of the GNU General Public License as published by
30 ;; the Free Software Foundation; either version 2, or (at your option)
33 ;; GNU Emacs is distributed in the hope that it will be useful,
34 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 ;; GNU General Public License for more details.
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with GNU Emacs; see the file COPYING. If not, write to the
40 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41 ;; Boston, MA 02111-1307, USA.
43 ;;; Corrections made by Ilya Zakharevich ilyaz@cpan.org
44 ;;; XEmacs changes by Peter Arius arius@informatik.uni-erlangen.de
48 ;; $Id: cperl-mode.el,v 5.23 2007/02/15 11:34:23 vera Exp vera $
50 ;;; If your Emacs does not default to `cperl-mode' on Perl files:
51 ;;; To use this mode put the following into
54 ;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)
56 ;; You can either fine-tune the bells and whistles of this mode or
57 ;; bulk enable them by putting
59 ;; (setq cperl-hairy t)
61 ;; in your .emacs file. (Emacs rulers do not consider it politically
62 ;; correct to make whistles enabled by default.)
64 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
65 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
66 ;; `cperl-non-problems', `cperl-praise', `cperl-speed'. <<<<<<
68 ;; Additional useful commands to put into your .emacs file (before
71 ;; (setq auto-mode-alist
72 ;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
73 ;; (setq interpreter-mode-alist (append interpreter-mode-alist
74 ;; '(("miniperl" . perl-mode))))
76 ;; The mode information (on C-h m) provides some customization help.
77 ;; If you use font-lock feature of this mode, it is advisable to use
78 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
80 ;; Faces used now: three faces for first-class and second-class keywords
81 ;; and control flow words, one for each: comments, string, labels,
82 ;; functions definitions and packages, arrays, hashes, and variable
83 ;; definitions. If you do not see all these faces, your font-lock does
84 ;; not define them, so you need to define them manually.
85 ;; Maybe you have an obsolete font-lock from 19.28 or earlier. Upgrade.
87 ;; If you have a grayscale monitor, and do not have the variable
88 ;; font-lock-display-type bound to 'grayscale, insert
90 ;; (setq font-lock-display-type 'grayscale)
92 ;; into your .emacs file (this is relevant before RMS Emacs 20).
94 ;; This mode supports font-lock, imenu and mode-compile. In the
95 ;; hairy version font-lock is on, but you should activate imenu
96 ;; yourself (note that mode-compile is not standard yet). Well, you
97 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
98 ;; to bind it like that:
100 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
102 ;;; Font lock bugs as of v4.32:
104 ;; The following kinds of Perl code erroneously start strings:
106 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
107 ;; likewise with m, tr, y, q, qX instead of s
109 ;;; In fact the version of font-lock that this version supports can be
110 ;;; much newer than the version you actually have. This means that a
111 ;;; lot of faces can be set up, but are not visible on your screen
112 ;;; since the coloring rules for this faces are not defined.
114 ;;; Updates: ========================================
116 ;;; Made less hairy by default: parentheses not electric,
117 ;;; linefeed not magic. Bug with abbrev-mode corrected.
120 ;;; Better indentation:
121 ;;; subs inside braces should work now,
122 ;;; Toplevel braces obey customization.
123 ;;; indent-for-comment knows about bad cases, cperl-indent-for-comment
124 ;;; moves cursor to a correct place.
125 ;;; cperl-indent-exp written from the scratch! Slow... (quadratic!) :-(
126 ;;; (50 secs on DB::DB (sub of 430 lines), 486/66)
127 ;;; Minor documentation fixes.
128 ;;; Imenu understands packages as prefixes (including nested).
129 ;;; Hairy options can be switched off one-by-one by setting to null.
130 ;;; Names of functions and variables changed to conform to `cperl-' style.
133 ;;; Some bugs with indentation of labels (and embedded subs) corrected.
134 ;;; `cperl-indent-region' done (slow :-()).
135 ;;; `cperl-fill-paragraph' done.
136 ;;; Better package support for `imenu'.
137 ;;; Progress indicator for indentation (with `imenu' loaded).
138 ;;; `Cperl-set' was busted, now setting the individual hairy option
139 ;;; should be better.
142 ;;; `cperl-set-style' done.
143 ;;; `cperl-check-syntax' done.
145 ;;; New config variables `cperl-close-paren-offset' and `cperl-comment-column'.
146 ;;; Bugs with `cperl-auto-newline' corrected.
147 ;;; `cperl-electric-lbrace' can work with `cperl-auto-newline' in situation
150 ;;;; 1.7 XEmacs (arius@informatik.uni-erlangen.de):
151 ;;; - use `next-command-event', if `next-command-events' does not exist
152 ;;; - use `find-face' as def. of `is-face'
153 ;;; - corrected def. of `x-color-defined-p'
154 ;;; - added const defs for font-lock-comment-face,
155 ;;; font-lock-keyword-face and font-lock-function-name-face
156 ;;; - added def. of font-lock-variable-name-face
157 ;;; - added (require 'easymenu) inside an `eval-when-compile'
158 ;;; - replaced 4-argument `substitute-key-definition' with ordinary
160 ;;; - replaced `mark-active' in menu definition by `cperl-use-region-p'.
162 ;;; - use emacs-vers.el (http://www.cs.utah.edu/~eeide/emacs/emacs-vers.el.gz)
163 ;;; for portable code?
164 ;;; - should `cperl-mode' do a
165 ;;; (if (featurep 'easymenu) (easy-menu-add cperl-menu))
166 ;;; or should this be left to the user's `cperl-mode-hook'?
168 ;;; Some bugs introduced by the above fix corrected (IZ ;-).
169 ;;; Some bugs under XEmacs introduced by the correction corrected.
171 ;;; Some more can remain since there are two many different variants.
174 ;;; We do not support fontification of arrays and hashes under
175 ;;; obsolete font-lock any more. Upgrade.
177 ;;;; after 1.8 Minor bug with parentheses.
178 ;;;; after 1.9 Improvements from Joe Marzot.
180 ;;; Does not need easymenu to compile under XEmacs.
181 ;;; `vc-insert-headers' should work better.
182 ;;; Should work with 19.29 and 19.12.
183 ;;; Small improvements to fontification.
184 ;;; Expansion of keywords does not depend on C-? being backspace.
187 ;;; 19.29 and 19.12 supported.
188 ;;; `cperl-font-lock-enhanced' deprecated. Use font-lock-extra.el.
189 ;;; Support for font-lock-extra.el.
193 ;;; Support for perl5-info.
194 ;;; `imenu-go-find-at-position' in Tools requires imenu-go.el (see hints above)
195 ;;; Imenu entries do not work with stock imenu.el. Patch sent to maintainers.
196 ;;; Fontifies `require a if b;', __DATA__.
197 ;;; Arglist for auto-fill-mode was incorrect.
200 ;;; `cperl-lineup-step' and `cperl-lineup' added: lineup constructions
202 ;;; `cperl-do-auto-fill' updated for 19.29 style.
203 ;;; `cperl-info-on-command' now has a default.
204 ;;; Workaround for broken C-h on XEmacs.
205 ;;; VC strings escaped.
206 ;;; C-h f now may prompt for function name instead of going on,
207 ;;; controlled by `cperl-info-on-command-no-prompt'.
210 ;;; Msb buffer list includes perl files
211 ;;; Indent-for-comment uses indent-to
212 ;;; Can write tag files using etags.
215 ;;; Recognizes (tries to ;-) {...} which are not blocks during indentation.
216 ;;; `cperl-close-paren-offset' affects ?\] too (and ?\} if not block)
217 ;;; Bug with auto-filling comments started with "##" corrected.
219 ;;;; Very slow now: on DB::DB 0.91, 486/66:
221 ;;;Function Name Call Count Elapsed Time Average Time
222 ;;;======================================== ========== ============ ============
223 ;;;cperl-block-p 469 3.7799999999 0.0080597014
224 ;;;cperl-get-state 505 163.39000000 0.3235445544
225 ;;;cperl-comment-indent 12 0.0299999999 0.0024999999
226 ;;;cperl-backward-to-noncomment 939 4.4599999999 0.0047497337
227 ;;;cperl-calculate-indent 505 172.22000000 0.3410297029
228 ;;;cperl-indent-line 505 172.88000000 0.3423366336
229 ;;;cperl-use-region-p 40 0.0299999999 0.0007499999
230 ;;;cperl-indent-exp 1 177.97000000 177.97000000
231 ;;;cperl-to-comment-or-eol 1453 3.9800000000 0.0027391603
232 ;;;cperl-backward-to-start-of-continued-exp 9 0.0300000000 0.0033333333
233 ;;;cperl-indent-region 1 177.94000000 177.94000000
236 ;;; Takes into account white space after opening parentheses during indent.
237 ;;; May highlight pods and here-documents: see `cperl-pod-here-scan',
238 ;;; `cperl-pod-here-fontify', `cperl-pod-face'. Does not use this info
239 ;;; for indentation so far.
240 ;;; Fontification updated to 19.30 style.
241 ;;; The change 19.29->30 did not add all the required functionality,
242 ;;; but broke "font-lock-extra.el". Get "choose-color.el" from
243 ;;; http://ilyaz.org/software/emacs
247 ;;; recognized as a start of a block.
248 ;;; Two different font-lock-levels provided.
249 ;;; `cperl-pod-head-face' introduced. Used for highlighting.
250 ;;; `imenu' marks pods, +Packages moved to the head.
253 ;;; Scan for pods highlights here-docs too.
254 ;;; Note that the tag of here-doc may be rehighlighted later by lazy-lock.
255 ;;; Only one here-doc-tag per line is supported, and one in comment
256 ;;; or a string may break fontification.
257 ;;; POD headers were supposed to fill one line only.
260 ;;; `font-lock-keywords' were set in 19.30 style _always_. Current scheme
261 ;;; may break under XEmacs.
262 ;;; `cperl-calculate-indent' dis suppose that `parse-start' was defined.
263 ;;; `fontified' tag is added to fontified text as well as `lazy-lock' (for
264 ;;; compatibility with older lazy-lock.el) (older one overfontifies
265 ;;; something nevertheless :-().
266 ;;; Will not indent something inside pod and here-documents.
267 ;;; Fontifies the package name after import/no/bootstrap.
268 ;;; Added new entry to menu with meta-info about the mode.
271 ;;; Prefontification works much better with 19.29. Should be checked
272 ;;; with 19.30 as well.
273 ;;; Some misprints in docs corrected.
274 ;;; Now $a{-text} and -text => "blah" are fontified as strings too.
275 ;;; Now the pod search is much stricter, so it can help you to find
276 ;;; pod sections which are broken because of whitespace before =blah
277 ;;; - just observe the fontification.
280 ;;; Anonymous subs are indented with respect to the level of
281 ;;; indentation of `sub' now.
282 ;;; {} is recognized as hash after `bless' and `return'.
283 ;;; Anonymous subs are split by `cperl-linefeed' as well.
284 ;;; Electric parens embrace a region if present.
285 ;;; To make `cperl-auto-newline' useful,
286 ;;; `cperl-auto-newline-after-colon' is introduced.
287 ;;; `cperl-electric-parens' is now t or nul. The old meaning is moved to
288 ;;; `cperl-electric-parens-string'.
289 ;;; `cperl-toggle-auto-newline' introduced, put on C-c C-a.
290 ;;; `cperl-toggle-abbrev' introduced, put on C-c C-k.
291 ;;; `cperl-toggle-electric' introduced, put on C-c C-e.
292 ;;; Beginning-of-defun-regexp was not anchored.
295 ;;; Auto-newline grants `cperl-extra-newline-before-brace' if "{" is typed
297 ;;; {} is recognized as expression after `tr' and friends.
300 ;;; Entry Hierarchy added to imenu. Very primitive so far.
301 ;;; One needs newer `imenu-go'.el. A patch to `imenu' is needed as well.
302 ;;; Writes its own TAGS files.
303 ;;; Class viewer based on TAGS files. Does not trace @ISA so far.
304 ;;; 19.31: Problems with scan for PODs corrected.
305 ;;; First POD header correctly fontified.
306 ;;; I needed (setq imenu-use-keymap-menu t) to get good imenu in 19.31.
307 ;;; Apparently it makes a lot of hierarchy code obsolete...
310 ;;; Tags filler now scans *.xs as well.
311 ;;; The info from *.xs scan is used by the hierarchy viewer.
312 ;;; Hierarchy viewer documented.
313 ;;; Bug in 19.31 imenu documented.
316 ;;; New location for info-files mentioned,
317 ;;; Electric-; should work better.
318 ;;; Minor bugs with POD marking.
320 ;;;; After 1.25 (probably not...)
321 ;;; `cperl-info-page' introduced.
322 ;;; To make `uncomment-region' working, `comment-region' would
323 ;;; not insert extra space.
324 ;;; Here documents delimiters better recognized
325 ;;; (empty one, and non-alphanums in quotes handled). May be wrong with 1<<14?
326 ;;; `cperl-db' added, used in menu.
327 ;;; imenu scan removes text-properties, for better debugging
328 ;;; - but the bug is in 19.31 imenu.
329 ;;; formats highlighted by font-lock and prescan, embedded comments
331 ;;; POD/friends scan merged in one pass.
332 ;;; Syntax class is not used for analyzing the code, only char-syntax
333 ;;; may be checked against _ or'ed with w.
334 ;;; Syntax class of `:' changed to be _.
335 ;;; `cperl-find-bad-style' added.
338 ;;; When search for here-documents, we ignore commented << in simplest cases.
339 ;;; `cperl-get-help' added, available on C-h v and from menu.
340 ;;; Auto-help added. Default with `cperl-hairy', switchable on/off
341 ;;; with startup variable `cperl-lazy-help-time' and from
342 ;;; menu. Requires `run-with-idle-timer'.
343 ;;; Highlighting of @abc{@efg} was wrong - interchanged two regexps.
346 ;;; Indentation: At toplevel after a label - fixed.
347 ;;; 1.27 was put to archives in binary mode ===> DOSish :-(
350 ;;; Thanks to Martin Buchholz <mrb@Eng.Sun.COM>: misprints in
351 ;;; comments and docstrings corrected, XEmacs support cleaned up.
352 ;;; The closing parenths would enclose the region into matching
353 ;;; parens under the same conditions as the opening ones.
354 ;;; Minor updates to `cperl-short-docs'.
355 ;;; Will not consider <<= as start of here-doc.
358 ;;; Added an extra advice to look into Micro-docs. ;-).
359 ;;; Enclosing of region when you press a closing parenth is regulated by
360 ;;; `cperl-electric-parens-string'.
361 ;;; Minor updates to `cperl-short-docs'.
362 ;;; `initialize-new-tags-table' called only if present (Does this help
363 ;;; with generation of tags under XEmacs?).
364 ;;; When creating/updating tag files, new info is written at the old place,
365 ;;; or at the end (is this a wanted behaviour? I need this in perl build directory).
368 ;;; All the keywords from keywords.pl included (maybe with dummy explanation).
369 ;;; No auto-help inside strings, comment, here-docs, formats, and pods.
370 ;;; Shrinkwrapping of info, regulated by `cperl-max-help-size',
371 ;;; `cperl-shrink-wrap-info-frame'.
372 ;;; Info on variables as well.
373 ;;; Recognision of HERE-DOCS improved yet more.
374 ;;; Autonewline works on `}' without warnings.
375 ;;; Autohelp works again on $_[0].
378 ;;; perl-descr.el found its author - hi, Johan!
379 ;;; Some support for correct indent after here-docs and friends (may
380 ;;; be superseeded by eminent change to Emacs internals).
381 ;;; Should work with older Emaxen as well ( `-style stuff removed).
385 ;;; Started to add support for `syntax-table' property (should work
386 ;;; with patched Emaxen), controlled by
387 ;;; `cperl-use-syntax-table-text-property'. Currently recognized:
388 ;;; All quote-like operators: m, s, y, tr, qq, qw, qx, q,
389 ;;; // in most frequent context:
391 ;;; ~ { ( = | & + - * ! , ;
393 ;;; while if unless until and or not xor split grep map
394 ;;; Here-documents, formats, PODs,
397 ;;; sub a ($); sub a ($) {}
398 ;;; (provide 'cperl-mode) was missing!
399 ;;; `cperl-after-expr-p' is now much smarter after `}'.
400 ;;; `cperl-praise' added to mini-docs.
401 ;;; Utilities try to support subs-with-prototypes.
404 ;;; `cperl-after-expr-p' is now much smarter after "() {}" and "word {}":
405 ;;; if word is "else, map, grep".
406 ;;; Updated for new values of syntax-table constants.
407 ;;; Uses `help-char' (at last!) (disabled, does not work?!)
408 ;;; A couple of regexps where missing _ in character classes.
409 ;;; -s could be considered as start of regexp, 1../blah/ was not,
410 ;;; as was not /blah/ at start of file.
413 ;;; "\C-hv" was wrongly "\C-hf"
414 ;;; C-hv was not working on `[index()]' because of [] in skip-chars-*.
415 ;;; `__PACKAGE__' supported.
416 ;;; Thanks for Greg Badros: `cperl-lazy-unstall' is more complete,
417 ;;; `cperl-get-help' is made compatible with `query-replace'.
419 ;;;; As of Apr 15, development version of 19.34 supports
420 ;;;; `syntax-table' text properties. Try setting
421 ;;;; `cperl-use-syntax-table-text-property'.
424 ;;; We scan for s{}[] as well (in simplest situations).
425 ;;; We scan for $blah'foo as well.
426 ;;; The default is to use `syntax-table' text property if Emacs is good enough.
427 ;;; `cperl-lineup' is put on C-M-| (=C-M-S-\\).
428 ;;; Start of `cperl-beautify-regexp'.
431 ;;; `cperl-tags-hier-init' did not work in text-mode.
432 ;;; `cperl-noscan-files-regexp' had a misprint.
433 ;;; Generation of Class Hierarchy was broken due to a bug in `x-popup-menu'
437 ;;; my,local highlight vars after {} too.
438 ;;; TAGS could not be created before imenu was loaded.
439 ;;; `cperl-indent-left-aligned-comments' created.
440 ;;; Logic of `cperl-indent-exp' changed a little bit, should be more
441 ;;; robust w.r.t. multiline strings.
442 ;;; Recognition of blah'foo takes into account strings.
443 ;;; Added '.al' to the list of Perl extensions.
444 ;;; Class hierarchy is "mostly" sorted (need to rethink algorthm
445 ;;; of pruning one-root-branch subtrees to get yet better sorting.)
446 ;;; Regeneration of TAGS was busted.
447 ;;; Can use `syntax-table' property when generating TAGS
448 ;;; (governed by `cperl-use-syntax-table-text-property-for-tags').
451 ;;; Can process several =pod/=cut sections one after another.
452 ;;; Knows of `extproc' when under `emx', indents with `__END__' and `__DATA__'.
453 ;;; `cperl-under-as-char' implemented (XEmacs people like broken behaviour).
454 ;;; Beautifier for regexps fixed.
455 ;;; `cperl-beautify-level', `cperl-contract-level' coded
457 ;;;; Emacs's 20.2 problems:
458 ;;; `imenu.el' has bugs, `imenu-add-to-menubar' does not work.
459 ;;; Couple of others problems with 20.2 were reported, my ability to check/fix
460 ;;; them is very reduced now.
463 ;;; 'C-M-|' in XEmacs fixed
466 ;;; &&s was not recognized as start of regular expression;
467 ;;; Will "preprocess" the contents of //e part of s///e too;
468 ;;; What to do with s# blah # foo #e ?
469 ;;; Should handle s;blah;foo;; better.
470 ;;; Now the only known problems with regular expression recognition:
471 ;;;;;;; s<foo>/bar/ - different delimiters (end ignored)
472 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into one chunk)
473 ;;;;;;; s/foo// - empty subst (made into one chunk + '/')
474 ;;;;;;; s/foo/(bar)/ - start-group at start of subst (internal group will not match backwards)
477 ;;; We highlight closing / of s/blah/foo/e;
478 ;;; This handles s# blah # foo #e too;
479 ;;; s//blah/, s///, s/blah// works again, and s#blah## too, the algorithm
480 ;;; is much simpler now;
481 ;;; Next round of changes: s\\\ works, s<blah>/foo/,
482 ;;; comments between the first and the second part allowed
483 ;;; Another problem discovered:
484 ;;;;;;; s[foo] <blah>e - e part delimited by different <> (will not match)
485 ;;; `cperl-find-pods-heres' somehow maybe called when string-face is undefined
486 ;;; - put a stupid workaround for 20.1
489 ;;; Could indent here-docs for comments;
490 ;;; These problems fixed:
491 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into two chunk)
492 ;;;;;;; s[foo] <blah>e - "e" part delimited by "different" <> (will match)
493 ;;; Matching brackets honor prefices, may expand abbreviations;
494 ;;; When expanding abbrevs, will remove last char only after
495 ;;; self-inserted whitespace;
496 ;;; More convenient "Refress hard constructs" in menu;
497 ;;; `cperl-add-tags-recurse', `cperl-add-tags-recurse-noxs'
498 ;;; added (for -batch mode);
499 ;;; Better handling of errors when scanning for Perl constructs;
500 ;;;;;;; Possible "problem" with class hierarchy in Perl distribution
501 ;;;;;;; directory: ./ext duplicates ./lib;
502 ;;; Write relative paths for generated TAGS;
505 ;;; s /// may be separated by "\n\f" too;
506 ;;; `s #blah' recognized as a comment;
507 ;;; Would highlight s/abc//s wrong;
508 ;;; Debugging code in `cperl-electric-keywords' was leaking a message;
511 ;;; RMS changes for 20.3 merged
513 ;;;; 2.0.1.0: RMS mode (has 3 misprints)
516 ;;; RMS whitespace changes for 20.3 merged
522 ;;; Merge `c-style-alist' since `c-mode' is no more. (Somebody who
523 ;;; uses the styles should check that they work OK!)
524 ;;; All the variable warnings go away, some undef functions too.
527 ;;; Added `cperl-perldoc' (thanks to Anthony Foiani <afoiani@uswest.com>)
528 ;;; Added `cperl-pod-to-manpage' (thanks to Nick Roberts <Nick.Roberts@src.bae.co.uk>)
529 ;;; All the function warnings go away.
532 ;;; `Perl doc', `Regexp' submenus created (latter to allow short displays).
533 ;;; `cperl-clobber-lisp-bindings' added.
534 ;;; $a->y() is not y///.
535 ;;; `cperl-after-block-p' was missing a `save-excursion' => wrong results.
536 ;;; `cperl-val' was defined too late.
537 ;;; `cperl-init-faces' was failing.
538 ;;; Init faces when loading `ps-print'.
541 ;;; `cperl-toggle-autohelp' implemented.
542 ;;; `while SPACE LESS' was buggy.
543 ;;; `-text' in `[-text => 1]' was not highlighted.
544 ;;; `cperl-after-block-p' was FALSE after `sub f {}'.
547 ;;; `foreachmy', `formy' expanded too.
548 ;;; Expand `=pod-directive'.
549 ;;; `cperl-linefeed' behaves reasonable in POD-directive lines.
550 ;;; `cperl-electric-keyword' prints a message, governed by
551 ;;; `cperl-message-electric-keyword'.
554 ;;; Typing `}' was not checking for being block or not.
555 ;;; Beautifying levels in RE: Did not know about lookbehind;
556 ;;; finding *which* level was not intuitive;
557 ;;; `cperl-beautify-levels' added.
558 ;;; Allow here-docs contain `=head1' and friends (at least for keywords).
561 ;;; Fix for broken `font-lock-unfontify-region-function'. Should
562 ;;; preserve `syntax-table' properties even with `lazy-lock'.
565 ;;; Some more compile time warnings crept in.
566 ;;; `cperl-indent-region-fix-else' implemented.
567 ;;; `cperl-fix-line-spacing' implemented.
568 ;;; `cperl-invert-if-unless' implemented (C-c C-t and in Menu).
569 ;;; Upgraded hints to mention 20.2's goods/bads.
570 ;;; Started to use `cperl-extra-newline-before-brace-multiline',
571 ;;; `cperl-break-one-line-blocks-when-indent',
572 ;;; `cperl-fix-hanging-brace-when-indent', `cperl-merge-trailing-else'.
575 ;;; Workaround for another `font-lock's `syntax-table' text-property bug.
576 ;;; `zerop' could be applied to nil.
577 ;;; At last, may work with `font-lock' without setting `cperl-font-lock'.
578 ;;; (We expect that starting from 19.33, `font-lock' supports keywords
579 ;;; being a function - what is a correct version?)
580 ;;; Rename `cperl-indent-region-fix-else' to
581 ;;; `cperl-indent-region-fix-constructs'.
582 ;;; `cperl-fix-line-spacing' could be triggered inside strings, would not
583 ;;; know what to do with BLOCKs of map/printf/etc.
584 ;;; `cperl-merge-trailing-else' and `cperl-fix-line-spacing' handle
586 ;;; Indentation after {BLOCK} knows about map/printf/etc.
587 ;;; Finally: treat after-comma lines as continuation lines.
590 ;;; `continue' made electric.
591 ;;; Electric `do' inserts `do/while'.
592 ;;; Some extra compile-time warnings crept in.
593 ;;; `font-lock' of 19.33 could not handle font-lock-keywords being a function
594 ;;; returning a symbol.
597 ;;; Changes to make syntaxification to be autoredone via `font-lock'.
598 ;;; Switched on by `cperl-syntaxify-by-font-lock', off by default so far.
601 ;;; Remove some commented out chunks.
602 ;;; Styles are slightly updated (a lot of work is needed, especially
603 ;;; with new `cperl-fix-line-spacing').
606 ;;; Old value of style is memorized when choosing a new style, may be
607 ;;; restored from the same menu.
608 ;;; Mode-documentation added to micro-docs.
609 ;;; `cperl-praise' updated.
610 ;;; `cperl-toggle-construct-fix' added on C-c C-w and menu.
611 ;;; `auto-fill-mode' added on C-c C-f and menu.
612 ;;; `PerlStyle' style added.
613 ;;; Message for termination of scan corrected.
617 ;;; Did not work with -q
621 ;;; `cperl-speed' hints added.
622 ;;; Minor style fixes.
625 ;;; Make backspace electric after expansion of `else/continue' too.
628 ;;; Starting to merge changes to RMS emacs version.
631 ;;; Merged custom stuff and darn `font-lock-constant-face'.
634 ;;; Bumped the version to 3.1
637 ;;; Fixed customization to honor cperl-hairy.
638 ;;; Created customization groups. Sent to RMS to include into 2.3.
641 ;;; Interaction of `font-lock-hot-pass' and `cperl-syntaxify-by-font-lock'.
642 ;;; (`cperl-after-block-and-statement-beg'):
643 ;;; (`cperl-after-block-p'):
644 ;;; (`cperl-after-expr-p'): It is BLOCK if we reach lim when backup sexp.
645 ;;; (`cperl-indent-region'): Make a marker for END - text added/removed.
646 ;;; (`cperl-style-alist', `cperl-styles-entries')
647 ;;; Include `cperl-merge-trailing-else' where the value is clear.
651 ;;; (`cperl-problems'): Improvements to docs.
654 ;;; (`cperl-mode'): Make lazy syntaxification possible.
655 ;;; (`cperl-find-pods-heres'): Safe a position in buffer where it is safe to
656 ;;; restart syntaxification.
657 ;;; (`cperl-syntaxify-by-font-lock'): Set to t, should be safe now.
660 ;;; (`cperl-syntaxify-by-font-lock'): Better default, customizes to
664 ;;; (`cperl-find-pods-heres'): changed so that -d ?foo? is a RE.
665 ;;; (`cperl-array-face'): changed name from `font-lock-emphasized-face'.
666 ;;; (`cperl-hash-face'): changed name from `font-lock-other-emphasized-face'.
667 ;;; Use `defface' to define these two extra faces.
670 ;;; Can use linear algorithm for indentation if Emacs supports it:
671 ;;; indenting DB::DB (800+ lines) improved from 69 sec to 11 sec
672 ;;; (73 vs 15 with imenu).
673 ;;; (`cperl-emacs-can-parse'): New state.
674 ;;; (`cperl-indent-line'): Corrected to use global state.
675 ;;; (`cperl-calculate-indent'): Likewise.
676 ;;; (`cperl-fix-line-spacing'): Likewise (not used yet).
679 ;;; (`cperl-choose-color'): Converted to a function (to be compilable in text-mode).
682 ;;; (`cperl-dark-background '): Disable without window-system.
685 ;;; Do `defface' only if window-system.
688 ;;; (`cperl-fix-line-spacing'): sped up to bail out early.
689 ;;; (`cperl-indent-region'): Disable hooks during the call (how to call them later?).
691 ;;; Now indents 820-line-long function in 6.5 sec (including syntaxification) the first time
692 ;;; (when buffer has few properties), 7.1 sec the second time.
694 ;;;Function Name Call Count Elapsed Time Average Time
695 ;;;========================================= ========== ============ ============
696 ;;;cperl-indent-exp 1 10.039999999 10.039999999
697 ;;;cperl-indent-region 1 10.0 10.0
698 ;;;cperl-indent-line 821 6.2100000000 0.0075639464
699 ;;;cperl-calculate-indent 821 5.0199999999 0.0061144945
700 ;;;cperl-backward-to-noncomment 2856 2.0500000000 0.0007177871
701 ;;;cperl-fontify-syntaxically 2 1.78 0.8900000000
702 ;;;cperl-find-pods-heres 2 1.78 0.8900000000
703 ;;;cperl-update-syntaxification 1 1.78 1.78
704 ;;;cperl-fix-line-spacing 769 1.4800000000 0.0019245773
705 ;;;cperl-after-block-and-statement-beg 163 1.4100000000 0.0086503067
706 ;;;cperl-block-p 775 1.1800000000 0.0015225806
707 ;;;cperl-to-comment-or-eol 3652 1.1200000000 0.0003066812
708 ;;;cperl-after-block-p 165 1.0500000000 0.0063636363
709 ;;;cperl-commentify 141 0.22 0.0015602836
710 ;;;cperl-get-state 813 0.16 0.0001968019
711 ;;;cperl-backward-to-start-of-continued-exp 26 0.12 0.0046153846
712 ;;;cperl-delay-update-hook 2107 0.0899999999 4.271...e-05
713 ;;;cperl-protect-defun-start 141 0.0700000000 0.0004964539
714 ;;;cperl-after-label 407 0.0599999999 0.0001474201
715 ;;;cperl-forward-re 139 0.0299999999 0.0002158273
716 ;;;cperl-comment-indent 26 0.0299999999 0.0011538461
717 ;;;cperl-use-region-p 8 0.0 0.0
718 ;;;cperl-lazy-hook 15 0.0 0.0
719 ;;;cperl-after-expr-p 8 0.0 0.0
720 ;;;cperl-font-lock-unfontify-region-function 1 0.0 0.0
722 ;;;Function Name Call Count Elapsed Time Average Time
723 ;;;========================================= ========== ============ ============
724 ;;;cperl-fix-line-spacing 769 1.4500000000 0.0018855656
725 ;;;cperl-indent-line 13 0.3100000000 0.0238461538
726 ;;;cperl-after-block-and-statement-beg 69 0.2700000000 0.0039130434
727 ;;;cperl-after-block-p 69 0.2099999999 0.0030434782
728 ;;;cperl-calculate-indent 13 0.1000000000 0.0076923076
729 ;;;cperl-backward-to-noncomment 177 0.0700000000 0.0003954802
730 ;;;cperl-get-state 13 0.0 0.0
731 ;;;cperl-to-comment-or-eol 179 0.0 0.0
732 ;;;cperl-get-help-defer 1 0.0 0.0
733 ;;;cperl-lazy-hook 11 0.0 0.0
734 ;;;cperl-after-expr-p 2 0.0 0.0
735 ;;;cperl-block-p 13 0.0 0.0
736 ;;;cperl-after-label 5 0.0 0.0
739 ;;; (`cperl-find-pods-heres'): do not warn on `=cut' if doing a chunk only.
742 ;;; (`cperl-mode'): load pseudo-faces on `cperl-find-pods-heres' (for 19.30).
743 ;;; (`x-color-defined-p'): was not compiling on XEmacs
744 ;;; (`cperl-find-pods-heres'): 1 << 6 was OK, but 1<<6 was considered as HERE
745 ;;; <file/glob> made into a string.
748 ;;; (`cperl-find-pods-heres'): Postpone addition of faces after syntactic step
749 ;;; Recognition of <FH> was wrong.
750 ;;; (`cperl-clobber-lisp-bindings'): if set, C-c variants are the old ones
751 ;;; (`cperl-unwind-to-safe'): New function.
752 ;;; (`cperl-fontify-syntaxically'): Use `cperl-unwind-to-safe' to start at reasonable position.
755 ;;; (`cperl-forward-re'): Highlight the trailing / in s/foo// as string.
756 ;;; Highlight the starting // in s//foo/ as function-name.
759 ;;; (`cperl-find-pods-heres'): Highlight `gem' in s///gem as a keyword.
762 ;;; (`cperl-find-pods-heres'): `qr' added
763 ;;; (`cperl-electric-keyword'): Likewise
764 ;;; (`cperl-electric-else'): Likewise
765 ;;; (`cperl-to-comment-or-eol'): Likewise
766 ;;; (`cperl-make-regexp-x'): Likewise
767 ;;; (`cperl-init-faces'): Likewise, and `lock' (as overridable?).
768 ;;; (`cperl-find-pods-heres'): Knows that split// is null-RE.
769 ;;; Highlights separators in 3-parts expressions
773 ;;; (`cperl-find-pods-heres'): <> was considered as a glob
774 ;;; (`cperl-syntaxify-unwind'): New configuration variable
775 ;;; (`cperl-fontify-m-as-s'): New configuration variable
778 ;;; (`cperl-find-pods-heres'): of the last line being `=head1' fixed.
780 ;;; Handling of a long construct is still buggy if only the part of
781 ;;; construct touches the updated region (we unwind to the start of
782 ;;; long construct, but the end may have residual properties).
784 ;;; (`cperl-unwind-to-safe'): would not go to beginning of buffer.
785 ;;; (`cperl-electric-pod'): check for after-expr was performed
786 ;;; inside of POD too.
789 ;;; (`cperl-backward-to-noncomment'): better treatment of PODs and HEREs.
791 ;;; Indent-line works good, but indent-region does not - at toplevel...
792 ;;; (`cperl-unwind-to-safe'): Signature changed.
793 ;;; (`x-color-defined-p'): was defmacro'ed with a tick. Remove another def.
794 ;;; (`cperl-clobber-mode-lists'): New configuration variable.
795 ;;; (`cperl-array-face'): One of definitions was garbled.
798 ;;; (`cperl-not-bad-style-regexp'): Updated.
799 ;;; (`cperl-make-regexp-x'): Misprint in a message.
800 ;;; (`cperl-find-pods-heres'): $a-1 ? foo : bar; was a regexp.
801 ;;; `<< (' was considered a start of POD.
802 ;;; Init: `cperl-is-face' was busted.
803 ;;; (`cperl-make-face'): New macros.
804 ;;; (`cperl-force-face'): New macros.
805 ;;; (`cperl-init-faces'): Corrected to use new macros;
806 ;;; `if' for copying `reference-face' to
807 ;;; `constant-face' was backward.
808 ;;; (`font-lock-other-type-face'): Done via `defface' too.
811 ;;; (`cperl-init-faces-weak'): use `cperl-force-face'.
812 ;;; (`cperl-after-block-p'): After END/BEGIN we are a block.
813 ;;; (`cperl-mode'): `font-lock-unfontify-region-function'
814 ;;; was set to a wrong function.
815 ;;; (`cperl-comment-indent'): Commenting __END__ was not working.
816 ;;; (`cperl-indent-for-comment'): Likewise.
817 ;;; (Indenting is still misbehaving at toplevel.)
820 ;;; (`cperl-unwind-to-safe'): Signature changed, unwinds end too.
821 ;;; (`cperl-find-pods-heres'): mark qq[]-etc sections as syntax-type=string
822 ;;; (`cperl-fontify-syntaxically'): Unwinds start and end to go out of
823 ;;; long strings (not very successful).
825 ;;; >>>> CPerl should be usable in write mode too now <<<<
827 ;;; (`cperl-syntaxify-by-font-lock'): Better default - off in text-mode.
828 ;;; (`cperl-tips'): Updated docs.
829 ;;; (`cperl-problems'): Updated docs.
832 ;;; (`cperl-calculate-indent'): Did not consider `,' as continuation mark for statements.
833 ;;; (`cperl-write-tags'): Correct for XEmacs's `visit-tags-table-buffer'.
836 ;;; (`cperl-calculate-indent'): Avoid parse-data optimization at toplevel.
837 ;;; Should indent correctly at toplevel too.
838 ;;; (`cperl-tags-hier-init'): Gross hack to pretend we work (are we?).
839 ;;; (`cperl-find-pods-heres'): Was not processing sub protos after a comment ine.
840 ;;; Was treating $a++ <= 5 as a glob.
843 ;;; (toplevel): require custom unprotected => failure on 19.28.
844 ;;; (`cperl-xemacs-p') defined when compile too
845 ;;; (`cperl-tags-hier-init'): Another try to work around XEmacs problems
846 ;;; Better progress messages.
847 ;;; (`cperl-find-tags'): Was writing line/pos in a wrong order,
848 ;;; pos off by 1 and not at beg-of-line.
849 ;;; (`cperl-etags-snarf-tag'): New macro
850 ;;; (`cperl-etags-goto-tag-location'): New macro
851 ;;; (`cperl-write-tags'): When removing old TAGS info was not
852 ;;; relativizing filename
855 ;;; (`cperl-version'): New variable. New menu entry
858 ;;; (`cperl-tips'): Updated.
859 ;;; (`cperl-non-problems'): Updated.
860 ;;; random: References to future 20.3 removed.
863 ;;; (`perl-font-lock-keywords'): Would not highlight `sub foo($$);'.
864 ;;; Docstrings: Menu was described as `CPerl' instead of `Perl'
867 ;;; (`cperl-toggle-construct-fix'): Was toggling to t instead of 1.
868 ;;; (`cperl-ps-print-init'): Associate `cperl-array-face', `cperl-hash-face'
869 ;;; remove `font-lock-emphasized-face'.
870 ;;; remove `font-lock-other-emphasized-face'.
871 ;;; remove `font-lock-reference-face'.
872 ;;; remove `font-lock-keyword-face'.
873 ;;; Use `eval-after-load'.
874 ;;; (`cperl-init-faces'): remove init `font-lock-other-emphasized-face'.
875 ;;; remove init `font-lock-emphasized-face'.
876 ;;; remove init `font-lock-keyword-face'.
877 ;;; (`cperl-tips-faces'): New variable and an entry into Mini-docs.
878 ;;; (`cperl-indent-region'): Do not indent whitespace lines
879 ;;; (`cperl-indent-exp'): Was not processing else-blocks.
880 ;;; (`cperl-calculate-indent'): Remove another parse-data optimization
881 ;;; at toplevel: would indent correctly.
882 ;;; (`cperl-get-state'): NOP line removed.
885 ;;; (`cperl-ps-print-init'): Remove not-CPerl-related faces.
886 ;;; (`cperl-ps-print'): New function and menu entry.
887 ;;; (`cperl-ps-print-face-properties'): New configuration variable.
888 ;;; (`cperl-invalid-face'): New configuration variable.
889 ;;; (`cperl-nonoverridable-face'): New face. Renamed from
890 ;;; `font-lock-other-type-face'.
891 ;;; (`perl-font-lock-keywords'): Highlight trailing whitespace
892 ;;; (`cperl-contract-levels'): Documentation corrected.
893 ;;; (`cperl-contract-level'): Likewise.
896 ;;; (`cperl-ps-print'): `ps-print-face-extension-alist' was not in old Emaxen,
897 ;;; same with `ps-extend-face-list'
898 ;;; (`cperl-ps-extend-face-list'): New macro.
901 ;;; (`cperl-init-faces'): Interpolate `cperl-invalid-face'.
902 ;;; (`cperl-forward-re'): Emit a meaningful error instead of a cryptic
903 ;;; one for uncomplete REx near end-of-buffer.
904 ;;; (`cperl-find-pods-heres'): Tolerate unfinished REx at end-of-buffer.
907 ;;; (`cperl-find-pods-heres'): `unwind-protect' was left commented.
910 ;;; (`cperl-invalid-face'): Change to ''underline.
913 ;;; (`cperl-find-pods-heres'): / and ? after : start a REx.
914 ;;; (`cperl-after-expr-p'): Skip labels when checking
915 ;;; (`cperl-calculate-indent'): Correct for labels when calculating
916 ;;; indentation of continuations.
917 ;;; Docstring updated.
920 ;;; Minor (mostly spelling) corrections from 20.3.3 merged.
923 ;;; (`cperl-tips'): Another workaround added. Sent to RMS for 20.4.
926 ;;; (`cperl-praise'): Mention linear-time indent.
927 ;;; (`cperl-find-pods-heres'): @if ? a : b was considered a REx.
930 ;;; (`cperl-after-expr-p'): Make true after __END__.
931 ;;; (`cperl-electric-pod'): "SYNOPSIS" was misspelled.
934 ;;; (`cperl-beautify-regexp-piece'): Was not allowing for *? after a class.
935 ;;; Allow for POSIX char-classes.
936 ;;; Remove trailing whitespace when
937 ;;; adding new linebreak.
938 ;;; Add a level counter to stop shallow.
939 ;;; Indents unprocessed groups rigidly.
940 ;;; (`cperl-beautify-regexp'): Add an optional count argument to go that
941 ;;; many levels deep.
942 ;;; (`cperl-beautify-level'): Likewise
943 ;;; Menu: Add new entries to Regexp menu to do one level
944 ;;; (`cperl-contract-level'): Was entering an infinite loop
945 ;;; (`cperl-find-pods-heres'): Typo (double quoting).
946 ;;; Was detecting < $file > as FH instead of glob.
947 ;;; Support for comments in RExen (except
948 ;;; for m#\#comment#x), governed by
949 ;;; `cperl-regexp-scan'.
950 ;;; (`cperl-regexp-scan'): New customization variable.
951 ;;; (`cperl-forward-re'): Improve logic of resetting syntax table.
953 ;;;; After 4.23 and: After 4.24:
954 ;;; (`cperl-contract-levels'): Restore position.
955 ;;; (`cperl-beautify-level'): Likewise.
956 ;;; (`cperl-beautify-regexp'): Likewise.
957 ;;; (`cperl-commentify'): Rudimental support for length=1 runs
958 ;;; (`cperl-find-pods-heres'): Process 1-char long REx comments too /a#/x
959 ;;; Processes REx-comments in #-delimited RExen.
960 ;;; MAJOR BUG CORRECTED: after a misparse
961 ;;; a body of a subroutine could be corrupted!!!
962 ;;; One might need to reeval the function body
963 ;;; to fix things. (A similar bug was
964 ;;; present in `cperl-indent-region' eons ago.)
966 ;; (defun foo () (let ((a '(t))) (insert (format "%s" a)) (setcar a 'BUG) t))
969 ;;; C-x C-e the above three lines (at end-of-line). First evaluation
970 ;;; of `foo' inserts (t), second one inserts (BUG) ?!
972 ;;; In CPerl it was triggered by inserting then deleting `/' at start of
973 ;;; / a (?# asdf {[(}asdf )ef,/;
976 ;;; (`cperl-commentify'): Was recognizing length=2 "strings" as length=1.
977 ;;; (`imenu-example--create-perl-index'):
978 ;;; Was not enforcing syntaxification-to-the-end.
979 ;;; (`cperl-invert-if-unless'): Allow `for', `foreach'.
980 ;;; (`cperl-find-pods-heres'): Quote `cperl-nonoverridable-face'.
981 ;;; Mark qw(), m()x as indentable.
982 ;;; (`cperl-init-faces'): Highlight `sysopen' too.
983 ;;; Highlight $var in `for my $var' too.
984 ;;; (`cperl-invert-if-unless'): Was leaving whitespace at end.
985 ;;; (`cperl-linefeed'): Was splitting $var{$foo} if point after `{'.
986 ;;; (`cperl-calculate-indent'): Remove old commented out code.
987 ;;; Support (primitive) indentation of qw(), m()x.
991 ;;; (`cperl-problems'): Mention `fill-paragraph' on comment. \"" and
992 ;;; q [] with intervening newlines.
993 ;;; (`cperl-autoindent-on-semi'): New customization variable.
994 ;;; (`cperl-electric-semi'): Use `cperl-autoindent-on-semi'.
995 ;;; (`cperl-tips'): Mention how to make CPerl the default mode.
996 ;;; (`cperl-mode'): Support `outline-minor-mode'
997 ;;; (Thanks to Mark A. Hershberger).
998 ;;; (`cperl-outline-level'): New function.
999 ;;; (`cperl-highlight-variables-indiscriminately'): New customization var.
1000 ;;; (`cperl-init-faces'): Use `cperl-highlight-variables-indiscriminately'.
1001 ;;; (Thanks to Sean Kamath <kamath@pogo.wv.tek.com>).
1002 ;;; (`cperl-after-block-p'): Support CHECK and INIT.
1003 ;;; (`cperl-init-faces'): Likewise and "our".
1004 ;;; (Thanks to Doug MacEachern <dougm@covalent.net>).
1005 ;;; (`cperl-short-docs'): Likewise and "our".
1009 ;;; (`cperl-find-pods-heres'): Recognize \"" as a string.
1010 ;;; Mark whitespace and comments between q and []
1011 ;;; as `syntax-type' => `prestring'.
1012 ;;; Allow whitespace between << and "FOO".
1013 ;;; (`cperl-problems'): Remove \"" and q [] with intervening newlines.
1014 ;;; Mention multiple <<EOF as unsupported.
1015 ;;; (`cperl-highlight-variables-indiscriminately'): Doc misprint fixed.
1016 ;;; (`cperl-indent-parens-as-block'): New configuration variable.
1017 ;;; (`cperl-calculate-indent'): Merge cases of indenting non-BLOCK groups.
1018 ;;; Use `cperl-indent-parens-as-block'.
1019 ;;; (`cperl-find-pods-heres'): Test for =cut without empty line instead of
1020 ;;; complaining about no =cut.
1021 ;;; (`cperl-electric-pod'): Change the REx for POD from "\n\n=" to "^\n=".
1022 ;;; (`cperl-find-pods-heres'): Likewise.
1023 ;;; (`cperl-electric-pod'): Change `forward-sexp' to `forward-word':
1024 ;;; POD could've been marked as comment already.
1025 ;;; (`cperl-unwind-to-safe'): Unwind before start of POD too.
1028 ;;; (`cperl-forward-re'): Throw an error at proper moment REx unfinished.
1031 ;;; (`x-color-defined-p'): Make an extra case to peacify the warning.
1032 ;;; Toplevel: `defvar' to peacify the warnings.
1033 ;;; (`cperl-find-pods-heres'): Could access `font-lock-comment-face' in -nw.
1034 ;;;; No -nw-compile time warnings now.
1035 ;;; (`cperl-find-tags'): TAGS file had too short substring-to-search.
1036 ;;; Be less verbose in non-interactive mode
1037 ;;; (`imenu-example--create-perl-index'): Set index-marker after name
1038 ;;; (`cperl-outline-regexp'): New variable.
1039 ;;; (`cperl-outline-level'): Made compatible with `cperl-outline-regexp'.
1040 ;;; (`cperl-mode'): Made use `cperl-outline-regexp'.
1043 ;;; (`cperl-find-pods-heres'): =cut the last thing, no blank line, was error.
1044 ;;; (`cperl-outline-level'): Make start-of-file same level as `package'.
1047 ;;; (`cperl-electric-pod'): `head1' and `over' electric only if empty.
1048 ;;; (`cperl-unreadable-ok'): New variable.
1049 ;;; (`cperl-find-tags'): Use `cperl-unreadable-ok', do not fail
1050 ;;; on an unreadable file
1051 ;;; (`cperl-write-tags'): Use `cperl-unreadable-ok', do not fail
1052 ;;; on an unreadable directory
1055 ;;; Syncronized with v1.60 from Emacs 21.3.
1056 ;;; Mostly docstring and formatting changes, and:
1058 ;;; (`cperl-noscan-files-regexp'): Do not scan CVS subdirs
1059 ;;; (`cperl-problems'): Note that newer XEmacsen may syntaxify too
1060 ;;; (`imenu-example--create-perl-index'):
1061 ;;; Renamed to `cperl-imenu--create-perl-index'
1062 ;;; (`cperl-mode'): Replace `make-variable-buffer-local' by `make-local-variable'
1063 ;;; (`cperl-setup-tmp-buf'): Likewise
1064 ;;; (`cperl-fix-line-spacing'): Fix a misprint of "t" for "\t"
1065 ;;; (`cperl-next-bad-style'): Fix misprints in character literals
1068 ;;; (`cperl-font-lock-keywords'): +etc: Aliased to perl-font-lock-keywords.
1071 ;;; Further updates of whitespace and spelling w.r.t. RMS version.
1072 ;;; (`cperl-font-lock-keywords'): +etc: Avoid warnings when aliasing.
1073 ;;; (`cperl-mode'): Use `normal-auto-fill-function' if present.
1074 ;;; (`cperl-use-major-mode'): New variable
1075 ;;; (`cperl-can-font-lock'): New variable; replaces `window-system'
1076 ;;; (`cperl-tags-hier-init'): use `display-popup-menus-p' (if present)
1077 ;;; to choose `x-popup-menu' vs `tmm-prompt'
1079 ;;;; 4.35 has the following differences from version 1.40+ of RMS Emacs:
1081 ;;; New variables `cperl-use-major-mode', `cperl-can-font-lock';
1082 ;;; `cperl-use-major-mode' is (effectively) 'cperl-mode in RMS.
1083 ;;; `cperl-under-as-char' is nil in RMS.
1084 ;;; Minor differences in docstrings, and `cperl-non-problems'.
1085 ;;; Backward compatibility addressed: (`); (function (lambda ...)); font-lock;
1086 ;;; (:italic t bold t) vs (:slant italic :weight bold) in faces;
1087 ;;; `normal-auto-fill-function'.
1088 ;;; RMS version has wrong logic in `cperl-calculate-indent': $a = { } is
1089 ;;; wrongly indented if the closing brace is on a separate line.
1090 ;;; Different choice of ordering if's for is-x-REx and (eq (char-after b) ?\#)
1091 ;;; in `cperl-find-pods-heres'. [Cosmetic]
1094 ;;; (`cperl-find-pods-heres'): If no end of HERE-doc found, mark to the end
1095 ;;; of buffer. This enables recognition of end
1096 ;;; of HERE-doc "as one types".
1097 ;;; Require "\n" after trailing tag of HERE-doc.
1098 ;;; \( made non-quoting outside of string/comment
1099 ;;; (gdj-contributed).
1100 ;;; Likewise for \$.
1101 ;;; Remove `here-doc-group' text property at start
1102 ;;; (makes this property reliable).
1103 ;;; Text property `first-format-line' ==> t.
1104 ;;; Do not recognize $opt_s and $opt::s as s///.
1105 ;;; (`cperl-perldoc'): Use case-sensitive search (contributed).
1106 ;;; (`cperl-fix-line-spacing'): Allow "_" in $vars of foreach etc. when
1107 ;;; underscore isn't a word char (gdj-contributed).
1108 ;;; (`defun-prompt-regexp'): Allow prototypes.
1109 ;;; (`cperl-vc-header-alist'): Extract numeric version from the Id.
1110 ;;; Toplevel: Put toggle-autohelp into the mode menu.
1111 ;;; Better docs for toggle/set/unset autohelp.
1112 ;;; (`cperl-electric-backspace-untabify'): New customization variable
1113 ;;; (`cperl-after-expr-p'): Works after here-docs, formats, and PODs too
1114 ;;; (affects many electric constructs).
1115 ;;; (`cperl-calculate-indent'): Takes into account `first-format-line' ==>
1116 ;;; works after format.
1117 ;;; (`cperl-short-docs'): Make it work with ... too.
1118 ;;; "array context" ==> "list context"
1119 ;;; (`cperl-electric-keyword'): make $if (etc: "$@%&*") non-electric
1120 ;;; '(' after keyword would insert a doubled paren
1121 ;;; (`cperl-electric-paren'): documented affected by `cperl-electric-parens'
1122 ;;; (`cperl-electric-rparen'): Likewise
1123 ;;; (`cperl-build-manpage'): New function by Nick Roberts
1124 ;;; (`cperl-perldoc'): Make it work in XEmacs too
1127 ;;; (`cperl-find-pods-heres'): Recognize s => 1 and {s} (as a key or varname),
1128 ;;; { s:: } and { s::bar::baz } as varnames.
1129 ;;; (`cperl-after-expr-p'): Updates syntaxification before checks
1130 ;;; (`cperl-calculate-indent'): Likewise
1131 ;;; Fix wrong indent of blocks starting with POD
1132 ;;; (`cperl-after-block-p'): Optional argument for checking for a pre-block
1133 ;;; Recognize `continue' blocks too.
1134 ;;; (`cperl-electric-brace'): use `cperl-after-block-p' for detection;
1135 ;;; Now works for else/continue/sub blocks
1136 ;;; (`cperl-short-docs'): Minor edits; make messages fit 80-column screen
1139 ;;; `cperl-add-tags-recurse-noxs-fullpath': new function (for -batch mode)
1142 ;;;;;; Major edit. Summary of most visible changes:
1144 ;;;;;; a) Multiple <<HERE per line allowed.
1145 ;;;;;; b) Handles multiline subroutine declaration headers (with comments).
1146 ;;;;;; (The exception is `cperl-etags' - but it is not used in the rest
1147 ;;;;;; of the mode.)
1148 ;;;;;; c) Fontifies multiline my/our declarations (even with comments,
1149 ;;;;;; and with legacy `font-lock').
1150 ;;;;;; d) Major speedup of syntaxification, both immediate and postponed
1151 ;;;;;; (3.5x to 15x [for different CPUs and versions of Emacs] on the
1152 ;;;;;; huge real-life document I tested).
1153 ;;;;;; e) New bindings, edits to imenu.
1154 ;;;;;; f) "_" is made into word-char during fontification/syntaxification;
1155 ;;;;;; some attempts to recognize non-word "_" during other operations too.
1156 ;;;;;; g) Detect bug in Emacs with `looking-at' inside `narrow' and bulk out.
1157 ;;;;;; h) autoload some more perldoc-related stuff
1158 ;;;;;; i) Some new convenience features: ISpell POD/HEREDOCs, narrow-to-HEREDOC
1159 ;;;;;; j) Attempt to incorporate XEmacs edits which reached me
1161 ;;;; Fine-grained changelog:
1162 ;;; `cperl-hook-after-change': New configuration variable
1163 ;;; `cperl-vc-sccs-header': Likewise
1164 ;;; `cperl-vc-sccs-header': Likewise
1165 ;;; `cperl-vc-header-alist': Default via two preceding variables
1166 ;;; `cperl-invalid-face': Remove double quoting under XEmacs
1167 ;;; (still needed under 21.2)
1168 ;;; `cperl-tips': Update URLs for resources
1169 ;;; `cperl-problems': Likewise
1170 ;;; `cperl-praise': Mention new features
1171 ;;; New C-c key bindings: for `cperl-find-bad-style',
1172 ;;; `cperl-pod-spell', `cperl-here-doc-spell', `cperl-narrow-to-here-doc',
1173 ;;; `cperl-perdoc', `cperl-perldoc-at-point'
1174 ;;; CPerl Mode menu changes: "Fix style by spaces", "Imenu on Perl Info"
1175 ;;; moved, new submenu of Tools with Ispell entries and narrowing.
1176 ;;; `cperl-after-sub-regexp': New defsubst
1177 ;;; `cperl-imenu--function-name-regexp-perl': Use `cperl-after-sub-regexp',
1178 ;;; Allows heads up to head4
1179 ;;; Allow "package;"
1180 ;;; `defun-prompt-regexp': Use `cperl-after-sub-regexp',
1181 ;;; `paren-backwards-message': ??? Something for XEmacs???
1182 ;;; `cperl-mode': Never auto-switch abbrev-mode off
1183 ;;; Try to allow '_' be non-word char
1184 ;;; Do not use `font-lock-unfontify-region-function' on XEmacs
1185 ;;; Reset syntax cache on mode start
1186 ;;; Support multiline facification (even
1187 ;;; on legacy `font-lock')
1188 ;;; `cperl-facemenu-add-face-function': ??? Some contributed code ???
1189 ;;; `cperl-after-change-function': Since `font-lock' and `lazy-lock'
1190 ;;; refuse to inform us whether the fontification is due to lazy
1191 ;;; calling or due to edit to a buffer, install our own hook
1192 ;;; (controlled by `cperl-hook-after-change')
1193 ;;; `cperl-electric-pod': =cut may have been recognized as start
1194 ;;; `cperl-block-p': Moved, updated for attributes
1195 ;;; `cperl-calculate-indent': Try to allow '_' be non-word char
1196 ;;; Support subs with attributes
1197 ;;; `cperl-where-am-i': Queit (?) a warning
1198 ;;; `cperl-cached-syntax-table' New function
1199 ;;; `cperl-forward-re': Use `cperl-cached-syntax-table'
1200 ;;; `cperl-unwind-to-safe': Recognize `syntax-type' property
1201 ;;; changing in a middle of line
1202 ;;; `cperl-find-sub-attrs': New function
1203 ;;; `cperl-find-pods-heres': Allow many <<EOP per line
1204 ;;; Allow subs with attributes
1205 ;;; Major speedups (3.5x..15x on a real-life
1206 ;;; test file nph-proxy.pl)
1207 ;;; Recognize "extproc " (OS/2)
1208 ;;; case-folded and only at start
1209 ;;; /x on s///x with empty replacement was
1212 ;;; `cperl-after-block-p': Remarks on diff with `cperl-block-p'
1213 ;;; Allow subs with attributes, labels
1214 ;;; Do not confuse "else::foo" with "else"
1215 ;;; Minor optimizations...
1216 ;;; `cperl-after-expr-p': Try to allow '_' be non-word char
1217 ;;; `cperl-fill-paragraph': Try to detect a major bug in Emacs
1218 ;;; with `looking-at' inside `narrow' and bulk out if found
1219 ;;; `cperl-imenu--create-perl-index': Updates for new
1220 ;;; `cperl-imenu--function-name-regexp-perl'
1221 ;;; `cperl-outline-level': Likewise
1222 ;;; `cperl-init-faces': Allow multiline subroutine headers
1223 ;;; and my/our declarations, and ones with comments
1224 ;;; Allow subroutine attributes
1225 ;;; `cperl-imenu-on-info': Better docstring.
1226 ;;; `cperl-etags' Rudimentary support for attributes
1227 ;;; Support for packages and "package;"
1228 ;;; `cperl-add-tags-recurse-noxs': Better (?) docstring
1229 ;;; `cperl-add-tags-recurse-noxs-fullpath': Likewise
1230 ;;; `cperl-tags-hier-init': Misprint for `fboundp' fixed
1231 ;;; `cperl-not-bad-style-regexp': Try to allow '_' be non-word char
1232 ;;; `cperl-perldoc': Add autoload
1233 ;;; `cperl-perldoc-at-point': Likewise
1234 ;;; `cperl-here-doc-spell': New function
1235 ;;; `cperl-pod-spell': Likewise
1236 ;;; `cperl-map-pods-heres': Likewise
1237 ;;; `cperl-get-here-doc-region': Likewise
1238 ;;; `cperl-font-lock-fontify-region-function': Likewise (backward compatibility
1239 ;;; for legacy `font-lock')
1240 ;;; `cperl-font-lock-unfontify-region-function': Fix style
1241 ;;; `cperl-fontify-syntaxically': Recognize and optimize away
1242 ;;; deferred calls with no-change. Governed by `cperl-hook-after-change'
1243 ;;; `cperl-fontify-update': Recognize that syntaxification region
1244 ;;; can be larger than fontification one.
1245 ;;; XXXX we leave `cperl-postpone' property, so this is quadratic...
1246 ;;; `cperl-fontify-update-bad': Temporary placeholder until
1247 ;;; it is clear how to implement `cperl-fontify-update'.
1248 ;;; `cperl-time-fontification': New function
1249 ;;; `attrib-group': New text attribute
1250 ;;; `multiline': New value: `syntax-type' text attribute
1253 ;;; `cperl-emulate-lazy-lock': New function
1254 ;;; `cperl-fontify-syntaxically': Would skip large regions
1255 ;;; Add `cperl-time-fontification', `cperl-emulate-lazy-lock' to menu
1256 ;;; Some globals were declared, but uninitialized
1258 ;;;; After 5.3, 5.4:
1259 ;;; `cperl-facemenu-add-face-function': Add docs, fix U<>
1260 ;;; Copyright message updated.
1261 ;;; `cperl-init-faces': Work around a bug in `font-lock'. May slow
1262 ;;; facification down a bit.
1263 ;;; Misprint for my|our|local for old `font-lock'
1264 ;;; "our" was not fontified same as "my|local"
1265 ;;; Highlight variables after "my" etc even in
1266 ;;; a middle of an expression
1267 ;;; Do not facify multiple variables after my etc
1268 ;;; unless parentheses are present
1271 ;;; `cperl-fontify-syntaxically': after-change hook could reset
1272 ;;; `cperl-syntax-done-to' to a middle of line; unwind to BOL.
1275 ;;; `cperl-init-faces': Allow highlighting of local ($/)
1276 ;;; `cperl-problems-old-emaxen': New variable (for the purpose of DOCSTRING).
1277 ;;; `cperl-problems': Remove fixed problems.
1278 ;;; `cperl-find-pods-heres': Recognize #-comments in m##x too
1279 ;;; Recognize charclasses (unless delimiter is \).
1280 ;;; `cperl-fontify-syntaxically': Unwinding to safe was done in wrong order
1281 ;;; `cperl-regexp-scan': Update docs
1282 ;;; `cperl-beautify-regexp-piece': use information got from regexp scan
1285 ;;; Major user visible changes:
1286 ;;; Recognition and fontification of character classes in RExen.
1287 ;;; Variable indentation of RExen according to groups
1289 ;;; `cperl-find-pods-heres': Recognize POSIX classes in REx charclasses
1290 ;;; Fontify REx charclasses in variable-name face
1291 ;;; Fontify POSIX charclasses in "type" face
1292 ;;; Fontify unmatched "]" in function-name face
1293 ;;; Mark first-char of HERE-doc as `front-sticky'
1294 ;;; Reset `front-sticky' property when needed
1295 ;;; `cperl-calculate-indent': Indents //x -RExen accordning to parens level
1296 ;;; `cperl-to-comment-or-eol': Recognize ends of `syntax-type' constructs
1297 ;;; `cperl-backward-to-noncomment': Recognize stringy `syntax-type' constructs
1298 ;;; Support `narrow'ed buffers.
1299 ;;; `cperl-praise': Remove a reservation
1300 ;;; `cperl-make-indent': New function
1301 ;;; `cperl-indent-for-comment': Use `cperl-make-indent'
1302 ;;; `cperl-indent-line': Likewise
1303 ;;; `cperl-lineup': Likewise
1304 ;;; `cperl-beautify-regexp-piece': Likewise
1305 ;;; `cperl-contract-level': Likewise
1306 ;;; `cperl-toggle-set-debug-unwind': New function
1307 ;;; New menu entry for this
1308 ;;; `fill-paragraph-function': Use when `boundp'
1309 ;;; `cperl-calculate-indent': Take into account groups when indenting RExen
1310 ;;; `cperl-to-comment-or-eol': Recognize # which end a string
1311 ;;; `cperl-modify-syntax-type': Make only syntax-table property non-sticky
1312 ;;; `cperl-fill-paragraph': Return t: needed for `fill-paragraph-function'
1313 ;;; `cperl-fontify-syntaxically': More clear debugging message
1314 ;;; `cperl-pod2man-build-command': XEmacs portability: check `Man-filter-list'
1315 ;;; `cperl-init-faces': More complicated highlight even on XEmacs (new)
1316 ;;; Merge cosmetic changes from XEmacs
1319 ;;; `cperl-1+': Moved to before the first use
1320 ;;; `cperl-1-': Likewise
1324 ;;; This code may lock Emacs hard!!! Use on your own risk!
1326 ;;; `cperl-font-locking': New internal variable
1327 ;;; `cperl-beginning-of-property': New function
1328 ;;; `cperl-calculate-indent': Use `cperl-beginning-of-property'
1329 ;;; instead of `previous-single-property-change'
1330 ;;; `cperl-unwind-to-safe': Likewise
1331 ;;; `cperl-after-expr-p': Likewise
1332 ;;; `cperl-get-here-doc-region': Likewise
1333 ;;; `cperl-font-lock-fontify-region-function': Likewise
1334 ;;; `cperl-to-comment-or-eol': Do not call `cperl-update-syntaxification'
1336 ;;; Bound `next-single-property-change'
1338 ;;; `cperl-unwind-to-safe': Bound likewise
1339 ;;; `cperl-font-lock-fontify-region-function': Likewise
1340 ;;; `cperl-find-pods-heres': Mark as recursive for `cperl-to-comment-or-eol'
1341 ;;; Initialization of
1342 ;;; `cperl-font-lock-multiline-start' could be missed if the "main"
1343 ;;; fontification did not run due to the keyword being already fontified.
1344 ;;; `cperl-pod-spell': Return t from do-one-chunk function
1345 ;;; `cperl-map-pods-heres': Stop when the worker returns nil
1346 ;;; Call `cperl-update-syntaxification'
1347 ;;; `cperl-get-here-doc-region': Call `cperl-update-syntaxification'
1348 ;;; `cperl-get-here-doc-delim': Remove unused function
1352 ;;; The possible lockup of Emacs (introduced in 5.10) fixed
1354 ;;; `cperl-unwind-to-safe': `cperl-beginning-of-property' won't return nil
1355 ;;; `cperl-syntaxify-for-menu': New customization variable
1356 ;;; `cperl-select-this-pod-or-here-doc': New function
1357 ;;; `cperl-get-here-doc-region': Extra argument
1358 ;;; Do not adjust pos by 1
1360 ;;; New menu entries (Perl/Tools): selection of current POD or HERE-DOC section
1361 ;;; (Debugging CPerl:) backtrace on fontification
1364 ;;; `cperl-cached-syntax-table': use `car-safe'
1365 ;;; `cperl-forward-re': Remove spurious argument SET-ST
1366 ;;; Add documentation
1367 ;;; `cperl-forward-group-in-re': New function
1368 ;;; `cperl-find-pods-heres': Find and highlight (?{}) blocks in RExen
1369 ;;; (XXXX Temporary (?) hack is to syntax-mark them as comment)
1372 ;;; `cperl-string-syntax-table': Make { and } not-grouping
1373 ;;; (Sometimes they ARE grouping in RExen, but matching them would only
1374 ;;; confuse in many situations when they are not)
1375 ;;; `beginning-of-buffer': Replaced two occurences with goto-char...
1376 ;;; `cperl-calculate-indent': `char-after' could be nil...
1377 ;;; `cperl-find-pods-heres': REx can start after "[" too
1378 ;;; Hightlight (??{}) in RExen too
1379 ;;; `cperl-maybe-white-and-comment-rex': New constant
1380 ;;; `cperl-white-and-comment-rex': Likewise
1381 ;;; XXXX Not very efficient, but hard to make
1382 ;;; better while keeping 1 group
1385 ;;; `cperl-find-pods-heres': $foo << identifier() is not a HERE-DOC
1386 ;;; Likewise for 1 << identifier
1389 ;;; `cperl-find-pods-heres': Different logic for $foo .= <<EOF etc
1390 ;;; Error-less condition-case could fail
1391 ;;; `cperl-font-lock-fontify-region-function': Likewise
1392 ;;; `cperl-init-faces': Likewise
1395 ;;; `cperl-find-pods-heres': Support property REx-part2
1396 ;;; `cperl-calculate-indent': Likewise
1397 ;;; Don't special-case REx with non-empty 1st line
1398 ;;; `cperl-find-pods-heres': In RExen, highlight non-literal backslashes
1399 ;;; Invert highlighting of charclasses:
1400 ;;; now the envelop is highlighted
1401 ;;; Highlight many others 0-length builtins
1402 ;;; `cperl-praise': Mention indenting and highlight in RExen
1405 ;;; `cperl-find-pods-heres': Highlight capturing parens in REx
1408 ;;; `cperl-find-pods-heres': Highlight '|' for alternation
1409 ;;; Initialize `font-lock-warning-face' if not present
1410 ;;; `cperl-find-pods-heres': Use `font-lock-warning-face' instead of
1411 ;;; `font-lock-function-name-face'
1412 ;;; `cperl-look-at-leading-count': Likewise
1413 ;;; `cperl-find-pods-heres': localize `font-lock-variable-name-face'
1414 ;;; `font-lock-keyword-face' (needed for
1415 ;;; batch processing) etc
1416 ;;; Use `font-lock-builtin-face' for builtin in REx
1417 ;;; Now `font-lock-variable-name-face'
1418 ;;; is used for interpolated variables
1419 ;;; Use "talking aliases" for faces inside REx
1420 ;;; Highlight parts of REx (except in charclasses)
1421 ;;; according to the syntax and/or semantic
1422 ;;; Syntax-mark a {}-part of (?{}) as "comment"
1423 ;;; (it was the ()-part)
1424 ;;; Better logic to distinguish what is what in REx
1425 ;;; `cperl-tips-faces': Document REx highlighting
1426 ;;; `cperl-praise': Mention REx syntax highlight etc.
1429 ;;; `cperl-find-sub-attrs': Would not always manage to print error message
1430 ;;; `cperl-find-pods-heres': localize `font-lock-constant-face'
1433 ;;; `cperl-find-pods-heres': Misprint in REx for parsing REx
1434 ;;; Very minor optimization
1435 ;;; `my-cperl-REx-modifiers-face' got quoted
1436 ;;; Recognize "print $foo <<END" as HERE-doc
1437 ;;; Put `REx-interpolated' text attribute if needed
1438 ;;; `cperl-invert-if-unless-modifiers': New function
1439 ;;; `cperl-backward-to-start-of-expr': Likewise
1440 ;;; `cperl-forward-to-end-of-expr': Likewise
1441 ;;; `cperl-invert-if-unless': Works in "the opposite way" too
1442 ;;; Cursor position on return is on the switch-word
1443 ;;; Indents comments better
1444 ;;; `REx-interpolated': New text attribute
1445 ;;; `cperl-next-interpolated-REx': New function
1446 ;;; `cperl-next-interpolated-REx-0': Likewise
1447 ;;; `cperl-next-interpolated-REx-1': Likewise
1448 ;;; "\C-c\C-x", "\C-c\C-y", "\C-c\C-v": New keybinding for these functions
1449 ;;; Perl/Regexp menu: 3 new entries for `cperl-next-interpolated-REx'
1450 ;;; `cperl-praise': Mention finded interpolated RExen
1453 ;;; `cperl-init-faces': Highlight %$foo, @$foo too
1454 ;;; `cperl-short-docs': Better docs for system, exec
1455 ;;; `cperl-find-pods-heres': Better detect << after print {FH} <<EOF etc.
1456 ;;; Would not find HERE-doc ended by EOF without NL
1457 ;;; `cperl-short-docs': Correct not-doubled \-escapes
1458 ;;; start block: Put some `defvar' for stuff gone from XEmacs
1461 ;;; initial comment: Extend copyright, fix email address
1462 ;;; `cperl-indent-comment-at-column-0': New customization variable
1463 ;;; `cperl-comment-indent': Indentation after $#a would increasy by 1
1464 ;;; `cperl-mode': Make `defun-prompt-regexp' grok BEGIN/END etc
1465 ;;; `cperl-find-pods-heres': Mark CODE of s///e as `syntax-type' `multiline'
1466 ;;; `cperl-at-end-of-expr': Would fail if @BAR=12 follows after ";"
1467 ;;; `cperl-init-faces': If `cperl-highlight-variables-indiscriminately'
1468 ;;; highlight $ in $foo too (UNTESTED)
1469 ;;; `cperl-set-style': Docstring missed some available styles
1470 ;;; toplevel: Menubar/Perl/Indent-Styles had FSF, now K&R
1471 ;;; Change "Current" to "Memorize Current"
1472 ;;; `cperl-indent-wrt-brace': New customization variable; the default is
1473 ;;; as for pre-5.2 version
1474 ;;; `cperl-styles-entries': Keep `cperl-extra-newline-before-brace-multiline'
1475 ;;; `cperl-style-alist': Likewise
1476 ;;; `cperl-fix-line-spacing': Support `cperl-merge-trailing-else' being nil,
1477 ;;; and `cperl-extra-newline-before-brace' etc
1479 ;;; `cperl-indent-exp': Plans B and C to find continuation blocks even
1480 ;;; if `cperl-extra-newline-before-brace' is t
1483 ;;; Improve some docstrings concerning indentation.
1484 ;;; `cperl-indent-rules-alist': New variable
1485 ;;; `cperl-sniff-for-indent': New function name
1486 ;; (separated from `cperl-calculate-indent')
1487 ;;; `cperl-calculate-indent': Separated the sniffer and the indenter;
1488 ;;; uses `cperl-sniff-for-indent' now
1489 ;;; `cperl-comment-indent': Test for `cperl-indent-comment-at-column-0'
1491 ;;; Support `comment-column' = 0
1494 ;;; `cperl-where-am-i': Remove function
1495 ;;; `cperl-backward-to-noncomment': Would go too far when skipping POD/HEREs
1496 ;;; `cperl-sniff-for-indent': [string] and [comment] were inverted
1497 ;;; When looking for label, skip s:m:y:tr
1498 ;;; `cperl-indent-line': Likewise.
1499 ;;; `cperl-mode': `font-lock-multiline' was assumed auto-local
1500 ;;; `cperl-windowed-init': Wrong `ps-print' handling
1501 ;;; (both thanks to Chong Yidong)
1502 ;;; `cperl-look-at-leading-count': Could fail with unfinished RExen
1503 ;;; `cperl-find-pods-heres': If the second part of s()[] is missing,
1504 ;;; could try to highlight delimiters...
1508 (if (fboundp 'eval-when-compile)
1516 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
1517 (defvar cperl-can-font-lock
1519 (and (boundp 'emacs-major-version)
1521 (> emacs-major-version 20)))))
1522 (if cperl-can-font-lock
1523 (require 'font-lock))
1524 (defvar msb-menu-cond)
1525 (defvar gud-perldb-history)
1526 (defvar font-lock-background-mode) ; not in Emacs
1527 (defvar font-lock-display-type) ; ditto
1528 (defvar paren-backwards-message) ; Not in newer XEmacs?
1529 (defvar vc-rcs-header) ; likewise?
1530 (defvar vc-sccs-header) ; likewise?
1531 (or (fboundp 'defgroup)
1532 (defmacro defgroup (name val doc &rest arr)
1534 (or (fboundp 'custom-declare-variable)
1535 (defmacro defcustom (name val doc &rest arr)
1536 (` (defvar (, name) (, val) (, doc)))))
1537 (or (and (fboundp 'custom-declare-variable)
1538 (string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
1539 (defmacro defface (&rest arr)
1541 ;; Avoid warning (tmp definitions)
1542 (or (fboundp 'x-color-defined-p)
1543 (defmacro x-color-defined-p (col)
1544 (cond ((fboundp 'color-defined-p) (` (color-defined-p (, col))))
1546 ((fboundp 'valid-color-name-p) (` (valid-color-name-p (, col))))
1548 ((fboundp 'x-valid-color-name-p) (` (x-valid-color-name-p (, col))))
1549 (t '(error "Cannot implement color-defined-p")))))
1550 (defmacro cperl-is-face (arg) ; Takes quoted arg
1551 (cond ((fboundp 'find-face)
1552 (` (find-face (, arg))))
1553 (;;(and (fboundp 'face-list)
1555 (fboundp 'face-list)
1556 (` (member (, arg) (and (fboundp 'face-list)
1559 (` (boundp (, arg))))))
1560 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
1561 (cond ((fboundp 'make-face)
1562 (` (make-face (quote (, arg)))))
1564 (` (defvar (, arg) (quote (, arg)) (, descr))))))
1565 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
1567 (or (cperl-is-face (quote (, arg)))
1568 (cperl-make-face (, arg) (, descr)))
1569 (or (boundp (quote (, arg))) ; We use unquoted variants too
1570 (defvar (, arg) (quote (, arg)) (, descr))))))
1572 (defmacro cperl-etags-snarf-tag (file line)
1574 (beginning-of-line 2)
1575 (list (, file) (, line)))))
1576 (defmacro cperl-etags-snarf-tag (file line)
1577 (` (etags-snarf-tag))))
1579 (defmacro cperl-etags-goto-tag-location (elt)
1581 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
1582 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
1583 ;; Probably will not work due to some save-excursion???
1584 ;; Or save-file-position?
1585 ;; (message "Did I get to line %s?" (elt (, elt) 1))
1586 (goto-line (string-to-int (elt (, elt) 1)))))
1588 (defmacro cperl-etags-goto-tag-location (elt)
1589 (` (etags-goto-tag-location (, elt)))))))
1591 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
1593 (defvar cperl-can-font-lock
1595 (and (boundp 'emacs-major-version)
1597 (> emacs-major-version 20)))))
1601 (error nil)) ; Already fixed by eval-when-compile
1603 (defun cperl-choose-color (&rest list)
1607 (if (or (x-color-defined-p (car list))
1609 (setq answer (car list))))
1610 (setq list (cdr list)))
1615 "Major mode for editing Perl code."
1619 (defgroup cperl-indentation-details nil
1624 (defgroup cperl-affected-by-hairy nil
1625 "Variables affected by `cperl-hairy'."
1629 (defgroup cperl-autoinsert-details nil
1630 "Auto-insert tuneup."
1634 (defgroup cperl-faces nil
1635 "Fontification colors."
1639 (defgroup cperl-speed nil
1640 "Speed vs. validity tuneup."
1644 (defgroup cperl-help-system nil
1645 "Help system tuneup."
1650 (defcustom cperl-extra-newline-before-brace nil
1651 "*Non-nil means that if, elsif, while, until, else, for, foreach
1652 and do constructs look like:
1663 :group 'cperl-autoinsert-details)
1665 (defcustom cperl-extra-newline-before-brace-multiline
1666 cperl-extra-newline-before-brace
1667 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
1668 for constructs with multiline if/unless/while/until/for/foreach condition."
1670 :group 'cperl-autoinsert-details)
1672 (defcustom cperl-indent-level 2
1673 "*Indentation of CPerl statements with respect to containing block."
1675 :group 'cperl-indentation-details)
1677 (defcustom cperl-lineup-step nil
1678 "*`cperl-lineup' will always lineup at multiple of this number.
1679 If nil, the value of `cperl-indent-level' will be used."
1680 :type '(choice (const nil) integer)
1681 :group 'cperl-indentation-details)
1683 (defcustom cperl-brace-imaginary-offset 0
1684 "*Imagined indentation of a Perl open brace that actually follows a statement.
1685 An open brace following other text is treated as if it were this far
1686 to the right of the start of its line."
1688 :group 'cperl-indentation-details)
1690 (defcustom cperl-brace-offset 0
1691 "*Extra indentation for braces, compared with other text in same context."
1693 :group 'cperl-indentation-details)
1694 (defcustom cperl-label-offset -2
1695 "*Offset of CPerl label lines relative to usual indentation."
1697 :group 'cperl-indentation-details)
1698 (defcustom cperl-min-label-indent 1
1699 "*Minimal offset of CPerl label lines."
1701 :group 'cperl-indentation-details)
1702 (defcustom cperl-continued-statement-offset 2
1703 "*Extra indent for lines not starting new statements."
1705 :group 'cperl-indentation-details)
1706 (defcustom cperl-continued-brace-offset 0
1707 "*Extra indent for substatements that start with open-braces.
1708 This is in addition to cperl-continued-statement-offset."
1710 :group 'cperl-indentation-details)
1711 (defcustom cperl-close-paren-offset -1
1712 "*Extra indent for substatements that start with close-parenthesis."
1714 :group 'cperl-indentation-details)
1716 (defcustom cperl-indent-wrt-brace t
1717 "*Non-nil means indent statements in if/etc block relative brace, not if/etc.
1718 Versions 5.2 ... 5.20 behaved as if this were `nil'."
1720 :group 'cperl-indentation-details)
1722 (defcustom cperl-auto-newline nil
1723 "*Non-nil means automatically newline before and after braces,
1724 and after colons and semicolons, inserted in CPerl code. The following
1725 \\[cperl-electric-backspace] will remove the inserted whitespace.
1726 Insertion after colons requires both this variable and
1727 `cperl-auto-newline-after-colon' set."
1729 :group 'cperl-autoinsert-details)
1731 (defcustom cperl-autoindent-on-semi nil
1732 "*Non-nil means automatically indent after insertion of (semi)colon.
1733 Active if `cperl-auto-newline' is false."
1735 :group 'cperl-autoinsert-details)
1737 (defcustom cperl-auto-newline-after-colon nil
1738 "*Non-nil means automatically newline even after colons.
1739 Subject to `cperl-auto-newline' setting."
1741 :group 'cperl-autoinsert-details)
1743 (defcustom cperl-tab-always-indent t
1744 "*Non-nil means TAB in CPerl mode should always reindent the current line,
1745 regardless of where in the line point is when the TAB command is used."
1747 :group 'cperl-indentation-details)
1749 (defcustom cperl-font-lock nil
1750 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
1751 Can be overwritten by `cperl-hairy' if nil."
1752 :type '(choice (const null) boolean)
1753 :group 'cperl-affected-by-hairy)
1755 (defcustom cperl-electric-lbrace-space nil
1756 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
1757 Can be overwritten by `cperl-hairy' if nil."
1758 :type '(choice (const null) boolean)
1759 :group 'cperl-affected-by-hairy)
1761 (defcustom cperl-electric-parens-string "({[]})<"
1762 "*String of parentheses that should be electric in CPerl.
1763 Closing ones are electric only if the region is highlighted."
1765 :group 'cperl-affected-by-hairy)
1767 (defcustom cperl-electric-parens nil
1768 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
1769 Can be overwritten by `cperl-hairy' if nil."
1770 :type '(choice (const null) boolean)
1771 :group 'cperl-affected-by-hairy)
1773 (defvar zmacs-regions) ; Avoid warning
1775 (defcustom cperl-electric-parens-mark
1777 (or (and (boundp 'transient-mark-mode) ; For Emacs
1778 transient-mark-mode)
1779 (and (boundp 'zmacs-regions) ; For XEmacs
1781 "*Not-nil means that electric parens look for active mark.
1782 Default is yes if there is visual feedback on mark."
1784 :group 'cperl-autoinsert-details)
1786 (defcustom cperl-electric-linefeed nil
1787 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
1788 In any case these two mean plain and hairy linefeeds together.
1789 Can be overwritten by `cperl-hairy' if nil."
1790 :type '(choice (const null) boolean)
1791 :group 'cperl-affected-by-hairy)
1793 (defcustom cperl-electric-keywords nil
1794 "*Not-nil (and non-null) means keywords are electric in CPerl.
1795 Can be overwritten by `cperl-hairy' if nil."
1796 :type '(choice (const null) boolean)
1797 :group 'cperl-affected-by-hairy)
1799 (defcustom cperl-electric-backspace-untabify t
1800 "*Not-nil means electric-backspace will untabify in CPerl."
1802 :group 'cperl-autoinsert-details)
1804 (defcustom cperl-hairy nil
1805 "*Not-nil means most of the bells and whistles are enabled in CPerl.
1806 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
1807 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
1808 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
1809 `cperl-lazy-help-time'."
1811 :group 'cperl-affected-by-hairy)
1813 (defcustom cperl-comment-column 32
1814 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
1816 :group 'cperl-indentation-details)
1818 (defcustom cperl-indent-comment-at-column-0 nil
1819 "*Non-nil means that comment started at column 0 should be indentable."
1821 :group 'cperl-indentation-details)
1823 (defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
1824 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
1825 :type '(repeat string)
1828 (defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
1829 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
1830 :type '(repeat string)
1833 ;; This became obsolete...
1834 (defcustom cperl-vc-header-alist '()
1835 "*What to use as `vc-header-alist' in CPerl.
1836 Obsolete, with newer Emacsen use `cperl-vc-rcs-header' or
1837 `cperl-vc-sccs-header' instead. If this list is empty, `vc-header-alist'
1838 will be reconstructed basing on these two variables."
1839 :type '(repeat (list symbol string))
1842 (defcustom cperl-clobber-mode-lists
1845 (boundp 'interpreter-mode-alist)
1846 (assoc "miniperl" interpreter-mode-alist)
1847 (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
1848 "*Whether to install us into `interpreter-' and `extension' mode lists."
1852 (defcustom cperl-info-on-command-no-prompt nil
1853 "*Not-nil (and non-null) means not to prompt on C-h f.
1854 The opposite behaviour is always available if prefixed with C-c.
1855 Can be overwritten by `cperl-hairy' if nil."
1856 :type '(choice (const null) boolean)
1857 :group 'cperl-affected-by-hairy)
1859 (defcustom cperl-clobber-lisp-bindings nil
1860 "*Not-nil (and non-null) means not overwrite C-h f.
1861 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
1862 Can be overwritten by `cperl-hairy' if nil."
1863 :type '(choice (const null) boolean)
1864 :group 'cperl-affected-by-hairy)
1866 (defcustom cperl-lazy-help-time nil
1867 "*Not-nil (and non-null) means to show lazy help after given idle time.
1868 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
1869 :type '(choice (const null) (const nil) integer)
1870 :group 'cperl-affected-by-hairy)
1872 (defcustom cperl-pod-face 'font-lock-comment-face
1873 "*The result of evaluation of this expression is used for POD highlighting."
1875 :group 'cperl-faces)
1877 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
1878 "*The result of evaluation of this expression is used for POD highlighting.
1879 Font for POD headers."
1881 :group 'cperl-faces)
1883 (defcustom cperl-here-face 'font-lock-string-face
1884 "*The result of evaluation of this expression is used for here-docs highlighting."
1886 :group 'cperl-faces)
1888 ;;; Some double-evaluation happened with font-locks... Needed with 21.2...
1889 (defvar cperl-singly-quote-face cperl-xemacs-p)
1891 (defcustom cperl-invalid-face ; Does not customize with '' on XEmacs
1892 (if cperl-singly-quote-face
1893 'underline ''underline) ; On older Emacsen was evaluated by `font-lock'
1894 (if cperl-singly-quote-face
1895 "*This face is used for highlighting trailing whitespace."
1896 "*The result of evaluation of this expression highlights trailing whitespace.")
1898 :group 'cperl-faces)
1900 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
1901 "*Not-nil after evaluation means to highlight POD and here-docs sections."
1903 :group 'cperl-faces)
1905 (defcustom cperl-fontify-m-as-s t
1906 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
1908 :group 'cperl-faces)
1910 (defcustom cperl-highlight-variables-indiscriminately nil
1911 "*Non-nil means perform additional highlighting on variables.
1912 Currently only changes how scalar variables are highlighted.
1913 Note that that variable is only read at initialization time for
1914 the variable `perl-font-lock-keywords-2', so changing it after you've
1915 entered CPerl mode the first time will have no effect."
1919 (defcustom cperl-pod-here-scan t
1920 "*Not-nil means look for POD and here-docs sections during startup.
1921 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
1923 :group 'cperl-speed)
1925 (defcustom cperl-regexp-scan t
1926 "*Not-nil means make marking of regular expression more thorough.
1927 Effective only with `cperl-pod-here-scan'."
1929 :group 'cperl-speed)
1931 (defcustom cperl-hook-after-change t
1932 "*Not-nil means install hook to know which regions of buffer are changed.
1933 May significantly speed up delayed fontification. Changes take effect
1936 :group 'cperl-speed)
1938 (defcustom cperl-imenu-addback nil
1939 "*Not-nil means add backreferences to generated `imenu's.
1940 May require patched `imenu' and `imenu-go'. Obsolete."
1942 :group 'cperl-help-system)
1944 (defcustom cperl-max-help-size 66
1945 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
1946 :type '(choice integer (const nil))
1947 :group 'cperl-help-system)
1949 (defcustom cperl-shrink-wrap-info-frame t
1950 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
1952 :group 'cperl-help-system)
1954 (defcustom cperl-info-page "perl"
1955 "*Name of the info page containing perl docs.
1956 Older version of this page was called `perl5', newer `perl'."
1958 :group 'cperl-help-system)
1960 (defcustom cperl-use-syntax-table-text-property
1961 (boundp 'parse-sexp-lookup-properties)
1962 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
1964 :group 'cperl-speed)
1966 (defcustom cperl-use-syntax-table-text-property-for-tags
1967 cperl-use-syntax-table-text-property
1968 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
1970 :group 'cperl-speed)
1972 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
1973 "*Regexp to match files to scan when generating TAGS."
1977 (defcustom cperl-noscan-files-regexp
1978 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
1979 "*Regexp to match files/dirs to skip when generating TAGS."
1983 (defcustom cperl-regexp-indent-step nil
1984 "*Indentation used when beautifying regexps.
1985 If nil, the value of `cperl-indent-level' will be used."
1986 :type '(choice integer (const nil))
1987 :group 'cperl-indentation-details)
1989 (defcustom cperl-indent-left-aligned-comments t
1990 "*Non-nil means that the comment starting in leftmost column should indent."
1992 :group 'cperl-indentation-details)
1994 (defcustom cperl-under-as-char t
1995 "*Non-nil means that the _ (underline) should be treated as word char."
1999 (defcustom cperl-extra-perl-args ""
2000 "*Extra arguments to use when starting Perl.
2001 Currently used with `cperl-check-syntax' only."
2005 (defcustom cperl-message-electric-keyword t
2006 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
2008 :group 'cperl-help-system)
2010 (defcustom cperl-indent-region-fix-constructs 1
2011 "*Amount of space to insert between `}' and `else' or `elsif'
2012 in `cperl-indent-region'. Set to nil to leave as is. Values other
2013 than 1 and nil will probably not work."
2014 :type '(choice (const nil) (const 1))
2015 :group 'cperl-indentation-details)
2017 (defcustom cperl-break-one-line-blocks-when-indent t
2018 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
2019 need to be reformatted into multiline ones when indenting a region."
2021 :group 'cperl-indentation-details)
2023 (defcustom cperl-fix-hanging-brace-when-indent t
2024 "*Non-nil means that BLOCK-end `}' may be put on a separate line
2025 when indenting a region.
2026 Braces followed by else/elsif/while/until are excepted."
2028 :group 'cperl-indentation-details)
2030 (defcustom cperl-merge-trailing-else t
2031 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
2032 may be merged to be on the same line when indenting a region."
2034 :group 'cperl-indentation-details)
2036 (defcustom cperl-indent-parens-as-block nil
2037 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
2038 but for trailing \",\" inside the group, which won't increase indentation.
2039 One should tune up `cperl-close-paren-offset' as well."
2041 :group 'cperl-indentation-details)
2043 (defcustom cperl-syntaxify-by-font-lock
2044 (and cperl-can-font-lock
2045 (boundp 'parse-sexp-lookup-properties))
2046 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
2047 :type '(choice (const message) boolean)
2048 :group 'cperl-speed)
2050 (defcustom cperl-syntaxify-unwind
2052 "*Non-nil means that CPerl unwinds to a start of a long construction
2053 when syntaxifying a chunk of buffer."
2055 :group 'cperl-speed)
2057 (defcustom cperl-syntaxify-for-menu
2059 "*Non-nil means that CPerl syntaxifies up to the point before showing menu.
2060 This way enabling/disabling of menu items is more correct."
2062 :group 'cperl-speed)
2064 (defcustom cperl-ps-print-face-properties
2065 '((font-lock-keyword-face nil nil bold shadow)
2066 (font-lock-variable-name-face nil nil bold)
2067 (font-lock-function-name-face nil nil bold italic box)
2068 (font-lock-constant-face nil "LightGray" bold)
2069 (cperl-array-face nil "LightGray" bold underline)
2070 (cperl-hash-face nil "LightGray" bold italic underline)
2071 (font-lock-comment-face nil "LightGray" italic)
2072 (font-lock-string-face nil nil italic underline)
2073 (cperl-nonoverridable-face nil nil italic underline)
2074 (font-lock-type-face nil nil underline)
2075 (font-lock-warning-face nil "LightGray" bold italic box)
2076 (underline nil "LightGray" strikeout))
2077 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
2078 :type '(repeat (cons symbol
2079 (cons (choice (const nil) string)
2080 (cons (choice (const nil) string)
2082 :group 'cperl-faces)
2084 (if cperl-can-font-lock
2086 (defvar cperl-dark-background
2087 (cperl-choose-color "navy" "os2blue" "darkgreen"))
2088 (defvar cperl-dark-foreground
2089 (cperl-choose-color "orchid1" "orange"))
2091 (defface cperl-nonoverridable-face
2092 (` ((((class grayscale) (background light))
2093 (:background "Gray90" :italic t :underline t))
2094 (((class grayscale) (background dark))
2095 (:foreground "Gray80" :italic t :underline t :bold t))
2096 (((class color) (background light))
2097 (:foreground "chartreuse3"))
2098 (((class color) (background dark))
2099 (:foreground (, cperl-dark-foreground)))
2100 (t (:bold t :underline t))))
2101 "Font Lock mode face used to highlight array names."
2102 :group 'cperl-faces)
2104 (defface cperl-array-face
2105 (` ((((class grayscale) (background light))
2106 (:background "Gray90" :bold t))
2107 (((class grayscale) (background dark))
2108 (:foreground "Gray80" :bold t))
2109 (((class color) (background light))
2110 (:foreground "Blue" :background "lightyellow2" :bold t))
2111 (((class color) (background dark))
2112 (:foreground "yellow" :background (, cperl-dark-background) :bold t))
2114 "Font Lock mode face used to highlight array names."
2115 :group 'cperl-faces)
2117 (defface cperl-hash-face
2118 (` ((((class grayscale) (background light))
2119 (:background "Gray90" :bold t :italic t))
2120 (((class grayscale) (background dark))
2121 (:foreground "Gray80" :bold t :italic t))
2122 (((class color) (background light))
2123 (:foreground "Red" :background "lightyellow2" :bold t :italic t))
2124 (((class color) (background dark))
2125 (:foreground "Red" :background (, cperl-dark-background) :bold t :italic t))
2126 (t (:bold t :italic t))))
2127 "Font Lock mode face used to highlight hash names."
2128 :group 'cperl-faces)))
2132 ;;; Short extra-docs.
2134 (defvar cperl-tips 'please-ignore-this-line
2135 "Get maybe newer version of this package from
2136 http://ilyaz.org/software/emacs
2137 Subdirectory `cperl-mode' may contain yet newer development releases and/or
2138 patches to related files.
2140 For best results apply to an older Emacs the patches from
2141 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
2142 \(this upgrades syntax-parsing abilities of RMS Emaxen v19.34 and
2143 v20.2 up to the level of RMS Emacs v20.3 - a must for a good Perl
2144 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
2146 Get support packages choose-color.el (or font-lock-extra.el before
2147 19.30), imenu-go.el from the same place. \(Look for other files there
2148 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
2149 later you should use choose-color.el *instead* of font-lock-extra.el
2150 \(and you will not get smart highlighting in C :-().
2152 Note that to enable Compile choices in the menu you need to install
2155 If your Emacs does not default to `cperl-mode' on Perl files, and you
2156 want it to: put the following into your .emacs file:
2158 (autoload 'perl-mode \"cperl-mode\" \"alternate mode for editing Perl programs\" t)
2162 (defalias 'perl-mode 'cperl-mode)
2165 $CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
2166 Also, one can generate a newer documentation running `pod2texi' converter
2167 $CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
2169 If you use imenu-go, run imenu on perl5-info buffer (you can do it
2170 from Perl menu). If many files are related, generate TAGS files from
2171 Tools/Tags submenu in Perl menu.
2173 If some class structure is too complicated, use Tools/Hierarchy-view
2174 from Perl menu, or hierarchic view of imenu. The second one uses the
2175 current buffer only, the first one requires generation of TAGS from
2176 Perl/Tools/Tags menu beforehand.
2178 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
2180 Switch auto-help on/off with Perl/Tools/Auto-help.
2182 Though with contemporary Emaxen CPerl mode should maintain the correct
2183 parsing of Perl even when editing, sometimes it may be lost. Fix this by
2191 In cases of more severe confusion sometimes it is helpful to do
2193 M-x load-l RET cperl-mode RET
2198 \\[load-library] cperl-mode RET
2201 Before reporting (non-)problems look in the problem section of online
2202 micro-docs on what I know about CPerl problems.")
2204 (defvar cperl-problems 'please-ignore-this-line
2205 "Description of problems in CPerl mode.
2206 Some faces will not be shown on some versions of Emacs unless you
2207 install choose-color.el, available from
2208 http://ilyaz.org/software/emacs
2210 `fill-paragraph' on a comment may leave the point behind the
2211 paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
2212 to detect it and bulk out).
2214 See documentation of a variable `cperl-problems-old-emaxen' for the
2215 problems which disappear if you upgrade Emacs to a reasonably new
2216 version (20.3 for RMS Emacs, and those of 2004 for XEmacs).")
2218 (defvar cperl-problems-old-emaxen 'please-ignore-this-line
2219 "Description of problems in CPerl mode specific for older Emacs versions.
2221 Emacs had a _very_ restricted syntax parsing engine until RMS's Emacs
2222 20.1. Most problems below are corrected starting from this version of
2223 Emacs, and all of them should be fixed in RMS's version 20.3. (Or apply
2224 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
2225 this respect (until 2003).
2227 Note that even with newer Emacsen in some very rare cases the details
2228 of interaction of `font-lock' and syntaxification may be not cleaned
2229 up yet. You may get slightly different colors basing on the order of
2230 fontification and syntaxification. Say, the initial faces is correct,
2231 but editing the buffer breaks this.
2233 Even with older Emacsen CPerl mode tries to corrects some Emacs
2234 misunderstandings, however, for efficiency reasons the degree of
2235 correction is different for different operations. The partially
2236 corrected problems are: POD sections, here-documents, regexps. The
2237 operations are: highlighting, indentation, electric keywords, electric
2240 This may be confusing, since the regexp s#//#/#\; may be highlighted
2241 as a comment, but it will be recognized as a regexp by the indentation
2242 code. Or the opposite case, when a POD section is highlighted, but
2243 may break the indentation of the following code (though indentation
2244 should work if the balance of delimiters is not broken by POD).
2246 The main trick (to make $ a \"backslash\") makes constructions like
2247 ${aaa} look like unbalanced braces. The only trick I can think of is
2248 to insert it as $ {aaa} (legal in perl5, not in perl4).
2250 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
2251 as /($|\\s)/. Note that such a transposition is not always possible.
2253 The solution is to upgrade your Emacs or patch an older one. Note
2254 that RMS's 20.2 has some bugs related to `syntax-table' text
2255 properties. Patches are available on the main CPerl download site,
2258 If these bugs cannot be fixed on your machine (say, you have an inferior
2259 environment and cannot recompile), you may still disable all the fancy stuff
2260 via `cperl-use-syntax-table-text-property'.")
2262 (defvar cperl-non-problems 'please-ignore-this-line
2263 "As you know from `problems' section, Perl syntax is too hard for CPerl on
2264 older Emacsen. Here is what you can do if you cannot upgrade, or if
2265 you want to switch off these capabilities on RMS Emacs 20.2 (+patches) or 20.3
2266 or better. Please skip this docs if you run a capable Emacs already.
2268 Most of the time, if you write your own code, you may find an equivalent
2269 \(and almost as readable) expression (what is discussed below is usually
2270 not relevant on newer Emacsen, since they can do it automatically).
2272 Try to help CPerl: add comments with embedded quotes to fix CPerl
2273 misunderstandings about the end of quotation:
2277 You won't need it too often. The reason: $ \"quotes\" the following
2278 character (this saves a life a lot of times in CPerl), thus due to
2279 Emacs parsing rules it does not consider tick (i.e., ' ) after a
2280 dollar as a closing one, but as a usual character. This is usually
2281 correct, but not in the above context.
2283 Even with older Emacsen the indentation code is pretty wise. The only
2284 drawback is that it relied on Emacs parsing to find matching
2285 parentheses. And Emacs *could not* match parentheses in Perl 100%
2288 would not break indentation, but
2294 could confuse CPerl a lot.
2296 If you still get wrong indentation in situation that you think the
2297 code should be able to parse, try:
2299 a) Check what Emacs thinks about balance of your parentheses.
2300 b) Supply the code to me (IZ).
2302 Pods were treated _very_ rudimentally. Here-documents were not
2303 treated at all (except highlighting and inhibiting indentation). Upgrade.
2305 To speed up coloring the following compromises exist:
2306 a) sub in $mypackage::sub may be highlighted.
2307 b) -z in [a-z] may be highlighted.
2308 c) if your regexp contains a keyword (like \"s\"), it may be highlighted.
2311 Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove
2312 `car' before `imenu-choose-buffer-index' in `imenu'.
2313 `imenu-add-to-menubar' in 20.2 is broken.
2314 A lot of things on XEmacs may be broken too, judging by bug reports I
2315 receive. Note that some releases of XEmacs are better than the others
2316 as far as bugs reports I see are concerned.")
2318 (defvar cperl-praise 'please-ignore-this-line
2319 "Advantages of CPerl mode.
2321 0) It uses the newest `syntax-table' property ;-);
2323 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
2324 mode - but the latter number may have improved too in last years) even
2325 with old Emaxen which do not support `syntax-table' property.
2327 When using `syntax-table' property for syntax assist hints, it should
2328 handle 99.995% of lines correct - or somesuch. It automatically
2329 updates syntax assist hints when you edit your script.
2331 2) It is generally believed to be \"the most user-friendly Emacs
2332 package\" whatever it may mean (I doubt that the people who say similar
2333 things tried _all_ the rest of Emacs ;-), but this was not a lonely
2336 3) Everything is customizable, one-by-one or in a big sweep;
2338 4) It has many easily-accessable \"tools\":
2339 a) Can run program, check syntax, start debugger;
2340 b) Can lineup vertically \"middles\" of rows, like `=' in
2343 c) Can insert spaces where this impoves readability (in one
2344 interactive sweep over the buffer);
2345 d) Has support for imenu, including:
2346 1) Separate unordered list of \"interesting places\";
2347 2) Separate TOC of POD sections;
2348 3) Separate list of packages;
2349 4) Hierarchical view of methods in (sub)packages;
2350 5) and functions (by the full name - with package);
2351 e) Has an interface to INFO docs for Perl; The interface is
2352 very flexible, including shrink-wrapping of
2353 documentation buffer/frame;
2354 f) Has a builtin list of one-line explanations for perl constructs.
2355 g) Can show these explanations if you stay long enough at the
2356 corresponding place (or on demand);
2357 h) Has an enhanced fontification (using 3 or 4 additional faces
2358 comparing to font-lock - basically, different
2359 namespaces in Perl have different colors);
2360 i) Can construct TAGS basing on its knowledge of Perl syntax,
2361 the standard menu has 6 different way to generate
2362 TAGS (if \"by directory\", .xs files - with C-language
2363 bindings - are included in the scan);
2364 j) Can build a hierarchical view of classes (via imenu) basing
2365 on generated TAGS file;
2366 k) Has electric parentheses, electric newlines, uses Abbrev
2367 for electric logical constructs
2369 with different styles of expansion (context sensitive
2370 to be not so bothering). Electric parentheses behave
2371 \"as they should\" in a presence of a visible region.
2372 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
2378 n) Highlights (by user-choice) either 3-delimiters constructs
2379 (such as tr/a/b/), or regular expressions and `y/tr';
2380 o) Highlights trailing whitespace;
2381 p) Is able to manipulate Perl Regular Expressions to ease
2382 conversion to a more readable form.
2383 q) Can ispell POD sections and HERE-DOCs.
2384 r) Understands comments and character classes inside regular
2385 expressions; can find matching () and [] in a regular expression.
2386 s) Allows indentation of //x-style regular expressions;
2387 t) Highlights different symbols in regular expressions according
2388 to their function; much less problems with backslashitis;
2389 u) Allows to find regular expressions which contain interpolated parts.
2391 5) The indentation engine was very smart, but most of tricks may be
2392 not needed anymore with the support for `syntax-table' property. Has
2393 progress indicator for indentation (with `imenu' loaded).
2395 6) Indent-region improves inline-comments as well; also corrects
2396 whitespace *inside* the conditional/loop constructs.
2398 7) Fill-paragraph correctly handles multi-line comments;
2400 8) Can switch to different indentation styles by one command, and restore
2401 the settings present before the switch.
2403 9) When doing indentation of control constructs, may correct
2404 line-breaks/spacing between elements of the construct.
2406 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
2407 capable syntax engines).
2409 11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
2412 (defvar cperl-speed 'please-ignore-this-line
2413 "This is an incomplete compendium of what is available in other parts
2414 of CPerl documentation. (Please inform me if I skept anything.)
2416 There is a perception that CPerl is slower than alternatives. This part
2417 of documentation is designed to overcome this misconception.
2419 *By default* CPerl tries to enable the most comfortable settings.
2420 From most points of view, correctly working package is infinitely more
2421 comfortable than a non-correctly working one, thus by default CPerl
2422 prefers correctness over speed. Below is the guide how to change
2423 settings if your preferences are different.
2425 A) Speed of loading the file. When loading file, CPerl may perform a
2426 scan which indicates places which cannot be parsed by primitive Emacs
2427 syntax-parsing routines, and marks them up so that either
2429 A1) CPerl may work around these deficiencies (for big chunks, mostly
2430 PODs and HERE-documents), or
2431 A2) On capable Emaxen CPerl will use improved syntax-handlings
2432 which reads mark-up hints directly.
2434 The scan in case A2 is much more comprehensive, thus may be slower.
2436 User can disable syntax-engine-helping scan of A2 by setting
2437 `cperl-use-syntax-table-text-property'
2438 variable to nil (if it is set to t).
2440 One can disable the scan altogether (both A1 and A2) by setting
2441 `cperl-pod-here-scan'
2444 B) Speed of editing operations.
2446 One can add a (minor) speedup to editing operations by setting
2447 `cperl-use-syntax-table-text-property'
2448 variable to nil (if it is set to t). This will disable
2449 syntax-engine-helping scan, thus will make many more Perl
2450 constructs be wrongly recognized by CPerl, thus may lead to
2451 wrongly matched parentheses, wrong indentation, etc.
2453 One can unset `cperl-syntaxify-unwind'. This might speed up editing
2454 of, say, long POD sections.")
2456 (defvar cperl-tips-faces 'please-ignore-this-line
2457 "CPerl mode uses following faces for highlighting:
2459 `cperl-array-face' Array names
2460 `cperl-hash-face' Hash names
2461 `font-lock-comment-face' Comments, PODs and whatever is considered
2462 syntaxically to be not code
2463 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
2464 2-arg operators s/y/tr/ or of RExen,
2465 `font-lock-warning-face' Special-cased m// and s//foo/,
2466 `font-lock-function-name-face' _ as a target of a file tests, file tests,
2467 subroutine names at the moment of definition
2468 (except those conflicting with Perl operators),
2469 package names (when recognized), format names
2470 `font-lock-keyword-face' Control flow switch constructs, declarators
2471 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
2472 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
2473 literal parts and the terminator of formats
2474 and whatever is syntaxically considered
2476 `font-lock-type-face' Overridable keywords
2477 `font-lock-variable-name-face' Variable declarations, indirect array and
2478 hash names, POD headers/item names
2479 `cperl-invalid-face' Trailing whitespace
2481 Note that in several situations the highlighting tries to inform about
2482 possible confusion, such as different colors for function names in
2483 declarations depending on what they (do not) override, or special cases
2484 m// and s/// which do not do what one would expect them to do.
2486 Help with best setup of these faces for printout requested (for each of
2487 the faces: please specify bold, italic, underline, shadow and box.)
2489 In regular expressions (except character classes):
2490 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs
2491 `font-lock-constant-face': Delimiters
2492 `font-lock-warning-face' Special-cased m// and s//foo/,
2493 Mismatched closing delimiters, parens
2494 we couldn't match, misplaced quantifiers,
2495 unrecognized escape sequences
2496 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
2497 `font-lock-type-face' POSIX classes inside charclasses,
2498 escape sequences with arguments (\x \23 \p \N)
2499 and others match-a-char escape sequences
2500 `font-lock-keyword-face' Capturing parens, and |
2501 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
2502 `font-lock-builtin-face' \"Remaining\" 0-length constructs, executable
2503 parts of a REx, not-capturing parens
2504 `font-lock-variable-name-face' Interpolated constructs, embedded code
2505 `font-lock-comment-face' Embedded comments
2511 ;;; Portability stuff:
2513 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
2514 (` (define-key cperl-mode-map
2516 (` (if cperl-xemacs-p (, xemacs-key) (, emacs-key)))
2520 (defvar cperl-del-back-ch
2521 (car (append (where-is-internal 'delete-backward-char)
2522 (where-is-internal 'backward-delete-char-untabify)))
2523 "Character generated by key bound to `delete-backward-char'.")
2525 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
2526 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
2528 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
2531 ;; "Active regions" are on: use region only if active
2532 ;; "Active regions" are off: use region unconditionally
2533 (defun cperl-use-region-p ()
2534 (if zmacs-regions (mark) t)))
2535 (defun cperl-use-region-p ()
2536 (if transient-mark-mode mark-active t))
2537 (defun cperl-mark-active () mark-active))
2539 (defsubst cperl-enable-font-lock ()
2540 cperl-can-font-lock)
2542 (defun cperl-putback-char (c) ; Emacs 19
2543 (set 'unread-command-events (list c))) ; Avoid undefined warning
2545 (if (boundp 'unread-command-events)
2547 (defun cperl-putback-char (c) ; XEmacs >= 19.12
2548 (setq unread-command-events (list (eval '(character-to-event c))))))
2549 (defun cperl-putback-char (c) ; XEmacs <= 19.11
2550 (set 'unread-command-event (eval '(character-to-event c))))) ; Avoid warnings
2552 (or (fboundp 'uncomment-region)
2553 (defun uncomment-region (beg end)
2555 (comment-region beg end -1)))
2557 (defvar cperl-do-not-fontify
2558 (if (string< emacs-version "19.30")
2561 "Text property which inhibits refontification.")
2563 (defsubst cperl-put-do-not-fontify (from to &optional post)
2564 ;; If POST, do not do it with postponed fontification
2565 (if (and post cperl-syntaxify-by-font-lock)
2567 (put-text-property (max (point-min) (1- from))
2568 to cperl-do-not-fontify t)))
2570 (defcustom cperl-mode-hook nil
2571 "Hook run by CPerl mode."
2575 (defvar cperl-syntax-state nil)
2576 (defvar cperl-syntax-done-to nil)
2577 (defvar cperl-emacs-can-parse (> (length (save-excursion
2578 (parse-partial-sexp (point) (point)))) 9))
2580 ;; Make customization possible "in reverse"
2581 (defsubst cperl-val (symbol &optional default hairy)
2583 ((eq (symbol-value symbol) 'null) default)
2584 (cperl-hairy (or hairy t))
2585 (t (symbol-value symbol))))
2588 (defun cperl-make-indent (column &optional minimum keep)
2589 "Makes indent of the current line the requested amount.
2590 Unless KEEP, removes the old indentation. Works around a bug in ancient
2592 (let ((prop (get-text-property (point) 'syntax-type)))
2594 (delete-horizontal-space))
2595 (indent-to column minimum)
2596 ;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
2598 (> (current-column) 0)
2601 (or (get-text-property (point) 'syntax-type)
2602 (and (looking-at "\\=[ \t]")
2603 (put-text-property (point) (match-end 0)
2604 'syntax-type prop)))))))
2606 ;;; Probably it is too late to set these guys already, but it can help later:
2608 (and cperl-clobber-mode-lists
2609 (setq auto-mode-alist
2610 (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
2611 (and (boundp 'interpreter-mode-alist)
2612 (setq interpreter-mode-alist (append interpreter-mode-alist
2613 '(("miniperl" . perl-mode))))))
2614 (if (fboundp 'eval-when-compile)
2620 '(imenu easymenu etags timer man info))
2621 (if (fboundp 'ps-extend-face-list)
2622 (defmacro cperl-ps-extend-face-list (arg)
2623 (` (ps-extend-face-list (, arg))))
2624 (defmacro cperl-ps-extend-face-list (arg)
2625 (` (error "This version of Emacs has no `ps-extend-face-list'"))))
2626 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
2627 ;; macros instead of defsubsts don't work on Emacs, so we do the
2628 ;; expansion manually. Any other suggestions?
2629 (if cperl-can-font-lock
2630 (require 'font-lock))
2633 (defvar cperl-mode-abbrev-table nil
2634 "Abbrev table in use in CPerl mode buffers.")
2636 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
2638 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
2640 (if cperl-mode-map nil
2641 (setq cperl-mode-map (make-sparse-keymap))
2642 (cperl-define-key "{" 'cperl-electric-lbrace)
2643 (cperl-define-key "[" 'cperl-electric-paren)
2644 (cperl-define-key "(" 'cperl-electric-paren)
2645 (cperl-define-key "<" 'cperl-electric-paren)
2646 (cperl-define-key "}" 'cperl-electric-brace)
2647 (cperl-define-key "]" 'cperl-electric-rparen)
2648 (cperl-define-key ")" 'cperl-electric-rparen)
2649 (cperl-define-key ";" 'cperl-electric-semi)
2650 (cperl-define-key ":" 'cperl-electric-terminator)
2651 (cperl-define-key "\C-j" 'newline-and-indent)
2652 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
2653 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
2654 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
2655 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
2656 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
2657 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
2658 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
2659 (cperl-define-key "\C-c\C-b" 'cperl-find-bad-style)
2660 (cperl-define-key "\C-c\C-p" 'cperl-pod-spell)
2661 (cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell)
2662 (cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc)
2663 (cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx)
2664 (cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0)
2665 (cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1)
2666 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
2667 (cperl-define-key "\C-c\C-hp" 'cperl-perldoc)
2668 (cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point)
2669 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
2670 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
2672 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
2673 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
2674 (cperl-define-key "\177" 'cperl-electric-backspace)
2675 (cperl-define-key "\t" 'cperl-indent-command)
2676 ;; don't clobber the backspace binding:
2677 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
2678 [(control c) (control h) F])
2679 (if (cperl-val 'cperl-clobber-lisp-bindings)
2681 (cperl-define-key "\C-hf"
2682 ;;(concat (char-to-string help-char) "f") ; does not work
2683 'cperl-info-on-command
2685 (cperl-define-key "\C-hv"
2686 ;;(concat (char-to-string help-char) "v") ; does not work
2689 (cperl-define-key "\C-c\C-hf"
2690 ;;(concat (char-to-string help-char) "f") ; does not work
2691 (key-binding "\C-hf")
2692 [(control c) (control h) f])
2693 (cperl-define-key "\C-c\C-hv"
2694 ;;(concat (char-to-string help-char) "v") ; does not work
2695 (key-binding "\C-hv")
2696 [(control c) (control h) v]))
2697 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
2698 [(control c) (control h) f])
2699 (cperl-define-key "\C-c\C-hv"
2700 ;;(concat (char-to-string help-char) "v") ; does not work
2702 [(control c) (control h) v]))
2703 (if (and cperl-xemacs-p
2704 (<= emacs-minor-version 11) (<= emacs-major-version 19))
2706 ;; substitute-key-definition is usefulness-deenhanced...
2707 ;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
2708 (cperl-define-key "\e;" 'cperl-indent-for-comment)
2709 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
2710 (or (boundp 'fill-paragraph-function)
2711 (substitute-key-definition
2712 'fill-paragraph 'cperl-fill-paragraph
2713 cperl-mode-map global-map))
2714 (substitute-key-definition
2715 'indent-sexp 'cperl-indent-exp
2716 cperl-mode-map global-map)
2717 (substitute-key-definition
2718 'indent-region 'cperl-indent-region
2719 cperl-mode-map global-map)
2720 (substitute-key-definition
2721 'indent-for-comment 'cperl-indent-for-comment
2722 cperl-mode-map global-map)))
2725 (defvar cperl-lazy-installed)
2726 (defvar cperl-old-style nil)
2731 cperl-menu cperl-mode-map "Menu for CPerl mode"
2733 ["Beginning of function" beginning-of-defun t]
2734 ["End of function" end-of-defun t]
2735 ["Mark function" mark-defun t]
2736 ["Indent expression" cperl-indent-exp t]
2737 ["Fill paragraph/comment" cperl-fill-paragraph t]
2739 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
2740 ["Invert if/unless/while etc" cperl-invert-if-unless t]
2742 ["Beautify" cperl-beautify-regexp
2743 cperl-use-syntax-table-text-property]
2744 ["Beautify one level deep" (cperl-beautify-regexp 1)
2745 cperl-use-syntax-table-text-property]
2746 ["Beautify a group" cperl-beautify-level
2747 cperl-use-syntax-table-text-property]
2748 ["Beautify a group one level deep" (cperl-beautify-level 1)
2749 cperl-use-syntax-table-text-property]
2750 ["Contract a group" cperl-contract-level
2751 cperl-use-syntax-table-text-property]
2752 ["Contract groups" cperl-contract-levels
2753 cperl-use-syntax-table-text-property]
2755 ["Find next interpolated" cperl-next-interpolated-REx
2756 (next-single-property-change (point-min) 'REx-interpolated)]
2757 ["Find next interpolated (no //o)"
2758 cperl-next-interpolated-REx-0
2759 (or (text-property-any (point-min) (point-max) 'REx-interpolated t)
2760 (text-property-any (point-min) (point-max) 'REx-interpolated 1))]
2761 ["Find next interpolated (neither //o nor whole-REx)"
2762 cperl-next-interpolated-REx-1
2763 (text-property-any (point-min) (point-max) 'REx-interpolated t)])
2764 ["Insert spaces if needed to fix style" cperl-find-bad-style t]
2765 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
2767 ["Indent region" cperl-indent-region (cperl-use-region-p)]
2768 ["Comment region" cperl-comment-region (cperl-use-region-p)]
2769 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
2771 ["Run" mode-compile (fboundp 'mode-compile)]
2772 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
2773 (get-buffer "*compilation*"))]
2774 ["Next error" next-error (get-buffer "*compilation*")]
2775 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
2777 ["Debugger" cperl-db t]
2780 ["Imenu" imenu (fboundp 'imenu)]
2781 ["Imenu on Perl Info" cperl-imenu-on-info (featurep 'imenu)]
2783 ["Ispell PODs" cperl-pod-spell
2784 ;; Better not to update syntaxification here:
2785 ;; debugging syntaxificatio can be broken by this???
2787 (get-text-property (point-min) 'in-pod)
2789 (and cperl-syntaxify-for-menu
2790 (cperl-update-syntaxification (point-max) (point-max)))
2791 (next-single-property-change (point-min) 'in-pod nil (point-max)))
2793 ["Ispell HERE-DOCs" cperl-here-doc-spell
2795 (and cperl-syntaxify-for-menu
2796 (cperl-update-syntaxification (point-max) (point-max)))
2797 (next-single-property-change (point-min) 'here-doc-group nil (point-max)))
2799 ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
2800 (eq 'here-doc (progn
2801 (and cperl-syntaxify-for-menu
2802 (cperl-update-syntaxification (point) (point)))
2803 (get-text-property (point) 'syntax-type)))]
2804 ["Select this HERE-DOC or POD section"
2805 cperl-select-this-pod-or-here-doc
2807 (and cperl-syntaxify-for-menu
2808 (cperl-update-syntaxification (point) (point)))
2809 (get-text-property (point) 'syntax-type))
2812 ["CPerl pretty print (exprmntl)" cperl-ps-print
2813 (fboundp 'ps-extend-face-list)]
2815 ["Syntaxify region" cperl-find-pods-heres-region
2816 (cperl-use-region-p)]
2817 ["Profile syntaxification" cperl-time-fontification t]
2818 ["Debug errors in delayed fontification" cperl-emulate-lazy-lock t]
2819 ["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t]
2820 ["Debug backtrace on syntactic scan (BEWARE!!!)"
2821 (cperl-toggle-set-debug-unwind nil t) t]
2823 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
2824 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
2826 ;;; ["Create tags for current file" cperl-etags t]
2827 ;;; ["Add tags for current file" (cperl-etags t) t]
2828 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
2829 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
2830 ;;; ["Create tags for Perl files in (sub)directories"
2831 ;;; (cperl-etags nil 'recursive) t]
2832 ;;; ["Add tags for Perl files in (sub)directories"
2833 ;;; (cperl-etags t 'recursive) t])
2834 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
2835 ["Create tags for current file" (cperl-write-tags nil t) t]
2836 ["Add tags for current file" (cperl-write-tags) t]
2837 ["Create tags for Perl files in directory"
2838 (cperl-write-tags nil t nil t) t]
2839 ["Add tags for Perl files in directory"
2840 (cperl-write-tags nil nil nil t) t]
2841 ["Create tags for Perl files in (sub)directories"
2842 (cperl-write-tags nil t t t) t]
2843 ["Add tags for Perl files in (sub)directories"
2844 (cperl-write-tags nil nil t t) t]))
2846 ["Define word at point" imenu-go-find-at-position
2847 (fboundp 'imenu-go-find-at-position)]
2848 ["Help on function" cperl-info-on-command t]
2849 ["Help on function at point" cperl-info-on-current-command t]
2850 ["Help on symbol at point" cperl-get-help t]
2851 ["Perldoc" cperl-perldoc t]
2852 ["Perldoc on word at point" cperl-perldoc-at-point t]
2853 ["View manpage of POD in this file" cperl-build-manpage t]
2854 ["Auto-help on" cperl-lazy-install
2855 (and (fboundp 'run-with-idle-timer)
2856 (not cperl-lazy-installed))]
2857 ["Auto-help off" cperl-lazy-unstall
2858 (and (fboundp 'run-with-idle-timer)
2859 cperl-lazy-installed)])
2861 ["Auto newline" cperl-toggle-auto-newline t]
2862 ["Electric parens" cperl-toggle-electric t]
2863 ["Electric keywords" cperl-toggle-abbrev t]
2864 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
2865 ["Auto-help on Perl constructs" cperl-toggle-autohelp t]
2866 ["Auto fill" auto-fill-mode t])
2868 ["CPerl" (cperl-set-style "CPerl") t]
2869 ["PerlStyle" (cperl-set-style "PerlStyle") t]
2870 ["GNU" (cperl-set-style "GNU") t]
2871 ["C++" (cperl-set-style "C++") t]
2872 ["K&R" (cperl-set-style "K&R") t]
2873 ["BSD" (cperl-set-style "BSD") t]
2874 ["Whitesmith" (cperl-set-style "Whitesmith") t]
2875 ["Memorize Current" (cperl-set-style "Current") t]
2876 ["Memorized" (cperl-set-style-back) cperl-old-style])
2878 ["Tips" (describe-variable 'cperl-tips) t]
2879 ["Problems" (describe-variable 'cperl-problems) t]
2880 ["Non-problems" (describe-variable 'cperl-non-problems) t]
2881 ["Speed" (describe-variable 'cperl-speed) t]
2882 ["Praise" (describe-variable 'cperl-praise) t]
2883 ["Faces" (describe-variable 'cperl-tips-faces) t]
2884 ["CPerl mode" (describe-function 'cperl-mode) t]
2886 (message "The version of master-file for this CPerl is %s"
2887 cperl-version) t]))))
2890 (autoload 'c-macro-expand "cmacexp"
2891 "Display the result of expanding all C macros occurring in the region.
2892 The expansion is entirely correct because it uses the C preprocessor."
2895 ;;; These two must be unwound, otherwise take exponential time
2896 (defconst cperl-maybe-white-and-comment-rex "[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
2897 "Regular expression to match optional whitespace with interpspersed comments.
2898 Should contain exactly one group.")
2900 ;;; This one is tricky to unwind; still very inefficient...
2901 (defconst cperl-white-and-comment-rex "\\([ \t\n]\\|#[^\n]*\n\\)+"
2902 "Regular expression to match whitespace with interpspersed comments.
2903 Should contain exactly one group.")
2906 ;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
2907 ;;; `cperl-outline-regexp', `defun-prompt-regexp'.
2908 ;;; Details of groups in this may be used in several functions; see comments
2909 ;;; near mentioned above variable(s)...
2910 ;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
2911 (defsubst cperl-after-sub-regexp (named attr) ; 9 groups without attr...
2912 "Match the text after `sub' in a subroutine declaration.
2913 If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
2914 of attributes (if present), or end of the name or prototype (whatever is
2916 (concat ; Assume n groups before this...
2917 "\\(" ; n+1=name-group
2918 cperl-white-and-comment-rex ; n+2=pre-name
2919 "\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
2920 "\\)" ; END n+1=name-group
2922 "\\(" ; n+4=proto-group
2923 cperl-maybe-white-and-comment-rex ; n+5=pre-proto
2924 "\\(([^()]*)\\)" ; n+6=prototype
2925 "\\)?" ; END n+4=proto-group
2926 "\\(" ; n+7=attr-group
2927 cperl-maybe-white-and-comment-rex ; n+8=pre-attr
2928 "\\(" ; n+9=start-attr
2932 cperl-maybe-white-and-comment-rex ; whitespace-comments
2933 "\\(\\sw\\|_\\)+" ; attr-name
2934 ;; attr-arg (1 level of internal parens allowed!)
2935 "\\((\\(\\\\.\\|[^\\\\()]\\|([^\\\\()]*)\\)*)\\)?"
2936 "\\(" ; optional : (XXX allows trailing???)
2937 cperl-maybe-white-and-comment-rex ; whitespace-comments
2942 "\\)?" ; END n+6=proto-group
2945 ;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
2946 ;;; and `cperl-outline-level'.
2947 ;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 8=sub-name (+3)
2948 (defvar cperl-imenu--function-name-regexp-perl
2951 "\\([ \t]*package" ; 2 = package-group
2952 "\\(" ; 3 = package-name-group
2953 cperl-white-and-comment-rex ; 4 = pre-package-name
2954 "\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
2957 (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
2958 cperl-maybe-white-and-comment-rex ; 15=pre-block
2960 "=head\\([1-4]\\)[ \t]+" ; 16=level
2961 "\\([^\n]+\\)$" ; 17=text
2964 (defvar cperl-outline-regexp
2965 (concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
2967 (defvar cperl-mode-syntax-table nil
2968 "Syntax table in use in CPerl mode buffers.")
2970 (defvar cperl-string-syntax-table nil
2971 "Syntax table in use in CPerl mode string-like chunks.")
2973 (defsubst cperl-1- (p)
2974 (max (point-min) (1- p)))
2976 (defsubst cperl-1+ (p)
2977 (min (point-max) (1+ p)))
2979 (if cperl-mode-syntax-table
2981 (setq cperl-mode-syntax-table (make-syntax-table))
2982 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
2983 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
2984 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
2985 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
2986 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
2987 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
2988 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
2989 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
2990 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
2991 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
2992 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
2993 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
2994 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
2995 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
2996 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
2997 (if cperl-under-as-char
2998 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
2999 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
3000 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
3001 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
3002 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
3003 (modify-syntax-entry ?\{ "." cperl-string-syntax-table)
3004 (modify-syntax-entry ?\} "." cperl-string-syntax-table)
3005 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment )
3009 ;; provide an alias for working with emacs 19. the perl-mode that comes
3010 ;; with it is really bad, and this lets us seamlessly replace it.
3012 (fset 'perl-mode 'cperl-mode)
3013 (defvar cperl-faces-init nil)
3015 (defvar cperl-msb-fixed nil)
3016 (defvar font-lock-syntactic-keywords)
3017 (defvar perl-font-lock-keywords)
3018 (defvar perl-font-lock-keywords-1)
3019 (defvar perl-font-lock-keywords-2)
3020 (defvar outline-level)
3021 (if (fboundp 'defvaralias)
3022 (let ((f 'defvaralias)) ; Some functions deduce stuff from the mode name...
3023 (funcall f 'cperl-font-lock-keywords 'perl-font-lock-keywords)
3024 (funcall f 'cperl-font-lock-keywords-1 'perl-font-lock-keywords-1)
3025 (funcall f 'cperl-font-lock-keywords-2 'perl-font-lock-keywords-2)))
3027 (defvar cperl-use-major-mode 'perl-mode)
3028 (defvar cperl-font-lock-multiline-start nil)
3029 (defvar cperl-font-lock-multiline nil)
3030 (defvar cperl-compilation-error-regexp-alist nil)
3031 (defvar cperl-font-locking nil)
3034 (defun cperl-mode ()
3035 "Major mode for editing Perl code.
3036 Expression and list commands understand all C brackets.
3037 Tab indents for Perl code.
3038 Paragraphs are separated by blank lines only.
3039 Delete converts tabs to spaces as it moves back.
3041 Various characters in Perl almost always come in pairs: {}, (), [],
3042 sometimes <>. When the user types the first, she gets the second as
3043 well, with optional special formatting done on {}. (Disabled by
3044 default.) You can always quote (with \\[quoted-insert]) the left
3045 \"paren\" to avoid the expansion. The processing of < is special,
3046 since most the time you mean \"less\". CPerl mode tries to guess
3047 whether you want to type pair <>, and inserts is if it
3048 appropriate. You can set `cperl-electric-parens-string' to the string that
3049 contains the parenths from the above list you want to be electrical.
3050 Electricity of parenths is controlled by `cperl-electric-parens'.
3051 You may also set `cperl-electric-parens-mark' to have electric parens
3052 look for active mark and \"embrace\" a region if possible.'
3054 CPerl mode provides expansion of the Perl control constructs:
3056 if, else, elsif, unless, while, until, continue, do,
3057 for, foreach, formy and foreachmy.
3059 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
3061 The user types the keyword immediately followed by a space, which
3062 causes the construct to be expanded, and the point is positioned where
3063 she is most likely to want to be. eg. when the user types a space
3064 following \"if\" the following appears in the buffer: if () { or if ()
3065 } { } and the cursor is between the parentheses. The user can then
3066 type some boolean expression within the parens. Having done that,
3067 typing \\[cperl-linefeed] places you - appropriately indented - on a
3068 new line between the braces (if you typed \\[cperl-linefeed] in a POD
3069 directive line, then appropriate number of new lines is inserted).
3071 If CPerl decides that you want to insert \"English\" style construct like
3075 it will not do any expansion. See also help on variable
3076 `cperl-extra-newline-before-brace'. (Note that one can switch the
3077 help message on expansion by setting `cperl-message-electric-keyword'
3080 \\[cperl-linefeed] is a convenience replacement for typing carriage
3081 return. It places you in the next line with proper indentation, or if
3082 you type it inside the inline block of control construct, like
3084 foreach (@lines) {print; print}
3086 and you are on a boundary of a statement inside braces, it will
3087 transform the construct into a multiline and will place you into an
3088 appropriately indented blank line. If you need a usual
3089 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
3090 see documentation on `cperl-electric-linefeed'.
3092 Use \\[cperl-invert-if-unless] to change a construction of the form
3102 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
3103 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
3104 on electric space between $ and {, `cperl-electric-parens-string' is
3105 the string that contains parentheses that should be electric in CPerl
3106 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
3107 setting `cperl-electric-keywords' enables electric expansion of
3108 control structures in CPerl. `cperl-electric-linefeed' governs which
3109 one of two linefeed behavior is preferable. You can enable all these
3110 options simultaneously (recommended mode of use) by setting
3111 `cperl-hairy' to t. In this case you can switch separate options off
3112 by setting them to `null'. Note that one may undo the extra
3113 whitespace inserted by semis and braces in `auto-newline'-mode by
3114 consequent \\[cperl-electric-backspace].
3116 If your site has perl5 documentation in info format, you can use commands
3117 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
3118 These keys run commands `cperl-info-on-current-command' and
3119 `cperl-info-on-command', which one is which is controlled by variable
3120 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
3121 \(in turn affected by `cperl-hairy').
3123 Even if you have no info-format documentation, short one-liner-style
3124 help is available on \\[cperl-get-help], and one can run perldoc or
3127 It is possible to show this help automatically after some idle time.
3128 This is regulated by variable `cperl-lazy-help-time'. Default with
3129 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
3130 secs idle time . It is also possible to switch this on/off from the
3131 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
3133 Use \\[cperl-lineup] to vertically lineup some construction - put the
3134 beginning of the region at the start of construction, and make region
3135 span the needed amount of lines.
3137 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
3138 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
3139 here-docs sections. With capable Emaxen results of scan are used
3140 for indentation too, otherwise they are used for highlighting only.
3142 Variables controlling indentation style:
3143 `cperl-tab-always-indent'
3144 Non-nil means TAB in CPerl mode should always reindent the current line,
3145 regardless of where in the line point is when the TAB command is used.
3146 `cperl-indent-left-aligned-comments'
3147 Non-nil means that the comment starting in leftmost column should indent.
3148 `cperl-auto-newline'
3149 Non-nil means automatically newline before and after braces,
3150 and after colons and semicolons, inserted in Perl code. The following
3151 \\[cperl-electric-backspace] will remove the inserted whitespace.
3152 Insertion after colons requires both this variable and
3153 `cperl-auto-newline-after-colon' set.
3154 `cperl-auto-newline-after-colon'
3155 Non-nil means automatically newline even after colons.
3156 Subject to `cperl-auto-newline' setting.
3157 `cperl-indent-level'
3158 Indentation of Perl statements within surrounding block.
3159 The surrounding block's indentation is the indentation
3160 of the line on which the open-brace appears.
3161 `cperl-continued-statement-offset'
3162 Extra indentation given to a substatement, such as the
3163 then-clause of an if, or body of a while, or just a statement continuation.
3164 `cperl-continued-brace-offset'
3165 Extra indentation given to a brace that starts a substatement.
3166 This is in addition to `cperl-continued-statement-offset'.
3167 `cperl-brace-offset'
3168 Extra indentation for line if it starts with an open brace.
3169 `cperl-brace-imaginary-offset'
3170 An open brace following other text is treated as if it the line started
3171 this far to the right of the actual line indentation.
3172 `cperl-label-offset'
3173 Extra indentation for line that is a label.
3174 `cperl-min-label-indent'
3175 Minimal indentation for line that is a label.
3177 Settings for classic indent-styles: K&R BSD=C++ GNU PerlStyle=Whitesmith
3178 `cperl-indent-level' 5 4 2 4
3179 `cperl-brace-offset' 0 0 0 0
3180 `cperl-continued-brace-offset' -5 -4 0 0
3181 `cperl-label-offset' -5 -4 -2 -4
3182 `cperl-continued-statement-offset' 5 4 2 4
3184 CPerl knows several indentation styles, and may bulk set the
3185 corresponding variables. Use \\[cperl-set-style] to do this. Use
3186 \\[cperl-set-style-back] to restore the memorized preexisting values
3187 \(both available from menu). See examples in `cperl-style-examples'.
3189 Part of the indentation style is how different parts of if/elsif/else
3190 statements are broken into lines; in CPerl, this is reflected on how
3191 templates for these constructs are created (controlled by
3192 `cperl-extra-newline-before-brace'), and how reflow-logic should treat \"continuation\" blocks of else/elsif/continue, controlled by the same variable,
3193 and by `cperl-extra-newline-before-brace-multiline',
3194 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'.
3196 If `cperl-indent-level' is 0, the statement after opening brace in
3197 column 0 is indented on
3198 `cperl-brace-offset'+`cperl-continued-statement-offset'.
3200 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
3203 DO NOT FORGET to read micro-docs (available from `Perl' menu)
3204 or as help on variables `cperl-tips', `cperl-problems',
3205 `cperl-non-problems', `cperl-praise', `cperl-speed'."
3207 (kill-all-local-variables)
3208 (use-local-map cperl-mode-map)
3209 (if (cperl-val 'cperl-electric-linefeed)
3211 (local-set-key "\C-J" 'cperl-linefeed)
3212 (local-set-key "\C-C\C-J" 'newline-and-indent)))
3214 (cperl-val 'cperl-clobber-lisp-bindings)
3215 (cperl-val 'cperl-info-on-command-no-prompt))
3217 ;; don't clobber the backspace binding:
3218 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
3219 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
3220 [(control c) (control h) f])))
3221 (setq major-mode cperl-use-major-mode)
3222 (setq mode-name "CPerl")
3223 (if (not cperl-mode-abbrev-table)
3224 (let ((prev-a-c abbrevs-changed))
3225 (define-abbrev-table 'cperl-mode-abbrev-table '(
3226 ("if" "if" cperl-electric-keyword 0)
3227 ("elsif" "elsif" cperl-electric-keyword 0)
3228 ("while" "while" cperl-electric-keyword 0)
3229 ("until" "until" cperl-electric-keyword 0)
3230 ("unless" "unless" cperl-electric-keyword 0)
3231 ("else" "else" cperl-electric-else 0)
3232 ("continue" "continue" cperl-electric-else 0)
3233 ("for" "for" cperl-electric-keyword 0)
3234 ("foreach" "foreach" cperl-electric-keyword 0)
3235 ("formy" "formy" cperl-electric-keyword 0)
3236 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
3237 ("do" "do" cperl-electric-keyword 0)
3238 ("=pod" "=pod" cperl-electric-pod 0)
3239 ("=over" "=over" cperl-electric-pod 0)
3240 ("=head1" "=head1" cperl-electric-pod 0)
3241 ("=head2" "=head2" cperl-electric-pod 0)
3242 ("pod" "pod" cperl-electric-pod 0)
3243 ("over" "over" cperl-electric-pod 0)
3244 ("head1" "head1" cperl-electric-pod 0)
3245 ("head2" "head2" cperl-electric-pod 0)))
3246 (setq abbrevs-changed prev-a-c)))
3247 (setq local-abbrev-table cperl-mode-abbrev-table)
3248 (if (cperl-val 'cperl-electric-keywords)
3250 (set-syntax-table cperl-mode-syntax-table)
3251 ;; Until Emacs is multi-threaded, we do not actually need it local:
3252 (make-local-variable 'cperl-font-lock-multiline-start)
3253 (make-local-variable 'cperl-font-locking)
3254 (make-local-variable 'outline-regexp)
3255 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
3256 (setq outline-regexp cperl-outline-regexp)
3257 (make-local-variable 'outline-level)
3258 (setq outline-level 'cperl-outline-level)
3259 (make-local-variable 'paragraph-start)
3260 (setq paragraph-start (concat "^$\\|" page-delimiter))
3261 (make-local-variable 'paragraph-separate)
3262 (setq paragraph-separate paragraph-start)
3263 (make-local-variable 'paragraph-ignore-fill-prefix)
3264 (setq paragraph-ignore-fill-prefix t)
3267 (make-local-variable 'paren-backwards-message)
3268 (set 'paren-backwards-message t)))
3269 (make-local-variable 'indent-line-function)
3270 (setq indent-line-function 'cperl-indent-line)
3271 (make-local-variable 'require-final-newline)
3272 (setq require-final-newline t)
3273 (make-local-variable 'comment-start)
3274 (setq comment-start "# ")
3275 (make-local-variable 'comment-end)
3276 (setq comment-end "")
3277 (make-local-variable 'comment-column)
3278 (setq comment-column cperl-comment-column)
3279 (make-local-variable 'comment-start-skip)
3280 (setq comment-start-skip "#+ *")
3281 (make-local-variable 'defun-prompt-regexp)
3283 ;;; (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
3284 ;;; cperl-maybe-white-and-comment-rex ; 15=pre-block
3285 (setq defun-prompt-regexp
3286 (concat "[ \t]*\\(sub"
3287 (cperl-after-sub-regexp 'named 'attr-groups)
3289 "\\(BEGIN\\|CHECK\\|INIT\\|END\\|AUTOLOAD\\|DESTROY\\)"
3291 cperl-maybe-white-and-comment-rex))
3292 (make-local-variable 'comment-indent-function)
3293 (setq comment-indent-function 'cperl-comment-indent)
3294 (and (boundp 'fill-paragraph-function)
3296 (make-local-variable 'fill-paragraph-function)
3297 (set 'fill-paragraph-function 'cperl-fill-paragraph)))
3298 (make-local-variable 'parse-sexp-ignore-comments)
3299 (setq parse-sexp-ignore-comments t)
3300 (make-local-variable 'indent-region-function)
3301 (setq indent-region-function 'cperl-indent-region)
3302 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
3303 (make-local-variable 'imenu-create-index-function)
3304 (setq imenu-create-index-function
3305 (function cperl-imenu--create-perl-index))
3306 (make-local-variable 'imenu-sort-function)
3307 (setq imenu-sort-function nil)
3308 (make-local-variable 'vc-rcs-header)
3309 (set 'vc-rcs-header cperl-vc-rcs-header)
3310 (make-local-variable 'vc-sccs-header)
3311 (set 'vc-sccs-header cperl-vc-sccs-header)
3312 ;; This one is obsolete...
3313 (make-local-variable 'vc-header-alist)
3314 (set 'vc-header-alist (or cperl-vc-header-alist ; Avoid warning
3315 (` ((SCCS (, (car cperl-vc-sccs-header)))
3316 (RCS (, (car cperl-vc-rcs-header)))))))
3317 (cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x
3318 (make-local-variable 'compilation-error-regexp-alist-alist)
3319 (set 'compilation-error-regexp-alist-alist
3320 (cons (cons 'cperl cperl-compilation-error-regexp-alist)
3321 (symbol-value 'compilation-error-regexp-alist-alist)))
3322 (let ((f 'compilation-build-compilation-error-regexp-alist))
3324 ((boundp 'compilation-error-regexp-alist);; xmeacs 19.x
3325 (make-local-variable 'compilation-error-regexp-alist)
3326 (set 'compilation-error-regexp-alist
3327 (cons cperl-compilation-error-regexp-alist
3328 (symbol-value 'compilation-error-regexp-alist)))))
3329 (make-local-variable 'font-lock-defaults)
3330 (setq font-lock-defaults
3332 ((string< emacs-version "19.30")
3333 '(perl-font-lock-keywords-2 nil nil ((?_ . "w"))))
3334 ((string< emacs-version "19.33") ; Which one to use?
3335 '((perl-font-lock-keywords
3336 perl-font-lock-keywords-1
3337 perl-font-lock-keywords-2) nil nil ((?_ . "w"))))
3339 '((cperl-load-font-lock-keywords
3340 cperl-load-font-lock-keywords-1
3341 cperl-load-font-lock-keywords-2) nil nil ((?_ . "w"))))))
3342 (make-local-variable 'cperl-syntax-state)
3343 (setq cperl-syntax-state nil) ; reset syntaxification cache
3344 (if cperl-use-syntax-table-text-property
3346 (make-local-variable 'parse-sexp-lookup-properties)
3347 ;; Do not introduce variable if not needed, we check it!
3348 (set 'parse-sexp-lookup-properties t)
3349 ;; Fix broken font-lock:
3350 (or (boundp 'font-lock-unfontify-region-function)
3351 (set 'font-lock-unfontify-region-function
3352 'font-lock-default-unfontify-region))
3353 (unless cperl-xemacs-p ; Our: just a plug for wrong font-lock
3354 (make-local-variable 'font-lock-unfontify-region-function)
3355 (set 'font-lock-unfontify-region-function ; not present with old Emacs
3356 'cperl-font-lock-unfontify-region-function))
3357 (make-local-variable 'cperl-syntax-done-to)
3358 (setq cperl-syntax-done-to nil) ; reset syntaxification cache
3359 ;; Another bug: unless font-lock-syntactic-keywords, font-lock
3360 ;; ignores syntax-table text-property. (t) is a hack
3361 ;; to make font-lock think that font-lock-syntactic-keywords
3363 (make-local-variable 'font-lock-syntactic-keywords)
3364 (setq font-lock-syntactic-keywords
3365 (if cperl-syntaxify-by-font-lock
3366 '(t (cperl-fontify-syntaxically))
3368 (if (boundp 'font-lock-multiline) ; Newer font-lock; use its facilities
3370 (setq cperl-font-lock-multiline t) ; Not localized...
3371 (set (make-local-variable 'font-lock-multiline) t))
3372 (make-local-variable 'font-lock-fontify-region-function)
3373 (set 'font-lock-fontify-region-function ; not present with old Emacs
3374 'cperl-font-lock-fontify-region-function))
3375 (make-local-variable 'font-lock-fontify-region-function)
3376 (set 'font-lock-fontify-region-function ; not present with old Emacs
3377 'cperl-font-lock-fontify-region-function)
3378 (make-local-variable 'cperl-old-style)
3379 (if (boundp 'normal-auto-fill-function) ; 19.33 and later
3380 (set (make-local-variable 'normal-auto-fill-function)
3381 'cperl-do-auto-fill) ; RMS has it as #'cperl-do-auto-fill ???
3382 (or (fboundp 'cperl-old-auto-fill-mode)
3384 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
3385 (defun auto-fill-mode (&optional arg)
3387 (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
3388 (and auto-fill-function (memq major-mode '(perl-mode cperl-mode))
3389 (setq auto-fill-function 'cperl-do-auto-fill))))))
3390 (if (cperl-enable-font-lock)
3391 (if (cperl-val 'cperl-font-lock)
3392 (progn (or cperl-faces-init (cperl-init-faces))
3393 (font-lock-mode 1))))
3394 (set (make-local-variable 'facemenu-add-face-function)
3395 'cperl-facemenu-add-face-function) ; XXXX What this guy is for???
3396 (and (boundp 'msb-menu-cond)
3397 (not cperl-msb-fixed)
3399 (if (featurep 'easymenu)
3400 (easy-menu-add cperl-menu)) ; A NOP in RMS Emacs.
3401 (run-hooks 'cperl-mode-hook)
3402 (if cperl-hook-after-change
3404 (make-local-hook 'after-change-functions)
3405 (add-hook 'after-change-functions 'cperl-after-change-function nil t)))
3406 ;; After hooks since fontification will break this
3407 (if cperl-pod-here-scan
3408 (or cperl-syntaxify-by-font-lock
3409 (progn (or cperl-faces-init (cperl-init-faces-weak))
3410 (cperl-find-pods-heres)))))
3412 ;; Fix for perldb - make default reasonable
3416 (perldb (read-from-minibuffer "Run perldb (like this): "
3417 (if (consp gud-perldb-history)
3418 (car gud-perldb-history)
3419 (concat "perl " ;;(file-name-nondirectory
3423 (buffer-file-name)))
3425 '(gud-perldb-history . 1))))
3427 (defun cperl-msb-fix ()
3428 ;; Adds perl files to msb menu, supposes that msb is already loaded
3429 (setq cperl-msb-fixed t)
3430 (let* ((l (length msb-menu-cond))
3431 (last (nth (1- l) msb-menu-cond))
3432 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
3433 (handle (1- (nth 1 last))))
3434 (setcdr precdr (list
3436 '(memq major-mode '(cperl-mode perl-mode))
3441 ;; This is used by indent-for-comment
3442 ;; to decide how much to indent a comment in CPerl code
3443 ;; based on its context. Do fallback if comment is found wrong.
3445 (defvar cperl-wrong-comment)
3446 (defvar cperl-st-cfence '(14)) ; Comment-fence
3447 (defvar cperl-st-sfence '(15)) ; String-fence
3448 (defvar cperl-st-punct '(1))
3449 (defvar cperl-st-word '(2))
3450 (defvar cperl-st-bra '(4 . ?\>))
3451 (defvar cperl-st-ket '(5 . ?\<))
3454 (defun cperl-comment-indent () ; called at point at supposed comment
3455 (let ((p (point)) (c (current-column)) was phony)
3456 (if (and (not cperl-indent-comment-at-column-0)
3458 0 ; Existing comment at bol stays there.
3459 ;; Wrong comment found
3461 (setq was (cperl-to-comment-or-eol)
3462 phony (eq (get-text-property (point) 'syntax-table)
3465 (progn ; Too naive???
3466 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
3467 (if (eq (preceding-char) ?\#)
3470 (if (= (point) p) ; Our caller found a correct place
3472 (skip-chars-backward " \t")
3473 (setq was (current-column))
3476 (max (1+ was) ; Else indent at comment column
3478 ;; No, the caller found a random place; we need to edit ourselves
3480 (insert comment-start)
3481 (backward-char (length comment-start)))
3482 (setq cperl-wrong-comment t)
3483 (cperl-make-indent comment-column 1) ; Indent min 1
3486 ;;;(defun cperl-comment-indent-fallback ()
3487 ;;; "Is called if the standard comment-search procedure fails.
3488 ;;;Point is at start of real comment."
3489 ;;; (let ((c (current-column)) target cnt prevc)
3490 ;;; (if (= c comment-column) nil
3491 ;;; (setq cnt (skip-chars-backward "[ \t]"))
3492 ;;; (setq target (max (1+ (setq prevc
3493 ;;; (current-column))) ; Else indent at comment column
3494 ;;; comment-column))
3495 ;;; (if (= c comment-column) nil
3496 ;;; (delete-backward-char cnt)
3497 ;;; (while (< prevc target)
3499 ;;; (setq prevc (current-column)))
3500 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
3501 ;;; (while (< prevc target)
3503 ;;; (setq prevc (current-column)))))))
3505 (defun cperl-indent-for-comment ()
3506 "Substitute for `indent-for-comment' in CPerl."
3508 (let (cperl-wrong-comment)
3509 (indent-for-comment)
3510 (if cperl-wrong-comment ; set by `cperl-comment-indent'
3511 (progn (cperl-to-comment-or-eol)
3512 (forward-char (length comment-start))))))
3514 (defun cperl-comment-region (b e arg)
3515 "Comment or uncomment each line in the region in CPerl mode.
3516 See `comment-region'."
3517 (interactive "r\np")
3518 (let ((comment-start "#"))
3519 (comment-region b e arg)))
3521 (defun cperl-uncomment-region (b e arg)
3522 "Uncomment or comment each line in the region in CPerl mode.
3523 See `comment-region'."
3524 (interactive "r\np")
3525 (let ((comment-start "#"))
3526 (comment-region b e (- arg))))
3528 (defvar cperl-brace-recursing nil)
3530 (defun cperl-electric-brace (arg &optional only-before)
3531 "Insert character and correct line's indentation.
3532 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
3533 place (even in empty line), but not after. If after \")\" and the inserted
3534 char is \"{\", insert extra newline before only if
3535 `cperl-extra-newline-before-brace'."
3538 (other-end (if (and cperl-electric-parens-mark
3544 (not cperl-brace-recursing)
3545 (cperl-val 'cperl-electric-parens)
3546 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
3547 ;; Need to insert a matching pair
3550 (setq insertpos (point-marker))
3551 (goto-char other-end)
3552 (setq last-command-char ?\{)
3553 (cperl-electric-lbrace arg insertpos))
3555 ;; Check whether we close something "usual" with `}'
3556 (if (and (eq last-command-char ?\})
3560 (up-list (- (prefix-numeric-value arg)))
3561 ;;(cperl-after-block-p (point-min))
3562 (or (cperl-after-expr-p nil "{;)")
3563 ;; after sub, else, continue
3564 (cperl-after-block-p nil 'pre)))
3566 ;; Just insert the guy
3567 (self-insert-command (prefix-numeric-value arg))
3568 (if (and (not arg) ; No args, end (of empty line or auto)
3570 (or (and (null only-before)
3572 (skip-chars-backward " \t")
3574 (and (eq last-command-char ?\{) ; Do not insert newline
3575 ;; if after ")" and `cperl-extra-newline-before-brace'
3576 ;; is nil, do not insert extra newline.
3577 (not cperl-extra-newline-before-brace)
3579 (skip-chars-backward " \t")
3580 (eq (preceding-char) ?\))))
3581 (if cperl-auto-newline
3582 (progn (cperl-indent-line) (newline) t) nil)))
3584 (self-insert-command (prefix-numeric-value arg))
3586 (if cperl-auto-newline
3587 (setq insertpos (1- (point))))
3588 (if (and cperl-auto-newline (null only-before))
3591 (cperl-indent-line)))
3593 (if insertpos (progn (goto-char insertpos)
3594 (search-forward (make-string
3595 1 last-command-char))
3596 (setq insertpos (1- (point)))))
3600 (goto-char insertpos)
3601 (self-insert-command (prefix-numeric-value arg)))
3602 (self-insert-command (prefix-numeric-value arg)))))))
3604 (defun cperl-electric-lbrace (arg &optional end)
3605 "Insert character, correct line's indentation, correct quoting by space."
3607 (let ((cperl-brace-recursing t)
3608 (cperl-auto-newline cperl-auto-newline)
3610 (if (and cperl-electric-parens-mark
3618 (and (cperl-val 'cperl-electric-lbrace-space)
3619 (eq (preceding-char) ?$)
3621 (skip-chars-backward "$")
3622 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
3624 ;; Check whether we are in comment
3628 (not (looking-at "[ \t]*#")))
3629 (cperl-after-expr-p nil "{;)"))
3631 (setq cperl-auto-newline nil))
3632 (cperl-electric-brace arg)
3633 (and (cperl-val 'cperl-electric-parens)
3634 (eq last-command-char ?{)
3635 (memq last-command-char
3636 (append cperl-electric-parens-string nil))
3637 (or (if other-end (goto-char (marker-position other-end)))
3639 (setq last-command-char ?} pos (point))
3640 (progn (cperl-electric-brace arg t)
3643 (defun cperl-electric-paren (arg)
3644 "Insert an opening parenthesis or a matching pair of parentheses.
3645 See `cperl-electric-parens'."
3647 (let ((beg (save-excursion (beginning-of-line) (point)))
3648 (other-end (if (and cperl-electric-parens-mark
3655 (if (and (cperl-val 'cperl-electric-parens)
3656 (memq last-command-char
3657 (append cperl-electric-parens-string nil))
3658 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
3659 ;;(not (save-excursion (search-backward "#" beg t)))
3660 (if (eq last-command-char ?<)
3662 (and abbrev-mode ; later it is too late, may be after `for'
3664 (cperl-after-expr-p nil "{;(,:="))
3667 (self-insert-command (prefix-numeric-value arg))
3668 (if other-end (goto-char (marker-position other-end)))
3669 (insert (make-string
3670 (prefix-numeric-value arg)
3671 (cdr (assoc last-command-char '((?{ .?})
3675 (forward-char (- (prefix-numeric-value arg))))
3676 (self-insert-command (prefix-numeric-value arg)))))
3678 (defun cperl-electric-rparen (arg)
3679 "Insert a matching pair of parentheses if marking is active.
3680 If not, or if we are not at the end of marking range, would self-insert.
3681 Affected by `cperl-electric-parens'."
3683 (let ((beg (save-excursion (beginning-of-line) (point)))
3684 (other-end (if (and cperl-electric-parens-mark
3685 (cperl-val 'cperl-electric-parens)
3686 (memq last-command-char
3687 (append cperl-electric-parens-string nil))
3694 (cperl-val 'cperl-electric-parens)
3695 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
3696 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
3697 ;;(not (save-excursion (search-backward "#" beg t)))
3700 (self-insert-command (prefix-numeric-value arg))
3702 (if other-end (goto-char other-end))
3703 (insert (make-string
3704 (prefix-numeric-value arg)
3705 (cdr (assoc last-command-char '((?\} . ?\{)
3710 (self-insert-command (prefix-numeric-value arg)))))
3712 (defun cperl-electric-keyword ()
3713 "Insert a construction appropriate after a keyword.
3714 Help message may be switched off by setting `cperl-message-electric-keyword'
3716 (let ((beg (save-excursion (beginning-of-line) (point)))
3717 (dollar (and (eq last-command-char ?$)
3718 (eq this-command 'self-insert-command)))
3719 (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
3720 (memq this-command '(self-insert-command newline))))
3722 (and (save-excursion
3726 (setq do (looking-at "do\\>")))
3728 (cperl-after-expr-p nil "{;:"))
3732 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
3734 (save-excursion (or (not (re-search-backward "^=" nil t))
3737 (and cperl-use-syntax-table-text-property
3738 (not (eq (get-text-property (point)
3741 (save-excursion (forward-sexp -1)
3742 (not (memq (following-char) (append "$@%&*" nil))))
3744 (and (eq (preceding-char) ?y)
3745 (progn ; "foreachmy"
3751 (memq this-command '(self-insert-command newline)))))
3752 (and dollar (insert " $"))
3754 ;;(insert " () {\n}")
3756 (cperl-extra-newline-before-brace
3757 (insert (if do "\n" " ()\n"))
3763 (and do (insert " while ();")))
3765 (insert (if do " {\n} while ();" " () {\n}"))))
3766 (or (looking-at "[ \t]\\|$") (insert " "))
3768 (if dollar (progn (search-backward "$")
3772 (search-backward ")")
3773 (if (eq last-command-char ?\()
3774 (progn ; Avoid "if (())"
3775 (delete-backward-char 1)
3776 (delete-backward-char -1))))
3778 (cperl-putback-char cperl-del-back-ch))
3779 (if cperl-message-electric-keyword
3780 (message "Precede char by C-q to avoid expansion"))))))
3782 (defun cperl-ensure-newlines (n &optional pos)
3783 "Make sure there are N newlines after the point."
3784 (or pos (setq pos (point)))
3785 (if (looking-at "\n")
3789 (cperl-ensure-newlines (1- n) pos)
3792 (defun cperl-electric-pod ()
3793 "Insert a POD chunk appropriate after a =POD directive."
3794 (let ((delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
3795 (memq this-command '(self-insert-command newline))))
3796 head1 notlast name p really-delete over)
3797 (and (save-excursion
3800 (eq (preceding-char) ?=)
3802 (setq head1 (looking-at "head1\\>[ \t]*$"))
3803 (setq over (and (looking-at "over\\>[ \t]*$")
3804 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
3808 (get-text-property (point) 'in-pod)
3809 (cperl-after-expr-p nil "{;:")
3810 (and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t)
3811 (not (looking-at "\n*=cut"))
3812 (or (not cperl-use-syntax-table-text-property)
3813 (eq (get-text-property (point) 'syntax-type) 'pod))))))
3816 (setq notlast (re-search-forward "^\n=" nil t)))
3820 (cperl-ensure-newlines 2)
3826 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
3827 nil t)))) ; Only one
3830 (setq name (file-name-sans-extension
3831 (file-name-nondirectory (buffer-file-name)))
3833 (insert " NAME\n\n" name
3834 " - \n\n=head1 SYNOPSIS\n\n\n\n"
3835 "=head1 DESCRIPTION")
3836 (cperl-ensure-newlines 4)
3840 (setq really-delete t))
3845 (insert "\n\n=item \n\n\n\n"
3847 (cperl-ensure-newlines 2)
3851 (setq really-delete t)))
3852 (if (and delete really-delete)
3853 (cperl-putback-char cperl-del-back-ch))))))
3855 (defun cperl-electric-else ()
3856 "Insert a construction appropriate after a keyword.
3857 Help message may be switched off by setting `cperl-message-electric-keyword'
3859 (let ((beg (save-excursion (beginning-of-line) (point))))
3860 (and (save-excursion
3862 (cperl-after-expr-p nil "{;:"))
3866 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
3868 (save-excursion (or (not (re-search-backward "^=" nil t))
3870 (and cperl-use-syntax-table-text-property
3871 (not (eq (get-text-property (point)
3876 ;;(insert " {\n\n}")
3878 (cperl-extra-newline-before-brace
3884 (insert " {\n\n}")))
3885 (or (looking-at "[ \t]\\|$") (insert " "))
3889 (cperl-putback-char cperl-del-back-ch)
3890 (setq this-command 'cperl-electric-else)
3891 (if cperl-message-electric-keyword
3892 (message "Precede char by C-q to avoid expansion"))))))
3894 (defun cperl-linefeed ()
3895 "Go to end of line, open a new line and indent appropriately.
3896 If in POD, insert appropriate lines."
3898 (let ((beg (save-excursion (beginning-of-line) (point)))
3899 (end (save-excursion (end-of-line) (point)))
3900 (pos (point)) start over cut res)
3901 (if (and ; Check if we need to split:
3902 ; i.e., on a boundary and inside "{...}"
3903 (save-excursion (cperl-to-comment-or-eol)
3904 (>= (point) pos)) ; Not in a comment
3906 (skip-chars-backward " \t" beg)
3908 (looking-at "[;{]")) ; After { or ; + spaces
3909 (looking-at "[ \t]*}") ; Before }
3910 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
3913 (eq (car (parse-partial-sexp pos end -1)) -1)
3914 ; Leave the level of parens
3915 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
3917 (cperl-after-block-p (point-min))
3920 (setq start (point-marker))
3921 (<= start pos))))) ; Redundant? Are after the
3922 ; start of parens group.
3924 (skip-chars-backward " \t")
3925 (or (memq (preceding-char) (append ";{" nil))
3931 (or (looking-at "{[ \t]*$") ; If there is a statement
3932 ; before, move it to separate line
3936 (cperl-indent-line)))
3937 (forward-line 1) ; We are on the target line
3940 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
3941 ; after, move it to separate line
3944 (search-backward "}" beg)
3945 (skip-chars-backward " \t")
3946 (or (memq (preceding-char) (append ";{" nil))
3951 (forward-line -1) ; We are on the line before target
3953 (newline-and-indent))
3954 (end-of-line) ; else - no splitting
3956 ((and (looking-at "\n[ \t]*{$")
3958 (skip-chars-backward " \t")
3959 (eq (preceding-char) ?\)))) ; Probably if () {} group
3960 ; with an extra newline.
3962 (cperl-indent-line))
3963 ((save-excursion ; In POD header
3964 (forward-paragraph -1)
3965 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
3966 ;; We are after \n now, so look for the rest
3967 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
3969 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
3970 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
3974 (forward-paragraph -1)
3977 (setq cut (buffer-substring (point)
3981 (delete-char (- (save-excursion (end-of-line) (point))
3983 (setq res (expand-abbrev))
3989 (cperl-ensure-newlines (if cut 2 4))
3991 ((get-text-property (point) 'in-pod) ; In POD section
3992 (cperl-ensure-newlines 4)
3994 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
3996 (cperl-indent-line))
3998 (newline-and-indent))))))
4000 (defun cperl-electric-semi (arg)
4001 "Insert character and correct line's indentation."
4003 (if cperl-auto-newline
4004 (cperl-electric-terminator arg)
4005 (self-insert-command (prefix-numeric-value arg))
4006 (if cperl-autoindent-on-semi
4007 (cperl-indent-line))))
4009 (defun cperl-electric-terminator (arg)
4010 "Insert character and correct line's indentation."
4013 (auto (and cperl-auto-newline
4014 (or (not (eq last-command-char ?:))
4015 cperl-auto-newline-after-colon)))
4017 (if (and ;;(not arg)
4019 (not (save-excursion
4021 (skip-chars-forward " \t")
4023 ;; Ignore in comment lines
4024 (= (following-char) ?#)
4025 ;; Colon is special only after a label
4026 ;; So quickly rule out most other uses of colon
4027 ;; and do no indentation for them.
4028 (and (eq last-command-char ?:)
4031 (skip-chars-forward " \t")
4032 (and (< (point) end)
4033 (progn (goto-char (- end 1))
4034 (not (looking-at ":"))))))
4036 (beginning-of-defun)
4037 (let ((pps (parse-partial-sexp (point) end)))
4038 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
4040 (self-insert-command (prefix-numeric-value arg))
4042 (if auto (setq insertpos (point-marker)))
4048 (cperl-indent-line)))
4050 (if insertpos (goto-char (1- (marker-position insertpos)))
4055 (goto-char insertpos)
4056 (self-insert-command (prefix-numeric-value arg)))
4057 (self-insert-command (prefix-numeric-value arg)))))
4059 (defun cperl-electric-backspace (arg)
4060 "Backspace, or remove the whitespace around the point inserted by an electric
4061 key. Will untabivy if `cperl-electric-backspace-untabify' is non-nil."
4063 (if (and cperl-auto-newline
4064 (memq last-command '(cperl-electric-semi
4065 cperl-electric-terminator
4066 cperl-electric-lbrace))
4067 (memq (preceding-char) '(?\ ?\t ?\n)))
4069 (if (eq last-command 'cperl-electric-lbrace)
4070 (skip-chars-forward " \t\n"))
4072 (skip-chars-backward " \t\n")
4073 (delete-region (point) p))
4074 (and (eq last-command 'cperl-electric-else)
4075 ;; We are removing the whitespace *inside* cperl-electric-else
4076 (setq this-command 'cperl-electric-else-really))
4077 (if (and cperl-auto-newline
4078 (eq last-command 'cperl-electric-else-really)
4079 (memq (preceding-char) '(?\ ?\t ?\n)))
4081 (skip-chars-forward " \t\n")
4083 (skip-chars-backward " \t\n")
4084 (delete-region (point) p))
4085 (if cperl-electric-backspace-untabify
4086 (backward-delete-char-untabify arg)
4087 (delete-backward-char arg)))))
4089 (defun cperl-inside-parens-p () ;; NOT USED????
4093 (narrow-to-region (point)
4094 (progn (beginning-of-defun) (point)))
4095 (goto-char (point-max))
4096 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
4099 (defun cperl-indent-command (&optional whole-exp)
4100 "Indent current line as Perl code, or in some cases insert a tab character.
4101 If `cperl-tab-always-indent' is non-nil (the default), always indent current
4102 line. Otherwise, indent the current line only if point is at the left margin
4103 or in the line's indentation; otherwise insert a tab.
4105 A numeric argument, regardless of its value,
4106 means indent rigidly all the lines of the expression starting after point
4107 so that this line becomes properly indented.
4108 The relative indentation among the lines of the expression are preserved."
4110 (cperl-update-syntaxification (point) (point))
4112 ;; If arg, always indent this line as Perl
4113 ;; and shift remaining lines of expression the same amount.
4114 (let ((shift-amt (cperl-indent-line))
4117 (if cperl-tab-always-indent
4118 (beginning-of-line))
4125 (if (and shift-amt (> end beg))
4126 (indent-code-rigidly beg end shift-amt "#")))
4127 (if (and (not cperl-tab-always-indent)
4129 (skip-chars-backward " \t")
4132 (cperl-indent-line))))
4134 (defun cperl-indent-line (&optional parse-data)
4135 "Indent current line as Perl code.
4136 Return the amount the indentation changed by."
4137 (let ((case-fold-search nil)
4138 (pos (- (point-max) (point)))
4139 indent i beg shift-amt)
4140 (setq indent (cperl-calculate-indent parse-data)
4144 (cond ((or (eq indent nil) (eq indent t))
4145 (setq indent (current-indentation) i nil))
4146 ;;((eq indent t) ; Never?
4147 ;; (setq indent (cperl-calculate-indent-within-comment)))
4148 ;;((looking-at "[ \t]*#")
4151 (skip-chars-forward " \t")
4152 (if (listp indent) (setq indent (car indent)))
4153 (cond ((and (looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
4154 (not (looking-at "[smy]:\\|tr:")))
4156 (setq indent (max cperl-min-label-indent
4157 (+ indent cperl-label-offset)))))
4158 ((= (following-char) ?})
4159 (setq indent (- indent cperl-indent-level)))
4160 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
4161 (setq indent (+ indent cperl-close-paren-offset)))
4162 ((= (following-char) ?{)
4163 (setq indent (+ indent cperl-brace-offset))))))
4164 (skip-chars-forward " \t")
4165 (setq shift-amt (and i (- indent (current-column))))
4166 (if (or (not shift-amt)
4168 (if (> (- (point-max) pos) (point))
4169 (goto-char (- (point-max) pos)))
4170 ;;;(delete-region beg (point))
4171 ;;;(indent-to indent)
4172 (cperl-make-indent indent)
4173 ;; If initial point was within line's indentation,
4174 ;; position after the indentation. Else stay at same point in text.
4175 (if (> (- (point-max) pos) (point))
4176 (goto-char (- (point-max) pos))))
4179 (defun cperl-after-label ()
4180 ;; Returns true if the point is after label. Does not do save-excursion.
4181 (and (eq (preceding-char) ?:)
4182 (memq (char-syntax (char-after (- (point) 2)))
4186 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
4188 (defun cperl-get-state (&optional parse-start start-state)
4189 ;; returns list (START STATE DEPTH PRESTART),
4190 ;; START is a good place to start parsing, or equal to
4191 ;; PARSE-START if preset,
4192 ;; STATE is what is returned by `parse-partial-sexp'.
4193 ;; DEPTH is true is we are immediately after end of block
4194 ;; which contains START.
4195 ;; PRESTART is the position basing on which START was found.
4197 (let ((start-point (point)) depth state start prestart)
4198 (if (and parse-start
4199 (<= parse-start start-point))
4200 (goto-char parse-start)
4201 (beginning-of-defun)
4202 (setq start-state nil))
4203 (setq prestart (point))
4205 ;; Try to go out, if sub is not on the outermost level
4206 (while (< (point) start-point)
4207 (setq start (point) parse-start start depth nil
4208 state (parse-partial-sexp start start-point -1))
4209 (if (> (car state) -1) nil
4210 ;; The current line could start like }}}, so the indentation
4211 ;; corresponds to a different level than what we reached
4213 (beginning-of-line 2))) ; Go to the next line.
4214 (if start (goto-char start))) ; Not at the start of file
4215 (setq start (point))
4216 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
4217 (list start state depth prestart))))
4219 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
4221 (defun cperl-beginning-of-property (p prop &optional lim)
4222 "Given that P has a property PROP, find where the property starts.
4223 Will not look before LIM."
4224 ;;; XXXX What to do at point-max???
4225 (or (previous-single-property-change (cperl-1+ p) prop lim)
4227 ;;; (cond ((eq p (point-min))
4229 ;;; ((and lim (<= p lim))
4231 ;;; ((not (get-text-property (1- p) prop))
4233 ;;; (t (or (previous-single-property-change p look-prop lim)
4237 (defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start
4238 ;; Old workhorse for calculation of indentation; the major problem
4239 ;; is that it mixes the sniffer logic to understand what the current line
4240 ;; MEANS with the logic to actually calculate where to indent it.
4241 ;; The latter part should be eventually moved to `cperl-calculate-indent';
4242 ;; actually, this is mostly done now...
4243 (cperl-update-syntaxification (point) (point))
4244 (let ((res (get-text-property (point) 'syntax-type)))
4247 ((and (memq res '(pod here-doc here-doc-delim format))
4248 (not (get-text-property (point) 'indentable)))
4250 ;; before start of POD - whitespace found since do not have 'pod!
4251 ((looking-at "[ \t]*\n=")
4252 (error "Spaces before POD section!"))
4253 ((and (not cperl-indent-left-aligned-comments)
4255 [comment-special:at-beginning-of-line])
4256 ((get-text-property (point) 'in-pod)
4260 (let* ((indent-point (point))
4261 (char-after-pos (save-excursion
4262 (skip-chars-forward " \t")
4264 (char-after (char-after char-after-pos))
4265 (pre-indent-point (point))
4266 p prop look-prop is-block delim)
4267 (save-excursion ; Know we are not in POD, find appropriate pos before
4268 (cperl-backward-to-noncomment nil)
4269 (setq p (max (point-min) (1- (point)))
4270 prop (get-text-property p 'syntax-type)
4271 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
4273 (if (memq prop '(pod here-doc format here-doc-delim))
4275 (goto-char (cperl-beginning-of-property p look-prop))
4277 (setq pre-indent-point (point)))))
4278 (goto-char pre-indent-point) ; Orig line skipping preceeding pod/etc
4279 (let* ((case-fold-search nil)
4280 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
4281 (start (or (nth 2 parse-data) ; last complete sexp terminated
4282 (nth 0 s-s))) ; Good place to start parsing
4284 (containing-sexp (car (cdr state)))
4287 ;;containing-sexp ;; We are buggy at toplevel :-(
4290 (setcar parse-data pre-indent-point)
4291 (setcar (cdr parse-data) state)
4292 (or (nth 2 parse-data)
4293 (setcar (cddr parse-data) start))
4294 ;; Before this point: end of statement
4295 (setq old-indent (nth 3 parse-data))))
4296 (cond ((get-text-property (point) 'indentable)
4297 ;; indent to "after" the surrounding open
4298 ;; (same offset as `cperl-beautify-regexp-piece'),
4299 ;; skip blanks if we do not close the expression.
4300 (setq delim ; We do not close the expression
4302 (cperl-1+ char-after-pos) 'indentable)
4303 p (1+ (cperl-beginning-of-property
4304 (point) 'indentable))
4305 is-block ; misused for: preceeding line in REx
4306 (save-excursion ; Find preceeding line
4307 (cperl-backward-to-noncomment p)
4310 (progn ; get indent from the first line
4312 (skip-chars-forward " \t")
4313 (if (memq (char-after (point))
4315 nil ; Can't use intentation of this line...
4317 (skip-chars-forward " \t")
4319 prop (parse-partial-sexp p char-after-pos))
4320 (cond ((not delim) ; End the REx, ignore is-block
4321 (vector 'indentable 'terminator p is-block))
4322 (is-block ; Indent w.r.t. preceeding line
4323 (vector 'indentable 'cont-line char-after-pos
4324 is-block char-after p))
4325 (t ; No preceeding line...
4326 (vector 'indentable 'first-line p))))
4327 ((get-text-property char-after-pos 'REx-part2)
4328 (vector 'REx-part2 (point)))
4333 ;; XXXX Do we need to special-case this?
4334 ((null containing-sexp)
4335 ;; Line is at top level. May be data or function definition,
4336 ;; or may be function argument declaration.
4337 ;; Indent like the previous top level line
4338 ;; unless that ends in a closeparen without semicolon,
4339 ;; in which case this line is the first argument decl.
4340 (skip-chars-forward " \t")
4341 (cperl-backward-to-noncomment (or old-indent (point-min)))
4344 (eq (point) old-indent) ; old-indent was at comment
4345 (eq (preceding-char) ?\;)
4347 (and (eq (preceding-char) ?\})
4348 (cperl-after-block-and-statement-beg
4349 (point-min))) ; Was start - too close
4350 (memq char-after (append ")]}" nil))
4351 (and (eq (preceding-char) ?\:) ; label
4354 (skip-chars-backward " \t")
4355 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
4356 (get-text-property (point) 'first-format-line)))
4358 ;; Look at previous line that's at column 0
4359 ;; to determine whether we are in top-level decls
4360 ;; or function's arg decls. Set basic-indent accordingly.
4361 ;; Now add a little if this is a continuation line.
4364 (not (eq char-after ?\C-j))
4365 (setcdr (cddr parse-data)
4366 (list pre-indent-point)))
4367 (vector 'toplevel start char-after state (nth 2 s-s)))
4370 (and (setq delim (= (char-after containing-sexp) ?{))
4371 (save-excursion ; Is it a hash?
4372 (goto-char containing-sexp)
4374 cperl-indent-parens-as-block))
4375 ;; group is an expression, not a block:
4376 ;; indent to just after the surrounding open parens,
4377 ;; skip blanks if we do not close the expression.
4378 (goto-char (1+ containing-sexp))
4379 (or (memq char-after
4380 (append (if delim "}" ")]}") nil))
4381 (looking-at "[ \t]*\\(#\\|$\\)")
4382 (skip-chars-forward " \t"))
4383 (setq old-indent (point)) ; delim=is-brace
4384 (vector 'in-parens char-after (point) delim containing-sexp))
4386 ;; Statement level. Is it a continuation or a new statement?
4387 ;; Find previous non-comment character.
4388 (goto-char pre-indent-point) ; Skip one level of POD/etc
4389 (cperl-backward-to-noncomment containing-sexp)
4390 ;; Back up over label lines, since they don't
4391 ;; affect whether our line is a continuation.
4393 (while;;(or (eq (preceding-char) ?\,)
4394 (and (eq (preceding-char) ?:)
4395 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
4396 (memq (char-syntax (char-after (- (point) 2)))
4399 ;; This is always FALSE?
4400 (if (eq (preceding-char) ?\,)
4401 ;; Will go to beginning of line, essentially.
4402 ;; Will ignore embedded sexpr XXXX.
4403 (cperl-backward-to-start-of-continued-exp containing-sexp))
4405 (cperl-backward-to-noncomment containing-sexp))
4406 ;; Now we get non-label preceeding the indent point
4407 (if (not (or (eq (1- (point)) containing-sexp)
4408 (memq (preceding-char)
4409 (append (if is-block " ;{" " ,;{") '(nil)))
4410 (and (eq (preceding-char) ?\})
4411 (cperl-after-block-and-statement-beg
4413 (get-text-property (point) 'first-format-line)))
4414 ;; This line is continuation of preceding line's statement;
4415 ;; indent `cperl-continued-statement-offset' more than the
4416 ;; previous line of the statement.
4418 ;; There might be a label on this line, just
4419 ;; consider it bad style and ignore it.
4421 (cperl-backward-to-start-of-continued-exp containing-sexp)
4422 (vector 'continuation (point) char-after is-block delim))
4423 ;; This line starts a new statement.
4424 ;; Position following last unclosed open brace
4425 (goto-char containing-sexp)
4426 ;; Is line first statement after an open-brace?
4428 ;; If no, find that first statement and indent like
4429 ;; it. If the first statement begins with label, do
4430 ;; not believe when the indentation of the label is too
4434 (let ((colon-line-end 0))
4436 (progn (skip-chars-forward " \t\n")
4437 ;; s: foo : bar :x is NOT label
4438 (and (looking-at "#\\|\\([a-zA-Z0-9_$]+\\):[^:]\\|=[a-zA-Z]")
4439 (not (looking-at "[sym]:\\|tr:"))))
4440 ;; Skip over comments and labels following openbrace.
4441 (cond ((= (following-char) ?\#)
4443 ((= (following-char) ?\=)
4445 (or (next-single-property-change (point) 'in-pod)
4446 (point-max)))) ; do not loop if no syntaxification
4449 (save-excursion (end-of-line)
4450 (setq colon-line-end (point)))
4451 (search-forward ":"))))
4452 ;; We are at beginning of code (NOT label or comment)
4453 ;; First, the following code counts
4454 ;; if it is before the line we want to indent.
4455 (and (< (point) indent-point)
4456 (vector 'have-prev-sibling (point) colon-line-end
4459 ;; If no previous statement,
4460 ;; indent it relative to line brace is on.
4462 ;; For open-braces not the first thing in a line,
4463 ;; add in cperl-brace-imaginary-offset.
4465 ;; If first thing on a line: ?????
4466 ;; Move back over whitespace before the openbrace.
4467 (setq ; brace first thing on a line
4468 old-indent (progn (skip-chars-backward " \t") (bolp)))
4469 ;; Should we indent w.r.t. earlier than start?
4470 ;; Move to start of control group, possibly on a different line
4471 (or cperl-indent-wrt-brace
4472 (cperl-backward-to-noncomment (point-min)))
4473 ;; If the openbrace is preceded by a parenthesized exp,
4474 ;; move to the beginning of that;
4475 (if (eq (preceding-char) ?\))
4478 (cperl-backward-to-noncomment (point-min))))
4479 ;; In the case it starts a subroutine, indent with
4480 ;; respect to `sub', not with respect to the
4481 ;; first thing on the line, say in the case of
4482 ;; anonymous sub in a hash.
4483 (if (and;; Is it a sub in group starting on this line?
4484 (cond ((get-text-property (point) 'attrib-group)
4485 (goto-char (cperl-beginning-of-property
4486 (point) 'attrib-group)))
4487 ((eq (preceding-char) ?b)
4489 (looking-at "sub\\>")))
4490 (setq p (nth 1 ; start of innermost containing list
4492 (save-excursion (beginning-of-line)
4496 (goto-char (1+ p)) ; enclosing block on the same line
4497 (skip-chars-forward " \t")
4498 (vector 'code-start-in-block containing-sexp char-after
4499 (and delim (not is-block)) ; is a HASH
4500 old-indent ; brace first thing on a line
4501 t (point) ; have something before...
4505 ;; Get initial indentation of the line we are on.
4506 ;; If line starts with label, calculate label indentation
4507 (vector 'code-start-in-block containing-sexp char-after
4508 (and delim (not is-block)) ; is a HASH
4509 old-indent ; brace first thing on a line
4510 nil (point))))))))))))))) ; nothing interesting before
4512 (defvar cperl-indent-rules-alist
4513 '((pod nil) ; via `syntax-type' property
4514 (here-doc nil) ; via `syntax-type' property
4515 (here-doc-delim nil) ; via `syntax-type' property
4516 (format nil) ; via `syntax-type' property
4517 (in-pod nil) ; via `in-pod' property
4518 (comment-special:at-beginning-of-line nil)
4521 "Alist of indentation rules for CPerl mode.
4524 number: add this amount of indentation.")
4526 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
4527 "Return appropriate indentation for current line as Perl code.
4528 In usual case returns an integer: the column to indent to.
4529 Returns nil if line starts inside a string, t if in a comment.
4531 Will not correct the indentation for labels, but will correct it for braces
4532 and closing parentheses and brackets."
4533 ;; This code is still a broken architecture: in some cases we need to
4534 ;; compensate for some modifications which `cperl-indent-line' will add later
4536 (let ((i (cperl-sniff-for-indent parse-data)) what p)
4538 ;;((or (null i) (eq i t) (numberp i))
4541 (setq what (assoc (elt i 0) cperl-indent-rules-alist))
4543 (what (cadr what)) ; Load from table
4545 ;; Indenters for regular expressions with //x and qw()
4547 ((eq 'REx-part2 (elt i 0)) ;; [self start] start of /REP in s//REP/x
4548 (goto-char (elt i 1))
4549 (condition-case nil ; Use indentation of the 1st part
4552 ((eq 'indentable (elt i 0)) ; Indenter for REGEXP qw() etc
4553 (cond ;;; [indentable terminator start-pos is-block]
4554 ((eq 'terminator (elt i 1)) ; Lone terminator of "indentable string"
4555 (goto-char (elt i 2)) ; After opening parens
4556 (1- (current-column)))
4557 ((eq 'first-line (elt i 1)); [indentable first-line start-pos]
4558 (goto-char (elt i 2))
4559 (+ (or cperl-regexp-indent-step cperl-indent-level)
4562 ((eq 'cont-line (elt i 1)); [indentable cont-line pos prev-pos first-char start-pos]
4563 ;; Indent as the level after closing parens
4564 (goto-char (elt i 2)) ; indent line
4565 (skip-chars-forward " \t)") ; Skip closing parens
4567 (goto-char (elt i 3)) ; previous line
4568 (skip-chars-forward " \t)") ; Skip closing parens
4569 ;; Number of parens in between:
4570 (setq p (nth 0 (parse-partial-sexp (point) p))
4571 what (elt i 4)) ; First char on current line
4572 (goto-char (elt i 3)) ; previous line
4573 (+ (* p (or cperl-regexp-indent-step cperl-indent-level))
4574 (cond ((eq what ?\) )
4575 (- cperl-close-paren-offset)) ; compensate
4577 (- (or cperl-regexp-indent-step cperl-indent-level)))
4579 (if (eq (following-char) ?\| )
4580 (or cperl-regexp-indent-step cperl-indent-level)
4584 (error "Unrecognized value of indent: " i))))
4586 ;; Indenter for stuff at toplevel
4588 ((eq 'toplevel (elt i 0)) ;; [toplevel start char-after state immed-after-block]
4589 (+ (save-excursion ; To beg-of-defun, or end of last sexp
4590 (goto-char (elt i 1)) ; start = Good place to start parsing
4591 (- (current-indentation) ;
4592 (if (elt i 4) cperl-indent-level 0))) ; immed-after-block
4593 (if (eq (elt i 2) ?{) cperl-continued-brace-offset 0) ; char-after
4594 ;; Look at previous line that's at column 0
4595 ;; to determine whether we are in top-level decls
4596 ;; or function's arg decls. Set basic-indent accordingly.
4597 ;; Now add a little if this is a continuation line.
4598 (if (elt i 3) ; state (XXX What is the semantic???)
4600 cperl-continued-statement-offset)))
4602 ;; Indenter for stuff in "parentheses" (or brackets, braces-as-hash)
4604 ((eq 'in-parens (elt i 0))
4605 ;; in-parens char-after old-indent-point is-brace containing-sexp
4607 ;; group is an expression, not a block:
4608 ;; indent to just after the surrounding open parens,
4609 ;; skip blanks if we do not close the expression.
4611 (goto-char (elt i 2)) ; old-indent-point
4613 (if (and (elt i 3) ; is-brace
4614 (eq (elt i 1) ?\})) ; char-after
4615 ;; Correct indentation of trailing ?\}
4616 (+ cperl-indent-level cperl-close-paren-offset)
4619 ;; Indenter for continuation lines
4621 ((eq 'continuation (elt i 0))
4622 ;; [continuation statement-start char-after is-block is-brace]
4623 (goto-char (elt i 1)) ; statement-start
4624 (+ (if (memq (elt i 2) (append "}])" nil)) ; char-after
4626 cperl-continued-statement-offset)
4627 (if (or (elt i 3) ; is-block
4628 (not (elt i 4)) ; is-brace
4629 (not (eq (elt i 2) ?\}))) ; char-after
4631 ;; Now it is a hash reference
4632 (+ cperl-indent-level cperl-close-paren-offset))
4633 ;; Labels do not take :: ...
4634 (if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
4635 (if (> (current-indentation) cperl-min-label-indent)
4636 (- (current-indentation) cperl-label-offset)
4637 ;; Do not move `parse-data', this should
4638 ;; be quick anyway (this comment comes
4639 ;; from different location):
4640 (cperl-calculate-indent))
4642 (if (eq (elt i 2) ?\{) ; char-after
4643 cperl-continued-brace-offset 0)))
4645 ;; Indenter for lines in a block which are not leading lines
4647 ((eq 'have-prev-sibling (elt i 0))
4648 ;; [have-prev-sibling sibling-beg colon-line-end block-start]
4649 (goto-char (elt i 1)) ; sibling-beg
4650 (if (> (elt i 2) (point)) ; colon-line-end; have label before point
4651 (if (> (current-indentation)
4652 cperl-min-label-indent)
4653 (- (current-indentation) cperl-label-offset)
4654 ;; Do not believe: `max' was involved in calculation of indent
4655 (+ cperl-indent-level
4657 (goto-char (elt i 3)) ; block-start
4658 (current-indentation))))
4661 ;; Indenter for the first line in a block
4663 ((eq 'code-start-in-block (elt i 0))
4664 ;;[code-start-in-block before-brace char-after
4665 ;; is-a-HASH-ref brace-is-first-thing-on-a-line
4666 ;; group-starts-before-start-of-sub start-of-control-group]
4667 (goto-char (elt i 1))
4668 ;; For open brace in column zero, don't let statement
4669 ;; start there too. If cperl-indent-level=0,
4670 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
4671 (+ (if (and (bolp) (zerop cperl-indent-level))
4672 (+ cperl-brace-offset cperl-continued-statement-offset)
4674 (if (and (elt i 3) ; is-a-HASH-ref
4675 (eq (elt i 2) ?\})) ; char-after: End of a hash reference
4676 (+ cperl-indent-level cperl-close-paren-offset)
4678 ;; Unless openbrace is the first nonwhite thing on the line,
4679 ;; add the cperl-brace-imaginary-offset.
4680 (if (elt i 4) 0 ; brace-is-first-thing-on-a-line
4681 cperl-brace-imaginary-offset)
4683 (goto-char (elt i 6)) ; start-of-control-group
4684 (if (elt i 5) ; group-starts-before-start-of-sub
4686 ;; Get initial indentation of the line we are on.
4687 ;; If line starts with label, calculate label indentation
4690 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
4691 (if (> (current-indentation) cperl-min-label-indent)
4692 (- (current-indentation) cperl-label-offset)
4693 ;; Do not move `parse-data', this should
4695 (cperl-calculate-indent))
4696 (current-indentation))))))
4698 (error "Unrecognized value of indent: " i))))
4700 (error (format "Got strange value of indent: " i)))))))
4702 (defun cperl-calculate-indent-within-comment ()
4703 "Return the indentation amount for line, assuming that
4704 the current line is to be regarded as part of a block comment."
4705 (let (end star-start)
4708 (skip-chars-forward " \t")
4710 (and (= (following-char) ?#)
4712 (cperl-to-comment-or-eol)
4718 (defun cperl-to-comment-or-eol ()
4719 "Go to position before comment on the current line, or to end of line.
4720 Returns true if comment is found. In POD will not move the point."
4721 ;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
4722 ;; then looks for literal # or end-of-line.
4723 (let (state stop-in cpoint (lim (progn (end-of-line) (point))) pr e)
4724 (or cperl-font-locking
4725 (cperl-update-syntaxification lim lim))
4727 (if (setq pr (get-text-property (point) 'syntax-type))
4728 (setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
4729 (if (or (eq pr 'pod)
4730 (if (or (not e) (> e lim)) ; deep inside a group
4731 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
4732 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
4733 ;; Else - need to do it the hard way
4734 (and (and e (<= e lim))
4736 (while (not stop-in)
4737 (setq state (parse-partial-sexp (point) lim nil nil nil t))
4739 ;; If fails (beginning-of-line inside sexp), then contains not-comment
4740 (if (nth 4 state) ; After `#';
4741 ; (nth 2 state) can be
4742 ; beginning of m,s,qq and so
4746 (setq cpoint (point))
4747 (goto-char (nth 2 state))
4749 ((looking-at "\\(s\\|tr\\)\\>")
4750 (or (re-search-forward
4751 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
4754 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
4755 (or (re-search-forward
4756 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
4759 (t ; It was fair comment
4760 (setq stop-in t) ; Finish
4761 (goto-char (1- cpoint)))))
4762 (setq stop-in t) ; Finish
4764 (setq stop-in t))) ; Finish
4767 (defsubst cperl-modify-syntax-type (at how)
4768 (if (< at (point-max))
4770 (put-text-property at (1+ at) 'syntax-table how)
4771 (put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
4773 (defun cperl-protect-defun-start (s e)
4774 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
4777 (while (re-search-forward "^\\s(" e 'to-end)
4778 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
4780 (defun cperl-commentify (bb e string &optional noface)
4781 (if cperl-use-syntax-table-text-property
4782 (if (eq noface 'n) ; Only immediate
4784 ;; We suppose that e is _after_ the end of construction, as after eol.
4785 (setq string (if string cperl-st-sfence cperl-st-cfence))
4787 ;; one-char string/comment?!
4788 (cperl-modify-syntax-type bb cperl-st-punct)
4789 (cperl-modify-syntax-type bb string)
4790 (cperl-modify-syntax-type (1- e) string))
4791 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
4792 (put-text-property (1+ bb) (1- e)
4793 'syntax-table cperl-string-syntax-table))
4794 (cperl-protect-defun-start bb e))
4797 (not cperl-pod-here-fontify)
4798 (put-text-property bb e 'face (if string 'font-lock-string-face
4799 'font-lock-comment-face)))))
4801 (defvar cperl-starters '(( ?\( . ?\) )
4806 (defun cperl-cached-syntax-table (st)
4807 "Get a syntax table cached in ST, or create and cache into ST a syntax table.
4808 All the entries of the syntax table are \".\", except for a backslash, which
4812 (setcar st (make-syntax-table))
4816 (modify-syntax-entry i "." st)
4818 (modify-syntax-entry ?\\ "\\" st)
4821 (defun cperl-forward-re (lim end is-2arg st-l err-l argument
4822 &optional ostart oend)
4823 "Find the end of a regular expression or a stringish construct (q[] etc).
4824 The point should be before the starting delimiter.
4826 Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
4827 is s/// or tr/// like expression. If END is nil, generates an error
4828 message if needed. If SET-ST is non-nil, will use (or generate) a
4829 cached syntax table in ST-L. If ERR-L is non-nil, will store the
4830 error message in its CAR (unless it already contains some error
4831 message). ARGUMENT should be the name of the construct (used in error
4832 messages). OSTART, OEND may be set in recursive calls when processing
4833 the second argument of 2ARG construct.
4835 Works *before* syntax recognition is done. In IS-2ARG situation may
4836 modify syntax-type text property if the situation is too hard."
4837 (let (b starter ender st i i2 go-forward reset-st set-st)
4838 (skip-chars-forward " \t")
4839 ;; ender means matching-char matcher.
4841 starter (if (eobp) 0 (char-after b))
4842 ender (cdr (assoc starter cperl-starters)))
4843 ;; What if starter == ?\\ ????
4844 (setq st (cperl-cached-syntax-table st-l))
4846 ;; Whether we have an intermediate point
4848 ;; Prepare the syntax table:
4849 (if (not ender) ; m/blah/, s/x//, s/x/y/
4850 (modify-syntax-entry starter "$" st)
4851 (modify-syntax-entry starter (concat "(" (list ender)) st)
4852 (modify-syntax-entry ender (concat ")" (list starter)) st))
4855 ;; We use `$' syntax class to find matching stuff, but $$
4856 ;; is recognized the same as $, so we need to check this manually.
4857 (if (and (eq starter (char-after (cperl-1+ b)))
4859 ;; $ has TeXish matching rules, so $$ equiv $...
4861 (setq reset-st (syntax-table))
4862 (set-syntax-table st)
4864 (if (<= (point) (1+ b))
4865 (error "Unfinished regular expression"))
4866 (set-syntax-table reset-st)
4868 ;; Now the problem is with m;blah;;
4870 (eq (preceding-char)
4871 (char-after (- (point) 2)))
4874 (= 0 (% (skip-chars-backward "\\\\") 2)))
4876 ;; Now we are after the first part.
4877 (and is-2arg ; Have trailing part
4879 (eq (following-char) starter) ; Empty trailing part
4881 (or (eq (char-syntax (following-char)) ?.)
4882 ;; Make trailing letter into punctuation
4883 (cperl-modify-syntax-type (point) cperl-st-punct))
4884 (setq is-2arg nil go-forward t))) ; Ignore the tail
4885 (if is-2arg ; Not number => have second part
4887 (setq i (point) i2 i)
4889 (if (memq (following-char) '(?\ ?\t ?\n ?\f))
4891 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4892 (goto-char (match-end 0))
4893 (skip-chars-forward " \t\n\f"))
4896 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
4897 (if ender (modify-syntax-entry ender "." st))
4899 (setq ender (cperl-forward-re lim end nil st-l err-l
4900 argument starter ender)
4901 ender (nth 2 ender)))))
4902 (error (goto-char lim)
4905 (set-syntax-table reset-st))
4908 "End of `%s%s%c ... %c' string/RE not found: %s"
4910 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
4911 starter (or ender starter) bb)
4912 (or (car err-l) (setcar err-l b)))))
4915 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
4916 (if ender (modify-syntax-entry ender "." st))))
4917 ;; i: have 2 args, after end of the first arg
4918 ;; i2: start of the second arg, if any (before delim iff `ender').
4919 ;; ender: the last arg bounded by parens-like chars, the second one of them
4920 ;; starter: the starting delimiter of the first arg
4921 ;; go-forward: has 2 args, and the second part is empty
4922 (list i i2 ender starter go-forward)))
4924 (defun cperl-forward-group-in-re (&optional st-l)
4925 "Find the end of a group in a REx.
4926 Return the error message (if any). Does not work if delimiter is `)'.
4927 Works before syntax recognition is done."
4928 ;; Works *before* syntax recognition is done
4929 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
4930 (let (st b reset-st)
4933 (setq st (cperl-cached-syntax-table st-l))
4934 (modify-syntax-entry ?\( "()" st)
4935 (modify-syntax-entry ?\) ")(" st)
4936 (setq reset-st (syntax-table))
4937 (set-syntax-table st)
4940 "cperl-forward-group-in-re: error %s" b)))
4941 ;; now restore the initial state
4944 (modify-syntax-entry ?\( "." st)
4945 (modify-syntax-entry ?\) "." st)))
4947 (set-syntax-table reset-st))
4951 (defvar font-lock-string-face)
4952 ;;(defvar font-lock-reference-face)
4953 (defvar font-lock-constant-face)
4954 (defsubst cperl-postpone-fontification (b e type val &optional now)
4955 ;; Do after syntactic fontification?
4956 (if cperl-syntaxify-by-font-lock
4957 (or now (put-text-property b e 'cperl-postpone (cons type val)))
4958 (put-text-property b e type val)))
4960 ;;; Here is how the global structures (those which cannot be
4961 ;;; recognized locally) are marked:
4963 ;; Start-to-end is marked `in-pod' ==> t
4964 ;; Each non-literal part is marked `syntax-type' ==> `pod'
4965 ;; Each literal part is marked `syntax-type' ==> `in-pod'
4967 ;; Start-to-end is marked `here-doc-group' ==> t
4968 ;; The body is marked `syntax-type' ==> `here-doc'
4969 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
4971 ;; First line (to =) marked `first-format-line' ==> t
4972 ;; After-this--to-end is marked `syntax-type' ==> `format'
4973 ;; d) 'Q'uoted string:
4974 ;; part between markers inclusive is marked `syntax-type' ==> `string'
4975 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
4976 ;; second part of s///e is marked `syntax-type' ==> `multiline'
4977 ;; e) Attributes of subroutines: `attrib-group' ==> t
4978 ;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
4979 ;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
4981 ;;; In addition, some parts of RExes may be marked as `REx-interpolated'
4982 ;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
4984 (defun cperl-unwind-to-safe (before &optional end)
4985 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
4986 (let ((pos (point)) opos)
4987 (while (and pos (progn
4989 (get-text-property (setq pos (point)) 'syntax-type)))
4991 pos (cperl-beginning-of-property pos 'syntax-type))
4992 (if (eq pos (point-min))
4997 (goto-char (cperl-1- pos))
5000 (goto-char (setq pos (cperl-1- pos))))
5002 (goto-char (point-min))))
5004 (and (looking-at "\n*=")
5005 (/= 0 (skip-chars-backward "\n"))
5009 ;; Do the same for end, going small steps
5011 (while (and end (get-text-property end 'syntax-type))
5013 end (next-single-property-change end 'syntax-type nil (point-max)))
5014 (if end (progn (goto-char end)
5015 (or (bolp) (forward-line 1))
5016 (setq end (point)))))
5019 ;;; These are needed for byte-compile (at least with v19)
5020 (defvar cperl-nonoverridable-face)
5021 (defvar font-lock-variable-name-face)
5022 (defvar font-lock-function-name-face)
5023 (defvar font-lock-keyword-face)
5024 (defvar font-lock-builtin-face)
5025 (defvar font-lock-type-face)
5026 (defvar font-lock-comment-face)
5027 (defvar font-lock-warning-face)
5029 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
5030 "Syntaxically mark (and fontify) attributes of a subroutine.
5031 Should be called with the point before leading colon of an attribute."
5032 ;; Works *before* syntax recognition is done
5033 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
5034 (let (st b p reset-st after-first (start (point)) start1 end1)
5038 "\\(" ; 1=optional? colon
5039 ":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
5041 (if after-first "?" "")
5042 ;; No space between name and paren allowed...
5043 "\\(\\sw+\\)" ; 3=name
5044 "\\((\\)?")) ; 4=optional paren
5045 (and (match-beginning 1)
5046 (cperl-postpone-fontification
5047 (match-beginning 0) (cperl-1+ (match-beginning 0))
5048 'face font-lock-constant-face))
5049 (setq start1 (match-beginning 3) end1 (match-end 3))
5050 (cperl-postpone-fontification start1 end1
5051 'face font-lock-constant-face)
5052 (goto-char end1) ; end or before `('
5053 (if (match-end 4) ; Have attribute arguments...
5056 (setq st (cperl-cached-syntax-table st-l))
5057 (modify-syntax-entry ?\( "()" st)
5058 (modify-syntax-entry ?\) ")(" st))
5059 (setq reset-st (syntax-table) p (point))
5060 (set-syntax-table st)
5062 (set-syntax-table reset-st)
5064 (cperl-commentify p (point) t))) ; mark as string
5065 (forward-comment (buffer-size))
5066 (setq after-first t))
5068 "L%d: attribute `%s': %s"
5069 (count-lines (point-min) (point))
5070 (and start1 end1 (buffer-substring start1 end1)) b)
5074 (put-text-property start (point)
5075 'attrib-group (if (looking-at "{") t 0))
5077 (< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
5078 ;; Apparently, we do not need `multiline': faces added now
5079 (put-text-property (+ 3 pos) (cperl-1+ (point))
5080 'syntax-type 'sub-decl))
5081 (and b-fname ; Fontify here: the following condition
5082 (cperl-postpone-fontification ; is too hard to determine by
5083 b-fname e-fname 'face ; a REx, so do it here
5084 (if (looking-at "{")
5085 font-lock-function-name-face
5086 font-lock-variable-name-face)))))
5087 ;; now restore the initial state
5090 (modify-syntax-entry ?\( "." st)
5091 (modify-syntax-entry ?\) "." st)))
5093 (set-syntax-table reset-st))))
5095 (defsubst cperl-look-at-leading-count (is-x-REx e)
5098 (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
5099 (1- e) t)) ; return nil on failure, no moving
5100 (if (eq ?\{ (preceding-char)) nil
5101 (cperl-postpone-fontification
5102 (1- (point)) (point)
5103 'face font-lock-warning-face))))
5105 ;;; Debugging this may require (setq max-specpdl-size 2000)...
5106 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc)
5107 "Scans the buffer for hard-to-parse Perl constructions.
5108 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
5109 the sections using `cperl-pod-head-face', `cperl-pod-face',
5112 (or min (setq min (point-min)
5113 cperl-syntax-state nil
5114 cperl-syntax-done-to min))
5115 (or max (setq max (point-max)))
5116 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
5117 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
5118 is-REx is-x-REx REx-subgr-start REx-subgr-end was-subgr i2 hairy-RE
5119 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
5120 (modified (buffer-modified-p)) overshoot is-o-REx
5121 (after-change-functions nil)
5122 (cperl-font-locking t)
5123 (use-syntax-state (and cperl-syntax-state
5124 (>= min (car cperl-syntax-state))))
5125 (state-point (if use-syntax-state
5126 (car cperl-syntax-state)
5128 (state (if use-syntax-state
5129 (cdr cperl-syntax-state)))
5130 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
5131 (st-l (list nil)) (err-l (list nil))
5132 ;; Somehow font-lock may be not loaded yet...
5133 ;; (e.g., when building TAGS via command-line call)
5134 (font-lock-string-face (if (boundp 'font-lock-string-face)
5135 font-lock-string-face
5136 'font-lock-string-face))
5137 (my-cperl-delimiters-face (if (boundp 'font-lock-constant-face)
5138 font-lock-constant-face
5139 'font-lock-constant-face))
5140 (my-cperl-REx-spec-char-face ; [] ^.$ and wrapper-of ({})
5141 (if (boundp 'font-lock-function-name-face)
5142 font-lock-function-name-face
5143 'font-lock-function-name-face))
5144 (font-lock-variable-name-face ; interpolated vars and ({})-code
5145 (if (boundp 'font-lock-variable-name-face)
5146 font-lock-variable-name-face
5147 'font-lock-variable-name-face))
5148 (font-lock-function-name-face ; used in `cperl-find-sub-attrs'
5149 (if (boundp 'font-lock-function-name-face)
5150 font-lock-function-name-face
5151 'font-lock-function-name-face))
5152 (font-lock-constant-face ; used in `cperl-find-sub-attrs'
5153 (if (boundp 'font-lock-constant-face)
5154 font-lock-constant-face
5155 'font-lock-constant-face))
5156 (my-cperl-REx-0length-face ; 0-length, (?:)etc, non-literal \
5157 (if (boundp 'font-lock-builtin-face)
5158 font-lock-builtin-face
5159 'font-lock-builtin-face))
5160 (font-lock-comment-face
5161 (if (boundp 'font-lock-comment-face)
5162 font-lock-comment-face
5163 'font-lock-comment-face))
5164 (font-lock-warning-face
5165 (if (boundp 'font-lock-warning-face)
5166 font-lock-warning-face
5167 'font-lock-warning-face))
5168 (my-cperl-REx-ctl-face ; (|)
5169 (if (boundp 'font-lock-keyword-face)
5170 font-lock-keyword-face
5171 'font-lock-keyword-face))
5172 (my-cperl-REx-modifiers-face ; //gims
5173 (if (boundp 'cperl-nonoverridable-face)
5174 cperl-nonoverridable-face
5175 'cperl-nonoverridable-face))
5176 (my-cperl-REx-length1-face ; length=1 escaped chars, POSIX classes
5177 (if (boundp 'font-lock-type-face)
5179 'font-lock-type-face))
5180 (stop-point (if ignore-max
5185 "\\(\\`\n?\\|^\n\\)=" ; POD
5187 ;; One extra () before this:
5190 ;; First variant "BLAH" or just ``.
5191 "[ \t]*" ; Yes, whitespace is allowed!
5192 "\\([\"'`]\\)" ; 2 + 1 = 3
5193 "\\([^\"'`\n]*\\)" ; 3 + 1
5196 ;; Second variant: Identifier or \ID (same as 'ID') or empty
5197 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
5198 ;; Do not have <<= or << 30 or <<30 or << $blah.
5199 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
5200 "\\(\\)" ; To preserve count of pars :-( 6 + 1
5203 ;; 1+6 extra () before this:
5204 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" ;FRMAT
5205 (if cperl-use-syntax-table-text-property
5208 ;; 1+6+2=9 extra () before this:
5209 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT
5211 ;; 1+6+2+1=10 extra () before this:
5212 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
5214 ;; 1+6+2+1+1=11 extra () before this
5215 "\\<sub\\>" ; sub with proto/attr
5217 cperl-white-and-comment-rex
5218 "\\(::[a-zA-Z_:'0-9]*\\|[a-zA-Z_'][a-zA-Z_:'0-9]*\\)\\)?" ; name
5220 cperl-maybe-white-and-comment-rex
5221 "\\(([^()]*)\\|:[^:]\\)\\)" ; prototype or attribute start
5223 ;; 1+6+2+1+1+6=17 extra () before this:
5224 "\\$\\(['{]\\)" ; $' or ${foo}
5226 ;; 1+6+2+1+1+6+1=18 extra () before this (old pack'var syntax;
5227 ;; we do not support intervening comments...):
5228 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
5229 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
5231 "__\\(END\\|DATA\\)__" ; __END__ or __DATA__
5232 ;; 1+6+2+1+1+6+1+1+1=20 extra () before this:
5234 "\\\\\\(['`\"($]\\)") ; BACKWACKED something-hairy
5240 (message "Scanning for \"hard\" Perl constructions..."))
5241 ;;(message "find: %s --> %s" min max)
5242 (and cperl-pod-here-fontify
5243 ;; We had evals here, do not know why...
5244 (setq face cperl-pod-face
5245 head-face cperl-pod-head-face
5246 here-face cperl-here-face))
5247 (remove-text-properties min max
5248 '(syntax-type t in-pod t syntax-table t
5259 ;; Need to remove face as well...
5261 (and (eq system-type 'emx)
5263 (let ((case-fold-search t))
5264 (looking-at "extproc[ \t]")) ; Analogue of #!
5265 (cperl-commentify min
5266 (save-excursion (end-of-line) (point))
5270 (re-search-forward search max t))
5271 (setq tmpend nil) ; Valid for most cases
5272 (setq b (match-beginning 0)
5273 state (save-excursion (parse-partial-sexp
5274 state-point b nil nil state))
5277 ;; 1+6+2+1+1+6=17 extra () before this:
5279 ((match-beginning 18) ; $' or ${foo}
5280 (if (eq (preceding-char) ?\') ; $'
5282 (setq b (1- (point))
5283 state (parse-partial-sexp
5284 state-point (1- b) nil nil state)
5286 (if (nth 3 state) ; in string
5287 (cperl-modify-syntax-type (1- b) cperl-st-punct))
5290 (setq bb (match-beginning 0))
5291 (cperl-modify-syntax-type bb cperl-st-punct)))
5292 ;; No processing in strings/comments beyond this point:
5293 ((or (nth 3 state) (nth 4 state))
5294 t) ; Do nothing in comment/string
5295 ((match-beginning 1) ; POD section
5296 ;; "\\(\\`\n?\\|^\n\\)="
5297 (setq b (match-beginning 0)
5298 state (parse-partial-sexp
5299 state-point b nil nil state)
5301 (if (or (nth 3 state) (nth 4 state)
5302 (looking-at "cut\\>"))
5303 (if (or (nth 3 state) (nth 4 state) ignore-max)
5304 nil ; Doing a chunk only
5305 (message "=cut is not preceded by a POD section")
5306 (or (car err-l) (setcar err-l (point))))
5311 tb (match-beginning 0)
5312 b1 nil) ; error condition
5313 ;; We do not search to max, since we may be called from
5314 ;; some hook of fontification, and max is random
5315 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
5318 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
5320 (message "=cut is not preceded by an empty line")
5322 (or (car err-l) (setcar err-l b))))))
5323 (beginning-of-line 2) ; An empty line after =cut is not POD!
5327 (remove-text-properties
5328 max e '(syntax-type t in-pod t syntax-table t
5340 (put-text-property b e 'in-pod t)
5341 (put-text-property b e 'syntax-type 'in-pod)
5343 (while (re-search-forward "\n\n[ \t]" e t)
5344 ;; We start 'pod 1 char earlier to include the preceding line
5346 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
5347 (cperl-put-do-not-fontify b (point) t)
5348 ;; mark the non-literal parts as PODs
5349 (if cperl-pod-here-fontify
5350 (cperl-postpone-fontification b (point) 'face face t))
5351 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
5354 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
5355 (cperl-put-do-not-fontify (point) e t)
5356 (if cperl-pod-here-fontify
5358 ;; mark the non-literal parts as PODs
5359 (cperl-postpone-fontification (point) e 'face face t)
5362 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
5364 (cperl-postpone-fontification
5365 (match-beginning 1) (match-end 1)
5367 (while (re-search-forward
5369 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
5372 (cperl-postpone-fontification
5373 (match-beginning 1) (match-end 1)
5375 (cperl-commentify bb e nil)
5377 (or (eq e (point-max))
5378 (forward-char -1)))) ; Prepare for immediate POD start.
5380 ;; We can do many here-per-line;
5381 ;; but multiline quote on the same line as <<HERE confuses us...
5382 ;; ;; One extra () before this:
5385 ;; ;; First variant "BLAH" or just ``.
5386 ;; "[ \t]*" ; Yes, whitespace is allowed!
5387 ;; "\\([\"'`]\\)" ; 2 + 1
5388 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
5391 ;; ;; Second variant: Identifier or \ID or empty
5392 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
5393 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
5394 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
5395 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
5397 ((match-beginning 2) ; 1 + 1
5399 tb (match-beginning 0)
5400 c (and ; not HERE-DOC
5403 (or (looking-at "[ \t]*(") ; << function_call()
5404 (save-excursion ; 1 << func_name, or $foo << 10
5408 ;;; XXX What to do: foo <<bar ???
5409 ;;; XXX Need to support print {a} <<B ???
5412 ; $foo << b; $f .= <<B;
5413 ; ($f+1) << b; a($f) . <<B;
5414 ; foo 1, <<B; $x{a} <<b;
5416 ((looking-at "[0-9$({]")
5419 (looking-at "[ \t]*<<")
5425 (looking-at "\\(printf?\\|system\\|exec\\|sort\\)\\>")))
5427 (error nil))) ; func(<<EOF)
5428 (and (not (match-beginning 6)) ; Empty
5430 "[ \t]*[=0-9$@%&(]"))))))
5431 (if c ; Not here-doc
5433 (setq c (match-end 2)) ; 1 + 1
5434 (if (match-beginning 5) ;4 + 1
5435 (setq b1 (match-beginning 5) ; 4 + 1
5436 e1 (match-end 5)) ; 4 + 1
5437 (setq b1 (match-beginning 4) ; 3 + 1
5438 e1 (match-end 4))) ; 3 + 1
5439 (setq tag (buffer-substring b1 e1)
5440 qtag (regexp-quote tag))
5441 (cond (cperl-pod-here-fontify
5442 ;; Highlight the starting delimiter
5443 (cperl-postpone-fontification
5444 b1 e1 'face my-cperl-delimiters-face)
5445 (cperl-put-do-not-fontify b1 e1 t)))
5449 (goto-char end-of-here-doc))
5451 ;; We do not search to max, since we may be called from
5452 ;; some hook of fontification, and max is random
5453 (or (and (re-search-forward (concat "^" qtag "$")
5455 ;;;(eq (following-char) ?\n) ; XXXX WHY???
5457 (progn ; Pretend we matched at the end
5458 (goto-char (point-max))
5459 (re-search-forward "\\'")
5460 (message "End of here-document `%s' not found." tag)
5461 (or (car err-l) (setcar err-l b))))
5462 (if cperl-pod-here-fontify
5464 ;; Highlight the ending delimiter
5465 (cperl-postpone-fontification
5466 (match-beginning 0) (match-end 0)
5467 'face my-cperl-delimiters-face)
5468 (cperl-put-do-not-fontify b (match-end 0) t)
5469 ;; Highlight the HERE-DOC
5470 (cperl-postpone-fontification b (match-beginning 0)
5472 (setq e1 (cperl-1+ (match-end 0)))
5473 (put-text-property b (match-beginning 0)
5474 'syntax-type 'here-doc)
5475 (put-text-property (match-beginning 0) e1
5476 'syntax-type 'here-doc-delim)
5477 (put-text-property b e1 'here-doc-group t)
5478 ;; This makes insertion at the start of HERE-DOC update
5479 ;; the whole construct:
5480 (put-text-property b (cperl-1+ b) 'front-sticky '(syntax-type))
5481 (cperl-commentify b e1 nil)
5482 (cperl-put-do-not-fontify b (match-end 0) t)
5483 ;; Cache the syntax info...
5484 (setq cperl-syntax-state (cons state-point state))
5485 ;; ... and process the rest of the line...
5487 (elt ; non-inter ignore-max
5488 (cperl-find-pods-heres c i t end t e1) 1))
5489 (if (and overshoot (> overshoot (point)))
5490 (goto-char overshoot)
5491 (setq overshoot e1))
5495 ((match-beginning 8)
5496 ;; 1+6=7 extra () before this:
5497 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
5499 name (if (match-beginning 8) ; 7 + 1
5500 (buffer-substring (match-beginning 8) ; 7 + 1
5501 (match-end 8)) ; 7 + 1
5503 tb (match-beginning 0))
5505 (put-text-property (save-excursion
5508 b 'first-format-line 't)
5509 (if cperl-pod-here-fontify
5510 (while (and (eq (forward-line) 0)
5511 (not (looking-at "^[.;]$")))
5513 ((looking-at "^#")) ; Skip comments
5514 ((and argument ; Skip argument multi-lines
5515 (looking-at "^[ \t]*{"))
5517 (setq argument nil))
5518 (argument ; Skip argument lines
5519 (setq argument nil))
5522 (setq argument (looking-at "^[^\n]*[@^]"))
5524 ;; Highlight the format line
5525 (cperl-postpone-fontification b1 (point)
5526 'face font-lock-string-face)
5527 (cperl-commentify b1 (point) nil)
5528 (cperl-put-do-not-fontify b1 (point) t))))
5529 ;; We do not search to max, since we may be called from
5530 ;; some hook of fontification, and max is random
5531 (re-search-forward "^[.;]$" stop-point 'toend))
5533 (if (looking-at "^\\.$") ; ";" is not supported yet
5535 ;; Highlight the ending delimiter
5536 (cperl-postpone-fontification (point) (+ (point) 2)
5537 'face font-lock-string-face)
5538 (cperl-commentify (point) (+ (point) 2) nil)
5539 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
5540 (message "End of format `%s' not found." name)
5541 (or (car err-l) (setcar err-l b)))
5545 (put-text-property b (point) 'syntax-type 'format))
5546 ;; qq-like String or Regexp:
5547 ((or (match-beginning 10) (match-beginning 11))
5548 ;; 1+6+2=9 extra () before this:
5549 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
5551 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
5552 (setq b1 (if (match-beginning 10) 10 11)
5553 argument (buffer-substring
5554 (match-beginning b1) (match-end b1))
5555 b (point) ; end of qq etc
5557 c (char-after (match-beginning b1))
5558 bb (char-after (1- (match-beginning b1))) ; tmp holder
5559 ;; bb == "Not a stringy"
5560 bb (if (eq b1 10) ; user variables/whatever
5561 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
5562 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
5563 ((eq bb ?\:) ; $opt::s
5565 (- (match-beginning b1) 2))
5567 ((eq bb ?\>) ; $foo->s
5569 (- (match-beginning b1) 2))
5572 (not (eq (char-after ; &&m/blah/
5573 (- (match-beginning b1) 2))
5576 ;; <file> or <$file>
5578 ;; Do not stringify <FH>, <$fh> :
5581 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
5582 tb (match-beginning 0))
5583 (goto-char (match-beginning b1))
5584 (cperl-backward-to-noncomment (point-min))
5586 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
5591 ;; What is below: regexp-p?
5593 (or (memq (preceding-char)
5594 (append (if (memq c '(?\? ?\<))
5597 "~{(=|&+-*!,;:[") nil))
5598 (and (eq (preceding-char) ?\})
5599 (cperl-after-block-p (point-min)))
5600 (and (eq (char-syntax (preceding-char)) ?w)
5603 ;;; After these keywords `/' starts a RE. One should add all the
5604 ;;; functions/builtins which expect an argument, but ...
5605 (if (eq (preceding-char) ?-)
5607 (looking-at "[a-zA-Z]\\>")
5609 (not (memq (preceding-char)
5612 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
5613 (and (eq (preceding-char) ?.)
5614 (eq (char-after (- (point) 2)) ?.))
5616 ;; m|blah| ? foo : bar;
5619 cperl-use-syntax-table-text-property
5623 (looking-at "\\s|"))))))
5626 ;; Check for $a -> y
5627 (setq b1 (preceding-char)
5630 (eq (char-after (- go 2)) ?-))
5636 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5637 (goto-char (match-end 0))
5638 (skip-chars-forward " \t\n\f"))
5639 (cond ((and (eq (following-char) ?\})
5641 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
5643 (skip-chars-backward " \t\n\f")
5644 (if (memq (preceding-char) (append "$@%&*" nil))
5650 (looking-at ; $foo -> {s}
5651 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
5652 (and ; $foo[12] -> {s}
5653 (memq (following-char) '(?\{ ?\[))
5656 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
5659 ((and (eq (following-char) ?=)
5660 (eq (char-after (1+ (point))) ?\>))
5661 ;; Check for { foo => 1, s => 2 }
5662 ;; Apparently s=> is never a substitution...
5664 ((and (eq (following-char) ?:)
5665 (eq b1 ?\{) ; Check for $ { s::bar }
5666 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
5669 (skip-chars-backward " \t\n\f")
5670 (memq (preceding-char)
5671 (append "$@%&*" nil))))
5677 ;; Skip whitespace and comments...
5678 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5679 (goto-char (match-end 0))
5680 (skip-chars-forward " \t\n\f"))
5682 (put-text-property b (point) 'syntax-type 'prestring))
5683 ;; qtag means two-arg matcher, may be reset to
5684 ;; 2 or 3 later if some special quoting is needed.
5685 ;; e1 means matching-char matcher.
5686 (setq b (point) ; before the first delimiter
5688 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
5689 ;; We do not search to max, since we may be called from
5690 ;; some hook of fontification, and max is random
5691 i (cperl-forward-re stop-point end
5693 st-l err-l argument)
5694 ;; If `go', then it is considered as 1-arg, `b1' is nil
5695 ;; as in s/foo//x; the point is before final "slash"
5696 b1 (nth 1 i) ; start of the second part
5697 tag (nth 2 i) ; ender-char, true if second part
5698 ; is with matching chars []
5699 go (nth 4 i) ; There is a 1-char part after the end
5700 i (car i) ; intermediate point
5702 ;; Before end of the second part if non-matching: ///
5703 tail (if (and i (not tag))
5705 e (if i i e1) ; end of the first part
5706 qtag nil ; need to preserve backslashitis
5707 is-x-REx nil is-o-REx nil); REx has //x //o modifiers
5708 ;; If s{} (), then b/b1 are at "{", "(", e1/i after ")", "}"
5709 ;; Commenting \\ is dangerous, what about ( ?
5711 (eq (char-after i) ?\\)
5713 (and (if go (looking-at ".\\sw*x")
5714 (looking-at "\\sw*x")) ; qr//x
5716 (and (if go (looking-at ".\\sw*o")
5717 (looking-at "\\sw*o")) ; //o
5720 ;; Considered as 1arg form
5722 (cperl-commentify b (point) t)
5723 (put-text-property b (point) 'syntax-type 'string)
5725 ;; ignore other text properties:
5726 (string-match "^qw$" argument))
5727 (put-text-property b (point) 'indentable t))
5729 (setq e1 (cperl-1+ e1))
5732 (cperl-commentify b i t)
5733 (if (looking-at "\\sw*e") ; s///e
5735 ;; Cache the syntax info...
5736 (setq cperl-syntax-state (cons state-point state))
5739 (car (cperl-find-pods-heres b1 (1- (point)) t end))
5741 (goto-char (1+ max)))
5742 (if (and tag (eq (preceding-char) ?\>))
5744 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
5745 (cperl-modify-syntax-type i cperl-st-bra)))
5746 (put-text-property b i 'syntax-type 'string)
5747 (put-text-property i (point) 'syntax-type 'multiline)
5749 (put-text-property b i 'indentable t)))
5750 (cperl-commentify b1 (point) t)
5751 (put-text-property b (point) 'syntax-type 'string)
5753 (put-text-property b i 'indentable t))
5755 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
5757 ;; Now: tail: if the second part is non-matching without ///e
5758 (if (eq (char-syntax (following-char)) ?w)
5760 (forward-word 1) ; skip modifiers s///s
5761 (if tail (cperl-commentify tail (point) t))
5762 (cperl-postpone-fontification
5763 e1 (point) 'face my-cperl-REx-modifiers-face)))
5764 ;; Check whether it is m// which means "previous match"
5765 ;; and highlight differently
5767 (and (string-match "^\\([sm]?\\|qr\\)$" argument)
5768 (or (not (= (length argument) 0))
5772 ;; split // *is* using zero-pattern
5778 (not (looking-at "split\\>")))
5780 (cperl-postpone-fontification
5781 b e 'face font-lock-warning-face)
5782 (if (or i2 ; Has 2 args
5783 (and cperl-fontify-m-as-s
5785 (string-match "^\\(m\\|qr\\)$" argument)
5786 (and (eq 0 (length argument))
5787 (not (eq ?\< (char-after b)))))))
5789 (cperl-postpone-fontification
5790 b (cperl-1+ b) 'face my-cperl-delimiters-face)
5791 (cperl-postpone-fontification
5792 (1- e) e 'face my-cperl-delimiters-face)))
5793 (if (and is-REx cperl-regexp-scan)
5794 ;; Process RExen: embedded comments, charclasses and ]
5795 ;;;/\3333\xFg\x{FFF}a\ppp\PPP\qqq\C\99f(?{ foo })(??{ foo })/;
5796 ;;;/a\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
5797 ;;;/(?<=foo)(?<!bar)(x)(?:$ab|\$\/)$|\\\b\x888\776\[\:$/xxx;
5798 ;;;m?(\?\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
5799 ;;;m$(^ab[c]\$)$ + m+(^ab[c]\$\+)+ + m](^ab[c\]$|.+)] + m)(^ab[c]$|.+\));
5800 ;;;m^a[\^b]c^ + m.a[^b]\.c.;
5804 (cperl-look-at-leading-count is-x-REx e)
5808 (if (eq (char-after b) ?\#)
5809 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
5810 "\\((\\?#\\)\\|\\(#\\)")
5811 ;; keep the same count: add a fake group
5812 (if (eq (char-after b) ?\#)
5813 "\\((\\?\\\\#\\)\\(\\)"
5814 "\\((\\?#\\)\\(\\)"))
5820 ;; XXXX Will not be able to use it in s)))
5821 (if (eq (char-after b) ?\) )
5822 "\\())))\\)" ; Will never match
5823 (if (eq (char-after b) ?? )
5824 ;;"\\((\\\\\\?\\(\\\\\\?\\)?{\\)"
5825 "\\((\\\\\\?\\\\\\?{\\|()\\\\\\?{\\)"
5826 "\\((\\?\\??{\\)")) ; 5= (??{ (?{
5827 "\\|" ; 6= 0-length, 7: name, 8,9:code, 10:group
5828 "\\(" ;; XXXX 1-char variables, exc. |()\s
5831 "[_a-zA-Z:][_a-zA-Z0-9:]*"
5833 "{[^{}]*}" ; only one-level allowed
5837 "\\(" ;;8,9:code part of array/hash elt
5843 ;; XXXX: what if u is delim?
5851 "\\\\[luLUEQbBAzZG]"
5854 "\\(" ; 10 group opener follower
5855 "\\?\\((\\?\\)" ; 11: in (?(?=C)A|B)
5857 "\\?[:=!>?{]" ; "?" something
5859 "\\?[-imsx]+[:)]" ; (?i) (?-s:.)
5861 "\\?([0-9]+)" ; (?(1)foo|bar)
5869 "\\\\\\(.\\)" ; 12=\SYMBOL
5872 (and (< (point) (1- e))
5873 (re-search-forward hairy-RE (1- e) 'to-end))
5874 (goto-char (match-beginning 0))
5875 (setq REx-subgr-start (point)
5876 was-subgr (following-char))
5878 ((match-beginning 6) ; 0-length builtins, groups
5879 (goto-char (match-end 0))
5880 (if (match-beginning 11)
5881 (goto-char (match-beginning 11)))
5884 (cperl-postpone-fontification
5885 (match-beginning 0) (point)
5888 ((eq was-subgr ?\) )
5893 (if (if (eq (char-after b) ?? )
5894 (looking-at "(\\\\\\?")
5895 (eq (char-after (1+ (point))) ?\?))
5896 my-cperl-REx-0length-face
5897 my-cperl-REx-ctl-face)
5898 font-lock-warning-face))
5899 (error font-lock-warning-face)))
5900 ((eq was-subgr ?\| )
5901 my-cperl-REx-ctl-face)
5902 ((eq was-subgr ?\$ )
5903 (if (> (point) (1+ REx-subgr-start))
5906 (match-beginning 0) (point)
5909 (if (and (eq (match-beginning 0)
5913 font-lock-variable-name-face)
5914 my-cperl-REx-spec-char-face))
5915 ((memq was-subgr (append "^." nil) )
5916 my-cperl-REx-spec-char-face)
5917 ((eq was-subgr ?\( )
5918 (if (not (match-beginning 10))
5919 my-cperl-REx-ctl-face
5920 my-cperl-REx-0length-face))
5921 (t my-cperl-REx-0length-face)))
5922 (if (and (memq was-subgr (append "(|" nil))
5923 (not (string-match "(\\?[-imsx]+)"
5925 (cperl-look-at-leading-count is-x-REx e))
5926 (setq was-subgr nil)) ; We do stuff here
5927 ((match-beginning 12) ; \SYMBOL
5931 ;; How many chars to not highlight:
5932 ;; 0-len special-alnums in other branch =>
5933 ;; Generic: \non-alnum (1), \alnum (1+face)
5934 ;; Is-delim: \non-alnum (1/spec-2) alnum-1 (=what hai)
5935 (setq REx-subgr-start (point)
5936 qtag (preceding-char))
5937 (cperl-postpone-fontification
5938 (- (point) 2) (- (point) 1) 'face
5940 (append "ghijkmoqvFHIJKMORTVY" nil))
5941 font-lock-warning-face
5942 my-cperl-REx-0length-face))
5943 (if (and (eq (char-after b) qtag)
5944 (memq qtag (append ".])^$|*?+" nil)))
5946 (if (and cperl-use-syntax-table-text-property
5949 REx-subgr-start (1- (point))
5950 'syntax-table cperl-st-punct))
5951 (cperl-postpone-fontification
5952 (1- (point)) (point) 'face
5953 ; \] can't appear below
5954 (if (memq qtag (append ".]^$" nil))
5955 'my-cperl-REx-spec-char-face
5956 (if (memq qtag (append "*?+" nil))
5957 'my-cperl-REx-0length-face
5958 'my-cperl-REx-ctl-face))))) ; )|
5959 ;; Test for arguments:
5961 ;; This is not pretty: the 5.8.7 logic:
5962 ;; \0numx -> octal (up to total 3 dig)
5963 ;; \DIGIT -> backref unless \0
5964 ;; \DIGITs -> backref if legal
5965 ;; otherwise up to 3 -> octal
5966 ;; Do not try to distinguish, we guess
5967 ((or (and (memq qtag (append "01234567" nil))
5969 "\\=[01234567]?[01234567]?"
5971 (and (memq qtag (append "89" nil))
5973 "\\=[0123456789]*" (1- e) 'to-end))
5976 "\\=[0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}"
5978 (and (memq qtag (append "pPN" nil))
5979 (re-search-forward "\\={[^{}]+}\\|."
5981 (eq (char-syntax qtag) ?w))
5982 (cperl-postpone-fontification
5983 (1- REx-subgr-start) (point)
5984 'face my-cperl-REx-length1-face))))
5985 (setq was-subgr nil)) ; We do stuff here
5986 ((match-beginning 3) ; [charclass]
5988 (if (eq (char-after b) ?^ )
5989 (and (eq (following-char) ?\\ )
5990 (eq (char-after (cperl-1+ (point)))
5993 (and (eq (following-char) ?^ )
5995 (setq argument b ; continue?
5996 tag nil ; list of POSIX classes
5998 (if (eq (char-after b) ?\] )
5999 (and (eq (following-char) ?\\ )
6000 (eq (char-after (cperl-1+ (point)))
6002 (setq qtag (1+ qtag))
6004 (and (eq (following-char) ?\] )
6006 ;; Apparently, I can't put \] into a charclass
6007 ;; in m]]: m][\\\]\]] produces [\\]]
6008 ;;; POSIX? [:word:] [:^word:] only inside []
6009 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]")
6013 (if (eq (char-after b) ?\] )
6014 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]"
6015 "\\=\\(\\\\.\\|[^]\\\\]\\)*]")
6017 ;; Is this ] an end of POSIX class?
6020 (search-backward "[" argument t)
6021 (< REx-subgr-start (point))
6023 (and ; Should work with delim = \
6024 (eq (preceding-char) ?\\ )
6025 (= (% (skip-chars-backward
6029 ((eq (char-after b) ?\] )
6030 "\\\\*\\[:\\^?\\sw+:\\\\\\]")
6031 ((eq (char-after b) ?\: )
6032 "\\\\*\\[\\\\:\\^?\\sw+\\\\:]")
6033 ((eq (char-after b) ?^ )
6034 "\\\\*\\[:\\(\\\\\\^\\)?\\sw+:\]")
6035 ((eq (char-syntax (char-after b))
6038 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\"
6039 (char-to-string (char-after b))
6041 (t "\\\\*\\[:\\^?\\sw*:]")))
6042 (setq argument (point))))
6043 (setq tag (cons (cons argument (point))
6045 argument (point)) ; continue
6046 (setq argument nil)))
6048 (message "Couldn't find end of charclass in a REx, pos=%s"
6050 (if (and cperl-use-syntax-table-text-property
6051 (> (- (point) 2) REx-subgr-start))
6053 (1+ REx-subgr-start) (1- (point))
6054 'syntax-table cperl-st-punct))
6055 (cperl-postpone-fontification
6056 REx-subgr-start qtag
6057 'face my-cperl-REx-spec-char-face)
6058 (cperl-postpone-fontification
6059 (1- (point)) (point) 'face
6060 my-cperl-REx-spec-char-face)
6061 (if (eq (char-after b) ?\] )
6062 (cperl-postpone-fontification
6063 (- (point) 2) (1- (point))
6064 'face my-cperl-REx-0length-face))
6066 (cperl-postpone-fontification
6067 (car (car tag)) (cdr (car tag))
6068 'face my-cperl-REx-length1-face)
6069 (setq tag (cdr tag)))
6070 (setq was-subgr nil)) ; did facing already
6072 ((and (match-beginning 2) ; #-comment
6073 (/= (match-beginning 2) (match-end 2)))
6074 (beginning-of-line 2)
6076 (goto-char (1- e))))
6077 ((match-beginning 4) ; character "]"
6078 (setq was-subgr nil) ; We do stuff here
6079 (goto-char (match-end 0))
6080 (if cperl-use-syntax-table-text-property
6082 (1- (point)) (point)
6083 'syntax-table cperl-st-punct))
6084 (cperl-postpone-fontification
6085 (1- (point)) (point)
6086 'face font-lock-warning-face))
6087 ((match-beginning 5) ; before (?{}) (??{})
6088 (setq tag (match-end 0))
6090 (cperl-forward-group-in-re st-l))
6092 (setq qtag "no matching `)' found"))
6093 (and (not (eq (char-after (- (point) 2))
6095 (setq qtag "Can't find })")))
6099 (cperl-postpone-fontification
6100 (1- tag) (1- (point))
6101 'face font-lock-variable-name-face)
6102 (cperl-postpone-fontification
6103 REx-subgr-start (1- tag)
6104 'face my-cperl-REx-spec-char-face)
6105 (cperl-postpone-fontification
6106 (1- (point)) (point)
6107 'face my-cperl-REx-spec-char-face)
6108 (if cperl-use-syntax-table-text-property
6111 (- (point) 2) (1- (point))
6112 'syntax-table cperl-st-cfence)
6114 (+ REx-subgr-start 2)
6115 (+ REx-subgr-start 3)
6116 'syntax-table cperl-st-cfence))))
6117 (setq was-subgr nil))
6119 ;; Inside "(" and "\" arn't special in any way
6120 ;; Works also if the outside delimiters are ().
6121 (or;;(if (eq (char-after b) ?\) )
6122 ;;(re-search-forward
6123 ;; "[^\\\\]\\(\\\\\\\\\\)*\\\\)"
6125 (search-forward ")" (1- e) 'toend)
6128 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
6134 (setq REx-subgr-end (point))
6136 REx-subgr-start REx-subgr-end nil)
6137 (cperl-postpone-fontification
6138 REx-subgr-start REx-subgr-end
6139 'face font-lock-comment-face))))))
6140 (if (and is-REx is-x-REx)
6141 (put-text-property (1+ b) (1- e)
6142 'syntax-subtype 'x-REx)))
6143 (if (and i2 e1 b1 (> e1 b1))
6144 (progn ; No errors finding the second part...
6145 (cperl-postpone-fontification
6146 (1- e1) e1 'face my-cperl-delimiters-face)
6147 (if (assoc (char-after b) cperl-starters)
6149 (cperl-postpone-fontification
6150 b1 (1+ b1) 'face my-cperl-delimiters-face)
6151 (put-text-property b1 (1+ b1)
6155 ((match-beginning 17) ; sub with prototype or attribute
6156 ;; 1+6+2+1+1=11 extra () before this (sub with proto/attr):
6157 ;;"\\<sub\\>\\(" ;12
6158 ;; cperl-white-and-comment-rex ;13
6159 ;; "\\([a-zA-Z_:'0-9]+\\)\\)?" ; name ;14
6160 ;;"\\(" cperl-maybe-white-and-comment-rex ;15,16
6161 ;; "\\(([^()]*)\\|:[^:]\\)\\)" ; 17:proto or attribute start
6162 (setq b1 (match-beginning 14) e1 (match-end 14))
6163 (if (memq (char-after (1- b))
6164 '(?\$ ?\@ ?\% ?\& ?\*))
6167 (if (eq (char-after (match-beginning 17)) ?\( )
6169 (cperl-commentify ; Prototypes; mark as string
6170 (match-beginning 17) (match-end 17) t)
6171 (goto-char (match-end 0))
6172 ;; Now look for attributes after prototype:
6173 (forward-comment (buffer-size))
6174 (and (looking-at ":[^:]")
6175 (cperl-find-sub-attrs st-l b1 e1 b)))
6176 ;; treat attributes without prototype
6177 (goto-char (match-beginning 17))
6178 (cperl-find-sub-attrs st-l b1 e1 b))))
6179 ;; 1+6+2+1+1+6+1=18 extra () before this:
6180 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
6181 ((match-beginning 19) ; old $abc'efg syntax
6182 (setq bb (match-end 0))
6183 ;;;(if (nth 3 state) nil ; in string
6184 (put-text-property (1- bb) bb 'syntax-table cperl-st-word)
6186 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
6187 ;; "__\\(END\\|DATA\\)__"
6188 ((match-beginning 20) ; __END__, __DATA__
6189 (setq bb (match-end 0))
6190 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
6191 (cperl-commentify b bb nil)
6193 ;; "\\\\\\(['`\"($]\\)"
6194 ((match-beginning 21)
6195 ;; Trailing backslash; make non-quoting outside string/comment
6196 (setq bb (match-end 0))
6198 (skip-chars-backward "\\\\")
6199 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
6200 (cperl-modify-syntax-type b cperl-st-punct)
6202 (t (error "Error in regexp of the sniffer")))
6203 (if (> (point) stop-point)
6206 (message "Garbage after __END__/__DATA__ ignored")
6207 (message "Unbalanced syntax found while scanning")
6208 (or (car err-l) (setcar err-l b)))
6209 (goto-char stop-point))))
6210 (setq cperl-syntax-state (cons state-point state)
6211 ;; Do not mark syntax as done past tmpend???
6212 cperl-syntax-done-to (or tmpend (max (point) max)))
6213 ;;(message "state-at=%s, done-to=%s" state-point cperl-syntax-done-to)
6215 (if (car err-l) (goto-char (car err-l))
6217 (message "Scanning for \"hard\" Perl constructions... done"))))
6218 (and (buffer-modified-p)
6220 (set-buffer-modified-p nil))
6221 (set-syntax-table cperl-mode-syntax-table))
6222 (list (car err-l) overshoot)))
6224 (defun cperl-find-pods-heres-region (min max)
6226 (cperl-find-pods-heres min max))
6228 (defun cperl-backward-to-noncomment (lim)
6229 ;; Stops at lim or after non-whitespace that is not in comment
6230 ;; XXXX Wrongly understands end-of-multiline strings with # as comment
6232 (while (and (not stop) (> (point) (or lim (point-min))))
6233 (skip-chars-backward " \t\n\f" lim)
6236 (if (memq (setq pr (get-text-property (point) 'syntax-type))
6237 '(pod here-doc here-doc-delim))
6239 (cperl-unwind-to-safe nil)
6240 (setq pr (get-text-property (point) 'syntax-type))))
6241 (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
6242 (not (memq pr '(string prestring))))
6243 (progn (cperl-to-comment-or-eol) (bolp))
6245 (skip-chars-backward " \t")
6246 (if (< p (point)) (goto-char p))
6249 ;; Used only in `cperl-calculate-indent'...
6250 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
6251 ;; Positions is before ?\{. Checks whether it starts a block.
6252 ;; No save-excursion! This is more a distinguisher of a block/hash ref...
6253 (cperl-backward-to-noncomment (point-min))
6254 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
6255 ; Label may be mixed up with `$blah :'
6256 (save-excursion (cperl-after-label))
6257 (get-text-property (cperl-1- (point)) 'attrib-group)
6258 (and (memq (char-syntax (preceding-char)) '(?w ?_))
6261 ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
6262 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
6263 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
6264 ;; sub bless::foo {}
6266 (cperl-backward-to-noncomment (point-min))
6267 (and (eq (preceding-char) ?b)
6270 (looking-at "sub[ \t\n\f#]")))))))))
6272 ;;; What is the difference of (cperl-after-block-p lim t) and (cperl-block-p)?
6273 ;;; No save-excursion; condition-case ... In (cperl-block-p) the block
6274 ;;; may be a part of an in-statement construct, such as
6275 ;;; ${something()}, print {FH} $data.
6276 ;;; Moreover, one takes positive approach (looks for else,grep etc)
6277 ;;; another negative (looks for bless,tr etc)
6278 (defun cperl-after-block-p (lim &optional pre-block)
6279 "Return true if the preceeding } (if PRE-BLOCK, following {) delimits a block.
6280 Would not look before LIM. Assumes that LIM is a good place to begin a
6281 statement. The kind of block we treat here is one after which a new
6282 statement would start; thus the block in ${func()} does not count."
6286 (or pre-block (forward-sexp -1))
6287 (cperl-backward-to-noncomment lim)
6288 (or (eq (point) lim)
6289 ;; if () {} // sub f () {} // sub f :a(') {}
6290 (eq (preceding-char) ?\) )
6292 (save-excursion (cperl-after-label))
6294 (get-text-property (cperl-1- (point)) 'attrib-group)
6295 (if (memq (char-syntax (preceding-char)) '(?w ?_)) ; else {}
6298 ;; else {} but not else::func {}
6299 (or (and (looking-at "\\(else\\|continue\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
6300 (not (looking-at "\\(\\sw\\|_\\)+::")))
6303 (cperl-backward-to-noncomment lim)
6304 (and (eq (preceding-char) ?b)
6307 (looking-at "sub[ \t\n\f#]"))))))
6308 ;; What preceeds is not word... XXXX Last statement in sub???
6309 (cperl-after-expr-p lim))))
6312 (defun cperl-after-expr-p (&optional lim chars test)
6313 "Return true if the position is good for start of expression.
6314 TEST is the expression to evaluate at the found position. If absent,
6315 CHARS is a string that contains good characters to have before us (however,
6316 `}' is treated \"smartly\" if it is not in the list)."
6317 (let ((lim (or lim (point-min)))
6319 (cperl-update-syntaxification (point) (point))
6321 (while (and (not stop) (> (point) lim))
6322 (skip-chars-backward " \t\n\f" lim)
6325 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
6326 ;; '(pod here-doc here-doc-delim))
6327 (if (get-text-property (point) 'here-doc-group)
6330 (cperl-beginning-of-property (point) 'here-doc-group))
6331 (beginning-of-line 0)))
6332 (if (get-text-property (point) 'in-pod)
6335 (cperl-beginning-of-property (point) 'in-pod))
6336 (beginning-of-line 0)))
6337 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
6338 ;; Else: last iteration, or a label
6339 (cperl-to-comment-or-eol) ; Will not move past "." after a format
6340 (skip-chars-backward " \t")
6341 (if (< p (point)) (goto-char p))
6343 (if (and (eq (preceding-char) ?:)
6346 (skip-chars-backward " \t\n\f" lim)
6347 (memq (char-syntax (preceding-char)) '(?w ?_))))
6348 (forward-sexp -1) ; Possibly label. Skip it
6351 (or (bobp) ; ???? Needed
6353 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
6355 (if test (eval test)
6356 (or (memq (preceding-char) (append (or chars "{;") nil))
6357 (and (eq (preceding-char) ?\})
6358 (cperl-after-block-p lim))
6359 (and (eq (following-char) ?.) ; in format: see comment above
6360 (eq (get-text-property (point) 'syntax-type)
6363 (defun cperl-backward-to-start-of-expr (&optional lim)
6366 (while (and (or (not lim)
6368 (not (cperl-after-expr-p lim)))
6370 ;; May be after $, @, $# etc of a variable
6371 (skip-chars-backward "$@%#")))
6374 (defun cperl-at-end-of-expr (&optional lim)
6375 ;; Since the SEXP approach below is very fragile, do some overengineering
6376 (or (looking-at (concat cperl-maybe-white-and-comment-rex "[;}]"))
6379 ;; If nothing interesting after, does as (forward-sexp -1);
6380 ;; otherwise fails, or ends at a start of following sexp.
6381 ;; XXXX PROBLEMS: if what follows (after ";") @FOO, or ${bar}
6382 ;; may be stuck after @ or $; just put some stupid workaround now:
6386 (while (memq (preceding-char) (append "%&@$*" nil))
6389 (cperl-after-expr-p lim))))
6392 (defun cperl-forward-to-end-of-expr (&optional lim)
6396 (while (and (< (point) (or lim (point-max)))
6397 (not (cperl-at-end-of-expr)))
6401 (defun cperl-backward-to-start-of-continued-exp (lim)
6402 (if (memq (preceding-char) (append ")]}\"'`" nil))
6405 (if (<= (point) lim)
6406 (goto-char (1+ lim)))
6407 (skip-chars-forward " \t"))
6409 (defun cperl-after-block-and-statement-beg (lim)
6410 ;; We assume that we are after ?\}
6412 (cperl-after-block-p lim)
6415 (cperl-backward-to-noncomment (point-min))
6418 (not (= (char-syntax (preceding-char)) ?w))
6423 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
6426 (defvar innerloop-done nil)
6427 (defvar last-depth nil)
6429 (defun cperl-indent-exp ()
6430 "Simple variant of indentation of continued-sexp.
6432 Will not indent comment if it starts at `comment-indent' or looks like
6433 continuation of the comment on the previous line.
6435 If `cperl-indent-region-fix-constructs', will improve spacing on
6436 conditional/loop constructs."
6439 (let ((tmp-end (progn (end-of-line) (point))) top done)
6444 ;; Plan A: if line has an unfinished paren-group, go to end-of-group
6445 (while (= -1 (nth 0 (parse-partial-sexp (point) tmp-end -1)))
6446 (setq top (point))) ; Get the outermost parenths in line
6448 (while (< (point) tmp-end)
6449 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
6450 (or (eolp) (forward-sexp 1)))
6451 (if (> (point) tmp-end) ; Yes, there an unfinished block
6453 (if (eq ?\) (preceding-char))
6454 (progn ;; Plan B: find by REGEXP block followup this line
6459 (if (eq (following-char) ?$ ) ; for my $var (list)
6462 (if (looking-at "\\(my\\|local\\|our\\)\\>")
6463 (forward-sexp -1))))
6465 (concat "\\(\\elsif\\|if\\|unless\\|while\\|until"
6466 "\\|for\\(each\\)?\\>\\(\\("
6467 cperl-maybe-white-and-comment-rex
6468 "\\(my\\|local\\|our\\)\\)?"
6469 cperl-maybe-white-and-comment-rex
6470 "\\$[_a-zA-Z0-9]+\\)?\\)\\>"))
6474 (setq top (point)))))
6475 (error (setq done t)))
6477 (if (looking-at ; Try Plan C: continuation block
6478 (concat cperl-maybe-white-and-comment-rex
6479 "\\<\\(else\\|elsif\|continue\\)\\>"))
6481 (goto-char (match-end 0))
6484 (setq tmp-end (point))))
6488 (setq tmp-end (point))))
6490 (setq tmp-end (point-marker)))
6491 (if cperl-indent-region-fix-constructs
6492 (cperl-fix-line-spacing tmp-end))
6493 (cperl-indent-region (point) tmp-end))))
6495 (defun cperl-fix-line-spacing (&optional end parse-data)
6496 "Improve whitespace in a conditional/loop construct.
6497 Returns some position at the last line."
6500 (setq end (point-max)))
6501 (let ((ee (save-excursion (end-of-line) (point)))
6502 (cperl-indent-region-fix-constructs
6503 (or cperl-indent-region-fix-constructs 1))
6504 p pp ml have-brace ret)
6511 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
6512 (setq have-brace (save-excursion (search-forward "}" ee t)))))
6513 nil ; Do not need to do anything
6517 (if cperl-merge-trailing-else
6519 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
6521 (search-forward "}")
6523 (skip-chars-forward " \t\n")
6524 (delete-region p (point))
6525 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6526 (beginning-of-line)))
6527 (if (looking-at "[ \t]*}[ \t]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
6529 (search-forward "}")
6530 (delete-horizontal-space)
6533 (if (cperl-indent-line parse-data)
6535 (cperl-fix-line-spacing end parse-data)
6536 (setq ret (point)))))))
6539 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
6541 (search-forward "}")
6542 (delete-horizontal-space)
6543 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6544 (beginning-of-line)))
6548 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
6551 (delete-horizontal-space)
6552 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6553 (beginning-of-line)))
6557 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
6560 (delete-horizontal-space)
6561 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6562 (beginning-of-line)))
6564 ;; foreach my $var (
6566 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
6569 (delete-horizontal-space)
6571 (make-string cperl-indent-region-fix-constructs ?\ ))
6572 (beginning-of-line)))
6573 ;; Looking at (with or without "}" at start, ending after "({"):
6574 ;; } foreach my $var () OR {
6576 "[ \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]*{")
6578 (setq ml (match-beginning 8)) ; "(" or "{" after control word
6579 (re-search-forward "[({]")
6582 (if (eq (following-char) ?\( )
6585 (setq pp (point))) ; past parenth-group
6586 ;; after `else' or nothing
6587 (if ml ; after `else'
6588 (skip-chars-backward " \t\n")
6589 (beginning-of-line))
6591 ;; Now after the sexp before the brace
6592 ;; Multiline expr should be special
6593 (setq ml (and pp (save-excursion (goto-char p)
6594 (search-forward "\n" pp t))))
6595 (if (and (or (not pp) (< pp end)) ; Do not go too far...
6596 (looking-at "[ \t\n]*{"))
6599 ((bolp) ; Were before `{', no if/else/etc
6601 ((looking-at "\\(\t*\\| [ \t]+\\){") ; Not exactly 1 SPACE
6602 (delete-horizontal-space)
6604 cperl-extra-newline-before-brace-multiline
6605 cperl-extra-newline-before-brace)
6607 (delete-horizontal-space)
6610 (if (cperl-indent-line parse-data)
6612 (cperl-fix-line-spacing end parse-data)
6613 (setq ret (point)))))
6615 (make-string cperl-indent-region-fix-constructs ?\ ))))
6616 ((and (looking-at "[ \t]*\n")
6618 cperl-extra-newline-before-brace-multiline
6619 cperl-extra-newline-before-brace)))
6621 (skip-chars-forward " \t\n")
6622 (delete-region pp (point))
6624 (make-string cperl-indent-region-fix-constructs ?\ )))
6625 ((and (looking-at "[\t ]*{")
6626 (if ml cperl-extra-newline-before-brace-multiline
6627 cperl-extra-newline-before-brace))
6628 (delete-horizontal-space)
6631 (if (cperl-indent-line parse-data)
6633 (cperl-fix-line-spacing end parse-data)
6634 (setq ret (point))))))
6635 ;; Now we are before `{'
6636 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
6638 (skip-chars-forward " \t\n")
6643 (setq ml (search-forward "\n" p t))
6644 (if (or cperl-break-one-line-blocks-when-indent ml)
6645 ;; not good: multi-line BLOCK
6648 (delete-horizontal-space)
6651 (if (cperl-indent-line parse-data)
6652 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
6654 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
6655 ;; Now check whether there is a hanging `}'
6659 cperl-fix-hanging-brace-when-indent
6661 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
6665 (if (and (<= (point) pp)
6666 (eq (preceding-char) ?\} )
6667 (cperl-after-block-and-statement-beg (point-min)))
6674 (skip-chars-backward " \t")
6676 ;; `}' was the first thing on the line, insert NL *after* it.
6678 (cperl-indent-line parse-data)
6679 (search-forward "}")
6680 (delete-horizontal-space)
6682 (delete-horizontal-space)
6683 (or (eq (preceding-char) ?\;)
6685 (and (eq (preceding-char) ?\} )
6686 (cperl-after-block-p (point-min)))
6690 (if (cperl-indent-line parse-data)
6691 (setq ret (cperl-fix-line-spacing end parse-data)))
6692 (beginning-of-line)))))
6695 (defvar cperl-update-start) ; Do not need to make them local
6696 (defvar cperl-update-end)
6697 (defun cperl-delay-update-hook (beg end old-len)
6698 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
6699 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
6701 (defun cperl-indent-region (start end)
6702 "Simple variant of indentation of region in CPerl mode.
6703 Should be slow. Will not indent comment if it starts at `comment-indent'
6704 or looks like continuation of the comment on the previous line.
6705 Indents all the lines whose first character is between START and END
6708 If `cperl-indent-region-fix-constructs', will improve spacing on
6709 conditional/loop constructs."
6711 (cperl-update-syntaxification end end)
6713 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
6714 (let ((indent-info (if cperl-emacs-can-parse
6715 (list nil nil nil) ; Cannot use '(), since will modify
6717 (pm 0) (imenu-scanning-message "Indenting... (%3d%%)")
6718 after-change-functions ; Speed it up!
6719 st comm old-comm-indent new-comm-indent p pp i empty)
6720 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
6722 (setq old-comm-indent (and (cperl-to-comment-or-eol)
6724 new-comm-indent old-comm-indent)
6726 (setq end (set-marker (make-marker) end)) ; indentation changes pos
6727 (or (bolp) (beginning-of-line 2))
6728 (or (fboundp 'imenu-progress-message)
6729 (message "Indenting... For feedback load `imenu'..."))
6730 (while (and (<= (point) end) (not (eobp))) ; bol to check start
6731 (and (fboundp 'imenu-progress-message)
6732 (imenu-progress-message
6733 pm (/ (* 100 (- (point) start)) (- end start -1))))
6736 (setq empty (looking-at "[ \t]*\n"))
6737 (and (setq comm (looking-at "[ \t]*#"))
6738 (or (eq (current-indentation) (or old-comm-indent
6740 (setq old-comm-indent nil))))
6741 (if (and old-comm-indent
6743 (= (current-indentation) old-comm-indent)
6744 (not (eq (get-text-property (point) 'syntax-type) 'pod))
6745 (not (eq (get-text-property (point) 'syntax-table)
6747 (let ((comment-column new-comm-indent))
6748 (indent-for-comment)))
6750 (setq i (cperl-indent-line indent-info))
6754 (if cperl-indent-region-fix-constructs
6755 (goto-char (cperl-fix-line-spacing end indent-info)))
6756 (if (setq old-comm-indent
6757 (and (cperl-to-comment-or-eol)
6758 (not (memq (get-text-property (point)
6761 (not (eq (get-text-property (point)
6765 (progn (indent-for-comment)
6766 (skip-chars-backward " \t")
6767 (skip-chars-backward "#")
6768 (setq new-comm-indent (current-column))))))))
6769 (beginning-of-line 2))
6770 (if (fboundp 'imenu-progress-message)
6771 (imenu-progress-message pm 100)
6773 ;; Now run the update hooks
6774 (and after-change-functions
6777 (goto-char cperl-update-end)
6780 (goto-char cperl-update-start)
6782 (delete-char -1))))))
6784 ;; Stolen from lisp-mode with a lot of improvements
6786 (defun cperl-fill-paragraph (&optional justify iteration)
6787 "Like \\[fill-paragraph], but handle CPerl comments.
6788 If any of the current line is a comment, fill the comment or the
6789 block of it that point is in, preserving the comment's initial
6790 indentation and initial hashes. Behaves usually outside of comment."
6792 (let (;; Non-nil if the current line contains a comment.
6794 fill-paragraph-function ; do not recurse
6795 ;; If has-comment, the appropriate fill-prefix for the comment.
6797 ;; Line that contains code and comment (or nil)
6799 c spaces len dc (comment-column comment-column))
6800 ;; Figure out what kind of comment we are looking at.
6805 ;; A line with nothing but a comment on it?
6806 ((looking-at "[ \t]*#[# \t]*")
6808 comment-fill-prefix (buffer-substring (match-beginning 0)
6811 ;; A line with some code, followed by a comment? Remember that the
6812 ;; semi which starts the comment shouldn't be part of a string or
6814 ((cperl-to-comment-or-eol)
6815 (setq has-comment t)
6816 (looking-at "#+[ \t]*")
6817 (setq start (point) c (current-column)
6819 (concat (make-string (current-column) ?\ )
6820 (buffer-substring (match-beginning 0) (match-end 0)))
6821 spaces (progn (skip-chars-backward " \t")
6822 (buffer-substring (point) start))
6823 dc (- c (current-column)) len (- start (point))
6824 start (point-marker))
6826 (insert (make-string dc ?-))))) ; Placeholder (to avoid splitting???)
6827 (if (not has-comment)
6828 (fill-paragraph justify) ; Do the usual thing outside of comment
6829 ;; Narrow to include only the comment, and then fill the region.
6832 ;; Find the first line we should include in the region to fill.
6833 (if start (progn (beginning-of-line) (point))
6835 (while (and (zerop (forward-line -1))
6836 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
6837 ;; We may have gone to far. Go forward again.
6838 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
6841 ;; Find the beginning of the first line past the region to fill.
6843 (while (progn (forward-line 1)
6844 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
6846 ;; Remove existing hashes
6847 (goto-char (point-min))
6848 (while (progn (forward-line 1) (< (point) (point-max)))
6849 (skip-chars-forward " \t")
6850 (if (looking-at "#+")
6852 (if (and (eq (point) (match-beginning 0))
6853 (not (eq (point) (match-end 0)))) nil
6855 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage"))
6856 (delete-char (- (match-end 0) (match-beginning 0))))))
6858 ;; Lines with only hashes on them can be paragraph boundaries.
6859 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
6860 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
6861 (fill-prefix comment-fill-prefix))
6862 (fill-paragraph justify)))
6867 (progn (delete-char dc) (insert spaces)))
6868 (if (or (= (current-column) c) iteration) nil
6869 (setq comment-column c)
6870 (indent-for-comment)
6871 ;; Repeat once more, flagging as iteration
6872 (cperl-fill-paragraph justify t))))))
6875 (defun cperl-do-auto-fill ()
6876 ;; Break out if the line is short enough
6877 (if (> (save-excursion
6881 (let ((c (save-excursion (beginning-of-line)
6882 (cperl-to-comment-or-eol) (point)))
6883 (s (memq (following-char) '(?\ ?\t))) marker)
6884 (if (>= c (point)) nil
6885 (setq marker (point-marker))
6886 (cperl-fill-paragraph)
6888 ;; Is not enough, sometimes marker is a start of line
6889 (if (bolp) (progn (re-search-forward "#+[ \t]*")
6890 (goto-char (match-end 0))))
6891 ;; Following space could have gone:
6892 (if (or (not s) (memq (following-char) '(?\ ?\t))) nil
6895 ;; Previous space could have gone:
6896 (or (memq (preceding-char) '(?\ ?\t)) (insert " "))))))
6898 (defun cperl-imenu-addback (lst &optional isback name)
6899 ;; We suppose that the lst is a DAG, unless the first element only
6900 ;; loops back, and ISBACK is set. Thus this function cannot be
6901 ;; applied twice without ISBACK set.
6902 (cond ((not cperl-imenu-addback) lst)
6905 (setq name "+++BACK+++"))
6906 (mapcar (lambda (elt)
6907 (if (and (listp elt) (listp (cdr elt)))
6909 ;; In the other order it goes up
6910 ;; one level only ;-(
6911 (setcdr elt (cons (cons name lst)
6913 (cperl-imenu-addback (cdr elt) t name))))
6914 (if isback (cdr lst) lst))
6917 (defun cperl-imenu--create-perl-index (&optional regexp)
6919 (require 'imenu) ; May be called from TAGS creator
6920 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
6921 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
6922 (index-meth-alist '()) meth
6923 packages ends-ranges p marker is-proto
6924 (prev-pos 0) is-pack index index1 name (end-range 0) package)
6925 (goto-char (point-min))
6927 (message "Scanning Perl for index")
6928 (imenu-progress-message prev-pos 0))
6929 (cperl-update-syntaxification (point-max) (point-max))
6930 ;; Search for the function
6931 (progn ;;save-match-data
6932 (while (re-search-forward
6933 (or regexp cperl-imenu--function-name-regexp-perl)
6936 (imenu-progress-message prev-pos))
6937 ;; 2=package-group, 5=package-name 8=sub-name
6939 ((and ; Skip some noise if building tags
6940 (match-beginning 5) ; package name
6941 ;;(eq (char-after (match-beginning 2)) ?p) ; package
6942 (not (save-match-data
6943 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
6946 (or (match-beginning 2)
6947 (match-beginning 8)) ; package or sub
6948 ;; Skip if quoted (will not skip multi-line ''-strings :-():
6949 (null (get-text-property (match-beginning 1) 'syntax-table))
6950 (null (get-text-property (match-beginning 1) 'syntax-type))
6951 (null (get-text-property (match-beginning 1) 'in-pod)))
6952 (setq is-pack (match-beginning 2))
6953 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
6954 ;; (goto-char (match-end 0))) ; Messes what follows
6957 (while (and ends-ranges (>= p (car ends-ranges)))
6958 ;; delete obsolete entries
6959 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
6960 (setq package (or (car packages) "")
6961 end-range (or (car ends-ranges) 0))
6962 (if is-pack ; doing "package"
6964 (if (match-beginning 5) ; named package
6965 (setq name (buffer-substring (match-beginning 5)
6968 (set-text-properties 0 (length name) nil name)
6970 package (concat name "::")
6971 name (concat "package " name))
6972 ;; Support nameless packages
6973 (setq name "package;" package ""))
6976 (parse-partial-sexp (point) (point-max) -1) (point))
6977 ends-ranges (cons end-range ends-ranges)
6978 packages (cons package packages)))
6980 (or (eq (following-char) ?\;)
6981 (eq 0 (get-text-property (point) 'attrib-group)))))
6982 ;; Skip this function name if it is a prototype declaration.
6983 (if (and is-proto (not is-pack)) nil
6986 (buffer-substring (match-beginning 8) (match-end 8)))
6987 (set-text-properties 0 (length name) nil name))
6988 (setq marker (make-marker))
6989 (set-marker marker (match-end (if is-pack 2 8)))
6991 ((string-match "[:']" name)
6993 ((> p end-range) nil)
6995 (setq name (concat package name) meth t)))
6996 (setq index (cons name marker))
6998 (push index index-pack-alist)
6999 (push index index-alist))
7000 (if meth (push index index-meth-alist))
7001 (push index index-unsorted-alist)))
7002 ((match-beginning 16) ; POD section
7003 (setq name (buffer-substring (match-beginning 17) (match-end 17))
7004 marker (make-marker))
7005 (set-marker marker (match-beginning 17))
7006 (set-text-properties 0 (length name) nil name)
7007 (setq name (concat (make-string
7008 (* 3 (- (char-after (match-beginning 16)) ?1))
7011 index (cons name marker))
7012 (setq index1 (cons (concat "=" name) (cdr index)))
7013 (push index index-pod-alist)
7014 (push index1 index-unsorted-alist)))))
7016 (imenu-progress-message prev-pos 100))
7018 (if (default-value 'imenu-sort-function)
7019 (sort index-alist (default-value 'imenu-sort-function))
7020 (nreverse index-alist)))
7021 (and index-pod-alist
7022 (push (cons "+POD headers+..."
7023 (nreverse index-pod-alist))
7025 (and (or index-pack-alist index-meth-alist)
7026 (let ((lst index-pack-alist) hier-list pack elt group name)
7027 ;; Remove "package ", reverse and uniquify.
7029 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
7030 (if (assoc name hier-list) nil
7031 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
7032 (setq lst index-meth-alist)
7034 (setq elt (car lst) lst (cdr lst))
7035 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
7036 (setq pack (substring (car elt) 0 (match-beginning 0)))
7037 (if (setq group (assoc pack hier-list))
7038 (if (listp (cdr group))
7039 ;; Have some functions already
7041 (cons (cons (substring
7043 (+ 2 (match-beginning 0)))
7046 (setcdr group (list (cons (substring
7048 (+ 2 (match-beginning 0)))
7052 (list (cons (substring
7054 (+ 2 (match-beginning 0)))
7057 (push (cons "+Hierarchy+..."
7060 (and index-pack-alist
7061 (push (cons "+Packages+..."
7062 (nreverse index-pack-alist))
7064 (and (or index-pack-alist index-pod-alist
7065 (default-value 'imenu-sort-function))
7066 index-unsorted-alist
7067 (push (cons "+Unsorted List+..."
7068 (nreverse index-unsorted-alist))
7070 (cperl-imenu-addback index-alist)))
7073 ;; Suggested by Mark A. Hershberger
7074 (defun cperl-outline-level ()
7075 (looking-at outline-regexp)
7076 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
7077 ;;;; 2=package-group, 5=package-name 8=sub-name 16=head-level
7078 ((match-beginning 2) 0) ; package
7079 ((match-beginning 8) 1) ; sub
7080 ((match-beginning 16)
7081 (- (char-after (match-beginning 16)) ?0)) ; headN ==> N
7082 (t 5))) ; should not happen
7085 (defvar cperl-compilation-error-regexp-alist
7086 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
7087 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
7089 "Alist that specifies how to match errors in perl output.")
7091 (if (fboundp 'eval-after-load)
7094 '(setq perl-compilation-error-regexp-alist
7095 cperl-compilation-error-regexp-alist)))
7098 (defun cperl-windowed-init ()
7099 "Initialization under windowed version."
7100 (cond ((featurep 'ps-print)
7101 (or cperl-faces-init
7103 (and (boundp 'font-lock-multiline)
7104 (setq cperl-font-lock-multiline t))
7105 (cperl-init-faces))))
7106 ((not cperl-faces-init)
7107 (add-hook 'font-lock-mode-hook
7110 (if (memq major-mode '(perl-mode cperl-mode))
7112 (or cperl-faces-init (cperl-init-faces)))))))
7113 (if (fboundp 'eval-after-load)
7116 '(or cperl-faces-init (cperl-init-faces)))))))
7118 (defun cperl-load-font-lock-keywords ()
7119 (or cperl-faces-init (cperl-init-faces))
7120 perl-font-lock-keywords)
7122 (defun cperl-load-font-lock-keywords-1 ()
7123 (or cperl-faces-init (cperl-init-faces))
7124 perl-font-lock-keywords-1)
7126 (defun cperl-load-font-lock-keywords-2 ()
7127 (or cperl-faces-init (cperl-init-faces))
7128 perl-font-lock-keywords-2)
7130 (defvar perl-font-lock-keywords-1 nil
7131 "Additional expressions to highlight in Perl mode. Minimal set.")
7132 (defvar perl-font-lock-keywords nil
7133 "Additional expressions to highlight in Perl mode. Default set.")
7134 (defvar perl-font-lock-keywords-2 nil
7135 "Additional expressions to highlight in Perl mode. Maximal set.")
7137 (defvar font-lock-background-mode)
7138 (defvar font-lock-display-type)
7139 (defun cperl-init-faces-weak ()
7140 ;; Allow `cperl-find-pods-heres' to run.
7141 (or (boundp 'font-lock-constant-face)
7142 (cperl-force-face font-lock-constant-face
7143 "Face for constant and label names"))
7144 (or (boundp 'font-lock-warning-face)
7145 (cperl-force-face font-lock-warning-face
7146 "Face for things which should stand out"))
7147 ;;(setq font-lock-constant-face 'font-lock-constant-face)
7150 (defun cperl-init-faces ()
7151 (condition-case errs
7153 (require 'font-lock)
7154 (and (fboundp 'font-lock-fontify-anchored-keywords)
7155 (featurep 'font-lock-extra)
7156 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
7157 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
7158 (if (fboundp 'font-lock-fontify-anchored-keywords)
7159 (setq font-lock-anchored t))
7161 t-font-lock-keywords
7163 (list "[ \t]+$" 0 cperl-invalid-face t)
7166 "\\(^\\|[^$@%&\\]\\)\\<\\("
7169 '("if" "until" "while" "elsif" "else" "unless" "for"
7170 "foreach" "continue" "exit" "die" "last" "goto" "next"
7171 "redo" "return" "local" "exec" "sub" "do" "dump" "use" "our"
7172 "require" "package" "eval" "my" "BEGIN" "END" "CHECK" "INIT")
7173 "\\|") ; Flow control
7174 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
7175 ; In what follows we use `type' style
7176 ; for overwritable builtins
7179 "\\(^\\|[^$@%&\\]\\)\\<\\("
7180 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
7181 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
7182 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
7183 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
7184 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
7185 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
7186 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
7187 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
7188 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
7189 ;; "gethostbyname" "gethostent" "getlogin"
7190 ;; "getnetbyaddr" "getnetbyname" "getnetent"
7191 ;; "getpeername" "getpgrp" "getppid" "getpriority"
7192 ;; "getprotobyname" "getprotobynumber" "getprotoent"
7193 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
7194 ;; "getservbyport" "getservent" "getsockname"
7195 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
7196 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
7197 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
7198 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
7199 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
7200 ;; "quotemeta" "rand" "read" "readdir" "readline"
7201 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
7202 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
7203 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
7204 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
7205 ;; "setpriority" "setprotoent" "setpwent" "setservent"
7206 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
7207 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
7208 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
7209 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
7210 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
7211 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
7212 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
7213 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
7214 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
7215 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
7216 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
7217 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
7218 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
7219 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
7220 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
7221 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
7222 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
7223 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
7224 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
7225 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
7226 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
7227 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
7228 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
7229 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
7230 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
7231 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
7232 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
7233 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
7234 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
7235 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
7236 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
7237 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
7238 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
7239 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
7240 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
7241 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
7242 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
7243 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
7244 "\\)\\>") 2 'font-lock-type-face)
7245 ;; In what follows we use `other' style
7246 ;; for nonoverwritable builtins
7247 ;; Somehow 's', 'm' are not auto-generated???
7250 "\\(^\\|[^$@%&\\]\\)\\<\\("
7251 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "chomp"
7252 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
7253 ;; "eval" "exists" "for" "foreach" "format" "goto"
7254 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
7255 ;; "no" "our" "package" "pop" "pos" "print" "printf" "push"
7256 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
7257 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
7258 ;; "undef" "unless" "unshift" "untie" "until" "use"
7260 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
7261 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
7262 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|INIT\\|if\\|keys\\|"
7263 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
7264 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
7265 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
7266 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
7267 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
7268 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
7269 "\\|[sm]" ; Added manually
7270 "\\)\\>") 2 'cperl-nonoverridable-face)
7271 ;; (mapconcat 'identity
7272 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
7273 ;; "#include" "#define" "#undef")
7275 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
7276 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
7277 ;; This highlights declarations and definitions differenty.
7278 ;; We do not try to highlight in the case of attributes:
7279 ;; it is already done by `cperl-find-pods-heres'
7280 (list (concat "\\<sub"
7281 cperl-white-and-comment-rex ; whitespace/comments
7282 "\\([^ \n\t{;()]+\\)" ; 2=name (assume non-anonymous)
7284 cperl-maybe-white-and-comment-rex ;whitespace/comments?
7285 "([^()]*)\\)?" ; prototype
7286 cperl-maybe-white-and-comment-rex ; whitespace/comments?
7288 2 (if cperl-font-lock-multiline
7289 '(if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
7290 'font-lock-function-name-face
7291 'font-lock-variable-name-face)
7292 ;; need to manually set 'multiline' for older font-locks
7294 (if (< 1 (count-lines (match-beginning 0)
7297 (+ 3 (match-beginning 0)) (match-end 0)
7298 'syntax-type 'multiline))
7299 (if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
7300 'font-lock-function-name-face
7301 'font-lock-variable-name-face))))
7302 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
7303 2 font-lock-function-name-face)
7304 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
7305 1 font-lock-function-name-face)
7306 (cond ((featurep 'font-lock-extra)
7307 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7308 (2 font-lock-string-face t)
7309 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
7311 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7312 (2 font-lock-string-face t)
7313 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7315 (1 font-lock-string-face t))))
7316 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7317 2 font-lock-string-face t)))
7318 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
7319 font-lock-string-face t)
7320 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
7321 font-lock-constant-face) ; labels
7322 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
7323 2 font-lock-constant-face)
7324 ;; Uncomment to get perl-mode-like vars
7325 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
7326 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
7327 ;;; (2 (cons font-lock-variable-name-face '(underline))))
7328 (cond ((featurep 'font-lock-extra)
7329 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
7330 (3 font-lock-variable-name-face)
7332 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
7333 (1 font-lock-variable-name-face)
7334 (2 '(restart 2 nil) nil t)))
7335 nil t))) ; local variables, multiple
7337 ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
7338 (` ((, (concat "\\<\\(my\\|local\\|our\\)"
7339 cperl-maybe-white-and-comment-rex
7341 cperl-maybe-white-and-comment-rex
7342 "\\)?\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
7343 (5 (, (if cperl-font-lock-multiline
7344 'font-lock-variable-name-face
7345 '(progn (setq cperl-font-lock-multiline-start
7346 (match-beginning 0))
7347 'font-lock-variable-name-face))))
7349 cperl-maybe-white-and-comment-rex
7351 cperl-maybe-white-and-comment-rex
7352 "\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
7353 ;; Bug in font-lock: limit is used not only to limit
7354 ;; searches, but to set the "extend window for
7355 ;; facification" property. Thus we need to minimize.
7356 (, (if cperl-font-lock-multiline
7357 '(if (match-beginning 3)
7359 (goto-char (match-beginning 3))
7365 (error nil)))) ; typeahead
7366 (1- (point))) ; report limit
7367 (forward-char -2)) ; disable continued expr
7368 '(if (match-beginning 3)
7369 (point-max) ; No limit for continuation
7370 (forward-char -2)))) ; disable continued expr
7371 (, (if cperl-font-lock-multiline
7374 ;; "my" may be already fontified (POD),
7375 ;; so cperl-font-lock-multiline-start is nil
7376 (if (or (not cperl-font-lock-multiline-start)
7378 cperl-font-lock-multiline-start
7382 (1+ cperl-font-lock-multiline-start) (point)
7383 'syntax-type 'multiline))
7384 (setq cperl-font-lock-multiline-start nil))))
7385 (3 font-lock-variable-name-face)))))
7386 (t '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
7387 3 font-lock-variable-name-face)))
7388 '("\\<for\\(each\\)?\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
7389 4 font-lock-variable-name-face)))
7391 t-font-lock-keywords-1
7392 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
7393 ;; not yet as of XEmacs 19.12, works with 21.1.11
7395 (not cperl-xemacs-p)
7396 (string< "21.1.9" emacs-version)
7397 (and (string< "21.1.10" emacs-version)
7398 (string< emacs-version "21.1.2")))
7400 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
7401 (if (eq (char-after (match-beginning 2)) ?%)
7404 t) ; arrays and hashes
7405 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
7407 (if (= (- (match-end 2) (match-beginning 2)) 1)
7408 (if (eq (char-after (match-beginning 3)) ?{)
7410 cperl-array-face) ; arrays and hashes
7411 font-lock-variable-name-face) ; Just to put something
7413 ("\\(@\\|\\$#\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
7414 (1 cperl-array-face)
7415 (2 font-lock-variable-name-face))
7416 ("\\(%\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
7418 (2 font-lock-variable-name-face))
7419 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
7420 ;;; Too much noise from \s* @s[ and friends
7421 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
7422 ;;(3 font-lock-function-name-face t t)
7424 ;; (if (cperl-slash-is-regexp)
7425 ;; font-lock-function-name-face 'default) nil t))
7427 (if cperl-highlight-variables-indiscriminately
7428 (setq t-font-lock-keywords-1
7429 (append t-font-lock-keywords-1
7430 (list '("\\([$*]{?\\sw+\\)" 1
7431 font-lock-variable-name-face)))))
7432 (setq perl-font-lock-keywords-1
7433 (if cperl-syntaxify-by-font-lock
7434 (cons 'cperl-fontify-update
7435 t-font-lock-keywords)
7436 t-font-lock-keywords)
7437 perl-font-lock-keywords perl-font-lock-keywords-1
7438 perl-font-lock-keywords-2 (append
7439 perl-font-lock-keywords-1
7440 t-font-lock-keywords-1)))
7441 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
7442 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
7443 (eval ; Avoid a warning
7444 '(font-lock-require-faces
7446 ;; Color-light Color-dark Gray-light Gray-dark Mono
7447 (list 'font-lock-comment-face
7448 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
7453 (list 'font-lock-string-face
7454 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
7459 (list 'font-lock-function-name-face
7461 "Blue" "LightSkyBlue" "Gray50" "LightGray"
7462 (cdr (assq 'background-color ; if mono
7463 (frame-parameters))))
7466 (cdr (assq 'foreground-color ; if mono
7467 (frame-parameters))))
7471 (list 'font-lock-variable-name-face
7472 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
7477 (list 'font-lock-type-face
7478 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
7483 (list 'font-lock-warning-face
7484 ["Pink" "Red" "Gray50" "LightGray"]
7491 (list 'font-lock-constant-face
7492 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
7497 (list 'cperl-nonoverridable-face
7498 ["chartreuse3" ("orchid1" "orange")
7504 (list 'cperl-array-face
7505 ["blue" "yellow" nil "Gray80"]
7506 ["lightyellow2" ("navy" "os2blue" "darkgreen")
7511 (list 'cperl-hash-face
7512 ["red" "red" nil "Gray80"]
7513 ["lightyellow2" ("navy" "os2blue" "darkgreen")
7518 ;; Do it the dull way, without choose-color
7519 (defvar cperl-guessed-background nil
7520 "Display characteristics as guessed by cperl.")
7521 ;; (or (fboundp 'x-color-defined-p)
7522 ;; (defalias 'x-color-defined-p
7523 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
7524 ;; ;; XEmacs >= 19.12
7525 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
7527 ;; (t 'x-valid-color-name-p))))
7528 (cperl-force-face font-lock-constant-face
7529 "Face for constant and label names")
7530 (cperl-force-face font-lock-variable-name-face
7531 "Face for variable names")
7532 (cperl-force-face font-lock-type-face
7533 "Face for data types")
7534 (cperl-force-face cperl-nonoverridable-face
7535 "Face for data types from another group")
7536 (cperl-force-face font-lock-warning-face
7537 "Face for things which should stand out")
7538 (cperl-force-face font-lock-comment-face
7539 "Face for comments")
7540 (cperl-force-face font-lock-function-name-face
7541 "Face for function names")
7542 (cperl-force-face cperl-hash-face
7544 (cperl-force-face cperl-array-face
7546 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
7547 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
7548 ;;(or (boundp 'font-lock-type-face)
7549 ;; (defconst font-lock-type-face
7550 ;; 'font-lock-type-face
7551 ;; "Face to use for data types."))
7552 ;;(or (boundp 'cperl-nonoverridable-face)
7553 ;; (defconst cperl-nonoverridable-face
7554 ;; 'cperl-nonoverridable-face
7555 ;; "Face to use for data types from another group."))
7556 ;;(if (not cperl-xemacs-p) nil
7557 ;; (or (boundp 'font-lock-comment-face)
7558 ;; (defconst font-lock-comment-face
7559 ;; 'font-lock-comment-face
7560 ;; "Face to use for comments."))
7561 ;; (or (boundp 'font-lock-keyword-face)
7562 ;; (defconst font-lock-keyword-face
7563 ;; 'font-lock-keyword-face
7564 ;; "Face to use for keywords."))
7565 ;; (or (boundp 'font-lock-function-name-face)
7566 ;; (defconst font-lock-function-name-face
7567 ;; 'font-lock-function-name-face
7568 ;; "Face to use for function names.")))
7570 (not (cperl-is-face 'cperl-array-face))
7571 (cperl-is-face 'font-lock-emphasized-face))
7572 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
7574 (not (cperl-is-face 'cperl-hash-face))
7575 (cperl-is-face 'font-lock-other-emphasized-face))
7576 (copy-face 'font-lock-other-emphasized-face
7579 (not (cperl-is-face 'cperl-nonoverridable-face))
7580 (cperl-is-face 'font-lock-other-type-face))
7581 (copy-face 'font-lock-other-type-face
7582 'cperl-nonoverridable-face))
7583 ;;(or (boundp 'cperl-hash-face)
7584 ;; (defconst cperl-hash-face
7586 ;; "Face to use for hashes."))
7587 ;;(or (boundp 'cperl-array-face)
7588 ;; (defconst cperl-array-face
7589 ;; 'cperl-array-face
7590 ;; "Face to use for arrays."))
7591 ;; Here we try to guess background
7593 (if (boundp 'font-lock-background-mode)
7594 font-lock-background-mode
7596 (face-list (and (fboundp 'face-list) (face-list))))
7597 ;;;; (fset 'cperl-is-face
7598 ;;;; (cond ((fboundp 'find-face)
7599 ;;;; (symbol-function 'find-face))
7601 ;;;; (function (lambda (face) (member face face-list))))
7603 ;;;; (function (lambda (face) (boundp face))))))
7604 (defvar cperl-guessed-background
7605 (if (and (boundp 'font-lock-display-type)
7606 (eq font-lock-display-type 'grayscale))
7609 "Background as guessed by CPerl mode")
7610 (and (not (cperl-is-face 'font-lock-constant-face))
7611 (cperl-is-face 'font-lock-reference-face)
7612 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
7613 (if (cperl-is-face 'font-lock-type-face) nil
7614 (copy-face 'default 'font-lock-type-face)
7616 ((eq background 'light)
7617 (set-face-foreground 'font-lock-type-face
7618 (if (x-color-defined-p "seagreen")
7621 ((eq background 'dark)
7622 (set-face-foreground 'font-lock-type-face
7623 (if (x-color-defined-p "os2pink")
7627 (set-face-background 'font-lock-type-face "gray90"))))
7628 (if (cperl-is-face 'cperl-nonoverridable-face)
7630 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
7632 ((eq background 'light)
7633 (set-face-foreground 'cperl-nonoverridable-face
7634 (if (x-color-defined-p "chartreuse3")
7637 ((eq background 'dark)
7638 (set-face-foreground 'cperl-nonoverridable-face
7639 (if (x-color-defined-p "orchid1")
7642 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
7643 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
7645 ;;; ((eq background 'light)
7646 ;;; (set-face-background 'font-lock-other-emphasized-face
7647 ;;; (if (x-color-defined-p "lightyellow2")
7649 ;;; (if (x-color-defined-p "lightyellow")
7651 ;;; "light yellow"))))
7652 ;;; ((eq background 'dark)
7653 ;;; (set-face-background 'font-lock-other-emphasized-face
7654 ;;; (if (x-color-defined-p "navy")
7656 ;;; (if (x-color-defined-p "darkgreen")
7658 ;;; "dark green"))))
7659 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
7660 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
7661 ;;; (copy-face 'bold 'font-lock-emphasized-face)
7663 ;;; ((eq background 'light)
7664 ;;; (set-face-background 'font-lock-emphasized-face
7665 ;;; (if (x-color-defined-p "lightyellow2")
7667 ;;; "lightyellow")))
7668 ;;; ((eq background 'dark)
7669 ;;; (set-face-background 'font-lock-emphasized-face
7670 ;;; (if (x-color-defined-p "navy")
7672 ;;; (if (x-color-defined-p "darkgreen")
7674 ;;; "dark green"))))
7675 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
7676 (if (cperl-is-face 'font-lock-variable-name-face) nil
7677 (copy-face 'italic 'font-lock-variable-name-face))
7678 (if (cperl-is-face 'font-lock-constant-face) nil
7679 (copy-face 'italic 'font-lock-constant-face))))
7680 (setq cperl-faces-init t))
7681 (error (message "cperl-init-faces (ignored): %s" errs))))
7684 (defun cperl-ps-print-init ()
7685 "Initialization of `ps-print' components for faces used in CPerl."
7686 (eval-after-load "ps-print"
7687 '(setq ps-bold-faces
7688 ;; font-lock-variable-name-face
7689 ;; font-lock-constant-face
7690 (append '(cperl-array-face
7694 ;; font-lock-constant-face
7695 (append '(cperl-nonoverridable-face
7699 ;; font-lock-type-face
7700 (append '(cperl-array-face
7703 cperl-nonoverridable-face)
7704 ps-underlined-faces))))
7706 (defvar ps-print-face-extension-alist)
7708 (defun cperl-ps-print (&optional file)
7709 "Pretty-print in CPerl style.
7710 If optional argument FILE is an empty string, prints to printer, otherwise
7711 to the file FILE. If FILE is nil, prompts for a file name.
7713 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
7716 (setq file (read-from-minibuffer
7717 "Print to file (if empty - to printer): "
7718 (concat (buffer-file-name) ".ps")
7719 nil nil 'file-name-history)))
7720 (or (> (length file) 0)
7722 (require 'ps-print) ; To get ps-print-face-extension-alist
7723 (let ((ps-print-color-p t)
7724 (ps-print-face-extension-alist ps-print-face-extension-alist))
7725 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
7726 (ps-print-buffer-with-faces file)))
7728 ;;; (defun cperl-ps-print-init ()
7729 ;;; "Initialization of `ps-print' components for faces used in CPerl."
7730 ;;; ;; Guard against old versions
7731 ;;; (defvar ps-underlined-faces nil)
7732 ;;; (defvar ps-bold-faces nil)
7733 ;;; (defvar ps-italic-faces nil)
7734 ;;; (setq ps-bold-faces
7735 ;;; (append '(font-lock-emphasized-face
7736 ;;; cperl-array-face
7737 ;;; font-lock-keyword-face
7738 ;;; font-lock-variable-name-face
7739 ;;; font-lock-constant-face
7740 ;;; font-lock-reference-face
7741 ;;; font-lock-other-emphasized-face
7742 ;;; cperl-hash-face)
7744 ;;; (setq ps-italic-faces
7745 ;;; (append '(cperl-nonoverridable-face
7746 ;;; font-lock-constant-face
7747 ;;; font-lock-reference-face
7748 ;;; font-lock-other-emphasized-face
7749 ;;; cperl-hash-face)
7750 ;;; ps-italic-faces))
7751 ;;; (setq ps-underlined-faces
7752 ;;; (append '(font-lock-emphasized-face
7753 ;;; cperl-array-face
7754 ;;; font-lock-other-emphasized-face
7756 ;;; cperl-nonoverridable-face font-lock-type-face)
7757 ;;; ps-underlined-faces))
7758 ;;; (cons 'font-lock-type-face ps-underlined-faces))
7761 (if (cperl-enable-font-lock) (cperl-windowed-init))
7763 (defconst cperl-styles-entries
7764 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
7765 cperl-label-offset cperl-extra-newline-before-brace
7766 cperl-extra-newline-before-brace-multiline
7767 cperl-merge-trailing-else
7768 cperl-continued-statement-offset))
7770 (defconst cperl-style-examples
7771 "##### Numbers etc are: cperl-indent-level cperl-brace-offset
7772 ##### cperl-continued-brace-offset cperl-label-offset
7773 ##### cperl-continued-statement-offset
7774 ##### cperl-merge-trailing-else cperl-extra-newline-before-brace
7776 ########### (Do not forget cperl-extra-newline-before-brace-multiline)
7778 ### CPerl (=GNU - extra-newline-before-brace + merge-trailing-else) 2/0/0/-2/2/t/nil
7790 ### PerlStyle (=CPerl with 4 as indent) 4/0/0/-4/4/t/nil
7802 ### GNU 2/0/0/-2/2/nil/t
7817 ### C++ (=PerlStyle with braces aligned with control words) 4/0/-4/-4/4/nil/t
7832 ### BSD (=C++, but will not change preexisting merge-trailing-else
7833 ### and extra-newline-before-brace ) 4/0/-4/-4/4
7848 ### K&R (=C++ with indent 5 - merge-trailing-else, but will not
7849 ### change preexisting extra-newline-before-brace) 5/0/-5/-5/5/nil
7864 ### Whitesmith (=PerlStyle, but will not change preexisting
7865 ### extra-newline-before-brace and merge-trailing-else) 4/0/0/-4/4
7880 "Examples of if/else with different indent styles (with v4.23).")
7882 (defconst cperl-style-alist
7883 '(("CPerl" ;; =GNU - extra-newline-before-brace + cperl-merge-trailing-else
7884 (cperl-indent-level . 2)
7885 (cperl-brace-offset . 0)
7886 (cperl-continued-brace-offset . 0)
7887 (cperl-label-offset . -2)
7888 (cperl-continued-statement-offset . 2)
7889 (cperl-extra-newline-before-brace . nil)
7890 (cperl-extra-newline-before-brace-multiline . nil)
7891 (cperl-merge-trailing-else . t))
7893 ("PerlStyle" ; CPerl with 4 as indent
7894 (cperl-indent-level . 4)
7895 (cperl-brace-offset . 0)
7896 (cperl-continued-brace-offset . 0)
7897 (cperl-label-offset . -4)
7898 (cperl-continued-statement-offset . 4)
7899 (cperl-extra-newline-before-brace . nil)
7900 (cperl-extra-newline-before-brace-multiline . nil)
7901 (cperl-merge-trailing-else . t))
7904 (cperl-indent-level . 2)
7905 (cperl-brace-offset . 0)
7906 (cperl-continued-brace-offset . 0)
7907 (cperl-label-offset . -2)
7908 (cperl-continued-statement-offset . 2)
7909 (cperl-extra-newline-before-brace . t)
7910 (cperl-extra-newline-before-brace-multiline . t)
7911 (cperl-merge-trailing-else . nil))
7914 (cperl-indent-level . 5)
7915 (cperl-brace-offset . 0)
7916 (cperl-continued-brace-offset . -5)
7917 (cperl-label-offset . -5)
7918 (cperl-continued-statement-offset . 5)
7919 ;;(cperl-extra-newline-before-brace . nil) ; ???
7920 ;;(cperl-extra-newline-before-brace-multiline . nil)
7921 (cperl-merge-trailing-else . nil))
7924 (cperl-indent-level . 4)
7925 (cperl-brace-offset . 0)
7926 (cperl-continued-brace-offset . -4)
7927 (cperl-label-offset . -4)
7928 (cperl-continued-statement-offset . 4)
7929 ;;(cperl-extra-newline-before-brace . nil) ; ???
7930 ;;(cperl-extra-newline-before-brace-multiline . nil)
7931 ;;(cperl-merge-trailing-else . nil) ; ???
7935 (cperl-indent-level . 4)
7936 (cperl-brace-offset . 0)
7937 (cperl-continued-brace-offset . -4)
7938 (cperl-label-offset . -4)
7939 (cperl-continued-statement-offset . 4)
7940 (cperl-extra-newline-before-brace . t)
7941 (cperl-extra-newline-before-brace-multiline . t)
7942 (cperl-merge-trailing-else . nil))
7945 (cperl-indent-level . 4)
7946 (cperl-brace-offset . 0)
7947 (cperl-continued-brace-offset . 0)
7948 (cperl-label-offset . -4)
7949 (cperl-continued-statement-offset . 4)
7950 ;;(cperl-extra-newline-before-brace . nil) ; ???
7951 ;;(cperl-extra-newline-before-brace-multiline . nil)
7952 ;;(cperl-merge-trailing-else . nil) ; ???
7955 "List of variables to set to get a particular indentation style.
7956 Should be used via `cperl-set-style' or via Perl menu.
7958 See examples in `cperl-style-examples'.")
7960 (defun cperl-set-style (style)
7961 "Set CPerl mode variables to use one of several different indentation styles.
7962 The arguments are a string representing the desired style.
7963 The list of styles is in `cperl-style-alist', available styles
7964 are CPerl, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith.
7966 The current value of style is memorized (unless there is a memorized
7967 data already), may be restored by `cperl-set-style-back'.
7969 Chosing \"Current\" style will not change style, so this may be used for
7970 side-effect of memorizing only. Examples in `cperl-style-examples'."
7972 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
7973 cperl-style-alist)))
7974 (list (completing-read "Enter style: " list nil 'insist))))
7976 (setq cperl-old-style
7979 (cons name (eval name))))
7980 cperl-styles-entries)))
7981 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
7983 (setq setting (car style) style (cdr style))
7984 (set (car setting) (cdr setting)))))
7986 (defun cperl-set-style-back ()
7987 "Restore a style memorised by `cperl-set-style'."
7989 (or cperl-old-style (error "The style was not changed"))
7991 (while cperl-old-style
7992 (setq setting (car cperl-old-style)
7993 cperl-old-style (cdr cperl-old-style))
7994 (set (car setting) (cdr setting)))))
7996 (defun cperl-check-syntax ()
7998 (require 'mode-compile)
7999 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
8000 (eval '(mode-compile)))) ; Avoid a warning
8002 (defun cperl-info-buffer (type)
8003 ;; Returns buffer with documentation. Creates if missing.
8004 ;; If TYPE, this vars buffer.
8005 ;; Special care is taken to not stomp over an existing info buffer
8006 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
8007 (info (get-buffer bname))
8008 (oldbuf (get-buffer "*info*")))
8010 (save-window-excursion
8015 (rename-buffer "*info-perl-tmp*")))
8016 (save-window-excursion
8018 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
8019 (set-buffer "*info*")
8020 (rename-buffer bname)
8022 (set-buffer "*info-perl-tmp*")
8023 (rename-buffer "*info*")
8024 (set-buffer bname)))
8025 (make-local-variable 'window-min-height)
8026 (setq window-min-height 2)
8027 (current-buffer)))))
8029 (defun cperl-word-at-point (&optional p)
8030 "Return the word at point or at P."
8032 (if p (goto-char p))
8033 (or (cperl-word-at-point-hard)
8036 (funcall (or (and (boundp 'find-tag-default-function)
8037 find-tag-default-function)
8038 (get major-mode 'find-tag-default-function)
8039 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
8040 ;; automatically used within `find-tag-default':
8041 'find-tag-default))))))
8043 (defun cperl-info-on-command (command)
8044 "Show documentation for Perl command COMMAND in other window.
8045 If perl-info buffer is shown in some frame, uses this frame.
8046 Customized by setting variables `cperl-shrink-wrap-info-frame',
8047 `cperl-max-help-size'."
8049 (let* ((default (cperl-word-at-point))
8051 (format "Find doc for Perl function (default %s): "
8053 (list (if (equal read "")
8057 (let ((buffer (current-buffer))
8058 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
8059 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
8060 max-height char-height buf-list)
8061 (if (string-match "^-[a-zA-Z]$" command)
8062 (setq cmd-desc "^-X[ \t\n]"))
8063 (setq isvar (string-match "^[$@%]" command)
8064 buf (cperl-info-buffer isvar)
8065 iniwin (selected-window)
8066 fr1 (window-frame iniwin))
8068 (goto-char (point-min))
8070 (progn (re-search-forward "^-X[ \t\n]")
8072 (if (re-search-forward cmd-desc nil t)
8074 ;; Go back to beginning of the group (ex, for qq)
8075 (if (re-search-backward "^[ \t\n\f]")
8080 buf-list (list buf "*info-perl-var*" "*info-perl*"))
8081 (while (and (not win) buf-list)
8082 (setq win (get-buffer-window (car buf-list) t))
8083 (setq buf-list (cdr buf-list)))
8085 (eq (window-buffer win) buf)
8086 (set-window-buffer win buf))
8087 (and win (setq fr2 (window-frame win)))
8088 (if (or (not fr2) (eq fr1 fr2))
8090 (special-display-popup-frame buf) ; Make it visible
8091 (select-window win))
8092 (goto-char pos) ; Needed (?!).
8094 (setq iniheight (window-height)
8095 frheight (frame-height)
8096 not-loner (< iniheight (1- frheight))) ; Are not alone
8097 (cond ((if not-loner cperl-max-help-size
8098 cperl-shrink-wrap-info-frame)
8104 (if (re-search-forward
8105 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
8106 (match-beginning 0) (point-max)))))
8109 (/ (* (- frheight 3) cperl-max-help-size) 100)
8110 (setq char-height (frame-char-height))
8111 ;; Non-functioning under OS/2:
8112 (if (eq char-height 1) (setq char-height 18))
8113 ;; Title, menubar, + 2 for slack
8114 (- (/ (x-display-pixel-height) char-height) 4)))
8115 (if (> height max-height) (setq height max-height))
8116 ;;(message "was %s doing %s" iniheight height)
8118 (enlarge-window (- height iniheight))
8119 (set-frame-height (window-frame win) (1+ height)))))
8120 (set-window-start (selected-window) pos))
8121 (message "No entry for %s found." command))
8122 ;;(pop-to-buffer buffer)
8123 (select-window iniwin)))
8125 (defun cperl-info-on-current-command ()
8126 "Show documentation for Perl command at point in other window."
8128 (cperl-info-on-command (cperl-word-at-point)))
8130 (defun cperl-imenu-info-imenu-search ()
8131 (if (looking-at "^-X[ \t\n]") nil
8133 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
8136 (defun cperl-imenu-info-imenu-name ()
8138 (match-beginning 1) (match-end 1)))
8140 (defun cperl-imenu-on-info ()
8141 "Shows imenu for Perl Info Buffer.
8142 Opens Perl Info buffer if needed."
8144 (let* ((buffer (current-buffer))
8145 imenu-create-index-function
8146 imenu-prev-index-position-function
8147 imenu-extract-index-name-function
8148 (index-item (save-restriction
8149 (save-window-excursion
8150 (set-buffer (cperl-info-buffer nil))
8151 (setq imenu-create-index-function
8152 'imenu-default-create-index-function
8153 imenu-prev-index-position-function
8154 'cperl-imenu-info-imenu-search
8155 imenu-extract-index-name-function
8156 'cperl-imenu-info-imenu-name)
8157 (imenu-choose-buffer-index)))))
8161 (pop-to-buffer "*info-perl*")
8163 ((markerp (cdr index-item))
8164 (goto-char (marker-position (cdr index-item))))
8166 (goto-char (cdr index-item))))
8167 (set-window-start (selected-window) (point))
8168 (pop-to-buffer buffer)))))
8170 (defun cperl-lineup (beg end &optional step minshift)
8171 "Lineup construction in a region.
8172 Beginning of region should be at the start of a construction.
8173 All first occurrences of this construction in the lines that are
8174 partially contained in the region are lined up at the same column.
8176 MINSHIFT is the minimal amount of space to insert before the construction.
8177 STEP is the tabwidth to position constructions.
8178 If STEP is nil, `cperl-lineup-step' will be used
8179 \(or `cperl-indent-level', if `cperl-lineup-step' is `nil').
8180 Will not move the position at the start to the left."
8182 (let (search col tcol seen b)
8186 (setq end (point-marker))
8188 (skip-chars-forward " \t\f")
8189 (setq beg (point-marker))
8190 (indent-region beg end nil)
8192 (setq col (current-column))
8193 (if (looking-at "[a-zA-Z0-9_]")
8194 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
8198 (buffer-substring (match-beginning 0)
8199 (match-end 0))) "\\>"))
8200 (error "Cannot line up in a middle of the word"))
8201 (if (looking-at "$")
8202 (error "Cannot line up end of line"))
8203 (setq search (regexp-quote (char-to-string (following-char)))))
8204 (setq step (or step cperl-lineup-step cperl-indent-level))
8205 (or minshift (setq minshift 1))
8207 (beginning-of-line 2)
8208 (and (< (point) end)
8209 (re-search-forward search end t)
8210 (goto-char (match-beginning 0))))
8211 (setq tcol (current-column) seen t)
8212 (if (> tcol col) (setq col tcol)))
8214 (error "The construction to line up occurred only once"))
8216 (setq col (+ col minshift))
8217 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
8220 (cperl-make-indent col)
8221 (beginning-of-line 2)
8222 (and (< (point) end)
8223 (re-search-forward search end t)
8224 (goto-char (match-beginning 0)))))))) ; No body
8226 (defun cperl-etags (&optional add all files) ;; NOT USED???
8227 "Run etags with appropriate options for Perl files.
8228 If optional argument ALL is `recursive', will process Perl files
8229 in subdirectories too."
8232 (args '("-l" "none" "-r"
8233 ;; 1=fullname 2=package? 3=name 4=proto? 5=attrs? (VERY APPROX!)
8234 "/\\<sub[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([ \t]*:[^#{;]*\\)?\\([{#]\\|$\\)/\\3/"
8236 "/\\<package[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\([#;]\\|$\\)/\\1/"
8238 "/\\<\\(package\\)[ \\t]*;/\\1;/"))
8240 (if add (setq args (cons "-a" args)))
8241 (or files (setq files (list buffer-file-name)))
8243 ((eq all 'recursive)
8244 ;;(error "Not implemented: recursive")
8245 (setq args (append (list "-e"
8246 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
8248 find(\\&wanted, '.');
8253 ;;(error "Not implemented: all")
8254 (setq args (append (list "-e"
8255 "push @ARGV, <*.PL *.pl *.pm>;
8260 (setq args (append args files))))
8261 (setq res (apply 'call-process cmd nil nil nil args))
8263 (message "etags returned \"%s\"" res))))
8265 (defun cperl-toggle-auto-newline ()
8266 "Toggle the state of `cperl-auto-newline'."
8268 (setq cperl-auto-newline (not cperl-auto-newline))
8269 (message "Newlines will %sbe auto-inserted now."
8270 (if cperl-auto-newline "" "not ")))
8272 (defun cperl-toggle-abbrev ()
8273 "Toggle the state of automatic keyword expansion in CPerl mode."
8275 (abbrev-mode (if abbrev-mode 0 1))
8276 (message "Perl control structure will %sbe auto-inserted now."
8277 (if abbrev-mode "" "not ")))
8280 (defun cperl-toggle-electric ()
8281 "Toggle the state of parentheses doubling in CPerl mode."
8283 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
8284 (message "Parentheses will %sbe auto-doubled now."
8285 (if (cperl-val 'cperl-electric-parens) "" "not ")))
8287 (defun cperl-toggle-autohelp ()
8288 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
8289 Delay of auto-help controlled by `cperl-lazy-help-time'."
8291 (if (fboundp 'run-with-idle-timer)
8293 (if cperl-lazy-installed
8294 (cperl-lazy-unstall)
8295 (cperl-lazy-install))
8296 (message "Perl help messages will %sbe automatically shown now."
8297 (if cperl-lazy-installed "" "not ")))
8298 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
8300 (defun cperl-toggle-construct-fix ()
8301 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
8303 (setq cperl-indent-region-fix-constructs
8304 (if cperl-indent-region-fix-constructs
8307 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
8308 (if cperl-indent-region-fix-constructs "" "not ")))
8310 (defun cperl-toggle-set-debug-unwind (arg &optional backtrace)
8311 "Toggle (or, with numeric argument, set) debugging state of syntaxification.
8312 Nonpositive numeric argument disables debugging messages. The message
8313 summarizes which regions it was decided to rescan for syntactic constructs.
8315 The message looks like this:
8317 Syxify req=123..138 actual=101..146 done-to: 112=>146 statepos: 73=>117
8319 Numbers are character positions in the buffer. REQ provides the range to
8320 rescan requested by `font-lock'. ACTUAL is the range actually resyntaxified;
8321 for correct operation it should start and end outside any special syntactic
8322 construct. DONE-TO and STATEPOS indicate changes to internal caches maintained
8326 (setq arg (if (eq cperl-syntaxify-by-font-lock
8327 (if backtrace 'backtrace 'message)) 0 1)))
8328 (setq arg (if (> arg 0) (if backtrace 'backtrace 'message) t))
8329 (setq cperl-syntaxify-by-font-lock arg)
8330 (message "Debugging messages of syntax unwind %sabled."
8331 (if (eq arg t) "dis" "en")))
8333 ;;;; Tags file creation.
8335 (defvar cperl-tmp-buffer " *cperl-tmp*")
8337 (defun cperl-setup-tmp-buf ()
8338 (set-buffer (get-buffer-create cperl-tmp-buffer))
8339 (set-syntax-table cperl-mode-syntax-table)
8340 (buffer-disable-undo)
8342 (if cperl-use-syntax-table-text-property-for-tags
8344 (make-local-variable 'parse-sexp-lookup-properties)
8345 ;; Do not introduce variable if not needed, we check it!
8346 (set 'parse-sexp-lookup-properties t))))
8348 (defun cperl-xsub-scan ()
8351 (let ((index-alist '())
8352 (prev-pos 0) index index1 name package prefix)
8353 (goto-char (point-min))
8355 (message "Scanning XSUB for index")
8356 (imenu-progress-message prev-pos 0))
8357 ;; Search for the function
8358 (progn ;;save-match-data
8359 (while (re-search-forward
8360 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
8363 (imenu-progress-message prev-pos))
8365 ((match-beginning 2) ; SECTION
8366 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
8367 (goto-char (match-beginning 0))
8368 (skip-chars-forward " \t")
8370 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
8371 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
8373 ((not package) nil) ; C language section
8374 ((match-beginning 3) ; XSUB
8375 (goto-char (1+ (match-beginning 3)))
8376 (setq index (imenu-example--name-and-position))
8377 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
8378 (if (and prefix (string-match (concat "^" prefix) name))
8379 (setq name (substring name (length prefix))))
8380 (cond ((string-match "::" name) nil)
8382 (setq index1 (cons (concat package "::" name) (cdr index)))
8383 (push index1 index-alist)))
8385 (push index index-alist))
8387 ;; (beginning-of-line)
8388 (setq index (imenu-example--name-and-position))
8389 (setcar index (concat package "::BOOT:"))
8390 (push index index-alist)))))
8392 (imenu-progress-message prev-pos 100))
8395 (defvar cperl-unreadable-ok nil)
8397 (defun cperl-find-tags (ifile xs topdir)
8398 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
8399 (cperl-pod-here-fontify nil) f file)
8401 (if b (set-buffer b)
8402 (cperl-setup-tmp-buf))
8405 (setq file (car (insert-file-contents ifile)))
8406 (error (if cperl-unreadable-ok nil
8408 (format "File %s unreadable. Continue? " ifile))
8409 (setq cperl-unreadable-ok t)
8410 (error "Aborting: unreadable file %s" ifile)))))
8412 (message "Unreadable file %s" ifile)
8413 (message "Scanning file %s ..." file)
8414 (if (and cperl-use-syntax-table-text-property-for-tags
8416 (condition-case err ; after __END__ may have garbage
8417 (cperl-find-pods-heres nil nil noninteractive)
8418 (error (message "While scanning for syntax: %s" err))))
8420 (setq lst (cperl-xsub-scan))
8421 (setq ind (cperl-imenu--create-perl-index))
8422 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
8427 (cond ((string-match "^[_a-zA-Z]" (car elt))
8428 (goto-char (cdr elt))
8429 (beginning-of-line) ; pos should be of the start of the line
8432 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
8433 (buffer-substring (progn
8434 (goto-char (cdr elt))
8435 ;; After name now...
8436 (or (eolp) (forward-char 1))
8444 (setq elt (car lst) lst (cdr lst))
8449 (if (string-match "^package " (car elt))
8450 (substring (car elt) 8)
8453 (number-to-string (elt elt 2)) ; Line
8455 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
8457 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
8458 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
8460 ;; Need to insert the name without package as well
8461 (setq lst (cons (cons (substring (elt elt 3)
8469 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
8470 (set-text-properties 0 (length rel) nil rel)
8471 (and (equal topdir (substring rel 0 (length topdir)))
8472 (setq rel (substring file (length topdir))))
8473 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
8474 (setq ret (buffer-substring 1 (point-max)))
8477 (message "Scanning file %s finished" file))
8480 (defun cperl-add-tags-recurse-noxs ()
8481 "Add to TAGS data for \"pure\" Perl files in the current directory and kids.
8483 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8484 -f cperl-add-tags-recurse-noxs
8486 (cperl-write-tags nil nil t t nil t))
8488 (defun cperl-add-tags-recurse-noxs-fullpath ()
8489 "Add to TAGS data for \"pure\" Perl in the current directory and kids.
8490 Writes down fullpath, so TAGS is relocatable (but if the build directory
8491 is relocated, the file TAGS inside it breaks). Use as
8492 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8493 -f cperl-add-tags-recurse-noxs-fullpath
8495 (cperl-write-tags nil nil t t nil t ""))
8497 (defun cperl-add-tags-recurse ()
8498 "Add to TAGS file data for Perl files in the current directory and kids.
8500 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8501 -f cperl-add-tags-recurse
8503 (cperl-write-tags nil nil t t))
8505 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
8506 ;; If INBUFFER, do not select buffer, and do not save
8507 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
8510 (setq file (if dir default-directory (buffer-file-name)))
8511 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
8513 (setq topdir default-directory))
8514 (let ((tags-file-name "TAGS")
8515 (case-fold-search (eq system-type 'emx))
8518 (cond (inbuffer nil) ; Already there
8519 ((file-exists-p tags-file-name)
8521 (visit-tags-table-buffer)
8522 (visit-tags-table-buffer tags-file-name)))
8523 (t (set-buffer (find-file-noselect tags-file-name))))
8526 (cond ((eq erase 'ignore))
8529 (setq erase 'ignore)))
8532 (directory-files file t
8533 (if recurse nil cperl-scan-files-regexp)
8536 (if cperl-unreadable-ok nil
8538 (format "Directory %s unreadable. Continue? " file))
8539 (setq cperl-unreadable-ok t
8540 tm nil) ; Return empty list
8541 (error "Aborting: unreadable directory %s" file)))))))
8545 ((string-match cperl-noscan-files-regexp file)
8547 ((not (file-directory-p file))
8548 (if (string-match cperl-scan-files-regexp file)
8549 (cperl-write-tags file erase recurse nil t noxs topdir)))
8551 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
8554 (setq xs (string-match "\\.xs$" file))
8555 (if (not (and xs noxs))
8557 (cond ((eq erase 'ignore) (goto-char (point-max)))
8558 (erase (erase-buffer))
8562 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
8563 (set-text-properties 0 (length rel) nil rel)
8564 (and (equal topdir (substring rel 0 (length topdir)))
8565 (setq rel (substring file (length topdir))))
8566 (if (search-forward (concat "\f\n" rel ",") nil t)
8568 (search-backward "\f\n")
8569 (delete-region (point)
8572 (if (search-forward "\f\n"
8576 (goto-char (point-max)))))
8577 (insert (cperl-find-tags file xs topdir))))))
8578 (if inbuffer nil ; Delegate to the caller
8579 (save-buffer 0) ; No backup
8580 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
8581 (initialize-new-tags-table))))))
8583 (defvar cperl-tags-hier-regexp-list
8590 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
8592 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
8595 (defvar cperl-hierarchy '(() ())
8596 "Global hierarchy of classes.")
8598 (defun cperl-tags-hier-fill ()
8599 ;; Suppose we are in a tag table cooked by cperl.
8601 (let (type pack name pos line chunk ord cons1 file str info fileind)
8602 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
8603 (setq pos (match-beginning 0)
8604 pack (match-beginning 2))
8606 (if (looking-at (concat
8615 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
8616 name (buffer-substring (match-beginning 2) (match-end 2))
8617 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
8618 line (buffer-substring (match-beginning 3) (match-end 3))
8621 fileind (format "%s:%s" file line)
8622 ;; Moves to beginning of the next line:
8623 info (cperl-etags-snarf-tag file line))
8626 ;; Make new member of hierarchy name ==> file ==> pos if needed
8627 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
8629 (setcdr cons1 (cons (cons fileind (vector file info))
8631 ;; First occurrence of the name, start alist
8632 (setq cons1 (cons name (list (cons fileind (vector file info)))))
8634 (setcar (cdr cperl-hierarchy)
8635 (cons cons1 (nth 1 cperl-hierarchy)))
8636 (setcar cperl-hierarchy
8637 (cons cons1 (car cperl-hierarchy)))))))
8640 (defun cperl-tags-hier-init (&optional update)
8641 "Show hierarchical menu of classes and methods.
8642 Finds info about classes by a scan of loaded TAGS files.
8643 Supposes that the TAGS files contain fully qualified function names.
8644 One may build such TAGS files from CPerl mode menu."
8648 (if (or update (null (nth 2 cperl-hierarchy)))
8649 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
8652 (setcdr elt (cdr (nth 1 elt)))))))
8653 pack name cons1 to l1 l2 l3 l4 b)
8654 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
8655 (setq cperl-hierarchy (list l1 l2 l3))
8656 (if cperl-xemacs-p ; Not checked
8659 ;; Does this work in XEmacs?
8660 (call-interactively 'visit-tags-table))
8661 (message "Updating list of classes...")
8662 (set-buffer (get-file-buffer tags-file-name))
8663 (cperl-tags-hier-fill))
8665 (call-interactively 'visit-tags-table))
8669 (message "Updating list of classes... %s" tagsfile)
8670 (set-buffer (get-file-buffer tagsfile))
8671 (cperl-tags-hier-fill)))
8673 (message "Updating list of classes... postprocessing..."))
8674 (mapcar remover (car cperl-hierarchy))
8675 (mapcar remover (nth 1 cperl-hierarchy))
8676 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
8677 (cons "Methods: " (car cperl-hierarchy))))
8678 (cperl-tags-treeify to 1)
8679 (setcar (nthcdr 2 cperl-hierarchy)
8680 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
8681 (message "Updating list of classes: done, requesting display...")
8682 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
8684 (or (nth 2 cperl-hierarchy)
8685 (error "No items found"))
8687 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
8688 (if (if (fboundp 'display-popup-menus-p)
8689 (let ((f 'display-popup-menus-p))
8692 (x-popup-menu t (nth 2 cperl-hierarchy))
8694 (tmm-prompt (nth 2 cperl-hierarchy))))
8695 (if (and update (listp update))
8696 (progn (while (cdr update) (setq update (cdr update)))
8697 (setq update (car update)))) ; Get the last from the list
8698 (if (vectorp update)
8700 (find-file (elt update 0))
8701 (cperl-etags-goto-tag-location (elt update 1))))
8702 (if (eq update -999) (cperl-tags-hier-init t)))
8704 (defun cperl-tags-treeify (to level)
8705 ;; cadr of `to' is read-write. On start it is a cons
8706 (let* ((regexp (concat "^\\(" (mapconcat
8708 (make-list level "[_a-zA-Z0-9]+")
8711 (packages (cdr (nth 1 to)))
8712 (methods (cdr (nth 2 to)))
8713 l1 head tail cons1 cons2 ord writeto packs recurse
8714 root-packages root-functions ms many_ms same_name ps
8718 (cond ((and (string-match regexp (car elt))
8719 (or (eq ord 1) (match-end 2)))
8720 (setq head (substring (car elt) 0 (match-end 1))
8721 tail (if (match-end 2) (substring (car elt)
8724 (if (setq cons1 (assoc head writeto)) nil
8725 ;; Need to init new head
8726 (setcdr writeto (cons (list head (list "Packages: ")
8729 (setq cons1 (nth 1 writeto)))
8730 (setq cons2 (nth ord cons1)) ; Either packs or meths
8731 (setcdr cons2 (cons elt (cdr cons2))))
8733 (setq root-functions (cons elt root-functions)))
8735 (setq root-packages (cons elt root-packages))))))))
8736 (setcdr to l1) ; Init to dynamic space
8739 (mapcar move-deeper packages)
8741 (mapcar move-deeper methods)
8743 (mapcar (function (lambda (elt)
8744 (cperl-tags-treeify elt (1+ level))))
8746 ;;Now clean up leaders with one child only
8747 (mapcar (function (lambda (elt)
8748 (if (not (and (listp (cdr elt))
8749 (eq (length elt) 2))) nil
8750 (setcar elt (car (nth 1 elt)))
8751 (setcdr elt (cdr (nth 1 elt))))))
8753 ;; Sort the roots of subtrees
8754 (if (default-value 'imenu-sort-function)
8756 (sort (cdr to) (default-value 'imenu-sort-function))))
8757 ;; Now add back functions removed from display
8758 (mapcar (function (lambda (elt)
8759 (setcdr to (cons elt (cdr to)))))
8760 (if (default-value 'imenu-sort-function)
8762 (sort root-functions (default-value 'imenu-sort-function)))
8764 ;; Now add back packages removed from display
8765 (mapcar (function (lambda (elt)
8766 (setcdr to (cons (cons (concat "package " (car elt))
8769 (if (default-value 'imenu-sort-function)
8771 (sort root-packages (default-value 'imenu-sort-function)))
8775 ;;; '(keymap "Name1"
8779 ;;; ("Tail1" "x") ("Tail2" "y"))))
8781 (defun cperl-list-fold (list name limit)
8782 (let (list1 list2 elt1 (num 0))
8783 (if (<= (length list) limit) list
8784 (setq list1 nil list2 nil)
8789 (if (<= num imenu-max-items)
8790 (setq list2 (cons elt1 list2))
8791 (setq list1 (cons (cons name
8796 (nreverse (cons (cons name
8800 (defun cperl-menu-to-keymap (menu &optional name)
8806 (cond ((listp (cdr elt))
8807 (setq list (cperl-list-fold
8808 (cdr elt) (car elt) imenu-max-items))
8811 (cperl-menu-to-keymap list))))
8813 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
8814 (cperl-list-fold menu "Root" imenu-max-items)))))
8817 (defvar cperl-bad-style-regexp
8818 (mapconcat 'identity
8819 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
8820 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
8822 "Finds places such that insertion of a whitespace may help a lot.")
8824 (defvar cperl-not-bad-style-regexp
8827 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
8828 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
8829 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
8830 "<\\$?\\sw+\\(\\.\\(\\sw\\|_\\)+\\)?>" ; <IN> <stdin.h>
8831 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
8838 "\\\\[&$@*\\\\]" ; \&func
8841 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
8844 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
8845 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
8846 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
8850 "If matches at the start of match found by `my-bad-c-style-regexp',
8851 insertion of a whitespace will not help.")
8855 (defun cperl-find-bad-style ()
8856 "Find places in the buffer where insertion of a whitespace may help.
8857 Prompts user for insertion of spaces.
8858 Currently it is tuned to C and Perl syntax."
8860 (let (found-bad (p (point)))
8861 (setq last-nonmenu-event 13) ; To disable popup
8862 (goto-char (point-min))
8863 (map-y-or-n-p "Insert space here? "
8864 (lambda (arg) (insert " "))
8865 'cperl-next-bad-style
8866 '("location" "locations" "insert a space into")
8867 '((?\C-r (lambda (arg)
8868 (let ((buffer-quit-function
8869 'exit-recursive-edit))
8870 (message "Exit with Esc Esc")
8872 t)) ; Consider acted upon
8873 "edit, exit with Esc Esc")
8875 (let ((buffer-quit-function
8876 'exit-recursive-edit))
8877 (message "Exit with Esc Esc")
8879 t)) ; Consider acted upon
8880 "edit, exit with Esc Esc"))
8882 (if found-bad (goto-char found-bad)
8884 (message "No appropriate place found"))))
8886 (defun cperl-next-bad-style ()
8887 (let (p (not-found t) (point (point)) found)
8888 (while (and not-found
8889 (re-search-forward cperl-bad-style-regexp nil 'to-end))
8891 (goto-char (match-beginning 0))
8893 (looking-at cperl-not-bad-style-regexp)
8894 ;; Check for a < -b and friends
8895 (and (eq (following-char) ?\-)
8897 (skip-chars-backward " \t\n")
8898 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
8899 ;; Now check for syntax type
8901 (setq found (point))
8902 (beginning-of-defun)
8903 (let ((pps (parse-partial-sexp (point) found)))
8904 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
8905 (goto-char (match-end 0))
8913 (defvar cperl-have-help-regexp
8917 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
8918 "[$@]\\^[a-zA-Z]" ; Special variable
8919 "[$@][^ \n\t]" ; Special variable
8920 "-[a-zA-Z]" ; File test
8921 "\\\\[a-zA-Z0]" ; Special chars
8922 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
8923 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
8924 "[a-zA-Z_0-9:]+" ; symbol or number
8931 "Matches places in the buffer we can find help for.")
8933 (defvar cperl-message-on-help-error t)
8934 (defvar cperl-help-from-timer nil)
8936 (defun cperl-word-at-point-hard ()
8937 ;; Does not save-excursion
8938 ;; Get to the something meaningful
8939 (or (eobp) (eolp) (forward-char 1))
8940 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
8941 (save-excursion (beginning-of-line) (point))
8944 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
8945 ;; (skip-chars-backward " \n\t\r({[]});,")
8946 ;; (or (bobp) (backward-char 1))))
8949 ((looking-at "[a-zA-Z0-9_:]") ; symbol
8950 (skip-chars-backward "a-zA-Z0-9_:")
8952 ((and (eq (preceding-char) ?^) ; $^I
8953 (eq (char-after (- (point) 2)) ?\$))
8955 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
8957 ((and (eq (preceding-char) ?\=)
8958 (eq (current-column) 1))
8959 (forward-char -1))) ; =head1
8960 (if (and (eq (preceding-char) ?\<)
8961 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
8963 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
8965 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
8967 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
8968 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
8970 ((and (eq (preceding-char) ?\$)
8971 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
8973 ((and (eq (following-char) ?\>)
8974 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
8977 (and (eq (preceding-char) ?\<)
8978 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
8979 (search-backward "<"))))
8980 ((and (eq (following-char) ?\$)
8981 (eq (preceding-char) ?\<)
8982 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
8984 (if (looking-at cperl-have-help-regexp)
8985 (buffer-substring (match-beginning 0) (match-end 0))))
8987 (defun cperl-get-help ()
8988 "Get one-line docs on the symbol at the point.
8989 The data for these docs is a little bit obsolete and may be in fact longer
8990 than a line. Your contribution to update/shorten it is appreciated."
8992 (save-match-data ; May be called "inside" query-replace
8994 (let ((word (cperl-word-at-point-hard)))
8996 (if (and cperl-help-from-timer ; Bail out if not in mainland
8997 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
8998 (or (memq (get-text-property (point) 'face)
8999 '(font-lock-comment-face font-lock-string-face))
9000 (memq (get-text-property (point) 'syntax-type)
9001 '(pod here-doc format))))
9003 (cperl-describe-perl-symbol word))
9004 (if cperl-message-on-help-error
9005 (message "Nothing found for %s..."
9006 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
9008 ;;; Stolen from perl-descr.el by Johan Vromans:
9010 (defvar cperl-doc-buffer " *perl-doc*"
9011 "Where the documentation can be found.")
9013 (defun cperl-describe-perl-symbol (val)
9014 "Display the documentation of symbol at point, a Perl operator."
9015 (let ((enable-recursive-minibuffers t)
9018 ((string-match "^[&*][a-zA-Z_]" val)
9019 (setq val (concat (substring val 0 1) "NAME")))
9020 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
9021 (setq val (concat "@" (substring val 1 (match-end 1)))))
9022 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
9023 (setq val (concat "%" (substring val 1 (match-end 1)))))
9024 ((and (string= val "x") (string-match "^x=" val))
9026 ((string-match "^\\$[\C-a-\C-z]" val)
9027 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
9028 ((string-match "^CORE::" val)
9029 (setq val "CORE::"))
9030 ((string-match "^SUPER::" val)
9031 (setq val "SUPER::"))
9032 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
9033 (setq val "<NAME>")))
9034 (setq regexp (concat "^"
9035 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
9037 "\\([ \t([/]\\|$\\)"))
9039 ;; get the buffer with the documentation text
9040 (cperl-switch-to-doc-buffer)
9042 ;; lookup in the doc
9043 (goto-char (point-min))
9044 (let ((case-fold-search nil))
9046 (if (re-search-forward regexp (point-max) t)
9048 (beginning-of-line 1)
9049 (let ((lnstart (point)))
9051 (message "%s" (buffer-substring lnstart (point)))))
9052 (if cperl-message-on-help-error
9053 (message "No definition for %s" val)))))))
9055 (defvar cperl-short-docs 'please-ignore-this-line
9056 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
9057 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
9058 ... Range (list context); flip/flop [no flop when flip] (scalar context).
9059 ! ... Logical negation.
9060 ... != ... Numeric inequality.
9061 ... !~ ... Search pattern, substitution, or translation (negated).
9062 $! In numeric context: errno. In a string context: error string.
9063 $\" The separator which joins elements of arrays interpolated in strings.
9064 $# The output format for printed numbers. Default is %.15g or close.
9065 $$ Process number of this script. Changes in the fork()ed child process.
9066 $% The current page number of the currently selected output channel.
9068 The following variables are always local to the current block:
9070 $1 Match of the 1st set of parentheses in the last match (auto-local).
9071 $2 Match of the 2nd set of parentheses in the last match (auto-local).
9072 $3 Match of the 3rd set of parentheses in the last match (auto-local).
9073 $4 Match of the 4th set of parentheses in the last match (auto-local).
9074 $5 Match of the 5th set of parentheses in the last match (auto-local).
9075 $6 Match of the 6th set of parentheses in the last match (auto-local).
9076 $7 Match of the 7th set of parentheses in the last match (auto-local).
9077 $8 Match of the 8th set of parentheses in the last match (auto-local).
9078 $9 Match of the 9th set of parentheses in the last match (auto-local).
9079 $& The string matched by the last pattern match (auto-local).
9080 $' The string after what was matched by the last match (auto-local).
9081 $` The string before what was matched by the last match (auto-local).
9083 $( The real gid of this process.
9084 $) The effective gid of this process.
9085 $* Deprecated: Set to 1 to do multiline matching within a string.
9086 $+ The last bracket matched by the last search pattern.
9087 $, The output field separator for the print operator.
9088 $- The number of lines left on the page.
9089 $. The current input line number of the last filehandle that was read.
9090 $/ The input record separator, newline by default.
9091 $0 Name of the file containing the current perl script (read/write).
9092 $: String may be broken after these characters to fill ^-lines in a format.
9093 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
9094 $< The real uid of this process.
9095 $= The page length of the current output channel. Default is 60 lines.
9096 $> The effective uid of this process.
9097 $? The status returned by the last ``, pipe close or `system'.
9098 $@ The perl error message from the last eval or do @var{EXPR} command.
9099 $ARGV The name of the current file used with <> .
9100 $[ Deprecated: The index of the first element/char in an array/string.
9101 $\\ The output record separator for the print operator.
9102 $] The perl version string as displayed with perl -v.
9103 $^ The name of the current top-of-page format.
9104 $^A The current value of the write() accumulator for format() lines.
9105 $^D The value of the perl debug (-D) flags.
9106 $^E Information about the last system error other than that provided by $!.
9107 $^F The highest system file descriptor, ordinarily 2.
9108 $^H The current set of syntax checks enabled by `use strict'.
9109 $^I The value of the in-place edit extension (perl -i option).
9110 $^L What formats output to perform a formfeed. Default is \f.
9111 $^M A buffer for emergency memory allocation when running out of memory.
9112 $^O The operating system name under which this copy of Perl was built.
9113 $^P Internal debugging flag.
9114 $^T The time the script was started. Used by -A/-M/-C file tests.
9115 $^W True if warnings are requested (perl -w flag).
9116 $^X The name under which perl was invoked (argv[0] in C-speech).
9117 $_ The default input and pattern-searching space.
9118 $| Auto-flush after write/print on current output channel? Default 0.
9119 $~ The name of the current report format.
9120 ... % ... Modulo division.
9121 ... %= ... Modulo division assignment.
9122 %ENV Contains the current environment.
9123 %INC List of files that have been require-d or do-ne.
9124 %SIG Used to set signal handlers for various signals.
9125 ... & ... Bitwise and.
9126 ... && ... Logical and.
9127 ... &&= ... Logical and assignment.
9128 ... &= ... Bitwise and assignment.
9129 ... * ... Multiplication.
9130 ... ** ... Exponentiation.
9131 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
9132 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
9133 ... + ... Addition. +EXPR Makes EXPR into scalar context.
9134 ++ Auto-increment (magical on strings). ++EXPR EXPR++
9135 ... += ... Addition assignment.
9137 ... - ... Subtraction.
9138 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
9139 ... -= ... Subtraction assignment.
9140 -A Access time in days since script started.
9141 -B File is a non-text (binary) file.
9142 -C Inode change time in days since script started.
9143 -M Age in days since script started.
9144 -O File is owned by real uid.
9145 -R File is readable by real uid.
9146 -S File is a socket .
9147 -T File is a text file.
9148 -W File is writable by real uid.
9149 -X File is executable by real uid.
9150 -b File is a block special file.
9151 -c File is a character special file.
9152 -d File is a directory.
9154 -f File is a plain file.
9155 -g File has setgid bit set.
9156 -k File has sticky bit set.
9157 -l File is a symbolic link.
9158 -o File is owned by effective uid.
9159 -p File is a named pipe (FIFO).
9160 -r File is readable by effective uid.
9161 -s File has non-zero size.
9162 -t Tests if filehandle (STDIN by default) is opened to a tty.
9163 -u File has setuid bit set.
9164 -w File is writable by effective uid.
9165 -x File is executable by effective uid.
9166 -z File has zero size.
9167 . Concatenate strings.
9168 .. Range (list context); flip/flop (scalar context) operator.
9169 .= Concatenate assignment strings
9170 ... / ... Division. /PATTERN/ioxsmg Pattern match
9171 ... /= ... Division assignment.
9172 /PATTERN/ioxsmg Pattern match.
9173 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
9174 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
9175 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
9176 <> Reads line from union of files in @ARGV (= command line) and STDIN.
9177 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
9178 ... <= ... Numeric less than or equal to.
9179 ... <=> ... Numeric compare.
9180 ... = ... Assignment.
9181 ... == ... Numeric equality.
9182 ... =~ ... Search pattern, substitution, or translation
9183 ... > ... Numeric greater than.
9184 ... >= ... Numeric greater than or equal to.
9185 ... >> ... Bitwise shift right.
9186 ... >>= ... Bitwise shift right assignment.
9187 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
9188 ?PATTERN? One-time pattern match.
9189 @ARGV Command line arguments (not including the command name - see $0).
9190 @INC List of places to look for perl scripts during do/include/use.
9191 @_ Parameter array for subroutines; result of split() unless in list context.
9192 \\ Creates reference to what follows, like \$var, or quotes non-\w in strings.
9193 \\0 Octal char, e.g. \\033.
9194 \\E Case modification terminator. See \\Q, \\L, and \\U.
9195 \\L Lowercase until \\E . See also \\l, lc.
9196 \\U Upcase until \\E . See also \\u, uc.
9197 \\Q Quote metacharacters until \\E . See also quotemeta.
9198 \\a Alarm character (octal 007).
9199 \\b Backspace character (octal 010).
9200 \\c Control character, e.g. \\c[ .
9201 \\e Escape character (octal 033).
9202 \\f Formfeed character (octal 014).
9203 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
9204 \\n Newline character (octal 012 on most systems).
9205 \\r Return character (octal 015 on most systems).
9206 \\t Tab character (octal 011).
9207 \\u Upcase the next character. See also \\U and \\l, ucfirst.
9208 \\x Hex character, e.g. \\x1b.
9209 ... ^ ... Bitwise exclusive or.
9210 __END__ Ends program source.
9211 __DATA__ Ends program source.
9212 __FILE__ Current (source) filename.
9213 __LINE__ Current line in current source.
9214 __PACKAGE__ Current package.
9215 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
9216 ARGVOUT Output filehandle with -i flag.
9217 BEGIN { ... } Immediately executed (during compilation) piece of code.
9218 END { ... } Pseudo-subroutine executed after the script finishes.
9219 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
9220 INIT { ... } Pseudo-subroutine executed before the script starts running.
9221 DATA Input filehandle for what follows after __END__ or __DATA__.
9222 accept(NEWSOCKET,GENERICSOCKET)
9235 ... cmp ... String compare.
9236 connect(SOCKET,NAME)
9237 continue of { block } continue { block }. Is executed after `next' or at end.
9239 crypt(PLAINTEXT,SALT)
9241 dbmopen(%HASH,DBNAME,MODE)
9245 do { ... }|SUBR while|until EXPR executes at least once
9246 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
9256 ... eq ... String equality.
9257 eval(EXPR) or eval { BLOCK }
9258 exec([TRUENAME] ARGV0, ARGVs) or exec(SHELL_COMMAND_LINE)
9261 fcntl(FILEHANDLE,FUNCTION,SCALAR)
9263 flock(FILEHANDLE,OPERATION)
9264 for (EXPR;EXPR;EXPR) { ... }
9265 foreach [VAR] (@ARRAY) { ... }
9267 ... ge ... String greater than or equal.
9272 gethostbyaddr(ADDR,ADDRTYPE)
9276 getnetbyaddr(ADDR,ADDRTYPE)
9282 getpriority(WHICH,WHO)
9283 getprotobyname(NAME)
9284 getprotobynumber(NUMBER)
9289 getservbyname(NAME,PROTO)
9290 getservbyport(PORT,PROTO)
9293 getsockopt(SOCKET,LEVEL,OPTNAME)
9296 ... gt ... String greater than.
9298 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
9299 index(STR,SUBSTR[,OFFSET])
9301 ioctl(FILEHANDLE,FUNCTION,SCALAR)
9306 ... le ... String less than or equal.
9308 link(OLDFILE,NEWFILE)
9309 listen(SOCKET,QUEUESIZE)
9313 lstat(EXPR|FILEHANDLE|VAR)
9314 ... lt ... String less than.
9316 mkdir(FILENAME,MODE)
9319 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
9320 msgsnd(ID,MSG,FLAGS)
9321 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
9322 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
9323 ... ne ... String inequality.
9326 open(FILEHANDLE[,EXPR])
9327 opendir(DIRHANDLE,EXPR)
9328 ord(EXPR) ASCII value of the first char of the string.
9330 package NAME Introduces package context.
9331 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
9333 print [FILEHANDLE] [(LIST)]
9334 printf [FILEHANDLE] (FORMAT,LIST)
9336 q/STRING/ Synonym for 'STRING'
9337 qq/STRING/ Synonym for \"STRING\"
9338 qx/STRING/ Synonym for `STRING`
9340 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9343 recv(SOCKET,SCALAR,LEN,FLAGS)
9345 rename(OLDNAME,NEWNAME)
9346 require [FILENAME | PERL_VERSION]
9350 rewinddir(DIRHANDLE)
9351 rindex(STR,SUBSTR[,OFFSET])
9353 s/PATTERN/REPLACEMENT/gieoxsm
9355 seek(FILEHANDLE,POSITION,WHENCE)
9356 seekdir(DIRHANDLE,POS)
9357 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
9358 semctl(ID,SEMNUM,CMD,ARG)
9359 semget(KEY,NSEMS,SIZE,FLAGS)
9361 send(SOCKET,MSG,FLAGS[,TO])
9363 sethostent(STAYOPEN)
9366 setpriority(WHICH,WHO,PRIORITY)
9367 setprotoent(STAYOPEN)
9369 setservent(STAYOPEN)
9370 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
9373 shmget(KEY,SIZE,FLAGS)
9374 shmread(ID,VAR,POS,SIZE)
9375 shmwrite(ID,STRING,POS,SIZE)
9376 shutdown(SOCKET,HOW)
9379 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
9380 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
9381 sort [SUBROUTINE] (LIST)
9382 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
9383 split[(/PATTERN/[,EXPR[,LIMIT]])]
9384 sprintf(FORMAT,LIST)
9387 stat(EXPR|FILEHANDLE|VAR)
9389 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
9390 substr(EXPR,OFFSET[,LEN])
9391 symlink(OLDFILE,NEWFILE)
9393 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9394 system([TRUENAME] ARGV0 [,ARGV]) or system(SHELL_COMMAND_LINE)
9395 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9400 tr/SEARCHLIST/REPLACEMENTLIST/cds
9401 truncate(FILE|EXPR,LENGTH)
9404 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
9406 unpack(TEMPLATE,EXPR)
9408 until (EXPR) { ... } EXPR until EXPR
9411 vec(EXPR,OFFSET,BITS)
9414 wantarray Returns true if the sub/eval is called in list context.
9416 while (EXPR) { ... } EXPR while EXPR
9417 write[(EXPR|FILEHANDLE)]
9418 ... x ... Repeat string or array.
9419 x= ... Repetition assignment.
9420 y/SEARCHLIST/REPLACEMENTLIST/
9421 ... | ... Bitwise or.
9422 ... || ... Logical or.
9423 ~ ... Unary bitwise complement.
9424 #! OS interpreter indicator. If contains `perl', used for options, and -x.
9425 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
9426 CORE:: Prefix to access builtin function if imported sub obscures it.
9427 SUPER:: Prefix to lookup for a method in @ISA classes.
9428 DESTROY Shorthand for `sub DESTROY {...}'.
9429 ... EQ ... Obsolete synonym of `eq'.
9430 ... GE ... Obsolete synonym of `ge'.
9431 ... GT ... Obsolete synonym of `gt'.
9432 ... LE ... Obsolete synonym of `le'.
9433 ... LT ... Obsolete synonym of `lt'.
9434 ... NE ... Obsolete synonym of `ne'.
9435 abs [ EXPR ] absolute value
9436 ... and ... Low-precedence synonym for &&.
9437 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
9438 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
9439 chr Converts a number to char with the same ordinal.
9440 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
9441 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
9442 exists $HASH{KEY} True if the key exists.
9443 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
9444 formline PICTURE, LIST Backdoor into \"format\" processing.
9445 glob EXPR Synonym of <EXPR>.
9446 lc [ EXPR ] Returns lowercased EXPR.
9447 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
9448 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
9449 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
9450 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
9451 not ... Low-precedence synonym for ! - negation.
9452 ... or ... Low-precedence synonym for ||.
9453 pos STRING Set/Get end-position of the last match over this string, see \\G.
9454 quotemeta [ EXPR ] Quote regexp metacharacters.
9455 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
9456 readline FH Synonym of <FH>.
9457 readpipe CMD Synonym of `CMD`.
9458 ref [ EXPR ] Type of EXPR when dereferenced.
9459 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
9460 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
9461 tied Returns internal object for a tied data.
9462 uc [ EXPR ] Returns upcased EXPR.
9463 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
9464 untie VAR Unlink an object from a simple Perl variable.
9465 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
9466 ... xor ... Low-precedence synonym for exclusive or.
9467 prototype \&SUB Returns prototype of the function given a reference.
9468 =head1 Top-level heading.
9469 =head2 Second-level heading.
9470 =head3 Third-level heading (is there such?).
9471 =over [ NUMBER ] Start list.
9472 =item [ TITLE ] Start new item in the list.
9474 =cut Switch from POD to Perl.
9475 =pod Switch from Perl to POD.
9478 (defun cperl-switch-to-doc-buffer ()
9479 "Go to the perl documentation buffer and insert the documentation."
9481 (let ((buf (get-buffer-create cperl-doc-buffer)))
9483 (switch-to-buffer-other-window buf)
9485 (if (= (buffer-size) 0)
9487 (insert (documentation-property 'cperl-short-docs
9488 'variable-documentation))
9489 (setq buffer-read-only t)))))
9491 (defun cperl-beautify-regexp-piece (b e embed level)
9492 ;; b is before the starting delimiter, e before the ending
9493 ;; e should be a marker, may be changed, but remains "correct".
9494 ;; EMBED is nil iff we process the whole REx.
9495 ;; The REx is guaranteed to have //x
9496 ;; LEVEL shows how many levels deep to go
9497 ;; position at enter and at leave is not defined
9498 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
9502 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
9506 ((looking-at "(\\?[^a-zA-Z]")
9508 ((looking-at "(\\?") ; (?i)
9512 (setq c (if embed (current-indentation) (1- (current-column)))
9513 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
9514 (or (looking-at "[ \t]*[\n#]")
9519 (if (re-search-forward "[^ \t]" e t)
9520 (progn ; Something before the ending delimiter
9522 (delete-horizontal-space)
9524 (cperl-make-indent c)
9525 (set-marker e (point))))
9528 (while (< (point) (marker-position e))
9532 (skip-chars-forward " \t")
9533 (delete-region s (point))
9534 (cperl-make-indent c1)
9538 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
9539 "\\|" ; Embedded variable
9540 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
9543 "\\|" ; simple-code simple-code*?
9544 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
9548 "\\((\\(\\?\\)?\\)" ; 7 8
9551 (goto-char (match-end 0))
9553 (cond ((match-beginning 1) ; Alphanum word + junk
9555 ((or (match-beginning 3) ; $ab[12]
9556 (and (match-beginning 5) ; X* X+ X{2,3}
9557 (eq (preceding-char) ?\{)))
9560 ((and ; [], already syntaxified
9563 cperl-use-syntax-table-text-property)
9566 (or (eq (preceding-char) ?\])
9567 (error "[]-group not terminated"))
9569 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
9570 ((match-beginning 6) ; []
9572 (if (looking-at "\\^?\\]")
9573 (goto-char (match-end 0)))
9574 ;; XXXX POSIX classes?!
9575 (while (and (not pos)
9576 (re-search-forward "\\[:\\|\\]" e t))
9577 (if (eq (preceding-char) ?:)
9578 (or (re-search-forward ":\\]" e t)
9579 (error "[:POSIX:]-group in []-group not terminated"))
9581 (or (eq (preceding-char) ?\])
9582 (error "[]-group not terminated"))
9584 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
9585 ((match-beginning 7) ; ()
9586 (goto-char (match-beginning 0))
9587 (setq pos (current-column))
9590 (delete-horizontal-space)
9592 (cperl-make-indent c1)))
9595 ;; (or (forward-sexp 1)
9598 ;; (error "()-group not terminated")))
9599 (set-marker m (1- (point)))
9600 (set-marker m1 (point))
9602 (if (progn ; indent rigidly if multiline
9603 ;; In fact does not make a lot of sense, since
9604 ;; the starting position can be already lost due
9605 ;; to insertion of "\n" and " "
9607 (search-forward "\n" m1 t))
9608 (indent-rigidly (point) m1 (- c1 pos)))
9609 (setq level (1- level))
9611 ((not (match-beginning 8))
9612 (cperl-beautify-regexp-piece tmp m t level))
9613 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
9615 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
9616 (goto-char (+ 2 tmp))
9618 (cperl-beautify-regexp-piece (point) m t level))
9619 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
9620 (goto-char (+ 3 tmp))
9621 (cperl-beautify-regexp-piece (point) m t level))
9623 (cperl-beautify-regexp-piece tmp m t level))))
9625 (cond ((looking-at "[*+?]\\??")
9626 (goto-char (match-end 0)))
9627 ((eq (following-char) ?\{)
9629 (if (eq (following-char) ?\?)
9631 (skip-chars-forward " \t")
9633 (if (looking-at "[#\n]")
9635 (or (eolp) (indent-for-comment))
9636 (beginning-of-line 2))
9637 (delete-horizontal-space)
9641 ((match-beginning 9) ; |
9645 (if (re-search-forward "[^ \t]" tmp t)
9648 (delete-horizontal-space)
9651 (delete-region (point) tmp))
9652 (cperl-make-indent c)
9654 (skip-chars-forward " \t")
9656 (if (looking-at "[#\n]")
9657 (beginning-of-line 2)
9658 (delete-horizontal-space)
9662 (or (looking-at "[ \t\n]")
9665 (skip-chars-forward " \t"))
9666 (or (looking-at "[#\n]")
9667 (error "Unknown code `%s' in a regexp"
9668 (buffer-substring (point) (1+ (point)))))
9669 (and inline (end-of-line 2)))
9670 ;; Special-case the last line of group
9671 (if (and (>= (point) (marker-position e))
9672 (/= (current-indentation) c))
9675 (cperl-make-indent c)))))
9677 (defun cperl-make-regexp-x ()
9678 ;; Returns position of the start
9679 ;; XXX this is called too often! Need to cache the result!
9681 (or cperl-use-syntax-table-text-property
9682 (error "I need to have a regexp marked!"))
9684 (if (looking-at "\\s|")
9686 (if (looking-at "\\([smy]\\|qr\\)\\s|")
9688 (re-search-backward "\\s|"))) ; Assume it is scanned already.
9690 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
9691 (sub-p (eq (preceding-char) ?s)) s)
9693 (set-marker e (1- (point)))
9694 (setq delim (preceding-char))
9695 (if (and sub-p (eq delim (char-after (- (point) 2))))
9696 (error "Possible s/blah// - do not know how to deal with"))
9697 (if sub-p (forward-sexp 1))
9698 (if (looking-at "\\sw*x")
9701 ;; Protect fragile " ", "#"
9704 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
9710 (defun cperl-beautify-regexp (&optional deep)
9711 "Do it. (Experimental, may change semantics, recheck the result.)
9712 We suppose that the regexp is scanned already."
9714 (setq deep (if deep (prefix-numeric-value deep) -1))
9716 (goto-char (cperl-make-regexp-x))
9717 (let ((b (point)) (e (make-marker)))
9719 (set-marker e (1- (point)))
9720 (cperl-beautify-regexp-piece b e nil deep))))
9722 (defun cperl-regext-to-level-start ()
9723 "Goto start of an enclosing group in regexp.
9724 We suppose that the regexp is scanned already."
9726 (let ((limit (cperl-make-regexp-x)) done)
9728 (or (eq (following-char) ?\()
9729 (search-backward "(" (1+ limit) t)
9730 (error "Cannot find `(' which starts a group"))
9733 (skip-chars-backward "\\")
9734 (looking-at "\\(\\\\\\\\\\)*(")))
9735 (or done (forward-char -1)))))
9737 (defun cperl-contract-level ()
9738 "Find an enclosing group in regexp and contract it.
9739 \(Experimental, may change semantics, recheck the result.)
9740 We suppose that the regexp is scanned already."
9742 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
9743 (cperl-regext-to-level-start)
9744 (let ((b (point)) (e (make-marker)) c)
9746 (set-marker e (1- (point)))
9748 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
9750 ((match-beginning 1) ; #-comment
9751 (or c (setq c (current-indentation)))
9752 (beginning-of-line 2) ; Skip
9753 (cperl-make-indent c))
9756 (just-one-space))))))
9758 (defun cperl-contract-levels ()
9759 "Find an enclosing group in regexp and contract all the kids.
9760 \(Experimental, may change semantics, recheck the result.)
9761 We suppose that the regexp is scanned already."
9765 (cperl-regext-to-level-start)
9766 (error ; We are outside outermost group
9767 (goto-char (cperl-make-regexp-x))))
9768 (let ((b (point)) (e (make-marker)) s c)
9770 (set-marker e (1- (point)))
9772 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
9774 ((match-beginning 1) ; Skip
9777 (cperl-contract-level)))))))
9779 (defun cperl-beautify-level (&optional deep)
9780 "Find an enclosing group in regexp and beautify it.
9781 \(Experimental, may change semantics, recheck the result.)
9782 We suppose that the regexp is scanned already."
9784 (setq deep (if deep (prefix-numeric-value deep) -1))
9786 (cperl-regext-to-level-start)
9787 (let ((b (point)) (e (make-marker)))
9789 (set-marker e (1- (point)))
9790 (cperl-beautify-regexp-piece b e nil deep))))
9792 (defun cperl-invert-if-unless-modifiers ()
9793 "Change `B if A;' into `if (A) {B}' etc if possible.
9796 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string
9797 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>"))
9798 (and (= (char-syntax (preceding-char)) ?w)
9800 (setq pre-if (point))
9801 (cperl-backward-to-start-of-expr)
9802 (setq pre-B (point))
9803 (forward-sexp 1) ; otherwise forward-to-end-of-expr is NOP
9804 (cperl-forward-to-end-of-expr)
9805 (setq post-A (point))
9807 (or (looking-at w-rex)
9808 ;; Find the position
9809 (progn (goto-char post-A)
9811 (not (looking-at w-rex))
9814 (setq pre-if (point))))
9815 (or (looking-at w-rex)
9816 (error "Can't find `if', `unless', `while', `until', `for' or `foreach'"))
9817 ;; 1 B 2 ... 3 B-com ... 4 if 5 ... if-com 6 ... 7 A 8
9818 (setq if-string (buffer-substring (match-beginning 0) (match-end 0)))
9819 ;; First, simple part: find code boundaries
9821 (setq post-if (point))
9824 (setq post-B (point))
9825 (cperl-backward-to-start-of-expr)
9826 (setq pre-B (point))
9827 (setq B (buffer-substring pre-B post-B))
9831 ;; May be after $, @, $# etc of a variable
9832 (skip-chars-backward "$@%#")
9833 (setq pre-A (point))
9834 (cperl-forward-to-end-of-expr)
9835 (setq post-A (point))
9836 (setq A (buffer-substring pre-A post-A))
9837 ;; Now modify (from end, to not break the stuff)
9838 (skip-chars-forward " \t;")
9839 (delete-region pre-A (point)) ; we move to pre-A
9840 (insert "\n" B ";\n}")
9841 (and (looking-at "[ \t]*#") (cperl-indent-for-comment))
9842 (delete-region pre-if post-if)
9843 (delete-region pre-B post-B)
9845 (insert if-string " (" A ") {")
9846 (setq post-B (point))
9847 (if (looking-at "[ \t]+$")
9848 (delete-horizontal-space)
9849 (if (looking-at "[ \t]*#")
9850 (cperl-indent-for-comment)
9853 (if (looking-at "[ \t]*$")
9854 (progn ; delete line
9855 (delete-horizontal-space)
9856 (delete-region (point) (1+ (point)))))
9858 (goto-char (1- post-B))
9863 (defun cperl-invert-if-unless ()
9864 "Change `if (A) {B}' into `B if A;' etc (or visa versa) if possible.
9865 If the cursor is not on the leading keyword of the BLOCK flavor of
9866 construct, will assume it is the STATEMENT flavor, so will try to find
9867 the appropriate statement modifier."
9869 (and (= (char-syntax (preceding-char)) ?w)
9871 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
9872 (let ((pre-if (point))
9873 pre-A post-A pre-B post-B A B state p end-B-code is-block B-comment
9874 (if-string (buffer-substring (match-beginning 0) (match-end 0))))
9876 (setq post-A (point))
9878 (setq pre-A (point))
9879 (setq is-block (and (eq (following-char) ?\( )
9885 (eq (following-char) ?\{ ))
9891 (setq post-B (point))
9893 (setq pre-B (point))
9894 (if (and (eq (following-char) ?\{ )
9896 (cperl-backward-to-noncomment post-A)
9897 (eq (preceding-char) ?\) )))
9898 (if (condition-case nil
9903 (looking-at "\\<els\\(e\\|if\\)\\>"))
9906 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" if-string)
9907 (goto-char (1- post-B))
9908 (cperl-backward-to-noncomment pre-B)
9909 (if (eq (preceding-char) ?\;)
9911 (setq end-B-code (point))
9913 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" end-B-code t)
9914 (setq p (match-beginning 0)
9915 A (buffer-substring p (match-end 0))
9916 state (parse-partial-sexp pre-B p))
9920 (error "`%s' inside `%s' BLOCK" A if-string))
9921 (goto-char (match-end 0)))
9923 (goto-char (1+ pre-B))
9924 (skip-chars-forward " \t\n")
9925 (setq B (buffer-substring (point) end-B-code))
9926 (goto-char end-B-code)
9927 (or (looking-at ";?[ \t\n]*}")
9929 (skip-chars-forward "; \t\n")
9931 (buffer-substring (point) (1- post-B)))))
9934 (goto-char (1- post-A))
9935 (cperl-backward-to-noncomment pre-A)
9936 (or (looking-at "[ \t\n]*)")
9937 (goto-char (1- post-A)))
9939 (goto-char (1+ pre-A))
9940 (skip-chars-forward " \t\n")
9941 (setq A (buffer-substring (point) p))
9942 (delete-region pre-B post-B)
9943 (delete-region pre-A post-A)
9946 (and B-comment (insert B-comment " "))
9949 (setq pre-A (point))
9951 (delete-horizontal-space)
9952 (setq post-B (point))
9953 (if (looking-at "#")
9954 (indent-for-comment))
9957 (delete-horizontal-space)
9961 (setq pre-A (set-marker (make-marker) pre-A))
9962 (while (<= (point) (marker-position pre-A))
9965 (goto-char (marker-position pre-A))
9969 (indent-for-comment)
9970 (goto-char (marker-position pre-A)))))
9971 (error "`%s' (EXPR) not with an {BLOCK}" if-string)))
9972 ;; (error "`%s' not with an (EXPR)" if-string)
9974 (cperl-invert-if-unless-modifiers)))
9975 ;;(error "Not at `if', `unless', `while', `until', `for' or `foreach'")
9976 (cperl-invert-if-unless-modifiers)))
9978 ;;; By Anthony Foiani <afoiani@uswest.com>
9979 ;;; Getting help on modules in C-h f ?
9980 ;;; This is a modified version of `man'.
9981 ;;; Need to teach it how to lookup functions
9983 (defun cperl-perldoc (word)
9984 "Run `perldoc' on WORD."
9986 (list (let* ((default-entry (cperl-word-at-point))
9988 (format "perldoc entry%s: "
9989 (if (string= default-entry "")
9991 (format " (default %s)" default-entry))))))
9992 (if (string= input "")
9993 (if (string= default-entry "")
9994 (error "No perldoc args given")
9998 (let* ((case-fold-search nil)
10000 (string-match "^[a-z]+$" word)
10001 (string-match (concat "^" word "\\>")
10002 (documentation-property
10004 'variable-documentation))))
10005 (manual-program (if is-func "perldoc -f" "perldoc")))
10008 (let ((Manual-program "perldoc")
10009 (Manual-switches (if is-func (list "-f"))))
10010 (manual-entry word)))
10012 (Man-getpage-in-background word)))))
10015 (defun cperl-perldoc-at-point ()
10016 "Run a `perldoc' on the word around point."
10018 (cperl-perldoc (cperl-word-at-point)))
10020 (defcustom pod2man-program "pod2man"
10021 "*File name for `pod2man'."
10025 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
10026 (defun cperl-pod-to-manpage ()
10027 "Create a virtual manpage in Emacs from the Perl Online Documentation."
10030 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
10031 (bufname (concat "Man " buffer-file-name))
10032 (buffer (generate-new-buffer bufname)))
10034 (set-buffer buffer)
10035 (let ((process-environment (copy-sequence process-environment)))
10036 ;; Prevent any attempt to use display terminal fanciness.
10037 (setenv "TERM" "dumb")
10038 (set-process-sentinel
10039 (start-process pod2man-program buffer "sh" "-c"
10040 (format (cperl-pod2man-build-command) pod2man-args))
10041 'Man-bgproc-sentinel)))))
10043 ;;; Updated version by him too
10044 (defun cperl-build-manpage ()
10045 "Create a virtual manpage in Emacs from the POD in the file."
10050 (let ((Manual-program "perldoc"))
10051 (manual-entry buffer-file-name)))
10053 (let* ((manual-program "perldoc"))
10054 (Man-getpage-in-background buffer-file-name)))))
10056 (defun cperl-pod2man-build-command ()
10057 "Builds the entire background manpage and cleaning command."
10058 (let ((command (concat pod2man-program " %s 2>/dev/null"))
10059 (flist (and (boundp 'Man-filter-list) Man-filter-list)))
10060 (while (and flist (car flist))
10061 (let ((pcom (car (car flist)))
10062 (pargs (cdr (car flist))))
10064 (concat command " | " pcom " "
10065 (mapconcat '(lambda (phrase)
10066 (if (not (stringp phrase))
10067 (error "Malformed Man-filter-list"))
10070 (setq flist (cdr flist))))
10074 (defun cperl-next-interpolated-REx-1 ()
10075 "Move point to next REx which has interpolated parts without //o.
10076 Skips RExes consisting of one interpolated variable.
10078 Note that skipped RExen are not performance hits."
10080 (cperl-next-interpolated-REx 1))
10082 (defun cperl-next-interpolated-REx-0 ()
10083 "Move point to next REx which has interpolated parts without //o."
10085 (cperl-next-interpolated-REx 0))
10087 (defun cperl-next-interpolated-REx (&optional skip beg limit)
10088 "Move point to next REx which has interpolated parts.
10089 SKIP is a list of possible types to skip, BEG and LIMIT are the starting
10090 point and the limit of search (default to point and end of buffer).
10092 SKIP may be a number, then it behaves as list of numbers up to SKIP; this
10093 semantic may be used as a numeric argument.
10095 Types are 0 for / $rex /o (interpolated once), 1 for /$rex/ (if $rex is
10096 a result of qr//, this is not a performance hit), t for the rest."
10098 (if (numberp skip) (setq skip (list 0 skip)))
10099 (or beg (setq beg (point)))
10100 (or limit (setq limit (point-max))) ; needed for n-s-p-c
10102 (and (eq (get-text-property beg 'syntax-type) 'string)
10103 (setq beg (next-single-property-change beg 'syntax-type nil limit)))
10104 (cperl-map-pods-heres
10105 (function (lambda (s e p)
10106 (if (memq (get-text-property s 'REx-interpolated) skip)
10110 'REx-interpolated beg limit)
10111 (if pp (goto-char pp)
10112 (message "No more interpolated REx"))))
10114 ;;; Initial version contributed by Trey Belew
10115 (defun cperl-here-doc-spell (&optional beg end)
10116 "Spell-check HERE-documents in the Perl buffer.
10117 If a region is highlighted, restricts to the region."
10119 (cperl-pod-spell t beg end))
10121 (defun cperl-pod-spell (&optional do-heres beg end)
10122 "Spell-check POD documentation.
10123 If invoked with prefix argument, will do HERE-DOCs instead.
10124 If a region is highlighted, restricts to the region."
10128 (if (cperl-mark-active)
10129 (setq beg (min (mark) (point))
10130 end (max (mark) (point)))
10131 (setq beg (point-min)
10133 (cperl-map-pods-heres (function
10136 (setq e (save-excursion
10140 (ispell-region s e)
10142 (if do-heres 'here-doc-group 'in-pod)
10145 (defun cperl-map-pods-heres (func &optional prop s end)
10146 "Executes a function over regions of pods or here-documents.
10147 PROP is the text-property to search for; default to `in-pod'. Stop when
10148 function returns nil."
10149 (let (pos posend has-prop (cont t))
10150 (or prop (setq prop 'in-pod))
10151 (or s (setq s (point-min)))
10152 (or end (setq end (point-max)))
10153 (cperl-update-syntaxification end end)
10155 (goto-char (setq pos s))
10156 (while (and cont (< pos end))
10157 (setq has-prop (get-text-property pos prop))
10158 (setq posend (next-single-property-change pos prop nil end))
10160 (setq cont (funcall func pos posend prop)))
10161 (setq pos posend)))))
10163 ;;; Based on code by Masatake YAMATO:
10164 (defun cperl-get-here-doc-region (&optional pos pod)
10165 "Return HERE document region around the point.
10166 Return nil if the point is not in a HERE document region. If POD is non-nil,
10167 will return a POD section if point is in a POD section."
10168 (or pos (setq pos (point)))
10169 (cperl-update-syntaxification pos pos)
10170 (if (or (eq 'here-doc (get-text-property pos 'syntax-type))
10172 (eq 'pod (get-text-property pos 'syntax-type))))
10173 (let ((b (cperl-beginning-of-property pos 'syntax-type))
10174 (e (next-single-property-change pos 'syntax-type)))
10175 (cons b (or e (point-max))))))
10177 (defun cperl-narrow-to-here-doc (&optional pos)
10178 "Narrows editing region to the HERE-DOC at POS.
10179 POS defaults to the point."
10181 (or pos (setq pos (point)))
10182 (let ((p (cperl-get-here-doc-region pos)))
10183 (or p (error "Not inside a HERE document"))
10184 (narrow-to-region (car p) (cdr p))
10186 "When you are finished with narrow editing, type C-x n w")))
10188 (defun cperl-select-this-pod-or-here-doc (&optional pos)
10189 "Select the HERE-DOC (or POD section) at POS.
10190 POS defaults to the point."
10192 (let ((p (cperl-get-here-doc-region pos t)))
10195 (goto-char (car p))
10196 (push-mark (cdr p) nil t)) ; Message, activate in transient-mode
10197 (message "I do not think POS is in POD or a HERE-doc..."))))
10199 (defun cperl-facemenu-add-face-function (face end)
10200 "A callback to process user-initiated font-change requests.
10201 Translates `bold', `italic', and `bold-italic' requests to insertion of
10202 corresponding POD directives, and `underline' to C<> POD directive.
10204 Such requests are usually bound to M-o LETTER."
10205 (or (get-text-property (point) 'in-pod)
10206 (error "Faces can only be set within POD"))
10207 (setq facemenu-end-add-face (if (eq face 'bold-italic) ">>" ">"))
10208 (cdr (or (assq face '((bold . "B<")
10210 (bold-italic . "B<I<")
10211 (underline . "C<")))
10212 (error "Face %s not configured for cperl-mode"
10215 (defun cperl-time-fontification (&optional l step lim)
10216 "Times how long it takes to do incremental fontification in a region.
10217 L is the line to start at, STEP is the number of lines to skip when
10218 doing next incremental fontification, LIM is the maximal number of
10219 incremental fontification to perform. Messages are accumulated in
10222 May be used for pinpointing which construct slows down buffer fontification:
10223 start with default arguments, then refine the slowdown regions."
10224 (interactive "nLine to start at: \nnStep to do incremental fontification: ")
10226 (or step (setq step 500))
10227 (or lim (setq lim 40))
10228 (let* ((timems (function (lambda ()
10229 (let ((tt (current-time)))
10230 (+ (* 1000 (nth 1 tt)) (/ (nth 2 tt) 1000))))))
10231 (tt (funcall timems)) (c 0) delta tot)
10234 (setq tot (- (- tt (setq tt (funcall timems)))))
10235 (message "cperl-mode at %s: %s" l tot)
10236 (while (and (< c lim) (not (eobp)))
10237 (forward-line step)
10238 (setq l (+ l step))
10240 (cperl-update-syntaxification (point) (point))
10241 (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
10242 (message "to %s:%6s,%7s" l delta tot))
10245 (defun cperl-emulate-lazy-lock (&optional window-size)
10246 "Emulate `lazy-lock' without `condition-case', so `debug-on-error' works.
10247 Start fontifying the buffer from the start (or end) using the given
10248 WINDOW-SIZE (units is lines). Negative WINDOW-SIZE starts at end, and
10249 goes backwards; default is -50. This function is not CPerl-specific; it
10250 may be used to debug problems with delayed incremental fontification."
10252 "nSize of window for incremental fontification, negative goes backwards: ")
10253 (or window-size (setq window-size -50))
10254 (let ((pos (if (> window-size 0)
10260 ;; Why needed??? With older font-locks???
10261 (set (make-local-variable 'font-lock-cache-position) (make-marker))
10262 (while (if (> window-size 0)
10263 (< pos (point-max))
10264 (> pos (point-min)))
10266 (forward-line window-size)
10268 (font-lock-fontify-region (min p pos) (max p pos))
10272 (defun cperl-lazy-install ()) ; Avoid a warning
10273 (defun cperl-lazy-unstall ()) ; Avoid a warning
10275 (if (fboundp 'run-with-idle-timer)
10277 (defvar cperl-help-shown nil
10278 "Non-nil means that the help was already shown now.")
10280 (defvar cperl-lazy-installed nil
10281 "Non-nil means that the lazy-help handlers are installed now.")
10283 (defun cperl-lazy-install ()
10284 "Switches on Auto-Help on Perl constructs (put in the message area).
10285 Delay of auto-help controlled by `cperl-lazy-help-time'."
10287 (make-variable-buffer-local 'cperl-help-shown)
10288 (if (and (cperl-val 'cperl-lazy-help-time)
10289 (not cperl-lazy-installed))
10291 (add-hook 'post-command-hook 'cperl-lazy-hook)
10292 (run-with-idle-timer
10293 (cperl-val 'cperl-lazy-help-time 1000000 5)
10295 'cperl-get-help-defer)
10296 (setq cperl-lazy-installed t))))
10298 (defun cperl-lazy-unstall ()
10299 "Switches off Auto-Help on Perl constructs (put in the message area).
10300 Delay of auto-help controlled by `cperl-lazy-help-time'."
10302 (remove-hook 'post-command-hook 'cperl-lazy-hook)
10303 (cancel-function-timers 'cperl-get-help-defer)
10304 (setq cperl-lazy-installed nil))
10306 (defun cperl-lazy-hook ()
10307 (setq cperl-help-shown nil))
10309 (defun cperl-get-help-defer ()
10310 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
10311 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
10313 (setq cperl-help-shown t))))
10314 (cperl-lazy-install)))
10317 ;;; Plug for wrong font-lock:
10319 (defun cperl-font-lock-unfontify-region-function (beg end)
10320 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
10321 (inhibit-read-only t) (inhibit-point-motion-hooks t)
10322 before-change-functions after-change-functions
10323 deactivate-mark buffer-file-name buffer-file-truename)
10324 (remove-text-properties beg end '(face nil))
10325 (if (and (not modified) (buffer-modified-p))
10326 (set-buffer-modified-p nil))))
10328 (defun cperl-font-lock-fontify-region-function (beg end loudly)
10329 "Extends the region to safe positions, then calls the default function.
10330 Newer `font-lock's can do it themselves.
10331 We unwind only as far as needed for fontification. Syntaxification may
10332 do extra unwind via `cperl-unwind-to-safe'."
10337 (beginning-of-line)
10338 (eq (get-text-property (setq beg (point)) 'syntax-type)
10340 (if (setq beg (cperl-beginning-of-property beg 'syntax-type))
10346 (or (bolp) (condition-case nil
10349 (eq (get-text-property (setq end (point)) 'syntax-type)
10351 (setq end (next-single-property-change end 'syntax-type nil (point-max)))
10353 (setq end (point)))
10354 (font-lock-default-fontify-region beg end loudly))
10356 (defvar cperl-d-l nil)
10357 (defun cperl-fontify-syntaxically (end)
10358 ;; Some vars for debugging only
10359 ;; (message "Syntaxifying...")
10360 (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
10361 (istate (car cperl-syntax-state))
10362 start from-start edebug-backtrace-buffer)
10363 (if (eq cperl-syntaxify-by-font-lock 'backtrace)
10366 (let ((f 'edebug-backtrace))
10367 (funcall f)))) ; Avoid compile-time warning
10368 (or cperl-syntax-done-to
10369 (setq cperl-syntax-done-to (point-min)
10371 (setq start (if (and cperl-hook-after-change
10373 cperl-syntax-done-to ; Fontify without change; ignore start
10374 ;; Need to forget what is after `start'
10375 (min cperl-syntax-done-to (point))))
10377 (beginning-of-line)
10378 (setq start (point))
10379 (and cperl-syntaxify-unwind
10380 (setq end (cperl-unwind-to-safe t end)
10383 (setq cperl-syntax-done-to start) ; In case what follows fails
10384 (cperl-find-pods-heres start end t nil t))
10385 (if (memq cperl-syntaxify-by-font-lock '(backtrace message))
10386 (message "Syxify req=%s..%s actual=%s..%s done-to: %s=>%s statepos: %s=>%s"
10387 dbg iend start end idone cperl-syntax-done-to
10388 istate (car cperl-syntax-state))) ; For debugging
10389 nil)) ; Do not iterate
10391 (defun cperl-fontify-update (end)
10392 (let ((pos (point-min)) prop posend)
10393 (setq end (point-max))
10395 (setq prop (get-text-property pos 'cperl-postpone)
10396 posend (next-single-property-change pos 'cperl-postpone nil end))
10397 (and prop (put-text-property pos posend (car prop) (cdr prop)))
10398 (setq pos posend)))
10399 nil) ; Do not iterate
10401 (defun cperl-fontify-update-bad (end)
10402 ;; Since fontification happens with different region than syntaxification,
10403 ;; do to the end of buffer, not to END;;; likewise, start earlier if needed
10404 (let* ((pos (point)) (prop (get-text-property pos 'cperl-postpone)) posend)
10406 (setq pos (or (cperl-beginning-of-property
10407 (cperl-1+ pos) 'cperl-postpone)
10410 (setq posend (next-single-property-change pos 'cperl-postpone))
10411 (and prop (put-text-property pos posend (car prop) (cdr prop)))
10413 (setq prop (get-text-property pos 'cperl-postpone))))
10414 nil) ; Do not iterate
10416 ;; Called when any modification is made to buffer text.
10417 (defun cperl-after-change-function (beg end old-len)
10418 ;; We should have been informed about changes by `font-lock'. Since it
10419 ;; does not inform as which calls are defered, do it ourselves
10420 (if cperl-syntax-done-to
10421 (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
10423 (defun cperl-update-syntaxification (from to)
10424 (if (and cperl-use-syntax-table-text-property
10425 cperl-syntaxify-by-font-lock
10426 (or (null cperl-syntax-done-to)
10427 (< cperl-syntax-done-to to)))
10431 (cperl-fontify-syntaxically to)))))
10433 (defvar cperl-version
10434 (let ((v "$Revision: 5.23 $"))
10435 (string-match ":\\s *\\([0-9.]+\\)" v)
10436 (substring v (match-beginning 1) (match-end 1)))
10437 "Version of IZ-supported CPerl package this file is based on.")
10439 (provide 'cperl-mode)
10441 ;;; cperl-mode.el ends here