[t/spec] Rewrite a bunch more series test into modern form. Also shorten and make...
[pugs.git] / util / cperl-mode.el
blobf4c46016b4046695403146fd65b669c5ad3d3297
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
5 ;; Free Software Foundation, Inc.
7 ;; Author: Ilya Zakharevich and Bob Olson
8 ;; Maintainer: Ilya Zakharevich <cperl@ilyaz.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)
31 ;; any later version.
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 cperl@ilyaz.org
44 ;;; XEmacs changes by Peter Arius arius@informatik.uni-erlangen.de
46 ;;; Commentary:
48 ;; $Id: cperl-mode.el 266 2006-09-06 09:36:40Z ss5 $
50 ;;; If your Emacs does not default to `cperl-mode' on Perl files:
51 ;;; To use this mode put the following into
52 ;;; your .emacs file:
54 ;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)
56 ;; You can either fine-tune the bells and whistles of this mode or
57 ;; bulk enable them by putting
59 ;; (setq cperl-hairy t)
61 ;; in your .emacs file. (Emacs rulers do not consider it politically
62 ;; correct to make whistles enabled by default.)
64 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
65 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
66 ;; `cperl-non-problems', `cperl-praise', `cperl-speed'. <<<<<<
68 ;; Additional useful commands to put into your .emacs file (before
69 ;; RMS Emacs 20.3):
71 ;; (setq auto-mode-alist
72 ;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
73 ;; (setq interpreter-mode-alist (append interpreter-mode-alist
74 ;; '(("miniperl" . perl-mode))))
76 ;; The mode information (on C-h m) provides some customization help.
77 ;; If you use font-lock feature of this mode, it is advisable to use
78 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
80 ;; Faces used now: three faces for first-class and second-class keywords
81 ;; and control flow words, one for each: comments, string, labels,
82 ;; functions definitions and packages, arrays, hashes, and variable
83 ;; definitions. If you do not see all these faces, your font-lock does
84 ;; not define them, so you need to define them manually.
85 ;; Maybe you have an obsolete font-lock from 19.28 or earlier. Upgrade.
87 ;; If you have a grayscale monitor, and do not have the variable
88 ;; font-lock-display-type bound to 'grayscale, insert
90 ;; (setq font-lock-display-type 'grayscale)
92 ;; into your .emacs file (this is relevant before RMS Emacs 20).
94 ;; This mode supports font-lock, imenu and mode-compile. In the
95 ;; hairy version font-lock is on, but you should activate imenu
96 ;; yourself (note that mode-compile is not standard yet). Well, you
97 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
98 ;; to bind it like that:
100 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
102 ;;; Font lock bugs as of v4.32:
104 ;; The following kinds of Perl code erroneously start strings:
105 ;; \$` \$' \$"
106 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
107 ;; likewise with m, tr, y, q, qX instead of s
109 ;;; In fact the version of font-lock that this version supports can be
110 ;;; much newer than the version you actually have. This means that a
111 ;;; lot of faces can be set up, but are not visible on your screen
112 ;;; since the coloring rules for this faces are not defined.
114 ;;; Updates: ========================================
116 ;;; Made less hairy by default: parentheses not electric,
117 ;;; linefeed not magic. Bug with abbrev-mode corrected.
119 ;;;; After 1.4:
120 ;;; Better indentation:
121 ;;; subs inside braces should work now,
122 ;;; Toplevel braces obey customization.
123 ;;; indent-for-comment knows about bad cases, cperl-indent-for-comment
124 ;;; moves cursor to a correct place.
125 ;;; cperl-indent-exp written from the scratch! Slow... (quadratic!) :-(
126 ;;; (50 secs on DB::DB (sub of 430 lines), 486/66)
127 ;;; Minor documentation fixes.
128 ;;; Imenu understands packages as prefixes (including nested).
129 ;;; Hairy options can be switched off one-by-one by setting to null.
130 ;;; Names of functions and variables changed to conform to `cperl-' style.
132 ;;;; After 1.5:
133 ;;; Some bugs with indentation of labels (and embedded subs) corrected.
134 ;;; `cperl-indent-region' done (slow :-()).
135 ;;; `cperl-fill-paragraph' done.
136 ;;; Better package support for `imenu'.
137 ;;; Progress indicator for indentation (with `imenu' loaded).
138 ;;; `Cperl-set' was busted, now setting the individual hairy option
139 ;;; should be better.
141 ;;;; After 1.6:
142 ;;; `cperl-set-style' done.
143 ;;; `cperl-check-syntax' done.
144 ;;; Menu done.
145 ;;; New config variables `cperl-close-paren-offset' and `cperl-comment-column'.
146 ;;; Bugs with `cperl-auto-newline' corrected.
147 ;;; `cperl-electric-lbrace' can work with `cperl-auto-newline' in situation
148 ;;; like $hash{.
150 ;;;; 1.7 XEmacs (arius@informatik.uni-erlangen.de):
151 ;;; - use `next-command-event', if `next-command-events' does not exist
152 ;;; - use `find-face' as def. of `is-face'
153 ;;; - corrected def. of `x-color-defined-p'
154 ;;; - added const defs for font-lock-comment-face,
155 ;;; font-lock-keyword-face and font-lock-function-name-face
156 ;;; - added def. of font-lock-variable-name-face
157 ;;; - added (require 'easymenu) inside an `eval-when-compile'
158 ;;; - replaced 4-argument `substitute-key-definition' with ordinary
159 ;;; `define-key's
160 ;;; - replaced `mark-active' in menu definition by `cperl-use-region-p'.
161 ;;; Todo (at least):
162 ;;; - use emacs-vers.el (http://www.cs.utah.edu/~eeide/emacs/emacs-vers.el.gz)
163 ;;; for portable code?
164 ;;; - should `cperl-mode' do a
165 ;;; (if (featurep 'easymenu) (easy-menu-add cperl-menu))
166 ;;; or should this be left to the user's `cperl-mode-hook'?
168 ;;; Some bugs introduced by the above fix corrected (IZ ;-).
169 ;;; Some bugs under XEmacs introduced by the correction corrected.
171 ;;; Some more can remain since there are two many different variants.
172 ;;; Please feedback!
174 ;;; We do not support fontification of arrays and hashes under
175 ;;; obsolete font-lock any more. Upgrade.
177 ;;;; after 1.8 Minor bug with parentheses.
178 ;;;; after 1.9 Improvements from Joe Marzot.
179 ;;;; after 1.10
180 ;;; Does not need easymenu to compile under XEmacs.
181 ;;; `vc-insert-headers' should work better.
182 ;;; Should work with 19.29 and 19.12.
183 ;;; Small improvements to fontification.
184 ;;; Expansion of keywords does not depend on C-? being backspace.
186 ;;; after 1.10+
187 ;;; 19.29 and 19.12 supported.
188 ;;; `cperl-font-lock-enhanced' deprecated. Use font-lock-extra.el.
189 ;;; Support for font-lock-extra.el.
191 ;;;; After 1.11:
192 ;;; Tools submenu.
193 ;;; Support for perl5-info.
194 ;;; `imenu-go-find-at-position' in Tools requires imenu-go.el (see hints above)
195 ;;; Imenu entries do not work with stock imenu.el. Patch sent to maintainers.
196 ;;; Fontifies `require a if b;', __DATA__.
197 ;;; Arglist for auto-fill-mode was incorrect.
199 ;;;; After 1.12:
200 ;;; `cperl-lineup-step' and `cperl-lineup' added: lineup constructions
201 ;;; vertically.
202 ;;; `cperl-do-auto-fill' updated for 19.29 style.
203 ;;; `cperl-info-on-command' now has a default.
204 ;;; Workaround for broken C-h on XEmacs.
205 ;;; VC strings escaped.
206 ;;; C-h f now may prompt for function name instead of going on,
207 ;;; controlled by `cperl-info-on-command-no-prompt'.
209 ;;;; After 1.13:
210 ;;; Msb buffer list includes perl files
211 ;;; Indent-for-comment uses indent-to
212 ;;; Can write tag files using etags.
214 ;;;; After 1.14:
215 ;;; Recognizes (tries to ;-) {...} which are not blocks during indentation.
216 ;;; `cperl-close-paren-offset' affects ?\] too (and ?\} if not block)
217 ;;; Bug with auto-filling comments started with "##" corrected.
219 ;;;; Very slow now: on DB::DB 0.91, 486/66:
221 ;;;Function Name Call Count Elapsed Time Average Time
222 ;;;======================================== ========== ============ ============
223 ;;;cperl-block-p 469 3.7799999999 0.0080597014
224 ;;;cperl-get-state 505 163.39000000 0.3235445544
225 ;;;cperl-comment-indent 12 0.0299999999 0.0024999999
226 ;;;cperl-backward-to-noncomment 939 4.4599999999 0.0047497337
227 ;;;cperl-calculate-indent 505 172.22000000 0.3410297029
228 ;;;cperl-indent-line 505 172.88000000 0.3423366336
229 ;;;cperl-use-region-p 40 0.0299999999 0.0007499999
230 ;;;cperl-indent-exp 1 177.97000000 177.97000000
231 ;;;cperl-to-comment-or-eol 1453 3.9800000000 0.0027391603
232 ;;;cperl-backward-to-start-of-continued-exp 9 0.0300000000 0.0033333333
233 ;;;cperl-indent-region 1 177.94000000 177.94000000
235 ;;;; After 1.15:
236 ;;; Takes into account white space after opening parentheses during indent.
237 ;;; May highlight pods and here-documents: see `cperl-pod-here-scan',
238 ;;; `cperl-pod-here-fontify', `cperl-pod-face'. Does not use this info
239 ;;; for indentation so far.
240 ;;; Fontification updated to 19.30 style.
241 ;;; The change 19.29->30 did not add all the required functionality,
242 ;;; but broke "font-lock-extra.el". Get "choose-color.el" from
243 ;;; http://ilyaz.org/software/emacs
245 ;;;; After 1.16:
246 ;;; else # comment
247 ;;; recognized as a start of a block.
248 ;;; Two different font-lock-levels provided.
249 ;;; `cperl-pod-head-face' introduced. Used for highlighting.
250 ;;; `imenu' marks pods, +Packages moved to the head.
252 ;;;; After 1.17:
253 ;;; Scan for pods highlights here-docs too.
254 ;;; Note that the tag of here-doc may be rehighlighted later by lazy-lock.
255 ;;; Only one here-doc-tag per line is supported, and one in comment
256 ;;; or a string may break fontification.
257 ;;; POD headers were supposed to fill one line only.
259 ;;;; After 1.18:
260 ;;; `font-lock-keywords' were set in 19.30 style _always_. Current scheme
261 ;;; may break under XEmacs.
262 ;;; `cperl-calculate-indent' dis suppose that `parse-start' was defined.
263 ;;; `fontified' tag is added to fontified text as well as `lazy-lock' (for
264 ;;; compatibility with older lazy-lock.el) (older one overfontifies
265 ;;; something nevertheless :-().
266 ;;; Will not indent something inside pod and here-documents.
267 ;;; Fontifies the package name after import/no/bootstrap.
268 ;;; Added new entry to menu with meta-info about the mode.
270 ;;;; After 1.19:
271 ;;; Prefontification works much better with 19.29. Should be checked
272 ;;; with 19.30 as well.
273 ;;; Some misprints in docs corrected.
274 ;;; Now $a{-text} and -text => "blah" are fontified as strings too.
275 ;;; Now the pod search is much stricter, so it can help you to find
276 ;;; pod sections which are broken because of whitespace before =blah
277 ;;; - just observe the fontification.
279 ;;;; After 1.20
280 ;;; Anonymous subs are indented with respect to the level of
281 ;;; indentation of `sub' now.
282 ;;; {} is recognized as hash after `bless' and `return'.
283 ;;; Anonymous subs are split by `cperl-linefeed' as well.
284 ;;; Electric parens embrace a region if present.
285 ;;; To make `cperl-auto-newline' useful,
286 ;;; `cperl-auto-newline-after-colon' is introduced.
287 ;;; `cperl-electric-parens' is now t or nul. The old meaning is moved to
288 ;;; `cperl-electric-parens-string'.
289 ;;; `cperl-toggle-auto-newline' introduced, put on C-c C-a.
290 ;;; `cperl-toggle-abbrev' introduced, put on C-c C-k.
291 ;;; `cperl-toggle-electric' introduced, put on C-c C-e.
292 ;;; Beginning-of-defun-regexp was not anchored.
294 ;;;; After 1.21
295 ;;; Auto-newline grants `cperl-extra-newline-before-brace' if "{" is typed
296 ;;; after ")".
297 ;;; {} is recognized as expression after `tr' and friends.
299 ;;;; After 1.22
300 ;;; Entry Hierarchy added to imenu. Very primitive so far.
301 ;;; One needs newer `imenu-go'.el. A patch to `imenu' is needed as well.
302 ;;; Writes its own TAGS files.
303 ;;; Class viewer based on TAGS files. Does not trace @ISA so far.
304 ;;; 19.31: Problems with scan for PODs corrected.
305 ;;; First POD header correctly fontified.
306 ;;; I needed (setq imenu-use-keymap-menu t) to get good imenu in 19.31.
307 ;;; Apparently it makes a lot of hierarchy code obsolete...
309 ;;;; After 1.23
310 ;;; Tags filler now scans *.xs as well.
311 ;;; The info from *.xs scan is used by the hierarchy viewer.
312 ;;; Hierarchy viewer documented.
313 ;;; Bug in 19.31 imenu documented.
315 ;;;; After 1.24
316 ;;; New location for info-files mentioned,
317 ;;; Electric-; should work better.
318 ;;; Minor bugs with POD marking.
320 ;;;; After 1.25 (probably not...)
321 ;;; `cperl-info-page' introduced.
322 ;;; To make `uncomment-region' working, `comment-region' would
323 ;;; not insert extra space.
324 ;;; Here documents delimiters better recognized
325 ;;; (empty one, and non-alphanums in quotes handled). May be wrong with 1<<14?
326 ;;; `cperl-db' added, used in menu.
327 ;;; imenu scan removes text-properties, for better debugging
328 ;;; - but the bug is in 19.31 imenu.
329 ;;; formats highlighted by font-lock and prescan, embedded comments
330 ;;; are not treated.
331 ;;; POD/friends scan merged in one pass.
332 ;;; Syntax class is not used for analyzing the code, only char-syntax
333 ;;; may be checked against _ or'ed with w.
334 ;;; Syntax class of `:' changed to be _.
335 ;;; `cperl-find-bad-style' added.
337 ;;;; After 1.25
338 ;;; When search for here-documents, we ignore commented << in simplest cases.
339 ;;; `cperl-get-help' added, available on C-h v and from menu.
340 ;;; Auto-help added. Default with `cperl-hairy', switchable on/off
341 ;;; with startup variable `cperl-lazy-help-time' and from
342 ;;; menu. Requires `run-with-idle-timer'.
343 ;;; Highlighting of @abc{@efg} was wrong - interchanged two regexps.
345 ;;;; After 1.27
346 ;;; Indentation: At toplevel after a label - fixed.
347 ;;; 1.27 was put to archives in binary mode ===> DOSish :-(
349 ;;;; After 1.28
350 ;;; Thanks to Martin Buchholz <mrb@Eng.Sun.COM>: misprints in
351 ;;; comments and docstrings corrected, XEmacs support cleaned up.
352 ;;; The closing parenths would enclose the region into matching
353 ;;; parens under the same conditions as the opening ones.
354 ;;; Minor updates to `cperl-short-docs'.
355 ;;; Will not consider <<= as start of here-doc.
357 ;;;; After 1.29
358 ;;; Added an extra advice to look into Micro-docs. ;-).
359 ;;; Enclosing of region when you press a closing parenth is regulated by
360 ;;; `cperl-electric-parens-string'.
361 ;;; Minor updates to `cperl-short-docs'.
362 ;;; `initialize-new-tags-table' called only if present (Does this help
363 ;;; with generation of tags under XEmacs?).
364 ;;; When creating/updating tag files, new info is written at the old place,
365 ;;; or at the end (is this a wanted behaviour? I need this in perl build directory).
367 ;;;; After 1.30
368 ;;; All the keywords from keywords.pl included (maybe with dummy explanation).
369 ;;; No auto-help inside strings, comment, here-docs, formats, and pods.
370 ;;; Shrinkwrapping of info, regulated by `cperl-max-help-size',
371 ;;; `cperl-shrink-wrap-info-frame'.
372 ;;; Info on variables as well.
373 ;;; Recognision of HERE-DOCS improved yet more.
374 ;;; Autonewline works on `}' without warnings.
375 ;;; Autohelp works again on $_[0].
377 ;;;; After 1.31
378 ;;; perl-descr.el found its author - hi, Johan!
379 ;;; Some support for correct indent after here-docs and friends (may
380 ;;; be superseeded by eminent change to Emacs internals).
381 ;;; Should work with older Emaxen as well ( `-style stuff removed).
383 ;;;; After 1.32
385 ;;; Started to add support for `syntax-table' property (should work
386 ;;; with patched Emaxen), controlled by
387 ;;; `cperl-use-syntax-table-text-property'. Currently recognized:
388 ;;; All quote-like operators: m, s, y, tr, qq, qw, qx, q,
389 ;;; // in most frequent context:
390 ;;; after block or
391 ;;; ~ { ( = | & + - * ! , ;
392 ;;; or
393 ;;; while if unless until and or not xor split grep map
394 ;;; Here-documents, formats, PODs,
395 ;;; ${...}
396 ;;; 'abc$'
397 ;;; sub a ($); sub a ($) {}
398 ;;; (provide 'cperl-mode) was missing!
399 ;;; `cperl-after-expr-p' is now much smarter after `}'.
400 ;;; `cperl-praise' added to mini-docs.
401 ;;; Utilities try to support subs-with-prototypes.
403 ;;;; After 1.32.1
404 ;;; `cperl-after-expr-p' is now much smarter after "() {}" and "word {}":
405 ;;; if word is "else, map, grep".
406 ;;; Updated for new values of syntax-table constants.
407 ;;; Uses `help-char' (at last!) (disabled, does not work?!)
408 ;;; A couple of regexps where missing _ in character classes.
409 ;;; -s could be considered as start of regexp, 1../blah/ was not,
410 ;;; as was not /blah/ at start of file.
412 ;;;; After 1.32.2
413 ;;; "\C-hv" was wrongly "\C-hf"
414 ;;; C-hv was not working on `[index()]' because of [] in skip-chars-*.
415 ;;; `__PACKAGE__' supported.
416 ;;; Thanks for Greg Badros: `cperl-lazy-unstall' is more complete,
417 ;;; `cperl-get-help' is made compatible with `query-replace'.
419 ;;;; As of Apr 15, development version of 19.34 supports
420 ;;;; `syntax-table' text properties. Try setting
421 ;;;; `cperl-use-syntax-table-text-property'.
423 ;;;; After 1.32.3
424 ;;; We scan for s{}[] as well (in simplest situations).
425 ;;; We scan for $blah'foo as well.
426 ;;; The default is to use `syntax-table' text property if Emacs is good enough.
427 ;;; `cperl-lineup' is put on C-M-| (=C-M-S-\\).
428 ;;; Start of `cperl-beautify-regexp'.
430 ;;;; After 1.32.4
431 ;;; `cperl-tags-hier-init' did not work in text-mode.
432 ;;; `cperl-noscan-files-regexp' had a misprint.
433 ;;; Generation of Class Hierarchy was broken due to a bug in `x-popup-menu'
434 ;;; in 19.34.
436 ;;;; After 1.33:
437 ;;; my,local highlight vars after {} too.
438 ;;; TAGS could not be created before imenu was loaded.
439 ;;; `cperl-indent-left-aligned-comments' created.
440 ;;; Logic of `cperl-indent-exp' changed a little bit, should be more
441 ;;; robust w.r.t. multiline strings.
442 ;;; Recognition of blah'foo takes into account strings.
443 ;;; Added '.al' to the list of Perl extensions.
444 ;;; Class hierarchy is "mostly" sorted (need to rethink algorthm
445 ;;; of pruning one-root-branch subtrees to get yet better sorting.)
446 ;;; Regeneration of TAGS was busted.
447 ;;; Can use `syntax-table' property when generating TAGS
448 ;;; (governed by `cperl-use-syntax-table-text-property-for-tags').
450 ;;;; After 1.35:
451 ;;; Can process several =pod/=cut sections one after another.
452 ;;; Knows of `extproc' when under `emx', indents with `__END__' and `__DATA__'.
453 ;;; `cperl-under-as-char' implemented (XEmacs people like broken behaviour).
454 ;;; Beautifier for regexps fixed.
455 ;;; `cperl-beautify-level', `cperl-contract-level' coded
457 ;;;; Emacs's 20.2 problems:
458 ;;; `imenu.el' has bugs, `imenu-add-to-menubar' does not work.
459 ;;; Couple of others problems with 20.2 were reported, my ability to check/fix
460 ;;; them is very reduced now.
462 ;;;; After 1.36:
463 ;;; 'C-M-|' in XEmacs fixed
465 ;;;; After 1.37:
466 ;;; &&s was not recognized as start of regular expression;
467 ;;; Will "preprocess" the contents of //e part of s///e too;
468 ;;; What to do with s# blah # foo #e ?
469 ;;; Should handle s;blah;foo;; better.
470 ;;; Now the only known problems with regular expression recognition:
471 ;;;;;;; s<foo>/bar/ - different delimiters (end ignored)
472 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into one chunk)
473 ;;;;;;; s/foo// - empty subst (made into one chunk + '/')
474 ;;;;;;; s/foo/(bar)/ - start-group at start of subst (internal group will not match backwards)
476 ;;;; After 1.38:
477 ;;; We highlight closing / of s/blah/foo/e;
478 ;;; This handles s# blah # foo #e too;
479 ;;; s//blah/, s///, s/blah// works again, and s#blah## too, the algorithm
480 ;;; is much simpler now;
481 ;;; Next round of changes: s\\\ works, s<blah>/foo/,
482 ;;; comments between the first and the second part allowed
483 ;;; Another problem discovered:
484 ;;;;;;; s[foo] <blah>e - e part delimited by different <> (will not match)
485 ;;; `cperl-find-pods-heres' somehow maybe called when string-face is undefined
486 ;;; - put a stupid workaround for 20.1
488 ;;;; After 1.39:
489 ;;; Could indent here-docs for comments;
490 ;;; These problems fixed:
491 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into two chunk)
492 ;;;;;;; s[foo] <blah>e - "e" part delimited by "different" <> (will match)
493 ;;; Matching brackets honor prefices, may expand abbreviations;
494 ;;; When expanding abbrevs, will remove last char only after
495 ;;; self-inserted whitespace;
496 ;;; More convenient "Refress hard constructs" in menu;
497 ;;; `cperl-add-tags-recurse', `cperl-add-tags-recurse-noxs'
498 ;;; added (for -batch mode);
499 ;;; Better handling of errors when scanning for Perl constructs;
500 ;;;;;;; Possible "problem" with class hierarchy in Perl distribution
501 ;;;;;;; directory: ./ext duplicates ./lib;
502 ;;; Write relative paths for generated TAGS;
504 ;;;; After 1.40:
505 ;;; s /// may be separated by "\n\f" too;
506 ;;; `s #blah' recognized as a comment;
507 ;;; Would highlight s/abc//s wrong;
508 ;;; Debugging code in `cperl-electric-keywords' was leaking a message;
510 ;;;; After 1.41:
511 ;;; RMS changes for 20.3 merged
513 ;;;; 2.0.1.0: RMS mode (has 3 misprints)
515 ;;;; After 2.0:
516 ;;; RMS whitespace changes for 20.3 merged
518 ;;;; After 2.1:
519 ;;; History updated
521 ;;;; After 2.2:
522 ;;; Merge `c-style-alist' since `c-mode' is no more. (Somebody who
523 ;;; uses the styles should check that they work OK!)
524 ;;; All the variable warnings go away, some undef functions too.
526 ;;;; After 2.3:
527 ;;; Added `cperl-perldoc' (thanks to Anthony Foiani <afoiani@uswest.com>)
528 ;;; Added `cperl-pod-to-manpage' (thanks to Nick Roberts <Nick.Roberts@src.bae.co.uk>)
529 ;;; All the function warnings go away.
531 ;;;; After 2.4:
532 ;;; `Perl doc', `Regexp' submenus created (latter to allow short displays).
533 ;;; `cperl-clobber-lisp-bindings' added.
534 ;;; $a->y() is not y///.
535 ;;; `cperl-after-block-p' was missing a `save-excursion' => wrong results.
536 ;;; `cperl-val' was defined too late.
537 ;;; `cperl-init-faces' was failing.
538 ;;; Init faces when loading `ps-print'.
540 ;;;; After 2.4:
541 ;;; `cperl-toggle-autohelp' implemented.
542 ;;; `while SPACE LESS' was buggy.
543 ;;; `-text' in `[-text => 1]' was not highlighted.
544 ;;; `cperl-after-block-p' was FALSE after `sub f {}'.
546 ;;;; After 2.5:
547 ;;; `foreachmy', `formy' expanded too.
548 ;;; Expand `=pod-directive'.
549 ;;; `cperl-linefeed' behaves reasonable in POD-directive lines.
550 ;;; `cperl-electric-keyword' prints a message, governed by
551 ;;; `cperl-message-electric-keyword'.
553 ;;;; After 2.6:
554 ;;; Typing `}' was not checking for being block or not.
555 ;;; Beautifying levels in RE: Did not know about lookbehind;
556 ;;; finding *which* level was not intuitive;
557 ;;; `cperl-beautify-levels' added.
558 ;;; Allow here-docs contain `=head1' and friends (at least for keywords).
560 ;;;; After 2.7:
561 ;;; Fix for broken `font-lock-unfontify-region-function'. Should
562 ;;; preserve `syntax-table' properties even with `lazy-lock'.
564 ;;;; After 2.8:
565 ;;; Some more compile time warnings crept in.
566 ;;; `cperl-indent-region-fix-else' implemented.
567 ;;; `cperl-fix-line-spacing' implemented.
568 ;;; `cperl-invert-if-unless' implemented (C-c C-t and in Menu).
569 ;;; Upgraded hints to mention 20.2's goods/bads.
570 ;;; Started to use `cperl-extra-newline-before-brace-multiline',
571 ;;; `cperl-break-one-line-blocks-when-indent',
572 ;;; `cperl-fix-hanging-brace-when-indent', `cperl-merge-trailing-else'.
574 ;;;; After 2.9:
575 ;;; Workaround for another `font-lock's `syntax-table' text-property bug.
576 ;;; `zerop' could be applied to nil.
577 ;;; At last, may work with `font-lock' without setting `cperl-font-lock'.
578 ;;; (We expect that starting from 19.33, `font-lock' supports keywords
579 ;;; being a function - what is a correct version?)
580 ;;; Rename `cperl-indent-region-fix-else' to
581 ;;; `cperl-indent-region-fix-constructs'.
582 ;;; `cperl-fix-line-spacing' could be triggered inside strings, would not
583 ;;; know what to do with BLOCKs of map/printf/etc.
584 ;;; `cperl-merge-trailing-else' and `cperl-fix-line-spacing' handle
585 ;;; `continue' too.
586 ;;; Indentation after {BLOCK} knows about map/printf/etc.
587 ;;; Finally: treat after-comma lines as continuation lines.
589 ;;;; After 2.10:
590 ;;; `continue' made electric.
591 ;;; Electric `do' inserts `do/while'.
592 ;;; Some extra compile-time warnings crept in.
593 ;;; `font-lock' of 19.33 could not handle font-lock-keywords being a function
594 ;;; returning a symbol.
596 ;;;; After 2.11:
597 ;;; Changes to make syntaxification to be autoredone via `font-lock'.
598 ;;; Switched on by `cperl-syntaxify-by-font-lock', off by default so far.
600 ;;;; After 2.12:
601 ;;; Remove some commented out chunks.
602 ;;; Styles are slightly updated (a lot of work is needed, especially
603 ;;; with new `cperl-fix-line-spacing').
605 ;;;; After 2.13:
606 ;;; Old value of style is memorized when choosing a new style, may be
607 ;;; restored from the same menu.
608 ;;; Mode-documentation added to micro-docs.
609 ;;; `cperl-praise' updated.
610 ;;; `cperl-toggle-construct-fix' added on C-c C-w and menu.
611 ;;; `auto-fill-mode' added on C-c C-f and menu.
612 ;;; `PerlStyle' style added.
613 ;;; Message for termination of scan corrected.
615 ;;;; After 2.14:
617 ;;; Did not work with -q
619 ;;;; After 2.15:
621 ;;; `cperl-speed' hints added.
622 ;;; Minor style fixes.
624 ;;;; After 2.15:
625 ;;; Make backspace electric after expansion of `else/continue' too.
627 ;;;; After 2.16:
628 ;;; Starting to merge changes to RMS emacs version.
630 ;;;; After 2.17:
631 ;;; Merged custom stuff and darn `font-lock-constant-face'.
633 ;;;; After 2.18:
634 ;;; Bumped the version to 3.1
636 ;;;; After 3.1:
637 ;;; Fixed customization to honor cperl-hairy.
638 ;;; Created customization groups. Sent to RMS to include into 2.3.
640 ;;;; After 3.2:
641 ;;; Interaction of `font-lock-hot-pass' and `cperl-syntaxify-by-font-lock'.
642 ;;; (`cperl-after-block-and-statement-beg'):
643 ;;; (`cperl-after-block-p'):
644 ;;; (`cperl-after-expr-p'): It is BLOCK if we reach lim when backup sexp.
645 ;;; (`cperl-indent-region'): Make a marker for END - text added/removed.
646 ;;; (`cperl-style-alist', `cperl-styles-entries')
647 ;;; Include `cperl-merge-trailing-else' where the value is clear.
649 ;;;; After 3.3:
650 ;;; (`cperl-tips'):
651 ;;; (`cperl-problems'): Improvements to docs.
653 ;;;; After 3.4:
654 ;;; (`cperl-mode'): Make lazy syntaxification possible.
655 ;;; (`cperl-find-pods-heres'): Safe a position in buffer where it is safe to
656 ;;; restart syntaxification.
657 ;;; (`cperl-syntaxify-by-font-lock'): Set to t, should be safe now.
659 ;;;; After 3.5:
660 ;;; (`cperl-syntaxify-by-font-lock'): Better default, customizes to
661 ;;; `message' too.
663 ;;;; After 3.6:
664 ;;; (`cperl-find-pods-heres'): changed so that -d ?foo? is a RE.
665 ;;; (`cperl-array-face'): changed name from `font-lock-emphasized-face'.
666 ;;; (`cperl-hash-face'): changed name from `font-lock-other-emphasized-face'.
667 ;;; Use `defface' to define these two extra faces.
669 ;;;; After 3.7:
670 ;;; Can use linear algorithm for indentation if Emacs supports it:
671 ;;; indenting DB::DB (800+ lines) improved from 69 sec to 11 sec
672 ;;; (73 vs 15 with imenu).
673 ;;; (`cperl-emacs-can-parse'): New state.
674 ;;; (`cperl-indent-line'): Corrected to use global state.
675 ;;; (`cperl-calculate-indent'): Likewise.
676 ;;; (`cperl-fix-line-spacing'): Likewise (not used yet).
678 ;;;; After 3.8:
679 ;;; (`cperl-choose-color'): Converted to a function (to be compilable in text-mode).
681 ;;;; After 3.9:
682 ;;; (`cperl-dark-background '): Disable without window-system.
684 ;;;; After 3.10:
685 ;;; Do `defface' only if window-system.
687 ;;;; After 3.11:
688 ;;; (`cperl-fix-line-spacing'): sped up to bail out early.
689 ;;; (`cperl-indent-region'): Disable hooks during the call (how to call them later?).
691 ;;; Now indents 820-line-long function in 6.5 sec (including syntaxification) the first time
692 ;;; (when buffer has few properties), 7.1 sec the second time.
694 ;;;Function Name Call Count Elapsed Time Average Time
695 ;;;========================================= ========== ============ ============
696 ;;;cperl-indent-exp 1 10.039999999 10.039999999
697 ;;;cperl-indent-region 1 10.0 10.0
698 ;;;cperl-indent-line 821 6.2100000000 0.0075639464
699 ;;;cperl-calculate-indent 821 5.0199999999 0.0061144945
700 ;;;cperl-backward-to-noncomment 2856 2.0500000000 0.0007177871
701 ;;;cperl-fontify-syntaxically 2 1.78 0.8900000000
702 ;;;cperl-find-pods-heres 2 1.78 0.8900000000
703 ;;;cperl-update-syntaxification 1 1.78 1.78
704 ;;;cperl-fix-line-spacing 769 1.4800000000 0.0019245773
705 ;;;cperl-after-block-and-statement-beg 163 1.4100000000 0.0086503067
706 ;;;cperl-block-p 775 1.1800000000 0.0015225806
707 ;;;cperl-to-comment-or-eol 3652 1.1200000000 0.0003066812
708 ;;;cperl-after-block-p 165 1.0500000000 0.0063636363
709 ;;;cperl-commentify 141 0.22 0.0015602836
710 ;;;cperl-get-state 813 0.16 0.0001968019
711 ;;;cperl-backward-to-start-of-continued-exp 26 0.12 0.0046153846
712 ;;;cperl-delay-update-hook 2107 0.0899999999 4.271...e-05
713 ;;;cperl-protect-defun-start 141 0.0700000000 0.0004964539
714 ;;;cperl-after-label 407 0.0599999999 0.0001474201
715 ;;;cperl-forward-re 139 0.0299999999 0.0002158273
716 ;;;cperl-comment-indent 26 0.0299999999 0.0011538461
717 ;;;cperl-use-region-p 8 0.0 0.0
718 ;;;cperl-lazy-hook 15 0.0 0.0
719 ;;;cperl-after-expr-p 8 0.0 0.0
720 ;;;cperl-font-lock-unfontify-region-function 1 0.0 0.0
722 ;;;Function Name Call Count Elapsed Time Average Time
723 ;;;========================================= ========== ============ ============
724 ;;;cperl-fix-line-spacing 769 1.4500000000 0.0018855656
725 ;;;cperl-indent-line 13 0.3100000000 0.0238461538
726 ;;;cperl-after-block-and-statement-beg 69 0.2700000000 0.0039130434
727 ;;;cperl-after-block-p 69 0.2099999999 0.0030434782
728 ;;;cperl-calculate-indent 13 0.1000000000 0.0076923076
729 ;;;cperl-backward-to-noncomment 177 0.0700000000 0.0003954802
730 ;;;cperl-get-state 13 0.0 0.0
731 ;;;cperl-to-comment-or-eol 179 0.0 0.0
732 ;;;cperl-get-help-defer 1 0.0 0.0
733 ;;;cperl-lazy-hook 11 0.0 0.0
734 ;;;cperl-after-expr-p 2 0.0 0.0
735 ;;;cperl-block-p 13 0.0 0.0
736 ;;;cperl-after-label 5 0.0 0.0
738 ;;;; After 3.12:
739 ;;; (`cperl-find-pods-heres'): do not warn on `=cut' if doing a chunk only.
741 ;;;; After 3.13:
742 ;;; (`cperl-mode'): load pseudo-faces on `cperl-find-pods-heres' (for 19.30).
743 ;;; (`x-color-defined-p'): was not compiling on XEmacs
744 ;;; (`cperl-find-pods-heres'): 1 << 6 was OK, but 1<<6 was considered as HERE
745 ;;; <file/glob> made into a string.
747 ;;;; After 3.14:
748 ;;; (`cperl-find-pods-heres'): Postpone addition of faces after syntactic step
749 ;;; Recognition of <FH> was wrong.
750 ;;; (`cperl-clobber-lisp-bindings'): if set, C-c variants are the old ones
751 ;;; (`cperl-unwind-to-safe'): New function.
752 ;;; (`cperl-fontify-syntaxically'): Use `cperl-unwind-to-safe' to start at reasonable position.
754 ;;;; After 3.15:
755 ;;; (`cperl-forward-re'): Highlight the trailing / in s/foo// as string.
756 ;;; Highlight the starting // in s//foo/ as function-name.
758 ;;;; After 3.16:
759 ;;; (`cperl-find-pods-heres'): Highlight `gem' in s///gem as a keyword.
761 ;;;; After 4.0:
762 ;;; (`cperl-find-pods-heres'): `qr' added
763 ;;; (`cperl-electric-keyword'): Likewise
764 ;;; (`cperl-electric-else'): Likewise
765 ;;; (`cperl-to-comment-or-eol'): Likewise
766 ;;; (`cperl-make-regexp-x'): Likewise
767 ;;; (`cperl-init-faces'): Likewise, and `lock' (as overridable?).
768 ;;; (`cperl-find-pods-heres'): Knows that split// is null-RE.
769 ;;; Highlights separators in 3-parts expressions
770 ;;; as labels.
772 ;;;; After 4.1:
773 ;;; (`cperl-find-pods-heres'): <> was considered as a glob
774 ;;; (`cperl-syntaxify-unwind'): New configuration variable
775 ;;; (`cperl-fontify-m-as-s'): New configuration variable
777 ;;;; After 4.2:
778 ;;; (`cperl-find-pods-heres'): of the last line being `=head1' fixed.
780 ;;; Handling of a long construct is still buggy if only the part of
781 ;;; construct touches the updated region (we unwind to the start of
782 ;;; long construct, but the end may have residual properties).
784 ;;; (`cperl-unwind-to-safe'): would not go to beginning of buffer.
785 ;;; (`cperl-electric-pod'): check for after-expr was performed
786 ;;; inside of POD too.
788 ;;;; After 4.3:
789 ;;; (`cperl-backward-to-noncomment'): better treatment of PODs and HEREs.
791 ;;; Indent-line works good, but indent-region does not - at toplevel...
792 ;;; (`cperl-unwind-to-safe'): Signature changed.
793 ;;; (`x-color-defined-p'): was defmacro'ed with a tick. Remove another def.
794 ;;; (`cperl-clobber-mode-lists'): New configuration variable.
795 ;;; (`cperl-array-face'): One of definitions was garbled.
797 ;;;; After 4.4:
798 ;;; (`cperl-not-bad-style-regexp'): Updated.
799 ;;; (`cperl-make-regexp-x'): Misprint in a message.
800 ;;; (`cperl-find-pods-heres'): $a-1 ? foo : bar; was a regexp.
801 ;;; `<< (' was considered a start of POD.
802 ;;; Init: `cperl-is-face' was busted.
803 ;;; (`cperl-make-face'): New macros.
804 ;;; (`cperl-force-face'): New macros.
805 ;;; (`cperl-init-faces'): Corrected to use new macros;
806 ;;; `if' for copying `reference-face' to
807 ;;; `constant-face' was backward.
808 ;;; (`font-lock-other-type-face'): Done via `defface' too.
810 ;;;; After 4.5:
811 ;;; (`cperl-init-faces-weak'): use `cperl-force-face'.
812 ;;; (`cperl-after-block-p'): After END/BEGIN we are a block.
813 ;;; (`cperl-mode'): `font-lock-unfontify-region-function'
814 ;;; was set to a wrong function.
815 ;;; (`cperl-comment-indent'): Commenting __END__ was not working.
816 ;;; (`cperl-indent-for-comment'): Likewise.
817 ;;; (Indenting is still misbehaving at toplevel.)
819 ;;;; After 4.5:
820 ;;; (`cperl-unwind-to-safe'): Signature changed, unwinds end too.
821 ;;; (`cperl-find-pods-heres'): mark qq[]-etc sections as syntax-type=string
822 ;;; (`cperl-fontify-syntaxically'): Unwinds start and end to go out of
823 ;;; long strings (not very successful).
825 ;;; >>>> CPerl should be usable in write mode too now <<<<
827 ;;; (`cperl-syntaxify-by-font-lock'): Better default - off in text-mode.
828 ;;; (`cperl-tips'): Updated docs.
829 ;;; (`cperl-problems'): Updated docs.
831 ;;;; After 4.6:
832 ;;; (`cperl-calculate-indent'): Did not consider `,' as continuation mark for statements.
833 ;;; (`cperl-write-tags'): Correct for XEmacs's `visit-tags-table-buffer'.
835 ;;;; After 4.7:
836 ;;; (`cperl-calculate-indent'): Avoid parse-data optimization at toplevel.
837 ;;; Should indent correctly at toplevel too.
838 ;;; (`cperl-tags-hier-init'): Gross hack to pretend we work (are we?).
839 ;;; (`cperl-find-pods-heres'): Was not processing sub protos after a comment ine.
840 ;;; Was treating $a++ <= 5 as a glob.
842 ;;;; After 4.8:
843 ;;; (toplevel): require custom unprotected => failure on 19.28.
844 ;;; (`cperl-xemacs-p') defined when compile too
845 ;;; (`cperl-tags-hier-init'): Another try to work around XEmacs problems
846 ;;; Better progress messages.
847 ;;; (`cperl-find-tags'): Was writing line/pos in a wrong order,
848 ;;; pos off by 1 and not at beg-of-line.
849 ;;; (`cperl-etags-snarf-tag'): New macro
850 ;;; (`cperl-etags-goto-tag-location'): New macro
851 ;;; (`cperl-write-tags'): When removing old TAGS info was not
852 ;;; relativizing filename
854 ;;;; After 4.9:
855 ;;; (`cperl-version'): New variable. New menu entry
857 ;;;; After 4.10:
858 ;;; (`cperl-tips'): Updated.
859 ;;; (`cperl-non-problems'): Updated.
860 ;;; random: References to future 20.3 removed.
862 ;;;; After 4.11:
863 ;;; (`perl-font-lock-keywords'): Would not highlight `sub foo($$);'.
864 ;;; Docstrings: Menu was described as `CPerl' instead of `Perl'
866 ;;;; After 4.12:
867 ;;; (`cperl-toggle-construct-fix'): Was toggling to t instead of 1.
868 ;;; (`cperl-ps-print-init'): Associate `cperl-array-face', `cperl-hash-face'
869 ;;; remove `font-lock-emphasized-face'.
870 ;;; remove `font-lock-other-emphasized-face'.
871 ;;; remove `font-lock-reference-face'.
872 ;;; remove `font-lock-keyword-face'.
873 ;;; Use `eval-after-load'.
874 ;;; (`cperl-init-faces'): remove init `font-lock-other-emphasized-face'.
875 ;;; remove init `font-lock-emphasized-face'.
876 ;;; remove init `font-lock-keyword-face'.
877 ;;; (`cperl-tips-faces'): New variable and an entry into Mini-docs.
878 ;;; (`cperl-indent-region'): Do not indent whitespace lines
879 ;;; (`cperl-indent-exp'): Was not processing else-blocks.
880 ;;; (`cperl-calculate-indent'): Remove another parse-data optimization
881 ;;; at toplevel: would indent correctly.
882 ;;; (`cperl-get-state'): NOP line removed.
884 ;;;; After 4.13:
885 ;;; (`cperl-ps-print-init'): Remove not-CPerl-related faces.
886 ;;; (`cperl-ps-print'): New function and menu entry.
887 ;;; (`cperl-ps-print-face-properties'): New configuration variable.
888 ;;; (`cperl-invalid-face'): New configuration variable.
889 ;;; (`cperl-nonoverridable-face'): New face. Renamed from
890 ;;; `font-lock-other-type-face'.
891 ;;; (`perl-font-lock-keywords'): Highlight trailing whitespace
892 ;;; (`cperl-contract-levels'): Documentation corrected.
893 ;;; (`cperl-contract-level'): Likewise.
895 ;;;; After 4.14:
896 ;;; (`cperl-ps-print'): `ps-print-face-extension-alist' was not in old Emaxen,
897 ;;; same with `ps-extend-face-list'
898 ;;; (`cperl-ps-extend-face-list'): New macro.
900 ;;;; After 4.15:
901 ;;; (`cperl-init-faces'): Interpolate `cperl-invalid-face'.
902 ;;; (`cperl-forward-re'): Emit a meaningful error instead of a cryptic
903 ;;; one for uncomplete REx near end-of-buffer.
904 ;;; (`cperl-find-pods-heres'): Tolerate unfinished REx at end-of-buffer.
906 ;;;; After 4.16:
907 ;;; (`cperl-find-pods-heres'): `unwind-protect' was left commented.
909 ;;;; After 4.17:
910 ;;; (`cperl-invalid-face'): Change to ''underline.
912 ;;;; After 4.18:
913 ;;; (`cperl-find-pods-heres'): / and ? after : start a REx.
914 ;;; (`cperl-after-expr-p'): Skip labels when checking
915 ;;; (`cperl-calculate-indent'): Correct for labels when calculating
916 ;;; indentation of continuations.
917 ;;; Docstring updated.
919 ;;;; After 4.19:
920 ;;; Minor (mostly spelling) corrections from 20.3.3 merged.
922 ;;;; After 4.20:
923 ;;; (`cperl-tips'): Another workaround added. Sent to RMS for 20.4.
925 ;;;; After 4.21:
926 ;;; (`cperl-praise'): Mention linear-time indent.
927 ;;; (`cperl-find-pods-heres'): @if ? a : b was considered a REx.
929 ;;;; After 4.22:
930 ;;; (`cperl-after-expr-p'): Make true after __END__.
931 ;;; (`cperl-electric-pod'): "SYNOPSIS" was misspelled.
933 ;;;; After 4.23:
934 ;;; (`cperl-beautify-regexp-piece'): Was not allowing for *? after a class.
935 ;;; Allow for POSIX char-classes.
936 ;;; Remove trailing whitespace when
937 ;;; adding new linebreak.
938 ;;; Add a level counter to stop shallow.
939 ;;; Indents unprocessed groups rigidly.
940 ;;; (`cperl-beautify-regexp'): Add an optional count argument to go that
941 ;;; many levels deep.
942 ;;; (`cperl-beautify-level'): Likewise
943 ;;; Menu: Add new entries to Regexp menu to do one level
944 ;;; (`cperl-contract-level'): Was entering an infinite loop
945 ;;; (`cperl-find-pods-heres'): Typo (double quoting).
946 ;;; Was detecting < $file > as FH instead of glob.
947 ;;; Support for comments in RExen (except
948 ;;; for m#\#comment#x), governed by
949 ;;; `cperl-regexp-scan'.
950 ;;; (`cperl-regexp-scan'): New customization variable.
951 ;;; (`cperl-forward-re'): Improve logic of resetting syntax table.
953 ;;;; After 4.23 and: After 4.24:
954 ;;; (`cperl-contract-levels'): Restore position.
955 ;;; (`cperl-beautify-level'): Likewise.
956 ;;; (`cperl-beautify-regexp'): Likewise.
957 ;;; (`cperl-commentify'): Rudimental support for length=1 runs
958 ;;; (`cperl-find-pods-heres'): Process 1-char long REx comments too /a#/x
959 ;;; Processes REx-comments in #-delimited RExen.
960 ;;; MAJOR BUG CORRECTED: after a misparse
961 ;;; a body of a subroutine could be corrupted!!!
962 ;;; One might need to reeval the function body
963 ;;; to fix things. (A similar bug was
964 ;;; present in `cperl-indent-region' eons ago.)
965 ;;; To reproduce:
966 ;; (defun foo () (let ((a '(t))) (insert (format "%s" a)) (setcar a 'BUG) t))
967 ;; (foo)
968 ;; (foo)
969 ;;; C-x C-e the above three lines (at end-of-line). First evaluation
970 ;;; of `foo' inserts (t), second one inserts (BUG) ?!
972 ;;; In CPerl it was triggered by inserting then deleting `/' at start of
973 ;;; / a (?# asdf {[(}asdf )ef,/;
975 ;;;; After 4.25:
976 ;;; (`cperl-commentify'): Was recognizing length=2 "strings" as length=1.
977 ;;; (`imenu-example--create-perl-index'):
978 ;;; Was not enforcing syntaxification-to-the-end.
979 ;;; (`cperl-invert-if-unless'): Allow `for', `foreach'.
980 ;;; (`cperl-find-pods-heres'): Quote `cperl-nonoverridable-face'.
981 ;;; Mark qw(), m()x as indentable.
982 ;;; (`cperl-init-faces'): Highlight `sysopen' too.
983 ;;; Highlight $var in `for my $var' too.
984 ;;; (`cperl-invert-if-unless'): Was leaving whitespace at end.
985 ;;; (`cperl-linefeed'): Was splitting $var{$foo} if point after `{'.
986 ;;; (`cperl-calculate-indent'): Remove old commented out code.
987 ;;; Support (primitive) indentation of qw(), m()x.
990 ;;;; After 4.26:
991 ;;; (`cperl-problems'): Mention `fill-paragraph' on comment. \"" and
992 ;;; q [] with intervening newlines.
993 ;;; (`cperl-autoindent-on-semi'): New customization variable.
994 ;;; (`cperl-electric-semi'): Use `cperl-autoindent-on-semi'.
995 ;;; (`cperl-tips'): Mention how to make CPerl the default mode.
996 ;;; (`cperl-mode'): Support `outline-minor-mode'
997 ;;; (Thanks to Mark A. Hershberger).
998 ;;; (`cperl-outline-level'): New function.
999 ;;; (`cperl-highlight-variables-indiscriminately'): New customization var.
1000 ;;; (`cperl-init-faces'): Use `cperl-highlight-variables-indiscriminately'.
1001 ;;; (Thanks to Sean Kamath <kamath@pogo.wv.tek.com>).
1002 ;;; (`cperl-after-block-p'): Support CHECK and INIT.
1003 ;;; (`cperl-init-faces'): Likewise and "our".
1004 ;;; (Thanks to Doug MacEachern <dougm@covalent.net>).
1005 ;;; (`cperl-short-docs'): Likewise and "our".
1008 ;;;; After 4.27:
1009 ;;; (`cperl-find-pods-heres'): Recognize \"" as a string.
1010 ;;; Mark whitespace and comments between q and []
1011 ;;; as `syntax-type' => `prestring'.
1012 ;;; Allow whitespace between << and "FOO".
1013 ;;; (`cperl-problems'): Remove \"" and q [] with intervening newlines.
1014 ;;; Mention multiple <<EOF as unsupported.
1015 ;;; (`cperl-highlight-variables-indiscriminately'): Doc misprint fixed.
1016 ;;; (`cperl-indent-parens-as-block'): New configuration variable.
1017 ;;; (`cperl-calculate-indent'): Merge cases of indenting non-BLOCK groups.
1018 ;;; Use `cperl-indent-parens-as-block'.
1019 ;;; (`cperl-find-pods-heres'): Test for =cut without empty line instead of
1020 ;;; complaining about no =cut.
1021 ;;; (`cperl-electric-pod'): Change the REx for POD from "\n\n=" to "^\n=".
1022 ;;; (`cperl-find-pods-heres'): Likewise.
1023 ;;; (`cperl-electric-pod'): Change `forward-sexp' to `forward-word':
1024 ;;; POD could've been marked as comment already.
1025 ;;; (`cperl-unwind-to-safe'): Unwind before start of POD too.
1027 ;;;; After 4.28:
1028 ;;; (`cperl-forward-re'): Throw an error at proper moment REx unfinished.
1030 ;;;; After 4.29:
1031 ;;; (`x-color-defined-p'): Make an extra case to peacify the warning.
1032 ;;; Toplevel: `defvar' to peacify the warnings.
1033 ;;; (`cperl-find-pods-heres'): Could access `font-lock-comment-face' in -nw.
1034 ;;;; No -nw-compile time warnings now.
1035 ;;; (`cperl-find-tags'): TAGS file had too short substring-to-search.
1036 ;;; Be less verbose in non-interactive mode
1037 ;;; (`imenu-example--create-perl-index'): Set index-marker after name
1038 ;;; (`cperl-outline-regexp'): New variable.
1039 ;;; (`cperl-outline-level'): Made compatible with `cperl-outline-regexp'.
1040 ;;; (`cperl-mode'): Made use `cperl-outline-regexp'.
1042 ;;;; After 4.30:
1043 ;;; (`cperl-find-pods-heres'): =cut the last thing, no blank line, was error.
1044 ;;; (`cperl-outline-level'): Make start-of-file same level as `package'.
1046 ;;;; After 4.31:
1047 ;;; (`cperl-electric-pod'): `head1' and `over' electric only if empty.
1048 ;;; (`cperl-unreadable-ok'): New variable.
1049 ;;; (`cperl-find-tags'): Use `cperl-unreadable-ok', do not fail
1050 ;;; on an unreadable file
1051 ;;; (`cperl-write-tags'): Use `cperl-unreadable-ok', do not fail
1052 ;;; on an unreadable directory
1054 ;;;; After 4.32:
1055 ;;; Syncronized with v1.60 from Emacs 21.3.
1056 ;;; Mostly docstring and formatting changes, and:
1058 ;;; (`cperl-noscan-files-regexp'): Do not scan CVS subdirs
1059 ;;; (`cperl-problems'): Note that newer XEmacsen may syntaxify too
1060 ;;; (`imenu-example--create-perl-index'):
1061 ;;; Renamed to `cperl-imenu--create-perl-index'
1062 ;;; (`cperl-mode'): Replace `make-variable-buffer-local' by `make-local-variable'
1063 ;;; (`cperl-setup-tmp-buf'): Likewise
1064 ;;; (`cperl-fix-line-spacing'): Fix a misprint of "t" for "\t"
1065 ;;; (`cperl-next-bad-style'): Fix misprints in character literals
1067 ;;;; After 4.33:
1068 ;;; (`cperl-font-lock-keywords'): +etc: Aliased to perl-font-lock-keywords.
1070 ;;;; After 4.34:
1071 ;;; Further updates of whitespace and spelling w.r.t. RMS version.
1072 ;;; (`cperl-font-lock-keywords'): +etc: Avoid warnings when aliasing.
1073 ;;; (`cperl-mode'): Use `normal-auto-fill-function' if present.
1074 ;;; (`cperl-use-major-mode'): New variable
1075 ;;; (`cperl-can-font-lock'): New variable; replaces `window-system'
1076 ;;; (`cperl-tags-hier-init'): use `display-popup-menus-p' (if present)
1077 ;;; to choose `x-popup-menu' vs `tmm-prompt'
1079 ;;;; 4.35 has the following differences from version 1.40+ of RMS Emacs:
1081 ;;; New variables `cperl-use-major-mode', `cperl-can-font-lock';
1082 ;;; `cperl-use-major-mode' is (effectively) 'cperl-mode in RMS.
1083 ;;; `cperl-under-as-char' is nil in RMS.
1084 ;;; Minor differences in docstrings, and `cperl-non-problems'.
1085 ;;; Backward compatibility addressed: (`); (function (lambda ...)); font-lock;
1086 ;;; (:italic t bold t) vs (:slant italic :weight bold) in faces;
1087 ;;; `normal-auto-fill-function'.
1088 ;;; RMS version has wrong logic in `cperl-calculate-indent': $a = { } is
1089 ;;; wrongly indented if the closing brace is on a separate line.
1090 ;;; Different choice of ordering if's for is-x-REx and (eq (char-after b) ?\#)
1091 ;;; in `cperl-find-pods-heres'. [Cosmetic]
1093 ;;;; After 4.35:
1094 ;;; (`cperl-find-pods-heres'): If no end of HERE-doc found, mark to the end
1095 ;;; of buffer. This enables recognition of end
1096 ;;; of HERE-doc "as one types".
1097 ;;; Require "\n" after trailing tag of HERE-doc.
1098 ;;; \( made non-quoting outside of string/comment
1099 ;;; (gdj-contributed).
1100 ;;; Likewise for \$.
1101 ;;; Remove `here-doc-group' text property at start
1102 ;;; (makes this property reliable).
1103 ;;; Text property `first-format-line' ==> t.
1104 ;;; Do not recognize $opt_s and $opt::s as s///.
1105 ;;; (`cperl-perldoc'): Use case-sensitive search (contributed).
1106 ;;; (`cperl-fix-line-spacing'): Allow "_" in $vars of foreach etc. when
1107 ;;; underscore isn't a word char (gdj-contributed).
1108 ;;; (`defun-prompt-regexp'): Allow prototypes.
1109 ;;; (`cperl-vc-header-alist'): Extract numeric version from the Id.
1110 ;;; Toplevel: Put toggle-autohelp into the mode menu.
1111 ;;; Better docs for toggle/set/unset autohelp.
1112 ;;; (`cperl-electric-backspace-untabify'): New customization variable
1113 ;;; (`cperl-after-expr-p'): Works after here-docs, formats, and PODs too
1114 ;;; (affects many electric constructs).
1115 ;;; (`cperl-calculate-indent'): Takes into account `first-format-line' ==>
1116 ;;; works after format.
1117 ;;; (`cperl-short-docs'): Make it work with ... too.
1118 ;;; "array context" ==> "list context"
1119 ;;; (`cperl-electric-keyword'): make $if (etc: "$@%&*") non-electric
1120 ;;; '(' after keyword would insert a doubled paren
1121 ;;; (`cperl-electric-paren'): documented affected by `cperl-electric-parens'
1122 ;;; (`cperl-electric-rparen'): Likewise
1123 ;;; (`cperl-build-manpage'): New function by Nick Roberts
1124 ;;; (`cperl-perldoc'): Make it work in XEmacs too
1126 ;;;; After 4.36:
1127 ;;; (`cperl-find-pods-heres'): Recognize s => 1 and {s} (as a key or varname),
1128 ;;; { s:: } and { s::bar::baz } as varnames.
1129 ;;; (`cperl-after-expr-p'): Updates syntaxification before checks
1130 ;;; (`cperl-calculate-indent'): Likewise
1131 ;;; Fix wrong indent of blocks starting with POD
1132 ;;; (`cperl-after-block-p'): Optional argument for checking for a pre-block
1133 ;;; Recognize `continue' blocks too.
1134 ;;; (`cperl-electric-brace'): use `cperl-after-block-p' for detection;
1135 ;;; Now works for else/continue/sub blocks
1136 ;;; (`cperl-short-docs'): Minor edits; make messages fit 80-column screen
1138 ;;;; After 5.0:
1139 ;;; `cperl-add-tags-recurse-noxs-fullpath': new function (for -batch mode)
1141 ;;;; After 5.1:
1142 ;;;;;; Major edit. Summary of most visible changes:
1144 ;;;;;; a) Multiple <<HERE per line allowed.
1145 ;;;;;; b) Handles multiline subroutine declaration headers (with comments).
1146 ;;;;;; (The exception is `cperl-etags' - but it is not used in the rest
1147 ;;;;;; of the mode.)
1148 ;;;;;; c) Fontifies multiline my/our declarations (even with comments,
1149 ;;;;;; and with legacy `font-lock').
1150 ;;;;;; d) Major speedup of syntaxification, both immediate and postponed
1151 ;;;;;; (3.5x to 15x [for different CPUs and versions of Emacs] on the
1152 ;;;;;; huge real-life document I tested).
1153 ;;;;;; e) New bindings, edits to imenu.
1154 ;;;;;; f) "_" is made into word-char during fontification/syntaxification;
1155 ;;;;;; some attempts to recognize non-word "_" during other operations too.
1156 ;;;;;; g) Detect bug in Emacs with `looking-at' inside `narrow' and bulk out.
1157 ;;;;;; h) autoload some more perldoc-related stuff
1158 ;;;;;; i) Some new convenience features: ISpell POD/HEREDOCs, narrow-to-HEREDOC
1159 ;;;;;; j) Attempt to incorporate XEmacs edits which reached me
1161 ;;;; Fine-grained changelog:
1162 ;;; `cperl-hook-after-change': New configuration variable
1163 ;;; `cperl-vc-sccs-header': Likewise
1164 ;;; `cperl-vc-sccs-header': Likewise
1165 ;;; `cperl-vc-header-alist': Default via two preceding variables
1166 ;;; `cperl-invalid-face': Remove double quoting under XEmacs
1167 ;;; (still needed under 21.2)
1168 ;;; `cperl-tips': Update URLs for resources
1169 ;;; `cperl-problems': Likewise
1170 ;;; `cperl-praise': Mention new features
1171 ;;; New C-c key bindings: for `cperl-find-bad-style',
1172 ;;; `cperl-pod-spell', `cperl-here-doc-spell', `cperl-narrow-to-here-doc',
1173 ;;; `cperl-perdoc', `cperl-perldoc-at-point'
1174 ;;; CPerl Mode menu changes: "Fix style by spaces", "Imenu on Perl Info"
1175 ;;; moved, new submenu of Tools with Ispell entries and narrowing.
1176 ;;; `cperl-after-sub-regexp': New defsubst
1177 ;;; `cperl-imenu--function-name-regexp-perl': Use `cperl-after-sub-regexp',
1178 ;;; Allows heads up to head4
1179 ;;; Allow "package;"
1180 ;;; `defun-prompt-regexp': Use `cperl-after-sub-regexp',
1181 ;;; `paren-backwards-message': ??? Something for XEmacs???
1182 ;;; `cperl-mode': Never auto-switch abbrev-mode off
1183 ;;; Try to allow '_' be non-word char
1184 ;;; Do not use `font-lock-unfontify-region-function' on XEmacs
1185 ;;; Reset syntax cache on mode start
1186 ;;; Support multiline facification (even
1187 ;;; on legacy `font-lock')
1188 ;;; `cperl-facemenu-add-face-function': ??? Some contributed code ???
1189 ;;; `cperl-after-change-function': Since `font-lock' and `lazy-lock'
1190 ;;; refuse to inform us whether the fontification is due to lazy
1191 ;;; calling or due to edit to a buffer, install our own hook
1192 ;;; (controlled by `cperl-hook-after-change')
1193 ;;; `cperl-electric-pod': =cut may have been recognized as start
1194 ;;; `cperl-block-p': Moved, updated for attributes
1195 ;;; `cperl-calculate-indent': Try to allow '_' be non-word char
1196 ;;; Support subs with attributes
1197 ;;; `cperl-where-am-i': Queit (?) a warning
1198 ;;; `cperl-cached-syntax-table' New function
1199 ;;; `cperl-forward-re': Use `cperl-cached-syntax-table'
1200 ;;; `cperl-unwind-to-safe': Recognize `syntax-type' property
1201 ;;; changing in a middle of line
1202 ;;; `cperl-find-sub-attrs': New function
1203 ;;; `cperl-find-pods-heres': Allow many <<EOP per line
1204 ;;; Allow subs with attributes
1205 ;;; Major speedups (3.5x..15x on a real-life
1206 ;;; test file nph-proxy.pl)
1207 ;;; Recognize "extproc " (OS/2)
1208 ;;; case-folded and only at start
1209 ;;; /x on s///x with empty replacement was
1210 ;;; not recognized
1211 ;;; Better comments
1212 ;;; `cperl-after-block-p': Remarks on diff with `cperl-block-p'
1213 ;;; Allow subs with attributes, labels
1214 ;;; Do not confuse "else::foo" with "else"
1215 ;;; Minor optimizations...
1216 ;;; `cperl-after-expr-p': Try to allow '_' be non-word char
1217 ;;; `cperl-fill-paragraph': Try to detect a major bug in Emacs
1218 ;;; with `looking-at' inside `narrow' and bulk out if found
1219 ;;; `cperl-imenu--create-perl-index': Updates for new
1220 ;;; `cperl-imenu--function-name-regexp-perl'
1221 ;;; `cperl-outline-level': Likewise
1222 ;;; `cperl-init-faces': Allow multiline subroutine headers
1223 ;;; and my/our declarations, and ones with comments
1224 ;;; Allow subroutine attributes
1225 ;;; `cperl-imenu-on-info': Better docstring.
1226 ;;; `cperl-etags' Rudimentary support for attributes
1227 ;;; Support for packages and "package;"
1228 ;;; `cperl-add-tags-recurse-noxs': Better (?) docstring
1229 ;;; `cperl-add-tags-recurse-noxs-fullpath': Likewise
1230 ;;; `cperl-tags-hier-init': Misprint for `fboundp' fixed
1231 ;;; `cperl-not-bad-style-regexp': Try to allow '_' be non-word char
1232 ;;; `cperl-perldoc': Add autoload
1233 ;;; `cperl-perldoc-at-point': Likewise
1234 ;;; `cperl-here-doc-spell': New function
1235 ;;; `cperl-pod-spell': Likewise
1236 ;;; `cperl-map-pods-heres': Likewise
1237 ;;; `cperl-get-here-doc-region': Likewise
1238 ;;; `cperl-font-lock-fontify-region-function': Likewise (backward compatibility
1239 ;;; for legacy `font-lock')
1240 ;;; `cperl-font-lock-unfontify-region-function': Fix style
1241 ;;; `cperl-fontify-syntaxically': Recognize and optimize away
1242 ;;; deferred calls with no-change. Governed by `cperl-hook-after-change'
1243 ;;; `cperl-fontify-update': Recognize that syntaxification region
1244 ;;; can be larger than fontification one.
1245 ;;; XXXX we leave `cperl-postpone' property, so this is quadratic...
1246 ;;; `cperl-fontify-update-bad': Temporary placeholder until
1247 ;;; it is clear how to implement `cperl-fontify-update'.
1248 ;;; `cperl-time-fontification': New function
1249 ;;; `attrib-group': New text attribute
1250 ;;; `multiline': New value: `syntax-type' text attribute
1252 ;;;; After 5.2:
1253 ;;; `cperl-emulate-lazy-lock': New function
1254 ;;; `cperl-fontify-syntaxically': Would skip large regions
1255 ;;; Add `cperl-time-fontification', `cperl-emulate-lazy-lock' to menu
1256 ;;; Some globals were declared, but uninitialized
1258 ;;;; After 5.3, 5.4:
1259 ;;; `cperl-facemenu-add-face-function': Add docs, fix U<>
1260 ;;; Copyright message updated.
1261 ;;; `cperl-init-faces': Work around a bug in `font-lock'. May slow
1262 ;;; facification down a bit.
1263 ;;; Misprint for my|our|local for old `font-lock'
1264 ;;; "our" was not fontified same as "my|local"
1265 ;;; Highlight variables after "my" etc even in
1266 ;;; a middle of an expression
1267 ;;; Do not facify multiple variables after my etc
1268 ;;; unless parentheses are present
1270 ;;; After 5.5, 5.6
1271 ;;; `cperl-fontify-syntaxically': after-change hook could reset
1272 ;;; `cperl-syntax-done-to' to a middle of line; unwind to BOL.
1274 ;;; After 5.7:
1275 ;;; `cperl-init-faces': Allow highlighting of local ($/)
1276 ;;; `cperl-problems-old-emaxen': New variable (for the purpose of DOCSTRING).
1277 ;;; `cperl-problems': Remove fixed problems.
1278 ;;; `cperl-find-pods-heres': Recognize #-comments in m##x too
1279 ;;; Recognize charclasses (unless delimiter is \).
1280 ;;; `cperl-fontify-syntaxically': Unwinding to safe was done in wrong order
1281 ;;; `cperl-regexp-scan': Update docs
1282 ;;; `cperl-beautify-regexp-piece': use information got from regexp scan
1284 ;;; After 5.8:
1285 ;;; Major user visible changes:
1286 ;;; Recognition and fontification of character classes in RExen.
1287 ;;; Variable indentation of RExen according to groups
1289 ;;; `cperl-find-pods-heres': Recognize POSIX classes in REx charclasses
1290 ;;; Fontify REx charclasses in variable-name face
1291 ;;; Fontify POSIX charclasses in "type" face
1292 ;;; Fontify unmatched "]" in function-name face
1293 ;;; Mark first-char of HERE-doc as `front-sticky'
1294 ;;; Reset `front-sticky' property when needed
1295 ;;; `cperl-calculate-indent': Indents //x -RExen accordning to parens level
1296 ;;; `cperl-to-comment-or-eol': Recognize ends of `syntax-type' constructs
1297 ;;; `cperl-backward-to-noncomment': Recognize stringy `syntax-type' constructs
1298 ;;; Support `narrow'ed buffers.
1299 ;;; `cperl-praise': Remove a reservation
1300 ;;; `cperl-make-indent': New function
1301 ;;; `cperl-indent-for-comment': Use `cperl-make-indent'
1302 ;;; `cperl-indent-line': Likewise
1303 ;;; `cperl-lineup': Likewise
1304 ;;; `cperl-beautify-regexp-piece': Likewise
1305 ;;; `cperl-contract-level': Likewise
1306 ;;; `cperl-toggle-set-debug-unwind': New function
1307 ;;; New menu entry for this
1308 ;;; `fill-paragraph-function': Use when `boundp'
1309 ;;; `cperl-calculate-indent': Take into account groups when indenting RExen
1310 ;;; `cperl-to-comment-or-eol': Recognize # which end a string
1311 ;;; `cperl-modify-syntax-type': Make only syntax-table property non-sticky
1312 ;;; `cperl-fill-paragraph': Return t: needed for `fill-paragraph-function'
1313 ;;; `cperl-fontify-syntaxically': More clear debugging message
1314 ;;; `cperl-pod2man-build-command': XEmacs portability: check `Man-filter-list'
1315 ;;; `cperl-init-faces': More complicated highlight even on XEmacs (new)
1316 ;;; Merge cosmetic changes from XEmacs
1318 ;;; After 5.9:
1319 ;;; `cperl-1+': Moved to before the first use
1320 ;;; `cperl-1-': Likewise
1322 ;;; After 5.10:
1324 ;;; This code may lock Emacs hard!!! Use on your own risk!
1326 ;;; `cperl-font-locking': New internal variable
1327 ;;; `cperl-beginning-of-property': New function
1328 ;;; `cperl-calculate-indent': Use `cperl-beginning-of-property'
1329 ;;; instead of `previous-single-property-change'
1330 ;;; `cperl-unwind-to-safe': Likewise
1331 ;;; `cperl-after-expr-p': Likewise
1332 ;;; `cperl-get-here-doc-region': Likewise
1333 ;;; `cperl-font-lock-fontify-region-function': Likewise
1334 ;;; `cperl-to-comment-or-eol': Do not call `cperl-update-syntaxification'
1335 ;;; recursively
1336 ;;; Bound `next-single-property-change'
1337 ;;; via `point-max'
1338 ;;; `cperl-unwind-to-safe': Bound likewise
1339 ;;; `cperl-font-lock-fontify-region-function': Likewise
1340 ;;; `cperl-find-pods-heres': Mark as recursive for `cperl-to-comment-or-eol'
1341 ;;; Initialization of
1342 ;;; `cperl-font-lock-multiline-start' could be missed if the "main"
1343 ;;; fontification did not run due to the keyword being already fontified.
1344 ;;; `cperl-pod-spell': Return t from do-one-chunk function
1345 ;;; `cperl-map-pods-heres': Stop when the worker returns nil
1346 ;;; Call `cperl-update-syntaxification'
1347 ;;; `cperl-get-here-doc-region': Call `cperl-update-syntaxification'
1348 ;;; `cperl-get-here-doc-delim': Remove unused function
1350 ;;; After 5.11:
1352 ;;; The possible lockup of Emacs (introduced in 5.10) fixed
1354 ;;; `cperl-unwind-to-safe': `cperl-beginning-of-property' won't return nil
1355 ;;; `cperl-syntaxify-for-menu': New customization variable
1356 ;;; `cperl-select-this-pod-or-here-doc': New function
1357 ;;; `cperl-get-here-doc-region': Extra argument.
1358 ;;; Do not adjust pos by 1.
1360 ;;; New menu entries (Perl/Tools): selection of current POD or HERE-DOC section
1361 ;;; (Debugging CPerl:) backtrace on fontification
1363 ;;; After 5.12:
1364 ;;; `cperl-cached-syntax-table': use `car-safe'
1365 ;;; `cperl-forward-re': Remove spurious argument SET-ST
1366 ;;; Add documentation
1367 ;;; `cperl-forward-group-in-re': New function
1368 ;;; `cperl-find-pods-heres': Find and highlight (?{}) blocks in RExen.
1369 ;;; (XXXX Temporary (?) hack is to syntax-mark them as comment)
1371 ;;; After 5.13:
1372 ;;; `cperl-string-syntax-table': Make { and } not-grouping
1373 ;;; (Sometimes they ARE grouping in RExen, but matching them would only
1374 ;;; confuse in many situations when they are not).
1375 ;;; `beginning-of-buffer': Replaced two occurences with goto-char...
1376 ;;; `cperl-calculate-indent': `char-after' could be nil...
1377 ;;; `cperl-find-pods-heres': REx can start after "[" too
1378 ;;; Hightlight (??{}) in RExen too
1379 ;;; `cperl-maybe-white-and-comment-rex': New constant
1380 ;;; `cperl-white-and-comment-rex': Likewise
1381 ;;; XXXX Not very efficient, but hard to make
1382 ;;; better while keeping 1 group.
1384 ;;; After 5.13:
1385 ;;; `cperl-find-pods-heres': $foo << identifier() is not a HERE-DOC
1386 ;;; Likewise for 1 << identifier
1388 ;;; After 5.14:
1389 ;;; `cperl-find-pods-heres': Different logic for $foo .= <<EOF etc
1390 ;;; Error-less condition-case could fail
1391 ;;; `cperl-font-lock-fontify-region-function': Likewise
1392 ;;; `cperl-init-faces': Likewise
1394 ;;; After 5.15:
1395 ;;; `cperl-find-pods-heres': Support property REx-part2
1396 ;;; `cperl-calculate-indent': Likewise
1397 ;;; Don't special-case REx with non-empty 1st line
1398 ;;; `cperl-find-pods-heres': In RExen, highlight non-literal backslashes
1399 ;;; Invert highlighting of charclasses:
1400 ;;; now the envelop is highlighted
1401 ;;; Highlight many others 0-length builtins
1402 ;;; `cperl-praise': Mention indenting and highlight in RExen.
1404 ;;; After 5.15:
1405 ;;; `cperl-find-pods-heres': Highlight capturing parens in REx
1407 ;;; After 5.16:
1408 ;;; `cperl-find-pods-heres': Highlight '|' for alternation
1409 ;;; Initialize `font-lock-warning-face' if not present
1410 ;;; `cperl-find-pods-heres': Use `font-lock-warning-face' instead of
1411 ;;; `font-lock-function-name-face'
1412 ;;; `cperl-look-at-leading-count': Likewise
1413 ;;; `cperl-find-pods-heres': localize `font-lock-variable-name-face'
1414 ;;; `font-lock-keyword-face' (needed for
1415 ;;; batch processing) etc
1416 ;;; Use `font-lock-builtin-face' for builtin in REx
1417 ;;; Now `font-lock-variable-name-face'
1418 ;;; is used for interpolated variables.
1419 ;;; Use "talking aliases" for faces inside REx
1420 ;;; Highlight parts of REx (except in charclasses)
1421 ;;; according to the syntax and/or semantic
1422 ;;; Syntax-mark a {}-part of (?{}) as "comment"
1423 ;;; (it was the ()-part)
1424 ;;; Better logic to distinguish what is what in REx
1425 ;;; `cperl-tips-faces': Document REx highlighting
1426 ;;; `cperl-praise': Mention REx syntax highlight etc.
1428 ;;; After 5.17:
1429 ;;; `cperl-find-sub-attrs': Would not always manage to print error message
1430 ;;; `cperl-find-pods-heres': localize `font-lock-constant-face'
1432 ;;; After 5.18:
1433 ;;; `cperl-find-pods-heres': Misprint in REx for parsing REx
1434 ;;; Very minor optimization
1435 ;;; `my-cperl-REx-modifiers-face' got quoted
1436 ;;; Recognize "print $foo <<END" as HERE-doc.
1437 ;;; Put `REx-interpolated' text attribute if needed
1438 ;;; `cperl-invert-if-unless-modifiers': New function.
1439 ;;; `cperl-backward-to-start-of-expr': Likewise
1440 ;;; `cperl-forward-to-end-of-expr': Likewise
1441 ;;; `cperl-invert-if-unless': Works in "the opposite way" too.
1442 ;;; Cursor position on return is on the switch-word
1443 ;;; Indents comments better
1444 ;;; `REx-interpolated': New text attribute
1445 ;;; `cperl-next-interpolated-REx': New function.
1446 ;;; `cperl-next-interpolated-REx-0': Likewise.
1447 ;;; `cperl-next-interpolated-REx-1': Likewise.
1448 ;;; "\C-c\C-x", "\C-c\C-y", "\C-c\C-v": New keybinding for these functions
1449 ;;; Perl/Regexp menu: 3 new entries for `cperl-next-interpolated-REx'
1450 ;;; `cperl-praise': Mention finded interpolated RExen.
1452 ;;; After 5.19:
1453 ;;; `cperl-init-faces': Highlight %$foo, @$foo too.
1454 ;;; `cperl-short-docs': Better docs for system, exec
1455 ;;; `cperl-find-pods-heres': Better detect << after print {FH} <<EOF etc.
1456 ;;; Would not find HERE-doc ended by EOF without NL
1457 ;;; `cperl-short-docs': Correct not-doubled \-escapes
1459 ;;; Perl6 changes by Steffen Schwigon (http://renormalist.net)
1461 ;;; Modified to understand Perl6 syntax.
1462 ;;; Details:
1464 ;;; New config variable `cperl-use-v6' that switches between Perl5/Perl6
1465 ;;; syntax.
1467 ;;; Simple heuristics to automatically activate Perl6 specific syntax
1468 ;;; * search for "use v6" or "class ..." near beginning of file
1469 ;;; * file suffix .p6
1471 ;;; Highlighting new keywords/builtins:
1472 ;;; class, module, role, grammar, rule, token, regex,
1473 ;;; has, state, does,
1474 ;;; say,
1475 ;;; rx,
1476 ;;; any, all, one, none,
1477 ;;; returns, of,
1478 ;;; multi/proto sub method,
1479 ;;; given, when, default, loop,
1480 ;;; gather, take, taken,
1481 ;;; coro, yield,
1482 ;;; try, err,
1483 ;;; zip, uniq, reduce, sum, max, min, kv, pairs, type, pick,
1484 ;;; "bit" "int" "str" "num" "ref" "bool" "Any" "Bit" "Int" "Str" "Num" "Ref",
1485 ;;; "Complex" "Exception" "Seq" "Range" "Set" "Junction" "Pair" "Mapping" "Signature" "Capture",
1486 ;;; "Bool" "Array" "Hash" "IO" "Code" "Routine" "Sub" "Method" "Submethod",
1487 ;;; "Macro" "Rule" "Block" "Bare" "Parametric" "Package" "Module" "Class", "Role",
1488 ;;; "Object" "Grammar" "List" "Lazy" "Eager",
1489 ;;; "Real" "Scalar" "int8" "Socket"
1491 ;;; Indentation:
1492 ;;; recognize sub traits (returns Type, is rw, etc.)
1493 ;;; recognize more special blocks:
1494 ;;; START, ENTER, LEAVE, KEEP, UNDO, FIRST, NEXT,
1495 ;;; LAST, PRE, POST, CATCH, CONTROL,
1496 ;;; given, when, default, gather, loop,
1497 ;;; class, module, role, grammar
1499 ;;; Recognize if/elsif/unless/while/until/given/when/for/loop-conditions
1500 ;;; without parens. (currently rather trivial heuristic)
1502 ;;; New rx// quote operator for regular expressions,
1503 ;;; parameterized rx// modifiers like perl5<i>, nth(3), x(3)
1505 ;;; m// and s/// similar to new rx//
1507 ;;; `Pugs' style added.
1509 ;;; Now only the @ and % sigils match arrays and hashes,
1510 ;;; not the bracket or brace after it.
1512 ;;; Brackets/braces for arrays/hashes must
1513 ;;; have no whitespace after variable name.
1515 ;;; No longer mark sub prototypes as string, just use ordinary highlighting.
1517 ;;; Highlight variable names with [.:^*+?=!] after twigils (@.name, $:name, $^name, ...)
1519 ;;; Fixed $:name was wrongly interpreted as label
1522 ;;; Code:
1524 (if (fboundp 'eval-when-compile)
1525 (eval-when-compile
1526 (condition-case nil
1527 (require 'custom)
1528 (error nil))
1529 (condition-case nil
1530 (require 'man)
1531 (error nil))
1532 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
1533 (defvar cperl-can-font-lock
1534 (or cperl-xemacs-p
1535 (and (boundp 'emacs-major-version)
1536 (or window-system
1537 (> emacs-major-version 20)))))
1538 (if cperl-can-font-lock
1539 (require 'font-lock))
1540 (defvar msb-menu-cond)
1541 (defvar gud-perldb-history)
1542 (defvar font-lock-background-mode) ; not in Emacs
1543 (defvar font-lock-display-type) ; ditto
1544 (defvar paren-backwards-message) ; Not in newer XEmacs?
1545 (defvar vc-rcs-header) ; likewise?
1546 (defvar vc-sccs-header) ; likewise?
1547 (defvar compilation-error-regexp-alist) ; used in Emacs 22
1548 (or (fboundp 'defgroup)
1549 (defmacro defgroup (name val doc &rest arr)
1550 nil))
1551 (or (fboundp 'custom-declare-variable)
1552 (defmacro defcustom (name val doc &rest arr)
1553 (` (defvar (, name) (, val) (, doc)))))
1554 (or (and (fboundp 'custom-declare-variable)
1555 (string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
1556 (defmacro defface (&rest arr)
1557 nil))
1558 ;; Avoid warning (tmp definitions)
1559 (or (fboundp 'x-color-defined-p)
1560 (defmacro x-color-defined-p (col)
1561 (cond ((fboundp 'color-defined-p) (` (color-defined-p (, col))))
1562 ;; XEmacs >= 19.12
1563 ((fboundp 'valid-color-name-p) (` (valid-color-name-p (, col))))
1564 ;; XEmacs 19.11
1565 ((fboundp 'x-valid-color-name-p) (` (x-valid-color-name-p (, col))))
1566 (t '(error "Cannot implement color-defined-p")))))
1567 (defmacro cperl-is-face (arg) ; Takes quoted arg
1568 (cond ((fboundp 'find-face)
1569 (` (find-face (, arg))))
1570 (;;(and (fboundp 'face-list)
1571 ;; (face-list))
1572 (fboundp 'face-list)
1573 (` (member (, arg) (and (fboundp 'face-list)
1574 (face-list)))))
1576 (` (boundp (, arg))))))
1577 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
1578 (cond ((fboundp 'make-face)
1579 (` (make-face (quote (, arg)))))
1581 (` (defvar (, arg) (quote (, arg)) (, descr))))))
1582 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
1583 (` (progn
1584 (or (cperl-is-face (quote (, arg)))
1585 (cperl-make-face (, arg) (, descr)))
1586 (or (boundp (quote (, arg))) ; We use unquoted variants too
1587 (defvar (, arg) (quote (, arg)) (, descr))))))
1588 (if cperl-xemacs-p
1589 (defmacro cperl-etags-snarf-tag (file line)
1590 (` (progn
1591 (beginning-of-line 2)
1592 (list (, file) (, line)))))
1593 (defmacro cperl-etags-snarf-tag (file line)
1594 (` (etags-snarf-tag))))
1595 (if cperl-xemacs-p
1596 (defmacro cperl-etags-goto-tag-location (elt)
1597 (`;;(progn
1598 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
1599 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
1600 ;; Probably will not work due to some save-excursion???
1601 ;; Or save-file-position?
1602 ;; (message "Did I get to line %s?" (elt (, elt) 1))
1603 (goto-line (string-to-int (elt (, elt) 1)))))
1605 (defmacro cperl-etags-goto-tag-location (elt)
1606 (` (etags-goto-tag-location (, elt)))))))
1608 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
1610 (defvar cperl-can-font-lock
1611 (or cperl-xemacs-p
1612 (and (boundp 'emacs-major-version)
1613 (or window-system
1614 (> emacs-major-version 20)))))
1616 (condition-case nil
1617 (require 'custom)
1618 (error nil)) ; Already fixed by eval-when-compile
1620 (defun cperl-choose-color (&rest list)
1621 (let (answer)
1622 (while list
1623 (or answer
1624 (if (or (x-color-defined-p (car list))
1625 (null (cdr list)))
1626 (setq answer (car list))))
1627 (setq list (cdr list)))
1628 answer))
1631 (defgroup cperl nil
1632 "Major mode for editing Perl code."
1633 :prefix "cperl-"
1634 :group 'languages)
1636 (defgroup cperl-indentation-details nil
1637 "Indentation."
1638 :prefix "cperl-"
1639 :group 'cperl)
1641 (defgroup cperl-affected-by-hairy nil
1642 "Variables affected by `cperl-hairy'."
1643 :prefix "cperl-"
1644 :group 'cperl)
1646 (defgroup cperl-autoinsert-details nil
1647 "Auto-insert tuneup."
1648 :prefix "cperl-"
1649 :group 'cperl)
1651 (defgroup cperl-faces nil
1652 "Fontification colors."
1653 :prefix "cperl-"
1654 :group 'cperl)
1656 (defgroup cperl-speed nil
1657 "Speed vs. validity tuneup."
1658 :prefix "cperl-"
1659 :group 'cperl)
1661 (defgroup cperl-help-system nil
1662 "Help system tuneup."
1663 :prefix "cperl-"
1664 :group 'cperl)
1667 (defcustom cperl-extra-newline-before-brace nil
1668 "*Non-nil means that if, elsif, while, until, else, for, foreach
1669 and do constructs look like:
1671 if ()
1675 instead of:
1677 if () {
1679 :type 'boolean
1680 :group 'cperl-autoinsert-details)
1682 (defcustom cperl-extra-newline-before-brace-multiline
1683 cperl-extra-newline-before-brace
1684 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
1685 for constructs with multiline if/unless/while/until/for/foreach condition."
1686 :type 'boolean
1687 :group 'cperl-autoinsert-details)
1689 (defcustom cperl-indent-level 2
1690 "*Indentation of CPerl statements with respect to containing block."
1691 :type 'integer
1692 :group 'cperl-indentation-details)
1694 (defcustom cperl-lineup-step nil
1695 "*`cperl-lineup' will always lineup at multiple of this number.
1696 If nil, the value of `cperl-indent-level' will be used."
1697 :type '(choice (const nil) integer)
1698 :group 'cperl-indentation-details)
1700 (defcustom cperl-brace-imaginary-offset 0
1701 "*Imagined indentation of a Perl open brace that actually follows a statement.
1702 An open brace following other text is treated as if it were this far
1703 to the right of the start of its line."
1704 :type 'integer
1705 :group 'cperl-indentation-details)
1707 (defcustom cperl-brace-offset 0
1708 "*Extra indentation for braces, compared with other text in same context."
1709 :type 'integer
1710 :group 'cperl-indentation-details)
1711 (defcustom cperl-label-offset -2
1712 "*Offset of CPerl label lines relative to usual indentation."
1713 :type 'integer
1714 :group 'cperl-indentation-details)
1715 (defcustom cperl-min-label-indent 1
1716 "*Minimal offset of CPerl label lines."
1717 :type 'integer
1718 :group 'cperl-indentation-details)
1719 (defcustom cperl-continued-statement-offset 2
1720 "*Extra indent for lines not starting new statements."
1721 :type 'integer
1722 :group 'cperl-indentation-details)
1723 (defcustom cperl-continued-brace-offset 0
1724 "*Extra indent for substatements that start with open-braces.
1725 This is in addition to cperl-continued-statement-offset."
1726 :type 'integer
1727 :group 'cperl-indentation-details)
1728 (defcustom cperl-close-paren-offset -1
1729 "*Extra indent for substatements that start with close-parenthesis."
1730 :type 'integer
1731 :group 'cperl-indentation-details)
1733 (defcustom cperl-auto-newline nil
1734 "*Non-nil means automatically newline before and after braces,
1735 and after colons and semicolons, inserted in CPerl code. The following
1736 \\[cperl-electric-backspace] will remove the inserted whitespace.
1737 Insertion after colons requires both this variable and
1738 `cperl-auto-newline-after-colon' set."
1739 :type 'boolean
1740 :group 'cperl-autoinsert-details)
1742 (defcustom cperl-autoindent-on-semi nil
1743 "*Non-nil means automatically indent after insertion of (semi)colon.
1744 Active if `cperl-auto-newline' is false."
1745 :type 'boolean
1746 :group 'cperl-autoinsert-details)
1748 (defcustom cperl-auto-newline-after-colon nil
1749 "*Non-nil means automatically newline even after colons.
1750 Subject to `cperl-auto-newline' setting."
1751 :type 'boolean
1752 :group 'cperl-autoinsert-details)
1754 (defcustom cperl-tab-always-indent t
1755 "*Non-nil means TAB in CPerl mode should always reindent the current line,
1756 regardless of where in the line point is when the TAB command is used."
1757 :type 'boolean
1758 :group 'cperl-indentation-details)
1760 (defcustom cperl-font-lock nil
1761 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
1762 Can be overwritten by `cperl-hairy' if nil."
1763 :type '(choice (const null) boolean)
1764 :group 'cperl-affected-by-hairy)
1766 (defcustom cperl-electric-lbrace-space nil
1767 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
1768 Can be overwritten by `cperl-hairy' if nil."
1769 :type '(choice (const null) boolean)
1770 :group 'cperl-affected-by-hairy)
1772 (defcustom cperl-electric-parens-string "({[]})<"
1773 "*String of parentheses that should be electric in CPerl.
1774 Closing ones are electric only if the region is highlighted."
1775 :type 'string
1776 :group 'cperl-affected-by-hairy)
1778 (defcustom cperl-electric-parens nil
1779 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
1780 Can be overwritten by `cperl-hairy' if nil."
1781 :type '(choice (const null) boolean)
1782 :group 'cperl-affected-by-hairy)
1784 (defvar zmacs-regions) ; Avoid warning
1786 (defcustom cperl-electric-parens-mark
1787 (and window-system
1788 (or (and (boundp 'transient-mark-mode) ; For Emacs
1789 transient-mark-mode)
1790 (and (boundp 'zmacs-regions) ; For XEmacs
1791 zmacs-regions)))
1792 "*Not-nil means that electric parens look for active mark.
1793 Default is yes if there is visual feedback on mark."
1794 :type 'boolean
1795 :group 'cperl-autoinsert-details)
1797 (defcustom cperl-electric-linefeed nil
1798 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
1799 In any case these two mean plain and hairy linefeeds together.
1800 Can be overwritten by `cperl-hairy' if nil."
1801 :type '(choice (const null) boolean)
1802 :group 'cperl-affected-by-hairy)
1804 (defcustom cperl-electric-keywords nil
1805 "*Not-nil (and non-null) means keywords are electric in CPerl.
1806 Can be overwritten by `cperl-hairy' if nil."
1807 :type '(choice (const null) boolean)
1808 :group 'cperl-affected-by-hairy)
1810 (defcustom cperl-electric-backspace-untabify t
1811 "*Not-nil means electric-backspace will untabify in CPerl."
1812 :type 'boolean
1813 :group 'cperl-autoinsert-details)
1815 (defcustom cperl-hairy nil
1816 "*Not-nil means most of the bells and whistles are enabled in CPerl.
1817 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
1818 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
1819 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
1820 `cperl-lazy-help-time'."
1821 :type 'boolean
1822 :group 'cperl-affected-by-hairy)
1824 (defcustom cperl-comment-column 32
1825 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
1826 :type 'integer
1827 :group 'cperl-indentation-details)
1829 (defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
1830 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
1831 :type '(repeat string)
1832 :group 'cperl)
1834 (defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
1835 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
1836 :type '(repeat string)
1837 :group 'cperl)
1839 ;; This became obsolete...
1840 (defcustom cperl-vc-header-alist '()
1841 "*What to use as `vc-header-alist' in CPerl.
1842 Obsolete, with newer Emacsen use `cperl-vc-rcs-header' or
1843 `cperl-vc-sccs-header' instead. If this list is empty, `vc-header-alist'
1844 will be reconstructed basing on these two variables."
1845 :type '(repeat (list symbol string))
1846 :group 'cperl)
1848 (defcustom cperl-clobber-mode-lists
1849 (not
1850 (and
1851 (boundp 'interpreter-mode-alist)
1852 (assoc "miniperl" interpreter-mode-alist)
1853 (assoc "\\.\\([pP][Llm6]\\|al\\)$" auto-mode-alist)))
1854 "*Whether to install us into `interpreter-' and `extension' mode lists."
1855 :type 'boolean
1856 :group 'cperl)
1858 (defcustom cperl-info-on-command-no-prompt nil
1859 "*Not-nil (and non-null) means not to prompt on C-h f.
1860 The opposite behaviour is always available if prefixed with C-c.
1861 Can be overwritten by `cperl-hairy' if nil."
1862 :type '(choice (const null) boolean)
1863 :group 'cperl-affected-by-hairy)
1865 (defcustom cperl-clobber-lisp-bindings nil
1866 "*Not-nil (and non-null) means not overwrite C-h f.
1867 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
1868 Can be overwritten by `cperl-hairy' if nil."
1869 :type '(choice (const null) boolean)
1870 :group 'cperl-affected-by-hairy)
1872 (defcustom cperl-lazy-help-time nil
1873 "*Not-nil (and non-null) means to show lazy help after given idle time.
1874 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
1875 :type '(choice (const null) (const nil) integer)
1876 :group 'cperl-affected-by-hairy)
1878 (defcustom cperl-pod-face 'font-lock-comment-face
1879 "*The result of evaluation of this expression is used for POD highlighting."
1880 :type 'face
1881 :group 'cperl-faces)
1883 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
1884 "*The result of evaluation of this expression is used for POD highlighting.
1885 Font for POD headers."
1886 :type 'face
1887 :group 'cperl-faces)
1889 (defcustom cperl-here-face 'font-lock-string-face
1890 "*The result of evaluation of this expression is used for here-docs highlighting."
1891 :type 'face
1892 :group 'cperl-faces)
1894 ;;; Some double-evaluation happened with font-locks... Needed with 21.2...
1895 (defvar cperl-singly-quote-face cperl-xemacs-p)
1897 (defcustom cperl-invalid-face ; Does not customize with '' on XEmacs
1898 (if cperl-singly-quote-face
1899 'underline ''underline) ; On older Emacsen was evaluated by `font-lock'
1900 (if cperl-singly-quote-face
1901 "*This face is used for highlighting trailing whitespace."
1902 "*The result of evaluation of this expression highlights trailing whitespace.")
1903 :type 'face
1904 :group 'cperl-faces)
1906 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
1907 "*Not-nil after evaluation means to highlight POD and here-docs sections."
1908 :type 'boolean
1909 :group 'cperl-faces)
1911 (defcustom cperl-fontify-m-as-s t
1912 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
1913 :type 'boolean
1914 :group 'cperl-faces)
1916 (defcustom cperl-highlight-variables-indiscriminately nil
1917 "*Non-nil means perform additional highlighting on variables.
1918 Currently only changes how scalar variables are highlighted.
1919 Note that that variable is only read at initialization time for
1920 the variable `perl-font-lock-keywords-2', so changing it after you've
1921 entered CPerl mode the first time will have no effect."
1922 :type 'boolean
1923 :group 'cperl)
1925 (defcustom cperl-pod-here-scan t
1926 "*Not-nil means look for POD and here-docs sections during startup.
1927 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
1928 :type 'boolean
1929 :group 'cperl-speed)
1931 (defcustom cperl-regexp-scan t
1932 "*Not-nil means make marking of regular expression more thorough.
1933 Effective only with `cperl-pod-here-scan'."
1934 :type 'boolean
1935 :group 'cperl-speed)
1937 (defcustom cperl-hook-after-change t
1938 "*Not-nil means install hook to know which regions of buffer are changed.
1939 May significantly speed up delayed fontification. Changes take effect
1940 after reload."
1941 :type 'boolean
1942 :group 'cperl-speed)
1944 (defcustom cperl-imenu-addback nil
1945 "*Not-nil means add backreferences to generated `imenu's.
1946 May require patched `imenu' and `imenu-go'. Obsolete."
1947 :type 'boolean
1948 :group 'cperl-help-system)
1950 (defcustom cperl-max-help-size 66
1951 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
1952 :type '(choice integer (const nil))
1953 :group 'cperl-help-system)
1955 (defcustom cperl-shrink-wrap-info-frame t
1956 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
1957 :type 'boolean
1958 :group 'cperl-help-system)
1960 (defcustom cperl-info-page "perl"
1961 "*Name of the info page containing perl docs.
1962 Older version of this page was called `perl5', newer `perl'."
1963 :type 'string
1964 :group 'cperl-help-system)
1966 (defcustom cperl-use-syntax-table-text-property
1967 (boundp 'parse-sexp-lookup-properties)
1968 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
1969 :type 'boolean
1970 :group 'cperl-speed)
1972 (defcustom cperl-use-syntax-table-text-property-for-tags
1973 cperl-use-syntax-table-text-property
1974 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
1975 :type 'boolean
1976 :group 'cperl-speed)
1978 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm6]\\|xs\\)$"
1979 "*Regexp to match files to scan when generating TAGS."
1980 :type 'regexp
1981 :group 'cperl)
1983 (defcustom cperl-noscan-files-regexp
1984 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
1985 "*Regexp to match files/dirs to skip when generating TAGS."
1986 :type 'regexp
1987 :group 'cperl)
1989 (defcustom cperl-regexp-indent-step nil
1990 "*Indentation used when beautifying regexps.
1991 If nil, the value of `cperl-indent-level' will be used."
1992 :type '(choice integer (const nil))
1993 :group 'cperl-indentation-details)
1995 (defcustom cperl-indent-left-aligned-comments t
1996 "*Non-nil means that the comment starting in leftmost column should indent."
1997 :type 'boolean
1998 :group 'cperl-indentation-details)
2000 (defcustom cperl-under-as-char t
2001 "*Non-nil means that the _ (underline) should be treated as word char."
2002 :type 'boolean
2003 :group 'cperl)
2005 (defcustom cperl-extra-perl-args ""
2006 "*Extra arguments to use when starting Perl.
2007 Currently used with `cperl-check-syntax' only."
2008 :type 'string
2009 :group 'cperl)
2011 (defcustom cperl-message-electric-keyword t
2012 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
2013 :type 'boolean
2014 :group 'cperl-help-system)
2016 (defcustom cperl-indent-region-fix-constructs 1
2017 "*Amount of space to insert between `}' and `else' or `elsif'
2018 in `cperl-indent-region'. Set to nil to leave as is. Values other
2019 than 1 and nil will probably not work."
2020 :type '(choice (const nil) (const 1))
2021 :group 'cperl-indentation-details)
2023 (defcustom cperl-break-one-line-blocks-when-indent t
2024 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
2025 need to be reformatted into multiline ones when indenting a region."
2026 :type 'boolean
2027 :group 'cperl-indentation-details)
2029 (defcustom cperl-fix-hanging-brace-when-indent t
2030 "*Non-nil means that BLOCK-end `}' may be put on a separate line
2031 when indenting a region.
2032 Braces followed by else/elsif/while/until are excepted."
2033 :type 'boolean
2034 :group 'cperl-indentation-details)
2036 (defcustom cperl-merge-trailing-else t
2037 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
2038 may be merged to be on the same line when indenting a region."
2039 :type 'boolean
2040 :group 'cperl-indentation-details)
2042 (defcustom cperl-indent-parens-as-block nil
2043 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
2044 but for trailing \",\" inside the group, which won't increase indentation.
2045 One should tune up `cperl-close-paren-offset' as well."
2046 :type 'boolean
2047 :group 'cperl-indentation-details)
2049 (defcustom cperl-syntaxify-by-font-lock
2050 (and cperl-can-font-lock
2051 (boundp 'parse-sexp-lookup-properties))
2052 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
2053 :type '(choice (const message) boolean)
2054 :group 'cperl-speed)
2056 (defcustom cperl-syntaxify-unwind
2058 "*Non-nil means that CPerl unwinds to a start of a long construction
2059 when syntaxifying a chunk of buffer."
2060 :type 'boolean
2061 :group 'cperl-speed)
2063 (defcustom cperl-syntaxify-for-menu
2065 "*Non-nil means that CPerl syntaxifies up to the point before showing menu.
2066 This way enabling/disabling of menu items is more correct."
2067 :type 'boolean
2068 :group 'cperl-speed)
2070 (defcustom cperl-ps-print-face-properties
2071 '((font-lock-keyword-face nil nil bold shadow)
2072 (font-lock-variable-name-face nil nil bold)
2073 (font-lock-function-name-face nil nil bold italic box)
2074 (font-lock-constant-face nil "LightGray" bold)
2075 (cperl-array-face nil "LightGray" bold underline)
2076 (cperl-hash-face nil "LightGray" bold italic underline)
2077 (font-lock-comment-face nil "LightGray" italic)
2078 (font-lock-string-face nil nil italic underline)
2079 (cperl-nonoverridable-face nil nil italic underline)
2080 (font-lock-type-face nil nil underline)
2081 (font-lock-warning-face nil "LightGray" bold italic box)
2082 (underline nil "LightGray" strikeout))
2083 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
2084 :type '(repeat (cons symbol
2085 (cons (choice (const nil) string)
2086 (cons (choice (const nil) string)
2087 (repeat symbol)))))
2088 :group 'cperl-faces)
2090 (defcustom cperl-use-v6 nil
2091 "*Non-nil means that CPerl parses for Perl6 syntax."
2092 :type 'boolean
2093 :group 'cperl)
2095 (defun cperl-looks-like-perl6 ()
2096 ;; Searches for typical Perl6 patterns and returns true if found.
2097 ;; TODO: Tooooo lame.
2099 (string-match "\\.[Pp]6$" (buffer-file-name))
2100 (save-excursion
2101 (beginning-of-buffer)
2102 (search-forward-regexp "^[\t ]*\\(use \\(v6\\|6\\.[0-9]+\\)\\|\\(class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\)[\t ]+.*;\\)" 320 t))))
2104 (if cperl-can-font-lock
2105 (progn
2106 (defvar cperl-dark-background
2107 (cperl-choose-color "navy" "os2blue" "darkgreen"))
2108 (defvar cperl-dark-foreground
2109 (cperl-choose-color "orchid1" "orange"))
2111 (defface cperl-nonoverridable-face
2112 (` ((((class grayscale) (background light))
2113 (:background "Gray90" :italic t :underline t))
2114 (((class grayscale) (background dark))
2115 (:foreground "Gray80" :italic t :underline t :bold t))
2116 (((class color) (background light))
2117 (:foreground "chartreuse3"))
2118 (((class color) (background dark))
2119 (:foreground (, cperl-dark-foreground)))
2120 (t (:bold t :underline t))))
2121 "Font Lock mode face used to highlight array names."
2122 :group 'cperl-faces)
2124 (defface cperl-array-face
2125 (` ((((class grayscale) (background light))
2126 (:background "Gray90" :bold t))
2127 (((class grayscale) (background dark))
2128 (:foreground "Gray80" :bold t))
2129 (((class color) (background light))
2130 (:foreground "Blue" :background "lightyellow2" :bold t))
2131 (((class color) (background dark))
2132 (:foreground "yellow" :background (, cperl-dark-background) :bold t))
2133 (t (:bold t))))
2134 "Font Lock mode face used to highlight array names."
2135 :group 'cperl-faces)
2137 (defface cperl-hash-face
2138 (` ((((class grayscale) (background light))
2139 (:background "Gray90" :bold t :italic t))
2140 (((class grayscale) (background dark))
2141 (:foreground "Gray80" :bold t :italic t))
2142 (((class color) (background light))
2143 (:foreground "Red" :background "lightyellow2" :bold t :italic t))
2144 (((class color) (background dark))
2145 (:foreground "Red" :background (, cperl-dark-background) :bold t :italic t))
2146 (t (:bold t :italic t))))
2147 "Font Lock mode face used to highlight hash names."
2148 :group 'cperl-faces)))
2152 ;;; Short extra-docs.
2154 (defvar cperl-tips 'please-ignore-this-line
2155 "Get maybe newer version of this package from
2156 http://ilyaz.org/software/emacs
2157 Subdirectory `cperl-mode' may contain yet newer development releases and/or
2158 patches to related files.
2160 For best results apply to an older Emacs the patches from
2161 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
2162 \(this upgrades syntax-parsing abilities of RMS Emaxen v19.34 and
2163 v20.2 up to the level of RMS Emacs v20.3 - a must for a good Perl
2164 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
2166 Get support packages choose-color.el (or font-lock-extra.el before
2167 19.30), imenu-go.el from the same place. \(Look for other files there
2168 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
2169 later you should use choose-color.el *instead* of font-lock-extra.el
2170 \(and you will not get smart highlighting in C :-().
2172 Note that to enable Compile choices in the menu you need to install
2173 mode-compile.el.
2175 If your Emacs does not default to `cperl-mode' on Perl files, and you
2176 want it to: put the following into your .emacs file:
2178 (autoload 'perl-mode \"cperl-mode\" \"alternate mode for editing Perl programs\" t)
2182 (defalias 'perl-mode 'cperl-mode)
2184 Get perl5-info from
2185 $CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
2186 Also, one can generate a newer documentation running `pod2texi' converter
2187 $CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
2189 If you use imenu-go, run imenu on perl5-info buffer (you can do it
2190 from Perl menu). If many files are related, generate TAGS files from
2191 Tools/Tags submenu in Perl menu.
2193 If some class structure is too complicated, use Tools/Hierarchy-view
2194 from Perl menu, or hierarchic view of imenu. The second one uses the
2195 current buffer only, the first one requires generation of TAGS from
2196 Perl/Tools/Tags menu beforehand.
2198 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
2200 Switch auto-help on/off with Perl/Tools/Auto-help.
2202 Though with contemporary Emaxen CPerl mode should maintain the correct
2203 parsing of Perl even when editing, sometimes it may be lost. Fix this by
2205 M-x norm RET
2209 \\[normal-mode]
2211 In cases of more severe confusion sometimes it is helpful to do
2213 M-x load-l RET cperl-mode RET
2214 M-x norm RET
2218 \\[load-library] cperl-mode RET
2219 \\[normal-mode]
2221 Before reporting (non-)problems look in the problem section of online
2222 micro-docs on what I know about CPerl problems.")
2224 (defvar cperl-problems 'please-ignore-this-line
2225 "Description of problems in CPerl mode.
2226 Some faces will not be shown on some versions of Emacs unless you
2227 install choose-color.el, available from
2228 http://ilyaz.org/software/emacs
2230 `fill-paragraph' on a comment may leave the point behind the
2231 paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
2232 to detect it and bulk out).
2234 See documentation of a variable `cperl-problems-old-emaxen' for the
2235 problems which disappear if you upgrade Emacs to a reasonably new
2236 version (20.3 for RMS Emacs, and those of 2004 for XEmacs).")
2238 (defvar cperl-problems-old-emaxen 'please-ignore-this-line
2239 "Description of problems in CPerl mode specific for older Emacs versions.
2241 Emacs had a _very_ restricted syntax parsing engine until RMS's Emacs
2242 20.1. Most problems below are corrected starting from this version of
2243 Emacs, and all of them should be fixed in RMS's version 20.3. (Or apply
2244 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
2245 this respect (until 2003).
2247 Note that even with newer Emacsen in some very rare cases the details
2248 of interaction of `font-lock' and syntaxification may be not cleaned
2249 up yet. You may get slightly different colors basing on the order of
2250 fontification and syntaxification. Say, the initial faces is correct,
2251 but editing the buffer breaks this.
2253 Even with older Emacsen CPerl mode tries to corrects some Emacs
2254 misunderstandings, however, for efficiency reasons the degree of
2255 correction is different for different operations. The partially
2256 corrected problems are: POD sections, here-documents, regexps. The
2257 operations are: highlighting, indentation, electric keywords, electric
2258 braces.
2260 This may be confusing, since the regexp s#//#/#\; may be highlighted
2261 as a comment, but it will be recognized as a regexp by the indentation
2262 code. Or the opposite case, when a POD section is highlighted, but
2263 may break the indentation of the following code (though indentation
2264 should work if the balance of delimiters is not broken by POD).
2266 The main trick (to make $ a \"backslash\") makes constructions like
2267 ${aaa} look like unbalanced braces. The only trick I can think of is
2268 to insert it as $ {aaa} (legal in perl5, not in perl4).
2270 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
2271 as /($|\\s)/. Note that such a transposition is not always possible.
2273 The solution is to upgrade your Emacs or patch an older one. Note
2274 that RMS's 20.2 has some bugs related to `syntax-table' text
2275 properties. Patches are available on the main CPerl download site,
2276 and on CPAN.
2278 If these bugs cannot be fixed on your machine (say, you have an inferior
2279 environment and cannot recompile), you may still disable all the fancy stuff
2280 via `cperl-use-syntax-table-text-property'.")
2282 (defvar cperl-non-problems 'please-ignore-this-line
2283 "As you know from `problems' section, Perl syntax is too hard for CPerl on
2284 older Emacsen. Here is what you can do if you cannot upgrade, or if
2285 you want to switch off these capabilities on RMS Emacs 20.2 (+patches) or 20.3
2286 or better. Please skip this docs if you run a capable Emacs already.
2288 Most of the time, if you write your own code, you may find an equivalent
2289 \(and almost as readable) expression (what is discussed below is usually
2290 not relevant on newer Emacsen, since they can do it automatically).
2292 Try to help CPerl: add comments with embedded quotes to fix CPerl
2293 misunderstandings about the end of quotation:
2295 $a='500$'; # ';
2297 You won't need it too often. The reason: $ \"quotes\" the following
2298 character (this saves a life a lot of times in CPerl), thus due to
2299 Emacs parsing rules it does not consider tick (i.e., ' ) after a
2300 dollar as a closing one, but as a usual character. This is usually
2301 correct, but not in the above context.
2303 Even with older Emacsen the indentation code is pretty wise. The only
2304 drawback is that it relied on Emacs parsing to find matching
2305 parentheses. And Emacs *could not* match parentheses in Perl 100%
2306 correctly. So
2307 1 if s#//#/#;
2308 would not break indentation, but
2309 1 if ( s#//#/# );
2310 would. Upgrade.
2312 By similar reasons
2313 s\"abc\"def\";
2314 could confuse CPerl a lot.
2316 If you still get wrong indentation in situation that you think the
2317 code should be able to parse, try:
2319 a) Check what Emacs thinks about balance of your parentheses.
2320 b) Supply the code to me (IZ).
2322 Pods were treated _very_ rudimentally. Here-documents were not
2323 treated at all (except highlighting and inhibiting indentation). Upgrade.
2325 To speed up coloring the following compromises exist:
2326 a) sub in $mypackage::sub may be highlighted.
2327 b) -z in [a-z] may be highlighted.
2328 c) if your regexp contains a keyword (like \"s\"), it may be highlighted.
2331 Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove
2332 `car' before `imenu-choose-buffer-index' in `imenu'.
2333 `imenu-add-to-menubar' in 20.2 is broken.
2334 A lot of things on XEmacs may be broken too, judging by bug reports I
2335 receive. Note that some releases of XEmacs are better than the others
2336 as far as bugs reports I see are concerned.")
2338 (defvar cperl-praise 'please-ignore-this-line
2339 "Advantages of CPerl mode.
2341 0) It uses the newest `syntax-table' property ;-);
2343 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
2344 mode - but the latter number may have improved too in last years) even
2345 with old Emaxen which do not support `syntax-table' property.
2347 When using `syntax-table' property for syntax assist hints, it should
2348 handle 99.995% of lines correct - or somesuch. It automatically
2349 updates syntax assist hints when you edit your script.
2351 2) It is generally believed to be \"the most user-friendly Emacs
2352 package\" whatever it may mean (I doubt that the people who say similar
2353 things tried _all_ the rest of Emacs ;-), but this was not a lonely
2354 voice);
2356 3) Everything is customizable, one-by-one or in a big sweep;
2358 4) It has many easily-accessable \"tools\":
2359 a) Can run program, check syntax, start debugger;
2360 b) Can lineup vertically \"middles\" of rows, like `=' in
2361 a = b;
2362 cc = d;
2363 c) Can insert spaces where this impoves readability (in one
2364 interactive sweep over the buffer);
2365 d) Has support for imenu, including:
2366 1) Separate unordered list of \"interesting places\";
2367 2) Separate TOC of POD sections;
2368 3) Separate list of packages;
2369 4) Hierarchical view of methods in (sub)packages;
2370 5) and functions (by the full name - with package);
2371 e) Has an interface to INFO docs for Perl; The interface is
2372 very flexible, including shrink-wrapping of
2373 documentation buffer/frame;
2374 f) Has a builtin list of one-line explanations for perl constructs.
2375 g) Can show these explanations if you stay long enough at the
2376 corresponding place (or on demand);
2377 h) Has an enhanced fontification (using 3 or 4 additional faces
2378 comparing to font-lock - basically, different
2379 namespaces in Perl have different colors);
2380 i) Can construct TAGS basing on its knowledge of Perl syntax,
2381 the standard menu has 6 different way to generate
2382 TAGS (if \"by directory\", .xs files - with C-language
2383 bindings - are included in the scan);
2384 j) Can build a hierarchical view of classes (via imenu) basing
2385 on generated TAGS file;
2386 k) Has electric parentheses, electric newlines, uses Abbrev
2387 for electric logical constructs
2388 while () {}
2389 with different styles of expansion (context sensitive
2390 to be not so bothering). Electric parentheses behave
2391 \"as they should\" in a presence of a visible region.
2392 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
2393 m) Can convert from
2394 if (A) { B }
2396 B if A;
2398 n) Highlights (by user-choice) either 3-delimiters constructs
2399 (such as tr/a/b/), or regular expressions and `y/tr';
2400 o) Highlights trailing whitespace;
2401 p) Is able to manipulate Perl Regular Expressions to ease
2402 conversion to a more readable form.
2403 q) Can ispell POD sections and HERE-DOCs.
2404 r) Understands comments and character classes inside regular
2405 expressions; can find matching () and [] in a regular expression.
2406 s) Allows indentation of //x-style regular expressions;
2407 t) Highlights different symbols in regular expressions according
2408 to their function; much less problems with backslashitis;
2409 u) Allows to find regular expressions which contain interpolated parts.
2411 5) The indentation engine was very smart, but most of tricks may be
2412 not needed anymore with the support for `syntax-table' property. Has
2413 progress indicator for indentation (with `imenu' loaded).
2415 6) Indent-region improves inline-comments as well; also corrects
2416 whitespace *inside* the conditional/loop constructs.
2418 7) Fill-paragraph correctly handles multi-line comments;
2420 8) Can switch to different indentation styles by one command, and restore
2421 the settings present before the switch.
2423 9) When doing indentation of control constructs, may correct
2424 line-breaks/spacing between elements of the construct.
2426 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
2427 capable syntax engines).
2429 11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
2432 (defvar cperl-speed 'please-ignore-this-line
2433 "This is an incomplete compendium of what is available in other parts
2434 of CPerl documentation. (Please inform me if I skept anything.)
2436 There is a perception that CPerl is slower than alternatives. This part
2437 of documentation is designed to overcome this misconception.
2439 *By default* CPerl tries to enable the most comfortable settings.
2440 From most points of view, correctly working package is infinitely more
2441 comfortable than a non-correctly working one, thus by default CPerl
2442 prefers correctness over speed. Below is the guide how to change
2443 settings if your preferences are different.
2445 A) Speed of loading the file. When loading file, CPerl may perform a
2446 scan which indicates places which cannot be parsed by primitive Emacs
2447 syntax-parsing routines, and marks them up so that either
2449 A1) CPerl may work around these deficiencies (for big chunks, mostly
2450 PODs and HERE-documents), or
2451 A2) On capable Emaxen CPerl will use improved syntax-handlings
2452 which reads mark-up hints directly.
2454 The scan in case A2 is much more comprehensive, thus may be slower.
2456 User can disable syntax-engine-helping scan of A2 by setting
2457 `cperl-use-syntax-table-text-property'
2458 variable to nil (if it is set to t).
2460 One can disable the scan altogether (both A1 and A2) by setting
2461 `cperl-pod-here-scan'
2462 to nil.
2464 B) Speed of editing operations.
2466 One can add a (minor) speedup to editing operations by setting
2467 `cperl-use-syntax-table-text-property'
2468 variable to nil (if it is set to t). This will disable
2469 syntax-engine-helping scan, thus will make many more Perl
2470 constructs be wrongly recognized by CPerl, thus may lead to
2471 wrongly matched parentheses, wrong indentation, etc.
2473 One can unset `cperl-syntaxify-unwind'. This might speed up editing
2474 of, say, long POD sections.")
2476 (defvar cperl-tips-faces 'please-ignore-this-line
2477 "CPerl mode uses following faces for highlighting:
2479 `cperl-array-face' Array names
2480 `cperl-hash-face' Hash names
2481 `font-lock-comment-face' Comments, PODs and whatever is considered
2482 syntaxically to be not code
2483 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
2484 2-arg operators s/y/tr/ or of RExen,
2485 `font-lock-warning-face' Special-cased m// and s//foo/,
2486 `font-lock-function-name-face' _ as a target of a file tests, file tests,
2487 subroutine names at the moment of definition
2488 (except those conflicting with Perl operators),
2489 package names (when recognized), format names
2490 `font-lock-keyword-face' Control flow switch constructs, declarators
2491 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
2492 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
2493 literal parts and the terminator of formats
2494 and whatever is syntaxically considered
2495 as string literals
2496 `font-lock-type-face' Overridable keywords
2497 `font-lock-variable-name-face' Variable declarations, indirect array and
2498 hash names, POD headers/item names
2499 `cperl-invalid-face' Trailing whitespace
2501 Note that in several situations the highlighting tries to inform about
2502 possible confusion, such as different colors for function names in
2503 declarations depending on what they (do not) override, or special cases
2504 m// and s/// which do not do what one would expect them to do.
2506 Help with best setup of these faces for printout requested (for each of
2507 the faces: please specify bold, italic, underline, shadow and box.)
2509 In regular expressions (except character classes):
2510 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs
2511 `font-lock-constant-face': Delimiters
2512 `font-lock-warning-face' Special-cased m// and s//foo/,
2513 Mismatched closing delimiters, parens
2514 we couldn't match, misplaced quantifiers,
2515 unrecognized escape sequences
2516 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
2517 `font-lock-type-face' POSIX classes inside charclasses,
2518 escape sequences with arguments (\x \23 \p \N)
2519 and others match-a-char escape sequences
2520 `font-lock-keyword-face' Capturing parens, and |
2521 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
2522 `font-lock-builtin-face' \"Remaining\" 0-length constructs, executable
2523 parts of a REx, not-capturing parens
2524 `font-lock-variable-name-face' Interpolated constructs, embedded code
2525 `font-lock-comment-face' Embedded comments
2531 ;;; Portability stuff:
2533 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
2534 (` (define-key cperl-mode-map
2535 (, (if xemacs-key
2536 (` (if cperl-xemacs-p (, xemacs-key) (, emacs-key)))
2537 emacs-key))
2538 (, definition))))
2540 (defvar cperl-del-back-ch
2541 (car (append (where-is-internal 'delete-backward-char)
2542 (where-is-internal 'backward-delete-char-untabify)))
2543 "Character generated by key bound to `delete-backward-char'.")
2545 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
2546 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
2548 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
2549 (if cperl-xemacs-p
2550 (progn
2551 ;; "Active regions" are on: use region only if active
2552 ;; "Active regions" are off: use region unconditionally
2553 (defun cperl-use-region-p ()
2554 (if zmacs-regions (mark) t)))
2555 (defun cperl-use-region-p ()
2556 (if transient-mark-mode mark-active t))
2557 (defun cperl-mark-active () mark-active))
2559 (defsubst cperl-enable-font-lock ()
2560 cperl-can-font-lock)
2562 (defun cperl-putback-char (c) ; Emacs 19
2563 (set 'unread-command-events (list c))) ; Avoid undefined warning
2565 (if (boundp 'unread-command-events)
2566 (if cperl-xemacs-p
2567 (defun cperl-putback-char (c) ; XEmacs >= 19.12
2568 (setq unread-command-events (list (eval '(character-to-event c))))))
2569 (defun cperl-putback-char (c) ; XEmacs <= 19.11
2570 (set 'unread-command-event (eval '(character-to-event c))))) ; Avoid warnings
2572 (or (fboundp 'uncomment-region)
2573 (defun uncomment-region (beg end)
2574 (interactive "r")
2575 (comment-region beg end -1)))
2577 (defvar cperl-do-not-fontify
2578 (if (string< emacs-version "19.30")
2579 'fontified
2580 'lazy-lock)
2581 "Text property which inhibits refontification.")
2583 (defsubst cperl-put-do-not-fontify (from to &optional post)
2584 ;; If POST, do not do it with postponed fontification
2585 (if (and post cperl-syntaxify-by-font-lock)
2587 (put-text-property (max (point-min) (1- from))
2588 to cperl-do-not-fontify t)))
2590 (defcustom cperl-mode-hook nil
2591 "Hook run by CPerl mode."
2592 :type 'hook
2593 :group 'cperl)
2595 (defvar cperl-syntax-state nil)
2596 (defvar cperl-syntax-done-to nil)
2597 (defvar cperl-emacs-can-parse (> (length (save-excursion
2598 (parse-partial-sexp (point) (point)))) 9))
2600 ;; Make customization possible "in reverse"
2601 (defsubst cperl-val (symbol &optional default hairy)
2602 (cond
2603 ((eq (symbol-value symbol) 'null) default)
2604 (cperl-hairy (or hairy t))
2605 (t (symbol-value symbol))))
2608 (defun cperl-make-indent (column &optional minimum keep)
2609 "Makes indent of the current line the requested amount.
2610 If ANEW, removes the old indentation. Works around a bug in ancient
2611 versions of Emacs."
2612 (let ((prop (get-text-property (point) 'syntax-type)))
2613 (or keep
2614 (delete-horizontal-space))
2615 (indent-to column minimum)
2616 ;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
2617 (and prop
2618 (> (current-column) 0)
2619 (save-excursion
2620 (beginning-of-line)
2621 (or (get-text-property (point) 'syntax-type)
2622 (and (looking-at "\\=[ \t]")
2623 (put-text-property (point) (match-end 0)
2624 'syntax-type prop)))))))
2626 ;;; Probably it is too late to set these guys already, but it can help later:
2628 (and cperl-clobber-mode-lists
2629 (setq auto-mode-alist
2630 (append '(("\\.\\([pP][Llm6]\\|al\\)$" . perl-mode)) auto-mode-alist ))
2631 (and (boundp 'interpreter-mode-alist)
2632 (setq interpreter-mode-alist (append interpreter-mode-alist
2633 '(("miniperl" . perl-mode))))))
2634 (if (fboundp 'eval-when-compile)
2635 (eval-when-compile
2636 (mapcar (lambda (p)
2637 (condition-case nil
2638 (require p)
2639 (error nil)))
2640 '(imenu easymenu etags timer man info))
2641 (if (fboundp 'ps-extend-face-list)
2642 (defmacro cperl-ps-extend-face-list (arg)
2643 (` (ps-extend-face-list (, arg))))
2644 (defmacro cperl-ps-extend-face-list (arg)
2645 (` (error "This version of Emacs has no `ps-extend-face-list'"))))
2646 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
2647 ;; macros instead of defsubsts don't work on Emacs, so we do the
2648 ;; expansion manually. Any other suggestions?
2649 (if cperl-can-font-lock
2650 (require 'font-lock))
2651 (require 'cl)))
2653 (defvar cperl-mode-abbrev-table nil
2654 "Abbrev table in use in CPerl mode buffers.")
2656 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
2658 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
2660 (if cperl-mode-map nil
2661 (setq cperl-mode-map (make-sparse-keymap))
2662 (cperl-define-key "{" 'cperl-electric-lbrace)
2663 (cperl-define-key "[" 'cperl-electric-paren)
2664 (cperl-define-key "(" 'cperl-electric-paren)
2665 (cperl-define-key "<" 'cperl-electric-paren)
2666 (cperl-define-key "}" 'cperl-electric-brace)
2667 (cperl-define-key "]" 'cperl-electric-rparen)
2668 (cperl-define-key ")" 'cperl-electric-rparen)
2669 (cperl-define-key ";" 'cperl-electric-semi)
2670 (cperl-define-key ":" 'cperl-electric-terminator)
2671 (cperl-define-key "\C-j" 'newline-and-indent)
2672 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
2673 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
2674 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
2675 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
2676 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
2677 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
2678 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
2679 (cperl-define-key "\C-c\C-b" 'cperl-find-bad-style)
2680 (cperl-define-key "\C-c\C-p" 'cperl-pod-spell)
2681 (cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell)
2682 (cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc)
2683 (cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx)
2684 (cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0)
2685 (cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1)
2686 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
2687 (cperl-define-key "\C-c\C-hp" 'cperl-perldoc)
2688 (cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point)
2689 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
2690 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
2691 [(control meta |)])
2692 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
2693 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
2694 (cperl-define-key "\177" 'cperl-electric-backspace)
2695 (cperl-define-key "\t" 'cperl-indent-command)
2696 ;; don't clobber the backspace binding:
2697 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
2698 [(control c) (control h) F])
2699 (if (cperl-val 'cperl-clobber-lisp-bindings)
2700 (progn
2701 (cperl-define-key "\C-hf"
2702 ;;(concat (char-to-string help-char) "f") ; does not work
2703 'cperl-info-on-command
2704 [(control h) f])
2705 (cperl-define-key "\C-hv"
2706 ;;(concat (char-to-string help-char) "v") ; does not work
2707 'cperl-get-help
2708 [(control h) v])
2709 (cperl-define-key "\C-c\C-hf"
2710 ;;(concat (char-to-string help-char) "f") ; does not work
2711 (key-binding "\C-hf")
2712 [(control c) (control h) f])
2713 (cperl-define-key "\C-c\C-hv"
2714 ;;(concat (char-to-string help-char) "v") ; does not work
2715 (key-binding "\C-hv")
2716 [(control c) (control h) v]))
2717 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
2718 [(control c) (control h) f])
2719 (cperl-define-key "\C-c\C-hv"
2720 ;;(concat (char-to-string help-char) "v") ; does not work
2721 'cperl-get-help
2722 [(control c) (control h) v]))
2723 (if (and cperl-xemacs-p
2724 (<= emacs-minor-version 11) (<= emacs-major-version 19))
2725 (progn
2726 ;; substitute-key-definition is usefulness-deenhanced...
2727 ;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
2728 (cperl-define-key "\e;" 'cperl-indent-for-comment)
2729 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
2730 (or (boundp 'fill-paragraph-function)
2731 (substitute-key-definition
2732 'fill-paragraph 'cperl-fill-paragraph
2733 cperl-mode-map global-map))
2734 (substitute-key-definition
2735 'indent-sexp 'cperl-indent-exp
2736 cperl-mode-map global-map)
2737 (substitute-key-definition
2738 'indent-region 'cperl-indent-region
2739 cperl-mode-map global-map)
2740 (substitute-key-definition
2741 'indent-for-comment 'cperl-indent-for-comment
2742 cperl-mode-map global-map)))
2744 (defvar cperl-menu)
2745 (defvar cperl-lazy-installed)
2746 (defvar cperl-old-style nil)
2747 (condition-case nil
2748 (progn
2749 (require 'easymenu)
2750 (easy-menu-define
2751 cperl-menu cperl-mode-map "Menu for CPerl mode"
2752 '("Perl"
2753 ["Beginning of function" beginning-of-defun t]
2754 ["End of function" end-of-defun t]
2755 ["Mark function" mark-defun t]
2756 ["Indent expression" cperl-indent-exp t]
2757 ["Fill paragraph/comment" cperl-fill-paragraph t]
2758 "----"
2759 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
2760 ["Invert if/unless/while etc" cperl-invert-if-unless t]
2761 ("Regexp"
2762 ["Beautify" cperl-beautify-regexp
2763 cperl-use-syntax-table-text-property]
2764 ["Beautify one level deep" (cperl-beautify-regexp 1)
2765 cperl-use-syntax-table-text-property]
2766 ["Beautify a group" cperl-beautify-level
2767 cperl-use-syntax-table-text-property]
2768 ["Beautify a group one level deep" (cperl-beautify-level 1)
2769 cperl-use-syntax-table-text-property]
2770 ["Contract a group" cperl-contract-level
2771 cperl-use-syntax-table-text-property]
2772 ["Contract groups" cperl-contract-levels
2773 cperl-use-syntax-table-text-property]
2774 "----"
2775 ["Find next interpolated" cperl-next-interpolated-REx
2776 (next-single-property-change (point-min) 'REx-interpolated)]
2777 ["Find next interpolated (no //o)"
2778 cperl-next-interpolated-REx-0
2779 (or (text-property-any (point-min) (point-max) 'REx-interpolated t)
2780 (text-property-any (point-min) (point-max) 'REx-interpolated 1))]
2781 ["Find next interpolated (neither //o nor whole-REx)"
2782 cperl-next-interpolated-REx-1
2783 (text-property-any (point-min) (point-max) 'REx-interpolated t)])
2784 ["Insert spaces if needed to fix style" cperl-find-bad-style t]
2785 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
2786 "----"
2787 ["Indent region" cperl-indent-region (cperl-use-region-p)]
2788 ["Comment region" cperl-comment-region (cperl-use-region-p)]
2789 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
2790 "----"
2791 ["Run" mode-compile (fboundp 'mode-compile)]
2792 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
2793 (get-buffer "*compilation*"))]
2794 ["Next error" next-error (get-buffer "*compilation*")]
2795 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
2796 "----"
2797 ["Debugger" cperl-db t]
2798 "----"
2799 ("Tools"
2800 ["Imenu" imenu (fboundp 'imenu)]
2801 ["Imenu on Perl Info" cperl-imenu-on-info (featurep 'imenu)]
2802 "----"
2803 ["Ispell PODs" cperl-pod-spell
2804 ;; Better not to update syntaxification here:
2805 ;; debugging syntaxificatio can be broken by this???
2807 (get-text-property (point-min) 'in-pod)
2808 (< (progn
2809 (and cperl-syntaxify-for-menu
2810 (cperl-update-syntaxification (point-max) (point-max)))
2811 (next-single-property-change (point-min) 'in-pod nil (point-max)))
2812 (point-max)))]
2813 ["Ispell HERE-DOCs" cperl-here-doc-spell
2814 (< (progn
2815 (and cperl-syntaxify-for-menu
2816 (cperl-update-syntaxification (point-max) (point-max)))
2817 (next-single-property-change (point-min) 'here-doc-group nil (point-max)))
2818 (point-max))]
2819 ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
2820 (eq 'here-doc (progn
2821 (and cperl-syntaxify-for-menu
2822 (cperl-update-syntaxification (point) (point)))
2823 (get-text-property (point) 'syntax-type)))]
2824 ["Select this HERE-DOC or POD section"
2825 cperl-select-this-pod-or-here-doc
2826 (memq (progn
2827 (and cperl-syntaxify-for-menu
2828 (cperl-update-syntaxification (point) (point)))
2829 (get-text-property (point) 'syntax-type))
2830 '(here-doc pod))]
2831 "----"
2832 ["CPerl pretty print (exprmntl)" cperl-ps-print
2833 (fboundp 'ps-extend-face-list)]
2834 "----"
2835 ["Syntaxify region" cperl-find-pods-heres-region
2836 (cperl-use-region-p)]
2837 ["Profile syntaxification" cperl-time-fontification t]
2838 ["Debug errors in delayed fontification" cperl-emulate-lazy-lock t]
2839 ["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t]
2840 ["Debug backtrace on syntactic scan (BEWARE!!!)"
2841 (cperl-toggle-set-debug-unwind nil t) t]
2842 "----"
2843 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
2844 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
2845 ("Tags"
2846 ;;; ["Create tags for current file" cperl-etags t]
2847 ;;; ["Add tags for current file" (cperl-etags t) t]
2848 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
2849 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
2850 ;;; ["Create tags for Perl files in (sub)directories"
2851 ;;; (cperl-etags nil 'recursive) t]
2852 ;;; ["Add tags for Perl files in (sub)directories"
2853 ;;; (cperl-etags t 'recursive) t])
2854 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
2855 ["Create tags for current file" (cperl-write-tags nil t) t]
2856 ["Add tags for current file" (cperl-write-tags) t]
2857 ["Create tags for Perl files in directory"
2858 (cperl-write-tags nil t nil t) t]
2859 ["Add tags for Perl files in directory"
2860 (cperl-write-tags nil nil nil t) t]
2861 ["Create tags for Perl files in (sub)directories"
2862 (cperl-write-tags nil t t t) t]
2863 ["Add tags for Perl files in (sub)directories"
2864 (cperl-write-tags nil nil t t) t]))
2865 ("Perl docs"
2866 ["Define word at point" imenu-go-find-at-position
2867 (fboundp 'imenu-go-find-at-position)]
2868 ["Help on function" cperl-info-on-command t]
2869 ["Help on function at point" cperl-info-on-current-command t]
2870 ["Help on symbol at point" cperl-get-help t]
2871 ["Perldoc" cperl-perldoc t]
2872 ["Perldoc on word at point" cperl-perldoc-at-point t]
2873 ["View manpage of POD in this file" cperl-build-manpage t]
2874 ["Auto-help on" cperl-lazy-install
2875 (and (fboundp 'run-with-idle-timer)
2876 (not cperl-lazy-installed))]
2877 ["Auto-help off" cperl-lazy-unstall
2878 (and (fboundp 'run-with-idle-timer)
2879 cperl-lazy-installed)])
2880 ("Toggle..."
2881 ["Auto newline" cperl-toggle-auto-newline t]
2882 ["Electric parens" cperl-toggle-electric t]
2883 ["Electric keywords" cperl-toggle-abbrev t]
2884 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
2885 ["Auto-help on Perl constructs" cperl-toggle-autohelp t]
2886 ["Auto fill" auto-fill-mode t])
2887 ("Indent styles..."
2888 ["CPerl" (cperl-set-style "CPerl") t]
2889 ["PerlStyle" (cperl-set-style "PerlStyle") t]
2890 ["Pugs" (cperl-set-style "Pugs") t]
2891 ["GNU" (cperl-set-style "GNU") t]
2892 ["C++" (cperl-set-style "C++") t]
2893 ["FSF" (cperl-set-style "FSF") t]
2894 ["BSD" (cperl-set-style "BSD") t]
2895 ["Whitesmith" (cperl-set-style "Whitesmith") t]
2896 ["Current" (cperl-set-style "Current") t]
2897 ["Memorized" (cperl-set-style-back) cperl-old-style])
2898 ("Micro-docs"
2899 ["Tips" (describe-variable 'cperl-tips) t]
2900 ["Problems" (describe-variable 'cperl-problems) t]
2901 ["Non-problems" (describe-variable 'cperl-non-problems) t]
2902 ["Speed" (describe-variable 'cperl-speed) t]
2903 ["Praise" (describe-variable 'cperl-praise) t]
2904 ["Faces" (describe-variable 'cperl-tips-faces) t]
2905 ["CPerl mode" (describe-function 'cperl-mode) t]
2906 ["CPerl version"
2907 (message "The version of master-file for this CPerl is %s"
2908 cperl-version) t]))))
2909 (error nil))
2911 (autoload 'c-macro-expand "cmacexp"
2912 "Display the result of expanding all C macros occurring in the region.
2913 The expansion is entirely correct because it uses the C preprocessor."
2916 ;;; These two must be unwound, otherwise take exponential time
2917 (defconst cperl-maybe-white-and-comment-rex "[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
2918 "Regular expression to match optional whitespace with interpspersed comments.
2919 Should contain exactly one group.")
2921 ;;; This one is tricky to unwind; still very inefficient...
2922 (defconst cperl-white-and-comment-rex "\\([ \t\n]\\|#[^\n]*\n\\)+"
2923 "Regular expression to match whitespace with interpspersed comments.
2924 Should contain exactly one group.")
2927 ;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
2928 ;;; `cperl-outline-regexp', `defun-prompt-regexp'.
2929 ;;; Details of groups in this may be used in several functions; see comments
2930 ;;; near mentioned above variable(s)...
2931 ;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
2932 (defsubst cperl-after-sub-regexp (named attr) ; 9 groups without attr...
2933 "Match the text after `sub' in a subroutine declaration.
2934 If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
2935 of attributes (if present), or end of the name or prototype (whatever is
2936 the last)."
2937 (concat ; Assume n groups before this...
2938 "\\(" ; n+1=name-group
2939 cperl-white-and-comment-rex ; n+2=pre-name
2940 "\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
2941 "\\)" ; END n+1=name-group
2942 (if named "" "?")
2943 "\\(" ; n+4=proto-group
2944 cperl-maybe-white-and-comment-rex ; n+5=pre-proto
2945 "\\(([^()]*)\\)" ; n+6=prototype
2946 "\\)?" ; END n+4=proto-group
2947 "\\(" ; n+7=attr-group
2948 cperl-maybe-white-and-comment-rex ; n+8=pre-attr
2949 "\\(" ; n+9=start-attr
2951 (if attr (concat
2952 "\\("
2953 cperl-maybe-white-and-comment-rex ; whitespace-comments
2954 "\\(\\sw\\|_\\)+" ; attr-name
2955 ;; attr-arg (1 level of internal parens allowed!)
2956 "\\((\\(\\\\.\\|[^\\\\()]\\|([^\\\\()]*)\\)*)\\)?"
2957 "\\(" ; optional : (XXX allows trailing???)
2958 cperl-maybe-white-and-comment-rex ; whitespace-comments
2959 ":\\)?"
2960 "\\)+")
2961 "[^:]")
2962 "\\)"
2963 "\\)?" ; END n+6=proto-group
2966 ;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
2967 ;;; and `cperl-outline-level'.
2968 ;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 11=sub-name (+3)
2969 (defvar cperl-imenu--function-name-regexp-perl
2970 (concat
2971 "^\\(" ; 1 = all
2972 "\\([ \t]*package" ; 2 = package-group
2973 "\\(" ; 3 = package-name-group
2974 cperl-white-and-comment-rex ; 4 = pre-package-name
2975 "\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
2976 "\\|"
2977 "[ \t]*\\(\\(multi\\|proto\\)[ \t]*\\)?\\(coro\\|sub\\|method\\|submethod\\)?" ; perl6
2978 (cperl-after-sub-regexp 'named nil) ; 11=name 14=proto 17=attr-start
2979 cperl-maybe-white-and-comment-rex ; 18=pre-block
2980 "\\|"
2981 "=head\\([1-4]\\)[ \t]+" ; 19=level
2982 "\\([^\n]+\\)$" ; 20=text
2983 "\\)"))
2985 (defvar cperl-outline-regexp
2986 (concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
2988 (defvar cperl-mode-syntax-table nil
2989 "Syntax table in use in CPerl mode buffers.")
2991 (defvar cperl-string-syntax-table nil
2992 "Syntax table in use in CPerl mode string-like chunks.")
2994 (defsubst cperl-1- (p)
2995 (max (point-min) (1- p)))
2997 (defsubst cperl-1+ (p)
2998 (min (point-max) (1+ p)))
3000 (if cperl-mode-syntax-table
3002 (setq cperl-mode-syntax-table (make-syntax-table))
3003 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
3004 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
3005 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
3006 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
3007 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
3008 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
3009 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
3010 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
3011 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
3012 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
3013 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
3014 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
3015 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
3016 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
3017 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
3018 (if cperl-under-as-char
3019 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
3020 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
3021 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
3022 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
3023 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
3024 (modify-syntax-entry ?\{ "." cperl-string-syntax-table)
3025 (modify-syntax-entry ?\} "." cperl-string-syntax-table)
3026 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment )
3030 ;; provide an alias for working with emacs 19. the perl-mode that comes
3031 ;; with it is really bad, and this lets us seamlessly replace it.
3032 ;;;###autoload
3033 (fset 'perl-mode 'cperl-mode)
3034 (defvar cperl-faces-init nil)
3035 ;; Fix for msb.el
3036 (defvar cperl-msb-fixed nil)
3037 (defvar font-lock-syntactic-keywords)
3038 (defvar perl-font-lock-keywords)
3039 (defvar perl-font-lock-keywords-1)
3040 (defvar perl-font-lock-keywords-2)
3041 (defvar outline-level)
3042 (if (fboundp 'defvaralias)
3043 (let ((f 'defvaralias)) ; Some functions deduce stuff from the mode name...
3044 (funcall f 'cperl-font-lock-keywords 'perl-font-lock-keywords)
3045 (funcall f 'cperl-font-lock-keywords-1 'perl-font-lock-keywords-1)
3046 (funcall f 'cperl-font-lock-keywords-2 'perl-font-lock-keywords-2)))
3048 (defvar cperl-use-major-mode 'perl-mode)
3049 (defvar cperl-font-lock-multiline-start nil)
3050 (defvar cperl-font-lock-multiline nil)
3051 (defvar cperl-compilation-error-regexp-alist nil)
3052 (defvar cperl-font-locking nil)
3054 ;;;###autoload
3055 (defun cperl-mode ()
3056 "Major mode for editing Perl code.
3057 Expression and list commands understand all C brackets.
3058 Tab indents for Perl code.
3059 Paragraphs are separated by blank lines only.
3060 Delete converts tabs to spaces as it moves back.
3062 Various characters in Perl almost always come in pairs: {}, (), [],
3063 sometimes <>. When the user types the first, she gets the second as
3064 well, with optional special formatting done on {}. (Disabled by
3065 default.) You can always quote (with \\[quoted-insert]) the left
3066 \"paren\" to avoid the expansion. The processing of < is special,
3067 since most the time you mean \"less\". CPerl mode tries to guess
3068 whether you want to type pair <>, and inserts is if it
3069 appropriate. You can set `cperl-electric-parens-string' to the string that
3070 contains the parenths from the above list you want to be electrical.
3071 Electricity of parenths is controlled by `cperl-electric-parens'.
3072 You may also set `cperl-electric-parens-mark' to have electric parens
3073 look for active mark and \"embrace\" a region if possible.'
3075 CPerl mode provides expansion of the Perl control constructs:
3077 if, else, elsif, unless, while, until, continue, do,
3078 for, foreach, formy and foreachmy.
3080 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
3082 The user types the keyword immediately followed by a space, which
3083 causes the construct to be expanded, and the point is positioned where
3084 she is most likely to want to be. eg. when the user types a space
3085 following \"if\" the following appears in the buffer: if () { or if ()
3086 } { } and the cursor is between the parentheses. The user can then
3087 type some boolean expression within the parens. Having done that,
3088 typing \\[cperl-linefeed] places you - appropriately indented - on a
3089 new line between the braces (if you typed \\[cperl-linefeed] in a POD
3090 directive line, then appropriate number of new lines is inserted).
3092 If CPerl decides that you want to insert \"English\" style construct like
3094 bite if angry;
3096 it will not do any expansion. See also help on variable
3097 `cperl-extra-newline-before-brace'. (Note that one can switch the
3098 help message on expansion by setting `cperl-message-electric-keyword'
3099 to nil.)
3101 \\[cperl-linefeed] is a convenience replacement for typing carriage
3102 return. It places you in the next line with proper indentation, or if
3103 you type it inside the inline block of control construct, like
3105 foreach (@lines) {print; print}
3107 and you are on a boundary of a statement inside braces, it will
3108 transform the construct into a multiline and will place you into an
3109 appropriately indented blank line. If you need a usual
3110 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
3111 see documentation on `cperl-electric-linefeed'.
3113 Use \\[cperl-invert-if-unless] to change a construction of the form
3115 if (A) { B }
3117 into
3119 B if A;
3121 \\{cperl-mode-map}
3123 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
3124 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
3125 on electric space between $ and {, `cperl-electric-parens-string' is
3126 the string that contains parentheses that should be electric in CPerl
3127 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
3128 setting `cperl-electric-keywords' enables electric expansion of
3129 control structures in CPerl. `cperl-electric-linefeed' governs which
3130 one of two linefeed behavior is preferable. You can enable all these
3131 options simultaneously (recommended mode of use) by setting
3132 `cperl-hairy' to t. In this case you can switch separate options off
3133 by setting them to `null'. Note that one may undo the extra
3134 whitespace inserted by semis and braces in `auto-newline'-mode by
3135 consequent \\[cperl-electric-backspace].
3137 If your site has perl5 documentation in info format, you can use commands
3138 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
3139 These keys run commands `cperl-info-on-current-command' and
3140 `cperl-info-on-command', which one is which is controlled by variable
3141 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
3142 \(in turn affected by `cperl-hairy').
3144 Even if you have no info-format documentation, short one-liner-style
3145 help is available on \\[cperl-get-help], and one can run perldoc or
3146 man via menu.
3148 It is possible to show this help automatically after some idle time.
3149 This is regulated by variable `cperl-lazy-help-time'. Default with
3150 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
3151 secs idle time . It is also possible to switch this on/off from the
3152 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
3154 Use \\[cperl-lineup] to vertically lineup some construction - put the
3155 beginning of the region at the start of construction, and make region
3156 span the needed amount of lines.
3158 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
3159 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
3160 here-docs sections. With capable Emaxen results of scan are used
3161 for indentation too, otherwise they are used for highlighting only.
3163 Variables controlling indentation style:
3164 `cperl-tab-always-indent'
3165 Non-nil means TAB in CPerl mode should always reindent the current line,
3166 regardless of where in the line point is when the TAB command is used.
3167 `cperl-indent-left-aligned-comments'
3168 Non-nil means that the comment starting in leftmost column should indent.
3169 `cperl-auto-newline'
3170 Non-nil means automatically newline before and after braces,
3171 and after colons and semicolons, inserted in Perl code. The following
3172 \\[cperl-electric-backspace] will remove the inserted whitespace.
3173 Insertion after colons requires both this variable and
3174 `cperl-auto-newline-after-colon' set.
3175 `cperl-auto-newline-after-colon'
3176 Non-nil means automatically newline even after colons.
3177 Subject to `cperl-auto-newline' setting.
3178 `cperl-indent-level'
3179 Indentation of Perl statements within surrounding block.
3180 The surrounding block's indentation is the indentation
3181 of the line on which the open-brace appears.
3182 `cperl-continued-statement-offset'
3183 Extra indentation given to a substatement, such as the
3184 then-clause of an if, or body of a while, or just a statement continuation.
3185 `cperl-continued-brace-offset'
3186 Extra indentation given to a brace that starts a substatement.
3187 This is in addition to `cperl-continued-statement-offset'.
3188 `cperl-brace-offset'
3189 Extra indentation for line if it starts with an open brace.
3190 `cperl-brace-imaginary-offset'
3191 An open brace following other text is treated as if it the line started
3192 this far to the right of the actual line indentation.
3193 `cperl-label-offset'
3194 Extra indentation for line that is a label.
3195 `cperl-min-label-indent'
3196 Minimal indentation for line that is a label.
3198 Settings for K&R and BSD indentation styles are
3199 `cperl-indent-level' 5 8
3200 `cperl-continued-statement-offset' 5 8
3201 `cperl-brace-offset' -5 -8
3202 `cperl-label-offset' -5 -8
3204 CPerl knows several indentation styles, and may bulk set the
3205 corresponding variables. Use \\[cperl-set-style] to do this. Use
3206 \\[cperl-set-style-back] to restore the memorized preexisting values
3207 \(both available from menu).
3209 If `cperl-indent-level' is 0, the statement after opening brace in
3210 column 0 is indented on
3211 `cperl-brace-offset'+`cperl-continued-statement-offset'.
3213 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
3214 with no args.
3216 DO NOT FORGET to read micro-docs (available from `Perl' menu)
3217 or as help on variables `cperl-tips', `cperl-problems',
3218 `cperl-non-problems', `cperl-praise', `cperl-speed'."
3219 (interactive)
3220 (kill-all-local-variables)
3221 (use-local-map cperl-mode-map)
3222 (if (cperl-val 'cperl-electric-linefeed)
3223 (progn
3224 (local-set-key "\C-J" 'cperl-linefeed)
3225 (local-set-key "\C-C\C-J" 'newline-and-indent)))
3226 (if (and
3227 (cperl-val 'cperl-clobber-lisp-bindings)
3228 (cperl-val 'cperl-info-on-command-no-prompt))
3229 (progn
3230 ;; don't clobber the backspace binding:
3231 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
3232 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
3233 [(control c) (control h) f])))
3234 (setq major-mode cperl-use-major-mode)
3235 (setq mode-name "CPerl")
3236 (if (not cperl-mode-abbrev-table)
3237 (let ((prev-a-c abbrevs-changed))
3238 (define-abbrev-table 'cperl-mode-abbrev-table '(
3239 ("if" "if" cperl-electric-keyword 0)
3240 ("elsif" "elsif" cperl-electric-keyword 0)
3241 ("while" "while" cperl-electric-keyword 0)
3242 ("until" "until" cperl-electric-keyword 0)
3243 ("unless" "unless" cperl-electric-keyword 0)
3244 ("else" "else" cperl-electric-else 0)
3245 ("continue" "continue" cperl-electric-else 0)
3246 ("for" "for" cperl-electric-keyword 0)
3247 ("foreach" "foreach" cperl-electric-keyword 0)
3248 ("formy" "formy" cperl-electric-keyword 0)
3249 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
3250 ("do" "do" cperl-electric-keyword 0)
3251 ("=pod" "=pod" cperl-electric-pod 0)
3252 ("=over" "=over" cperl-electric-pod 0)
3253 ("=head1" "=head1" cperl-electric-pod 0)
3254 ("=head2" "=head2" cperl-electric-pod 0)
3255 ("pod" "pod" cperl-electric-pod 0)
3256 ("over" "over" cperl-electric-pod 0)
3257 ("head1" "head1" cperl-electric-pod 0)
3258 ("head2" "head2" cperl-electric-pod 0)))
3259 (setq abbrevs-changed prev-a-c)))
3260 (setq local-abbrev-table cperl-mode-abbrev-table)
3261 (if (cperl-val 'cperl-electric-keywords)
3262 (abbrev-mode 1))
3263 (set-syntax-table cperl-mode-syntax-table)
3264 ;; Until Emacs is multi-threaded, we do not actually need it local:
3265 (make-local-variable 'cperl-font-lock-multiline-start)
3266 (make-local-variable 'cperl-font-locking)
3267 (make-local-variable 'outline-regexp)
3268 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
3269 (setq outline-regexp cperl-outline-regexp)
3270 (make-local-variable 'outline-level)
3271 (setq outline-level 'cperl-outline-level)
3272 (make-local-variable 'paragraph-start)
3273 (setq paragraph-start (concat "^$\\|" page-delimiter))
3274 (make-local-variable 'paragraph-separate)
3275 (setq paragraph-separate paragraph-start)
3276 (make-local-variable 'paragraph-ignore-fill-prefix)
3277 (setq paragraph-ignore-fill-prefix t)
3278 (if cperl-xemacs-p
3279 (progn
3280 (make-local-variable 'paren-backwards-message)
3281 (set 'paren-backwards-message t)))
3282 (make-local-variable 'indent-line-function)
3283 (setq indent-line-function 'cperl-indent-line)
3284 (make-local-variable 'require-final-newline)
3285 (setq require-final-newline t)
3286 (make-local-variable 'comment-start)
3287 (setq comment-start "# ")
3288 (make-local-variable 'comment-end)
3289 (setq comment-end "")
3290 (make-local-variable 'comment-column)
3291 (setq comment-column cperl-comment-column)
3292 (make-local-variable 'comment-start-skip)
3293 (setq comment-start-skip "#+ *")
3294 (make-local-variable 'defun-prompt-regexp)
3295 ;;; "[ \t]*sub"
3296 ;;; (cperl-after-sub-regexp 'named nil) ; 11=name 14=proto 17=attr-start
3297 ;;; cperl-maybe-white-and-comment-rex ; 16=pre-block
3298 (setq defun-prompt-regexp
3299 (concat "[ \t]*sub"
3300 (cperl-after-sub-regexp 'named 'attr-groups)
3301 cperl-maybe-white-and-comment-rex))
3302 (make-local-variable 'comment-indent-function)
3303 (setq comment-indent-function 'cperl-comment-indent)
3304 (and (boundp 'fill-paragraph-function)
3305 (progn
3306 (make-local-variable 'fill-paragraph-function)
3307 (set 'fill-paragraph-function 'cperl-fill-paragraph)))
3308 (make-local-variable 'parse-sexp-ignore-comments)
3309 (setq parse-sexp-ignore-comments t)
3310 (make-local-variable 'indent-region-function)
3311 (setq indent-region-function 'cperl-indent-region)
3312 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
3313 (make-local-variable 'imenu-create-index-function)
3314 (setq imenu-create-index-function
3315 (function cperl-imenu--create-perl-index))
3316 (make-local-variable 'imenu-sort-function)
3317 (setq imenu-sort-function nil)
3318 (make-local-variable 'vc-rcs-header)
3319 (set 'vc-rcs-header cperl-vc-rcs-header)
3320 (make-local-variable 'vc-sccs-header)
3321 (set 'vc-sccs-header cperl-vc-sccs-header)
3322 ;; This one is obsolete...
3323 (make-local-variable 'vc-header-alist)
3324 (set 'vc-header-alist (or cperl-vc-header-alist ; Avoid warning
3325 (` ((SCCS (, (car cperl-vc-sccs-header)))
3326 (RCS (, (car cperl-vc-rcs-header)))))))
3327 (cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x, emacs22
3328 (make-local-variable 'compilation-error-regexp-alist-alist)
3329 (set 'compilation-error-regexp-alist-alist
3330 (cons (cons 'cperl cperl-compilation-error-regexp-alist)
3331 (symbol-value 'compilation-error-regexp-alist-alist)))
3332 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
3333 (let ((f 'compilation-build-compilation-error-regexp-alist))
3334 (funcall f)) ; xemacs 20.x
3335 (make-local-variable 'compilation-error-regexp-alist) ; emacs22
3336 (push 'cperl compilation-error-regexp-alist)))
3337 ((boundp 'compilation-error-regexp-alist);; xmeacs 19.x
3338 (make-local-variable 'compilation-error-regexp-alist)
3339 (set 'compilation-error-regexp-alist
3340 (cons cperl-compilation-error-regexp-alist
3341 (symbol-value 'compilation-error-regexp-alist)))))
3342 (make-local-variable 'font-lock-defaults)
3343 (setq font-lock-defaults
3344 (cond
3345 ((string< emacs-version "19.30")
3346 '(perl-font-lock-keywords-2 nil nil ((?_ . "w"))))
3347 ((string< emacs-version "19.33") ; Which one to use?
3348 '((perl-font-lock-keywords
3349 perl-font-lock-keywords-1
3350 perl-font-lock-keywords-2) nil nil ((?_ . "w"))))
3352 '((cperl-load-font-lock-keywords
3353 cperl-load-font-lock-keywords-1
3354 cperl-load-font-lock-keywords-2) nil nil ((?_ . "w"))))))
3355 (make-local-variable 'cperl-syntax-state)
3356 (setq cperl-syntax-state nil) ; reset syntaxification cache
3357 (if cperl-use-syntax-table-text-property
3358 (progn
3359 (make-local-variable 'parse-sexp-lookup-properties)
3360 ;; Do not introduce variable if not needed, we check it!
3361 (set 'parse-sexp-lookup-properties t)
3362 ;; Fix broken font-lock:
3363 (or (boundp 'font-lock-unfontify-region-function)
3364 (set 'font-lock-unfontify-region-function
3365 'font-lock-default-unfontify-region))
3366 (unless cperl-xemacs-p ; Our: just a plug for wrong font-lock
3367 (make-local-variable 'font-lock-unfontify-region-function)
3368 (set 'font-lock-unfontify-region-function ; not present with old Emacs
3369 'cperl-font-lock-unfontify-region-function))
3370 (make-local-variable 'cperl-syntax-done-to)
3371 (setq cperl-syntax-done-to nil) ; reset syntaxification cache
3372 ;; Another bug: unless font-lock-syntactic-keywords, font-lock
3373 ;; ignores syntax-table text-property. (t) is a hack
3374 ;; to make font-lock think that font-lock-syntactic-keywords
3375 ;; are defined
3376 (make-local-variable 'font-lock-syntactic-keywords)
3377 (setq font-lock-syntactic-keywords
3378 (if cperl-syntaxify-by-font-lock
3379 '(t (cperl-fontify-syntaxically))
3380 '(t)))))
3381 (if (boundp 'font-lock-multiline) ; Newer font-lock; use its facilities
3382 (progn
3383 (setq cperl-font-lock-multiline t) ; Not localized...
3384 (set 'font-lock-multiline t)) ; not present with old Emacs; auto-local
3385 (make-local-variable 'font-lock-fontify-region-function)
3386 (set 'font-lock-fontify-region-function ; not present with old Emacs
3387 'cperl-font-lock-fontify-region-function))
3388 (make-local-variable 'font-lock-fontify-region-function)
3389 (set 'font-lock-fontify-region-function ; not present with old Emacs
3390 'cperl-font-lock-fontify-region-function)
3391 (make-local-variable 'cperl-old-style)
3392 (make-local-variable 'cperl-use-v6)
3393 (if (cperl-looks-like-perl6)
3394 (set 'cperl-use-v6 t)
3395 (set 'cperl-use-v6 nil)
3397 (if (boundp 'normal-auto-fill-function) ; 19.33 and later
3398 (set (make-local-variable 'normal-auto-fill-function)
3399 'cperl-do-auto-fill) ; RMS has it as #'cperl-do-auto-fill ???
3400 (or (fboundp 'cperl-old-auto-fill-mode)
3401 (progn
3402 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
3403 (defun auto-fill-mode (&optional arg)
3404 (interactive "P")
3405 (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
3406 (and auto-fill-function (memq major-mode '(perl-mode cperl-mode))
3407 (setq auto-fill-function 'cperl-do-auto-fill))))))
3408 (if (cperl-enable-font-lock)
3409 (if (cperl-val 'cperl-font-lock)
3410 (progn (or cperl-faces-init (cperl-init-faces))
3411 (font-lock-mode 1))))
3412 (set (make-local-variable 'facemenu-add-face-function)
3413 'cperl-facemenu-add-face-function) ; XXXX What this guy is for???
3414 (and (boundp 'msb-menu-cond)
3415 (not cperl-msb-fixed)
3416 (cperl-msb-fix))
3417 (if (featurep 'easymenu)
3418 (easy-menu-add cperl-menu)) ; A NOP in RMS Emacs.
3419 (run-hooks 'cperl-mode-hook)
3420 (if cperl-hook-after-change
3421 (progn
3422 (make-local-hook 'after-change-functions)
3423 (add-hook 'after-change-functions 'cperl-after-change-function nil t)))
3424 ;; After hooks since fontification will break this
3425 (if cperl-pod-here-scan
3426 (or cperl-syntaxify-by-font-lock
3427 (progn (or cperl-faces-init (cperl-init-faces-weak))
3428 (cperl-find-pods-heres)))))
3430 ;; Fix for perldb - make default reasonable
3431 (defun cperl-db ()
3432 (interactive)
3433 (require 'gud)
3434 (perldb (read-from-minibuffer "Run perldb (like this): "
3435 (if (consp gud-perldb-history)
3436 (car gud-perldb-history)
3437 (concat "perl " ;;(file-name-nondirectory
3438 ;; I have problems
3439 ;; in OS/2
3440 ;; otherwise
3441 (buffer-file-name)))
3442 nil nil
3443 '(gud-perldb-history . 1))))
3445 (defun cperl-msb-fix ()
3446 ;; Adds perl files to msb menu, supposes that msb is already loaded
3447 (setq cperl-msb-fixed t)
3448 (let* ((l (length msb-menu-cond))
3449 (last (nth (1- l) msb-menu-cond))
3450 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
3451 (handle (1- (nth 1 last))))
3452 (setcdr precdr (list
3453 (list
3454 '(memq major-mode '(cperl-mode perl-mode))
3455 handle
3456 "Perl Files (%d)")
3457 last))))
3459 ;; This is used by indent-for-comment
3460 ;; to decide how much to indent a comment in CPerl code
3461 ;; based on its context. Do fallback if comment is found wrong.
3463 (defvar cperl-wrong-comment)
3464 (defvar cperl-st-cfence '(14)) ; Comment-fence
3465 (defvar cperl-st-sfence '(15)) ; String-fence
3466 (defvar cperl-st-punct '(1))
3467 (defvar cperl-st-word '(2))
3468 (defvar cperl-st-bra '(4 . ?\>))
3469 (defvar cperl-st-ket '(5 . ?\<))
3472 (defun cperl-comment-indent ()
3473 (let ((p (point)) (c (current-column)) was phony)
3474 (if (looking-at "^#") 0 ; Existing comment at bol stays there.
3475 ;; Wrong comment found
3476 (save-excursion
3477 (setq was (cperl-to-comment-or-eol)
3478 phony (eq (get-text-property (point) 'syntax-table)
3479 cperl-st-cfence))
3480 (if phony
3481 (progn
3482 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
3483 (if (eq (preceding-char) ?\#)
3484 (forward-char -1))
3485 (setq was nil)))
3486 (if (= (point) p)
3487 (progn
3488 (skip-chars-backward " \t")
3489 (max (1+ (current-column)) ; Else indent at comment column
3490 comment-column))
3491 (if was nil
3492 (insert comment-start)
3493 (backward-char (length comment-start)))
3494 (setq cperl-wrong-comment t)
3495 (cperl-make-indent comment-column 1 'keep) ; Indent minimum 1
3496 c))))) ; except leave at least one space.
3498 ;;;(defun cperl-comment-indent-fallback ()
3499 ;;; "Is called if the standard comment-search procedure fails.
3500 ;;;Point is at start of real comment."
3501 ;;; (let ((c (current-column)) target cnt prevc)
3502 ;;; (if (= c comment-column) nil
3503 ;;; (setq cnt (skip-chars-backward "[ \t]"))
3504 ;;; (setq target (max (1+ (setq prevc
3505 ;;; (current-column))) ; Else indent at comment column
3506 ;;; comment-column))
3507 ;;; (if (= c comment-column) nil
3508 ;;; (delete-backward-char cnt)
3509 ;;; (while (< prevc target)
3510 ;;; (insert "\t")
3511 ;;; (setq prevc (current-column)))
3512 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
3513 ;;; (while (< prevc target)
3514 ;;; (insert " ")
3515 ;;; (setq prevc (current-column)))))))
3517 (defun cperl-indent-for-comment ()
3518 "Substitute for `indent-for-comment' in CPerl."
3519 (interactive)
3520 (let (cperl-wrong-comment)
3521 (indent-for-comment)
3522 (if cperl-wrong-comment ; set by `cperl-comment-indent'
3523 (progn (cperl-to-comment-or-eol)
3524 (forward-char (length comment-start))))))
3526 (defun cperl-comment-region (b e arg)
3527 "Comment or uncomment each line in the region in CPerl mode.
3528 See `comment-region'."
3529 (interactive "r\np")
3530 (let ((comment-start "#"))
3531 (comment-region b e arg)))
3533 (defun cperl-uncomment-region (b e arg)
3534 "Uncomment or comment each line in the region in CPerl mode.
3535 See `comment-region'."
3536 (interactive "r\np")
3537 (let ((comment-start "#"))
3538 (comment-region b e (- arg))))
3540 (defvar cperl-brace-recursing nil)
3542 (defun cperl-electric-brace (arg &optional only-before)
3543 "Insert character and correct line's indentation.
3544 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
3545 place (even in empty line), but not after. If after \")\" and the inserted
3546 char is \"{\", insert extra newline before only if
3547 `cperl-extra-newline-before-brace'."
3548 (interactive "P")
3549 (let (insertpos
3550 (other-end (if (and cperl-electric-parens-mark
3551 (cperl-mark-active)
3552 (< (mark) (point)))
3553 (mark)
3554 nil)))
3555 (if (and other-end
3556 (not cperl-brace-recursing)
3557 (cperl-val 'cperl-electric-parens)
3558 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
3559 ;; Need to insert a matching pair
3560 (progn
3561 (save-excursion
3562 (setq insertpos (point-marker))
3563 (goto-char other-end)
3564 (setq last-command-char ?\{)
3565 (cperl-electric-lbrace arg insertpos))
3566 (forward-char 1))
3567 ;; Check whether we close something "usual" with `}'
3568 (if (and (eq last-command-char ?\})
3569 (not
3570 (condition-case nil
3571 (save-excursion
3572 (up-list (- (prefix-numeric-value arg)))
3573 ;;(cperl-after-block-p (point-min))
3574 (or (cperl-after-expr-p nil "{;)")
3575 ;; after sub, else, continue
3576 (cperl-after-block-p nil 'pre)))
3577 (error nil))))
3578 ;; Just insert the guy
3579 (self-insert-command (prefix-numeric-value arg))
3580 (if (and (not arg) ; No args, end (of empty line or auto)
3581 (eolp)
3582 (or (and (null only-before)
3583 (save-excursion
3584 (skip-chars-backward " \t")
3585 (bolp)))
3586 (and (eq last-command-char ?\{) ; Do not insert newline
3587 ;; if after ")" and `cperl-extra-newline-before-brace'
3588 ;; is nil, do not insert extra newline.
3589 (not cperl-extra-newline-before-brace)
3590 (save-excursion
3591 (skip-chars-backward " \t")
3592 (eq (preceding-char) ?\))))
3593 (if cperl-auto-newline
3594 (progn (cperl-indent-line) (newline) t) nil)))
3595 (progn
3596 (self-insert-command (prefix-numeric-value arg))
3597 (cperl-indent-line)
3598 (if cperl-auto-newline
3599 (setq insertpos (1- (point))))
3600 (if (and cperl-auto-newline (null only-before))
3601 (progn
3602 (newline)
3603 (cperl-indent-line)))
3604 (save-excursion
3605 (if insertpos (progn (goto-char insertpos)
3606 (search-forward (make-string
3607 1 last-command-char))
3608 (setq insertpos (1- (point)))))
3609 (delete-char -1))))
3610 (if insertpos
3611 (save-excursion
3612 (goto-char insertpos)
3613 (self-insert-command (prefix-numeric-value arg)))
3614 (self-insert-command (prefix-numeric-value arg)))))))
3616 (defun cperl-electric-lbrace (arg &optional end)
3617 "Insert character, correct line's indentation, correct quoting by space."
3618 (interactive "P")
3619 (let ((cperl-brace-recursing t)
3620 (cperl-auto-newline cperl-auto-newline)
3621 (other-end (or end
3622 (if (and cperl-electric-parens-mark
3623 (cperl-mark-active)
3624 (> (mark) (point)))
3625 (save-excursion
3626 (goto-char (mark))
3627 (point-marker))
3628 nil)))
3629 pos after)
3630 (and (cperl-val 'cperl-electric-lbrace-space)
3631 (eq (preceding-char) ?$)
3632 (save-excursion
3633 (skip-chars-backward "$")
3634 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
3635 (insert ?\ ))
3636 ;; Check whether we are in comment
3637 (if (and
3638 (save-excursion
3639 (beginning-of-line)
3640 (not (looking-at "[ \t]*#")))
3641 (cperl-after-expr-p nil "{;)"))
3643 (setq cperl-auto-newline nil))
3644 (cperl-electric-brace arg)
3645 (and (cperl-val 'cperl-electric-parens)
3646 (eq last-command-char ?{)
3647 (memq last-command-char
3648 (append cperl-electric-parens-string nil))
3649 (or (if other-end (goto-char (marker-position other-end)))
3651 (setq last-command-char ?} pos (point))
3652 (progn (cperl-electric-brace arg t)
3653 (goto-char pos)))))
3655 (defun cperl-electric-paren (arg)
3656 "Insert an opening parenthesis or a matching pair of parentheses.
3657 See `cperl-electric-parens'."
3658 (interactive "P")
3659 (let ((beg (save-excursion (beginning-of-line) (point)))
3660 (other-end (if (and cperl-electric-parens-mark
3661 (cperl-mark-active)
3662 (> (mark) (point)))
3663 (save-excursion
3664 (goto-char (mark))
3665 (point-marker))
3666 nil)))
3667 (if (and (cperl-val 'cperl-electric-parens)
3668 (memq last-command-char
3669 (append cperl-electric-parens-string nil))
3670 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
3671 ;;(not (save-excursion (search-backward "#" beg t)))
3672 (if (eq last-command-char ?<)
3673 (progn
3674 (and abbrev-mode ; later it is too late, may be after `for'
3675 (expand-abbrev))
3676 (cperl-after-expr-p nil "{;(,:="))
3678 (progn
3679 (self-insert-command (prefix-numeric-value arg))
3680 (if other-end (goto-char (marker-position other-end)))
3681 (insert (make-string
3682 (prefix-numeric-value arg)
3683 (cdr (assoc last-command-char '((?{ .?})
3684 (?[ . ?])
3685 (?( . ?))
3686 (?< . ?>))))))
3687 (forward-char (- (prefix-numeric-value arg))))
3688 (self-insert-command (prefix-numeric-value arg)))))
3690 (defun cperl-electric-rparen (arg)
3691 "Insert a matching pair of parentheses if marking is active.
3692 If not, or if we are not at the end of marking range, would self-insert.
3693 Affected by `cperl-electric-parens'."
3694 (interactive "P")
3695 (let ((beg (save-excursion (beginning-of-line) (point)))
3696 (other-end (if (and cperl-electric-parens-mark
3697 (cperl-val 'cperl-electric-parens)
3698 (memq last-command-char
3699 (append cperl-electric-parens-string nil))
3700 (cperl-mark-active)
3701 (< (mark) (point)))
3702 (mark)
3703 nil))
3705 (if (and other-end
3706 (cperl-val 'cperl-electric-parens)
3707 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
3708 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
3709 ;;(not (save-excursion (search-backward "#" beg t)))
3711 (progn
3712 (self-insert-command (prefix-numeric-value arg))
3713 (setq p (point))
3714 (if other-end (goto-char other-end))
3715 (insert (make-string
3716 (prefix-numeric-value arg)
3717 (cdr (assoc last-command-char '((?\} . ?\{)
3718 (?\] . ?\[)
3719 (?\) . ?\()
3720 (?\> . ?\<))))))
3721 (goto-char (1+ p)))
3722 (self-insert-command (prefix-numeric-value arg)))))
3724 (defun cperl-electric-keyword ()
3725 "Insert a construction appropriate after a keyword.
3726 Help message may be switched off by setting `cperl-message-electric-keyword'
3727 to nil."
3728 (let ((beg (save-excursion (beginning-of-line) (point)))
3729 (dollar (and (eq last-command-char ?$)
3730 (eq this-command 'self-insert-command)))
3731 (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
3732 (memq this-command '(self-insert-command newline))))
3733 my do)
3734 (and (save-excursion
3735 (condition-case nil
3736 (progn
3737 (backward-sexp 1)
3738 (setq do (looking-at "do\\>")))
3739 (error nil))
3740 (cperl-after-expr-p nil "{;:"))
3741 (save-excursion
3742 (not
3743 (re-search-backward
3744 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
3745 beg t)))
3746 (save-excursion (or (not (re-search-backward "^=" nil t))
3748 (looking-at "=cut")
3749 (and cperl-use-syntax-table-text-property
3750 (not (eq (get-text-property (point)
3751 'syntax-type)
3752 'pod))))))
3753 (save-excursion (forward-sexp -1)
3754 (not (memq (following-char) (append "$@%&*" nil))))
3755 (progn
3756 (and (eq (preceding-char) ?y)
3757 (progn ; "foreachmy"
3758 (forward-char -2)
3759 (insert " ")
3760 (forward-char 2)
3761 (setq my t dollar t
3762 delete
3763 (memq this-command '(self-insert-command newline)))))
3764 (and dollar (insert " $"))
3765 (cperl-indent-line)
3766 ;;(insert " () {\n}")
3767 (cond
3768 (cperl-extra-newline-before-brace
3769 (insert (if do "\n" " ()\n"))
3770 (insert "{")
3771 (cperl-indent-line)
3772 (insert "\n")
3773 (cperl-indent-line)
3774 (insert "\n}")
3775 (and do (insert " while ();")))
3777 (insert (if do " {\n} while ();" " () {\n}"))))
3778 (or (looking-at "[ \t]\\|$") (insert " "))
3779 (cperl-indent-line)
3780 (if dollar (progn (search-backward "$")
3781 (if my
3782 (forward-char 1)
3783 (delete-char 1)))
3784 (search-backward ")")
3785 (if (eq last-command-char ?\()
3786 (progn ; Avoid "if (())"
3787 (delete-backward-char 1)
3788 (delete-backward-char -1))))
3789 (if delete
3790 (cperl-putback-char cperl-del-back-ch))
3791 (if cperl-message-electric-keyword
3792 (message "Precede char by C-q to avoid expansion"))))))
3794 (defun cperl-ensure-newlines (n &optional pos)
3795 "Make sure there are N newlines after the point."
3796 (or pos (setq pos (point)))
3797 (if (looking-at "\n")
3798 (forward-char 1)
3799 (insert "\n"))
3800 (if (> n 1)
3801 (cperl-ensure-newlines (1- n) pos)
3802 (goto-char pos)))
3804 (defun cperl-electric-pod ()
3805 "Insert a POD chunk appropriate after a =POD directive."
3806 (let ((delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
3807 (memq this-command '(self-insert-command newline))))
3808 head1 notlast name p really-delete over)
3809 (and (save-excursion
3810 (forward-word -1)
3811 (and
3812 (eq (preceding-char) ?=)
3813 (progn
3814 (setq head1 (looking-at "head1\\>[ \t]*$"))
3815 (setq over (and (looking-at "over\\>[ \t]*$")
3816 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
3817 (forward-char -1)
3818 (bolp))
3820 (get-text-property (point) 'in-pod)
3821 (cperl-after-expr-p nil "{;:")
3822 (and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t)
3823 (not (looking-at "\n*=cut"))
3824 (or (not cperl-use-syntax-table-text-property)
3825 (eq (get-text-property (point) 'syntax-type) 'pod))))))
3826 (progn
3827 (save-excursion
3828 (setq notlast (re-search-forward "^\n=" nil t)))
3829 (or notlast
3830 (progn
3831 (insert "\n\n=cut")
3832 (cperl-ensure-newlines 2)
3833 (forward-word -2)
3834 (if (and head1
3835 (not
3836 (save-excursion
3837 (forward-char -1)
3838 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
3839 nil t)))) ; Only one
3840 (progn
3841 (forward-word 1)
3842 (setq name (file-name-sans-extension
3843 (file-name-nondirectory (buffer-file-name)))
3844 p (point))
3845 (insert " NAME\n\n" name
3846 " - \n\n=head1 SYNOPSIS\n\n\n\n"
3847 "=head1 DESCRIPTION")
3848 (cperl-ensure-newlines 4)
3849 (goto-char p)
3850 (forward-word 2)
3851 (end-of-line)
3852 (setq really-delete t))
3853 (forward-word 1))))
3854 (if over
3855 (progn
3856 (setq p (point))
3857 (insert "\n\n=item \n\n\n\n"
3858 "=back")
3859 (cperl-ensure-newlines 2)
3860 (goto-char p)
3861 (forward-word 1)
3862 (end-of-line)
3863 (setq really-delete t)))
3864 (if (and delete really-delete)
3865 (cperl-putback-char cperl-del-back-ch))))))
3867 (defun cperl-electric-else ()
3868 "Insert a construction appropriate after a keyword.
3869 Help message may be switched off by setting `cperl-message-electric-keyword'
3870 to nil."
3871 (let ((beg (save-excursion (beginning-of-line) (point))))
3872 (and (save-excursion
3873 (backward-sexp 1)
3874 (cperl-after-expr-p nil "{;:"))
3875 (save-excursion
3876 (not
3877 (re-search-backward
3878 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
3879 beg t)))
3880 (save-excursion (or (not (re-search-backward "^=" nil t))
3881 (looking-at "=cut")
3882 (and cperl-use-syntax-table-text-property
3883 (not (eq (get-text-property (point)
3884 'syntax-type)
3885 'pod)))))
3886 (progn
3887 (cperl-indent-line)
3888 ;;(insert " {\n\n}")
3889 (cond
3890 (cperl-extra-newline-before-brace
3891 (insert "\n")
3892 (insert "{")
3893 (cperl-indent-line)
3894 (insert "\n\n}"))
3896 (insert " {\n\n}")))
3897 (or (looking-at "[ \t]\\|$") (insert " "))
3898 (cperl-indent-line)
3899 (forward-line -1)
3900 (cperl-indent-line)
3901 (cperl-putback-char cperl-del-back-ch)
3902 (setq this-command 'cperl-electric-else)
3903 (if cperl-message-electric-keyword
3904 (message "Precede char by C-q to avoid expansion"))))))
3906 (defun cperl-linefeed ()
3907 "Go to end of line, open a new line and indent appropriately.
3908 If in POD, insert appropriate lines."
3909 (interactive)
3910 (let ((beg (save-excursion (beginning-of-line) (point)))
3911 (end (save-excursion (end-of-line) (point)))
3912 (pos (point)) start over cut res)
3913 (if (and ; Check if we need to split:
3914 ; i.e., on a boundary and inside "{...}"
3915 (save-excursion (cperl-to-comment-or-eol)
3916 (>= (point) pos)) ; Not in a comment
3917 (or (save-excursion
3918 (skip-chars-backward " \t" beg)
3919 (forward-char -1)
3920 (looking-at "[;{]")) ; After { or ; + spaces
3921 (looking-at "[ \t]*}") ; Before }
3922 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
3923 (save-excursion
3924 (and
3925 (eq (car (parse-partial-sexp pos end -1)) -1)
3926 ; Leave the level of parens
3927 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
3928 ; Are at end
3929 (cperl-after-block-p (point-min))
3930 (progn
3931 (backward-sexp 1)
3932 (setq start (point-marker))
3933 (<= start pos))))) ; Redundant? Are after the
3934 ; start of parens group.
3935 (progn
3936 (skip-chars-backward " \t")
3937 (or (memq (preceding-char) (append ";{" nil))
3938 (insert ";"))
3939 (insert "\n")
3940 (forward-line -1)
3941 (cperl-indent-line)
3942 (goto-char start)
3943 (or (looking-at "{[ \t]*$") ; If there is a statement
3944 ; before, move it to separate line
3945 (progn
3946 (forward-char 1)
3947 (insert "\n")
3948 (cperl-indent-line)))
3949 (forward-line 1) ; We are on the target line
3950 (cperl-indent-line)
3951 (beginning-of-line)
3952 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
3953 ; after, move it to separate line
3954 (progn
3955 (end-of-line)
3956 (search-backward "}" beg)
3957 (skip-chars-backward " \t")
3958 (or (memq (preceding-char) (append ";{" nil))
3959 (insert ";"))
3960 (insert "\n")
3961 (cperl-indent-line)
3962 (forward-line -1)))
3963 (forward-line -1) ; We are on the line before target
3964 (end-of-line)
3965 (newline-and-indent))
3966 (end-of-line) ; else - no splitting
3967 (cond
3968 ((and (looking-at "\n[ \t]*{$")
3969 (save-excursion
3970 (skip-chars-backward " \t")
3971 (eq (preceding-char) ?\)))) ; Probably if () {} group
3972 ; with an extra newline.
3973 (forward-line 2)
3974 (cperl-indent-line))
3975 ((save-excursion ; In POD header
3976 (forward-paragraph -1)
3977 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
3978 ;; We are after \n now, so look for the rest
3979 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
3980 (progn
3981 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
3982 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
3983 t)))
3984 (if (and over
3985 (progn
3986 (forward-paragraph -1)
3987 (forward-word 1)
3988 (setq pos (point))
3989 (setq cut (buffer-substring (point)
3990 (save-excursion
3991 (end-of-line)
3992 (point))))
3993 (delete-char (- (save-excursion (end-of-line) (point))
3994 (point)))
3995 (setq res (expand-abbrev))
3996 (save-excursion
3997 (goto-char pos)
3998 (insert cut))
3999 res))
4001 (cperl-ensure-newlines (if cut 2 4))
4002 (forward-line 2)))
4003 ((get-text-property (point) 'in-pod) ; In POD section
4004 (cperl-ensure-newlines 4)
4005 (forward-line 2))
4006 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
4007 (forward-line 1)
4008 (cperl-indent-line))
4010 (newline-and-indent))))))
4012 (defun cperl-electric-semi (arg)
4013 "Insert character and correct line's indentation."
4014 (interactive "P")
4015 (if cperl-auto-newline
4016 (cperl-electric-terminator arg)
4017 (self-insert-command (prefix-numeric-value arg))
4018 (if cperl-autoindent-on-semi
4019 (cperl-indent-line))))
4021 (defun cperl-electric-terminator (arg)
4022 "Insert character and correct line's indentation."
4023 (interactive "P")
4024 (let ((end (point))
4025 (auto (and cperl-auto-newline
4026 (or (not (eq last-command-char ?:))
4027 cperl-auto-newline-after-colon)))
4028 insertpos)
4029 (if (and ;;(not arg)
4030 (eolp)
4031 (not (save-excursion
4032 (beginning-of-line)
4033 (skip-chars-forward " \t")
4035 ;; Ignore in comment lines
4036 (= (following-char) ?#)
4037 ;; Colon is special only after a label
4038 ;; So quickly rule out most other uses of colon
4039 ;; and do no indentation for them.
4040 (and (eq last-command-char ?:)
4041 (save-excursion
4042 (forward-word 1)
4043 (skip-chars-forward " \t")
4044 (and (< (point) end)
4045 (progn (goto-char (- end 1))
4046 (not (looking-at ":"))))))
4047 (progn
4048 (beginning-of-defun)
4049 (let ((pps (parse-partial-sexp (point) end)))
4050 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
4051 (progn
4052 (self-insert-command (prefix-numeric-value arg))
4053 ;;(forward-char -1)
4054 (if auto (setq insertpos (point-marker)))
4055 ;;(forward-char 1)
4056 (cperl-indent-line)
4057 (if auto
4058 (progn
4059 (newline)
4060 (cperl-indent-line)))
4061 (save-excursion
4062 (if insertpos (goto-char (1- (marker-position insertpos)))
4063 (forward-char -1))
4064 (delete-char 1))))
4065 (if insertpos
4066 (save-excursion
4067 (goto-char insertpos)
4068 (self-insert-command (prefix-numeric-value arg)))
4069 (self-insert-command (prefix-numeric-value arg)))))
4071 (defun cperl-electric-backspace (arg)
4072 "Backspace, or remove the whitespace around the point inserted by an electric
4073 key. Will untabivy if `cperl-electric-backspace-untabify' is non-nil."
4074 (interactive "p")
4075 (if (and cperl-auto-newline
4076 (memq last-command '(cperl-electric-semi
4077 cperl-electric-terminator
4078 cperl-electric-lbrace))
4079 (memq (preceding-char) '(?\ ?\t ?\n)))
4080 (let (p)
4081 (if (eq last-command 'cperl-electric-lbrace)
4082 (skip-chars-forward " \t\n"))
4083 (setq p (point))
4084 (skip-chars-backward " \t\n")
4085 (delete-region (point) p))
4086 (and (eq last-command 'cperl-electric-else)
4087 ;; We are removing the whitespace *inside* cperl-electric-else
4088 (setq this-command 'cperl-electric-else-really))
4089 (if (and cperl-auto-newline
4090 (eq last-command 'cperl-electric-else-really)
4091 (memq (preceding-char) '(?\ ?\t ?\n)))
4092 (let (p)
4093 (skip-chars-forward " \t\n")
4094 (setq p (point))
4095 (skip-chars-backward " \t\n")
4096 (delete-region (point) p))
4097 (if cperl-electric-backspace-untabify
4098 (backward-delete-char-untabify arg)
4099 (delete-backward-char arg)))))
4101 (defun cperl-inside-parens-p () ;; NOT USED????
4102 (condition-case ()
4103 (save-excursion
4104 (save-restriction
4105 (narrow-to-region (point)
4106 (progn (beginning-of-defun) (point)))
4107 (goto-char (point-max))
4108 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
4109 (error nil)))
4111 (defun cperl-indent-command (&optional whole-exp)
4112 "Indent current line as Perl code, or in some cases insert a tab character.
4113 If `cperl-tab-always-indent' is non-nil (the default), always indent current
4114 line. Otherwise, indent the current line only if point is at the left margin
4115 or in the line's indentation; otherwise insert a tab.
4117 A numeric argument, regardless of its value,
4118 means indent rigidly all the lines of the expression starting after point
4119 so that this line becomes properly indented.
4120 The relative indentation among the lines of the expression are preserved."
4121 (interactive "P")
4122 (cperl-update-syntaxification (point) (point))
4123 (if whole-exp
4124 ;; If arg, always indent this line as Perl
4125 ;; and shift remaining lines of expression the same amount.
4126 (let ((shift-amt (cperl-indent-line))
4127 beg end)
4128 (save-excursion
4129 (if cperl-tab-always-indent
4130 (beginning-of-line))
4131 (setq beg (point))
4132 (forward-sexp 1)
4133 (setq end (point))
4134 (goto-char beg)
4135 (forward-line 1)
4136 (setq beg (point)))
4137 (if (and shift-amt (> end beg))
4138 (indent-code-rigidly beg end shift-amt "#")))
4139 (if (and (not cperl-tab-always-indent)
4140 (save-excursion
4141 (skip-chars-backward " \t")
4142 (not (bolp))))
4143 (insert-tab)
4144 (cperl-indent-line))))
4146 (defun cperl-indent-line (&optional parse-data)
4147 "Indent current line as Perl code.
4148 Return the amount the indentation changed by."
4149 (let ((case-fold-search nil)
4150 (pos (- (point-max) (point)))
4151 indent i beg shift-amt)
4152 (setq indent (cperl-calculate-indent parse-data)
4153 i indent)
4154 (beginning-of-line)
4155 (setq beg (point))
4156 (cond ((or (eq indent nil) (eq indent t))
4157 (setq indent (current-indentation) i nil))
4158 ;;((eq indent t) ; Never?
4159 ;; (setq indent (cperl-calculate-indent-within-comment)))
4160 ;;((looking-at "[ \t]*#")
4161 ;; (setq indent 0))
4163 (skip-chars-forward " \t")
4164 (if (listp indent) (setq indent (car indent)))
4165 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
4166 (and (> indent 0)
4167 (setq indent (max cperl-min-label-indent
4168 (+ indent cperl-label-offset)))))
4169 ((= (following-char) ?})
4170 (setq indent (- indent cperl-indent-level)))
4171 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
4172 (setq indent (+ indent cperl-close-paren-offset)))
4173 ((= (following-char) ?{)
4174 (setq indent (+ indent cperl-brace-offset))))))
4175 (skip-chars-forward " \t")
4176 (setq shift-amt (and i (- indent (current-column))))
4177 (if (or (not shift-amt)
4178 (zerop shift-amt))
4179 (if (> (- (point-max) pos) (point))
4180 (goto-char (- (point-max) pos)))
4181 ;;;(delete-region beg (point))
4182 ;;;(indent-to indent)
4183 (cperl-make-indent indent)
4184 ;; If initial point was within line's indentation,
4185 ;; position after the indentation. Else stay at same point in text.
4186 (if (> (- (point-max) pos) (point))
4187 (goto-char (- (point-max) pos))))
4188 shift-amt))
4190 (defun cperl-after-label ()
4191 ;; Returns true if the point is after label. Does not do save-excursion.
4192 (and (eq (preceding-char) ?:)
4193 (memq (char-syntax (char-after (- (point) 2)))
4194 '(?w ?_))
4195 (progn
4196 (backward-sexp)
4197 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
4199 (defun cperl-get-state (&optional parse-start start-state)
4200 ;; returns list (START STATE DEPTH PRESTART),
4201 ;; START is a good place to start parsing, or equal to
4202 ;; PARSE-START if preset,
4203 ;; STATE is what is returned by `parse-partial-sexp'.
4204 ;; DEPTH is true is we are immediately after end of block
4205 ;; which contains START.
4206 ;; PRESTART is the position basing on which START was found.
4207 (save-excursion
4208 (let ((start-point (point)) depth state start prestart)
4209 (if (and parse-start
4210 (<= parse-start start-point))
4211 (goto-char parse-start)
4212 (beginning-of-defun)
4213 (setq start-state nil))
4214 (setq prestart (point))
4215 (if start-state nil
4216 ;; Try to go out, if sub is not on the outermost level
4217 (while (< (point) start-point)
4218 (setq start (point) parse-start start depth nil
4219 state (parse-partial-sexp start start-point -1))
4220 (if (> (car state) -1) nil
4221 ;; The current line could start like }}}, so the indentation
4222 ;; corresponds to a different level than what we reached
4223 (setq depth t)
4224 (beginning-of-line 2))) ; Go to the next line.
4225 (if start (goto-char start))) ; Not at the start of file
4226 (setq start (point))
4227 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
4228 (list start state depth prestart))))
4230 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
4232 (defun cperl-beginning-of-property (p prop &optional lim)
4233 "Given that P has a property PROP, find where the property starts.
4234 Will not look before LIM."
4235 ;;; XXXX What to do at point-max???
4236 (or (previous-single-property-change (cperl-1+ p) prop lim)
4237 (point-min))
4238 ;;; (cond ((eq p (point-min))
4239 ;;; p)
4240 ;;; ((and lim (<= p lim))
4241 ;;; p)
4242 ;;; ((not (get-text-property (1- p) prop))
4243 ;;; p)
4244 ;;; (t (or (previous-single-property-change p look-prop lim)
4245 ;;; (point-min))))
4248 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
4249 "Return appropriate indentation for current line as Perl code.
4250 In usual case returns an integer: the column to indent to.
4251 Returns nil if line starts inside a string, t if in a comment.
4253 Will not correct the indentation for labels, but will correct it for braces
4254 and closing parentheses and brackets."
4255 (cperl-update-syntaxification (point) (point))
4256 (save-excursion
4257 (if (or
4258 (and (memq (get-text-property (point) 'syntax-type)
4259 '(pod here-doc here-doc-delim format))
4260 (not (get-text-property (point) 'indentable)))
4261 ;; before start of POD - whitespace found since do not have 'pod!
4262 (and (looking-at "[ \t]*\n=")
4263 (error "Spaces before POD section!"))
4264 (and (not cperl-indent-left-aligned-comments)
4265 (looking-at "^#")))
4267 (beginning-of-line)
4268 (let* ((indent-point (point))
4269 (char-after-pos (save-excursion
4270 (skip-chars-forward " \t")
4271 (point)))
4272 (char-after (char-after char-after-pos))
4273 (in-pod (get-text-property (point) 'in-pod))
4274 (pre-indent-point (point))
4275 p prop look-prop is-block delim)
4276 (cond
4277 (in-pod
4278 ;; In the verbatim part, probably code example. What to do???
4281 (save-excursion
4282 ;; Not in POD
4283 (cperl-backward-to-noncomment nil)
4284 (setq p (max (point-min) (1- (point)))
4285 prop (get-text-property p 'syntax-type)
4286 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
4287 'syntax-type))
4288 (if (memq prop '(pod here-doc format here-doc-delim))
4289 (progn
4290 (goto-char (cperl-beginning-of-property p look-prop))
4291 (beginning-of-line)
4292 (setq pre-indent-point (point)))))))
4293 (goto-char pre-indent-point)
4294 (let* ((case-fold-search nil)
4295 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
4296 (start (or (nth 2 parse-data)
4297 (nth 0 s-s)))
4298 (state (nth 1 s-s))
4299 (containing-sexp (car (cdr state)))
4300 old-indent)
4301 (if (and
4302 ;;containing-sexp ;; We are buggy at toplevel :-(
4303 parse-data)
4304 (progn
4305 (setcar parse-data pre-indent-point)
4306 (setcar (cdr parse-data) state)
4307 (or (nth 2 parse-data)
4308 (setcar (cddr parse-data) start))
4309 ;; Before this point: end of statement
4310 (setq old-indent (nth 3 parse-data))))
4311 (cond ((get-text-property (point) 'indentable)
4312 ;; indent to "after" the surrounding open
4313 ;; (same offset as `cperl-beautify-regexp-piece'),
4314 ;; skip blanks if we do not close the expression.
4315 (setq delim ; We do not close the expression
4316 (get-text-property
4317 (cperl-1+ char-after-pos) 'indentable)
4318 p (1+ (cperl-beginning-of-property
4319 (point) 'indentable))
4320 is-block ; misused for: preceeding line in REx
4321 (save-excursion ; Find preceeding line
4322 (cperl-backward-to-noncomment p)
4323 (beginning-of-line)
4324 (if (<= (point) p)
4325 (progn ; get indent from the first line
4326 (goto-char p)
4327 (skip-chars-forward " \t")
4328 (if (memq (char-after (point))
4329 (append "#\n" nil))
4330 nil ; Can't use intentation of this line...
4331 (point)))
4332 (skip-chars-forward " \t")
4333 (point)))
4334 prop (parse-partial-sexp p char-after-pos))
4335 (cond ((not delim)
4336 (goto-char p) ; beginning of REx etc
4337 (1- (current-column))) ; End the REx, ignore is-block
4338 (is-block
4339 ;; Indent as the level after closing parens
4340 (goto-char char-after-pos)
4341 (skip-chars-forward " \t)")
4342 (setq char-after-pos (point))
4343 (goto-char is-block)
4344 (skip-chars-forward " \t)")
4345 (setq p (parse-partial-sexp (point) char-after-pos))
4346 (goto-char is-block)
4347 (+ (* (nth 0 p)
4348 (or cperl-regexp-indent-step cperl-indent-level))
4349 (cond ((eq char-after ?\) )
4350 (- cperl-close-paren-offset)) ; compensate
4351 ((eq char-after ?\| )
4352 (- (or cperl-regexp-indent-step cperl-indent-level)))
4353 (t 0))
4354 (if (eq (following-char) ?\| )
4355 (or cperl-regexp-indent-step cperl-indent-level)
4357 (current-column)))
4358 ;; Now we have no preceeding line...
4360 (goto-char p)
4361 (+ (or cperl-regexp-indent-step cperl-indent-level)
4363 (current-column)))))
4364 ((get-text-property char-after-pos 'REx-part2)
4365 (condition-case nil ; Use indentation of the 1st part
4366 (forward-sexp -1))
4367 (current-column))
4368 ((or (nth 3 state) (nth 4 state))
4369 ;; return nil or t if should not change this line
4370 (nth 4 state))
4371 ;; XXXX Do we need to special-case this?
4372 ((null containing-sexp)
4373 ;; Line is at top level. May be data or function definition,
4374 ;; or may be function argument declaration.
4375 ;; Indent like the previous top level line
4376 ;; unless that ends in a closeparen without semicolon,
4377 ;; in which case this line is the first argument decl.
4378 (skip-chars-forward " \t")
4379 (+ (save-excursion
4380 (goto-char start)
4381 (- (current-indentation)
4382 (if (nth 2 s-s) cperl-indent-level 0)))
4383 (if (eq char-after ?{) cperl-continued-brace-offset 0)
4384 (progn
4385 (cperl-backward-to-noncomment (or old-indent (point-min)))
4386 ;; Look at previous line that's at column 0
4387 ;; to determine whether we are in top-level decls
4388 ;; or function's arg decls. Set basic-indent accordingly.
4389 ;; Now add a little if this is a continuation line.
4390 (if (or (bobp)
4391 (eq (point) old-indent) ; old-indent was at comment
4392 (eq (preceding-char) ?\;)
4393 ;; Had ?\) too
4394 (and (eq (preceding-char) ?\})
4395 (cperl-after-block-and-statement-beg
4396 (point-min))) ; Was start - too close
4397 (memq char-after (append ")]}" nil))
4398 (and (eq (preceding-char) ?\:) ; label
4399 (progn
4400 (forward-sexp -1)
4401 (skip-chars-backward " \t")
4402 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
4403 (get-text-property (point) 'first-format-line))
4404 (progn
4405 (if (and parse-data
4406 (not (eq char-after ?\C-j)))
4407 (setcdr (cddr parse-data)
4408 (list pre-indent-point)))
4410 cperl-continued-statement-offset))))
4411 ((not
4412 (or (setq is-block
4413 (and (setq delim (= (char-after containing-sexp) ?{))
4414 (save-excursion ; Is it a hash?
4415 (goto-char containing-sexp)
4416 (cperl-block-p))))
4417 cperl-indent-parens-as-block))
4418 ;; group is an expression, not a block:
4419 ;; indent to just after the surrounding open parens,
4420 ;; skip blanks if we do not close the expression.
4421 (goto-char (1+ containing-sexp))
4422 (or (memq char-after
4423 (append (if delim "}" ")]}") nil))
4424 (looking-at "[ \t]*\\(#\\|$\\)")
4425 (skip-chars-forward " \t"))
4426 (+ (current-column)
4427 (if (and delim
4428 (eq char-after ?\}))
4429 ;; Correct indentation of trailing ?\}
4430 (+ cperl-indent-level cperl-close-paren-offset)
4431 0)))
4432 ;;; ((and (/= (char-after containing-sexp) ?{)
4433 ;;; (not cperl-indent-parens-as-block))
4434 ;;; ;; line is expression, not statement:
4435 ;;; ;; indent to just after the surrounding open,
4436 ;;; ;; skip blanks if we do not close the expression.
4437 ;;; (goto-char (1+ containing-sexp))
4438 ;;; (or (memq char-after (append ")]}" nil))
4439 ;;; (looking-at "[ \t]*\\(#\\|$\\)")
4440 ;;; (skip-chars-forward " \t"))
4441 ;;; (current-column))
4442 ;;; ((progn
4443 ;;; ;; Containing-expr starts with \{. Check whether it is a hash.
4444 ;;; (goto-char containing-sexp)
4445 ;;; (and (not (cperl-block-p))
4446 ;;; (not cperl-indent-parens-as-block)))
4447 ;;; (goto-char (1+ containing-sexp))
4448 ;;; (or (eq char-after ?\})
4449 ;;; (looking-at "[ \t]*\\(#\\|$\\)")
4450 ;;; (skip-chars-forward " \t"))
4451 ;;; (+ (current-column) ; Correct indentation of trailing ?\}
4452 ;;; (if (eq char-after ?\}) (+ cperl-indent-level
4453 ;;; cperl-close-paren-offset)
4454 ;;; 0)))
4456 ;; Statement level. Is it a continuation or a new statement?
4457 ;; Find previous non-comment character.
4458 (goto-char pre-indent-point)
4459 (cperl-backward-to-noncomment containing-sexp)
4460 ;; Back up over label lines, since they don't
4461 ;; affect whether our line is a continuation.
4462 ;; (Had \, too)
4463 (while;;(or (eq (preceding-char) ?\,)
4464 (and (eq (preceding-char) ?:)
4465 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
4466 (memq (char-syntax (char-after (- (point) 2)))
4467 '(?w ?_))))
4469 (if (eq (preceding-char) ?\,)
4470 ;; Will go to beginning of line, essentially.
4471 ;; Will ignore embedded sexpr XXXX.
4472 (cperl-backward-to-start-of-continued-exp containing-sexp))
4473 (beginning-of-line)
4474 (cperl-backward-to-noncomment containing-sexp))
4475 ;; Now we get the answer.
4476 (if (not (or (eq (1- (point)) containing-sexp)
4477 (memq (preceding-char)
4478 (append (if is-block " ;{" " ,;{") '(nil)))
4479 (and (eq (preceding-char) ?\})
4480 (cperl-after-block-and-statement-beg
4481 containing-sexp))
4482 (get-text-property (point) 'first-format-line)))
4483 ;; This line is continuation of preceding line's statement;
4484 ;; indent `cperl-continued-statement-offset' more than the
4485 ;; previous line of the statement.
4487 ;; There might be a label on this line, just
4488 ;; consider it bad style and ignore it.
4489 (progn
4490 (cperl-backward-to-start-of-continued-exp containing-sexp)
4491 (+ (if (memq char-after (append "}])" nil))
4492 0 ; Closing parenth
4493 cperl-continued-statement-offset)
4494 (if (or is-block
4495 (not delim)
4496 (not (eq char-after ?\})))
4498 ;; Now it is a hash reference
4499 (+ cperl-indent-level cperl-close-paren-offset))
4500 ;; Labels do not take :: ...
4501 (if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
4502 (if (> (current-indentation) cperl-min-label-indent)
4503 (- (current-indentation) cperl-label-offset)
4504 ;; Do not move `parse-data', this should
4505 ;; be quick anyway (this comment comes
4506 ;; from different location):
4507 (cperl-calculate-indent))
4508 (current-column))
4509 (if (eq char-after ?\{)
4510 cperl-continued-brace-offset 0)))
4511 ;; This line starts a new statement.
4512 ;; Position following last unclosed open.
4513 (goto-char containing-sexp)
4514 ;; Is line first statement after an open-brace?
4516 ;; If no, find that first statement and indent like
4517 ;; it. If the first statement begins with label, do
4518 ;; not believe when the indentation of the label is too
4519 ;; small.
4520 (save-excursion
4521 (forward-char 1)
4522 (setq old-indent (current-indentation))
4523 (let ((colon-line-end 0))
4524 (while
4525 (progn (skip-chars-forward " \t\n")
4526 (and (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]\\|=[a-zA-Z]")
4527 (not (looking-at "$:")))) ; perl6: don't misinterpret $:foo as label; todo: correct in P5? Else use-v6'ify!
4528 ;; Skip over comments and labels following openbrace.
4529 (cond ((= (following-char) ?\#)
4530 (forward-line 1))
4531 ((= (following-char) ?\=)
4532 (goto-char
4533 (or (next-single-property-change (point) 'in-pod)
4534 (point-max)))) ; do not loop if no syntaxification
4535 ;; label:
4537 (save-excursion (end-of-line)
4538 (setq colon-line-end (point)))
4539 (search-forward ":"))))
4540 ;; The first following code counts
4541 ;; if it is before the line we want to indent.
4542 (and (< (point) indent-point)
4543 (if (> colon-line-end (point)) ; After label
4544 (if (> (current-indentation)
4545 cperl-min-label-indent)
4546 (- (current-indentation) cperl-label-offset)
4547 ;; Do not believe: `max' is involved
4548 (+ old-indent cperl-indent-level))
4549 (current-column)))))
4550 ;; If no previous statement,
4551 ;; indent it relative to line brace is on.
4552 ;; For open brace in column zero, don't let statement
4553 ;; start there too. If cperl-indent-level is zero,
4554 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
4555 ;; For open-braces not the first thing in a line,
4556 ;; add in cperl-brace-imaginary-offset.
4558 ;; If first thing on a line: ?????
4559 (+ (if (and (bolp) (zerop cperl-indent-level))
4560 (+ cperl-brace-offset cperl-continued-statement-offset)
4561 cperl-indent-level)
4562 (if (or is-block
4563 (not delim)
4564 (not (eq char-after ?\})))
4566 ;; Now it is a hash reference
4567 (+ cperl-indent-level cperl-close-paren-offset))
4568 ;; Move back over whitespace before the openbrace.
4569 ;; If openbrace is not first nonwhite thing on the line,
4570 ;; add the cperl-brace-imaginary-offset.
4571 (progn (skip-chars-backward " \t")
4572 (if (bolp) 0 cperl-brace-imaginary-offset))
4573 ;; If the openbrace is preceded by a parenthesized exp,
4574 ;; move to the beginning of that;
4575 ;; possibly a different line
4576 (progn
4577 (cperl-backward-to-noncomment (point-min))
4578 (if (eq (preceding-char) ?\))
4579 (forward-sexp -1))
4580 ;; In the case it starts a subroutine, indent with
4581 ;; respect to `sub', not with respect to the
4582 ;; first thing on the line, say in the case of
4583 ;; anonymous sub in a hash.
4585 ;;(skip-chars-backward " \t")
4586 (cperl-backward-to-noncomment (point-min))
4587 (if (and
4589 (and (get-text-property (point) 'attrib-group)
4590 (goto-char
4591 (cperl-beginning-of-property
4592 (point) 'attrib-group)))
4593 (and (eq (preceding-char) ?b)
4594 (progn
4595 (forward-sexp -1)
4596 (looking-at "\\(coro\\|sub\\|method\\|submethod\\)\\>")))) ; perl6
4597 (setq old-indent
4598 (nth 1
4599 (parse-partial-sexp
4600 (save-excursion (beginning-of-line) (point))
4601 (point)))))
4602 (progn (goto-char (1+ old-indent))
4603 (skip-chars-forward " \t")
4604 (current-column))
4605 ;; Get initial indentation of the line we are on.
4606 ;; If line starts with label, calculate label indentation
4607 (if (save-excursion
4608 (beginning-of-line)
4609 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
4610 (if (> (current-indentation) cperl-min-label-indent)
4611 (- (current-indentation) cperl-label-offset)
4612 ;; Do not move `parse-data', this should
4613 ;; be quick anyway:
4614 (cperl-calculate-indent))
4615 (current-indentation))))))))))))))
4617 (defvar cperl-indent-alist
4618 '((string nil)
4619 (comment nil)
4620 (toplevel 0)
4621 (toplevel-after-parenth 2)
4622 (toplevel-continued 2)
4623 (expression 1))
4624 "Alist of indentation rules for CPerl mode.
4625 The values mean:
4626 nil: do not indent;
4627 number: add this amount of indentation.
4629 Not finished, not used.")
4631 (defun cperl-where-am-i (&optional parse-start start-state)
4632 ;; Unfinished
4633 "Return a list of lists ((TYPE POS)...) of good points before the point.
4634 POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'.
4636 Not finished, not used."
4637 (save-excursion
4638 (let* ((start-point (point)) unused
4639 (s-s (cperl-get-state))
4640 (start (nth 0 s-s))
4641 (state (nth 1 s-s))
4642 (prestart (nth 3 s-s))
4643 (containing-sexp (car (cdr state)))
4644 (case-fold-search nil)
4645 (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
4646 (cond ((nth 3 state) ; In string
4647 (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
4648 ((nth 4 state) ; In comment
4649 (setq res (cons '(comment) res)))
4650 ((null containing-sexp)
4651 ;; Line is at top level.
4652 ;; Indent like the previous top level line
4653 ;; unless that ends in a closeparen without semicolon,
4654 ;; in which case this line is the first argument decl.
4655 (cperl-backward-to-noncomment (or parse-start (point-min)))
4656 ;;(skip-chars-backward " \t\f\n")
4657 (cond
4658 ((or (bobp)
4659 (memq (preceding-char) (append ";}" nil)))
4660 (setq res (cons (list 'toplevel start) res)))
4661 ((eq (preceding-char) ?\) )
4662 (setq res (cons (list 'toplevel-after-parenth start) res)))
4664 (setq res (cons (list 'toplevel-continued start) res)))))
4665 ((/= (char-after containing-sexp) ?{)
4666 ;; line is expression, not statement:
4667 ;; indent to just after the surrounding open.
4668 ;; skip blanks if we do not close the expression.
4669 (setq res (cons (list 'expression-blanks
4670 (progn
4671 (goto-char (1+ containing-sexp))
4672 (or (looking-at "[ \t]*\\(#\\|$\\)")
4673 (skip-chars-forward " \t"))
4674 (point)))
4675 (cons (list 'expression containing-sexp) res))))
4676 ((progn
4677 ;; Containing-expr starts with \{. Check whether it is a hash.
4678 (goto-char containing-sexp)
4679 (not (cperl-block-p)))
4680 (setq res (cons (list 'expression-blanks
4681 (progn
4682 (goto-char (1+ containing-sexp))
4683 (or (looking-at "[ \t]*\\(#\\|$\\)")
4684 (skip-chars-forward " \t"))
4685 (point)))
4686 (cons (list 'expression containing-sexp) res))))
4688 ;; Statement level.
4689 (setq res (cons (list 'in-block containing-sexp) res))
4690 ;; Is it a continuation or a new statement?
4691 ;; Find previous non-comment character.
4692 (cperl-backward-to-noncomment containing-sexp)
4693 ;; Back up over label lines, since they don't
4694 ;; affect whether our line is a continuation.
4695 ;; Back up comma-delimited lines too ?????
4696 (while (or (eq (preceding-char) ?\,)
4697 (save-excursion (cperl-after-label)))
4698 (if (eq (preceding-char) ?\,)
4699 ;; Will go to beginning of line, essentially
4700 ;; Will ignore embedded sexpr XXXX.
4701 (cperl-backward-to-start-of-continued-exp containing-sexp))
4702 (beginning-of-line)
4703 (cperl-backward-to-noncomment containing-sexp))
4704 ;; Now we get the answer.
4705 (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
4706 ;; This line is continuation of preceding line's statement.
4707 (list (list 'statement-continued containing-sexp))
4708 ;; This line starts a new statement.
4709 ;; Position following last unclosed open.
4710 (goto-char containing-sexp)
4711 ;; Is line first statement after an open-brace?
4713 ;; If no, find that first statement and indent like
4714 ;; it. If the first statement begins with label, do
4715 ;; not believe when the indentation of the label is too
4716 ;; small.
4717 (save-excursion
4718 (forward-char 1)
4719 (let ((colon-line-end 0))
4720 (while (progn (skip-chars-forward " \t\n" start-point)
4721 (and (< (point) start-point)
4722 (looking-at
4723 "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
4724 ;; Skip over comments and labels following openbrace.
4725 (cond ((= (following-char) ?\#)
4726 ;;(forward-line 1)
4727 (end-of-line))
4728 ;; label:
4730 (save-excursion (end-of-line)
4731 (setq colon-line-end (point)))
4732 (search-forward ":"))))
4733 ;; Now at the point, after label, or at start
4734 ;; of first statement in the block.
4735 (and (< (point) start-point)
4736 (if (> colon-line-end (point))
4737 ;; Before statement after label
4738 (if (> (current-indentation)
4739 cperl-min-label-indent)
4740 (list (list 'label-in-block (point)))
4741 ;; Do not believe: `max' is involved
4742 (list
4743 (list 'label-in-block-min-indent (point))))
4744 ;; Before statement
4745 (list 'statement-in-block (point))))))
4746 ;; If no previous statement,
4747 ;; indent it relative to line brace is on.
4748 ;; For open brace in column zero, don't let statement
4749 ;; start there too. If cperl-indent-level is zero,
4750 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
4751 ;; For open-braces not the first thing in a line,
4752 ;; add in cperl-brace-imaginary-offset.
4754 ;; If first thing on a line: ?????
4755 (setq unused ; This is not finished...
4756 (+ (if (and (bolp) (zerop cperl-indent-level))
4757 (+ cperl-brace-offset cperl-continued-statement-offset)
4758 cperl-indent-level)
4759 ;; Move back over whitespace before the openbrace.
4760 ;; If openbrace is not first nonwhite thing on the line,
4761 ;; add the cperl-brace-imaginary-offset.
4762 (progn (skip-chars-backward " \t")
4763 (if (bolp) 0 cperl-brace-imaginary-offset))
4764 ;; If the openbrace is preceded by a parenthesized exp,
4765 ;; move to the beginning of that;
4766 ;; possibly a different line
4767 (progn
4768 (if (eq (preceding-char) ?\))
4769 (forward-sexp -1))
4770 ;; Get initial indentation of the line we are on.
4771 ;; If line starts with label, calculate label indentation
4772 (if (save-excursion
4773 (beginning-of-line)
4774 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
4775 (if (> (current-indentation) cperl-min-label-indent)
4776 (- (current-indentation) cperl-label-offset)
4777 (cperl-calculate-indent))
4778 (current-indentation)))))))))
4779 res)))
4781 (defun cperl-calculate-indent-within-comment ()
4782 "Return the indentation amount for line, assuming that
4783 the current line is to be regarded as part of a block comment."
4784 (let (end star-start)
4785 (save-excursion
4786 (beginning-of-line)
4787 (skip-chars-forward " \t")
4788 (setq end (point))
4789 (and (= (following-char) ?#)
4790 (forward-line -1)
4791 (cperl-to-comment-or-eol)
4792 (setq end (point)))
4793 (goto-char end)
4794 (current-column))))
4797 (defun cperl-to-comment-or-eol ()
4798 "Go to position before comment on the current line, or to end of line.
4799 Returns true if comment is found. In POD will not move the point."
4800 ;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
4801 ;; then looks for literal # or end-of-line.
4802 (let (state stop-in cpoint (lim (progn (end-of-line) (point))) pr e)
4803 (or cperl-font-locking
4804 (cperl-update-syntaxification lim lim))
4805 (beginning-of-line)
4806 (if (setq pr (get-text-property (point) 'syntax-type))
4807 (setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
4808 (if (or (eq pr 'pod)
4809 (if (or (not e) (> e lim)) ; deep inside a group
4810 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
4811 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
4812 ;; Else - need to do it the hard way
4813 (and (and e (<= e lim))
4814 (goto-char e))
4815 (while (not stop-in)
4816 (setq state (parse-partial-sexp (point) lim nil nil nil t))
4817 ; stop at comment
4818 ;; If fails (beginning-of-line inside sexp), then contains not-comment
4819 (if (nth 4 state) ; After `#';
4820 ; (nth 2 state) can be
4821 ; beginning of m,s,qq and so
4822 ; on
4823 (if (nth 2 state)
4824 (progn
4825 (setq cpoint (point))
4826 (goto-char (nth 2 state))
4827 (cond
4828 ((looking-at "\\(s\\|tr\\)\\>")
4829 (or (re-search-forward
4830 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
4831 lim 'move)
4832 (setq stop-in t)))
4833 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
4834 (or (re-search-forward
4835 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
4836 lim 'move)
4837 (setq stop-in t)))
4838 (t ; It was fair comment
4839 (setq stop-in t) ; Finish
4840 (goto-char (1- cpoint)))))
4841 (setq stop-in t) ; Finish
4842 (forward-char -1))
4843 (setq stop-in t))) ; Finish
4844 (nth 4 state))))
4846 (defsubst cperl-modify-syntax-type (at how)
4847 (if (< at (point-max))
4848 (progn
4849 (put-text-property at (1+ at) 'syntax-table how)
4850 (put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
4852 (defun cperl-protect-defun-start (s e)
4853 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
4854 (save-excursion
4855 (goto-char s)
4856 (while (re-search-forward "^\\s(" e 'to-end)
4857 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
4859 (defun cperl-commentify (bb e string &optional noface)
4860 (if cperl-use-syntax-table-text-property
4861 (if (eq noface 'n) ; Only immediate
4863 ;; We suppose that e is _after_ the end of construction, as after eol.
4864 (setq string (if string cperl-st-sfence cperl-st-cfence))
4865 (if (> bb (- e 2))
4866 ;; one-char string/comment?!
4867 (cperl-modify-syntax-type bb cperl-st-punct)
4868 (cperl-modify-syntax-type bb string)
4869 (cperl-modify-syntax-type (1- e) string))
4870 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
4871 (put-text-property (1+ bb) (1- e)
4872 'syntax-table cperl-string-syntax-table))
4873 (cperl-protect-defun-start bb e))
4874 ;; Fontify
4875 (or noface
4876 (not cperl-pod-here-fontify)
4877 (put-text-property bb e 'face (if string 'font-lock-string-face
4878 'font-lock-comment-face)))))
4880 (defvar cperl-starters '(( ?\( . ?\) )
4881 ( ?\[ . ?\] )
4882 ( ?\{ . ?\} )
4883 ( ?\< . ?\> )))
4885 (defun cperl-cached-syntax-table (st)
4886 "Get a syntax table cached in ST, or create and cache into ST a syntax table.
4887 All the entries of the syntax table are \".\", except for a backslash, which
4888 is quoting."
4889 (if (car-safe st)
4890 (car st)
4891 (setcar st (make-syntax-table))
4892 (setq st (car st))
4893 (let ((i 0))
4894 (while (< i 256)
4895 (modify-syntax-entry i "." st)
4896 (setq i (1+ i))))
4897 (modify-syntax-entry ?\\ "\\" st)
4898 st))
4900 (defun cperl-forward-re (lim end is-2arg st-l err-l argument
4901 &optional ostart oend)
4902 "Find the end of a regular expression or a stringish construct (q[] etc).
4903 The point should be before the starting delimiter.
4905 Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
4906 is s/// or tr/// like expression. If END is nil, generates an error
4907 message if needed. If SET-ST is non-nil, will use (or generate) a
4908 cached syntax table in ST-L. If ERR-L is non-nil, will store the
4909 error message in its CAR (unless it already contains some error
4910 message). ARGUMENT should be the name of the construct (used in error
4911 messages). OSTART, OEND may be set in recursive calls when processing
4912 the second argument of 2ARG construct.
4914 Works *before* syntax recognition is done. In IS-2ARG situation may
4915 modify syntax-type text property if the situation is too hard."
4916 (let (b starter ender st i i2 go-forward reset-st set-st)
4917 (skip-chars-forward " \t")
4918 ;; ender means matching-char matcher.
4919 (setq b (point)
4920 starter (if (eobp) 0 (char-after b))
4921 ender (cdr (assoc starter cperl-starters)))
4922 ;; What if starter == ?\\ ????
4923 (setq st (cperl-cached-syntax-table st-l))
4924 (setq set-st t)
4925 ;; Whether we have an intermediate point
4926 (setq i nil)
4927 ;; Prepare the syntax table:
4928 (if (not ender) ; m/blah/, s/x//, s/x/y/
4929 (modify-syntax-entry starter "$" st)
4930 (modify-syntax-entry starter (concat "(" (list ender)) st)
4931 (modify-syntax-entry ender (concat ")" (list starter)) st))
4932 (condition-case bb
4933 (progn
4934 ;; We use `$' syntax class to find matching stuff, but $$
4935 ;; is recognized the same as $, so we need to check this manually.
4936 (if (and (eq starter (char-after (cperl-1+ b)))
4937 (not ender))
4938 ;; $ has TeXish matching rules, so $$ equiv $...
4939 (forward-char 2)
4940 (setq reset-st (syntax-table))
4941 (set-syntax-table st)
4942 (forward-sexp 1)
4943 (if (<= (point) (1+ b))
4944 (error "Unfinished regular expression"))
4945 (set-syntax-table reset-st)
4946 (setq reset-st nil)
4947 ;; Now the problem is with m;blah;;
4948 (and (not ender)
4949 (eq (preceding-char)
4950 (char-after (- (point) 2)))
4951 (save-excursion
4952 (forward-char -2)
4953 (= 0 (% (skip-chars-backward "\\\\") 2)))
4954 (forward-char -1)))
4955 ;; Now we are after the first part.
4956 (and is-2arg ; Have trailing part
4957 (not ender)
4958 (eq (following-char) starter) ; Empty trailing part
4959 (progn
4960 (or (eq (char-syntax (following-char)) ?.)
4961 ;; Make trailing letter into punctuation
4962 (cperl-modify-syntax-type (point) cperl-st-punct))
4963 (setq is-2arg nil go-forward t))) ; Ignore the tail
4964 (if is-2arg ; Not number => have second part
4965 (progn
4966 (setq i (point) i2 i)
4967 (if ender
4968 (if (memq (following-char) '(?\ ?\t ?\n ?\f))
4969 (progn
4970 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4971 (goto-char (match-end 0))
4972 (skip-chars-forward " \t\n\f"))
4973 (setq i2 (point))))
4974 (forward-char -1))
4975 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
4976 (if ender (modify-syntax-entry ender "." st))
4977 (setq set-st nil)
4978 (setq ender (cperl-forward-re lim end nil st-l err-l
4979 argument starter ender)
4980 ender (nth 2 ender)))))
4981 (error (goto-char lim)
4982 (setq set-st nil)
4983 (if reset-st
4984 (set-syntax-table reset-st))
4985 (or end
4986 (message
4987 "End of `%s%s%c ... %c' string/RE not found: %s"
4988 argument
4989 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
4990 starter (or ender starter) bb)
4991 (or (car err-l) (setcar err-l b)))))
4992 (if set-st
4993 (progn
4994 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
4995 (if ender (modify-syntax-entry ender "." st))))
4996 ;; i: have 2 args, after end of the first arg
4997 ;; i2: start of the second arg, if any (before delim iff `ender').
4998 ;; ender: the last arg bounded by parens-like chars, the second one of them
4999 ;; starter: the starting delimiter of the first arg
5000 ;; go-forward: has 2 args, and the second part is empty
5001 (list i i2 ender starter go-forward)))
5003 (defun cperl-forward-group-in-re (&optional st-l)
5004 "Find the end of a group in a REx.
5005 Return the error message (if any). Does not work if delimiter is `)'.
5006 Works before syntax recognition is done."
5007 ;; Works *before* syntax recognition is done
5008 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
5009 (let (st b reset-st)
5010 (condition-case b
5011 (progn
5012 (setq st (cperl-cached-syntax-table st-l))
5013 (modify-syntax-entry ?\( "()" st)
5014 (modify-syntax-entry ?\) ")(" st)
5015 (setq reset-st (syntax-table))
5016 (set-syntax-table st)
5017 (forward-sexp 1))
5018 (error (message
5019 "cperl-forward-group-in-re: error %s" b)))
5020 ;; now restore the initial state
5021 (if st
5022 (progn
5023 (modify-syntax-entry ?\( "." st)
5024 (modify-syntax-entry ?\) "." st)))
5025 (if reset-st
5026 (set-syntax-table reset-st))
5030 (defvar font-lock-string-face)
5031 ;;(defvar font-lock-reference-face)
5032 (defvar font-lock-constant-face)
5033 (defsubst cperl-postpone-fontification (b e type val &optional now)
5034 ;; Do after syntactic fontification?
5035 (if cperl-syntaxify-by-font-lock
5036 (or now (put-text-property b e 'cperl-postpone (cons type val)))
5037 (put-text-property b e type val)))
5039 ;;; Here is how the global structures (those which cannot be
5040 ;;; recognized locally) are marked:
5041 ;; a) PODs:
5042 ;; Start-to-end is marked `in-pod' ==> t
5043 ;; Each non-literal part is marked `syntax-type' ==> `pod'
5044 ;; Each literal part is marked `syntax-type' ==> `in-pod'
5045 ;; b) HEREs:
5046 ;; Start-to-end is marked `here-doc-group' ==> t
5047 ;; The body is marked `syntax-type' ==> `here-doc'
5048 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
5049 ;; c) FORMATs:
5050 ;; First line (to =) marked `first-format-line' ==> t
5051 ;; After-this--to-end is marked `syntax-type' ==> `format'
5052 ;; d) 'Q'uoted string:
5053 ;; part between markers inclusive is marked `syntax-type' ==> `string'
5054 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
5055 ;; e) Attributes of subroutines: `attrib-group' ==> t
5056 ;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
5057 ;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
5059 ;;; In addition, some parts of RExes may be marked as `REx-interpolated'
5060 ;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
5062 (defun cperl-unwind-to-safe (before &optional end)
5063 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
5064 (let ((pos (point)) opos)
5065 (while (and pos (progn
5066 (beginning-of-line)
5067 (get-text-property (setq pos (point)) 'syntax-type)))
5068 (setq opos pos
5069 pos (cperl-beginning-of-property pos 'syntax-type))
5070 (if (eq pos (point-min))
5071 (setq pos nil))
5072 (if pos
5073 (if before
5074 (progn
5075 (goto-char (cperl-1- pos))
5076 (beginning-of-line)
5077 (setq pos (point)))
5078 (goto-char (setq pos (cperl-1- pos))))
5079 ;; Up to the start
5080 (goto-char (point-min))))
5081 ;; Skip empty lines
5082 (and (looking-at "\n*=")
5083 (/= 0 (skip-chars-backward "\n"))
5084 (forward-char))
5085 (setq pos (point))
5086 (if end
5087 ;; Do the same for end, going small steps
5088 (save-excursion
5089 (while (and end (get-text-property end 'syntax-type))
5090 (setq pos end
5091 end (next-single-property-change end 'syntax-type nil (point-max)))
5092 (if end (progn (goto-char end)
5093 (or (bolp) (forward-line 1))
5094 (setq end (point)))))
5095 (or end pos)))))
5097 ;;; These are needed for byte-compile (at least with v19)
5098 (defvar cperl-nonoverridable-face)
5099 (defvar font-lock-variable-name-face)
5100 (defvar font-lock-function-name-face)
5101 (defvar font-lock-keyword-face)
5102 (defvar font-lock-builtin-face)
5103 (defvar font-lock-type-face)
5104 (defvar font-lock-comment-face)
5105 (defvar font-lock-warning-face)
5107 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
5108 "Syntaxically mark (and fontify) attributes of a subroutine.
5109 Should be called with the point before leading colon of an attribute."
5110 ;; Works *before* syntax recognition is done
5111 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
5112 (let (st b p reset-st after-first (start (point)) start1 end1)
5113 (condition-case b
5114 (while (looking-at
5115 (concat
5116 "\\(" ; 1=optional? colon
5117 ":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
5118 "\\)"
5119 (if after-first "?" "")
5120 ;; No space between name and paren allowed...
5121 "\\(\\sw+\\)" ; 3=name
5122 "\\((\\)?")) ; 4=optional paren
5123 (and (match-beginning 1)
5124 (cperl-postpone-fontification
5125 (match-beginning 0) (cperl-1+ (match-beginning 0))
5126 'face font-lock-constant-face))
5127 (setq start1 (match-beginning 3) end1 (match-end 3))
5128 (cperl-postpone-fontification start1 end1
5129 'face font-lock-constant-face)
5130 (goto-char end1) ; end or before `('
5131 (if (match-end 4) ; Have attribute arguments...
5132 (progn
5133 (if st nil
5134 (setq st (cperl-cached-syntax-table st-l))
5135 (modify-syntax-entry ?\( "()" st)
5136 (modify-syntax-entry ?\) ")(" st))
5137 (setq reset-st (syntax-table) p (point))
5138 (set-syntax-table st)
5139 (forward-sexp 1)
5140 (set-syntax-table reset-st)
5141 (setq reset-st nil)
5142 (cperl-commentify p (point) t))) ; mark as string
5143 (forward-comment (buffer-size))
5144 (setq after-first t))
5145 (error (message
5146 "L%d: attribute `%s': %s"
5147 (count-lines (point-min) (point))
5148 (and start1 end1 (buffer-substring start1 end1)) b)
5149 (setq start nil)))
5150 (and start
5151 (progn
5152 (put-text-property start (point)
5153 'attrib-group (if (looking-at "{") t 0))
5154 (and pos
5155 (< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
5156 ;; Apparently, we do not need `multiline': faces added now
5157 (put-text-property (+ 3 pos) (cperl-1+ (point))
5158 'syntax-type 'sub-decl))
5159 (and b-fname ; Fontify here: the following condition
5160 (cperl-postpone-fontification ; is too hard to determine by
5161 b-fname e-fname 'face ; a REx, so do it here
5162 (if (looking-at "{")
5163 font-lock-function-name-face
5164 font-lock-variable-name-face)))))
5165 ;; now restore the initial state
5166 (if st
5167 (progn
5168 (modify-syntax-entry ?\( "." st)
5169 (modify-syntax-entry ?\) "." st)))
5170 (if reset-st
5171 (set-syntax-table reset-st))))
5173 (defsubst cperl-look-at-leading-count (is-x-REx e)
5174 (if (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
5175 (1- e) t) ; return nil on failure, no moving
5176 (if (eq ?\{ (preceding-char)) nil
5177 (cperl-postpone-fontification
5178 (1- (point)) (point)
5179 'face font-lock-warning-face))))
5181 ;;; Debugging this may require (setq max-specpdl-size 2000)...
5182 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc)
5183 "Scans the buffer for hard-to-parse Perl constructions.
5184 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
5185 the sections using `cperl-pod-head-face', `cperl-pod-face',
5186 `cperl-here-face'."
5187 (interactive)
5188 (or min (setq min (point-min)
5189 cperl-syntax-state nil
5190 cperl-syntax-done-to min))
5191 (or max (setq max (point-max)))
5192 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
5193 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
5194 is-REx is-x-REx REx-subgr-start REx-subgr-end was-subgr i2 hairy-RE
5195 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
5196 (modified (buffer-modified-p)) overshoot is-o-REx
5197 (after-change-functions nil)
5198 (cperl-font-locking t)
5199 (use-syntax-state (and cperl-syntax-state
5200 (>= min (car cperl-syntax-state))))
5201 (state-point (if use-syntax-state
5202 (car cperl-syntax-state)
5203 (point-min)))
5204 (state (if use-syntax-state
5205 (cdr cperl-syntax-state)))
5206 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
5207 (st-l (list nil)) (err-l (list nil))
5208 ;; Somehow font-lock may be not loaded yet...
5209 ;; (e.g., when building TAGS via command-line call)
5210 (font-lock-string-face (if (boundp 'font-lock-string-face)
5211 font-lock-string-face
5212 'font-lock-string-face))
5213 (my-cperl-delimiters-face (if (boundp 'font-lock-constant-face)
5214 font-lock-constant-face
5215 'font-lock-constant-face))
5216 (my-cperl-REx-spec-char-face ; [] ^.$ and wrapper-of ({})
5217 (if (boundp 'font-lock-function-name-face)
5218 font-lock-function-name-face
5219 'font-lock-function-name-face))
5220 (font-lock-variable-name-face ; interpolated vars and ({})-code
5221 (if (boundp 'font-lock-variable-name-face)
5222 font-lock-variable-name-face
5223 'font-lock-variable-name-face))
5224 (font-lock-function-name-face ; used in `cperl-find-sub-attrs'
5225 (if (boundp 'font-lock-function-name-face)
5226 font-lock-function-name-face
5227 'font-lock-function-name-face))
5228 (font-lock-constant-face ; used in `cperl-find-sub-attrs'
5229 (if (boundp 'font-lock-constant-face)
5230 font-lock-constant-face
5231 'font-lock-constant-face))
5232 (my-cperl-REx-0length-face ; 0-length, (?:)etc, non-literal \
5233 (if (boundp 'font-lock-builtin-face)
5234 font-lock-builtin-face
5235 'font-lock-builtin-face))
5236 (font-lock-comment-face
5237 (if (boundp 'font-lock-comment-face)
5238 font-lock-comment-face
5239 'font-lock-comment-face))
5240 (font-lock-warning-face
5241 (if (boundp 'font-lock-warning-face)
5242 font-lock-warning-face
5243 'font-lock-warning-face))
5244 (my-cperl-REx-ctl-face ; (|)
5245 (if (boundp 'font-lock-keyword-face)
5246 font-lock-keyword-face
5247 'font-lock-keyword-face))
5248 (my-cperl-REx-modifiers-face ; //gims
5249 (if (boundp 'cperl-nonoverridable-face)
5250 cperl-nonoverridable-face
5251 'cperl-nonoverridable-face))
5252 (my-cperl-REx-length1-face ; length=1 escaped chars, POSIX classes
5253 (if (boundp 'font-lock-type-face)
5254 font-lock-type-face
5255 'font-lock-type-face))
5256 (stop-point (if ignore-max
5257 (point-max)
5258 max))
5259 (search
5260 (concat
5261 "\\(\\`\n?\\|^\n\\)=" ; POD
5262 "\\|"
5263 ;; One extra () before this:
5264 "<<" ; HERE-DOC
5265 "\\(" ; 1 + 1
5266 ;; First variant "BLAH" or just ``.
5267 "[ \t]*" ; Yes, whitespace is allowed!
5268 "\\([\"'`]\\)" ; 2 + 1 = 3
5269 "\\([^\"'`\n]*\\)" ; 3 + 1
5270 "\\3"
5271 "\\|"
5272 ;; Second variant: Identifier or \ID (same as 'ID') or empty
5273 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
5274 ;; Do not have <<= or << 30 or <<30 or << $blah.
5275 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
5276 "\\(\\)" ; To preserve count of pars :-( 6 + 1
5277 "\\)"
5278 "\\|"
5279 ;; 1+6 extra () before this:
5280 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" ;FRMAT
5281 (if cperl-use-syntax-table-text-property
5282 (concat
5283 "\\|"
5284 ;; 1+6+2=9 extra () before this:
5285 (if (not cperl-use-v6) ; perl6
5286 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT - Perl5
5287 ;;"\\<\\(q[wxq]?\\)\\>" ; QUOTED CONSTRUCT - Perl6
5288 "\\<\\(q[wxq]?\\|\\(?:rx\\|[ms]\\|tr\\)\\s *\\(?::\\(?:[igcpw]\\|ignorecase\\|global\\(?:ly\\)?\\|continue\\|pos\\|once\\|words\\|bytes\\|codes\\|graphs\\|langs\\|\\|[0-9]+\\(?:st\\|nd\\|rd\\|th\\|x\\)\\|ov\\|overlap\\|ex\\|exhaustive\\|rw\\|P5\\|perl5\\|Perl5\\(?:<[a-zA-Z]+>\\)?\\|nth\\(?:([0-9]+)\\)?\\|x\\(?:([0-9]+)\\)?\\)\\s *\\)*\\)\\>:?") ; perl6: rx
5290 "\\|"
5291 ;; 1+6+2+1=10 extra () before this:
5292 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
5293 "\\|"
5294 ;; 1+6+2+1+1=11 extra () before this
5295 "\\<sub\\>" ; sub with proto/attr
5296 "\\("
5297 cperl-white-and-comment-rex
5298 "\\(::[a-zA-Z_:'0-9]*\\|[a-zA-Z_'][a-zA-Z_:'0-9]*\\)\\)?" ; name
5299 "\\("
5300 cperl-maybe-white-and-comment-rex
5301 "\\(([^()]*)\\|:[^:]\\)\\)" ; prototype or attribute start
5302 "\\|"
5303 ;; 1+6+2+1+1+6=17 extra () before this:
5304 "\\$\\(['{]\\)" ; $' or ${foo}
5305 "\\|"
5306 ;; 1+6+2+1+1+6+1=18 extra () before this (old pack'var syntax;
5307 ;; we do not support intervening comments...):
5308 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
5309 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
5310 "\\|"
5311 "__\\(END\\|DATA\\)__" ; __END__ or __DATA__
5312 ;; 1+6+2+1+1+6+1+1+1=20 extra () before this:
5313 "\\|"
5314 "\\\\\\(['`\"($]\\)" ; BACKWACKED something-hairy
5315 ;; 1+6+2+1+1+6+1+1+1+1=21 extra () before this: ; perl6
5316 ;; "\\|"
5317 ;; "\\<\\(\\(rx\\|[ms]\\|tr\\)\\s *\\(:\\([igcpw]\\|ignorecase\\|global\\(ly\\)?\\|continue\\|pos\\|once\\|words\\|bytes\\|codes\\|graphs\\|langs\\|\\|[0-9]+\\(st\\|nd\\|rd\\|th\\|x\\)\\|ov\\|overlap\\|ex\\|exhaustive\\|rw\\|P5\\|perl5\\|Perl5\\(<[a-zA-Z]+>\\)?\\|nth\\(([0-9]+)\\)?\\|x\\(([0-9]+)\\)?\\)\\s *\\)*\\)\\>:?") ; perl6: rx
5318 ;; 1+6+2+1+1+6+1+1+1+1+7=28 extra () before this: ; perl6
5319 ""))))
5320 (unwind-protect
5321 (progn
5322 (save-excursion
5323 (or non-inter
5324 (message "Scanning for \"hard\" Perl constructions..."))
5325 ;;(message "find: %s --> %s" min max)
5326 (and cperl-pod-here-fontify
5327 ;; We had evals here, do not know why...
5328 (setq face cperl-pod-face
5329 head-face cperl-pod-head-face
5330 here-face cperl-here-face))
5331 (remove-text-properties min max
5332 '(syntax-type t in-pod t syntax-table t
5333 attrib-group t
5334 REx-interpolated t
5335 cperl-postpone t
5336 syntax-subtype t
5337 rear-nonsticky t
5338 front-sticky t
5339 here-doc-group t
5340 first-format-line t
5341 REx-part2 t
5342 indentable t))
5343 ;; Need to remove face as well...
5344 (goto-char min)
5345 (and (eq system-type 'emx)
5346 (eq (point) 1)
5347 (let ((case-fold-search t))
5348 (looking-at "extproc[ \t]")) ; Analogue of #!
5349 (cperl-commentify min
5350 (save-excursion (end-of-line) (point))
5351 nil))
5352 (while (and
5353 (< (point) max)
5354 (re-search-forward search max t))
5355 (setq tmpend nil) ; Valid for most cases
5356 (setq b (match-beginning 0)
5357 state (save-excursion (parse-partial-sexp
5358 state-point b nil nil state))
5359 state-point b)
5360 (cond
5361 ;; 1+6+2+1+1+6=17 extra () before this:
5362 ;; "\\$\\(['{]\\)"
5363 ((match-beginning 18) ; $' or ${foo}
5364 (if (eq (preceding-char) ?\') ; $'
5365 (progn
5366 (setq b (1- (point))
5367 state (parse-partial-sexp
5368 state-point (1- b) nil nil state)
5369 state-point (1- b))
5370 (if (nth 3 state) ; in string
5371 (cperl-modify-syntax-type (1- b) cperl-st-punct))
5372 (goto-char (1+ b)))
5373 ;; else: ${
5374 (setq bb (match-beginning 0))
5375 (cperl-modify-syntax-type bb cperl-st-punct)))
5376 ;; No processing in strings/comments beyond this point:
5377 ((or (nth 3 state) (nth 4 state))
5378 t) ; Do nothing in comment/string
5379 ((match-beginning 1) ; POD section
5380 ;; "\\(\\`\n?\\|^\n\\)="
5381 (setq b (match-beginning 0)
5382 state (parse-partial-sexp
5383 state-point b nil nil state)
5384 state-point b)
5385 (if (or (nth 3 state) (nth 4 state)
5386 (looking-at "cut\\>"))
5387 (if (or (nth 3 state) (nth 4 state) ignore-max)
5388 nil ; Doing a chunk only
5389 (message "=cut is not preceded by a POD section")
5390 (or (car err-l) (setcar err-l (point))))
5391 (beginning-of-line)
5393 (setq b (point)
5394 bb b
5395 tb (match-beginning 0)
5396 b1 nil) ; error condition
5397 ;; We do not search to max, since we may be called from
5398 ;; some hook of fontification, and max is random
5399 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
5400 (progn
5401 (goto-char b)
5402 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
5403 (progn
5404 (message "=cut is not preceded by an empty line")
5405 (setq b1 t)
5406 (or (car err-l) (setcar err-l b))))))
5407 (beginning-of-line 2) ; An empty line after =cut is not POD!
5408 (setq e (point))
5409 (and (> e max)
5410 (progn
5411 (remove-text-properties
5412 max e '(syntax-type t in-pod t syntax-table t
5413 attrib-group t
5414 REx-interpolated t
5415 cperl-postpone t
5416 syntax-subtype t
5417 here-doc-group t
5418 rear-nonsticky t
5419 front-sticky t
5420 first-format-line t
5421 REx-part2 t
5422 indentable t))
5423 (setq tmpend tb)))
5424 (put-text-property b e 'in-pod t)
5425 (put-text-property b e 'syntax-type 'in-pod)
5426 (goto-char b)
5427 (while (re-search-forward "\n\n[ \t]" e t)
5428 ;; We start 'pod 1 char earlier to include the preceding line
5429 (beginning-of-line)
5430 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
5431 (cperl-put-do-not-fontify b (point) t)
5432 ;; mark the non-literal parts as PODs
5433 (if cperl-pod-here-fontify
5434 (cperl-postpone-fontification b (point) 'face face t))
5435 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
5436 (beginning-of-line)
5437 (setq b (point)))
5438 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
5439 (cperl-put-do-not-fontify (point) e t)
5440 (if cperl-pod-here-fontify
5441 (progn
5442 ;; mark the non-literal parts as PODs
5443 (cperl-postpone-fontification (point) e 'face face t)
5444 (goto-char bb)
5445 (if (looking-at
5446 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
5447 ;; mark the headers
5448 (cperl-postpone-fontification
5449 (match-beginning 1) (match-end 1)
5450 'face head-face))
5451 (while (re-search-forward
5452 ;; One paragraph
5453 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
5454 e 'toend)
5455 ;; mark the headers
5456 (cperl-postpone-fontification
5457 (match-beginning 1) (match-end 1)
5458 'face head-face))))
5459 (cperl-commentify bb e nil)
5460 (goto-char e)
5461 (or (eq e (point-max))
5462 (forward-char -1)))) ; Prepare for immediate POD start.
5463 ;; Here document
5464 ;; We can do many here-per-line;
5465 ;; but multiline quote on the same line as <<HERE confuses us...
5466 ;; ;; One extra () before this:
5467 ;;"<<"
5468 ;; "\\(" ; 1 + 1
5469 ;; ;; First variant "BLAH" or just ``.
5470 ;; "[ \t]*" ; Yes, whitespace is allowed!
5471 ;; "\\([\"'`]\\)" ; 2 + 1
5472 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
5473 ;; "\\3"
5474 ;; "\\|"
5475 ;; ;; Second variant: Identifier or \ID or empty
5476 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
5477 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
5478 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
5479 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
5480 ;; "\\)"
5481 ((match-beginning 2) ; 1 + 1
5482 (setq b (point)
5483 tb (match-beginning 0)
5484 c (and ; not HERE-DOC
5485 (match-beginning 5)
5486 (save-match-data
5487 (or (looking-at "[ \t]*(") ; << function_call()
5488 (save-excursion ; 1 << func_name, or $foo << 10
5489 (condition-case nil
5490 (progn
5491 (goto-char tb)
5492 ;;; XXX What to do: foo <<bar ???
5493 ;;; XXX Need to support print {a} <<B ???
5494 (forward-sexp -1)
5495 (save-match-data
5496 ; $foo << b; $f .= <<B;
5497 ; ($f+1) << b; a($f) . <<B;
5498 ; foo 1, <<B; $x{a} <<b;
5499 (cond
5500 ((looking-at "[0-9$({]")
5501 (forward-sexp 1)
5502 (and
5503 (looking-at "[ \t]*<<")
5504 (condition-case nil
5505 ;; print $foo <<EOF
5506 (progn
5507 (forward-sexp -2)
5508 (not
5509 (looking-at "\\(printf?\\|system\\|exec\\|sort\\)\\>")))
5510 (error t)))))))
5511 (error nil))) ; func(<<EOF)
5512 (and (not (match-beginning 6)) ; Empty
5513 (looking-at
5514 "[ \t]*[=0-9$@%&(]"))))))
5515 (if c ; Not here-doc
5516 nil ; Skip it.
5517 (setq c (match-end 2)) ; 1 + 1
5518 (if (match-beginning 5) ;4 + 1
5519 (setq b1 (match-beginning 5) ; 4 + 1
5520 e1 (match-end 5)) ; 4 + 1
5521 (setq b1 (match-beginning 4) ; 3 + 1
5522 e1 (match-end 4))) ; 3 + 1
5523 (setq tag (buffer-substring b1 e1)
5524 qtag (regexp-quote tag))
5525 (cond (cperl-pod-here-fontify
5526 ;; Highlight the starting delimiter
5527 (cperl-postpone-fontification
5528 b1 e1 'face my-cperl-delimiters-face)
5529 (cperl-put-do-not-fontify b1 e1 t)))
5530 (forward-line)
5531 (setq i (point))
5532 (if end-of-here-doc
5533 (goto-char end-of-here-doc))
5534 (setq b (point))
5535 ;; We do not search to max, since we may be called from
5536 ;; some hook of fontification, and max is random
5537 (or (and (re-search-forward (concat "^" qtag "$")
5538 stop-point 'toend)
5539 ;;;(eq (following-char) ?\n) ; XXXX WHY???
5541 (progn ; Pretend we matched at the end
5542 (goto-char (point-max))
5543 (re-search-forward "\\'")
5544 (message "End of here-document `%s' not found." tag)
5545 (or (car err-l) (setcar err-l b))))
5546 (if cperl-pod-here-fontify
5547 (progn
5548 ;; Highlight the ending delimiter
5549 (cperl-postpone-fontification
5550 (match-beginning 0) (match-end 0)
5551 'face my-cperl-delimiters-face)
5552 (cperl-put-do-not-fontify b (match-end 0) t)
5553 ;; Highlight the HERE-DOC
5554 (cperl-postpone-fontification b (match-beginning 0)
5555 'face here-face)))
5556 (setq e1 (cperl-1+ (match-end 0)))
5557 (put-text-property b (match-beginning 0)
5558 'syntax-type 'here-doc)
5559 (put-text-property (match-beginning 0) e1
5560 'syntax-type 'here-doc-delim)
5561 (put-text-property b e1 'here-doc-group t)
5562 ;; This makes insertion at the start of HERE-DOC update
5563 ;; the whole construct:
5564 (put-text-property b (cperl-1+ b) 'front-sticky '(syntax-type))
5565 (cperl-commentify b e1 nil)
5566 (cperl-put-do-not-fontify b (match-end 0) t)
5567 ;; Cache the syntax info...
5568 (setq cperl-syntax-state (cons state-point state))
5569 ;; ... and process the rest of the line...
5570 (setq overshoot
5571 (elt ; non-inter ignore-max
5572 (cperl-find-pods-heres c i t end t e1) 1))
5573 (if (and overshoot (> overshoot (point)))
5574 (goto-char overshoot)
5575 (setq overshoot e1))
5576 (if (> e1 max)
5577 (setq tmpend tb))))
5578 ;; format
5579 ((match-beginning 8)
5580 ;; 1+6=7 extra () before this:
5581 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
5582 (setq b (point)
5583 name (if (match-beginning 8) ; 7 + 1
5584 (buffer-substring (match-beginning 8) ; 7 + 1
5585 (match-end 8)) ; 7 + 1
5587 tb (match-beginning 0))
5588 (setq argument nil)
5589 (put-text-property (save-excursion
5590 (beginning-of-line)
5591 (point))
5592 b 'first-format-line 't)
5593 (if cperl-pod-here-fontify
5594 (while (and (eq (forward-line) 0)
5595 (not (looking-at "^[.;]$")))
5596 (cond
5597 ((looking-at "^#")) ; Skip comments
5598 ((and argument ; Skip argument multi-lines
5599 (looking-at "^[ \t]*{"))
5600 (forward-sexp 1)
5601 (setq argument nil))
5602 (argument ; Skip argument lines
5603 (setq argument nil))
5604 (t ; Format line
5605 (setq b1 (point))
5606 (setq argument (looking-at "^[^\n]*[@^]"))
5607 (end-of-line)
5608 ;; Highlight the format line
5609 (cperl-postpone-fontification b1 (point)
5610 'face font-lock-string-face)
5611 (cperl-commentify b1 (point) nil)
5612 (cperl-put-do-not-fontify b1 (point) t))))
5613 ;; We do not search to max, since we may be called from
5614 ;; some hook of fontification, and max is random
5615 (re-search-forward "^[.;]$" stop-point 'toend))
5616 (beginning-of-line)
5617 (if (looking-at "^\\.$") ; ";" is not supported yet
5618 (progn
5619 ;; Highlight the ending delimiter
5620 (cperl-postpone-fontification (point) (+ (point) 2)
5621 'face font-lock-string-face)
5622 (cperl-commentify (point) (+ (point) 2) nil)
5623 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
5624 (message "End of format `%s' not found." name)
5625 (or (car err-l) (setcar err-l b)))
5626 (forward-line)
5627 (if (> (point) max)
5628 (setq tmpend tb))
5629 (put-text-property b (point) 'syntax-type 'format))
5630 ;; qq-like String or Regexp:
5631 ((or (match-beginning 10) (match-beginning 11))
5632 ;; 1+6+2=9 extra () before this:
5633 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
5634 ;; "\\|"
5635 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
5636 (setq b1 (if (match-beginning 10) 10 11)
5637 argument (buffer-substring
5638 (match-beginning b1) (match-end b1))
5639 b (point) ; end of qq etc
5641 c (char-after (match-beginning b1))
5642 bb (char-after (1- (match-beginning b1))) ; tmp holder
5643 ;; bb == "Not a stringy"
5644 bb (if (eq b1 10) ; user variables/whatever
5645 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
5646 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
5647 ((eq bb ?\:) ; $opt::s
5648 (eq (char-after
5649 (- (match-beginning b1) 2))
5650 ?\:))
5651 ((eq bb ?\>) ; $foo->s
5652 (eq (char-after
5653 (- (match-beginning b1) 2))
5654 ?\-))
5655 ((eq bb ?\&)
5656 (not (eq (char-after ; &&m/blah/
5657 (- (match-beginning b1) 2))
5658 ?\&)))
5659 (t t)))
5660 ;; <file> or <$file>
5661 (and (eq c ?\<)
5662 ;; Do not stringify <FH>, <$fh> :
5663 (save-match-data
5664 (looking-at
5665 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
5666 tb (match-beginning 0))
5667 (goto-char (match-beginning b1))
5668 (cperl-backward-to-noncomment (point-min))
5669 (or bb
5670 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
5671 (setq argument ""
5672 b1 nil
5673 bb ; Not a regexp?
5674 (not
5675 ;; What is below: regexp-p?
5676 (and
5677 (or (memq (preceding-char)
5678 (append (if (memq c '(?\? ?\<))
5679 ;; $a++ ? 1 : 2
5680 "~{(=|&*!,;:["
5681 "~{(=|&+-*!,;:[") nil))
5682 (and (eq (preceding-char) ?\})
5683 (cperl-after-block-p (point-min)))
5684 (and (eq (char-syntax (preceding-char)) ?w)
5685 (progn
5686 (forward-sexp -1)
5687 ;;; After these keywords `/' starts a RE. One should add all the
5688 ;;; functions/builtins which expect an argument, but ...
5689 (if (eq (preceding-char) ?-)
5690 ;; -d ?foo? is a RE
5691 (looking-at "[a-zA-Z]\\>")
5692 (and
5693 (not (memq (preceding-char)
5694 '(?$ ?@ ?& ?%)))
5695 (looking-at
5696 "\\(while\\|if\\|unless\\|when\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
5697 (and (eq (preceding-char) ?.)
5698 (eq (char-after (- (point) 2)) ?.))
5699 (bobp))
5700 ;; m|blah| ? foo : bar;
5701 (not
5702 (and (eq c ?\?)
5703 cperl-use-syntax-table-text-property
5704 (not (bobp))
5705 (progn
5706 (forward-char -1)
5707 (looking-at "\\s|"))))))
5708 b (1- b))
5709 ;; s y tr m
5710 ;; Check for $a -> y
5711 (setq b1 (preceding-char)
5712 go (point))
5713 (if (and (eq b1 ?>)
5714 (eq (char-after (- go 2)) ?-))
5715 ;; Not a regexp
5716 (setq bb t))))
5717 (or bb
5718 (progn
5719 (goto-char b)
5720 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5721 (goto-char (match-end 0))
5722 (skip-chars-forward " \t\n\f"))
5723 (cond ((and (eq (following-char) ?\})
5724 (eq b1 ?\{))
5725 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
5726 (goto-char (1- go))
5727 (skip-chars-backward " \t\n\f")
5728 (if (memq (preceding-char) (append "$@%&*" nil))
5729 (setq bb t) ; @{y}
5730 (condition-case nil
5731 (forward-sexp -1)
5732 (error nil)))
5733 (if (or bb
5734 (looking-at ; $foo -> {s}
5735 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
5736 (and ; $foo[12] -> {s}
5737 (memq (following-char) '(?\{ ?\[))
5738 (progn
5739 (forward-sexp 1)
5740 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
5741 (setq bb t)
5742 (goto-char b)))
5743 ((and (eq (following-char) ?=)
5744 (eq (char-after (1+ (point))) ?\>))
5745 ;; Check for { foo => 1, s => 2 }
5746 ;; Apparently s=> is never a substitution...
5747 (setq bb t))
5748 ((and (eq (following-char) ?:)
5749 (eq b1 ?\{) ; Check for $ { s::bar }
5750 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
5751 (progn
5752 (goto-char (1- go))
5753 (skip-chars-backward " \t\n\f")
5754 (memq (preceding-char)
5755 (append "$@%&*" nil))))
5756 (setq bb t))
5757 ((eobp)
5758 (setq bb t)))))
5759 (if bb
5760 (goto-char i)
5761 ;; Skip whitespace and comments...
5762 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5763 (goto-char (match-end 0))
5764 (skip-chars-forward " \t\n\f"))
5765 (if (> (point) b)
5766 (put-text-property b (point) 'syntax-type 'prestring))
5767 ;; qtag means two-arg matcher, may be reset to
5768 ;; 2 or 3 later if some special quoting is needed.
5769 ;; e1 means matching-char matcher.
5770 (setq b (point) ; before the first delimiter
5771 ;; has 2 args
5772 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
5773 ;; We do not search to max, since we may be called from
5774 ;; some hook of fontification, and max is random
5775 i (cperl-forward-re stop-point end
5777 st-l err-l argument)
5778 ;; If `go', then it is considered as 1-arg, `b1' is nil
5779 ;; as in s/foo//x; the point is before final "slash"
5780 b1 (nth 1 i) ; start of the second part
5781 tag (nth 2 i) ; ender-char, true if second part
5782 ; is with matching chars []
5783 go (nth 4 i) ; There is a 1-char part after the end
5784 i (car i) ; intermediate point
5785 e1 (point) ; end
5786 ;; Before end of the second part if non-matching: ///
5787 tail (if (and i (not tag))
5788 (1- e1))
5789 e (if i i e1) ; end of the first part
5790 qtag nil ; need to preserve backslashitis
5791 is-x-REx nil is-o-REx nil); REx has //x //o modifiers
5792 ;; If s{} (), then b/b1 are at "{", "(", e1/i after ")", "}"
5793 ;; Commenting \\ is dangerous, what about ( ?
5794 (and i tail
5795 (eq (char-after i) ?\\)
5796 (setq qtag t))
5797 (and (if go (looking-at ".\\sw*x")
5798 (looking-at "\\sw*x")) ; qr//x
5799 (setq is-x-REx t))
5800 (and (if go (looking-at ".\\sw*o")
5801 (looking-at "\\sw*o")) ; //o
5802 (setq is-o-REx t))
5803 (if (null i)
5804 ;; Considered as 1arg form
5805 (progn
5806 (cperl-commentify b (point) t)
5807 (put-text-property b (point) 'syntax-type 'string)
5808 (if (or is-x-REx
5809 ;; ignore other text properties:
5810 (string-match "^qw$" argument))
5811 (put-text-property b (point) 'indentable t))
5812 (and go
5813 (setq e1 (cperl-1+ e1))
5814 (or (eobp)
5815 (forward-char 1))))
5816 (cperl-commentify b i t)
5817 (if (looking-at "\\sw*e") ; s///e
5818 (progn
5819 ;; Cache the syntax info...
5820 (setq cperl-syntax-state (cons state-point state))
5821 (and
5822 ;; silent:
5823 (car (cperl-find-pods-heres b1 (1- (point)) t end))
5824 ;; Error
5825 (goto-char (1+ max)))
5826 (if (and tag (eq (preceding-char) ?\>))
5827 (progn
5828 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
5829 (cperl-modify-syntax-type i cperl-st-bra)))
5830 (put-text-property b i 'syntax-type 'string)
5831 (if is-x-REx
5832 (put-text-property b i 'indentable t)))
5833 (cperl-commentify b1 (point) t)
5834 (put-text-property b (point) 'syntax-type 'string)
5835 (if is-x-REx
5836 (put-text-property b i 'indentable t))
5837 (if qtag
5838 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
5839 (setq tail nil)))
5840 ;; Now: tail: if the second part is non-matching without ///e
5841 (if (eq (char-syntax (following-char)) ?w)
5842 (progn
5843 (forward-word 1) ; skip modifiers s///s
5844 (if tail (cperl-commentify tail (point) t))
5845 (cperl-postpone-fontification
5846 e1 (point) 'face my-cperl-REx-modifiers-face)))
5847 ;; Check whether it is m// which means "previous match"
5848 ;; and highlight differently
5849 (setq is-REx
5850 (and (string-match "^\\([sm]?\\|qr\\|rx\\)$" argument)
5851 (or (not (= (length argument) 0))
5852 (not (eq c ?\<)))))
5853 (if (and is-REx
5854 (eq e (+ 2 b))
5855 ;; split // *is* using zero-pattern
5856 (save-excursion
5857 (condition-case nil
5858 (progn
5859 (goto-char tb)
5860 (forward-sexp -1)
5861 (not (looking-at "split\\>")))
5862 (error t))))
5863 (cperl-postpone-fontification
5864 b e 'face font-lock-warning-face)
5865 (if (or i2 ; Has 2 args
5866 (and cperl-fontify-m-as-s
5868 ;; (string-match "^\\(m\\|qr\\)$" argument) ; perl6
5869 (string-match "^\\(\\(rx\\|[msy]\\|tr\\)\\s *\\(:\\([igcpw]\\|ignorecase\\|global\\(ly\\)?\\|continue\\|pos\\|once\\|words\\|bytes\\|codes\\|graphs\\|langs\\|\\|[0-9]+\\(st\\|nd\\|rd\\|th\\|x\\)\\|ov\\|overlap\\|ex\\|exhaustive\\|rw\\|P5\\|perl5\\|Perl5\\(<[a-zA-Z]+>\\)?\\|nth\\(([0-9]+)\\)?\\|x\\(([0-9]+)\\)?\\)\\s *\\)*\\)$" argument) ; perl6: rx
5870 (and (eq 0 (length argument))
5871 (not (eq ?\< (char-after b)))))))
5872 (progn
5873 (cperl-postpone-fontification
5874 b (cperl-1+ b) 'face my-cperl-delimiters-face)
5875 (cperl-postpone-fontification
5876 (1- e) e 'face my-cperl-delimiters-face)))
5877 (if (and is-REx cperl-regexp-scan)
5878 ;; Process RExen: embedded comments, charclasses and ]
5879 ;;;/\3333\xFg\x{FFF}a\ppp\PPP\qqq\C\99f(?{ foo })(??{ foo })/;
5880 ;;;/a\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
5881 ;;;/(?<=foo)(?<!bar)(x)(?:$ab|\$\/)$|\\\b\x888\776\[\:$/xxx;
5882 ;;;m?(\?\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
5883 ;;;m$(^ab[c]\$)$ + m+(^ab[c]\$\+)+ + m](^ab[c\]$|.+)] + m)(^ab[c]$|.+\));
5884 ;;;m^a[\^b]c^ + m.a[^b]\.c.;
5885 (save-excursion
5886 (goto-char (1+ b))
5887 ;; First
5888 (cperl-look-at-leading-count is-x-REx e)
5889 (setq hairy-RE
5890 (concat
5891 (if is-x-REx
5892 (if (eq (char-after b) ?\#)
5893 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
5894 "\\((\\?#\\)\\|\\(#\\)")
5895 ;; keep the same count: add a fake group
5896 (if (eq (char-after b) ?\#)
5897 "\\((\\?\\\\#\\)\\(\\)"
5898 "\\((\\?#\\)\\(\\)"))
5899 "\\|"
5900 "\\(\\[\\)" ; 3=[
5901 "\\|"
5902 "\\(]\\)" ; 4=]
5903 "\\|"
5904 ;; XXXX Will not be able to use it in s)))
5905 (if (eq (char-after b) ?\) )
5906 "\\())))\\)" ; Will never match
5907 (if (eq (char-after b) ?? )
5908 ;;"\\((\\\\\\?\\(\\\\\\?\\)?{\\)"
5909 "\\((\\\\\\?\\\\\\?{\\|()\\\\\\?{\\)"
5910 "\\((\\?\\??{\\)")) ; 5= (??{ (?{
5911 "\\|" ; 6= 0-length, 7: name, 8,9:code, 10:group
5912 "\\(" ;; XXXX 1-char variables, exc. |()\s
5913 "[$@]"
5914 "\\("
5915 "[_a-zA-Z:][_a-zA-Z0-9:]*"
5916 "\\|"
5917 "{[^{}]*}" ; only one-level allowed
5918 "\\|"
5919 "[^{(|) \t\r\n\f]"
5920 "\\)"
5921 "\\(" ;;8,9:code part of array/hash elt
5922 "\\(" "->" "\\)?"
5923 "\\[[^][]*\\]"
5924 "\\|"
5925 "{[^{}]*}"
5926 "\\)*"
5927 ;; XXXX: what if u is delim?
5928 "\\|"
5929 "[)^|$.*?+]"
5930 "\\|"
5931 "{[0-9]+}"
5932 "\\|"
5933 "{[0-9]+,[0-9]*}"
5934 "\\|"
5935 "\\\\[luLUEQbBAzZG]"
5936 "\\|"
5937 "(" ; Group opener
5938 "\\(" ; 10 group opener follower
5939 "\\?\\((\\?\\)" ; 11: in (?(?=C)A|B)
5940 "\\|"
5941 "\\?[:=!>?{]" ; "?" something
5942 "\\|"
5943 "\\?[-imsx]+[:)]" ; (?i) (?-s:.)
5944 "\\|"
5945 "\\?([0-9]+)" ; (?(1)foo|bar)
5946 "\\|"
5947 "\\?<[=!]"
5948 ;;;"\\|"
5949 ;;; "\\?"
5950 "\\)?"
5951 "\\)"
5952 "\\|"
5953 "\\\\\\(.\\)" ; 12=\SYMBOL
5955 (while
5956 (and (< (point) (1- e))
5957 (re-search-forward hairy-RE (1- e) 'to-end))
5958 (goto-char (match-beginning 0))
5959 (setq REx-subgr-start (point)
5960 was-subgr (following-char))
5961 (cond
5962 ((match-beginning 6) ; 0-length builtins, groups
5963 (goto-char (match-end 0))
5964 (if (match-beginning 11)
5965 (goto-char (match-beginning 11)))
5966 (if (>= (point) e)
5967 (goto-char (1- e)))
5968 (cperl-postpone-fontification
5969 (match-beginning 0) (point)
5970 'face
5971 (cond
5972 ((eq was-subgr ?\) )
5973 (condition-case nil
5974 (save-excursion
5975 (forward-sexp -1)
5976 (if (> (point) b)
5977 (if (if (eq (char-after b) ?? )
5978 (looking-at "(\\\\\\?")
5979 (eq (char-after (1+ (point))) ?\?))
5980 my-cperl-REx-0length-face
5981 my-cperl-REx-ctl-face)
5982 font-lock-warning-face))
5983 (error font-lock-warning-face)))
5984 ((eq was-subgr ?\| )
5985 my-cperl-REx-ctl-face)
5986 ((eq was-subgr ?\$ )
5987 (if (> (point) (1+ REx-subgr-start))
5988 (progn
5989 (put-text-property
5990 (match-beginning 0) (point)
5991 'REx-interpolated
5992 (if is-o-REx 0
5993 (if (and (eq (match-beginning 0)
5994 (1+ b))
5995 (eq (point)
5996 (1- e))) 1 t)))
5997 font-lock-variable-name-face)
5998 my-cperl-REx-spec-char-face))
5999 ((memq was-subgr (append "^." nil) )
6000 my-cperl-REx-spec-char-face)
6001 ((eq was-subgr ?\( )
6002 (if (not (match-beginning 10))
6003 my-cperl-REx-ctl-face
6004 my-cperl-REx-0length-face))
6005 (t my-cperl-REx-0length-face)))
6006 (if (and (memq was-subgr (append "(|" nil))
6007 (not (string-match "(\\?[-imsx]+)"
6008 (match-string 0))))
6009 (cperl-look-at-leading-count is-x-REx e))
6010 (setq was-subgr nil)) ; We do stuff here
6011 ((match-beginning 12) ; \SYMBOL
6012 (forward-char 2)
6013 (if (>= (point) e)
6014 (goto-char (1- e))
6015 ;; How many chars to not highlight:
6016 ;; 0-len special-alnums in other branch =>
6017 ;; Generic: \non-alnum (1), \alnum (1+face)
6018 ;; Is-delim: \non-alnum (1/spec-2) alnum-1 (=what hai)
6019 (setq REx-subgr-start (point)
6020 qtag (preceding-char))
6021 (cperl-postpone-fontification
6022 (- (point) 2) (- (point) 1) 'face
6023 (if (memq qtag
6024 (append "ghijkmoqvFHIJKMORTVY" nil))
6025 font-lock-warning-face
6026 my-cperl-REx-0length-face))
6027 (if (and (eq (char-after b) qtag)
6028 (memq qtag (append ".])^$|*?+" nil)))
6029 (progn
6030 (if (and cperl-use-syntax-table-text-property
6031 (eq qtag ?\) ))
6032 (put-text-property
6033 REx-subgr-start (1- (point))
6034 'syntax-table cperl-st-punct))
6035 (cperl-postpone-fontification
6036 (1- (point)) (point) 'face
6037 ; \] can't appear below
6038 (if (memq qtag (append ".]^$" nil))
6039 'my-cperl-REx-spec-char-face
6040 (if (memq qtag (append "*?+" nil))
6041 'my-cperl-REx-0length-face
6042 'my-cperl-REx-ctl-face))))) ; )|
6043 ;; Test for arguments:
6044 (cond
6045 ;; This is not pretty: the 5.8.7 logic:
6046 ;; \0numx -> octal (up to total 3 dig)
6047 ;; \DIGIT -> backref unless \0
6048 ;; \DIGITs -> backref if legal
6049 ;; otherwise up to 3 -> octal
6050 ;; Do not try to distinguish, we guess
6051 ((or (and (memq qtag (append "01234567" nil))
6052 (re-search-forward
6053 "\\=[01234567]?[01234567]?"
6054 (1- e) 'to-end))
6055 (and (memq qtag (append "89" nil))
6056 (re-search-forward
6057 "\\=[0123456789]*" (1- e) 'to-end))
6058 (and (eq qtag ?x)
6059 (re-search-forward
6060 "\\=[0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}"
6061 (1- e) 'to-end))
6062 (and (memq qtag (append "pPN" nil))
6063 (re-search-forward "\\={[^{}]+}\\|."
6064 (1- e) 'to-end))
6065 (eq (char-syntax qtag) ?w))
6066 (cperl-postpone-fontification
6067 (1- REx-subgr-start) (point)
6068 'face my-cperl-REx-length1-face))))
6069 (setq was-subgr nil)) ; We do stuff here
6070 ((match-beginning 3) ; [charclass]
6071 (forward-char 1)
6072 (if (eq (char-after b) ?^ )
6073 (and (eq (following-char) ?\\ )
6074 (eq (char-after (cperl-1+ (point)))
6075 ?^ )
6076 (forward-char 2))
6077 (and (eq (following-char) ?^ )
6078 (forward-char 1)))
6079 (setq argument b ; continue?
6080 tag nil ; list of POSIX classes
6081 qtag (point))
6082 (if (eq (char-after b) ?\] )
6083 (and (eq (following-char) ?\\ )
6084 (eq (char-after (cperl-1+ (point)))
6085 ?\] )
6086 (setq qtag (1+ qtag))
6087 (forward-char 2))
6088 (and (eq (following-char) ?\] )
6089 (forward-char 1)))
6090 ;; Apparently, I can't put \] into a charclass
6091 ;; in m]]: m][\\\]\]] produces [\\]]
6092 ;;; POSIX? [:word:] [:^word:] only inside []
6093 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]")
6094 (while
6095 (and argument
6096 (re-search-forward
6097 (if (eq (char-after b) ?\] )
6098 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]"
6099 "\\=\\(\\\\.\\|[^]\\\\]\\)*]")
6100 (1- e) 'toend))
6101 ;; Is this ] an end of POSIX class?
6102 (if (save-excursion
6103 (and
6104 (search-backward "[" argument t)
6105 (< REx-subgr-start (point))
6106 (not
6107 (and ; Should work with delim = \
6108 (eq (preceding-char) ?\\ )
6109 (= (% (skip-chars-backward
6110 "\\\\") 2) 0)))
6111 (looking-at
6112 (cond
6113 ((eq (char-after b) ?\] )
6114 "\\\\*\\[:\\^?\\sw+:\\\\\\]")
6115 ((eq (char-after b) ?\: )
6116 "\\\\*\\[\\\\:\\^?\\sw+\\\\:]")
6117 ((eq (char-after b) ?^ )
6118 "\\\\*\\[:\\(\\\\\\^\\)?\\sw+:\]")
6119 ((eq (char-syntax (char-after b))
6121 (concat
6122 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\"
6123 (char-to-string (char-after b))
6124 "\\|\\sw\\)+:\]"))
6125 (t "\\\\*\\[:\\^?\\sw*:]")))
6126 (setq argument (point))))
6127 (setq tag (cons (cons argument (point))
6128 tag)
6129 argument (point)) ; continue
6130 (setq argument nil)))
6131 (and argument
6132 (message "Couldn't find end of charclass in a REx, pos=%s"
6133 REx-subgr-start))
6134 (if (and cperl-use-syntax-table-text-property
6135 (> (- (point) 2) REx-subgr-start))
6136 (put-text-property
6137 (1+ REx-subgr-start) (1- (point))
6138 'syntax-table cperl-st-punct))
6139 (cperl-postpone-fontification
6140 REx-subgr-start qtag
6141 'face my-cperl-REx-spec-char-face)
6142 (cperl-postpone-fontification
6143 (1- (point)) (point) 'face
6144 my-cperl-REx-spec-char-face)
6145 (if (eq (char-after b) ?\] )
6146 (cperl-postpone-fontification
6147 (- (point) 2) (1- (point))
6148 'face my-cperl-REx-0length-face))
6149 (while tag
6150 (cperl-postpone-fontification
6151 (car (car tag)) (cdr (car tag))
6152 'face my-cperl-REx-length1-face)
6153 (setq tag (cdr tag)))
6154 (setq was-subgr nil)) ; did facing already
6155 ;; Now rare stuff:
6156 ((and (match-beginning 2) ; #-comment
6157 (/= (match-beginning 2) (match-end 2)))
6158 (beginning-of-line 2)
6159 (if (> (point) e)
6160 (goto-char (1- e))))
6161 ((match-beginning 4) ; character "]"
6162 (setq was-subgr nil) ; We do stuff here
6163 (goto-char (match-end 0))
6164 (if cperl-use-syntax-table-text-property
6165 (put-text-property
6166 (1- (point)) (point)
6167 'syntax-table cperl-st-punct))
6168 (cperl-postpone-fontification
6169 (1- (point)) (point)
6170 'face font-lock-warning-face))
6171 ((match-beginning 5) ; before (?{}) (??{})
6172 (setq tag (match-end 0))
6173 (if (or (setq qtag
6174 (cperl-forward-group-in-re st-l))
6175 (and (>= (point) e)
6176 (setq qtag "no matching `)' found"))
6177 (and (not (eq (char-after (- (point) 2))
6178 ?\} ))
6179 (setq qtag "Can't find })")))
6180 (progn
6181 (goto-char (1- e))
6182 (message qtag))
6183 (cperl-postpone-fontification
6184 (1- tag) (1- (point))
6185 'face font-lock-variable-name-face)
6186 (cperl-postpone-fontification
6187 REx-subgr-start (1- tag)
6188 'face my-cperl-REx-spec-char-face)
6189 (cperl-postpone-fontification
6190 (1- (point)) (point)
6191 'face my-cperl-REx-spec-char-face)
6192 (if cperl-use-syntax-table-text-property
6193 (progn
6194 (put-text-property
6195 (- (point) 2) (1- (point))
6196 'syntax-table cperl-st-cfence)
6197 (put-text-property
6198 (+ REx-subgr-start 2)
6199 (+ REx-subgr-start 3)
6200 'syntax-table cperl-st-cfence))))
6201 (setq was-subgr nil))
6202 (t ; (?#)-comment
6203 ;; Inside "(" and "\" arn't special in any way
6204 ;; Works also if the outside delimiters are ().
6205 (or;;(if (eq (char-after b) ?\) )
6206 ;;(re-search-forward
6207 ;; "[^\\\\]\\(\\\\\\\\\\)*\\\\)"
6208 ;; (1- e) 'toend)
6209 (search-forward ")" (1- e) 'toend)
6211 (message
6212 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
6213 REx-subgr-start))))
6214 (if (>= (point) e)
6215 (goto-char (1- e)))
6216 (cond
6217 (was-subgr
6218 (setq REx-subgr-end (point))
6219 (cperl-commentify
6220 REx-subgr-start REx-subgr-end nil)
6221 (cperl-postpone-fontification
6222 REx-subgr-start REx-subgr-end
6223 'face font-lock-comment-face))))))
6224 (if (and is-REx is-x-REx)
6225 (put-text-property (1+ b) (1- e)
6226 'syntax-subtype 'x-REx)))
6227 (if i2
6228 (progn
6229 (cperl-postpone-fontification
6230 (1- e1) e1 'face my-cperl-delimiters-face)
6231 (if (assoc (char-after b) cperl-starters)
6232 (progn
6233 (cperl-postpone-fontification
6234 b1 (1+ b1) 'face my-cperl-delimiters-face)
6235 (put-text-property b1 (1+ b1)
6236 'REx-part2 t)))))
6237 (if (> (point) max)
6238 (setq tmpend tb))))
6239 ((match-beginning 17) ; sub with prototype or attribute
6240 ;; 1+6+2+1+1=11 extra () before this (sub with proto/attr):
6241 ;;"\\<sub\\>\\(" ;12
6242 ;; cperl-white-and-comment-rex ;13
6243 ;; "\\([a-zA-Z_:'0-9]+\\)\\)?" ; name ;14
6244 ;;"\\(" cperl-maybe-white-and-comment-rex ;15,16
6245 ;; "\\(([^()]*)\\|:[^:]\\)\\)" ; 17:proto or attribute start
6246 (if (not cperl-use-v6) ; perl6: for perl6 we just use ordinary highlighting in sub params
6247 (progn
6248 (setq b1 (match-beginning 14) e1 (match-end 14))
6249 (if (memq (char-after (1- b))
6250 '(?\$ ?\@ ?\% ?\& ?\*))
6252 (goto-char b)
6253 (if (eq (char-after (match-beginning 17)) ?\( )
6254 (progn
6255 (cperl-commentify ; Prototypes; mark as string
6256 (match-beginning 17) (match-end 17) t)
6257 (goto-char (match-end 0))
6258 ;; Now look for attributes after prototype:
6259 (forward-comment (buffer-size))
6260 (and (looking-at ":[^:]")
6261 (cperl-find-sub-attrs st-l b1 e1 b)))
6262 ;; treat attributes without prototype
6263 (goto-char (match-beginning 17))
6264 (cperl-find-sub-attrs st-l b1 e1 b))))))
6265 ;; 1+6+2+1+1+6+1=18 extra () before this:
6266 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
6267 ((match-beginning 19) ; old $abc'efg syntax
6268 (setq bb (match-end 0))
6269 ;;;(if (nth 3 state) nil ; in string
6270 (put-text-property (1- bb) bb 'syntax-table cperl-st-word)
6271 (goto-char bb))
6272 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
6273 ;; "__\\(END\\|DATA\\)__"
6274 ((match-beginning 20) ; __END__, __DATA__
6275 (setq bb (match-end 0))
6276 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
6277 (cperl-commentify b bb nil)
6278 (setq end t))
6279 ;; "\\\\\\(['`\"($]\\)"
6280 ((match-beginning 21)
6281 ;; Trailing backslash; make non-quoting outside string/comment
6282 (setq bb (match-end 0))
6283 (goto-char b)
6284 (skip-chars-backward "\\\\")
6285 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
6286 (cperl-modify-syntax-type b cperl-st-punct)
6287 (goto-char bb))
6288 (t (error "Error in regexp of the sniffer")))
6289 (if (> (point) stop-point)
6290 (progn
6291 (if end
6292 (message "Garbage after __END__/__DATA__ ignored")
6293 (message "Unbalanced syntax found while scanning")
6294 (or (car err-l) (setcar err-l b)))
6295 (goto-char stop-point))))
6296 (setq cperl-syntax-state (cons state-point state)
6297 ;; Do not mark syntax as done past tmpend???
6298 cperl-syntax-done-to (or tmpend (max (point) max)))
6299 ;;(message "state-at=%s, done-to=%s" state-point cperl-syntax-done-to)
6301 (if (car err-l) (goto-char (car err-l))
6302 (or non-inter
6303 (message "Scanning for \"hard\" Perl constructions... done"))))
6304 (and (buffer-modified-p)
6305 (not modified)
6306 (set-buffer-modified-p nil))
6307 (set-syntax-table cperl-mode-syntax-table))
6308 (list (car err-l) overshoot)))
6310 (defun cperl-find-pods-heres-region (min max)
6311 (interactive "r")
6312 (cperl-find-pods-heres min max))
6314 (defun cperl-backward-to-noncomment (lim)
6315 ;; Stops at lim or after non-whitespace that is not in comment
6316 ;; XXXX Wrongly understands end-of-multiline strings with # as comment
6317 (let (stop p pr)
6318 (while (and (not stop) (> (point) (or lim (point-min))))
6319 (skip-chars-backward " \t\n\f" lim)
6320 (setq p (point))
6321 (beginning-of-line)
6322 (if (memq (setq pr (get-text-property (point) 'syntax-type))
6323 '(pod here-doc here-doc-delim))
6324 (cperl-unwind-to-safe nil)
6325 (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
6326 (not (memq pr '(string prestring))))
6327 (progn (cperl-to-comment-or-eol) (bolp))
6328 (progn
6329 (skip-chars-backward " \t")
6330 (if (< p (point)) (goto-char p))
6331 (setq stop t)))))))
6333 ;; Used only in `cperl-calculate-indent'...
6334 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
6335 ;; Positions is before ?\{. Checks whether it starts a block.
6336 ;; No save-excursion! This is more a distinguisher of a block/hash ref...
6338 (and ; perl6: it's never a hash if whitespace before brace (not yet perfect)
6339 (cond (cperl-use-v6))
6340 (memq (preceding-char) (append " \t" nil)))
6341 (progn
6342 (cperl-backward-to-noncomment (point-min))
6343 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
6344 ; Label may be mixed up with `$blah :'
6345 (save-excursion (cperl-after-label))
6346 (get-text-property (cperl-1- (point)) 'attrib-group)
6347 (and (memq (char-syntax (preceding-char)) '(?w ?_))
6348 (progn
6349 (backward-sexp)
6350 ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
6351 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
6352 (not (looking-at "\\(bless\\|return\\|\\(\\(rx\\|[msy]\\|tr\\)\\s *\\(:\\([igcpw]\\|ignorecase\\|global\\(ly\\)?\\|continue\\|pos\\|once\\|words\\|bytes\\|codes\\|graphs\\|langs\\|\\|[0-9]+\\(st\\|nd\\|rd\\|th\\|x\\)\\|ov\\|overlap\\|ex\\|exhaustive\\|rw\\|P5\\|perl5\\|Perl5\\(<[a-zA-Z]+>\\)?\\|nth\\(([0-9]+)\\)?\\|x\\(([0-9]+)\\)?\\)\\s *\\)*\\):?\\)")) ;; perl6 23.06.2006
6353 (not (looking-at "\\$[a-zA-Z0-9_]+"))) ; perl6: todo: why? (topics before blockstart?); even better [$@%]?
6354 ;; sub bless::foo {}
6355 (progn
6356 (cperl-backward-to-noncomment (point-min))
6357 (and (eq (preceding-char) ?b)
6358 (progn
6359 (forward-sexp -1)
6360 (looking-at "\\(coro\\|sub\\|method\\|submethod\\)[ \t\n\f#]"))))))) ; perl6
6361 (if cperl-use-v6
6362 (progn ; perl6: "if/elsif/unless/while/until/given/when/for/loop" without parens; just look at beginning of line
6363 (beginning-of-line)
6364 (looking-at "\\s *}?\\s *\\(\\(els\\(e\\s +\\|\\)\\)?if\\|un\\(less\\|til\\)\\|given\\|wh\\(ile\\|en\\)\\|for\\|loop\\)\\>"))))))
6367 ;;; What is the difference of (cperl-after-block-p lim t) and (cperl-block-p)?
6368 ;;; No save-excursion; condition-case ... In (cperl-block-p) the block
6369 ;;; may be a part of an in-statement construct, such as
6370 ;;; ${something()}, print {FH} $data.
6371 ;;; Moreover, one takes positive approach (looks for else,grep etc)
6372 ;;; another negative (looks for bless,tr etc)
6373 (defun cperl-after-block-p (lim &optional pre-block)
6374 "Return true if the preceeding } (if PRE-BLOCK, following {) delimits a block.
6375 Would not look before LIM. Assumes that LIM is a good place to begin a
6376 statement. The kind of block we treat here is one after which a new
6377 statement would start; thus the block in ${func()} does not count."
6378 (save-excursion
6379 (condition-case nil
6380 (progn
6381 (or pre-block (forward-sexp -1))
6382 (cperl-backward-to-noncomment lim)
6383 (or (eq (point) lim)
6384 ;; if () {} // sub f () {} // sub f :a(') {}
6385 (eq (preceding-char) ?\) )
6386 ;; label: {}
6387 (save-excursion (cperl-after-label))
6388 ;; sub :attr {}
6389 (get-text-property (cperl-1- (point)) 'attrib-group)
6390 (if (memq (char-syntax (preceding-char)) '(?w ?_)) ; else {}
6392 (save-excursion
6393 (forward-sexp -1)
6394 ;; else {} but not else::func {}
6395 (or (and (looking-at "\\(else\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\|continue\\|grep\\|map\\|gather\\|async\\|atomically\\|given\\|when\\|default\\|loop\\|for\\|BEGIN\\|END\\|CHECK\\|INIT\\|START\\|FIRST\\|ENTER\\|LEAVE\\|KEEP\\|UNDO\\|NEXT\\|LAST\\|PRE\\|POST\\|CATCH\\|CONTROL\\|\\(\\(multi\\|proto\\)[ \t]*\\)?\\(coro\\|sub\\|method\\|submethod\\)?\\)\\>")
6396 (not (looking-at "\\(\\sw\\|_\\)+::")))
6397 ;; sub f {}
6398 (progn
6399 (cperl-backward-to-noncomment lim)
6400 (and (eq (preceding-char) ?b)
6401 (progn
6402 (forward-sexp -1)
6403 (looking-at "\\(coro\\|sub\\|method\\|submethod\\)[ \t\n\f#]")))))) ; perl6
6404 (save-excursion ; perl6: returns Type {} / is rw {} / is cached {} / ...
6405 (forward-sexp -2)
6406 (looking-at "\\(returns\\|of\\|is\\|does[ \t]\\(rw\\|readonly\\|ref\\|copy\\|context\\|cached\\|signature\\|parsed\\|reparsed\\|inline\\|tighter\\|looser\\|equiv\\|export\\|assoc\\|extended\\|deep\\|also\\)\\|will[ \t]do\\)\\>")))
6407 ;; What preceeds is not word... XXXX Last statement in sub???
6408 (cperl-after-expr-p lim))
6409 (save-excursion ; perl6: "if/elsif/unless/while/until/given/when/for/loop" without parens; just look at beginning of line
6410 ;; perl6: todo: correct in P5? Then use-v6'ify!
6411 (beginning-of-line)
6412 (looking-at "\\s *}?\\s *\\(\\(els\\(e\\s +\\|\\)\\)?if\\|un\\(less\\|til\\)\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\|gather\\|async\\|atomically\\|given\\|wh\\(ile\\|en\\)\\|loop\\|for\\|\\(\\(multi\\|proto\\)[ \t]*\\)?\\(coro\\|sub\\|method\\|submethod\\)?\\)\\>"))))
6413 (error nil))))
6415 (defun cperl-after-expr-p (&optional lim chars test)
6416 "Return true if the position is good for start of expression.
6417 TEST is the expression to evaluate at the found position. If absent,
6418 CHARS is a string that contains good characters to have before us (however,
6419 `}' is treated \"smartly\" if it is not in the list)."
6420 (let ((lim (or lim (point-min)))
6421 stop p pr)
6422 (cperl-update-syntaxification (point) (point))
6423 (save-excursion
6424 (while (and (not stop) (> (point) lim))
6425 (skip-chars-backward " \t\n\f" lim)
6426 (setq p (point))
6427 (beginning-of-line)
6428 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
6429 ;; '(pod here-doc here-doc-delim))
6430 (if (get-text-property (point) 'here-doc-group)
6431 (progn
6432 (goto-char
6433 (cperl-beginning-of-property (point) 'here-doc-group))
6434 (beginning-of-line 0)))
6435 (if (get-text-property (point) 'in-pod)
6436 (progn
6437 (goto-char
6438 (cperl-beginning-of-property (point) 'in-pod))
6439 (beginning-of-line 0)))
6440 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
6441 ;; Else: last iteration, or a label
6442 (cperl-to-comment-or-eol) ; Will not move past "." after a format
6443 (skip-chars-backward " \t")
6444 (if (< p (point)) (goto-char p))
6445 (setq p (point))
6446 (if (and (eq (preceding-char) ?:)
6447 (progn
6448 (forward-char -1)
6449 (skip-chars-backward " \t\n\f" lim)
6450 (memq (char-syntax (preceding-char)) '(?w ?_))))
6451 (forward-sexp -1) ; Possibly label. Skip it
6452 (goto-char p)
6453 (setq stop t))))
6454 (or (bobp) ; ???? Needed
6455 (eq (point) lim)
6456 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
6457 (progn
6458 (if test (eval test)
6459 (or (memq (preceding-char) (append (or chars "{;") nil))
6460 (and (eq (preceding-char) ?\})
6461 (cperl-after-block-p lim))
6462 (and (eq (following-char) ?.) ; in format: see comment above
6463 (eq (get-text-property (point) 'syntax-type)
6464 'format)))))))))
6466 (defun cperl-backward-to-start-of-expr (&optional lim)
6467 (condition-case nil
6468 (progn
6469 (while (and (or (not lim)
6470 (> (point) lim))
6471 (not (cperl-after-expr-p lim)))
6472 (forward-sexp -1)
6473 ;; May be after $, @, $# etc of a variable
6474 (skip-chars-backward "$@%#")))
6475 (error nil)))
6477 (defun cperl-at-end-of-expr (&optional lim)
6478 (condition-case nil
6479 (save-excursion
6480 ;; If nothing interesting after, same as (forward-sexp -1); otherwise
6481 ;; fails, or at a start of following sexp:
6482 (let ((p (point)))
6483 (forward-sexp 1)
6484 (forward-sexp -1)
6485 (or (< (point) p)
6486 (cperl-after-expr-p lim))))
6487 (error t)))
6489 (defun cperl-forward-to-end-of-expr (&optional lim)
6490 (let ((p (point))))
6491 (condition-case nil
6492 (progn
6493 (while (and (< (point) (or lim (point-max)))
6494 (not (cperl-at-end-of-expr)))
6495 (forward-sexp 1)))
6496 (error nil)))
6498 (defun cperl-backward-to-start-of-continued-exp (lim)
6499 (if (memq (preceding-char) (append ")]}\"'`" nil))
6500 (forward-sexp -1))
6501 (beginning-of-line)
6502 (if (<= (point) lim)
6503 (goto-char (1+ lim)))
6504 (skip-chars-forward " \t"))
6506 (defun cperl-after-block-and-statement-beg (lim)
6507 ;; We assume that we are after ?\}
6508 (and
6509 (cperl-after-block-p lim)
6510 (save-excursion
6511 (forward-sexp -1)
6512 (cperl-backward-to-noncomment (point-min))
6513 (or (bobp)
6514 (eq (point) lim)
6515 (not (= (char-syntax (preceding-char)) ?w))
6516 (progn
6517 (forward-sexp -1)
6518 (not
6519 (looking-at
6520 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
6523 (defvar innerloop-done nil)
6524 (defvar last-depth nil)
6526 (defun cperl-indent-exp ()
6527 "Simple variant of indentation of continued-sexp.
6529 Will not indent comment if it starts at `comment-indent' or looks like
6530 continuation of the comment on the previous line.
6532 If `cperl-indent-region-fix-constructs', will improve spacing on
6533 conditional/loop constructs."
6534 (interactive)
6535 (save-excursion
6536 (let ((tmp-end (progn (end-of-line) (point))) top done)
6537 (save-excursion
6538 (beginning-of-line)
6539 (while (null done)
6540 (setq top (point))
6541 (while (= (nth 0 (parse-partial-sexp (point) tmp-end
6542 -1)) -1)
6543 (setq top (point))) ; Get the outermost parenths in line
6544 (goto-char top)
6545 (while (< (point) tmp-end)
6546 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
6547 (or (eolp) (forward-sexp 1)))
6548 (if (> (point) tmp-end)
6549 (save-excursion
6550 (end-of-line)
6551 (setq tmp-end (point)))
6552 (setq done t)))
6553 (goto-char tmp-end)
6554 (setq tmp-end (point-marker)))
6555 (if cperl-indent-region-fix-constructs
6556 (cperl-fix-line-spacing tmp-end))
6557 (cperl-indent-region (point) tmp-end))))
6559 (defun cperl-fix-line-spacing (&optional end parse-data)
6560 "Improve whitespace in a conditional/loop construct.
6561 Returns some position at the last line."
6562 (interactive)
6563 (or end
6564 (setq end (point-max)))
6565 (let ((ee (save-excursion (end-of-line) (point)))
6566 (cperl-indent-region-fix-constructs
6567 (or cperl-indent-region-fix-constructs 1))
6568 p pp ml have-brace ret)
6569 (save-excursion
6570 (beginning-of-line)
6571 (setq ret (point))
6572 ;; }? continue
6573 ;; blah; }
6574 (if (not
6575 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\|loop\\)") ; perl6-last
6576 (setq have-brace (save-excursion (search-forward "}" ee t)))))
6577 nil ; Do not need to do anything
6578 ;; Looking at:
6579 ;; }
6580 ;; else
6581 (if (and cperl-merge-trailing-else
6582 (looking-at
6583 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>"))
6584 (progn
6585 (search-forward "}")
6586 (setq p (point))
6587 (skip-chars-forward " \t\n")
6588 (delete-region p (point))
6589 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6590 (beginning-of-line)))
6591 ;; Looking at:
6592 ;; } else
6593 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
6594 (progn
6595 (search-forward "}")
6596 (delete-horizontal-space)
6597 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6598 (beginning-of-line)))
6599 ;; Looking at:
6600 ;; else {
6601 (if (looking-at
6602 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\|loop\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]") ; perl6-last
6603 (progn
6604 (forward-word 1)
6605 (delete-horizontal-space)
6606 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6607 (beginning-of-line)))
6608 ;; Looking at:
6609 ;; foreach my $var
6610 (if (looking-at
6611 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\|state\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
6612 (progn
6613 (forward-word 2)
6614 (delete-horizontal-space)
6615 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6616 (beginning-of-line)))
6617 ;; Looking at:
6618 ;; foreach my $var (
6619 (if (looking-at
6620 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\|state\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
6621 (progn
6622 (forward-sexp 3)
6623 (delete-horizontal-space)
6624 (insert
6625 (make-string cperl-indent-region-fix-constructs ?\ ))
6626 (beginning-of-line)))
6627 ;; Looking at:
6628 ;; } foreach my $var () {
6629 (if (looking-at
6630 "[ \t]*\\(}[ \t]*\\)?\\<\\(\\els\\(e\\|if\\)\\|continue\\|if\\|unless\\|while\\|loop\\|for\\(each\\)?\\(\\([ \t]+\\(my\\|local\\|our\\|state\\)\\)?[ \t]*\\$[_a-zA-Z0-9]+\\)?\\|until\\)\\>\\([ \t]*(\\|[ \t\n]*{\\)\\|[ \t]*{") ; perl6-last
6631 (progn
6632 (setq ml (match-beginning 8))
6633 (re-search-forward "[({]")
6634 (forward-char -1)
6635 (setq p (point))
6636 (if (eq (following-char) ?\( )
6637 (progn
6638 (forward-sexp 1)
6639 (setq pp (point)))
6640 ;; after `else' or nothing
6641 (if ml ; after `else'
6642 (skip-chars-backward " \t\n")
6643 (beginning-of-line))
6644 (setq pp nil))
6645 ;; Now after the sexp before the brace
6646 ;; Multiline expr should be special
6647 (setq ml (and pp (save-excursion (goto-char p)
6648 (search-forward "\n" pp t))))
6649 (if (and (or (not pp) (< pp end))
6650 (looking-at "[ \t\n]*{"))
6651 (progn
6652 (cond
6653 ((bolp) ; Were before `{', no if/else/etc
6654 nil)
6655 ((looking-at "\\(\t*\\| [ \t]+\\){")
6656 (delete-horizontal-space)
6657 (if (if ml
6658 cperl-extra-newline-before-brace-multiline
6659 cperl-extra-newline-before-brace)
6660 (progn
6661 (delete-horizontal-space)
6662 (insert "\n")
6663 (setq ret (point))
6664 (if (cperl-indent-line parse-data)
6665 (progn
6666 (cperl-fix-line-spacing end parse-data)
6667 (setq ret (point)))))
6668 (insert
6669 (make-string cperl-indent-region-fix-constructs ?\ ))))
6670 ((and (looking-at "[ \t]*\n")
6671 (not (if ml
6672 cperl-extra-newline-before-brace-multiline
6673 cperl-extra-newline-before-brace)))
6674 (setq pp (point))
6675 (skip-chars-forward " \t\n")
6676 (delete-region pp (point))
6677 (insert
6678 (make-string cperl-indent-region-fix-constructs ?\ ))))
6679 ;; Now we are before `{'
6680 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
6681 (progn
6682 (skip-chars-forward " \t\n")
6683 (setq pp (point))
6684 (forward-sexp 1)
6685 (setq p (point))
6686 (goto-char pp)
6687 (setq ml (search-forward "\n" p t))
6688 (if (or cperl-break-one-line-blocks-when-indent ml)
6689 ;; not good: multi-line BLOCK
6690 (progn
6691 (goto-char (1+ pp))
6692 (delete-horizontal-space)
6693 (insert "\n")
6694 (setq ret (point))
6695 (if (cperl-indent-line parse-data)
6696 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
6697 (beginning-of-line)
6698 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
6699 ;; Now check whether there is a hanging `}'
6700 ;; Looking at:
6701 ;; } blah
6702 (if (and
6703 cperl-fix-hanging-brace-when-indent
6704 have-brace
6705 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
6706 (condition-case nil
6707 (progn
6708 (up-list 1)
6709 (if (and (<= (point) pp)
6710 (eq (preceding-char) ?\} )
6711 (cperl-after-block-and-statement-beg (point-min)))
6713 (goto-char p)
6714 nil))
6715 (error nil)))
6716 (progn
6717 (forward-char -1)
6718 (skip-chars-backward " \t")
6719 (if (bolp)
6720 ;; `}' was the first thing on the line, insert NL *after* it.
6721 (progn
6722 (cperl-indent-line parse-data)
6723 (search-forward "}")
6724 (delete-horizontal-space)
6725 (insert "\n"))
6726 (delete-horizontal-space)
6727 (or (eq (preceding-char) ?\;)
6728 (bolp)
6729 (and (eq (preceding-char) ?\} )
6730 (cperl-after-block-p (point-min)))
6731 (insert ";"))
6732 (insert "\n")
6733 (setq ret (point)))
6734 (if (cperl-indent-line parse-data)
6735 (setq ret (cperl-fix-line-spacing end parse-data)))
6736 (beginning-of-line)))))
6737 ret))
6739 (defvar cperl-update-start) ; Do not need to make them local
6740 (defvar cperl-update-end)
6741 (defun cperl-delay-update-hook (beg end old-len)
6742 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
6743 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
6745 (defun cperl-indent-region (start end)
6746 "Simple variant of indentation of region in CPerl mode.
6747 Should be slow. Will not indent comment if it starts at `comment-indent'
6748 or looks like continuation of the comment on the previous line.
6749 Indents all the lines whose first character is between START and END
6750 inclusive.
6752 If `cperl-indent-region-fix-constructs', will improve spacing on
6753 conditional/loop constructs."
6754 (interactive "r")
6755 (cperl-update-syntaxification end end)
6756 (save-excursion
6757 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
6758 (let ((indent-info (if cperl-emacs-can-parse
6759 (list nil nil nil) ; Cannot use '(), since will modify
6760 nil))
6761 (pm 0) (imenu-scanning-message "Indenting... (%3d%%)")
6762 after-change-functions ; Speed it up!
6763 st comm old-comm-indent new-comm-indent p pp i empty)
6764 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
6765 (goto-char start)
6766 (setq old-comm-indent (and (cperl-to-comment-or-eol)
6767 (current-column))
6768 new-comm-indent old-comm-indent)
6769 (goto-char start)
6770 (setq end (set-marker (make-marker) end)) ; indentation changes pos
6771 (or (bolp) (beginning-of-line 2))
6772 (or (fboundp 'imenu-progress-message)
6773 (message "Indenting... For feedback load `imenu'..."))
6774 (while (and (<= (point) end) (not (eobp))) ; bol to check start
6775 (and (fboundp 'imenu-progress-message)
6776 (imenu-progress-message
6777 pm (/ (* 100 (- (point) start)) (- end start -1))))
6778 (setq st (point))
6779 (if (or
6780 (setq empty (looking-at "[ \t]*\n"))
6781 (and (setq comm (looking-at "[ \t]*#"))
6782 (or (eq (current-indentation) (or old-comm-indent
6783 comment-column))
6784 (setq old-comm-indent nil))))
6785 (if (and old-comm-indent
6786 (not empty)
6787 (= (current-indentation) old-comm-indent)
6788 (not (eq (get-text-property (point) 'syntax-type) 'pod))
6789 (not (eq (get-text-property (point) 'syntax-table)
6790 cperl-st-cfence)))
6791 (let ((comment-column new-comm-indent))
6792 (indent-for-comment)))
6793 (progn
6794 (setq i (cperl-indent-line indent-info))
6795 (or comm
6796 (not i)
6797 (progn
6798 (if cperl-indent-region-fix-constructs
6799 (goto-char (cperl-fix-line-spacing end indent-info)))
6800 (if (setq old-comm-indent
6801 (and (cperl-to-comment-or-eol)
6802 (not (memq (get-text-property (point)
6803 'syntax-type)
6804 '(pod here-doc)))
6805 (not (eq (get-text-property (point)
6806 'syntax-table)
6807 cperl-st-cfence))
6808 (current-column)))
6809 (progn (indent-for-comment)
6810 (skip-chars-backward " \t")
6811 (skip-chars-backward "#")
6812 (setq new-comm-indent (current-column))))))))
6813 (beginning-of-line 2))
6814 (if (fboundp 'imenu-progress-message)
6815 (imenu-progress-message pm 100)
6816 (message nil)))
6817 ;; Now run the update hooks
6818 (and after-change-functions
6819 cperl-update-end
6820 (save-excursion
6821 (goto-char cperl-update-end)
6822 (insert " ")
6823 (delete-char -1)
6824 (goto-char cperl-update-start)
6825 (insert " ")
6826 (delete-char -1))))))
6828 ;; Stolen from lisp-mode with a lot of improvements
6830 (defun cperl-fill-paragraph (&optional justify iteration)
6831 "Like \\[fill-paragraph], but handle CPerl comments.
6832 If any of the current line is a comment, fill the comment or the
6833 block of it that point is in, preserving the comment's initial
6834 indentation and initial hashes. Behaves usually outside of comment."
6835 (interactive "P")
6836 (let (;; Non-nil if the current line contains a comment.
6837 has-comment
6838 fill-paragraph-function ; do not recurse
6839 ;; If has-comment, the appropriate fill-prefix for the comment.
6840 comment-fill-prefix
6841 ;; Line that contains code and comment (or nil)
6842 start
6843 c spaces len dc (comment-column comment-column))
6844 ;; Figure out what kind of comment we are looking at.
6845 (save-excursion
6846 (beginning-of-line)
6847 (cond
6849 ;; A line with nothing but a comment on it?
6850 ((looking-at "[ \t]*#[# \t]*")
6851 (setq has-comment t
6852 comment-fill-prefix (buffer-substring (match-beginning 0)
6853 (match-end 0))))
6855 ;; A line with some code, followed by a comment? Remember that the
6856 ;; semi which starts the comment shouldn't be part of a string or
6857 ;; character.
6858 ((cperl-to-comment-or-eol)
6859 (setq has-comment t)
6860 (looking-at "#+[ \t]*")
6861 (setq start (point) c (current-column)
6862 comment-fill-prefix
6863 (concat (make-string (current-column) ?\ )
6864 (buffer-substring (match-beginning 0) (match-end 0)))
6865 spaces (progn (skip-chars-backward " \t")
6866 (buffer-substring (point) start))
6867 dc (- c (current-column)) len (- start (point))
6868 start (point-marker))
6869 (delete-char len)
6870 (insert (make-string dc ?-))))) ; Placeholder (to avoid splitting???)
6871 (if (not has-comment)
6872 (fill-paragraph justify) ; Do the usual thing outside of comment
6873 ;; Narrow to include only the comment, and then fill the region.
6874 (save-restriction
6875 (narrow-to-region
6876 ;; Find the first line we should include in the region to fill.
6877 (if start (progn (beginning-of-line) (point))
6878 (save-excursion
6879 (while (and (zerop (forward-line -1))
6880 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
6881 ;; We may have gone to far. Go forward again.
6882 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
6883 (forward-line 1))
6884 (point)))
6885 ;; Find the beginning of the first line past the region to fill.
6886 (save-excursion
6887 (while (progn (forward-line 1)
6888 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
6889 (point)))
6890 ;; Remove existing hashes
6891 (goto-char (point-min))
6892 (while (progn (forward-line 1) (< (point) (point-max)))
6893 (skip-chars-forward " \t")
6894 (if (looking-at "#+")
6895 (progn
6896 (if (and (eq (point) (match-beginning 0))
6897 (not (eq (point) (match-end 0)))) nil
6898 (error
6899 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage"))
6900 (delete-char (- (match-end 0) (match-beginning 0))))))
6902 ;; Lines with only hashes on them can be paragraph boundaries.
6903 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
6904 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
6905 (fill-prefix comment-fill-prefix))
6906 (fill-paragraph justify)))
6907 (if (and start)
6908 (progn
6909 (goto-char start)
6910 (if (> dc 0)
6911 (progn (delete-char dc) (insert spaces)))
6912 (if (or (= (current-column) c) iteration) nil
6913 (setq comment-column c)
6914 (indent-for-comment)
6915 ;; Repeat once more, flagging as iteration
6916 (cperl-fill-paragraph justify t))))))
6919 (defun cperl-do-auto-fill ()
6920 ;; Break out if the line is short enough
6921 (if (> (save-excursion
6922 (end-of-line)
6923 (current-column))
6924 fill-column)
6925 (let ((c (save-excursion (beginning-of-line)
6926 (cperl-to-comment-or-eol) (point)))
6927 (s (memq (following-char) '(?\ ?\t))) marker)
6928 (if (>= c (point)) nil
6929 (setq marker (point-marker))
6930 (cperl-fill-paragraph)
6931 (goto-char marker)
6932 ;; Is not enough, sometimes marker is a start of line
6933 (if (bolp) (progn (re-search-forward "#+[ \t]*")
6934 (goto-char (match-end 0))))
6935 ;; Following space could have gone:
6936 (if (or (not s) (memq (following-char) '(?\ ?\t))) nil
6937 (insert " ")
6938 (backward-char 1))
6939 ;; Previous space could have gone:
6940 (or (memq (preceding-char) '(?\ ?\t)) (insert " "))))))
6942 (defun cperl-imenu-addback (lst &optional isback name)
6943 ;; We suppose that the lst is a DAG, unless the first element only
6944 ;; loops back, and ISBACK is set. Thus this function cannot be
6945 ;; applied twice without ISBACK set.
6946 (cond ((not cperl-imenu-addback) lst)
6948 (or name
6949 (setq name "+++BACK+++"))
6950 (mapcar (lambda (elt)
6951 (if (and (listp elt) (listp (cdr elt)))
6952 (progn
6953 ;; In the other order it goes up
6954 ;; one level only ;-(
6955 (setcdr elt (cons (cons name lst)
6956 (cdr elt)))
6957 (cperl-imenu-addback (cdr elt) t name))))
6958 (if isback (cdr lst) lst))
6959 lst)))
6961 (defun cperl-imenu--create-perl-index (&optional regexp)
6962 (require 'cl)
6963 (require 'imenu) ; May be called from TAGS creator
6964 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
6965 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
6966 (index-meth-alist '()) meth
6967 packages ends-ranges p marker is-proto
6968 (prev-pos 0) is-pack index index1 name (end-range 0) package)
6969 (goto-char (point-min))
6970 (if noninteractive
6971 (message "Scanning Perl for index")
6972 (imenu-progress-message prev-pos 0))
6973 (cperl-update-syntaxification (point-max) (point-max))
6974 ;; Search for the function
6975 (progn ;;save-match-data
6976 (while (re-search-forward
6977 (or regexp cperl-imenu--function-name-regexp-perl)
6978 nil t)
6979 (or noninteractive
6980 (imenu-progress-message prev-pos))
6981 ;; 2=package-group, 5=package-name 11=sub-name
6982 (cond
6983 ((and ; Skip some noise if building tags
6984 (match-beginning 5) ; package name
6985 ;;(eq (char-after (match-beginning 2)) ?p) ; package
6986 (not (save-match-data
6987 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
6988 nil)
6989 ((and
6990 (or (match-beginning 2)
6991 (match-beginning 11)) ; package or sub
6992 ;; Skip if quoted (will not skip multi-line ''-strings :-():
6993 (null (get-text-property (match-beginning 1) 'syntax-table))
6994 (null (get-text-property (match-beginning 1) 'syntax-type))
6995 (null (get-text-property (match-beginning 1) 'in-pod)))
6996 (setq is-pack (match-beginning 2))
6997 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
6998 ;; (goto-char (match-end 0))) ; Messes what follows
6999 (setq meth nil
7000 p (point))
7001 (while (and ends-ranges (>= p (car ends-ranges)))
7002 ;; delete obsolete entries
7003 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
7004 (setq package (or (car packages) "")
7005 end-range (or (car ends-ranges) 0))
7006 (if is-pack ; doing "package"
7007 (progn
7008 (if (match-beginning 5) ; named package
7009 (setq name (buffer-substring (match-beginning 5)
7010 (match-end 5))
7011 name (progn
7012 (set-text-properties 0 (length name) nil name)
7013 name)
7014 package (concat name "::")
7015 name (concat "package " name))
7016 ;; Support nameless packages
7017 (setq name "package;" package ""))
7018 (setq end-range
7019 (save-excursion
7020 (parse-partial-sexp (point) (point-max) -1) (point))
7021 ends-ranges (cons end-range ends-ranges)
7022 packages (cons package packages)))
7023 (setq is-proto
7024 (or (eq (following-char) ?\;)
7025 (eq 0 (get-text-property (point) 'attrib-group)))))
7026 ;; Skip this function name if it is a prototype declaration.
7027 (if (and is-proto (not is-pack)) nil
7028 (or is-pack
7029 (setq name
7030 (buffer-substring (match-beginning 11) (match-end 11)))
7031 (set-text-properties 0 (length name) nil name))
7032 (setq marker (make-marker))
7033 (set-marker marker (match-end (if is-pack 2 11)))
7034 (cond (is-pack nil)
7035 ((string-match "[:']" name)
7036 (setq meth t))
7037 ((> p end-range) nil)
7039 (setq name (concat package name) meth t)))
7040 (setq index (cons name marker))
7041 (if is-pack
7042 (push index index-pack-alist)
7043 (push index index-alist))
7044 (if meth (push index index-meth-alist))
7045 (push index index-unsorted-alist)))
7046 ((match-beginning 19) ; POD section
7047 (setq name (buffer-substring (match-beginning 20) (match-end 20))
7048 marker (make-marker))
7049 (set-marker marker (match-beginning 20))
7050 (set-text-properties 0 (length name) nil name)
7051 (setq name (concat (make-string
7052 (* 3 (- (char-after (match-beginning 19)) ?1))
7053 ?\ )
7054 name)
7055 index (cons name marker))
7056 (setq index1 (cons (concat "=" name) (cdr index)))
7057 (push index index-pod-alist)
7058 (push index1 index-unsorted-alist)))))
7059 (or noninteractive
7060 (imenu-progress-message prev-pos 100))
7061 (setq index-alist
7062 (if (default-value 'imenu-sort-function)
7063 (sort index-alist (default-value 'imenu-sort-function))
7064 (nreverse index-alist)))
7065 (and index-pod-alist
7066 (push (cons "+POD headers+..."
7067 (nreverse index-pod-alist))
7068 index-alist))
7069 (and (or index-pack-alist index-meth-alist)
7070 (let ((lst index-pack-alist) hier-list pack elt group name)
7071 ;; Remove "package ", reverse and uniquify.
7072 (while lst
7073 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 11))
7074 (if (assoc name hier-list) nil
7075 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
7076 (setq lst index-meth-alist)
7077 (while lst
7078 (setq elt (car lst) lst (cdr lst))
7079 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
7080 (setq pack (substring (car elt) 0 (match-beginning 0)))
7081 (if (setq group (assoc pack hier-list))
7082 (if (listp (cdr group))
7083 ;; Have some functions already
7084 (setcdr group
7085 (cons (cons (substring
7086 (car elt)
7087 (+ 2 (match-beginning 0)))
7088 (cdr elt))
7089 (cdr group)))
7090 (setcdr group (list (cons (substring
7091 (car elt)
7092 (+ 2 (match-beginning 0)))
7093 (cdr elt)))))
7094 (setq hier-list
7095 (cons (cons pack
7096 (list (cons (substring
7097 (car elt)
7098 (+ 2 (match-beginning 0)))
7099 (cdr elt))))
7100 hier-list))))))
7101 (push (cons "+Hierarchy+..."
7102 hier-list)
7103 index-alist)))
7104 (and index-pack-alist
7105 (push (cons "+Packages+..."
7106 (nreverse index-pack-alist))
7107 index-alist))
7108 (and (or index-pack-alist index-pod-alist
7109 (default-value 'imenu-sort-function))
7110 index-unsorted-alist
7111 (push (cons "+Unsorted List+..."
7112 (nreverse index-unsorted-alist))
7113 index-alist))
7114 (cperl-imenu-addback index-alist)))
7117 ;; Suggested by Mark A. Hershberger
7118 (defun cperl-outline-level ()
7119 (looking-at outline-regexp)
7120 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
7121 ;;;; 2=package-group, 5=package-name 11=sub-name 19=head-level
7122 ((match-beginning 2) 0) ; package
7123 ((match-beginning 11) 1) ; sub
7124 ((match-beginning 19)
7125 (- (char-after (match-beginning 19)) ?0)) ; headN ==> N
7126 (t 5))) ; should not happen
7129 (defvar cperl-compilation-error-regexp-alist
7130 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
7131 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
7132 2 3))
7133 "Alist that specifies how to match errors in perl output.")
7135 (if (fboundp 'eval-after-load)
7136 (eval-after-load
7137 "mode-compile"
7138 '(setq perl-compilation-error-regexp-alist
7139 cperl-compilation-error-regexp-alist)))
7142 (defun cperl-windowed-init ()
7143 "Initialization under windowed version."
7144 (if (or (featurep 'ps-print) cperl-faces-init)
7145 ;; Need to init anyway:
7146 (or cperl-faces-init (cperl-init-faces))
7147 (add-hook 'font-lock-mode-hook
7148 (function
7149 (lambda ()
7150 (if (memq major-mode '(perl-mode cperl-mode))
7151 (progn
7152 (or cperl-faces-init (cperl-init-faces)))))))
7153 (if (fboundp 'eval-after-load)
7154 (eval-after-load
7155 "ps-print"
7156 '(or cperl-faces-init (cperl-init-faces))))))
7158 (defun cperl-load-font-lock-keywords ()
7159 (or cperl-faces-init (cperl-init-faces))
7160 perl-font-lock-keywords)
7162 (defun cperl-load-font-lock-keywords-1 ()
7163 (or cperl-faces-init (cperl-init-faces))
7164 perl-font-lock-keywords-1)
7166 (defun cperl-load-font-lock-keywords-2 ()
7167 (or cperl-faces-init (cperl-init-faces))
7168 perl-font-lock-keywords-2)
7170 (defvar perl-font-lock-keywords-1 nil
7171 "Additional expressions to highlight in Perl mode. Minimal set.")
7172 (defvar perl-font-lock-keywords nil
7173 "Additional expressions to highlight in Perl mode. Default set.")
7174 (defvar perl-font-lock-keywords-2 nil
7175 "Additional expressions to highlight in Perl mode. Maximal set.")
7177 (defvar font-lock-background-mode)
7178 (defvar font-lock-display-type)
7179 (defun cperl-init-faces-weak ()
7180 ;; Allow `cperl-find-pods-heres' to run.
7181 (or (boundp 'font-lock-constant-face)
7182 (cperl-force-face font-lock-constant-face
7183 "Face for constant and label names"))
7184 (or (boundp 'font-lock-warning-face)
7185 (cperl-force-face font-lock-warning-face
7186 "Face for things which should stand out"))
7187 ;;(setq font-lock-constant-face 'font-lock-constant-face)
7190 (defun cperl-init-faces ()
7191 (condition-case errs
7192 (progn
7193 (require 'font-lock)
7194 (and (fboundp 'font-lock-fontify-anchored-keywords)
7195 (featurep 'font-lock-extra)
7196 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
7197 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
7198 (if (fboundp 'font-lock-fontify-anchored-keywords)
7199 (setq font-lock-anchored t))
7200 (setq
7201 t-font-lock-keywords
7202 (list
7203 (list "[ \t]+$" 0 cperl-invalid-face t)
7204 (cons
7205 (concat
7206 "\\(^\\|[^$@%&\\]\\)\\<\\("
7207 (mapconcat
7208 'identity
7209 '("if" "until" "while" "elsif" "else" "unless" "for"
7210 "foreach" "continue" "exit" "die" "last" "loop" "goto" "next"
7211 "redo" "return" "local" "exec" "sub" "do" "dump" "use" "our" "state"
7212 "require" "package" "eval" "my" "BEGIN" "END" "CHECK"
7213 "INIT" "START" "FIRST" "ENTER" "LEAVE" "KEEP"
7214 "UNDO" "NEXT" "LAST" "PRE" "POST" "CATCH" "CONTROL"
7215 "given" "when" "default" "has" "returns" "of" "is" "does"
7216 "\\(\\(multi\\|proto\\)[ \t]*\\)?\\(coro\\|sub\\|method\\|submethod\\)?"
7217 "class" "module" "role" "try")
7218 "\\|") ; Flow control
7219 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
7220 ; In what follows we use `type' style
7221 ; for overwritable builtins
7222 (list
7223 (concat
7224 "\\(^\\|[^$@%&\\]\\)\\<\\("
7225 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm" "all" "as"
7226 ;; "and" "any" "atan2" "bind" "binmode" "bless" "caller"
7227 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
7228 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
7229 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
7230 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
7231 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
7232 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
7233 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
7234 ;; "gethostbyname" "gethostent" "getlogin"
7235 ;; "getnetbyaddr" "getnetbyname" "getnetent"
7236 ;; "getpeername" "getpgrp" "getppid" "getpriority"
7237 ;; "getprotobyname" "getprotobynumber" "getprotoent"
7238 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
7239 ;; "getservbyport" "getservent" "getsockname"
7240 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
7241 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
7242 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
7243 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
7244 ;; "not" "none" "oct" "one" "open" "opendir" "or" "ord" "pack" "perl" "pipe"
7245 ;; "quotemeta" "rand" "read" "readdir" "readline"
7246 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
7247 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
7248 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
7249 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
7250 ;; "setpriority" "setprotoent" "setpwent" "setservent"
7251 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
7252 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
7253 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
7254 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
7255 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
7256 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
7257 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
7258 "a\\(bs\\|ccept\\|tan2\\|l\\(arm\\|l\\)\\|n\\(d\\|y\\)\\|s\\)\\|"
7259 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
7260 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
7261 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
7262 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
7263 "e\\(rr\\|x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
7264 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
7265 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
7266 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
7267 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
7268 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
7269 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
7270 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
7271 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
7272 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
7273 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
7274 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
7275 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|o\\(ne\\|t\\)\\)\\|o\\(pen\\(\\|dir\\)\\|ne\\|"
7276 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\|erl\\)\\|quotemeta\\|"
7277 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
7278 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
7279 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
7280 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
7281 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
7282 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
7283 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
7284 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
7285 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
7286 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
7287 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
7288 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
7289 "\\)\\>") 2 'font-lock-type-face)
7290 (list ;; perl6
7291 (concat
7292 "\\(^\\|[^$@%&\\]\\)\\<\\("
7293 ;; the builtin types:
7294 ;; bit" "int" "str" "num" "ref" "bool" "Any" "Bit" "Int" "Str" "Num" "Ref"
7295 ;; Complex Exception Seq Range Set Junction Pair Mapping Signature Capture "
7296 ;; Bag\\|Mapping\\|Blob\\|KeyHash\\|KeySet\\|KeyBag\\|Buf\\|Regex\\|Match\\|Any\\|"
7297 ;; Bool" "Array" "Hash" "IO" "Code" "Routine" "Sub" "Method" "Submethod"
7298 ;; Macro" "Rule" "Block" "Bare" "Parametric" "Package" "Module" "Class" "Role"
7299 ;; Object" "Grammar" "List" "Lazy" "Eager"
7300 ;; Real" "Scalar" "int8" "Socket"
7301 "bit\\|int\\|str\\|num\\|ref\\|bool\\|Any\\|Bit\\|Int\\|Str\\|Num\\|Ref\\|"
7302 "Complex\\|Exception\\|Seq\\|Range\\|Set\\|Junction\\|Pair\\|Mapping\\|Signature\\|Capture\\|"
7303 "Bag\\|Mapping\\|Blob\\|KeyHash\\|KeySet\\|KeyBag\\|Buf\\|Regex\\|Match\\|Any\\|"
7304 "Bool\\|Array\\|Hash\\|IO\\|Code\\|Routine\\|Sub\\|Method\\|Submethod\\|"
7305 "Macro\\|Rule\\|Block\\|Bare\\|Parametric\\|Package\\|Module\\|Class\\|Role\\|"
7306 "Object\\|Grammar\\|List\\|Lazy\\|Eager\\|"
7307 "Real\\|Scalar\\|int8\\|Socket\\|"
7308 "rw\\|readonly\\|ref\\|copy\\|context\\|cached\\|signature\\|parsed\\|reparsed\\|inline\\|"
7309 "tighter\\|looser\\|equiv\\|export\\|extended\\|deep\\|also"
7310 "\\)\\>") 2 'font-lock-type-face)
7311 ;; In what follows we use `other' style
7312 ;; for nonoverwritable builtins
7313 ;; Somehow 's', 'm' are not auto-generated???
7314 (list
7315 (concat
7316 "\\(^\\|[^$@%&\\]\\)\\<\\("
7317 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "async" "atomically" "chomp"
7318 ;; "chop" "class" "coro" "defined" "delete" "do" "each" "else" "elsif"
7319 ;; "eval" "exists" "for" "foreach" "format" "gather" "grammar" "goto"
7320 ;; "grep" "has" "if" "keys" "kv" "last" "local" "loop" "map" "my" "next"
7321 ;; "no" "our" "pairs" "package" "pop" "pos" "pick" "print" "printf" "push"
7322 ;; "q" "qq" "qw" "qx" "redo" "rx" "reduce" "regex" "return" "role" "rule" "say" "scalar" "shift"
7323 ;; "sort" "splice" "split" "study" "state" "sum" "take" "taken" "type" "token" "sub" "tie" "tr"
7324 ;; "undef" "uniq" "unless" "unshift" "untie" "until" "uniq" "use"
7325 ;; "while" "y" "zip"
7326 "AUTOLOAD\\|BEGIN\\|CHECK\\|a\\(sync\\|tomically\\)\\|c\\(lass\\|ho\\(p\\|mp\\)\\|oro\\)\\|d\\(e\\(fined\\|lete\\)\\|"
7327 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
7328 "END\\|for\\(\\|each\\|mat\\)\\|g\\(ather\\|r\\(ep\\|ammar\\)\\|oto\\)\\|has\\|INIT\\|if\\|k\\(eys\\|v\\)\\|"
7329 "l\\(ast\\|o\\(cal\\|op\\)\\)\\|m\\(a\\(p\\|x\\)\\|in\\|odule\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
7330 "p\\(a\\(ckage\\|irs\\)\\|ick\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
7331 "q\\(\\|q\\|w\\|x\\|r\\)\\|rx\\|re\\(gex\\|turn\\|d\\(o\\|uce\\)\\)\\|r\\(o\\|u\\)le\\|s\\(ay\\|pli\\(ce\\|t\\)\\|"
7332 "calar\\|t\\(udy\\|ate\\)\\|u\\(b\\|m\\)\\|hift\\|ort\\)\\|t\\(r\\|ie\\|ype\\|oken\\|aken?\\)\\|"
7333 "u\\(se\\|n\\(iq\\|shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
7334 "while\\|y\\|zip\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
7335 "\\|[sm]" ; Added manually
7336 "\\)\\>") 2 'cperl-nonoverridable-face)
7337 ;; (mapconcat 'identity
7338 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
7339 ;; "#include" "#define" "#undef")
7340 ;; "\\|")
7341 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
7342 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
7343 ;; This highlights declarations and definitions differenty.
7344 ;; We do not try to highlight in the case of attributes:
7345 ;; it is already done by `cperl-find-pods-heres'
7346 (list (concat "\\<\\(\\(multi\\|proto\\)[ \t]*\\)?\\(coro\\|sub\\|method\\|submethod\\)?" ; perl6: multi|proto sub methods
7347 cperl-white-and-comment-rex ; whitespace/comments
7348 "\\([^ \n\t{;()]+\\)" ; 5=name (assume non-anonymous)
7349 "\\("
7350 cperl-maybe-white-and-comment-rex ;whitespace/comments?
7351 "([^()]*)\\)?" ; prototype
7352 cperl-maybe-white-and-comment-rex ; whitespace/comments?
7353 "\\(returns[ \t]+.*\\)?" ; perl6: returns
7354 cperl-maybe-white-and-comment-rex ; whitespace/comments?
7355 "[{;]")
7356 5 (if cperl-font-lock-multiline
7357 '(if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
7358 'font-lock-function-name-face
7359 'font-lock-variable-name-face)
7360 ;; need to manually set 'multiline' for older font-locks
7361 '(progn
7362 (if (< 1 (count-lines (match-beginning 0)
7363 (match-end 0)))
7364 (put-text-property
7365 (+ 3 (match-beginning 0)) (match-end 0)
7366 'syntax-type 'multiline))
7367 (if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
7368 'font-lock-function-name-face
7369 'font-lock-variable-name-face))))
7370 '("\\<\\(package\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
7371 2 font-lock-function-name-face)
7372 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
7373 1 font-lock-function-name-face)
7374 (cond ((featurep 'font-lock-extra)
7375 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7376 (2 font-lock-string-face t)
7377 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
7378 (font-lock-anchored
7379 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7380 (2 font-lock-string-face t)
7381 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7382 nil nil
7383 (1 font-lock-string-face t))))
7384 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7385 2 font-lock-string-face t)))
7386 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
7387 font-lock-string-face t)
7388 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
7389 font-lock-constant-face) ; labels
7390 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
7391 2 font-lock-constant-face)
7392 ;; Uncomment to get perl-mode-like vars
7393 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
7394 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
7395 ;;; (2 (cons font-lock-variable-name-face '(underline))))
7396 (cond ((featurep 'font-lock-extra)
7397 '("^[ \t]*\\(has\\|my\\|local\\|our\\|state\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
7398 (3 font-lock-variable-name-face)
7399 (4 '(another 4 nil
7400 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
7401 (1 font-lock-variable-name-face)
7402 (2 '(restart 2 nil) nil t)))
7403 nil t))) ; local variables, multiple
7404 (font-lock-anchored
7405 ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
7406 (` ((, (concat "\\<\\(has\\|my\\|local\\|our\\|state\\)"
7407 cperl-maybe-white-and-comment-rex
7408 "\\(("
7409 cperl-maybe-white-and-comment-rex
7410 "\\)?\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
7411 (5 (, (if cperl-font-lock-multiline
7412 'font-lock-variable-name-face
7413 '(progn (setq cperl-font-lock-multiline-start
7414 (match-beginning 0))
7415 'font-lock-variable-name-face))))
7416 ((, (concat "\\="
7417 cperl-maybe-white-and-comment-rex
7419 cperl-maybe-white-and-comment-rex
7420 "\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
7421 ;; Bug in font-lock: limit is used not only to limit
7422 ;; searches, but to set the "extend window for
7423 ;; facification" property. Thus we need to minimize.
7424 (, (if cperl-font-lock-multiline
7425 '(if (match-beginning 3)
7426 (save-excursion
7427 (goto-char (match-beginning 3))
7428 (condition-case nil
7429 (forward-sexp 1)
7430 (error
7431 (condition-case nil
7432 (forward-char 200)
7433 (error nil)))) ; typeahead
7434 (1- (point))) ; report limit
7435 (forward-char -2)) ; disable continued expr
7436 '(if (match-beginning 3)
7437 (point-max) ; No limit for continuation
7438 (forward-char -2)))) ; disable continued expr
7439 (, (if cperl-font-lock-multiline
7441 '(progn ; Do at end
7442 ;; "my" may be already fontified (POD),
7443 ;; so cperl-font-lock-multiline-start is nil
7444 (if (or (not cperl-font-lock-multiline-start)
7445 (> 2 (count-lines
7446 cperl-font-lock-multiline-start
7447 (point))))
7449 (put-text-property
7450 (1+ cperl-font-lock-multiline-start) (point)
7451 'syntax-type 'multiline))
7452 (setq cperl-font-lock-multiline-start nil))))
7453 (3 font-lock-variable-name-face)))))
7454 (t '("^[ \t{}]*\\(has\\|my\\|local\\|our\\|state\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
7455 3 font-lock-variable-name-face)))
7456 '("\\<for\\(each\\)?\\([ \t]+\\(has\\|my\\|local\\|our\\|state\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
7457 4 font-lock-variable-name-face)))
7458 (if (not cperl-use-v6)
7459 (setq
7460 t-font-lock-keywords-1
7461 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
7462 ;; not yet as of XEmacs 19.12, works with 21.1.11
7464 (not cperl-xemacs-p)
7465 (string< "21.1.9" emacs-version)
7466 (and (string< "21.1.10" emacs-version)
7467 (string< emacs-version "21.1.2")))
7469 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
7470 (if (eq (char-after (match-beginning 2)) ?%)
7471 cperl-hash-face
7472 cperl-array-face)
7473 t) ; arrays and hashes
7474 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
7476 (if (= (- (match-end 2) (match-beginning 2)) 1)
7477 (if (eq (char-after (match-beginning 3)) ?{)
7478 cperl-hash-face
7479 cperl-array-face) ; arrays and hashes
7480 font-lock-variable-name-face)) ; Just to put something
7481 ("\\(@\\|\\$#\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
7482 (1 cperl-array-face)
7483 (2 font-lock-variable-name-face))
7484 ("\\(%\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
7485 (1 cperl-hash-face)
7486 (2 font-lock-variable-name-face))
7487 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
7488 ;;; Too much noise from \s* @s[ and friends
7489 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
7490 ;;(3 font-lock-function-name-face t t)
7491 ;;(4
7492 ;; (if (cperl-slash-is-regexp)
7493 ;; font-lock-function-name-face 'default) nil t))
7495 (setq ; perl6: no whitespace allowed before subscripts in Perl6
7496 t-font-lock-keywords-1
7497 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
7498 ;; not yet as of XEmacs 19.12, works with 21.1.11
7500 (not cperl-xemacs-p)
7501 (string< "21.1.9" emacs-version)
7502 (and (string< "21.1.10" emacs-version)
7503 (string< emacs-version "21.1.2")))
7505 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:.^*+?=!][a-zA-Z0-9_:]*\\)" 1 ; perl6: Twigils %.name %:name %^name, %*name, %+name, %?name, %=name, %!name
7506 (if (eq (char-after (match-beginning 2)) ?%)
7507 cperl-hash-face
7508 cperl-array-face)
7509 t) ; arrays and hashes
7510 ("\\(\\([$@]+\\)[a-zA-Z_:.^*+?=!][a-zA-Z0-9_:]*\\)\\([[{]\\)" ; perl6: Twigils $.name $:name $^name, $*name, $+name, $?name, $=name, $!name
7512 (if (= (- (match-end 2) (match-beginning 2)) 1)
7513 (if (eq (char-after (match-beginning 3)) ?{)
7514 cperl-hash-face
7515 cperl-array-face) ; arrays and hashes
7516 font-lock-variable-name-face)) ; Just to put something
7517 ))))
7519 (if cperl-highlight-variables-indiscriminately
7520 (setq t-font-lock-keywords-1
7521 (append t-font-lock-keywords-1
7522 (list '("[$*][{:.^*+?=!]?\\(\\sw+\\)" 1 ; perl6: Twigils $.name $:name $^name, $*name, $+name, $?name, $=name, $!name
7523 font-lock-variable-name-face)))))
7524 (setq perl-font-lock-keywords-1
7525 (if cperl-syntaxify-by-font-lock
7526 (cons 'cperl-fontify-update
7527 t-font-lock-keywords)
7528 t-font-lock-keywords)
7529 perl-font-lock-keywords perl-font-lock-keywords-1
7530 perl-font-lock-keywords-2 (append
7531 perl-font-lock-keywords-1
7532 t-font-lock-keywords-1)))
7533 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
7534 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
7535 (eval ; Avoid a warning
7536 '(font-lock-require-faces
7537 (list
7538 ;; Color-light Color-dark Gray-light Gray-dark Mono
7539 (list 'font-lock-comment-face
7540 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
7542 [nil nil t t t]
7543 [nil nil t t t]
7544 nil)
7545 (list 'font-lock-string-face
7546 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
7549 [nil nil t t t]
7550 nil)
7551 (list 'font-lock-function-name-face
7552 (vector
7553 "Blue" "LightSkyBlue" "Gray50" "LightGray"
7554 (cdr (assq 'background-color ; if mono
7555 (frame-parameters))))
7556 (vector
7557 nil nil nil nil
7558 (cdr (assq 'foreground-color ; if mono
7559 (frame-parameters))))
7560 [nil nil t t t]
7562 nil)
7563 (list 'font-lock-variable-name-face
7564 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
7566 [nil nil t t t]
7567 [nil nil t t t]
7568 nil)
7569 (list 'font-lock-type-face
7570 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
7572 [nil nil t t t]
7574 [nil nil t t t])
7575 (list 'font-lock-warning-face
7576 ["Pink" "Red" "Gray50" "LightGray"]
7577 ["gray20" "gray90"
7578 "gray80" "gray20"]
7579 [nil nil t t t]
7581 [nil nil t t t]
7583 (list 'font-lock-constant-face
7584 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
7586 [nil nil t t t]
7588 [nil nil t t t])
7589 (list 'cperl-nonoverridable-face
7590 ["chartreuse3" ("orchid1" "orange")
7591 nil "Gray80"]
7592 [nil nil "gray90"]
7593 [nil nil nil t t]
7594 [nil nil t t]
7595 [nil nil t t t])
7596 (list 'cperl-array-face
7597 ["blue" "yellow" nil "Gray80"]
7598 ["lightyellow2" ("navy" "os2blue" "darkgreen")
7599 "gray90"]
7602 nil)
7603 (list 'cperl-hash-face
7604 ["red" "red" nil "Gray80"]
7605 ["lightyellow2" ("navy" "os2blue" "darkgreen")
7606 "gray90"]
7609 nil))))
7610 ;; Do it the dull way, without choose-color
7611 (defvar cperl-guessed-background nil
7612 "Display characteristics as guessed by cperl.")
7613 ;; (or (fboundp 'x-color-defined-p)
7614 ;; (defalias 'x-color-defined-p
7615 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
7616 ;; ;; XEmacs >= 19.12
7617 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
7618 ;; ;; XEmacs 19.11
7619 ;; (t 'x-valid-color-name-p))))
7620 (cperl-force-face font-lock-constant-face
7621 "Face for constant and label names")
7622 (cperl-force-face font-lock-variable-name-face
7623 "Face for variable names")
7624 (cperl-force-face font-lock-type-face
7625 "Face for data types")
7626 (cperl-force-face cperl-nonoverridable-face
7627 "Face for data types from another group")
7628 (cperl-force-face font-lock-warning-face
7629 "Face for things which should stand out")
7630 (cperl-force-face font-lock-comment-face
7631 "Face for comments")
7632 (cperl-force-face font-lock-function-name-face
7633 "Face for function names")
7634 (cperl-force-face cperl-hash-face
7635 "Face for hashes")
7636 (cperl-force-face cperl-array-face
7637 "Face for arrays")
7638 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
7639 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
7640 ;;(or (boundp 'font-lock-type-face)
7641 ;; (defconst font-lock-type-face
7642 ;; 'font-lock-type-face
7643 ;; "Face to use for data types."))
7644 ;;(or (boundp 'cperl-nonoverridable-face)
7645 ;; (defconst cperl-nonoverridable-face
7646 ;; 'cperl-nonoverridable-face
7647 ;; "Face to use for data types from another group."))
7648 ;;(if (not cperl-xemacs-p) nil
7649 ;; (or (boundp 'font-lock-comment-face)
7650 ;; (defconst font-lock-comment-face
7651 ;; 'font-lock-comment-face
7652 ;; "Face to use for comments."))
7653 ;; (or (boundp 'font-lock-keyword-face)
7654 ;; (defconst font-lock-keyword-face
7655 ;; 'font-lock-keyword-face
7656 ;; "Face to use for keywords."))
7657 ;; (or (boundp 'font-lock-function-name-face)
7658 ;; (defconst font-lock-function-name-face
7659 ;; 'font-lock-function-name-face
7660 ;; "Face to use for function names.")))
7661 (if (and
7662 (not (cperl-is-face 'cperl-array-face))
7663 (cperl-is-face 'font-lock-emphasized-face))
7664 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
7665 (if (and
7666 (not (cperl-is-face 'cperl-hash-face))
7667 (cperl-is-face 'font-lock-other-emphasized-face))
7668 (copy-face 'font-lock-other-emphasized-face
7669 'cperl-hash-face))
7670 (if (and
7671 (not (cperl-is-face 'cperl-nonoverridable-face))
7672 (cperl-is-face 'font-lock-other-type-face))
7673 (copy-face 'font-lock-other-type-face
7674 'cperl-nonoverridable-face))
7675 ;;(or (boundp 'cperl-hash-face)
7676 ;; (defconst cperl-hash-face
7677 ;; 'cperl-hash-face
7678 ;; "Face to use for hashes."))
7679 ;;(or (boundp 'cperl-array-face)
7680 ;; (defconst cperl-array-face
7681 ;; 'cperl-array-face
7682 ;; "Face to use for arrays."))
7683 ;; Here we try to guess background
7684 (let ((background
7685 (if (boundp 'font-lock-background-mode)
7686 font-lock-background-mode
7687 'light))
7688 (face-list (and (fboundp 'face-list) (face-list))))
7689 ;;;; (fset 'cperl-is-face
7690 ;;;; (cond ((fboundp 'find-face)
7691 ;;;; (symbol-function 'find-face))
7692 ;;;; (face-list
7693 ;;;; (function (lambda (face) (member face face-list))))
7694 ;;;; (t
7695 ;;;; (function (lambda (face) (boundp face))))))
7696 (defvar cperl-guessed-background
7697 (if (and (boundp 'font-lock-display-type)
7698 (eq font-lock-display-type 'grayscale))
7699 'gray
7700 background)
7701 "Background as guessed by CPerl mode")
7702 (and (not (cperl-is-face 'font-lock-constant-face))
7703 (cperl-is-face 'font-lock-reference-face)
7704 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
7705 (if (cperl-is-face 'font-lock-type-face) nil
7706 (copy-face 'default 'font-lock-type-face)
7707 (cond
7708 ((eq background 'light)
7709 (set-face-foreground 'font-lock-type-face
7710 (if (x-color-defined-p "seagreen")
7711 "seagreen"
7712 "sea green")))
7713 ((eq background 'dark)
7714 (set-face-foreground 'font-lock-type-face
7715 (if (x-color-defined-p "os2pink")
7716 "os2pink"
7717 "pink")))
7719 (set-face-background 'font-lock-type-face "gray90"))))
7720 (if (cperl-is-face 'cperl-nonoverridable-face)
7722 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
7723 (cond
7724 ((eq background 'light)
7725 (set-face-foreground 'cperl-nonoverridable-face
7726 (if (x-color-defined-p "chartreuse3")
7727 "chartreuse3"
7728 "chartreuse")))
7729 ((eq background 'dark)
7730 (set-face-foreground 'cperl-nonoverridable-face
7731 (if (x-color-defined-p "orchid1")
7732 "orchid1"
7733 "orange")))))
7734 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
7735 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
7736 ;;; (cond
7737 ;;; ((eq background 'light)
7738 ;;; (set-face-background 'font-lock-other-emphasized-face
7739 ;;; (if (x-color-defined-p "lightyellow2")
7740 ;;; "lightyellow2"
7741 ;;; (if (x-color-defined-p "lightyellow")
7742 ;;; "lightyellow"
7743 ;;; "light yellow"))))
7744 ;;; ((eq background 'dark)
7745 ;;; (set-face-background 'font-lock-other-emphasized-face
7746 ;;; (if (x-color-defined-p "navy")
7747 ;;; "navy"
7748 ;;; (if (x-color-defined-p "darkgreen")
7749 ;;; "darkgreen"
7750 ;;; "dark green"))))
7751 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
7752 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
7753 ;;; (copy-face 'bold 'font-lock-emphasized-face)
7754 ;;; (cond
7755 ;;; ((eq background 'light)
7756 ;;; (set-face-background 'font-lock-emphasized-face
7757 ;;; (if (x-color-defined-p "lightyellow2")
7758 ;;; "lightyellow2"
7759 ;;; "lightyellow")))
7760 ;;; ((eq background 'dark)
7761 ;;; (set-face-background 'font-lock-emphasized-face
7762 ;;; (if (x-color-defined-p "navy")
7763 ;;; "navy"
7764 ;;; (if (x-color-defined-p "darkgreen")
7765 ;;; "darkgreen"
7766 ;;; "dark green"))))
7767 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
7768 (if (cperl-is-face 'font-lock-variable-name-face) nil
7769 (copy-face 'italic 'font-lock-variable-name-face))
7770 (if (cperl-is-face 'font-lock-constant-face) nil
7771 (copy-face 'italic 'font-lock-constant-face))))
7772 (setq cperl-faces-init t))
7773 (error (message "cperl-init-faces (ignored): %s" errs))))
7776 (defun cperl-ps-print-init ()
7777 "Initialization of `ps-print' components for faces used in CPerl."
7778 (eval-after-load "ps-print"
7779 '(setq ps-bold-faces
7780 ;; font-lock-variable-name-face
7781 ;; font-lock-constant-face
7782 (append '(cperl-array-face
7783 cperl-hash-face)
7784 ps-bold-faces)
7785 ps-italic-faces
7786 ;; font-lock-constant-face
7787 (append '(cperl-nonoverridable-face
7788 cperl-hash-face)
7789 ps-italic-faces)
7790 ps-underlined-faces
7791 ;; font-lock-type-face
7792 (append '(cperl-array-face
7793 cperl-hash-face
7794 underline
7795 cperl-nonoverridable-face)
7796 ps-underlined-faces))))
7798 (defvar ps-print-face-extension-alist)
7800 (defun cperl-ps-print (&optional file)
7801 "Pretty-print in CPerl style.
7802 If optional argument FILE is an empty string, prints to printer, otherwise
7803 to the file FILE. If FILE is nil, prompts for a file name.
7805 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
7806 (interactive)
7807 (or file
7808 (setq file (read-from-minibuffer
7809 "Print to file (if empty - to printer): "
7810 (concat (buffer-file-name) ".ps")
7811 nil nil 'file-name-history)))
7812 (or (> (length file) 0)
7813 (setq file nil))
7814 (require 'ps-print) ; To get ps-print-face-extension-alist
7815 (let ((ps-print-color-p t)
7816 (ps-print-face-extension-alist ps-print-face-extension-alist))
7817 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
7818 (ps-print-buffer-with-faces file)))
7820 ;;; (defun cperl-ps-print-init ()
7821 ;;; "Initialization of `ps-print' components for faces used in CPerl."
7822 ;;; ;; Guard against old versions
7823 ;;; (defvar ps-underlined-faces nil)
7824 ;;; (defvar ps-bold-faces nil)
7825 ;;; (defvar ps-italic-faces nil)
7826 ;;; (setq ps-bold-faces
7827 ;;; (append '(font-lock-emphasized-face
7828 ;;; cperl-array-face
7829 ;;; font-lock-keyword-face
7830 ;;; font-lock-variable-name-face
7831 ;;; font-lock-constant-face
7832 ;;; font-lock-reference-face
7833 ;;; font-lock-other-emphasized-face
7834 ;;; cperl-hash-face)
7835 ;;; ps-bold-faces))
7836 ;;; (setq ps-italic-faces
7837 ;;; (append '(cperl-nonoverridable-face
7838 ;;; font-lock-constant-face
7839 ;;; font-lock-reference-face
7840 ;;; font-lock-other-emphasized-face
7841 ;;; cperl-hash-face)
7842 ;;; ps-italic-faces))
7843 ;;; (setq ps-underlined-faces
7844 ;;; (append '(font-lock-emphasized-face
7845 ;;; cperl-array-face
7846 ;;; font-lock-other-emphasized-face
7847 ;;; cperl-hash-face
7848 ;;; cperl-nonoverridable-face font-lock-type-face)
7849 ;;; ps-underlined-faces))
7850 ;;; (cons 'font-lock-type-face ps-underlined-faces))
7853 (if (cperl-enable-font-lock) (cperl-windowed-init))
7855 (defconst cperl-styles-entries
7856 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
7857 cperl-label-offset cperl-extra-newline-before-brace
7858 cperl-merge-trailing-else
7859 cperl-continued-statement-offset))
7861 (defconst cperl-style-alist
7862 '(("CPerl" ; =GNU without extra-newline-before-brace
7863 (cperl-indent-level . 2)
7864 (cperl-brace-offset . 0)
7865 (cperl-continued-brace-offset . 0)
7866 (cperl-label-offset . -2)
7867 (cperl-extra-newline-before-brace . nil)
7868 (cperl-merge-trailing-else . t)
7869 (cperl-continued-statement-offset . 2))
7870 ("PerlStyle" ; CPerl with 4 as indent
7871 (cperl-indent-level . 4)
7872 (cperl-brace-offset . 0)
7873 (cperl-continued-brace-offset . 0)
7874 (cperl-label-offset . -4)
7875 (cperl-extra-newline-before-brace . nil)
7876 (cperl-merge-trailing-else . t)
7877 (cperl-continued-statement-offset . 4))
7878 ("Pugs"
7879 (indent-tabs-mode . nil)
7880 (cperl-indent-level . 4)
7881 (cperl-brace-offset . 0)
7882 (cperl-continued-brace-offset . -4)
7883 (cperl-label-offset . -4)
7884 (cperl-extra-newline-before-brace . nil)
7885 (cperl-merge-trailing-else . t)
7886 (cperl-continued-statement-offset . 4))
7887 ("GNU"
7888 (cperl-indent-level . 2)
7889 (cperl-brace-offset . 0)
7890 (cperl-continued-brace-offset . 0)
7891 (cperl-label-offset . -2)
7892 (cperl-extra-newline-before-brace . t)
7893 (cperl-merge-trailing-else . nil)
7894 (cperl-continued-statement-offset . 2))
7895 ("K&R"
7896 (cperl-indent-level . 5)
7897 (cperl-brace-offset . 0)
7898 (cperl-continued-brace-offset . -5)
7899 (cperl-label-offset . -5)
7900 ;;(cperl-extra-newline-before-brace . nil) ; ???
7901 (cperl-merge-trailing-else . nil)
7902 (cperl-continued-statement-offset . 5))
7903 ("BSD"
7904 (cperl-indent-level . 4)
7905 (cperl-brace-offset . 0)
7906 (cperl-continued-brace-offset . -4)
7907 (cperl-label-offset . -4)
7908 ;;(cperl-extra-newline-before-brace . nil) ; ???
7909 (cperl-continued-statement-offset . 4))
7910 ("C++"
7911 (cperl-indent-level . 4)
7912 (cperl-brace-offset . 0)
7913 (cperl-continued-brace-offset . -4)
7914 (cperl-label-offset . -4)
7915 (cperl-continued-statement-offset . 4)
7916 (cperl-merge-trailing-else . nil)
7917 (cperl-extra-newline-before-brace . t))
7918 ("Current")
7919 ("Whitesmith"
7920 (cperl-indent-level . 4)
7921 (cperl-brace-offset . 0)
7922 (cperl-continued-brace-offset . 0)
7923 (cperl-label-offset . -4)
7924 ;;(cperl-extra-newline-before-brace . nil) ; ???
7925 (cperl-continued-statement-offset . 4)))
7926 "(Experimental) list of variables to set to get a particular indentation style.
7927 Should be used via `cperl-set-style' or via Perl menu.")
7929 (defun cperl-set-style (style)
7930 "Set CPerl mode variables to use one of several different indentation styles.
7931 The arguments are a string representing the desired style.
7932 The list of styles is in `cperl-style-alist', available styles
7933 are GNU, K&R, BSD, C++ and Whitesmith.
7935 The current value of style is memorized (unless there is a memorized
7936 data already), may be restored by `cperl-set-style-back'.
7938 Chosing \"Current\" style will not change style, so this may be used for
7939 side-effect of memorizing only."
7940 (interactive
7941 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
7942 cperl-style-alist)))
7943 (list (completing-read "Enter style: " list nil 'insist))))
7944 (or cperl-old-style
7945 (setq cperl-old-style
7946 (mapcar (function
7947 (lambda (name)
7948 (cons name (eval name))))
7949 cperl-styles-entries)))
7950 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
7951 (while style
7952 (setq setting (car style) style (cdr style))
7953 (set (car setting) (cdr setting)))))
7955 (defun cperl-set-style-back ()
7956 "Restore a style memorised by `cperl-set-style'."
7957 (interactive)
7958 (or cperl-old-style (error "The style was not changed"))
7959 (let (setting)
7960 (while cperl-old-style
7961 (setq setting (car cperl-old-style)
7962 cperl-old-style (cdr cperl-old-style))
7963 (set (car setting) (cdr setting)))))
7965 (defun cperl-check-syntax ()
7966 (interactive)
7967 (require 'mode-compile)
7968 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
7969 (eval '(mode-compile)))) ; Avoid a warning
7971 (defun cperl-info-buffer (type)
7972 ;; Returns buffer with documentation. Creates if missing.
7973 ;; If TYPE, this vars buffer.
7974 ;; Special care is taken to not stomp over an existing info buffer
7975 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
7976 (info (get-buffer bname))
7977 (oldbuf (get-buffer "*info*")))
7978 (if info info
7979 (save-window-excursion
7980 ;; Get Info running
7981 (require 'info)
7982 (cond (oldbuf
7983 (set-buffer oldbuf)
7984 (rename-buffer "*info-perl-tmp*")))
7985 (save-window-excursion
7986 (info))
7987 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
7988 (set-buffer "*info*")
7989 (rename-buffer bname)
7990 (cond (oldbuf
7991 (set-buffer "*info-perl-tmp*")
7992 (rename-buffer "*info*")
7993 (set-buffer bname)))
7994 (make-local-variable 'window-min-height)
7995 (setq window-min-height 2)
7996 (current-buffer)))))
7998 (defun cperl-word-at-point (&optional p)
7999 "Return the word at point or at P."
8000 (save-excursion
8001 (if p (goto-char p))
8002 (or (cperl-word-at-point-hard)
8003 (progn
8004 (require 'etags)
8005 (funcall (or (and (boundp 'find-tag-default-function)
8006 find-tag-default-function)
8007 (get major-mode 'find-tag-default-function)
8008 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
8009 ;; automatically used within `find-tag-default':
8010 'find-tag-default))))))
8012 (defun cperl-info-on-command (command)
8013 "Show documentation for Perl command COMMAND in other window.
8014 If perl-info buffer is shown in some frame, uses this frame.
8015 Customized by setting variables `cperl-shrink-wrap-info-frame',
8016 `cperl-max-help-size'."
8017 (interactive
8018 (let* ((default (cperl-word-at-point))
8019 (read (read-string
8020 (format "Find doc for Perl function (default %s): "
8021 default))))
8022 (list (if (equal read "")
8023 default
8024 read))))
8026 (let ((buffer (current-buffer))
8027 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
8028 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
8029 max-height char-height buf-list)
8030 (if (string-match "^-[a-zA-Z]$" command)
8031 (setq cmd-desc "^-X[ \t\n]"))
8032 (setq isvar (string-match "^[$@%]" command)
8033 buf (cperl-info-buffer isvar)
8034 iniwin (selected-window)
8035 fr1 (window-frame iniwin))
8036 (set-buffer buf)
8037 (goto-char (point-min))
8038 (or isvar
8039 (progn (re-search-forward "^-X[ \t\n]")
8040 (forward-line -1)))
8041 (if (re-search-forward cmd-desc nil t)
8042 (progn
8043 ;; Go back to beginning of the group (ex, for qq)
8044 (if (re-search-backward "^[ \t\n\f]")
8045 (forward-line 1))
8046 (beginning-of-line)
8047 ;; Get some of
8048 (setq pos (point)
8049 buf-list (list buf "*info-perl-var*" "*info-perl*"))
8050 (while (and (not win) buf-list)
8051 (setq win (get-buffer-window (car buf-list) t))
8052 (setq buf-list (cdr buf-list)))
8053 (or (not win)
8054 (eq (window-buffer win) buf)
8055 (set-window-buffer win buf))
8056 (and win (setq fr2 (window-frame win)))
8057 (if (or (not fr2) (eq fr1 fr2))
8058 (pop-to-buffer buf)
8059 (special-display-popup-frame buf) ; Make it visible
8060 (select-window win))
8061 (goto-char pos) ; Needed (?!).
8062 ;; Resize
8063 (setq iniheight (window-height)
8064 frheight (frame-height)
8065 not-loner (< iniheight (1- frheight))) ; Are not alone
8066 (cond ((if not-loner cperl-max-help-size
8067 cperl-shrink-wrap-info-frame)
8068 (setq height
8069 (+ 2
8070 (count-lines
8072 (save-excursion
8073 (if (re-search-forward
8074 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
8075 (match-beginning 0) (point-max)))))
8076 max-height
8077 (if not-loner
8078 (/ (* (- frheight 3) cperl-max-help-size) 100)
8079 (setq char-height (frame-char-height))
8080 ;; Non-functioning under OS/2:
8081 (if (eq char-height 1) (setq char-height 18))
8082 ;; Title, menubar, + 2 for slack
8083 (- (/ (x-display-pixel-height) char-height) 4)))
8084 (if (> height max-height) (setq height max-height))
8085 ;;(message "was %s doing %s" iniheight height)
8086 (if not-loner
8087 (enlarge-window (- height iniheight))
8088 (set-frame-height (window-frame win) (1+ height)))))
8089 (set-window-start (selected-window) pos))
8090 (message "No entry for %s found." command))
8091 ;;(pop-to-buffer buffer)
8092 (select-window iniwin)))
8094 (defun cperl-info-on-current-command ()
8095 "Show documentation for Perl command at point in other window."
8096 (interactive)
8097 (cperl-info-on-command (cperl-word-at-point)))
8099 (defun cperl-imenu-info-imenu-search ()
8100 (if (looking-at "^-X[ \t\n]") nil
8101 (re-search-backward
8102 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
8103 (forward-line 1)))
8105 (defun cperl-imenu-info-imenu-name ()
8106 (buffer-substring
8107 (match-beginning 1) (match-end 1)))
8109 (defun cperl-imenu-on-info ()
8110 "Shows imenu for Perl Info Buffer.
8111 Opens Perl Info buffer if needed."
8112 (interactive)
8113 (let* ((buffer (current-buffer))
8114 imenu-create-index-function
8115 imenu-prev-index-position-function
8116 imenu-extract-index-name-function
8117 (index-item (save-restriction
8118 (save-window-excursion
8119 (set-buffer (cperl-info-buffer nil))
8120 (setq imenu-create-index-function
8121 'imenu-default-create-index-function
8122 imenu-prev-index-position-function
8123 'cperl-imenu-info-imenu-search
8124 imenu-extract-index-name-function
8125 'cperl-imenu-info-imenu-name)
8126 (imenu-choose-buffer-index)))))
8127 (and index-item
8128 (progn
8129 (push-mark)
8130 (pop-to-buffer "*info-perl*")
8131 (cond
8132 ((markerp (cdr index-item))
8133 (goto-char (marker-position (cdr index-item))))
8135 (goto-char (cdr index-item))))
8136 (set-window-start (selected-window) (point))
8137 (pop-to-buffer buffer)))))
8139 (defun cperl-lineup (beg end &optional step minshift)
8140 "Lineup construction in a region.
8141 Beginning of region should be at the start of a construction.
8142 All first occurrences of this construction in the lines that are
8143 partially contained in the region are lined up at the same column.
8145 MINSHIFT is the minimal amount of space to insert before the construction.
8146 STEP is the tabwidth to position constructions.
8147 If STEP is nil, `cperl-lineup-step' will be used
8148 \(or `cperl-indent-level', if `cperl-lineup-step' is `nil').
8149 Will not move the position at the start to the left."
8150 (interactive "r")
8151 (let (search col tcol seen b)
8152 (save-excursion
8153 (goto-char end)
8154 (end-of-line)
8155 (setq end (point-marker))
8156 (goto-char beg)
8157 (skip-chars-forward " \t\f")
8158 (setq beg (point-marker))
8159 (indent-region beg end nil)
8160 (goto-char beg)
8161 (setq col (current-column))
8162 (if (looking-at "[a-zA-Z0-9_]")
8163 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
8164 (setq search
8165 (concat "\\<"
8166 (regexp-quote
8167 (buffer-substring (match-beginning 0)
8168 (match-end 0))) "\\>"))
8169 (error "Cannot line up in a middle of the word"))
8170 (if (looking-at "$")
8171 (error "Cannot line up end of line"))
8172 (setq search (regexp-quote (char-to-string (following-char)))))
8173 (setq step (or step cperl-lineup-step cperl-indent-level))
8174 (or minshift (setq minshift 1))
8175 (while (progn
8176 (beginning-of-line 2)
8177 (and (< (point) end)
8178 (re-search-forward search end t)
8179 (goto-char (match-beginning 0))))
8180 (setq tcol (current-column) seen t)
8181 (if (> tcol col) (setq col tcol)))
8182 (or seen
8183 (error "The construction to line up occurred only once"))
8184 (goto-char beg)
8185 (setq col (+ col minshift))
8186 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
8187 (while
8188 (progn
8189 (cperl-make-indent col)
8190 (beginning-of-line 2)
8191 (and (< (point) end)
8192 (re-search-forward search end t)
8193 (goto-char (match-beginning 0)))))))) ; No body
8195 (defun cperl-etags (&optional add all files) ;; NOT USED???
8196 "Run etags with appropriate options for Perl files.
8197 If optional argument ALL is `recursive', will process Perl files
8198 in subdirectories too."
8199 (interactive)
8200 (let ((cmd "etags")
8201 (args '("-l" "none" "-r"
8202 ;; 1=fullname 2=package? 3=name 4=proto? 5=attrs? (VERY APPROX!)
8203 "/\\<sub[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([ \t]*:[^#{;]*\\)?\\([{#]\\|$\\)/\\3/"
8204 "-r"
8205 "/\\<\\(package\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\)[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\([#;]\\|$\\)/\\2/"; perl6
8206 "-r"
8207 "/\\<\\(package\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\)[ \\t]*;/\\1;/"))
8208 res)
8209 (if add (setq args (cons "-a" args)))
8210 (or files (setq files (list buffer-file-name)))
8211 (cond
8212 ((eq all 'recursive)
8213 ;;(error "Not implemented: recursive")
8214 (setq args (append (list "-e"
8215 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm6]$/}
8216 use File::Find;
8217 find(\\&wanted, '.');
8218 exec @ARGV;"
8219 cmd) args)
8220 cmd "perl"))
8221 (all
8222 ;;(error "Not implemented: all")
8223 (setq args (append (list "-e"
8224 "push @ARGV, <*.PL *.pl *.pm>;
8225 exec @ARGV;"
8226 cmd) args)
8227 cmd "perl"))
8229 (setq args (append args files))))
8230 (setq res (apply 'call-process cmd nil nil nil args))
8231 (or (eq res 0)
8232 (message "etags returned \"%s\"" res))))
8234 (defun cperl-toggle-auto-newline ()
8235 "Toggle the state of `cperl-auto-newline'."
8236 (interactive)
8237 (setq cperl-auto-newline (not cperl-auto-newline))
8238 (message "Newlines will %sbe auto-inserted now."
8239 (if cperl-auto-newline "" "not ")))
8241 (defun cperl-toggle-abbrev ()
8242 "Toggle the state of automatic keyword expansion in CPerl mode."
8243 (interactive)
8244 (abbrev-mode (if abbrev-mode 0 1))
8245 (message "Perl control structure will %sbe auto-inserted now."
8246 (if abbrev-mode "" "not ")))
8249 (defun cperl-toggle-electric ()
8250 "Toggle the state of parentheses doubling in CPerl mode."
8251 (interactive)
8252 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
8253 (message "Parentheses will %sbe auto-doubled now."
8254 (if (cperl-val 'cperl-electric-parens) "" "not ")))
8256 (defun cperl-toggle-autohelp ()
8257 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
8258 Delay of auto-help controlled by `cperl-lazy-help-time'."
8259 (interactive)
8260 (if (fboundp 'run-with-idle-timer)
8261 (progn
8262 (if cperl-lazy-installed
8263 (cperl-lazy-unstall)
8264 (cperl-lazy-install))
8265 (message "Perl help messages will %sbe automatically shown now."
8266 (if cperl-lazy-installed "" "not ")))
8267 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
8269 (defun cperl-toggle-construct-fix ()
8270 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
8271 (interactive)
8272 (setq cperl-indent-region-fix-constructs
8273 (if cperl-indent-region-fix-constructs
8276 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
8277 (if cperl-indent-region-fix-constructs "" "not ")))
8279 (defun cperl-toggle-set-debug-unwind (arg &optional backtrace)
8280 "Toggle (or, with numeric argument, set) debugging state of syntaxification.
8281 Nonpositive numeric argument disables debugging messages. The message
8282 summarizes which regions it was decided to rescan for syntactic constructs.
8284 The message looks like this:
8286 Syxify req=123..138 actual=101..146 done-to: 112=>146 statepos: 73=>117
8288 Numbers are character positions in the buffer. REQ provides the range to
8289 rescan requested by `font-lock'. ACTUAL is the range actually resyntaxified;
8290 for correct operation it should start and end outside any special syntactic
8291 construct. DONE-TO and STATEPOS indicate changes to internal caches maintained
8292 by CPerl."
8293 (interactive "P")
8294 (or arg
8295 (setq arg (if (eq cperl-syntaxify-by-font-lock
8296 (if backtrace 'backtrace 'message)) 0 1)))
8297 (setq arg (if (> arg 0) (if backtrace 'backtrace 'message) t))
8298 (setq cperl-syntaxify-by-font-lock arg)
8299 (message "Debugging messages of syntax unwind %sabled."
8300 (if (eq arg t) "dis" "en")))
8302 ;;;; Tags file creation.
8304 (defvar cperl-tmp-buffer " *cperl-tmp*")
8306 (defun cperl-setup-tmp-buf ()
8307 (set-buffer (get-buffer-create cperl-tmp-buffer))
8308 (set-syntax-table cperl-mode-syntax-table)
8309 (buffer-disable-undo)
8310 (auto-fill-mode 0)
8311 (if cperl-use-syntax-table-text-property-for-tags
8312 (progn
8313 (make-local-variable 'parse-sexp-lookup-properties)
8314 ;; Do not introduce variable if not needed, we check it!
8315 (set 'parse-sexp-lookup-properties t))))
8317 (defun cperl-xsub-scan ()
8318 (require 'cl)
8319 (require 'imenu)
8320 (let ((index-alist '())
8321 (prev-pos 0) index index1 name package prefix)
8322 (goto-char (point-min))
8323 (if noninteractive
8324 (message "Scanning XSUB for index")
8325 (imenu-progress-message prev-pos 0))
8326 ;; Search for the function
8327 (progn ;;save-match-data
8328 (while (re-search-forward
8329 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
8330 nil t)
8331 (or noninteractive
8332 (imenu-progress-message prev-pos))
8333 (cond
8334 ((match-beginning 2) ; SECTION
8335 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
8336 (goto-char (match-beginning 0))
8337 (skip-chars-forward " \t")
8338 (forward-char 1)
8339 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
8340 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
8341 (setq prefix nil)))
8342 ((not package) nil) ; C language section
8343 ((match-beginning 3) ; XSUB
8344 (goto-char (1+ (match-beginning 3)))
8345 (setq index (imenu-example--name-and-position))
8346 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
8347 (if (and prefix (string-match (concat "^" prefix) name))
8348 (setq name (substring name (length prefix))))
8349 (cond ((string-match "::" name) nil)
8351 (setq index1 (cons (concat package "::" name) (cdr index)))
8352 (push index1 index-alist)))
8353 (setcar index name)
8354 (push index index-alist))
8355 (t ; BOOT: section
8356 ;; (beginning-of-line)
8357 (setq index (imenu-example--name-and-position))
8358 (setcar index (concat package "::BOOT:"))
8359 (push index index-alist)))))
8360 (or noninteractive
8361 (imenu-progress-message prev-pos 100))
8362 index-alist))
8364 (defvar cperl-unreadable-ok nil)
8366 (defun cperl-find-tags (ifile xs topdir)
8367 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
8368 (cperl-pod-here-fontify nil) f file)
8369 (save-excursion
8370 (if b (set-buffer b)
8371 (cperl-setup-tmp-buf))
8372 (erase-buffer)
8373 (condition-case err
8374 (setq file (car (insert-file-contents ifile)))
8375 (error (if cperl-unreadable-ok nil
8376 (if (y-or-n-p
8377 (format "File %s unreadable. Continue? " ifile))
8378 (setq cperl-unreadable-ok t)
8379 (error "Aborting: unreadable file %s" ifile)))))
8380 (if (not file)
8381 (message "Unreadable file %s" ifile)
8382 (message "Scanning file %s ..." file)
8383 (if (and cperl-use-syntax-table-text-property-for-tags
8384 (not xs))
8385 (condition-case err ; after __END__ may have garbage
8386 (cperl-find-pods-heres nil nil noninteractive)
8387 (error (message "While scanning for syntax: %s" err))))
8388 (if xs
8389 (setq lst (cperl-xsub-scan))
8390 (setq ind (cperl-imenu--create-perl-index))
8391 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
8392 (setq lst
8393 (mapcar
8394 (function
8395 (lambda (elt)
8396 (cond ((string-match "^[_a-zA-Z]" (car elt))
8397 (goto-char (cdr elt))
8398 (beginning-of-line) ; pos should be of the start of the line
8399 (list (car elt)
8400 (point)
8401 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
8402 (buffer-substring (progn
8403 (goto-char (cdr elt))
8404 ;; After name now...
8405 (or (eolp) (forward-char 1))
8406 (point))
8407 (progn
8408 (beginning-of-line)
8409 (point))))))))
8410 lst))
8411 (erase-buffer)
8412 (while lst
8413 (setq elt (car lst) lst (cdr lst))
8414 (if elt
8415 (progn
8416 (insert (elt elt 3)
8418 (if (string-match "^\\(package\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\) " (car elt)) ; perl6
8419 (substring (car elt) 8)
8420 (car elt) )
8422 (number-to-string (elt elt 2)) ; Line
8424 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
8425 "\n")
8426 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
8427 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]" ; perl6: TODO: multi|proto submethods
8428 (elt elt 3)))
8429 ;; Need to insert the name without package as well
8430 (setq lst (cons (cons (substring (elt elt 3)
8431 (match-beginning 1)
8432 (match-end 1))
8433 (cdr elt))
8434 lst))))))
8435 (setq pos (point))
8436 (goto-char 1)
8437 (setq rel file)
8438 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
8439 (set-text-properties 0 (length rel) nil rel)
8440 (and (equal topdir (substring rel 0 (length topdir)))
8441 (setq rel (substring file (length topdir))))
8442 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
8443 (setq ret (buffer-substring 1 (point-max)))
8444 (erase-buffer)
8445 (or noninteractive
8446 (message "Scanning file %s finished" file))
8447 ret))))
8449 (defun cperl-add-tags-recurse-noxs ()
8450 "Add to TAGS data for \"pure\" Perl files in the current directory and kids.
8451 Use as
8452 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8453 -f cperl-add-tags-recurse-noxs
8455 (cperl-write-tags nil nil t t nil t))
8457 (defun cperl-add-tags-recurse-noxs-fullpath ()
8458 "Add to TAGS data for \"pure\" Perl in the current directory and kids.
8459 Writes down fullpath, so TAGS is relocatable (but if the build directory
8460 is relocated, the file TAGS inside it breaks). Use as
8461 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8462 -f cperl-add-tags-recurse-noxs-fullpath
8464 (cperl-write-tags nil nil t t nil t ""))
8466 (defun cperl-add-tags-recurse ()
8467 "Add to TAGS file data for Perl files in the current directory and kids.
8468 Use as
8469 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8470 -f cperl-add-tags-recurse
8472 (cperl-write-tags nil nil t t))
8474 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
8475 ;; If INBUFFER, do not select buffer, and do not save
8476 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
8477 (require 'etags)
8478 (if file nil
8479 (setq file (if dir default-directory (buffer-file-name)))
8480 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
8481 (or topdir
8482 (setq topdir default-directory))
8483 (let ((tags-file-name "TAGS")
8484 (case-fold-search (eq system-type 'emx))
8485 xs rel tm)
8486 (save-excursion
8487 (cond (inbuffer nil) ; Already there
8488 ((file-exists-p tags-file-name)
8489 (if cperl-xemacs-p
8490 (visit-tags-table-buffer)
8491 (visit-tags-table-buffer tags-file-name)))
8492 (t (set-buffer (find-file-noselect tags-file-name))))
8493 (cond
8494 (dir
8495 (cond ((eq erase 'ignore))
8496 (erase
8497 (erase-buffer)
8498 (setq erase 'ignore)))
8499 (let ((files
8500 (condition-case err
8501 (directory-files file t
8502 (if recurse nil cperl-scan-files-regexp)
8504 (error
8505 (if cperl-unreadable-ok nil
8506 (if (y-or-n-p
8507 (format "Directory %s unreadable. Continue? " file))
8508 (setq cperl-unreadable-ok t
8509 tm nil) ; Return empty list
8510 (error "Aborting: unreadable directory %s" file)))))))
8511 (mapcar (function
8512 (lambda (file)
8513 (cond
8514 ((string-match cperl-noscan-files-regexp file)
8515 nil)
8516 ((not (file-directory-p file))
8517 (if (string-match cperl-scan-files-regexp file)
8518 (cperl-write-tags file erase recurse nil t noxs topdir)))
8519 ((not recurse) nil)
8520 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
8521 files)))
8523 (setq xs (string-match "\\.xs$" file))
8524 (if (not (and xs noxs))
8525 (progn
8526 (cond ((eq erase 'ignore) (goto-char (point-max)))
8527 (erase (erase-buffer))
8529 (goto-char 1)
8530 (setq rel file)
8531 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
8532 (set-text-properties 0 (length rel) nil rel)
8533 (and (equal topdir (substring rel 0 (length topdir)))
8534 (setq rel (substring file (length topdir))))
8535 (if (search-forward (concat "\f\n" rel ",") nil t)
8536 (progn
8537 (search-backward "\f\n")
8538 (delete-region (point)
8539 (save-excursion
8540 (forward-char 1)
8541 (if (search-forward "\f\n"
8542 nil 'toend)
8543 (- (point) 2)
8544 (point-max)))))
8545 (goto-char (point-max)))))
8546 (insert (cperl-find-tags file xs topdir))))))
8547 (if inbuffer nil ; Delegate to the caller
8548 (save-buffer 0) ; No backup
8549 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
8550 (initialize-new-tags-table))))))
8552 (defvar cperl-tags-hier-regexp-list
8553 (concat
8554 "^\\("
8555 "\\(package\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\)\\>"
8556 "\\|"
8557 "sub\\>[^\n]+::"
8558 "\\|"
8559 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
8560 "\\|"
8561 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
8562 "\\)"))
8564 (defvar cperl-hierarchy '(() ())
8565 "Global hierarchy of classes.")
8567 (defun cperl-tags-hier-fill ()
8568 ;; Suppose we are in a tag table cooked by cperl.
8569 (goto-char 1)
8570 (let (type pack name pos line chunk ord cons1 file str info fileind)
8571 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
8572 (setq pos (match-beginning 0)
8573 pack (match-beginning 2))
8574 (beginning-of-line)
8575 (if (looking-at (concat
8576 "\\([^\n]+\\)"
8577 "\C-?"
8578 "\\([^\n]+\\)"
8579 "\C-a"
8580 "\\([0-9]+\\)"
8582 "\\([0-9]+\\)"))
8583 (progn
8584 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
8585 name (buffer-substring (match-beginning 2) (match-end 2))
8586 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
8587 line (buffer-substring (match-beginning 3) (match-end 3))
8588 ord (if pack 1 0)
8589 file (file-of-tag)
8590 fileind (format "%s:%s" file line)
8591 ;; Moves to beginning of the next line:
8592 info (cperl-etags-snarf-tag file line))
8593 ;; Move back
8594 (forward-char -1)
8595 ;; Make new member of hierarchy name ==> file ==> pos if needed
8596 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
8597 ;; Name known
8598 (setcdr cons1 (cons (cons fileind (vector file info))
8599 (cdr cons1)))
8600 ;; First occurrence of the name, start alist
8601 (setq cons1 (cons name (list (cons fileind (vector file info)))))
8602 (if pack
8603 (setcar (cdr cperl-hierarchy)
8604 (cons cons1 (nth 1 cperl-hierarchy)))
8605 (setcar cperl-hierarchy
8606 (cons cons1 (car cperl-hierarchy)))))))
8607 (end-of-line))))
8609 (defun cperl-tags-hier-init (&optional update)
8610 "Show hierarchical menu of classes and methods.
8611 Finds info about classes by a scan of loaded TAGS files.
8612 Supposes that the TAGS files contain fully qualified function names.
8613 One may build such TAGS files from CPerl mode menu."
8614 (interactive)
8615 (require 'etags)
8616 (require 'imenu)
8617 (if (or update (null (nth 2 cperl-hierarchy)))
8618 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
8619 (or (nthcdr 2 elt)
8620 ;; Only in one file
8621 (setcdr elt (cdr (nth 1 elt)))))))
8622 pack name cons1 to l1 l2 l3 l4 b)
8623 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
8624 (setq cperl-hierarchy (list l1 l2 l3))
8625 (if cperl-xemacs-p ; Not checked
8626 (progn
8627 (or tags-file-name
8628 ;; Does this work in XEmacs?
8629 (call-interactively 'visit-tags-table))
8630 (message "Updating list of classes...")
8631 (set-buffer (get-file-buffer tags-file-name))
8632 (cperl-tags-hier-fill))
8633 (or tags-table-list
8634 (call-interactively 'visit-tags-table))
8635 (mapcar
8636 (function
8637 (lambda (tagsfile)
8638 (message "Updating list of classes... %s" tagsfile)
8639 (set-buffer (get-file-buffer tagsfile))
8640 (cperl-tags-hier-fill)))
8641 tags-table-list)
8642 (message "Updating list of classes... postprocessing..."))
8643 (mapcar remover (car cperl-hierarchy))
8644 (mapcar remover (nth 1 cperl-hierarchy))
8645 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
8646 (cons "Methods: " (car cperl-hierarchy))))
8647 (cperl-tags-treeify to 1)
8648 (setcar (nthcdr 2 cperl-hierarchy)
8649 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
8650 (message "Updating list of classes: done, requesting display...")
8651 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
8653 (or (nth 2 cperl-hierarchy)
8654 (error "No items found"))
8655 (setq update
8656 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
8657 (if (if (fboundp 'display-popup-menus-p)
8658 (let ((f 'display-popup-menus-p))
8659 (funcall f))
8660 window-system)
8661 (x-popup-menu t (nth 2 cperl-hierarchy))
8662 (require 'tmm)
8663 (tmm-prompt (nth 2 cperl-hierarchy))))
8664 (if (and update (listp update))
8665 (progn (while (cdr update) (setq update (cdr update)))
8666 (setq update (car update)))) ; Get the last from the list
8667 (if (vectorp update)
8668 (progn
8669 (find-file (elt update 0))
8670 (cperl-etags-goto-tag-location (elt update 1))))
8671 (if (eq update -999) (cperl-tags-hier-init t)))
8673 (defun cperl-tags-treeify (to level)
8674 ;; cadr of `to' is read-write. On start it is a cons
8675 (let* ((regexp (concat "^\\(" (mapconcat
8676 'identity
8677 (make-list level "[_a-zA-Z0-9]+")
8678 "::")
8679 "\\)\\(::\\)?"))
8680 (packages (cdr (nth 1 to)))
8681 (methods (cdr (nth 2 to)))
8682 l1 head tail cons1 cons2 ord writeto packs recurse
8683 root-packages root-functions ms many_ms same_name ps
8684 (move-deeper
8685 (function
8686 (lambda (elt)
8687 (cond ((and (string-match regexp (car elt))
8688 (or (eq ord 1) (match-end 2)))
8689 (setq head (substring (car elt) 0 (match-end 1))
8690 tail (if (match-end 2) (substring (car elt)
8691 (match-end 2)))
8692 recurse t)
8693 (if (setq cons1 (assoc head writeto)) nil
8694 ;; Need to init new head
8695 (setcdr writeto (cons (list head (list "Packages: ")
8696 (list "Methods: "))
8697 (cdr writeto)))
8698 (setq cons1 (nth 1 writeto)))
8699 (setq cons2 (nth ord cons1)) ; Either packs or meths
8700 (setcdr cons2 (cons elt (cdr cons2))))
8701 ((eq ord 2)
8702 (setq root-functions (cons elt root-functions)))
8704 (setq root-packages (cons elt root-packages))))))))
8705 (setcdr to l1) ; Init to dynamic space
8706 (setq writeto to)
8707 (setq ord 1)
8708 (mapcar move-deeper packages)
8709 (setq ord 2)
8710 (mapcar move-deeper methods)
8711 (if recurse
8712 (mapcar (function (lambda (elt)
8713 (cperl-tags-treeify elt (1+ level))))
8714 (cdr to)))
8715 ;;Now clean up leaders with one child only
8716 (mapcar (function (lambda (elt)
8717 (if (not (and (listp (cdr elt))
8718 (eq (length elt) 2))) nil
8719 (setcar elt (car (nth 1 elt)))
8720 (setcdr elt (cdr (nth 1 elt))))))
8721 (cdr to))
8722 ;; Sort the roots of subtrees
8723 (if (default-value 'imenu-sort-function)
8724 (setcdr to
8725 (sort (cdr to) (default-value 'imenu-sort-function))))
8726 ;; Now add back functions removed from display
8727 (mapcar (function (lambda (elt)
8728 (setcdr to (cons elt (cdr to)))))
8729 (if (default-value 'imenu-sort-function)
8730 (nreverse
8731 (sort root-functions (default-value 'imenu-sort-function)))
8732 root-functions))
8733 ;; Now add back packages removed from display
8734 (mapcar (function (lambda (elt)
8735 (setcdr to (cons (cons (concat "package " (car elt))
8736 (cdr elt))
8737 (cdr to)))))
8738 (if (default-value 'imenu-sort-function)
8739 (nreverse
8740 (sort root-packages (default-value 'imenu-sort-function)))
8741 root-packages))))
8743 ;;;(x-popup-menu t
8744 ;;; '(keymap "Name1"
8745 ;;; ("Ret1" "aa")
8746 ;;; ("Head1" "ab"
8747 ;;; keymap "Name2"
8748 ;;; ("Tail1" "x") ("Tail2" "y"))))
8750 (defun cperl-list-fold (list name limit)
8751 (let (list1 list2 elt1 (num 0))
8752 (if (<= (length list) limit) list
8753 (setq list1 nil list2 nil)
8754 (while list
8755 (setq num (1+ num)
8756 elt1 (car list)
8757 list (cdr list))
8758 (if (<= num imenu-max-items)
8759 (setq list2 (cons elt1 list2))
8760 (setq list1 (cons (cons name
8761 (nreverse list2))
8762 list1)
8763 list2 (list elt1)
8764 num 1)))
8765 (nreverse (cons (cons name
8766 (nreverse list2))
8767 list1)))))
8769 (defun cperl-menu-to-keymap (menu &optional name)
8770 (let (list)
8771 (cons 'keymap
8772 (mapcar
8773 (function
8774 (lambda (elt)
8775 (cond ((listp (cdr elt))
8776 (setq list (cperl-list-fold
8777 (cdr elt) (car elt) imenu-max-items))
8778 (cons nil
8779 (cons (car elt)
8780 (cperl-menu-to-keymap list))))
8782 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
8783 (cperl-list-fold menu "Root" imenu-max-items)))))
8786 (defvar cperl-bad-style-regexp
8787 (mapconcat 'identity
8788 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
8789 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
8790 "\\|")
8791 "Finds places such that insertion of a whitespace may help a lot.")
8793 (defvar cperl-not-bad-style-regexp
8794 (mapconcat
8795 'identity
8796 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
8797 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
8798 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
8799 "<\\$?\\sw+\\(\\.\\(\\sw\\|_\\)+\\)?>" ; <IN> <stdin.h>
8800 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
8801 "-[0-9]" ; -5
8802 "\\+\\+" ; ++var
8803 "--" ; --var
8804 ".->" ; a->b
8805 "->" ; a SPACE ->b
8806 "\\[-" ; a[-1]
8807 "\\\\[&$@*\\\\]" ; \&func
8808 "^=" ; =head
8809 "\\$." ; $|
8810 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
8811 "||"
8812 "&&"
8813 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
8814 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
8815 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
8816 ;;"[*/+-|&<.]+="
8818 "\\|")
8819 "If matches at the start of match found by `my-bad-c-style-regexp',
8820 insertion of a whitespace will not help.")
8822 (defvar found-bad)
8824 (defun cperl-find-bad-style ()
8825 "Find places in the buffer where insertion of a whitespace may help.
8826 Prompts user for insertion of spaces.
8827 Currently it is tuned to C and Perl syntax."
8828 (interactive)
8829 (let (found-bad (p (point)))
8830 (setq last-nonmenu-event 13) ; To disable popup
8831 (goto-char (point-min))
8832 (map-y-or-n-p "Insert space here? "
8833 (lambda (arg) (insert " "))
8834 'cperl-next-bad-style
8835 '("location" "locations" "insert a space into")
8836 '((?\C-r (lambda (arg)
8837 (let ((buffer-quit-function
8838 'exit-recursive-edit))
8839 (message "Exit with Esc Esc")
8840 (recursive-edit)
8841 t)) ; Consider acted upon
8842 "edit, exit with Esc Esc")
8843 (?e (lambda (arg)
8844 (let ((buffer-quit-function
8845 'exit-recursive-edit))
8846 (message "Exit with Esc Esc")
8847 (recursive-edit)
8848 t)) ; Consider acted upon
8849 "edit, exit with Esc Esc"))
8851 (if found-bad (goto-char found-bad)
8852 (goto-char p)
8853 (message "No appropriate place found"))))
8855 (defun cperl-next-bad-style ()
8856 (let (p (not-found t) (point (point)) found)
8857 (while (and not-found
8858 (re-search-forward cperl-bad-style-regexp nil 'to-end))
8859 (setq p (point))
8860 (goto-char (match-beginning 0))
8861 (if (or
8862 (looking-at cperl-not-bad-style-regexp)
8863 ;; Check for a < -b and friends
8864 (and (eq (following-char) ?\-)
8865 (save-excursion
8866 (skip-chars-backward " \t\n")
8867 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
8868 ;; Now check for syntax type
8869 (save-match-data
8870 (setq found (point))
8871 (beginning-of-defun)
8872 (let ((pps (parse-partial-sexp (point) found)))
8873 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
8874 (goto-char (match-end 0))
8875 (goto-char (1- p))
8876 (setq not-found nil
8877 found-bad found)))
8878 (not not-found)))
8881 ;;; Getting help
8882 (defvar cperl-have-help-regexp
8883 ;;(concat "\\("
8884 (mapconcat
8885 'identity
8886 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
8887 "[$@]\\^[a-zA-Z]" ; Special variable
8888 "[$@][^ \n\t]" ; Special variable
8889 "-[a-zA-Z]" ; File test
8890 "\\\\[a-zA-Z0]" ; Special chars
8891 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
8892 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
8893 "[a-zA-Z_0-9:]+" ; symbol or number
8894 "x="
8895 "#!")
8896 ;;"\\)\\|\\("
8897 "\\|")
8898 ;;"\\)"
8900 "Matches places in the buffer we can find help for.")
8902 (defvar cperl-message-on-help-error t)
8903 (defvar cperl-help-from-timer nil)
8905 (defun cperl-word-at-point-hard ()
8906 ;; Does not save-excursion
8907 ;; Get to the something meaningful
8908 (or (eobp) (eolp) (forward-char 1))
8909 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
8910 (save-excursion (beginning-of-line) (point))
8911 'to-beg)
8912 ;; (cond
8913 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
8914 ;; (skip-chars-backward " \n\t\r({[]});,")
8915 ;; (or (bobp) (backward-char 1))))
8916 ;; Try to backtrace
8917 (cond
8918 ((looking-at "[a-zA-Z0-9_:]") ; symbol
8919 (skip-chars-backward "a-zA-Z0-9_:")
8920 (cond
8921 ((and (eq (preceding-char) ?^) ; $^I
8922 (eq (char-after (- (point) 2)) ?\$))
8923 (forward-char -2))
8924 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
8925 (forward-char -1))
8926 ((and (eq (preceding-char) ?\=)
8927 (eq (current-column) 1))
8928 (forward-char -1))) ; =head1
8929 (if (and (eq (preceding-char) ?\<)
8930 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
8931 (forward-char -1)))
8932 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
8933 (forward-char -1))
8934 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
8935 (forward-char -1))
8936 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
8937 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
8938 (cond
8939 ((and (eq (preceding-char) ?\$)
8940 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
8941 (forward-char -1))
8942 ((and (eq (following-char) ?\>)
8943 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
8944 (save-excursion
8945 (forward-sexp -1)
8946 (and (eq (preceding-char) ?\<)
8947 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
8948 (search-backward "<"))))
8949 ((and (eq (following-char) ?\$)
8950 (eq (preceding-char) ?\<)
8951 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
8952 (forward-char -1)))
8953 (if (looking-at cperl-have-help-regexp)
8954 (buffer-substring (match-beginning 0) (match-end 0))))
8956 (defun cperl-get-help ()
8957 "Get one-line docs on the symbol at the point.
8958 The data for these docs is a little bit obsolete and may be in fact longer
8959 than a line. Your contribution to update/shorten it is appreciated."
8960 (interactive)
8961 (save-match-data ; May be called "inside" query-replace
8962 (save-excursion
8963 (let ((word (cperl-word-at-point-hard)))
8964 (if word
8965 (if (and cperl-help-from-timer ; Bail out if not in mainland
8966 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
8967 (or (memq (get-text-property (point) 'face)
8968 '(font-lock-comment-face font-lock-string-face))
8969 (memq (get-text-property (point) 'syntax-type)
8970 '(pod here-doc format))))
8972 (cperl-describe-perl-symbol word))
8973 (if cperl-message-on-help-error
8974 (message "Nothing found for %s..."
8975 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
8977 ;;; Stolen from perl-descr.el by Johan Vromans:
8979 (defvar cperl-doc-buffer " *perl-doc*"
8980 "Where the documentation can be found.")
8982 (defun cperl-describe-perl-symbol (val)
8983 "Display the documentation of symbol at point, a Perl operator."
8984 (let ((enable-recursive-minibuffers t)
8985 args-file regexp)
8986 (cond
8987 ((string-match "^[&*][a-zA-Z_]" val)
8988 (setq val (concat (substring val 0 1) "NAME")))
8989 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
8990 (setq val (concat "@" (substring val 1 (match-end 1)))))
8991 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
8992 (setq val (concat "%" (substring val 1 (match-end 1)))))
8993 ((and (string= val "x") (string-match "^x=" val))
8994 (setq val "x="))
8995 ((string-match "^\\$[\C-a-\C-z]" val)
8996 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
8997 ((string-match "^CORE::" val)
8998 (setq val "CORE::"))
8999 ((string-match "^SUPER::" val)
9000 (setq val "SUPER::"))
9001 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
9002 (setq val "<NAME>")))
9003 (setq regexp (concat "^"
9004 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
9005 (regexp-quote val)
9006 "\\([ \t([/]\\|$\\)"))
9008 ;; get the buffer with the documentation text
9009 (cperl-switch-to-doc-buffer)
9011 ;; lookup in the doc
9012 (goto-char (point-min))
9013 (let ((case-fold-search nil))
9014 (list
9015 (if (re-search-forward regexp (point-max) t)
9016 (save-excursion
9017 (beginning-of-line 1)
9018 (let ((lnstart (point)))
9019 (end-of-line)
9020 (message "%s" (buffer-substring lnstart (point)))))
9021 (if cperl-message-on-help-error
9022 (message "No definition for %s" val)))))))
9024 (defvar cperl-short-docs 'please-ignore-this-line
9025 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
9026 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
9027 ... Range (list context); flip/flop [no flop when flip] (scalar context).
9028 ! ... Logical negation.
9029 ... != ... Numeric inequality.
9030 ... !~ ... Search pattern, substitution, or translation (negated).
9031 $! In numeric context: errno. In a string context: error string.
9032 $\" The separator which joins elements of arrays interpolated in strings.
9033 $# The output format for printed numbers. Default is %.15g or close.
9034 $$ Process number of this script. Changes in the fork()ed child process.
9035 $% The current page number of the currently selected output channel.
9037 The following variables are always local to the current block:
9039 $1 Match of the 1st set of parentheses in the last match (auto-local).
9040 $2 Match of the 2nd set of parentheses in the last match (auto-local).
9041 $3 Match of the 3rd set of parentheses in the last match (auto-local).
9042 $4 Match of the 4th set of parentheses in the last match (auto-local).
9043 $5 Match of the 5th set of parentheses in the last match (auto-local).
9044 $6 Match of the 6th set of parentheses in the last match (auto-local).
9045 $7 Match of the 7th set of parentheses in the last match (auto-local).
9046 $8 Match of the 8th set of parentheses in the last match (auto-local).
9047 $9 Match of the 9th set of parentheses in the last match (auto-local).
9048 $& The string matched by the last pattern match (auto-local).
9049 $' The string after what was matched by the last match (auto-local).
9050 $` The string before what was matched by the last match (auto-local).
9052 $( The real gid of this process.
9053 $) The effective gid of this process.
9054 $* Deprecated: Set to 1 to do multiline matching within a string.
9055 $+ The last bracket matched by the last search pattern.
9056 $, The output field separator for the print operator.
9057 $- The number of lines left on the page.
9058 $. The current input line number of the last filehandle that was read.
9059 $/ The input record separator, newline by default.
9060 $0 Name of the file containing the current perl script (read/write).
9061 $: String may be broken after these characters to fill ^-lines in a format.
9062 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
9063 $< The real uid of this process.
9064 $= The page length of the current output channel. Default is 60 lines.
9065 $> The effective uid of this process.
9066 $? The status returned by the last ``, pipe close or `system'.
9067 $@ The perl error message from the last eval or do @var{EXPR} command.
9068 $ARGV The name of the current file used with <> .
9069 $[ Deprecated: The index of the first element/char in an array/string.
9070 $\\ The output record separator for the print operator.
9071 $] The perl version string as displayed with perl -v.
9072 $^ The name of the current top-of-page format.
9073 $^A The current value of the write() accumulator for format() lines.
9074 $^D The value of the perl debug (-D) flags.
9075 $^E Information about the last system error other than that provided by $!.
9076 $^F The highest system file descriptor, ordinarily 2.
9077 $^H The current set of syntax checks enabled by `use strict'.
9078 $^I The value of the in-place edit extension (perl -i option).
9079 $^L What formats output to perform a formfeed. Default is \f.
9080 $^M A buffer for emergency memory allocation when running out of memory.
9081 $^O The operating system name under which this copy of Perl was built.
9082 $^P Internal debugging flag.
9083 $^T The time the script was started. Used by -A/-M/-C file tests.
9084 $^W True if warnings are requested (perl -w flag).
9085 $^X The name under which perl was invoked (argv[0] in C-speech).
9086 $_ The default input and pattern-searching space.
9087 $| Auto-flush after write/print on current output channel? Default 0.
9088 $~ The name of the current report format.
9089 ... % ... Modulo division.
9090 ... %= ... Modulo division assignment.
9091 %ENV Contains the current environment.
9092 %INC List of files that have been require-d or do-ne.
9093 %SIG Used to set signal handlers for various signals.
9094 ... & ... Bitwise and.
9095 ... && ... Logical and.
9096 ... &&= ... Logical and assignment.
9097 ... &= ... Bitwise and assignment.
9098 ... * ... Multiplication.
9099 ... ** ... Exponentiation.
9100 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
9101 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
9102 ... + ... Addition. +EXPR Makes EXPR into scalar context.
9103 ++ Auto-increment (magical on strings). ++EXPR EXPR++
9104 ... += ... Addition assignment.
9105 , Comma operator.
9106 ... - ... Subtraction.
9107 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
9108 ... -= ... Subtraction assignment.
9109 -A Access time in days since script started.
9110 -B File is a non-text (binary) file.
9111 -C Inode change time in days since script started.
9112 -M Age in days since script started.
9113 -O File is owned by real uid.
9114 -R File is readable by real uid.
9115 -S File is a socket .
9116 -T File is a text file.
9117 -W File is writable by real uid.
9118 -X File is executable by real uid.
9119 -b File is a block special file.
9120 -c File is a character special file.
9121 -d File is a directory.
9122 -e File exists .
9123 -f File is a plain file.
9124 -g File has setgid bit set.
9125 -k File has sticky bit set.
9126 -l File is a symbolic link.
9127 -o File is owned by effective uid.
9128 -p File is a named pipe (FIFO).
9129 -r File is readable by effective uid.
9130 -s File has non-zero size.
9131 -t Tests if filehandle (STDIN by default) is opened to a tty.
9132 -u File has setuid bit set.
9133 -w File is writable by effective uid.
9134 -x File is executable by effective uid.
9135 -z File has zero size.
9136 . Concatenate strings.
9137 .. Range (list context); flip/flop (scalar context) operator.
9138 .= Concatenate assignment strings
9139 ... / ... Division. /PATTERN/ioxsmg Pattern match
9140 ... /= ... Division assignment.
9141 /PATTERN/ioxsmg Pattern match.
9142 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
9143 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
9144 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
9145 <> Reads line from union of files in @ARGV (= command line) and STDIN.
9146 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
9147 ... <= ... Numeric less than or equal to.
9148 ... <=> ... Numeric compare.
9149 ... = ... Assignment.
9150 ... == ... Numeric equality.
9151 ... =~ ... Search pattern, substitution, or translation
9152 ... > ... Numeric greater than.
9153 ... >= ... Numeric greater than or equal to.
9154 ... >> ... Bitwise shift right.
9155 ... >>= ... Bitwise shift right assignment.
9156 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
9157 ?PATTERN? One-time pattern match.
9158 @ARGV Command line arguments (not including the command name - see $0).
9159 @INC List of places to look for perl scripts during do/include/use.
9160 @_ Parameter array for subroutines; result of split() unless in list context.
9161 \\ Creates reference to what follows, like \$var, or quotes non-\w in strings.
9162 \\0 Octal char, e.g. \\033.
9163 \\E Case modification terminator. See \\Q, \\L, and \\U.
9164 \\L Lowercase until \\E . See also \\l, lc.
9165 \\U Upcase until \\E . See also \\u, uc.
9166 \\Q Quote metacharacters until \\E . See also quotemeta.
9167 \\a Alarm character (octal 007).
9168 \\b Backspace character (octal 010).
9169 \\c Control character, e.g. \\c[ .
9170 \\e Escape character (octal 033).
9171 \\f Formfeed character (octal 014).
9172 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
9173 \\n Newline character (octal 012 on most systems).
9174 \\r Return character (octal 015 on most systems).
9175 \\t Tab character (octal 011).
9176 \\u Upcase the next character. See also \\U and \\l, ucfirst.
9177 \\x Hex character, e.g. \\x1b.
9178 ... ^ ... Bitwise exclusive or.
9179 __END__ Ends program source.
9180 __DATA__ Ends program source.
9181 __FILE__ Current (source) filename.
9182 __LINE__ Current line in current source.
9183 __PACKAGE__ Current package.
9184 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
9185 ARGVOUT Output filehandle with -i flag.
9186 BEGIN { ... } Immediately executed (during compilation) piece of code.
9187 END { ... } Pseudo-subroutine executed after the script finishes.
9188 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
9189 INIT { ... } Pseudo-subroutine executed before the script starts running.
9190 DATA Input filehandle for what follows after __END__ or __DATA__.
9191 accept(NEWSOCKET,GENERICSOCKET)
9192 alarm(SECONDS)
9193 atan2(X,Y)
9194 bind(SOCKET,NAME)
9195 binmode(FILEHANDLE)
9196 caller[(LEVEL)]
9197 chdir(EXPR)
9198 chmod(LIST)
9199 chop[(LIST|VAR)]
9200 chown(LIST)
9201 chroot(FILENAME)
9202 close(FILEHANDLE)
9203 closedir(DIRHANDLE)
9204 ... cmp ... String compare.
9205 connect(SOCKET,NAME)
9206 continue of { block } continue { block }. Is executed after `next' or at end.
9207 cos(EXPR)
9208 crypt(PLAINTEXT,SALT)
9209 dbmclose(%HASH)
9210 dbmopen(%HASH,DBNAME,MODE)
9211 defined(EXPR)
9212 delete($HASH{KEY})
9213 die(LIST)
9214 do { ... }|SUBR while|until EXPR executes at least once
9215 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
9216 dump LABEL
9217 each(%HASH)
9218 endgrent
9219 endhostent
9220 endnetent
9221 endprotoent
9222 endpwent
9223 endservent
9224 eof[([FILEHANDLE])]
9225 ... eq ... String equality.
9226 eval(EXPR) or eval { BLOCK }
9227 exec([TRUENAME] ARGV0, ARGVs) or exec(SHELL_COMMAND_LINE)
9228 exit(EXPR)
9229 exp(EXPR)
9230 fcntl(FILEHANDLE,FUNCTION,SCALAR)
9231 fileno(FILEHANDLE)
9232 flock(FILEHANDLE,OPERATION)
9233 for (EXPR;EXPR;EXPR) { ... }
9234 foreach [VAR] (@ARRAY) { ... }
9235 fork
9236 ... ge ... String greater than or equal.
9237 getc[(FILEHANDLE)]
9238 getgrent
9239 getgrgid(GID)
9240 getgrnam(NAME)
9241 gethostbyaddr(ADDR,ADDRTYPE)
9242 gethostbyname(NAME)
9243 gethostent
9244 getlogin
9245 getnetbyaddr(ADDR,ADDRTYPE)
9246 getnetbyname(NAME)
9247 getnetent
9248 getpeername(SOCKET)
9249 getpgrp(PID)
9250 getppid
9251 getpriority(WHICH,WHO)
9252 getprotobyname(NAME)
9253 getprotobynumber(NUMBER)
9254 getprotoent
9255 getpwent
9256 getpwnam(NAME)
9257 getpwuid(UID)
9258 getservbyname(NAME,PROTO)
9259 getservbyport(PORT,PROTO)
9260 getservent
9261 getsockname(SOCKET)
9262 getsockopt(SOCKET,LEVEL,OPTNAME)
9263 gmtime(EXPR)
9264 goto LABEL
9265 ... gt ... String greater than.
9266 hex(EXPR)
9267 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
9268 index(STR,SUBSTR[,OFFSET])
9269 int(EXPR)
9270 ioctl(FILEHANDLE,FUNCTION,SCALAR)
9271 join(EXPR,LIST)
9272 keys(%HASH)
9273 kill(LIST)
9274 last [LABEL]
9275 ... le ... String less than or equal.
9276 length(EXPR)
9277 link(OLDFILE,NEWFILE)
9278 listen(SOCKET,QUEUESIZE)
9279 local(LIST)
9280 localtime(EXPR)
9281 log(EXPR)
9282 lstat(EXPR|FILEHANDLE|VAR)
9283 ... lt ... String less than.
9284 m/PATTERN/iogsmx
9285 mkdir(FILENAME,MODE)
9286 msgctl(ID,CMD,ARG)
9287 msgget(KEY,FLAGS)
9288 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
9289 msgsnd(ID,MSG,FLAGS)
9290 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
9291 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
9292 ... ne ... String inequality.
9293 next [LABEL]
9294 oct(EXPR)
9295 open(FILEHANDLE[,EXPR])
9296 opendir(DIRHANDLE,EXPR)
9297 ord(EXPR) ASCII value of the first char of the string.
9298 pack(TEMPLATE,LIST)
9299 package NAME Introduces package context.
9300 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
9301 pop(ARRAY)
9302 print [FILEHANDLE] [(LIST)]
9303 printf [FILEHANDLE] (FORMAT,LIST)
9304 push(ARRAY,LIST)
9305 q/STRING/ Synonym for 'STRING'
9306 qq/STRING/ Synonym for \"STRING\"
9307 qx/STRING/ Synonym for `STRING`
9308 rand[(EXPR)]
9309 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9310 readdir(DIRHANDLE)
9311 readlink(EXPR)
9312 recv(SOCKET,SCALAR,LEN,FLAGS)
9313 redo [LABEL]
9314 rename(OLDNAME,NEWNAME)
9315 require [FILENAME | PERL_VERSION]
9316 reset[(EXPR)]
9317 return(LIST)
9318 reverse(LIST)
9319 rewinddir(DIRHANDLE)
9320 rindex(STR,SUBSTR[,OFFSET])
9321 rmdir(FILENAME)
9322 s/PATTERN/REPLACEMENT/gieoxsm
9323 scalar(EXPR)
9324 seek(FILEHANDLE,POSITION,WHENCE)
9325 seekdir(DIRHANDLE,POS)
9326 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
9327 semctl(ID,SEMNUM,CMD,ARG)
9328 semget(KEY,NSEMS,SIZE,FLAGS)
9329 semop(KEY,...)
9330 send(SOCKET,MSG,FLAGS[,TO])
9331 setgrent
9332 sethostent(STAYOPEN)
9333 setnetent(STAYOPEN)
9334 setpgrp(PID,PGRP)
9335 setpriority(WHICH,WHO,PRIORITY)
9336 setprotoent(STAYOPEN)
9337 setpwent
9338 setservent(STAYOPEN)
9339 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
9340 shift[(ARRAY)]
9341 shmctl(ID,CMD,ARG)
9342 shmget(KEY,SIZE,FLAGS)
9343 shmread(ID,VAR,POS,SIZE)
9344 shmwrite(ID,STRING,POS,SIZE)
9345 shutdown(SOCKET,HOW)
9346 sin(EXPR)
9347 sleep[(EXPR)]
9348 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
9349 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
9350 sort [SUBROUTINE] (LIST)
9351 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
9352 split[(/PATTERN/[,EXPR[,LIMIT]])]
9353 sprintf(FORMAT,LIST)
9354 sqrt(EXPR)
9355 srand(EXPR)
9356 stat(EXPR|FILEHANDLE|VAR)
9357 study[(SCALAR)]
9358 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
9359 substr(EXPR,OFFSET[,LEN])
9360 symlink(OLDFILE,NEWFILE)
9361 syscall(LIST)
9362 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9363 system([TRUENAME] ARGV0 [,ARGV]) or system(SHELL_COMMAND_LINE)
9364 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9365 tell[(FILEHANDLE)]
9366 telldir(DIRHANDLE)
9367 time
9368 times
9369 tr/SEARCHLIST/REPLACEMENTLIST/cds
9370 truncate(FILE|EXPR,LENGTH)
9371 umask[(EXPR)]
9372 undef[(EXPR)]
9373 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
9374 unlink(LIST)
9375 unpack(TEMPLATE,EXPR)
9376 unshift(ARRAY,LIST)
9377 until (EXPR) { ... } EXPR until EXPR
9378 utime(LIST)
9379 values(%HASH)
9380 vec(EXPR,OFFSET,BITS)
9381 wait
9382 waitpid(PID,FLAGS)
9383 wantarray Returns true if the sub/eval is called in list context.
9384 warn(LIST)
9385 while (EXPR) { ... } EXPR while EXPR
9386 write[(EXPR|FILEHANDLE)]
9387 ... x ... Repeat string or array.
9388 x= ... Repetition assignment.
9389 y/SEARCHLIST/REPLACEMENTLIST/
9390 ... | ... Bitwise or.
9391 ... || ... Logical or.
9392 ~ ... Unary bitwise complement.
9393 #! OS interpreter indicator. If contains `perl', used for options, and -x.
9394 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
9395 CORE:: Prefix to access builtin function if imported sub obscures it.
9396 SUPER:: Prefix to lookup for a method in @ISA classes.
9397 DESTROY Shorthand for `sub DESTROY {...}'.
9398 ... EQ ... Obsolete synonym of `eq'.
9399 ... GE ... Obsolete synonym of `ge'.
9400 ... GT ... Obsolete synonym of `gt'.
9401 ... LE ... Obsolete synonym of `le'.
9402 ... LT ... Obsolete synonym of `lt'.
9403 ... NE ... Obsolete synonym of `ne'.
9404 abs [ EXPR ] absolute value
9405 ... and ... Low-precedence synonym for &&.
9406 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
9407 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
9408 chr Converts a number to char with the same ordinal.
9409 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
9410 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
9411 exists $HASH{KEY} True if the key exists.
9412 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
9413 formline PICTURE, LIST Backdoor into \"format\" processing.
9414 glob EXPR Synonym of <EXPR>.
9415 lc [ EXPR ] Returns lowercased EXPR.
9416 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
9417 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
9418 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
9419 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
9420 not ... Low-precedence synonym for ! - negation.
9421 ... or ... Low-precedence synonym for ||.
9422 pos STRING Set/Get end-position of the last match over this string, see \\G.
9423 quotemeta [ EXPR ] Quote regexp metacharacters.
9424 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
9425 readline FH Synonym of <FH>.
9426 readpipe CMD Synonym of `CMD`.
9427 ref [ EXPR ] Type of EXPR when dereferenced.
9428 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
9429 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
9430 tied Returns internal object for a tied data.
9431 uc [ EXPR ] Returns upcased EXPR.
9432 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
9433 untie VAR Unlink an object from a simple Perl variable.
9434 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
9435 ... xor ... Low-precedence synonym for exclusive or.
9436 prototype \&SUB Returns prototype of the function given a reference.
9437 =head1 Top-level heading.
9438 =head2 Second-level heading.
9439 =head3 Third-level heading (is there such?).
9440 =over [ NUMBER ] Start list.
9441 =item [ TITLE ] Start new item in the list.
9442 =back End list.
9443 =cut Switch from POD to Perl.
9444 =pod Switch from Perl to POD.
9447 (defun cperl-switch-to-doc-buffer ()
9448 "Go to the perl documentation buffer and insert the documentation."
9449 (interactive)
9450 (let ((buf (get-buffer-create cperl-doc-buffer)))
9451 (if (interactive-p)
9452 (switch-to-buffer-other-window buf)
9453 (set-buffer buf))
9454 (if (= (buffer-size) 0)
9455 (progn
9456 (insert (documentation-property 'cperl-short-docs
9457 'variable-documentation))
9458 (setq buffer-read-only t)))))
9460 (defun cperl-beautify-regexp-piece (b e embed level)
9461 ;; b is before the starting delimiter, e before the ending
9462 ;; e should be a marker, may be changed, but remains "correct".
9463 ;; EMBED is nil iff we process the whole REx.
9464 ;; The REx is guaranteed to have //x
9465 ;; LEVEL shows how many levels deep to go
9466 ;; position at enter and at leave is not defined
9467 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
9468 (if (not embed)
9469 (goto-char (1+ b))
9470 (goto-char b)
9471 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
9472 (forward-char 2)
9473 (delete-char 1)
9474 (forward-char 1))
9475 ((looking-at "(\\?[^a-zA-Z]")
9476 (forward-char 3))
9477 ((looking-at "(\\?") ; (?i)
9478 (forward-char 2))
9480 (forward-char 1))))
9481 (setq c (if embed (current-indentation) (1- (current-column)))
9482 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
9483 (or (looking-at "[ \t]*[\n#]")
9484 (progn
9485 (insert "\n")))
9486 (goto-char e)
9487 (beginning-of-line)
9488 (if (re-search-forward "[^ \t]" e t)
9489 (progn ; Something before the ending delimiter
9490 (goto-char e)
9491 (delete-horizontal-space)
9492 (insert "\n")
9493 (cperl-make-indent c)
9494 (set-marker e (point))))
9495 (goto-char b)
9496 (end-of-line 2)
9497 (while (< (point) (marker-position e))
9498 (beginning-of-line)
9499 (setq s (point)
9500 inline t)
9501 (skip-chars-forward " \t")
9502 (delete-region s (point))
9503 (cperl-make-indent c1)
9504 (while (and
9505 inline
9506 (looking-at
9507 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
9508 "\\|" ; Embedded variable
9509 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
9510 "\\|" ; $ ^
9511 "[$^]"
9512 "\\|" ; simple-code simple-code*?
9513 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
9514 "\\|" ; Class
9515 "\\(\\[\\)" ; 6
9516 "\\|" ; Grouping
9517 "\\((\\(\\?\\)?\\)" ; 7 8
9518 "\\|" ; |
9519 "\\(|\\)"))) ; 9
9520 (goto-char (match-end 0))
9521 (setq spaces t)
9522 (cond ((match-beginning 1) ; Alphanum word + junk
9523 (forward-char -1))
9524 ((or (match-beginning 3) ; $ab[12]
9525 (and (match-beginning 5) ; X* X+ X{2,3}
9526 (eq (preceding-char) ?\{)))
9527 (forward-char -1)
9528 (forward-sexp 1))
9529 ((and ; [], already syntaxified
9530 (match-beginning 6)
9531 cperl-regexp-scan
9532 cperl-use-syntax-table-text-property)
9533 (forward-char -1)
9534 (forward-sexp 1)
9535 (or (eq (preceding-char) ?\])
9536 (error "[]-group not terminated"))
9537 (re-search-forward
9538 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
9539 ((match-beginning 6) ; []
9540 (setq tmp (point))
9541 (if (looking-at "\\^?\\]")
9542 (goto-char (match-end 0)))
9543 ;; XXXX POSIX classes?!
9544 (while (and (not pos)
9545 (re-search-forward "\\[:\\|\\]" e t))
9546 (if (eq (preceding-char) ?:)
9547 (or (re-search-forward ":\\]" e t)
9548 (error "[:POSIX:]-group in []-group not terminated"))
9549 (setq pos t)))
9550 (or (eq (preceding-char) ?\])
9551 (error "[]-group not terminated"))
9552 (re-search-forward
9553 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
9554 ((match-beginning 7) ; ()
9555 (goto-char (match-beginning 0))
9556 (setq pos (current-column))
9557 (or (eq pos c1)
9558 (progn
9559 (delete-horizontal-space)
9560 (insert "\n")
9561 (cperl-make-indent c1)))
9562 (setq tmp (point))
9563 (forward-sexp 1)
9564 ;; (or (forward-sexp 1)
9565 ;; (progn
9566 ;; (goto-char tmp)
9567 ;; (error "()-group not terminated")))
9568 (set-marker m (1- (point)))
9569 (set-marker m1 (point))
9570 (if (= level 1)
9571 (if (progn ; indent rigidly if multiline
9572 ;; In fact does not make a lot of sense, since
9573 ;; the starting position can be already lost due
9574 ;; to insertion of "\n" and " "
9575 (goto-char tmp)
9576 (search-forward "\n" m1 t))
9577 (indent-rigidly (point) m1 (- c1 pos)))
9578 (setq level (1- level))
9579 (cond
9580 ((not (match-beginning 8))
9581 (cperl-beautify-regexp-piece tmp m t level))
9582 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
9584 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
9585 (goto-char (+ 2 tmp))
9586 (forward-sexp 1)
9587 (cperl-beautify-regexp-piece (point) m t level))
9588 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
9589 (goto-char (+ 3 tmp))
9590 (cperl-beautify-regexp-piece (point) m t level))
9592 (cperl-beautify-regexp-piece tmp m t level))))
9593 (goto-char m1)
9594 (cond ((looking-at "[*+?]\\??")
9595 (goto-char (match-end 0)))
9596 ((eq (following-char) ?\{)
9597 (forward-sexp 1)
9598 (if (eq (following-char) ?\?)
9599 (forward-char))))
9600 (skip-chars-forward " \t")
9601 (setq spaces nil)
9602 (if (looking-at "[#\n]")
9603 (progn
9604 (or (eolp) (indent-for-comment))
9605 (beginning-of-line 2))
9606 (delete-horizontal-space)
9607 (insert "\n"))
9608 (end-of-line)
9609 (setq inline nil))
9610 ((match-beginning 9) ; |
9611 (forward-char -1)
9612 (setq tmp (point))
9613 (beginning-of-line)
9614 (if (re-search-forward "[^ \t]" tmp t)
9615 (progn
9616 (goto-char tmp)
9617 (delete-horizontal-space)
9618 (insert "\n"))
9619 ;; first at line
9620 (delete-region (point) tmp))
9621 (cperl-make-indent c)
9622 (forward-char 1)
9623 (skip-chars-forward " \t")
9624 (setq spaces nil)
9625 (if (looking-at "[#\n]")
9626 (beginning-of-line 2)
9627 (delete-horizontal-space)
9628 (insert "\n"))
9629 (end-of-line)
9630 (setq inline nil)))
9631 (or (looking-at "[ \t\n]")
9632 (not spaces)
9633 (insert " "))
9634 (skip-chars-forward " \t"))
9635 (or (looking-at "[#\n]")
9636 (error "Unknown code `%s' in a regexp"
9637 (buffer-substring (point) (1+ (point)))))
9638 (and inline (end-of-line 2)))
9639 ;; Special-case the last line of group
9640 (if (and (>= (point) (marker-position e))
9641 (/= (current-indentation) c))
9642 (progn
9643 (beginning-of-line)
9644 (cperl-make-indent c)))))
9646 (defun cperl-make-regexp-x ()
9647 ;; Returns position of the start
9648 ;; XXX this is called too often! Need to cache the result!
9649 (save-excursion
9650 (or cperl-use-syntax-table-text-property
9651 (error "I need to have a regexp marked!"))
9652 ;; Find the start
9653 (if (looking-at "\\s|")
9654 nil ; good already
9655 (if (looking-at "\\([smy]\\|qr\\|rx\\)\\s|") ; perl6: rx
9656 (forward-char 1)
9657 (re-search-backward "\\s|"))) ; Assume it is scanned already.
9658 ;;(forward-char 1)
9659 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
9660 (sub-p (eq (preceding-char) ?s)) s)
9661 (forward-sexp 1)
9662 (set-marker e (1- (point)))
9663 (setq delim (preceding-char))
9664 (if (and sub-p (eq delim (char-after (- (point) 2))))
9665 (error "Possible s/blah// - do not know how to deal with"))
9666 (if sub-p (forward-sexp 1))
9667 (if (looking-at "\\sw*x")
9668 (setq have-x t)
9669 (insert "x"))
9670 ;; Protect fragile " ", "#"
9671 (if have-x nil
9672 (goto-char (1+ b))
9673 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
9674 (forward-char -1)
9675 (insert "\\")
9676 (forward-char 1)))
9677 b)))
9679 (defun cperl-beautify-regexp (&optional deep)
9680 "Do it. (Experimental, may change semantics, recheck the result.)
9681 We suppose that the regexp is scanned already."
9682 (interactive "P")
9683 (setq deep (if deep (prefix-numeric-value deep) -1))
9684 (save-excursion
9685 (goto-char (cperl-make-regexp-x))
9686 (let ((b (point)) (e (make-marker)))
9687 (forward-sexp 1)
9688 (set-marker e (1- (point)))
9689 (cperl-beautify-regexp-piece b e nil deep))))
9691 (defun cperl-regext-to-level-start ()
9692 "Goto start of an enclosing group in regexp.
9693 We suppose that the regexp is scanned already."
9694 (interactive)
9695 (let ((limit (cperl-make-regexp-x)) done)
9696 (while (not done)
9697 (or (eq (following-char) ?\()
9698 (search-backward "(" (1+ limit) t)
9699 (error "Cannot find `(' which starts a group"))
9700 (setq done
9701 (save-excursion
9702 (skip-chars-backward "\\")
9703 (looking-at "\\(\\\\\\\\\\)*(")))
9704 (or done (forward-char -1)))))
9706 (defun cperl-contract-level ()
9707 "Find an enclosing group in regexp and contract it.
9708 \(Experimental, may change semantics, recheck the result.)
9709 We suppose that the regexp is scanned already."
9710 (interactive)
9711 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
9712 (cperl-regext-to-level-start)
9713 (let ((b (point)) (e (make-marker)) c)
9714 (forward-sexp 1)
9715 (set-marker e (1- (point)))
9716 (goto-char b)
9717 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
9718 (cond
9719 ((match-beginning 1) ; #-comment
9720 (or c (setq c (current-indentation)))
9721 (beginning-of-line 2) ; Skip
9722 (cperl-make-indent c))
9724 (delete-char -1)
9725 (just-one-space))))))
9727 (defun cperl-contract-levels ()
9728 "Find an enclosing group in regexp and contract all the kids.
9729 \(Experimental, may change semantics, recheck the result.)
9730 We suppose that the regexp is scanned already."
9731 (interactive)
9732 (save-excursion
9733 (condition-case nil
9734 (cperl-regext-to-level-start)
9735 (error ; We are outside outermost group
9736 (goto-char (cperl-make-regexp-x))))
9737 (let ((b (point)) (e (make-marker)) s c)
9738 (forward-sexp 1)
9739 (set-marker e (1- (point)))
9740 (goto-char (1+ b))
9741 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
9742 (cond
9743 ((match-beginning 1) ; Skip
9744 nil)
9745 (t ; Group
9746 (cperl-contract-level)))))))
9748 (defun cperl-beautify-level (&optional deep)
9749 "Find an enclosing group in regexp and beautify it.
9750 \(Experimental, may change semantics, recheck the result.)
9751 We suppose that the regexp is scanned already."
9752 (interactive "P")
9753 (setq deep (if deep (prefix-numeric-value deep) -1))
9754 (save-excursion
9755 (cperl-regext-to-level-start)
9756 (let ((b (point)) (e (make-marker)))
9757 (forward-sexp 1)
9758 (set-marker e (1- (point)))
9759 (cperl-beautify-regexp-piece b e nil deep))))
9761 (defun cperl-invert-if-unless-modifiers ()
9762 "Change `B if A;' into `if (A) {B}' etc if possible.
9763 \(Unfinished.)"
9764 (interactive) ;
9765 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string
9766 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>"))
9767 (and (= (char-syntax (preceding-char)) ?w)
9768 (forward-sexp -1))
9769 (setq pre-if (point))
9770 (cperl-backward-to-start-of-expr)
9771 (setq pre-B (point))
9772 (forward-sexp 1) ; otherwise forward-to-end-of-expr is NOP
9773 (cperl-forward-to-end-of-expr)
9774 (setq post-A (point))
9775 (goto-char pre-if)
9776 (or (looking-at w-rex)
9777 ;; Find the position
9778 (progn (goto-char post-A)
9779 (while (and
9780 (not (looking-at w-rex))
9781 (> (point) pre-B))
9782 (forward-sexp -1))
9783 (setq pre-if (point))))
9784 (or (looking-at w-rex)
9785 (error "Can't find `if', `unless', `while', `until', `for' or `foreach'"))
9786 ;; 1 B 2 ... 3 B-com ... 4 if 5 ... if-com 6 ... 7 A 8
9787 (setq if-string (buffer-substring (match-beginning 0) (match-end 0)))
9788 ;; First, simple part: find code boundaries
9789 (forward-sexp 1)
9790 (setq post-if (point))
9791 (forward-sexp -2)
9792 (forward-sexp 1)
9793 (setq post-B (point))
9794 (cperl-backward-to-start-of-expr)
9795 (setq pre-B (point))
9796 (setq B (buffer-substring pre-B post-B))
9797 (goto-char pre-if)
9798 (forward-sexp 2)
9799 (forward-sexp -1)
9800 ;; May be after $, @, $# etc of a variable
9801 (skip-chars-backward "$@%#")
9802 (setq pre-A (point))
9803 (cperl-forward-to-end-of-expr)
9804 (setq post-A (point))
9805 (setq A (buffer-substring pre-A post-A))
9806 ;; Now modify (from end, to not break the stuff)
9807 (skip-chars-forward " \t;")
9808 (delete-region pre-A (point)) ; we move to pre-A
9809 (insert "\n" B ";\n}")
9810 (and (looking-at "[ \t]*#") (cperl-indent-for-comment))
9811 (delete-region pre-if post-if)
9812 (delete-region pre-B post-B)
9813 (goto-char pre-B)
9814 (insert if-string " (" A ") {")
9815 (setq post-B (point))
9816 (if (looking-at "[ \t]+$")
9817 (delete-horizontal-space)
9818 (if (looking-at "[ \t]*#")
9819 (cperl-indent-for-comment)
9820 (just-one-space)))
9821 (forward-line 1)
9822 (if (looking-at "[ \t]*$")
9823 (progn ; delete line
9824 (delete-horizontal-space)
9825 (delete-region (point) (1+ (point)))))
9826 (cperl-indent-line)
9827 (goto-char (1- post-B))
9828 (forward-sexp 1)
9829 (cperl-indent-line)
9830 (goto-char pre-B)))
9832 (defun cperl-invert-if-unless ()
9833 "Change `if (A) {B}' into `B if A;' etc (or visa versa) if possible.
9834 If the cursor is not on the leading keyword of the BLOCK flavor of
9835 construct, will assume it is the STATEMENT flavor, so will try to find
9836 the appropriate statement modifier."
9837 (interactive)
9838 (and (= (char-syntax (preceding-char)) ?w)
9839 (forward-sexp -1))
9840 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
9841 (let ((pre-if (point))
9842 pre-A post-A pre-B post-B A B state p end-B-code is-block B-comment
9843 (if-string (buffer-substring (match-beginning 0) (match-end 0))))
9844 (forward-sexp 2)
9845 (setq post-A (point))
9846 (forward-sexp -1)
9847 (setq pre-A (point))
9848 (setq is-block (and (eq (following-char) ?\( )
9849 (save-excursion
9850 (condition-case nil
9851 (progn
9852 (forward-sexp 2)
9853 (forward-sexp -1)
9854 (eq (following-char) ?\{ ))
9855 (error nil)))))
9856 (if is-block
9857 (progn
9858 (goto-char post-A)
9859 (forward-sexp 1)
9860 (setq post-B (point))
9861 (forward-sexp -1)
9862 (setq pre-B (point))
9863 (if (and (eq (following-char) ?\{ )
9864 (progn
9865 (cperl-backward-to-noncomment post-A)
9866 (eq (preceding-char) ?\) )))
9867 (if (condition-case nil
9868 (progn
9869 (goto-char post-B)
9870 (forward-sexp 1)
9871 (forward-sexp -1)
9872 (looking-at "\\<els\\(e\\|if\\)\\>"))
9873 (error nil))
9874 (error
9875 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" if-string)
9876 (goto-char (1- post-B))
9877 (cperl-backward-to-noncomment pre-B)
9878 (if (eq (preceding-char) ?\;)
9879 (forward-char -1))
9880 (setq end-B-code (point))
9881 (goto-char pre-B)
9882 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" end-B-code t)
9883 (setq p (match-beginning 0)
9884 A (buffer-substring p (match-end 0))
9885 state (parse-partial-sexp pre-B p))
9886 (or (nth 3 state)
9887 (nth 4 state)
9888 (nth 5 state)
9889 (error "`%s' inside `%s' BLOCK" A if-string))
9890 (goto-char (match-end 0)))
9891 ;; Finally got it
9892 (goto-char (1+ pre-B))
9893 (skip-chars-forward " \t\n")
9894 (setq B (buffer-substring (point) end-B-code))
9895 (goto-char end-B-code)
9896 (or (looking-at ";?[ \t\n]*}")
9897 (progn
9898 (skip-chars-forward "; \t\n")
9899 (setq B-comment
9900 (buffer-substring (point) (1- post-B)))))
9901 (and (equal B "")
9902 (setq B "1"))
9903 (goto-char (1- post-A))
9904 (cperl-backward-to-noncomment pre-A)
9905 (or (looking-at "[ \t\n]*)")
9906 (goto-char (1- post-A)))
9907 (setq p (point))
9908 (goto-char (1+ pre-A))
9909 (skip-chars-forward " \t\n")
9910 (setq A (buffer-substring (point) p))
9911 (delete-region pre-B post-B)
9912 (delete-region pre-A post-A)
9913 (goto-char pre-if)
9914 (insert B " ")
9915 (and B-comment (insert B-comment " "))
9916 (just-one-space)
9917 (forward-word 1)
9918 (setq pre-A (point))
9919 (insert " " A ";")
9920 (delete-horizontal-space)
9921 (setq post-B (point))
9922 (if (looking-at "#")
9923 (indent-for-comment))
9924 (goto-char post-B)
9925 (forward-char -1)
9926 (delete-horizontal-space)
9927 (goto-char pre-A)
9928 (just-one-space)
9929 (goto-char pre-if)
9930 (setq pre-A (set-marker (make-marker) pre-A))
9931 (while (<= (point) (marker-position pre-A))
9932 (cperl-indent-line)
9933 (forward-line 1))
9934 (goto-char (marker-position pre-A))
9935 (if B-comment
9936 (progn
9937 (forward-line -1)
9938 (indent-for-comment)
9939 (goto-char (marker-position pre-A)))))
9940 (error "`%s' (EXPR) not with an {BLOCK}" if-string)))
9941 ;; (error "`%s' not with an (EXPR)" if-string)
9942 (forward-sexp -1)
9943 (cperl-invert-if-unless-modifiers)))
9944 ;;(error "Not at `if', `unless', `while', `until', `for' or `foreach'")
9945 (cperl-invert-if-unless-modifiers)))
9947 ;;; By Anthony Foiani <afoiani@uswest.com>
9948 ;;; Getting help on modules in C-h f ?
9949 ;;; This is a modified version of `man'.
9950 ;;; Need to teach it how to lookup functions
9951 ;;;###autoload
9952 (defun cperl-perldoc (word)
9953 "Run `perldoc' on WORD."
9954 (interactive
9955 (list (let* ((default-entry (cperl-word-at-point))
9956 (input (read-string
9957 (format "perldoc entry%s: "
9958 (if (string= default-entry "")
9960 (format " (default %s)" default-entry))))))
9961 (if (string= input "")
9962 (if (string= default-entry "")
9963 (error "No perldoc args given")
9964 default-entry)
9965 input))))
9966 (require 'man)
9967 (let* ((case-fold-search nil)
9968 (is-func (and
9969 (string-match "^[a-z]+$" word)
9970 (string-match (concat "^" word "\\>")
9971 (documentation-property
9972 'cperl-short-docs
9973 'variable-documentation))))
9974 (manual-program (if is-func "perldoc -f" "perldoc")))
9975 (cond
9976 (cperl-xemacs-p
9977 (let ((Manual-program "perldoc")
9978 (Manual-switches (if is-func (list "-f"))))
9979 (manual-entry word)))
9981 (Man-getpage-in-background word)))))
9983 ;;;###autoload
9984 (defun cperl-perldoc-at-point ()
9985 "Run a `perldoc' on the word around point."
9986 (interactive)
9987 (cperl-perldoc (cperl-word-at-point)))
9989 (defcustom pod2man-program "pod2man"
9990 "*File name for `pod2man'."
9991 :type 'file
9992 :group 'cperl)
9994 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
9995 (defun cperl-pod-to-manpage ()
9996 "Create a virtual manpage in Emacs from the Perl Online Documentation."
9997 (interactive)
9998 (require 'man)
9999 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
10000 (bufname (concat "Man " buffer-file-name))
10001 (buffer (generate-new-buffer bufname)))
10002 (save-excursion
10003 (set-buffer buffer)
10004 (let ((process-environment (copy-sequence process-environment)))
10005 ;; Prevent any attempt to use display terminal fanciness.
10006 (setenv "TERM" "dumb")
10007 (set-process-sentinel
10008 (start-process pod2man-program buffer "sh" "-c"
10009 (format (cperl-pod2man-build-command) pod2man-args))
10010 'Man-bgproc-sentinel)))))
10012 ;;; Updated version by him too
10013 (defun cperl-build-manpage ()
10014 "Create a virtual manpage in Emacs from the POD in the file."
10015 (interactive)
10016 (require 'man)
10017 (cond
10018 (cperl-xemacs-p
10019 (let ((Manual-program "perldoc"))
10020 (manual-entry buffer-file-name)))
10022 (let* ((manual-program "perldoc"))
10023 (Man-getpage-in-background buffer-file-name)))))
10025 (defun cperl-pod2man-build-command ()
10026 "Builds the entire background manpage and cleaning command."
10027 (let ((command (concat pod2man-program " %s 2>/dev/null"))
10028 (flist (and (boundp 'Man-filter-list) Man-filter-list)))
10029 (while (and flist (car flist))
10030 (let ((pcom (car (car flist)))
10031 (pargs (cdr (car flist))))
10032 (setq command
10033 (concat command " | " pcom " "
10034 (mapconcat '(lambda (phrase)
10035 (if (not (stringp phrase))
10036 (error "Malformed Man-filter-list"))
10037 phrase)
10038 pargs " ")))
10039 (setq flist (cdr flist))))
10040 command))
10043 (defun cperl-next-interpolated-REx-1 ()
10044 "Move point to next REx which has interpolated parts without //o.
10045 Skips RExes consisting of one interpolated variable.
10047 Note that skipped RExen are not performance hits."
10048 (interactive "")
10049 (cperl-next-interpolated-REx 1))
10051 (defun cperl-next-interpolated-REx-0 ()
10052 "Move point to next REx which has interpolated parts without //o."
10053 (interactive "")
10054 (cperl-next-interpolated-REx 0))
10056 (defun cperl-next-interpolated-REx (&optional skip beg limit)
10057 "Move point to next REx which has interpolated parts.
10058 SKIP is a list of possible types to skip, BEG and LIMIT are the starting
10059 point and the limit of search (default to point and end of buffer).
10061 SKIP may be a number, then it behaves as list of numbers up to SKIP; this
10062 semantic may be used as a numeric argument.
10064 Types are 0 for / $rex /o (interpolated once), 1 for /$rex/ (if $rex is
10065 a result of qr//, this is not a performance hit), t for the rest."
10066 (interactive "P")
10067 (if (numberp skip) (setq skip (list 0 skip)))
10068 (or beg (setq beg (point)))
10069 (or limit (setq limit (point-max))) ; needed for n-s-p-c
10070 (let (pp)
10071 (and (eq (get-text-property beg 'syntax-type) 'string)
10072 (setq beg (next-single-property-change beg 'syntax-type nil limit)))
10073 (cperl-map-pods-heres
10074 (function (lambda (s e p)
10075 (if (memq (get-text-property s 'REx-interpolated) skip)
10077 (setq pp s)
10078 nil))) ; nil stops
10079 'REx-interpolated beg limit)
10080 (if pp (goto-char pp)
10081 (message "No more interpolated REx"))))
10083 ;;; Initial version contributed by Trey Belew
10084 (defun cperl-here-doc-spell (&optional beg end)
10085 "Spell-check HERE-documents in the Perl buffer.
10086 If a region is highlighted, restricts to the region."
10087 (interactive "")
10088 (cperl-pod-spell t beg end))
10090 (defun cperl-pod-spell (&optional do-heres beg end)
10091 "Spell-check POD documentation.
10092 If invoked with prefix argument, will do HERE-DOCs instead.
10093 If a region is highlighted, restricts to the region."
10094 (interactive "P")
10095 (save-excursion
10096 (let (beg end)
10097 (if (cperl-mark-active)
10098 (setq beg (min (mark) (point))
10099 end (max (mark) (point)))
10100 (setq beg (point-min)
10101 end (point-max)))
10102 (cperl-map-pods-heres (function
10103 (lambda (s e p)
10104 (if do-heres
10105 (setq e (save-excursion
10106 (goto-char e)
10107 (forward-line -1)
10108 (point))))
10109 (ispell-region s e)
10111 (if do-heres 'here-doc-group 'in-pod)
10112 beg end))))
10114 (defun cperl-map-pods-heres (func &optional prop s end)
10115 "Executes a function over regions of pods or here-documents.
10116 PROP is the text-property to search for; default to `in-pod'. Stop when
10117 function returns nil."
10118 (let (pos posend has-prop (cont t))
10119 (or prop (setq prop 'in-pod))
10120 (or s (setq s (point-min)))
10121 (or end (setq end (point-max)))
10122 (cperl-update-syntaxification end end)
10123 (save-excursion
10124 (goto-char (setq pos s))
10125 (while (and cont (< pos end))
10126 (setq has-prop (get-text-property pos prop))
10127 (setq posend (next-single-property-change pos prop nil end))
10128 (and has-prop
10129 (setq cont (funcall func pos posend prop)))
10130 (setq pos posend)))))
10132 ;;; Based on code by Masatake YAMATO:
10133 (defun cperl-get-here-doc-region (&optional pos pod)
10134 "Return HERE document region around the point.
10135 Return nil if the point is not in a HERE document region. If POD is non-nil,
10136 will return a POD section if point is in a POD section."
10137 (or pos (setq pos (point)))
10138 (cperl-update-syntaxification pos pos)
10139 (if (or (eq 'here-doc (get-text-property pos 'syntax-type))
10140 (and pod
10141 (eq 'pod (get-text-property pos 'syntax-type))))
10142 (let ((b (cperl-beginning-of-property pos 'syntax-type))
10143 (e (next-single-property-change pos 'syntax-type)))
10144 (cons b (or e (point-max))))))
10146 (defun cperl-narrow-to-here-doc (&optional pos)
10147 "Narrows editing region to the HERE-DOC at POS.
10148 POS defaults to the point."
10149 (interactive "d")
10150 (or pos (setq pos (point)))
10151 (let ((p (cperl-get-here-doc-region pos)))
10152 (or p (error "Not inside a HERE document"))
10153 (narrow-to-region (car p) (cdr p))
10154 (message
10155 "When you are finished with narrow editing, type C-x n w")))
10157 (defun cperl-select-this-pod-or-here-doc (&optional pos)
10158 "Select the HERE-DOC (or POD section) at POS.
10159 POS defaults to the point."
10160 (interactive "d")
10161 (let ((p (cperl-get-here-doc-region pos t)))
10162 (if p
10163 (progn
10164 (goto-char (car p))
10165 (push-mark (cdr p) nil t)) ; Message, activate in transient-mode
10166 (message "I do not think POS is in POD or a HERE-doc..."))))
10168 (defun cperl-facemenu-add-face-function (face end)
10169 "A callback to process user-initiated font-change requests.
10170 Translates `bold', `italic', and `bold-italic' requests to insertion of
10171 corresponding POD directives, and `underline' to C<> POD directive.
10173 Such requests are usually bound to M-o LETTER."
10174 (or (get-text-property (point) 'in-pod)
10175 (error "Faces can only be set within POD"))
10176 (setq facemenu-end-add-face (if (eq face 'bold-italic) ">>" ">"))
10177 (cdr (or (assq face '((bold . "B<")
10178 (italic . "I<")
10179 (bold-italic . "B<I<")
10180 (underline . "C<")))
10181 (error "Face %s not configured for cperl-mode"
10182 face))))
10184 (defun cperl-time-fontification (&optional l step lim)
10185 "Times how long it takes to do incremental fontification in a region.
10186 L is the line to start at, STEP is the number of lines to skip when
10187 doing next incremental fontification, LIM is the maximal number of
10188 incremental fontification to perform. Messages are accumulated in
10189 *Messages* buffer.
10191 May be used for pinpointing which construct slows down buffer fontification:
10192 start with default arguments, then refine the slowdown regions."
10193 (interactive "nLine to start at: \nnStep to do incremental fontification: ")
10194 (or l (setq l 1))
10195 (or step (setq step 500))
10196 (or lim (setq lim 40))
10197 (let* ((timems (function (lambda ()
10198 (let ((tt (current-time)))
10199 (+ (* 1000 (nth 1 tt)) (/ (nth 2 tt) 1000))))))
10200 (tt (funcall timems)) (c 0) delta tot)
10201 (goto-line l)
10202 (cperl-mode)
10203 (setq tot (- (- tt (setq tt (funcall timems)))))
10204 (message "cperl-mode at %s: %s" l tot)
10205 (while (and (< c lim) (not (eobp)))
10206 (forward-line step)
10207 (setq l (+ l step))
10208 (setq c (1+ c))
10209 (cperl-update-syntaxification (point) (point))
10210 (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
10211 (message "to %s:%6s,%7s" l delta tot))
10212 tot))
10214 (defun cperl-emulate-lazy-lock (&optional window-size)
10215 "Emulate `lazy-lock' without `condition-case', so `debug-on-error' works.
10216 Start fontifying the buffer from the start (or end) using the given
10217 WINDOW-SIZE (units is lines). Negative WINDOW-SIZE starts at end, and
10218 goes backwards; default is -50. This function is not CPerl-specific; it
10219 may be used to debug problems with delayed incremental fontification."
10220 (interactive
10221 "nSize of window for incremental fontification, negative goes backwards: ")
10222 (or window-size (setq window-size -50))
10223 (let ((pos (if (> window-size 0)
10224 (point-min)
10225 (point-max)))
10227 (goto-char pos)
10228 (normal-mode)
10229 ;; Why needed??? With older font-locks???
10230 (set (make-local-variable 'font-lock-cache-position) (make-marker))
10231 (while (if (> window-size 0)
10232 (< pos (point-max))
10233 (> pos (point-min)))
10234 (setq p (progn
10235 (forward-line window-size)
10236 (point)))
10237 (font-lock-fontify-region (min p pos) (max p pos))
10238 (setq pos p))))
10241 (defun cperl-lazy-install ()) ; Avoid a warning
10242 (defun cperl-lazy-unstall ()) ; Avoid a warning
10244 (if (fboundp 'run-with-idle-timer)
10245 (progn
10246 (defvar cperl-help-shown nil
10247 "Non-nil means that the help was already shown now.")
10249 (defvar cperl-lazy-installed nil
10250 "Non-nil means that the lazy-help handlers are installed now.")
10252 (defun cperl-lazy-install ()
10253 "Switches on Auto-Help on Perl constructs (put in the message area).
10254 Delay of auto-help controlled by `cperl-lazy-help-time'."
10255 (interactive)
10256 (make-variable-buffer-local 'cperl-help-shown)
10257 (if (and (cperl-val 'cperl-lazy-help-time)
10258 (not cperl-lazy-installed))
10259 (progn
10260 (add-hook 'post-command-hook 'cperl-lazy-hook)
10261 (run-with-idle-timer
10262 (cperl-val 'cperl-lazy-help-time 1000000 5)
10264 'cperl-get-help-defer)
10265 (setq cperl-lazy-installed t))))
10267 (defun cperl-lazy-unstall ()
10268 "Switches off Auto-Help on Perl constructs (put in the message area).
10269 Delay of auto-help controlled by `cperl-lazy-help-time'."
10270 (interactive)
10271 (remove-hook 'post-command-hook 'cperl-lazy-hook)
10272 (cancel-function-timers 'cperl-get-help-defer)
10273 (setq cperl-lazy-installed nil))
10275 (defun cperl-lazy-hook ()
10276 (setq cperl-help-shown nil))
10278 (defun cperl-get-help-defer ()
10279 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
10280 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
10281 (cperl-get-help)
10282 (setq cperl-help-shown t))))
10283 (cperl-lazy-install)))
10286 ;;; Plug for wrong font-lock:
10288 (defun cperl-font-lock-unfontify-region-function (beg end)
10289 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
10290 (inhibit-read-only t) (inhibit-point-motion-hooks t)
10291 before-change-functions after-change-functions
10292 deactivate-mark buffer-file-name buffer-file-truename)
10293 (remove-text-properties beg end '(face nil))
10294 (if (and (not modified) (buffer-modified-p))
10295 (set-buffer-modified-p nil))))
10297 (defun cperl-font-lock-fontify-region-function (beg end loudly)
10298 "Extends the region to safe positions, then calls the default function.
10299 Newer `font-lock's can do it themselves.
10300 We unwind only as far as needed for fontification. Syntaxification may
10301 do extra unwind via `cperl-unwind-to-safe'."
10302 (save-excursion
10303 (goto-char beg)
10304 (while (and beg
10305 (progn
10306 (beginning-of-line)
10307 (eq (get-text-property (setq beg (point)) 'syntax-type)
10308 'multiline)))
10309 (if (setq beg (cperl-beginning-of-property beg 'syntax-type))
10310 (goto-char beg)))
10311 (setq beg (point))
10312 (goto-char end)
10313 (while (and end
10314 (progn
10315 (or (bolp) (condition-case nil
10316 (forward-line 1)
10317 (error nil)))
10318 (eq (get-text-property (setq end (point)) 'syntax-type)
10319 'multiline)))
10320 (setq end (next-single-property-change end 'syntax-type nil (point-max)))
10321 (goto-char end))
10322 (setq end (point)))
10323 (font-lock-default-fontify-region beg end loudly))
10325 (defvar cperl-d-l nil)
10326 (defun cperl-fontify-syntaxically (end)
10327 ;; Some vars for debugging only
10328 ;; (message "Syntaxifying...")
10329 (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
10330 (istate (car cperl-syntax-state))
10331 start from-start edebug-backtrace-buffer)
10332 (if (eq cperl-syntaxify-by-font-lock 'backtrace)
10333 (progn
10334 (require 'edebug)
10335 (let ((f 'edebug-backtrace))
10336 (funcall f)))) ; Avoid compile-time warning
10337 (or cperl-syntax-done-to
10338 (setq cperl-syntax-done-to (point-min)
10339 from-start t))
10340 (setq start (if (and cperl-hook-after-change
10341 (not from-start))
10342 cperl-syntax-done-to ; Fontify without change; ignore start
10343 ;; Need to forget what is after `start'
10344 (min cperl-syntax-done-to (point))))
10345 (goto-char start)
10346 (beginning-of-line)
10347 (setq start (point))
10348 (and cperl-syntaxify-unwind
10349 (setq end (cperl-unwind-to-safe t end)
10350 start (point)))
10351 (and (> end start)
10352 (setq cperl-syntax-done-to start) ; In case what follows fails
10353 (cperl-find-pods-heres start end t nil t))
10354 (if (memq cperl-syntaxify-by-font-lock '(backtrace message))
10355 (message "Syxify req=%s..%s actual=%s..%s done-to: %s=>%s statepos: %s=>%s"
10356 dbg iend start end idone cperl-syntax-done-to
10357 istate (car cperl-syntax-state))) ; For debugging
10358 nil)) ; Do not iterate
10360 (defun cperl-fontify-update (end)
10361 (let ((pos (point-min)) prop posend)
10362 (setq end (point-max))
10363 (while (< pos end)
10364 (setq prop (get-text-property pos 'cperl-postpone)
10365 posend (next-single-property-change pos 'cperl-postpone nil end))
10366 (and prop (put-text-property pos posend (car prop) (cdr prop)))
10367 (setq pos posend)))
10368 nil) ; Do not iterate
10370 (defun cperl-fontify-update-bad (end)
10371 ;; Since fontification happens with different region than syntaxification,
10372 ;; do to the end of buffer, not to END;;; likewise, start earlier if needed
10373 (let* ((pos (point)) (prop (get-text-property pos 'cperl-postpone)) posend)
10374 (if prop
10375 (setq pos (or (cperl-beginning-of-property
10376 (cperl-1+ pos) 'cperl-postpone)
10377 (point-min))))
10378 (while (< pos end)
10379 (setq posend (next-single-property-change pos 'cperl-postpone))
10380 (and prop (put-text-property pos posend (car prop) (cdr prop)))
10381 (setq pos posend)
10382 (setq prop (get-text-property pos 'cperl-postpone))))
10383 nil) ; Do not iterate
10385 ;; Called when any modification is made to buffer text.
10386 (defun cperl-after-change-function (beg end old-len)
10387 ;; We should have been informed about changes by `font-lock'. Since it
10388 ;; does not inform as which calls are defered, do it ourselves
10389 (if cperl-syntax-done-to
10390 (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
10392 (defun cperl-update-syntaxification (from to)
10393 (if (and cperl-use-syntax-table-text-property
10394 cperl-syntaxify-by-font-lock
10395 (or (null cperl-syntax-done-to)
10396 (< cperl-syntax-done-to to)))
10397 (progn
10398 (save-excursion
10399 (goto-char from)
10400 (cperl-fontify-syntaxically to)))))
10402 (defvar cperl-version
10403 (let ((v "Revision: 5.20.2-Pugs "))
10404 (string-match ":\\s *\\([-0-9a-z.]+\\)" v)
10405 (substring v (match-beginning 1) (match-end 1)))
10406 "Version of IZ-supported CPerl package this file is based on.")
10408 (provide 'cperl-mode)
10410 ;;; cperl-mode.el ends here