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
45 ;;; XEmacs 'delete key behavior handling added for XEmacs 20.x by
46 ;;; Gary D. Foster <Gary.Foster@corp.sun.com>
47 ;;; Karl M. Hegbloom <karlheg@inetarena.com>
51 ;; $Id: cperl-mode.el,v 6.2 2008/04/14 23:14:52 vera Exp vera $
53 ;;; If your Emacs does not default to `cperl-mode' on Perl files:
54 ;;; To use this mode put the following into
57 ;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)
59 ;; You can either fine-tune the bells and whistles of this mode or
60 ;; bulk enable them by putting
62 ;; (setq cperl-hairy t)
64 ;; in your .emacs file. (Emacs rulers do not consider it politically
65 ;; correct to make whistles enabled by default.)
67 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
68 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
69 ;; `cperl-non-problems', `cperl-praise', `cperl-speed'. <<<<<<
71 ;;; Note also that there are "authoritative" version of this file <<<<<<
72 ;;; (available on http://ilyaz.org/software/emacs/), and versions <<<<<<
73 ;;; "customized" for a particular Emacs distribution by Emacs <<<<<<
74 ;;; maintainers themselves. As expected, the "authoritative" <<<<<<
75 ;;; version is known to be much less buggy. Usually the <<<<<<
76 ;;; maintainers add a verbiage after numbers in `cperl-version'. <<<<<<
78 ;; Additional useful commands to put into your .emacs file (before
81 ;; (setq auto-mode-alist
82 ;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
83 ;; (setq interpreter-mode-alist (append interpreter-mode-alist
84 ;; '(("miniperl" . perl-mode))))
86 ;; The mode information (on C-h m) provides some customization help.
87 ;; If you use font-lock feature of this mode, it is advisable to use
88 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
90 ;; Faces used now: three faces for first-class and second-class keywords
91 ;; and control flow words, one for each: comments, string, labels,
92 ;; functions definitions and packages, arrays, hashes, and variable
93 ;; definitions. If you do not see all these faces, your font-lock does
94 ;; not define them, so you need to define them manually.
95 ;; Maybe you have an obsolete font-lock from 19.28 or earlier. Upgrade.
97 ;; If you have a grayscale monitor, and do not have the variable
98 ;; font-lock-display-type bound to 'grayscale, insert
100 ;; (setq font-lock-display-type 'grayscale)
102 ;; into your .emacs file (this is relevant before RMS Emacs 20).
104 ;; This mode supports font-lock, imenu and mode-compile. In the
105 ;; hairy version font-lock is on, but you should activate imenu
106 ;; yourself (note that mode-compile is not standard yet). Well, you
107 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
108 ;; to bind it like that:
110 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
112 ;;; Font lock bugs as of v4.32:
114 ;; The following kinds of Perl code erroneously start strings:
116 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
117 ;; likewise with m, tr, y, q, qX instead of s
119 ;;; In fact the version of font-lock that this version supports can be
120 ;;; much newer than the version you actually have. This means that a
121 ;;; lot of faces can be set up, but are not visible on your screen
122 ;;; since the coloring rules for this faces are not defined.
124 ;;; Updates: ========================================
126 ;;; Made less hairy by default: parentheses not electric,
127 ;;; linefeed not magic. Bug with abbrev-mode corrected.
130 ;;; Better indentation:
131 ;;; subs inside braces should work now,
132 ;;; Toplevel braces obey customization.
133 ;;; indent-for-comment knows about bad cases, cperl-indent-for-comment
134 ;;; moves cursor to a correct place.
135 ;;; cperl-indent-exp written from the scratch! Slow... (quadratic!) :-(
136 ;;; (50 secs on DB::DB (sub of 430 lines), 486/66)
137 ;;; Minor documentation fixes.
138 ;;; Imenu understands packages as prefixes (including nested).
139 ;;; Hairy options can be switched off one-by-one by setting to null.
140 ;;; Names of functions and variables changed to conform to `cperl-' style.
143 ;;; Some bugs with indentation of labels (and embedded subs) corrected.
144 ;;; `cperl-indent-region' done (slow :-()).
145 ;;; `cperl-fill-paragraph' done.
146 ;;; Better package support for `imenu'.
147 ;;; Progress indicator for indentation (with `imenu' loaded).
148 ;;; `Cperl-set' was busted, now setting the individual hairy option
149 ;;; should be better.
152 ;;; `cperl-set-style' done.
153 ;;; `cperl-check-syntax' done.
155 ;;; New config variables `cperl-close-paren-offset' and `cperl-comment-column'.
156 ;;; Bugs with `cperl-auto-newline' corrected.
157 ;;; `cperl-electric-lbrace' can work with `cperl-auto-newline' in situation
160 ;;;; 1.7 XEmacs (arius@informatik.uni-erlangen.de):
161 ;;; - use `next-command-event', if `next-command-events' does not exist
162 ;;; - use `find-face' as def. of `is-face'
163 ;;; - corrected def. of `x-color-defined-p'
164 ;;; - added const defs for font-lock-comment-face,
165 ;;; font-lock-keyword-face and font-lock-function-name-face
166 ;;; - added def. of font-lock-variable-name-face
167 ;;; - added (require 'easymenu) inside an `eval-when-compile'
168 ;;; - replaced 4-argument `substitute-key-definition' with ordinary
170 ;;; - replaced `mark-active' in menu definition by `cperl-use-region-p'.
172 ;;; - use emacs-vers.el (http://www.cs.utah.edu/~eeide/emacs/emacs-vers.el.gz)
173 ;;; for portable code?
174 ;;; - should `cperl-mode' do a
175 ;;; (if (featurep 'easymenu) (easy-menu-add cperl-menu))
176 ;;; or should this be left to the user's `cperl-mode-hook'?
178 ;;; Some bugs introduced by the above fix corrected (IZ ;-).
179 ;;; Some bugs under XEmacs introduced by the correction corrected.
181 ;;; Some more can remain since there are two many different variants.
184 ;;; We do not support fontification of arrays and hashes under
185 ;;; obsolete font-lock any more. Upgrade.
187 ;;;; after 1.8 Minor bug with parentheses.
188 ;;;; after 1.9 Improvements from Joe Marzot.
190 ;;; Does not need easymenu to compile under XEmacs.
191 ;;; `vc-insert-headers' should work better.
192 ;;; Should work with 19.29 and 19.12.
193 ;;; Small improvements to fontification.
194 ;;; Expansion of keywords does not depend on C-? being backspace.
197 ;;; 19.29 and 19.12 supported.
198 ;;; `cperl-font-lock-enhanced' deprecated. Use font-lock-extra.el.
199 ;;; Support for font-lock-extra.el.
203 ;;; Support for perl5-info.
204 ;;; `imenu-go-find-at-position' in Tools requires imenu-go.el (see hints above)
205 ;;; Imenu entries do not work with stock imenu.el. Patch sent to maintainers.
206 ;;; Fontifies `require a if b;', __DATA__.
207 ;;; Arglist for auto-fill-mode was incorrect.
210 ;;; `cperl-lineup-step' and `cperl-lineup' added: lineup constructions
212 ;;; `cperl-do-auto-fill' updated for 19.29 style.
213 ;;; `cperl-info-on-command' now has a default.
214 ;;; Workaround for broken C-h on XEmacs.
215 ;;; VC strings escaped.
216 ;;; C-h f now may prompt for function name instead of going on,
217 ;;; controlled by `cperl-info-on-command-no-prompt'.
220 ;;; Msb buffer list includes perl files
221 ;;; Indent-for-comment uses indent-to
222 ;;; Can write tag files using etags.
225 ;;; Recognizes (tries to ;-) {...} which are not blocks during indentation.
226 ;;; `cperl-close-paren-offset' affects ?\] too (and ?\} if not block)
227 ;;; Bug with auto-filling comments started with "##" corrected.
229 ;;;; Very slow now: on DB::DB 0.91, 486/66:
231 ;;;Function Name Call Count Elapsed Time Average Time
232 ;;;======================================== ========== ============ ============
233 ;;;cperl-block-p 469 3.7799999999 0.0080597014
234 ;;;cperl-get-state 505 163.39000000 0.3235445544
235 ;;;cperl-comment-indent 12 0.0299999999 0.0024999999
236 ;;;cperl-backward-to-noncomment 939 4.4599999999 0.0047497337
237 ;;;cperl-calculate-indent 505 172.22000000 0.3410297029
238 ;;;cperl-indent-line 505 172.88000000 0.3423366336
239 ;;;cperl-use-region-p 40 0.0299999999 0.0007499999
240 ;;;cperl-indent-exp 1 177.97000000 177.97000000
241 ;;;cperl-to-comment-or-eol 1453 3.9800000000 0.0027391603
242 ;;;cperl-backward-to-start-of-continued-exp 9 0.0300000000 0.0033333333
243 ;;;cperl-indent-region 1 177.94000000 177.94000000
246 ;;; Takes into account white space after opening parentheses during indent.
247 ;;; May highlight pods and here-documents: see `cperl-pod-here-scan',
248 ;;; `cperl-pod-here-fontify', `cperl-pod-face'. Does not use this info
249 ;;; for indentation so far.
250 ;;; Fontification updated to 19.30 style.
251 ;;; The change 19.29->30 did not add all the required functionality,
252 ;;; but broke "font-lock-extra.el". Get "choose-color.el" from
253 ;;; http://ilyaz.org/software/emacs
257 ;;; recognized as a start of a block.
258 ;;; Two different font-lock-levels provided.
259 ;;; `cperl-pod-head-face' introduced. Used for highlighting.
260 ;;; `imenu' marks pods, +Packages moved to the head.
263 ;;; Scan for pods highlights here-docs too.
264 ;;; Note that the tag of here-doc may be rehighlighted later by lazy-lock.
265 ;;; Only one here-doc-tag per line is supported, and one in comment
266 ;;; or a string may break fontification.
267 ;;; POD headers were supposed to fill one line only.
270 ;;; `font-lock-keywords' were set in 19.30 style _always_. Current scheme
271 ;;; may break under XEmacs.
272 ;;; `cperl-calculate-indent' dis suppose that `parse-start' was defined.
273 ;;; `fontified' tag is added to fontified text as well as `lazy-lock' (for
274 ;;; compatibility with older lazy-lock.el) (older one overfontifies
275 ;;; something nevertheless :-().
276 ;;; Will not indent something inside pod and here-documents.
277 ;;; Fontifies the package name after import/no/bootstrap.
278 ;;; Added new entry to menu with meta-info about the mode.
281 ;;; Prefontification works much better with 19.29. Should be checked
282 ;;; with 19.30 as well.
283 ;;; Some misprints in docs corrected.
284 ;;; Now $a{-text} and -text => "blah" are fontified as strings too.
285 ;;; Now the pod search is much stricter, so it can help you to find
286 ;;; pod sections which are broken because of whitespace before =blah
287 ;;; - just observe the fontification.
290 ;;; Anonymous subs are indented with respect to the level of
291 ;;; indentation of `sub' now.
292 ;;; {} is recognized as hash after `bless' and `return'.
293 ;;; Anonymous subs are split by `cperl-linefeed' as well.
294 ;;; Electric parens embrace a region if present.
295 ;;; To make `cperl-auto-newline' useful,
296 ;;; `cperl-auto-newline-after-colon' is introduced.
297 ;;; `cperl-electric-parens' is now t or nul. The old meaning is moved to
298 ;;; `cperl-electric-parens-string'.
299 ;;; `cperl-toggle-auto-newline' introduced, put on C-c C-a.
300 ;;; `cperl-toggle-abbrev' introduced, put on C-c C-k.
301 ;;; `cperl-toggle-electric' introduced, put on C-c C-e.
302 ;;; Beginning-of-defun-regexp was not anchored.
305 ;;; Auto-newline grants `cperl-extra-newline-before-brace' if "{" is typed
307 ;;; {} is recognized as expression after `tr' and friends.
310 ;;; Entry Hierarchy added to imenu. Very primitive so far.
311 ;;; One needs newer `imenu-go'.el. A patch to `imenu' is needed as well.
312 ;;; Writes its own TAGS files.
313 ;;; Class viewer based on TAGS files. Does not trace @ISA so far.
314 ;;; 19.31: Problems with scan for PODs corrected.
315 ;;; First POD header correctly fontified.
316 ;;; I needed (setq imenu-use-keymap-menu t) to get good imenu in 19.31.
317 ;;; Apparently it makes a lot of hierarchy code obsolete...
320 ;;; Tags filler now scans *.xs as well.
321 ;;; The info from *.xs scan is used by the hierarchy viewer.
322 ;;; Hierarchy viewer documented.
323 ;;; Bug in 19.31 imenu documented.
326 ;;; New location for info-files mentioned,
327 ;;; Electric-; should work better.
328 ;;; Minor bugs with POD marking.
330 ;;;; After 1.25 (probably not...)
331 ;;; `cperl-info-page' introduced.
332 ;;; To make `uncomment-region' working, `comment-region' would
333 ;;; not insert extra space.
334 ;;; Here documents delimiters better recognized
335 ;;; (empty one, and non-alphanums in quotes handled). May be wrong with 1<<14?
336 ;;; `cperl-db' added, used in menu.
337 ;;; imenu scan removes text-properties, for better debugging
338 ;;; - but the bug is in 19.31 imenu.
339 ;;; formats highlighted by font-lock and prescan, embedded comments
341 ;;; POD/friends scan merged in one pass.
342 ;;; Syntax class is not used for analyzing the code, only char-syntax
343 ;;; may be checked against _ or'ed with w.
344 ;;; Syntax class of `:' changed to be _.
345 ;;; `cperl-find-bad-style' added.
348 ;;; When search for here-documents, we ignore commented << in simplest cases.
349 ;;; `cperl-get-help' added, available on C-h v and from menu.
350 ;;; Auto-help added. Default with `cperl-hairy', switchable on/off
351 ;;; with startup variable `cperl-lazy-help-time' and from
352 ;;; menu. Requires `run-with-idle-timer'.
353 ;;; Highlighting of @abc{@efg} was wrong - interchanged two regexps.
356 ;;; Indentation: At toplevel after a label - fixed.
357 ;;; 1.27 was put to archives in binary mode ===> DOSish :-(
360 ;;; Thanks to Martin Buchholz <mrb@Eng.Sun.COM>: misprints in
361 ;;; comments and docstrings corrected, XEmacs support cleaned up.
362 ;;; The closing parenths would enclose the region into matching
363 ;;; parens under the same conditions as the opening ones.
364 ;;; Minor updates to `cperl-short-docs'.
365 ;;; Will not consider <<= as start of here-doc.
368 ;;; Added an extra advice to look into Micro-docs. ;-).
369 ;;; Enclosing of region when you press a closing parenth is regulated by
370 ;;; `cperl-electric-parens-string'.
371 ;;; Minor updates to `cperl-short-docs'.
372 ;;; `initialize-new-tags-table' called only if present (Does this help
373 ;;; with generation of tags under XEmacs?).
374 ;;; When creating/updating tag files, new info is written at the old place,
375 ;;; or at the end (is this a wanted behaviour? I need this in perl build directory).
378 ;;; All the keywords from keywords.pl included (maybe with dummy explanation).
379 ;;; No auto-help inside strings, comment, here-docs, formats, and pods.
380 ;;; Shrinkwrapping of info, regulated by `cperl-max-help-size',
381 ;;; `cperl-shrink-wrap-info-frame'.
382 ;;; Info on variables as well.
383 ;;; Recognision of HERE-DOCS improved yet more.
384 ;;; Autonewline works on `}' without warnings.
385 ;;; Autohelp works again on $_[0].
388 ;;; perl-descr.el found its author - hi, Johan!
389 ;;; Some support for correct indent after here-docs and friends (may
390 ;;; be superseeded by eminent change to Emacs internals).
391 ;;; Should work with older Emaxen as well ( `-style stuff removed).
395 ;;; Started to add support for `syntax-table' property (should work
396 ;;; with patched Emaxen), controlled by
397 ;;; `cperl-use-syntax-table-text-property'. Currently recognized:
398 ;;; All quote-like operators: m, s, y, tr, qq, qw, qx, q,
399 ;;; // in most frequent context:
401 ;;; ~ { ( = | & + - * ! , ;
403 ;;; while if unless until and or not xor split grep map
404 ;;; Here-documents, formats, PODs,
407 ;;; sub a ($); sub a ($) {}
408 ;;; (provide 'cperl-mode) was missing!
409 ;;; `cperl-after-expr-p' is now much smarter after `}'.
410 ;;; `cperl-praise' added to mini-docs.
411 ;;; Utilities try to support subs-with-prototypes.
414 ;;; `cperl-after-expr-p' is now much smarter after "() {}" and "word {}":
415 ;;; if word is "else, map, grep".
416 ;;; Updated for new values of syntax-table constants.
417 ;;; Uses `help-char' (at last!) (disabled, does not work?!)
418 ;;; A couple of regexps where missing _ in character classes.
419 ;;; -s could be considered as start of regexp, 1../blah/ was not,
420 ;;; as was not /blah/ at start of file.
423 ;;; "\C-hv" was wrongly "\C-hf"
424 ;;; C-hv was not working on `[index()]' because of [] in skip-chars-*.
425 ;;; `__PACKAGE__' supported.
426 ;;; Thanks for Greg Badros: `cperl-lazy-unstall' is more complete,
427 ;;; `cperl-get-help' is made compatible with `query-replace'.
429 ;;;; As of Apr 15, development version of 19.34 supports
430 ;;;; `syntax-table' text properties. Try setting
431 ;;;; `cperl-use-syntax-table-text-property'.
434 ;;; We scan for s{}[] as well (in simplest situations).
435 ;;; We scan for $blah'foo as well.
436 ;;; The default is to use `syntax-table' text property if Emacs is good enough.
437 ;;; `cperl-lineup' is put on C-M-| (=C-M-S-\\).
438 ;;; Start of `cperl-beautify-regexp'.
441 ;;; `cperl-tags-hier-init' did not work in text-mode.
442 ;;; `cperl-noscan-files-regexp' had a misprint.
443 ;;; Generation of Class Hierarchy was broken due to a bug in `x-popup-menu'
447 ;;; my,local highlight vars after {} too.
448 ;;; TAGS could not be created before imenu was loaded.
449 ;;; `cperl-indent-left-aligned-comments' created.
450 ;;; Logic of `cperl-indent-exp' changed a little bit, should be more
451 ;;; robust w.r.t. multiline strings.
452 ;;; Recognition of blah'foo takes into account strings.
453 ;;; Added '.al' to the list of Perl extensions.
454 ;;; Class hierarchy is "mostly" sorted (need to rethink algorthm
455 ;;; of pruning one-root-branch subtrees to get yet better sorting.)
456 ;;; Regeneration of TAGS was busted.
457 ;;; Can use `syntax-table' property when generating TAGS
458 ;;; (governed by `cperl-use-syntax-table-text-property-for-tags').
461 ;;; Can process several =pod/=cut sections one after another.
462 ;;; Knows of `extproc' when under `emx', indents with `__END__' and `__DATA__'.
463 ;;; `cperl-under-as-char' implemented (XEmacs people like broken behaviour).
464 ;;; Beautifier for regexps fixed.
465 ;;; `cperl-beautify-level', `cperl-contract-level' coded
467 ;;;; Emacs's 20.2 problems:
468 ;;; `imenu.el' has bugs, `imenu-add-to-menubar' does not work.
469 ;;; Couple of others problems with 20.2 were reported, my ability to check/fix
470 ;;; them is very reduced now.
473 ;;; 'C-M-|' in XEmacs fixed
476 ;;; &&s was not recognized as start of regular expression;
477 ;;; Will "preprocess" the contents of //e part of s///e too;
478 ;;; What to do with s# blah # foo #e ?
479 ;;; Should handle s;blah;foo;; better.
480 ;;; Now the only known problems with regular expression recognition:
481 ;;;;;;; s<foo>/bar/ - different delimiters (end ignored)
482 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into one chunk)
483 ;;;;;;; s/foo// - empty subst (made into one chunk + '/')
484 ;;;;;;; s/foo/(bar)/ - start-group at start of subst (internal group will not match backwards)
487 ;;; We highlight closing / of s/blah/foo/e;
488 ;;; This handles s# blah # foo #e too;
489 ;;; s//blah/, s///, s/blah// works again, and s#blah## too, the algorithm
490 ;;; is much simpler now;
491 ;;; Next round of changes: s\\\ works, s<blah>/foo/,
492 ;;; comments between the first and the second part allowed
493 ;;; Another problem discovered:
494 ;;;;;;; s[foo] <blah>e - e part delimited by different <> (will not match)
495 ;;; `cperl-find-pods-heres' somehow maybe called when string-face is undefined
496 ;;; - put a stupid workaround for 20.1
499 ;;; Could indent here-docs for comments;
500 ;;; These problems fixed:
501 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into two chunk)
502 ;;;;;;; s[foo] <blah>e - "e" part delimited by "different" <> (will match)
503 ;;; Matching brackets honor prefices, may expand abbreviations;
504 ;;; When expanding abbrevs, will remove last char only after
505 ;;; self-inserted whitespace;
506 ;;; More convenient "Refress hard constructs" in menu;
507 ;;; `cperl-add-tags-recurse', `cperl-add-tags-recurse-noxs'
508 ;;; added (for -batch mode);
509 ;;; Better handling of errors when scanning for Perl constructs;
510 ;;;;;;; Possible "problem" with class hierarchy in Perl distribution
511 ;;;;;;; directory: ./ext duplicates ./lib;
512 ;;; Write relative paths for generated TAGS;
515 ;;; s /// may be separated by "\n\f" too;
516 ;;; `s #blah' recognized as a comment;
517 ;;; Would highlight s/abc//s wrong;
518 ;;; Debugging code in `cperl-electric-keywords' was leaking a message;
521 ;;; RMS changes for 20.3 merged
523 ;;;; 2.0.1.0: RMS mode (has 3 misprints)
526 ;;; RMS whitespace changes for 20.3 merged
532 ;;; Merge `c-style-alist' since `c-mode' is no more. (Somebody who
533 ;;; uses the styles should check that they work OK!)
534 ;;; All the variable warnings go away, some undef functions too.
537 ;;; Added `cperl-perldoc' (thanks to Anthony Foiani <afoiani@uswest.com>)
538 ;;; Added `cperl-pod-to-manpage' (thanks to Nick Roberts <Nick.Roberts@src.bae.co.uk>)
539 ;;; All the function warnings go away.
542 ;;; `Perl doc', `Regexp' submenus created (latter to allow short displays).
543 ;;; `cperl-clobber-lisp-bindings' added.
544 ;;; $a->y() is not y///.
545 ;;; `cperl-after-block-p' was missing a `save-excursion' => wrong results.
546 ;;; `cperl-val' was defined too late.
547 ;;; `cperl-init-faces' was failing.
548 ;;; Init faces when loading `ps-print'.
551 ;;; `cperl-toggle-autohelp' implemented.
552 ;;; `while SPACE LESS' was buggy.
553 ;;; `-text' in `[-text => 1]' was not highlighted.
554 ;;; `cperl-after-block-p' was FALSE after `sub f {}'.
557 ;;; `foreachmy', `formy' expanded too.
558 ;;; Expand `=pod-directive'.
559 ;;; `cperl-linefeed' behaves reasonable in POD-directive lines.
560 ;;; `cperl-electric-keyword' prints a message, governed by
561 ;;; `cperl-message-electric-keyword'.
564 ;;; Typing `}' was not checking for being block or not.
565 ;;; Beautifying levels in RE: Did not know about lookbehind;
566 ;;; finding *which* level was not intuitive;
567 ;;; `cperl-beautify-levels' added.
568 ;;; Allow here-docs contain `=head1' and friends (at least for keywords).
571 ;;; Fix for broken `font-lock-unfontify-region-function'. Should
572 ;;; preserve `syntax-table' properties even with `lazy-lock'.
575 ;;; Some more compile time warnings crept in.
576 ;;; `cperl-indent-region-fix-else' implemented.
577 ;;; `cperl-fix-line-spacing' implemented.
578 ;;; `cperl-invert-if-unless' implemented (C-c C-t and in Menu).
579 ;;; Upgraded hints to mention 20.2's goods/bads.
580 ;;; Started to use `cperl-extra-newline-before-brace-multiline',
581 ;;; `cperl-break-one-line-blocks-when-indent',
582 ;;; `cperl-fix-hanging-brace-when-indent', `cperl-merge-trailing-else'.
585 ;;; Workaround for another `font-lock's `syntax-table' text-property bug.
586 ;;; `zerop' could be applied to nil.
587 ;;; At last, may work with `font-lock' without setting `cperl-font-lock'.
588 ;;; (We expect that starting from 19.33, `font-lock' supports keywords
589 ;;; being a function - what is a correct version?)
590 ;;; Rename `cperl-indent-region-fix-else' to
591 ;;; `cperl-indent-region-fix-constructs'.
592 ;;; `cperl-fix-line-spacing' could be triggered inside strings, would not
593 ;;; know what to do with BLOCKs of map/printf/etc.
594 ;;; `cperl-merge-trailing-else' and `cperl-fix-line-spacing' handle
596 ;;; Indentation after {BLOCK} knows about map/printf/etc.
597 ;;; Finally: treat after-comma lines as continuation lines.
600 ;;; `continue' made electric.
601 ;;; Electric `do' inserts `do/while'.
602 ;;; Some extra compile-time warnings crept in.
603 ;;; `font-lock' of 19.33 could not handle font-lock-keywords being a function
604 ;;; returning a symbol.
607 ;;; Changes to make syntaxification to be autoredone via `font-lock'.
608 ;;; Switched on by `cperl-syntaxify-by-font-lock', off by default so far.
611 ;;; Remove some commented out chunks.
612 ;;; Styles are slightly updated (a lot of work is needed, especially
613 ;;; with new `cperl-fix-line-spacing').
616 ;;; Old value of style is memorized when choosing a new style, may be
617 ;;; restored from the same menu.
618 ;;; Mode-documentation added to micro-docs.
619 ;;; `cperl-praise' updated.
620 ;;; `cperl-toggle-construct-fix' added on C-c C-w and menu.
621 ;;; `auto-fill-mode' added on C-c C-f and menu.
622 ;;; `PerlStyle' style added.
623 ;;; Message for termination of scan corrected.
627 ;;; Did not work with -q
631 ;;; `cperl-speed' hints added.
632 ;;; Minor style fixes.
635 ;;; Make backspace electric after expansion of `else/continue' too.
638 ;;; Starting to merge changes to RMS emacs version.
641 ;;; Merged custom stuff and darn `font-lock-constant-face'.
644 ;;; Bumped the version to 3.1
647 ;;; Fixed customization to honor cperl-hairy.
648 ;;; Created customization groups. Sent to RMS to include into 2.3.
651 ;;; Interaction of `font-lock-hot-pass' and `cperl-syntaxify-by-font-lock'.
652 ;;; (`cperl-after-block-and-statement-beg'):
653 ;;; (`cperl-after-block-p'):
654 ;;; (`cperl-after-expr-p'): It is BLOCK if we reach lim when backup sexp.
655 ;;; (`cperl-indent-region'): Make a marker for END - text added/removed.
656 ;;; (`cperl-style-alist', `cperl-styles-entries')
657 ;;; Include `cperl-merge-trailing-else' where the value is clear.
661 ;;; (`cperl-problems'): Improvements to docs.
664 ;;; (`cperl-mode'): Make lazy syntaxification possible.
665 ;;; (`cperl-find-pods-heres'): Safe a position in buffer where it is safe to
666 ;;; restart syntaxification.
667 ;;; (`cperl-syntaxify-by-font-lock'): Set to t, should be safe now.
670 ;;; (`cperl-syntaxify-by-font-lock'): Better default, customizes to
674 ;;; (`cperl-find-pods-heres'): changed so that -d ?foo? is a RE.
675 ;;; (`cperl-array-face'): changed name from `font-lock-emphasized-face'.
676 ;;; (`cperl-hash-face'): changed name from `font-lock-other-emphasized-face'.
677 ;;; Use `defface' to define these two extra faces.
680 ;;; Can use linear algorithm for indentation if Emacs supports it:
681 ;;; indenting DB::DB (800+ lines) improved from 69 sec to 11 sec
682 ;;; (73 vs 15 with imenu).
683 ;;; (`cperl-emacs-can-parse'): New state.
684 ;;; (`cperl-indent-line'): Corrected to use global state.
685 ;;; (`cperl-calculate-indent'): Likewise.
686 ;;; (`cperl-fix-line-spacing'): Likewise (not used yet).
689 ;;; (`cperl-choose-color'): Converted to a function (to be compilable in text-mode).
692 ;;; (`cperl-dark-background '): Disable without window-system.
695 ;;; Do `defface' only if window-system.
698 ;;; (`cperl-fix-line-spacing'): sped up to bail out early.
699 ;;; (`cperl-indent-region'): Disable hooks during the call (how to call them later?).
701 ;;; Now indents 820-line-long function in 6.5 sec (including syntaxification) the first time
702 ;;; (when buffer has few properties), 7.1 sec the second time.
704 ;;;Function Name Call Count Elapsed Time Average Time
705 ;;;========================================= ========== ============ ============
706 ;;;cperl-indent-exp 1 10.039999999 10.039999999
707 ;;;cperl-indent-region 1 10.0 10.0
708 ;;;cperl-indent-line 821 6.2100000000 0.0075639464
709 ;;;cperl-calculate-indent 821 5.0199999999 0.0061144945
710 ;;;cperl-backward-to-noncomment 2856 2.0500000000 0.0007177871
711 ;;;cperl-fontify-syntaxically 2 1.78 0.8900000000
712 ;;;cperl-find-pods-heres 2 1.78 0.8900000000
713 ;;;cperl-update-syntaxification 1 1.78 1.78
714 ;;;cperl-fix-line-spacing 769 1.4800000000 0.0019245773
715 ;;;cperl-after-block-and-statement-beg 163 1.4100000000 0.0086503067
716 ;;;cperl-block-p 775 1.1800000000 0.0015225806
717 ;;;cperl-to-comment-or-eol 3652 1.1200000000 0.0003066812
718 ;;;cperl-after-block-p 165 1.0500000000 0.0063636363
719 ;;;cperl-commentify 141 0.22 0.0015602836
720 ;;;cperl-get-state 813 0.16 0.0001968019
721 ;;;cperl-backward-to-start-of-continued-exp 26 0.12 0.0046153846
722 ;;;cperl-delay-update-hook 2107 0.0899999999 4.271...e-05
723 ;;;cperl-protect-defun-start 141 0.0700000000 0.0004964539
724 ;;;cperl-after-label 407 0.0599999999 0.0001474201
725 ;;;cperl-forward-re 139 0.0299999999 0.0002158273
726 ;;;cperl-comment-indent 26 0.0299999999 0.0011538461
727 ;;;cperl-use-region-p 8 0.0 0.0
728 ;;;cperl-lazy-hook 15 0.0 0.0
729 ;;;cperl-after-expr-p 8 0.0 0.0
730 ;;;cperl-font-lock-unfontify-region-function 1 0.0 0.0
732 ;;;Function Name Call Count Elapsed Time Average Time
733 ;;;========================================= ========== ============ ============
734 ;;;cperl-fix-line-spacing 769 1.4500000000 0.0018855656
735 ;;;cperl-indent-line 13 0.3100000000 0.0238461538
736 ;;;cperl-after-block-and-statement-beg 69 0.2700000000 0.0039130434
737 ;;;cperl-after-block-p 69 0.2099999999 0.0030434782
738 ;;;cperl-calculate-indent 13 0.1000000000 0.0076923076
739 ;;;cperl-backward-to-noncomment 177 0.0700000000 0.0003954802
740 ;;;cperl-get-state 13 0.0 0.0
741 ;;;cperl-to-comment-or-eol 179 0.0 0.0
742 ;;;cperl-get-help-defer 1 0.0 0.0
743 ;;;cperl-lazy-hook 11 0.0 0.0
744 ;;;cperl-after-expr-p 2 0.0 0.0
745 ;;;cperl-block-p 13 0.0 0.0
746 ;;;cperl-after-label 5 0.0 0.0
749 ;;; (`cperl-find-pods-heres'): do not warn on `=cut' if doing a chunk only.
752 ;;; (`cperl-mode'): load pseudo-faces on `cperl-find-pods-heres' (for 19.30).
753 ;;; (`x-color-defined-p'): was not compiling on XEmacs
754 ;;; (`cperl-find-pods-heres'): 1 << 6 was OK, but 1<<6 was considered as HERE
755 ;;; <file/glob> made into a string.
758 ;;; (`cperl-find-pods-heres'): Postpone addition of faces after syntactic step
759 ;;; Recognition of <FH> was wrong.
760 ;;; (`cperl-clobber-lisp-bindings'): if set, C-c variants are the old ones
761 ;;; (`cperl-unwind-to-safe'): New function.
762 ;;; (`cperl-fontify-syntaxically'): Use `cperl-unwind-to-safe' to start at reasonable position.
765 ;;; (`cperl-forward-re'): Highlight the trailing / in s/foo// as string.
766 ;;; Highlight the starting // in s//foo/ as function-name.
769 ;;; (`cperl-find-pods-heres'): Highlight `gem' in s///gem as a keyword.
772 ;;; (`cperl-find-pods-heres'): `qr' added
773 ;;; (`cperl-electric-keyword'): Likewise
774 ;;; (`cperl-electric-else'): Likewise
775 ;;; (`cperl-to-comment-or-eol'): Likewise
776 ;;; (`cperl-make-regexp-x'): Likewise
777 ;;; (`cperl-init-faces'): Likewise, and `lock' (as overridable?).
778 ;;; (`cperl-find-pods-heres'): Knows that split// is null-RE.
779 ;;; Highlights separators in 3-parts expressions
783 ;;; (`cperl-find-pods-heres'): <> was considered as a glob
784 ;;; (`cperl-syntaxify-unwind'): New configuration variable
785 ;;; (`cperl-fontify-m-as-s'): New configuration variable
788 ;;; (`cperl-find-pods-heres'): of the last line being `=head1' fixed.
790 ;;; Handling of a long construct is still buggy if only the part of
791 ;;; construct touches the updated region (we unwind to the start of
792 ;;; long construct, but the end may have residual properties).
794 ;;; (`cperl-unwind-to-safe'): would not go to beginning of buffer.
795 ;;; (`cperl-electric-pod'): check for after-expr was performed
796 ;;; inside of POD too.
799 ;;; (`cperl-backward-to-noncomment'): better treatment of PODs and HEREs.
801 ;;; Indent-line works good, but indent-region does not - at toplevel...
802 ;;; (`cperl-unwind-to-safe'): Signature changed.
803 ;;; (`x-color-defined-p'): was defmacro'ed with a tick. Remove another def.
804 ;;; (`cperl-clobber-mode-lists'): New configuration variable.
805 ;;; (`cperl-array-face'): One of definitions was garbled.
808 ;;; (`cperl-not-bad-style-regexp'): Updated.
809 ;;; (`cperl-make-regexp-x'): Misprint in a message.
810 ;;; (`cperl-find-pods-heres'): $a-1 ? foo : bar; was a regexp.
811 ;;; `<< (' was considered a start of POD.
812 ;;; Init: `cperl-is-face' was busted.
813 ;;; (`cperl-make-face'): New macros.
814 ;;; (`cperl-force-face'): New macros.
815 ;;; (`cperl-init-faces'): Corrected to use new macros;
816 ;;; `if' for copying `reference-face' to
817 ;;; `constant-face' was backward.
818 ;;; (`font-lock-other-type-face'): Done via `defface' too.
821 ;;; (`cperl-init-faces-weak'): use `cperl-force-face'.
822 ;;; (`cperl-after-block-p'): After END/BEGIN we are a block.
823 ;;; (`cperl-mode'): `font-lock-unfontify-region-function'
824 ;;; was set to a wrong function.
825 ;;; (`cperl-comment-indent'): Commenting __END__ was not working.
826 ;;; (`cperl-indent-for-comment'): Likewise.
827 ;;; (Indenting is still misbehaving at toplevel.)
830 ;;; (`cperl-unwind-to-safe'): Signature changed, unwinds end too.
831 ;;; (`cperl-find-pods-heres'): mark qq[]-etc sections as syntax-type=string
832 ;;; (`cperl-fontify-syntaxically'): Unwinds start and end to go out of
833 ;;; long strings (not very successful).
835 ;;; >>>> CPerl should be usable in write mode too now <<<<
837 ;;; (`cperl-syntaxify-by-font-lock'): Better default - off in text-mode.
838 ;;; (`cperl-tips'): Updated docs.
839 ;;; (`cperl-problems'): Updated docs.
842 ;;; (`cperl-calculate-indent'): Did not consider `,' as continuation mark for statements.
843 ;;; (`cperl-write-tags'): Correct for XEmacs's `visit-tags-table-buffer'.
846 ;;; (`cperl-calculate-indent'): Avoid parse-data optimization at toplevel.
847 ;;; Should indent correctly at toplevel too.
848 ;;; (`cperl-tags-hier-init'): Gross hack to pretend we work (are we?).
849 ;;; (`cperl-find-pods-heres'): Was not processing sub protos after a comment ine.
850 ;;; Was treating $a++ <= 5 as a glob.
853 ;;; (toplevel): require custom unprotected => failure on 19.28.
854 ;;; (`cperl-xemacs-p') defined when compile too
855 ;;; (`cperl-tags-hier-init'): Another try to work around XEmacs problems
856 ;;; Better progress messages.
857 ;;; (`cperl-find-tags'): Was writing line/pos in a wrong order,
858 ;;; pos off by 1 and not at beg-of-line.
859 ;;; (`cperl-etags-snarf-tag'): New macro
860 ;;; (`cperl-etags-goto-tag-location'): New macro
861 ;;; (`cperl-write-tags'): When removing old TAGS info was not
862 ;;; relativizing filename
865 ;;; (`cperl-version'): New variable. New menu entry
868 ;;; (`cperl-tips'): Updated.
869 ;;; (`cperl-non-problems'): Updated.
870 ;;; random: References to future 20.3 removed.
873 ;;; (`perl-font-lock-keywords'): Would not highlight `sub foo($$);'.
874 ;;; Docstrings: Menu was described as `CPerl' instead of `Perl'
877 ;;; (`cperl-toggle-construct-fix'): Was toggling to t instead of 1.
878 ;;; (`cperl-ps-print-init'): Associate `cperl-array-face', `cperl-hash-face'
879 ;;; remove `font-lock-emphasized-face'.
880 ;;; remove `font-lock-other-emphasized-face'.
881 ;;; remove `font-lock-reference-face'.
882 ;;; remove `font-lock-keyword-face'.
883 ;;; Use `eval-after-load'.
884 ;;; (`cperl-init-faces'): remove init `font-lock-other-emphasized-face'.
885 ;;; remove init `font-lock-emphasized-face'.
886 ;;; remove init `font-lock-keyword-face'.
887 ;;; (`cperl-tips-faces'): New variable and an entry into Mini-docs.
888 ;;; (`cperl-indent-region'): Do not indent whitespace lines
889 ;;; (`cperl-indent-exp'): Was not processing else-blocks.
890 ;;; (`cperl-calculate-indent'): Remove another parse-data optimization
891 ;;; at toplevel: would indent correctly.
892 ;;; (`cperl-get-state'): NOP line removed.
895 ;;; (`cperl-ps-print-init'): Remove not-CPerl-related faces.
896 ;;; (`cperl-ps-print'): New function and menu entry.
897 ;;; (`cperl-ps-print-face-properties'): New configuration variable.
898 ;;; (`cperl-invalid-face'): New configuration variable.
899 ;;; (`cperl-nonoverridable-face'): New face. Renamed from
900 ;;; `font-lock-other-type-face'.
901 ;;; (`perl-font-lock-keywords'): Highlight trailing whitespace
902 ;;; (`cperl-contract-levels'): Documentation corrected.
903 ;;; (`cperl-contract-level'): Likewise.
906 ;;; (`cperl-ps-print'): `ps-print-face-extension-alist' was not in old Emaxen,
907 ;;; same with `ps-extend-face-list'
908 ;;; (`cperl-ps-extend-face-list'): New macro.
911 ;;; (`cperl-init-faces'): Interpolate `cperl-invalid-face'.
912 ;;; (`cperl-forward-re'): Emit a meaningful error instead of a cryptic
913 ;;; one for uncomplete REx near end-of-buffer.
914 ;;; (`cperl-find-pods-heres'): Tolerate unfinished REx at end-of-buffer.
917 ;;; (`cperl-find-pods-heres'): `unwind-protect' was left commented.
920 ;;; (`cperl-invalid-face'): Change to ''underline.
923 ;;; (`cperl-find-pods-heres'): / and ? after : start a REx.
924 ;;; (`cperl-after-expr-p'): Skip labels when checking
925 ;;; (`cperl-calculate-indent'): Correct for labels when calculating
926 ;;; indentation of continuations.
927 ;;; Docstring updated.
930 ;;; Minor (mostly spelling) corrections from 20.3.3 merged.
933 ;;; (`cperl-tips'): Another workaround added. Sent to RMS for 20.4.
936 ;;; (`cperl-praise'): Mention linear-time indent.
937 ;;; (`cperl-find-pods-heres'): @if ? a : b was considered a REx.
940 ;;; (`cperl-after-expr-p'): Make true after __END__.
941 ;;; (`cperl-electric-pod'): "SYNOPSIS" was misspelled.
944 ;;; (`cperl-beautify-regexp-piece'): Was not allowing for *? after a class.
945 ;;; Allow for POSIX char-classes.
946 ;;; Remove trailing whitespace when
947 ;;; adding new linebreak.
948 ;;; Add a level counter to stop shallow.
949 ;;; Indents unprocessed groups rigidly.
950 ;;; (`cperl-beautify-regexp'): Add an optional count argument to go that
951 ;;; many levels deep.
952 ;;; (`cperl-beautify-level'): Likewise
953 ;;; Menu: Add new entries to Regexp menu to do one level
954 ;;; (`cperl-contract-level'): Was entering an infinite loop
955 ;;; (`cperl-find-pods-heres'): Typo (double quoting).
956 ;;; Was detecting < $file > as FH instead of glob.
957 ;;; Support for comments in RExen (except
958 ;;; for m#\#comment#x), governed by
959 ;;; `cperl-regexp-scan'.
960 ;;; (`cperl-regexp-scan'): New customization variable.
961 ;;; (`cperl-forward-re'): Improve logic of resetting syntax table.
963 ;;;; After 4.23 and: After 4.24:
964 ;;; (`cperl-contract-levels'): Restore position.
965 ;;; (`cperl-beautify-level'): Likewise.
966 ;;; (`cperl-beautify-regexp'): Likewise.
967 ;;; (`cperl-commentify'): Rudimental support for length=1 runs
968 ;;; (`cperl-find-pods-heres'): Process 1-char long REx comments too /a#/x
969 ;;; Processes REx-comments in #-delimited RExen.
970 ;;; MAJOR BUG CORRECTED: after a misparse
971 ;;; a body of a subroutine could be corrupted!!!
972 ;;; One might need to reeval the function body
973 ;;; to fix things. (A similar bug was
974 ;;; present in `cperl-indent-region' eons ago.)
976 ;; (defun foo () (let ((a '(t))) (insert (format "%s" a)) (setcar a 'BUG) t))
979 ;;; C-x C-e the above three lines (at end-of-line). First evaluation
980 ;;; of `foo' inserts (t), second one inserts (BUG) ?!
982 ;;; In CPerl it was triggered by inserting then deleting `/' at start of
983 ;;; / a (?# asdf {[(}asdf )ef,/;
986 ;;; (`cperl-commentify'): Was recognizing length=2 "strings" as length=1.
987 ;;; (`imenu-example--create-perl-index'):
988 ;;; Was not enforcing syntaxification-to-the-end.
989 ;;; (`cperl-invert-if-unless'): Allow `for', `foreach'.
990 ;;; (`cperl-find-pods-heres'): Quote `cperl-nonoverridable-face'.
991 ;;; Mark qw(), m()x as indentable.
992 ;;; (`cperl-init-faces'): Highlight `sysopen' too.
993 ;;; Highlight $var in `for my $var' too.
994 ;;; (`cperl-invert-if-unless'): Was leaving whitespace at end.
995 ;;; (`cperl-linefeed'): Was splitting $var{$foo} if point after `{'.
996 ;;; (`cperl-calculate-indent'): Remove old commented out code.
997 ;;; Support (primitive) indentation of qw(), m()x.
1001 ;;; (`cperl-problems'): Mention `fill-paragraph' on comment. \"" and
1002 ;;; q [] with intervening newlines.
1003 ;;; (`cperl-autoindent-on-semi'): New customization variable.
1004 ;;; (`cperl-electric-semi'): Use `cperl-autoindent-on-semi'.
1005 ;;; (`cperl-tips'): Mention how to make CPerl the default mode.
1006 ;;; (`cperl-mode'): Support `outline-minor-mode'
1007 ;;; (Thanks to Mark A. Hershberger).
1008 ;;; (`cperl-outline-level'): New function.
1009 ;;; (`cperl-highlight-variables-indiscriminately'): New customization var.
1010 ;;; (`cperl-init-faces'): Use `cperl-highlight-variables-indiscriminately'.
1011 ;;; (Thanks to Sean Kamath <kamath@pogo.wv.tek.com>).
1012 ;;; (`cperl-after-block-p'): Support CHECK and INIT.
1013 ;;; (`cperl-init-faces'): Likewise and "our".
1014 ;;; (Thanks to Doug MacEachern <dougm@covalent.net>).
1015 ;;; (`cperl-short-docs'): Likewise and "our".
1019 ;;; (`cperl-find-pods-heres'): Recognize \"" as a string.
1020 ;;; Mark whitespace and comments between q and []
1021 ;;; as `syntax-type' => `prestring'.
1022 ;;; Allow whitespace between << and "FOO".
1023 ;;; (`cperl-problems'): Remove \"" and q [] with intervening newlines.
1024 ;;; Mention multiple <<EOF as unsupported.
1025 ;;; (`cperl-highlight-variables-indiscriminately'): Doc misprint fixed.
1026 ;;; (`cperl-indent-parens-as-block'): New configuration variable.
1027 ;;; (`cperl-calculate-indent'): Merge cases of indenting non-BLOCK groups.
1028 ;;; Use `cperl-indent-parens-as-block'.
1029 ;;; (`cperl-find-pods-heres'): Test for =cut without empty line instead of
1030 ;;; complaining about no =cut.
1031 ;;; (`cperl-electric-pod'): Change the REx for POD from "\n\n=" to "^\n=".
1032 ;;; (`cperl-find-pods-heres'): Likewise.
1033 ;;; (`cperl-electric-pod'): Change `forward-sexp' to `forward-word':
1034 ;;; POD could've been marked as comment already.
1035 ;;; (`cperl-unwind-to-safe'): Unwind before start of POD too.
1038 ;;; (`cperl-forward-re'): Throw an error at proper moment REx unfinished.
1041 ;;; (`x-color-defined-p'): Make an extra case to peacify the warning.
1042 ;;; Toplevel: `defvar' to peacify the warnings.
1043 ;;; (`cperl-find-pods-heres'): Could access `font-lock-comment-face' in -nw.
1044 ;;;; No -nw-compile time warnings now.
1045 ;;; (`cperl-find-tags'): TAGS file had too short substring-to-search.
1046 ;;; Be less verbose in non-interactive mode
1047 ;;; (`imenu-example--create-perl-index'): Set index-marker after name
1048 ;;; (`cperl-outline-regexp'): New variable.
1049 ;;; (`cperl-outline-level'): Made compatible with `cperl-outline-regexp'.
1050 ;;; (`cperl-mode'): Made use `cperl-outline-regexp'.
1053 ;;; (`cperl-find-pods-heres'): =cut the last thing, no blank line, was error.
1054 ;;; (`cperl-outline-level'): Make start-of-file same level as `package'.
1057 ;;; (`cperl-electric-pod'): `head1' and `over' electric only if empty.
1058 ;;; (`cperl-unreadable-ok'): New variable.
1059 ;;; (`cperl-find-tags'): Use `cperl-unreadable-ok', do not fail
1060 ;;; on an unreadable file
1061 ;;; (`cperl-write-tags'): Use `cperl-unreadable-ok', do not fail
1062 ;;; on an unreadable directory
1065 ;;; Syncronized with v1.60 from Emacs 21.3.
1066 ;;; Mostly docstring and formatting changes, and:
1068 ;;; (`cperl-noscan-files-regexp'): Do not scan CVS subdirs
1069 ;;; (`cperl-problems'): Note that newer XEmacsen may syntaxify too
1070 ;;; (`imenu-example--create-perl-index'):
1071 ;;; Renamed to `cperl-imenu--create-perl-index'
1072 ;;; (`cperl-mode'): Replace `make-variable-buffer-local' by `make-local-variable'
1073 ;;; (`cperl-setup-tmp-buf'): Likewise
1074 ;;; (`cperl-fix-line-spacing'): Fix a misprint of "t" for "\t"
1075 ;;; (`cperl-next-bad-style'): Fix misprints in character literals
1078 ;;; (`cperl-font-lock-keywords'): +etc: Aliased to perl-font-lock-keywords.
1081 ;;; Further updates of whitespace and spelling w.r.t. RMS version.
1082 ;;; (`cperl-font-lock-keywords'): +etc: Avoid warnings when aliasing.
1083 ;;; (`cperl-mode'): Use `normal-auto-fill-function' if present.
1084 ;;; (`cperl-use-major-mode'): New variable
1085 ;;; (`cperl-can-font-lock'): New variable; replaces `window-system'
1086 ;;; (`cperl-tags-hier-init'): use `display-popup-menus-p' (if present)
1087 ;;; to choose `x-popup-menu' vs `tmm-prompt'
1089 ;;;; 4.35 has the following differences from version 1.40+ of RMS Emacs:
1091 ;;; New variables `cperl-use-major-mode', `cperl-can-font-lock';
1092 ;;; `cperl-use-major-mode' is (effectively) 'cperl-mode in RMS.
1093 ;;; `cperl-under-as-char' is nil in RMS.
1094 ;;; Minor differences in docstrings, and `cperl-non-problems'.
1095 ;;; Backward compatibility addressed: (`); (function (lambda ...)); font-lock;
1096 ;;; (:italic t bold t) vs (:slant italic :weight bold) in faces;
1097 ;;; `normal-auto-fill-function'.
1098 ;;; RMS version has wrong logic in `cperl-calculate-indent': $a = { } is
1099 ;;; wrongly indented if the closing brace is on a separate line.
1100 ;;; Different choice of ordering if's for is-x-REx and (eq (char-after b) ?\#)
1101 ;;; in `cperl-find-pods-heres'. [Cosmetic]
1104 ;;; (`cperl-find-pods-heres'): If no end of HERE-doc found, mark to the end
1105 ;;; of buffer. This enables recognition of end
1106 ;;; of HERE-doc "as one types".
1107 ;;; Require "\n" after trailing tag of HERE-doc.
1108 ;;; \( made non-quoting outside of string/comment
1109 ;;; (gdj-contributed).
1110 ;;; Likewise for \$.
1111 ;;; Remove `here-doc-group' text property at start
1112 ;;; (makes this property reliable).
1113 ;;; Text property `first-format-line' ==> t.
1114 ;;; Do not recognize $opt_s and $opt::s as s///.
1115 ;;; (`cperl-perldoc'): Use case-sensitive search (contributed).
1116 ;;; (`cperl-fix-line-spacing'): Allow "_" in $vars of foreach etc. when
1117 ;;; underscore isn't a word char (gdj-contributed).
1118 ;;; (`defun-prompt-regexp'): Allow prototypes.
1119 ;;; (`cperl-vc-header-alist'): Extract numeric version from the Id.
1120 ;;; Toplevel: Put toggle-autohelp into the mode menu.
1121 ;;; Better docs for toggle/set/unset autohelp.
1122 ;;; (`cperl-electric-backspace-untabify'): New customization variable
1123 ;;; (`cperl-after-expr-p'): Works after here-docs, formats, and PODs too
1124 ;;; (affects many electric constructs).
1125 ;;; (`cperl-calculate-indent'): Takes into account `first-format-line' ==>
1126 ;;; works after format.
1127 ;;; (`cperl-short-docs'): Make it work with ... too.
1128 ;;; "array context" ==> "list context"
1129 ;;; (`cperl-electric-keyword'): make $if (etc: "$@%&*") non-electric
1130 ;;; '(' after keyword would insert a doubled paren
1131 ;;; (`cperl-electric-paren'): documented affected by `cperl-electric-parens'
1132 ;;; (`cperl-electric-rparen'): Likewise
1133 ;;; (`cperl-build-manpage'): New function by Nick Roberts
1134 ;;; (`cperl-perldoc'): Make it work in XEmacs too
1137 ;;; (`cperl-find-pods-heres'): Recognize s => 1 and {s} (as a key or varname),
1138 ;;; { s:: } and { s::bar::baz } as varnames.
1139 ;;; (`cperl-after-expr-p'): Updates syntaxification before checks
1140 ;;; (`cperl-calculate-indent'): Likewise
1141 ;;; Fix wrong indent of blocks starting with POD
1142 ;;; (`cperl-after-block-p'): Optional argument for checking for a pre-block
1143 ;;; Recognize `continue' blocks too.
1144 ;;; (`cperl-electric-brace'): use `cperl-after-block-p' for detection;
1145 ;;; Now works for else/continue/sub blocks
1146 ;;; (`cperl-short-docs'): Minor edits; make messages fit 80-column screen
1149 ;;; `cperl-add-tags-recurse-noxs-fullpath': new function (for -batch mode)
1152 ;;;;;; Major edit. Summary of most visible changes:
1154 ;;;;;; a) Multiple <<HERE per line allowed.
1155 ;;;;;; b) Handles multiline subroutine declaration headers (with comments).
1156 ;;;;;; (The exception is `cperl-etags' - but it is not used in the rest
1157 ;;;;;; of the mode.)
1158 ;;;;;; c) Fontifies multiline my/our declarations (even with comments,
1159 ;;;;;; and with legacy `font-lock').
1160 ;;;;;; d) Major speedup of syntaxification, both immediate and postponed
1161 ;;;;;; (3.5x to 15x [for different CPUs and versions of Emacs] on the
1162 ;;;;;; huge real-life document I tested).
1163 ;;;;;; e) New bindings, edits to imenu.
1164 ;;;;;; f) "_" is made into word-char during fontification/syntaxification;
1165 ;;;;;; some attempts to recognize non-word "_" during other operations too.
1166 ;;;;;; g) Detect bug in Emacs with `looking-at' inside `narrow' and bulk out.
1167 ;;;;;; h) autoload some more perldoc-related stuff
1168 ;;;;;; i) Some new convenience features: ISpell POD/HEREDOCs, narrow-to-HEREDOC
1169 ;;;;;; j) Attempt to incorporate XEmacs edits which reached me
1171 ;;;; Fine-grained changelog:
1172 ;;; `cperl-hook-after-change': New configuration variable
1173 ;;; `cperl-vc-sccs-header': Likewise
1174 ;;; `cperl-vc-sccs-header': Likewise
1175 ;;; `cperl-vc-header-alist': Default via two preceding variables
1176 ;;; `cperl-invalid-face': Remove double quoting under XEmacs
1177 ;;; (still needed under 21.2)
1178 ;;; `cperl-tips': Update URLs for resources
1179 ;;; `cperl-problems': Likewise
1180 ;;; `cperl-praise': Mention new features
1181 ;;; New C-c key bindings: for `cperl-find-bad-style',
1182 ;;; `cperl-pod-spell', `cperl-here-doc-spell', `cperl-narrow-to-here-doc',
1183 ;;; `cperl-perdoc', `cperl-perldoc-at-point'
1184 ;;; CPerl Mode menu changes: "Fix style by spaces", "Imenu on Perl Info"
1185 ;;; moved, new submenu of Tools with Ispell entries and narrowing.
1186 ;;; `cperl-after-sub-regexp': New defsubst
1187 ;;; `cperl-imenu--function-name-regexp-perl': Use `cperl-after-sub-regexp',
1188 ;;; Allows heads up to head4
1189 ;;; Allow "package;"
1190 ;;; `defun-prompt-regexp': Use `cperl-after-sub-regexp',
1191 ;;; `paren-backwards-message': ??? Something for XEmacs???
1192 ;;; `cperl-mode': Never auto-switch abbrev-mode off
1193 ;;; Try to allow '_' be non-word char
1194 ;;; Do not use `font-lock-unfontify-region-function' on XEmacs
1195 ;;; Reset syntax cache on mode start
1196 ;;; Support multiline facification (even
1197 ;;; on legacy `font-lock')
1198 ;;; `cperl-facemenu-add-face-function': ??? Some contributed code ???
1199 ;;; `cperl-after-change-function': Since `font-lock' and `lazy-lock'
1200 ;;; refuse to inform us whether the fontification is due to lazy
1201 ;;; calling or due to edit to a buffer, install our own hook
1202 ;;; (controlled by `cperl-hook-after-change')
1203 ;;; `cperl-electric-pod': =cut may have been recognized as start
1204 ;;; `cperl-block-p': Moved, updated for attributes
1205 ;;; `cperl-calculate-indent': Try to allow '_' be non-word char
1206 ;;; Support subs with attributes
1207 ;;; `cperl-where-am-i': Queit (?) a warning
1208 ;;; `cperl-cached-syntax-table' New function
1209 ;;; `cperl-forward-re': Use `cperl-cached-syntax-table'
1210 ;;; `cperl-unwind-to-safe': Recognize `syntax-type' property
1211 ;;; changing in a middle of line
1212 ;;; `cperl-find-sub-attrs': New function
1213 ;;; `cperl-find-pods-heres': Allow many <<EOP per line
1214 ;;; Allow subs with attributes
1215 ;;; Major speedups (3.5x..15x on a real-life
1216 ;;; test file nph-proxy.pl)
1217 ;;; Recognize "extproc " (OS/2)
1218 ;;; case-folded and only at start
1219 ;;; /x on s///x with empty replacement was
1222 ;;; `cperl-after-block-p': Remarks on diff with `cperl-block-p'
1223 ;;; Allow subs with attributes, labels
1224 ;;; Do not confuse "else::foo" with "else"
1225 ;;; Minor optimizations...
1226 ;;; `cperl-after-expr-p': Try to allow '_' be non-word char
1227 ;;; `cperl-fill-paragraph': Try to detect a major bug in Emacs
1228 ;;; with `looking-at' inside `narrow' and bulk out if found
1229 ;;; `cperl-imenu--create-perl-index': Updates for new
1230 ;;; `cperl-imenu--function-name-regexp-perl'
1231 ;;; `cperl-outline-level': Likewise
1232 ;;; `cperl-init-faces': Allow multiline subroutine headers
1233 ;;; and my/our declarations, and ones with comments
1234 ;;; Allow subroutine attributes
1235 ;;; `cperl-imenu-on-info': Better docstring.
1236 ;;; `cperl-etags' Rudimentary support for attributes
1237 ;;; Support for packages and "package;"
1238 ;;; `cperl-add-tags-recurse-noxs': Better (?) docstring
1239 ;;; `cperl-add-tags-recurse-noxs-fullpath': Likewise
1240 ;;; `cperl-tags-hier-init': Misprint for `fboundp' fixed
1241 ;;; `cperl-not-bad-style-regexp': Try to allow '_' be non-word char
1242 ;;; `cperl-perldoc': Add autoload
1243 ;;; `cperl-perldoc-at-point': Likewise
1244 ;;; `cperl-here-doc-spell': New function
1245 ;;; `cperl-pod-spell': Likewise
1246 ;;; `cperl-map-pods-heres': Likewise
1247 ;;; `cperl-get-here-doc-region': Likewise
1248 ;;; `cperl-font-lock-fontify-region-function': Likewise (backward compatibility
1249 ;;; for legacy `font-lock')
1250 ;;; `cperl-font-lock-unfontify-region-function': Fix style
1251 ;;; `cperl-fontify-syntaxically': Recognize and optimize away
1252 ;;; deferred calls with no-change. Governed by `cperl-hook-after-change'
1253 ;;; `cperl-fontify-update': Recognize that syntaxification region
1254 ;;; can be larger than fontification one.
1255 ;;; XXXX we leave `cperl-postpone' property, so this is quadratic...
1256 ;;; `cperl-fontify-update-bad': Temporary placeholder until
1257 ;;; it is clear how to implement `cperl-fontify-update'.
1258 ;;; `cperl-time-fontification': New function
1259 ;;; `attrib-group': New text attribute
1260 ;;; `multiline': New value: `syntax-type' text attribute
1263 ;;; `cperl-emulate-lazy-lock': New function
1264 ;;; `cperl-fontify-syntaxically': Would skip large regions
1265 ;;; Add `cperl-time-fontification', `cperl-emulate-lazy-lock' to menu
1266 ;;; Some globals were declared, but uninitialized
1268 ;;;; After 5.3, 5.4:
1269 ;;; `cperl-facemenu-add-face-function': Add docs, fix U<>
1270 ;;; Copyright message updated.
1271 ;;; `cperl-init-faces': Work around a bug in `font-lock'. May slow
1272 ;;; facification down a bit.
1273 ;;; Misprint for my|our|local for old `font-lock'
1274 ;;; "our" was not fontified same as "my|local"
1275 ;;; Highlight variables after "my" etc even in
1276 ;;; a middle of an expression
1277 ;;; Do not facify multiple variables after my etc
1278 ;;; unless parentheses are present
1281 ;;; `cperl-fontify-syntaxically': after-change hook could reset
1282 ;;; `cperl-syntax-done-to' to a middle of line; unwind to BOL.
1285 ;;; `cperl-init-faces': Allow highlighting of local ($/)
1286 ;;; `cperl-problems-old-emaxen': New variable (for the purpose of DOCSTRING).
1287 ;;; `cperl-problems': Remove fixed problems.
1288 ;;; `cperl-find-pods-heres': Recognize #-comments in m##x too
1289 ;;; Recognize charclasses (unless delimiter is \).
1290 ;;; `cperl-fontify-syntaxically': Unwinding to safe was done in wrong order
1291 ;;; `cperl-regexp-scan': Update docs
1292 ;;; `cperl-beautify-regexp-piece': use information got from regexp scan
1295 ;;; Major user visible changes:
1296 ;;; Recognition and fontification of character classes in RExen.
1297 ;;; Variable indentation of RExen according to groups
1299 ;;; `cperl-find-pods-heres': Recognize POSIX classes in REx charclasses
1300 ;;; Fontify REx charclasses in variable-name face
1301 ;;; Fontify POSIX charclasses in "type" face
1302 ;;; Fontify unmatched "]" in function-name face
1303 ;;; Mark first-char of HERE-doc as `front-sticky'
1304 ;;; Reset `front-sticky' property when needed
1305 ;;; `cperl-calculate-indent': Indents //x -RExen accordning to parens level
1306 ;;; `cperl-to-comment-or-eol': Recognize ends of `syntax-type' constructs
1307 ;;; `cperl-backward-to-noncomment': Recognize stringy `syntax-type' constructs
1308 ;;; Support `narrow'ed buffers.
1309 ;;; `cperl-praise': Remove a reservation
1310 ;;; `cperl-make-indent': New function
1311 ;;; `cperl-indent-for-comment': Use `cperl-make-indent'
1312 ;;; `cperl-indent-line': Likewise
1313 ;;; `cperl-lineup': Likewise
1314 ;;; `cperl-beautify-regexp-piece': Likewise
1315 ;;; `cperl-contract-level': Likewise
1316 ;;; `cperl-toggle-set-debug-unwind': New function
1317 ;;; New menu entry for this
1318 ;;; `fill-paragraph-function': Use when `boundp'
1319 ;;; `cperl-calculate-indent': Take into account groups when indenting RExen
1320 ;;; `cperl-to-comment-or-eol': Recognize # which end a string
1321 ;;; `cperl-modify-syntax-type': Make only syntax-table property non-sticky
1322 ;;; `cperl-fill-paragraph': Return t: needed for `fill-paragraph-function'
1323 ;;; `cperl-fontify-syntaxically': More clear debugging message
1324 ;;; `cperl-pod2man-build-command': XEmacs portability: check `Man-filter-list'
1325 ;;; `cperl-init-faces': More complicated highlight even on XEmacs (new)
1326 ;;; Merge cosmetic changes from XEmacs
1329 ;;; `cperl-1+': Moved to before the first use
1330 ;;; `cperl-1-': Likewise
1334 ;;; This code may lock Emacs hard!!! Use on your own risk!
1336 ;;; `cperl-font-locking': New internal variable
1337 ;;; `cperl-beginning-of-property': New function
1338 ;;; `cperl-calculate-indent': Use `cperl-beginning-of-property'
1339 ;;; instead of `previous-single-property-change'
1340 ;;; `cperl-unwind-to-safe': Likewise
1341 ;;; `cperl-after-expr-p': Likewise
1342 ;;; `cperl-get-here-doc-region': Likewise
1343 ;;; `cperl-font-lock-fontify-region-function': Likewise
1344 ;;; `cperl-to-comment-or-eol': Do not call `cperl-update-syntaxification'
1346 ;;; Bound `next-single-property-change'
1348 ;;; `cperl-unwind-to-safe': Bound likewise
1349 ;;; `cperl-font-lock-fontify-region-function': Likewise
1350 ;;; `cperl-find-pods-heres': Mark as recursive for `cperl-to-comment-or-eol'
1351 ;;; Initialization of
1352 ;;; `cperl-font-lock-multiline-start' could be missed if the "main"
1353 ;;; fontification did not run due to the keyword being already fontified.
1354 ;;; `cperl-pod-spell': Return t from do-one-chunk function
1355 ;;; `cperl-map-pods-heres': Stop when the worker returns nil
1356 ;;; Call `cperl-update-syntaxification'
1357 ;;; `cperl-get-here-doc-region': Call `cperl-update-syntaxification'
1358 ;;; `cperl-get-here-doc-delim': Remove unused function
1362 ;;; The possible lockup of Emacs (introduced in 5.10) fixed
1364 ;;; `cperl-unwind-to-safe': `cperl-beginning-of-property' won't return nil
1365 ;;; `cperl-syntaxify-for-menu': New customization variable
1366 ;;; `cperl-select-this-pod-or-here-doc': New function
1367 ;;; `cperl-get-here-doc-region': Extra argument
1368 ;;; Do not adjust pos by 1
1370 ;;; New menu entries (Perl/Tools): selection of current POD or HERE-DOC section
1371 ;;; (Debugging CPerl:) backtrace on fontification
1374 ;;; `cperl-cached-syntax-table': use `car-safe'
1375 ;;; `cperl-forward-re': Remove spurious argument SET-ST
1376 ;;; Add documentation
1377 ;;; `cperl-forward-group-in-re': New function
1378 ;;; `cperl-find-pods-heres': Find and highlight (?{}) blocks in RExen
1379 ;;; (XXXX Temporary (?) hack is to syntax-mark them as comment)
1382 ;;; `cperl-string-syntax-table': Make { and } not-grouping
1383 ;;; (Sometimes they ARE grouping in RExen, but matching them would only
1384 ;;; confuse in many situations when they are not)
1385 ;;; `beginning-of-buffer': Replaced two occurences with goto-char...
1386 ;;; `cperl-calculate-indent': `char-after' could be nil...
1387 ;;; `cperl-find-pods-heres': REx can start after "[" too
1388 ;;; Hightlight (??{}) in RExen too
1389 ;;; `cperl-maybe-white-and-comment-rex': New constant
1390 ;;; `cperl-white-and-comment-rex': Likewise
1391 ;;; XXXX Not very efficient, but hard to make
1392 ;;; better while keeping 1 group
1395 ;;; `cperl-find-pods-heres': $foo << identifier() is not a HERE-DOC
1396 ;;; Likewise for 1 << identifier
1399 ;;; `cperl-find-pods-heres': Different logic for $foo .= <<EOF etc
1400 ;;; Error-less condition-case could fail
1401 ;;; `cperl-font-lock-fontify-region-function': Likewise
1402 ;;; `cperl-init-faces': Likewise
1405 ;;; `cperl-find-pods-heres': Support property REx-part2
1406 ;;; `cperl-calculate-indent': Likewise
1407 ;;; Don't special-case REx with non-empty 1st line
1408 ;;; `cperl-find-pods-heres': In RExen, highlight non-literal backslashes
1409 ;;; Invert highlighting of charclasses:
1410 ;;; now the envelop is highlighted
1411 ;;; Highlight many others 0-length builtins
1412 ;;; `cperl-praise': Mention indenting and highlight in RExen
1415 ;;; `cperl-find-pods-heres': Highlight capturing parens in REx
1418 ;;; `cperl-find-pods-heres': Highlight '|' for alternation
1419 ;;; Initialize `font-lock-warning-face' if not present
1420 ;;; `cperl-find-pods-heres': Use `font-lock-warning-face' instead of
1421 ;;; `font-lock-function-name-face'
1422 ;;; `cperl-look-at-leading-count': Likewise
1423 ;;; `cperl-find-pods-heres': localize `font-lock-variable-name-face'
1424 ;;; `font-lock-keyword-face' (needed for
1425 ;;; batch processing) etc
1426 ;;; Use `font-lock-builtin-face' for builtin in REx
1427 ;;; Now `font-lock-variable-name-face'
1428 ;;; is used for interpolated variables
1429 ;;; Use "talking aliases" for faces inside REx
1430 ;;; Highlight parts of REx (except in charclasses)
1431 ;;; according to the syntax and/or semantic
1432 ;;; Syntax-mark a {}-part of (?{}) as "comment"
1433 ;;; (it was the ()-part)
1434 ;;; Better logic to distinguish what is what in REx
1435 ;;; `cperl-tips-faces': Document REx highlighting
1436 ;;; `cperl-praise': Mention REx syntax highlight etc.
1439 ;;; `cperl-find-sub-attrs': Would not always manage to print error message
1440 ;;; `cperl-find-pods-heres': localize `font-lock-constant-face'
1443 ;;; `cperl-find-pods-heres': Misprint in REx for parsing REx
1444 ;;; Very minor optimization
1445 ;;; `my-cperl-REx-modifiers-face' got quoted
1446 ;;; Recognize "print $foo <<END" as HERE-doc
1447 ;;; Put `REx-interpolated' text attribute if needed
1448 ;;; `cperl-invert-if-unless-modifiers': New function
1449 ;;; `cperl-backward-to-start-of-expr': Likewise
1450 ;;; `cperl-forward-to-end-of-expr': Likewise
1451 ;;; `cperl-invert-if-unless': Works in "the opposite way" too
1452 ;;; Cursor position on return is on the switch-word
1453 ;;; Indents comments better
1454 ;;; `REx-interpolated': New text attribute
1455 ;;; `cperl-next-interpolated-REx': New function
1456 ;;; `cperl-next-interpolated-REx-0': Likewise
1457 ;;; `cperl-next-interpolated-REx-1': Likewise
1458 ;;; "\C-c\C-x", "\C-c\C-y", "\C-c\C-v": New keybinding for these functions
1459 ;;; Perl/Regexp menu: 3 new entries for `cperl-next-interpolated-REx'
1460 ;;; `cperl-praise': Mention finded interpolated RExen
1463 ;;; `cperl-init-faces': Highlight %$foo, @$foo too
1464 ;;; `cperl-short-docs': Better docs for system, exec
1465 ;;; `cperl-find-pods-heres': Better detect << after print {FH} <<EOF etc.
1466 ;;; Would not find HERE-doc ended by EOF without NL
1467 ;;; `cperl-short-docs': Correct not-doubled \-escapes
1468 ;;; start block: Put some `defvar' for stuff gone from XEmacs
1471 ;;; initial comment: Extend copyright, fix email address
1472 ;;; `cperl-indent-comment-at-column-0': New customization variable
1473 ;;; `cperl-comment-indent': Indentation after $#a would increasy by 1
1474 ;;; `cperl-mode': Make `defun-prompt-regexp' grok BEGIN/END etc
1475 ;;; `cperl-find-pods-heres': Mark CODE of s///e as `syntax-type' `multiline'
1476 ;;; `cperl-at-end-of-expr': Would fail if @BAR=12 follows after ";"
1477 ;;; `cperl-init-faces': If `cperl-highlight-variables-indiscriminately'
1478 ;;; highlight $ in $foo too (UNTESTED)
1479 ;;; `cperl-set-style': Docstring missed some available styles
1480 ;;; toplevel: Menubar/Perl/Indent-Styles had FSF, now K&R
1481 ;;; Change "Current" to "Memorize Current"
1482 ;;; `cperl-indent-wrt-brace': New customization variable; the default is
1483 ;;; as for pre-5.2 version
1484 ;;; `cperl-styles-entries': Keep `cperl-extra-newline-before-brace-multiline'
1485 ;;; `cperl-style-alist': Likewise
1486 ;;; `cperl-fix-line-spacing': Support `cperl-merge-trailing-else' being nil,
1487 ;;; and `cperl-extra-newline-before-brace' etc
1489 ;;; `cperl-indent-exp': Plans B and C to find continuation blocks even
1490 ;;; if `cperl-extra-newline-before-brace' is t
1493 ;;; Improve some docstrings concerning indentation.
1494 ;;; `cperl-indent-rules-alist': New variable
1495 ;;; `cperl-sniff-for-indent': New function name
1496 ;; (separated from `cperl-calculate-indent')
1497 ;;; `cperl-calculate-indent': Separated the sniffer and the indenter;
1498 ;;; uses `cperl-sniff-for-indent' now
1499 ;;; `cperl-comment-indent': Test for `cperl-indent-comment-at-column-0'
1501 ;;; Support `comment-column' = 0
1504 ;;; `cperl-where-am-i': Remove function
1505 ;;; `cperl-backward-to-noncomment': Would go too far when skipping POD/HEREs
1506 ;;; `cperl-sniff-for-indent': [string] and [comment] were inverted
1507 ;;; When looking for label, skip s:m:y:tr
1508 ;;; `cperl-indent-line': Likewise
1509 ;;; `cperl-mode': `font-lock-multiline' was assumed auto-local
1510 ;;; `cperl-windowed-init': Wrong `ps-print' handling
1511 ;;; (both thanks to Chong Yidong)
1512 ;;; `cperl-look-at-leading-count': Could fail with unfinished RExen
1513 ;;; `cperl-find-pods-heres': If the second part of s()[] is missing,
1514 ;;; could try to highlight delimiters...
1517 ;;; toplevel: Add comment on existence of different flavors
1518 ;;; `cperl-string-syntax-table': Was treating quotes as special
1519 ;;; Mode menu: Add "Report indentation context"
1520 ;;; `cperl-sniff-for-indent': Update comments
1521 ;;; `cperl-make-regexp-x': Was treating qr wrong
1522 ;;; `cperl-fill-paragraph': v22.1 needs `save-excursion' (XXXX BUG???)
1523 ;;; (Thanks to Pete Harlan)
1524 ;;; `cperl-build-manpage': set `Man-switches' for use in
1525 ;;; `Man-getpage-in-background'
1526 ;;; `cperl-perldoc': Likewise (Thanks to Alexander Haeckel)
1527 ;;; `cperl-beautify-regexp-piece': Allow for indentation of (?:)-group
1528 ;;; `cperl-beautify-level': Likewise
1529 ;;; `cperl-mode': `compilation-error-regexp-alist-alist'
1530 ;;; is defined in Emacs22, with different
1531 ;;; semantic than in XEmacs21
1532 ;;; (Thanks to Mark T. Kennedy)
1533 ;;; toplevel: Need to defvar `compilation-error-regexp-alist'
1534 ;;; `cperl-find-pods-heres': Check for unfinished s treated s/a// as such
1535 ;;; Better comments in REx highlighting
1536 ;;; Highlighting of - in charclasses
1537 ;;; (Does not pay attention to alphanum/dash delim)
1538 ;;; `cperl-forward-re': Do not print "unmatched" during electric {
1541 ;;; `cperl-find-pods-heres': Better comments in REx highlighting
1542 ;;; Treat backslashes before POSIX charclass better
1543 ;;; Highlighting of - and \ESCAPED in charclasses
1544 ;;; (Doesnt pay attention to alphanum/dash delim)
1545 ;;; Change POSIX class highlight to variable-name
1546 ;;; `cperl-highlight-charclass': New subst
1547 ;;; `cperl-tips-faces' Correct literal backwacks, mention multipliers
1550 ;;;; Incorporate XEmacs changes:
1551 ;;; `cperl-mode-map': Bind 'delete 'backspace on XEmacs
1552 ;;; `cperl-electric-delete': New (unsupported) function for XEmacs bindings
1553 ;;; toplevel: Define obsolete alias for `pod-spell'
1554 ;;; autoload updates to `mode-alist's
1557 ;;; toplevel: Add .PM to autoload mode list
1558 ;;; `cperl-insert-faces-example': New function
1559 ;;; Mode menu: New Micro-docs choice: Show Faces
1563 (if (fboundp 'eval-when-compile)
1571 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
1572 (defvar cperl-can-font-lock
1574 (and (boundp 'emacs-major-version)
1576 (> emacs-major-version 20)))))
1577 (if cperl-can-font-lock
1578 (require 'font-lock))
1579 (defvar msb-menu-cond)
1580 (defvar gud-perldb-history)
1581 (defvar font-lock-background-mode) ; not in Emacs
1582 (defvar font-lock-display-type) ; ditto
1583 (defvar paren-backwards-message) ; Not in newer XEmacs?
1584 (defvar vc-rcs-header) ; likewise?
1585 (defvar vc-sccs-header) ; likewise?
1586 (defvar compilation-error-regexp-alist) ; used in Emacs 22
1587 (or (fboundp 'defgroup)
1588 (defmacro defgroup (name val doc &rest arr)
1590 (or (fboundp 'custom-declare-variable)
1591 (defmacro defcustom (name val doc &rest arr)
1592 (` (defvar (, name) (, val) (, doc)))))
1593 (or (and (fboundp 'custom-declare-variable)
1594 (string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
1595 (defmacro defface (&rest arr)
1597 ;; Avoid warning (tmp definitions)
1598 (or (fboundp 'x-color-defined-p)
1599 (defmacro x-color-defined-p (col)
1600 (cond ((fboundp 'color-defined-p) (` (color-defined-p (, col))))
1602 ((fboundp 'valid-color-name-p) (` (valid-color-name-p (, col))))
1604 ((fboundp 'x-valid-color-name-p) (` (x-valid-color-name-p (, col))))
1605 (t '(error "Cannot implement color-defined-p")))))
1606 (defmacro cperl-is-face (arg) ; Takes quoted arg
1607 (cond ((fboundp 'find-face)
1608 (` (find-face (, arg))))
1609 (;;(and (fboundp 'face-list)
1611 (fboundp 'face-list)
1612 (` (member (, arg) (and (fboundp 'face-list)
1615 (` (boundp (, arg))))))
1616 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
1617 (cond ((fboundp 'make-face)
1618 (` (make-face (quote (, arg)))))
1620 (` (defvar (, arg) (quote (, arg)) (, descr))))))
1621 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
1623 (or (cperl-is-face (quote (, arg)))
1624 (cperl-make-face (, arg) (, descr)))
1625 (or (boundp (quote (, arg))) ; We use unquoted variants too
1626 (defvar (, arg) (quote (, arg)) (, descr))))))
1628 (defmacro cperl-etags-snarf-tag (file line)
1630 (beginning-of-line 2)
1631 (list (, file) (, line)))))
1632 (defmacro cperl-etags-snarf-tag (file line)
1633 (` (etags-snarf-tag))))
1635 (defmacro cperl-etags-goto-tag-location (elt)
1637 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
1638 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
1639 ;; Probably will not work due to some save-excursion???
1640 ;; Or save-file-position?
1641 ;; (message "Did I get to line %s?" (elt (, elt) 1))
1642 (goto-line (string-to-int (elt (, elt) 1)))))
1644 (defmacro cperl-etags-goto-tag-location (elt)
1645 (` (etags-goto-tag-location (, elt)))))))
1647 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
1649 (defvar cperl-can-font-lock
1651 (and (boundp 'emacs-major-version)
1653 (> emacs-major-version 20)))))
1657 (error nil)) ; Already fixed by eval-when-compile
1659 (defun cperl-choose-color (&rest list)
1663 (if (or (x-color-defined-p (car list))
1665 (setq answer (car list))))
1666 (setq list (cdr list)))
1671 "Major mode for editing Perl code."
1675 (defgroup cperl-indentation-details nil
1680 (defgroup cperl-affected-by-hairy nil
1681 "Variables affected by `cperl-hairy'."
1685 (defgroup cperl-autoinsert-details nil
1686 "Auto-insert tuneup."
1690 (defgroup cperl-faces nil
1691 "Fontification colors."
1695 (defgroup cperl-speed nil
1696 "Speed vs. validity tuneup."
1700 (defgroup cperl-help-system nil
1701 "Help system tuneup."
1706 (defcustom cperl-extra-newline-before-brace nil
1707 "*Non-nil means that if, elsif, while, until, else, for, foreach
1708 and do constructs look like:
1719 :group 'cperl-autoinsert-details)
1721 (defcustom cperl-extra-newline-before-brace-multiline
1722 cperl-extra-newline-before-brace
1723 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
1724 for constructs with multiline if/unless/while/until/for/foreach condition."
1726 :group 'cperl-autoinsert-details)
1728 (defcustom cperl-indent-level 2
1729 "*Indentation of CPerl statements with respect to containing block."
1731 :group 'cperl-indentation-details)
1733 (defcustom cperl-lineup-step nil
1734 "*`cperl-lineup' will always lineup at multiple of this number.
1735 If nil, the value of `cperl-indent-level' will be used."
1736 :type '(choice (const nil) integer)
1737 :group 'cperl-indentation-details)
1739 (defcustom cperl-brace-imaginary-offset 0
1740 "*Imagined indentation of a Perl open brace that actually follows a statement.
1741 An open brace following other text is treated as if it were this far
1742 to the right of the start of its line."
1744 :group 'cperl-indentation-details)
1746 (defcustom cperl-brace-offset 0
1747 "*Extra indentation for braces, compared with other text in same context."
1749 :group 'cperl-indentation-details)
1750 (defcustom cperl-label-offset -2
1751 "*Offset of CPerl label lines relative to usual indentation."
1753 :group 'cperl-indentation-details)
1754 (defcustom cperl-min-label-indent 1
1755 "*Minimal offset of CPerl label lines."
1757 :group 'cperl-indentation-details)
1758 (defcustom cperl-continued-statement-offset 2
1759 "*Extra indent for lines not starting new statements."
1761 :group 'cperl-indentation-details)
1762 (defcustom cperl-continued-brace-offset 0
1763 "*Extra indent for substatements that start with open-braces.
1764 This is in addition to cperl-continued-statement-offset."
1766 :group 'cperl-indentation-details)
1767 (defcustom cperl-close-paren-offset -1
1768 "*Extra indent for substatements that start with close-parenthesis."
1770 :group 'cperl-indentation-details)
1772 (defcustom cperl-indent-wrt-brace t
1773 "*Non-nil means indent statements in if/etc block relative brace, not if/etc.
1774 Versions 5.2 ... 5.20 behaved as if this were `nil'."
1776 :group 'cperl-indentation-details)
1778 (defcustom cperl-auto-newline nil
1779 "*Non-nil means automatically newline before and after braces,
1780 and after colons and semicolons, inserted in CPerl code. The following
1781 \\[cperl-electric-backspace] will remove the inserted whitespace.
1782 Insertion after colons requires both this variable and
1783 `cperl-auto-newline-after-colon' set."
1785 :group 'cperl-autoinsert-details)
1787 (defcustom cperl-autoindent-on-semi nil
1788 "*Non-nil means automatically indent after insertion of (semi)colon.
1789 Active if `cperl-auto-newline' is false."
1791 :group 'cperl-autoinsert-details)
1793 (defcustom cperl-auto-newline-after-colon nil
1794 "*Non-nil means automatically newline even after colons.
1795 Subject to `cperl-auto-newline' setting."
1797 :group 'cperl-autoinsert-details)
1799 (defcustom cperl-tab-always-indent t
1800 "*Non-nil means TAB in CPerl mode should always reindent the current line,
1801 regardless of where in the line point is when the TAB command is used."
1803 :group 'cperl-indentation-details)
1805 (defcustom cperl-font-lock nil
1806 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
1807 Can be overwritten by `cperl-hairy' if nil."
1808 :type '(choice (const null) boolean)
1809 :group 'cperl-affected-by-hairy)
1811 (defcustom cperl-electric-lbrace-space nil
1812 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
1813 Can be overwritten by `cperl-hairy' if nil."
1814 :type '(choice (const null) boolean)
1815 :group 'cperl-affected-by-hairy)
1817 (defcustom cperl-electric-parens-string "({[]})<"
1818 "*String of parentheses that should be electric in CPerl.
1819 Closing ones are electric only if the region is highlighted."
1821 :group 'cperl-affected-by-hairy)
1823 (defcustom cperl-electric-parens nil
1824 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
1825 Can be overwritten by `cperl-hairy' if nil."
1826 :type '(choice (const null) boolean)
1827 :group 'cperl-affected-by-hairy)
1829 (defvar zmacs-regions) ; Avoid warning
1831 (defcustom cperl-electric-parens-mark
1833 (or (and (boundp 'transient-mark-mode) ; For Emacs
1834 transient-mark-mode)
1835 (and (boundp 'zmacs-regions) ; For XEmacs
1837 "*Not-nil means that electric parens look for active mark.
1838 Default is yes if there is visual feedback on mark."
1840 :group 'cperl-autoinsert-details)
1842 (defcustom cperl-electric-linefeed nil
1843 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
1844 In any case these two mean plain and hairy linefeeds together.
1845 Can be overwritten by `cperl-hairy' if nil."
1846 :type '(choice (const null) boolean)
1847 :group 'cperl-affected-by-hairy)
1849 (defcustom cperl-electric-keywords nil
1850 "*Not-nil (and non-null) means keywords are electric in CPerl.
1851 Can be overwritten by `cperl-hairy' if nil."
1852 :type '(choice (const null) boolean)
1853 :group 'cperl-affected-by-hairy)
1855 (defcustom cperl-electric-backspace-untabify t
1856 "*Not-nil means electric-backspace will untabify in CPerl."
1858 :group 'cperl-autoinsert-details)
1860 (defcustom cperl-hairy nil
1861 "*Not-nil means most of the bells and whistles are enabled in CPerl.
1862 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
1863 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
1864 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
1865 `cperl-lazy-help-time'."
1867 :group 'cperl-affected-by-hairy)
1869 (defcustom cperl-comment-column 32
1870 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
1872 :group 'cperl-indentation-details)
1874 (defcustom cperl-indent-comment-at-column-0 nil
1875 "*Non-nil means that comment started at column 0 should be indentable."
1877 :group 'cperl-indentation-details)
1879 (defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
1880 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
1881 :type '(repeat string)
1884 (defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
1885 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
1886 :type '(repeat string)
1889 ;; This became obsolete...
1890 (defcustom cperl-vc-header-alist '()
1891 "*What to use as `vc-header-alist' in CPerl.
1892 Obsolete, with newer Emacsen use `cperl-vc-rcs-header' or
1893 `cperl-vc-sccs-header' instead. If this list is empty, `vc-header-alist'
1894 will be reconstructed basing on these two variables."
1895 :type '(repeat (list symbol string))
1898 (defcustom cperl-clobber-mode-lists
1901 (boundp 'interpreter-mode-alist)
1902 (assoc "miniperl" interpreter-mode-alist)
1903 (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
1904 "*Whether to install us into `interpreter-' and `extension' mode lists."
1908 (defcustom cperl-info-on-command-no-prompt nil
1909 "*Not-nil (and non-null) means not to prompt on C-h f.
1910 The opposite behaviour is always available if prefixed with C-c.
1911 Can be overwritten by `cperl-hairy' if nil."
1912 :type '(choice (const null) boolean)
1913 :group 'cperl-affected-by-hairy)
1915 (defcustom cperl-clobber-lisp-bindings nil
1916 "*Not-nil (and non-null) means not overwrite C-h f.
1917 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
1918 Can be overwritten by `cperl-hairy' if nil."
1919 :type '(choice (const null) boolean)
1920 :group 'cperl-affected-by-hairy)
1922 (defcustom cperl-lazy-help-time nil
1923 "*Not-nil (and non-null) means to show lazy help after given idle time.
1924 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
1925 :type '(choice (const null) (const nil) integer)
1926 :group 'cperl-affected-by-hairy)
1928 (defcustom cperl-pod-face 'font-lock-comment-face
1929 "*The result of evaluation of this expression is used for POD highlighting."
1931 :group 'cperl-faces)
1933 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
1934 "*The result of evaluation of this expression is used for POD highlighting.
1935 Font for POD headers."
1937 :group 'cperl-faces)
1939 (defcustom cperl-here-face 'font-lock-string-face
1940 "*The result of evaluation of this expression is used for here-docs highlighting."
1942 :group 'cperl-faces)
1944 ;;; Some double-evaluation happened with font-locks... Needed with 21.2...
1945 (defvar cperl-singly-quote-face cperl-xemacs-p)
1947 (defcustom cperl-invalid-face ; Does not customize with '' on XEmacs
1948 (if cperl-singly-quote-face
1949 'underline ''underline) ; On older Emacsen was evaluated by `font-lock'
1950 (if cperl-singly-quote-face
1951 "*This face is used for highlighting trailing whitespace."
1952 "*The result of evaluation of this expression highlights trailing whitespace.")
1954 :group 'cperl-faces)
1956 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
1957 "*Not-nil after evaluation means to highlight POD and here-docs sections."
1959 :group 'cperl-faces)
1961 (defcustom cperl-fontify-m-as-s t
1962 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
1964 :group 'cperl-faces)
1966 (defcustom cperl-highlight-variables-indiscriminately nil
1967 "*Non-nil means perform additional highlighting on variables.
1968 Currently only changes how scalar variables are highlighted.
1969 Note that that variable is only read at initialization time for
1970 the variable `perl-font-lock-keywords-2', so changing it after you've
1971 entered CPerl mode the first time will have no effect."
1975 (defcustom cperl-pod-here-scan t
1976 "*Not-nil means look for POD and here-docs sections during startup.
1977 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
1979 :group 'cperl-speed)
1981 (defcustom cperl-regexp-scan t
1982 "*Not-nil means make marking of regular expression more thorough.
1983 Effective only with `cperl-pod-here-scan'."
1985 :group 'cperl-speed)
1987 (defcustom cperl-hook-after-change t
1988 "*Not-nil means install hook to know which regions of buffer are changed.
1989 May significantly speed up delayed fontification. Changes take effect
1992 :group 'cperl-speed)
1994 (defcustom cperl-imenu-addback nil
1995 "*Not-nil means add backreferences to generated `imenu's.
1996 May require patched `imenu' and `imenu-go'. Obsolete."
1998 :group 'cperl-help-system)
2000 (defcustom cperl-max-help-size 66
2001 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
2002 :type '(choice integer (const nil))
2003 :group 'cperl-help-system)
2005 (defcustom cperl-shrink-wrap-info-frame t
2006 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
2008 :group 'cperl-help-system)
2010 (defcustom cperl-info-page "perl"
2011 "*Name of the info page containing perl docs.
2012 Older version of this page was called `perl5', newer `perl'."
2014 :group 'cperl-help-system)
2016 (defcustom cperl-use-syntax-table-text-property
2017 (boundp 'parse-sexp-lookup-properties)
2018 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
2020 :group 'cperl-speed)
2022 (defcustom cperl-use-syntax-table-text-property-for-tags
2023 cperl-use-syntax-table-text-property
2024 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
2026 :group 'cperl-speed)
2028 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
2029 "*Regexp to match files to scan when generating TAGS."
2033 (defcustom cperl-noscan-files-regexp
2034 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
2035 "*Regexp to match files/dirs to skip when generating TAGS."
2039 (defcustom cperl-regexp-indent-step nil
2040 "*Indentation used when beautifying regexps.
2041 If nil, the value of `cperl-indent-level' will be used."
2042 :type '(choice integer (const nil))
2043 :group 'cperl-indentation-details)
2045 (defcustom cperl-indent-left-aligned-comments t
2046 "*Non-nil means that the comment starting in leftmost column should indent."
2048 :group 'cperl-indentation-details)
2050 (defcustom cperl-under-as-char t
2051 "*Non-nil means that the _ (underline) should be treated as word char."
2055 (defcustom cperl-extra-perl-args ""
2056 "*Extra arguments to use when starting Perl.
2057 Currently used with `cperl-check-syntax' only."
2061 (defcustom cperl-message-electric-keyword t
2062 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
2064 :group 'cperl-help-system)
2066 (defcustom cperl-indent-region-fix-constructs 1
2067 "*Amount of space to insert between `}' and `else' or `elsif'
2068 in `cperl-indent-region'. Set to nil to leave as is. Values other
2069 than 1 and nil will probably not work."
2070 :type '(choice (const nil) (const 1))
2071 :group 'cperl-indentation-details)
2073 (defcustom cperl-break-one-line-blocks-when-indent t
2074 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
2075 need to be reformatted into multiline ones when indenting a region."
2077 :group 'cperl-indentation-details)
2079 (defcustom cperl-fix-hanging-brace-when-indent t
2080 "*Non-nil means that BLOCK-end `}' may be put on a separate line
2081 when indenting a region.
2082 Braces followed by else/elsif/while/until are excepted."
2084 :group 'cperl-indentation-details)
2086 (defcustom cperl-merge-trailing-else t
2087 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
2088 may be merged to be on the same line when indenting a region."
2090 :group 'cperl-indentation-details)
2092 (defcustom cperl-indent-parens-as-block nil
2093 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
2094 but for trailing \",\" inside the group, which won't increase indentation.
2095 One should tune up `cperl-close-paren-offset' as well."
2097 :group 'cperl-indentation-details)
2099 (defcustom cperl-syntaxify-by-font-lock
2100 (and cperl-can-font-lock
2101 (boundp 'parse-sexp-lookup-properties))
2102 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
2103 :type '(choice (const message) boolean)
2104 :group 'cperl-speed)
2106 (defcustom cperl-syntaxify-unwind
2108 "*Non-nil means that CPerl unwinds to a start of a long construction
2109 when syntaxifying a chunk of buffer."
2111 :group 'cperl-speed)
2113 (defcustom cperl-syntaxify-for-menu
2115 "*Non-nil means that CPerl syntaxifies up to the point before showing menu.
2116 This way enabling/disabling of menu items is more correct."
2118 :group 'cperl-speed)
2120 (defcustom cperl-ps-print-face-properties
2121 '((font-lock-keyword-face nil nil bold shadow)
2122 (font-lock-variable-name-face nil nil bold)
2123 (font-lock-function-name-face nil nil bold italic box)
2124 (font-lock-constant-face nil "LightGray" bold)
2125 (cperl-array-face nil "LightGray" bold underline)
2126 (cperl-hash-face nil "LightGray" bold italic underline)
2127 (font-lock-comment-face nil "LightGray" italic)
2128 (font-lock-string-face nil nil italic underline)
2129 (cperl-nonoverridable-face nil nil italic underline)
2130 (font-lock-type-face nil nil underline)
2131 (font-lock-warning-face nil "LightGray" bold italic box)
2132 (underline nil "LightGray" strikeout))
2133 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
2134 :type '(repeat (cons symbol
2135 (cons (choice (const nil) string)
2136 (cons (choice (const nil) string)
2138 :group 'cperl-faces)
2140 (if cperl-can-font-lock
2142 (defvar cperl-dark-background
2143 (cperl-choose-color "navy" "os2blue" "darkgreen"))
2144 (defvar cperl-dark-foreground
2145 (cperl-choose-color "orchid1" "orange"))
2147 (defface cperl-nonoverridable-face
2148 (` ((((class grayscale) (background light))
2149 (:background "Gray90" :italic t :underline t))
2150 (((class grayscale) (background dark))
2151 (:foreground "Gray80" :italic t :underline t :bold t))
2152 (((class color) (background light))
2153 (:foreground "chartreuse3"))
2154 (((class color) (background dark))
2155 (:foreground (, cperl-dark-foreground)))
2156 (t (:bold t :underline t))))
2157 "Font Lock mode face used to highlight array names."
2158 :group 'cperl-faces)
2160 (defface cperl-array-face
2161 (` ((((class grayscale) (background light))
2162 (:background "Gray90" :bold t))
2163 (((class grayscale) (background dark))
2164 (:foreground "Gray80" :bold t))
2165 (((class color) (background light))
2166 (:foreground "Blue" :background "lightyellow2" :bold t))
2167 (((class color) (background dark))
2168 (:foreground "yellow" :background (, cperl-dark-background) :bold t))
2170 "Font Lock mode face used to highlight array names."
2171 :group 'cperl-faces)
2173 (defface cperl-hash-face
2174 (` ((((class grayscale) (background light))
2175 (:background "Gray90" :bold t :italic t))
2176 (((class grayscale) (background dark))
2177 (:foreground "Gray80" :bold t :italic t))
2178 (((class color) (background light))
2179 (:foreground "Red" :background "lightyellow2" :bold t :italic t))
2180 (((class color) (background dark))
2181 (:foreground "Red" :background (, cperl-dark-background) :bold t :italic t))
2182 (t (:bold t :italic t))))
2183 "Font Lock mode face used to highlight hash names."
2184 :group 'cperl-faces)))
2188 ;;; Short extra-docs.
2190 (defvar cperl-tips 'please-ignore-this-line
2191 "Get maybe newer version of this package from
2192 http://ilyaz.org/software/emacs
2193 Subdirectory `cperl-mode' may contain yet newer development releases and/or
2194 patches to related files.
2196 For best results apply to an older Emacs the patches from
2197 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
2198 \(this upgrades syntax-parsing abilities of RMS Emaxen v19.34 and
2199 v20.2 up to the level of RMS Emacs v20.3 - a must for a good Perl
2200 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
2202 Get support packages choose-color.el (or font-lock-extra.el before
2203 19.30), imenu-go.el from the same place. \(Look for other files there
2204 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
2205 later you should use choose-color.el *instead* of font-lock-extra.el
2206 \(and you will not get smart highlighting in C :-().
2208 Note that to enable Compile choices in the menu you need to install
2211 If your Emacs does not default to `cperl-mode' on Perl files, and you
2212 want it to: put the following into your .emacs file:
2214 (autoload 'perl-mode \"cperl-mode\" \"alternate mode for editing Perl programs\" t)
2218 (defalias 'perl-mode 'cperl-mode)
2221 $CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
2222 Also, one can generate a newer documentation running `pod2texi' converter
2223 $CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
2225 If you use imenu-go, run imenu on perl5-info buffer (you can do it
2226 from Perl menu). If many files are related, generate TAGS files from
2227 Tools/Tags submenu in Perl menu.
2229 If some class structure is too complicated, use Tools/Hierarchy-view
2230 from Perl menu, or hierarchic view of imenu. The second one uses the
2231 current buffer only, the first one requires generation of TAGS from
2232 Perl/Tools/Tags menu beforehand.
2234 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
2236 Switch auto-help on/off with Perl/Tools/Auto-help.
2238 Though with contemporary Emaxen CPerl mode should maintain the correct
2239 parsing of Perl even when editing, sometimes it may be lost. Fix this by
2247 In cases of more severe confusion sometimes it is helpful to do
2249 M-x load-l RET cperl-mode RET
2254 \\[load-library] cperl-mode RET
2257 Before reporting (non-)problems look in the problem section of online
2258 micro-docs on what I know about CPerl problems.")
2260 (defvar cperl-problems 'please-ignore-this-line
2261 "Description of problems in CPerl mode.
2262 Some faces will not be shown on some versions of Emacs unless you
2263 install choose-color.el, available from
2264 http://ilyaz.org/software/emacs
2266 `fill-paragraph' on a comment may leave the point behind the
2267 paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
2268 to detect it and bulk out).
2270 See documentation of a variable `cperl-problems-old-emaxen' for the
2271 problems which disappear if you upgrade Emacs to a reasonably new
2272 version (20.3 for RMS Emacs, and those of 2004 for XEmacs).")
2274 (defvar cperl-problems-old-emaxen 'please-ignore-this-line
2275 "Description of problems in CPerl mode specific for older Emacs versions.
2277 Emacs had a _very_ restricted syntax parsing engine until RMS's Emacs
2278 20.1. Most problems below are corrected starting from this version of
2279 Emacs, and all of them should be fixed in RMS's version 20.3. (Or apply
2280 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
2281 this respect (until 2003).
2283 Note that even with newer Emacsen in some very rare cases the details
2284 of interaction of `font-lock' and syntaxification may be not cleaned
2285 up yet. You may get slightly different colors basing on the order of
2286 fontification and syntaxification. Say, the initial faces is correct,
2287 but editing the buffer breaks this.
2289 Even with older Emacsen CPerl mode tries to corrects some Emacs
2290 misunderstandings, however, for efficiency reasons the degree of
2291 correction is different for different operations. The partially
2292 corrected problems are: POD sections, here-documents, regexps. The
2293 operations are: highlighting, indentation, electric keywords, electric
2296 This may be confusing, since the regexp s#//#/#\; may be highlighted
2297 as a comment, but it will be recognized as a regexp by the indentation
2298 code. Or the opposite case, when a POD section is highlighted, but
2299 may break the indentation of the following code (though indentation
2300 should work if the balance of delimiters is not broken by POD).
2302 The main trick (to make $ a \"backslash\") makes constructions like
2303 ${aaa} look like unbalanced braces. The only trick I can think of is
2304 to insert it as $ {aaa} (legal in perl5, not in perl4).
2306 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
2307 as /($|\\s)/. Note that such a transposition is not always possible.
2309 The solution is to upgrade your Emacs or patch an older one. Note
2310 that RMS's 20.2 has some bugs related to `syntax-table' text
2311 properties. Patches are available on the main CPerl download site,
2314 If these bugs cannot be fixed on your machine (say, you have an inferior
2315 environment and cannot recompile), you may still disable all the fancy stuff
2316 via `cperl-use-syntax-table-text-property'.")
2318 (defvar cperl-non-problems 'please-ignore-this-line
2319 "As you know from `problems' section, Perl syntax is too hard for CPerl on
2320 older Emacsen. Here is what you can do if you cannot upgrade, or if
2321 you want to switch off these capabilities on RMS Emacs 20.2 (+patches) or 20.3
2322 or better. Please skip this docs if you run a capable Emacs already.
2324 Most of the time, if you write your own code, you may find an equivalent
2325 \(and almost as readable) expression (what is discussed below is usually
2326 not relevant on newer Emacsen, since they can do it automatically).
2328 Try to help CPerl: add comments with embedded quotes to fix CPerl
2329 misunderstandings about the end of quotation:
2333 You won't need it too often. The reason: $ \"quotes\" the following
2334 character (this saves a life a lot of times in CPerl), thus due to
2335 Emacs parsing rules it does not consider tick (i.e., ' ) after a
2336 dollar as a closing one, but as a usual character. This is usually
2337 correct, but not in the above context.
2339 Even with older Emacsen the indentation code is pretty wise. The only
2340 drawback is that it relied on Emacs parsing to find matching
2341 parentheses. And Emacs *could not* match parentheses in Perl 100%
2344 would not break indentation, but
2350 could confuse CPerl a lot.
2352 If you still get wrong indentation in situation that you think the
2353 code should be able to parse, try:
2355 a) Check what Emacs thinks about balance of your parentheses.
2356 b) Supply the code to me (IZ).
2358 Pods were treated _very_ rudimentally. Here-documents were not
2359 treated at all (except highlighting and inhibiting indentation). Upgrade.
2361 To speed up coloring the following compromises exist:
2362 a) sub in $mypackage::sub may be highlighted.
2363 b) -z in [a-z] may be highlighted.
2364 c) if your regexp contains a keyword (like \"s\"), it may be highlighted.
2367 Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove
2368 `car' before `imenu-choose-buffer-index' in `imenu'.
2369 `imenu-add-to-menubar' in 20.2 is broken.
2370 A lot of things on XEmacs may be broken too, judging by bug reports I
2371 receive. Note that some releases of XEmacs are better than the others
2372 as far as bugs reports I see are concerned.")
2374 (defvar cperl-praise 'please-ignore-this-line
2375 "Advantages of CPerl mode.
2377 0) It uses the newest `syntax-table' property ;-);
2379 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
2380 mode - but the latter number may have improved too in last years) even
2381 with old Emaxen which do not support `syntax-table' property.
2383 When using `syntax-table' property for syntax assist hints, it should
2384 handle 99.995% of lines correct - or somesuch. It automatically
2385 updates syntax assist hints when you edit your script.
2387 2) It is generally believed to be \"the most user-friendly Emacs
2388 package\" whatever it may mean (I doubt that the people who say similar
2389 things tried _all_ the rest of Emacs ;-), but this was not a lonely
2392 3) Everything is customizable, one-by-one or in a big sweep;
2394 4) It has many easily-accessable \"tools\":
2395 a) Can run program, check syntax, start debugger;
2396 b) Can lineup vertically \"middles\" of rows, like `=' in
2399 c) Can insert spaces where this impoves readability (in one
2400 interactive sweep over the buffer);
2401 d) Has support for imenu, including:
2402 1) Separate unordered list of \"interesting places\";
2403 2) Separate TOC of POD sections;
2404 3) Separate list of packages;
2405 4) Hierarchical view of methods in (sub)packages;
2406 5) and functions (by the full name - with package);
2407 e) Has an interface to INFO docs for Perl; The interface is
2408 very flexible, including shrink-wrapping of
2409 documentation buffer/frame;
2410 f) Has a builtin list of one-line explanations for perl constructs.
2411 g) Can show these explanations if you stay long enough at the
2412 corresponding place (or on demand);
2413 h) Has an enhanced fontification (using 3 or 4 additional faces
2414 comparing to font-lock - basically, different
2415 namespaces in Perl have different colors);
2416 i) Can construct TAGS basing on its knowledge of Perl syntax,
2417 the standard menu has 6 different way to generate
2418 TAGS (if \"by directory\", .xs files - with C-language
2419 bindings - are included in the scan);
2420 j) Can build a hierarchical view of classes (via imenu) basing
2421 on generated TAGS file;
2422 k) Has electric parentheses, electric newlines, uses Abbrev
2423 for electric logical constructs
2425 with different styles of expansion (context sensitive
2426 to be not so bothering). Electric parentheses behave
2427 \"as they should\" in a presence of a visible region.
2428 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
2434 n) Highlights (by user-choice) either 3-delimiters constructs
2435 (such as tr/a/b/), or regular expressions and `y/tr';
2436 o) Highlights trailing whitespace;
2437 p) Is able to manipulate Perl Regular Expressions to ease
2438 conversion to a more readable form.
2439 q) Can ispell POD sections and HERE-DOCs.
2440 r) Understands comments and character classes inside regular
2441 expressions; can find matching () and [] in a regular expression.
2442 s) Allows indentation of //x-style regular expressions;
2443 t) Highlights different symbols in regular expressions according
2444 to their function; much less problems with backslashitis;
2445 u) Allows to find regular expressions which contain interpolated parts.
2447 5) The indentation engine was very smart, but most of tricks may be
2448 not needed anymore with the support for `syntax-table' property. Has
2449 progress indicator for indentation (with `imenu' loaded).
2451 6) Indent-region improves inline-comments as well; also corrects
2452 whitespace *inside* the conditional/loop constructs.
2454 7) Fill-paragraph correctly handles multi-line comments;
2456 8) Can switch to different indentation styles by one command, and restore
2457 the settings present before the switch.
2459 9) When doing indentation of control constructs, may correct
2460 line-breaks/spacing between elements of the construct.
2462 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
2463 capable syntax engines).
2465 11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
2468 (defvar cperl-speed 'please-ignore-this-line
2469 "This is an incomplete compendium of what is available in other parts
2470 of CPerl documentation. (Please inform me if I skept anything.)
2472 There is a perception that CPerl is slower than alternatives. This part
2473 of documentation is designed to overcome this misconception.
2475 *By default* CPerl tries to enable the most comfortable settings.
2476 From most points of view, correctly working package is infinitely more
2477 comfortable than a non-correctly working one, thus by default CPerl
2478 prefers correctness over speed. Below is the guide how to change
2479 settings if your preferences are different.
2481 A) Speed of loading the file. When loading file, CPerl may perform a
2482 scan which indicates places which cannot be parsed by primitive Emacs
2483 syntax-parsing routines, and marks them up so that either
2485 A1) CPerl may work around these deficiencies (for big chunks, mostly
2486 PODs and HERE-documents), or
2487 A2) On capable Emaxen CPerl will use improved syntax-handlings
2488 which reads mark-up hints directly.
2490 The scan in case A2 is much more comprehensive, thus may be slower.
2492 User can disable syntax-engine-helping scan of A2 by setting
2493 `cperl-use-syntax-table-text-property'
2494 variable to nil (if it is set to t).
2496 One can disable the scan altogether (both A1 and A2) by setting
2497 `cperl-pod-here-scan'
2500 B) Speed of editing operations.
2502 One can add a (minor) speedup to editing operations by setting
2503 `cperl-use-syntax-table-text-property'
2504 variable to nil (if it is set to t). This will disable
2505 syntax-engine-helping scan, thus will make many more Perl
2506 constructs be wrongly recognized by CPerl, thus may lead to
2507 wrongly matched parentheses, wrong indentation, etc.
2509 One can unset `cperl-syntaxify-unwind'. This might speed up editing
2510 of, say, long POD sections.")
2512 (defvar cperl-tips-faces 'please-ignore-this-line
2513 "CPerl mode uses following faces for highlighting:
2515 `cperl-array-face' Array names
2516 `cperl-hash-face' Hash names
2517 `font-lock-comment-face' Comments, PODs and whatever is considered
2518 syntaxically to be not code
2519 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
2520 2-arg operators s/y/tr/ or of RExen,
2521 `font-lock-warning-face' Special-cased m// and s//foo/,
2522 `font-lock-function-name-face' _ as a target of a file tests, file tests,
2523 subroutine names at the moment of definition
2524 (except those conflicting with Perl operators),
2525 package names (when recognized), format names
2526 `font-lock-keyword-face' Control flow switch constructs, declarators
2527 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
2528 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
2529 literal parts and the terminator of formats
2530 and whatever is syntaxically considered
2532 `font-lock-type-face' Overridable keywords
2533 `font-lock-variable-name-face' Variable declarations, indirect array and
2534 hash names, POD headers/item names
2535 `cperl-invalid-face' Trailing whitespace
2537 Note that in several situations the highlighting tries to inform about
2538 possible confusion, such as different colors for function names in
2539 declarations depending on what they (do not) override, or special cases
2540 m// and s/// which do not do what one would expect them to do.
2542 Help with best setup of these faces for printout requested (for each of
2543 the faces: please specify bold, italic, underline, shadow and box.)
2545 In regular expressions (including character classes):
2546 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs
2547 `font-lock-constant-face': Delimiters
2548 `font-lock-warning-face' Special-cased m// and s//foo/,
2549 Mismatched closing delimiters, parens
2550 we couldn't match, misplaced quantifiers,
2551 unrecognized escape sequences
2552 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
2553 `font-lock-type-face' escape sequences with arguments (\\x \\23 \\p \\N)
2554 and others match-a-char escape sequences
2555 `font-lock-keyword-face' Capturing parens, and |
2556 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
2557 \"Range -\" in character classes
2558 `font-lock-builtin-face' \"Remaining\" 0-length constructs, multipliers
2559 ?+*{}, not-capturing parens, leading
2560 backslashes of escape sequences
2561 `font-lock-variable-name-face' Interpolated constructs, embedded code,
2562 POSIX classes (inside charclasses)
2563 `font-lock-comment-face' Embedded comments
2569 ;;; Portability stuff:
2571 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
2572 (` (define-key cperl-mode-map
2574 (` (if cperl-xemacs-p (, xemacs-key) (, emacs-key)))
2578 (defvar cperl-del-back-ch
2579 (car (append (where-is-internal 'delete-backward-char)
2580 (where-is-internal 'backward-delete-char-untabify)))
2581 "Character generated by key bound to `delete-backward-char'.")
2583 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
2584 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
2586 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
2589 ;; "Active regions" are on: use region only if active
2590 ;; "Active regions" are off: use region unconditionally
2591 (defun cperl-use-region-p ()
2592 (if zmacs-regions (mark) t)))
2593 (defun cperl-use-region-p ()
2594 (if transient-mark-mode mark-active t))
2595 (defun cperl-mark-active () mark-active))
2597 (defsubst cperl-enable-font-lock ()
2598 cperl-can-font-lock)
2600 (defun cperl-putback-char (c) ; Emacs 19
2601 (set 'unread-command-events (list c))) ; Avoid undefined warning
2603 (if (boundp 'unread-command-events)
2605 (defun cperl-putback-char (c) ; XEmacs >= 19.12
2606 (setq unread-command-events (list (eval '(character-to-event c))))))
2607 (defun cperl-putback-char (c) ; XEmacs <= 19.11
2608 (set 'unread-command-event (eval '(character-to-event c))))) ; Avoid warnings
2610 (or (fboundp 'uncomment-region)
2611 (defun uncomment-region (beg end)
2613 (comment-region beg end -1)))
2615 (defvar cperl-do-not-fontify
2616 (if (string< emacs-version "19.30")
2619 "Text property which inhibits refontification.")
2621 (defsubst cperl-put-do-not-fontify (from to &optional post)
2622 ;; If POST, do not do it with postponed fontification
2623 (if (and post cperl-syntaxify-by-font-lock)
2625 (put-text-property (max (point-min) (1- from))
2626 to cperl-do-not-fontify t)))
2628 (defcustom cperl-mode-hook nil
2629 "Hook run by CPerl mode."
2633 (defvar cperl-syntax-state nil)
2634 (defvar cperl-syntax-done-to nil)
2635 (defvar cperl-emacs-can-parse (> (length (save-excursion
2636 (parse-partial-sexp (point) (point)))) 9))
2638 ;; Make customization possible "in reverse"
2639 (defsubst cperl-val (symbol &optional default hairy)
2641 ((eq (symbol-value symbol) 'null) default)
2642 (cperl-hairy (or hairy t))
2643 (t (symbol-value symbol))))
2646 (defun cperl-make-indent (column &optional minimum keep)
2647 "Makes indent of the current line the requested amount.
2648 Unless KEEP, removes the old indentation. Works around a bug in ancient
2650 (let ((prop (get-text-property (point) 'syntax-type)))
2652 (delete-horizontal-space))
2653 (indent-to column minimum)
2654 ;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
2656 (> (current-column) 0)
2659 (or (get-text-property (point) 'syntax-type)
2660 (and (looking-at "\\=[ \t]")
2661 (put-text-property (point) (match-end 0)
2662 'syntax-type prop)))))))
2664 ;;; Probably it is too late to set these guys already, but it can help later:
2666 (and cperl-clobber-mode-lists
2667 (setq auto-mode-alist
2668 (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
2669 (and (boundp 'interpreter-mode-alist)
2670 (setq interpreter-mode-alist (append interpreter-mode-alist
2671 '(("miniperl" . perl-mode))))))
2672 (if (fboundp 'eval-when-compile)
2678 '(imenu easymenu etags timer man info))
2679 (if (fboundp 'ps-extend-face-list)
2680 (defmacro cperl-ps-extend-face-list (arg)
2681 (` (ps-extend-face-list (, arg))))
2682 (defmacro cperl-ps-extend-face-list (arg)
2683 (` (error "This version of Emacs has no `ps-extend-face-list'"))))
2684 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
2685 ;; macros instead of defsubsts don't work on Emacs, so we do the
2686 ;; expansion manually. Any other suggestions?
2687 (if cperl-can-font-lock
2688 (require 'font-lock))
2691 (defvar cperl-mode-abbrev-table nil
2692 "Abbrev table in use in CPerl mode buffers.")
2694 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
2696 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
2698 (if cperl-mode-map nil
2699 (setq cperl-mode-map (make-sparse-keymap))
2700 (cperl-define-key "{" 'cperl-electric-lbrace)
2701 (cperl-define-key "[" 'cperl-electric-paren)
2702 (cperl-define-key "(" 'cperl-electric-paren)
2703 (cperl-define-key "<" 'cperl-electric-paren)
2704 (cperl-define-key "}" 'cperl-electric-brace)
2705 (cperl-define-key "]" 'cperl-electric-rparen)
2706 (cperl-define-key ")" 'cperl-electric-rparen)
2707 (cperl-define-key ";" 'cperl-electric-semi)
2708 (cperl-define-key ":" 'cperl-electric-terminator)
2709 (cperl-define-key "\C-j" 'newline-and-indent)
2710 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
2711 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
2712 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
2713 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
2714 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
2715 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
2716 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
2717 (cperl-define-key "\C-c\C-b" 'cperl-find-bad-style)
2718 (cperl-define-key "\C-c\C-p" 'cperl-pod-spell)
2719 (cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell)
2720 (cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc)
2721 (cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx)
2722 (cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0)
2723 (cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1)
2724 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
2725 (cperl-define-key "\C-c\C-hp" 'cperl-perldoc)
2726 (cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point)
2727 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
2728 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
2730 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
2731 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
2732 ;; XEmacs change: bind cperl-electric-delete to 'delete
2735 (cperl-define-key 'backspace 'cperl-electric-backspace)
2736 (cperl-define-key 'delete 'cperl-electric-delete))
2737 (cperl-define-key "\177" 'cperl-electric-backspace))
2738 (cperl-define-key "\t" 'cperl-indent-command)
2739 ;; don't clobber the backspace binding:
2740 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
2741 [(control c) (control h) F])
2742 (if (cperl-val 'cperl-clobber-lisp-bindings)
2744 (cperl-define-key "\C-hf"
2745 ;;(concat (char-to-string help-char) "f") ; does not work
2746 'cperl-info-on-command
2748 (cperl-define-key "\C-hv"
2749 ;;(concat (char-to-string help-char) "v") ; does not work
2752 (cperl-define-key "\C-c\C-hf"
2753 ;;(concat (char-to-string help-char) "f") ; does not work
2754 (key-binding "\C-hf")
2755 [(control c) (control h) f])
2756 (cperl-define-key "\C-c\C-hv"
2757 ;;(concat (char-to-string help-char) "v") ; does not work
2758 (key-binding "\C-hv")
2759 [(control c) (control h) v]))
2760 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
2761 [(control c) (control h) f])
2762 (cperl-define-key "\C-c\C-hv"
2763 ;;(concat (char-to-string help-char) "v") ; does not work
2765 [(control c) (control h) v]))
2766 (if (and cperl-xemacs-p
2767 (<= emacs-minor-version 11) (<= emacs-major-version 19))
2769 ;; substitute-key-definition is usefulness-deenhanced...
2770 ;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
2771 (cperl-define-key "\e;" 'cperl-indent-for-comment)
2772 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
2773 (or (boundp 'fill-paragraph-function)
2774 (substitute-key-definition
2775 'fill-paragraph 'cperl-fill-paragraph
2776 cperl-mode-map global-map))
2777 (substitute-key-definition
2778 'indent-sexp 'cperl-indent-exp
2779 cperl-mode-map global-map)
2780 (substitute-key-definition
2781 'indent-region 'cperl-indent-region
2782 cperl-mode-map global-map)
2783 (substitute-key-definition
2784 'indent-for-comment 'cperl-indent-for-comment
2785 cperl-mode-map global-map)))
2788 (defvar cperl-lazy-installed)
2789 (defvar cperl-old-style nil)
2794 cperl-menu cperl-mode-map "Menu for CPerl mode"
2796 ["Beginning of function" beginning-of-defun t]
2797 ["End of function" end-of-defun t]
2798 ["Mark function" mark-defun t]
2799 ["Indent expression" cperl-indent-exp t]
2800 ["Fill paragraph/comment" cperl-fill-paragraph t]
2802 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
2803 ["Invert if/unless/while etc" cperl-invert-if-unless t]
2805 ["Beautify" cperl-beautify-regexp
2806 cperl-use-syntax-table-text-property]
2807 ["Beautify one level deep" (cperl-beautify-regexp 1)
2808 cperl-use-syntax-table-text-property]
2809 ["Beautify a group" cperl-beautify-level
2810 cperl-use-syntax-table-text-property]
2811 ["Beautify a group one level deep" (cperl-beautify-level 1)
2812 cperl-use-syntax-table-text-property]
2813 ["Contract a group" cperl-contract-level
2814 cperl-use-syntax-table-text-property]
2815 ["Contract groups" cperl-contract-levels
2816 cperl-use-syntax-table-text-property]
2818 ["Find next interpolated" cperl-next-interpolated-REx
2819 (next-single-property-change (point-min) 'REx-interpolated)]
2820 ["Find next interpolated (no //o)"
2821 cperl-next-interpolated-REx-0
2822 (or (text-property-any (point-min) (point-max) 'REx-interpolated t)
2823 (text-property-any (point-min) (point-max) 'REx-interpolated 1))]
2824 ["Find next interpolated (neither //o nor whole-REx)"
2825 cperl-next-interpolated-REx-1
2826 (text-property-any (point-min) (point-max) 'REx-interpolated t)])
2827 ["Insert spaces if needed to fix style" cperl-find-bad-style t]
2828 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
2830 ["Indent region" cperl-indent-region (cperl-use-region-p)]
2831 ["Comment region" cperl-comment-region (cperl-use-region-p)]
2832 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
2834 ["Run" mode-compile (fboundp 'mode-compile)]
2835 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
2836 (get-buffer "*compilation*"))]
2837 ["Next error" next-error (get-buffer "*compilation*")]
2838 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
2840 ["Debugger" cperl-db t]
2843 ["Imenu" imenu (fboundp 'imenu)]
2844 ["Imenu on Perl Info" cperl-imenu-on-info (featurep 'imenu)]
2846 ["Ispell PODs" cperl-pod-spell
2847 ;; Better not to update syntaxification here:
2848 ;; debugging syntaxificatio can be broken by this???
2850 (get-text-property (point-min) 'in-pod)
2852 (and cperl-syntaxify-for-menu
2853 (cperl-update-syntaxification (point-max) (point-max)))
2854 (next-single-property-change (point-min) 'in-pod nil (point-max)))
2856 ["Ispell HERE-DOCs" cperl-here-doc-spell
2858 (and cperl-syntaxify-for-menu
2859 (cperl-update-syntaxification (point-max) (point-max)))
2860 (next-single-property-change (point-min) 'here-doc-group nil (point-max)))
2862 ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
2863 (eq 'here-doc (progn
2864 (and cperl-syntaxify-for-menu
2865 (cperl-update-syntaxification (point) (point)))
2866 (get-text-property (point) 'syntax-type)))]
2867 ["Select this HERE-DOC or POD section"
2868 cperl-select-this-pod-or-here-doc
2870 (and cperl-syntaxify-for-menu
2871 (cperl-update-syntaxification (point) (point)))
2872 (get-text-property (point) 'syntax-type))
2875 ["CPerl pretty print (exprmntl)" cperl-ps-print
2876 (fboundp 'ps-extend-face-list)]
2878 ["Syntaxify region" cperl-find-pods-heres-region
2879 (cperl-use-region-p)]
2880 ["Profile syntaxification" cperl-time-fontification t]
2881 ["Debug errors in delayed fontification" cperl-emulate-lazy-lock t]
2882 ["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t]
2883 ["Debug backtrace on syntactic scan (BEWARE!!!)"
2884 (cperl-toggle-set-debug-unwind nil t) t]
2886 ["Report indentation context"
2887 (message "%s" (cperl-sniff-for-indent)) t]
2889 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
2890 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
2892 ;;; ["Create tags for current file" cperl-etags t]
2893 ;;; ["Add tags for current file" (cperl-etags t) t]
2894 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
2895 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
2896 ;;; ["Create tags for Perl files in (sub)directories"
2897 ;;; (cperl-etags nil 'recursive) t]
2898 ;;; ["Add tags for Perl files in (sub)directories"
2899 ;;; (cperl-etags t 'recursive) t])
2900 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
2901 ["Create tags for current file" (cperl-write-tags nil t) t]
2902 ["Add tags for current file" (cperl-write-tags) t]
2903 ["Create tags for Perl files in directory"
2904 (cperl-write-tags nil t nil t) t]
2905 ["Add tags for Perl files in directory"
2906 (cperl-write-tags nil nil nil t) t]
2907 ["Create tags for Perl files in (sub)directories"
2908 (cperl-write-tags nil t t t) t]
2909 ["Add tags for Perl files in (sub)directories"
2910 (cperl-write-tags nil nil t t) t]))
2912 ["Define word at point" imenu-go-find-at-position
2913 (fboundp 'imenu-go-find-at-position)]
2914 ["Help on function" cperl-info-on-command t]
2915 ["Help on function at point" cperl-info-on-current-command t]
2916 ["Help on symbol at point" cperl-get-help t]
2917 ["Perldoc" cperl-perldoc t]
2918 ["Perldoc on word at point" cperl-perldoc-at-point t]
2919 ["View manpage of POD in this file" cperl-build-manpage t]
2920 ["Auto-help on" cperl-lazy-install
2921 (and (fboundp 'run-with-idle-timer)
2922 (not cperl-lazy-installed))]
2923 ["Auto-help off" cperl-lazy-unstall
2924 (and (fboundp 'run-with-idle-timer)
2925 cperl-lazy-installed)])
2927 ["Auto newline" cperl-toggle-auto-newline t]
2928 ["Electric parens" cperl-toggle-electric t]
2929 ["Electric keywords" cperl-toggle-abbrev t]
2930 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
2931 ["Auto-help on Perl constructs" cperl-toggle-autohelp t]
2932 ["Auto fill" auto-fill-mode t])
2934 ["CPerl" (cperl-set-style "CPerl") t]
2935 ["PerlStyle" (cperl-set-style "PerlStyle") t]
2936 ["GNU" (cperl-set-style "GNU") t]
2937 ["C++" (cperl-set-style "C++") t]
2938 ["K&R" (cperl-set-style "K&R") t]
2939 ["BSD" (cperl-set-style "BSD") t]
2940 ["Whitesmith" (cperl-set-style "Whitesmith") t]
2941 ["Memorize Current" (cperl-set-style "Current") t]
2942 ["Memorized" (cperl-set-style-back) cperl-old-style])
2944 ["Tips" (describe-variable 'cperl-tips) t]
2945 ["Problems" (describe-variable 'cperl-problems) t]
2946 ["Non-problems" (describe-variable 'cperl-non-problems) t]
2947 ["Speed" (describe-variable 'cperl-speed) t]
2948 ["Praise" (describe-variable 'cperl-praise) t]
2949 ["Faces" (describe-variable 'cperl-tips-faces) t]
2950 ["Show Faces" (cperl-insert-faces-example) t]
2951 ["CPerl mode" (describe-function 'cperl-mode) t]
2953 (message "The version of master-file for this CPerl is %s"
2954 cperl-version) t]))))
2957 (autoload 'c-macro-expand "cmacexp"
2958 "Display the result of expanding all C macros occurring in the region.
2959 The expansion is entirely correct because it uses the C preprocessor."
2962 ;;; These two must be unwound, otherwise take exponential time
2963 (defconst cperl-maybe-white-and-comment-rex "[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
2964 "Regular expression to match optional whitespace with interpspersed comments.
2965 Should contain exactly one group.")
2967 ;;; This one is tricky to unwind; still very inefficient...
2968 (defconst cperl-white-and-comment-rex "\\([ \t\n]\\|#[^\n]*\n\\)+"
2969 "Regular expression to match whitespace with interpspersed comments.
2970 Should contain exactly one group.")
2973 ;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
2974 ;;; `cperl-outline-regexp', `defun-prompt-regexp'.
2975 ;;; Details of groups in this may be used in several functions; see comments
2976 ;;; near mentioned above variable(s)...
2977 ;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
2978 (defsubst cperl-after-sub-regexp (named attr) ; 9 groups without attr...
2979 "Match the text after `sub' in a subroutine declaration.
2980 If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
2981 of attributes (if present), or end of the name or prototype (whatever is
2983 (concat ; Assume n groups before this...
2984 "\\(" ; n+1=name-group
2985 cperl-white-and-comment-rex ; n+2=pre-name
2986 "\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
2987 "\\)" ; END n+1=name-group
2989 "\\(" ; n+4=proto-group
2990 cperl-maybe-white-and-comment-rex ; n+5=pre-proto
2991 "\\(([^()]*)\\)" ; n+6=prototype
2992 "\\)?" ; END n+4=proto-group
2993 "\\(" ; n+7=attr-group
2994 cperl-maybe-white-and-comment-rex ; n+8=pre-attr
2995 "\\(" ; n+9=start-attr
2999 cperl-maybe-white-and-comment-rex ; whitespace-comments
3000 "\\(\\sw\\|_\\)+" ; attr-name
3001 ;; attr-arg (1 level of internal parens allowed!)
3002 "\\((\\(\\\\.\\|[^\\\\()]\\|([^\\\\()]*)\\)*)\\)?"
3003 "\\(" ; optional : (XXX allows trailing???)
3004 cperl-maybe-white-and-comment-rex ; whitespace-comments
3009 "\\)?" ; END n+6=proto-group
3012 ;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
3013 ;;; and `cperl-outline-level'.
3014 ;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 8=sub-name (+3)
3015 (defvar cperl-imenu--function-name-regexp-perl
3018 "\\([ \t]*package" ; 2 = package-group
3019 "\\(" ; 3 = package-name-group
3020 cperl-white-and-comment-rex ; 4 = pre-package-name
3021 "\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
3024 (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
3025 cperl-maybe-white-and-comment-rex ; 15=pre-block
3027 "=head\\([1-4]\\)[ \t]+" ; 16=level
3028 "\\([^\n]+\\)$" ; 17=text
3031 (defvar cperl-outline-regexp
3032 (concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
3034 (defvar cperl-mode-syntax-table nil
3035 "Syntax table in use in CPerl mode buffers.")
3037 (defvar cperl-string-syntax-table nil
3038 "Syntax table in use in CPerl mode string-like chunks.")
3040 (defsubst cperl-1- (p)
3041 (max (point-min) (1- p)))
3043 (defsubst cperl-1+ (p)
3044 (min (point-max) (1+ p)))
3046 (if cperl-mode-syntax-table
3048 (setq cperl-mode-syntax-table (make-syntax-table))
3049 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
3050 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
3051 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
3052 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
3053 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
3054 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
3055 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
3056 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
3057 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
3058 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
3059 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
3060 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
3061 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
3062 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
3063 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
3064 (if cperl-under-as-char
3065 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
3066 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
3067 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
3068 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
3069 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
3070 (modify-syntax-entry ?\{ "." cperl-string-syntax-table)
3071 (modify-syntax-entry ?\} "." cperl-string-syntax-table)
3072 (modify-syntax-entry ?\" "." cperl-string-syntax-table)
3073 (modify-syntax-entry ?' "." cperl-string-syntax-table)
3074 (modify-syntax-entry ?` "." cperl-string-syntax-table)
3075 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment )
3079 ;; provide an alias for working with emacs 19. the perl-mode that comes
3080 ;; with it is really bad, and this lets us seamlessly replace it.
3082 (fset 'perl-mode 'cperl-mode)
3083 (defvar cperl-faces-init nil)
3085 (defvar cperl-msb-fixed nil)
3086 (defvar font-lock-syntactic-keywords)
3087 (defvar perl-font-lock-keywords)
3088 (defvar perl-font-lock-keywords-1)
3089 (defvar perl-font-lock-keywords-2)
3090 (defvar outline-level)
3091 (if (fboundp 'defvaralias)
3092 (let ((f 'defvaralias)) ; Some functions deduce stuff from the mode name...
3093 (funcall f 'cperl-font-lock-keywords 'perl-font-lock-keywords)
3094 (funcall f 'cperl-font-lock-keywords-1 'perl-font-lock-keywords-1)
3095 (funcall f 'cperl-font-lock-keywords-2 'perl-font-lock-keywords-2)))
3097 (defvar cperl-use-major-mode 'perl-mode)
3098 (defvar cperl-font-lock-multiline-start nil)
3099 (defvar cperl-font-lock-multiline nil)
3100 (defvar cperl-compilation-error-regexp-alist nil)
3101 (defvar cperl-font-locking nil)
3104 (defun cperl-mode ()
3105 "Major mode for editing Perl code.
3106 Expression and list commands understand all C brackets.
3107 Tab indents for Perl code.
3108 Paragraphs are separated by blank lines only.
3109 Delete converts tabs to spaces as it moves back.
3111 Various characters in Perl almost always come in pairs: {}, (), [],
3112 sometimes <>. When the user types the first, she gets the second as
3113 well, with optional special formatting done on {}. (Disabled by
3114 default.) You can always quote (with \\[quoted-insert]) the left
3115 \"paren\" to avoid the expansion. The processing of < is special,
3116 since most the time you mean \"less\". CPerl mode tries to guess
3117 whether you want to type pair <>, and inserts is if it
3118 appropriate. You can set `cperl-electric-parens-string' to the string that
3119 contains the parenths from the above list you want to be electrical.
3120 Electricity of parenths is controlled by `cperl-electric-parens'.
3121 You may also set `cperl-electric-parens-mark' to have electric parens
3122 look for active mark and \"embrace\" a region if possible.'
3124 CPerl mode provides expansion of the Perl control constructs:
3126 if, else, elsif, unless, while, until, continue, do,
3127 for, foreach, formy and foreachmy.
3129 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
3131 The user types the keyword immediately followed by a space, which
3132 causes the construct to be expanded, and the point is positioned where
3133 she is most likely to want to be. eg. when the user types a space
3134 following \"if\" the following appears in the buffer: if () { or if ()
3135 } { } and the cursor is between the parentheses. The user can then
3136 type some boolean expression within the parens. Having done that,
3137 typing \\[cperl-linefeed] places you - appropriately indented - on a
3138 new line between the braces (if you typed \\[cperl-linefeed] in a POD
3139 directive line, then appropriate number of new lines is inserted).
3141 If CPerl decides that you want to insert \"English\" style construct like
3145 it will not do any expansion. See also help on variable
3146 `cperl-extra-newline-before-brace'. (Note that one can switch the
3147 help message on expansion by setting `cperl-message-electric-keyword'
3150 \\[cperl-linefeed] is a convenience replacement for typing carriage
3151 return. It places you in the next line with proper indentation, or if
3152 you type it inside the inline block of control construct, like
3154 foreach (@lines) {print; print}
3156 and you are on a boundary of a statement inside braces, it will
3157 transform the construct into a multiline and will place you into an
3158 appropriately indented blank line. If you need a usual
3159 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
3160 see documentation on `cperl-electric-linefeed'.
3162 Use \\[cperl-invert-if-unless] to change a construction of the form
3172 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
3173 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
3174 on electric space between $ and {, `cperl-electric-parens-string' is
3175 the string that contains parentheses that should be electric in CPerl
3176 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
3177 setting `cperl-electric-keywords' enables electric expansion of
3178 control structures in CPerl. `cperl-electric-linefeed' governs which
3179 one of two linefeed behavior is preferable. You can enable all these
3180 options simultaneously (recommended mode of use) by setting
3181 `cperl-hairy' to t. In this case you can switch separate options off
3182 by setting them to `null'. Note that one may undo the extra
3183 whitespace inserted by semis and braces in `auto-newline'-mode by
3184 consequent \\[cperl-electric-backspace].
3186 If your site has perl5 documentation in info format, you can use commands
3187 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
3188 These keys run commands `cperl-info-on-current-command' and
3189 `cperl-info-on-command', which one is which is controlled by variable
3190 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
3191 \(in turn affected by `cperl-hairy').
3193 Even if you have no info-format documentation, short one-liner-style
3194 help is available on \\[cperl-get-help], and one can run perldoc or
3197 It is possible to show this help automatically after some idle time.
3198 This is regulated by variable `cperl-lazy-help-time'. Default with
3199 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
3200 secs idle time . It is also possible to switch this on/off from the
3201 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
3203 Use \\[cperl-lineup] to vertically lineup some construction - put the
3204 beginning of the region at the start of construction, and make region
3205 span the needed amount of lines.
3207 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
3208 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
3209 here-docs sections. With capable Emaxen results of scan are used
3210 for indentation too, otherwise they are used for highlighting only.
3212 Variables controlling indentation style:
3213 `cperl-tab-always-indent'
3214 Non-nil means TAB in CPerl mode should always reindent the current line,
3215 regardless of where in the line point is when the TAB command is used.
3216 `cperl-indent-left-aligned-comments'
3217 Non-nil means that the comment starting in leftmost column should indent.
3218 `cperl-auto-newline'
3219 Non-nil means automatically newline before and after braces,
3220 and after colons and semicolons, inserted in Perl code. The following
3221 \\[cperl-electric-backspace] will remove the inserted whitespace.
3222 Insertion after colons requires both this variable and
3223 `cperl-auto-newline-after-colon' set.
3224 `cperl-auto-newline-after-colon'
3225 Non-nil means automatically newline even after colons.
3226 Subject to `cperl-auto-newline' setting.
3227 `cperl-indent-level'
3228 Indentation of Perl statements within surrounding block.
3229 The surrounding block's indentation is the indentation
3230 of the line on which the open-brace appears.
3231 `cperl-continued-statement-offset'
3232 Extra indentation given to a substatement, such as the
3233 then-clause of an if, or body of a while, or just a statement continuation.
3234 `cperl-continued-brace-offset'
3235 Extra indentation given to a brace that starts a substatement.
3236 This is in addition to `cperl-continued-statement-offset'.
3237 `cperl-brace-offset'
3238 Extra indentation for line if it starts with an open brace.
3239 `cperl-brace-imaginary-offset'
3240 An open brace following other text is treated as if it the line started
3241 this far to the right of the actual line indentation.
3242 `cperl-label-offset'
3243 Extra indentation for line that is a label.
3244 `cperl-min-label-indent'
3245 Minimal indentation for line that is a label.
3247 Settings for classic indent-styles: K&R BSD=C++ GNU PerlStyle=Whitesmith
3248 `cperl-indent-level' 5 4 2 4
3249 `cperl-brace-offset' 0 0 0 0
3250 `cperl-continued-brace-offset' -5 -4 0 0
3251 `cperl-label-offset' -5 -4 -2 -4
3252 `cperl-continued-statement-offset' 5 4 2 4
3254 CPerl knows several indentation styles, and may bulk set the
3255 corresponding variables. Use \\[cperl-set-style] to do this. Use
3256 \\[cperl-set-style-back] to restore the memorized preexisting values
3257 \(both available from menu). See examples in `cperl-style-examples'.
3259 Part of the indentation style is how different parts of if/elsif/else
3260 statements are broken into lines; in CPerl, this is reflected on how
3261 templates for these constructs are created (controlled by
3262 `cperl-extra-newline-before-brace'), and how reflow-logic should treat
3263 \"continuation\" blocks of else/elsif/continue, controlled by the same
3264 variable, and by `cperl-extra-newline-before-brace-multiline',
3265 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'.
3267 If `cperl-indent-level' is 0, the statement after opening brace in
3268 column 0 is indented on
3269 `cperl-brace-offset'+`cperl-continued-statement-offset'.
3271 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
3274 DO NOT FORGET to read micro-docs (available from `Perl' menu,
3275 or as help on variables `cperl-tips', `cperl-problems',
3276 `cperl-non-problems', `cperl-praise', `cperl-speed',
3277 `cperl-tips-faces')."
3279 (kill-all-local-variables)
3280 (use-local-map cperl-mode-map)
3281 (if (cperl-val 'cperl-electric-linefeed)
3283 (local-set-key "\C-J" 'cperl-linefeed)
3284 (local-set-key "\C-C\C-J" 'newline-and-indent)))
3286 (cperl-val 'cperl-clobber-lisp-bindings)
3287 (cperl-val 'cperl-info-on-command-no-prompt))
3289 ;; don't clobber the backspace binding:
3290 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
3291 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
3292 [(control c) (control h) f])))
3293 (setq major-mode cperl-use-major-mode)
3294 (setq mode-name "CPerl")
3295 (if (not cperl-mode-abbrev-table)
3296 (let ((prev-a-c abbrevs-changed))
3297 (define-abbrev-table 'cperl-mode-abbrev-table '(
3298 ("if" "if" cperl-electric-keyword 0)
3299 ("elsif" "elsif" cperl-electric-keyword 0)
3300 ("while" "while" cperl-electric-keyword 0)
3301 ("until" "until" cperl-electric-keyword 0)
3302 ("unless" "unless" cperl-electric-keyword 0)
3303 ("else" "else" cperl-electric-else 0)
3304 ("continue" "continue" cperl-electric-else 0)
3305 ("for" "for" cperl-electric-keyword 0)
3306 ("foreach" "foreach" cperl-electric-keyword 0)
3307 ("formy" "formy" cperl-electric-keyword 0)
3308 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
3309 ("do" "do" cperl-electric-keyword 0)
3310 ("=pod" "=pod" cperl-electric-pod 0)
3311 ("=over" "=over" cperl-electric-pod 0)
3312 ("=head1" "=head1" cperl-electric-pod 0)
3313 ("=head2" "=head2" cperl-electric-pod 0)
3314 ("pod" "pod" cperl-electric-pod 0)
3315 ("over" "over" cperl-electric-pod 0)
3316 ("head1" "head1" cperl-electric-pod 0)
3317 ("head2" "head2" cperl-electric-pod 0)))
3318 (setq abbrevs-changed prev-a-c)))
3319 (setq local-abbrev-table cperl-mode-abbrev-table)
3320 (if (cperl-val 'cperl-electric-keywords)
3322 (set-syntax-table cperl-mode-syntax-table)
3323 ;; Until Emacs is multi-threaded, we do not actually need it local:
3324 (make-local-variable 'cperl-font-lock-multiline-start)
3325 (make-local-variable 'cperl-font-locking)
3326 (make-local-variable 'outline-regexp)
3327 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
3328 (setq outline-regexp cperl-outline-regexp)
3329 (make-local-variable 'outline-level)
3330 (setq outline-level 'cperl-outline-level)
3331 (make-local-variable 'paragraph-start)
3332 (setq paragraph-start (concat "^$\\|" page-delimiter))
3333 (make-local-variable 'paragraph-separate)
3334 (setq paragraph-separate paragraph-start)
3335 (make-local-variable 'paragraph-ignore-fill-prefix)
3336 (setq paragraph-ignore-fill-prefix t)
3339 (make-local-variable 'paren-backwards-message)
3340 (set 'paren-backwards-message t)))
3341 (make-local-variable 'indent-line-function)
3342 (setq indent-line-function 'cperl-indent-line)
3343 (make-local-variable 'require-final-newline)
3344 (setq require-final-newline t)
3345 (make-local-variable 'comment-start)
3346 (setq comment-start "# ")
3347 (make-local-variable 'comment-end)
3348 (setq comment-end "")
3349 (make-local-variable 'comment-column)
3350 (setq comment-column cperl-comment-column)
3351 (make-local-variable 'comment-start-skip)
3352 (setq comment-start-skip "#+ *")
3353 (make-local-variable 'defun-prompt-regexp)
3355 ;;; (cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
3356 ;;; cperl-maybe-white-and-comment-rex ; 15=pre-block
3357 (setq defun-prompt-regexp
3358 (concat "[ \t]*\\(sub"
3359 (cperl-after-sub-regexp 'named 'attr-groups)
3361 "\\(BEGIN\\|CHECK\\|INIT\\|END\\|AUTOLOAD\\|DESTROY\\)"
3363 cperl-maybe-white-and-comment-rex))
3364 (make-local-variable 'comment-indent-function)
3365 (setq comment-indent-function 'cperl-comment-indent)
3366 (and (boundp 'fill-paragraph-function)
3368 (make-local-variable 'fill-paragraph-function)
3369 (set 'fill-paragraph-function 'cperl-fill-paragraph)))
3370 (make-local-variable 'parse-sexp-ignore-comments)
3371 (setq parse-sexp-ignore-comments t)
3372 (make-local-variable 'indent-region-function)
3373 (setq indent-region-function 'cperl-indent-region)
3374 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
3375 (make-local-variable 'imenu-create-index-function)
3376 (setq imenu-create-index-function
3377 (function cperl-imenu--create-perl-index))
3378 (make-local-variable 'imenu-sort-function)
3379 (setq imenu-sort-function nil)
3380 (make-local-variable 'vc-rcs-header)
3381 (set 'vc-rcs-header cperl-vc-rcs-header)
3382 (make-local-variable 'vc-sccs-header)
3383 (set 'vc-sccs-header cperl-vc-sccs-header)
3384 ;; This one is obsolete...
3385 (make-local-variable 'vc-header-alist)
3386 (set 'vc-header-alist (or cperl-vc-header-alist ; Avoid warning
3387 (` ((SCCS (, (car cperl-vc-sccs-header)))
3388 (RCS (, (car cperl-vc-rcs-header)))))))
3389 (cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x, emacs22
3390 (make-local-variable 'compilation-error-regexp-alist-alist)
3391 (set 'compilation-error-regexp-alist-alist
3392 (cons (cons 'cperl cperl-compilation-error-regexp-alist)
3393 (symbol-value 'compilation-error-regexp-alist-alist)))
3394 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
3395 (let ((f 'compilation-build-compilation-error-regexp-alist))
3396 (funcall f)) ; xemacs 20.x
3397 (make-local-variable 'compilation-error-regexp-alist) ; emacs22
3398 (push 'cperl compilation-error-regexp-alist)))
3399 ((boundp 'compilation-error-regexp-alist);; xmeacs 19.x
3400 (make-local-variable 'compilation-error-regexp-alist)
3401 (set 'compilation-error-regexp-alist
3402 (cons cperl-compilation-error-regexp-alist
3403 (symbol-value 'compilation-error-regexp-alist)))))
3404 (make-local-variable 'font-lock-defaults)
3405 (setq font-lock-defaults
3407 ((string< emacs-version "19.30")
3408 '(perl-font-lock-keywords-2 nil nil ((?_ . "w"))))
3409 ((string< emacs-version "19.33") ; Which one to use?
3410 '((perl-font-lock-keywords
3411 perl-font-lock-keywords-1
3412 perl-font-lock-keywords-2) nil nil ((?_ . "w"))))
3414 '((cperl-load-font-lock-keywords
3415 cperl-load-font-lock-keywords-1
3416 cperl-load-font-lock-keywords-2) nil nil ((?_ . "w"))))))
3417 (make-local-variable 'cperl-syntax-state)
3418 (setq cperl-syntax-state nil) ; reset syntaxification cache
3419 (if cperl-use-syntax-table-text-property
3421 (make-local-variable 'parse-sexp-lookup-properties)
3422 ;; Do not introduce variable if not needed, we check it!
3423 (set 'parse-sexp-lookup-properties t)
3424 ;; Fix broken font-lock:
3425 (or (boundp 'font-lock-unfontify-region-function)
3426 (set 'font-lock-unfontify-region-function
3427 'font-lock-default-unfontify-region))
3428 (unless cperl-xemacs-p ; Our: just a plug for wrong font-lock
3429 (make-local-variable 'font-lock-unfontify-region-function)
3430 (set 'font-lock-unfontify-region-function ; not present with old Emacs
3431 'cperl-font-lock-unfontify-region-function))
3432 (make-local-variable 'cperl-syntax-done-to)
3433 (setq cperl-syntax-done-to nil) ; reset syntaxification cache
3434 ;; Another bug: unless font-lock-syntactic-keywords, font-lock
3435 ;; ignores syntax-table text-property. (t) is a hack
3436 ;; to make font-lock think that font-lock-syntactic-keywords
3438 (make-local-variable 'font-lock-syntactic-keywords)
3439 (setq font-lock-syntactic-keywords
3440 (if cperl-syntaxify-by-font-lock
3441 '(t (cperl-fontify-syntaxically))
3443 (if (boundp 'font-lock-multiline) ; Newer font-lock; use its facilities
3445 (setq cperl-font-lock-multiline t) ; Not localized...
3446 (set (make-local-variable 'font-lock-multiline) t))
3447 (make-local-variable 'font-lock-fontify-region-function)
3448 (set 'font-lock-fontify-region-function ; not present with old Emacs
3449 'cperl-font-lock-fontify-region-function))
3450 (make-local-variable 'font-lock-fontify-region-function)
3451 (set 'font-lock-fontify-region-function ; not present with old Emacs
3452 'cperl-font-lock-fontify-region-function)
3453 (make-local-variable 'cperl-old-style)
3454 (if (boundp 'normal-auto-fill-function) ; 19.33 and later
3455 (set (make-local-variable 'normal-auto-fill-function)
3456 'cperl-do-auto-fill) ; RMS has it as #'cperl-do-auto-fill ???
3457 (or (fboundp 'cperl-old-auto-fill-mode)
3459 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
3460 (defun auto-fill-mode (&optional arg)
3462 (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
3463 (and auto-fill-function (memq major-mode '(perl-mode cperl-mode))
3464 (setq auto-fill-function 'cperl-do-auto-fill))))))
3465 (if (cperl-enable-font-lock)
3466 (if (cperl-val 'cperl-font-lock)
3467 (progn (or cperl-faces-init (cperl-init-faces))
3468 (font-lock-mode 1))))
3469 (set (make-local-variable 'facemenu-add-face-function)
3470 'cperl-facemenu-add-face-function) ; XXXX What this guy is for???
3471 (and (boundp 'msb-menu-cond)
3472 (not cperl-msb-fixed)
3474 (if (featurep 'easymenu)
3475 (easy-menu-add cperl-menu)) ; A NOP in RMS Emacs.
3476 (run-hooks 'cperl-mode-hook)
3477 (if cperl-hook-after-change
3479 (make-local-hook 'after-change-functions)
3480 (add-hook 'after-change-functions 'cperl-after-change-function nil t)))
3481 ;; After hooks since fontification will break this
3482 (if cperl-pod-here-scan
3483 (or cperl-syntaxify-by-font-lock
3484 (progn (or cperl-faces-init (cperl-init-faces-weak))
3485 (cperl-find-pods-heres)))))
3487 (defun cperl-insert-faces-example ()
3488 "Insert example \"CODE\" demonstrating CPerl facification at beginning-of-line."
3490 (beginning-of-line))
3492 "my $o = sprintf grep //, <<EOP, $ENV{$_} or warn $$msg[0] for @ARGV; #junk
3495 -f _ or -f $_ or die 'What?';
3497 /\\3333\\xFg\\x{FFF}a\\ppp\\PPP\\qqq\\C\\99f(?{ foo })(??{ foo })/;
3498 /a{4,5}\\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
3499 /(?<=foo)(?<!bar)(x\")(?:$ab|\\$\\/)$|\\\\\\b\\x888\\776\\[\\:$/xxx;
3500 m?(\\?\\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
3501 m$(^ab[c]\\$)$ + m+(^ab[c]\\$\\+)+ + m](^ab[c\\]$|.+)] + m)(^ab[c]$|.+\\));
3504 m^a[\\^b-e\\xFF]c^ + m.a[^b]\\.c.; # OK
3505 m^a[\\^-b-\\e--[\\--\\xFF\\c[\\cX-\\0333-\\0555-\\N{name}\\pp--\\P{prop}--\\\\\\05555]^;
3506 m^a[[:alpha:]-[:alpha:]-a-[:alpha:][-aa-[[:alpha:]-b-[:alpha:]-[:alpha:]]^;
3507 m^a[x\\\\[:alpha:]-\\\\[:alpha:]-a-\\\\[:alpha:][-aa-[[:alpha:]-b-\\\\[:alpha:]-\\\\[:alpha:]]^;
3508 m^a[x\\\\[:alpha:][:alpha:]\\\\[:alpha:][-aa-[[:alpha:]\\\\[:alpha:][:alpha:]]^;
3511 ;; Fix for perldb - make default reasonable
3515 (perldb (read-from-minibuffer "Run perldb (like this): "
3516 (if (consp gud-perldb-history)
3517 (car gud-perldb-history)
3518 (concat "perl " ;;(file-name-nondirectory
3522 (buffer-file-name)))
3524 '(gud-perldb-history . 1))))
3526 (defun cperl-msb-fix ()
3527 ;; Adds perl files to msb menu, supposes that msb is already loaded
3528 (setq cperl-msb-fixed t)
3529 (let* ((l (length msb-menu-cond))
3530 (last (nth (1- l) msb-menu-cond))
3531 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
3532 (handle (1- (nth 1 last))))
3533 (setcdr precdr (list
3535 '(memq major-mode '(cperl-mode perl-mode))
3540 ;; This is used by indent-for-comment
3541 ;; to decide how much to indent a comment in CPerl code
3542 ;; based on its context. Do fallback if comment is found wrong.
3544 (defvar cperl-wrong-comment)
3545 (defvar cperl-st-cfence '(14)) ; Comment-fence
3546 (defvar cperl-st-sfence '(15)) ; String-fence
3547 (defvar cperl-st-punct '(1))
3548 (defvar cperl-st-word '(2))
3549 (defvar cperl-st-bra '(4 . ?\>))
3550 (defvar cperl-st-ket '(5 . ?\<))
3553 (defun cperl-comment-indent () ; called at point at supposed comment
3554 (let ((p (point)) (c (current-column)) was phony)
3555 (if (and (not cperl-indent-comment-at-column-0)
3557 0 ; Existing comment at bol stays there.
3558 ;; Wrong comment found
3560 (setq was (cperl-to-comment-or-eol)
3561 phony (eq (get-text-property (point) 'syntax-table)
3564 (progn ; Too naive???
3565 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
3566 (if (eq (preceding-char) ?\#)
3569 (if (= (point) p) ; Our caller found a correct place
3571 (skip-chars-backward " \t")
3572 (setq was (current-column))
3575 (max (1+ was) ; Else indent at comment column
3577 ;; No, the caller found a random place; we need to edit ourselves
3579 (insert comment-start)
3580 (backward-char (length comment-start)))
3581 (setq cperl-wrong-comment t)
3582 (cperl-make-indent comment-column 1) ; Indent min 1
3585 ;;;(defun cperl-comment-indent-fallback ()
3586 ;;; "Is called if the standard comment-search procedure fails.
3587 ;;;Point is at start of real comment."
3588 ;;; (let ((c (current-column)) target cnt prevc)
3589 ;;; (if (= c comment-column) nil
3590 ;;; (setq cnt (skip-chars-backward "[ \t]"))
3591 ;;; (setq target (max (1+ (setq prevc
3592 ;;; (current-column))) ; Else indent at comment column
3593 ;;; comment-column))
3594 ;;; (if (= c comment-column) nil
3595 ;;; (delete-backward-char cnt)
3596 ;;; (while (< prevc target)
3598 ;;; (setq prevc (current-column)))
3599 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
3600 ;;; (while (< prevc target)
3602 ;;; (setq prevc (current-column)))))))
3604 (defun cperl-indent-for-comment ()
3605 "Substitute for `indent-for-comment' in CPerl."
3607 (let (cperl-wrong-comment)
3608 (indent-for-comment)
3609 (if cperl-wrong-comment ; set by `cperl-comment-indent'
3610 (progn (cperl-to-comment-or-eol)
3611 (forward-char (length comment-start))))))
3613 (defun cperl-comment-region (b e arg)
3614 "Comment or uncomment each line in the region in CPerl mode.
3615 See `comment-region'."
3616 (interactive "r\np")
3617 (let ((comment-start "#"))
3618 (comment-region b e arg)))
3620 (defun cperl-uncomment-region (b e arg)
3621 "Uncomment or comment each line in the region in CPerl mode.
3622 See `comment-region'."
3623 (interactive "r\np")
3624 (let ((comment-start "#"))
3625 (comment-region b e (- arg))))
3627 (defvar cperl-brace-recursing nil)
3629 (defun cperl-electric-brace (arg &optional only-before)
3630 "Insert character and correct line's indentation.
3631 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
3632 place (even in empty line), but not after. If after \")\" and the inserted
3633 char is \"{\", insert extra newline before only if
3634 `cperl-extra-newline-before-brace'."
3637 (other-end (if (and cperl-electric-parens-mark
3643 (not cperl-brace-recursing)
3644 (cperl-val 'cperl-electric-parens)
3645 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
3646 ;; Need to insert a matching pair
3649 (setq insertpos (point-marker))
3650 (goto-char other-end)
3651 (setq last-command-char ?\{)
3652 (cperl-electric-lbrace arg insertpos))
3654 ;; Check whether we close something "usual" with `}'
3655 (if (and (eq last-command-char ?\})
3659 (up-list (- (prefix-numeric-value arg)))
3660 ;;(cperl-after-block-p (point-min))
3661 (or (cperl-after-expr-p nil "{;)")
3662 ;; after sub, else, continue
3663 (cperl-after-block-p nil 'pre)))
3665 ;; Just insert the guy
3666 (self-insert-command (prefix-numeric-value arg))
3667 (if (and (not arg) ; No args, end (of empty line or auto)
3669 (or (and (null only-before)
3671 (skip-chars-backward " \t")
3673 (and (eq last-command-char ?\{) ; Do not insert newline
3674 ;; if after ")" and `cperl-extra-newline-before-brace'
3675 ;; is nil, do not insert extra newline.
3676 (not cperl-extra-newline-before-brace)
3678 (skip-chars-backward " \t")
3679 (eq (preceding-char) ?\))))
3680 (if cperl-auto-newline
3681 (progn (cperl-indent-line) (newline) t) nil)))
3683 (self-insert-command (prefix-numeric-value arg))
3685 (if cperl-auto-newline
3686 (setq insertpos (1- (point))))
3687 (if (and cperl-auto-newline (null only-before))
3690 (cperl-indent-line)))
3692 (if insertpos (progn (goto-char insertpos)
3693 (search-forward (make-string
3694 1 last-command-char))
3695 (setq insertpos (1- (point)))))
3699 (goto-char insertpos)
3700 (self-insert-command (prefix-numeric-value arg)))
3701 (self-insert-command (prefix-numeric-value arg))
3702 ;;;(insert (make-string (prefix-numeric-value arg) last-command-char))
3705 (defun cperl-electric-lbrace (arg &optional end)
3706 "Insert character, correct line's indentation, correct quoting by space."
3708 (let ((cperl-brace-recursing t)
3709 (cperl-auto-newline cperl-auto-newline)
3711 (if (and cperl-electric-parens-mark
3719 (and (cperl-val 'cperl-electric-lbrace-space)
3720 (eq (preceding-char) ?$)
3722 (skip-chars-backward "$")
3723 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
3725 ;; Check whether we are in comment
3729 (not (looking-at "[ \t]*#")))
3730 (cperl-after-expr-p nil "{;)"))
3732 (setq cperl-auto-newline nil))
3733 (cperl-electric-brace arg)
3734 (and (cperl-val 'cperl-electric-parens)
3735 (eq last-command-char ?{)
3736 (memq last-command-char
3737 (append cperl-electric-parens-string nil))
3738 (or (if other-end (goto-char (marker-position other-end)))
3740 (setq last-command-char ?} pos (point))
3741 (progn (cperl-electric-brace arg t)
3744 (defun cperl-electric-paren (arg)
3745 "Insert an opening parenthesis or a matching pair of parentheses.
3746 See `cperl-electric-parens'."
3748 (let ((beg (save-excursion (beginning-of-line) (point)))
3749 (other-end (if (and cperl-electric-parens-mark
3756 (if (and (cperl-val 'cperl-electric-parens)
3757 (memq last-command-char
3758 (append cperl-electric-parens-string nil))
3759 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
3760 ;;(not (save-excursion (search-backward "#" beg t)))
3761 (if (eq last-command-char ?<)
3763 (and abbrev-mode ; later it is too late, may be after `for'
3765 (cperl-after-expr-p nil "{;(,:="))
3768 (self-insert-command (prefix-numeric-value arg))
3769 (if other-end (goto-char (marker-position other-end)))
3770 (insert (make-string
3771 (prefix-numeric-value arg)
3772 (cdr (assoc last-command-char '((?{ .?})
3776 (forward-char (- (prefix-numeric-value arg))))
3777 (self-insert-command (prefix-numeric-value arg)))))
3779 (defun cperl-electric-rparen (arg)
3780 "Insert a matching pair of parentheses if marking is active.
3781 If not, or if we are not at the end of marking range, would self-insert.
3782 Affected by `cperl-electric-parens'."
3784 (let ((beg (save-excursion (beginning-of-line) (point)))
3785 (other-end (if (and cperl-electric-parens-mark
3786 (cperl-val 'cperl-electric-parens)
3787 (memq last-command-char
3788 (append cperl-electric-parens-string nil))
3795 (cperl-val 'cperl-electric-parens)
3796 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
3797 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
3798 ;;(not (save-excursion (search-backward "#" beg t)))
3801 (self-insert-command (prefix-numeric-value arg))
3803 (if other-end (goto-char other-end))
3804 (insert (make-string
3805 (prefix-numeric-value arg)
3806 (cdr (assoc last-command-char '((?\} . ?\{)
3811 (self-insert-command (prefix-numeric-value arg)))))
3813 (defun cperl-electric-keyword ()
3814 "Insert a construction appropriate after a keyword.
3815 Help message may be switched off by setting `cperl-message-electric-keyword'
3817 (let ((beg (save-excursion (beginning-of-line) (point)))
3818 (dollar (and (eq last-command-char ?$)
3819 (eq this-command 'self-insert-command)))
3820 (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
3821 (memq this-command '(self-insert-command newline))))
3823 (and (save-excursion
3827 (setq do (looking-at "do\\>")))
3829 (cperl-after-expr-p nil "{;:"))
3833 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
3835 (save-excursion (or (not (re-search-backward "^=" nil t))
3838 (and cperl-use-syntax-table-text-property
3839 (not (eq (get-text-property (point)
3842 (save-excursion (forward-sexp -1)
3843 (not (memq (following-char) (append "$@%&*" nil))))
3845 (and (eq (preceding-char) ?y)
3846 (progn ; "foreachmy"
3852 (memq this-command '(self-insert-command newline)))))
3853 (and dollar (insert " $"))
3855 ;;(insert " () {\n}")
3857 (cperl-extra-newline-before-brace
3858 (insert (if do "\n" " ()\n"))
3864 (and do (insert " while ();")))
3866 (insert (if do " {\n} while ();" " () {\n}"))))
3867 (or (looking-at "[ \t]\\|$") (insert " "))
3869 (if dollar (progn (search-backward "$")
3873 (search-backward ")")
3874 (if (eq last-command-char ?\()
3875 (progn ; Avoid "if (())"
3876 (delete-backward-char 1)
3877 (delete-backward-char -1))))
3879 (cperl-putback-char cperl-del-back-ch))
3880 (if cperl-message-electric-keyword
3881 (message "Precede char by C-q to avoid expansion"))))))
3883 (defun cperl-ensure-newlines (n &optional pos)
3884 "Make sure there are N newlines after the point."
3885 (or pos (setq pos (point)))
3886 (if (looking-at "\n")
3890 (cperl-ensure-newlines (1- n) pos)
3893 (defun cperl-electric-pod ()
3894 "Insert a POD chunk appropriate after a =POD directive."
3895 (let ((delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
3896 (memq this-command '(self-insert-command newline))))
3897 head1 notlast name p really-delete over)
3898 (and (save-excursion
3901 (eq (preceding-char) ?=)
3903 (setq head1 (looking-at "head1\\>[ \t]*$"))
3904 (setq over (and (looking-at "over\\>[ \t]*$")
3905 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
3909 (get-text-property (point) 'in-pod)
3910 (cperl-after-expr-p nil "{;:")
3911 (and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t)
3912 (not (looking-at "\n*=cut"))
3913 (or (not cperl-use-syntax-table-text-property)
3914 (eq (get-text-property (point) 'syntax-type) 'pod))))))
3917 (setq notlast (re-search-forward "^\n=" nil t)))
3921 (cperl-ensure-newlines 2)
3927 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
3928 nil t)))) ; Only one
3931 (setq name (file-name-sans-extension
3932 (file-name-nondirectory (buffer-file-name)))
3934 (insert " NAME\n\n" name
3935 " - \n\n=head1 SYNOPSIS\n\n\n\n"
3936 "=head1 DESCRIPTION")
3937 (cperl-ensure-newlines 4)
3941 (setq really-delete t))
3946 (insert "\n\n=item \n\n\n\n"
3948 (cperl-ensure-newlines 2)
3952 (setq really-delete t)))
3953 (if (and delete really-delete)
3954 (cperl-putback-char cperl-del-back-ch))))))
3956 (defun cperl-electric-else ()
3957 "Insert a construction appropriate after a keyword.
3958 Help message may be switched off by setting `cperl-message-electric-keyword'
3960 (let ((beg (save-excursion (beginning-of-line) (point))))
3961 (and (save-excursion
3963 (cperl-after-expr-p nil "{;:"))
3967 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
3969 (save-excursion (or (not (re-search-backward "^=" nil t))
3971 (and cperl-use-syntax-table-text-property
3972 (not (eq (get-text-property (point)
3977 ;;(insert " {\n\n}")
3979 (cperl-extra-newline-before-brace
3985 (insert " {\n\n}")))
3986 (or (looking-at "[ \t]\\|$") (insert " "))
3990 (cperl-putback-char cperl-del-back-ch)
3991 (setq this-command 'cperl-electric-else)
3992 (if cperl-message-electric-keyword
3993 (message "Precede char by C-q to avoid expansion"))))))
3995 (defun cperl-linefeed ()
3996 "Go to end of line, open a new line and indent appropriately.
3997 If in POD, insert appropriate lines."
3999 (let ((beg (save-excursion (beginning-of-line) (point)))
4000 (end (save-excursion (end-of-line) (point)))
4001 (pos (point)) start over cut res)
4002 (if (and ; Check if we need to split:
4003 ; i.e., on a boundary and inside "{...}"
4004 (save-excursion (cperl-to-comment-or-eol)
4005 (>= (point) pos)) ; Not in a comment
4007 (skip-chars-backward " \t" beg)
4009 (looking-at "[;{]")) ; After { or ; + spaces
4010 (looking-at "[ \t]*}") ; Before }
4011 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
4014 (eq (car (parse-partial-sexp pos end -1)) -1)
4015 ; Leave the level of parens
4016 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
4018 (cperl-after-block-p (point-min))
4021 (setq start (point-marker))
4022 (<= start pos))))) ; Redundant? Are after the
4023 ; start of parens group.
4025 (skip-chars-backward " \t")
4026 (or (memq (preceding-char) (append ";{" nil))
4032 (or (looking-at "{[ \t]*$") ; If there is a statement
4033 ; before, move it to separate line
4037 (cperl-indent-line)))
4038 (forward-line 1) ; We are on the target line
4041 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
4042 ; after, move it to separate line
4045 (search-backward "}" beg)
4046 (skip-chars-backward " \t")
4047 (or (memq (preceding-char) (append ";{" nil))
4052 (forward-line -1) ; We are on the line before target
4054 (newline-and-indent))
4055 (end-of-line) ; else - no splitting
4057 ((and (looking-at "\n[ \t]*{$")
4059 (skip-chars-backward " \t")
4060 (eq (preceding-char) ?\)))) ; Probably if () {} group
4061 ; with an extra newline.
4063 (cperl-indent-line))
4064 ((save-excursion ; In POD header
4065 (forward-paragraph -1)
4066 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
4067 ;; We are after \n now, so look for the rest
4068 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
4070 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
4071 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
4075 (forward-paragraph -1)
4078 (setq cut (buffer-substring (point)
4082 (delete-char (- (save-excursion (end-of-line) (point))
4084 (setq res (expand-abbrev))
4090 (cperl-ensure-newlines (if cut 2 4))
4092 ((get-text-property (point) 'in-pod) ; In POD section
4093 (cperl-ensure-newlines 4)
4095 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
4097 (cperl-indent-line))
4099 (newline-and-indent))))))
4101 (defun cperl-electric-semi (arg)
4102 "Insert character and correct line's indentation."
4104 (if cperl-auto-newline
4105 (cperl-electric-terminator arg)
4106 (self-insert-command (prefix-numeric-value arg))
4107 (if cperl-autoindent-on-semi
4108 (cperl-indent-line))))
4110 (defun cperl-electric-terminator (arg)
4111 "Insert character and correct line's indentation."
4114 (auto (and cperl-auto-newline
4115 (or (not (eq last-command-char ?:))
4116 cperl-auto-newline-after-colon)))
4118 (if (and ;;(not arg)
4120 (not (save-excursion
4122 (skip-chars-forward " \t")
4124 ;; Ignore in comment lines
4125 (= (following-char) ?#)
4126 ;; Colon is special only after a label
4127 ;; So quickly rule out most other uses of colon
4128 ;; and do no indentation for them.
4129 (and (eq last-command-char ?:)
4132 (skip-chars-forward " \t")
4133 (and (< (point) end)
4134 (progn (goto-char (- end 1))
4135 (not (looking-at ":"))))))
4137 (beginning-of-defun)
4138 (let ((pps (parse-partial-sexp (point) end)))
4139 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
4141 (self-insert-command (prefix-numeric-value arg))
4143 (if auto (setq insertpos (point-marker)))
4149 (cperl-indent-line)))
4151 (if insertpos (goto-char (1- (marker-position insertpos)))
4156 (goto-char insertpos)
4157 (self-insert-command (prefix-numeric-value arg)))
4158 (self-insert-command (prefix-numeric-value arg)))))
4160 (defun cperl-electric-backspace (arg)
4161 "Backspace, or remove the whitespace around the point inserted by an electric
4162 key. Will untabivy if `cperl-electric-backspace-untabify' is non-nil."
4164 (if (and cperl-auto-newline
4165 (memq last-command '(cperl-electric-semi
4166 cperl-electric-terminator
4167 cperl-electric-lbrace))
4168 (memq (preceding-char) '(?\ ?\t ?\n)))
4170 (if (eq last-command 'cperl-electric-lbrace)
4171 (skip-chars-forward " \t\n"))
4173 (skip-chars-backward " \t\n")
4174 (delete-region (point) p))
4175 (and (eq last-command 'cperl-electric-else)
4176 ;; We are removing the whitespace *inside* cperl-electric-else
4177 (setq this-command 'cperl-electric-else-really))
4178 (if (and cperl-auto-newline
4179 (eq last-command 'cperl-electric-else-really)
4180 (memq (preceding-char) '(?\ ?\t ?\n)))
4182 (skip-chars-forward " \t\n")
4184 (skip-chars-backward " \t\n")
4185 (delete-region (point) p))
4186 (if cperl-electric-backspace-untabify
4187 (backward-delete-char-untabify arg)
4188 (delete-backward-char arg)))))
4191 ;; helper function for deletion, which honors the desired delete direction
4192 ;; behavior. Added by Gary D. Foster, <Gary.Foster@corp.sun.com> and bound
4193 ;; to the 'delete keysym by default.
4194 (defun cperl-electric-delete (arg)
4195 "Delete, or remove the whitespace inserted by an electric key.
4196 Delete direction is controlled by the setting of `delete-key-deletes-forward'."
4198 (if (and cperl-auto-newline
4199 (memq last-command '(cperl-electric-semi
4200 cperl-electric-terminator
4201 cperl-electric-lbrace))
4202 (memq (preceding-char) '(? ?\t ?\n)))
4204 (if (eq last-command 'cperl-electric-lbrace)
4205 (skip-chars-forward " \t\n"))
4207 (skip-chars-backward " \t\n")
4208 (delete-region (point) p))
4209 (if (fboundp 'backward-or-forward-delete-char)
4210 (let ((f 'backward-or-forward-delete-char))
4211 (funcall f arg)) ; Avoid "not defined"
4212 (backward-delete-char-untabify arg))))
4214 (defun cperl-inside-parens-p () ;; NOT USED????
4218 (narrow-to-region (point)
4219 (progn (beginning-of-defun) (point)))
4220 (goto-char (point-max))
4221 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
4224 (defun cperl-indent-command (&optional whole-exp)
4225 "Indent current line as Perl code, or in some cases insert a tab character.
4226 If `cperl-tab-always-indent' is non-nil (the default), always indent current
4227 line. Otherwise, indent the current line only if point is at the left margin
4228 or in the line's indentation; otherwise insert a tab.
4230 A numeric argument, regardless of its value,
4231 means indent rigidly all the lines of the expression starting after point
4232 so that this line becomes properly indented.
4233 The relative indentation among the lines of the expression are preserved."
4235 (cperl-update-syntaxification (point) (point))
4237 ;; If arg, always indent this line as Perl
4238 ;; and shift remaining lines of expression the same amount.
4239 (let ((shift-amt (cperl-indent-line))
4242 (if cperl-tab-always-indent
4243 (beginning-of-line))
4250 (if (and shift-amt (> end beg))
4251 (indent-code-rigidly beg end shift-amt "#")))
4252 (if (and (not cperl-tab-always-indent)
4254 (skip-chars-backward " \t")
4257 (cperl-indent-line))))
4259 (defun cperl-indent-line (&optional parse-data)
4260 "Indent current line as Perl code.
4261 Return the amount the indentation changed by."
4262 (let ((case-fold-search nil)
4263 (pos (- (point-max) (point)))
4264 indent i beg shift-amt)
4265 (setq indent (cperl-calculate-indent parse-data)
4269 (cond ((or (eq indent nil) (eq indent t))
4270 (setq indent (current-indentation) i nil))
4271 ;;((eq indent t) ; Never?
4272 ;; (setq indent (cperl-calculate-indent-within-comment)))
4273 ;;((looking-at "[ \t]*#")
4276 (skip-chars-forward " \t")
4277 (if (listp indent) (setq indent (car indent)))
4278 (cond ((and (looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
4279 (not (looking-at "[smy]:\\|tr:")))
4281 (setq indent (max cperl-min-label-indent
4282 (+ indent cperl-label-offset)))))
4283 ((= (following-char) ?})
4284 (setq indent (- indent cperl-indent-level)))
4285 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
4286 (setq indent (+ indent cperl-close-paren-offset)))
4287 ((= (following-char) ?{)
4288 (setq indent (+ indent cperl-brace-offset))))))
4289 (skip-chars-forward " \t")
4290 (setq shift-amt (and i (- indent (current-column))))
4291 (if (or (not shift-amt)
4293 (if (> (- (point-max) pos) (point))
4294 (goto-char (- (point-max) pos)))
4295 ;;;(delete-region beg (point))
4296 ;;;(indent-to indent)
4297 (cperl-make-indent indent)
4298 ;; If initial point was within line's indentation,
4299 ;; position after the indentation. Else stay at same point in text.
4300 (if (> (- (point-max) pos) (point))
4301 (goto-char (- (point-max) pos))))
4304 (defun cperl-after-label ()
4305 ;; Returns true if the point is after label. Does not do save-excursion.
4306 (and (eq (preceding-char) ?:)
4307 (memq (char-syntax (char-after (- (point) 2)))
4311 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
4313 (defun cperl-get-state (&optional parse-start start-state)
4314 ;; returns list (START STATE DEPTH PRESTART),
4315 ;; START is a good place to start parsing, or equal to
4316 ;; PARSE-START if preset,
4317 ;; STATE is what is returned by `parse-partial-sexp'.
4318 ;; DEPTH is true is we are immediately after end of block
4319 ;; which contains START.
4320 ;; PRESTART is the position basing on which START was found.
4322 (let ((start-point (point)) depth state start prestart)
4323 (if (and parse-start
4324 (<= parse-start start-point))
4325 (goto-char parse-start)
4326 (beginning-of-defun)
4327 (setq start-state nil))
4328 (setq prestart (point))
4330 ;; Try to go out, if sub is not on the outermost level
4331 (while (< (point) start-point)
4332 (setq start (point) parse-start start depth nil
4333 state (parse-partial-sexp start start-point -1))
4334 (if (> (car state) -1) nil
4335 ;; The current line could start like }}}, so the indentation
4336 ;; corresponds to a different level than what we reached
4338 (beginning-of-line 2))) ; Go to the next line.
4339 (if start (goto-char start))) ; Not at the start of file
4340 (setq start (point))
4341 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
4342 (list start state depth prestart))))
4344 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
4346 (defun cperl-beginning-of-property (p prop &optional lim)
4347 "Given that P has a property PROP, find where the property starts.
4348 Will not look before LIM."
4349 ;;; XXXX What to do at point-max???
4350 (or (previous-single-property-change (cperl-1+ p) prop lim)
4352 ;;; (cond ((eq p (point-min))
4354 ;;; ((and lim (<= p lim))
4356 ;;; ((not (get-text-property (1- p) prop))
4358 ;;; (t (or (previous-single-property-change p look-prop lim)
4362 (defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start
4363 ;; the sniffer logic to understand what the current line MEANS.
4364 (cperl-update-syntaxification (point) (point))
4365 (let ((res (get-text-property (point) 'syntax-type)))
4368 ((and (memq res '(pod here-doc here-doc-delim format))
4369 (not (get-text-property (point) 'indentable)))
4371 ;; before start of POD - whitespace found since do not have 'pod!
4372 ((looking-at "[ \t]*\n=")
4373 (error "Spaces before POD section!"))
4374 ((and (not cperl-indent-left-aligned-comments)
4376 [comment-special:at-beginning-of-line])
4377 ((get-text-property (point) 'in-pod)
4381 (let* ((indent-point (point))
4382 (char-after-pos (save-excursion
4383 (skip-chars-forward " \t")
4385 (char-after (char-after char-after-pos))
4386 (pre-indent-point (point))
4387 p prop look-prop is-block delim)
4388 (save-excursion ; Know we are not in POD, find appropriate pos before
4389 (cperl-backward-to-noncomment nil)
4390 (setq p (max (point-min) (1- (point)))
4391 prop (get-text-property p 'syntax-type)
4392 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
4394 (if (memq prop '(pod here-doc format here-doc-delim))
4396 (goto-char (cperl-beginning-of-property p look-prop))
4398 (setq pre-indent-point (point)))))
4399 (goto-char pre-indent-point) ; Orig line skipping preceeding pod/etc
4400 (let* ((case-fold-search nil)
4401 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
4402 (start (or (nth 2 parse-data) ; last complete sexp terminated
4403 (nth 0 s-s))) ; Good place to start parsing
4405 (containing-sexp (car (cdr state)))
4408 ;;containing-sexp ;; We are buggy at toplevel :-(
4411 (setcar parse-data pre-indent-point)
4412 (setcar (cdr parse-data) state)
4413 (or (nth 2 parse-data)
4414 (setcar (cddr parse-data) start))
4415 ;; Before this point: end of statement
4416 (setq old-indent (nth 3 parse-data))))
4417 (cond ((get-text-property (point) 'indentable)
4418 ;; indent to "after" the surrounding open
4419 ;; (same offset as `cperl-beautify-regexp-piece'),
4420 ;; skip blanks if we do not close the expression.
4421 (setq delim ; We do not close the expression
4423 (cperl-1+ char-after-pos) 'indentable)
4424 p (1+ (cperl-beginning-of-property
4425 (point) 'indentable))
4426 is-block ; misused for: preceeding line in REx
4427 (save-excursion ; Find preceeding line
4428 (cperl-backward-to-noncomment p)
4431 (progn ; get indent from the first line
4433 (skip-chars-forward " \t")
4434 (if (memq (char-after (point))
4436 nil ; Can't use intentation of this line...
4438 (skip-chars-forward " \t")
4440 prop (parse-partial-sexp p char-after-pos))
4441 (cond ((not delim) ; End the REx, ignore is-block
4442 (vector 'indentable 'terminator p is-block))
4443 (is-block ; Indent w.r.t. preceeding line
4444 (vector 'indentable 'cont-line char-after-pos
4445 is-block char-after p))
4446 (t ; No preceeding line...
4447 (vector 'indentable 'first-line p))))
4448 ((get-text-property char-after-pos 'REx-part2)
4449 (vector 'REx-part2 (point)))
4454 ;; XXXX Do we need to special-case this?
4455 ((null containing-sexp)
4456 ;; Line is at top level. May be data or function definition,
4457 ;; or may be function argument declaration.
4458 ;; Indent like the previous top level line
4459 ;; unless that ends in a closeparen without semicolon,
4460 ;; in which case this line is the first argument decl.
4461 (skip-chars-forward " \t")
4462 (cperl-backward-to-noncomment (or old-indent (point-min)))
4465 (eq (point) old-indent) ; old-indent was at comment
4466 (eq (preceding-char) ?\;)
4468 (and (eq (preceding-char) ?\})
4469 (cperl-after-block-and-statement-beg
4470 (point-min))) ; Was start - too close
4471 (memq char-after (append ")]}" nil))
4472 (and (eq (preceding-char) ?\:) ; label
4475 (skip-chars-backward " \t")
4476 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
4477 (get-text-property (point) 'first-format-line)))
4479 ;; Look at previous line that's at column 0
4480 ;; to determine whether we are in top-level decls
4481 ;; or function's arg decls. Set basic-indent accordingly.
4482 ;; Now add a little if this is a continuation line.
4485 (not (eq char-after ?\C-j))
4486 (setcdr (cddr parse-data)
4487 (list pre-indent-point)))
4488 (vector 'toplevel start char-after state (nth 2 s-s)))
4491 (and (setq delim (= (char-after containing-sexp) ?{))
4492 (save-excursion ; Is it a hash?
4493 (goto-char containing-sexp)
4495 cperl-indent-parens-as-block))
4496 ;; group is an expression, not a block:
4497 ;; indent to just after the surrounding open parens,
4498 ;; skip blanks if we do not close the expression.
4499 (goto-char (1+ containing-sexp))
4500 (or (memq char-after
4501 (append (if delim "}" ")]}") nil))
4502 (looking-at "[ \t]*\\(#\\|$\\)")
4503 (skip-chars-forward " \t"))
4504 (setq old-indent (point)) ; delim=is-brace
4505 (vector 'in-parens char-after (point) delim containing-sexp))
4507 ;; Statement level. Is it a continuation or a new statement?
4508 ;; Find previous non-comment character.
4509 (goto-char pre-indent-point) ; Skip one level of POD/etc
4510 (cperl-backward-to-noncomment containing-sexp)
4511 ;; Back up over label lines, since they don't
4512 ;; affect whether our line is a continuation.
4514 (while;;(or (eq (preceding-char) ?\,)
4515 (and (eq (preceding-char) ?:)
4516 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
4517 (memq (char-syntax (char-after (- (point) 2)))
4520 ;; This is always FALSE?
4521 (if (eq (preceding-char) ?\,)
4522 ;; Will go to beginning of line, essentially.
4523 ;; Will ignore embedded sexpr XXXX.
4524 (cperl-backward-to-start-of-continued-exp containing-sexp))
4526 (cperl-backward-to-noncomment containing-sexp))
4527 ;; Now we get non-label preceeding the indent point
4528 (if (not (or (eq (1- (point)) containing-sexp)
4529 (memq (preceding-char)
4530 (append (if is-block " ;{" " ,;{") '(nil)))
4531 (and (eq (preceding-char) ?\})
4532 (cperl-after-block-and-statement-beg
4534 (get-text-property (point) 'first-format-line)))
4535 ;; This line is continuation of preceding line's statement;
4536 ;; indent `cperl-continued-statement-offset' more than the
4537 ;; previous line of the statement.
4539 ;; There might be a label on this line, just
4540 ;; consider it bad style and ignore it.
4542 (cperl-backward-to-start-of-continued-exp containing-sexp)
4543 (vector 'continuation (point) char-after is-block delim))
4544 ;; This line starts a new statement.
4545 ;; Position following last unclosed open brace
4546 (goto-char containing-sexp)
4547 ;; Is line first statement after an open-brace?
4549 ;; If no, find that first statement and indent like
4550 ;; it. If the first statement begins with label, do
4551 ;; not believe when the indentation of the label is too
4555 (let ((colon-line-end 0))
4557 (progn (skip-chars-forward " \t\n")
4558 ;; s: foo : bar :x is NOT label
4559 (and (looking-at "#\\|\\([a-zA-Z0-9_$]+\\):[^:]\\|=[a-zA-Z]")
4560 (not (looking-at "[sym]:\\|tr:"))))
4561 ;; Skip over comments and labels following openbrace.
4562 (cond ((= (following-char) ?\#)
4564 ((= (following-char) ?\=)
4566 (or (next-single-property-change (point) 'in-pod)
4567 (point-max)))) ; do not loop if no syntaxification
4570 (save-excursion (end-of-line)
4571 (setq colon-line-end (point)))
4572 (search-forward ":"))))
4573 ;; We are at beginning of code (NOT label or comment)
4574 ;; First, the following code counts
4575 ;; if it is before the line we want to indent.
4576 (and (< (point) indent-point)
4577 (vector 'have-prev-sibling (point) colon-line-end
4580 ;; If no previous statement,
4581 ;; indent it relative to line brace is on.
4583 ;; For open-braces not the first thing in a line,
4584 ;; add in cperl-brace-imaginary-offset.
4586 ;; If first thing on a line: ?????
4587 ;; Move back over whitespace before the openbrace.
4588 (setq ; brace first thing on a line
4589 old-indent (progn (skip-chars-backward " \t") (bolp)))
4590 ;; Should we indent w.r.t. earlier than start?
4591 ;; Move to start of control group, possibly on a different line
4592 (or cperl-indent-wrt-brace
4593 (cperl-backward-to-noncomment (point-min)))
4594 ;; If the openbrace is preceded by a parenthesized exp,
4595 ;; move to the beginning of that;
4596 (if (eq (preceding-char) ?\))
4599 (cperl-backward-to-noncomment (point-min))))
4600 ;; In the case it starts a subroutine, indent with
4601 ;; respect to `sub', not with respect to the
4602 ;; first thing on the line, say in the case of
4603 ;; anonymous sub in a hash.
4604 (if (and;; Is it a sub in group starting on this line?
4605 (cond ((get-text-property (point) 'attrib-group)
4606 (goto-char (cperl-beginning-of-property
4607 (point) 'attrib-group)))
4608 ((eq (preceding-char) ?b)
4610 (looking-at "sub\\>")))
4611 (setq p (nth 1 ; start of innermost containing list
4613 (save-excursion (beginning-of-line)
4617 (goto-char (1+ p)) ; enclosing block on the same line
4618 (skip-chars-forward " \t")
4619 (vector 'code-start-in-block containing-sexp char-after
4620 (and delim (not is-block)) ; is a HASH
4621 old-indent ; brace first thing on a line
4622 t (point) ; have something before...
4626 ;; Get initial indentation of the line we are on.
4627 ;; If line starts with label, calculate label indentation
4628 (vector 'code-start-in-block containing-sexp char-after
4629 (and delim (not is-block)) ; is a HASH
4630 old-indent ; brace first thing on a line
4631 nil (point))))))))))))))) ; nothing interesting before
4633 (defvar cperl-indent-rules-alist
4634 '((pod nil) ; via `syntax-type' property
4635 (here-doc nil) ; via `syntax-type' property
4636 (here-doc-delim nil) ; via `syntax-type' property
4637 (format nil) ; via `syntax-type' property
4638 (in-pod nil) ; via `in-pod' property
4639 (comment-special:at-beginning-of-line nil)
4642 "Alist of indentation rules for CPerl mode.
4645 number: add this amount of indentation.")
4647 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
4648 "Return appropriate indentation for current line as Perl code.
4649 In usual case returns an integer: the column to indent to.
4650 Returns nil if line starts inside a string, t if in a comment.
4652 Will not correct the indentation for labels, but will correct it for braces
4653 and closing parentheses and brackets."
4654 ;; This code is still a broken architecture: in some cases we need to
4655 ;; compensate for some modifications which `cperl-indent-line' will add later
4657 (let ((i (cperl-sniff-for-indent parse-data)) what p)
4659 ;;((or (null i) (eq i t) (numberp i))
4662 (setq what (assoc (elt i 0) cperl-indent-rules-alist))
4664 (what (cadr what)) ; Load from table
4666 ;; Indenters for regular expressions with //x and qw()
4668 ((eq 'REx-part2 (elt i 0)) ;; [self start] start of /REP in s//REP/x
4669 (goto-char (elt i 1))
4670 (condition-case nil ; Use indentation of the 1st part
4673 ((eq 'indentable (elt i 0)) ; Indenter for REGEXP qw() etc
4674 (cond ;;; [indentable terminator start-pos is-block]
4675 ((eq 'terminator (elt i 1)) ; Lone terminator of "indentable string"
4676 (goto-char (elt i 2)) ; After opening parens
4677 (1- (current-column)))
4678 ((eq 'first-line (elt i 1)); [indentable first-line start-pos]
4679 (goto-char (elt i 2))
4680 (+ (or cperl-regexp-indent-step cperl-indent-level)
4683 ((eq 'cont-line (elt i 1)); [indentable cont-line pos prev-pos first-char start-pos]
4684 ;; Indent as the level after closing parens
4685 (goto-char (elt i 2)) ; indent line
4686 (skip-chars-forward " \t)") ; Skip closing parens
4688 (goto-char (elt i 3)) ; previous line
4689 (skip-chars-forward " \t)") ; Skip closing parens
4690 ;; Number of parens in between:
4691 (setq p (nth 0 (parse-partial-sexp (point) p))
4692 what (elt i 4)) ; First char on current line
4693 (goto-char (elt i 3)) ; previous line
4694 (+ (* p (or cperl-regexp-indent-step cperl-indent-level))
4695 (cond ((eq what ?\) )
4696 (- cperl-close-paren-offset)) ; compensate
4698 (- (or cperl-regexp-indent-step cperl-indent-level)))
4700 (if (eq (following-char) ?\| )
4701 (or cperl-regexp-indent-step cperl-indent-level)
4705 (error "Unrecognized value of indent: " i))))
4707 ;; Indenter for stuff at toplevel
4709 ((eq 'toplevel (elt i 0)) ;; [toplevel start char-after state immed-after-block]
4710 (+ (save-excursion ; To beg-of-defun, or end of last sexp
4711 (goto-char (elt i 1)) ; start = Good place to start parsing
4712 (- (current-indentation) ;
4713 (if (elt i 4) cperl-indent-level 0))) ; immed-after-block
4714 (if (eq (elt i 2) ?{) cperl-continued-brace-offset 0) ; char-after
4715 ;; Look at previous line that's at column 0
4716 ;; to determine whether we are in top-level decls
4717 ;; or function's arg decls. Set basic-indent accordingly.
4718 ;; Now add a little if this is a continuation line.
4719 (if (elt i 3) ; state (XXX What is the semantic???)
4721 cperl-continued-statement-offset)))
4723 ;; Indenter for stuff in "parentheses" (or brackets, braces-as-hash)
4725 ((eq 'in-parens (elt i 0))
4726 ;; in-parens char-after old-indent-point is-brace containing-sexp
4728 ;; group is an expression, not a block:
4729 ;; indent to just after the surrounding open parens,
4730 ;; skip blanks if we do not close the expression.
4732 (goto-char (elt i 2)) ; old-indent-point
4734 (if (and (elt i 3) ; is-brace
4735 (eq (elt i 1) ?\})) ; char-after
4736 ;; Correct indentation of trailing ?\}
4737 (+ cperl-indent-level cperl-close-paren-offset)
4740 ;; Indenter for continuation lines
4742 ((eq 'continuation (elt i 0))
4743 ;; [continuation statement-start char-after is-block is-brace]
4744 (goto-char (elt i 1)) ; statement-start
4745 (+ (if (memq (elt i 2) (append "}])" nil)) ; char-after
4747 cperl-continued-statement-offset)
4748 (if (or (elt i 3) ; is-block
4749 (not (elt i 4)) ; is-brace
4750 (not (eq (elt i 2) ?\}))) ; char-after
4752 ;; Now it is a hash reference
4753 (+ cperl-indent-level cperl-close-paren-offset))
4754 ;; Labels do not take :: ...
4755 (if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
4756 (if (> (current-indentation) cperl-min-label-indent)
4757 (- (current-indentation) cperl-label-offset)
4758 ;; Do not move `parse-data', this should
4759 ;; be quick anyway (this comment comes
4760 ;; from different location):
4761 (cperl-calculate-indent))
4763 (if (eq (elt i 2) ?\{) ; char-after
4764 cperl-continued-brace-offset 0)))
4766 ;; Indenter for lines in a block which are not leading lines
4768 ((eq 'have-prev-sibling (elt i 0))
4769 ;; [have-prev-sibling sibling-beg colon-line-end block-start]
4770 (goto-char (elt i 1)) ; sibling-beg
4771 (if (> (elt i 2) (point)) ; colon-line-end; have label before point
4772 (if (> (current-indentation)
4773 cperl-min-label-indent)
4774 (- (current-indentation) cperl-label-offset)
4775 ;; Do not believe: `max' was involved in calculation of indent
4776 (+ cperl-indent-level
4778 (goto-char (elt i 3)) ; block-start
4779 (current-indentation))))
4782 ;; Indenter for the first line in a block
4784 ((eq 'code-start-in-block (elt i 0))
4785 ;;[code-start-in-block before-brace char-after
4786 ;; is-a-HASH-ref brace-is-first-thing-on-a-line
4787 ;; group-starts-before-start-of-sub start-of-control-group]
4788 (goto-char (elt i 1))
4789 ;; For open brace in column zero, don't let statement
4790 ;; start there too. If cperl-indent-level=0,
4791 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
4792 (+ (if (and (bolp) (zerop cperl-indent-level))
4793 (+ cperl-brace-offset cperl-continued-statement-offset)
4795 (if (and (elt i 3) ; is-a-HASH-ref
4796 (eq (elt i 2) ?\})) ; char-after: End of a hash reference
4797 (+ cperl-indent-level cperl-close-paren-offset)
4799 ;; Unless openbrace is the first nonwhite thing on the line,
4800 ;; add the cperl-brace-imaginary-offset.
4801 (if (elt i 4) 0 ; brace-is-first-thing-on-a-line
4802 cperl-brace-imaginary-offset)
4804 (goto-char (elt i 6)) ; start-of-control-group
4805 (if (elt i 5) ; group-starts-before-start-of-sub
4807 ;; Get initial indentation of the line we are on.
4808 ;; If line starts with label, calculate label indentation
4811 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
4812 (if (> (current-indentation) cperl-min-label-indent)
4813 (- (current-indentation) cperl-label-offset)
4814 ;; Do not move `parse-data', this should
4816 (cperl-calculate-indent))
4817 (current-indentation))))))
4819 (error "Unrecognized value of indent: " i))))
4821 (error (format "Got strange value of indent: " i)))))))
4823 (defun cperl-calculate-indent-within-comment ()
4824 "Return the indentation amount for line, assuming that
4825 the current line is to be regarded as part of a block comment."
4826 (let (end star-start)
4829 (skip-chars-forward " \t")
4831 (and (= (following-char) ?#)
4833 (cperl-to-comment-or-eol)
4839 (defun cperl-to-comment-or-eol ()
4840 "Go to position before comment on the current line, or to end of line.
4841 Returns true if comment is found. In POD will not move the point."
4842 ;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
4843 ;; then looks for literal # or end-of-line.
4844 (let (state stop-in cpoint (lim (progn (end-of-line) (point))) pr e)
4845 (or cperl-font-locking
4846 (cperl-update-syntaxification lim lim))
4848 (if (setq pr (get-text-property (point) 'syntax-type))
4849 (setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
4850 (if (or (eq pr 'pod)
4851 (if (or (not e) (> e lim)) ; deep inside a group
4852 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
4853 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
4854 ;; Else - need to do it the hard way
4855 (and (and e (<= e lim))
4857 (while (not stop-in)
4858 (setq state (parse-partial-sexp (point) lim nil nil nil t))
4860 ;; If fails (beginning-of-line inside sexp), then contains not-comment
4861 (if (nth 4 state) ; After `#';
4862 ; (nth 2 state) can be
4863 ; beginning of m,s,qq and so
4867 (setq cpoint (point))
4868 (goto-char (nth 2 state))
4870 ((looking-at "\\(s\\|tr\\)\\>")
4871 (or (re-search-forward
4872 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
4875 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
4876 (or (re-search-forward
4877 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
4880 (t ; It was fair comment
4881 (setq stop-in t) ; Finish
4882 (goto-char (1- cpoint)))))
4883 (setq stop-in t) ; Finish
4885 (setq stop-in t))) ; Finish
4888 (defsubst cperl-modify-syntax-type (at how)
4889 (if (< at (point-max))
4891 (put-text-property at (1+ at) 'syntax-table how)
4892 (put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
4894 (defun cperl-protect-defun-start (s e)
4895 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
4898 (while (re-search-forward "^\\s(" e 'to-end)
4899 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
4901 (defun cperl-commentify (bb e string &optional noface)
4902 (if cperl-use-syntax-table-text-property
4903 (if (eq noface 'n) ; Only immediate
4905 ;; We suppose that e is _after_ the end of construction, as after eol.
4906 (setq string (if string cperl-st-sfence cperl-st-cfence))
4908 ;; one-char string/comment?!
4909 (cperl-modify-syntax-type bb cperl-st-punct)
4910 (cperl-modify-syntax-type bb string)
4911 (cperl-modify-syntax-type (1- e) string))
4912 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
4913 (put-text-property (1+ bb) (1- e)
4914 'syntax-table cperl-string-syntax-table))
4915 (cperl-protect-defun-start bb e))
4918 (not cperl-pod-here-fontify)
4919 (put-text-property bb e 'face (if string 'font-lock-string-face
4920 'font-lock-comment-face)))))
4922 (defvar cperl-starters '(( ?\( . ?\) )
4927 (defun cperl-cached-syntax-table (st)
4928 "Get a syntax table cached in ST, or create and cache into ST a syntax table.
4929 All the entries of the syntax table are \".\", except for a backslash, which
4933 (setcar st (make-syntax-table))
4937 (modify-syntax-entry i "." st)
4939 (modify-syntax-entry ?\\ "\\" st)
4942 (defun cperl-forward-re (lim end is-2arg st-l err-l argument
4943 &optional ostart oend)
4944 "Find the end of a regular expression or a stringish construct (q[] etc).
4945 The point should be before the starting delimiter.
4947 Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
4948 is s/// or tr/// like expression. If END is nil, generates an error
4949 message if needed. If SET-ST is non-nil, will use (or generate) a
4950 cached syntax table in ST-L. If ERR-L is non-nil, will store the
4951 error message in its CAR (unless it already contains some error
4952 message). ARGUMENT should be the name of the construct (used in error
4953 messages). OSTART, OEND may be set in recursive calls when processing
4954 the second argument of 2ARG construct.
4956 Works *before* syntax recognition is done. In IS-2ARG situation may
4957 modify syntax-type text property if the situation is too hard."
4958 (let (b starter ender st i i2 go-forward reset-st set-st)
4959 (skip-chars-forward " \t")
4960 ;; ender means matching-char matcher.
4962 starter (if (eobp) 0 (char-after b))
4963 ender (cdr (assoc starter cperl-starters)))
4964 ;; What if starter == ?\\ ????
4965 (setq st (cperl-cached-syntax-table st-l))
4967 ;; Whether we have an intermediate point
4969 ;; Prepare the syntax table:
4970 (if (not ender) ; m/blah/, s/x//, s/x/y/
4971 (modify-syntax-entry starter "$" st)
4972 (modify-syntax-entry starter (concat "(" (list ender)) st)
4973 (modify-syntax-entry ender (concat ")" (list starter)) st))
4976 ;; We use `$' syntax class to find matching stuff, but $$
4977 ;; is recognized the same as $, so we need to check this manually.
4978 (if (and (eq starter (char-after (cperl-1+ b)))
4980 ;; $ has TeXish matching rules, so $$ equiv $...
4982 (setq reset-st (syntax-table))
4983 (set-syntax-table st)
4985 (if (<= (point) (1+ b))
4986 (error "Unfinished regular expression"))
4987 (set-syntax-table reset-st)
4989 ;; Now the problem is with m;blah;;
4991 (eq (preceding-char)
4992 (char-after (- (point) 2)))
4995 (= 0 (% (skip-chars-backward "\\\\") 2)))
4997 ;; Now we are after the first part.
4998 (and is-2arg ; Have trailing part
5000 (eq (following-char) starter) ; Empty trailing part
5002 (or (eq (char-syntax (following-char)) ?.)
5003 ;; Make trailing letter into punctuation
5004 (cperl-modify-syntax-type (point) cperl-st-punct))
5005 (setq is-2arg nil go-forward t))) ; Ignore the tail
5006 (if is-2arg ; Not number => have second part
5008 (setq i (point) i2 i)
5010 (if (memq (following-char) '(?\ ?\t ?\n ?\f))
5012 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5013 (goto-char (match-end 0))
5014 (skip-chars-forward " \t\n\f"))
5017 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
5018 (if ender (modify-syntax-entry ender "." st))
5020 (setq ender (cperl-forward-re lim end nil st-l err-l
5021 argument starter ender)
5022 ender (nth 2 ender)))))
5023 (error (goto-char lim)
5026 (set-syntax-table reset-st))
5029 cperl-brace-recursing
5033 "End of `%s%s%c ... %c' string/RE not found: %s"
5035 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
5036 starter (or ender starter) bb)
5037 (or (car err-l) (setcar err-l b)))))
5040 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
5041 (if ender (modify-syntax-entry ender "." st))))
5042 ;; i: have 2 args, after end of the first arg
5043 ;; i2: start of the second arg, if any (before delim iff `ender').
5044 ;; ender: the last arg bounded by parens-like chars, the second one of them
5045 ;; starter: the starting delimiter of the first arg
5046 ;; go-forward: has 2 args, and the second part is empty
5047 (list i i2 ender starter go-forward)))
5049 (defun cperl-forward-group-in-re (&optional st-l)
5050 "Find the end of a group in a REx.
5051 Return the error message (if any). Does not work if delimiter is `)'.
5052 Works before syntax recognition is done."
5053 ;; Works *before* syntax recognition is done
5054 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
5055 (let (st b reset-st)
5058 (setq st (cperl-cached-syntax-table st-l))
5059 (modify-syntax-entry ?\( "()" st)
5060 (modify-syntax-entry ?\) ")(" st)
5061 (setq reset-st (syntax-table))
5062 (set-syntax-table st)
5065 "cperl-forward-group-in-re: error %s" b)))
5066 ;; now restore the initial state
5069 (modify-syntax-entry ?\( "." st)
5070 (modify-syntax-entry ?\) "." st)))
5072 (set-syntax-table reset-st))
5076 (defvar font-lock-string-face)
5077 ;;(defvar font-lock-reference-face)
5078 (defvar font-lock-constant-face)
5079 (defsubst cperl-postpone-fontification (b e type val &optional now)
5080 ;; Do after syntactic fontification?
5081 (if cperl-syntaxify-by-font-lock
5082 (or now (put-text-property b e 'cperl-postpone (cons type val)))
5083 (put-text-property b e type val)))
5085 ;;; Here is how the global structures (those which cannot be
5086 ;;; recognized locally) are marked:
5088 ;; Start-to-end is marked `in-pod' ==> t
5089 ;; Each non-literal part is marked `syntax-type' ==> `pod'
5090 ;; Each literal part is marked `syntax-type' ==> `in-pod'
5092 ;; Start-to-end is marked `here-doc-group' ==> t
5093 ;; The body is marked `syntax-type' ==> `here-doc'
5094 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
5096 ;; First line (to =) marked `first-format-line' ==> t
5097 ;; After-this--to-end is marked `syntax-type' ==> `format'
5098 ;; d) 'Q'uoted string:
5099 ;; part between markers inclusive is marked `syntax-type' ==> `string'
5100 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
5101 ;; second part of s///e is marked `syntax-type' ==> `multiline'
5102 ;; e) Attributes of subroutines: `attrib-group' ==> t
5103 ;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
5104 ;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
5106 ;;; In addition, some parts of RExes may be marked as `REx-interpolated'
5107 ;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
5109 (defun cperl-unwind-to-safe (before &optional end)
5110 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
5111 (let ((pos (point)) opos)
5112 (while (and pos (progn
5114 (get-text-property (setq pos (point)) 'syntax-type)))
5116 pos (cperl-beginning-of-property pos 'syntax-type))
5117 (if (eq pos (point-min))
5122 (goto-char (cperl-1- pos))
5125 (goto-char (setq pos (cperl-1- pos))))
5127 (goto-char (point-min))))
5129 (and (looking-at "\n*=")
5130 (/= 0 (skip-chars-backward "\n"))
5134 ;; Do the same for end, going small steps
5136 (while (and end (get-text-property end 'syntax-type))
5138 end (next-single-property-change end 'syntax-type nil (point-max)))
5139 (if end (progn (goto-char end)
5140 (or (bolp) (forward-line 1))
5141 (setq end (point)))))
5144 ;;; These are needed for byte-compile (at least with v19)
5145 (defvar cperl-nonoverridable-face)
5146 (defvar font-lock-variable-name-face)
5147 (defvar font-lock-function-name-face)
5148 (defvar font-lock-keyword-face)
5149 (defvar font-lock-builtin-face)
5150 (defvar font-lock-type-face)
5151 (defvar font-lock-comment-face)
5152 (defvar font-lock-warning-face)
5154 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
5155 "Syntaxically mark (and fontify) attributes of a subroutine.
5156 Should be called with the point before leading colon of an attribute."
5157 ;; Works *before* syntax recognition is done
5158 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
5159 (let (st b p reset-st after-first (start (point)) start1 end1)
5163 "\\(" ; 1=optional? colon
5164 ":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
5166 (if after-first "?" "")
5167 ;; No space between name and paren allowed...
5168 "\\(\\sw+\\)" ; 3=name
5169 "\\((\\)?")) ; 4=optional paren
5170 (and (match-beginning 1)
5171 (cperl-postpone-fontification
5172 (match-beginning 0) (cperl-1+ (match-beginning 0))
5173 'face font-lock-constant-face))
5174 (setq start1 (match-beginning 3) end1 (match-end 3))
5175 (cperl-postpone-fontification start1 end1
5176 'face font-lock-constant-face)
5177 (goto-char end1) ; end or before `('
5178 (if (match-end 4) ; Have attribute arguments...
5181 (setq st (cperl-cached-syntax-table st-l))
5182 (modify-syntax-entry ?\( "()" st)
5183 (modify-syntax-entry ?\) ")(" st))
5184 (setq reset-st (syntax-table) p (point))
5185 (set-syntax-table st)
5187 (set-syntax-table reset-st)
5189 (cperl-commentify p (point) t))) ; mark as string
5190 (forward-comment (buffer-size))
5191 (setq after-first t))
5193 "L%d: attribute `%s': %s"
5194 (count-lines (point-min) (point))
5195 (and start1 end1 (buffer-substring start1 end1)) b)
5199 (put-text-property start (point)
5200 'attrib-group (if (looking-at "{") t 0))
5202 (< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
5203 ;; Apparently, we do not need `multiline': faces added now
5204 (put-text-property (+ 3 pos) (cperl-1+ (point))
5205 'syntax-type 'sub-decl))
5206 (and b-fname ; Fontify here: the following condition
5207 (cperl-postpone-fontification ; is too hard to determine by
5208 b-fname e-fname 'face ; a REx, so do it here
5209 (if (looking-at "{")
5210 font-lock-function-name-face
5211 font-lock-variable-name-face)))))
5212 ;; now restore the initial state
5215 (modify-syntax-entry ?\( "." st)
5216 (modify-syntax-entry ?\) "." st)))
5218 (set-syntax-table reset-st))))
5220 (defsubst cperl-look-at-leading-count (is-x-REx e)
5223 (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
5224 (1- e) t)) ; return nil on failure, no moving
5225 (if (eq ?\{ (preceding-char)) nil
5226 (cperl-postpone-fontification
5227 (1- (point)) (point)
5228 'face font-lock-warning-face))))
5230 ;; Do some smarter-highlighting
5231 ;; XXXX Currently ignores alphanum/dash delims,
5232 (defsubst cperl-highlight-charclass (endbracket dashface bsface onec-space)
5233 (let ((l '(1 5 7)) ll lle lll
5234 ;; 2 groups, the first takes the whole match (include \[trnfabe])
5235 (singleChar (concat "\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)")))
5236 (while ; look for unescaped - between non-classes
5238 ;; On 19.33, certain simplifications lead
5239 ;; to bugs (as in [^a-z] \\| [trnfabe] )
5240 (concat ; 1: SingleChar (include \[trnfabe])
5242 ;;"\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)"
5243 "\\(" ; 3: DASH SingleChar (match optionally)
5245 singleChar ; 5: SingleChar
5246 ;;"\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)"
5249 "\\(" ; 7: other escapes
5250 "\\\\[pP]" "\\([^{]\\|{[^{}]*}\\)"
5251 "\\|" "\\\\[^pP]" "\\)"
5254 (if (match-beginning 4)
5255 (cperl-postpone-fontification
5256 (match-beginning 4) (match-end 4)
5258 ;; save match data (for looking-at)
5259 (setq lll (mapcar (function (lambda (elt) (cons (match-beginning elt)
5260 (match-end elt)))) l))
5265 ;; (message "Got %s of %s" ll l)
5266 (if (and ll (eq (char-after ll) ?\\ ))
5269 (cperl-postpone-fontification ll (1+ ll)
5271 (if (looking-at "\\\\[a-zA-Z0-9]")
5272 (cperl-postpone-fontification (1+ ll) lle
5273 'face onec-space))))
5274 (setq lll (cdr lll))))
5275 (goto-char endbracket) ; just in case something misbehaves???
5278 ;;; Debugging this may require (setq max-specpdl-size 2000)...
5279 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc)
5280 "Scans the buffer for hard-to-parse Perl constructions.
5281 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
5282 the sections using `cperl-pod-head-face', `cperl-pod-face',
5285 (or min (setq min (point-min)
5286 cperl-syntax-state nil
5287 cperl-syntax-done-to min))
5288 (or max (setq max (point-max)))
5289 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
5290 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
5291 is-REx is-x-REx REx-subgr-start REx-subgr-end was-subgr i2 hairy-RE
5292 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
5293 (modified (buffer-modified-p)) overshoot is-o-REx
5294 (after-change-functions nil)
5295 (cperl-font-locking t)
5296 (use-syntax-state (and cperl-syntax-state
5297 (>= min (car cperl-syntax-state))))
5298 (state-point (if use-syntax-state
5299 (car cperl-syntax-state)
5301 (state (if use-syntax-state
5302 (cdr cperl-syntax-state)))
5303 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
5304 (st-l (list nil)) (err-l (list nil))
5305 ;; Somehow font-lock may be not loaded yet...
5306 ;; (e.g., when building TAGS via command-line call)
5307 (font-lock-string-face (if (boundp 'font-lock-string-face)
5308 font-lock-string-face
5309 'font-lock-string-face))
5310 (my-cperl-delimiters-face (if (boundp 'font-lock-constant-face)
5311 font-lock-constant-face
5312 'font-lock-constant-face))
5313 (my-cperl-REx-spec-char-face ; [] ^.$ and wrapper-of ({})
5314 (if (boundp 'font-lock-function-name-face)
5315 font-lock-function-name-face
5316 'font-lock-function-name-face))
5317 (font-lock-variable-name-face ; interpolated vars and ({})-code
5318 (if (boundp 'font-lock-variable-name-face)
5319 font-lock-variable-name-face
5320 'font-lock-variable-name-face))
5321 (font-lock-function-name-face ; used in `cperl-find-sub-attrs'
5322 (if (boundp 'font-lock-function-name-face)
5323 font-lock-function-name-face
5324 'font-lock-function-name-face))
5325 (font-lock-constant-face ; used in `cperl-find-sub-attrs'
5326 (if (boundp 'font-lock-constant-face)
5327 font-lock-constant-face
5328 'font-lock-constant-face))
5329 (my-cperl-REx-0length-face ; 0-length, (?:)etc, non-literal \
5330 (if (boundp 'font-lock-builtin-face)
5331 font-lock-builtin-face
5332 'font-lock-builtin-face))
5333 (font-lock-comment-face
5334 (if (boundp 'font-lock-comment-face)
5335 font-lock-comment-face
5336 'font-lock-comment-face))
5337 (font-lock-warning-face
5338 (if (boundp 'font-lock-warning-face)
5339 font-lock-warning-face
5340 'font-lock-warning-face))
5341 (my-cperl-REx-ctl-face ; (|)
5342 (if (boundp 'font-lock-keyword-face)
5343 font-lock-keyword-face
5344 'font-lock-keyword-face))
5345 (my-cperl-REx-modifiers-face ; //gims
5346 (if (boundp 'cperl-nonoverridable-face)
5347 cperl-nonoverridable-face
5348 'cperl-nonoverridable-face))
5349 (my-cperl-REx-length1-face ; length=1 escaped chars, POSIX classes
5350 (if (boundp 'font-lock-type-face)
5352 'font-lock-type-face))
5353 (stop-point (if ignore-max
5358 "\\(\\`\n?\\|^\n\\)=" ; POD
5360 ;; One extra () before this:
5363 ;; First variant "BLAH" or just ``.
5364 "[ \t]*" ; Yes, whitespace is allowed!
5365 "\\([\"'`]\\)" ; 2 + 1 = 3
5366 "\\([^\"'`\n]*\\)" ; 3 + 1
5369 ;; Second variant: Identifier or \ID (same as 'ID') or empty
5370 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
5371 ;; Do not have <<= or << 30 or <<30 or << $blah.
5372 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
5373 "\\(\\)" ; To preserve count of pars :-( 6 + 1
5376 ;; 1+6 extra () before this:
5377 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" ;FRMAT
5378 (if cperl-use-syntax-table-text-property
5381 ;; 1+6+2=9 extra () before this:
5382 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT
5384 ;; 1+6+2+1=10 extra () before this:
5385 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
5387 ;; 1+6+2+1+1=11 extra () before this
5388 "\\<sub\\>" ; sub with proto/attr
5390 cperl-white-and-comment-rex
5391 "\\(::[a-zA-Z_:'0-9]*\\|[a-zA-Z_'][a-zA-Z_:'0-9]*\\)\\)?" ; name
5393 cperl-maybe-white-and-comment-rex
5394 "\\(([^()]*)\\|:[^:]\\)\\)" ; prototype or attribute start
5396 ;; 1+6+2+1+1+6=17 extra () before this:
5397 "\\$\\(['{]\\)" ; $' or ${foo}
5399 ;; 1+6+2+1+1+6+1=18 extra () before this (old pack'var syntax;
5400 ;; we do not support intervening comments...):
5401 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
5402 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
5404 "__\\(END\\|DATA\\)__" ; __END__ or __DATA__
5405 ;; 1+6+2+1+1+6+1+1+1=20 extra () before this:
5407 "\\\\\\(['`\"($]\\)") ; BACKWACKED something-hairy
5413 (message "Scanning for \"hard\" Perl constructions..."))
5414 ;;(message "find: %s --> %s" min max)
5415 (and cperl-pod-here-fontify
5416 ;; We had evals here, do not know why...
5417 (setq face cperl-pod-face
5418 head-face cperl-pod-head-face
5419 here-face cperl-here-face))
5420 (remove-text-properties min max
5421 '(syntax-type t in-pod t syntax-table t
5432 ;; Need to remove face as well...
5434 (and (eq system-type 'emx)
5436 (let ((case-fold-search t))
5437 (looking-at "extproc[ \t]")) ; Analogue of #!
5438 (cperl-commentify min
5439 (save-excursion (end-of-line) (point))
5443 (re-search-forward search max t))
5444 (setq tmpend nil) ; Valid for most cases
5445 (setq b (match-beginning 0)
5446 state (save-excursion (parse-partial-sexp
5447 state-point b nil nil state))
5450 ;; 1+6+2+1+1+6=17 extra () before this:
5452 ((match-beginning 18) ; $' or ${foo}
5453 (if (eq (preceding-char) ?\') ; $'
5455 (setq b (1- (point))
5456 state (parse-partial-sexp
5457 state-point (1- b) nil nil state)
5459 (if (nth 3 state) ; in string
5460 (cperl-modify-syntax-type (1- b) cperl-st-punct))
5463 (setq bb (match-beginning 0))
5464 (cperl-modify-syntax-type bb cperl-st-punct)))
5465 ;; No processing in strings/comments beyond this point:
5466 ((or (nth 3 state) (nth 4 state))
5467 t) ; Do nothing in comment/string
5468 ((match-beginning 1) ; POD section
5469 ;; "\\(\\`\n?\\|^\n\\)="
5470 (setq b (match-beginning 0)
5471 state (parse-partial-sexp
5472 state-point b nil nil state)
5474 (if (or (nth 3 state) (nth 4 state)
5475 (looking-at "cut\\>"))
5476 (if (or (nth 3 state) (nth 4 state) ignore-max)
5477 nil ; Doing a chunk only
5478 (message "=cut is not preceded by a POD section")
5479 (or (car err-l) (setcar err-l (point))))
5484 tb (match-beginning 0)
5485 b1 nil) ; error condition
5486 ;; We do not search to max, since we may be called from
5487 ;; some hook of fontification, and max is random
5488 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
5491 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
5493 (message "=cut is not preceded by an empty line")
5495 (or (car err-l) (setcar err-l b))))))
5496 (beginning-of-line 2) ; An empty line after =cut is not POD!
5500 (remove-text-properties
5501 max e '(syntax-type t in-pod t syntax-table t
5513 (put-text-property b e 'in-pod t)
5514 (put-text-property b e 'syntax-type 'in-pod)
5516 (while (re-search-forward "\n\n[ \t]" e t)
5517 ;; We start 'pod 1 char earlier to include the preceding line
5519 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
5520 (cperl-put-do-not-fontify b (point) t)
5521 ;; mark the non-literal parts as PODs
5522 (if cperl-pod-here-fontify
5523 (cperl-postpone-fontification b (point) 'face face t))
5524 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
5527 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
5528 (cperl-put-do-not-fontify (point) e t)
5529 (if cperl-pod-here-fontify
5531 ;; mark the non-literal parts as PODs
5532 (cperl-postpone-fontification (point) e 'face face t)
5535 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
5537 (cperl-postpone-fontification
5538 (match-beginning 1) (match-end 1)
5540 (while (re-search-forward
5542 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
5545 (cperl-postpone-fontification
5546 (match-beginning 1) (match-end 1)
5548 (cperl-commentify bb e nil)
5550 (or (eq e (point-max))
5551 (forward-char -1)))) ; Prepare for immediate POD start.
5553 ;; We can do many here-per-line;
5554 ;; but multiline quote on the same line as <<HERE confuses us...
5555 ;; ;; One extra () before this:
5558 ;; ;; First variant "BLAH" or just ``.
5559 ;; "[ \t]*" ; Yes, whitespace is allowed!
5560 ;; "\\([\"'`]\\)" ; 2 + 1
5561 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
5564 ;; ;; Second variant: Identifier or \ID or empty
5565 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
5566 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
5567 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
5568 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
5570 ((match-beginning 2) ; 1 + 1
5572 tb (match-beginning 0)
5573 c (and ; not HERE-DOC
5576 (or (looking-at "[ \t]*(") ; << function_call()
5577 (save-excursion ; 1 << func_name, or $foo << 10
5581 ;;; XXX What to do: foo <<bar ???
5582 ;;; XXX Need to support print {a} <<B ???
5585 ; $foo << b; $f .= <<B;
5586 ; ($f+1) << b; a($f) . <<B;
5587 ; foo 1, <<B; $x{a} <<b;
5589 ((looking-at "[0-9$({]")
5592 (looking-at "[ \t]*<<")
5598 (looking-at "\\(printf?\\|system\\|exec\\|sort\\)\\>")))
5600 (error nil))) ; func(<<EOF)
5601 (and (not (match-beginning 6)) ; Empty
5603 "[ \t]*[=0-9$@%&(]"))))))
5604 (if c ; Not here-doc
5606 (setq c (match-end 2)) ; 1 + 1
5607 (if (match-beginning 5) ;4 + 1
5608 (setq b1 (match-beginning 5) ; 4 + 1
5609 e1 (match-end 5)) ; 4 + 1
5610 (setq b1 (match-beginning 4) ; 3 + 1
5611 e1 (match-end 4))) ; 3 + 1
5612 (setq tag (buffer-substring b1 e1)
5613 qtag (regexp-quote tag))
5614 (cond (cperl-pod-here-fontify
5615 ;; Highlight the starting delimiter
5616 (cperl-postpone-fontification
5617 b1 e1 'face my-cperl-delimiters-face)
5618 (cperl-put-do-not-fontify b1 e1 t)))
5622 (goto-char end-of-here-doc))
5624 ;; We do not search to max, since we may be called from
5625 ;; some hook of fontification, and max is random
5626 (or (and (re-search-forward (concat "^" qtag "$")
5628 ;;;(eq (following-char) ?\n) ; XXXX WHY???
5630 (progn ; Pretend we matched at the end
5631 (goto-char (point-max))
5632 (re-search-forward "\\'")
5633 (message "End of here-document `%s' not found." tag)
5634 (or (car err-l) (setcar err-l b))))
5635 (if cperl-pod-here-fontify
5637 ;; Highlight the ending delimiter
5638 (cperl-postpone-fontification
5639 (match-beginning 0) (match-end 0)
5640 'face my-cperl-delimiters-face)
5641 (cperl-put-do-not-fontify b (match-end 0) t)
5642 ;; Highlight the HERE-DOC
5643 (cperl-postpone-fontification b (match-beginning 0)
5645 (setq e1 (cperl-1+ (match-end 0)))
5646 (put-text-property b (match-beginning 0)
5647 'syntax-type 'here-doc)
5648 (put-text-property (match-beginning 0) e1
5649 'syntax-type 'here-doc-delim)
5650 (put-text-property b e1 'here-doc-group t)
5651 ;; This makes insertion at the start of HERE-DOC update
5652 ;; the whole construct:
5653 (put-text-property b (cperl-1+ b) 'front-sticky '(syntax-type))
5654 (cperl-commentify b e1 nil)
5655 (cperl-put-do-not-fontify b (match-end 0) t)
5656 ;; Cache the syntax info...
5657 (setq cperl-syntax-state (cons state-point state))
5658 ;; ... and process the rest of the line...
5660 (elt ; non-inter ignore-max
5661 (cperl-find-pods-heres c i t end t e1) 1))
5662 (if (and overshoot (> overshoot (point)))
5663 (goto-char overshoot)
5664 (setq overshoot e1))
5668 ((match-beginning 8)
5669 ;; 1+6=7 extra () before this:
5670 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
5672 name (if (match-beginning 8) ; 7 + 1
5673 (buffer-substring (match-beginning 8) ; 7 + 1
5674 (match-end 8)) ; 7 + 1
5676 tb (match-beginning 0))
5678 (put-text-property (save-excursion
5681 b 'first-format-line 't)
5682 (if cperl-pod-here-fontify
5683 (while (and (eq (forward-line) 0)
5684 (not (looking-at "^[.;]$")))
5686 ((looking-at "^#")) ; Skip comments
5687 ((and argument ; Skip argument multi-lines
5688 (looking-at "^[ \t]*{"))
5690 (setq argument nil))
5691 (argument ; Skip argument lines
5692 (setq argument nil))
5695 (setq argument (looking-at "^[^\n]*[@^]"))
5697 ;; Highlight the format line
5698 (cperl-postpone-fontification b1 (point)
5699 'face font-lock-string-face)
5700 (cperl-commentify b1 (point) nil)
5701 (cperl-put-do-not-fontify b1 (point) t))))
5702 ;; We do not search to max, since we may be called from
5703 ;; some hook of fontification, and max is random
5704 (re-search-forward "^[.;]$" stop-point 'toend))
5706 (if (looking-at "^\\.$") ; ";" is not supported yet
5708 ;; Highlight the ending delimiter
5709 (cperl-postpone-fontification (point) (+ (point) 2)
5710 'face font-lock-string-face)
5711 (cperl-commentify (point) (+ (point) 2) nil)
5712 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
5713 (message "End of format `%s' not found." name)
5714 (or (car err-l) (setcar err-l b)))
5718 (put-text-property b (point) 'syntax-type 'format))
5719 ;; qq-like String or Regexp:
5720 ((or (match-beginning 10) (match-beginning 11))
5721 ;; 1+6+2=9 extra () before this:
5722 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
5724 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
5725 (setq b1 (if (match-beginning 10) 10 11)
5726 argument (buffer-substring
5727 (match-beginning b1) (match-end b1))
5728 b (point) ; end of qq etc
5730 c (char-after (match-beginning b1))
5731 bb (char-after (1- (match-beginning b1))) ; tmp holder
5732 ;; bb == "Not a stringy"
5733 bb (if (eq b1 10) ; user variables/whatever
5734 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
5735 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
5736 ((eq bb ?\:) ; $opt::s
5738 (- (match-beginning b1) 2))
5740 ((eq bb ?\>) ; $foo->s
5742 (- (match-beginning b1) 2))
5745 (not (eq (char-after ; &&m/blah/
5746 (- (match-beginning b1) 2))
5749 ;; <file> or <$file>
5751 ;; Do not stringify <FH>, <$fh> :
5754 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
5755 tb (match-beginning 0))
5756 (goto-char (match-beginning b1))
5757 (cperl-backward-to-noncomment (point-min))
5759 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
5764 ;; What is below: regexp-p?
5766 (or (memq (preceding-char)
5767 (append (if (memq c '(?\? ?\<))
5770 "~{(=|&+-*!,;:[") nil))
5771 (and (eq (preceding-char) ?\})
5772 (cperl-after-block-p (point-min)))
5773 (and (eq (char-syntax (preceding-char)) ?w)
5776 ;;; After these keywords `/' starts a RE. One should add all the
5777 ;;; functions/builtins which expect an argument, but ...
5778 (if (eq (preceding-char) ?-)
5780 (looking-at "[a-zA-Z]\\>")
5782 (not (memq (preceding-char)
5785 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
5786 (and (eq (preceding-char) ?.)
5787 (eq (char-after (- (point) 2)) ?.))
5789 ;; m|blah| ? foo : bar;
5792 cperl-use-syntax-table-text-property
5796 (looking-at "\\s|"))))))
5799 ;; Check for $a -> y
5800 (setq b1 (preceding-char)
5803 (eq (char-after (- go 2)) ?-))
5809 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5810 (goto-char (match-end 0))
5811 (skip-chars-forward " \t\n\f"))
5812 (cond ((and (eq (following-char) ?\})
5814 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
5816 (skip-chars-backward " \t\n\f")
5817 (if (memq (preceding-char) (append "$@%&*" nil))
5823 (looking-at ; $foo -> {s}
5824 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
5825 (and ; $foo[12] -> {s}
5826 (memq (following-char) '(?\{ ?\[))
5829 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
5832 ((and (eq (following-char) ?=)
5833 (eq (char-after (1+ (point))) ?\>))
5834 ;; Check for { foo => 1, s => 2 }
5835 ;; Apparently s=> is never a substitution...
5837 ((and (eq (following-char) ?:)
5838 (eq b1 ?\{) ; Check for $ { s::bar }
5839 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
5842 (skip-chars-backward " \t\n\f")
5843 (memq (preceding-char)
5844 (append "$@%&*" nil))))
5850 ;; Skip whitespace and comments...
5851 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5852 (goto-char (match-end 0))
5853 (skip-chars-forward " \t\n\f"))
5855 (put-text-property b (point) 'syntax-type 'prestring))
5856 ;; qtag means two-arg matcher, may be reset to
5857 ;; 2 or 3 later if some special quoting is needed.
5858 ;; e1 means matching-char matcher.
5859 (setq b (point) ; before the first delimiter
5861 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
5862 ;; We do not search to max, since we may be called from
5863 ;; some hook of fontification, and max is random
5864 i (cperl-forward-re stop-point end
5866 st-l err-l argument)
5867 ;; If `go', then it is considered as 1-arg, `b1' is nil
5868 ;; as in s/foo//x; the point is before final "slash"
5869 b1 (nth 1 i) ; start of the second part
5870 tag (nth 2 i) ; ender-char, true if second part
5871 ; is with matching chars []
5872 go (nth 4 i) ; There is a 1-char part after the end
5873 i (car i) ; intermediate point
5875 ;; Before end of the second part if non-matching: ///
5876 tail (if (and i (not tag))
5878 e (if i i e1) ; end of the first part
5879 qtag nil ; need to preserve backslashitis
5880 is-x-REx nil is-o-REx nil); REx has //x //o modifiers
5881 ;; If s{} (), then b/b1 are at "{", "(", e1/i after ")", "}"
5882 ;; Commenting \\ is dangerous, what about ( ?
5884 (eq (char-after i) ?\\)
5886 (and (if go (looking-at ".\\sw*x")
5887 (looking-at "\\sw*x")) ; qr//x
5889 (and (if go (looking-at ".\\sw*o")
5890 (looking-at "\\sw*o")) ; //o
5893 ;; Considered as 1arg form
5895 (cperl-commentify b (point) t)
5896 (put-text-property b (point) 'syntax-type 'string)
5898 ;; ignore other text properties:
5899 (string-match "^qw$" argument))
5900 (put-text-property b (point) 'indentable t))
5902 (setq e1 (cperl-1+ e1))
5905 (cperl-commentify b i t)
5906 (if (looking-at "\\sw*e") ; s///e
5908 ;; Cache the syntax info...
5909 (setq cperl-syntax-state (cons state-point state))
5912 (car (cperl-find-pods-heres b1 (1- (point)) t end))
5914 (goto-char (1+ max)))
5915 (if (and tag (eq (preceding-char) ?\>))
5917 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
5918 (cperl-modify-syntax-type i cperl-st-bra)))
5919 (put-text-property b i 'syntax-type 'string)
5920 (put-text-property i (point) 'syntax-type 'multiline)
5922 (put-text-property b i 'indentable t)))
5923 (cperl-commentify b1 (point) t)
5924 (put-text-property b (point) 'syntax-type 'string)
5926 (put-text-property b i 'indentable t))
5928 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
5930 ;; Now: tail: if the second part is non-matching without ///e
5931 (if (eq (char-syntax (following-char)) ?w)
5933 (forward-word 1) ; skip modifiers s///s
5934 (if tail (cperl-commentify tail (point) t))
5935 (cperl-postpone-fontification
5936 e1 (point) 'face my-cperl-REx-modifiers-face)))
5937 ;; Check whether it is m// which means "previous match"
5938 ;; and highlight differently
5940 (and (string-match "^\\([sm]?\\|qr\\)$" argument)
5941 (or (not (= (length argument) 0))
5945 ;; split // *is* using zero-pattern
5951 (not (looking-at "split\\>")))
5953 (cperl-postpone-fontification
5954 b e 'face font-lock-warning-face)
5955 (if (or i2 ; Has 2 args
5956 (and cperl-fontify-m-as-s
5958 (string-match "^\\(m\\|qr\\)$" argument)
5959 (and (eq 0 (length argument))
5960 (not (eq ?\< (char-after b)))))))
5962 (cperl-postpone-fontification
5963 b (cperl-1+ b) 'face my-cperl-delimiters-face)
5964 (cperl-postpone-fontification
5965 (1- e) e 'face my-cperl-delimiters-face)))
5966 (if (and is-REx cperl-regexp-scan)
5967 ;; Process RExen: embedded comments, charclasses and ]
5968 ;;;/\3333\xFg\x{FFF}a\ppp\PPP\qqq\C\99f(?{ foo })(??{ foo })/;
5969 ;;;/a{4,5}\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
5970 ;;;/(?<=foo)(?<!bar)(x")(?:$ab|\$\/)$|\\\b\x888\776\[\:$/xxx;
5971 ;;;m?(\?\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
5972 ;;;m$(^ab[c]\$)$ + m+(^ab[c]\$\+)+ + m](^ab[c\]$|.+)] + m)(^ab[c]$|.+\));
5975 ;;;m^a[\^b-e\xFF]c^ + m.a[^b]\.c.; # OK
5976 ;;;m^a[\^-b-\e--[\--\xFF\c[\cX-\0333-\0555-\N{name}\pp--\P{prop}--\\\05555]^;
5977 ;;;m^a[[:alpha:]-[:alpha:]-a-[:alpha:][-aa-[[:alpha:]-b-[:alpha:]-[:alpha:]]^;
5978 ;;;m^a[x\\[:alpha:]-\\[:alpha:]-a-\\[:alpha:][-aa-[[:alpha:]-b-\\[:alpha:]-\\[:alpha:]]^;
5979 ;;;m^a[x\\[:alpha:][:alpha:]\\[:alpha:][-aa-[[:alpha:]\\[:alpha:][:alpha:]]^;
5983 (cperl-look-at-leading-count is-x-REx e)
5987 (if (eq (char-after b) ?\#)
5988 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
5989 "\\((\\?#\\)\\|\\(#\\)")
5990 ;; keep the same count: add a fake group
5991 (if (eq (char-after b) ?\#)
5992 "\\((\\?\\\\#\\)\\(\\)"
5993 "\\((\\?#\\)\\(\\)"))
5999 ;; XXXX Will not be able to use it in s)))
6000 (if (eq (char-after b) ?\) )
6001 "\\())))\\)" ; Will never match
6002 (if (eq (char-after b) ?? )
6003 ;;"\\((\\\\\\?\\(\\\\\\?\\)?{\\)"
6004 "\\((\\\\\\?\\\\\\?{\\|()\\\\\\?{\\)"
6005 "\\((\\?\\??{\\)")) ; 5= (??{ (?{
6006 "\\|" ; 6= 0-length, 7: name, 8,9:code, 10:group
6007 "\\(" ;; XXXX 1-char variables, exc. |()\s
6010 "[_a-zA-Z:][_a-zA-Z0-9:]*"
6012 "{[^{}]*}" ; only one-level allowed
6016 "\\(" ;;8,9:code part of array/hash elt
6022 ;; XXXX: what if u is delim?
6030 "\\\\[luLUEQbBAzZG]"
6033 "\\(" ; 10 group opener follower
6034 "\\?\\((\\?\\)" ; 11: in (?(?=C)A|B)
6036 "\\?[:=!>?{]" ; "?" something
6038 "\\?[-imsx]+[:)]" ; (?i) (?-s:.)
6040 "\\?([0-9]+)" ; (?(1)foo|bar)
6048 "\\\\\\(.\\)" ; 12=\SYMBOL
6051 (and (< (point) (1- e))
6052 (re-search-forward hairy-RE (1- e) 'to-end))
6053 (goto-char (match-beginning 0))
6054 (setq REx-subgr-start (point)
6055 was-subgr (following-char))
6057 ((match-beginning 6) ; 0-length builtins, groups
6058 (goto-char (match-end 0))
6059 (if (match-beginning 11)
6060 (goto-char (match-beginning 11)))
6063 (cperl-postpone-fontification
6064 (match-beginning 0) (point)
6067 ((eq was-subgr ?\) )
6072 (if (if (eq (char-after b) ?? )
6073 (looking-at "(\\\\\\?")
6074 (eq (char-after (1+ (point))) ?\?))
6075 my-cperl-REx-0length-face
6076 my-cperl-REx-ctl-face)
6077 font-lock-warning-face))
6078 (error font-lock-warning-face)))
6079 ((eq was-subgr ?\| )
6080 my-cperl-REx-ctl-face)
6081 ((eq was-subgr ?\$ )
6082 (if (> (point) (1+ REx-subgr-start))
6085 (match-beginning 0) (point)
6088 (if (and (eq (match-beginning 0)
6092 font-lock-variable-name-face)
6093 my-cperl-REx-spec-char-face))
6094 ((memq was-subgr (append "^." nil) )
6095 my-cperl-REx-spec-char-face)
6096 ((eq was-subgr ?\( )
6097 (if (not (match-beginning 10))
6098 my-cperl-REx-ctl-face
6099 my-cperl-REx-0length-face))
6100 (t my-cperl-REx-0length-face)))
6101 (if (and (memq was-subgr (append "(|" nil))
6102 (not (string-match "(\\?[-imsx]+)"
6104 (cperl-look-at-leading-count is-x-REx e))
6105 (setq was-subgr nil)) ; We do stuff here
6106 ((match-beginning 12) ; \SYMBOL
6110 ;; How many chars to not highlight:
6111 ;; 0-len special-alnums in other branch =>
6112 ;; Generic: \non-alnum (1), \alnum (1+face)
6113 ;; Is-delim: \non-alnum (1/spec-2) alnum-1 (=what hai)
6114 (setq REx-subgr-start (point)
6115 qtag (preceding-char))
6116 (cperl-postpone-fontification
6117 (- (point) 2) (- (point) 1) 'face
6119 (append "ghijkmoqvFHIJKMORTVY" nil))
6120 font-lock-warning-face
6121 my-cperl-REx-0length-face))
6122 (if (and (eq (char-after b) qtag)
6123 (memq qtag (append ".])^$|*?+" nil)))
6125 (if (and cperl-use-syntax-table-text-property
6128 REx-subgr-start (1- (point))
6129 'syntax-table cperl-st-punct))
6130 (cperl-postpone-fontification
6131 (1- (point)) (point) 'face
6132 ; \] can't appear below
6133 (if (memq qtag (append ".]^$" nil))
6134 'my-cperl-REx-spec-char-face
6135 (if (memq qtag (append "*?+" nil))
6136 'my-cperl-REx-0length-face
6137 'my-cperl-REx-ctl-face))))) ; )|
6138 ;; Test for arguments:
6140 ;; This is not pretty: the 5.8.7 logic:
6141 ;; \0numx -> octal (up to total 3 dig)
6142 ;; \DIGIT -> backref unless \0
6143 ;; \DIGITs -> backref if legal
6144 ;; otherwise up to 3 -> octal
6145 ;; Do not try to distinguish, we guess
6146 ((or (and (memq qtag (append "01234567" nil))
6148 "\\=[01234567]?[01234567]?"
6150 (and (memq qtag (append "89" nil))
6152 "\\=[0123456789]*" (1- e) 'to-end))
6155 "\\=[0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}"
6157 (and (memq qtag (append "pPN" nil))
6158 (re-search-forward "\\={[^{}]+}\\|."
6160 (eq (char-syntax qtag) ?w))
6161 (cperl-postpone-fontification
6162 (1- REx-subgr-start) (point)
6163 'face my-cperl-REx-length1-face))))
6164 (setq was-subgr nil)) ; We do stuff here
6165 ((match-beginning 3) ; [charclass]
6166 ;; Highlight leader, trailer, POSIX classes
6168 (if (eq (char-after b) ?^ )
6169 (and (eq (following-char) ?\\ )
6170 (eq (char-after (cperl-1+ (point)))
6173 (and (eq (following-char) ?^ )
6175 (setq argument b ; continue? & end of last POSIX
6176 tag nil ; list of POSIX classes
6177 qtag (point)) ; after leading ^ if present
6178 (if (eq (char-after b) ?\] )
6179 (and (eq (following-char) ?\\ )
6180 (eq (char-after (cperl-1+ (point)))
6182 (setq qtag (1+ qtag))
6184 (and (eq (following-char) ?\] )
6186 (setq REx-subgr-end qtag) ;EndOf smart-highlighed
6187 ;; Apparently, I can't put \] into a charclass
6188 ;; in m]]: m][\\\]\]] produces [\\]]
6189 ;;; POSIX? [:word:] [:^word:] only inside []
6190 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]")
6191 (while ; look for unescaped ]
6194 (if (eq (char-after b) ?\] )
6195 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]"
6196 "\\=\\(\\\\.\\|[^]\\\\]\\)*]")
6198 ;; Is this ] an end of POSIX class?
6201 (search-backward "[" argument t)
6202 (< REx-subgr-start (point))
6203 (setq argument (point)) ; POSIX-start
6204 (or ; Should work with delim = \
6205 (not (eq (preceding-char) ?\\ ))
6206 ;; XXXX Double \\ is needed with 19.33
6207 (= (% (skip-chars-backward "\\\\") 2) 0))
6210 ((eq (char-after b) ?\] )
6211 "\\\\*\\[:\\^?\\sw+:\\\\\\]")
6212 ((eq (char-after b) ?\: )
6213 "\\\\*\\[\\\\:\\^?\\sw+\\\\:]")
6214 ((eq (char-after b) ?^ )
6215 "\\\\*\\[:\\(\\\\\\^\\)?\\sw+:\]")
6216 ((eq (char-syntax (char-after b))
6219 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\"
6220 (char-to-string (char-after b))
6222 (t "\\\\*\\[:\\^?\\sw*:]")))
6223 (goto-char REx-subgr-end)
6224 (cperl-highlight-charclass
6225 argument my-cperl-REx-spec-char-face
6226 my-cperl-REx-0length-face my-cperl-REx-length1-face)))
6227 (setq tag (cons (cons argument (point))
6230 REx-subgr-end argument) ; continue
6231 (setq argument nil)))
6233 (message "Couldn't find end of charclass in a REx, pos=%s"
6235 (setq argument (1- (point)))
6236 (goto-char REx-subgr-end)
6237 (cperl-highlight-charclass
6238 argument my-cperl-REx-spec-char-face
6239 my-cperl-REx-0length-face my-cperl-REx-length1-face)
6241 ;; Highlight starter, trailer, POSIX
6242 (if (and cperl-use-syntax-table-text-property
6243 (> (- (point) 2) REx-subgr-start))
6245 (1+ REx-subgr-start) (1- (point))
6246 'syntax-table cperl-st-punct))
6247 (cperl-postpone-fontification
6248 REx-subgr-start qtag
6249 'face my-cperl-REx-spec-char-face)
6250 (cperl-postpone-fontification
6251 (1- (point)) (point) 'face
6252 my-cperl-REx-spec-char-face)
6253 (if (eq (char-after b) ?\] )
6254 (cperl-postpone-fontification
6255 (- (point) 2) (1- (point))
6256 'face my-cperl-REx-0length-face))
6258 (cperl-postpone-fontification
6259 (car (car tag)) (cdr (car tag))
6260 'face font-lock-variable-name-face) ;my-cperl-REx-length1-face
6261 (setq tag (cdr tag)))
6262 (setq was-subgr nil)) ; did facing already
6264 ((and (match-beginning 2) ; #-comment
6265 (/= (match-beginning 2) (match-end 2)))
6266 (beginning-of-line 2)
6268 (goto-char (1- e))))
6269 ((match-beginning 4) ; character "]"
6270 (setq was-subgr nil) ; We do stuff here
6271 (goto-char (match-end 0))
6272 (if cperl-use-syntax-table-text-property
6274 (1- (point)) (point)
6275 'syntax-table cperl-st-punct))
6276 (cperl-postpone-fontification
6277 (1- (point)) (point)
6278 'face font-lock-warning-face))
6279 ((match-beginning 5) ; before (?{}) (??{})
6280 (setq tag (match-end 0))
6282 (cperl-forward-group-in-re st-l))
6284 (setq qtag "no matching `)' found"))
6285 (and (not (eq (char-after (- (point) 2))
6287 (setq qtag "Can't find })")))
6291 (cperl-postpone-fontification
6292 (1- tag) (1- (point))
6293 'face font-lock-variable-name-face)
6294 (cperl-postpone-fontification
6295 REx-subgr-start (1- tag)
6296 'face my-cperl-REx-spec-char-face)
6297 (cperl-postpone-fontification
6298 (1- (point)) (point)
6299 'face my-cperl-REx-spec-char-face)
6300 (if cperl-use-syntax-table-text-property
6303 (- (point) 2) (1- (point))
6304 'syntax-table cperl-st-cfence)
6306 (+ REx-subgr-start 2)
6307 (+ REx-subgr-start 3)
6308 'syntax-table cperl-st-cfence))))
6309 (setq was-subgr nil))
6311 ;; Inside "(" and "\" arn't special in any way
6312 ;; Works also if the outside delimiters are ().
6313 (or;;(if (eq (char-after b) ?\) )
6314 ;;(re-search-forward
6315 ;; "[^\\\\]\\(\\\\\\\\\\)*\\\\)"
6317 (search-forward ")" (1- e) 'toend)
6320 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
6326 (setq REx-subgr-end (point))
6328 REx-subgr-start REx-subgr-end nil)
6329 (cperl-postpone-fontification
6330 REx-subgr-start REx-subgr-end
6331 'face font-lock-comment-face))))))
6332 (if (and is-REx is-x-REx)
6333 (put-text-property (1+ b) (1- e)
6334 'syntax-subtype 'x-REx)))
6335 (if (and i2 e1 (or (not b1) (> e1 b1)))
6336 (progn ; No errors finding the second part...
6337 (cperl-postpone-fontification
6338 (1- e1) e1 'face my-cperl-delimiters-face)
6339 (if (assoc (char-after b) cperl-starters)
6341 (cperl-postpone-fontification
6342 b1 (1+ b1) 'face my-cperl-delimiters-face)
6343 (put-text-property b1 (1+ b1)
6347 ((match-beginning 17) ; sub with prototype or attribute
6348 ;; 1+6+2+1+1=11 extra () before this (sub with proto/attr):
6349 ;;"\\<sub\\>\\(" ;12
6350 ;; cperl-white-and-comment-rex ;13
6351 ;; "\\([a-zA-Z_:'0-9]+\\)\\)?" ; name ;14
6352 ;;"\\(" cperl-maybe-white-and-comment-rex ;15,16
6353 ;; "\\(([^()]*)\\|:[^:]\\)\\)" ; 17:proto or attribute start
6354 (setq b1 (match-beginning 14) e1 (match-end 14))
6355 (if (memq (char-after (1- b))
6356 '(?\$ ?\@ ?\% ?\& ?\*))
6359 (if (eq (char-after (match-beginning 17)) ?\( )
6361 (cperl-commentify ; Prototypes; mark as string
6362 (match-beginning 17) (match-end 17) t)
6363 (goto-char (match-end 0))
6364 ;; Now look for attributes after prototype:
6365 (forward-comment (buffer-size))
6366 (and (looking-at ":[^:]")
6367 (cperl-find-sub-attrs st-l b1 e1 b)))
6368 ;; treat attributes without prototype
6369 (goto-char (match-beginning 17))
6370 (cperl-find-sub-attrs st-l b1 e1 b))))
6371 ;; 1+6+2+1+1+6+1=18 extra () before this:
6372 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
6373 ((match-beginning 19) ; old $abc'efg syntax
6374 (setq bb (match-end 0))
6375 ;;;(if (nth 3 state) nil ; in string
6376 (put-text-property (1- bb) bb 'syntax-table cperl-st-word)
6378 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
6379 ;; "__\\(END\\|DATA\\)__"
6380 ((match-beginning 20) ; __END__, __DATA__
6381 (setq bb (match-end 0))
6382 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
6383 (cperl-commentify b bb nil)
6385 ;; "\\\\\\(['`\"($]\\)"
6386 ((match-beginning 21)
6387 ;; Trailing backslash; make non-quoting outside string/comment
6388 (setq bb (match-end 0))
6390 (skip-chars-backward "\\\\")
6391 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
6392 (cperl-modify-syntax-type b cperl-st-punct)
6394 (t (error "Error in regexp of the sniffer")))
6395 (if (> (point) stop-point)
6398 (message "Garbage after __END__/__DATA__ ignored")
6399 (message "Unbalanced syntax found while scanning")
6400 (or (car err-l) (setcar err-l b)))
6401 (goto-char stop-point))))
6402 (setq cperl-syntax-state (cons state-point state)
6403 ;; Do not mark syntax as done past tmpend???
6404 cperl-syntax-done-to (or tmpend (max (point) max)))
6405 ;;(message "state-at=%s, done-to=%s" state-point cperl-syntax-done-to)
6407 (if (car err-l) (goto-char (car err-l))
6409 (message "Scanning for \"hard\" Perl constructions... done"))))
6410 (and (buffer-modified-p)
6412 (set-buffer-modified-p nil))
6413 (set-syntax-table cperl-mode-syntax-table))
6414 (list (car err-l) overshoot)))
6416 (defun cperl-find-pods-heres-region (min max)
6418 (cperl-find-pods-heres min max))
6420 (defun cperl-backward-to-noncomment (lim)
6421 ;; Stops at lim or after non-whitespace that is not in comment
6422 ;; XXXX Wrongly understands end-of-multiline strings with # as comment
6424 (while (and (not stop) (> (point) (or lim (point-min))))
6425 (skip-chars-backward " \t\n\f" lim)
6428 (if (memq (setq pr (get-text-property (point) 'syntax-type))
6429 '(pod here-doc here-doc-delim))
6431 (cperl-unwind-to-safe nil)
6432 (setq pr (get-text-property (point) 'syntax-type))))
6433 (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
6434 (not (memq pr '(string prestring))))
6435 (progn (cperl-to-comment-or-eol) (bolp))
6437 (skip-chars-backward " \t")
6438 (if (< p (point)) (goto-char p))
6441 ;; Used only in `cperl-calculate-indent'...
6442 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
6443 ;; Positions is before ?\{. Checks whether it starts a block.
6444 ;; No save-excursion! This is more a distinguisher of a block/hash ref...
6445 (cperl-backward-to-noncomment (point-min))
6446 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
6447 ; Label may be mixed up with `$blah :'
6448 (save-excursion (cperl-after-label))
6449 (get-text-property (cperl-1- (point)) 'attrib-group)
6450 (and (memq (char-syntax (preceding-char)) '(?w ?_))
6453 ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
6454 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
6455 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
6456 ;; sub bless::foo {}
6458 (cperl-backward-to-noncomment (point-min))
6459 (and (eq (preceding-char) ?b)
6462 (looking-at "sub[ \t\n\f#]")))))))))
6464 ;;; What is the difference of (cperl-after-block-p lim t) and (cperl-block-p)?
6465 ;;; No save-excursion; condition-case ... In (cperl-block-p) the block
6466 ;;; may be a part of an in-statement construct, such as
6467 ;;; ${something()}, print {FH} $data.
6468 ;;; Moreover, one takes positive approach (looks for else,grep etc)
6469 ;;; another negative (looks for bless,tr etc)
6470 (defun cperl-after-block-p (lim &optional pre-block)
6471 "Return true if the preceeding } (if PRE-BLOCK, following {) delimits a block.
6472 Would not look before LIM. Assumes that LIM is a good place to begin a
6473 statement. The kind of block we treat here is one after which a new
6474 statement would start; thus the block in ${func()} does not count."
6478 (or pre-block (forward-sexp -1))
6479 (cperl-backward-to-noncomment lim)
6480 (or (eq (point) lim)
6481 ;; if () {} // sub f () {} // sub f :a(') {}
6482 (eq (preceding-char) ?\) )
6484 (save-excursion (cperl-after-label))
6486 (get-text-property (cperl-1- (point)) 'attrib-group)
6487 (if (memq (char-syntax (preceding-char)) '(?w ?_)) ; else {}
6490 ;; else {} but not else::func {}
6491 (or (and (looking-at "\\(else\\|continue\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
6492 (not (looking-at "\\(\\sw\\|_\\)+::")))
6495 (cperl-backward-to-noncomment lim)
6496 (and (eq (preceding-char) ?b)
6499 (looking-at "sub[ \t\n\f#]"))))))
6500 ;; What preceeds is not word... XXXX Last statement in sub???
6501 (cperl-after-expr-p lim))))
6504 (defun cperl-after-expr-p (&optional lim chars test)
6505 "Return true if the position is good for start of expression.
6506 TEST is the expression to evaluate at the found position. If absent,
6507 CHARS is a string that contains good characters to have before us (however,
6508 `}' is treated \"smartly\" if it is not in the list)."
6509 (let ((lim (or lim (point-min)))
6511 (cperl-update-syntaxification (point) (point))
6513 (while (and (not stop) (> (point) lim))
6514 (skip-chars-backward " \t\n\f" lim)
6517 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
6518 ;; '(pod here-doc here-doc-delim))
6519 (if (get-text-property (point) 'here-doc-group)
6522 (cperl-beginning-of-property (point) 'here-doc-group))
6523 (beginning-of-line 0)))
6524 (if (get-text-property (point) 'in-pod)
6527 (cperl-beginning-of-property (point) 'in-pod))
6528 (beginning-of-line 0)))
6529 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
6530 ;; Else: last iteration, or a label
6531 (cperl-to-comment-or-eol) ; Will not move past "." after a format
6532 (skip-chars-backward " \t")
6533 (if (< p (point)) (goto-char p))
6535 (if (and (eq (preceding-char) ?:)
6538 (skip-chars-backward " \t\n\f" lim)
6539 (memq (char-syntax (preceding-char)) '(?w ?_))))
6540 (forward-sexp -1) ; Possibly label. Skip it
6543 (or (bobp) ; ???? Needed
6545 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
6547 (if test (eval test)
6548 (or (memq (preceding-char) (append (or chars "{;") nil))
6549 (and (eq (preceding-char) ?\})
6550 (cperl-after-block-p lim))
6551 (and (eq (following-char) ?.) ; in format: see comment above
6552 (eq (get-text-property (point) 'syntax-type)
6555 (defun cperl-backward-to-start-of-expr (&optional lim)
6558 (while (and (or (not lim)
6560 (not (cperl-after-expr-p lim)))
6562 ;; May be after $, @, $# etc of a variable
6563 (skip-chars-backward "$@%#")))
6566 (defun cperl-at-end-of-expr (&optional lim)
6567 ;; Since the SEXP approach below is very fragile, do some overengineering
6568 (or (looking-at (concat cperl-maybe-white-and-comment-rex "[;}]"))
6571 ;; If nothing interesting after, does as (forward-sexp -1);
6572 ;; otherwise fails, or ends at a start of following sexp.
6573 ;; XXXX PROBLEMS: if what follows (after ";") @FOO, or ${bar}
6574 ;; may be stuck after @ or $; just put some stupid workaround now:
6578 (while (memq (preceding-char) (append "%&@$*" nil))
6581 (cperl-after-expr-p lim))))
6584 (defun cperl-forward-to-end-of-expr (&optional lim)
6588 (while (and (< (point) (or lim (point-max)))
6589 (not (cperl-at-end-of-expr)))
6593 (defun cperl-backward-to-start-of-continued-exp (lim)
6594 (if (memq (preceding-char) (append ")]}\"'`" nil))
6597 (if (<= (point) lim)
6598 (goto-char (1+ lim)))
6599 (skip-chars-forward " \t"))
6601 (defun cperl-after-block-and-statement-beg (lim)
6602 ;; We assume that we are after ?\}
6604 (cperl-after-block-p lim)
6607 (cperl-backward-to-noncomment (point-min))
6610 (not (= (char-syntax (preceding-char)) ?w))
6615 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
6618 (defvar innerloop-done nil)
6619 (defvar last-depth nil)
6621 (defun cperl-indent-exp ()
6622 "Simple variant of indentation of continued-sexp.
6624 Will not indent comment if it starts at `comment-indent' or looks like
6625 continuation of the comment on the previous line.
6627 If `cperl-indent-region-fix-constructs', will improve spacing on
6628 conditional/loop constructs."
6631 (let ((tmp-end (progn (end-of-line) (point))) top done)
6636 ;; Plan A: if line has an unfinished paren-group, go to end-of-group
6637 (while (= -1 (nth 0 (parse-partial-sexp (point) tmp-end -1)))
6638 (setq top (point))) ; Get the outermost parenths in line
6640 (while (< (point) tmp-end)
6641 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
6642 (or (eolp) (forward-sexp 1)))
6643 (if (> (point) tmp-end) ; Yes, there an unfinished block
6645 (if (eq ?\) (preceding-char))
6646 (progn ;; Plan B: find by REGEXP block followup this line
6651 (if (eq (following-char) ?$ ) ; for my $var (list)
6654 (if (looking-at "\\(my\\|local\\|our\\)\\>")
6655 (forward-sexp -1))))
6657 (concat "\\(\\elsif\\|if\\|unless\\|while\\|until"
6658 "\\|for\\(each\\)?\\>\\(\\("
6659 cperl-maybe-white-and-comment-rex
6660 "\\(my\\|local\\|our\\)\\)?"
6661 cperl-maybe-white-and-comment-rex
6662 "\\$[_a-zA-Z0-9]+\\)?\\)\\>"))
6666 (setq top (point)))))
6667 (error (setq done t)))
6669 (if (looking-at ; Try Plan C: continuation block
6670 (concat cperl-maybe-white-and-comment-rex
6671 "\\<\\(else\\|elsif\|continue\\)\\>"))
6673 (goto-char (match-end 0))
6676 (setq tmp-end (point))))
6680 (setq tmp-end (point))))
6682 (setq tmp-end (point-marker)))
6683 (if cperl-indent-region-fix-constructs
6684 (cperl-fix-line-spacing tmp-end))
6685 (cperl-indent-region (point) tmp-end))))
6687 (defun cperl-fix-line-spacing (&optional end parse-data)
6688 "Improve whitespace in a conditional/loop construct.
6689 Returns some position at the last line."
6692 (setq end (point-max)))
6693 (let ((ee (save-excursion (end-of-line) (point)))
6694 (cperl-indent-region-fix-constructs
6695 (or cperl-indent-region-fix-constructs 1))
6696 p pp ml have-brace ret)
6703 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
6704 (setq have-brace (save-excursion (search-forward "}" ee t)))))
6705 nil ; Do not need to do anything
6709 (if cperl-merge-trailing-else
6711 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
6713 (search-forward "}")
6715 (skip-chars-forward " \t\n")
6716 (delete-region p (point))
6717 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6718 (beginning-of-line)))
6719 (if (looking-at "[ \t]*}[ \t]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
6721 (search-forward "}")
6722 (delete-horizontal-space)
6725 (if (cperl-indent-line parse-data)
6727 (cperl-fix-line-spacing end parse-data)
6728 (setq ret (point)))))))
6731 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
6733 (search-forward "}")
6734 (delete-horizontal-space)
6735 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6736 (beginning-of-line)))
6740 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
6743 (delete-horizontal-space)
6744 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6745 (beginning-of-line)))
6749 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
6752 (delete-horizontal-space)
6753 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6754 (beginning-of-line)))
6756 ;; foreach my $var (
6758 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
6761 (delete-horizontal-space)
6763 (make-string cperl-indent-region-fix-constructs ?\ ))
6764 (beginning-of-line)))
6765 ;; Looking at (with or without "}" at start, ending after "({"):
6766 ;; } foreach my $var () OR {
6768 "[ \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]*{")
6770 (setq ml (match-beginning 8)) ; "(" or "{" after control word
6771 (re-search-forward "[({]")
6774 (if (eq (following-char) ?\( )
6777 (setq pp (point))) ; past parenth-group
6778 ;; after `else' or nothing
6779 (if ml ; after `else'
6780 (skip-chars-backward " \t\n")
6781 (beginning-of-line))
6783 ;; Now after the sexp before the brace
6784 ;; Multiline expr should be special
6785 (setq ml (and pp (save-excursion (goto-char p)
6786 (search-forward "\n" pp t))))
6787 (if (and (or (not pp) (< pp end)) ; Do not go too far...
6788 (looking-at "[ \t\n]*{"))
6791 ((bolp) ; Were before `{', no if/else/etc
6793 ((looking-at "\\(\t*\\| [ \t]+\\){") ; Not exactly 1 SPACE
6794 (delete-horizontal-space)
6796 cperl-extra-newline-before-brace-multiline
6797 cperl-extra-newline-before-brace)
6799 (delete-horizontal-space)
6802 (if (cperl-indent-line parse-data)
6804 (cperl-fix-line-spacing end parse-data)
6805 (setq ret (point)))))
6807 (make-string cperl-indent-region-fix-constructs ?\ ))))
6808 ((and (looking-at "[ \t]*\n")
6810 cperl-extra-newline-before-brace-multiline
6811 cperl-extra-newline-before-brace)))
6813 (skip-chars-forward " \t\n")
6814 (delete-region pp (point))
6816 (make-string cperl-indent-region-fix-constructs ?\ )))
6817 ((and (looking-at "[\t ]*{")
6818 (if ml cperl-extra-newline-before-brace-multiline
6819 cperl-extra-newline-before-brace))
6820 (delete-horizontal-space)
6823 (if (cperl-indent-line parse-data)
6825 (cperl-fix-line-spacing end parse-data)
6826 (setq ret (point))))))
6827 ;; Now we are before `{'
6828 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
6830 (skip-chars-forward " \t\n")
6835 (setq ml (search-forward "\n" p t))
6836 (if (or cperl-break-one-line-blocks-when-indent ml)
6837 ;; not good: multi-line BLOCK
6840 (delete-horizontal-space)
6843 (if (cperl-indent-line parse-data)
6844 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
6846 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
6847 ;; Now check whether there is a hanging `}'
6851 cperl-fix-hanging-brace-when-indent
6853 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
6857 (if (and (<= (point) pp)
6858 (eq (preceding-char) ?\} )
6859 (cperl-after-block-and-statement-beg (point-min)))
6866 (skip-chars-backward " \t")
6868 ;; `}' was the first thing on the line, insert NL *after* it.
6870 (cperl-indent-line parse-data)
6871 (search-forward "}")
6872 (delete-horizontal-space)
6874 (delete-horizontal-space)
6875 (or (eq (preceding-char) ?\;)
6877 (and (eq (preceding-char) ?\} )
6878 (cperl-after-block-p (point-min)))
6882 (if (cperl-indent-line parse-data)
6883 (setq ret (cperl-fix-line-spacing end parse-data)))
6884 (beginning-of-line)))))
6887 (defvar cperl-update-start) ; Do not need to make them local
6888 (defvar cperl-update-end)
6889 (defun cperl-delay-update-hook (beg end old-len)
6890 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
6891 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
6893 (defun cperl-indent-region (start end)
6894 "Simple variant of indentation of region in CPerl mode.
6895 Should be slow. Will not indent comment if it starts at `comment-indent'
6896 or looks like continuation of the comment on the previous line.
6897 Indents all the lines whose first character is between START and END
6900 If `cperl-indent-region-fix-constructs', will improve spacing on
6901 conditional/loop constructs."
6903 (cperl-update-syntaxification end end)
6905 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
6906 (let ((indent-info (if cperl-emacs-can-parse
6907 (list nil nil nil) ; Cannot use '(), since will modify
6909 (pm 0) (imenu-scanning-message "Indenting... (%3d%%)")
6910 after-change-functions ; Speed it up!
6911 st comm old-comm-indent new-comm-indent p pp i empty)
6912 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
6914 (setq old-comm-indent (and (cperl-to-comment-or-eol)
6916 new-comm-indent old-comm-indent)
6918 (setq end (set-marker (make-marker) end)) ; indentation changes pos
6919 (or (bolp) (beginning-of-line 2))
6920 (or (fboundp 'imenu-progress-message)
6921 (message "Indenting... For feedback load `imenu'..."))
6922 (while (and (<= (point) end) (not (eobp))) ; bol to check start
6923 (and (fboundp 'imenu-progress-message)
6924 (imenu-progress-message
6925 pm (/ (* 100 (- (point) start)) (- end start -1))))
6928 (setq empty (looking-at "[ \t]*\n"))
6929 (and (setq comm (looking-at "[ \t]*#"))
6930 (or (eq (current-indentation) (or old-comm-indent
6932 (setq old-comm-indent nil))))
6933 (if (and old-comm-indent
6935 (= (current-indentation) old-comm-indent)
6936 (not (eq (get-text-property (point) 'syntax-type) 'pod))
6937 (not (eq (get-text-property (point) 'syntax-table)
6939 (let ((comment-column new-comm-indent))
6940 (indent-for-comment)))
6942 (setq i (cperl-indent-line indent-info))
6946 (if cperl-indent-region-fix-constructs
6947 (goto-char (cperl-fix-line-spacing end indent-info)))
6948 (if (setq old-comm-indent
6949 (and (cperl-to-comment-or-eol)
6950 (not (memq (get-text-property (point)
6953 (not (eq (get-text-property (point)
6957 (progn (indent-for-comment)
6958 (skip-chars-backward " \t")
6959 (skip-chars-backward "#")
6960 (setq new-comm-indent (current-column))))))))
6961 (beginning-of-line 2))
6962 (if (fboundp 'imenu-progress-message)
6963 (imenu-progress-message pm 100)
6965 ;; Now run the update hooks
6966 (and after-change-functions
6969 (goto-char cperl-update-end)
6972 (goto-char cperl-update-start)
6974 (delete-char -1))))))
6976 ;; Stolen from lisp-mode with a lot of improvements
6977 (defun cperl-fill-paragraph (&optional justify iteration)
6978 "Like \\[fill-paragraph], but handle CPerl comments.
6979 If any of the current line is a comment, fill the comment or the
6980 block of it that point is in, preserving the comment's initial
6981 indentation and initial hashes. Behaves usually outside of comment."
6983 (let (;; Non-nil if the current line contains a comment.
6985 fill-paragraph-function ; do not recurse
6986 ;; If has-comment, the appropriate fill-prefix for the comment.
6988 ;; Line that contains code and comment (or nil)
6990 c spaces len dc (comment-column comment-column))
6991 ;; Figure out what kind of comment we are looking at.
6996 ;; A line with nothing but a comment on it?
6997 ((looking-at "[ \t]*#[# \t]*")
6999 comment-fill-prefix (buffer-substring (match-beginning 0)
7002 ;; A line with some code, followed by a comment? Remember that the
7003 ;; semi which starts the comment shouldn't be part of a string or
7005 ((cperl-to-comment-or-eol)
7006 (setq has-comment t)
7007 (looking-at "#+[ \t]*")
7008 (setq start (point) c (current-column)
7010 (concat (make-string (current-column) ?\ )
7011 (buffer-substring (match-beginning 0) (match-end 0)))
7012 spaces (progn (skip-chars-backward " \t")
7013 (buffer-substring (point) start))
7014 dc (- c (current-column)) len (- start (point))
7015 start (point-marker))
7017 (insert (make-string dc ?-))))) ; Placeholder (to avoid splitting???)
7018 (if (not has-comment)
7019 (fill-paragraph justify) ; Do the usual thing outside of comment
7020 ;; Narrow to include only the comment, and then fill the region.
7023 ;; Find the first line we should include in the region to fill.
7024 (if start (progn (beginning-of-line) (point))
7026 (while (and (zerop (forward-line -1))
7027 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
7028 ;; We may have gone to far. Go forward again.
7029 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
7032 ;; Find the beginning of the first line past the region to fill.
7034 (while (progn (forward-line 1)
7035 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
7037 ;; Remove existing hashes
7038 (goto-char (point-min))
7039 (save-excursion ; By some strange reason:needed in 22.1
7040 (while (progn (forward-line 1) (< (point) (point-max)))
7041 (skip-chars-forward " \t")
7042 (if (looking-at "#+")
7044 (if (and (eq (point) (match-beginning 0))
7045 (not (eq (point) (match-end 0)))) nil
7047 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage"))
7048 (delete-char (- (match-end 0) (match-beginning 0)))))))
7050 ;; Lines with only hashes on them can be paragraph boundaries.
7051 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
7052 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
7053 (fill-prefix comment-fill-prefix))
7054 (fill-paragraph justify)))
7059 (progn (delete-char dc) (insert spaces)))
7060 (if (or (= (current-column) c) iteration) nil
7061 (setq comment-column c)
7062 (indent-for-comment)
7063 ;; Repeat once more, flagging as iteration
7064 (cperl-fill-paragraph justify t))))))
7067 (defun cperl-do-auto-fill ()
7068 ;; Break out if the line is short enough
7069 (if (> (save-excursion
7073 (let ((c (save-excursion (beginning-of-line)
7074 (cperl-to-comment-or-eol) (point)))
7075 (s (memq (following-char) '(?\ ?\t))) marker)
7076 (if (>= c (point)) nil
7077 (setq marker (point-marker))
7078 (cperl-fill-paragraph)
7080 ;; Is not enough, sometimes marker is a start of line
7081 (if (bolp) (progn (re-search-forward "#+[ \t]*")
7082 (goto-char (match-end 0))))
7083 ;; Following space could have gone:
7084 (if (or (not s) (memq (following-char) '(?\ ?\t))) nil
7087 ;; Previous space could have gone:
7088 (or (memq (preceding-char) '(?\ ?\t)) (insert " "))))))
7090 (defun cperl-imenu-addback (lst &optional isback name)
7091 ;; We suppose that the lst is a DAG, unless the first element only
7092 ;; loops back, and ISBACK is set. Thus this function cannot be
7093 ;; applied twice without ISBACK set.
7094 (cond ((not cperl-imenu-addback) lst)
7097 (setq name "+++BACK+++"))
7098 (mapcar (lambda (elt)
7099 (if (and (listp elt) (listp (cdr elt)))
7101 ;; In the other order it goes up
7102 ;; one level only ;-(
7103 (setcdr elt (cons (cons name lst)
7105 (cperl-imenu-addback (cdr elt) t name))))
7106 (if isback (cdr lst) lst))
7109 (defun cperl-imenu--create-perl-index (&optional regexp)
7111 (require 'imenu) ; May be called from TAGS creator
7112 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
7113 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
7114 (index-meth-alist '()) meth
7115 packages ends-ranges p marker is-proto
7116 (prev-pos 0) is-pack index index1 name (end-range 0) package)
7117 (goto-char (point-min))
7119 (message "Scanning Perl for index")
7120 (imenu-progress-message prev-pos 0))
7121 (cperl-update-syntaxification (point-max) (point-max))
7122 ;; Search for the function
7123 (progn ;;save-match-data
7124 (while (re-search-forward
7125 (or regexp cperl-imenu--function-name-regexp-perl)
7128 (imenu-progress-message prev-pos))
7129 ;; 2=package-group, 5=package-name 8=sub-name
7131 ((and ; Skip some noise if building tags
7132 (match-beginning 5) ; package name
7133 ;;(eq (char-after (match-beginning 2)) ?p) ; package
7134 (not (save-match-data
7135 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
7138 (or (match-beginning 2)
7139 (match-beginning 8)) ; package or sub
7140 ;; Skip if quoted (will not skip multi-line ''-strings :-():
7141 (null (get-text-property (match-beginning 1) 'syntax-table))
7142 (null (get-text-property (match-beginning 1) 'syntax-type))
7143 (null (get-text-property (match-beginning 1) 'in-pod)))
7144 (setq is-pack (match-beginning 2))
7145 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
7146 ;; (goto-char (match-end 0))) ; Messes what follows
7149 (while (and ends-ranges (>= p (car ends-ranges)))
7150 ;; delete obsolete entries
7151 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
7152 (setq package (or (car packages) "")
7153 end-range (or (car ends-ranges) 0))
7154 (if is-pack ; doing "package"
7156 (if (match-beginning 5) ; named package
7157 (setq name (buffer-substring (match-beginning 5)
7160 (set-text-properties 0 (length name) nil name)
7162 package (concat name "::")
7163 name (concat "package " name))
7164 ;; Support nameless packages
7165 (setq name "package;" package ""))
7168 (parse-partial-sexp (point) (point-max) -1) (point))
7169 ends-ranges (cons end-range ends-ranges)
7170 packages (cons package packages)))
7172 (or (eq (following-char) ?\;)
7173 (eq 0 (get-text-property (point) 'attrib-group)))))
7174 ;; Skip this function name if it is a prototype declaration.
7175 (if (and is-proto (not is-pack)) nil
7178 (buffer-substring (match-beginning 8) (match-end 8)))
7179 (set-text-properties 0 (length name) nil name))
7180 (setq marker (make-marker))
7181 (set-marker marker (match-end (if is-pack 2 8)))
7183 ((string-match "[:']" name)
7185 ((> p end-range) nil)
7187 (setq name (concat package name) meth t)))
7188 (setq index (cons name marker))
7190 (push index index-pack-alist)
7191 (push index index-alist))
7192 (if meth (push index index-meth-alist))
7193 (push index index-unsorted-alist)))
7194 ((match-beginning 16) ; POD section
7195 (setq name (buffer-substring (match-beginning 17) (match-end 17))
7196 marker (make-marker))
7197 (set-marker marker (match-beginning 17))
7198 (set-text-properties 0 (length name) nil name)
7199 (setq name (concat (make-string
7200 (* 3 (- (char-after (match-beginning 16)) ?1))
7203 index (cons name marker))
7204 (setq index1 (cons (concat "=" name) (cdr index)))
7205 (push index index-pod-alist)
7206 (push index1 index-unsorted-alist)))))
7208 (imenu-progress-message prev-pos 100))
7210 (if (default-value 'imenu-sort-function)
7211 (sort index-alist (default-value 'imenu-sort-function))
7212 (nreverse index-alist)))
7213 (and index-pod-alist
7214 (push (cons "+POD headers+..."
7215 (nreverse index-pod-alist))
7217 (and (or index-pack-alist index-meth-alist)
7218 (let ((lst index-pack-alist) hier-list pack elt group name)
7219 ;; Remove "package ", reverse and uniquify.
7221 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
7222 (if (assoc name hier-list) nil
7223 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
7224 (setq lst index-meth-alist)
7226 (setq elt (car lst) lst (cdr lst))
7227 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
7228 (setq pack (substring (car elt) 0 (match-beginning 0)))
7229 (if (setq group (assoc pack hier-list))
7230 (if (listp (cdr group))
7231 ;; Have some functions already
7233 (cons (cons (substring
7235 (+ 2 (match-beginning 0)))
7238 (setcdr group (list (cons (substring
7240 (+ 2 (match-beginning 0)))
7244 (list (cons (substring
7246 (+ 2 (match-beginning 0)))
7249 (push (cons "+Hierarchy+..."
7252 (and index-pack-alist
7253 (push (cons "+Packages+..."
7254 (nreverse index-pack-alist))
7256 (and (or index-pack-alist index-pod-alist
7257 (default-value 'imenu-sort-function))
7258 index-unsorted-alist
7259 (push (cons "+Unsorted List+..."
7260 (nreverse index-unsorted-alist))
7262 (cperl-imenu-addback index-alist)))
7265 ;; Suggested by Mark A. Hershberger
7266 (defun cperl-outline-level ()
7267 (looking-at outline-regexp)
7268 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
7269 ;;;; 2=package-group, 5=package-name 8=sub-name 16=head-level
7270 ((match-beginning 2) 0) ; package
7271 ((match-beginning 8) 1) ; sub
7272 ((match-beginning 16)
7273 (- (char-after (match-beginning 16)) ?0)) ; headN ==> N
7274 (t 5))) ; should not happen
7277 (defvar cperl-compilation-error-regexp-alist
7278 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
7279 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
7281 "Alist that specifies how to match errors in perl output.")
7283 (if (fboundp 'eval-after-load)
7286 '(setq perl-compilation-error-regexp-alist
7287 cperl-compilation-error-regexp-alist)))
7290 (defun cperl-windowed-init ()
7291 "Initialization under windowed version."
7292 (cond ((featurep 'ps-print)
7293 (or cperl-faces-init
7295 (and (boundp 'font-lock-multiline)
7296 (setq cperl-font-lock-multiline t))
7297 (cperl-init-faces))))
7298 ((not cperl-faces-init)
7299 (add-hook 'font-lock-mode-hook
7302 (if (memq major-mode '(perl-mode cperl-mode))
7304 (or cperl-faces-init (cperl-init-faces)))))))
7305 (if (fboundp 'eval-after-load)
7308 '(or cperl-faces-init (cperl-init-faces)))))))
7310 (defun cperl-load-font-lock-keywords ()
7311 (or cperl-faces-init (cperl-init-faces))
7312 perl-font-lock-keywords)
7314 (defun cperl-load-font-lock-keywords-1 ()
7315 (or cperl-faces-init (cperl-init-faces))
7316 perl-font-lock-keywords-1)
7318 (defun cperl-load-font-lock-keywords-2 ()
7319 (or cperl-faces-init (cperl-init-faces))
7320 perl-font-lock-keywords-2)
7322 (defvar perl-font-lock-keywords-1 nil
7323 "Additional expressions to highlight in Perl mode. Minimal set.")
7324 (defvar perl-font-lock-keywords nil
7325 "Additional expressions to highlight in Perl mode. Default set.")
7326 (defvar perl-font-lock-keywords-2 nil
7327 "Additional expressions to highlight in Perl mode. Maximal set.")
7329 (defvar font-lock-background-mode)
7330 (defvar font-lock-display-type)
7331 (defun cperl-init-faces-weak ()
7332 ;; Allow `cperl-find-pods-heres' to run.
7333 (or (boundp 'font-lock-constant-face)
7334 (cperl-force-face font-lock-constant-face
7335 "Face for constant and label names"))
7336 (or (boundp 'font-lock-warning-face)
7337 (cperl-force-face font-lock-warning-face
7338 "Face for things which should stand out"))
7339 ;;(setq font-lock-constant-face 'font-lock-constant-face)
7342 (defun cperl-init-faces ()
7343 (condition-case errs
7345 (require 'font-lock)
7346 (and (fboundp 'font-lock-fontify-anchored-keywords)
7347 (featurep 'font-lock-extra)
7348 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
7349 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
7350 (if (fboundp 'font-lock-fontify-anchored-keywords)
7351 (setq font-lock-anchored t))
7353 t-font-lock-keywords
7355 (list "[ \t]+$" 0 cperl-invalid-face t)
7358 "\\(^\\|[^$@%&\\]\\)\\<\\("
7361 '("if" "until" "while" "elsif" "else" "unless" "for"
7362 "foreach" "continue" "exit" "die" "last" "goto" "next"
7363 "redo" "return" "local" "exec" "sub" "do" "dump" "use" "our"
7364 "require" "package" "eval" "my" "BEGIN" "END" "CHECK" "INIT")
7365 "\\|") ; Flow control
7366 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
7367 ; In what follows we use `type' style
7368 ; for overwritable builtins
7371 "\\(^\\|[^$@%&\\]\\)\\<\\("
7372 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
7373 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
7374 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
7375 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
7376 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
7377 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
7378 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
7379 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
7380 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
7381 ;; "gethostbyname" "gethostent" "getlogin"
7382 ;; "getnetbyaddr" "getnetbyname" "getnetent"
7383 ;; "getpeername" "getpgrp" "getppid" "getpriority"
7384 ;; "getprotobyname" "getprotobynumber" "getprotoent"
7385 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
7386 ;; "getservbyport" "getservent" "getsockname"
7387 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
7388 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
7389 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
7390 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
7391 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
7392 ;; "quotemeta" "rand" "read" "readdir" "readline"
7393 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
7394 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
7395 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
7396 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
7397 ;; "setpriority" "setprotoent" "setpwent" "setservent"
7398 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
7399 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
7400 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
7401 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
7402 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
7403 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
7404 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
7405 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
7406 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
7407 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
7408 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
7409 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
7410 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
7411 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
7412 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
7413 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
7414 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
7415 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
7416 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
7417 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
7418 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
7419 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
7420 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
7421 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
7422 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
7423 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
7424 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
7425 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
7426 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
7427 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
7428 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
7429 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
7430 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
7431 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
7432 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
7433 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
7434 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
7435 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
7436 "\\)\\>") 2 'font-lock-type-face)
7437 ;; In what follows we use `other' style
7438 ;; for nonoverwritable builtins
7439 ;; Somehow 's', 'm' are not auto-generated???
7442 "\\(^\\|[^$@%&\\]\\)\\<\\("
7443 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "chomp"
7444 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
7445 ;; "eval" "exists" "for" "foreach" "format" "goto"
7446 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
7447 ;; "no" "our" "package" "pop" "pos" "print" "printf" "push"
7448 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
7449 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
7450 ;; "undef" "unless" "unshift" "untie" "until" "use"
7452 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
7453 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
7454 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|INIT\\|if\\|keys\\|"
7455 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
7456 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
7457 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
7458 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
7459 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
7460 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
7461 "\\|[sm]" ; Added manually
7462 "\\)\\>") 2 'cperl-nonoverridable-face)
7463 ;; (mapconcat 'identity
7464 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
7465 ;; "#include" "#define" "#undef")
7467 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
7468 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
7469 ;; This highlights declarations and definitions differenty.
7470 ;; We do not try to highlight in the case of attributes:
7471 ;; it is already done by `cperl-find-pods-heres'
7472 (list (concat "\\<sub"
7473 cperl-white-and-comment-rex ; whitespace/comments
7474 "\\([^ \n\t{;()]+\\)" ; 2=name (assume non-anonymous)
7476 cperl-maybe-white-and-comment-rex ;whitespace/comments?
7477 "([^()]*)\\)?" ; prototype
7478 cperl-maybe-white-and-comment-rex ; whitespace/comments?
7480 2 (if cperl-font-lock-multiline
7481 '(if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
7482 'font-lock-function-name-face
7483 'font-lock-variable-name-face)
7484 ;; need to manually set 'multiline' for older font-locks
7486 (if (< 1 (count-lines (match-beginning 0)
7489 (+ 3 (match-beginning 0)) (match-end 0)
7490 'syntax-type 'multiline))
7491 (if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
7492 'font-lock-function-name-face
7493 'font-lock-variable-name-face))))
7494 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
7495 2 font-lock-function-name-face)
7496 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
7497 1 font-lock-function-name-face)
7498 (cond ((featurep 'font-lock-extra)
7499 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7500 (2 font-lock-string-face t)
7501 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
7503 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7504 (2 font-lock-string-face t)
7505 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7507 (1 font-lock-string-face t))))
7508 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7509 2 font-lock-string-face t)))
7510 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
7511 font-lock-string-face t)
7512 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
7513 font-lock-constant-face) ; labels
7514 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
7515 2 font-lock-constant-face)
7516 ;; Uncomment to get perl-mode-like vars
7517 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
7518 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
7519 ;;; (2 (cons font-lock-variable-name-face '(underline))))
7520 (cond ((featurep 'font-lock-extra)
7521 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
7522 (3 font-lock-variable-name-face)
7524 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
7525 (1 font-lock-variable-name-face)
7526 (2 '(restart 2 nil) nil t)))
7527 nil t))) ; local variables, multiple
7529 ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
7530 (` ((, (concat "\\<\\(my\\|local\\|our\\)"
7531 cperl-maybe-white-and-comment-rex
7533 cperl-maybe-white-and-comment-rex
7534 "\\)?\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
7535 (5 (, (if cperl-font-lock-multiline
7536 'font-lock-variable-name-face
7537 '(progn (setq cperl-font-lock-multiline-start
7538 (match-beginning 0))
7539 'font-lock-variable-name-face))))
7541 cperl-maybe-white-and-comment-rex
7543 cperl-maybe-white-and-comment-rex
7544 "\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
7545 ;; Bug in font-lock: limit is used not only to limit
7546 ;; searches, but to set the "extend window for
7547 ;; facification" property. Thus we need to minimize.
7548 (, (if cperl-font-lock-multiline
7549 '(if (match-beginning 3)
7551 (goto-char (match-beginning 3))
7557 (error nil)))) ; typeahead
7558 (1- (point))) ; report limit
7559 (forward-char -2)) ; disable continued expr
7560 '(if (match-beginning 3)
7561 (point-max) ; No limit for continuation
7562 (forward-char -2)))) ; disable continued expr
7563 (, (if cperl-font-lock-multiline
7566 ;; "my" may be already fontified (POD),
7567 ;; so cperl-font-lock-multiline-start is nil
7568 (if (or (not cperl-font-lock-multiline-start)
7570 cperl-font-lock-multiline-start
7574 (1+ cperl-font-lock-multiline-start) (point)
7575 'syntax-type 'multiline))
7576 (setq cperl-font-lock-multiline-start nil))))
7577 (3 font-lock-variable-name-face)))))
7578 (t '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
7579 3 font-lock-variable-name-face)))
7580 '("\\<for\\(each\\)?\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
7581 4 font-lock-variable-name-face)))
7583 t-font-lock-keywords-1
7584 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
7585 ;; not yet as of XEmacs 19.12, works with 21.1.11
7587 (not cperl-xemacs-p)
7588 (string< "21.1.9" emacs-version)
7589 (and (string< "21.1.10" emacs-version)
7590 (string< emacs-version "21.1.2")))
7592 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
7593 (if (eq (char-after (match-beginning 2)) ?%)
7596 t) ; arrays and hashes
7597 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
7599 (if (= (- (match-end 2) (match-beginning 2)) 1)
7600 (if (eq (char-after (match-beginning 3)) ?{)
7602 cperl-array-face) ; arrays and hashes
7603 font-lock-variable-name-face) ; Just to put something
7605 ("\\(@\\|\\$#\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
7606 (1 cperl-array-face)
7607 (2 font-lock-variable-name-face))
7608 ("\\(%\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
7610 (2 font-lock-variable-name-face))
7611 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
7612 ;;; Too much noise from \s* @s[ and friends
7613 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
7614 ;;(3 font-lock-function-name-face t t)
7616 ;; (if (cperl-slash-is-regexp)
7617 ;; font-lock-function-name-face 'default) nil t))
7619 (if cperl-highlight-variables-indiscriminately
7620 (setq t-font-lock-keywords-1
7621 (append t-font-lock-keywords-1
7622 (list '("\\([$*]{?\\sw+\\)" 1
7623 font-lock-variable-name-face)))))
7624 (setq perl-font-lock-keywords-1
7625 (if cperl-syntaxify-by-font-lock
7626 (cons 'cperl-fontify-update
7627 t-font-lock-keywords)
7628 t-font-lock-keywords)
7629 perl-font-lock-keywords perl-font-lock-keywords-1
7630 perl-font-lock-keywords-2 (append
7631 perl-font-lock-keywords-1
7632 t-font-lock-keywords-1)))
7633 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
7634 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
7635 (eval ; Avoid a warning
7636 '(font-lock-require-faces
7638 ;; Color-light Color-dark Gray-light Gray-dark Mono
7639 (list 'font-lock-comment-face
7640 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
7645 (list 'font-lock-string-face
7646 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
7651 (list 'font-lock-function-name-face
7653 "Blue" "LightSkyBlue" "Gray50" "LightGray"
7654 (cdr (assq 'background-color ; if mono
7655 (frame-parameters))))
7658 (cdr (assq 'foreground-color ; if mono
7659 (frame-parameters))))
7663 (list 'font-lock-variable-name-face
7664 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
7669 (list 'font-lock-type-face
7670 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
7675 (list 'font-lock-warning-face
7676 ["Pink" "Red" "Gray50" "LightGray"]
7683 (list 'font-lock-constant-face
7684 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
7689 (list 'cperl-nonoverridable-face
7690 ["chartreuse3" ("orchid1" "orange")
7696 (list 'cperl-array-face
7697 ["blue" "yellow" nil "Gray80"]
7698 ["lightyellow2" ("navy" "os2blue" "darkgreen")
7703 (list 'cperl-hash-face
7704 ["red" "red" nil "Gray80"]
7705 ["lightyellow2" ("navy" "os2blue" "darkgreen")
7710 ;; Do it the dull way, without choose-color
7711 (defvar cperl-guessed-background nil
7712 "Display characteristics as guessed by cperl.")
7713 ;; (or (fboundp 'x-color-defined-p)
7714 ;; (defalias 'x-color-defined-p
7715 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
7716 ;; ;; XEmacs >= 19.12
7717 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
7719 ;; (t 'x-valid-color-name-p))))
7720 (cperl-force-face font-lock-constant-face
7721 "Face for constant and label names")
7722 (cperl-force-face font-lock-variable-name-face
7723 "Face for variable names")
7724 (cperl-force-face font-lock-type-face
7725 "Face for data types")
7726 (cperl-force-face cperl-nonoverridable-face
7727 "Face for data types from another group")
7728 (cperl-force-face font-lock-warning-face
7729 "Face for things which should stand out")
7730 (cperl-force-face font-lock-comment-face
7731 "Face for comments")
7732 (cperl-force-face font-lock-function-name-face
7733 "Face for function names")
7734 (cperl-force-face cperl-hash-face
7736 (cperl-force-face cperl-array-face
7738 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
7739 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
7740 ;;(or (boundp 'font-lock-type-face)
7741 ;; (defconst font-lock-type-face
7742 ;; 'font-lock-type-face
7743 ;; "Face to use for data types."))
7744 ;;(or (boundp 'cperl-nonoverridable-face)
7745 ;; (defconst cperl-nonoverridable-face
7746 ;; 'cperl-nonoverridable-face
7747 ;; "Face to use for data types from another group."))
7748 ;;(if (not cperl-xemacs-p) nil
7749 ;; (or (boundp 'font-lock-comment-face)
7750 ;; (defconst font-lock-comment-face
7751 ;; 'font-lock-comment-face
7752 ;; "Face to use for comments."))
7753 ;; (or (boundp 'font-lock-keyword-face)
7754 ;; (defconst font-lock-keyword-face
7755 ;; 'font-lock-keyword-face
7756 ;; "Face to use for keywords."))
7757 ;; (or (boundp 'font-lock-function-name-face)
7758 ;; (defconst font-lock-function-name-face
7759 ;; 'font-lock-function-name-face
7760 ;; "Face to use for function names.")))
7762 (not (cperl-is-face 'cperl-array-face))
7763 (cperl-is-face 'font-lock-emphasized-face))
7764 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
7766 (not (cperl-is-face 'cperl-hash-face))
7767 (cperl-is-face 'font-lock-other-emphasized-face))
7768 (copy-face 'font-lock-other-emphasized-face
7771 (not (cperl-is-face 'cperl-nonoverridable-face))
7772 (cperl-is-face 'font-lock-other-type-face))
7773 (copy-face 'font-lock-other-type-face
7774 'cperl-nonoverridable-face))
7775 ;;(or (boundp 'cperl-hash-face)
7776 ;; (defconst cperl-hash-face
7778 ;; "Face to use for hashes."))
7779 ;;(or (boundp 'cperl-array-face)
7780 ;; (defconst cperl-array-face
7781 ;; 'cperl-array-face
7782 ;; "Face to use for arrays."))
7783 ;; Here we try to guess background
7785 (if (boundp 'font-lock-background-mode)
7786 font-lock-background-mode
7788 (face-list (and (fboundp 'face-list) (face-list))))
7789 ;;;; (fset 'cperl-is-face
7790 ;;;; (cond ((fboundp 'find-face)
7791 ;;;; (symbol-function 'find-face))
7793 ;;;; (function (lambda (face) (member face face-list))))
7795 ;;;; (function (lambda (face) (boundp face))))))
7796 (defvar cperl-guessed-background
7797 (if (and (boundp 'font-lock-display-type)
7798 (eq font-lock-display-type 'grayscale))
7801 "Background as guessed by CPerl mode")
7802 (and (not (cperl-is-face 'font-lock-constant-face))
7803 (cperl-is-face 'font-lock-reference-face)
7804 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
7805 (if (cperl-is-face 'font-lock-type-face) nil
7806 (copy-face 'default 'font-lock-type-face)
7808 ((eq background 'light)
7809 (set-face-foreground 'font-lock-type-face
7810 (if (x-color-defined-p "seagreen")
7813 ((eq background 'dark)
7814 (set-face-foreground 'font-lock-type-face
7815 (if (x-color-defined-p "os2pink")
7819 (set-face-background 'font-lock-type-face "gray90"))))
7820 (if (cperl-is-face 'cperl-nonoverridable-face)
7822 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
7824 ((eq background 'light)
7825 (set-face-foreground 'cperl-nonoverridable-face
7826 (if (x-color-defined-p "chartreuse3")
7829 ((eq background 'dark)
7830 (set-face-foreground 'cperl-nonoverridable-face
7831 (if (x-color-defined-p "orchid1")
7834 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
7835 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
7837 ;;; ((eq background 'light)
7838 ;;; (set-face-background 'font-lock-other-emphasized-face
7839 ;;; (if (x-color-defined-p "lightyellow2")
7841 ;;; (if (x-color-defined-p "lightyellow")
7843 ;;; "light yellow"))))
7844 ;;; ((eq background 'dark)
7845 ;;; (set-face-background 'font-lock-other-emphasized-face
7846 ;;; (if (x-color-defined-p "navy")
7848 ;;; (if (x-color-defined-p "darkgreen")
7850 ;;; "dark green"))))
7851 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
7852 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
7853 ;;; (copy-face 'bold 'font-lock-emphasized-face)
7855 ;;; ((eq background 'light)
7856 ;;; (set-face-background 'font-lock-emphasized-face
7857 ;;; (if (x-color-defined-p "lightyellow2")
7859 ;;; "lightyellow")))
7860 ;;; ((eq background 'dark)
7861 ;;; (set-face-background 'font-lock-emphasized-face
7862 ;;; (if (x-color-defined-p "navy")
7864 ;;; (if (x-color-defined-p "darkgreen")
7866 ;;; "dark green"))))
7867 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
7868 (if (cperl-is-face 'font-lock-variable-name-face) nil
7869 (copy-face 'italic 'font-lock-variable-name-face))
7870 (if (cperl-is-face 'font-lock-constant-face) nil
7871 (copy-face 'italic 'font-lock-constant-face))))
7872 (setq cperl-faces-init t))
7873 (error (message "cperl-init-faces (ignored): %s" errs))))
7876 (defun cperl-ps-print-init ()
7877 "Initialization of `ps-print' components for faces used in CPerl."
7878 (eval-after-load "ps-print"
7879 '(setq ps-bold-faces
7880 ;; font-lock-variable-name-face
7881 ;; font-lock-constant-face
7882 (append '(cperl-array-face
7886 ;; font-lock-constant-face
7887 (append '(cperl-nonoverridable-face
7891 ;; font-lock-type-face
7892 (append '(cperl-array-face
7895 cperl-nonoverridable-face)
7896 ps-underlined-faces))))
7898 (defvar ps-print-face-extension-alist)
7900 (defun cperl-ps-print (&optional file)
7901 "Pretty-print in CPerl style.
7902 If optional argument FILE is an empty string, prints to printer, otherwise
7903 to the file FILE. If FILE is nil, prompts for a file name.
7905 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
7908 (setq file (read-from-minibuffer
7909 "Print to file (if empty - to printer): "
7910 (concat (buffer-file-name) ".ps")
7911 nil nil 'file-name-history)))
7912 (or (> (length file) 0)
7914 (require 'ps-print) ; To get ps-print-face-extension-alist
7915 (let ((ps-print-color-p t)
7916 (ps-print-face-extension-alist ps-print-face-extension-alist))
7917 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
7918 (ps-print-buffer-with-faces file)))
7920 ;;; (defun cperl-ps-print-init ()
7921 ;;; "Initialization of `ps-print' components for faces used in CPerl."
7922 ;;; ;; Guard against old versions
7923 ;;; (defvar ps-underlined-faces nil)
7924 ;;; (defvar ps-bold-faces nil)
7925 ;;; (defvar ps-italic-faces nil)
7926 ;;; (setq ps-bold-faces
7927 ;;; (append '(font-lock-emphasized-face
7928 ;;; cperl-array-face
7929 ;;; font-lock-keyword-face
7930 ;;; font-lock-variable-name-face
7931 ;;; font-lock-constant-face
7932 ;;; font-lock-reference-face
7933 ;;; font-lock-other-emphasized-face
7934 ;;; cperl-hash-face)
7936 ;;; (setq ps-italic-faces
7937 ;;; (append '(cperl-nonoverridable-face
7938 ;;; font-lock-constant-face
7939 ;;; font-lock-reference-face
7940 ;;; font-lock-other-emphasized-face
7941 ;;; cperl-hash-face)
7942 ;;; ps-italic-faces))
7943 ;;; (setq ps-underlined-faces
7944 ;;; (append '(font-lock-emphasized-face
7945 ;;; cperl-array-face
7946 ;;; font-lock-other-emphasized-face
7948 ;;; cperl-nonoverridable-face font-lock-type-face)
7949 ;;; ps-underlined-faces))
7950 ;;; (cons 'font-lock-type-face ps-underlined-faces))
7953 (if (cperl-enable-font-lock) (cperl-windowed-init))
7955 (defconst cperl-styles-entries
7956 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
7957 cperl-label-offset cperl-extra-newline-before-brace
7958 cperl-extra-newline-before-brace-multiline
7959 cperl-merge-trailing-else
7960 cperl-continued-statement-offset))
7962 (defconst cperl-style-examples
7963 "##### Numbers etc are: cperl-indent-level cperl-brace-offset
7964 ##### cperl-continued-brace-offset cperl-label-offset
7965 ##### cperl-continued-statement-offset
7966 ##### cperl-merge-trailing-else cperl-extra-newline-before-brace
7968 ########### (Do not forget cperl-extra-newline-before-brace-multiline)
7970 ### CPerl (=GNU - extra-newline-before-brace + merge-trailing-else) 2/0/0/-2/2/t/nil
7982 ### PerlStyle (=CPerl with 4 as indent) 4/0/0/-4/4/t/nil
7994 ### GNU 2/0/0/-2/2/nil/t
8009 ### C++ (=PerlStyle with braces aligned with control words) 4/0/-4/-4/4/nil/t
8024 ### BSD (=C++, but will not change preexisting merge-trailing-else
8025 ### and extra-newline-before-brace ) 4/0/-4/-4/4
8040 ### K&R (=C++ with indent 5 - merge-trailing-else, but will not
8041 ### change preexisting extra-newline-before-brace) 5/0/-5/-5/5/nil
8056 ### Whitesmith (=PerlStyle, but will not change preexisting
8057 ### extra-newline-before-brace and merge-trailing-else) 4/0/0/-4/4
8072 "Examples of if/else with different indent styles (with v4.23).")
8074 (defconst cperl-style-alist
8075 '(("CPerl" ;; =GNU - extra-newline-before-brace + cperl-merge-trailing-else
8076 (cperl-indent-level . 2)
8077 (cperl-brace-offset . 0)
8078 (cperl-continued-brace-offset . 0)
8079 (cperl-label-offset . -2)
8080 (cperl-continued-statement-offset . 2)
8081 (cperl-extra-newline-before-brace . nil)
8082 (cperl-extra-newline-before-brace-multiline . nil)
8083 (cperl-merge-trailing-else . t))
8085 ("PerlStyle" ; CPerl with 4 as indent
8086 (cperl-indent-level . 4)
8087 (cperl-brace-offset . 0)
8088 (cperl-continued-brace-offset . 0)
8089 (cperl-label-offset . -4)
8090 (cperl-continued-statement-offset . 4)
8091 (cperl-extra-newline-before-brace . nil)
8092 (cperl-extra-newline-before-brace-multiline . nil)
8093 (cperl-merge-trailing-else . t))
8096 (cperl-indent-level . 2)
8097 (cperl-brace-offset . 0)
8098 (cperl-continued-brace-offset . 0)
8099 (cperl-label-offset . -2)
8100 (cperl-continued-statement-offset . 2)
8101 (cperl-extra-newline-before-brace . t)
8102 (cperl-extra-newline-before-brace-multiline . t)
8103 (cperl-merge-trailing-else . nil))
8106 (cperl-indent-level . 5)
8107 (cperl-brace-offset . 0)
8108 (cperl-continued-brace-offset . -5)
8109 (cperl-label-offset . -5)
8110 (cperl-continued-statement-offset . 5)
8111 ;;(cperl-extra-newline-before-brace . nil) ; ???
8112 ;;(cperl-extra-newline-before-brace-multiline . nil)
8113 (cperl-merge-trailing-else . nil))
8116 (cperl-indent-level . 4)
8117 (cperl-brace-offset . 0)
8118 (cperl-continued-brace-offset . -4)
8119 (cperl-label-offset . -4)
8120 (cperl-continued-statement-offset . 4)
8121 ;;(cperl-extra-newline-before-brace . nil) ; ???
8122 ;;(cperl-extra-newline-before-brace-multiline . nil)
8123 ;;(cperl-merge-trailing-else . nil) ; ???
8127 (cperl-indent-level . 4)
8128 (cperl-brace-offset . 0)
8129 (cperl-continued-brace-offset . -4)
8130 (cperl-label-offset . -4)
8131 (cperl-continued-statement-offset . 4)
8132 (cperl-extra-newline-before-brace . t)
8133 (cperl-extra-newline-before-brace-multiline . t)
8134 (cperl-merge-trailing-else . nil))
8137 (cperl-indent-level . 4)
8138 (cperl-brace-offset . 0)
8139 (cperl-continued-brace-offset . 0)
8140 (cperl-label-offset . -4)
8141 (cperl-continued-statement-offset . 4)
8142 ;;(cperl-extra-newline-before-brace . nil) ; ???
8143 ;;(cperl-extra-newline-before-brace-multiline . nil)
8144 ;;(cperl-merge-trailing-else . nil) ; ???
8147 "List of variables to set to get a particular indentation style.
8148 Should be used via `cperl-set-style' or via Perl menu.
8150 See examples in `cperl-style-examples'.")
8152 (defun cperl-set-style (style)
8153 "Set CPerl mode variables to use one of several different indentation styles.
8154 The arguments are a string representing the desired style.
8155 The list of styles is in `cperl-style-alist', available styles
8156 are CPerl, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith.
8158 The current value of style is memorized (unless there is a memorized
8159 data already), may be restored by `cperl-set-style-back'.
8161 Chosing \"Current\" style will not change style, so this may be used for
8162 side-effect of memorizing only. Examples in `cperl-style-examples'."
8164 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
8165 cperl-style-alist)))
8166 (list (completing-read "Enter style: " list nil 'insist))))
8168 (setq cperl-old-style
8171 (cons name (eval name))))
8172 cperl-styles-entries)))
8173 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
8175 (setq setting (car style) style (cdr style))
8176 (set (car setting) (cdr setting)))))
8178 (defun cperl-set-style-back ()
8179 "Restore a style memorised by `cperl-set-style'."
8181 (or cperl-old-style (error "The style was not changed"))
8183 (while cperl-old-style
8184 (setq setting (car cperl-old-style)
8185 cperl-old-style (cdr cperl-old-style))
8186 (set (car setting) (cdr setting)))))
8188 (defun cperl-check-syntax ()
8190 (require 'mode-compile)
8191 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
8192 (eval '(mode-compile)))) ; Avoid a warning
8194 (defun cperl-info-buffer (type)
8195 ;; Returns buffer with documentation. Creates if missing.
8196 ;; If TYPE, this vars buffer.
8197 ;; Special care is taken to not stomp over an existing info buffer
8198 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
8199 (info (get-buffer bname))
8200 (oldbuf (get-buffer "*info*")))
8202 (save-window-excursion
8207 (rename-buffer "*info-perl-tmp*")))
8208 (save-window-excursion
8210 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
8211 (set-buffer "*info*")
8212 (rename-buffer bname)
8214 (set-buffer "*info-perl-tmp*")
8215 (rename-buffer "*info*")
8216 (set-buffer bname)))
8217 (make-local-variable 'window-min-height)
8218 (setq window-min-height 2)
8219 (current-buffer)))))
8221 (defun cperl-word-at-point (&optional p)
8222 "Return the word at point or at P."
8224 (if p (goto-char p))
8225 (or (cperl-word-at-point-hard)
8228 (funcall (or (and (boundp 'find-tag-default-function)
8229 find-tag-default-function)
8230 (get major-mode 'find-tag-default-function)
8231 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
8232 ;; automatically used within `find-tag-default':
8233 'find-tag-default))))))
8235 (defun cperl-info-on-command (command)
8236 "Show documentation for Perl command COMMAND in other window.
8237 If perl-info buffer is shown in some frame, uses this frame.
8238 Customized by setting variables `cperl-shrink-wrap-info-frame',
8239 `cperl-max-help-size'."
8241 (let* ((default (cperl-word-at-point))
8243 (format "Find doc for Perl function (default %s): "
8245 (list (if (equal read "")
8249 (let ((buffer (current-buffer))
8250 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
8251 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
8252 max-height char-height buf-list)
8253 (if (string-match "^-[a-zA-Z]$" command)
8254 (setq cmd-desc "^-X[ \t\n]"))
8255 (setq isvar (string-match "^[$@%]" command)
8256 buf (cperl-info-buffer isvar)
8257 iniwin (selected-window)
8258 fr1 (window-frame iniwin))
8260 (goto-char (point-min))
8262 (progn (re-search-forward "^-X[ \t\n]")
8264 (if (re-search-forward cmd-desc nil t)
8266 ;; Go back to beginning of the group (ex, for qq)
8267 (if (re-search-backward "^[ \t\n\f]")
8272 buf-list (list buf "*info-perl-var*" "*info-perl*"))
8273 (while (and (not win) buf-list)
8274 (setq win (get-buffer-window (car buf-list) t))
8275 (setq buf-list (cdr buf-list)))
8277 (eq (window-buffer win) buf)
8278 (set-window-buffer win buf))
8279 (and win (setq fr2 (window-frame win)))
8280 (if (or (not fr2) (eq fr1 fr2))
8282 (special-display-popup-frame buf) ; Make it visible
8283 (select-window win))
8284 (goto-char pos) ; Needed (?!).
8286 (setq iniheight (window-height)
8287 frheight (frame-height)
8288 not-loner (< iniheight (1- frheight))) ; Are not alone
8289 (cond ((if not-loner cperl-max-help-size
8290 cperl-shrink-wrap-info-frame)
8296 (if (re-search-forward
8297 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
8298 (match-beginning 0) (point-max)))))
8301 (/ (* (- frheight 3) cperl-max-help-size) 100)
8302 (setq char-height (frame-char-height))
8303 ;; Non-functioning under OS/2:
8304 (if (eq char-height 1) (setq char-height 18))
8305 ;; Title, menubar, + 2 for slack
8306 (- (/ (x-display-pixel-height) char-height) 4)))
8307 (if (> height max-height) (setq height max-height))
8308 ;;(message "was %s doing %s" iniheight height)
8310 (enlarge-window (- height iniheight))
8311 (set-frame-height (window-frame win) (1+ height)))))
8312 (set-window-start (selected-window) pos))
8313 (message "No entry for %s found." command))
8314 ;;(pop-to-buffer buffer)
8315 (select-window iniwin)))
8317 (defun cperl-info-on-current-command ()
8318 "Show documentation for Perl command at point in other window."
8320 (cperl-info-on-command (cperl-word-at-point)))
8322 (defun cperl-imenu-info-imenu-search ()
8323 (if (looking-at "^-X[ \t\n]") nil
8325 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
8328 (defun cperl-imenu-info-imenu-name ()
8330 (match-beginning 1) (match-end 1)))
8332 (defun cperl-imenu-on-info ()
8333 "Shows imenu for Perl Info Buffer.
8334 Opens Perl Info buffer if needed."
8336 (let* ((buffer (current-buffer))
8337 imenu-create-index-function
8338 imenu-prev-index-position-function
8339 imenu-extract-index-name-function
8340 (index-item (save-restriction
8341 (save-window-excursion
8342 (set-buffer (cperl-info-buffer nil))
8343 (setq imenu-create-index-function
8344 'imenu-default-create-index-function
8345 imenu-prev-index-position-function
8346 'cperl-imenu-info-imenu-search
8347 imenu-extract-index-name-function
8348 'cperl-imenu-info-imenu-name)
8349 (imenu-choose-buffer-index)))))
8353 (pop-to-buffer "*info-perl*")
8355 ((markerp (cdr index-item))
8356 (goto-char (marker-position (cdr index-item))))
8358 (goto-char (cdr index-item))))
8359 (set-window-start (selected-window) (point))
8360 (pop-to-buffer buffer)))))
8362 (defun cperl-lineup (beg end &optional step minshift)
8363 "Lineup construction in a region.
8364 Beginning of region should be at the start of a construction.
8365 All first occurrences of this construction in the lines that are
8366 partially contained in the region are lined up at the same column.
8368 MINSHIFT is the minimal amount of space to insert before the construction.
8369 STEP is the tabwidth to position constructions.
8370 If STEP is nil, `cperl-lineup-step' will be used
8371 \(or `cperl-indent-level', if `cperl-lineup-step' is `nil').
8372 Will not move the position at the start to the left."
8374 (let (search col tcol seen b)
8378 (setq end (point-marker))
8380 (skip-chars-forward " \t\f")
8381 (setq beg (point-marker))
8382 (indent-region beg end nil)
8384 (setq col (current-column))
8385 (if (looking-at "[a-zA-Z0-9_]")
8386 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
8390 (buffer-substring (match-beginning 0)
8391 (match-end 0))) "\\>"))
8392 (error "Cannot line up in a middle of the word"))
8393 (if (looking-at "$")
8394 (error "Cannot line up end of line"))
8395 (setq search (regexp-quote (char-to-string (following-char)))))
8396 (setq step (or step cperl-lineup-step cperl-indent-level))
8397 (or minshift (setq minshift 1))
8399 (beginning-of-line 2)
8400 (and (< (point) end)
8401 (re-search-forward search end t)
8402 (goto-char (match-beginning 0))))
8403 (setq tcol (current-column) seen t)
8404 (if (> tcol col) (setq col tcol)))
8406 (error "The construction to line up occurred only once"))
8408 (setq col (+ col minshift))
8409 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
8412 (cperl-make-indent col)
8413 (beginning-of-line 2)
8414 (and (< (point) end)
8415 (re-search-forward search end t)
8416 (goto-char (match-beginning 0)))))))) ; No body
8418 (defun cperl-etags (&optional add all files) ;; NOT USED???
8419 "Run etags with appropriate options for Perl files.
8420 If optional argument ALL is `recursive', will process Perl files
8421 in subdirectories too."
8424 (args '("-l" "none" "-r"
8425 ;; 1=fullname 2=package? 3=name 4=proto? 5=attrs? (VERY APPROX!)
8426 "/\\<sub[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([ \t]*:[^#{;]*\\)?\\([{#]\\|$\\)/\\3/"
8428 "/\\<package[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\([#;]\\|$\\)/\\1/"
8430 "/\\<\\(package\\)[ \\t]*;/\\1;/"))
8432 (if add (setq args (cons "-a" args)))
8433 (or files (setq files (list buffer-file-name)))
8435 ((eq all 'recursive)
8436 ;;(error "Not implemented: recursive")
8437 (setq args (append (list "-e"
8438 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
8440 find(\\&wanted, '.');
8445 ;;(error "Not implemented: all")
8446 (setq args (append (list "-e"
8447 "push @ARGV, <*.PL *.pl *.pm>;
8452 (setq args (append args files))))
8453 (setq res (apply 'call-process cmd nil nil nil args))
8455 (message "etags returned \"%s\"" res))))
8457 (defun cperl-toggle-auto-newline ()
8458 "Toggle the state of `cperl-auto-newline'."
8460 (setq cperl-auto-newline (not cperl-auto-newline))
8461 (message "Newlines will %sbe auto-inserted now."
8462 (if cperl-auto-newline "" "not ")))
8464 (defun cperl-toggle-abbrev ()
8465 "Toggle the state of automatic keyword expansion in CPerl mode."
8467 (abbrev-mode (if abbrev-mode 0 1))
8468 (message "Perl control structure will %sbe auto-inserted now."
8469 (if abbrev-mode "" "not ")))
8472 (defun cperl-toggle-electric ()
8473 "Toggle the state of parentheses doubling in CPerl mode."
8475 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
8476 (message "Parentheses will %sbe auto-doubled now."
8477 (if (cperl-val 'cperl-electric-parens) "" "not ")))
8479 (defun cperl-toggle-autohelp ()
8480 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
8481 Delay of auto-help controlled by `cperl-lazy-help-time'."
8483 (if (fboundp 'run-with-idle-timer)
8485 (if cperl-lazy-installed
8486 (cperl-lazy-unstall)
8487 (cperl-lazy-install))
8488 (message "Perl help messages will %sbe automatically shown now."
8489 (if cperl-lazy-installed "" "not ")))
8490 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
8492 (defun cperl-toggle-construct-fix ()
8493 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
8495 (setq cperl-indent-region-fix-constructs
8496 (if cperl-indent-region-fix-constructs
8499 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
8500 (if cperl-indent-region-fix-constructs "" "not ")))
8502 (defun cperl-toggle-set-debug-unwind (arg &optional backtrace)
8503 "Toggle (or, with numeric argument, set) debugging state of syntaxification.
8504 Nonpositive numeric argument disables debugging messages. The message
8505 summarizes which regions it was decided to rescan for syntactic constructs.
8507 The message looks like this:
8509 Syxify req=123..138 actual=101..146 done-to: 112=>146 statepos: 73=>117
8511 Numbers are character positions in the buffer. REQ provides the range to
8512 rescan requested by `font-lock'. ACTUAL is the range actually resyntaxified;
8513 for correct operation it should start and end outside any special syntactic
8514 construct. DONE-TO and STATEPOS indicate changes to internal caches maintained
8518 (setq arg (if (eq cperl-syntaxify-by-font-lock
8519 (if backtrace 'backtrace 'message)) 0 1)))
8520 (setq arg (if (> arg 0) (if backtrace 'backtrace 'message) t))
8521 (setq cperl-syntaxify-by-font-lock arg)
8522 (message "Debugging messages of syntax unwind %sabled."
8523 (if (eq arg t) "dis" "en")))
8525 ;;;; Tags file creation.
8527 (defvar cperl-tmp-buffer " *cperl-tmp*")
8529 (defun cperl-setup-tmp-buf ()
8530 (set-buffer (get-buffer-create cperl-tmp-buffer))
8531 (set-syntax-table cperl-mode-syntax-table)
8532 (buffer-disable-undo)
8534 (if cperl-use-syntax-table-text-property-for-tags
8536 (make-local-variable 'parse-sexp-lookup-properties)
8537 ;; Do not introduce variable if not needed, we check it!
8538 (set 'parse-sexp-lookup-properties t))))
8540 (defun cperl-xsub-scan ()
8543 (let ((index-alist '())
8544 (prev-pos 0) index index1 name package prefix)
8545 (goto-char (point-min))
8547 (message "Scanning XSUB for index")
8548 (imenu-progress-message prev-pos 0))
8549 ;; Search for the function
8550 (progn ;;save-match-data
8551 (while (re-search-forward
8552 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
8555 (imenu-progress-message prev-pos))
8557 ((match-beginning 2) ; SECTION
8558 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
8559 (goto-char (match-beginning 0))
8560 (skip-chars-forward " \t")
8562 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
8563 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
8565 ((not package) nil) ; C language section
8566 ((match-beginning 3) ; XSUB
8567 (goto-char (1+ (match-beginning 3)))
8568 (setq index (imenu-example--name-and-position))
8569 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
8570 (if (and prefix (string-match (concat "^" prefix) name))
8571 (setq name (substring name (length prefix))))
8572 (cond ((string-match "::" name) nil)
8574 (setq index1 (cons (concat package "::" name) (cdr index)))
8575 (push index1 index-alist)))
8577 (push index index-alist))
8579 ;; (beginning-of-line)
8580 (setq index (imenu-example--name-and-position))
8581 (setcar index (concat package "::BOOT:"))
8582 (push index index-alist)))))
8584 (imenu-progress-message prev-pos 100))
8587 (defvar cperl-unreadable-ok nil)
8589 (defun cperl-find-tags (ifile xs topdir)
8590 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
8591 (cperl-pod-here-fontify nil) f file)
8593 (if b (set-buffer b)
8594 (cperl-setup-tmp-buf))
8597 (setq file (car (insert-file-contents ifile)))
8598 (error (if cperl-unreadable-ok nil
8600 (format "File %s unreadable. Continue? " ifile))
8601 (setq cperl-unreadable-ok t)
8602 (error "Aborting: unreadable file %s" ifile)))))
8604 (message "Unreadable file %s" ifile)
8605 (message "Scanning file %s ..." file)
8606 (if (and cperl-use-syntax-table-text-property-for-tags
8608 (condition-case err ; after __END__ may have garbage
8609 (cperl-find-pods-heres nil nil noninteractive)
8610 (error (message "While scanning for syntax: %s" err))))
8612 (setq lst (cperl-xsub-scan))
8613 (setq ind (cperl-imenu--create-perl-index))
8614 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
8619 (cond ((string-match "^[_a-zA-Z]" (car elt))
8620 (goto-char (cdr elt))
8621 (beginning-of-line) ; pos should be of the start of the line
8624 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
8625 (buffer-substring (progn
8626 (goto-char (cdr elt))
8627 ;; After name now...
8628 (or (eolp) (forward-char 1))
8636 (setq elt (car lst) lst (cdr lst))
8641 (if (string-match "^package " (car elt))
8642 (substring (car elt) 8)
8645 (number-to-string (elt elt 2)) ; Line
8647 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
8649 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
8650 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
8652 ;; Need to insert the name without package as well
8653 (setq lst (cons (cons (substring (elt elt 3)
8661 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
8662 (set-text-properties 0 (length rel) nil rel)
8663 (and (equal topdir (substring rel 0 (length topdir)))
8664 (setq rel (substring file (length topdir))))
8665 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
8666 (setq ret (buffer-substring 1 (point-max)))
8669 (message "Scanning file %s finished" file))
8672 (defun cperl-add-tags-recurse-noxs ()
8673 "Add to TAGS data for \"pure\" Perl files in the current directory and kids.
8675 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8676 -f cperl-add-tags-recurse-noxs
8678 (cperl-write-tags nil nil t t nil t))
8680 (defun cperl-add-tags-recurse-noxs-fullpath ()
8681 "Add to TAGS data for \"pure\" Perl in the current directory and kids.
8682 Writes down fullpath, so TAGS is relocatable (but if the build directory
8683 is relocated, the file TAGS inside it breaks). Use as
8684 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8685 -f cperl-add-tags-recurse-noxs-fullpath
8687 (cperl-write-tags nil nil t t nil t ""))
8689 (defun cperl-add-tags-recurse ()
8690 "Add to TAGS file data for Perl files in the current directory and kids.
8692 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8693 -f cperl-add-tags-recurse
8695 (cperl-write-tags nil nil t t))
8697 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
8698 ;; If INBUFFER, do not select buffer, and do not save
8699 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
8702 (setq file (if dir default-directory (buffer-file-name)))
8703 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
8705 (setq topdir default-directory))
8706 (let ((tags-file-name "TAGS")
8707 (case-fold-search (eq system-type 'emx))
8710 (cond (inbuffer nil) ; Already there
8711 ((file-exists-p tags-file-name)
8713 (visit-tags-table-buffer)
8714 (visit-tags-table-buffer tags-file-name)))
8715 (t (set-buffer (find-file-noselect tags-file-name))))
8718 (cond ((eq erase 'ignore))
8721 (setq erase 'ignore)))
8724 (directory-files file t
8725 (if recurse nil cperl-scan-files-regexp)
8728 (if cperl-unreadable-ok nil
8730 (format "Directory %s unreadable. Continue? " file))
8731 (setq cperl-unreadable-ok t
8732 tm nil) ; Return empty list
8733 (error "Aborting: unreadable directory %s" file)))))))
8737 ((string-match cperl-noscan-files-regexp file)
8739 ((not (file-directory-p file))
8740 (if (string-match cperl-scan-files-regexp file)
8741 (cperl-write-tags file erase recurse nil t noxs topdir)))
8743 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
8746 (setq xs (string-match "\\.xs$" file))
8747 (if (not (and xs noxs))
8749 (cond ((eq erase 'ignore) (goto-char (point-max)))
8750 (erase (erase-buffer))
8754 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
8755 (set-text-properties 0 (length rel) nil rel)
8756 (and (equal topdir (substring rel 0 (length topdir)))
8757 (setq rel (substring file (length topdir))))
8758 (if (search-forward (concat "\f\n" rel ",") nil t)
8760 (search-backward "\f\n")
8761 (delete-region (point)
8764 (if (search-forward "\f\n"
8768 (goto-char (point-max)))))
8769 (insert (cperl-find-tags file xs topdir))))))
8770 (if inbuffer nil ; Delegate to the caller
8771 (save-buffer 0) ; No backup
8772 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
8773 (initialize-new-tags-table))))))
8775 (defvar cperl-tags-hier-regexp-list
8782 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
8784 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
8787 (defvar cperl-hierarchy '(() ())
8788 "Global hierarchy of classes.")
8790 (defun cperl-tags-hier-fill ()
8791 ;; Suppose we are in a tag table cooked by cperl.
8793 (let (type pack name pos line chunk ord cons1 file str info fileind)
8794 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
8795 (setq pos (match-beginning 0)
8796 pack (match-beginning 2))
8798 (if (looking-at (concat
8807 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
8808 name (buffer-substring (match-beginning 2) (match-end 2))
8809 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
8810 line (buffer-substring (match-beginning 3) (match-end 3))
8813 fileind (format "%s:%s" file line)
8814 ;; Moves to beginning of the next line:
8815 info (cperl-etags-snarf-tag file line))
8818 ;; Make new member of hierarchy name ==> file ==> pos if needed
8819 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
8821 (setcdr cons1 (cons (cons fileind (vector file info))
8823 ;; First occurrence of the name, start alist
8824 (setq cons1 (cons name (list (cons fileind (vector file info)))))
8826 (setcar (cdr cperl-hierarchy)
8827 (cons cons1 (nth 1 cperl-hierarchy)))
8828 (setcar cperl-hierarchy
8829 (cons cons1 (car cperl-hierarchy)))))))
8832 (defun cperl-tags-hier-init (&optional update)
8833 "Show hierarchical menu of classes and methods.
8834 Finds info about classes by a scan of loaded TAGS files.
8835 Supposes that the TAGS files contain fully qualified function names.
8836 One may build such TAGS files from CPerl mode menu."
8840 (if (or update (null (nth 2 cperl-hierarchy)))
8841 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
8844 (setcdr elt (cdr (nth 1 elt)))))))
8845 pack name cons1 to l1 l2 l3 l4 b)
8846 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
8847 (setq cperl-hierarchy (list l1 l2 l3))
8848 (if cperl-xemacs-p ; Not checked
8851 ;; Does this work in XEmacs?
8852 (call-interactively 'visit-tags-table))
8853 (message "Updating list of classes...")
8854 (set-buffer (get-file-buffer tags-file-name))
8855 (cperl-tags-hier-fill))
8857 (call-interactively 'visit-tags-table))
8861 (message "Updating list of classes... %s" tagsfile)
8862 (set-buffer (get-file-buffer tagsfile))
8863 (cperl-tags-hier-fill)))
8865 (message "Updating list of classes... postprocessing..."))
8866 (mapcar remover (car cperl-hierarchy))
8867 (mapcar remover (nth 1 cperl-hierarchy))
8868 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
8869 (cons "Methods: " (car cperl-hierarchy))))
8870 (cperl-tags-treeify to 1)
8871 (setcar (nthcdr 2 cperl-hierarchy)
8872 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
8873 (message "Updating list of classes: done, requesting display...")
8874 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
8876 (or (nth 2 cperl-hierarchy)
8877 (error "No items found"))
8879 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
8880 (if (if (fboundp 'display-popup-menus-p)
8881 (let ((f 'display-popup-menus-p))
8884 (x-popup-menu t (nth 2 cperl-hierarchy))
8886 (tmm-prompt (nth 2 cperl-hierarchy))))
8887 (if (and update (listp update))
8888 (progn (while (cdr update) (setq update (cdr update)))
8889 (setq update (car update)))) ; Get the last from the list
8890 (if (vectorp update)
8892 (find-file (elt update 0))
8893 (cperl-etags-goto-tag-location (elt update 1))))
8894 (if (eq update -999) (cperl-tags-hier-init t)))
8896 (defun cperl-tags-treeify (to level)
8897 ;; cadr of `to' is read-write. On start it is a cons
8898 (let* ((regexp (concat "^\\(" (mapconcat
8900 (make-list level "[_a-zA-Z0-9]+")
8903 (packages (cdr (nth 1 to)))
8904 (methods (cdr (nth 2 to)))
8905 l1 head tail cons1 cons2 ord writeto packs recurse
8906 root-packages root-functions ms many_ms same_name ps
8910 (cond ((and (string-match regexp (car elt))
8911 (or (eq ord 1) (match-end 2)))
8912 (setq head (substring (car elt) 0 (match-end 1))
8913 tail (if (match-end 2) (substring (car elt)
8916 (if (setq cons1 (assoc head writeto)) nil
8917 ;; Need to init new head
8918 (setcdr writeto (cons (list head (list "Packages: ")
8921 (setq cons1 (nth 1 writeto)))
8922 (setq cons2 (nth ord cons1)) ; Either packs or meths
8923 (setcdr cons2 (cons elt (cdr cons2))))
8925 (setq root-functions (cons elt root-functions)))
8927 (setq root-packages (cons elt root-packages))))))))
8928 (setcdr to l1) ; Init to dynamic space
8931 (mapcar move-deeper packages)
8933 (mapcar move-deeper methods)
8935 (mapcar (function (lambda (elt)
8936 (cperl-tags-treeify elt (1+ level))))
8938 ;;Now clean up leaders with one child only
8939 (mapcar (function (lambda (elt)
8940 (if (not (and (listp (cdr elt))
8941 (eq (length elt) 2))) nil
8942 (setcar elt (car (nth 1 elt)))
8943 (setcdr elt (cdr (nth 1 elt))))))
8945 ;; Sort the roots of subtrees
8946 (if (default-value 'imenu-sort-function)
8948 (sort (cdr to) (default-value 'imenu-sort-function))))
8949 ;; Now add back functions removed from display
8950 (mapcar (function (lambda (elt)
8951 (setcdr to (cons elt (cdr to)))))
8952 (if (default-value 'imenu-sort-function)
8954 (sort root-functions (default-value 'imenu-sort-function)))
8956 ;; Now add back packages removed from display
8957 (mapcar (function (lambda (elt)
8958 (setcdr to (cons (cons (concat "package " (car elt))
8961 (if (default-value 'imenu-sort-function)
8963 (sort root-packages (default-value 'imenu-sort-function)))
8967 ;;; '(keymap "Name1"
8971 ;;; ("Tail1" "x") ("Tail2" "y"))))
8973 (defun cperl-list-fold (list name limit)
8974 (let (list1 list2 elt1 (num 0))
8975 (if (<= (length list) limit) list
8976 (setq list1 nil list2 nil)
8981 (if (<= num imenu-max-items)
8982 (setq list2 (cons elt1 list2))
8983 (setq list1 (cons (cons name
8988 (nreverse (cons (cons name
8992 (defun cperl-menu-to-keymap (menu &optional name)
8998 (cond ((listp (cdr elt))
8999 (setq list (cperl-list-fold
9000 (cdr elt) (car elt) imenu-max-items))
9003 (cperl-menu-to-keymap list))))
9005 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
9006 (cperl-list-fold menu "Root" imenu-max-items)))))
9009 (defvar cperl-bad-style-regexp
9010 (mapconcat 'identity
9011 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
9012 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
9014 "Finds places such that insertion of a whitespace may help a lot.")
9016 (defvar cperl-not-bad-style-regexp
9019 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
9020 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
9021 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
9022 "<\\$?\\sw+\\(\\.\\(\\sw\\|_\\)+\\)?>" ; <IN> <stdin.h>
9023 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
9030 "\\\\[&$@*\\\\]" ; \&func
9033 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
9036 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
9037 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
9038 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
9042 "If matches at the start of match found by `my-bad-c-style-regexp',
9043 insertion of a whitespace will not help.")
9047 (defun cperl-find-bad-style ()
9048 "Find places in the buffer where insertion of a whitespace may help.
9049 Prompts user for insertion of spaces.
9050 Currently it is tuned to C and Perl syntax."
9052 (let (found-bad (p (point)))
9053 (setq last-nonmenu-event 13) ; To disable popup
9054 (goto-char (point-min))
9055 (map-y-or-n-p "Insert space here? "
9056 (lambda (arg) (insert " "))
9057 'cperl-next-bad-style
9058 '("location" "locations" "insert a space into")
9059 '((?\C-r (lambda (arg)
9060 (let ((buffer-quit-function
9061 'exit-recursive-edit))
9062 (message "Exit with Esc Esc")
9064 t)) ; Consider acted upon
9065 "edit, exit with Esc Esc")
9067 (let ((buffer-quit-function
9068 'exit-recursive-edit))
9069 (message "Exit with Esc Esc")
9071 t)) ; Consider acted upon
9072 "edit, exit with Esc Esc"))
9074 (if found-bad (goto-char found-bad)
9076 (message "No appropriate place found"))))
9078 (defun cperl-next-bad-style ()
9079 (let (p (not-found t) (point (point)) found)
9080 (while (and not-found
9081 (re-search-forward cperl-bad-style-regexp nil 'to-end))
9083 (goto-char (match-beginning 0))
9085 (looking-at cperl-not-bad-style-regexp)
9086 ;; Check for a < -b and friends
9087 (and (eq (following-char) ?\-)
9089 (skip-chars-backward " \t\n")
9090 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
9091 ;; Now check for syntax type
9093 (setq found (point))
9094 (beginning-of-defun)
9095 (let ((pps (parse-partial-sexp (point) found)))
9096 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
9097 (goto-char (match-end 0))
9105 (defvar cperl-have-help-regexp
9109 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
9110 "[$@]\\^[a-zA-Z]" ; Special variable
9111 "[$@][^ \n\t]" ; Special variable
9112 "-[a-zA-Z]" ; File test
9113 "\\\\[a-zA-Z0]" ; Special chars
9114 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
9115 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
9116 "[a-zA-Z_0-9:]+" ; symbol or number
9123 "Matches places in the buffer we can find help for.")
9125 (defvar cperl-message-on-help-error t)
9126 (defvar cperl-help-from-timer nil)
9128 (defun cperl-word-at-point-hard ()
9129 ;; Does not save-excursion
9130 ;; Get to the something meaningful
9131 (or (eobp) (eolp) (forward-char 1))
9132 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
9133 (save-excursion (beginning-of-line) (point))
9136 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
9137 ;; (skip-chars-backward " \n\t\r({[]});,")
9138 ;; (or (bobp) (backward-char 1))))
9141 ((looking-at "[a-zA-Z0-9_:]") ; symbol
9142 (skip-chars-backward "a-zA-Z0-9_:")
9144 ((and (eq (preceding-char) ?^) ; $^I
9145 (eq (char-after (- (point) 2)) ?\$))
9147 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
9149 ((and (eq (preceding-char) ?\=)
9150 (eq (current-column) 1))
9151 (forward-char -1))) ; =head1
9152 (if (and (eq (preceding-char) ?\<)
9153 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
9155 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
9157 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
9159 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
9160 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
9162 ((and (eq (preceding-char) ?\$)
9163 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
9165 ((and (eq (following-char) ?\>)
9166 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
9169 (and (eq (preceding-char) ?\<)
9170 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
9171 (search-backward "<"))))
9172 ((and (eq (following-char) ?\$)
9173 (eq (preceding-char) ?\<)
9174 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
9176 (if (looking-at cperl-have-help-regexp)
9177 (buffer-substring (match-beginning 0) (match-end 0))))
9179 (defun cperl-get-help ()
9180 "Get one-line docs on the symbol at the point.
9181 The data for these docs is a little bit obsolete and may be in fact longer
9182 than a line. Your contribution to update/shorten it is appreciated."
9184 (save-match-data ; May be called "inside" query-replace
9186 (let ((word (cperl-word-at-point-hard)))
9188 (if (and cperl-help-from-timer ; Bail out if not in mainland
9189 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
9190 (or (memq (get-text-property (point) 'face)
9191 '(font-lock-comment-face font-lock-string-face))
9192 (memq (get-text-property (point) 'syntax-type)
9193 '(pod here-doc format))))
9195 (cperl-describe-perl-symbol word))
9196 (if cperl-message-on-help-error
9197 (message "Nothing found for %s..."
9198 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
9200 ;;; Stolen from perl-descr.el by Johan Vromans:
9202 (defvar cperl-doc-buffer " *perl-doc*"
9203 "Where the documentation can be found.")
9205 (defun cperl-describe-perl-symbol (val)
9206 "Display the documentation of symbol at point, a Perl operator."
9207 (let ((enable-recursive-minibuffers t)
9210 ((string-match "^[&*][a-zA-Z_]" val)
9211 (setq val (concat (substring val 0 1) "NAME")))
9212 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
9213 (setq val (concat "@" (substring val 1 (match-end 1)))))
9214 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
9215 (setq val (concat "%" (substring val 1 (match-end 1)))))
9216 ((and (string= val "x") (string-match "^x=" val))
9218 ((string-match "^\\$[\C-a-\C-z]" val)
9219 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
9220 ((string-match "^CORE::" val)
9221 (setq val "CORE::"))
9222 ((string-match "^SUPER::" val)
9223 (setq val "SUPER::"))
9224 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
9225 (setq val "<NAME>")))
9226 (setq regexp (concat "^"
9227 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
9229 "\\([ \t([/]\\|$\\)"))
9231 ;; get the buffer with the documentation text
9232 (cperl-switch-to-doc-buffer)
9234 ;; lookup in the doc
9235 (goto-char (point-min))
9236 (let ((case-fold-search nil))
9238 (if (re-search-forward regexp (point-max) t)
9240 (beginning-of-line 1)
9241 (let ((lnstart (point)))
9243 (message "%s" (buffer-substring lnstart (point)))))
9244 (if cperl-message-on-help-error
9245 (message "No definition for %s" val)))))))
9247 (defvar cperl-short-docs 'please-ignore-this-line
9248 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
9249 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
9250 ... Range (list context); flip/flop [no flop when flip] (scalar context).
9251 ! ... Logical negation.
9252 ... != ... Numeric inequality.
9253 ... !~ ... Search pattern, substitution, or translation (negated).
9254 $! In numeric context: errno. In a string context: error string.
9255 $\" The separator which joins elements of arrays interpolated in strings.
9256 $# The output format for printed numbers. Default is %.15g or close.
9257 $$ Process number of this script. Changes in the fork()ed child process.
9258 $% The current page number of the currently selected output channel.
9260 The following variables are always local to the current block:
9262 $1 Match of the 1st set of parentheses in the last match (auto-local).
9263 $2 Match of the 2nd set of parentheses in the last match (auto-local).
9264 $3 Match of the 3rd set of parentheses in the last match (auto-local).
9265 $4 Match of the 4th set of parentheses in the last match (auto-local).
9266 $5 Match of the 5th set of parentheses in the last match (auto-local).
9267 $6 Match of the 6th set of parentheses in the last match (auto-local).
9268 $7 Match of the 7th set of parentheses in the last match (auto-local).
9269 $8 Match of the 8th set of parentheses in the last match (auto-local).
9270 $9 Match of the 9th set of parentheses in the last match (auto-local).
9271 $& The string matched by the last pattern match (auto-local).
9272 $' The string after what was matched by the last match (auto-local).
9273 $` The string before what was matched by the last match (auto-local).
9275 $( The real gid of this process.
9276 $) The effective gid of this process.
9277 $* Deprecated: Set to 1 to do multiline matching within a string.
9278 $+ The last bracket matched by the last search pattern.
9279 $, The output field separator for the print operator.
9280 $- The number of lines left on the page.
9281 $. The current input line number of the last filehandle that was read.
9282 $/ The input record separator, newline by default.
9283 $0 Name of the file containing the current perl script (read/write).
9284 $: String may be broken after these characters to fill ^-lines in a format.
9285 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
9286 $< The real uid of this process.
9287 $= The page length of the current output channel. Default is 60 lines.
9288 $> The effective uid of this process.
9289 $? The status returned by the last ``, pipe close or `system'.
9290 $@ The perl error message from the last eval or do @var{EXPR} command.
9291 $ARGV The name of the current file used with <> .
9292 $[ Deprecated: The index of the first element/char in an array/string.
9293 $\\ The output record separator for the print operator.
9294 $] The perl version string as displayed with perl -v.
9295 $^ The name of the current top-of-page format.
9296 $^A The current value of the write() accumulator for format() lines.
9297 $^D The value of the perl debug (-D) flags.
9298 $^E Information about the last system error other than that provided by $!.
9299 $^F The highest system file descriptor, ordinarily 2.
9300 $^H The current set of syntax checks enabled by `use strict'.
9301 $^I The value of the in-place edit extension (perl -i option).
9302 $^L What formats output to perform a formfeed. Default is \f.
9303 $^M A buffer for emergency memory allocation when running out of memory.
9304 $^O The operating system name under which this copy of Perl was built.
9305 $^P Internal debugging flag.
9306 $^T The time the script was started. Used by -A/-M/-C file tests.
9307 $^W True if warnings are requested (perl -w flag).
9308 $^X The name under which perl was invoked (argv[0] in C-speech).
9309 $_ The default input and pattern-searching space.
9310 $| Auto-flush after write/print on current output channel? Default 0.
9311 $~ The name of the current report format.
9312 ... % ... Modulo division.
9313 ... %= ... Modulo division assignment.
9314 %ENV Contains the current environment.
9315 %INC List of files that have been require-d or do-ne.
9316 %SIG Used to set signal handlers for various signals.
9317 ... & ... Bitwise and.
9318 ... && ... Logical and.
9319 ... &&= ... Logical and assignment.
9320 ... &= ... Bitwise and assignment.
9321 ... * ... Multiplication.
9322 ... ** ... Exponentiation.
9323 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
9324 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
9325 ... + ... Addition. +EXPR Makes EXPR into scalar context.
9326 ++ Auto-increment (magical on strings). ++EXPR EXPR++
9327 ... += ... Addition assignment.
9329 ... - ... Subtraction.
9330 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
9331 ... -= ... Subtraction assignment.
9332 -A Access time in days since script started.
9333 -B File is a non-text (binary) file.
9334 -C Inode change time in days since script started.
9335 -M Age in days since script started.
9336 -O File is owned by real uid.
9337 -R File is readable by real uid.
9338 -S File is a socket .
9339 -T File is a text file.
9340 -W File is writable by real uid.
9341 -X File is executable by real uid.
9342 -b File is a block special file.
9343 -c File is a character special file.
9344 -d File is a directory.
9346 -f File is a plain file.
9347 -g File has setgid bit set.
9348 -k File has sticky bit set.
9349 -l File is a symbolic link.
9350 -o File is owned by effective uid.
9351 -p File is a named pipe (FIFO).
9352 -r File is readable by effective uid.
9353 -s File has non-zero size.
9354 -t Tests if filehandle (STDIN by default) is opened to a tty.
9355 -u File has setuid bit set.
9356 -w File is writable by effective uid.
9357 -x File is executable by effective uid.
9358 -z File has zero size.
9359 . Concatenate strings.
9360 .. Range (list context); flip/flop (scalar context) operator.
9361 .= Concatenate assignment strings
9362 ... / ... Division. /PATTERN/ioxsmg Pattern match
9363 ... /= ... Division assignment.
9364 /PATTERN/ioxsmg Pattern match.
9365 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
9366 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
9367 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
9368 <> Reads line from union of files in @ARGV (= command line) and STDIN.
9369 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
9370 ... <= ... Numeric less than or equal to.
9371 ... <=> ... Numeric compare.
9372 ... = ... Assignment.
9373 ... == ... Numeric equality.
9374 ... =~ ... Search pattern, substitution, or translation
9375 ... > ... Numeric greater than.
9376 ... >= ... Numeric greater than or equal to.
9377 ... >> ... Bitwise shift right.
9378 ... >>= ... Bitwise shift right assignment.
9379 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
9380 ?PATTERN? One-time pattern match.
9381 @ARGV Command line arguments (not including the command name - see $0).
9382 @INC List of places to look for perl scripts during do/include/use.
9383 @_ Parameter array for subroutines; result of split() unless in list context.
9384 \\ Creates reference to what follows, like \$var, or quotes non-\w in strings.
9385 \\0 Octal char, e.g. \\033.
9386 \\E Case modification terminator. See \\Q, \\L, and \\U.
9387 \\L Lowercase until \\E . See also \\l, lc.
9388 \\U Upcase until \\E . See also \\u, uc.
9389 \\Q Quote metacharacters until \\E . See also quotemeta.
9390 \\a Alarm character (octal 007).
9391 \\b Backspace character (octal 010).
9392 \\c Control character, e.g. \\c[ .
9393 \\e Escape character (octal 033).
9394 \\f Formfeed character (octal 014).
9395 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
9396 \\n Newline character (octal 012 on most systems).
9397 \\r Return character (octal 015 on most systems).
9398 \\t Tab character (octal 011).
9399 \\u Upcase the next character. See also \\U and \\l, ucfirst.
9400 \\x Hex character, e.g. \\x1b.
9401 ... ^ ... Bitwise exclusive or.
9402 __END__ Ends program source.
9403 __DATA__ Ends program source.
9404 __FILE__ Current (source) filename.
9405 __LINE__ Current line in current source.
9406 __PACKAGE__ Current package.
9407 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
9408 ARGVOUT Output filehandle with -i flag.
9409 BEGIN { ... } Immediately executed (during compilation) piece of code.
9410 END { ... } Pseudo-subroutine executed after the script finishes.
9411 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
9412 INIT { ... } Pseudo-subroutine executed before the script starts running.
9413 DATA Input filehandle for what follows after __END__ or __DATA__.
9414 accept(NEWSOCKET,GENERICSOCKET)
9427 ... cmp ... String compare.
9428 connect(SOCKET,NAME)
9429 continue of { block } continue { block }. Is executed after `next' or at end.
9431 crypt(PLAINTEXT,SALT)
9433 dbmopen(%HASH,DBNAME,MODE)
9437 do { ... }|SUBR while|until EXPR executes at least once
9438 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
9448 ... eq ... String equality.
9449 eval(EXPR) or eval { BLOCK }
9450 exec([TRUENAME] ARGV0, ARGVs) or exec(SHELL_COMMAND_LINE)
9453 fcntl(FILEHANDLE,FUNCTION,SCALAR)
9455 flock(FILEHANDLE,OPERATION)
9456 for (EXPR;EXPR;EXPR) { ... }
9457 foreach [VAR] (@ARRAY) { ... }
9459 ... ge ... String greater than or equal.
9464 gethostbyaddr(ADDR,ADDRTYPE)
9468 getnetbyaddr(ADDR,ADDRTYPE)
9474 getpriority(WHICH,WHO)
9475 getprotobyname(NAME)
9476 getprotobynumber(NUMBER)
9481 getservbyname(NAME,PROTO)
9482 getservbyport(PORT,PROTO)
9485 getsockopt(SOCKET,LEVEL,OPTNAME)
9488 ... gt ... String greater than.
9490 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
9491 index(STR,SUBSTR[,OFFSET])
9493 ioctl(FILEHANDLE,FUNCTION,SCALAR)
9498 ... le ... String less than or equal.
9500 link(OLDFILE,NEWFILE)
9501 listen(SOCKET,QUEUESIZE)
9505 lstat(EXPR|FILEHANDLE|VAR)
9506 ... lt ... String less than.
9508 mkdir(FILENAME,MODE)
9511 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
9512 msgsnd(ID,MSG,FLAGS)
9513 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
9514 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
9515 ... ne ... String inequality.
9518 open(FILEHANDLE[,EXPR])
9519 opendir(DIRHANDLE,EXPR)
9520 ord(EXPR) ASCII value of the first char of the string.
9522 package NAME Introduces package context.
9523 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
9525 print [FILEHANDLE] [(LIST)]
9526 printf [FILEHANDLE] (FORMAT,LIST)
9528 q/STRING/ Synonym for 'STRING'
9529 qq/STRING/ Synonym for \"STRING\"
9530 qx/STRING/ Synonym for `STRING`
9532 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9535 recv(SOCKET,SCALAR,LEN,FLAGS)
9537 rename(OLDNAME,NEWNAME)
9538 require [FILENAME | PERL_VERSION]
9542 rewinddir(DIRHANDLE)
9543 rindex(STR,SUBSTR[,OFFSET])
9545 s/PATTERN/REPLACEMENT/gieoxsm
9547 seek(FILEHANDLE,POSITION,WHENCE)
9548 seekdir(DIRHANDLE,POS)
9549 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
9550 semctl(ID,SEMNUM,CMD,ARG)
9551 semget(KEY,NSEMS,SIZE,FLAGS)
9553 send(SOCKET,MSG,FLAGS[,TO])
9555 sethostent(STAYOPEN)
9558 setpriority(WHICH,WHO,PRIORITY)
9559 setprotoent(STAYOPEN)
9561 setservent(STAYOPEN)
9562 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
9565 shmget(KEY,SIZE,FLAGS)
9566 shmread(ID,VAR,POS,SIZE)
9567 shmwrite(ID,STRING,POS,SIZE)
9568 shutdown(SOCKET,HOW)
9571 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
9572 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
9573 sort [SUBROUTINE] (LIST)
9574 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
9575 split[(/PATTERN/[,EXPR[,LIMIT]])]
9576 sprintf(FORMAT,LIST)
9579 stat(EXPR|FILEHANDLE|VAR)
9581 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
9582 substr(EXPR,OFFSET[,LEN])
9583 symlink(OLDFILE,NEWFILE)
9585 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9586 system([TRUENAME] ARGV0 [,ARGV]) or system(SHELL_COMMAND_LINE)
9587 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9592 tr/SEARCHLIST/REPLACEMENTLIST/cds
9593 truncate(FILE|EXPR,LENGTH)
9596 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
9598 unpack(TEMPLATE,EXPR)
9600 until (EXPR) { ... } EXPR until EXPR
9603 vec(EXPR,OFFSET,BITS)
9606 wantarray Returns true if the sub/eval is called in list context.
9608 while (EXPR) { ... } EXPR while EXPR
9609 write[(EXPR|FILEHANDLE)]
9610 ... x ... Repeat string or array.
9611 x= ... Repetition assignment.
9612 y/SEARCHLIST/REPLACEMENTLIST/
9613 ... | ... Bitwise or.
9614 ... || ... Logical or.
9615 ~ ... Unary bitwise complement.
9616 #! OS interpreter indicator. If contains `perl', used for options, and -x.
9617 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
9618 CORE:: Prefix to access builtin function if imported sub obscures it.
9619 SUPER:: Prefix to lookup for a method in @ISA classes.
9620 DESTROY Shorthand for `sub DESTROY {...}'.
9621 ... EQ ... Obsolete synonym of `eq'.
9622 ... GE ... Obsolete synonym of `ge'.
9623 ... GT ... Obsolete synonym of `gt'.
9624 ... LE ... Obsolete synonym of `le'.
9625 ... LT ... Obsolete synonym of `lt'.
9626 ... NE ... Obsolete synonym of `ne'.
9627 abs [ EXPR ] absolute value
9628 ... and ... Low-precedence synonym for &&.
9629 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
9630 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
9631 chr Converts a number to char with the same ordinal.
9632 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
9633 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
9634 exists $HASH{KEY} True if the key exists.
9635 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
9636 formline PICTURE, LIST Backdoor into \"format\" processing.
9637 glob EXPR Synonym of <EXPR>.
9638 lc [ EXPR ] Returns lowercased EXPR.
9639 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
9640 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
9641 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
9642 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
9643 not ... Low-precedence synonym for ! - negation.
9644 ... or ... Low-precedence synonym for ||.
9645 pos STRING Set/Get end-position of the last match over this string, see \\G.
9646 quotemeta [ EXPR ] Quote regexp metacharacters.
9647 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
9648 readline FH Synonym of <FH>.
9649 readpipe CMD Synonym of `CMD`.
9650 ref [ EXPR ] Type of EXPR when dereferenced.
9651 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
9652 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
9653 tied Returns internal object for a tied data.
9654 uc [ EXPR ] Returns upcased EXPR.
9655 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
9656 untie VAR Unlink an object from a simple Perl variable.
9657 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
9658 ... xor ... Low-precedence synonym for exclusive or.
9659 prototype \&SUB Returns prototype of the function given a reference.
9660 =head1 Top-level heading.
9661 =head2 Second-level heading.
9662 =head3 Third-level heading (is there such?).
9663 =over [ NUMBER ] Start list.
9664 =item [ TITLE ] Start new item in the list.
9666 =cut Switch from POD to Perl.
9667 =pod Switch from Perl to POD.
9670 (defun cperl-switch-to-doc-buffer ()
9671 "Go to the perl documentation buffer and insert the documentation."
9673 (let ((buf (get-buffer-create cperl-doc-buffer)))
9675 (switch-to-buffer-other-window buf)
9677 (if (= (buffer-size) 0)
9679 (insert (documentation-property 'cperl-short-docs
9680 'variable-documentation))
9681 (setq buffer-read-only t)))))
9683 (defun cperl-beautify-regexp-piece (b e embed level)
9684 ;; b is before the starting delimiter, e before the ending
9685 ;; e should be a marker, may be changed, but remains "correct".
9686 ;; EMBED is nil iff we process the whole REx.
9687 ;; The REx is guaranteed to have //x
9688 ;; LEVEL shows how many levels deep to go
9689 ;; position at enter and at leave is not defined
9690 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
9694 (setq c (if (eq embed t) (current-indentation) (current-column)))
9695 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
9699 ((looking-at "(\\?[^a-zA-Z]")
9701 ((looking-at "(\\?") ; (?i)
9706 (setq c (1- (current-column))))
9707 (setq c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
9708 (or (looking-at "[ \t]*[\n#]")
9713 (if (re-search-forward "[^ \t]" e t)
9714 (progn ; Something before the ending delimiter
9716 (delete-horizontal-space)
9718 (cperl-make-indent c)
9719 (set-marker e (point))))
9722 (while (< (point) (marker-position e))
9726 (skip-chars-forward " \t")
9727 (delete-region s (point))
9728 (cperl-make-indent c1)
9732 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
9733 "\\|" ; Embedded variable
9734 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
9737 "\\|" ; simple-code simple-code*?
9738 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
9742 "\\((\\(\\?\\)?\\)" ; 7 8
9745 (goto-char (match-end 0))
9747 (cond ((match-beginning 1) ; Alphanum word + junk
9749 ((or (match-beginning 3) ; $ab[12]
9750 (and (match-beginning 5) ; X* X+ X{2,3}
9751 (eq (preceding-char) ?\{)))
9754 ((and ; [], already syntaxified
9757 cperl-use-syntax-table-text-property)
9760 (or (eq (preceding-char) ?\])
9761 (error "[]-group not terminated"))
9763 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
9764 ((match-beginning 6) ; []
9766 (if (looking-at "\\^?\\]")
9767 (goto-char (match-end 0)))
9768 ;; XXXX POSIX classes?!
9769 (while (and (not pos)
9770 (re-search-forward "\\[:\\|\\]" e t))
9771 (if (eq (preceding-char) ?:)
9772 (or (re-search-forward ":\\]" e t)
9773 (error "[:POSIX:]-group in []-group not terminated"))
9775 (or (eq (preceding-char) ?\])
9776 (error "[]-group not terminated"))
9778 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
9779 ((match-beginning 7) ; ()
9780 (goto-char (match-beginning 0))
9781 (setq pos (current-column))
9784 (delete-horizontal-space)
9786 (cperl-make-indent c1)))
9789 ;; (or (forward-sexp 1)
9792 ;; (error "()-group not terminated")))
9793 (set-marker m (1- (point)))
9794 (set-marker m1 (point))
9796 (if (progn ; indent rigidly if multiline
9797 ;; In fact does not make a lot of sense, since
9798 ;; the starting position can be already lost due
9799 ;; to insertion of "\n" and " "
9801 (search-forward "\n" m1 t))
9802 (indent-rigidly (point) m1 (- c1 pos)))
9803 (setq level (1- level))
9805 ((not (match-beginning 8))
9806 (cperl-beautify-regexp-piece tmp m t level))
9807 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
9809 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
9810 (goto-char (+ 2 tmp))
9812 (cperl-beautify-regexp-piece (point) m t level))
9813 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
9814 (goto-char (+ 3 tmp))
9815 (cperl-beautify-regexp-piece (point) m t level))
9817 (cperl-beautify-regexp-piece tmp m t level))))
9819 (cond ((looking-at "[*+?]\\??")
9820 (goto-char (match-end 0)))
9821 ((eq (following-char) ?\{)
9823 (if (eq (following-char) ?\?)
9825 (skip-chars-forward " \t")
9827 (if (looking-at "[#\n]")
9829 (or (eolp) (indent-for-comment))
9830 (beginning-of-line 2))
9831 (delete-horizontal-space)
9835 ((match-beginning 9) ; |
9839 (if (re-search-forward "[^ \t]" tmp t)
9842 (delete-horizontal-space)
9845 (delete-region (point) tmp))
9846 (cperl-make-indent c)
9848 (skip-chars-forward " \t")
9850 (if (looking-at "[#\n]")
9851 (beginning-of-line 2)
9852 (delete-horizontal-space)
9856 (or (looking-at "[ \t\n]")
9859 (skip-chars-forward " \t"))
9860 (or (looking-at "[#\n]")
9861 (error "Unknown code `%s' in a regexp"
9862 (buffer-substring (point) (1+ (point)))))
9863 (and inline (end-of-line 2)))
9864 ;; Special-case the last line of group
9865 (if (and (>= (point) (marker-position e))
9866 (/= (current-indentation) c))
9869 (cperl-make-indent c)))))
9871 (defun cperl-make-regexp-x ()
9872 ;; Returns position of the start
9873 ;; XXX this is called too often! Need to cache the result!
9875 (or cperl-use-syntax-table-text-property
9876 (error "I need to have a regexp marked!"))
9878 (if (looking-at "\\s|")
9880 (if (or (looking-at "\\([smy]\\|qr\\)\\s|")
9881 (and (eq (preceding-char) ?q)
9882 (looking-at "\\(r\\)\\s|")))
9883 (goto-char (match-end 1))
9884 (re-search-backward "\\s|"))) ; Assume it is scanned already.
9886 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
9887 (sub-p (eq (preceding-char) ?s)) s)
9889 (set-marker e (1- (point)))
9890 (setq delim (preceding-char))
9891 (if (and sub-p (eq delim (char-after (- (point) 2))))
9892 (error "Possible s/blah// - do not know how to deal with"))
9893 (if sub-p (forward-sexp 1))
9894 (if (looking-at "\\sw*x")
9897 ;; Protect fragile " ", "#"
9900 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
9906 (defun cperl-beautify-regexp (&optional deep)
9907 "Do it. (Experimental, may change semantics, recheck the result.)
9908 We suppose that the regexp is scanned already."
9910 (setq deep (if deep (prefix-numeric-value deep) -1))
9912 (goto-char (cperl-make-regexp-x))
9913 (let ((b (point)) (e (make-marker)))
9915 (set-marker e (1- (point)))
9916 (cperl-beautify-regexp-piece b e nil deep))))
9918 (defun cperl-regext-to-level-start ()
9919 "Goto start of an enclosing group in regexp.
9920 We suppose that the regexp is scanned already."
9922 (let ((limit (cperl-make-regexp-x)) done)
9924 (or (eq (following-char) ?\()
9925 (search-backward "(" (1+ limit) t)
9926 (error "Cannot find `(' which starts a group"))
9929 (skip-chars-backward "\\")
9930 (looking-at "\\(\\\\\\\\\\)*(")))
9931 (or done (forward-char -1)))))
9933 (defun cperl-contract-level ()
9934 "Find an enclosing group in regexp and contract it.
9935 \(Experimental, may change semantics, recheck the result.)
9936 We suppose that the regexp is scanned already."
9938 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
9939 (cperl-regext-to-level-start)
9940 (let ((b (point)) (e (make-marker)) c)
9942 (set-marker e (1- (point)))
9944 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
9946 ((match-beginning 1) ; #-comment
9947 (or c (setq c (current-indentation)))
9948 (beginning-of-line 2) ; Skip
9949 (cperl-make-indent c))
9952 (just-one-space))))))
9954 (defun cperl-contract-levels ()
9955 "Find an enclosing group in regexp and contract all the kids.
9956 \(Experimental, may change semantics, recheck the result.)
9957 We suppose that the regexp is scanned already."
9961 (cperl-regext-to-level-start)
9962 (error ; We are outside outermost group
9963 (goto-char (cperl-make-regexp-x))))
9964 (let ((b (point)) (e (make-marker)) s c)
9966 (set-marker e (1- (point)))
9968 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
9970 ((match-beginning 1) ; Skip
9973 (cperl-contract-level)))))))
9975 (defun cperl-beautify-level (&optional deep)
9976 "Find an enclosing group in regexp and beautify it.
9977 \(Experimental, may change semantics, recheck the result.)
9978 We suppose that the regexp is scanned already."
9980 (setq deep (if deep (prefix-numeric-value deep) -1))
9982 (cperl-regext-to-level-start)
9983 (let ((b (point)) (e (make-marker)))
9985 (set-marker e (1- (point)))
9986 (cperl-beautify-regexp-piece b e 'level deep))))
9988 (defun cperl-invert-if-unless-modifiers ()
9989 "Change `B if A;' into `if (A) {B}' etc if possible.
9992 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string
9993 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>"))
9994 (and (= (char-syntax (preceding-char)) ?w)
9996 (setq pre-if (point))
9997 (cperl-backward-to-start-of-expr)
9998 (setq pre-B (point))
9999 (forward-sexp 1) ; otherwise forward-to-end-of-expr is NOP
10000 (cperl-forward-to-end-of-expr)
10001 (setq post-A (point))
10003 (or (looking-at w-rex)
10004 ;; Find the position
10005 (progn (goto-char post-A)
10007 (not (looking-at w-rex))
10010 (setq pre-if (point))))
10011 (or (looking-at w-rex)
10012 (error "Can't find `if', `unless', `while', `until', `for' or `foreach'"))
10013 ;; 1 B 2 ... 3 B-com ... 4 if 5 ... if-com 6 ... 7 A 8
10014 (setq if-string (buffer-substring (match-beginning 0) (match-end 0)))
10015 ;; First, simple part: find code boundaries
10017 (setq post-if (point))
10020 (setq post-B (point))
10021 (cperl-backward-to-start-of-expr)
10022 (setq pre-B (point))
10023 (setq B (buffer-substring pre-B post-B))
10027 ;; May be after $, @, $# etc of a variable
10028 (skip-chars-backward "$@%#")
10029 (setq pre-A (point))
10030 (cperl-forward-to-end-of-expr)
10031 (setq post-A (point))
10032 (setq A (buffer-substring pre-A post-A))
10033 ;; Now modify (from end, to not break the stuff)
10034 (skip-chars-forward " \t;")
10035 (delete-region pre-A (point)) ; we move to pre-A
10036 (insert "\n" B ";\n}")
10037 (and (looking-at "[ \t]*#") (cperl-indent-for-comment))
10038 (delete-region pre-if post-if)
10039 (delete-region pre-B post-B)
10041 (insert if-string " (" A ") {")
10042 (setq post-B (point))
10043 (if (looking-at "[ \t]+$")
10044 (delete-horizontal-space)
10045 (if (looking-at "[ \t]*#")
10046 (cperl-indent-for-comment)
10049 (if (looking-at "[ \t]*$")
10050 (progn ; delete line
10051 (delete-horizontal-space)
10052 (delete-region (point) (1+ (point)))))
10053 (cperl-indent-line)
10054 (goto-char (1- post-B))
10056 (cperl-indent-line)
10057 (goto-char pre-B)))
10059 (defun cperl-invert-if-unless ()
10060 "Change `if (A) {B}' into `B if A;' etc (or visa versa) if possible.
10061 If the cursor is not on the leading keyword of the BLOCK flavor of
10062 construct, will assume it is the STATEMENT flavor, so will try to find
10063 the appropriate statement modifier."
10065 (and (= (char-syntax (preceding-char)) ?w)
10067 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
10068 (let ((pre-if (point))
10069 pre-A post-A pre-B post-B A B state p end-B-code is-block B-comment
10070 (if-string (buffer-substring (match-beginning 0) (match-end 0))))
10072 (setq post-A (point))
10074 (setq pre-A (point))
10075 (setq is-block (and (eq (following-char) ?\( )
10077 (condition-case nil
10081 (eq (following-char) ?\{ ))
10087 (setq post-B (point))
10089 (setq pre-B (point))
10090 (if (and (eq (following-char) ?\{ )
10092 (cperl-backward-to-noncomment post-A)
10093 (eq (preceding-char) ?\) )))
10094 (if (condition-case nil
10099 (looking-at "\\<els\\(e\\|if\\)\\>"))
10102 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" if-string)
10103 (goto-char (1- post-B))
10104 (cperl-backward-to-noncomment pre-B)
10105 (if (eq (preceding-char) ?\;)
10107 (setq end-B-code (point))
10109 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" end-B-code t)
10110 (setq p (match-beginning 0)
10111 A (buffer-substring p (match-end 0))
10112 state (parse-partial-sexp pre-B p))
10116 (error "`%s' inside `%s' BLOCK" A if-string))
10117 (goto-char (match-end 0)))
10119 (goto-char (1+ pre-B))
10120 (skip-chars-forward " \t\n")
10121 (setq B (buffer-substring (point) end-B-code))
10122 (goto-char end-B-code)
10123 (or (looking-at ";?[ \t\n]*}")
10125 (skip-chars-forward "; \t\n")
10127 (buffer-substring (point) (1- post-B)))))
10130 (goto-char (1- post-A))
10131 (cperl-backward-to-noncomment pre-A)
10132 (or (looking-at "[ \t\n]*)")
10133 (goto-char (1- post-A)))
10135 (goto-char (1+ pre-A))
10136 (skip-chars-forward " \t\n")
10137 (setq A (buffer-substring (point) p))
10138 (delete-region pre-B post-B)
10139 (delete-region pre-A post-A)
10142 (and B-comment (insert B-comment " "))
10145 (setq pre-A (point))
10147 (delete-horizontal-space)
10148 (setq post-B (point))
10149 (if (looking-at "#")
10150 (indent-for-comment))
10153 (delete-horizontal-space)
10157 (setq pre-A (set-marker (make-marker) pre-A))
10158 (while (<= (point) (marker-position pre-A))
10159 (cperl-indent-line)
10161 (goto-char (marker-position pre-A))
10165 (indent-for-comment)
10166 (goto-char (marker-position pre-A)))))
10167 (error "`%s' (EXPR) not with an {BLOCK}" if-string)))
10168 ;; (error "`%s' not with an (EXPR)" if-string)
10170 (cperl-invert-if-unless-modifiers)))
10171 ;;(error "Not at `if', `unless', `while', `until', `for' or `foreach'")
10172 (cperl-invert-if-unless-modifiers)))
10174 ;;; By Anthony Foiani <afoiani@uswest.com>
10175 ;;; Getting help on modules in C-h f ?
10176 ;;; This is a modified version of `man'.
10177 ;;; Need to teach it how to lookup functions
10179 (defun cperl-perldoc (word)
10180 "Run `perldoc' on WORD."
10182 (list (let* ((default-entry (cperl-word-at-point))
10183 (input (read-string
10184 (format "perldoc entry%s: "
10185 (if (string= default-entry "")
10187 (format " (default %s)" default-entry))))))
10188 (if (string= input "")
10189 (if (string= default-entry "")
10190 (error "No perldoc args given")
10194 (let* ((case-fold-search nil)
10196 (string-match "^[a-z]+$" word)
10197 (string-match (concat "^" word "\\>")
10198 (documentation-property
10200 'variable-documentation))))
10202 (manual-program (if is-func "perldoc -f" "perldoc")))
10205 (let ((Manual-program "perldoc")
10206 (Manual-switches (if is-func (list "-f"))))
10207 (manual-entry word)))
10209 (Man-getpage-in-background word))))) ; uses `Man-switches'
10212 (defun cperl-perldoc-at-point ()
10213 "Run a `perldoc' on the word around point."
10215 (cperl-perldoc (cperl-word-at-point)))
10217 (defcustom pod2man-program "pod2man"
10218 "*File name for `pod2man'."
10222 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
10223 (defun cperl-pod-to-manpage ()
10224 "Create a virtual manpage in Emacs from the Perl Online Documentation."
10227 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
10228 (bufname (concat "Man " buffer-file-name))
10229 (buffer (generate-new-buffer bufname)))
10231 (set-buffer buffer)
10232 (let ((process-environment (copy-sequence process-environment)))
10233 ;; Prevent any attempt to use display terminal fanciness.
10234 (setenv "TERM" "dumb")
10235 (set-process-sentinel
10236 (start-process pod2man-program buffer "sh" "-c"
10237 (format (cperl-pod2man-build-command) pod2man-args))
10238 'Man-bgproc-sentinel)))))
10240 ;;; Updated version by him too
10241 (defun cperl-build-manpage ()
10242 "Create a virtual manpage in Emacs from the POD in the file."
10247 (let ((Manual-program "perldoc"))
10248 (manual-entry buffer-file-name)))
10250 (let* ((manual-program "perldoc")
10252 (Man-getpage-in-background buffer-file-name)))))
10254 (defun cperl-pod2man-build-command ()
10255 "Builds the entire background manpage and cleaning command."
10256 (let ((command (concat pod2man-program " %s 2>/dev/null"))
10257 (flist (and (boundp 'Man-filter-list) Man-filter-list)))
10258 (while (and flist (car flist))
10259 (let ((pcom (car (car flist)))
10260 (pargs (cdr (car flist))))
10262 (concat command " | " pcom " "
10263 (mapconcat '(lambda (phrase)
10264 (if (not (stringp phrase))
10265 (error "Malformed Man-filter-list"))
10268 (setq flist (cdr flist))))
10272 (defun cperl-next-interpolated-REx-1 ()
10273 "Move point to next REx which has interpolated parts without //o.
10274 Skips RExes consisting of one interpolated variable.
10276 Note that skipped RExen are not performance hits."
10278 (cperl-next-interpolated-REx 1))
10280 (defun cperl-next-interpolated-REx-0 ()
10281 "Move point to next REx which has interpolated parts without //o."
10283 (cperl-next-interpolated-REx 0))
10285 (defun cperl-next-interpolated-REx (&optional skip beg limit)
10286 "Move point to next REx which has interpolated parts.
10287 SKIP is a list of possible types to skip, BEG and LIMIT are the starting
10288 point and the limit of search (default to point and end of buffer).
10290 SKIP may be a number, then it behaves as list of numbers up to SKIP; this
10291 semantic may be used as a numeric argument.
10293 Types are 0 for / $rex /o (interpolated once), 1 for /$rex/ (if $rex is
10294 a result of qr//, this is not a performance hit), t for the rest."
10296 (if (numberp skip) (setq skip (list 0 skip)))
10297 (or beg (setq beg (point)))
10298 (or limit (setq limit (point-max))) ; needed for n-s-p-c
10300 (and (eq (get-text-property beg 'syntax-type) 'string)
10301 (setq beg (next-single-property-change beg 'syntax-type nil limit)))
10302 (cperl-map-pods-heres
10303 (function (lambda (s e p)
10304 (if (memq (get-text-property s 'REx-interpolated) skip)
10308 'REx-interpolated beg limit)
10309 (if pp (goto-char pp)
10310 (message "No more interpolated REx"))))
10312 ;;; Initial version contributed by Trey Belew
10313 (defun cperl-here-doc-spell (&optional beg end)
10314 "Spell-check HERE-documents in the Perl buffer.
10315 If a region is highlighted, restricts to the region."
10317 (cperl-pod-spell t beg end))
10319 (defun cperl-pod-spell (&optional do-heres beg end)
10320 "Spell-check POD documentation.
10321 If invoked with prefix argument, will do HERE-DOCs instead.
10322 If a region is highlighted, restricts to the region."
10326 (if (cperl-mark-active)
10327 (setq beg (min (mark) (point))
10328 end (max (mark) (point)))
10329 (setq beg (point-min)
10331 (cperl-map-pods-heres (function
10334 (setq e (save-excursion
10338 (ispell-region s e)
10340 (if do-heres 'here-doc-group 'in-pod)
10343 (defun cperl-map-pods-heres (func &optional prop s end)
10344 "Executes a function over regions of pods or here-documents.
10345 PROP is the text-property to search for; default to `in-pod'. Stop when
10346 function returns nil."
10347 (let (pos posend has-prop (cont t))
10348 (or prop (setq prop 'in-pod))
10349 (or s (setq s (point-min)))
10350 (or end (setq end (point-max)))
10351 (cperl-update-syntaxification end end)
10353 (goto-char (setq pos s))
10354 (while (and cont (< pos end))
10355 (setq has-prop (get-text-property pos prop))
10356 (setq posend (next-single-property-change pos prop nil end))
10358 (setq cont (funcall func pos posend prop)))
10359 (setq pos posend)))))
10361 ;;; Based on code by Masatake YAMATO:
10362 (defun cperl-get-here-doc-region (&optional pos pod)
10363 "Return HERE document region around the point.
10364 Return nil if the point is not in a HERE document region. If POD is non-nil,
10365 will return a POD section if point is in a POD section."
10366 (or pos (setq pos (point)))
10367 (cperl-update-syntaxification pos pos)
10368 (if (or (eq 'here-doc (get-text-property pos 'syntax-type))
10370 (eq 'pod (get-text-property pos 'syntax-type))))
10371 (let ((b (cperl-beginning-of-property pos 'syntax-type))
10372 (e (next-single-property-change pos 'syntax-type)))
10373 (cons b (or e (point-max))))))
10375 (defun cperl-narrow-to-here-doc (&optional pos)
10376 "Narrows editing region to the HERE-DOC at POS.
10377 POS defaults to the point."
10379 (or pos (setq pos (point)))
10380 (let ((p (cperl-get-here-doc-region pos)))
10381 (or p (error "Not inside a HERE document"))
10382 (narrow-to-region (car p) (cdr p))
10384 "When you are finished with narrow editing, type C-x n w")))
10386 (defun cperl-select-this-pod-or-here-doc (&optional pos)
10387 "Select the HERE-DOC (or POD section) at POS.
10388 POS defaults to the point."
10390 (let ((p (cperl-get-here-doc-region pos t)))
10393 (goto-char (car p))
10394 (push-mark (cdr p) nil t)) ; Message, activate in transient-mode
10395 (message "I do not think POS is in POD or a HERE-doc..."))))
10397 (defun cperl-facemenu-add-face-function (face end)
10398 "A callback to process user-initiated font-change requests.
10399 Translates `bold', `italic', and `bold-italic' requests to insertion of
10400 corresponding POD directives, and `underline' to C<> POD directive.
10402 Such requests are usually bound to M-o LETTER."
10403 (or (get-text-property (point) 'in-pod)
10404 (error "Faces can only be set within POD"))
10405 (setq facemenu-end-add-face (if (eq face 'bold-italic) ">>" ">"))
10406 (cdr (or (assq face '((bold . "B<")
10408 (bold-italic . "B<I<")
10409 (underline . "C<")))
10410 (error "Face %s not configured for cperl-mode"
10413 (defun cperl-time-fontification (&optional l step lim)
10414 "Times how long it takes to do incremental fontification in a region.
10415 L is the line to start at, STEP is the number of lines to skip when
10416 doing next incremental fontification, LIM is the maximal number of
10417 incremental fontification to perform. Messages are accumulated in
10420 May be used for pinpointing which construct slows down buffer fontification:
10421 start with default arguments, then refine the slowdown regions."
10422 (interactive "nLine to start at: \nnStep to do incremental fontification: ")
10424 (or step (setq step 500))
10425 (or lim (setq lim 40))
10426 (let* ((timems (function (lambda ()
10427 (let ((tt (current-time)))
10428 (+ (* 1000 (nth 1 tt)) (/ (nth 2 tt) 1000))))))
10429 (tt (funcall timems)) (c 0) delta tot)
10432 (setq tot (- (- tt (setq tt (funcall timems)))))
10433 (message "cperl-mode at %s: %s" l tot)
10434 (while (and (< c lim) (not (eobp)))
10435 (forward-line step)
10436 (setq l (+ l step))
10438 (cperl-update-syntaxification (point) (point))
10439 (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
10440 (message "to %s:%6s,%7s" l delta tot))
10443 (defun cperl-emulate-lazy-lock (&optional window-size)
10444 "Emulate `lazy-lock' without `condition-case', so `debug-on-error' works.
10445 Start fontifying the buffer from the start (or end) using the given
10446 WINDOW-SIZE (units is lines). Negative WINDOW-SIZE starts at end, and
10447 goes backwards; default is -50. This function is not CPerl-specific; it
10448 may be used to debug problems with delayed incremental fontification."
10450 "nSize of window for incremental fontification, negative goes backwards: ")
10451 (or window-size (setq window-size -50))
10452 (let ((pos (if (> window-size 0)
10458 ;; Why needed??? With older font-locks???
10459 (set (make-local-variable 'font-lock-cache-position) (make-marker))
10460 (while (if (> window-size 0)
10461 (< pos (point-max))
10462 (> pos (point-min)))
10464 (forward-line window-size)
10466 (font-lock-fontify-region (min p pos) (max p pos))
10470 (defun cperl-lazy-install ()) ; Avoid a warning
10471 (defun cperl-lazy-unstall ()) ; Avoid a warning
10473 (if (fboundp 'run-with-idle-timer)
10475 (defvar cperl-help-shown nil
10476 "Non-nil means that the help was already shown now.")
10478 (defvar cperl-lazy-installed nil
10479 "Non-nil means that the lazy-help handlers are installed now.")
10481 (defun cperl-lazy-install ()
10482 "Switches on Auto-Help on Perl constructs (put in the message area).
10483 Delay of auto-help controlled by `cperl-lazy-help-time'."
10485 (make-variable-buffer-local 'cperl-help-shown)
10486 (if (and (cperl-val 'cperl-lazy-help-time)
10487 (not cperl-lazy-installed))
10489 (add-hook 'post-command-hook 'cperl-lazy-hook)
10490 (run-with-idle-timer
10491 (cperl-val 'cperl-lazy-help-time 1000000 5)
10493 'cperl-get-help-defer)
10494 (setq cperl-lazy-installed t))))
10496 (defun cperl-lazy-unstall ()
10497 "Switches off Auto-Help on Perl constructs (put in the message area).
10498 Delay of auto-help controlled by `cperl-lazy-help-time'."
10500 (remove-hook 'post-command-hook 'cperl-lazy-hook)
10501 (cancel-function-timers 'cperl-get-help-defer)
10502 (setq cperl-lazy-installed nil))
10504 (defun cperl-lazy-hook ()
10505 (setq cperl-help-shown nil))
10507 (defun cperl-get-help-defer ()
10508 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
10509 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
10511 (setq cperl-help-shown t))))
10512 (cperl-lazy-install)))
10515 ;;; Plug for wrong font-lock:
10517 (defun cperl-font-lock-unfontify-region-function (beg end)
10518 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
10519 (inhibit-read-only t) (inhibit-point-motion-hooks t)
10520 before-change-functions after-change-functions
10521 deactivate-mark buffer-file-name buffer-file-truename)
10522 (remove-text-properties beg end '(face nil))
10523 (if (and (not modified) (buffer-modified-p))
10524 (set-buffer-modified-p nil))))
10526 (defun cperl-font-lock-fontify-region-function (beg end loudly)
10527 "Extends the region to safe positions, then calls the default function.
10528 Newer `font-lock's can do it themselves.
10529 We unwind only as far as needed for fontification. Syntaxification may
10530 do extra unwind via `cperl-unwind-to-safe'."
10535 (beginning-of-line)
10536 (eq (get-text-property (setq beg (point)) 'syntax-type)
10538 (if (setq beg (cperl-beginning-of-property beg 'syntax-type))
10544 (or (bolp) (condition-case nil
10547 (eq (get-text-property (setq end (point)) 'syntax-type)
10549 (setq end (next-single-property-change end 'syntax-type nil (point-max)))
10551 (setq end (point)))
10552 (font-lock-default-fontify-region beg end loudly))
10554 (defvar cperl-d-l nil)
10555 (defun cperl-fontify-syntaxically (end)
10556 ;; Some vars for debugging only
10557 ;; (message "Syntaxifying...")
10558 (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
10559 (istate (car cperl-syntax-state))
10560 start from-start edebug-backtrace-buffer)
10561 (if (eq cperl-syntaxify-by-font-lock 'backtrace)
10564 (let ((f 'edebug-backtrace))
10565 (funcall f)))) ; Avoid compile-time warning
10566 (or cperl-syntax-done-to
10567 (setq cperl-syntax-done-to (point-min)
10569 (setq start (if (and cperl-hook-after-change
10571 cperl-syntax-done-to ; Fontify without change; ignore start
10572 ;; Need to forget what is after `start'
10573 (min cperl-syntax-done-to (point))))
10575 (beginning-of-line)
10576 (setq start (point))
10577 (and cperl-syntaxify-unwind
10578 (setq end (cperl-unwind-to-safe t end)
10581 (setq cperl-syntax-done-to start) ; In case what follows fails
10582 (cperl-find-pods-heres start end t nil t))
10583 (if (memq cperl-syntaxify-by-font-lock '(backtrace message))
10584 (message "Syxify req=%s..%s actual=%s..%s done-to: %s=>%s statepos: %s=>%s"
10585 dbg iend start end idone cperl-syntax-done-to
10586 istate (car cperl-syntax-state))) ; For debugging
10587 nil)) ; Do not iterate
10589 (defun cperl-fontify-update (end)
10590 (let ((pos (point-min)) prop posend)
10591 (setq end (point-max))
10593 (setq prop (get-text-property pos 'cperl-postpone)
10594 posend (next-single-property-change pos 'cperl-postpone nil end))
10595 (and prop (put-text-property pos posend (car prop) (cdr prop)))
10596 (setq pos posend)))
10597 nil) ; Do not iterate
10599 (defun cperl-fontify-update-bad (end)
10600 ;; Since fontification happens with different region than syntaxification,
10601 ;; do to the end of buffer, not to END;;; likewise, start earlier if needed
10602 (let* ((pos (point)) (prop (get-text-property pos 'cperl-postpone)) posend)
10604 (setq pos (or (cperl-beginning-of-property
10605 (cperl-1+ pos) 'cperl-postpone)
10608 (setq posend (next-single-property-change pos 'cperl-postpone))
10609 (and prop (put-text-property pos posend (car prop) (cdr prop)))
10611 (setq prop (get-text-property pos 'cperl-postpone))))
10612 nil) ; Do not iterate
10614 ;; Called when any modification is made to buffer text.
10615 (defun cperl-after-change-function (beg end old-len)
10616 ;; We should have been informed about changes by `font-lock'. Since it
10617 ;; does not inform as which calls are defered, do it ourselves
10618 (if cperl-syntax-done-to
10619 (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
10621 (defun cperl-update-syntaxification (from to)
10622 (if (and cperl-use-syntax-table-text-property
10623 cperl-syntaxify-by-font-lock
10624 (or (null cperl-syntax-done-to)
10625 (< cperl-syntax-done-to to)))
10629 (cperl-fontify-syntaxically to)))))
10631 (defvar cperl-version
10632 (let ((v "$Revision: 6.2 $"))
10633 (string-match ":\\s *\\([0-9.]+\\)" v)
10634 (substring v (match-beginning 1) (match-end 1)))
10635 "Version of IZ-supported CPerl package this file is based on.")
10637 (if cperl-xemacs-p ;; backwards compatibility for XEmacs old POD spelling stuff
10638 (let ((f 'define-obsolete-function-alias))
10639 (funcall f 'pod-spell 'cperl-pod-spell))) ; Avoid "not defined"
10641 ;; XEmacs additions
10642 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.\\([pP][LlMm]\\|al\\)\\'" . perl-mode))
10643 ;;;###autoload(add-to-list 'interpreter-mode-alist '("perl" . perl-mode))
10645 (provide 'cperl-mode)
10647 ;;; cperl-mode.el ends here