[t/spec] Add tricky tests (which pass after latest Rakudo patch), unfudge old simple...
[pugs.git] / util / cperl-mode.el
blob9b5dcb5d3e2875e45f66af6c263bba504edc2aee
1 ;;; cperl-mode.el --- Perl code editing commands for Emacs
3 ;; Copyright (C) 1985, 86, 87, 91, 92, 93, 94, 95, 96, 97, 98, 99,
4 ;; 2000, 2003, 2005, 2006
5 ;; Free Software Foundation, Inc.
7 ;; Author: Ilya Zakharevich and Bob Olson
8 ;; Maintainer: Ilya Zakharevich <ilyaz@cpan.org>
9 ;; Keywords: languages, Perl
11 ;; This file is part of GNU Emacs.
13 ;;; This code started from the following message of long time ago
14 ;;; (IZ), but Bob does not maintain this mode any more:
16 ;;; From: olson@mcs.anl.gov (Bob Olson)
17 ;;; Newsgroups: comp.lang.perl
18 ;;; Subject: cperl-mode: Another perl mode for Gnuemacs
19 ;;; Date: 14 Aug 91 15:20:01 GMT
21 ;; Copyright (C) Ilya Zakharevich and Bob Olson
23 ;; This file may be distributed
24 ;; either under the same terms as GNU Emacs, or under the same terms
25 ;; as Perl. You should have received a copy of Perl Artistic license
26 ;; along with the Perl distribution.
28 ;; GNU Emacs is free software; you can redistribute it and/or modify
29 ;; it under the terms of the GNU General Public License as published by
30 ;; the Free Software Foundation; either version 2, or (at your option)
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 ilyaz@cpan.org
44 ;;; XEmacs changes by Peter Arius arius@informatik.uni-erlangen.de
45 ;;; XEmacs 'delete key behavior handling added for XEmacs 20.x by
46 ;;; Gary D. Foster <Gary.Foster@corp.sun.com>
47 ;;; Karl M. Hegbloom <karlheg@inetarena.com>
49 ;;; Commentary:
51 ;; $Id: cperl-mode.el,v 6.2 2008/04/14 23:14:52 vera Exp vera $
53 ;;; If your Emacs does not default to `cperl-mode' on Perl files:
54 ;;; To use this mode put the following into
55 ;;; your .emacs file:
57 ;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)
59 ;; You can either fine-tune the bells and whistles of this mode or
60 ;; bulk enable them by putting
62 ;; (setq cperl-hairy t)
64 ;; in your .emacs file. (Emacs rulers do not consider it politically
65 ;; correct to make whistles enabled by default.)
67 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
68 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
69 ;; `cperl-non-problems', `cperl-praise', `cperl-speed'. <<<<<<
71 ;;; Note also that there are "authoritative" version of this file <<<<<<
72 ;;; (available on http://ilyaz.org/software/emacs/), and versions <<<<<<
73 ;;; "customized" for a particular Emacs distribution by Emacs <<<<<<
74 ;;; maintainers themselves. As expected, the "authoritative" <<<<<<
75 ;;; version is known to be much less buggy. Usually the <<<<<<
76 ;;; maintainers add a verbiage after numbers in `cperl-version'. <<<<<<
78 ;; Additional useful commands to put into your .emacs file (before
79 ;; RMS Emacs 20.3):
81 ;; (setq auto-mode-alist
82 ;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
83 ;; (setq interpreter-mode-alist (append interpreter-mode-alist
84 ;; '(("miniperl" . perl-mode))))
86 ;; The mode information (on C-h m) provides some customization help.
87 ;; If you use font-lock feature of this mode, it is advisable to use
88 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
90 ;; Faces used now: three faces for first-class and second-class keywords
91 ;; and control flow words, one for each: comments, string, labels,
92 ;; functions definitions and packages, arrays, hashes, and variable
93 ;; definitions. If you do not see all these faces, your font-lock does
94 ;; not define them, so you need to define them manually.
95 ;; Maybe you have an obsolete font-lock from 19.28 or earlier. Upgrade.
97 ;; If you have a grayscale monitor, and do not have the variable
98 ;; font-lock-display-type bound to 'grayscale, insert
100 ;; (setq font-lock-display-type 'grayscale)
102 ;; into your .emacs file (this is relevant before RMS Emacs 20).
104 ;; This mode supports font-lock, imenu and mode-compile. In the
105 ;; hairy version font-lock is on, but you should activate imenu
106 ;; yourself (note that mode-compile is not standard yet). Well, you
107 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
108 ;; to bind it like that:
110 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
112 ;;; Font lock bugs as of v4.32:
114 ;; The following kinds of Perl code erroneously start strings:
115 ;; \$` \$' \$"
116 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
117 ;; likewise with m, tr, y, q, qX instead of s
119 ;;; In fact the version of font-lock that this version supports can be
120 ;;; much newer than the version you actually have. This means that a
121 ;;; lot of faces can be set up, but are not visible on your screen
122 ;;; since the coloring rules for this faces are not defined.
124 ;;; Updates: ========================================
126 ;;; Made less hairy by default: parentheses not electric,
127 ;;; linefeed not magic. Bug with abbrev-mode corrected.
129 ;;;; After 1.4:
130 ;;; Better indentation:
131 ;;; subs inside braces should work now,
132 ;;; Toplevel braces obey customization.
133 ;;; indent-for-comment knows about bad cases, cperl-indent-for-comment
134 ;;; moves cursor to a correct place.
135 ;;; cperl-indent-exp written from the scratch! Slow... (quadratic!) :-(
136 ;;; (50 secs on DB::DB (sub of 430 lines), 486/66)
137 ;;; Minor documentation fixes.
138 ;;; Imenu understands packages as prefixes (including nested).
139 ;;; Hairy options can be switched off one-by-one by setting to null.
140 ;;; Names of functions and variables changed to conform to `cperl-' style.
142 ;;;; After 1.5:
143 ;;; Some bugs with indentation of labels (and embedded subs) corrected.
144 ;;; `cperl-indent-region' done (slow :-()).
145 ;;; `cperl-fill-paragraph' done.
146 ;;; Better package support for `imenu'.
147 ;;; Progress indicator for indentation (with `imenu' loaded).
148 ;;; `Cperl-set' was busted, now setting the individual hairy option
149 ;;; should be better.
151 ;;;; After 1.6:
152 ;;; `cperl-set-style' done.
153 ;;; `cperl-check-syntax' done.
154 ;;; Menu done.
155 ;;; New config variables `cperl-close-paren-offset' and `cperl-comment-column'.
156 ;;; Bugs with `cperl-auto-newline' corrected.
157 ;;; `cperl-electric-lbrace' can work with `cperl-auto-newline' in situation
158 ;;; like $hash{.
160 ;;;; 1.7 XEmacs (arius@informatik.uni-erlangen.de):
161 ;;; - use `next-command-event', if `next-command-events' does not exist
162 ;;; - use `find-face' as def. of `is-face'
163 ;;; - corrected def. of `x-color-defined-p'
164 ;;; - added const defs for font-lock-comment-face,
165 ;;; font-lock-keyword-face and font-lock-function-name-face
166 ;;; - added def. of font-lock-variable-name-face
167 ;;; - added (require 'easymenu) inside an `eval-when-compile'
168 ;;; - replaced 4-argument `substitute-key-definition' with ordinary
169 ;;; `define-key's
170 ;;; - replaced `mark-active' in menu definition by `cperl-use-region-p'.
171 ;;; Todo (at least):
172 ;;; - use emacs-vers.el (http://www.cs.utah.edu/~eeide/emacs/emacs-vers.el.gz)
173 ;;; for portable code?
174 ;;; - should `cperl-mode' do a
175 ;;; (if (featurep 'easymenu) (easy-menu-add cperl-menu))
176 ;;; or should this be left to the user's `cperl-mode-hook'?
178 ;;; Some bugs introduced by the above fix corrected (IZ ;-).
179 ;;; Some bugs under XEmacs introduced by the correction corrected.
181 ;;; Some more can remain since there are two many different variants.
182 ;;; Please feedback!
184 ;;; We do not support fontification of arrays and hashes under
185 ;;; obsolete font-lock any more. Upgrade.
187 ;;;; after 1.8 Minor bug with parentheses.
188 ;;;; after 1.9 Improvements from Joe Marzot.
189 ;;;; after 1.10
190 ;;; Does not need easymenu to compile under XEmacs.
191 ;;; `vc-insert-headers' should work better.
192 ;;; Should work with 19.29 and 19.12.
193 ;;; Small improvements to fontification.
194 ;;; Expansion of keywords does not depend on C-? being backspace.
196 ;;; after 1.10+
197 ;;; 19.29 and 19.12 supported.
198 ;;; `cperl-font-lock-enhanced' deprecated. Use font-lock-extra.el.
199 ;;; Support for font-lock-extra.el.
201 ;;;; After 1.11:
202 ;;; Tools submenu.
203 ;;; Support for perl5-info.
204 ;;; `imenu-go-find-at-position' in Tools requires imenu-go.el (see hints above)
205 ;;; Imenu entries do not work with stock imenu.el. Patch sent to maintainers.
206 ;;; Fontifies `require a if b;', __DATA__.
207 ;;; Arglist for auto-fill-mode was incorrect.
209 ;;;; After 1.12:
210 ;;; `cperl-lineup-step' and `cperl-lineup' added: lineup constructions
211 ;;; vertically.
212 ;;; `cperl-do-auto-fill' updated for 19.29 style.
213 ;;; `cperl-info-on-command' now has a default.
214 ;;; Workaround for broken C-h on XEmacs.
215 ;;; VC strings escaped.
216 ;;; C-h f now may prompt for function name instead of going on,
217 ;;; controlled by `cperl-info-on-command-no-prompt'.
219 ;;;; After 1.13:
220 ;;; Msb buffer list includes perl files
221 ;;; Indent-for-comment uses indent-to
222 ;;; Can write tag files using etags.
224 ;;;; After 1.14:
225 ;;; Recognizes (tries to ;-) {...} which are not blocks during indentation.
226 ;;; `cperl-close-paren-offset' affects ?\] too (and ?\} if not block)
227 ;;; Bug with auto-filling comments started with "##" corrected.
229 ;;;; Very slow now: on DB::DB 0.91, 486/66:
231 ;;;Function Name Call Count Elapsed Time Average Time
232 ;;;======================================== ========== ============ ============
233 ;;;cperl-block-p 469 3.7799999999 0.0080597014
234 ;;;cperl-get-state 505 163.39000000 0.3235445544
235 ;;;cperl-comment-indent 12 0.0299999999 0.0024999999
236 ;;;cperl-backward-to-noncomment 939 4.4599999999 0.0047497337
237 ;;;cperl-calculate-indent 505 172.22000000 0.3410297029
238 ;;;cperl-indent-line 505 172.88000000 0.3423366336
239 ;;;cperl-use-region-p 40 0.0299999999 0.0007499999
240 ;;;cperl-indent-exp 1 177.97000000 177.97000000
241 ;;;cperl-to-comment-or-eol 1453 3.9800000000 0.0027391603
242 ;;;cperl-backward-to-start-of-continued-exp 9 0.0300000000 0.0033333333
243 ;;;cperl-indent-region 1 177.94000000 177.94000000
245 ;;;; After 1.15:
246 ;;; Takes into account white space after opening parentheses during indent.
247 ;;; May highlight pods and here-documents: see `cperl-pod-here-scan',
248 ;;; `cperl-pod-here-fontify', `cperl-pod-face'. Does not use this info
249 ;;; for indentation so far.
250 ;;; Fontification updated to 19.30 style.
251 ;;; The change 19.29->30 did not add all the required functionality,
252 ;;; but broke "font-lock-extra.el". Get "choose-color.el" from
253 ;;; http://ilyaz.org/software/emacs
255 ;;;; After 1.16:
256 ;;; else # comment
257 ;;; recognized as a start of a block.
258 ;;; Two different font-lock-levels provided.
259 ;;; `cperl-pod-head-face' introduced. Used for highlighting.
260 ;;; `imenu' marks pods, +Packages moved to the head.
262 ;;;; After 1.17:
263 ;;; Scan for pods highlights here-docs too.
264 ;;; Note that the tag of here-doc may be rehighlighted later by lazy-lock.
265 ;;; Only one here-doc-tag per line is supported, and one in comment
266 ;;; or a string may break fontification.
267 ;;; POD headers were supposed to fill one line only.
269 ;;;; After 1.18:
270 ;;; `font-lock-keywords' were set in 19.30 style _always_. Current scheme
271 ;;; may break under XEmacs.
272 ;;; `cperl-calculate-indent' dis suppose that `parse-start' was defined.
273 ;;; `fontified' tag is added to fontified text as well as `lazy-lock' (for
274 ;;; compatibility with older lazy-lock.el) (older one overfontifies
275 ;;; something nevertheless :-().
276 ;;; Will not indent something inside pod and here-documents.
277 ;;; Fontifies the package name after import/no/bootstrap.
278 ;;; Added new entry to menu with meta-info about the mode.
280 ;;;; After 1.19:
281 ;;; Prefontification works much better with 19.29. Should be checked
282 ;;; with 19.30 as well.
283 ;;; Some misprints in docs corrected.
284 ;;; Now $a{-text} and -text => "blah" are fontified as strings too.
285 ;;; Now the pod search is much stricter, so it can help you to find
286 ;;; pod sections which are broken because of whitespace before =blah
287 ;;; - just observe the fontification.
289 ;;;; After 1.20
290 ;;; Anonymous subs are indented with respect to the level of
291 ;;; indentation of `sub' now.
292 ;;; {} is recognized as hash after `bless' and `return'.
293 ;;; Anonymous subs are split by `cperl-linefeed' as well.
294 ;;; Electric parens embrace a region if present.
295 ;;; To make `cperl-auto-newline' useful,
296 ;;; `cperl-auto-newline-after-colon' is introduced.
297 ;;; `cperl-electric-parens' is now t or nul. The old meaning is moved to
298 ;;; `cperl-electric-parens-string'.
299 ;;; `cperl-toggle-auto-newline' introduced, put on C-c C-a.
300 ;;; `cperl-toggle-abbrev' introduced, put on C-c C-k.
301 ;;; `cperl-toggle-electric' introduced, put on C-c C-e.
302 ;;; Beginning-of-defun-regexp was not anchored.
304 ;;;; After 1.21
305 ;;; Auto-newline grants `cperl-extra-newline-before-brace' if "{" is typed
306 ;;; after ")".
307 ;;; {} is recognized as expression after `tr' and friends.
309 ;;;; After 1.22
310 ;;; Entry Hierarchy added to imenu. Very primitive so far.
311 ;;; One needs newer `imenu-go'.el. A patch to `imenu' is needed as well.
312 ;;; Writes its own TAGS files.
313 ;;; Class viewer based on TAGS files. Does not trace @ISA so far.
314 ;;; 19.31: Problems with scan for PODs corrected.
315 ;;; First POD header correctly fontified.
316 ;;; I needed (setq imenu-use-keymap-menu t) to get good imenu in 19.31.
317 ;;; Apparently it makes a lot of hierarchy code obsolete...
319 ;;;; After 1.23
320 ;;; Tags filler now scans *.xs as well.
321 ;;; The info from *.xs scan is used by the hierarchy viewer.
322 ;;; Hierarchy viewer documented.
323 ;;; Bug in 19.31 imenu documented.
325 ;;;; After 1.24
326 ;;; New location for info-files mentioned,
327 ;;; Electric-; should work better.
328 ;;; Minor bugs with POD marking.
330 ;;;; After 1.25 (probably not...)
331 ;;; `cperl-info-page' introduced.
332 ;;; To make `uncomment-region' working, `comment-region' would
333 ;;; not insert extra space.
334 ;;; Here documents delimiters better recognized
335 ;;; (empty one, and non-alphanums in quotes handled). May be wrong with 1<<14?
336 ;;; `cperl-db' added, used in menu.
337 ;;; imenu scan removes text-properties, for better debugging
338 ;;; - but the bug is in 19.31 imenu.
339 ;;; formats highlighted by font-lock and prescan, embedded comments
340 ;;; are not treated.
341 ;;; POD/friends scan merged in one pass.
342 ;;; Syntax class is not used for analyzing the code, only char-syntax
343 ;;; may be checked against _ or'ed with w.
344 ;;; Syntax class of `:' changed to be _.
345 ;;; `cperl-find-bad-style' added.
347 ;;;; After 1.25
348 ;;; When search for here-documents, we ignore commented << in simplest cases.
349 ;;; `cperl-get-help' added, available on C-h v and from menu.
350 ;;; Auto-help added. Default with `cperl-hairy', switchable on/off
351 ;;; with startup variable `cperl-lazy-help-time' and from
352 ;;; menu. Requires `run-with-idle-timer'.
353 ;;; Highlighting of @abc{@efg} was wrong - interchanged two regexps.
355 ;;;; After 1.27
356 ;;; Indentation: At toplevel after a label - fixed.
357 ;;; 1.27 was put to archives in binary mode ===> DOSish :-(
359 ;;;; After 1.28
360 ;;; Thanks to Martin Buchholz <mrb@Eng.Sun.COM>: misprints in
361 ;;; comments and docstrings corrected, XEmacs support cleaned up.
362 ;;; The closing parenths would enclose the region into matching
363 ;;; parens under the same conditions as the opening ones.
364 ;;; Minor updates to `cperl-short-docs'.
365 ;;; Will not consider <<= as start of here-doc.
367 ;;;; After 1.29
368 ;;; Added an extra advice to look into Micro-docs. ;-).
369 ;;; Enclosing of region when you press a closing parenth is regulated by
370 ;;; `cperl-electric-parens-string'.
371 ;;; Minor updates to `cperl-short-docs'.
372 ;;; `initialize-new-tags-table' called only if present (Does this help
373 ;;; with generation of tags under XEmacs?).
374 ;;; When creating/updating tag files, new info is written at the old place,
375 ;;; or at the end (is this a wanted behaviour? I need this in perl build directory).
377 ;;;; After 1.30
378 ;;; All the keywords from keywords.pl included (maybe with dummy explanation).
379 ;;; No auto-help inside strings, comment, here-docs, formats, and pods.
380 ;;; Shrinkwrapping of info, regulated by `cperl-max-help-size',
381 ;;; `cperl-shrink-wrap-info-frame'.
382 ;;; Info on variables as well.
383 ;;; Recognision of HERE-DOCS improved yet more.
384 ;;; Autonewline works on `}' without warnings.
385 ;;; Autohelp works again on $_[0].
387 ;;;; After 1.31
388 ;;; perl-descr.el found its author - hi, Johan!
389 ;;; Some support for correct indent after here-docs and friends (may
390 ;;; be superseeded by eminent change to Emacs internals).
391 ;;; Should work with older Emaxen as well ( `-style stuff removed).
393 ;;;; After 1.32
395 ;;; Started to add support for `syntax-table' property (should work
396 ;;; with patched Emaxen), controlled by
397 ;;; `cperl-use-syntax-table-text-property'. Currently recognized:
398 ;;; All quote-like operators: m, s, y, tr, qq, qw, qx, q,
399 ;;; // in most frequent context:
400 ;;; after block or
401 ;;; ~ { ( = | & + - * ! , ;
402 ;;; or
403 ;;; while if unless until and or not xor split grep map
404 ;;; Here-documents, formats, PODs,
405 ;;; ${...}
406 ;;; 'abc$'
407 ;;; sub a ($); sub a ($) {}
408 ;;; (provide 'cperl-mode) was missing!
409 ;;; `cperl-after-expr-p' is now much smarter after `}'.
410 ;;; `cperl-praise' added to mini-docs.
411 ;;; Utilities try to support subs-with-prototypes.
413 ;;;; After 1.32.1
414 ;;; `cperl-after-expr-p' is now much smarter after "() {}" and "word {}":
415 ;;; if word is "else, map, grep".
416 ;;; Updated for new values of syntax-table constants.
417 ;;; Uses `help-char' (at last!) (disabled, does not work?!)
418 ;;; A couple of regexps where missing _ in character classes.
419 ;;; -s could be considered as start of regexp, 1../blah/ was not,
420 ;;; as was not /blah/ at start of file.
422 ;;;; After 1.32.2
423 ;;; "\C-hv" was wrongly "\C-hf"
424 ;;; C-hv was not working on `[index()]' because of [] in skip-chars-*.
425 ;;; `__PACKAGE__' supported.
426 ;;; Thanks for Greg Badros: `cperl-lazy-unstall' is more complete,
427 ;;; `cperl-get-help' is made compatible with `query-replace'.
429 ;;;; As of Apr 15, development version of 19.34 supports
430 ;;;; `syntax-table' text properties. Try setting
431 ;;;; `cperl-use-syntax-table-text-property'.
433 ;;;; After 1.32.3
434 ;;; We scan for s{}[] as well (in simplest situations).
435 ;;; We scan for $blah'foo as well.
436 ;;; The default is to use `syntax-table' text property if Emacs is good enough.
437 ;;; `cperl-lineup' is put on C-M-| (=C-M-S-\\).
438 ;;; Start of `cperl-beautify-regexp'.
440 ;;;; After 1.32.4
441 ;;; `cperl-tags-hier-init' did not work in text-mode.
442 ;;; `cperl-noscan-files-regexp' had a misprint.
443 ;;; Generation of Class Hierarchy was broken due to a bug in `x-popup-menu'
444 ;;; in 19.34.
446 ;;;; After 1.33:
447 ;;; my,local highlight vars after {} too.
448 ;;; TAGS could not be created before imenu was loaded.
449 ;;; `cperl-indent-left-aligned-comments' created.
450 ;;; Logic of `cperl-indent-exp' changed a little bit, should be more
451 ;;; robust w.r.t. multiline strings.
452 ;;; Recognition of blah'foo takes into account strings.
453 ;;; Added '.al' to the list of Perl extensions.
454 ;;; Class hierarchy is "mostly" sorted (need to rethink algorthm
455 ;;; of pruning one-root-branch subtrees to get yet better sorting.)
456 ;;; Regeneration of TAGS was busted.
457 ;;; Can use `syntax-table' property when generating TAGS
458 ;;; (governed by `cperl-use-syntax-table-text-property-for-tags').
460 ;;;; After 1.35:
461 ;;; Can process several =pod/=cut sections one after another.
462 ;;; Knows of `extproc' when under `emx', indents with `__END__' and `__DATA__'.
463 ;;; `cperl-under-as-char' implemented (XEmacs people like broken behaviour).
464 ;;; Beautifier for regexps fixed.
465 ;;; `cperl-beautify-level', `cperl-contract-level' coded
467 ;;;; Emacs's 20.2 problems:
468 ;;; `imenu.el' has bugs, `imenu-add-to-menubar' does not work.
469 ;;; Couple of others problems with 20.2 were reported, my ability to check/fix
470 ;;; them is very reduced now.
472 ;;;; After 1.36:
473 ;;; 'C-M-|' in XEmacs fixed
475 ;;;; After 1.37:
476 ;;; &&s was not recognized as start of regular expression;
477 ;;; Will "preprocess" the contents of //e part of s///e too;
478 ;;; What to do with s# blah # foo #e ?
479 ;;; Should handle s;blah;foo;; better.
480 ;;; Now the only known problems with regular expression recognition:
481 ;;;;;;; s<foo>/bar/ - different delimiters (end ignored)
482 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into one chunk)
483 ;;;;;;; s/foo// - empty subst (made into one chunk + '/')
484 ;;;;;;; s/foo/(bar)/ - start-group at start of subst (internal group will not match backwards)
486 ;;;; After 1.38:
487 ;;; We highlight closing / of s/blah/foo/e;
488 ;;; This handles s# blah # foo #e too;
489 ;;; s//blah/, s///, s/blah// works again, and s#blah## too, the algorithm
490 ;;; is much simpler now;
491 ;;; Next round of changes: s\\\ works, s<blah>/foo/,
492 ;;; comments between the first and the second part allowed
493 ;;; Another problem discovered:
494 ;;;;;;; s[foo] <blah>e - e part delimited by different <> (will not match)
495 ;;; `cperl-find-pods-heres' somehow maybe called when string-face is undefined
496 ;;; - put a stupid workaround for 20.1
498 ;;;; After 1.39:
499 ;;; Could indent here-docs for comments;
500 ;;; These problems fixed:
501 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into two chunk)
502 ;;;;;;; s[foo] <blah>e - "e" part delimited by "different" <> (will match)
503 ;;; Matching brackets honor prefices, may expand abbreviations;
504 ;;; When expanding abbrevs, will remove last char only after
505 ;;; self-inserted whitespace;
506 ;;; More convenient "Refress hard constructs" in menu;
507 ;;; `cperl-add-tags-recurse', `cperl-add-tags-recurse-noxs'
508 ;;; added (for -batch mode);
509 ;;; Better handling of errors when scanning for Perl constructs;
510 ;;;;;;; Possible "problem" with class hierarchy in Perl distribution
511 ;;;;;;; directory: ./ext duplicates ./lib;
512 ;;; Write relative paths for generated TAGS;
514 ;;;; After 1.40:
515 ;;; s /// may be separated by "\n\f" too;
516 ;;; `s #blah' recognized as a comment;
517 ;;; Would highlight s/abc//s wrong;
518 ;;; Debugging code in `cperl-electric-keywords' was leaking a message;
520 ;;;; After 1.41:
521 ;;; RMS changes for 20.3 merged
523 ;;;; 2.0.1.0: RMS mode (has 3 misprints)
525 ;;;; After 2.0:
526 ;;; RMS whitespace changes for 20.3 merged
528 ;;;; After 2.1:
529 ;;; History updated
531 ;;;; After 2.2:
532 ;;; Merge `c-style-alist' since `c-mode' is no more. (Somebody who
533 ;;; uses the styles should check that they work OK!)
534 ;;; All the variable warnings go away, some undef functions too.
536 ;;;; After 2.3:
537 ;;; Added `cperl-perldoc' (thanks to Anthony Foiani <afoiani@uswest.com>)
538 ;;; Added `cperl-pod-to-manpage' (thanks to Nick Roberts <Nick.Roberts@src.bae.co.uk>)
539 ;;; All the function warnings go away.
541 ;;;; After 2.4:
542 ;;; `Perl doc', `Regexp' submenus created (latter to allow short displays).
543 ;;; `cperl-clobber-lisp-bindings' added.
544 ;;; $a->y() is not y///.
545 ;;; `cperl-after-block-p' was missing a `save-excursion' => wrong results.
546 ;;; `cperl-val' was defined too late.
547 ;;; `cperl-init-faces' was failing.
548 ;;; Init faces when loading `ps-print'.
550 ;;;; After 2.4:
551 ;;; `cperl-toggle-autohelp' implemented.
552 ;;; `while SPACE LESS' was buggy.
553 ;;; `-text' in `[-text => 1]' was not highlighted.
554 ;;; `cperl-after-block-p' was FALSE after `sub f {}'.
556 ;;;; After 2.5:
557 ;;; `foreachmy', `formy' expanded too.
558 ;;; Expand `=pod-directive'.
559 ;;; `cperl-linefeed' behaves reasonable in POD-directive lines.
560 ;;; `cperl-electric-keyword' prints a message, governed by
561 ;;; `cperl-message-electric-keyword'.
563 ;;;; After 2.6:
564 ;;; Typing `}' was not checking for being block or not.
565 ;;; Beautifying levels in RE: Did not know about lookbehind;
566 ;;; finding *which* level was not intuitive;
567 ;;; `cperl-beautify-levels' added.
568 ;;; Allow here-docs contain `=head1' and friends (at least for keywords).
570 ;;;; After 2.7:
571 ;;; Fix for broken `font-lock-unfontify-region-function'. Should
572 ;;; preserve `syntax-table' properties even with `lazy-lock'.
574 ;;;; After 2.8:
575 ;;; Some more compile time warnings crept in.
576 ;;; `cperl-indent-region-fix-else' implemented.
577 ;;; `cperl-fix-line-spacing' implemented.
578 ;;; `cperl-invert-if-unless' implemented (C-c C-t and in Menu).
579 ;;; Upgraded hints to mention 20.2's goods/bads.
580 ;;; Started to use `cperl-extra-newline-before-brace-multiline',
581 ;;; `cperl-break-one-line-blocks-when-indent',
582 ;;; `cperl-fix-hanging-brace-when-indent', `cperl-merge-trailing-else'.
584 ;;;; After 2.9:
585 ;;; Workaround for another `font-lock's `syntax-table' text-property bug.
586 ;;; `zerop' could be applied to nil.
587 ;;; At last, may work with `font-lock' without setting `cperl-font-lock'.
588 ;;; (We expect that starting from 19.33, `font-lock' supports keywords
589 ;;; being a function - what is a correct version?)
590 ;;; Rename `cperl-indent-region-fix-else' to
591 ;;; `cperl-indent-region-fix-constructs'.
592 ;;; `cperl-fix-line-spacing' could be triggered inside strings, would not
593 ;;; know what to do with BLOCKs of map/printf/etc.
594 ;;; `cperl-merge-trailing-else' and `cperl-fix-line-spacing' handle
595 ;;; `continue' too.
596 ;;; Indentation after {BLOCK} knows about map/printf/etc.
597 ;;; Finally: treat after-comma lines as continuation lines.
599 ;;;; After 2.10:
600 ;;; `continue' made electric.
601 ;;; Electric `do' inserts `do/while'.
602 ;;; Some extra compile-time warnings crept in.
603 ;;; `font-lock' of 19.33 could not handle font-lock-keywords being a function
604 ;;; returning a symbol.
606 ;;;; After 2.11:
607 ;;; Changes to make syntaxification to be autoredone via `font-lock'.
608 ;;; Switched on by `cperl-syntaxify-by-font-lock', off by default so far.
610 ;;;; After 2.12:
611 ;;; Remove some commented out chunks.
612 ;;; Styles are slightly updated (a lot of work is needed, especially
613 ;;; with new `cperl-fix-line-spacing').
615 ;;;; After 2.13:
616 ;;; Old value of style is memorized when choosing a new style, may be
617 ;;; restored from the same menu.
618 ;;; Mode-documentation added to micro-docs.
619 ;;; `cperl-praise' updated.
620 ;;; `cperl-toggle-construct-fix' added on C-c C-w and menu.
621 ;;; `auto-fill-mode' added on C-c C-f and menu.
622 ;;; `PerlStyle' style added.
623 ;;; Message for termination of scan corrected.
625 ;;;; After 2.14:
627 ;;; Did not work with -q
629 ;;;; After 2.15:
631 ;;; `cperl-speed' hints added.
632 ;;; Minor style fixes.
634 ;;;; After 2.15:
635 ;;; Make backspace electric after expansion of `else/continue' too.
637 ;;;; After 2.16:
638 ;;; Starting to merge changes to RMS emacs version.
640 ;;;; After 2.17:
641 ;;; Merged custom stuff and darn `font-lock-constant-face'.
643 ;;;; After 2.18:
644 ;;; Bumped the version to 3.1
646 ;;;; After 3.1:
647 ;;; Fixed customization to honor cperl-hairy.
648 ;;; Created customization groups. Sent to RMS to include into 2.3.
650 ;;;; After 3.2:
651 ;;; Interaction of `font-lock-hot-pass' and `cperl-syntaxify-by-font-lock'.
652 ;;; (`cperl-after-block-and-statement-beg'):
653 ;;; (`cperl-after-block-p'):
654 ;;; (`cperl-after-expr-p'): It is BLOCK if we reach lim when backup sexp.
655 ;;; (`cperl-indent-region'): Make a marker for END - text added/removed.
656 ;;; (`cperl-style-alist', `cperl-styles-entries')
657 ;;; Include `cperl-merge-trailing-else' where the value is clear.
659 ;;;; After 3.3:
660 ;;; (`cperl-tips'):
661 ;;; (`cperl-problems'): Improvements to docs.
663 ;;;; After 3.4:
664 ;;; (`cperl-mode'): Make lazy syntaxification possible.
665 ;;; (`cperl-find-pods-heres'): Safe a position in buffer where it is safe to
666 ;;; restart syntaxification.
667 ;;; (`cperl-syntaxify-by-font-lock'): Set to t, should be safe now.
669 ;;;; After 3.5:
670 ;;; (`cperl-syntaxify-by-font-lock'): Better default, customizes to
671 ;;; `message' too.
673 ;;;; After 3.6:
674 ;;; (`cperl-find-pods-heres'): changed so that -d ?foo? is a RE.
675 ;;; (`cperl-array-face'): changed name from `font-lock-emphasized-face'.
676 ;;; (`cperl-hash-face'): changed name from `font-lock-other-emphasized-face'.
677 ;;; Use `defface' to define these two extra faces.
679 ;;;; After 3.7:
680 ;;; Can use linear algorithm for indentation if Emacs supports it:
681 ;;; indenting DB::DB (800+ lines) improved from 69 sec to 11 sec
682 ;;; (73 vs 15 with imenu).
683 ;;; (`cperl-emacs-can-parse'): New state.
684 ;;; (`cperl-indent-line'): Corrected to use global state.
685 ;;; (`cperl-calculate-indent'): Likewise.
686 ;;; (`cperl-fix-line-spacing'): Likewise (not used yet).
688 ;;;; After 3.8:
689 ;;; (`cperl-choose-color'): Converted to a function (to be compilable in text-mode).
691 ;;;; After 3.9:
692 ;;; (`cperl-dark-background '): Disable without window-system.
694 ;;;; After 3.10:
695 ;;; Do `defface' only if window-system.
697 ;;;; After 3.11:
698 ;;; (`cperl-fix-line-spacing'): sped up to bail out early.
699 ;;; (`cperl-indent-region'): Disable hooks during the call (how to call them later?).
701 ;;; Now indents 820-line-long function in 6.5 sec (including syntaxification) the first time
702 ;;; (when buffer has few properties), 7.1 sec the second time.
704 ;;;Function Name Call Count Elapsed Time Average Time
705 ;;;========================================= ========== ============ ============
706 ;;;cperl-indent-exp 1 10.039999999 10.039999999
707 ;;;cperl-indent-region 1 10.0 10.0
708 ;;;cperl-indent-line 821 6.2100000000 0.0075639464
709 ;;;cperl-calculate-indent 821 5.0199999999 0.0061144945
710 ;;;cperl-backward-to-noncomment 2856 2.0500000000 0.0007177871
711 ;;;cperl-fontify-syntaxically 2 1.78 0.8900000000
712 ;;;cperl-find-pods-heres 2 1.78 0.8900000000
713 ;;;cperl-update-syntaxification 1 1.78 1.78
714 ;;;cperl-fix-line-spacing 769 1.4800000000 0.0019245773
715 ;;;cperl-after-block-and-statement-beg 163 1.4100000000 0.0086503067
716 ;;;cperl-block-p 775 1.1800000000 0.0015225806
717 ;;;cperl-to-comment-or-eol 3652 1.1200000000 0.0003066812
718 ;;;cperl-after-block-p 165 1.0500000000 0.0063636363
719 ;;;cperl-commentify 141 0.22 0.0015602836
720 ;;;cperl-get-state 813 0.16 0.0001968019
721 ;;;cperl-backward-to-start-of-continued-exp 26 0.12 0.0046153846
722 ;;;cperl-delay-update-hook 2107 0.0899999999 4.271...e-05
723 ;;;cperl-protect-defun-start 141 0.0700000000 0.0004964539
724 ;;;cperl-after-label 407 0.0599999999 0.0001474201
725 ;;;cperl-forward-re 139 0.0299999999 0.0002158273
726 ;;;cperl-comment-indent 26 0.0299999999 0.0011538461
727 ;;;cperl-use-region-p 8 0.0 0.0
728 ;;;cperl-lazy-hook 15 0.0 0.0
729 ;;;cperl-after-expr-p 8 0.0 0.0
730 ;;;cperl-font-lock-unfontify-region-function 1 0.0 0.0
732 ;;;Function Name Call Count Elapsed Time Average Time
733 ;;;========================================= ========== ============ ============
734 ;;;cperl-fix-line-spacing 769 1.4500000000 0.0018855656
735 ;;;cperl-indent-line 13 0.3100000000 0.0238461538
736 ;;;cperl-after-block-and-statement-beg 69 0.2700000000 0.0039130434
737 ;;;cperl-after-block-p 69 0.2099999999 0.0030434782
738 ;;;cperl-calculate-indent 13 0.1000000000 0.0076923076
739 ;;;cperl-backward-to-noncomment 177 0.0700000000 0.0003954802
740 ;;;cperl-get-state 13 0.0 0.0
741 ;;;cperl-to-comment-or-eol 179 0.0 0.0
742 ;;;cperl-get-help-defer 1 0.0 0.0
743 ;;;cperl-lazy-hook 11 0.0 0.0
744 ;;;cperl-after-expr-p 2 0.0 0.0
745 ;;;cperl-block-p 13 0.0 0.0
746 ;;;cperl-after-label 5 0.0 0.0
748 ;;;; After 3.12:
749 ;;; (`cperl-find-pods-heres'): do not warn on `=cut' if doing a chunk only.
751 ;;;; After 3.13:
752 ;;; (`cperl-mode'): load pseudo-faces on `cperl-find-pods-heres' (for 19.30).
753 ;;; (`x-color-defined-p'): was not compiling on XEmacs
754 ;;; (`cperl-find-pods-heres'): 1 << 6 was OK, but 1<<6 was considered as HERE
755 ;;; <file/glob> made into a string.
757 ;;;; After 3.14:
758 ;;; (`cperl-find-pods-heres'): Postpone addition of faces after syntactic step
759 ;;; Recognition of <FH> was wrong.
760 ;;; (`cperl-clobber-lisp-bindings'): if set, C-c variants are the old ones
761 ;;; (`cperl-unwind-to-safe'): New function.
762 ;;; (`cperl-fontify-syntaxically'): Use `cperl-unwind-to-safe' to start at reasonable position.
764 ;;;; After 3.15:
765 ;;; (`cperl-forward-re'): Highlight the trailing / in s/foo// as string.
766 ;;; Highlight the starting // in s//foo/ as function-name.
768 ;;;; After 3.16:
769 ;;; (`cperl-find-pods-heres'): Highlight `gem' in s///gem as a keyword.
771 ;;;; After 4.0:
772 ;;; (`cperl-find-pods-heres'): `qr' added
773 ;;; (`cperl-electric-keyword'): Likewise
774 ;;; (`cperl-electric-else'): Likewise
775 ;;; (`cperl-to-comment-or-eol'): Likewise
776 ;;; (`cperl-make-regexp-x'): Likewise
777 ;;; (`cperl-init-faces'): Likewise, and `lock' (as overridable?).
778 ;;; (`cperl-find-pods-heres'): Knows that split// is null-RE.
779 ;;; Highlights separators in 3-parts expressions
780 ;;; as labels.
782 ;;;; After 4.1:
783 ;;; (`cperl-find-pods-heres'): <> was considered as a glob
784 ;;; (`cperl-syntaxify-unwind'): New configuration variable
785 ;;; (`cperl-fontify-m-as-s'): New configuration variable
787 ;;;; After 4.2:
788 ;;; (`cperl-find-pods-heres'): of the last line being `=head1' fixed.
790 ;;; Handling of a long construct is still buggy if only the part of
791 ;;; construct touches the updated region (we unwind to the start of
792 ;;; long construct, but the end may have residual properties).
794 ;;; (`cperl-unwind-to-safe'): would not go to beginning of buffer.
795 ;;; (`cperl-electric-pod'): check for after-expr was performed
796 ;;; inside of POD too.
798 ;;;; After 4.3:
799 ;;; (`cperl-backward-to-noncomment'): better treatment of PODs and HEREs.
801 ;;; Indent-line works good, but indent-region does not - at toplevel...
802 ;;; (`cperl-unwind-to-safe'): Signature changed.
803 ;;; (`x-color-defined-p'): was defmacro'ed with a tick. Remove another def.
804 ;;; (`cperl-clobber-mode-lists'): New configuration variable.
805 ;;; (`cperl-array-face'): One of definitions was garbled.
807 ;;;; After 4.4:
808 ;;; (`cperl-not-bad-style-regexp'): Updated.
809 ;;; (`cperl-make-regexp-x'): Misprint in a message.
810 ;;; (`cperl-find-pods-heres'): $a-1 ? foo : bar; was a regexp.
811 ;;; `<< (' was considered a start of POD.
812 ;;; Init: `cperl-is-face' was busted.
813 ;;; (`cperl-make-face'): New macros.
814 ;;; (`cperl-force-face'): New macros.
815 ;;; (`cperl-init-faces'): Corrected to use new macros;
816 ;;; `if' for copying `reference-face' to
817 ;;; `constant-face' was backward.
818 ;;; (`font-lock-other-type-face'): Done via `defface' too.
820 ;;;; After 4.5:
821 ;;; (`cperl-init-faces-weak'): use `cperl-force-face'.
822 ;;; (`cperl-after-block-p'): After END/BEGIN we are a block.
823 ;;; (`cperl-mode'): `font-lock-unfontify-region-function'
824 ;;; was set to a wrong function.
825 ;;; (`cperl-comment-indent'): Commenting __END__ was not working.
826 ;;; (`cperl-indent-for-comment'): Likewise.
827 ;;; (Indenting is still misbehaving at toplevel.)
829 ;;;; After 4.5:
830 ;;; (`cperl-unwind-to-safe'): Signature changed, unwinds end too.
831 ;;; (`cperl-find-pods-heres'): mark qq[]-etc sections as syntax-type=string
832 ;;; (`cperl-fontify-syntaxically'): Unwinds start and end to go out of
833 ;;; long strings (not very successful).
835 ;;; >>>> CPerl should be usable in write mode too now <<<<
837 ;;; (`cperl-syntaxify-by-font-lock'): Better default - off in text-mode.
838 ;;; (`cperl-tips'): Updated docs.
839 ;;; (`cperl-problems'): Updated docs.
841 ;;;; After 4.6:
842 ;;; (`cperl-calculate-indent'): Did not consider `,' as continuation mark for statements.
843 ;;; (`cperl-write-tags'): Correct for XEmacs's `visit-tags-table-buffer'.
845 ;;;; After 4.7:
846 ;;; (`cperl-calculate-indent'): Avoid parse-data optimization at toplevel.
847 ;;; Should indent correctly at toplevel too.
848 ;;; (`cperl-tags-hier-init'): Gross hack to pretend we work (are we?).
849 ;;; (`cperl-find-pods-heres'): Was not processing sub protos after a comment ine.
850 ;;; Was treating $a++ <= 5 as a glob.
852 ;;;; After 4.8:
853 ;;; (toplevel): require custom unprotected => failure on 19.28.
854 ;;; (`cperl-xemacs-p') defined when compile too
855 ;;; (`cperl-tags-hier-init'): Another try to work around XEmacs problems
856 ;;; Better progress messages.
857 ;;; (`cperl-find-tags'): Was writing line/pos in a wrong order,
858 ;;; pos off by 1 and not at beg-of-line.
859 ;;; (`cperl-etags-snarf-tag'): New macro
860 ;;; (`cperl-etags-goto-tag-location'): New macro
861 ;;; (`cperl-write-tags'): When removing old TAGS info was not
862 ;;; relativizing filename
864 ;;;; After 4.9:
865 ;;; (`cperl-version'): New variable. New menu entry
867 ;;;; After 4.10:
868 ;;; (`cperl-tips'): Updated.
869 ;;; (`cperl-non-problems'): Updated.
870 ;;; random: References to future 20.3 removed.
872 ;;;; After 4.11:
873 ;;; (`perl-font-lock-keywords'): Would not highlight `sub foo($$);'.
874 ;;; Docstrings: Menu was described as `CPerl' instead of `Perl'
876 ;;;; After 4.12:
877 ;;; (`cperl-toggle-construct-fix'): Was toggling to t instead of 1.
878 ;;; (`cperl-ps-print-init'): Associate `cperl-array-face', `cperl-hash-face'
879 ;;; remove `font-lock-emphasized-face'.
880 ;;; remove `font-lock-other-emphasized-face'.
881 ;;; remove `font-lock-reference-face'.
882 ;;; remove `font-lock-keyword-face'.
883 ;;; Use `eval-after-load'.
884 ;;; (`cperl-init-faces'): remove init `font-lock-other-emphasized-face'.
885 ;;; remove init `font-lock-emphasized-face'.
886 ;;; remove init `font-lock-keyword-face'.
887 ;;; (`cperl-tips-faces'): New variable and an entry into Mini-docs.
888 ;;; (`cperl-indent-region'): Do not indent whitespace lines
889 ;;; (`cperl-indent-exp'): Was not processing else-blocks.
890 ;;; (`cperl-calculate-indent'): Remove another parse-data optimization
891 ;;; at toplevel: would indent correctly.
892 ;;; (`cperl-get-state'): NOP line removed.
894 ;;;; After 4.13:
895 ;;; (`cperl-ps-print-init'): Remove not-CPerl-related faces.
896 ;;; (`cperl-ps-print'): New function and menu entry.
897 ;;; (`cperl-ps-print-face-properties'): New configuration variable.
898 ;;; (`cperl-invalid-face'): New configuration variable.
899 ;;; (`cperl-nonoverridable-face'): New face. Renamed from
900 ;;; `font-lock-other-type-face'.
901 ;;; (`perl-font-lock-keywords'): Highlight trailing whitespace
902 ;;; (`cperl-contract-levels'): Documentation corrected.
903 ;;; (`cperl-contract-level'): Likewise.
905 ;;;; After 4.14:
906 ;;; (`cperl-ps-print'): `ps-print-face-extension-alist' was not in old Emaxen,
907 ;;; same with `ps-extend-face-list'
908 ;;; (`cperl-ps-extend-face-list'): New macro.
910 ;;;; After 4.15:
911 ;;; (`cperl-init-faces'): Interpolate `cperl-invalid-face'.
912 ;;; (`cperl-forward-re'): Emit a meaningful error instead of a cryptic
913 ;;; one for uncomplete REx near end-of-buffer.
914 ;;; (`cperl-find-pods-heres'): Tolerate unfinished REx at end-of-buffer.
916 ;;;; After 4.16:
917 ;;; (`cperl-find-pods-heres'): `unwind-protect' was left commented.
919 ;;;; After 4.17:
920 ;;; (`cperl-invalid-face'): Change to ''underline.
922 ;;;; After 4.18:
923 ;;; (`cperl-find-pods-heres'): / and ? after : start a REx.
924 ;;; (`cperl-after-expr-p'): Skip labels when checking
925 ;;; (`cperl-calculate-indent'): Correct for labels when calculating
926 ;;; indentation of continuations.
927 ;;; Docstring updated.
929 ;;;; After 4.19:
930 ;;; Minor (mostly spelling) corrections from 20.3.3 merged.
932 ;;;; After 4.20:
933 ;;; (`cperl-tips'): Another workaround added. Sent to RMS for 20.4.
935 ;;;; After 4.21:
936 ;;; (`cperl-praise'): Mention linear-time indent.
937 ;;; (`cperl-find-pods-heres'): @if ? a : b was considered a REx.
939 ;;;; After 4.22:
940 ;;; (`cperl-after-expr-p'): Make true after __END__.
941 ;;; (`cperl-electric-pod'): "SYNOPSIS" was misspelled.
943 ;;;; After 4.23:
944 ;;; (`cperl-beautify-regexp-piece'): Was not allowing for *? after a class.
945 ;;; Allow for POSIX char-classes.
946 ;;; Remove trailing whitespace when
947 ;;; adding new linebreak.
948 ;;; Add a level counter to stop shallow.
949 ;;; Indents unprocessed groups rigidly.
950 ;;; (`cperl-beautify-regexp'): Add an optional count argument to go that
951 ;;; many levels deep.
952 ;;; (`cperl-beautify-level'): Likewise
953 ;;; Menu: Add new entries to Regexp menu to do one level
954 ;;; (`cperl-contract-level'): Was entering an infinite loop
955 ;;; (`cperl-find-pods-heres'): Typo (double quoting).
956 ;;; Was detecting < $file > as FH instead of glob.
957 ;;; Support for comments in RExen (except
958 ;;; for m#\#comment#x), governed by
959 ;;; `cperl-regexp-scan'.
960 ;;; (`cperl-regexp-scan'): New customization variable.
961 ;;; (`cperl-forward-re'): Improve logic of resetting syntax table.
963 ;;;; After 4.23 and: After 4.24:
964 ;;; (`cperl-contract-levels'): Restore position.
965 ;;; (`cperl-beautify-level'): Likewise.
966 ;;; (`cperl-beautify-regexp'): Likewise.
967 ;;; (`cperl-commentify'): Rudimental support for length=1 runs
968 ;;; (`cperl-find-pods-heres'): Process 1-char long REx comments too /a#/x
969 ;;; Processes REx-comments in #-delimited RExen.
970 ;;; MAJOR BUG CORRECTED: after a misparse
971 ;;; a body of a subroutine could be corrupted!!!
972 ;;; One might need to reeval the function body
973 ;;; to fix things. (A similar bug was
974 ;;; present in `cperl-indent-region' eons ago.)
975 ;;; To reproduce:
976 ;; (defun foo () (let ((a '(t))) (insert (format "%s" a)) (setcar a 'BUG) t))
977 ;; (foo)
978 ;; (foo)
979 ;;; C-x C-e the above three lines (at end-of-line). First evaluation
980 ;;; of `foo' inserts (t), second one inserts (BUG) ?!
982 ;;; In CPerl it was triggered by inserting then deleting `/' at start of
983 ;;; / a (?# asdf {[(}asdf )ef,/;
985 ;;;; After 4.25:
986 ;;; (`cperl-commentify'): Was recognizing length=2 "strings" as length=1.
987 ;;; (`imenu-example--create-perl-index'):
988 ;;; Was not enforcing syntaxification-to-the-end.
989 ;;; (`cperl-invert-if-unless'): Allow `for', `foreach'.
990 ;;; (`cperl-find-pods-heres'): Quote `cperl-nonoverridable-face'.
991 ;;; Mark qw(), m()x as indentable.
992 ;;; (`cperl-init-faces'): Highlight `sysopen' too.
993 ;;; Highlight $var in `for my $var' too.
994 ;;; (`cperl-invert-if-unless'): Was leaving whitespace at end.
995 ;;; (`cperl-linefeed'): Was splitting $var{$foo} if point after `{'.
996 ;;; (`cperl-calculate-indent'): Remove old commented out code.
997 ;;; Support (primitive) indentation of qw(), m()x.
1000 ;;;; After 4.26:
1001 ;;; (`cperl-problems'): Mention `fill-paragraph' on comment. \"" and
1002 ;;; q [] with intervening newlines.
1003 ;;; (`cperl-autoindent-on-semi'): New customization variable.
1004 ;;; (`cperl-electric-semi'): Use `cperl-autoindent-on-semi'.
1005 ;;; (`cperl-tips'): Mention how to make CPerl the default mode.
1006 ;;; (`cperl-mode'): Support `outline-minor-mode'
1007 ;;; (Thanks to Mark A. Hershberger).
1008 ;;; (`cperl-outline-level'): New function.
1009 ;;; (`cperl-highlight-variables-indiscriminately'): New customization var.
1010 ;;; (`cperl-init-faces'): Use `cperl-highlight-variables-indiscriminately'.
1011 ;;; (Thanks to Sean Kamath <kamath@pogo.wv.tek.com>).
1012 ;;; (`cperl-after-block-p'): Support CHECK and INIT.
1013 ;;; (`cperl-init-faces'): Likewise and "our".
1014 ;;; (Thanks to Doug MacEachern <dougm@covalent.net>).
1015 ;;; (`cperl-short-docs'): Likewise and "our".
1018 ;;;; After 4.27:
1019 ;;; (`cperl-find-pods-heres'): Recognize \"" as a string.
1020 ;;; Mark whitespace and comments between q and []
1021 ;;; as `syntax-type' => `prestring'.
1022 ;;; Allow whitespace between << and "FOO".
1023 ;;; (`cperl-problems'): Remove \"" and q [] with intervening newlines.
1024 ;;; Mention multiple <<EOF as unsupported.
1025 ;;; (`cperl-highlight-variables-indiscriminately'): Doc misprint fixed.
1026 ;;; (`cperl-indent-parens-as-block'): New configuration variable.
1027 ;;; (`cperl-calculate-indent'): Merge cases of indenting non-BLOCK groups.
1028 ;;; Use `cperl-indent-parens-as-block'.
1029 ;;; (`cperl-find-pods-heres'): Test for =cut without empty line instead of
1030 ;;; complaining about no =cut.
1031 ;;; (`cperl-electric-pod'): Change the REx for POD from "\n\n=" to "^\n=".
1032 ;;; (`cperl-find-pods-heres'): Likewise.
1033 ;;; (`cperl-electric-pod'): Change `forward-sexp' to `forward-word':
1034 ;;; POD could've been marked as comment already.
1035 ;;; (`cperl-unwind-to-safe'): Unwind before start of POD too.
1037 ;;;; After 4.28:
1038 ;;; (`cperl-forward-re'): Throw an error at proper moment REx unfinished.
1040 ;;;; After 4.29:
1041 ;;; (`x-color-defined-p'): Make an extra case to peacify the warning.
1042 ;;; Toplevel: `defvar' to peacify the warnings.
1043 ;;; (`cperl-find-pods-heres'): Could access `font-lock-comment-face' in -nw.
1044 ;;;; No -nw-compile time warnings now.
1045 ;;; (`cperl-find-tags'): TAGS file had too short substring-to-search.
1046 ;;; Be less verbose in non-interactive mode
1047 ;;; (`imenu-example--create-perl-index'): Set index-marker after name
1048 ;;; (`cperl-outline-regexp'): New variable.
1049 ;;; (`cperl-outline-level'): Made compatible with `cperl-outline-regexp'.
1050 ;;; (`cperl-mode'): Made use `cperl-outline-regexp'.
1052 ;;;; After 4.30:
1053 ;;; (`cperl-find-pods-heres'): =cut the last thing, no blank line, was error.
1054 ;;; (`cperl-outline-level'): Make start-of-file same level as `package'.
1056 ;;;; After 4.31:
1057 ;;; (`cperl-electric-pod'): `head1' and `over' electric only if empty.
1058 ;;; (`cperl-unreadable-ok'): New variable.
1059 ;;; (`cperl-find-tags'): Use `cperl-unreadable-ok', do not fail
1060 ;;; on an unreadable file
1061 ;;; (`cperl-write-tags'): Use `cperl-unreadable-ok', do not fail
1062 ;;; on an unreadable directory
1064 ;;;; After 4.32:
1065 ;;; Syncronized with v1.60 from Emacs 21.3.
1066 ;;; Mostly docstring and formatting changes, and:
1068 ;;; (`cperl-noscan-files-regexp'): Do not scan CVS subdirs
1069 ;;; (`cperl-problems'): Note that newer XEmacsen may syntaxify too
1070 ;;; (`imenu-example--create-perl-index'):
1071 ;;; Renamed to `cperl-imenu--create-perl-index'
1072 ;;; (`cperl-mode'): Replace `make-variable-buffer-local' by `make-local-variable'
1073 ;;; (`cperl-setup-tmp-buf'): Likewise
1074 ;;; (`cperl-fix-line-spacing'): Fix a misprint of "t" for "\t"
1075 ;;; (`cperl-next-bad-style'): Fix misprints in character literals
1077 ;;;; After 4.33:
1078 ;;; (`cperl-font-lock-keywords'): +etc: Aliased to perl-font-lock-keywords.
1080 ;;;; After 4.34:
1081 ;;; Further updates of whitespace and spelling w.r.t. RMS version.
1082 ;;; (`cperl-font-lock-keywords'): +etc: Avoid warnings when aliasing.
1083 ;;; (`cperl-mode'): Use `normal-auto-fill-function' if present.
1084 ;;; (`cperl-use-major-mode'): New variable
1085 ;;; (`cperl-can-font-lock'): New variable; replaces `window-system'
1086 ;;; (`cperl-tags-hier-init'): use `display-popup-menus-p' (if present)
1087 ;;; to choose `x-popup-menu' vs `tmm-prompt'
1089 ;;;; 4.35 has the following differences from version 1.40+ of RMS Emacs:
1091 ;;; New variables `cperl-use-major-mode', `cperl-can-font-lock';
1092 ;;; `cperl-use-major-mode' is (effectively) 'cperl-mode in RMS.
1093 ;;; `cperl-under-as-char' is nil in RMS.
1094 ;;; Minor differences in docstrings, and `cperl-non-problems'.
1095 ;;; Backward compatibility addressed: (`); (function (lambda ...)); font-lock;
1096 ;;; (:italic t bold t) vs (:slant italic :weight bold) in faces;
1097 ;;; `normal-auto-fill-function'.
1098 ;;; RMS version has wrong logic in `cperl-calculate-indent': $a = { } is
1099 ;;; wrongly indented if the closing brace is on a separate line.
1100 ;;; Different choice of ordering if's for is-x-REx and (eq (char-after b) ?\#)
1101 ;;; in `cperl-find-pods-heres'. [Cosmetic]
1103 ;;;; After 4.35:
1104 ;;; (`cperl-find-pods-heres'): If no end of HERE-doc found, mark to the end
1105 ;;; of buffer. This enables recognition of end
1106 ;;; of HERE-doc "as one types".
1107 ;;; Require "\n" after trailing tag of HERE-doc.
1108 ;;; \( made non-quoting outside of string/comment
1109 ;;; (gdj-contributed).
1110 ;;; Likewise for \$.
1111 ;;; Remove `here-doc-group' text property at start
1112 ;;; (makes this property reliable).
1113 ;;; Text property `first-format-line' ==> t.
1114 ;;; Do not recognize $opt_s and $opt::s as s///.
1115 ;;; (`cperl-perldoc'): Use case-sensitive search (contributed).
1116 ;;; (`cperl-fix-line-spacing'): Allow "_" in $vars of foreach etc. when
1117 ;;; underscore isn't a word char (gdj-contributed).
1118 ;;; (`defun-prompt-regexp'): Allow prototypes.
1119 ;;; (`cperl-vc-header-alist'): Extract numeric version from the Id.
1120 ;;; Toplevel: Put toggle-autohelp into the mode menu.
1121 ;;; Better docs for toggle/set/unset autohelp.
1122 ;;; (`cperl-electric-backspace-untabify'): New customization variable
1123 ;;; (`cperl-after-expr-p'): Works after here-docs, formats, and PODs too
1124 ;;; (affects many electric constructs).
1125 ;;; (`cperl-calculate-indent'): Takes into account `first-format-line' ==>
1126 ;;; works after format.
1127 ;;; (`cperl-short-docs'): Make it work with ... too.
1128 ;;; "array context" ==> "list context"
1129 ;;; (`cperl-electric-keyword'): make $if (etc: "$@%&*") non-electric
1130 ;;; '(' after keyword would insert a doubled paren
1131 ;;; (`cperl-electric-paren'): documented affected by `cperl-electric-parens'
1132 ;;; (`cperl-electric-rparen'): Likewise
1133 ;;; (`cperl-build-manpage'): New function by Nick Roberts
1134 ;;; (`cperl-perldoc'): Make it work in XEmacs too
1136 ;;;; After 4.36:
1137 ;;; (`cperl-find-pods-heres'): Recognize s => 1 and {s} (as a key or varname),
1138 ;;; { s:: } and { s::bar::baz } as varnames.
1139 ;;; (`cperl-after-expr-p'): Updates syntaxification before checks
1140 ;;; (`cperl-calculate-indent'): Likewise
1141 ;;; Fix wrong indent of blocks starting with POD
1142 ;;; (`cperl-after-block-p'): Optional argument for checking for a pre-block
1143 ;;; Recognize `continue' blocks too.
1144 ;;; (`cperl-electric-brace'): use `cperl-after-block-p' for detection;
1145 ;;; Now works for else/continue/sub blocks
1146 ;;; (`cperl-short-docs'): Minor edits; make messages fit 80-column screen
1148 ;;;; After 5.0:
1149 ;;; `cperl-add-tags-recurse-noxs-fullpath': new function (for -batch mode)
1151 ;;;; After 5.1:
1152 ;;;;;; Major edit. Summary of most visible changes:
1154 ;;;;;; a) Multiple <<HERE per line allowed.
1155 ;;;;;; b) Handles multiline subroutine declaration headers (with comments).
1156 ;;;;;; (The exception is `cperl-etags' - but it is not used in the rest
1157 ;;;;;; of the mode.)
1158 ;;;;;; c) Fontifies multiline my/our declarations (even with comments,
1159 ;;;;;; and with legacy `font-lock').
1160 ;;;;;; d) Major speedup of syntaxification, both immediate and postponed
1161 ;;;;;; (3.5x to 15x [for different CPUs and versions of Emacs] on the
1162 ;;;;;; huge real-life document I tested).
1163 ;;;;;; e) New bindings, edits to imenu.
1164 ;;;;;; f) "_" is made into word-char during fontification/syntaxification;
1165 ;;;;;; some attempts to recognize non-word "_" during other operations too.
1166 ;;;;;; g) Detect bug in Emacs with `looking-at' inside `narrow' and bulk out.
1167 ;;;;;; h) autoload some more perldoc-related stuff
1168 ;;;;;; i) Some new convenience features: ISpell POD/HEREDOCs, narrow-to-HEREDOC
1169 ;;;;;; j) Attempt to incorporate XEmacs edits which reached me
1171 ;;;; Fine-grained changelog:
1172 ;;; `cperl-hook-after-change': New configuration variable
1173 ;;; `cperl-vc-sccs-header': Likewise
1174 ;;; `cperl-vc-sccs-header': Likewise
1175 ;;; `cperl-vc-header-alist': Default via two preceding variables
1176 ;;; `cperl-invalid-face': Remove double quoting under XEmacs
1177 ;;; (still needed under 21.2)
1178 ;;; `cperl-tips': Update URLs for resources
1179 ;;; `cperl-problems': Likewise
1180 ;;; `cperl-praise': Mention new features
1181 ;;; New C-c key bindings: for `cperl-find-bad-style',
1182 ;;; `cperl-pod-spell', `cperl-here-doc-spell', `cperl-narrow-to-here-doc',
1183 ;;; `cperl-perdoc', `cperl-perldoc-at-point'
1184 ;;; CPerl Mode menu changes: "Fix style by spaces", "Imenu on Perl Info"
1185 ;;; moved, new submenu of Tools with Ispell entries and narrowing.
1186 ;;; `cperl-after-sub-regexp': New defsubst
1187 ;;; `cperl-imenu--function-name-regexp-perl': Use `cperl-after-sub-regexp',
1188 ;;; Allows heads up to head4
1189 ;;; Allow "package;"
1190 ;;; `defun-prompt-regexp': Use `cperl-after-sub-regexp',
1191 ;;; `paren-backwards-message': ??? Something for XEmacs???
1192 ;;; `cperl-mode': Never auto-switch abbrev-mode off
1193 ;;; Try to allow '_' be non-word char
1194 ;;; Do not use `font-lock-unfontify-region-function' on XEmacs
1195 ;;; Reset syntax cache on mode start
1196 ;;; Support multiline facification (even
1197 ;;; on legacy `font-lock')
1198 ;;; `cperl-facemenu-add-face-function': ??? Some contributed code ???
1199 ;;; `cperl-after-change-function': Since `font-lock' and `lazy-lock'
1200 ;;; refuse to inform us whether the fontification is due to lazy
1201 ;;; calling or due to edit to a buffer, install our own hook
1202 ;;; (controlled by `cperl-hook-after-change')
1203 ;;; `cperl-electric-pod': =cut may have been recognized as start
1204 ;;; `cperl-block-p': Moved, updated for attributes
1205 ;;; `cperl-calculate-indent': Try to allow '_' be non-word char
1206 ;;; Support subs with attributes
1207 ;;; `cperl-where-am-i': Queit (?) a warning
1208 ;;; `cperl-cached-syntax-table' New function
1209 ;;; `cperl-forward-re': Use `cperl-cached-syntax-table'
1210 ;;; `cperl-unwind-to-safe': Recognize `syntax-type' property
1211 ;;; changing in a middle of line
1212 ;;; `cperl-find-sub-attrs': New function
1213 ;;; `cperl-find-pods-heres': Allow many <<EOP per line
1214 ;;; Allow subs with attributes
1215 ;;; Major speedups (3.5x..15x on a real-life
1216 ;;; test file nph-proxy.pl)
1217 ;;; Recognize "extproc " (OS/2)
1218 ;;; case-folded and only at start
1219 ;;; /x on s///x with empty replacement was
1220 ;;; not recognized
1221 ;;; Better comments
1222 ;;; `cperl-after-block-p': Remarks on diff with `cperl-block-p'
1223 ;;; Allow subs with attributes, labels
1224 ;;; Do not confuse "else::foo" with "else"
1225 ;;; Minor optimizations...
1226 ;;; `cperl-after-expr-p': Try to allow '_' be non-word char
1227 ;;; `cperl-fill-paragraph': Try to detect a major bug in Emacs
1228 ;;; with `looking-at' inside `narrow' and bulk out if found
1229 ;;; `cperl-imenu--create-perl-index': Updates for new
1230 ;;; `cperl-imenu--function-name-regexp-perl'
1231 ;;; `cperl-outline-level': Likewise
1232 ;;; `cperl-init-faces': Allow multiline subroutine headers
1233 ;;; and my/our declarations, and ones with comments
1234 ;;; Allow subroutine attributes
1235 ;;; `cperl-imenu-on-info': Better docstring.
1236 ;;; `cperl-etags' Rudimentary support for attributes
1237 ;;; Support for packages and "package;"
1238 ;;; `cperl-add-tags-recurse-noxs': Better (?) docstring
1239 ;;; `cperl-add-tags-recurse-noxs-fullpath': Likewise
1240 ;;; `cperl-tags-hier-init': Misprint for `fboundp' fixed
1241 ;;; `cperl-not-bad-style-regexp': Try to allow '_' be non-word char
1242 ;;; `cperl-perldoc': Add autoload
1243 ;;; `cperl-perldoc-at-point': Likewise
1244 ;;; `cperl-here-doc-spell': New function
1245 ;;; `cperl-pod-spell': Likewise
1246 ;;; `cperl-map-pods-heres': Likewise
1247 ;;; `cperl-get-here-doc-region': Likewise
1248 ;;; `cperl-font-lock-fontify-region-function': Likewise (backward compatibility
1249 ;;; for legacy `font-lock')
1250 ;;; `cperl-font-lock-unfontify-region-function': Fix style
1251 ;;; `cperl-fontify-syntaxically': Recognize and optimize away
1252 ;;; deferred calls with no-change. Governed by `cperl-hook-after-change'
1253 ;;; `cperl-fontify-update': Recognize that syntaxification region
1254 ;;; can be larger than fontification one.
1255 ;;; XXXX we leave `cperl-postpone' property, so this is quadratic...
1256 ;;; `cperl-fontify-update-bad': Temporary placeholder until
1257 ;;; it is clear how to implement `cperl-fontify-update'.
1258 ;;; `cperl-time-fontification': New function
1259 ;;; `attrib-group': New text attribute
1260 ;;; `multiline': New value: `syntax-type' text attribute
1262 ;;;; After 5.2:
1263 ;;; `cperl-emulate-lazy-lock': New function
1264 ;;; `cperl-fontify-syntaxically': Would skip large regions
1265 ;;; Add `cperl-time-fontification', `cperl-emulate-lazy-lock' to menu
1266 ;;; Some globals were declared, but uninitialized
1268 ;;;; After 5.3, 5.4:
1269 ;;; `cperl-facemenu-add-face-function': Add docs, fix U<>
1270 ;;; Copyright message updated.
1271 ;;; `cperl-init-faces': Work around a bug in `font-lock'. May slow
1272 ;;; facification down a bit.
1273 ;;; Misprint for my|our|local for old `font-lock'
1274 ;;; "our" was not fontified same as "my|local"
1275 ;;; Highlight variables after "my" etc even in
1276 ;;; a middle of an expression
1277 ;;; Do not facify multiple variables after my etc
1278 ;;; unless parentheses are present
1280 ;;; After 5.5, 5.6
1281 ;;; `cperl-fontify-syntaxically': after-change hook could reset
1282 ;;; `cperl-syntax-done-to' to a middle of line; unwind to BOL.
1284 ;;; After 5.7:
1285 ;;; `cperl-init-faces': Allow highlighting of local ($/)
1286 ;;; `cperl-problems-old-emaxen': New variable (for the purpose of DOCSTRING).
1287 ;;; `cperl-problems': Remove fixed problems.
1288 ;;; `cperl-find-pods-heres': Recognize #-comments in m##x too
1289 ;;; Recognize charclasses (unless delimiter is \).
1290 ;;; `cperl-fontify-syntaxically': Unwinding to safe was done in wrong order
1291 ;;; `cperl-regexp-scan': Update docs
1292 ;;; `cperl-beautify-regexp-piece': use information got from regexp scan
1294 ;;; After 5.8:
1295 ;;; Major user visible changes:
1296 ;;; Recognition and fontification of character classes in RExen.
1297 ;;; Variable indentation of RExen according to groups
1299 ;;; `cperl-find-pods-heres': Recognize POSIX classes in REx charclasses
1300 ;;; Fontify REx charclasses in variable-name face
1301 ;;; Fontify POSIX charclasses in "type" face
1302 ;;; Fontify unmatched "]" in function-name face
1303 ;;; Mark first-char of HERE-doc as `front-sticky'
1304 ;;; Reset `front-sticky' property when needed
1305 ;;; `cperl-calculate-indent': Indents //x -RExen accordning to parens level
1306 ;;; `cperl-to-comment-or-eol': Recognize ends of `syntax-type' constructs
1307 ;;; `cperl-backward-to-noncomment': Recognize stringy `syntax-type' constructs
1308 ;;; Support `narrow'ed buffers.
1309 ;;; `cperl-praise': Remove a reservation
1310 ;;; `cperl-make-indent': New function
1311 ;;; `cperl-indent-for-comment': Use `cperl-make-indent'
1312 ;;; `cperl-indent-line': Likewise
1313 ;;; `cperl-lineup': Likewise
1314 ;;; `cperl-beautify-regexp-piece': Likewise
1315 ;;; `cperl-contract-level': Likewise
1316 ;;; `cperl-toggle-set-debug-unwind': New function
1317 ;;; New menu entry for this
1318 ;;; `fill-paragraph-function': Use when `boundp'
1319 ;;; `cperl-calculate-indent': Take into account groups when indenting RExen
1320 ;;; `cperl-to-comment-or-eol': Recognize # which end a string
1321 ;;; `cperl-modify-syntax-type': Make only syntax-table property non-sticky
1322 ;;; `cperl-fill-paragraph': Return t: needed for `fill-paragraph-function'
1323 ;;; `cperl-fontify-syntaxically': More clear debugging message
1324 ;;; `cperl-pod2man-build-command': XEmacs portability: check `Man-filter-list'
1325 ;;; `cperl-init-faces': More complicated highlight even on XEmacs (new)
1326 ;;; Merge cosmetic changes from XEmacs
1328 ;;; After 5.9:
1329 ;;; `cperl-1+': Moved to before the first use
1330 ;;; `cperl-1-': Likewise
1332 ;;; After 5.10:
1334 ;;; This code may lock Emacs hard!!! Use on your own risk!
1336 ;;; `cperl-font-locking': New internal variable
1337 ;;; `cperl-beginning-of-property': New function
1338 ;;; `cperl-calculate-indent': Use `cperl-beginning-of-property'
1339 ;;; instead of `previous-single-property-change'
1340 ;;; `cperl-unwind-to-safe': Likewise
1341 ;;; `cperl-after-expr-p': Likewise
1342 ;;; `cperl-get-here-doc-region': Likewise
1343 ;;; `cperl-font-lock-fontify-region-function': Likewise
1344 ;;; `cperl-to-comment-or-eol': Do not call `cperl-update-syntaxification'
1345 ;;; recursively
1346 ;;; Bound `next-single-property-change'
1347 ;;; via `point-max'
1348 ;;; `cperl-unwind-to-safe': Bound likewise
1349 ;;; `cperl-font-lock-fontify-region-function': Likewise
1350 ;;; `cperl-find-pods-heres': Mark as recursive for `cperl-to-comment-or-eol'
1351 ;;; Initialization of
1352 ;;; `cperl-font-lock-multiline-start' could be missed if the "main"
1353 ;;; fontification did not run due to the keyword being already fontified.
1354 ;;; `cperl-pod-spell': Return t from do-one-chunk function
1355 ;;; `cperl-map-pods-heres': Stop when the worker returns nil
1356 ;;; Call `cperl-update-syntaxification'
1357 ;;; `cperl-get-here-doc-region': Call `cperl-update-syntaxification'
1358 ;;; `cperl-get-here-doc-delim': Remove unused function
1360 ;;; After 5.11:
1362 ;;; The possible lockup of Emacs (introduced in 5.10) fixed
1364 ;;; `cperl-unwind-to-safe': `cperl-beginning-of-property' won't return nil
1365 ;;; `cperl-syntaxify-for-menu': New customization variable
1366 ;;; `cperl-select-this-pod-or-here-doc': New function
1367 ;;; `cperl-get-here-doc-region': Extra argument
1368 ;;; Do not adjust pos by 1
1370 ;;; New menu entries (Perl/Tools): selection of current POD or HERE-DOC section
1371 ;;; (Debugging CPerl:) backtrace on fontification
1373 ;;; After 5.12:
1374 ;;; `cperl-cached-syntax-table': use `car-safe'
1375 ;;; `cperl-forward-re': Remove spurious argument SET-ST
1376 ;;; Add documentation
1377 ;;; `cperl-forward-group-in-re': New function
1378 ;;; `cperl-find-pods-heres': Find and highlight (?{}) blocks in RExen
1379 ;;; (XXXX Temporary (?) hack is to syntax-mark them as comment)
1381 ;;; After 5.13:
1382 ;;; `cperl-string-syntax-table': Make { and } not-grouping
1383 ;;; (Sometimes they ARE grouping in RExen, but matching them would only
1384 ;;; confuse in many situations when they are not)
1385 ;;; `beginning-of-buffer': Replaced two occurences with goto-char...
1386 ;;; `cperl-calculate-indent': `char-after' could be nil...
1387 ;;; `cperl-find-pods-heres': REx can start after "[" too
1388 ;;; Hightlight (??{}) in RExen too
1389 ;;; `cperl-maybe-white-and-comment-rex': New constant
1390 ;;; `cperl-white-and-comment-rex': Likewise
1391 ;;; XXXX Not very efficient, but hard to make
1392 ;;; better while keeping 1 group
1394 ;;; After 5.13:
1395 ;;; `cperl-find-pods-heres': $foo << identifier() is not a HERE-DOC
1396 ;;; Likewise for 1 << identifier
1398 ;;; After 5.14:
1399 ;;; `cperl-find-pods-heres': Different logic for $foo .= <<EOF etc
1400 ;;; Error-less condition-case could fail
1401 ;;; `cperl-font-lock-fontify-region-function': Likewise
1402 ;;; `cperl-init-faces': Likewise
1404 ;;; After 5.15:
1405 ;;; `cperl-find-pods-heres': Support property REx-part2
1406 ;;; `cperl-calculate-indent': Likewise
1407 ;;; Don't special-case REx with non-empty 1st line
1408 ;;; `cperl-find-pods-heres': In RExen, highlight non-literal backslashes
1409 ;;; Invert highlighting of charclasses:
1410 ;;; now the envelop is highlighted
1411 ;;; Highlight many others 0-length builtins
1412 ;;; `cperl-praise': Mention indenting and highlight in RExen
1414 ;;; After 5.15:
1415 ;;; `cperl-find-pods-heres': Highlight capturing parens in REx
1417 ;;; After 5.16:
1418 ;;; `cperl-find-pods-heres': Highlight '|' for alternation
1419 ;;; Initialize `font-lock-warning-face' if not present
1420 ;;; `cperl-find-pods-heres': Use `font-lock-warning-face' instead of
1421 ;;; `font-lock-function-name-face'
1422 ;;; `cperl-look-at-leading-count': Likewise
1423 ;;; `cperl-find-pods-heres': localize `font-lock-variable-name-face'
1424 ;;; `font-lock-keyword-face' (needed for
1425 ;;; batch processing) etc
1426 ;;; Use `font-lock-builtin-face' for builtin in REx
1427 ;;; Now `font-lock-variable-name-face'
1428 ;;; is used for interpolated variables
1429 ;;; Use "talking aliases" for faces inside REx
1430 ;;; Highlight parts of REx (except in charclasses)
1431 ;;; according to the syntax and/or semantic
1432 ;;; Syntax-mark a {}-part of (?{}) as "comment"
1433 ;;; (it was the ()-part)
1434 ;;; Better logic to distinguish what is what in REx
1435 ;;; `cperl-tips-faces': Document REx highlighting
1436 ;;; `cperl-praise': Mention REx syntax highlight etc.
1438 ;;; After 5.17:
1439 ;;; `cperl-find-sub-attrs': Would not always manage to print error message
1440 ;;; `cperl-find-pods-heres': localize `font-lock-constant-face'
1442 ;;; After 5.18:
1443 ;;; `cperl-find-pods-heres': Misprint in REx for parsing REx
1444 ;;; Very minor optimization
1445 ;;; `my-cperl-REx-modifiers-face' got quoted
1446 ;;; Recognize "print $foo <<END" as HERE-doc
1447 ;;; Put `REx-interpolated' text attribute if needed
1448 ;;; `cperl-invert-if-unless-modifiers': New function
1449 ;;; `cperl-backward-to-start-of-expr': Likewise
1450 ;;; `cperl-forward-to-end-of-expr': Likewise
1451 ;;; `cperl-invert-if-unless': Works in "the opposite way" too
1452 ;;; Cursor position on return is on the switch-word
1453 ;;; Indents comments better
1454 ;;; `REx-interpolated': New text attribute
1455 ;;; `cperl-next-interpolated-REx': New function
1456 ;;; `cperl-next-interpolated-REx-0': Likewise
1457 ;;; `cperl-next-interpolated-REx-1': Likewise
1458 ;;; "\C-c\C-x", "\C-c\C-y", "\C-c\C-v": New keybinding for these functions
1459 ;;; Perl/Regexp menu: 3 new entries for `cperl-next-interpolated-REx'
1460 ;;; `cperl-praise': Mention finded interpolated RExen
1462 ;;; After 5.19:
1463 ;;; `cperl-init-faces': Highlight %$foo, @$foo too
1464 ;;; `cperl-short-docs': Better docs for system, exec
1465 ;;; `cperl-find-pods-heres': Better detect << after print {FH} <<EOF etc.
1466 ;;; Would not find HERE-doc ended by EOF without NL
1467 ;;; `cperl-short-docs': Correct not-doubled \-escapes
1469 ;;; Perl6 changes by Steffen Schwigon (http://renormalist.net)
1471 ;;; Modified to understand Perl6 syntax.
1472 ;;; Details:
1474 ;;; New config variable `cperl-use-v6' that switches between Perl5/Perl6
1475 ;;; syntax.
1477 ;;; Simple heuristics to automatically activate Perl6 specific syntax
1478 ;;; * search for "use v6" or "class ..." near beginning of file
1479 ;;; * file suffix .p6
1481 ;;; Highlighting new keywords/builtins:
1482 ;;; class, module, role, grammar, rule, token, regex,
1483 ;;; has, state, does,
1484 ;;; say,
1485 ;;; rx,
1486 ;;; any, all, one, none,
1487 ;;; returns, of,
1488 ;;; multi/proto sub method,
1489 ;;; given, when, default, loop,
1490 ;;; gather, take, taken,
1491 ;;; coro, yield,
1492 ;;; try, err,
1493 ;;; zip, uniq, reduce, sum, max, min, kv, pairs, type, pick,
1494 ;;; "bit" "int" "str" "num" "ref" "bool" "Any" "Bit" "Int" "Str" "Num" "Ref",
1495 ;;; "Complex" "Exception" "Seq" "Range" "Set" "Junction" "Pair" "Mapping" "Signature" "Capture",
1496 ;;; "Bool" "Array" "Hash" "IO" "Code" "Routine" "Sub" "Method" "Submethod",
1497 ;;; "Macro" "Rule" "Block" "Bare" "Parametric" "Package" "Module" "Class", "Role",
1498 ;;; "Object" "Grammar" "List" "Lazy" "Eager",
1499 ;;; "Real" "Scalar" "int8" "Socket"
1501 ;;; Indentation:
1502 ;;; recognize sub traits (returns Type, is rw, etc.)
1503 ;;; recognize more special blocks:
1504 ;;; START, ENTER, LEAVE, KEEP, UNDO, FIRST, NEXT,
1505 ;;; LAST, PRE, POST, CATCH, CONTROL,
1506 ;;; given, when, default, gather, loop,
1507 ;;; class, module, role, grammar
1509 ;;; Recognize if/elsif/unless/while/until/given/when/for/loop-conditions
1510 ;;; without parens. (currently rather trivial heuristic)
1512 ;;; New rx// quote operator for regular expressions,
1513 ;;; parameterized rx// modifiers like perl5<i>, nth(3), x(3)
1515 ;;; m// and s/// similar to new rx//
1517 ;;; `Pugs' style added.
1519 ;;; Now only the @ and % sigils match arrays and hashes,
1520 ;;; not the bracket or brace after it.
1522 ;;; Brackets/braces for arrays/hashes must
1523 ;;; have no whitespace after variable name.
1525 ;;; No longer mark sub prototypes as string, just use ordinary highlighting.
1527 ;;; Highlight variable names with [.:^*+?=!] after twigils (@.name, $:name, $^name, ...)
1529 ;;; Fixed $:name was wrongly interpreted as label
1531 ;;; start block: Put some `defvar' for stuff gone from XEmacs
1533 ;;; After 5.20:
1534 ;;; initial comment: Extend copyright, fix email address
1535 ;;; `cperl-indent-comment-at-column-0': New customization variable
1536 ;;; `cperl-comment-indent': Indentation after $#a would increasy by 1
1537 ;;; `cperl-mode': Make `defun-prompt-regexp' grok BEGIN/END etc
1538 ;;; `cperl-find-pods-heres': Mark CODE of s///e as `syntax-type' `multiline'
1539 ;;; `cperl-at-end-of-expr': Would fail if @BAR=12 follows after ";"
1540 ;;; `cperl-init-faces': If `cperl-highlight-variables-indiscriminately'
1541 ;;; highlight $ in $foo too (UNTESTED)
1542 ;;; `cperl-set-style': Docstring missed some available styles
1543 ;;; toplevel: Menubar/Perl/Indent-Styles had FSF, now K&R
1544 ;;; Change "Current" to "Memorize Current"
1545 ;;; `cperl-indent-wrt-brace': New customization variable; the default is
1546 ;;; as for pre-5.2 version
1547 ;;; `cperl-styles-entries': Keep `cperl-extra-newline-before-brace-multiline'
1548 ;;; `cperl-style-alist': Likewise
1549 ;;; `cperl-fix-line-spacing': Support `cperl-merge-trailing-else' being nil,
1550 ;;; and `cperl-extra-newline-before-brace' etc
1551 ;;; being t
1552 ;;; `cperl-indent-exp': Plans B and C to find continuation blocks even
1553 ;;; if `cperl-extra-newline-before-brace' is t
1555 ;;; After 5.21:
1556 ;;; Improve some docstrings concerning indentation.
1557 ;;; `cperl-indent-rules-alist': New variable
1558 ;;; `cperl-sniff-for-indent': New function name
1559 ;; (separated from `cperl-calculate-indent')
1560 ;;; `cperl-calculate-indent': Separated the sniffer and the indenter;
1561 ;;; uses `cperl-sniff-for-indent' now
1562 ;;; `cperl-comment-indent': Test for `cperl-indent-comment-at-column-0'
1563 ;;; was inverted;
1564 ;;; Support `comment-column' = 0
1566 ;;; After 5.22:
1567 ;;; `cperl-where-am-i': Remove function
1568 ;;; `cperl-backward-to-noncomment': Would go too far when skipping POD/HEREs
1569 ;;; `cperl-sniff-for-indent': [string] and [comment] were inverted
1570 ;;; When looking for label, skip s:m:y:tr
1571 ;;; `cperl-indent-line': Likewise
1572 ;;; `cperl-mode': `font-lock-multiline' was assumed auto-local
1573 ;;; `cperl-windowed-init': Wrong `ps-print' handling
1574 ;;; (both thanks to Chong Yidong)
1575 ;;; `cperl-look-at-leading-count': Could fail with unfinished RExen
1576 ;;; `cperl-find-pods-heres': If the second part of s()[] is missing,
1577 ;;; could try to highlight delimiters...
1579 ;;; After 5.23:
1580 ;;; toplevel: Add comment on existence of different flavors
1581 ;;; `cperl-string-syntax-table': Was treating quotes as special
1582 ;;; Mode menu: Add "Report indentation context"
1583 ;;; `cperl-sniff-for-indent': Update comments
1584 ;;; `cperl-make-regexp-x': Was treating qr wrong
1585 ;;; `cperl-fill-paragraph': v22.1 needs `save-excursion' (XXXX BUG???)
1586 ;;; (Thanks to Pete Harlan)
1587 ;;; `cperl-build-manpage': set `Man-switches' for use in
1588 ;;; `Man-getpage-in-background'
1589 ;;; `cperl-perldoc': Likewise (Thanks to Alexander Haeckel)
1590 ;;; `cperl-beautify-regexp-piece': Allow for indentation of (?:)-group
1591 ;;; `cperl-beautify-level': Likewise
1592 ;;; `cperl-mode': `compilation-error-regexp-alist-alist'
1593 ;;; is defined in Emacs22, with different
1594 ;;; semantic than in XEmacs21
1595 ;;; (Thanks to Mark T. Kennedy)
1596 ;;; toplevel: Need to defvar `compilation-error-regexp-alist'
1597 ;;; `cperl-find-pods-heres': Check for unfinished s treated s/a// as such
1598 ;;; Better comments in REx highlighting
1599 ;;; Highlighting of - in charclasses
1600 ;;; (Does not pay attention to alphanum/dash delim)
1601 ;;; `cperl-forward-re': Do not print "unmatched" during electric {
1603 ;;; After 5.24:
1604 ;;; `cperl-find-pods-heres': Better comments in REx highlighting
1605 ;;; Treat backslashes before POSIX charclass better
1606 ;;; Highlighting of - and \ESCAPED in charclasses
1607 ;;; (Doesnt pay attention to alphanum/dash delim)
1608 ;;; Change POSIX class highlight to variable-name
1609 ;;; `cperl-highlight-charclass': New subst
1610 ;;; `cperl-tips-faces' Correct literal backwacks, mention multipliers
1612 ;;; After 6.0:
1613 ;;;; Incorporate XEmacs changes:
1614 ;;; `cperl-mode-map': Bind 'delete 'backspace on XEmacs
1615 ;;; `cperl-electric-delete': New (unsupported) function for XEmacs bindings
1616 ;;; toplevel: Define obsolete alias for `pod-spell'
1617 ;;; autoload updates to `mode-alist's
1619 ;;; After 6.1:
1620 ;;; toplevel: Add .PM to autoload mode list
1621 ;;; `cperl-insert-faces-example': New function
1622 ;;; Mode menu: New Micro-docs choice: Show Faces
1624 ;;; Code:
1626 (if (fboundp 'eval-when-compile)
1627 (eval-when-compile
1628 (condition-case nil
1629 (require 'custom)
1630 (error nil))
1631 (condition-case nil
1632 (require 'man)
1633 (error nil))
1634 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
1635 (defvar cperl-can-font-lock
1636 (or cperl-xemacs-p
1637 (and (boundp 'emacs-major-version)
1638 (or window-system
1639 (> emacs-major-version 20)))))
1640 (if cperl-can-font-lock
1641 (require 'font-lock))
1642 (defvar msb-menu-cond)
1643 (defvar gud-perldb-history)
1644 (defvar font-lock-background-mode) ; not in Emacs
1645 (defvar font-lock-display-type) ; ditto
1646 (defvar paren-backwards-message) ; Not in newer XEmacs?
1647 (defvar vc-rcs-header) ; likewise?
1648 (defvar vc-sccs-header) ; likewise?
1649 (defvar compilation-error-regexp-alist) ; used in Emacs 22
1650 (or (fboundp 'defgroup)
1651 (defmacro defgroup (name val doc &rest arr)
1652 nil))
1653 (or (fboundp 'custom-declare-variable)
1654 (defmacro defcustom (name val doc &rest arr)
1655 (` (defvar (, name) (, val) (, doc)))))
1656 (or (and (fboundp 'custom-declare-variable)
1657 (string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
1658 (defmacro defface (&rest arr)
1659 nil))
1660 ;; Avoid warning (tmp definitions)
1661 (or (fboundp 'x-color-defined-p)
1662 (defmacro x-color-defined-p (col)
1663 (cond ((fboundp 'color-defined-p) (` (color-defined-p (, col))))
1664 ;; XEmacs >= 19.12
1665 ((fboundp 'valid-color-name-p) (` (valid-color-name-p (, col))))
1666 ;; XEmacs 19.11
1667 ((fboundp 'x-valid-color-name-p) (` (x-valid-color-name-p (, col))))
1668 (t '(error "Cannot implement color-defined-p")))))
1669 (defmacro cperl-is-face (arg) ; Takes quoted arg
1670 (cond ((fboundp 'find-face)
1671 (` (find-face (, arg))))
1672 (;;(and (fboundp 'face-list)
1673 ;; (face-list))
1674 (fboundp 'face-list)
1675 (` (member (, arg) (and (fboundp 'face-list)
1676 (face-list)))))
1678 (` (boundp (, arg))))))
1679 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
1680 (cond ((fboundp 'make-face)
1681 (` (make-face (quote (, arg)))))
1683 (` (defvar (, arg) (quote (, arg)) (, descr))))))
1684 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
1685 (` (progn
1686 (or (cperl-is-face (quote (, arg)))
1687 (cperl-make-face (, arg) (, descr)))
1688 (or (boundp (quote (, arg))) ; We use unquoted variants too
1689 (defvar (, arg) (quote (, arg)) (, descr))))))
1690 (if cperl-xemacs-p
1691 (defmacro cperl-etags-snarf-tag (file line)
1692 (` (progn
1693 (beginning-of-line 2)
1694 (list (, file) (, line)))))
1695 (defmacro cperl-etags-snarf-tag (file line)
1696 (` (etags-snarf-tag))))
1697 (if cperl-xemacs-p
1698 (defmacro cperl-etags-goto-tag-location (elt)
1699 (`;;(progn
1700 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
1701 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
1702 ;; Probably will not work due to some save-excursion???
1703 ;; Or save-file-position?
1704 ;; (message "Did I get to line %s?" (elt (, elt) 1))
1705 (goto-line (string-to-int (elt (, elt) 1)))))
1707 (defmacro cperl-etags-goto-tag-location (elt)
1708 (` (etags-goto-tag-location (, elt)))))))
1710 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
1712 (defvar cperl-can-font-lock
1713 (or cperl-xemacs-p
1714 (and (boundp 'emacs-major-version)
1715 (or window-system
1716 (> emacs-major-version 20)))))
1718 (condition-case nil
1719 (require 'custom)
1720 (error nil)) ; Already fixed by eval-when-compile
1722 (defun cperl-choose-color (&rest list)
1723 (let (answer)
1724 (while list
1725 (or answer
1726 (if (or (x-color-defined-p (car list))
1727 (null (cdr list)))
1728 (setq answer (car list))))
1729 (setq list (cdr list)))
1730 answer))
1733 (defgroup cperl nil
1734 "Major mode for editing Perl code."
1735 :prefix "cperl-"
1736 :group 'languages)
1738 (defgroup cperl-indentation-details nil
1739 "Indentation."
1740 :prefix "cperl-"
1741 :group 'cperl)
1743 (defgroup cperl-affected-by-hairy nil
1744 "Variables affected by `cperl-hairy'."
1745 :prefix "cperl-"
1746 :group 'cperl)
1748 (defgroup cperl-autoinsert-details nil
1749 "Auto-insert tuneup."
1750 :prefix "cperl-"
1751 :group 'cperl)
1753 (defgroup cperl-faces nil
1754 "Fontification colors."
1755 :prefix "cperl-"
1756 :group 'cperl)
1758 (defgroup cperl-speed nil
1759 "Speed vs. validity tuneup."
1760 :prefix "cperl-"
1761 :group 'cperl)
1763 (defgroup cperl-help-system nil
1764 "Help system tuneup."
1765 :prefix "cperl-"
1766 :group 'cperl)
1769 (defcustom cperl-extra-newline-before-brace nil
1770 "*Non-nil means that if, elsif, while, until, else, for, foreach
1771 and do constructs look like:
1773 if ()
1777 instead of:
1779 if () {
1781 :type 'boolean
1782 :group 'cperl-autoinsert-details)
1784 (defcustom cperl-extra-newline-before-brace-multiline
1785 cperl-extra-newline-before-brace
1786 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
1787 for constructs with multiline if/unless/while/until/for/foreach condition."
1788 :type 'boolean
1789 :group 'cperl-autoinsert-details)
1791 (defcustom cperl-indent-level 2
1792 "*Indentation of CPerl statements with respect to containing block."
1793 :type 'integer
1794 :group 'cperl-indentation-details)
1796 (defcustom cperl-lineup-step nil
1797 "*`cperl-lineup' will always lineup at multiple of this number.
1798 If nil, the value of `cperl-indent-level' will be used."
1799 :type '(choice (const nil) integer)
1800 :group 'cperl-indentation-details)
1802 (defcustom cperl-brace-imaginary-offset 0
1803 "*Imagined indentation of a Perl open brace that actually follows a statement.
1804 An open brace following other text is treated as if it were this far
1805 to the right of the start of its line."
1806 :type 'integer
1807 :group 'cperl-indentation-details)
1809 (defcustom cperl-brace-offset 0
1810 "*Extra indentation for braces, compared with other text in same context."
1811 :type 'integer
1812 :group 'cperl-indentation-details)
1813 (defcustom cperl-label-offset -2
1814 "*Offset of CPerl label lines relative to usual indentation."
1815 :type 'integer
1816 :group 'cperl-indentation-details)
1817 (defcustom cperl-min-label-indent 1
1818 "*Minimal offset of CPerl label lines."
1819 :type 'integer
1820 :group 'cperl-indentation-details)
1821 (defcustom cperl-continued-statement-offset 2
1822 "*Extra indent for lines not starting new statements."
1823 :type 'integer
1824 :group 'cperl-indentation-details)
1825 (defcustom cperl-continued-brace-offset 0
1826 "*Extra indent for substatements that start with open-braces.
1827 This is in addition to cperl-continued-statement-offset."
1828 :type 'integer
1829 :group 'cperl-indentation-details)
1830 (defcustom cperl-close-paren-offset -1
1831 "*Extra indent for substatements that start with close-parenthesis."
1832 :type 'integer
1833 :group 'cperl-indentation-details)
1835 (defcustom cperl-indent-wrt-brace t
1836 "*Non-nil means indent statements in if/etc block relative brace, not if/etc.
1837 Versions 5.2 ... 5.20 behaved as if this were `nil'."
1838 :type 'boolean
1839 :group 'cperl-indentation-details)
1841 (defcustom cperl-auto-newline nil
1842 "*Non-nil means automatically newline before and after braces,
1843 and after colons and semicolons, inserted in CPerl code. The following
1844 \\[cperl-electric-backspace] will remove the inserted whitespace.
1845 Insertion after colons requires both this variable and
1846 `cperl-auto-newline-after-colon' set."
1847 :type 'boolean
1848 :group 'cperl-autoinsert-details)
1850 (defcustom cperl-autoindent-on-semi nil
1851 "*Non-nil means automatically indent after insertion of (semi)colon.
1852 Active if `cperl-auto-newline' is false."
1853 :type 'boolean
1854 :group 'cperl-autoinsert-details)
1856 (defcustom cperl-auto-newline-after-colon nil
1857 "*Non-nil means automatically newline even after colons.
1858 Subject to `cperl-auto-newline' setting."
1859 :type 'boolean
1860 :group 'cperl-autoinsert-details)
1862 (defcustom cperl-tab-always-indent t
1863 "*Non-nil means TAB in CPerl mode should always reindent the current line,
1864 regardless of where in the line point is when the TAB command is used."
1865 :type 'boolean
1866 :group 'cperl-indentation-details)
1868 (defcustom cperl-font-lock nil
1869 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
1870 Can be overwritten by `cperl-hairy' if nil."
1871 :type '(choice (const null) boolean)
1872 :group 'cperl-affected-by-hairy)
1874 (defcustom cperl-electric-lbrace-space nil
1875 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
1876 Can be overwritten by `cperl-hairy' if nil."
1877 :type '(choice (const null) boolean)
1878 :group 'cperl-affected-by-hairy)
1880 (defcustom cperl-electric-parens-string "({[]})<"
1881 "*String of parentheses that should be electric in CPerl.
1882 Closing ones are electric only if the region is highlighted."
1883 :type 'string
1884 :group 'cperl-affected-by-hairy)
1886 (defcustom cperl-electric-parens nil
1887 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
1888 Can be overwritten by `cperl-hairy' if nil."
1889 :type '(choice (const null) boolean)
1890 :group 'cperl-affected-by-hairy)
1892 (defvar zmacs-regions) ; Avoid warning
1894 (defcustom cperl-electric-parens-mark
1895 (and window-system
1896 (or (and (boundp 'transient-mark-mode) ; For Emacs
1897 transient-mark-mode)
1898 (and (boundp 'zmacs-regions) ; For XEmacs
1899 zmacs-regions)))
1900 "*Not-nil means that electric parens look for active mark.
1901 Default is yes if there is visual feedback on mark."
1902 :type 'boolean
1903 :group 'cperl-autoinsert-details)
1905 (defcustom cperl-electric-linefeed nil
1906 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
1907 In any case these two mean plain and hairy linefeeds together.
1908 Can be overwritten by `cperl-hairy' if nil."
1909 :type '(choice (const null) boolean)
1910 :group 'cperl-affected-by-hairy)
1912 (defcustom cperl-electric-keywords nil
1913 "*Not-nil (and non-null) means keywords are electric in CPerl.
1914 Can be overwritten by `cperl-hairy' if nil."
1915 :type '(choice (const null) boolean)
1916 :group 'cperl-affected-by-hairy)
1918 (defcustom cperl-electric-backspace-untabify t
1919 "*Not-nil means electric-backspace will untabify in CPerl."
1920 :type 'boolean
1921 :group 'cperl-autoinsert-details)
1923 (defcustom cperl-hairy nil
1924 "*Not-nil means most of the bells and whistles are enabled in CPerl.
1925 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
1926 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
1927 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
1928 `cperl-lazy-help-time'."
1929 :type 'boolean
1930 :group 'cperl-affected-by-hairy)
1932 (defcustom cperl-comment-column 32
1933 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
1934 :type 'integer
1935 :group 'cperl-indentation-details)
1937 (defcustom cperl-indent-comment-at-column-0 nil
1938 "*Non-nil means that comment started at column 0 should be indentable."
1939 :type 'boolean
1940 :group 'cperl-indentation-details)
1942 (defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
1943 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
1944 :type '(repeat string)
1945 :group 'cperl)
1947 (defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
1948 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
1949 :type '(repeat string)
1950 :group 'cperl)
1952 ;; This became obsolete...
1953 (defcustom cperl-vc-header-alist '()
1954 "*What to use as `vc-header-alist' in CPerl.
1955 Obsolete, with newer Emacsen use `cperl-vc-rcs-header' or
1956 `cperl-vc-sccs-header' instead. If this list is empty, `vc-header-alist'
1957 will be reconstructed basing on these two variables."
1958 :type '(repeat (list symbol string))
1959 :group 'cperl)
1961 (defcustom cperl-clobber-mode-lists
1962 (not
1963 (and
1964 (boundp 'interpreter-mode-alist)
1965 (assoc "miniperl" interpreter-mode-alist)
1966 (assoc "\\.\\([pP][LlmM6]6?\\|al\\)$" auto-mode-alist)))
1967 "*Whether to install us into `interpreter-' and `extension' mode lists."
1968 :type 'boolean
1969 :group 'cperl)
1971 (defcustom cperl-info-on-command-no-prompt nil
1972 "*Not-nil (and non-null) means not to prompt on C-h f.
1973 The opposite behaviour is always available if prefixed with C-c.
1974 Can be overwritten by `cperl-hairy' if nil."
1975 :type '(choice (const null) boolean)
1976 :group 'cperl-affected-by-hairy)
1978 (defcustom cperl-clobber-lisp-bindings nil
1979 "*Not-nil (and non-null) means not overwrite C-h f.
1980 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
1981 Can be overwritten by `cperl-hairy' if nil."
1982 :type '(choice (const null) boolean)
1983 :group 'cperl-affected-by-hairy)
1985 (defcustom cperl-lazy-help-time nil
1986 "*Not-nil (and non-null) means to show lazy help after given idle time.
1987 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
1988 :type '(choice (const null) (const nil) integer)
1989 :group 'cperl-affected-by-hairy)
1991 (defcustom cperl-pod-face 'font-lock-comment-face
1992 "*The result of evaluation of this expression is used for POD highlighting."
1993 :type 'face
1994 :group 'cperl-faces)
1996 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
1997 "*The result of evaluation of this expression is used for POD highlighting.
1998 Font for POD headers."
1999 :type 'face
2000 :group 'cperl-faces)
2002 (defcustom cperl-here-face 'font-lock-string-face
2003 "*The result of evaluation of this expression is used for here-docs highlighting."
2004 :type 'face
2005 :group 'cperl-faces)
2007 ;;; Some double-evaluation happened with font-locks... Needed with 21.2...
2008 (defvar cperl-singly-quote-face cperl-xemacs-p)
2010 (defcustom cperl-invalid-face ; Does not customize with '' on XEmacs
2011 (if cperl-singly-quote-face
2012 'underline ''underline) ; On older Emacsen was evaluated by `font-lock'
2013 (if cperl-singly-quote-face
2014 "*This face is used for highlighting trailing whitespace."
2015 "*The result of evaluation of this expression highlights trailing whitespace.")
2016 :type 'face
2017 :group 'cperl-faces)
2019 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
2020 "*Not-nil after evaluation means to highlight POD and here-docs sections."
2021 :type 'boolean
2022 :group 'cperl-faces)
2024 (defcustom cperl-fontify-m-as-s t
2025 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
2026 :type 'boolean
2027 :group 'cperl-faces)
2029 (defcustom cperl-highlight-variables-indiscriminately nil
2030 "*Non-nil means perform additional highlighting on variables.
2031 Currently only changes how scalar variables are highlighted.
2032 Note that that variable is only read at initialization time for
2033 the variable `perl-font-lock-keywords-2', so changing it after you've
2034 entered CPerl mode the first time will have no effect."
2035 :type 'boolean
2036 :group 'cperl)
2038 (defcustom cperl-pod-here-scan t
2039 "*Not-nil means look for POD and here-docs sections during startup.
2040 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
2041 :type 'boolean
2042 :group 'cperl-speed)
2044 (defcustom cperl-regexp-scan t
2045 "*Not-nil means make marking of regular expression more thorough.
2046 Effective only with `cperl-pod-here-scan'."
2047 :type 'boolean
2048 :group 'cperl-speed)
2050 (defcustom cperl-hook-after-change t
2051 "*Not-nil means install hook to know which regions of buffer are changed.
2052 May significantly speed up delayed fontification. Changes take effect
2053 after reload."
2054 :type 'boolean
2055 :group 'cperl-speed)
2057 (defcustom cperl-imenu-addback nil
2058 "*Not-nil means add backreferences to generated `imenu's.
2059 May require patched `imenu' and `imenu-go'. Obsolete."
2060 :type 'boolean
2061 :group 'cperl-help-system)
2063 (defcustom cperl-max-help-size 66
2064 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
2065 :type '(choice integer (const nil))
2066 :group 'cperl-help-system)
2068 (defcustom cperl-shrink-wrap-info-frame t
2069 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
2070 :type 'boolean
2071 :group 'cperl-help-system)
2073 (defcustom cperl-info-page "perl"
2074 "*Name of the info page containing perl docs.
2075 Older version of this page was called `perl5', newer `perl'."
2076 :type 'string
2077 :group 'cperl-help-system)
2079 (defcustom cperl-use-syntax-table-text-property
2080 (boundp 'parse-sexp-lookup-properties)
2081 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
2082 :type 'boolean
2083 :group 'cperl-speed)
2085 (defcustom cperl-use-syntax-table-text-property-for-tags
2086 cperl-use-syntax-table-text-property
2087 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
2088 :type 'boolean
2089 :group 'cperl-speed)
2091 (defcustom cperl-scan-files-regexp "\\.\\([pP][LlmM6]6?\\|xs\\)$"
2092 "*Regexp to match files to scan when generating TAGS."
2093 :type 'regexp
2094 :group 'cperl)
2096 (defcustom cperl-noscan-files-regexp
2097 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
2098 "*Regexp to match files/dirs to skip when generating TAGS."
2099 :type 'regexp
2100 :group 'cperl)
2102 (defcustom cperl-regexp-indent-step nil
2103 "*Indentation used when beautifying regexps.
2104 If nil, the value of `cperl-indent-level' will be used."
2105 :type '(choice integer (const nil))
2106 :group 'cperl-indentation-details)
2108 (defcustom cperl-indent-left-aligned-comments t
2109 "*Non-nil means that the comment starting in leftmost column should indent."
2110 :type 'boolean
2111 :group 'cperl-indentation-details)
2113 (defcustom cperl-under-as-char t
2114 "*Non-nil means that the _ (underline) should be treated as word char."
2115 :type 'boolean
2116 :group 'cperl)
2118 (defcustom cperl-extra-perl-args ""
2119 "*Extra arguments to use when starting Perl.
2120 Currently used with `cperl-check-syntax' only."
2121 :type 'string
2122 :group 'cperl)
2124 (defcustom cperl-message-electric-keyword t
2125 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
2126 :type 'boolean
2127 :group 'cperl-help-system)
2129 (defcustom cperl-indent-region-fix-constructs 1
2130 "*Amount of space to insert between `}' and `else' or `elsif'
2131 in `cperl-indent-region'. Set to nil to leave as is. Values other
2132 than 1 and nil will probably not work."
2133 :type '(choice (const nil) (const 1))
2134 :group 'cperl-indentation-details)
2136 (defcustom cperl-break-one-line-blocks-when-indent t
2137 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
2138 need to be reformatted into multiline ones when indenting a region."
2139 :type 'boolean
2140 :group 'cperl-indentation-details)
2142 (defcustom cperl-fix-hanging-brace-when-indent t
2143 "*Non-nil means that BLOCK-end `}' may be put on a separate line
2144 when indenting a region.
2145 Braces followed by else/elsif/while/until are excepted."
2146 :type 'boolean
2147 :group 'cperl-indentation-details)
2149 (defcustom cperl-merge-trailing-else t
2150 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
2151 may be merged to be on the same line when indenting a region."
2152 :type 'boolean
2153 :group 'cperl-indentation-details)
2155 (defcustom cperl-indent-parens-as-block nil
2156 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
2157 but for trailing \",\" inside the group, which won't increase indentation.
2158 One should tune up `cperl-close-paren-offset' as well."
2159 :type 'boolean
2160 :group 'cperl-indentation-details)
2162 (defcustom cperl-syntaxify-by-font-lock
2163 (and cperl-can-font-lock
2164 (boundp 'parse-sexp-lookup-properties))
2165 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
2166 :type '(choice (const message) boolean)
2167 :group 'cperl-speed)
2169 (defcustom cperl-syntaxify-unwind
2171 "*Non-nil means that CPerl unwinds to a start of a long construction
2172 when syntaxifying a chunk of buffer."
2173 :type 'boolean
2174 :group 'cperl-speed)
2176 (defcustom cperl-syntaxify-for-menu
2178 "*Non-nil means that CPerl syntaxifies up to the point before showing menu.
2179 This way enabling/disabling of menu items is more correct."
2180 :type 'boolean
2181 :group 'cperl-speed)
2183 (defcustom cperl-ps-print-face-properties
2184 '((font-lock-keyword-face nil nil bold shadow)
2185 (font-lock-variable-name-face nil nil bold)
2186 (font-lock-function-name-face nil nil bold italic box)
2187 (font-lock-constant-face nil "LightGray" bold)
2188 (cperl-array-face nil "LightGray" bold underline)
2189 (cperl-hash-face nil "LightGray" bold italic underline)
2190 (font-lock-comment-face nil "LightGray" italic)
2191 (font-lock-string-face nil nil italic underline)
2192 (cperl-nonoverridable-face nil nil italic underline)
2193 (font-lock-type-face nil nil underline)
2194 (font-lock-warning-face nil "LightGray" bold italic box)
2195 (underline nil "LightGray" strikeout))
2196 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
2197 :type '(repeat (cons symbol
2198 (cons (choice (const nil) string)
2199 (cons (choice (const nil) string)
2200 (repeat symbol)))))
2201 :group 'cperl-faces)
2203 (defcustom cperl-use-v6 nil
2204 "*Non-nil means that CPerl parses for Perl6 syntax."
2205 :type 'boolean
2206 :group 'cperl)
2208 (defun cperl-looks-like-perl6 ()
2209 ;; Searches for typical Perl6 patterns and returns true if found.
2210 ;; TODO: Tooooo lame.
2212 (string-match "\\.[Pp]6$" (buffer-file-name))
2213 (save-excursion
2214 (beginning-of-buffer)
2215 (search-forward-regexp "^[\t ]*\\(use \\(v6\\|6\\.[0-9]+\\)\\|\\(class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\)[\t ]+.*;\\)" 320 t))))
2217 (if cperl-can-font-lock
2218 (progn
2219 (defvar cperl-dark-background
2220 (cperl-choose-color "navy" "os2blue" "darkgreen"))
2221 (defvar cperl-dark-foreground
2222 (cperl-choose-color "orchid1" "orange"))
2224 (defface cperl-nonoverridable-face
2225 (` ((((class grayscale) (background light))
2226 (:background "Gray90" :italic t :underline t))
2227 (((class grayscale) (background dark))
2228 (:foreground "Gray80" :italic t :underline t :bold t))
2229 (((class color) (background light))
2230 (:foreground "chartreuse3"))
2231 (((class color) (background dark))
2232 (:foreground (, cperl-dark-foreground)))
2233 (t (:bold t :underline t))))
2234 "Font Lock mode face used to highlight array names."
2235 :group 'cperl-faces)
2237 (defface cperl-array-face
2238 (` ((((class grayscale) (background light))
2239 (:background "Gray90" :bold t))
2240 (((class grayscale) (background dark))
2241 (:foreground "Gray80" :bold t))
2242 (((class color) (background light))
2243 (:foreground "Blue" :background "lightyellow2" :bold t))
2244 (((class color) (background dark))
2245 (:foreground "yellow" :background (, cperl-dark-background) :bold t))
2246 (t (:bold t))))
2247 "Font Lock mode face used to highlight array names."
2248 :group 'cperl-faces)
2250 (defface cperl-hash-face
2251 (` ((((class grayscale) (background light))
2252 (:background "Gray90" :bold t :italic t))
2253 (((class grayscale) (background dark))
2254 (:foreground "Gray80" :bold t :italic t))
2255 (((class color) (background light))
2256 (:foreground "Red" :background "lightyellow2" :bold t :italic t))
2257 (((class color) (background dark))
2258 (:foreground "Red" :background (, cperl-dark-background) :bold t :italic t))
2259 (t (:bold t :italic t))))
2260 "Font Lock mode face used to highlight hash names."
2261 :group 'cperl-faces)))
2265 ;;; Short extra-docs.
2267 (defvar cperl-tips 'please-ignore-this-line
2268 "Get maybe newer version of this package from
2269 http://ilyaz.org/software/emacs
2270 Subdirectory `cperl-mode' may contain yet newer development releases and/or
2271 patches to related files.
2273 For best results apply to an older Emacs the patches from
2274 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
2275 \(this upgrades syntax-parsing abilities of RMS Emaxen v19.34 and
2276 v20.2 up to the level of RMS Emacs v20.3 - a must for a good Perl
2277 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
2279 Get support packages choose-color.el (or font-lock-extra.el before
2280 19.30), imenu-go.el from the same place. \(Look for other files there
2281 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
2282 later you should use choose-color.el *instead* of font-lock-extra.el
2283 \(and you will not get smart highlighting in C :-().
2285 Note that to enable Compile choices in the menu you need to install
2286 mode-compile.el.
2288 If your Emacs does not default to `cperl-mode' on Perl files, and you
2289 want it to: put the following into your .emacs file:
2291 (autoload 'perl-mode \"cperl-mode\" \"alternate mode for editing Perl programs\" t)
2295 (defalias 'perl-mode 'cperl-mode)
2297 Get perl5-info from
2298 $CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
2299 Also, one can generate a newer documentation running `pod2texi' converter
2300 $CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
2302 If you use imenu-go, run imenu on perl5-info buffer (you can do it
2303 from Perl menu). If many files are related, generate TAGS files from
2304 Tools/Tags submenu in Perl menu.
2306 If some class structure is too complicated, use Tools/Hierarchy-view
2307 from Perl menu, or hierarchic view of imenu. The second one uses the
2308 current buffer only, the first one requires generation of TAGS from
2309 Perl/Tools/Tags menu beforehand.
2311 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
2313 Switch auto-help on/off with Perl/Tools/Auto-help.
2315 Though with contemporary Emaxen CPerl mode should maintain the correct
2316 parsing of Perl even when editing, sometimes it may be lost. Fix this by
2318 M-x norm RET
2322 \\[normal-mode]
2324 In cases of more severe confusion sometimes it is helpful to do
2326 M-x load-l RET cperl-mode RET
2327 M-x norm RET
2331 \\[load-library] cperl-mode RET
2332 \\[normal-mode]
2334 Before reporting (non-)problems look in the problem section of online
2335 micro-docs on what I know about CPerl problems.")
2337 (defvar cperl-problems 'please-ignore-this-line
2338 "Description of problems in CPerl mode.
2339 Some faces will not be shown on some versions of Emacs unless you
2340 install choose-color.el, available from
2341 http://ilyaz.org/software/emacs
2343 `fill-paragraph' on a comment may leave the point behind the
2344 paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
2345 to detect it and bulk out).
2347 See documentation of a variable `cperl-problems-old-emaxen' for the
2348 problems which disappear if you upgrade Emacs to a reasonably new
2349 version (20.3 for RMS Emacs, and those of 2004 for XEmacs).")
2351 (defvar cperl-problems-old-emaxen 'please-ignore-this-line
2352 "Description of problems in CPerl mode specific for older Emacs versions.
2354 Emacs had a _very_ restricted syntax parsing engine until RMS's Emacs
2355 20.1. Most problems below are corrected starting from this version of
2356 Emacs, and all of them should be fixed in RMS's version 20.3. (Or apply
2357 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
2358 this respect (until 2003).
2360 Note that even with newer Emacsen in some very rare cases the details
2361 of interaction of `font-lock' and syntaxification may be not cleaned
2362 up yet. You may get slightly different colors basing on the order of
2363 fontification and syntaxification. Say, the initial faces is correct,
2364 but editing the buffer breaks this.
2366 Even with older Emacsen CPerl mode tries to corrects some Emacs
2367 misunderstandings, however, for efficiency reasons the degree of
2368 correction is different for different operations. The partially
2369 corrected problems are: POD sections, here-documents, regexps. The
2370 operations are: highlighting, indentation, electric keywords, electric
2371 braces.
2373 This may be confusing, since the regexp s#//#/#\; may be highlighted
2374 as a comment, but it will be recognized as a regexp by the indentation
2375 code. Or the opposite case, when a POD section is highlighted, but
2376 may break the indentation of the following code (though indentation
2377 should work if the balance of delimiters is not broken by POD).
2379 The main trick (to make $ a \"backslash\") makes constructions like
2380 ${aaa} look like unbalanced braces. The only trick I can think of is
2381 to insert it as $ {aaa} (legal in perl5, not in perl4).
2383 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
2384 as /($|\\s)/. Note that such a transposition is not always possible.
2386 The solution is to upgrade your Emacs or patch an older one. Note
2387 that RMS's 20.2 has some bugs related to `syntax-table' text
2388 properties. Patches are available on the main CPerl download site,
2389 and on CPAN.
2391 If these bugs cannot be fixed on your machine (say, you have an inferior
2392 environment and cannot recompile), you may still disable all the fancy stuff
2393 via `cperl-use-syntax-table-text-property'.")
2395 (defvar cperl-non-problems 'please-ignore-this-line
2396 "As you know from `problems' section, Perl syntax is too hard for CPerl on
2397 older Emacsen. Here is what you can do if you cannot upgrade, or if
2398 you want to switch off these capabilities on RMS Emacs 20.2 (+patches) or 20.3
2399 or better. Please skip this docs if you run a capable Emacs already.
2401 Most of the time, if you write your own code, you may find an equivalent
2402 \(and almost as readable) expression (what is discussed below is usually
2403 not relevant on newer Emacsen, since they can do it automatically).
2405 Try to help CPerl: add comments with embedded quotes to fix CPerl
2406 misunderstandings about the end of quotation:
2408 $a='500$'; # ';
2410 You won't need it too often. The reason: $ \"quotes\" the following
2411 character (this saves a life a lot of times in CPerl), thus due to
2412 Emacs parsing rules it does not consider tick (i.e., ' ) after a
2413 dollar as a closing one, but as a usual character. This is usually
2414 correct, but not in the above context.
2416 Even with older Emacsen the indentation code is pretty wise. The only
2417 drawback is that it relied on Emacs parsing to find matching
2418 parentheses. And Emacs *could not* match parentheses in Perl 100%
2419 correctly. So
2420 1 if s#//#/#;
2421 would not break indentation, but
2422 1 if ( s#//#/# );
2423 would. Upgrade.
2425 By similar reasons
2426 s\"abc\"def\";
2427 could confuse CPerl a lot.
2429 If you still get wrong indentation in situation that you think the
2430 code should be able to parse, try:
2432 a) Check what Emacs thinks about balance of your parentheses.
2433 b) Supply the code to me (IZ).
2435 Pods were treated _very_ rudimentally. Here-documents were not
2436 treated at all (except highlighting and inhibiting indentation). Upgrade.
2438 To speed up coloring the following compromises exist:
2439 a) sub in $mypackage::sub may be highlighted.
2440 b) -z in [a-z] may be highlighted.
2441 c) if your regexp contains a keyword (like \"s\"), it may be highlighted.
2444 Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove
2445 `car' before `imenu-choose-buffer-index' in `imenu'.
2446 `imenu-add-to-menubar' in 20.2 is broken.
2447 A lot of things on XEmacs may be broken too, judging by bug reports I
2448 receive. Note that some releases of XEmacs are better than the others
2449 as far as bugs reports I see are concerned.")
2451 (defvar cperl-praise 'please-ignore-this-line
2452 "Advantages of CPerl mode.
2454 0) It uses the newest `syntax-table' property ;-);
2456 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
2457 mode - but the latter number may have improved too in last years) even
2458 with old Emaxen which do not support `syntax-table' property.
2460 When using `syntax-table' property for syntax assist hints, it should
2461 handle 99.995% of lines correct - or somesuch. It automatically
2462 updates syntax assist hints when you edit your script.
2464 2) It is generally believed to be \"the most user-friendly Emacs
2465 package\" whatever it may mean (I doubt that the people who say similar
2466 things tried _all_ the rest of Emacs ;-), but this was not a lonely
2467 voice);
2469 3) Everything is customizable, one-by-one or in a big sweep;
2471 4) It has many easily-accessable \"tools\":
2472 a) Can run program, check syntax, start debugger;
2473 b) Can lineup vertically \"middles\" of rows, like `=' in
2474 a = b;
2475 cc = d;
2476 c) Can insert spaces where this impoves readability (in one
2477 interactive sweep over the buffer);
2478 d) Has support for imenu, including:
2479 1) Separate unordered list of \"interesting places\";
2480 2) Separate TOC of POD sections;
2481 3) Separate list of packages;
2482 4) Hierarchical view of methods in (sub)packages;
2483 5) and functions (by the full name - with package);
2484 e) Has an interface to INFO docs for Perl; The interface is
2485 very flexible, including shrink-wrapping of
2486 documentation buffer/frame;
2487 f) Has a builtin list of one-line explanations for perl constructs.
2488 g) Can show these explanations if you stay long enough at the
2489 corresponding place (or on demand);
2490 h) Has an enhanced fontification (using 3 or 4 additional faces
2491 comparing to font-lock - basically, different
2492 namespaces in Perl have different colors);
2493 i) Can construct TAGS basing on its knowledge of Perl syntax,
2494 the standard menu has 6 different way to generate
2495 TAGS (if \"by directory\", .xs files - with C-language
2496 bindings - are included in the scan);
2497 j) Can build a hierarchical view of classes (via imenu) basing
2498 on generated TAGS file;
2499 k) Has electric parentheses, electric newlines, uses Abbrev
2500 for electric logical constructs
2501 while () {}
2502 with different styles of expansion (context sensitive
2503 to be not so bothering). Electric parentheses behave
2504 \"as they should\" in a presence of a visible region.
2505 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
2506 m) Can convert from
2507 if (A) { B }
2509 B if A;
2511 n) Highlights (by user-choice) either 3-delimiters constructs
2512 (such as tr/a/b/), or regular expressions and `y/tr';
2513 o) Highlights trailing whitespace;
2514 p) Is able to manipulate Perl Regular Expressions to ease
2515 conversion to a more readable form.
2516 q) Can ispell POD sections and HERE-DOCs.
2517 r) Understands comments and character classes inside regular
2518 expressions; can find matching () and [] in a regular expression.
2519 s) Allows indentation of //x-style regular expressions;
2520 t) Highlights different symbols in regular expressions according
2521 to their function; much less problems with backslashitis;
2522 u) Allows to find regular expressions which contain interpolated parts.
2524 5) The indentation engine was very smart, but most of tricks may be
2525 not needed anymore with the support for `syntax-table' property. Has
2526 progress indicator for indentation (with `imenu' loaded).
2528 6) Indent-region improves inline-comments as well; also corrects
2529 whitespace *inside* the conditional/loop constructs.
2531 7) Fill-paragraph correctly handles multi-line comments;
2533 8) Can switch to different indentation styles by one command, and restore
2534 the settings present before the switch.
2536 9) When doing indentation of control constructs, may correct
2537 line-breaks/spacing between elements of the construct.
2539 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
2540 capable syntax engines).
2542 11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
2545 (defvar cperl-speed 'please-ignore-this-line
2546 "This is an incomplete compendium of what is available in other parts
2547 of CPerl documentation. (Please inform me if I skept anything.)
2549 There is a perception that CPerl is slower than alternatives. This part
2550 of documentation is designed to overcome this misconception.
2552 *By default* CPerl tries to enable the most comfortable settings.
2553 From most points of view, correctly working package is infinitely more
2554 comfortable than a non-correctly working one, thus by default CPerl
2555 prefers correctness over speed. Below is the guide how to change
2556 settings if your preferences are different.
2558 A) Speed of loading the file. When loading file, CPerl may perform a
2559 scan which indicates places which cannot be parsed by primitive Emacs
2560 syntax-parsing routines, and marks them up so that either
2562 A1) CPerl may work around these deficiencies (for big chunks, mostly
2563 PODs and HERE-documents), or
2564 A2) On capable Emaxen CPerl will use improved syntax-handlings
2565 which reads mark-up hints directly.
2567 The scan in case A2 is much more comprehensive, thus may be slower.
2569 User can disable syntax-engine-helping scan of A2 by setting
2570 `cperl-use-syntax-table-text-property'
2571 variable to nil (if it is set to t).
2573 One can disable the scan altogether (both A1 and A2) by setting
2574 `cperl-pod-here-scan'
2575 to nil.
2577 B) Speed of editing operations.
2579 One can add a (minor) speedup to editing operations by setting
2580 `cperl-use-syntax-table-text-property'
2581 variable to nil (if it is set to t). This will disable
2582 syntax-engine-helping scan, thus will make many more Perl
2583 constructs be wrongly recognized by CPerl, thus may lead to
2584 wrongly matched parentheses, wrong indentation, etc.
2586 One can unset `cperl-syntaxify-unwind'. This might speed up editing
2587 of, say, long POD sections.")
2589 (defvar cperl-tips-faces 'please-ignore-this-line
2590 "CPerl mode uses following faces for highlighting:
2592 `cperl-array-face' Array names
2593 `cperl-hash-face' Hash names
2594 `font-lock-comment-face' Comments, PODs and whatever is considered
2595 syntaxically to be not code
2596 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
2597 2-arg operators s/y/tr/ or of RExen,
2598 `font-lock-warning-face' Special-cased m// and s//foo/,
2599 `font-lock-function-name-face' _ as a target of a file tests, file tests,
2600 subroutine names at the moment of definition
2601 (except those conflicting with Perl operators),
2602 package names (when recognized), format names
2603 `font-lock-keyword-face' Control flow switch constructs, declarators
2604 `cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
2605 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
2606 literal parts and the terminator of formats
2607 and whatever is syntaxically considered
2608 as string literals
2609 `font-lock-type-face' Overridable keywords
2610 `font-lock-variable-name-face' Variable declarations, indirect array and
2611 hash names, POD headers/item names
2612 `cperl-invalid-face' Trailing whitespace
2614 Note that in several situations the highlighting tries to inform about
2615 possible confusion, such as different colors for function names in
2616 declarations depending on what they (do not) override, or special cases
2617 m// and s/// which do not do what one would expect them to do.
2619 Help with best setup of these faces for printout requested (for each of
2620 the faces: please specify bold, italic, underline, shadow and box.)
2622 In regular expressions (including character classes):
2623 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs
2624 `font-lock-constant-face': Delimiters
2625 `font-lock-warning-face' Special-cased m// and s//foo/,
2626 Mismatched closing delimiters, parens
2627 we couldn't match, misplaced quantifiers,
2628 unrecognized escape sequences
2629 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism
2630 `font-lock-type-face' escape sequences with arguments (\\x \\23 \\p \\N)
2631 and others match-a-char escape sequences
2632 `font-lock-keyword-face' Capturing parens, and |
2633 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ })
2634 \"Range -\" in character classes
2635 `font-lock-builtin-face' \"Remaining\" 0-length constructs, multipliers
2636 ?+*{}, not-capturing parens, leading
2637 backslashes of escape sequences
2638 `font-lock-variable-name-face' Interpolated constructs, embedded code,
2639 POSIX classes (inside charclasses)
2640 `font-lock-comment-face' Embedded comments
2646 ;;; Portability stuff:
2648 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
2649 (` (define-key cperl-mode-map
2650 (, (if xemacs-key
2651 (` (if cperl-xemacs-p (, xemacs-key) (, emacs-key)))
2652 emacs-key))
2653 (, definition))))
2655 (defvar cperl-del-back-ch
2656 (car (append (where-is-internal 'delete-backward-char)
2657 (where-is-internal 'backward-delete-char-untabify)))
2658 "Character generated by key bound to `delete-backward-char'.")
2660 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
2661 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
2663 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
2664 (if cperl-xemacs-p
2665 (progn
2666 ;; "Active regions" are on: use region only if active
2667 ;; "Active regions" are off: use region unconditionally
2668 (defun cperl-use-region-p ()
2669 (if zmacs-regions (mark) t)))
2670 (defun cperl-use-region-p ()
2671 (if transient-mark-mode mark-active t))
2672 (defun cperl-mark-active () mark-active))
2674 (defsubst cperl-enable-font-lock ()
2675 cperl-can-font-lock)
2677 (defun cperl-putback-char (c) ; Emacs 19
2678 (set 'unread-command-events (list c))) ; Avoid undefined warning
2680 (if (boundp 'unread-command-events)
2681 (if cperl-xemacs-p
2682 (defun cperl-putback-char (c) ; XEmacs >= 19.12
2683 (setq unread-command-events (list (eval '(character-to-event c))))))
2684 (defun cperl-putback-char (c) ; XEmacs <= 19.11
2685 (set 'unread-command-event (eval '(character-to-event c))))) ; Avoid warnings
2687 (or (fboundp 'uncomment-region)
2688 (defun uncomment-region (beg end)
2689 (interactive "r")
2690 (comment-region beg end -1)))
2692 (defvar cperl-do-not-fontify
2693 (if (string< emacs-version "19.30")
2694 'fontified
2695 'lazy-lock)
2696 "Text property which inhibits refontification.")
2698 (defsubst cperl-put-do-not-fontify (from to &optional post)
2699 ;; If POST, do not do it with postponed fontification
2700 (if (and post cperl-syntaxify-by-font-lock)
2702 (put-text-property (max (point-min) (1- from))
2703 to cperl-do-not-fontify t)))
2705 (defcustom cperl-mode-hook nil
2706 "Hook run by CPerl mode."
2707 :type 'hook
2708 :group 'cperl)
2710 (defvar cperl-syntax-state nil)
2711 (defvar cperl-syntax-done-to nil)
2712 (defvar cperl-emacs-can-parse (> (length (save-excursion
2713 (parse-partial-sexp (point) (point)))) 9))
2715 ;; Make customization possible "in reverse"
2716 (defsubst cperl-val (symbol &optional default hairy)
2717 (cond
2718 ((eq (symbol-value symbol) 'null) default)
2719 (cperl-hairy (or hairy t))
2720 (t (symbol-value symbol))))
2723 (defun cperl-make-indent (column &optional minimum keep)
2724 "Makes indent of the current line the requested amount.
2725 Unless KEEP, removes the old indentation. Works around a bug in ancient
2726 versions of Emacs."
2727 (let ((prop (get-text-property (point) 'syntax-type)))
2728 (or keep
2729 (delete-horizontal-space))
2730 (indent-to column minimum)
2731 ;; In old versions (e.g., 19.33) `indent-to' would not inherit properties
2732 (and prop
2733 (> (current-column) 0)
2734 (save-excursion
2735 (beginning-of-line)
2736 (or (get-text-property (point) 'syntax-type)
2737 (and (looking-at "\\=[ \t]")
2738 (put-text-property (point) (match-end 0)
2739 'syntax-type prop)))))))
2741 ;;; Probably it is too late to set these guys already, but it can help later:
2743 (and cperl-clobber-mode-lists
2744 (setq auto-mode-alist
2745 (append '(("\\.\\([pP][LlmM6]6?\\|al\\)$" . perl-mode)) auto-mode-alist ))
2746 (and (boundp 'interpreter-mode-alist)
2747 (setq interpreter-mode-alist (append interpreter-mode-alist
2748 '(("miniperl" . perl-mode))))))
2749 (if (fboundp 'eval-when-compile)
2750 (eval-when-compile
2751 (mapcar (lambda (p)
2752 (condition-case nil
2753 (require p)
2754 (error nil)))
2755 '(imenu easymenu etags timer man info))
2756 (if (fboundp 'ps-extend-face-list)
2757 (defmacro cperl-ps-extend-face-list (arg)
2758 (` (ps-extend-face-list (, arg))))
2759 (defmacro cperl-ps-extend-face-list (arg)
2760 (` (error "This version of Emacs has no `ps-extend-face-list'"))))
2761 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
2762 ;; macros instead of defsubsts don't work on Emacs, so we do the
2763 ;; expansion manually. Any other suggestions?
2764 (if cperl-can-font-lock
2765 (require 'font-lock))
2766 (require 'cl)))
2768 (defvar cperl-mode-abbrev-table nil
2769 "Abbrev table in use in CPerl mode buffers.")
2771 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
2773 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
2775 (if cperl-mode-map nil
2776 (setq cperl-mode-map (make-sparse-keymap))
2777 (cperl-define-key "{" 'cperl-electric-lbrace)
2778 (cperl-define-key "[" 'cperl-electric-paren)
2779 (cperl-define-key "(" 'cperl-electric-paren)
2780 (cperl-define-key "<" 'cperl-electric-paren)
2781 (cperl-define-key "}" 'cperl-electric-brace)
2782 (cperl-define-key "]" 'cperl-electric-rparen)
2783 (cperl-define-key ")" 'cperl-electric-rparen)
2784 (cperl-define-key ";" 'cperl-electric-semi)
2785 (cperl-define-key ":" 'cperl-electric-terminator)
2786 (cperl-define-key "\C-j" 'newline-and-indent)
2787 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
2788 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
2789 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
2790 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
2791 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
2792 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
2793 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
2794 (cperl-define-key "\C-c\C-b" 'cperl-find-bad-style)
2795 (cperl-define-key "\C-c\C-p" 'cperl-pod-spell)
2796 (cperl-define-key "\C-c\C-d" 'cperl-here-doc-spell)
2797 (cperl-define-key "\C-c\C-n" 'cperl-narrow-to-here-doc)
2798 (cperl-define-key "\C-c\C-v" 'cperl-next-interpolated-REx)
2799 (cperl-define-key "\C-c\C-x" 'cperl-next-interpolated-REx-0)
2800 (cperl-define-key "\C-c\C-y" 'cperl-next-interpolated-REx-1)
2801 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
2802 (cperl-define-key "\C-c\C-hp" 'cperl-perldoc)
2803 (cperl-define-key "\C-c\C-hP" 'cperl-perldoc-at-point)
2804 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
2805 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
2806 [(control meta |)])
2807 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
2808 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
2809 ;; XEmacs change: bind cperl-electric-delete to 'delete
2810 (if cperl-xemacs-p
2811 (progn
2812 (cperl-define-key 'backspace 'cperl-electric-backspace)
2813 (cperl-define-key 'delete 'cperl-electric-delete))
2814 (cperl-define-key "\177" 'cperl-electric-backspace))
2815 (cperl-define-key "\t" 'cperl-indent-command)
2816 ;; don't clobber the backspace binding:
2817 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
2818 [(control c) (control h) F])
2819 (if (cperl-val 'cperl-clobber-lisp-bindings)
2820 (progn
2821 (cperl-define-key "\C-hf"
2822 ;;(concat (char-to-string help-char) "f") ; does not work
2823 'cperl-info-on-command
2824 [(control h) f])
2825 (cperl-define-key "\C-hv"
2826 ;;(concat (char-to-string help-char) "v") ; does not work
2827 'cperl-get-help
2828 [(control h) v])
2829 (cperl-define-key "\C-c\C-hf"
2830 ;;(concat (char-to-string help-char) "f") ; does not work
2831 (key-binding "\C-hf")
2832 [(control c) (control h) f])
2833 (cperl-define-key "\C-c\C-hv"
2834 ;;(concat (char-to-string help-char) "v") ; does not work
2835 (key-binding "\C-hv")
2836 [(control c) (control h) v]))
2837 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
2838 [(control c) (control h) f])
2839 (cperl-define-key "\C-c\C-hv"
2840 ;;(concat (char-to-string help-char) "v") ; does not work
2841 'cperl-get-help
2842 [(control c) (control h) v]))
2843 (if (and cperl-xemacs-p
2844 (<= emacs-minor-version 11) (<= emacs-major-version 19))
2845 (progn
2846 ;; substitute-key-definition is usefulness-deenhanced...
2847 ;;;;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
2848 (cperl-define-key "\e;" 'cperl-indent-for-comment)
2849 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
2850 (or (boundp 'fill-paragraph-function)
2851 (substitute-key-definition
2852 'fill-paragraph 'cperl-fill-paragraph
2853 cperl-mode-map global-map))
2854 (substitute-key-definition
2855 'indent-sexp 'cperl-indent-exp
2856 cperl-mode-map global-map)
2857 (substitute-key-definition
2858 'indent-region 'cperl-indent-region
2859 cperl-mode-map global-map)
2860 (substitute-key-definition
2861 'indent-for-comment 'cperl-indent-for-comment
2862 cperl-mode-map global-map)))
2864 (defvar cperl-menu)
2865 (defvar cperl-lazy-installed)
2866 (defvar cperl-old-style nil)
2867 (condition-case nil
2868 (progn
2869 (require 'easymenu)
2870 (easy-menu-define
2871 cperl-menu cperl-mode-map "Menu for CPerl mode"
2872 '("Perl"
2873 ["Beginning of function" beginning-of-defun t]
2874 ["End of function" end-of-defun t]
2875 ["Mark function" mark-defun t]
2876 ["Indent expression" cperl-indent-exp t]
2877 ["Fill paragraph/comment" cperl-fill-paragraph t]
2878 "----"
2879 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
2880 ["Invert if/unless/while etc" cperl-invert-if-unless t]
2881 ("Regexp"
2882 ["Beautify" cperl-beautify-regexp
2883 cperl-use-syntax-table-text-property]
2884 ["Beautify one level deep" (cperl-beautify-regexp 1)
2885 cperl-use-syntax-table-text-property]
2886 ["Beautify a group" cperl-beautify-level
2887 cperl-use-syntax-table-text-property]
2888 ["Beautify a group one level deep" (cperl-beautify-level 1)
2889 cperl-use-syntax-table-text-property]
2890 ["Contract a group" cperl-contract-level
2891 cperl-use-syntax-table-text-property]
2892 ["Contract groups" cperl-contract-levels
2893 cperl-use-syntax-table-text-property]
2894 "----"
2895 ["Find next interpolated" cperl-next-interpolated-REx
2896 (next-single-property-change (point-min) 'REx-interpolated)]
2897 ["Find next interpolated (no //o)"
2898 cperl-next-interpolated-REx-0
2899 (or (text-property-any (point-min) (point-max) 'REx-interpolated t)
2900 (text-property-any (point-min) (point-max) 'REx-interpolated 1))]
2901 ["Find next interpolated (neither //o nor whole-REx)"
2902 cperl-next-interpolated-REx-1
2903 (text-property-any (point-min) (point-max) 'REx-interpolated t)])
2904 ["Insert spaces if needed to fix style" cperl-find-bad-style t]
2905 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
2906 "----"
2907 ["Indent region" cperl-indent-region (cperl-use-region-p)]
2908 ["Comment region" cperl-comment-region (cperl-use-region-p)]
2909 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
2910 "----"
2911 ["Run" mode-compile (fboundp 'mode-compile)]
2912 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
2913 (get-buffer "*compilation*"))]
2914 ["Next error" next-error (get-buffer "*compilation*")]
2915 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
2916 "----"
2917 ["Debugger" cperl-db t]
2918 "----"
2919 ("Tools"
2920 ["Imenu" imenu (fboundp 'imenu)]
2921 ["Imenu on Perl Info" cperl-imenu-on-info (featurep 'imenu)]
2922 "----"
2923 ["Ispell PODs" cperl-pod-spell
2924 ;; Better not to update syntaxification here:
2925 ;; debugging syntaxificatio can be broken by this???
2927 (get-text-property (point-min) 'in-pod)
2928 (< (progn
2929 (and cperl-syntaxify-for-menu
2930 (cperl-update-syntaxification (point-max) (point-max)))
2931 (next-single-property-change (point-min) 'in-pod nil (point-max)))
2932 (point-max)))]
2933 ["Ispell HERE-DOCs" cperl-here-doc-spell
2934 (< (progn
2935 (and cperl-syntaxify-for-menu
2936 (cperl-update-syntaxification (point-max) (point-max)))
2937 (next-single-property-change (point-min) 'here-doc-group nil (point-max)))
2938 (point-max))]
2939 ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
2940 (eq 'here-doc (progn
2941 (and cperl-syntaxify-for-menu
2942 (cperl-update-syntaxification (point) (point)))
2943 (get-text-property (point) 'syntax-type)))]
2944 ["Select this HERE-DOC or POD section"
2945 cperl-select-this-pod-or-here-doc
2946 (memq (progn
2947 (and cperl-syntaxify-for-menu
2948 (cperl-update-syntaxification (point) (point)))
2949 (get-text-property (point) 'syntax-type))
2950 '(here-doc pod))]
2951 "----"
2952 ["CPerl pretty print (exprmntl)" cperl-ps-print
2953 (fboundp 'ps-extend-face-list)]
2954 "----"
2955 ["Syntaxify region" cperl-find-pods-heres-region
2956 (cperl-use-region-p)]
2957 ["Profile syntaxification" cperl-time-fontification t]
2958 ["Debug errors in delayed fontification" cperl-emulate-lazy-lock t]
2959 ["Debug unwind for syntactic scan" cperl-toggle-set-debug-unwind t]
2960 ["Debug backtrace on syntactic scan (BEWARE!!!)"
2961 (cperl-toggle-set-debug-unwind nil t) t]
2962 "----"
2963 ["Report indentation context"
2964 (message "%s" (cperl-sniff-for-indent)) t]
2965 "----"
2966 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
2967 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
2968 ("Tags"
2969 ;;; ["Create tags for current file" cperl-etags t]
2970 ;;; ["Add tags for current file" (cperl-etags t) t]
2971 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
2972 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
2973 ;;; ["Create tags for Perl files in (sub)directories"
2974 ;;; (cperl-etags nil 'recursive) t]
2975 ;;; ["Add tags for Perl files in (sub)directories"
2976 ;;; (cperl-etags t 'recursive) t])
2977 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
2978 ["Create tags for current file" (cperl-write-tags nil t) t]
2979 ["Add tags for current file" (cperl-write-tags) t]
2980 ["Create tags for Perl files in directory"
2981 (cperl-write-tags nil t nil t) t]
2982 ["Add tags for Perl files in directory"
2983 (cperl-write-tags nil nil nil t) t]
2984 ["Create tags for Perl files in (sub)directories"
2985 (cperl-write-tags nil t t t) t]
2986 ["Add tags for Perl files in (sub)directories"
2987 (cperl-write-tags nil nil t t) t]))
2988 ("Perl docs"
2989 ["Define word at point" imenu-go-find-at-position
2990 (fboundp 'imenu-go-find-at-position)]
2991 ["Help on function" cperl-info-on-command t]
2992 ["Help on function at point" cperl-info-on-current-command t]
2993 ["Help on symbol at point" cperl-get-help t]
2994 ["Perldoc" cperl-perldoc t]
2995 ["Perldoc on word at point" cperl-perldoc-at-point t]
2996 ["View manpage of POD in this file" cperl-build-manpage t]
2997 ["Auto-help on" cperl-lazy-install
2998 (and (fboundp 'run-with-idle-timer)
2999 (not cperl-lazy-installed))]
3000 ["Auto-help off" cperl-lazy-unstall
3001 (and (fboundp 'run-with-idle-timer)
3002 cperl-lazy-installed)])
3003 ("Toggle..."
3004 ["Auto newline" cperl-toggle-auto-newline t]
3005 ["Electric parens" cperl-toggle-electric t]
3006 ["Electric keywords" cperl-toggle-abbrev t]
3007 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
3008 ["Auto-help on Perl constructs" cperl-toggle-autohelp t]
3009 ["Auto fill" auto-fill-mode t])
3010 ("Indent styles..."
3011 ["CPerl" (cperl-set-style "CPerl") t]
3012 ["PerlStyle" (cperl-set-style "PerlStyle") t]
3013 ["Pugs" (cperl-set-style "Pugs") t]
3014 ["GNU" (cperl-set-style "GNU") t]
3015 ["C++" (cperl-set-style "C++") t]
3016 ["K&R" (cperl-set-style "K&R") t]
3017 ["BSD" (cperl-set-style "BSD") t]
3018 ["Whitesmith" (cperl-set-style "Whitesmith") t]
3019 ["Memorize Current" (cperl-set-style "Current") t]
3020 ["Memorized" (cperl-set-style-back) cperl-old-style])
3021 ("Micro-docs"
3022 ["Tips" (describe-variable 'cperl-tips) t]
3023 ["Problems" (describe-variable 'cperl-problems) t]
3024 ["Non-problems" (describe-variable 'cperl-non-problems) t]
3025 ["Speed" (describe-variable 'cperl-speed) t]
3026 ["Praise" (describe-variable 'cperl-praise) t]
3027 ["Faces" (describe-variable 'cperl-tips-faces) t]
3028 ["Show Faces" (cperl-insert-faces-example) t]
3029 ["CPerl mode" (describe-function 'cperl-mode) t]
3030 ["CPerl version"
3031 (message "The version of master-file for this CPerl is %s"
3032 cperl-version) t]))))
3033 (error nil))
3035 (autoload 'c-macro-expand "cmacexp"
3036 "Display the result of expanding all C macros occurring in the region.
3037 The expansion is entirely correct because it uses the C preprocessor."
3040 ;;; These two must be unwound, otherwise take exponential time
3041 (defconst cperl-maybe-white-and-comment-rex "[ \t\n]*\\(#[^\n]*\n[ \t\n]*\\)*"
3042 "Regular expression to match optional whitespace with interpspersed comments.
3043 Should contain exactly one group.")
3045 ;;; This one is tricky to unwind; still very inefficient...
3046 (defconst cperl-white-and-comment-rex "\\([ \t\n]\\|#[^\n]*\n\\)+"
3047 "Regular expression to match whitespace with interpspersed comments.
3048 Should contain exactly one group.")
3051 ;;; Is incorporated in `cperl-imenu--function-name-regexp-perl'
3052 ;;; `cperl-outline-regexp', `defun-prompt-regexp'.
3053 ;;; Details of groups in this may be used in several functions; see comments
3054 ;;; near mentioned above variable(s)...
3055 ;;; sub($$):lvalue{} sub:lvalue{} Both allowed...
3056 (defsubst cperl-after-sub-regexp (named attr) ; 9 groups without attr...
3057 "Match the text after `sub' in a subroutine declaration.
3058 If NAMED is nil, allows anonymous subroutines. Matches up to the first \":\"
3059 of attributes (if present), or end of the name or prototype (whatever is
3060 the last)."
3061 (concat ; Assume n groups before this...
3062 "\\(" ; n+1=name-group
3063 cperl-white-and-comment-rex ; n+2=pre-name
3064 "\\(::[a-zA-Z_0-9:']+\\|[a-zA-Z_'][a-zA-Z_0-9:']*\\)" ; n+3=name
3065 "\\)" ; END n+1=name-group
3066 (if named "" "?")
3067 "\\(" ; n+4=proto-group
3068 cperl-maybe-white-and-comment-rex ; n+5=pre-proto
3069 "\\(([^()]*)\\)" ; n+6=prototype
3070 "\\)?" ; END n+4=proto-group
3071 "\\(" ; n+7=attr-group
3072 cperl-maybe-white-and-comment-rex ; n+8=pre-attr
3073 "\\(" ; n+9=start-attr
3075 (if attr (concat
3076 "\\("
3077 cperl-maybe-white-and-comment-rex ; whitespace-comments
3078 "\\(\\sw\\|_\\)+" ; attr-name
3079 ;; attr-arg (1 level of internal parens allowed!)
3080 "\\((\\(\\\\.\\|[^\\\\()]\\|([^\\\\()]*)\\)*)\\)?"
3081 "\\(" ; optional : (XXX allows trailing???)
3082 cperl-maybe-white-and-comment-rex ; whitespace-comments
3083 ":\\)?"
3084 "\\)+")
3085 "[^:]")
3086 "\\)"
3087 "\\)?" ; END n+6=proto-group
3090 ;;; Details of groups in this are used in `cperl-imenu--create-perl-index'
3091 ;;; and `cperl-outline-level'.
3092 ;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 11=sub-name (+3)
3093 (defvar cperl-imenu--function-name-regexp-perl
3094 (concat
3095 "^\\(" ; 1 = all
3096 "\\([ \t]*package" ; 2 = package-group
3097 "\\(" ; 3 = package-name-group
3098 cperl-white-and-comment-rex ; 4 = pre-package-name
3099 "\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
3100 "\\|"
3101 "[ \t]*\\(\\(multi\\|proto\\)[ \t]*\\)?\\(coro\\|sub\\|method\\|submethod\\)?" ; perl6
3102 (cperl-after-sub-regexp 'named nil) ; 11=name 14=proto 17=attr-start
3103 cperl-maybe-white-and-comment-rex ; 18=pre-block
3104 "\\|"
3105 "=head\\([1-4]\\)[ \t]+" ; 19=level
3106 "\\([^\n]+\\)$" ; 20=text
3107 "\\)"))
3109 (defvar cperl-outline-regexp
3110 (concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
3112 (defvar cperl-mode-syntax-table nil
3113 "Syntax table in use in CPerl mode buffers.")
3115 (defvar cperl-string-syntax-table nil
3116 "Syntax table in use in CPerl mode string-like chunks.")
3118 (defsubst cperl-1- (p)
3119 (max (point-min) (1- p)))
3121 (defsubst cperl-1+ (p)
3122 (min (point-max) (1+ p)))
3124 (if cperl-mode-syntax-table
3126 (setq cperl-mode-syntax-table (make-syntax-table))
3127 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
3128 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
3129 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
3130 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
3131 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
3132 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
3133 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
3134 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
3135 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
3136 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
3137 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
3138 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
3139 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
3140 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
3141 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
3142 (if cperl-under-as-char
3143 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
3144 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
3145 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
3146 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
3147 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
3148 (modify-syntax-entry ?\{ "." cperl-string-syntax-table)
3149 (modify-syntax-entry ?\} "." cperl-string-syntax-table)
3150 (modify-syntax-entry ?\" "." cperl-string-syntax-table)
3151 (modify-syntax-entry ?' "." cperl-string-syntax-table)
3152 (modify-syntax-entry ?` "." cperl-string-syntax-table)
3153 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment )
3157 ;; provide an alias for working with emacs 19. the perl-mode that comes
3158 ;; with it is really bad, and this lets us seamlessly replace it.
3159 ;;;###autoload
3160 (fset 'perl-mode 'cperl-mode)
3161 (defvar cperl-faces-init nil)
3162 ;; Fix for msb.el
3163 (defvar cperl-msb-fixed nil)
3164 (defvar font-lock-syntactic-keywords)
3165 (defvar perl-font-lock-keywords)
3166 (defvar perl-font-lock-keywords-1)
3167 (defvar perl-font-lock-keywords-2)
3168 (defvar outline-level)
3169 (if (fboundp 'defvaralias)
3170 (let ((f 'defvaralias)) ; Some functions deduce stuff from the mode name...
3171 (funcall f 'cperl-font-lock-keywords 'perl-font-lock-keywords)
3172 (funcall f 'cperl-font-lock-keywords-1 'perl-font-lock-keywords-1)
3173 (funcall f 'cperl-font-lock-keywords-2 'perl-font-lock-keywords-2)))
3175 (defvar cperl-use-major-mode 'perl-mode)
3176 (defvar cperl-font-lock-multiline-start nil)
3177 (defvar cperl-font-lock-multiline nil)
3178 (defvar cperl-compilation-error-regexp-alist nil)
3179 (defvar cperl-font-locking nil)
3181 ;;;###autoload
3182 (defun cperl-mode ()
3183 "Major mode for editing Perl code.
3184 Expression and list commands understand all C brackets.
3185 Tab indents for Perl code.
3186 Paragraphs are separated by blank lines only.
3187 Delete converts tabs to spaces as it moves back.
3189 Various characters in Perl almost always come in pairs: {}, (), [],
3190 sometimes <>. When the user types the first, she gets the second as
3191 well, with optional special formatting done on {}. (Disabled by
3192 default.) You can always quote (with \\[quoted-insert]) the left
3193 \"paren\" to avoid the expansion. The processing of < is special,
3194 since most the time you mean \"less\". CPerl mode tries to guess
3195 whether you want to type pair <>, and inserts is if it
3196 appropriate. You can set `cperl-electric-parens-string' to the string that
3197 contains the parenths from the above list you want to be electrical.
3198 Electricity of parenths is controlled by `cperl-electric-parens'.
3199 You may also set `cperl-electric-parens-mark' to have electric parens
3200 look for active mark and \"embrace\" a region if possible.'
3202 CPerl mode provides expansion of the Perl control constructs:
3204 if, else, elsif, unless, while, until, continue, do,
3205 for, foreach, formy and foreachmy.
3207 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
3209 The user types the keyword immediately followed by a space, which
3210 causes the construct to be expanded, and the point is positioned where
3211 she is most likely to want to be. eg. when the user types a space
3212 following \"if\" the following appears in the buffer: if () { or if ()
3213 } { } and the cursor is between the parentheses. The user can then
3214 type some boolean expression within the parens. Having done that,
3215 typing \\[cperl-linefeed] places you - appropriately indented - on a
3216 new line between the braces (if you typed \\[cperl-linefeed] in a POD
3217 directive line, then appropriate number of new lines is inserted).
3219 If CPerl decides that you want to insert \"English\" style construct like
3221 bite if angry;
3223 it will not do any expansion. See also help on variable
3224 `cperl-extra-newline-before-brace'. (Note that one can switch the
3225 help message on expansion by setting `cperl-message-electric-keyword'
3226 to nil.)
3228 \\[cperl-linefeed] is a convenience replacement for typing carriage
3229 return. It places you in the next line with proper indentation, or if
3230 you type it inside the inline block of control construct, like
3232 foreach (@lines) {print; print}
3234 and you are on a boundary of a statement inside braces, it will
3235 transform the construct into a multiline and will place you into an
3236 appropriately indented blank line. If you need a usual
3237 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
3238 see documentation on `cperl-electric-linefeed'.
3240 Use \\[cperl-invert-if-unless] to change a construction of the form
3242 if (A) { B }
3244 into
3246 B if A;
3248 \\{cperl-mode-map}
3250 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
3251 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
3252 on electric space between $ and {, `cperl-electric-parens-string' is
3253 the string that contains parentheses that should be electric in CPerl
3254 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
3255 setting `cperl-electric-keywords' enables electric expansion of
3256 control structures in CPerl. `cperl-electric-linefeed' governs which
3257 one of two linefeed behavior is preferable. You can enable all these
3258 options simultaneously (recommended mode of use) by setting
3259 `cperl-hairy' to t. In this case you can switch separate options off
3260 by setting them to `null'. Note that one may undo the extra
3261 whitespace inserted by semis and braces in `auto-newline'-mode by
3262 consequent \\[cperl-electric-backspace].
3264 If your site has perl5 documentation in info format, you can use commands
3265 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
3266 These keys run commands `cperl-info-on-current-command' and
3267 `cperl-info-on-command', which one is which is controlled by variable
3268 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
3269 \(in turn affected by `cperl-hairy').
3271 Even if you have no info-format documentation, short one-liner-style
3272 help is available on \\[cperl-get-help], and one can run perldoc or
3273 man via menu.
3275 It is possible to show this help automatically after some idle time.
3276 This is regulated by variable `cperl-lazy-help-time'. Default with
3277 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
3278 secs idle time . It is also possible to switch this on/off from the
3279 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
3281 Use \\[cperl-lineup] to vertically lineup some construction - put the
3282 beginning of the region at the start of construction, and make region
3283 span the needed amount of lines.
3285 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
3286 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
3287 here-docs sections. With capable Emaxen results of scan are used
3288 for indentation too, otherwise they are used for highlighting only.
3290 Variables controlling indentation style:
3291 `cperl-tab-always-indent'
3292 Non-nil means TAB in CPerl mode should always reindent the current line,
3293 regardless of where in the line point is when the TAB command is used.
3294 `cperl-indent-left-aligned-comments'
3295 Non-nil means that the comment starting in leftmost column should indent.
3296 `cperl-auto-newline'
3297 Non-nil means automatically newline before and after braces,
3298 and after colons and semicolons, inserted in Perl code. The following
3299 \\[cperl-electric-backspace] will remove the inserted whitespace.
3300 Insertion after colons requires both this variable and
3301 `cperl-auto-newline-after-colon' set.
3302 `cperl-auto-newline-after-colon'
3303 Non-nil means automatically newline even after colons.
3304 Subject to `cperl-auto-newline' setting.
3305 `cperl-indent-level'
3306 Indentation of Perl statements within surrounding block.
3307 The surrounding block's indentation is the indentation
3308 of the line on which the open-brace appears.
3309 `cperl-continued-statement-offset'
3310 Extra indentation given to a substatement, such as the
3311 then-clause of an if, or body of a while, or just a statement continuation.
3312 `cperl-continued-brace-offset'
3313 Extra indentation given to a brace that starts a substatement.
3314 This is in addition to `cperl-continued-statement-offset'.
3315 `cperl-brace-offset'
3316 Extra indentation for line if it starts with an open brace.
3317 `cperl-brace-imaginary-offset'
3318 An open brace following other text is treated as if it the line started
3319 this far to the right of the actual line indentation.
3320 `cperl-label-offset'
3321 Extra indentation for line that is a label.
3322 `cperl-min-label-indent'
3323 Minimal indentation for line that is a label.
3325 Settings for classic indent-styles: K&R BSD=C++ GNU PerlStyle=Whitesmith
3326 `cperl-indent-level' 5 4 2 4
3327 `cperl-brace-offset' 0 0 0 0
3328 `cperl-continued-brace-offset' -5 -4 0 0
3329 `cperl-label-offset' -5 -4 -2 -4
3330 `cperl-continued-statement-offset' 5 4 2 4
3332 CPerl knows several indentation styles, and may bulk set the
3333 corresponding variables. Use \\[cperl-set-style] to do this. Use
3334 \\[cperl-set-style-back] to restore the memorized preexisting values
3335 \(both available from menu). See examples in `cperl-style-examples'.
3337 Part of the indentation style is how different parts of if/elsif/else
3338 statements are broken into lines; in CPerl, this is reflected on how
3339 templates for these constructs are created (controlled by
3340 `cperl-extra-newline-before-brace'), and how reflow-logic should treat
3341 \"continuation\" blocks of else/elsif/continue, controlled by the same
3342 variable, and by `cperl-extra-newline-before-brace-multiline',
3343 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'.
3345 If `cperl-indent-level' is 0, the statement after opening brace in
3346 column 0 is indented on
3347 `cperl-brace-offset'+`cperl-continued-statement-offset'.
3349 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
3350 with no args.
3352 DO NOT FORGET to read micro-docs (available from `Perl' menu,
3353 or as help on variables `cperl-tips', `cperl-problems',
3354 `cperl-non-problems', `cperl-praise', `cperl-speed',
3355 `cperl-tips-faces')."
3356 (interactive)
3357 (kill-all-local-variables)
3358 (use-local-map cperl-mode-map)
3359 (if (cperl-val 'cperl-electric-linefeed)
3360 (progn
3361 (local-set-key "\C-J" 'cperl-linefeed)
3362 (local-set-key "\C-C\C-J" 'newline-and-indent)))
3363 (if (and
3364 (cperl-val 'cperl-clobber-lisp-bindings)
3365 (cperl-val 'cperl-info-on-command-no-prompt))
3366 (progn
3367 ;; don't clobber the backspace binding:
3368 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
3369 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
3370 [(control c) (control h) f])))
3371 (setq major-mode cperl-use-major-mode)
3372 (setq mode-name "CPerl")
3373 (if (not cperl-mode-abbrev-table)
3374 (let ((prev-a-c abbrevs-changed))
3375 (define-abbrev-table 'cperl-mode-abbrev-table '(
3376 ("if" "if" cperl-electric-keyword 0)
3377 ("elsif" "elsif" cperl-electric-keyword 0)
3378 ("while" "while" cperl-electric-keyword 0)
3379 ("until" "until" cperl-electric-keyword 0)
3380 ("unless" "unless" cperl-electric-keyword 0)
3381 ("else" "else" cperl-electric-else 0)
3382 ("continue" "continue" cperl-electric-else 0)
3383 ("for" "for" cperl-electric-keyword 0)
3384 ("foreach" "foreach" cperl-electric-keyword 0)
3385 ("formy" "formy" cperl-electric-keyword 0)
3386 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
3387 ("do" "do" cperl-electric-keyword 0)
3388 ("=pod" "=pod" cperl-electric-pod 0)
3389 ("=over" "=over" cperl-electric-pod 0)
3390 ("=head1" "=head1" cperl-electric-pod 0)
3391 ("=head2" "=head2" cperl-electric-pod 0)
3392 ("pod" "pod" cperl-electric-pod 0)
3393 ("over" "over" cperl-electric-pod 0)
3394 ("head1" "head1" cperl-electric-pod 0)
3395 ("head2" "head2" cperl-electric-pod 0)))
3396 (setq abbrevs-changed prev-a-c)))
3397 (setq local-abbrev-table cperl-mode-abbrev-table)
3398 (if (cperl-val 'cperl-electric-keywords)
3399 (abbrev-mode 1))
3400 (set-syntax-table cperl-mode-syntax-table)
3401 ;; Until Emacs is multi-threaded, we do not actually need it local:
3402 (make-local-variable 'cperl-font-lock-multiline-start)
3403 (make-local-variable 'cperl-font-locking)
3404 (make-local-variable 'outline-regexp)
3405 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
3406 (setq outline-regexp cperl-outline-regexp)
3407 (make-local-variable 'outline-level)
3408 (setq outline-level 'cperl-outline-level)
3409 (make-local-variable 'paragraph-start)
3410 (setq paragraph-start (concat "^$\\|" page-delimiter))
3411 (make-local-variable 'paragraph-separate)
3412 (setq paragraph-separate paragraph-start)
3413 (make-local-variable 'paragraph-ignore-fill-prefix)
3414 (setq paragraph-ignore-fill-prefix t)
3415 (if cperl-xemacs-p
3416 (progn
3417 (make-local-variable 'paren-backwards-message)
3418 (set 'paren-backwards-message t)))
3419 (make-local-variable 'indent-line-function)
3420 (setq indent-line-function 'cperl-indent-line)
3421 (make-local-variable 'require-final-newline)
3422 (setq require-final-newline t)
3423 (make-local-variable 'comment-start)
3424 (setq comment-start "# ")
3425 (make-local-variable 'comment-end)
3426 (setq comment-end "")
3427 (make-local-variable 'comment-column)
3428 (setq comment-column cperl-comment-column)
3429 (make-local-variable 'comment-start-skip)
3430 (setq comment-start-skip "#+ *")
3431 (make-local-variable 'defun-prompt-regexp)
3432 ;;; "[ \t]*sub"
3433 ;;; (cperl-after-sub-regexp 'named nil) ; 11=name 14=proto 17=attr-start
3434 ;;; cperl-maybe-white-and-comment-rex ; 16=pre-block
3435 (setq defun-prompt-regexp
3436 (concat "[ \t]*\\(sub"
3437 (cperl-after-sub-regexp 'named 'attr-groups)
3438 "\\|" ; per toke.c
3439 "\\(BEGIN\\|CHECK\\|INIT\\|END\\|AUTOLOAD\\|DESTROY\\)"
3440 "\\)"
3441 cperl-maybe-white-and-comment-rex))
3442 (make-local-variable 'comment-indent-function)
3443 (setq comment-indent-function 'cperl-comment-indent)
3444 (and (boundp 'fill-paragraph-function)
3445 (progn
3446 (make-local-variable 'fill-paragraph-function)
3447 (set 'fill-paragraph-function 'cperl-fill-paragraph)))
3448 (make-local-variable 'parse-sexp-ignore-comments)
3449 (setq parse-sexp-ignore-comments t)
3450 (make-local-variable 'indent-region-function)
3451 (setq indent-region-function 'cperl-indent-region)
3452 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
3453 (make-local-variable 'imenu-create-index-function)
3454 (setq imenu-create-index-function
3455 (function cperl-imenu--create-perl-index))
3456 (make-local-variable 'imenu-sort-function)
3457 (setq imenu-sort-function nil)
3458 (make-local-variable 'vc-rcs-header)
3459 (set 'vc-rcs-header cperl-vc-rcs-header)
3460 (make-local-variable 'vc-sccs-header)
3461 (set 'vc-sccs-header cperl-vc-sccs-header)
3462 ;; This one is obsolete...
3463 (make-local-variable 'vc-header-alist)
3464 (set 'vc-header-alist (or cperl-vc-header-alist ; Avoid warning
3465 (` ((SCCS (, (car cperl-vc-sccs-header)))
3466 (RCS (, (car cperl-vc-rcs-header)))))))
3467 (cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x, emacs22
3468 (make-local-variable 'compilation-error-regexp-alist-alist)
3469 (set 'compilation-error-regexp-alist-alist
3470 (cons (cons 'cperl cperl-compilation-error-regexp-alist)
3471 (symbol-value 'compilation-error-regexp-alist-alist)))
3472 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
3473 (let ((f 'compilation-build-compilation-error-regexp-alist))
3474 (funcall f)) ; xemacs 20.x
3475 (make-local-variable 'compilation-error-regexp-alist) ; emacs22
3476 (push 'cperl compilation-error-regexp-alist)))
3477 ((boundp 'compilation-error-regexp-alist);; xmeacs 19.x
3478 (make-local-variable 'compilation-error-regexp-alist)
3479 (set 'compilation-error-regexp-alist
3480 (cons cperl-compilation-error-regexp-alist
3481 (symbol-value 'compilation-error-regexp-alist)))))
3482 (make-local-variable 'font-lock-defaults)
3483 (setq font-lock-defaults
3484 (cond
3485 ((string< emacs-version "19.30")
3486 '(perl-font-lock-keywords-2 nil nil ((?_ . "w"))))
3487 ((string< emacs-version "19.33") ; Which one to use?
3488 '((perl-font-lock-keywords
3489 perl-font-lock-keywords-1
3490 perl-font-lock-keywords-2) nil nil ((?_ . "w"))))
3492 '((cperl-load-font-lock-keywords
3493 cperl-load-font-lock-keywords-1
3494 cperl-load-font-lock-keywords-2) nil nil ((?_ . "w"))))))
3495 (make-local-variable 'cperl-syntax-state)
3496 (setq cperl-syntax-state nil) ; reset syntaxification cache
3497 (if cperl-use-syntax-table-text-property
3498 (progn
3499 (make-local-variable 'parse-sexp-lookup-properties)
3500 ;; Do not introduce variable if not needed, we check it!
3501 (set 'parse-sexp-lookup-properties t)
3502 ;; Fix broken font-lock:
3503 (or (boundp 'font-lock-unfontify-region-function)
3504 (set 'font-lock-unfontify-region-function
3505 'font-lock-default-unfontify-region))
3506 (unless cperl-xemacs-p ; Our: just a plug for wrong font-lock
3507 (make-local-variable 'font-lock-unfontify-region-function)
3508 (set 'font-lock-unfontify-region-function ; not present with old Emacs
3509 'cperl-font-lock-unfontify-region-function))
3510 (make-local-variable 'cperl-syntax-done-to)
3511 (setq cperl-syntax-done-to nil) ; reset syntaxification cache
3512 ;; Another bug: unless font-lock-syntactic-keywords, font-lock
3513 ;; ignores syntax-table text-property. (t) is a hack
3514 ;; to make font-lock think that font-lock-syntactic-keywords
3515 ;; are defined
3516 (make-local-variable 'font-lock-syntactic-keywords)
3517 (setq font-lock-syntactic-keywords
3518 (if cperl-syntaxify-by-font-lock
3519 '(t (cperl-fontify-syntaxically))
3520 '(t)))))
3521 (if (boundp 'font-lock-multiline) ; Newer font-lock; use its facilities
3522 (progn
3523 (setq cperl-font-lock-multiline t) ; Not localized...
3524 (set (make-local-variable 'font-lock-multiline) t))
3525 (make-local-variable 'font-lock-fontify-region-function)
3526 (set 'font-lock-fontify-region-function ; not present with old Emacs
3527 'cperl-font-lock-fontify-region-function))
3528 (make-local-variable 'font-lock-fontify-region-function)
3529 (set 'font-lock-fontify-region-function ; not present with old Emacs
3530 'cperl-font-lock-fontify-region-function)
3531 (make-local-variable 'cperl-old-style)
3532 (make-local-variable 'cperl-use-v6)
3533 (if (cperl-looks-like-perl6)
3534 (set 'cperl-use-v6 t)
3535 (set 'cperl-use-v6 nil)
3537 (if (boundp 'normal-auto-fill-function) ; 19.33 and later
3538 (set (make-local-variable 'normal-auto-fill-function)
3539 'cperl-do-auto-fill) ; RMS has it as #'cperl-do-auto-fill ???
3540 (or (fboundp 'cperl-old-auto-fill-mode)
3541 (progn
3542 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
3543 (defun auto-fill-mode (&optional arg)
3544 (interactive "P")
3545 (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
3546 (and auto-fill-function (memq major-mode '(perl-mode cperl-mode))
3547 (setq auto-fill-function 'cperl-do-auto-fill))))))
3548 (if (cperl-enable-font-lock)
3549 (if (cperl-val 'cperl-font-lock)
3550 (progn (or cperl-faces-init (cperl-init-faces))
3551 (font-lock-mode 1))))
3552 (set (make-local-variable 'facemenu-add-face-function)
3553 'cperl-facemenu-add-face-function) ; XXXX What this guy is for???
3554 (and (boundp 'msb-menu-cond)
3555 (not cperl-msb-fixed)
3556 (cperl-msb-fix))
3557 (if (featurep 'easymenu)
3558 (easy-menu-add cperl-menu)) ; A NOP in RMS Emacs.
3559 (run-hooks 'cperl-mode-hook)
3560 (if cperl-hook-after-change
3561 (progn
3562 (make-local-hook 'after-change-functions)
3563 (add-hook 'after-change-functions 'cperl-after-change-function nil t)))
3564 ;; After hooks since fontification will break this
3565 (if cperl-pod-here-scan
3566 (or cperl-syntaxify-by-font-lock
3567 (progn (or cperl-faces-init (cperl-init-faces-weak))
3568 (cperl-find-pods-heres)))))
3570 (defun cperl-insert-faces-example ()
3571 "Insert example \"CODE\" demonstrating CPerl facification at beginning-of-line."
3572 (or (bolp)
3573 (beginning-of-line))
3574 (insert
3575 "my $o = sprintf grep //, <<EOP, $ENV{$_} or warn $$msg[0] for @ARGV; #junk
3576 some string
3578 -f _ or -f $_ or die 'What?';
3580 /\\3333\\xFg\\x{FFF}a\\ppp\\PPP\\qqq\\C\\99f(?{ foo })(??{ foo })/;
3581 /a{4,5}\\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
3582 /(?<=foo)(?<!bar)(x\")(?:$ab|\\$\\/)$|\\\\\\b\\x888\\776\\[\\:$/xxx;
3583 m?(\\?\\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
3584 m$(^ab[c]\\$)$ + m+(^ab[c]\\$\\+)+ + m](^ab[c\\]$|.+)] + m)(^ab[c]$|.+\\));
3585 s{a}{};
3586 s/.a//;
3587 m^a[\\^b-e\\xFF]c^ + m.a[^b]\\.c.; # OK
3588 m^a[\\^-b-\\e--[\\--\\xFF\\c[\\cX-\\0333-\\0555-\\N{name}\\pp--\\P{prop}--\\\\\\05555]^;
3589 m^a[[:alpha:]-[:alpha:]-a-[:alpha:][-aa-[[:alpha:]-b-[:alpha:]-[:alpha:]]^;
3590 m^a[x\\\\[:alpha:]-\\\\[:alpha:]-a-\\\\[:alpha:][-aa-[[:alpha:]-b-\\\\[:alpha:]-\\\\[:alpha:]]^;
3591 m^a[x\\\\[:alpha:][:alpha:]\\\\[:alpha:][-aa-[[:alpha:]\\\\[:alpha:][:alpha:]]^;
3594 ;; Fix for perldb - make default reasonable
3595 (defun cperl-db ()
3596 (interactive)
3597 (require 'gud)
3598 (perldb (read-from-minibuffer "Run perldb (like this): "
3599 (if (consp gud-perldb-history)
3600 (car gud-perldb-history)
3601 (concat "perl " ;;(file-name-nondirectory
3602 ;; I have problems
3603 ;; in OS/2
3604 ;; otherwise
3605 (buffer-file-name)))
3606 nil nil
3607 '(gud-perldb-history . 1))))
3609 (defun cperl-msb-fix ()
3610 ;; Adds perl files to msb menu, supposes that msb is already loaded
3611 (setq cperl-msb-fixed t)
3612 (let* ((l (length msb-menu-cond))
3613 (last (nth (1- l) msb-menu-cond))
3614 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
3615 (handle (1- (nth 1 last))))
3616 (setcdr precdr (list
3617 (list
3618 '(memq major-mode '(cperl-mode perl-mode))
3619 handle
3620 "Perl Files (%d)")
3621 last))))
3623 ;; This is used by indent-for-comment
3624 ;; to decide how much to indent a comment in CPerl code
3625 ;; based on its context. Do fallback if comment is found wrong.
3627 (defvar cperl-wrong-comment)
3628 (defvar cperl-st-cfence '(14)) ; Comment-fence
3629 (defvar cperl-st-sfence '(15)) ; String-fence
3630 (defvar cperl-st-punct '(1))
3631 (defvar cperl-st-word '(2))
3632 (defvar cperl-st-bra '(4 . ?\>))
3633 (defvar cperl-st-ket '(5 . ?\<))
3636 (defun cperl-comment-indent () ; called at point at supposed comment
3637 (let ((p (point)) (c (current-column)) was phony)
3638 (if (and (not cperl-indent-comment-at-column-0)
3639 (looking-at "^#"))
3640 0 ; Existing comment at bol stays there.
3641 ;; Wrong comment found
3642 (save-excursion
3643 (setq was (cperl-to-comment-or-eol)
3644 phony (eq (get-text-property (point) 'syntax-table)
3645 cperl-st-cfence))
3646 (if phony
3647 (progn ; Too naive???
3648 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
3649 (if (eq (preceding-char) ?\#)
3650 (forward-char -1))
3651 (setq was nil)))
3652 (if (= (point) p) ; Our caller found a correct place
3653 (progn
3654 (skip-chars-backward " \t")
3655 (setq was (current-column))
3656 (if (eq was 0)
3657 comment-column
3658 (max (1+ was) ; Else indent at comment column
3659 comment-column)))
3660 ;; No, the caller found a random place; we need to edit ourselves
3661 (if was nil
3662 (insert comment-start)
3663 (backward-char (length comment-start)))
3664 (setq cperl-wrong-comment t)
3665 (cperl-make-indent comment-column 1) ; Indent min 1
3666 c)))))
3668 ;;;(defun cperl-comment-indent-fallback ()
3669 ;;; "Is called if the standard comment-search procedure fails.
3670 ;;;Point is at start of real comment."
3671 ;;; (let ((c (current-column)) target cnt prevc)
3672 ;;; (if (= c comment-column) nil
3673 ;;; (setq cnt (skip-chars-backward "[ \t]"))
3674 ;;; (setq target (max (1+ (setq prevc
3675 ;;; (current-column))) ; Else indent at comment column
3676 ;;; comment-column))
3677 ;;; (if (= c comment-column) nil
3678 ;;; (delete-backward-char cnt)
3679 ;;; (while (< prevc target)
3680 ;;; (insert "\t")
3681 ;;; (setq prevc (current-column)))
3682 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
3683 ;;; (while (< prevc target)
3684 ;;; (insert " ")
3685 ;;; (setq prevc (current-column)))))))
3687 (defun cperl-indent-for-comment ()
3688 "Substitute for `indent-for-comment' in CPerl."
3689 (interactive)
3690 (let (cperl-wrong-comment)
3691 (indent-for-comment)
3692 (if cperl-wrong-comment ; set by `cperl-comment-indent'
3693 (progn (cperl-to-comment-or-eol)
3694 (forward-char (length comment-start))))))
3696 (defun cperl-comment-region (b e arg)
3697 "Comment or uncomment each line in the region in CPerl mode.
3698 See `comment-region'."
3699 (interactive "r\np")
3700 (let ((comment-start "#"))
3701 (comment-region b e arg)))
3703 (defun cperl-uncomment-region (b e arg)
3704 "Uncomment or comment each line in the region in CPerl mode.
3705 See `comment-region'."
3706 (interactive "r\np")
3707 (let ((comment-start "#"))
3708 (comment-region b e (- arg))))
3710 (defvar cperl-brace-recursing nil)
3712 (defun cperl-electric-brace (arg &optional only-before)
3713 "Insert character and correct line's indentation.
3714 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
3715 place (even in empty line), but not after. If after \")\" and the inserted
3716 char is \"{\", insert extra newline before only if
3717 `cperl-extra-newline-before-brace'."
3718 (interactive "P")
3719 (let (insertpos
3720 (other-end (if (and cperl-electric-parens-mark
3721 (cperl-mark-active)
3722 (< (mark) (point)))
3723 (mark)
3724 nil)))
3725 (if (and other-end
3726 (not cperl-brace-recursing)
3727 (cperl-val 'cperl-electric-parens)
3728 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
3729 ;; Need to insert a matching pair
3730 (progn
3731 (save-excursion
3732 (setq insertpos (point-marker))
3733 (goto-char other-end)
3734 (setq last-command-char ?\{)
3735 (cperl-electric-lbrace arg insertpos))
3736 (forward-char 1))
3737 ;; Check whether we close something "usual" with `}'
3738 (if (and (eq last-command-char ?\})
3739 (not
3740 (condition-case nil
3741 (save-excursion
3742 (up-list (- (prefix-numeric-value arg)))
3743 ;;(cperl-after-block-p (point-min))
3744 (or (cperl-after-expr-p nil "{;)")
3745 ;; after sub, else, continue
3746 (cperl-after-block-p nil 'pre)))
3747 (error nil))))
3748 ;; Just insert the guy
3749 (self-insert-command (prefix-numeric-value arg))
3750 (if (and (not arg) ; No args, end (of empty line or auto)
3751 (eolp)
3752 (or (and (null only-before)
3753 (save-excursion
3754 (skip-chars-backward " \t")
3755 (bolp)))
3756 (and (eq last-command-char ?\{) ; Do not insert newline
3757 ;; if after ")" and `cperl-extra-newline-before-brace'
3758 ;; is nil, do not insert extra newline.
3759 (not cperl-extra-newline-before-brace)
3760 (save-excursion
3761 (skip-chars-backward " \t")
3762 (eq (preceding-char) ?\))))
3763 (if cperl-auto-newline
3764 (progn (cperl-indent-line) (newline) t) nil)))
3765 (progn
3766 (self-insert-command (prefix-numeric-value arg))
3767 (cperl-indent-line)
3768 (if cperl-auto-newline
3769 (setq insertpos (1- (point))))
3770 (if (and cperl-auto-newline (null only-before))
3771 (progn
3772 (newline)
3773 (cperl-indent-line)))
3774 (save-excursion
3775 (if insertpos (progn (goto-char insertpos)
3776 (search-forward (make-string
3777 1 last-command-char))
3778 (setq insertpos (1- (point)))))
3779 (delete-char -1))))
3780 (if insertpos
3781 (save-excursion
3782 (goto-char insertpos)
3783 (self-insert-command (prefix-numeric-value arg)))
3784 (self-insert-command (prefix-numeric-value arg))
3785 ;;;(insert (make-string (prefix-numeric-value arg) last-command-char))
3786 )))))
3788 (defun cperl-electric-lbrace (arg &optional end)
3789 "Insert character, correct line's indentation, correct quoting by space."
3790 (interactive "P")
3791 (let ((cperl-brace-recursing t)
3792 (cperl-auto-newline cperl-auto-newline)
3793 (other-end (or end
3794 (if (and cperl-electric-parens-mark
3795 (cperl-mark-active)
3796 (> (mark) (point)))
3797 (save-excursion
3798 (goto-char (mark))
3799 (point-marker))
3800 nil)))
3801 pos after)
3802 (and (cperl-val 'cperl-electric-lbrace-space)
3803 (eq (preceding-char) ?$)
3804 (save-excursion
3805 (skip-chars-backward "$")
3806 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
3807 (insert ?\ ))
3808 ;; Check whether we are in comment
3809 (if (and
3810 (save-excursion
3811 (beginning-of-line)
3812 (not (looking-at "[ \t]*#")))
3813 (cperl-after-expr-p nil "{;)"))
3815 (setq cperl-auto-newline nil))
3816 (cperl-electric-brace arg)
3817 (and (cperl-val 'cperl-electric-parens)
3818 (eq last-command-char ?{)
3819 (memq last-command-char
3820 (append cperl-electric-parens-string nil))
3821 (or (if other-end (goto-char (marker-position other-end)))
3823 (setq last-command-char ?} pos (point))
3824 (progn (cperl-electric-brace arg t)
3825 (goto-char pos)))))
3827 (defun cperl-electric-paren (arg)
3828 "Insert an opening parenthesis or a matching pair of parentheses.
3829 See `cperl-electric-parens'."
3830 (interactive "P")
3831 (let ((beg (save-excursion (beginning-of-line) (point)))
3832 (other-end (if (and cperl-electric-parens-mark
3833 (cperl-mark-active)
3834 (> (mark) (point)))
3835 (save-excursion
3836 (goto-char (mark))
3837 (point-marker))
3838 nil)))
3839 (if (and (cperl-val 'cperl-electric-parens)
3840 (memq last-command-char
3841 (append cperl-electric-parens-string nil))
3842 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
3843 ;;(not (save-excursion (search-backward "#" beg t)))
3844 (if (eq last-command-char ?<)
3845 (progn
3846 (and abbrev-mode ; later it is too late, may be after `for'
3847 (expand-abbrev))
3848 (cperl-after-expr-p nil "{;(,:="))
3850 (progn
3851 (self-insert-command (prefix-numeric-value arg))
3852 (if other-end (goto-char (marker-position other-end)))
3853 (insert (make-string
3854 (prefix-numeric-value arg)
3855 (cdr (assoc last-command-char '((?{ .?})
3856 (?[ . ?])
3857 (?( . ?))
3858 (?< . ?>))))))
3859 (forward-char (- (prefix-numeric-value arg))))
3860 (self-insert-command (prefix-numeric-value arg)))))
3862 (defun cperl-electric-rparen (arg)
3863 "Insert a matching pair of parentheses if marking is active.
3864 If not, or if we are not at the end of marking range, would self-insert.
3865 Affected by `cperl-electric-parens'."
3866 (interactive "P")
3867 (let ((beg (save-excursion (beginning-of-line) (point)))
3868 (other-end (if (and cperl-electric-parens-mark
3869 (cperl-val 'cperl-electric-parens)
3870 (memq last-command-char
3871 (append cperl-electric-parens-string nil))
3872 (cperl-mark-active)
3873 (< (mark) (point)))
3874 (mark)
3875 nil))
3877 (if (and other-end
3878 (cperl-val 'cperl-electric-parens)
3879 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
3880 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
3881 ;;(not (save-excursion (search-backward "#" beg t)))
3883 (progn
3884 (self-insert-command (prefix-numeric-value arg))
3885 (setq p (point))
3886 (if other-end (goto-char other-end))
3887 (insert (make-string
3888 (prefix-numeric-value arg)
3889 (cdr (assoc last-command-char '((?\} . ?\{)
3890 (?\] . ?\[)
3891 (?\) . ?\()
3892 (?\> . ?\<))))))
3893 (goto-char (1+ p)))
3894 (self-insert-command (prefix-numeric-value arg)))))
3896 (defun cperl-electric-keyword ()
3897 "Insert a construction appropriate after a keyword.
3898 Help message may be switched off by setting `cperl-message-electric-keyword'
3899 to nil."
3900 (let ((beg (save-excursion (beginning-of-line) (point)))
3901 (dollar (and (eq last-command-char ?$)
3902 (eq this-command 'self-insert-command)))
3903 (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
3904 (memq this-command '(self-insert-command newline))))
3905 my do)
3906 (and (save-excursion
3907 (condition-case nil
3908 (progn
3909 (backward-sexp 1)
3910 (setq do (looking-at "do\\>")))
3911 (error nil))
3912 (cperl-after-expr-p nil "{;:"))
3913 (save-excursion
3914 (not
3915 (re-search-backward
3916 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
3917 beg t)))
3918 (save-excursion (or (not (re-search-backward "^=" nil t))
3920 (looking-at "=cut")
3921 (and cperl-use-syntax-table-text-property
3922 (not (eq (get-text-property (point)
3923 'syntax-type)
3924 'pod))))))
3925 (save-excursion (forward-sexp -1)
3926 (not (memq (following-char) (append "$@%&*" nil))))
3927 (progn
3928 (and (eq (preceding-char) ?y)
3929 (progn ; "foreachmy"
3930 (forward-char -2)
3931 (insert " ")
3932 (forward-char 2)
3933 (setq my t dollar t
3934 delete
3935 (memq this-command '(self-insert-command newline)))))
3936 (and dollar (insert " $"))
3937 (cperl-indent-line)
3938 ;;(insert " () {\n}")
3939 (cond
3940 (cperl-extra-newline-before-brace
3941 (insert (if do "\n" " ()\n"))
3942 (insert "{")
3943 (cperl-indent-line)
3944 (insert "\n")
3945 (cperl-indent-line)
3946 (insert "\n}")
3947 (and do (insert " while ();")))
3949 (insert (if do " {\n} while ();" " () {\n}"))))
3950 (or (looking-at "[ \t]\\|$") (insert " "))
3951 (cperl-indent-line)
3952 (if dollar (progn (search-backward "$")
3953 (if my
3954 (forward-char 1)
3955 (delete-char 1)))
3956 (search-backward ")")
3957 (if (eq last-command-char ?\()
3958 (progn ; Avoid "if (())"
3959 (delete-backward-char 1)
3960 (delete-backward-char -1))))
3961 (if delete
3962 (cperl-putback-char cperl-del-back-ch))
3963 (if cperl-message-electric-keyword
3964 (message "Precede char by C-q to avoid expansion"))))))
3966 (defun cperl-ensure-newlines (n &optional pos)
3967 "Make sure there are N newlines after the point."
3968 (or pos (setq pos (point)))
3969 (if (looking-at "\n")
3970 (forward-char 1)
3971 (insert "\n"))
3972 (if (> n 1)
3973 (cperl-ensure-newlines (1- n) pos)
3974 (goto-char pos)))
3976 (defun cperl-electric-pod ()
3977 "Insert a POD chunk appropriate after a =POD directive."
3978 (let ((delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
3979 (memq this-command '(self-insert-command newline))))
3980 head1 notlast name p really-delete over)
3981 (and (save-excursion
3982 (forward-word -1)
3983 (and
3984 (eq (preceding-char) ?=)
3985 (progn
3986 (setq head1 (looking-at "head1\\>[ \t]*$"))
3987 (setq over (and (looking-at "over\\>[ \t]*$")
3988 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
3989 (forward-char -1)
3990 (bolp))
3992 (get-text-property (point) 'in-pod)
3993 (cperl-after-expr-p nil "{;:")
3994 (and (re-search-backward "\\(\\`\n?\\|^\n\\)=\\sw+" (point-min) t)
3995 (not (looking-at "\n*=cut"))
3996 (or (not cperl-use-syntax-table-text-property)
3997 (eq (get-text-property (point) 'syntax-type) 'pod))))))
3998 (progn
3999 (save-excursion
4000 (setq notlast (re-search-forward "^\n=" nil t)))
4001 (or notlast
4002 (progn
4003 (insert "\n\n=cut")
4004 (cperl-ensure-newlines 2)
4005 (forward-word -2)
4006 (if (and head1
4007 (not
4008 (save-excursion
4009 (forward-char -1)
4010 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
4011 nil t)))) ; Only one
4012 (progn
4013 (forward-word 1)
4014 (setq name (file-name-sans-extension
4015 (file-name-nondirectory (buffer-file-name)))
4016 p (point))
4017 (insert " NAME\n\n" name
4018 " - \n\n=head1 SYNOPSIS\n\n\n\n"
4019 "=head1 DESCRIPTION")
4020 (cperl-ensure-newlines 4)
4021 (goto-char p)
4022 (forward-word 2)
4023 (end-of-line)
4024 (setq really-delete t))
4025 (forward-word 1))))
4026 (if over
4027 (progn
4028 (setq p (point))
4029 (insert "\n\n=item \n\n\n\n"
4030 "=back")
4031 (cperl-ensure-newlines 2)
4032 (goto-char p)
4033 (forward-word 1)
4034 (end-of-line)
4035 (setq really-delete t)))
4036 (if (and delete really-delete)
4037 (cperl-putback-char cperl-del-back-ch))))))
4039 (defun cperl-electric-else ()
4040 "Insert a construction appropriate after a keyword.
4041 Help message may be switched off by setting `cperl-message-electric-keyword'
4042 to nil."
4043 (let ((beg (save-excursion (beginning-of-line) (point))))
4044 (and (save-excursion
4045 (backward-sexp 1)
4046 (cperl-after-expr-p nil "{;:"))
4047 (save-excursion
4048 (not
4049 (re-search-backward
4050 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
4051 beg t)))
4052 (save-excursion (or (not (re-search-backward "^=" nil t))
4053 (looking-at "=cut")
4054 (and cperl-use-syntax-table-text-property
4055 (not (eq (get-text-property (point)
4056 'syntax-type)
4057 'pod)))))
4058 (progn
4059 (cperl-indent-line)
4060 ;;(insert " {\n\n}")
4061 (cond
4062 (cperl-extra-newline-before-brace
4063 (insert "\n")
4064 (insert "{")
4065 (cperl-indent-line)
4066 (insert "\n\n}"))
4068 (insert " {\n\n}")))
4069 (or (looking-at "[ \t]\\|$") (insert " "))
4070 (cperl-indent-line)
4071 (forward-line -1)
4072 (cperl-indent-line)
4073 (cperl-putback-char cperl-del-back-ch)
4074 (setq this-command 'cperl-electric-else)
4075 (if cperl-message-electric-keyword
4076 (message "Precede char by C-q to avoid expansion"))))))
4078 (defun cperl-linefeed ()
4079 "Go to end of line, open a new line and indent appropriately.
4080 If in POD, insert appropriate lines."
4081 (interactive)
4082 (let ((beg (save-excursion (beginning-of-line) (point)))
4083 (end (save-excursion (end-of-line) (point)))
4084 (pos (point)) start over cut res)
4085 (if (and ; Check if we need to split:
4086 ; i.e., on a boundary and inside "{...}"
4087 (save-excursion (cperl-to-comment-or-eol)
4088 (>= (point) pos)) ; Not in a comment
4089 (or (save-excursion
4090 (skip-chars-backward " \t" beg)
4091 (forward-char -1)
4092 (looking-at "[;{]")) ; After { or ; + spaces
4093 (looking-at "[ \t]*}") ; Before }
4094 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
4095 (save-excursion
4096 (and
4097 (eq (car (parse-partial-sexp pos end -1)) -1)
4098 ; Leave the level of parens
4099 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
4100 ; Are at end
4101 (cperl-after-block-p (point-min))
4102 (progn
4103 (backward-sexp 1)
4104 (setq start (point-marker))
4105 (<= start pos))))) ; Redundant? Are after the
4106 ; start of parens group.
4107 (progn
4108 (skip-chars-backward " \t")
4109 (or (memq (preceding-char) (append ";{" nil))
4110 (insert ";"))
4111 (insert "\n")
4112 (forward-line -1)
4113 (cperl-indent-line)
4114 (goto-char start)
4115 (or (looking-at "{[ \t]*$") ; If there is a statement
4116 ; before, move it to separate line
4117 (progn
4118 (forward-char 1)
4119 (insert "\n")
4120 (cperl-indent-line)))
4121 (forward-line 1) ; We are on the target line
4122 (cperl-indent-line)
4123 (beginning-of-line)
4124 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
4125 ; after, move it to separate line
4126 (progn
4127 (end-of-line)
4128 (search-backward "}" beg)
4129 (skip-chars-backward " \t")
4130 (or (memq (preceding-char) (append ";{" nil))
4131 (insert ";"))
4132 (insert "\n")
4133 (cperl-indent-line)
4134 (forward-line -1)))
4135 (forward-line -1) ; We are on the line before target
4136 (end-of-line)
4137 (newline-and-indent))
4138 (end-of-line) ; else - no splitting
4139 (cond
4140 ((and (looking-at "\n[ \t]*{$")
4141 (save-excursion
4142 (skip-chars-backward " \t")
4143 (eq (preceding-char) ?\)))) ; Probably if () {} group
4144 ; with an extra newline.
4145 (forward-line 2)
4146 (cperl-indent-line))
4147 ((save-excursion ; In POD header
4148 (forward-paragraph -1)
4149 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
4150 ;; We are after \n now, so look for the rest
4151 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
4152 (progn
4153 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
4154 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
4155 t)))
4156 (if (and over
4157 (progn
4158 (forward-paragraph -1)
4159 (forward-word 1)
4160 (setq pos (point))
4161 (setq cut (buffer-substring (point)
4162 (save-excursion
4163 (end-of-line)
4164 (point))))
4165 (delete-char (- (save-excursion (end-of-line) (point))
4166 (point)))
4167 (setq res (expand-abbrev))
4168 (save-excursion
4169 (goto-char pos)
4170 (insert cut))
4171 res))
4173 (cperl-ensure-newlines (if cut 2 4))
4174 (forward-line 2)))
4175 ((get-text-property (point) 'in-pod) ; In POD section
4176 (cperl-ensure-newlines 4)
4177 (forward-line 2))
4178 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
4179 (forward-line 1)
4180 (cperl-indent-line))
4182 (newline-and-indent))))))
4184 (defun cperl-electric-semi (arg)
4185 "Insert character and correct line's indentation."
4186 (interactive "P")
4187 (if cperl-auto-newline
4188 (cperl-electric-terminator arg)
4189 (self-insert-command (prefix-numeric-value arg))
4190 (if cperl-autoindent-on-semi
4191 (cperl-indent-line))))
4193 (defun cperl-electric-terminator (arg)
4194 "Insert character and correct line's indentation."
4195 (interactive "P")
4196 (let ((end (point))
4197 (auto (and cperl-auto-newline
4198 (or (not (eq last-command-char ?:))
4199 cperl-auto-newline-after-colon)))
4200 insertpos)
4201 (if (and ;;(not arg)
4202 (eolp)
4203 (not (save-excursion
4204 (beginning-of-line)
4205 (skip-chars-forward " \t")
4207 ;; Ignore in comment lines
4208 (= (following-char) ?#)
4209 ;; Colon is special only after a label
4210 ;; So quickly rule out most other uses of colon
4211 ;; and do no indentation for them.
4212 (and (eq last-command-char ?:)
4213 (save-excursion
4214 (forward-word 1)
4215 (skip-chars-forward " \t")
4216 (and (< (point) end)
4217 (progn (goto-char (- end 1))
4218 (not (looking-at ":"))))))
4219 (progn
4220 (beginning-of-defun)
4221 (let ((pps (parse-partial-sexp (point) end)))
4222 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
4223 (progn
4224 (self-insert-command (prefix-numeric-value arg))
4225 ;;(forward-char -1)
4226 (if auto (setq insertpos (point-marker)))
4227 ;;(forward-char 1)
4228 (cperl-indent-line)
4229 (if auto
4230 (progn
4231 (newline)
4232 (cperl-indent-line)))
4233 (save-excursion
4234 (if insertpos (goto-char (1- (marker-position insertpos)))
4235 (forward-char -1))
4236 (delete-char 1))))
4237 (if insertpos
4238 (save-excursion
4239 (goto-char insertpos)
4240 (self-insert-command (prefix-numeric-value arg)))
4241 (self-insert-command (prefix-numeric-value arg)))))
4243 (defun cperl-electric-backspace (arg)
4244 "Backspace, or remove the whitespace around the point inserted by an electric
4245 key. Will untabivy if `cperl-electric-backspace-untabify' is non-nil."
4246 (interactive "p")
4247 (if (and cperl-auto-newline
4248 (memq last-command '(cperl-electric-semi
4249 cperl-electric-terminator
4250 cperl-electric-lbrace))
4251 (memq (preceding-char) '(?\ ?\t ?\n)))
4252 (let (p)
4253 (if (eq last-command 'cperl-electric-lbrace)
4254 (skip-chars-forward " \t\n"))
4255 (setq p (point))
4256 (skip-chars-backward " \t\n")
4257 (delete-region (point) p))
4258 (and (eq last-command 'cperl-electric-else)
4259 ;; We are removing the whitespace *inside* cperl-electric-else
4260 (setq this-command 'cperl-electric-else-really))
4261 (if (and cperl-auto-newline
4262 (eq last-command 'cperl-electric-else-really)
4263 (memq (preceding-char) '(?\ ?\t ?\n)))
4264 (let (p)
4265 (skip-chars-forward " \t\n")
4266 (setq p (point))
4267 (skip-chars-backward " \t\n")
4268 (delete-region (point) p))
4269 (if cperl-electric-backspace-untabify
4270 (backward-delete-char-untabify arg)
4271 (delete-backward-char arg)))))
4273 ;; XEmacs addition
4274 ;; helper function for deletion, which honors the desired delete direction
4275 ;; behavior. Added by Gary D. Foster, <Gary.Foster@corp.sun.com> and bound
4276 ;; to the 'delete keysym by default.
4277 (defun cperl-electric-delete (arg)
4278 "Delete, or remove the whitespace inserted by an electric key.
4279 Delete direction is controlled by the setting of `delete-key-deletes-forward'."
4280 (interactive "*p")
4281 (if (and cperl-auto-newline
4282 (memq last-command '(cperl-electric-semi
4283 cperl-electric-terminator
4284 cperl-electric-lbrace))
4285 (memq (preceding-char) '(? ?\t ?\n)))
4286 (let (p)
4287 (if (eq last-command 'cperl-electric-lbrace)
4288 (skip-chars-forward " \t\n"))
4289 (setq p (point))
4290 (skip-chars-backward " \t\n")
4291 (delete-region (point) p))
4292 (if (fboundp 'backward-or-forward-delete-char)
4293 (let ((f 'backward-or-forward-delete-char))
4294 (funcall f arg)) ; Avoid "not defined"
4295 (backward-delete-char-untabify arg))))
4297 (defun cperl-inside-parens-p () ;; NOT USED????
4298 (condition-case ()
4299 (save-excursion
4300 (save-restriction
4301 (narrow-to-region (point)
4302 (progn (beginning-of-defun) (point)))
4303 (goto-char (point-max))
4304 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
4305 (error nil)))
4307 (defun cperl-indent-command (&optional whole-exp)
4308 "Indent current line as Perl code, or in some cases insert a tab character.
4309 If `cperl-tab-always-indent' is non-nil (the default), always indent current
4310 line. Otherwise, indent the current line only if point is at the left margin
4311 or in the line's indentation; otherwise insert a tab.
4313 A numeric argument, regardless of its value,
4314 means indent rigidly all the lines of the expression starting after point
4315 so that this line becomes properly indented.
4316 The relative indentation among the lines of the expression are preserved."
4317 (interactive "P")
4318 (cperl-update-syntaxification (point) (point))
4319 (if whole-exp
4320 ;; If arg, always indent this line as Perl
4321 ;; and shift remaining lines of expression the same amount.
4322 (let ((shift-amt (cperl-indent-line))
4323 beg end)
4324 (save-excursion
4325 (if cperl-tab-always-indent
4326 (beginning-of-line))
4327 (setq beg (point))
4328 (forward-sexp 1)
4329 (setq end (point))
4330 (goto-char beg)
4331 (forward-line 1)
4332 (setq beg (point)))
4333 (if (and shift-amt (> end beg))
4334 (indent-code-rigidly beg end shift-amt "#")))
4335 (if (and (not cperl-tab-always-indent)
4336 (save-excursion
4337 (skip-chars-backward " \t")
4338 (not (bolp))))
4339 (insert-tab)
4340 (cperl-indent-line))))
4342 (defun cperl-indent-line (&optional parse-data)
4343 "Indent current line as Perl code.
4344 Return the amount the indentation changed by."
4345 (let ((case-fold-search nil)
4346 (pos (- (point-max) (point)))
4347 indent i beg shift-amt)
4348 (setq indent (cperl-calculate-indent parse-data)
4349 i indent)
4350 (beginning-of-line)
4351 (setq beg (point))
4352 (cond ((or (eq indent nil) (eq indent t))
4353 (setq indent (current-indentation) i nil))
4354 ;;((eq indent t) ; Never?
4355 ;; (setq indent (cperl-calculate-indent-within-comment)))
4356 ;;((looking-at "[ \t]*#")
4357 ;; (setq indent 0))
4359 (skip-chars-forward " \t")
4360 (if (listp indent) (setq indent (car indent)))
4361 (cond ((and (looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
4362 (not (looking-at "[smy]:\\|tr:")))
4363 (and (> indent 0)
4364 (setq indent (max cperl-min-label-indent
4365 (+ indent cperl-label-offset)))))
4366 ((= (following-char) ?})
4367 (setq indent (- indent cperl-indent-level)))
4368 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
4369 (setq indent (+ indent cperl-close-paren-offset)))
4370 ((= (following-char) ?{)
4371 (setq indent (+ indent cperl-brace-offset))))))
4372 (skip-chars-forward " \t")
4373 (setq shift-amt (and i (- indent (current-column))))
4374 (if (or (not shift-amt)
4375 (zerop shift-amt))
4376 (if (> (- (point-max) pos) (point))
4377 (goto-char (- (point-max) pos)))
4378 ;;;(delete-region beg (point))
4379 ;;;(indent-to indent)
4380 (cperl-make-indent indent)
4381 ;; If initial point was within line's indentation,
4382 ;; position after the indentation. Else stay at same point in text.
4383 (if (> (- (point-max) pos) (point))
4384 (goto-char (- (point-max) pos))))
4385 shift-amt))
4387 (defun cperl-after-label ()
4388 ;; Returns true if the point is after label. Does not do save-excursion.
4389 (and (eq (preceding-char) ?:)
4390 (memq (char-syntax (char-after (- (point) 2)))
4391 '(?w ?_))
4392 (progn
4393 (backward-sexp)
4394 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
4396 (defun cperl-get-state (&optional parse-start start-state)
4397 ;; returns list (START STATE DEPTH PRESTART),
4398 ;; START is a good place to start parsing, or equal to
4399 ;; PARSE-START if preset,
4400 ;; STATE is what is returned by `parse-partial-sexp'.
4401 ;; DEPTH is true is we are immediately after end of block
4402 ;; which contains START.
4403 ;; PRESTART is the position basing on which START was found.
4404 (save-excursion
4405 (let ((start-point (point)) depth state start prestart)
4406 (if (and parse-start
4407 (<= parse-start start-point))
4408 (goto-char parse-start)
4409 (beginning-of-defun)
4410 (setq start-state nil))
4411 (setq prestart (point))
4412 (if start-state nil
4413 ;; Try to go out, if sub is not on the outermost level
4414 (while (< (point) start-point)
4415 (setq start (point) parse-start start depth nil
4416 state (parse-partial-sexp start start-point -1))
4417 (if (> (car state) -1) nil
4418 ;; The current line could start like }}}, so the indentation
4419 ;; corresponds to a different level than what we reached
4420 (setq depth t)
4421 (beginning-of-line 2))) ; Go to the next line.
4422 (if start (goto-char start))) ; Not at the start of file
4423 (setq start (point))
4424 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
4425 (list start state depth prestart))))
4427 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
4429 (defun cperl-beginning-of-property (p prop &optional lim)
4430 "Given that P has a property PROP, find where the property starts.
4431 Will not look before LIM."
4432 ;;; XXXX What to do at point-max???
4433 (or (previous-single-property-change (cperl-1+ p) prop lim)
4434 (point-min))
4435 ;;; (cond ((eq p (point-min))
4436 ;;; p)
4437 ;;; ((and lim (<= p lim))
4438 ;;; p)
4439 ;;; ((not (get-text-property (1- p) prop))
4440 ;;; p)
4441 ;;; (t (or (previous-single-property-change p look-prop lim)
4442 ;;; (point-min))))
4445 (defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start
4446 ;; the sniffer logic to understand what the current line MEANS.
4447 (cperl-update-syntaxification (point) (point))
4448 (let ((res (get-text-property (point) 'syntax-type)))
4449 (save-excursion
4450 (cond
4451 ((and (memq res '(pod here-doc here-doc-delim format))
4452 (not (get-text-property (point) 'indentable)))
4453 (vector res))
4454 ;; before start of POD - whitespace found since do not have 'pod!
4455 ((looking-at "[ \t]*\n=")
4456 (error "Spaces before POD section!"))
4457 ((and (not cperl-indent-left-aligned-comments)
4458 (looking-at "^#"))
4459 [comment-special:at-beginning-of-line])
4460 ((get-text-property (point) 'in-pod)
4461 [in-pod])
4463 (beginning-of-line)
4464 (let* ((indent-point (point))
4465 (char-after-pos (save-excursion
4466 (skip-chars-forward " \t")
4467 (point)))
4468 (char-after (char-after char-after-pos))
4469 (pre-indent-point (point))
4470 p prop look-prop is-block delim)
4471 (save-excursion ; Know we are not in POD, find appropriate pos before
4472 (cperl-backward-to-noncomment nil)
4473 (setq p (max (point-min) (1- (point)))
4474 prop (get-text-property p 'syntax-type)
4475 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
4476 'syntax-type))
4477 (if (memq prop '(pod here-doc format here-doc-delim))
4478 (progn
4479 (goto-char (cperl-beginning-of-property p look-prop))
4480 (beginning-of-line)
4481 (setq pre-indent-point (point)))))
4482 (goto-char pre-indent-point) ; Orig line skipping preceeding pod/etc
4483 (let* ((case-fold-search nil)
4484 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
4485 (start (or (nth 2 parse-data) ; last complete sexp terminated
4486 (nth 0 s-s))) ; Good place to start parsing
4487 (state (nth 1 s-s))
4488 (containing-sexp (car (cdr state)))
4489 old-indent)
4490 (if (and
4491 ;;containing-sexp ;; We are buggy at toplevel :-(
4492 parse-data)
4493 (progn
4494 (setcar parse-data pre-indent-point)
4495 (setcar (cdr parse-data) state)
4496 (or (nth 2 parse-data)
4497 (setcar (cddr parse-data) start))
4498 ;; Before this point: end of statement
4499 (setq old-indent (nth 3 parse-data))))
4500 (cond ((get-text-property (point) 'indentable)
4501 ;; indent to "after" the surrounding open
4502 ;; (same offset as `cperl-beautify-regexp-piece'),
4503 ;; skip blanks if we do not close the expression.
4504 (setq delim ; We do not close the expression
4505 (get-text-property
4506 (cperl-1+ char-after-pos) 'indentable)
4507 p (1+ (cperl-beginning-of-property
4508 (point) 'indentable))
4509 is-block ; misused for: preceeding line in REx
4510 (save-excursion ; Find preceeding line
4511 (cperl-backward-to-noncomment p)
4512 (beginning-of-line)
4513 (if (<= (point) p)
4514 (progn ; get indent from the first line
4515 (goto-char p)
4516 (skip-chars-forward " \t")
4517 (if (memq (char-after (point))
4518 (append "#\n" nil))
4519 nil ; Can't use intentation of this line...
4520 (point)))
4521 (skip-chars-forward " \t")
4522 (point)))
4523 prop (parse-partial-sexp p char-after-pos))
4524 (cond ((not delim) ; End the REx, ignore is-block
4525 (vector 'indentable 'terminator p is-block))
4526 (is-block ; Indent w.r.t. preceeding line
4527 (vector 'indentable 'cont-line char-after-pos
4528 is-block char-after p))
4529 (t ; No preceeding line...
4530 (vector 'indentable 'first-line p))))
4531 ((get-text-property char-after-pos 'REx-part2)
4532 (vector 'REx-part2 (point)))
4533 ((nth 4 state)
4534 [comment])
4535 ((nth 3 state)
4536 [string])
4537 ;; XXXX Do we need to special-case this?
4538 ((null containing-sexp)
4539 ;; Line is at top level. May be data or function definition,
4540 ;; or may be function argument declaration.
4541 ;; Indent like the previous top level line
4542 ;; unless that ends in a closeparen without semicolon,
4543 ;; in which case this line is the first argument decl.
4544 (skip-chars-forward " \t")
4545 (cperl-backward-to-noncomment (or old-indent (point-min)))
4546 (setq state
4547 (or (bobp)
4548 (eq (point) old-indent) ; old-indent was at comment
4549 (eq (preceding-char) ?\;)
4550 ;; Had ?\) too
4551 (and (eq (preceding-char) ?\})
4552 (cperl-after-block-and-statement-beg
4553 (point-min))) ; Was start - too close
4554 (memq char-after (append ")]}" nil))
4555 (and (eq (preceding-char) ?\:) ; label
4556 (progn
4557 (forward-sexp -1)
4558 (skip-chars-backward " \t")
4559 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
4560 (get-text-property (point) 'first-format-line)))
4562 ;; Look at previous line that's at column 0
4563 ;; to determine whether we are in top-level decls
4564 ;; or function's arg decls. Set basic-indent accordingly.
4565 ;; Now add a little if this is a continuation line.
4566 (and state
4567 parse-data
4568 (not (eq char-after ?\C-j))
4569 (setcdr (cddr parse-data)
4570 (list pre-indent-point)))
4571 (vector 'toplevel start char-after state (nth 2 s-s)))
4572 ((not
4573 (or (setq is-block
4574 (and (setq delim (= (char-after containing-sexp) ?{))
4575 (save-excursion ; Is it a hash?
4576 (goto-char containing-sexp)
4577 (cperl-block-p))))
4578 cperl-indent-parens-as-block))
4579 ;; group is an expression, not a block:
4580 ;; indent to just after the surrounding open parens,
4581 ;; skip blanks if we do not close the expression.
4582 (goto-char (1+ containing-sexp))
4583 (or (memq char-after
4584 (append (if delim "}" ")]}") nil))
4585 (looking-at "[ \t]*\\(#\\|$\\)")
4586 (skip-chars-forward " \t"))
4587 (setq old-indent (point)) ; delim=is-brace
4588 (vector 'in-parens char-after (point) delim containing-sexp))
4590 ;; Statement level. Is it a continuation or a new statement?
4591 ;; Find previous non-comment character.
4592 (goto-char pre-indent-point) ; Skip one level of POD/etc
4593 (cperl-backward-to-noncomment containing-sexp)
4594 ;; Back up over label lines, since they don't
4595 ;; affect whether our line is a continuation.
4596 ;; (Had \, too)
4597 (while;;(or (eq (preceding-char) ?\,)
4598 (and (eq (preceding-char) ?:)
4599 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
4600 (memq (char-syntax (char-after (- (point) 2)))
4601 '(?w ?_))))
4603 ;; This is always FALSE?
4604 (if (eq (preceding-char) ?\,)
4605 ;; Will go to beginning of line, essentially.
4606 ;; Will ignore embedded sexpr XXXX.
4607 (cperl-backward-to-start-of-continued-exp containing-sexp))
4608 (beginning-of-line)
4609 (cperl-backward-to-noncomment containing-sexp))
4610 ;; Now we get non-label preceeding the indent point
4611 (if (not (or (eq (1- (point)) containing-sexp)
4612 (memq (preceding-char)
4613 (append (if is-block " ;{" " ,;{") '(nil)))
4614 (and (eq (preceding-char) ?\})
4615 (cperl-after-block-and-statement-beg
4616 containing-sexp))
4617 (get-text-property (point) 'first-format-line)))
4618 ;; This line is continuation of preceding line's statement;
4619 ;; indent `cperl-continued-statement-offset' more than the
4620 ;; previous line of the statement.
4622 ;; There might be a label on this line, just
4623 ;; consider it bad style and ignore it.
4624 (progn
4625 (cperl-backward-to-start-of-continued-exp containing-sexp)
4626 (vector 'continuation (point) char-after is-block delim))
4627 ;; This line starts a new statement.
4628 ;; Position following last unclosed open brace
4629 (goto-char containing-sexp)
4630 ;; Is line first statement after an open-brace?
4632 ;; If no, find that first statement and indent like
4633 ;; it. If the first statement begins with label, do
4634 ;; not believe when the indentation of the label is too
4635 ;; small.
4636 (save-excursion
4637 (forward-char 1)
4638 (let ((colon-line-end 0))
4639 (while
4640 (progn (skip-chars-forward " \t\n")
4641 ;; s: foo : bar :x is NOT label
4642 (and (looking-at "#\\|\\([a-zA-Z0-9_$]+\\):[^:]\\|=[a-zA-Z]")
4643 (not (looking-at "[sym]:\\|tr:"))))
4644 ;; Skip over comments and labels following openbrace.
4645 (cond ((= (following-char) ?\#)
4646 (forward-line 1))
4647 ((= (following-char) ?\=)
4648 (goto-char
4649 (or (next-single-property-change (point) 'in-pod)
4650 (point-max)))) ; do not loop if no syntaxification
4651 ;; label:
4653 (save-excursion (end-of-line)
4654 (setq colon-line-end (point)))
4655 (search-forward ":"))))
4656 ;; We are at beginning of code (NOT label or comment)
4657 ;; First, the following code counts
4658 ;; if it is before the line we want to indent.
4659 (and (< (point) indent-point)
4660 (vector 'have-prev-sibling (point) colon-line-end
4661 containing-sexp))))
4662 (progn
4663 ;; If no previous statement,
4664 ;; indent it relative to line brace is on.
4666 ;; For open-braces not the first thing in a line,
4667 ;; add in cperl-brace-imaginary-offset.
4669 ;; If first thing on a line: ?????
4670 ;; Move back over whitespace before the openbrace.
4671 (setq ; brace first thing on a line
4672 old-indent (progn (skip-chars-backward " \t") (bolp)))
4673 ;; Should we indent w.r.t. earlier than start?
4674 ;; Move to start of control group, possibly on a different line
4675 (or cperl-indent-wrt-brace
4676 (cperl-backward-to-noncomment (point-min)))
4677 ;; If the openbrace is preceded by a parenthesized exp,
4678 ;; move to the beginning of that;
4679 (if (eq (preceding-char) ?\))
4680 (progn
4681 (forward-sexp -1)
4682 (cperl-backward-to-noncomment (point-min))))
4683 ;; In the case it starts a subroutine, indent with
4684 ;; respect to `sub', not with respect to the
4685 ;; first thing on the line, say in the case of
4686 ;; anonymous sub in a hash.
4687 (if (and;; Is it a sub in group starting on this line?
4688 (cond ((get-text-property (point) 'attrib-group)
4689 (goto-char (cperl-beginning-of-property
4690 (point) 'attrib-group)))
4691 ((eq (preceding-char) ?b)
4692 (forward-sexp -1)
4693 (looking-at "sub\\>")))
4694 (setq p (nth 1 ; start of innermost containing list
4695 (parse-partial-sexp
4696 (save-excursion (beginning-of-line)
4697 (point))
4698 (point)))))
4699 (progn
4700 (goto-char (1+ p)) ; enclosing block on the same line
4701 (skip-chars-forward " \t")
4702 (vector 'code-start-in-block containing-sexp char-after
4703 (and delim (not is-block)) ; is a HASH
4704 old-indent ; brace first thing on a line
4705 t (point) ; have something before...
4707 ;;(current-column)
4709 ;; Get initial indentation of the line we are on.
4710 ;; If line starts with label, calculate label indentation
4711 (vector 'code-start-in-block containing-sexp char-after
4712 (and delim (not is-block)) ; is a HASH
4713 old-indent ; brace first thing on a line
4714 nil (point))))))))))))))) ; nothing interesting before
4716 (defvar cperl-indent-rules-alist
4717 '((pod nil) ; via `syntax-type' property
4718 (here-doc nil) ; via `syntax-type' property
4719 (here-doc-delim nil) ; via `syntax-type' property
4720 (format nil) ; via `syntax-type' property
4721 (in-pod nil) ; via `in-pod' property
4722 (comment-special:at-beginning-of-line nil)
4723 (string t)
4724 (comment nil))
4725 "Alist of indentation rules for CPerl mode.
4726 The values mean:
4727 nil: do not indent;
4728 number: add this amount of indentation.")
4730 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
4731 "Return appropriate indentation for current line as Perl code.
4732 In usual case returns an integer: the column to indent to.
4733 Returns nil if line starts inside a string, t if in a comment.
4735 Will not correct the indentation for labels, but will correct it for braces
4736 and closing parentheses and brackets."
4737 ;; This code is still a broken architecture: in some cases we need to
4738 ;; compensate for some modifications which `cperl-indent-line' will add later
4739 (save-excursion
4740 (let ((i (cperl-sniff-for-indent parse-data)) what p)
4741 (cond
4742 ;;((or (null i) (eq i t) (numberp i))
4743 ;; i)
4744 ((vectorp i)
4745 (setq what (assoc (elt i 0) cperl-indent-rules-alist))
4746 (cond
4747 (what (cadr what)) ; Load from table
4749 ;; Indenters for regular expressions with //x and qw()
4751 ((eq 'REx-part2 (elt i 0)) ;; [self start] start of /REP in s//REP/x
4752 (goto-char (elt i 1))
4753 (condition-case nil ; Use indentation of the 1st part
4754 (forward-sexp -1))
4755 (current-column))
4756 ((eq 'indentable (elt i 0)) ; Indenter for REGEXP qw() etc
4757 (cond ;;; [indentable terminator start-pos is-block]
4758 ((eq 'terminator (elt i 1)) ; Lone terminator of "indentable string"
4759 (goto-char (elt i 2)) ; After opening parens
4760 (1- (current-column)))
4761 ((eq 'first-line (elt i 1)); [indentable first-line start-pos]
4762 (goto-char (elt i 2))
4763 (+ (or cperl-regexp-indent-step cperl-indent-level)
4765 (current-column)))
4766 ((eq 'cont-line (elt i 1)); [indentable cont-line pos prev-pos first-char start-pos]
4767 ;; Indent as the level after closing parens
4768 (goto-char (elt i 2)) ; indent line
4769 (skip-chars-forward " \t)") ; Skip closing parens
4770 (setq p (point))
4771 (goto-char (elt i 3)) ; previous line
4772 (skip-chars-forward " \t)") ; Skip closing parens
4773 ;; Number of parens in between:
4774 (setq p (nth 0 (parse-partial-sexp (point) p))
4775 what (elt i 4)) ; First char on current line
4776 (goto-char (elt i 3)) ; previous line
4777 (+ (* p (or cperl-regexp-indent-step cperl-indent-level))
4778 (cond ((eq what ?\) )
4779 (- cperl-close-paren-offset)) ; compensate
4780 ((eq what ?\| )
4781 (- (or cperl-regexp-indent-step cperl-indent-level)))
4782 (t 0))
4783 (if (eq (following-char) ?\| )
4784 (or cperl-regexp-indent-step cperl-indent-level)
4786 (current-column)))
4788 (error "Unrecognized value of indent: " i))))
4790 ;; Indenter for stuff at toplevel
4792 ((eq 'toplevel (elt i 0)) ;; [toplevel start char-after state immed-after-block]
4793 (+ (save-excursion ; To beg-of-defun, or end of last sexp
4794 (goto-char (elt i 1)) ; start = Good place to start parsing
4795 (- (current-indentation) ;
4796 (if (elt i 4) cperl-indent-level 0))) ; immed-after-block
4797 (if (eq (elt i 2) ?{) cperl-continued-brace-offset 0) ; char-after
4798 ;; Look at previous line that's at column 0
4799 ;; to determine whether we are in top-level decls
4800 ;; or function's arg decls. Set basic-indent accordingly.
4801 ;; Now add a little if this is a continuation line.
4802 (if (elt i 3) ; state (XXX What is the semantic???)
4804 cperl-continued-statement-offset)))
4806 ;; Indenter for stuff in "parentheses" (or brackets, braces-as-hash)
4808 ((eq 'in-parens (elt i 0))
4809 ;; in-parens char-after old-indent-point is-brace containing-sexp
4811 ;; group is an expression, not a block:
4812 ;; indent to just after the surrounding open parens,
4813 ;; skip blanks if we do not close the expression.
4814 (+ (progn
4815 (goto-char (elt i 2)) ; old-indent-point
4816 (current-column))
4817 (if (and (elt i 3) ; is-brace
4818 (eq (elt i 1) ?\})) ; char-after
4819 ;; Correct indentation of trailing ?\}
4820 (+ cperl-indent-level cperl-close-paren-offset)
4821 0)))
4823 ;; Indenter for continuation lines
4825 ((eq 'continuation (elt i 0))
4826 ;; [continuation statement-start char-after is-block is-brace]
4827 (goto-char (elt i 1)) ; statement-start
4828 (+ (if (memq (elt i 2) (append "}])" nil)) ; char-after
4829 0 ; Closing parenth
4830 cperl-continued-statement-offset)
4831 (if (or (elt i 3) ; is-block
4832 (not (elt i 4)) ; is-brace
4833 (not (eq (elt i 2) ?\}))) ; char-after
4835 ;; Now it is a hash reference
4836 (+ cperl-indent-level cperl-close-paren-offset))
4837 ;; Labels do not take :: ...
4838 (if (looking-at "\\(\\w\\|_\\)+[ \t]*:")
4839 (if (> (current-indentation) cperl-min-label-indent)
4840 (- (current-indentation) cperl-label-offset)
4841 ;; Do not move `parse-data', this should
4842 ;; be quick anyway (this comment comes
4843 ;; from different location):
4844 (cperl-calculate-indent))
4845 (current-column))
4846 (if (eq (elt i 2) ?\{) ; char-after
4847 cperl-continued-brace-offset 0)))
4849 ;; Indenter for lines in a block which are not leading lines
4851 ((eq 'have-prev-sibling (elt i 0))
4852 ;; [have-prev-sibling sibling-beg colon-line-end block-start]
4853 (goto-char (elt i 1)) ; sibling-beg
4854 (if (> (elt i 2) (point)) ; colon-line-end; have label before point
4855 (if (> (current-indentation)
4856 cperl-min-label-indent)
4857 (- (current-indentation) cperl-label-offset)
4858 ;; Do not believe: `max' was involved in calculation of indent
4859 (+ cperl-indent-level
4860 (save-excursion
4861 (goto-char (elt i 3)) ; block-start
4862 (current-indentation))))
4863 (current-column)))
4865 ;; Indenter for the first line in a block
4867 ((eq 'code-start-in-block (elt i 0))
4868 ;;[code-start-in-block before-brace char-after
4869 ;; is-a-HASH-ref brace-is-first-thing-on-a-line
4870 ;; group-starts-before-start-of-sub start-of-control-group]
4871 (goto-char (elt i 1))
4872 ;; For open brace in column zero, don't let statement
4873 ;; start there too. If cperl-indent-level=0,
4874 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
4875 (+ (if (and (bolp) (zerop cperl-indent-level))
4876 (+ cperl-brace-offset cperl-continued-statement-offset)
4877 cperl-indent-level)
4878 (if (and (elt i 3) ; is-a-HASH-ref
4879 (eq (elt i 2) ?\})) ; char-after: End of a hash reference
4880 (+ cperl-indent-level cperl-close-paren-offset)
4882 ;; Unless openbrace is the first nonwhite thing on the line,
4883 ;; add the cperl-brace-imaginary-offset.
4884 (if (elt i 4) 0 ; brace-is-first-thing-on-a-line
4885 cperl-brace-imaginary-offset)
4886 (progn
4887 (goto-char (elt i 6)) ; start-of-control-group
4888 (if (elt i 5) ; group-starts-before-start-of-sub
4889 (current-column)
4890 ;; Get initial indentation of the line we are on.
4891 ;; If line starts with label, calculate label indentation
4892 (if (save-excursion
4893 (beginning-of-line)
4894 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
4895 (if (> (current-indentation) cperl-min-label-indent)
4896 (- (current-indentation) cperl-label-offset)
4897 ;; Do not move `parse-data', this should
4898 ;; be quick anyway:
4899 (cperl-calculate-indent))
4900 (current-indentation))))))
4902 (error "Unrecognized value of indent: " i))))
4904 (error (format "Got strange value of indent: " i)))))))
4906 (defun cperl-calculate-indent-within-comment ()
4907 "Return the indentation amount for line, assuming that
4908 the current line is to be regarded as part of a block comment."
4909 (let (end star-start)
4910 (save-excursion
4911 (beginning-of-line)
4912 (skip-chars-forward " \t")
4913 (setq end (point))
4914 (and (= (following-char) ?#)
4915 (forward-line -1)
4916 (cperl-to-comment-or-eol)
4917 (setq end (point)))
4918 (goto-char end)
4919 (current-column))))
4922 (defun cperl-to-comment-or-eol ()
4923 "Go to position before comment on the current line, or to end of line.
4924 Returns true if comment is found. In POD will not move the point."
4925 ;; If the line is inside other syntax groups (qq-style strings, HERE-docs)
4926 ;; then looks for literal # or end-of-line.
4927 (let (state stop-in cpoint (lim (progn (end-of-line) (point))) pr e)
4928 (or cperl-font-locking
4929 (cperl-update-syntaxification lim lim))
4930 (beginning-of-line)
4931 (if (setq pr (get-text-property (point) 'syntax-type))
4932 (setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
4933 (if (or (eq pr 'pod)
4934 (if (or (not e) (> e lim)) ; deep inside a group
4935 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)))
4936 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
4937 ;; Else - need to do it the hard way
4938 (and (and e (<= e lim))
4939 (goto-char e))
4940 (while (not stop-in)
4941 (setq state (parse-partial-sexp (point) lim nil nil nil t))
4942 ; stop at comment
4943 ;; If fails (beginning-of-line inside sexp), then contains not-comment
4944 (if (nth 4 state) ; After `#';
4945 ; (nth 2 state) can be
4946 ; beginning of m,s,qq and so
4947 ; on
4948 (if (nth 2 state)
4949 (progn
4950 (setq cpoint (point))
4951 (goto-char (nth 2 state))
4952 (cond
4953 ((looking-at "\\(s\\|tr\\)\\>")
4954 (or (re-search-forward
4955 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
4956 lim 'move)
4957 (setq stop-in t)))
4958 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
4959 (or (re-search-forward
4960 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
4961 lim 'move)
4962 (setq stop-in t)))
4963 (t ; It was fair comment
4964 (setq stop-in t) ; Finish
4965 (goto-char (1- cpoint)))))
4966 (setq stop-in t) ; Finish
4967 (forward-char -1))
4968 (setq stop-in t))) ; Finish
4969 (nth 4 state))))
4971 (defsubst cperl-modify-syntax-type (at how)
4972 (if (< at (point-max))
4973 (progn
4974 (put-text-property at (1+ at) 'syntax-table how)
4975 (put-text-property at (1+ at) 'rear-nonsticky '(syntax-table)))))
4977 (defun cperl-protect-defun-start (s e)
4978 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
4979 (save-excursion
4980 (goto-char s)
4981 (while (re-search-forward "^\\s(" e 'to-end)
4982 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
4984 (defun cperl-commentify (bb e string &optional noface)
4985 (if cperl-use-syntax-table-text-property
4986 (if (eq noface 'n) ; Only immediate
4988 ;; We suppose that e is _after_ the end of construction, as after eol.
4989 (setq string (if string cperl-st-sfence cperl-st-cfence))
4990 (if (> bb (- e 2))
4991 ;; one-char string/comment?!
4992 (cperl-modify-syntax-type bb cperl-st-punct)
4993 (cperl-modify-syntax-type bb string)
4994 (cperl-modify-syntax-type (1- e) string))
4995 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
4996 (put-text-property (1+ bb) (1- e)
4997 'syntax-table cperl-string-syntax-table))
4998 (cperl-protect-defun-start bb e))
4999 ;; Fontify
5000 (or noface
5001 (not cperl-pod-here-fontify)
5002 (put-text-property bb e 'face (if string 'font-lock-string-face
5003 'font-lock-comment-face)))))
5005 (defvar cperl-starters '(( ?\( . ?\) )
5006 ( ?\[ . ?\] )
5007 ( ?\{ . ?\} )
5008 ( ?\< . ?\> )))
5010 (defun cperl-cached-syntax-table (st)
5011 "Get a syntax table cached in ST, or create and cache into ST a syntax table.
5012 All the entries of the syntax table are \".\", except for a backslash, which
5013 is quoting."
5014 (if (car-safe st)
5015 (car st)
5016 (setcar st (make-syntax-table))
5017 (setq st (car st))
5018 (let ((i 0))
5019 (while (< i 256)
5020 (modify-syntax-entry i "." st)
5021 (setq i (1+ i))))
5022 (modify-syntax-entry ?\\ "\\" st)
5023 st))
5025 (defun cperl-forward-re (lim end is-2arg st-l err-l argument
5026 &optional ostart oend)
5027 "Find the end of a regular expression or a stringish construct (q[] etc).
5028 The point should be before the starting delimiter.
5030 Goes to LIM if none is found. If IS-2ARG is non-nil, assumes that it
5031 is s/// or tr/// like expression. If END is nil, generates an error
5032 message if needed. If SET-ST is non-nil, will use (or generate) a
5033 cached syntax table in ST-L. If ERR-L is non-nil, will store the
5034 error message in its CAR (unless it already contains some error
5035 message). ARGUMENT should be the name of the construct (used in error
5036 messages). OSTART, OEND may be set in recursive calls when processing
5037 the second argument of 2ARG construct.
5039 Works *before* syntax recognition is done. In IS-2ARG situation may
5040 modify syntax-type text property if the situation is too hard."
5041 (let (b starter ender st i i2 go-forward reset-st set-st)
5042 (skip-chars-forward " \t")
5043 ;; ender means matching-char matcher.
5044 (setq b (point)
5045 starter (if (eobp) 0 (char-after b))
5046 ender (cdr (assoc starter cperl-starters)))
5047 ;; What if starter == ?\\ ????
5048 (setq st (cperl-cached-syntax-table st-l))
5049 (setq set-st t)
5050 ;; Whether we have an intermediate point
5051 (setq i nil)
5052 ;; Prepare the syntax table:
5053 (if (not ender) ; m/blah/, s/x//, s/x/y/
5054 (modify-syntax-entry starter "$" st)
5055 (modify-syntax-entry starter (concat "(" (list ender)) st)
5056 (modify-syntax-entry ender (concat ")" (list starter)) st))
5057 (condition-case bb
5058 (progn
5059 ;; We use `$' syntax class to find matching stuff, but $$
5060 ;; is recognized the same as $, so we need to check this manually.
5061 (if (and (eq starter (char-after (cperl-1+ b)))
5062 (not ender))
5063 ;; $ has TeXish matching rules, so $$ equiv $...
5064 (forward-char 2)
5065 (setq reset-st (syntax-table))
5066 (set-syntax-table st)
5067 (forward-sexp 1)
5068 (if (<= (point) (1+ b))
5069 (error "Unfinished regular expression"))
5070 (set-syntax-table reset-st)
5071 (setq reset-st nil)
5072 ;; Now the problem is with m;blah;;
5073 (and (not ender)
5074 (eq (preceding-char)
5075 (char-after (- (point) 2)))
5076 (save-excursion
5077 (forward-char -2)
5078 (= 0 (% (skip-chars-backward "\\\\") 2)))
5079 (forward-char -1)))
5080 ;; Now we are after the first part.
5081 (and is-2arg ; Have trailing part
5082 (not ender)
5083 (eq (following-char) starter) ; Empty trailing part
5084 (progn
5085 (or (eq (char-syntax (following-char)) ?.)
5086 ;; Make trailing letter into punctuation
5087 (cperl-modify-syntax-type (point) cperl-st-punct))
5088 (setq is-2arg nil go-forward t))) ; Ignore the tail
5089 (if is-2arg ; Not number => have second part
5090 (progn
5091 (setq i (point) i2 i)
5092 (if ender
5093 (if (memq (following-char) '(?\ ?\t ?\n ?\f))
5094 (progn
5095 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5096 (goto-char (match-end 0))
5097 (skip-chars-forward " \t\n\f"))
5098 (setq i2 (point))))
5099 (forward-char -1))
5100 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
5101 (if ender (modify-syntax-entry ender "." st))
5102 (setq set-st nil)
5103 (setq ender (cperl-forward-re lim end nil st-l err-l
5104 argument starter ender)
5105 ender (nth 2 ender)))))
5106 (error (goto-char lim)
5107 (setq set-st nil)
5108 (if reset-st
5109 (set-syntax-table reset-st))
5110 (or end
5111 (and
5112 cperl-brace-recursing
5113 (or (eq ostart ?\{)
5114 (eq starter ?\{)))
5115 (message
5116 "End of `%s%s%c ... %c' string/RE not found: %s"
5117 argument
5118 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
5119 starter (or ender starter) bb)
5120 (or (car err-l) (setcar err-l b)))))
5121 (if set-st
5122 (progn
5123 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
5124 (if ender (modify-syntax-entry ender "." st))))
5125 ;; i: have 2 args, after end of the first arg
5126 ;; i2: start of the second arg, if any (before delim iff `ender').
5127 ;; ender: the last arg bounded by parens-like chars, the second one of them
5128 ;; starter: the starting delimiter of the first arg
5129 ;; go-forward: has 2 args, and the second part is empty
5130 (list i i2 ender starter go-forward)))
5132 (defun cperl-forward-group-in-re (&optional st-l)
5133 "Find the end of a group in a REx.
5134 Return the error message (if any). Does not work if delimiter is `)'.
5135 Works before syntax recognition is done."
5136 ;; Works *before* syntax recognition is done
5137 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
5138 (let (st b reset-st)
5139 (condition-case b
5140 (progn
5141 (setq st (cperl-cached-syntax-table st-l))
5142 (modify-syntax-entry ?\( "()" st)
5143 (modify-syntax-entry ?\) ")(" st)
5144 (setq reset-st (syntax-table))
5145 (set-syntax-table st)
5146 (forward-sexp 1))
5147 (error (message
5148 "cperl-forward-group-in-re: error %s" b)))
5149 ;; now restore the initial state
5150 (if st
5151 (progn
5152 (modify-syntax-entry ?\( "." st)
5153 (modify-syntax-entry ?\) "." st)))
5154 (if reset-st
5155 (set-syntax-table reset-st))
5159 (defvar font-lock-string-face)
5160 ;;(defvar font-lock-reference-face)
5161 (defvar font-lock-constant-face)
5162 (defsubst cperl-postpone-fontification (b e type val &optional now)
5163 ;; Do after syntactic fontification?
5164 (if cperl-syntaxify-by-font-lock
5165 (or now (put-text-property b e 'cperl-postpone (cons type val)))
5166 (put-text-property b e type val)))
5168 ;;; Here is how the global structures (those which cannot be
5169 ;;; recognized locally) are marked:
5170 ;; a) PODs:
5171 ;; Start-to-end is marked `in-pod' ==> t
5172 ;; Each non-literal part is marked `syntax-type' ==> `pod'
5173 ;; Each literal part is marked `syntax-type' ==> `in-pod'
5174 ;; b) HEREs:
5175 ;; Start-to-end is marked `here-doc-group' ==> t
5176 ;; The body is marked `syntax-type' ==> `here-doc'
5177 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
5178 ;; c) FORMATs:
5179 ;; First line (to =) marked `first-format-line' ==> t
5180 ;; After-this--to-end is marked `syntax-type' ==> `format'
5181 ;; d) 'Q'uoted string:
5182 ;; part between markers inclusive is marked `syntax-type' ==> `string'
5183 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
5184 ;; second part of s///e is marked `syntax-type' ==> `multiline'
5185 ;; e) Attributes of subroutines: `attrib-group' ==> t
5186 ;; (or 0 if declaration); up to `{' or ';': `syntax-type' => `sub-decl'.
5187 ;; f) Multiline my/our declaration lists etc: `syntax-type' => `multiline'
5189 ;;; In addition, some parts of RExes may be marked as `REx-interpolated'
5190 ;;; (value: 0 in //o, 1 if "interpolated variable" is whole-REx, t otherwise).
5192 (defun cperl-unwind-to-safe (before &optional end)
5193 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
5194 (let ((pos (point)) opos)
5195 (while (and pos (progn
5196 (beginning-of-line)
5197 (get-text-property (setq pos (point)) 'syntax-type)))
5198 (setq opos pos
5199 pos (cperl-beginning-of-property pos 'syntax-type))
5200 (if (eq pos (point-min))
5201 (setq pos nil))
5202 (if pos
5203 (if before
5204 (progn
5205 (goto-char (cperl-1- pos))
5206 (beginning-of-line)
5207 (setq pos (point)))
5208 (goto-char (setq pos (cperl-1- pos))))
5209 ;; Up to the start
5210 (goto-char (point-min))))
5211 ;; Skip empty lines
5212 (and (looking-at "\n*=")
5213 (/= 0 (skip-chars-backward "\n"))
5214 (forward-char))
5215 (setq pos (point))
5216 (if end
5217 ;; Do the same for end, going small steps
5218 (save-excursion
5219 (while (and end (get-text-property end 'syntax-type))
5220 (setq pos end
5221 end (next-single-property-change end 'syntax-type nil (point-max)))
5222 (if end (progn (goto-char end)
5223 (or (bolp) (forward-line 1))
5224 (setq end (point)))))
5225 (or end pos)))))
5227 ;;; These are needed for byte-compile (at least with v19)
5228 (defvar cperl-nonoverridable-face)
5229 (defvar font-lock-variable-name-face)
5230 (defvar font-lock-function-name-face)
5231 (defvar font-lock-keyword-face)
5232 (defvar font-lock-builtin-face)
5233 (defvar font-lock-type-face)
5234 (defvar font-lock-comment-face)
5235 (defvar font-lock-warning-face)
5237 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
5238 "Syntaxically mark (and fontify) attributes of a subroutine.
5239 Should be called with the point before leading colon of an attribute."
5240 ;; Works *before* syntax recognition is done
5241 (or st-l (setq st-l (list nil))) ; Avoid overwriting '()
5242 (let (st b p reset-st after-first (start (point)) start1 end1)
5243 (condition-case b
5244 (while (looking-at
5245 (concat
5246 "\\(" ; 1=optional? colon
5247 ":" cperl-maybe-white-and-comment-rex ; 2=whitespace/comment?
5248 "\\)"
5249 (if after-first "?" "")
5250 ;; No space between name and paren allowed...
5251 "\\(\\sw+\\)" ; 3=name
5252 "\\((\\)?")) ; 4=optional paren
5253 (and (match-beginning 1)
5254 (cperl-postpone-fontification
5255 (match-beginning 0) (cperl-1+ (match-beginning 0))
5256 'face font-lock-constant-face))
5257 (setq start1 (match-beginning 3) end1 (match-end 3))
5258 (cperl-postpone-fontification start1 end1
5259 'face font-lock-constant-face)
5260 (goto-char end1) ; end or before `('
5261 (if (match-end 4) ; Have attribute arguments...
5262 (progn
5263 (if st nil
5264 (setq st (cperl-cached-syntax-table st-l))
5265 (modify-syntax-entry ?\( "()" st)
5266 (modify-syntax-entry ?\) ")(" st))
5267 (setq reset-st (syntax-table) p (point))
5268 (set-syntax-table st)
5269 (forward-sexp 1)
5270 (set-syntax-table reset-st)
5271 (setq reset-st nil)
5272 (cperl-commentify p (point) t))) ; mark as string
5273 (forward-comment (buffer-size))
5274 (setq after-first t))
5275 (error (message
5276 "L%d: attribute `%s': %s"
5277 (count-lines (point-min) (point))
5278 (and start1 end1 (buffer-substring start1 end1)) b)
5279 (setq start nil)))
5280 (and start
5281 (progn
5282 (put-text-property start (point)
5283 'attrib-group (if (looking-at "{") t 0))
5284 (and pos
5285 (< 1 (count-lines (+ 3 pos) (point))) ; end of `sub'
5286 ;; Apparently, we do not need `multiline': faces added now
5287 (put-text-property (+ 3 pos) (cperl-1+ (point))
5288 'syntax-type 'sub-decl))
5289 (and b-fname ; Fontify here: the following condition
5290 (cperl-postpone-fontification ; is too hard to determine by
5291 b-fname e-fname 'face ; a REx, so do it here
5292 (if (looking-at "{")
5293 font-lock-function-name-face
5294 font-lock-variable-name-face)))))
5295 ;; now restore the initial state
5296 (if st
5297 (progn
5298 (modify-syntax-entry ?\( "." st)
5299 (modify-syntax-entry ?\) "." st)))
5300 (if reset-st
5301 (set-syntax-table reset-st))))
5303 (defsubst cperl-look-at-leading-count (is-x-REx e)
5304 (if (and
5305 (< (point) e)
5306 (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
5307 (1- e) t)) ; return nil on failure, no moving
5308 (if (eq ?\{ (preceding-char)) nil
5309 (cperl-postpone-fontification
5310 (1- (point)) (point)
5311 'face font-lock-warning-face))))
5313 ;; Do some smarter-highlighting
5314 ;; XXXX Currently ignores alphanum/dash delims,
5315 (defsubst cperl-highlight-charclass (endbracket dashface bsface onec-space)
5316 (let ((l '(1 5 7)) ll lle lll
5317 ;; 2 groups, the first takes the whole match (include \[trnfabe])
5318 (singleChar (concat "\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)")))
5319 (while ; look for unescaped - between non-classes
5320 (re-search-forward
5321 ;; On 19.33, certain simplifications lead
5322 ;; to bugs (as in [^a-z] \\| [trnfabe] )
5323 (concat ; 1: SingleChar (include \[trnfabe])
5324 singleChar
5325 ;;"\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)"
5326 "\\(" ; 3: DASH SingleChar (match optionally)
5327 "\\(-\\)" ; 4: DASH
5328 singleChar ; 5: SingleChar
5329 ;;"\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)"
5330 "\\)?"
5331 "\\|"
5332 "\\(" ; 7: other escapes
5333 "\\\\[pP]" "\\([^{]\\|{[^{}]*}\\)"
5334 "\\|" "\\\\[^pP]" "\\)"
5336 endbracket 'toend)
5337 (if (match-beginning 4)
5338 (cperl-postpone-fontification
5339 (match-beginning 4) (match-end 4)
5340 'face dashface))
5341 ;; save match data (for looking-at)
5342 (setq lll (mapcar (function (lambda (elt) (cons (match-beginning elt)
5343 (match-end elt)))) l))
5344 (while lll
5345 (setq ll (car lll))
5346 (setq lle (cdr ll)
5347 ll (car ll))
5348 ;; (message "Got %s of %s" ll l)
5349 (if (and ll (eq (char-after ll) ?\\ ))
5350 (save-excursion
5351 (goto-char ll)
5352 (cperl-postpone-fontification ll (1+ ll)
5353 'face bsface)
5354 (if (looking-at "\\\\[a-zA-Z0-9]")
5355 (cperl-postpone-fontification (1+ ll) lle
5356 'face onec-space))))
5357 (setq lll (cdr lll))))
5358 (goto-char endbracket) ; just in case something misbehaves???
5361 ;;; Debugging this may require (setq max-specpdl-size 2000)...
5362 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc)
5363 "Scans the buffer for hard-to-parse Perl constructions.
5364 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
5365 the sections using `cperl-pod-head-face', `cperl-pod-face',
5366 `cperl-here-face'."
5367 (interactive)
5368 (or min (setq min (point-min)
5369 cperl-syntax-state nil
5370 cperl-syntax-done-to min))
5371 (or max (setq max (point-max)))
5372 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
5373 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
5374 is-REx is-x-REx REx-subgr-start REx-subgr-end was-subgr i2 hairy-RE
5375 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
5376 (modified (buffer-modified-p)) overshoot is-o-REx
5377 (after-change-functions nil)
5378 (cperl-font-locking t)
5379 (use-syntax-state (and cperl-syntax-state
5380 (>= min (car cperl-syntax-state))))
5381 (state-point (if use-syntax-state
5382 (car cperl-syntax-state)
5383 (point-min)))
5384 (state (if use-syntax-state
5385 (cdr cperl-syntax-state)))
5386 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
5387 (st-l (list nil)) (err-l (list nil))
5388 ;; Somehow font-lock may be not loaded yet...
5389 ;; (e.g., when building TAGS via command-line call)
5390 (font-lock-string-face (if (boundp 'font-lock-string-face)
5391 font-lock-string-face
5392 'font-lock-string-face))
5393 (my-cperl-delimiters-face (if (boundp 'font-lock-constant-face)
5394 font-lock-constant-face
5395 'font-lock-constant-face))
5396 (my-cperl-REx-spec-char-face ; [] ^.$ and wrapper-of ({})
5397 (if (boundp 'font-lock-function-name-face)
5398 font-lock-function-name-face
5399 'font-lock-function-name-face))
5400 (font-lock-variable-name-face ; interpolated vars and ({})-code
5401 (if (boundp 'font-lock-variable-name-face)
5402 font-lock-variable-name-face
5403 'font-lock-variable-name-face))
5404 (font-lock-function-name-face ; used in `cperl-find-sub-attrs'
5405 (if (boundp 'font-lock-function-name-face)
5406 font-lock-function-name-face
5407 'font-lock-function-name-face))
5408 (font-lock-constant-face ; used in `cperl-find-sub-attrs'
5409 (if (boundp 'font-lock-constant-face)
5410 font-lock-constant-face
5411 'font-lock-constant-face))
5412 (my-cperl-REx-0length-face ; 0-length, (?:)etc, non-literal \
5413 (if (boundp 'font-lock-builtin-face)
5414 font-lock-builtin-face
5415 'font-lock-builtin-face))
5416 (font-lock-comment-face
5417 (if (boundp 'font-lock-comment-face)
5418 font-lock-comment-face
5419 'font-lock-comment-face))
5420 (font-lock-warning-face
5421 (if (boundp 'font-lock-warning-face)
5422 font-lock-warning-face
5423 'font-lock-warning-face))
5424 (my-cperl-REx-ctl-face ; (|)
5425 (if (boundp 'font-lock-keyword-face)
5426 font-lock-keyword-face
5427 'font-lock-keyword-face))
5428 (my-cperl-REx-modifiers-face ; //gims
5429 (if (boundp 'cperl-nonoverridable-face)
5430 cperl-nonoverridable-face
5431 'cperl-nonoverridable-face))
5432 (my-cperl-REx-length1-face ; length=1 escaped chars, POSIX classes
5433 (if (boundp 'font-lock-type-face)
5434 font-lock-type-face
5435 'font-lock-type-face))
5436 (stop-point (if ignore-max
5437 (point-max)
5438 max))
5439 (search
5440 (concat
5441 "\\(\\`\n?\\|^\n\\)=" ; POD
5442 "\\|"
5443 ;; One extra () before this:
5444 "<<" ; HERE-DOC
5445 "\\(" ; 1 + 1
5446 ;; First variant "BLAH" or just ``.
5447 "[ \t]*" ; Yes, whitespace is allowed!
5448 "\\([\"'`]\\)" ; 2 + 1 = 3
5449 "\\([^\"'`\n]*\\)" ; 3 + 1
5450 "\\3"
5451 "\\|"
5452 ;; Second variant: Identifier or \ID (same as 'ID') or empty
5453 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
5454 ;; Do not have <<= or << 30 or <<30 or << $blah.
5455 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
5456 "\\(\\)" ; To preserve count of pars :-( 6 + 1
5457 "\\)"
5458 "\\|"
5459 ;; 1+6 extra () before this:
5460 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" ;FRMAT
5461 (if cperl-use-syntax-table-text-property
5462 (concat
5463 "\\|"
5464 ;; 1+6+2=9 extra () before this:
5465 (if (not cperl-use-v6) ; perl6
5466 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>" ; QUOTED CONSTRUCT - Perl5
5467 ;;"\\<\\(q[wxq]?\\)\\>" ; QUOTED CONSTRUCT - Perl6
5468 "\\<\\(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
5470 "\\|"
5471 ;; 1+6+2+1=10 extra () before this:
5472 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
5473 "\\|"
5474 ;; 1+6+2+1+1=11 extra () before this
5475 "\\<sub\\>" ; sub with proto/attr
5476 "\\("
5477 cperl-white-and-comment-rex
5478 "\\(::[a-zA-Z_:'0-9]*\\|[a-zA-Z_'][a-zA-Z_:'0-9]*\\)\\)?" ; name
5479 "\\("
5480 cperl-maybe-white-and-comment-rex
5481 "\\(([^()]*)\\|:[^:]\\)\\)" ; prototype or attribute start
5482 "\\|"
5483 ;; 1+6+2+1+1+6=17 extra () before this:
5484 "\\$\\(['{]\\)" ; $' or ${foo}
5485 "\\|"
5486 ;; 1+6+2+1+1+6+1=18 extra () before this (old pack'var syntax;
5487 ;; we do not support intervening comments...):
5488 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
5489 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
5490 "\\|"
5491 "__\\(END\\|DATA\\)__" ; __END__ or __DATA__
5492 ;; 1+6+2+1+1+6+1+1+1=20 extra () before this:
5493 "\\|"
5494 "\\\\\\(['`\"($]\\)" ; BACKWACKED something-hairy
5495 ;; 1+6+2+1+1+6+1+1+1+1=21 extra () before this: ; perl6
5496 ;; "\\|"
5497 ;; "\\<\\(\\(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
5498 ;; 1+6+2+1+1+6+1+1+1+1+7=28 extra () before this: ; perl6
5499 ""))))
5500 (unwind-protect
5501 (progn
5502 (save-excursion
5503 (or non-inter
5504 (message "Scanning for \"hard\" Perl constructions..."))
5505 ;;(message "find: %s --> %s" min max)
5506 (and cperl-pod-here-fontify
5507 ;; We had evals here, do not know why...
5508 (setq face cperl-pod-face
5509 head-face cperl-pod-head-face
5510 here-face cperl-here-face))
5511 (remove-text-properties min max
5512 '(syntax-type t in-pod t syntax-table t
5513 attrib-group t
5514 REx-interpolated t
5515 cperl-postpone t
5516 syntax-subtype t
5517 rear-nonsticky t
5518 front-sticky t
5519 here-doc-group t
5520 first-format-line t
5521 REx-part2 t
5522 indentable t))
5523 ;; Need to remove face as well...
5524 (goto-char min)
5525 (and (eq system-type 'emx)
5526 (eq (point) 1)
5527 (let ((case-fold-search t))
5528 (looking-at "extproc[ \t]")) ; Analogue of #!
5529 (cperl-commentify min
5530 (save-excursion (end-of-line) (point))
5531 nil))
5532 (while (and
5533 (< (point) max)
5534 (re-search-forward search max t))
5535 (setq tmpend nil) ; Valid for most cases
5536 (setq b (match-beginning 0)
5537 state (save-excursion (parse-partial-sexp
5538 state-point b nil nil state))
5539 state-point b)
5540 (cond
5541 ;; 1+6+2+1+1+6=17 extra () before this:
5542 ;; "\\$\\(['{]\\)"
5543 ((match-beginning 18) ; $' or ${foo}
5544 (if (eq (preceding-char) ?\') ; $'
5545 (progn
5546 (setq b (1- (point))
5547 state (parse-partial-sexp
5548 state-point (1- b) nil nil state)
5549 state-point (1- b))
5550 (if (nth 3 state) ; in string
5551 (cperl-modify-syntax-type (1- b) cperl-st-punct))
5552 (goto-char (1+ b)))
5553 ;; else: ${
5554 (setq bb (match-beginning 0))
5555 (cperl-modify-syntax-type bb cperl-st-punct)))
5556 ;; No processing in strings/comments beyond this point:
5557 ((or (nth 3 state) (nth 4 state))
5558 t) ; Do nothing in comment/string
5559 ((match-beginning 1) ; POD section
5560 ;; "\\(\\`\n?\\|^\n\\)="
5561 (setq b (match-beginning 0)
5562 state (parse-partial-sexp
5563 state-point b nil nil state)
5564 state-point b)
5565 (if (or (nth 3 state) (nth 4 state)
5566 (looking-at "cut\\>"))
5567 (if (or (nth 3 state) (nth 4 state) ignore-max)
5568 nil ; Doing a chunk only
5569 (message "=cut is not preceded by a POD section")
5570 (or (car err-l) (setcar err-l (point))))
5571 (beginning-of-line)
5573 (setq b (point)
5574 bb b
5575 tb (match-beginning 0)
5576 b1 nil) ; error condition
5577 ;; We do not search to max, since we may be called from
5578 ;; some hook of fontification, and max is random
5579 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
5580 (progn
5581 (goto-char b)
5582 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
5583 (progn
5584 (message "=cut is not preceded by an empty line")
5585 (setq b1 t)
5586 (or (car err-l) (setcar err-l b))))))
5587 (beginning-of-line 2) ; An empty line after =cut is not POD!
5588 (setq e (point))
5589 (and (> e max)
5590 (progn
5591 (remove-text-properties
5592 max e '(syntax-type t in-pod t syntax-table t
5593 attrib-group t
5594 REx-interpolated t
5595 cperl-postpone t
5596 syntax-subtype t
5597 here-doc-group t
5598 rear-nonsticky t
5599 front-sticky t
5600 first-format-line t
5601 REx-part2 t
5602 indentable t))
5603 (setq tmpend tb)))
5604 (put-text-property b e 'in-pod t)
5605 (put-text-property b e 'syntax-type 'in-pod)
5606 (goto-char b)
5607 (while (re-search-forward "\n\n[ \t]" e t)
5608 ;; We start 'pod 1 char earlier to include the preceding line
5609 (beginning-of-line)
5610 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
5611 (cperl-put-do-not-fontify b (point) t)
5612 ;; mark the non-literal parts as PODs
5613 (if cperl-pod-here-fontify
5614 (cperl-postpone-fontification b (point) 'face face t))
5615 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
5616 (beginning-of-line)
5617 (setq b (point)))
5618 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
5619 (cperl-put-do-not-fontify (point) e t)
5620 (if cperl-pod-here-fontify
5621 (progn
5622 ;; mark the non-literal parts as PODs
5623 (cperl-postpone-fontification (point) e 'face face t)
5624 (goto-char bb)
5625 (if (looking-at
5626 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
5627 ;; mark the headers
5628 (cperl-postpone-fontification
5629 (match-beginning 1) (match-end 1)
5630 'face head-face))
5631 (while (re-search-forward
5632 ;; One paragraph
5633 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
5634 e 'toend)
5635 ;; mark the headers
5636 (cperl-postpone-fontification
5637 (match-beginning 1) (match-end 1)
5638 'face head-face))))
5639 (cperl-commentify bb e nil)
5640 (goto-char e)
5641 (or (eq e (point-max))
5642 (forward-char -1)))) ; Prepare for immediate POD start.
5643 ;; Here document
5644 ;; We can do many here-per-line;
5645 ;; but multiline quote on the same line as <<HERE confuses us...
5646 ;; ;; One extra () before this:
5647 ;;"<<"
5648 ;; "\\(" ; 1 + 1
5649 ;; ;; First variant "BLAH" or just ``.
5650 ;; "[ \t]*" ; Yes, whitespace is allowed!
5651 ;; "\\([\"'`]\\)" ; 2 + 1
5652 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
5653 ;; "\\3"
5654 ;; "\\|"
5655 ;; ;; Second variant: Identifier or \ID or empty
5656 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
5657 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
5658 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
5659 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
5660 ;; "\\)"
5661 ((match-beginning 2) ; 1 + 1
5662 (setq b (point)
5663 tb (match-beginning 0)
5664 c (and ; not HERE-DOC
5665 (match-beginning 5)
5666 (save-match-data
5667 (or (looking-at "[ \t]*(") ; << function_call()
5668 (save-excursion ; 1 << func_name, or $foo << 10
5669 (condition-case nil
5670 (progn
5671 (goto-char tb)
5672 ;;; XXX What to do: foo <<bar ???
5673 ;;; XXX Need to support print {a} <<B ???
5674 (forward-sexp -1)
5675 (save-match-data
5676 ; $foo << b; $f .= <<B;
5677 ; ($f+1) << b; a($f) . <<B;
5678 ; foo 1, <<B; $x{a} <<b;
5679 (cond
5680 ((looking-at "[0-9$({]")
5681 (forward-sexp 1)
5682 (and
5683 (looking-at "[ \t]*<<")
5684 (condition-case nil
5685 ;; print $foo <<EOF
5686 (progn
5687 (forward-sexp -2)
5688 (not
5689 (looking-at "\\(printf?\\|system\\|exec\\|sort\\)\\>")))
5690 (error t)))))))
5691 (error nil))) ; func(<<EOF)
5692 (and (not (match-beginning 6)) ; Empty
5693 (looking-at
5694 "[ \t]*[=0-9$@%&(]"))))))
5695 (if c ; Not here-doc
5696 nil ; Skip it.
5697 (setq c (match-end 2)) ; 1 + 1
5698 (if (match-beginning 5) ;4 + 1
5699 (setq b1 (match-beginning 5) ; 4 + 1
5700 e1 (match-end 5)) ; 4 + 1
5701 (setq b1 (match-beginning 4) ; 3 + 1
5702 e1 (match-end 4))) ; 3 + 1
5703 (setq tag (buffer-substring b1 e1)
5704 qtag (regexp-quote tag))
5705 (cond (cperl-pod-here-fontify
5706 ;; Highlight the starting delimiter
5707 (cperl-postpone-fontification
5708 b1 e1 'face my-cperl-delimiters-face)
5709 (cperl-put-do-not-fontify b1 e1 t)))
5710 (forward-line)
5711 (setq i (point))
5712 (if end-of-here-doc
5713 (goto-char end-of-here-doc))
5714 (setq b (point))
5715 ;; We do not search to max, since we may be called from
5716 ;; some hook of fontification, and max is random
5717 (or (and (re-search-forward (concat "^" qtag "$")
5718 stop-point 'toend)
5719 ;;;(eq (following-char) ?\n) ; XXXX WHY???
5721 (progn ; Pretend we matched at the end
5722 (goto-char (point-max))
5723 (re-search-forward "\\'")
5724 (message "End of here-document `%s' not found." tag)
5725 (or (car err-l) (setcar err-l b))))
5726 (if cperl-pod-here-fontify
5727 (progn
5728 ;; Highlight the ending delimiter
5729 (cperl-postpone-fontification
5730 (match-beginning 0) (match-end 0)
5731 'face my-cperl-delimiters-face)
5732 (cperl-put-do-not-fontify b (match-end 0) t)
5733 ;; Highlight the HERE-DOC
5734 (cperl-postpone-fontification b (match-beginning 0)
5735 'face here-face)))
5736 (setq e1 (cperl-1+ (match-end 0)))
5737 (put-text-property b (match-beginning 0)
5738 'syntax-type 'here-doc)
5739 (put-text-property (match-beginning 0) e1
5740 'syntax-type 'here-doc-delim)
5741 (put-text-property b e1 'here-doc-group t)
5742 ;; This makes insertion at the start of HERE-DOC update
5743 ;; the whole construct:
5744 (put-text-property b (cperl-1+ b) 'front-sticky '(syntax-type))
5745 (cperl-commentify b e1 nil)
5746 (cperl-put-do-not-fontify b (match-end 0) t)
5747 ;; Cache the syntax info...
5748 (setq cperl-syntax-state (cons state-point state))
5749 ;; ... and process the rest of the line...
5750 (setq overshoot
5751 (elt ; non-inter ignore-max
5752 (cperl-find-pods-heres c i t end t e1) 1))
5753 (if (and overshoot (> overshoot (point)))
5754 (goto-char overshoot)
5755 (setq overshoot e1))
5756 (if (> e1 max)
5757 (setq tmpend tb))))
5758 ;; format
5759 ((match-beginning 8)
5760 ;; 1+6=7 extra () before this:
5761 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
5762 (setq b (point)
5763 name (if (match-beginning 8) ; 7 + 1
5764 (buffer-substring (match-beginning 8) ; 7 + 1
5765 (match-end 8)) ; 7 + 1
5767 tb (match-beginning 0))
5768 (setq argument nil)
5769 (put-text-property (save-excursion
5770 (beginning-of-line)
5771 (point))
5772 b 'first-format-line 't)
5773 (if cperl-pod-here-fontify
5774 (while (and (eq (forward-line) 0)
5775 (not (looking-at "^[.;]$")))
5776 (cond
5777 ((looking-at "^#")) ; Skip comments
5778 ((and argument ; Skip argument multi-lines
5779 (looking-at "^[ \t]*{"))
5780 (forward-sexp 1)
5781 (setq argument nil))
5782 (argument ; Skip argument lines
5783 (setq argument nil))
5784 (t ; Format line
5785 (setq b1 (point))
5786 (setq argument (looking-at "^[^\n]*[@^]"))
5787 (end-of-line)
5788 ;; Highlight the format line
5789 (cperl-postpone-fontification b1 (point)
5790 'face font-lock-string-face)
5791 (cperl-commentify b1 (point) nil)
5792 (cperl-put-do-not-fontify b1 (point) t))))
5793 ;; We do not search to max, since we may be called from
5794 ;; some hook of fontification, and max is random
5795 (re-search-forward "^[.;]$" stop-point 'toend))
5796 (beginning-of-line)
5797 (if (looking-at "^\\.$") ; ";" is not supported yet
5798 (progn
5799 ;; Highlight the ending delimiter
5800 (cperl-postpone-fontification (point) (+ (point) 2)
5801 'face font-lock-string-face)
5802 (cperl-commentify (point) (+ (point) 2) nil)
5803 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
5804 (message "End of format `%s' not found." name)
5805 (or (car err-l) (setcar err-l b)))
5806 (forward-line)
5807 (if (> (point) max)
5808 (setq tmpend tb))
5809 (put-text-property b (point) 'syntax-type 'format))
5810 ;; qq-like String or Regexp:
5811 ((or (match-beginning 10) (match-beginning 11))
5812 ;; 1+6+2=9 extra () before this:
5813 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
5814 ;; "\\|"
5815 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
5816 (setq b1 (if (match-beginning 10) 10 11)
5817 argument (buffer-substring
5818 (match-beginning b1) (match-end b1))
5819 b (point) ; end of qq etc
5821 c (char-after (match-beginning b1))
5822 bb (char-after (1- (match-beginning b1))) ; tmp holder
5823 ;; bb == "Not a stringy"
5824 bb (if (eq b1 10) ; user variables/whatever
5825 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
5826 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
5827 ((eq bb ?\:) ; $opt::s
5828 (eq (char-after
5829 (- (match-beginning b1) 2))
5830 ?\:))
5831 ((eq bb ?\>) ; $foo->s
5832 (eq (char-after
5833 (- (match-beginning b1) 2))
5834 ?\-))
5835 ((eq bb ?\&)
5836 (not (eq (char-after ; &&m/blah/
5837 (- (match-beginning b1) 2))
5838 ?\&)))
5839 (t t)))
5840 ;; <file> or <$file>
5841 (and (eq c ?\<)
5842 ;; Do not stringify <FH>, <$fh> :
5843 (save-match-data
5844 (looking-at
5845 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
5846 tb (match-beginning 0))
5847 (goto-char (match-beginning b1))
5848 (cperl-backward-to-noncomment (point-min))
5849 (or bb
5850 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
5851 (setq argument ""
5852 b1 nil
5853 bb ; Not a regexp?
5854 (not
5855 ;; What is below: regexp-p?
5856 (and
5857 (or (memq (preceding-char)
5858 (append (if (memq c '(?\? ?\<))
5859 ;; $a++ ? 1 : 2
5860 "~{(=|&*!,;:["
5861 "~{(=|&+-*!,;:[") nil))
5862 (and (eq (preceding-char) ?\})
5863 (cperl-after-block-p (point-min)))
5864 (and (eq (char-syntax (preceding-char)) ?w)
5865 (progn
5866 (forward-sexp -1)
5867 ;;; After these keywords `/' starts a RE. One should add all the
5868 ;;; functions/builtins which expect an argument, but ...
5869 (if (eq (preceding-char) ?-)
5870 ;; -d ?foo? is a RE
5871 (looking-at "[a-zA-Z]\\>")
5872 (and
5873 (not (memq (preceding-char)
5874 '(?$ ?@ ?& ?%)))
5875 (looking-at
5876 "\\(while\\|if\\|unless\\|when\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
5877 (and (eq (preceding-char) ?.)
5878 (eq (char-after (- (point) 2)) ?.))
5879 (bobp))
5880 ;; m|blah| ? foo : bar;
5881 (not
5882 (and (eq c ?\?)
5883 cperl-use-syntax-table-text-property
5884 (not (bobp))
5885 (progn
5886 (forward-char -1)
5887 (looking-at "\\s|"))))))
5888 b (1- b))
5889 ;; s y tr m
5890 ;; Check for $a -> y
5891 (setq b1 (preceding-char)
5892 go (point))
5893 (if (and (eq b1 ?>)
5894 (eq (char-after (- go 2)) ?-))
5895 ;; Not a regexp
5896 (setq bb t))))
5897 (or bb
5898 (progn
5899 (goto-char b)
5900 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5901 (goto-char (match-end 0))
5902 (skip-chars-forward " \t\n\f"))
5903 (cond ((and (eq (following-char) ?\})
5904 (eq b1 ?\{))
5905 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
5906 (goto-char (1- go))
5907 (skip-chars-backward " \t\n\f")
5908 (if (memq (preceding-char) (append "$@%&*" nil))
5909 (setq bb t) ; @{y}
5910 (condition-case nil
5911 (forward-sexp -1)
5912 (error nil)))
5913 (if (or bb
5914 (looking-at ; $foo -> {s}
5915 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
5916 (and ; $foo[12] -> {s}
5917 (memq (following-char) '(?\{ ?\[))
5918 (progn
5919 (forward-sexp 1)
5920 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
5921 (setq bb t)
5922 (goto-char b)))
5923 ((and (eq (following-char) ?=)
5924 (eq (char-after (1+ (point))) ?\>))
5925 ;; Check for { foo => 1, s => 2 }
5926 ;; Apparently s=> is never a substitution...
5927 (setq bb t))
5928 ((and (eq (following-char) ?:)
5929 (eq b1 ?\{) ; Check for $ { s::bar }
5930 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
5931 (progn
5932 (goto-char (1- go))
5933 (skip-chars-backward " \t\n\f")
5934 (memq (preceding-char)
5935 (append "$@%&*" nil))))
5936 (setq bb t))
5937 ((eobp)
5938 (setq bb t)))))
5939 (if bb
5940 (goto-char i)
5941 ;; Skip whitespace and comments...
5942 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
5943 (goto-char (match-end 0))
5944 (skip-chars-forward " \t\n\f"))
5945 (if (> (point) b)
5946 (put-text-property b (point) 'syntax-type 'prestring))
5947 ;; qtag means two-arg matcher, may be reset to
5948 ;; 2 or 3 later if some special quoting is needed.
5949 ;; e1 means matching-char matcher.
5950 (setq b (point) ; before the first delimiter
5951 ;; has 2 args
5952 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
5953 ;; We do not search to max, since we may be called from
5954 ;; some hook of fontification, and max is random
5955 i (cperl-forward-re stop-point end
5957 st-l err-l argument)
5958 ;; If `go', then it is considered as 1-arg, `b1' is nil
5959 ;; as in s/foo//x; the point is before final "slash"
5960 b1 (nth 1 i) ; start of the second part
5961 tag (nth 2 i) ; ender-char, true if second part
5962 ; is with matching chars []
5963 go (nth 4 i) ; There is a 1-char part after the end
5964 i (car i) ; intermediate point
5965 e1 (point) ; end
5966 ;; Before end of the second part if non-matching: ///
5967 tail (if (and i (not tag))
5968 (1- e1))
5969 e (if i i e1) ; end of the first part
5970 qtag nil ; need to preserve backslashitis
5971 is-x-REx nil is-o-REx nil); REx has //x //o modifiers
5972 ;; If s{} (), then b/b1 are at "{", "(", e1/i after ")", "}"
5973 ;; Commenting \\ is dangerous, what about ( ?
5974 (and i tail
5975 (eq (char-after i) ?\\)
5976 (setq qtag t))
5977 (and (if go (looking-at ".\\sw*x")
5978 (looking-at "\\sw*x")) ; qr//x
5979 (setq is-x-REx t))
5980 (and (if go (looking-at ".\\sw*o")
5981 (looking-at "\\sw*o")) ; //o
5982 (setq is-o-REx t))
5983 (if (null i)
5984 ;; Considered as 1arg form
5985 (progn
5986 (cperl-commentify b (point) t)
5987 (put-text-property b (point) 'syntax-type 'string)
5988 (if (or is-x-REx
5989 ;; ignore other text properties:
5990 (string-match "^qw$" argument))
5991 (put-text-property b (point) 'indentable t))
5992 (and go
5993 (setq e1 (cperl-1+ e1))
5994 (or (eobp)
5995 (forward-char 1))))
5996 (cperl-commentify b i t)
5997 (if (looking-at "\\sw*e") ; s///e
5998 (progn
5999 ;; Cache the syntax info...
6000 (setq cperl-syntax-state (cons state-point state))
6001 (and
6002 ;; silent:
6003 (car (cperl-find-pods-heres b1 (1- (point)) t end))
6004 ;; Error
6005 (goto-char (1+ max)))
6006 (if (and tag (eq (preceding-char) ?\>))
6007 (progn
6008 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
6009 (cperl-modify-syntax-type i cperl-st-bra)))
6010 (put-text-property b i 'syntax-type 'string)
6011 (put-text-property i (point) 'syntax-type 'multiline)
6012 (if is-x-REx
6013 (put-text-property b i 'indentable t)))
6014 (cperl-commentify b1 (point) t)
6015 (put-text-property b (point) 'syntax-type 'string)
6016 (if is-x-REx
6017 (put-text-property b i 'indentable t))
6018 (if qtag
6019 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
6020 (setq tail nil)))
6021 ;; Now: tail: if the second part is non-matching without ///e
6022 (if (eq (char-syntax (following-char)) ?w)
6023 (progn
6024 (forward-word 1) ; skip modifiers s///s
6025 (if tail (cperl-commentify tail (point) t))
6026 (cperl-postpone-fontification
6027 e1 (point) 'face my-cperl-REx-modifiers-face)))
6028 ;; Check whether it is m// which means "previous match"
6029 ;; and highlight differently
6030 (setq is-REx
6031 (and (string-match "^\\([sm]?\\|qr\\|rx\\)$" argument)
6032 (or (not (= (length argument) 0))
6033 (not (eq c ?\<)))))
6034 (if (and is-REx
6035 (eq e (+ 2 b))
6036 ;; split // *is* using zero-pattern
6037 (save-excursion
6038 (condition-case nil
6039 (progn
6040 (goto-char tb)
6041 (forward-sexp -1)
6042 (not (looking-at "split\\>")))
6043 (error t))))
6044 (cperl-postpone-fontification
6045 b e 'face font-lock-warning-face)
6046 (if (or i2 ; Has 2 args
6047 (and cperl-fontify-m-as-s
6049 ;; (string-match "^\\(m\\|qr\\)$" argument) ; perl6
6050 (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
6051 (and (eq 0 (length argument))
6052 (not (eq ?\< (char-after b)))))))
6053 (progn
6054 (cperl-postpone-fontification
6055 b (cperl-1+ b) 'face my-cperl-delimiters-face)
6056 (cperl-postpone-fontification
6057 (1- e) e 'face my-cperl-delimiters-face)))
6058 (if (and is-REx cperl-regexp-scan)
6059 ;; Process RExen: embedded comments, charclasses and ]
6060 ;;;/\3333\xFg\x{FFF}a\ppp\PPP\qqq\C\99f(?{ foo })(??{ foo })/;
6061 ;;;/a{4,5}\.b[^a[:ff:]b]x$ab->$[|$,$ab->[cd]->[ef]|$ab[xy].|^${a,b}{c,d}/;
6062 ;;;/(?<=foo)(?<!bar)(x")(?:$ab|\$\/)$|\\\b\x888\776\[\:$/xxx;
6063 ;;;m?(\?\?{b,a})? + m/(??{aa})(?(?=xx)aa|bb)(?#aac)/;
6064 ;;;m$(^ab[c]\$)$ + m+(^ab[c]\$\+)+ + m](^ab[c\]$|.+)] + m)(^ab[c]$|.+\));
6065 ;;;s{a}{};
6066 ;;;s/.a//;
6067 ;;;m^a[\^b-e\xFF]c^ + m.a[^b]\.c.; # OK
6068 ;;;m^a[\^-b-\e--[\--\xFF\c[\cX-\0333-\0555-\N{name}\pp--\P{prop}--\\\05555]^;
6069 ;;;m^a[[:alpha:]-[:alpha:]-a-[:alpha:][-aa-[[:alpha:]-b-[:alpha:]-[:alpha:]]^;
6070 ;;;m^a[x\\[:alpha:]-\\[:alpha:]-a-\\[:alpha:][-aa-[[:alpha:]-b-\\[:alpha:]-\\[:alpha:]]^;
6071 ;;;m^a[x\\[:alpha:][:alpha:]\\[:alpha:][-aa-[[:alpha:]\\[:alpha:][:alpha:]]^;
6072 (save-excursion
6073 (goto-char (1+ b))
6074 ;; First
6075 (cperl-look-at-leading-count is-x-REx e)
6076 (setq hairy-RE
6077 (concat
6078 (if is-x-REx
6079 (if (eq (char-after b) ?\#)
6080 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
6081 "\\((\\?#\\)\\|\\(#\\)")
6082 ;; keep the same count: add a fake group
6083 (if (eq (char-after b) ?\#)
6084 "\\((\\?\\\\#\\)\\(\\)"
6085 "\\((\\?#\\)\\(\\)"))
6086 "\\|"
6087 "\\(\\[\\)" ; 3=[
6088 "\\|"
6089 "\\(]\\)" ; 4=]
6090 "\\|"
6091 ;; XXXX Will not be able to use it in s)))
6092 (if (eq (char-after b) ?\) )
6093 "\\())))\\)" ; Will never match
6094 (if (eq (char-after b) ?? )
6095 ;;"\\((\\\\\\?\\(\\\\\\?\\)?{\\)"
6096 "\\((\\\\\\?\\\\\\?{\\|()\\\\\\?{\\)"
6097 "\\((\\?\\??{\\)")) ; 5= (??{ (?{
6098 "\\|" ; 6= 0-length, 7: name, 8,9:code, 10:group
6099 "\\(" ;; XXXX 1-char variables, exc. |()\s
6100 "[$@]"
6101 "\\("
6102 "[_a-zA-Z:][_a-zA-Z0-9:]*"
6103 "\\|"
6104 "{[^{}]*}" ; only one-level allowed
6105 "\\|"
6106 "[^{(|) \t\r\n\f]"
6107 "\\)"
6108 "\\(" ;;8,9:code part of array/hash elt
6109 "\\(" "->" "\\)?"
6110 "\\[[^][]*\\]"
6111 "\\|"
6112 "{[^{}]*}"
6113 "\\)*"
6114 ;; XXXX: what if u is delim?
6115 "\\|"
6116 "[)^|$.*?+]"
6117 "\\|"
6118 "{[0-9]+}"
6119 "\\|"
6120 "{[0-9]+,[0-9]*}"
6121 "\\|"
6122 "\\\\[luLUEQbBAzZG]"
6123 "\\|"
6124 "(" ; Group opener
6125 "\\(" ; 10 group opener follower
6126 "\\?\\((\\?\\)" ; 11: in (?(?=C)A|B)
6127 "\\|"
6128 "\\?[:=!>?{]" ; "?" something
6129 "\\|"
6130 "\\?[-imsx]+[:)]" ; (?i) (?-s:.)
6131 "\\|"
6132 "\\?([0-9]+)" ; (?(1)foo|bar)
6133 "\\|"
6134 "\\?<[=!]"
6135 ;;;"\\|"
6136 ;;; "\\?"
6137 "\\)?"
6138 "\\)"
6139 "\\|"
6140 "\\\\\\(.\\)" ; 12=\SYMBOL
6142 (while
6143 (and (< (point) (1- e))
6144 (re-search-forward hairy-RE (1- e) 'to-end))
6145 (goto-char (match-beginning 0))
6146 (setq REx-subgr-start (point)
6147 was-subgr (following-char))
6148 (cond
6149 ((match-beginning 6) ; 0-length builtins, groups
6150 (goto-char (match-end 0))
6151 (if (match-beginning 11)
6152 (goto-char (match-beginning 11)))
6153 (if (>= (point) e)
6154 (goto-char (1- e)))
6155 (cperl-postpone-fontification
6156 (match-beginning 0) (point)
6157 'face
6158 (cond
6159 ((eq was-subgr ?\) )
6160 (condition-case nil
6161 (save-excursion
6162 (forward-sexp -1)
6163 (if (> (point) b)
6164 (if (if (eq (char-after b) ?? )
6165 (looking-at "(\\\\\\?")
6166 (eq (char-after (1+ (point))) ?\?))
6167 my-cperl-REx-0length-face
6168 my-cperl-REx-ctl-face)
6169 font-lock-warning-face))
6170 (error font-lock-warning-face)))
6171 ((eq was-subgr ?\| )
6172 my-cperl-REx-ctl-face)
6173 ((eq was-subgr ?\$ )
6174 (if (> (point) (1+ REx-subgr-start))
6175 (progn
6176 (put-text-property
6177 (match-beginning 0) (point)
6178 'REx-interpolated
6179 (if is-o-REx 0
6180 (if (and (eq (match-beginning 0)
6181 (1+ b))
6182 (eq (point)
6183 (1- e))) 1 t)))
6184 font-lock-variable-name-face)
6185 my-cperl-REx-spec-char-face))
6186 ((memq was-subgr (append "^." nil) )
6187 my-cperl-REx-spec-char-face)
6188 ((eq was-subgr ?\( )
6189 (if (not (match-beginning 10))
6190 my-cperl-REx-ctl-face
6191 my-cperl-REx-0length-face))
6192 (t my-cperl-REx-0length-face)))
6193 (if (and (memq was-subgr (append "(|" nil))
6194 (not (string-match "(\\?[-imsx]+)"
6195 (match-string 0))))
6196 (cperl-look-at-leading-count is-x-REx e))
6197 (setq was-subgr nil)) ; We do stuff here
6198 ((match-beginning 12) ; \SYMBOL
6199 (forward-char 2)
6200 (if (>= (point) e)
6201 (goto-char (1- e))
6202 ;; How many chars to not highlight:
6203 ;; 0-len special-alnums in other branch =>
6204 ;; Generic: \non-alnum (1), \alnum (1+face)
6205 ;; Is-delim: \non-alnum (1/spec-2) alnum-1 (=what hai)
6206 (setq REx-subgr-start (point)
6207 qtag (preceding-char))
6208 (cperl-postpone-fontification
6209 (- (point) 2) (- (point) 1) 'face
6210 (if (memq qtag
6211 (append "ghijkmoqvFHIJKMORTVY" nil))
6212 font-lock-warning-face
6213 my-cperl-REx-0length-face))
6214 (if (and (eq (char-after b) qtag)
6215 (memq qtag (append ".])^$|*?+" nil)))
6216 (progn
6217 (if (and cperl-use-syntax-table-text-property
6218 (eq qtag ?\) ))
6219 (put-text-property
6220 REx-subgr-start (1- (point))
6221 'syntax-table cperl-st-punct))
6222 (cperl-postpone-fontification
6223 (1- (point)) (point) 'face
6224 ; \] can't appear below
6225 (if (memq qtag (append ".]^$" nil))
6226 'my-cperl-REx-spec-char-face
6227 (if (memq qtag (append "*?+" nil))
6228 'my-cperl-REx-0length-face
6229 'my-cperl-REx-ctl-face))))) ; )|
6230 ;; Test for arguments:
6231 (cond
6232 ;; This is not pretty: the 5.8.7 logic:
6233 ;; \0numx -> octal (up to total 3 dig)
6234 ;; \DIGIT -> backref unless \0
6235 ;; \DIGITs -> backref if legal
6236 ;; otherwise up to 3 -> octal
6237 ;; Do not try to distinguish, we guess
6238 ((or (and (memq qtag (append "01234567" nil))
6239 (re-search-forward
6240 "\\=[01234567]?[01234567]?"
6241 (1- e) 'to-end))
6242 (and (memq qtag (append "89" nil))
6243 (re-search-forward
6244 "\\=[0123456789]*" (1- e) 'to-end))
6245 (and (eq qtag ?x)
6246 (re-search-forward
6247 "\\=[0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}"
6248 (1- e) 'to-end))
6249 (and (memq qtag (append "pPN" nil))
6250 (re-search-forward "\\={[^{}]+}\\|."
6251 (1- e) 'to-end))
6252 (eq (char-syntax qtag) ?w))
6253 (cperl-postpone-fontification
6254 (1- REx-subgr-start) (point)
6255 'face my-cperl-REx-length1-face))))
6256 (setq was-subgr nil)) ; We do stuff here
6257 ((match-beginning 3) ; [charclass]
6258 ;; Highlight leader, trailer, POSIX classes
6259 (forward-char 1)
6260 (if (eq (char-after b) ?^ )
6261 (and (eq (following-char) ?\\ )
6262 (eq (char-after (cperl-1+ (point)))
6263 ?^ )
6264 (forward-char 2))
6265 (and (eq (following-char) ?^ )
6266 (forward-char 1)))
6267 (setq argument b ; continue? & end of last POSIX
6268 tag nil ; list of POSIX classes
6269 qtag (point)) ; after leading ^ if present
6270 (if (eq (char-after b) ?\] )
6271 (and (eq (following-char) ?\\ )
6272 (eq (char-after (cperl-1+ (point)))
6273 ?\] )
6274 (setq qtag (1+ qtag))
6275 (forward-char 2))
6276 (and (eq (following-char) ?\] )
6277 (forward-char 1)))
6278 (setq REx-subgr-end qtag) ;EndOf smart-highlighed
6279 ;; Apparently, I can't put \] into a charclass
6280 ;; in m]]: m][\\\]\]] produces [\\]]
6281 ;;; POSIX? [:word:] [:^word:] only inside []
6282 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]")
6283 (while ; look for unescaped ]
6284 (and argument
6285 (re-search-forward
6286 (if (eq (char-after b) ?\] )
6287 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]"
6288 "\\=\\(\\\\.\\|[^]\\\\]\\)*]")
6289 (1- e) 'toend))
6290 ;; Is this ] an end of POSIX class?
6291 (if (save-excursion
6292 (and
6293 (search-backward "[" argument t)
6294 (< REx-subgr-start (point))
6295 (setq argument (point)) ; POSIX-start
6296 (or ; Should work with delim = \
6297 (not (eq (preceding-char) ?\\ ))
6298 ;; XXXX Double \\ is needed with 19.33
6299 (= (% (skip-chars-backward "\\\\") 2) 0))
6300 (looking-at
6301 (cond
6302 ((eq (char-after b) ?\] )
6303 "\\\\*\\[:\\^?\\sw+:\\\\\\]")
6304 ((eq (char-after b) ?\: )
6305 "\\\\*\\[\\\\:\\^?\\sw+\\\\:]")
6306 ((eq (char-after b) ?^ )
6307 "\\\\*\\[:\\(\\\\\\^\\)?\\sw+:\]")
6308 ((eq (char-syntax (char-after b))
6310 (concat
6311 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\"
6312 (char-to-string (char-after b))
6313 "\\|\\sw\\)+:\]"))
6314 (t "\\\\*\\[:\\^?\\sw*:]")))
6315 (goto-char REx-subgr-end)
6316 (cperl-highlight-charclass
6317 argument my-cperl-REx-spec-char-face
6318 my-cperl-REx-0length-face my-cperl-REx-length1-face)))
6319 (setq tag (cons (cons argument (point))
6320 tag)
6321 argument (point)
6322 REx-subgr-end argument) ; continue
6323 (setq argument nil)))
6324 (and argument
6325 (message "Couldn't find end of charclass in a REx, pos=%s"
6326 REx-subgr-start))
6327 (setq argument (1- (point)))
6328 (goto-char REx-subgr-end)
6329 (cperl-highlight-charclass
6330 argument my-cperl-REx-spec-char-face
6331 my-cperl-REx-0length-face my-cperl-REx-length1-face)
6332 (forward-char 1)
6333 ;; Highlight starter, trailer, POSIX
6334 (if (and cperl-use-syntax-table-text-property
6335 (> (- (point) 2) REx-subgr-start))
6336 (put-text-property
6337 (1+ REx-subgr-start) (1- (point))
6338 'syntax-table cperl-st-punct))
6339 (cperl-postpone-fontification
6340 REx-subgr-start qtag
6341 'face my-cperl-REx-spec-char-face)
6342 (cperl-postpone-fontification
6343 (1- (point)) (point) 'face
6344 my-cperl-REx-spec-char-face)
6345 (if (eq (char-after b) ?\] )
6346 (cperl-postpone-fontification
6347 (- (point) 2) (1- (point))
6348 'face my-cperl-REx-0length-face))
6349 (while tag
6350 (cperl-postpone-fontification
6351 (car (car tag)) (cdr (car tag))
6352 'face font-lock-variable-name-face) ;my-cperl-REx-length1-face
6353 (setq tag (cdr tag)))
6354 (setq was-subgr nil)) ; did facing already
6355 ;; Now rare stuff:
6356 ((and (match-beginning 2) ; #-comment
6357 (/= (match-beginning 2) (match-end 2)))
6358 (beginning-of-line 2)
6359 (if (> (point) e)
6360 (goto-char (1- e))))
6361 ((match-beginning 4) ; character "]"
6362 (setq was-subgr nil) ; We do stuff here
6363 (goto-char (match-end 0))
6364 (if cperl-use-syntax-table-text-property
6365 (put-text-property
6366 (1- (point)) (point)
6367 'syntax-table cperl-st-punct))
6368 (cperl-postpone-fontification
6369 (1- (point)) (point)
6370 'face font-lock-warning-face))
6371 ((match-beginning 5) ; before (?{}) (??{})
6372 (setq tag (match-end 0))
6373 (if (or (setq qtag
6374 (cperl-forward-group-in-re st-l))
6375 (and (>= (point) e)
6376 (setq qtag "no matching `)' found"))
6377 (and (not (eq (char-after (- (point) 2))
6378 ?\} ))
6379 (setq qtag "Can't find })")))
6380 (progn
6381 (goto-char (1- e))
6382 (message qtag))
6383 (cperl-postpone-fontification
6384 (1- tag) (1- (point))
6385 'face font-lock-variable-name-face)
6386 (cperl-postpone-fontification
6387 REx-subgr-start (1- tag)
6388 'face my-cperl-REx-spec-char-face)
6389 (cperl-postpone-fontification
6390 (1- (point)) (point)
6391 'face my-cperl-REx-spec-char-face)
6392 (if cperl-use-syntax-table-text-property
6393 (progn
6394 (put-text-property
6395 (- (point) 2) (1- (point))
6396 'syntax-table cperl-st-cfence)
6397 (put-text-property
6398 (+ REx-subgr-start 2)
6399 (+ REx-subgr-start 3)
6400 'syntax-table cperl-st-cfence))))
6401 (setq was-subgr nil))
6402 (t ; (?#)-comment
6403 ;; Inside "(" and "\" arn't special in any way
6404 ;; Works also if the outside delimiters are ().
6405 (or;;(if (eq (char-after b) ?\) )
6406 ;;(re-search-forward
6407 ;; "[^\\\\]\\(\\\\\\\\\\)*\\\\)"
6408 ;; (1- e) 'toend)
6409 (search-forward ")" (1- e) 'toend)
6411 (message
6412 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
6413 REx-subgr-start))))
6414 (if (>= (point) e)
6415 (goto-char (1- e)))
6416 (cond
6417 (was-subgr
6418 (setq REx-subgr-end (point))
6419 (cperl-commentify
6420 REx-subgr-start REx-subgr-end nil)
6421 (cperl-postpone-fontification
6422 REx-subgr-start REx-subgr-end
6423 'face font-lock-comment-face))))))
6424 (if (and is-REx is-x-REx)
6425 (put-text-property (1+ b) (1- e)
6426 'syntax-subtype 'x-REx)))
6427 (if (and i2 e1 (or (not b1) (> e1 b1)))
6428 (progn ; No errors finding the second part...
6429 (cperl-postpone-fontification
6430 (1- e1) e1 'face my-cperl-delimiters-face)
6431 (if (assoc (char-after b) cperl-starters)
6432 (progn
6433 (cperl-postpone-fontification
6434 b1 (1+ b1) 'face my-cperl-delimiters-face)
6435 (put-text-property b1 (1+ b1)
6436 'REx-part2 t)))))
6437 (if (> (point) max)
6438 (setq tmpend tb))))
6439 ((match-beginning 17) ; sub with prototype or attribute
6440 ;; 1+6+2+1+1=11 extra () before this (sub with proto/attr):
6441 ;;"\\<sub\\>\\(" ;12
6442 ;; cperl-white-and-comment-rex ;13
6443 ;; "\\([a-zA-Z_:'0-9]+\\)\\)?" ; name ;14
6444 ;;"\\(" cperl-maybe-white-and-comment-rex ;15,16
6445 ;; "\\(([^()]*)\\|:[^:]\\)\\)" ; 17:proto or attribute start
6446 (if (not cperl-use-v6) ; perl6: for perl6 we just use ordinary highlighting in sub params
6447 (progn
6448 (setq b1 (match-beginning 14) e1 (match-end 14))
6449 (if (memq (char-after (1- b))
6450 '(?\$ ?\@ ?\% ?\& ?\*))
6452 (goto-char b)
6453 (if (eq (char-after (match-beginning 17)) ?\( )
6454 (progn
6455 (cperl-commentify ; Prototypes; mark as string
6456 (match-beginning 17) (match-end 17) t)
6457 (goto-char (match-end 0))
6458 ;; Now look for attributes after prototype:
6459 (forward-comment (buffer-size))
6460 (and (looking-at ":[^:]")
6461 (cperl-find-sub-attrs st-l b1 e1 b)))
6462 ;; treat attributes without prototype
6463 (goto-char (match-beginning 17))
6464 (cperl-find-sub-attrs st-l b1 e1 b))))))
6465 ;; 1+6+2+1+1+6+1=18 extra () before this:
6466 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
6467 ((match-beginning 19) ; old $abc'efg syntax
6468 (setq bb (match-end 0))
6469 ;;;(if (nth 3 state) nil ; in string
6470 (put-text-property (1- bb) bb 'syntax-table cperl-st-word)
6471 (goto-char bb))
6472 ;; 1+6+2+1+1+6+1+1=19 extra () before this:
6473 ;; "__\\(END\\|DATA\\)__"
6474 ((match-beginning 20) ; __END__, __DATA__
6475 (setq bb (match-end 0))
6476 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
6477 (cperl-commentify b bb nil)
6478 (setq end t))
6479 ;; "\\\\\\(['`\"($]\\)"
6480 ((match-beginning 21)
6481 ;; Trailing backslash; make non-quoting outside string/comment
6482 (setq bb (match-end 0))
6483 (goto-char b)
6484 (skip-chars-backward "\\\\")
6485 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
6486 (cperl-modify-syntax-type b cperl-st-punct)
6487 (goto-char bb))
6488 (t (error "Error in regexp of the sniffer")))
6489 (if (> (point) stop-point)
6490 (progn
6491 (if end
6492 (message "Garbage after __END__/__DATA__ ignored")
6493 (message "Unbalanced syntax found while scanning")
6494 (or (car err-l) (setcar err-l b)))
6495 (goto-char stop-point))))
6496 (setq cperl-syntax-state (cons state-point state)
6497 ;; Do not mark syntax as done past tmpend???
6498 cperl-syntax-done-to (or tmpend (max (point) max)))
6499 ;;(message "state-at=%s, done-to=%s" state-point cperl-syntax-done-to)
6501 (if (car err-l) (goto-char (car err-l))
6502 (or non-inter
6503 (message "Scanning for \"hard\" Perl constructions... done"))))
6504 (and (buffer-modified-p)
6505 (not modified)
6506 (set-buffer-modified-p nil))
6507 (set-syntax-table cperl-mode-syntax-table))
6508 (list (car err-l) overshoot)))
6510 (defun cperl-find-pods-heres-region (min max)
6511 (interactive "r")
6512 (cperl-find-pods-heres min max))
6514 (defun cperl-backward-to-noncomment (lim)
6515 ;; Stops at lim or after non-whitespace that is not in comment
6516 ;; XXXX Wrongly understands end-of-multiline strings with # as comment
6517 (let (stop p pr)
6518 (while (and (not stop) (> (point) (or lim (point-min))))
6519 (skip-chars-backward " \t\n\f" lim)
6520 (setq p (point))
6521 (beginning-of-line)
6522 (if (memq (setq pr (get-text-property (point) 'syntax-type))
6523 '(pod here-doc here-doc-delim))
6524 (progn
6525 (cperl-unwind-to-safe nil)
6526 (setq pr (get-text-property (point) 'syntax-type))))
6527 (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
6528 (not (memq pr '(string prestring))))
6529 (progn (cperl-to-comment-or-eol) (bolp))
6530 (progn
6531 (skip-chars-backward " \t")
6532 (if (< p (point)) (goto-char p))
6533 (setq stop t))))))
6535 ;; Used only in `cperl-calculate-indent'...
6536 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
6537 ;; Positions is before ?\{. Checks whether it starts a block.
6538 ;; No save-excursion! This is more a distinguisher of a block/hash ref...
6540 (and ; perl6: it's never a hash if whitespace before brace (not yet perfect)
6541 (cond (cperl-use-v6))
6542 (memq (preceding-char) (append " \t" nil)))
6543 (progn
6544 (cperl-backward-to-noncomment (point-min))
6545 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
6546 ; Label may be mixed up with `$blah :'
6547 (save-excursion (cperl-after-label))
6548 (get-text-property (cperl-1- (point)) 'attrib-group)
6549 (and (memq (char-syntax (preceding-char)) '(?w ?_))
6550 (progn
6551 (backward-sexp)
6552 ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
6553 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
6554 (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
6555 (not (looking-at "\\$[a-zA-Z0-9_]+"))) ; perl6: todo: why? (topics before blockstart?); even better [$@%]?
6556 ;; sub bless::foo {}
6557 (progn
6558 (cperl-backward-to-noncomment (point-min))
6559 (and (eq (preceding-char) ?b)
6560 (progn
6561 (forward-sexp -1)
6562 (looking-at "\\(coro\\|sub\\|method\\|submethod\\)[ \t\n\f#]"))))))) ; perl6
6563 (if cperl-use-v6
6564 (progn ; perl6: "if/elsif/unless/while/until/given/when/for/loop" without parens; just look at beginning of line
6565 (beginning-of-line)
6566 (looking-at "\\s *}?\\s *\\(\\(els\\(e\\s +\\|\\)\\)?if\\|un\\(less\\|til\\)\\|given\\|wh\\(ile\\|en\\)\\|for\\|loop\\)\\>"))))))
6569 ;;; What is the difference of (cperl-after-block-p lim t) and (cperl-block-p)?
6570 ;;; No save-excursion; condition-case ... In (cperl-block-p) the block
6571 ;;; may be a part of an in-statement construct, such as
6572 ;;; ${something()}, print {FH} $data.
6573 ;;; Moreover, one takes positive approach (looks for else,grep etc)
6574 ;;; another negative (looks for bless,tr etc)
6575 (defun cperl-after-block-p (lim &optional pre-block)
6576 "Return true if the preceeding } (if PRE-BLOCK, following {) delimits a block.
6577 Would not look before LIM. Assumes that LIM is a good place to begin a
6578 statement. The kind of block we treat here is one after which a new
6579 statement would start; thus the block in ${func()} does not count."
6580 (save-excursion
6581 (condition-case nil
6582 (progn
6583 (or pre-block (forward-sexp -1))
6584 (cperl-backward-to-noncomment lim)
6585 (or (eq (point) lim)
6586 ;; if () {} // sub f () {} // sub f :a(') {}
6587 (eq (preceding-char) ?\) )
6588 ;; label: {}
6589 (save-excursion (cperl-after-label))
6590 ;; sub :attr {}
6591 (get-text-property (cperl-1- (point)) 'attrib-group)
6592 (if (memq (char-syntax (preceding-char)) '(?w ?_)) ; else {}
6594 (save-excursion
6595 (forward-sexp -1)
6596 ;; else {} but not else::func {}
6597 (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\\)?\\)\\>")
6598 (not (looking-at "\\(\\sw\\|_\\)+::")))
6599 ;; sub f {}
6600 (progn
6601 (cperl-backward-to-noncomment lim)
6602 (and (eq (preceding-char) ?b)
6603 (progn
6604 (forward-sexp -1)
6605 (looking-at "\\(coro\\|sub\\|method\\|submethod\\)[ \t\n\f#]")))))) ; perl6
6606 (save-excursion ; perl6: returns Type {} / is rw {} / is cached {} / ...
6607 (forward-sexp -2)
6608 (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\\)\\>")))
6609 ;; What preceeds is not word... XXXX Last statement in sub???
6610 (cperl-after-expr-p lim))
6611 (save-excursion ; perl6: "if/elsif/unless/while/until/given/when/for/loop" without parens; just look at beginning of line
6612 ;; perl6: todo: correct in P5? Then use-v6'ify!
6613 (beginning-of-line)
6614 (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\\)?\\)\\>"))))
6615 (error nil))))
6617 (defun cperl-after-expr-p (&optional lim chars test)
6618 "Return true if the position is good for start of expression.
6619 TEST is the expression to evaluate at the found position. If absent,
6620 CHARS is a string that contains good characters to have before us (however,
6621 `}' is treated \"smartly\" if it is not in the list)."
6622 (let ((lim (or lim (point-min)))
6623 stop p pr)
6624 (cperl-update-syntaxification (point) (point))
6625 (save-excursion
6626 (while (and (not stop) (> (point) lim))
6627 (skip-chars-backward " \t\n\f" lim)
6628 (setq p (point))
6629 (beginning-of-line)
6630 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
6631 ;; '(pod here-doc here-doc-delim))
6632 (if (get-text-property (point) 'here-doc-group)
6633 (progn
6634 (goto-char
6635 (cperl-beginning-of-property (point) 'here-doc-group))
6636 (beginning-of-line 0)))
6637 (if (get-text-property (point) 'in-pod)
6638 (progn
6639 (goto-char
6640 (cperl-beginning-of-property (point) 'in-pod))
6641 (beginning-of-line 0)))
6642 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
6643 ;; Else: last iteration, or a label
6644 (cperl-to-comment-or-eol) ; Will not move past "." after a format
6645 (skip-chars-backward " \t")
6646 (if (< p (point)) (goto-char p))
6647 (setq p (point))
6648 (if (and (eq (preceding-char) ?:)
6649 (progn
6650 (forward-char -1)
6651 (skip-chars-backward " \t\n\f" lim)
6652 (memq (char-syntax (preceding-char)) '(?w ?_))))
6653 (forward-sexp -1) ; Possibly label. Skip it
6654 (goto-char p)
6655 (setq stop t))))
6656 (or (bobp) ; ???? Needed
6657 (eq (point) lim)
6658 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
6659 (progn
6660 (if test (eval test)
6661 (or (memq (preceding-char) (append (or chars "{;") nil))
6662 (and (eq (preceding-char) ?\})
6663 (cperl-after-block-p lim))
6664 (and (eq (following-char) ?.) ; in format: see comment above
6665 (eq (get-text-property (point) 'syntax-type)
6666 'format)))))))))
6668 (defun cperl-backward-to-start-of-expr (&optional lim)
6669 (condition-case nil
6670 (progn
6671 (while (and (or (not lim)
6672 (> (point) lim))
6673 (not (cperl-after-expr-p lim)))
6674 (forward-sexp -1)
6675 ;; May be after $, @, $# etc of a variable
6676 (skip-chars-backward "$@%#")))
6677 (error nil)))
6679 (defun cperl-at-end-of-expr (&optional lim)
6680 ;; Since the SEXP approach below is very fragile, do some overengineering
6681 (or (looking-at (concat cperl-maybe-white-and-comment-rex "[;}]"))
6682 (condition-case nil
6683 (save-excursion
6684 ;; If nothing interesting after, does as (forward-sexp -1);
6685 ;; otherwise fails, or ends at a start of following sexp.
6686 ;; XXXX PROBLEMS: if what follows (after ";") @FOO, or ${bar}
6687 ;; may be stuck after @ or $; just put some stupid workaround now:
6688 (let ((p (point)))
6689 (forward-sexp 1)
6690 (forward-sexp -1)
6691 (while (memq (preceding-char) (append "%&@$*" nil))
6692 (forward-char -1))
6693 (or (< (point) p)
6694 (cperl-after-expr-p lim))))
6695 (error t))))
6697 (defun cperl-forward-to-end-of-expr (&optional lim)
6698 (let ((p (point))))
6699 (condition-case nil
6700 (progn
6701 (while (and (< (point) (or lim (point-max)))
6702 (not (cperl-at-end-of-expr)))
6703 (forward-sexp 1)))
6704 (error nil)))
6706 (defun cperl-backward-to-start-of-continued-exp (lim)
6707 (if (memq (preceding-char) (append ")]}\"'`" nil))
6708 (forward-sexp -1))
6709 (beginning-of-line)
6710 (if (<= (point) lim)
6711 (goto-char (1+ lim)))
6712 (skip-chars-forward " \t"))
6714 (defun cperl-after-block-and-statement-beg (lim)
6715 ;; We assume that we are after ?\}
6716 (and
6717 (cperl-after-block-p lim)
6718 (save-excursion
6719 (forward-sexp -1)
6720 (cperl-backward-to-noncomment (point-min))
6721 (or (bobp)
6722 (eq (point) lim)
6723 (not (= (char-syntax (preceding-char)) ?w))
6724 (progn
6725 (forward-sexp -1)
6726 (not
6727 (looking-at
6728 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
6731 (defvar innerloop-done nil)
6732 (defvar last-depth nil)
6734 (defun cperl-indent-exp ()
6735 "Simple variant of indentation of continued-sexp.
6737 Will not indent comment if it starts at `comment-indent' or looks like
6738 continuation of the comment on the previous line.
6740 If `cperl-indent-region-fix-constructs', will improve spacing on
6741 conditional/loop constructs."
6742 (interactive)
6743 (save-excursion
6744 (let ((tmp-end (progn (end-of-line) (point))) top done)
6745 (save-excursion
6746 (beginning-of-line)
6747 (while (null done)
6748 (setq top (point))
6749 ;; Plan A: if line has an unfinished paren-group, go to end-of-group
6750 (while (= -1 (nth 0 (parse-partial-sexp (point) tmp-end -1)))
6751 (setq top (point))) ; Get the outermost parenths in line
6752 (goto-char top)
6753 (while (< (point) tmp-end)
6754 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
6755 (or (eolp) (forward-sexp 1)))
6756 (if (> (point) tmp-end) ; Yes, there an unfinished block
6758 (if (eq ?\) (preceding-char))
6759 (progn ;; Plan B: find by REGEXP block followup this line
6760 (setq top (point))
6761 (condition-case nil
6762 (progn
6763 (forward-sexp -2)
6764 (if (eq (following-char) ?$ ) ; for my $var (list)
6765 (progn
6766 (forward-sexp -1)
6767 (if (looking-at "\\(my\\|local\\|our\\)\\>")
6768 (forward-sexp -1))))
6769 (if (looking-at
6770 (concat "\\(\\elsif\\|if\\|unless\\|while\\|until"
6771 "\\|for\\(each\\)?\\>\\(\\("
6772 cperl-maybe-white-and-comment-rex
6773 "\\(my\\|local\\|our\\)\\)?"
6774 cperl-maybe-white-and-comment-rex
6775 "\\$[_a-zA-Z0-9]+\\)?\\)\\>"))
6776 (progn
6777 (goto-char top)
6778 (forward-sexp 1)
6779 (setq top (point)))))
6780 (error (setq done t)))
6781 (goto-char top))
6782 (if (looking-at ; Try Plan C: continuation block
6783 (concat cperl-maybe-white-and-comment-rex
6784 "\\<\\(else\\|elsif\|continue\\)\\>"))
6785 (progn
6786 (goto-char (match-end 0))
6787 (save-excursion
6788 (end-of-line)
6789 (setq tmp-end (point))))
6790 (setq done t))))
6791 (save-excursion
6792 (end-of-line)
6793 (setq tmp-end (point))))
6794 (goto-char tmp-end)
6795 (setq tmp-end (point-marker)))
6796 (if cperl-indent-region-fix-constructs
6797 (cperl-fix-line-spacing tmp-end))
6798 (cperl-indent-region (point) tmp-end))))
6800 (defun cperl-fix-line-spacing (&optional end parse-data)
6801 "Improve whitespace in a conditional/loop construct.
6802 Returns some position at the last line."
6803 (interactive)
6804 (or end
6805 (setq end (point-max)))
6806 (let ((ee (save-excursion (end-of-line) (point)))
6807 (cperl-indent-region-fix-constructs
6808 (or cperl-indent-region-fix-constructs 1))
6809 p pp ml have-brace ret)
6810 (save-excursion
6811 (beginning-of-line)
6812 (setq ret (point))
6813 ;; }? continue
6814 ;; blah; }
6815 (if (not
6816 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\|loop\\)") ; perl6-last
6817 (setq have-brace (save-excursion (search-forward "}" ee t)))))
6818 nil ; Do not need to do anything
6819 ;; Looking at:
6820 ;; }
6821 ;; else
6822 (if cperl-merge-trailing-else
6823 (if (looking-at
6824 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
6825 (progn
6826 (search-forward "}")
6827 (setq p (point))
6828 (skip-chars-forward " \t\n")
6829 (delete-region p (point))
6830 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6831 (beginning-of-line)))
6832 (if (looking-at "[ \t]*}[ \t]*\\(els\\(e\\|if\\)\\|continue\\)\\>")
6833 (save-excursion
6834 (search-forward "}")
6835 (delete-horizontal-space)
6836 (insert "\n")
6837 (setq ret (point))
6838 (if (cperl-indent-line parse-data)
6839 (progn
6840 (cperl-fix-line-spacing end parse-data)
6841 (setq ret (point)))))))
6842 ;; Looking at:
6843 ;; } else
6844 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
6845 (progn
6846 (search-forward "}")
6847 (delete-horizontal-space)
6848 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6849 (beginning-of-line)))
6850 ;; Looking at:
6851 ;; else {
6852 (if (looking-at
6853 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\|loop\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]") ; perl6-last
6854 (progn
6855 (forward-word 1)
6856 (delete-horizontal-space)
6857 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6858 (beginning-of-line)))
6859 ;; Looking at:
6860 ;; foreach my $var
6861 (if (looking-at
6862 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\|state\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
6863 (progn
6864 (forward-word 2)
6865 (delete-horizontal-space)
6866 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
6867 (beginning-of-line)))
6868 ;; Looking at:
6869 ;; foreach my $var (
6870 (if (looking-at
6871 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\|state\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
6872 (progn
6873 (forward-sexp 3)
6874 (delete-horizontal-space)
6875 (insert
6876 (make-string cperl-indent-region-fix-constructs ?\ ))
6877 (beginning-of-line)))
6878 ;; Looking at (with or without "}" at start, ending after "({"):
6879 ;; } foreach my $var () OR {
6880 (if (looking-at
6881 "[ \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
6882 (progn
6883 (setq ml (match-beginning 8)) ; "(" or "{" after control word
6884 (re-search-forward "[({]")
6885 (forward-char -1)
6886 (setq p (point))
6887 (if (eq (following-char) ?\( )
6888 (progn
6889 (forward-sexp 1)
6890 (setq pp (point))) ; past parenth-group
6891 ;; after `else' or nothing
6892 (if ml ; after `else'
6893 (skip-chars-backward " \t\n")
6894 (beginning-of-line))
6895 (setq pp nil))
6896 ;; Now after the sexp before the brace
6897 ;; Multiline expr should be special
6898 (setq ml (and pp (save-excursion (goto-char p)
6899 (search-forward "\n" pp t))))
6900 (if (and (or (not pp) (< pp end)) ; Do not go too far...
6901 (looking-at "[ \t\n]*{"))
6902 (progn
6903 (cond
6904 ((bolp) ; Were before `{', no if/else/etc
6905 nil)
6906 ((looking-at "\\(\t*\\| [ \t]+\\){") ; Not exactly 1 SPACE
6907 (delete-horizontal-space)
6908 (if (if ml
6909 cperl-extra-newline-before-brace-multiline
6910 cperl-extra-newline-before-brace)
6911 (progn
6912 (delete-horizontal-space)
6913 (insert "\n")
6914 (setq ret (point))
6915 (if (cperl-indent-line parse-data)
6916 (progn
6917 (cperl-fix-line-spacing end parse-data)
6918 (setq ret (point)))))
6919 (insert
6920 (make-string cperl-indent-region-fix-constructs ?\ ))))
6921 ((and (looking-at "[ \t]*\n")
6922 (not (if ml
6923 cperl-extra-newline-before-brace-multiline
6924 cperl-extra-newline-before-brace)))
6925 (setq pp (point))
6926 (skip-chars-forward " \t\n")
6927 (delete-region pp (point))
6928 (insert
6929 (make-string cperl-indent-region-fix-constructs ?\ )))
6930 ((and (looking-at "[\t ]*{")
6931 (if ml cperl-extra-newline-before-brace-multiline
6932 cperl-extra-newline-before-brace))
6933 (delete-horizontal-space)
6934 (insert "\n")
6935 (setq ret (point))
6936 (if (cperl-indent-line parse-data)
6937 (progn
6938 (cperl-fix-line-spacing end parse-data)
6939 (setq ret (point))))))
6940 ;; Now we are before `{'
6941 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
6942 (progn
6943 (skip-chars-forward " \t\n")
6944 (setq pp (point))
6945 (forward-sexp 1)
6946 (setq p (point))
6947 (goto-char pp)
6948 (setq ml (search-forward "\n" p t))
6949 (if (or cperl-break-one-line-blocks-when-indent ml)
6950 ;; not good: multi-line BLOCK
6951 (progn
6952 (goto-char (1+ pp))
6953 (delete-horizontal-space)
6954 (insert "\n")
6955 (setq ret (point))
6956 (if (cperl-indent-line parse-data)
6957 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
6958 (beginning-of-line)
6959 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
6960 ;; Now check whether there is a hanging `}'
6961 ;; Looking at:
6962 ;; } blah
6963 (if (and
6964 cperl-fix-hanging-brace-when-indent
6965 have-brace
6966 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
6967 (condition-case nil
6968 (progn
6969 (up-list 1)
6970 (if (and (<= (point) pp)
6971 (eq (preceding-char) ?\} )
6972 (cperl-after-block-and-statement-beg (point-min)))
6974 (goto-char p)
6975 nil))
6976 (error nil)))
6977 (progn
6978 (forward-char -1)
6979 (skip-chars-backward " \t")
6980 (if (bolp)
6981 ;; `}' was the first thing on the line, insert NL *after* it.
6982 (progn
6983 (cperl-indent-line parse-data)
6984 (search-forward "}")
6985 (delete-horizontal-space)
6986 (insert "\n"))
6987 (delete-horizontal-space)
6988 (or (eq (preceding-char) ?\;)
6989 (bolp)
6990 (and (eq (preceding-char) ?\} )
6991 (cperl-after-block-p (point-min)))
6992 (insert ";"))
6993 (insert "\n")
6994 (setq ret (point)))
6995 (if (cperl-indent-line parse-data)
6996 (setq ret (cperl-fix-line-spacing end parse-data)))
6997 (beginning-of-line)))))
6998 ret))
7000 (defvar cperl-update-start) ; Do not need to make them local
7001 (defvar cperl-update-end)
7002 (defun cperl-delay-update-hook (beg end old-len)
7003 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
7004 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
7006 (defun cperl-indent-region (start end)
7007 "Simple variant of indentation of region in CPerl mode.
7008 Should be slow. Will not indent comment if it starts at `comment-indent'
7009 or looks like continuation of the comment on the previous line.
7010 Indents all the lines whose first character is between START and END
7011 inclusive.
7013 If `cperl-indent-region-fix-constructs', will improve spacing on
7014 conditional/loop constructs."
7015 (interactive "r")
7016 (cperl-update-syntaxification end end)
7017 (save-excursion
7018 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
7019 (let ((indent-info (if cperl-emacs-can-parse
7020 (list nil nil nil) ; Cannot use '(), since will modify
7021 nil))
7022 (pm 0) (imenu-scanning-message "Indenting... (%3d%%)")
7023 after-change-functions ; Speed it up!
7024 st comm old-comm-indent new-comm-indent p pp i empty)
7025 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
7026 (goto-char start)
7027 (setq old-comm-indent (and (cperl-to-comment-or-eol)
7028 (current-column))
7029 new-comm-indent old-comm-indent)
7030 (goto-char start)
7031 (setq end (set-marker (make-marker) end)) ; indentation changes pos
7032 (or (bolp) (beginning-of-line 2))
7033 (or (fboundp 'imenu-progress-message)
7034 (message "Indenting... For feedback load `imenu'..."))
7035 (while (and (<= (point) end) (not (eobp))) ; bol to check start
7036 (and (fboundp 'imenu-progress-message)
7037 (imenu-progress-message
7038 pm (/ (* 100 (- (point) start)) (- end start -1))))
7039 (setq st (point))
7040 (if (or
7041 (setq empty (looking-at "[ \t]*\n"))
7042 (and (setq comm (looking-at "[ \t]*#"))
7043 (or (eq (current-indentation) (or old-comm-indent
7044 comment-column))
7045 (setq old-comm-indent nil))))
7046 (if (and old-comm-indent
7047 (not empty)
7048 (= (current-indentation) old-comm-indent)
7049 (not (eq (get-text-property (point) 'syntax-type) 'pod))
7050 (not (eq (get-text-property (point) 'syntax-table)
7051 cperl-st-cfence)))
7052 (let ((comment-column new-comm-indent))
7053 (indent-for-comment)))
7054 (progn
7055 (setq i (cperl-indent-line indent-info))
7056 (or comm
7057 (not i)
7058 (progn
7059 (if cperl-indent-region-fix-constructs
7060 (goto-char (cperl-fix-line-spacing end indent-info)))
7061 (if (setq old-comm-indent
7062 (and (cperl-to-comment-or-eol)
7063 (not (memq (get-text-property (point)
7064 'syntax-type)
7065 '(pod here-doc)))
7066 (not (eq (get-text-property (point)
7067 'syntax-table)
7068 cperl-st-cfence))
7069 (current-column)))
7070 (progn (indent-for-comment)
7071 (skip-chars-backward " \t")
7072 (skip-chars-backward "#")
7073 (setq new-comm-indent (current-column))))))))
7074 (beginning-of-line 2))
7075 (if (fboundp 'imenu-progress-message)
7076 (imenu-progress-message pm 100)
7077 (message nil)))
7078 ;; Now run the update hooks
7079 (and after-change-functions
7080 cperl-update-end
7081 (save-excursion
7082 (goto-char cperl-update-end)
7083 (insert " ")
7084 (delete-char -1)
7085 (goto-char cperl-update-start)
7086 (insert " ")
7087 (delete-char -1))))))
7089 ;; Stolen from lisp-mode with a lot of improvements
7090 (defun cperl-fill-paragraph (&optional justify iteration)
7091 "Like \\[fill-paragraph], but handle CPerl comments.
7092 If any of the current line is a comment, fill the comment or the
7093 block of it that point is in, preserving the comment's initial
7094 indentation and initial hashes. Behaves usually outside of comment."
7095 (interactive "P")
7096 (let (;; Non-nil if the current line contains a comment.
7097 has-comment
7098 fill-paragraph-function ; do not recurse
7099 ;; If has-comment, the appropriate fill-prefix for the comment.
7100 comment-fill-prefix
7101 ;; Line that contains code and comment (or nil)
7102 start
7103 c spaces len dc (comment-column comment-column))
7104 ;; Figure out what kind of comment we are looking at.
7105 (save-excursion
7106 (beginning-of-line)
7107 (cond
7109 ;; A line with nothing but a comment on it?
7110 ((looking-at "[ \t]*#[# \t]*")
7111 (setq has-comment t
7112 comment-fill-prefix (buffer-substring (match-beginning 0)
7113 (match-end 0))))
7115 ;; A line with some code, followed by a comment? Remember that the
7116 ;; semi which starts the comment shouldn't be part of a string or
7117 ;; character.
7118 ((cperl-to-comment-or-eol)
7119 (setq has-comment t)
7120 (looking-at "#+[ \t]*")
7121 (setq start (point) c (current-column)
7122 comment-fill-prefix
7123 (concat (make-string (current-column) ?\ )
7124 (buffer-substring (match-beginning 0) (match-end 0)))
7125 spaces (progn (skip-chars-backward " \t")
7126 (buffer-substring (point) start))
7127 dc (- c (current-column)) len (- start (point))
7128 start (point-marker))
7129 (delete-char len)
7130 (insert (make-string dc ?-))))) ; Placeholder (to avoid splitting???)
7131 (if (not has-comment)
7132 (fill-paragraph justify) ; Do the usual thing outside of comment
7133 ;; Narrow to include only the comment, and then fill the region.
7134 (save-restriction
7135 (narrow-to-region
7136 ;; Find the first line we should include in the region to fill.
7137 (if start (progn (beginning-of-line) (point))
7138 (save-excursion
7139 (while (and (zerop (forward-line -1))
7140 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
7141 ;; We may have gone to far. Go forward again.
7142 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
7143 (forward-line 1))
7144 (point)))
7145 ;; Find the beginning of the first line past the region to fill.
7146 (save-excursion
7147 (while (progn (forward-line 1)
7148 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
7149 (point)))
7150 ;; Remove existing hashes
7151 (goto-char (point-min))
7152 (save-excursion ; By some strange reason:needed in 22.1
7153 (while (progn (forward-line 1) (< (point) (point-max)))
7154 (skip-chars-forward " \t")
7155 (if (looking-at "#+")
7156 (progn
7157 (if (and (eq (point) (match-beginning 0))
7158 (not (eq (point) (match-end 0)))) nil
7159 (error
7160 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage"))
7161 (delete-char (- (match-end 0) (match-beginning 0)))))))
7163 ;; Lines with only hashes on them can be paragraph boundaries.
7164 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
7165 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
7166 (fill-prefix comment-fill-prefix))
7167 (fill-paragraph justify)))
7168 (if (and start)
7169 (progn
7170 (goto-char start)
7171 (if (> dc 0)
7172 (progn (delete-char dc) (insert spaces)))
7173 (if (or (= (current-column) c) iteration) nil
7174 (setq comment-column c)
7175 (indent-for-comment)
7176 ;; Repeat once more, flagging as iteration
7177 (cperl-fill-paragraph justify t))))))
7180 (defun cperl-do-auto-fill ()
7181 ;; Break out if the line is short enough
7182 (if (> (save-excursion
7183 (end-of-line)
7184 (current-column))
7185 fill-column)
7186 (let ((c (save-excursion (beginning-of-line)
7187 (cperl-to-comment-or-eol) (point)))
7188 (s (memq (following-char) '(?\ ?\t))) marker)
7189 (if (>= c (point)) nil
7190 (setq marker (point-marker))
7191 (cperl-fill-paragraph)
7192 (goto-char marker)
7193 ;; Is not enough, sometimes marker is a start of line
7194 (if (bolp) (progn (re-search-forward "#+[ \t]*")
7195 (goto-char (match-end 0))))
7196 ;; Following space could have gone:
7197 (if (or (not s) (memq (following-char) '(?\ ?\t))) nil
7198 (insert " ")
7199 (backward-char 1))
7200 ;; Previous space could have gone:
7201 (or (memq (preceding-char) '(?\ ?\t)) (insert " "))))))
7203 (defun cperl-imenu-addback (lst &optional isback name)
7204 ;; We suppose that the lst is a DAG, unless the first element only
7205 ;; loops back, and ISBACK is set. Thus this function cannot be
7206 ;; applied twice without ISBACK set.
7207 (cond ((not cperl-imenu-addback) lst)
7209 (or name
7210 (setq name "+++BACK+++"))
7211 (mapcar (lambda (elt)
7212 (if (and (listp elt) (listp (cdr elt)))
7213 (progn
7214 ;; In the other order it goes up
7215 ;; one level only ;-(
7216 (setcdr elt (cons (cons name lst)
7217 (cdr elt)))
7218 (cperl-imenu-addback (cdr elt) t name))))
7219 (if isback (cdr lst) lst))
7220 lst)))
7222 (defun cperl-imenu--create-perl-index (&optional regexp)
7223 (require 'cl)
7224 (require 'imenu) ; May be called from TAGS creator
7225 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
7226 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
7227 (index-meth-alist '()) meth
7228 packages ends-ranges p marker is-proto
7229 (prev-pos 0) is-pack index index1 name (end-range 0) package)
7230 (goto-char (point-min))
7231 (if noninteractive
7232 (message "Scanning Perl for index")
7233 (imenu-progress-message prev-pos 0))
7234 (cperl-update-syntaxification (point-max) (point-max))
7235 ;; Search for the function
7236 (progn ;;save-match-data
7237 (while (re-search-forward
7238 (or regexp cperl-imenu--function-name-regexp-perl)
7239 nil t)
7240 (or noninteractive
7241 (imenu-progress-message prev-pos))
7242 ;; 2=package-group, 5=package-name 11=sub-name
7243 (cond
7244 ((and ; Skip some noise if building tags
7245 (match-beginning 5) ; package name
7246 ;;(eq (char-after (match-beginning 2)) ?p) ; package
7247 (not (save-match-data
7248 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
7249 nil)
7250 ((and
7251 (or (match-beginning 2)
7252 (match-beginning 11)) ; package or sub
7253 ;; Skip if quoted (will not skip multi-line ''-strings :-():
7254 (null (get-text-property (match-beginning 1) 'syntax-table))
7255 (null (get-text-property (match-beginning 1) 'syntax-type))
7256 (null (get-text-property (match-beginning 1) 'in-pod)))
7257 (setq is-pack (match-beginning 2))
7258 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
7259 ;; (goto-char (match-end 0))) ; Messes what follows
7260 (setq meth nil
7261 p (point))
7262 (while (and ends-ranges (>= p (car ends-ranges)))
7263 ;; delete obsolete entries
7264 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
7265 (setq package (or (car packages) "")
7266 end-range (or (car ends-ranges) 0))
7267 (if is-pack ; doing "package"
7268 (progn
7269 (if (match-beginning 5) ; named package
7270 (setq name (buffer-substring (match-beginning 5)
7271 (match-end 5))
7272 name (progn
7273 (set-text-properties 0 (length name) nil name)
7274 name)
7275 package (concat name "::")
7276 name (concat "package " name))
7277 ;; Support nameless packages
7278 (setq name "package;" package ""))
7279 (setq end-range
7280 (save-excursion
7281 (parse-partial-sexp (point) (point-max) -1) (point))
7282 ends-ranges (cons end-range ends-ranges)
7283 packages (cons package packages)))
7284 (setq is-proto
7285 (or (eq (following-char) ?\;)
7286 (eq 0 (get-text-property (point) 'attrib-group)))))
7287 ;; Skip this function name if it is a prototype declaration.
7288 (if (and is-proto (not is-pack)) nil
7289 (or is-pack
7290 (setq name
7291 (buffer-substring (match-beginning 11) (match-end 11)))
7292 (set-text-properties 0 (length name) nil name))
7293 (setq marker (make-marker))
7294 (set-marker marker (match-end (if is-pack 2 11)))
7295 (cond (is-pack nil)
7296 ((string-match "[:']" name)
7297 (setq meth t))
7298 ((> p end-range) nil)
7300 (setq name (concat package name) meth t)))
7301 (setq index (cons name marker))
7302 (if is-pack
7303 (push index index-pack-alist)
7304 (push index index-alist))
7305 (if meth (push index index-meth-alist))
7306 (push index index-unsorted-alist)))
7307 ((match-beginning 19) ; POD section
7308 (setq name (buffer-substring (match-beginning 20) (match-end 20))
7309 marker (make-marker))
7310 (set-marker marker (match-beginning 20))
7311 (set-text-properties 0 (length name) nil name)
7312 (setq name (concat (make-string
7313 (* 3 (- (char-after (match-beginning 19)) ?1))
7314 ?\ )
7315 name)
7316 index (cons name marker))
7317 (setq index1 (cons (concat "=" name) (cdr index)))
7318 (push index index-pod-alist)
7319 (push index1 index-unsorted-alist)))))
7320 (or noninteractive
7321 (imenu-progress-message prev-pos 100))
7322 (setq index-alist
7323 (if (default-value 'imenu-sort-function)
7324 (sort index-alist (default-value 'imenu-sort-function))
7325 (nreverse index-alist)))
7326 (and index-pod-alist
7327 (push (cons "+POD headers+..."
7328 (nreverse index-pod-alist))
7329 index-alist))
7330 (and (or index-pack-alist index-meth-alist)
7331 (let ((lst index-pack-alist) hier-list pack elt group name)
7332 ;; Remove "package ", reverse and uniquify.
7333 (while lst
7334 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 11))
7335 (if (assoc name hier-list) nil
7336 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
7337 (setq lst index-meth-alist)
7338 (while lst
7339 (setq elt (car lst) lst (cdr lst))
7340 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
7341 (setq pack (substring (car elt) 0 (match-beginning 0)))
7342 (if (setq group (assoc pack hier-list))
7343 (if (listp (cdr group))
7344 ;; Have some functions already
7345 (setcdr group
7346 (cons (cons (substring
7347 (car elt)
7348 (+ 2 (match-beginning 0)))
7349 (cdr elt))
7350 (cdr group)))
7351 (setcdr group (list (cons (substring
7352 (car elt)
7353 (+ 2 (match-beginning 0)))
7354 (cdr elt)))))
7355 (setq hier-list
7356 (cons (cons pack
7357 (list (cons (substring
7358 (car elt)
7359 (+ 2 (match-beginning 0)))
7360 (cdr elt))))
7361 hier-list))))))
7362 (push (cons "+Hierarchy+..."
7363 hier-list)
7364 index-alist)))
7365 (and index-pack-alist
7366 (push (cons "+Packages+..."
7367 (nreverse index-pack-alist))
7368 index-alist))
7369 (and (or index-pack-alist index-pod-alist
7370 (default-value 'imenu-sort-function))
7371 index-unsorted-alist
7372 (push (cons "+Unsorted List+..."
7373 (nreverse index-unsorted-alist))
7374 index-alist))
7375 (cperl-imenu-addback index-alist)))
7378 ;; Suggested by Mark A. Hershberger
7379 (defun cperl-outline-level ()
7380 (looking-at outline-regexp)
7381 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
7382 ;;;; 2=package-group, 5=package-name 11=sub-name 19=head-level
7383 ((match-beginning 2) 0) ; package
7384 ((match-beginning 11) 1) ; sub
7385 ((match-beginning 19)
7386 (- (char-after (match-beginning 19)) ?0)) ; headN ==> N
7387 (t 5))) ; should not happen
7390 (defvar cperl-compilation-error-regexp-alist
7391 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORKS).
7392 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
7393 2 3))
7394 "Alist that specifies how to match errors in perl output.")
7396 (if (fboundp 'eval-after-load)
7397 (eval-after-load
7398 "mode-compile"
7399 '(setq perl-compilation-error-regexp-alist
7400 cperl-compilation-error-regexp-alist)))
7403 (defun cperl-windowed-init ()
7404 "Initialization under windowed version."
7405 (cond ((featurep 'ps-print)
7406 (or cperl-faces-init
7407 (progn
7408 (and (boundp 'font-lock-multiline)
7409 (setq cperl-font-lock-multiline t))
7410 (cperl-init-faces))))
7411 ((not cperl-faces-init)
7412 (add-hook 'font-lock-mode-hook
7413 (function
7414 (lambda ()
7415 (if (memq major-mode '(perl-mode cperl-mode))
7416 (progn
7417 (or cperl-faces-init (cperl-init-faces)))))))
7418 (if (fboundp 'eval-after-load)
7419 (eval-after-load
7420 "ps-print"
7421 '(or cperl-faces-init (cperl-init-faces)))))))
7423 (defun cperl-load-font-lock-keywords ()
7424 (or cperl-faces-init (cperl-init-faces))
7425 perl-font-lock-keywords)
7427 (defun cperl-load-font-lock-keywords-1 ()
7428 (or cperl-faces-init (cperl-init-faces))
7429 perl-font-lock-keywords-1)
7431 (defun cperl-load-font-lock-keywords-2 ()
7432 (or cperl-faces-init (cperl-init-faces))
7433 perl-font-lock-keywords-2)
7435 (defvar perl-font-lock-keywords-1 nil
7436 "Additional expressions to highlight in Perl mode. Minimal set.")
7437 (defvar perl-font-lock-keywords nil
7438 "Additional expressions to highlight in Perl mode. Default set.")
7439 (defvar perl-font-lock-keywords-2 nil
7440 "Additional expressions to highlight in Perl mode. Maximal set.")
7442 (defvar font-lock-background-mode)
7443 (defvar font-lock-display-type)
7444 (defun cperl-init-faces-weak ()
7445 ;; Allow `cperl-find-pods-heres' to run.
7446 (or (boundp 'font-lock-constant-face)
7447 (cperl-force-face font-lock-constant-face
7448 "Face for constant and label names"))
7449 (or (boundp 'font-lock-warning-face)
7450 (cperl-force-face font-lock-warning-face
7451 "Face for things which should stand out"))
7452 ;;(setq font-lock-constant-face 'font-lock-constant-face)
7455 (defun cperl-init-faces ()
7456 (condition-case errs
7457 (progn
7458 (require 'font-lock)
7459 (and (fboundp 'font-lock-fontify-anchored-keywords)
7460 (featurep 'font-lock-extra)
7461 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
7462 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
7463 (if (fboundp 'font-lock-fontify-anchored-keywords)
7464 (setq font-lock-anchored t))
7465 (setq
7466 t-font-lock-keywords
7467 (list
7468 (list "[ \t]+$" 0 cperl-invalid-face t)
7469 (cons
7470 (concat
7471 "\\(^\\|[^$@%&\\]\\)\\<\\("
7472 (mapconcat
7473 'identity
7474 '("if" "until" "while" "elsif" "else" "unless" "for"
7475 "foreach" "continue" "exit" "die" "last" "loop" "goto" "next"
7476 "redo" "return" "local" "exec" "sub" "do" "dump" "use" "our" "state"
7477 "require" "package" "eval" "my" "BEGIN" "END" "CHECK"
7478 "INIT" "START" "FIRST" "ENTER" "LEAVE" "KEEP"
7479 "UNDO" "NEXT" "LAST" "PRE" "POST" "CATCH" "CONTROL"
7480 "given" "when" "default" "has" "returns" "of" "is" "does"
7481 "\\(\\(multi\\|proto\\)[ \t]*\\)?\\(coro\\|sub\\|method\\|submethod\\)?"
7482 "class" "module" "role" "try")
7483 "\\|") ; Flow control
7484 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
7485 ; In what follows we use `type' style
7486 ; for overwritable builtins
7487 (list
7488 (concat
7489 "\\(^\\|[^$@%&\\]\\)\\<\\("
7490 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm" "all" "as"
7491 ;; "and" "any" "atan2" "bind" "binmode" "bless" "caller"
7492 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
7493 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
7494 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
7495 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
7496 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
7497 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
7498 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
7499 ;; "gethostbyname" "gethostent" "getlogin"
7500 ;; "getnetbyaddr" "getnetbyname" "getnetent"
7501 ;; "getpeername" "getpgrp" "getppid" "getpriority"
7502 ;; "getprotobyname" "getprotobynumber" "getprotoent"
7503 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
7504 ;; "getservbyport" "getservent" "getsockname"
7505 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
7506 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
7507 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
7508 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
7509 ;; "not" "none" "oct" "one" "open" "opendir" "or" "ord" "pack" "perl" "pipe"
7510 ;; "quotemeta" "rand" "read" "readdir" "readline"
7511 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
7512 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
7513 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
7514 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
7515 ;; "setpriority" "setprotoent" "setpwent" "setservent"
7516 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
7517 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
7518 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
7519 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
7520 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
7521 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
7522 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
7523 "a\\(bs\\|ccept\\|tan2\\|l\\(arm\\|l\\)\\|n\\(d\\|y\\)\\|s\\)\\|"
7524 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
7525 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
7526 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
7527 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
7528 "e\\(rr\\|x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
7529 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
7530 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
7531 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
7532 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
7533 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
7534 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
7535 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
7536 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
7537 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
7538 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
7539 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
7540 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|o\\(ne\\|t\\)\\)\\|o\\(pen\\(\\|dir\\)\\|ne\\|"
7541 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\|erl\\)\\|quotemeta\\|"
7542 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
7543 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
7544 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
7545 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
7546 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
7547 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
7548 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
7549 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
7550 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
7551 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
7552 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
7553 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
7554 "\\)\\>") 2 'font-lock-type-face)
7555 (list ;; perl6
7556 (concat
7557 "\\(^\\|[^$@%&\\]\\)\\<\\("
7558 ;; the builtin types:
7559 ;; bit" "int" "str" "num" "ref" "bool" "Any" "Bit" "Int" "Str" "Num" "Ref"
7560 ;; Complex Exception Seq Range Set Junction Pair Mapping Signature Capture "
7561 ;; Bag\\|Mapping\\|Blob\\|KeyHash\\|KeySet\\|KeyBag\\|Buf\\|Regex\\|Match\\|Any\\|"
7562 ;; Bool" "Array" "Hash" "IO" "Code" "Routine" "Sub" "Method" "Submethod"
7563 ;; Macro" "Rule" "Block" "Bare" "Parametric" "Package" "Module" "Class" "Role"
7564 ;; Object" "Grammar" "List" "Lazy" "Eager"
7565 ;; Real" "Scalar" "int8" "Socket"
7566 "bit\\|int\\|str\\|num\\|ref\\|bool\\|Any\\|Bit\\|Int\\|Str\\|Num\\|Ref\\|"
7567 "Complex\\|Exception\\|Seq\\|Range\\|Set\\|Junction\\|Pair\\|Mapping\\|Signature\\|Capture\\|"
7568 "Bag\\|Mapping\\|Blob\\|KeyHash\\|KeySet\\|KeyBag\\|Buf\\|Regex\\|Match\\|Any\\|"
7569 "Bool\\|Array\\|Hash\\|IO\\|Code\\|Routine\\|Sub\\|Method\\|Submethod\\|"
7570 "Macro\\|Rule\\|Block\\|Bare\\|Parametric\\|Package\\|Module\\|Class\\|Role\\|"
7571 "Object\\|Grammar\\|List\\|Lazy\\|Eager\\|"
7572 "Real\\|Scalar\\|int8\\|Socket\\|"
7573 "rw\\|readonly\\|ref\\|copy\\|context\\|cached\\|signature\\|parsed\\|reparsed\\|inline\\|"
7574 "tighter\\|looser\\|equiv\\|export\\|extended\\|deep\\|also"
7575 "\\)\\>") 2 'font-lock-type-face)
7576 ;; In what follows we use `other' style
7577 ;; for nonoverwritable builtins
7578 ;; Somehow 's', 'm' are not auto-generated???
7579 (list
7580 (concat
7581 "\\(^\\|[^$@%&\\]\\)\\<\\("
7582 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "async" "atomically" "chomp"
7583 ;; "chop" "class" "coro" "defined" "delete" "do" "each" "else" "elsif"
7584 ;; "eval" "exists" "for" "foreach" "format" "gather" "grammar" "goto"
7585 ;; "grep" "has" "if" "keys" "kv" "last" "local" "loop" "map" "my" "next"
7586 ;; "no" "our" "pairs" "package" "pop" "pos" "pick" "print" "printf" "push"
7587 ;; "q" "qq" "qw" "qx" "redo" "rx" "reduce" "regex" "return" "role" "rule" "say" "scalar" "shift"
7588 ;; "sort" "splice" "split" "study" "state" "sum" "take" "taken" "type" "token" "sub" "tie" "tr"
7589 ;; "undef" "uniq" "unless" "unshift" "untie" "until" "uniq" "use"
7590 ;; "while" "y" "zip"
7591 "AUTOLOAD\\|BEGIN\\|CHECK\\|a\\(sync\\|tomically\\)\\|c\\(lass\\|ho\\(p\\|mp\\)\\|oro\\)\\|d\\(e\\(fined\\|lete\\)\\|"
7592 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
7593 "END\\|for\\(\\|each\\|mat\\)\\|g\\(ather\\|r\\(ep\\|ammar\\)\\|oto\\)\\|has\\|INIT\\|if\\|k\\(eys\\|v\\)\\|"
7594 "l\\(ast\\|o\\(cal\\|op\\)\\)\\|m\\(a\\(p\\|x\\)\\|in\\|odule\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
7595 "p\\(a\\(ckage\\|irs\\)\\|ick\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
7596 "q\\(\\|q\\|w\\|x\\|r\\)\\|rx\\|re\\(gex\\|turn\\|d\\(o\\|uce\\)\\)\\|r\\(o\\|u\\)le\\|s\\(ay\\|pli\\(ce\\|t\\)\\|"
7597 "calar\\|t\\(udy\\|ate\\)\\|u\\(b\\|m\\)\\|hift\\|ort\\)\\|t\\(r\\|ie\\|ype\\|oken\\|aken?\\)\\|"
7598 "u\\(se\\|n\\(iq\\|shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
7599 "while\\|y\\|zip\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
7600 "\\|[sm]" ; Added manually
7601 "\\)\\>") 2 'cperl-nonoverridable-face)
7602 ;; (mapconcat 'identity
7603 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
7604 ;; "#include" "#define" "#undef")
7605 ;; "\\|")
7606 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
7607 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
7608 ;; This highlights declarations and definitions differenty.
7609 ;; We do not try to highlight in the case of attributes:
7610 ;; it is already done by `cperl-find-pods-heres'
7611 (list (concat "\\<\\(\\(multi\\|proto\\)[ \t]*\\)?\\(coro\\|sub\\|method\\|submethod\\)?" ; perl6: multi|proto sub methods
7612 cperl-white-and-comment-rex ; whitespace/comments
7613 "\\([^ \n\t{;()]+\\)" ; 5=name (assume non-anonymous)
7614 "\\("
7615 cperl-maybe-white-and-comment-rex ;whitespace/comments?
7616 "([^()]*)\\)?" ; prototype
7617 cperl-maybe-white-and-comment-rex ; whitespace/comments?
7618 "\\(returns[ \t]+.*\\)?" ; perl6: returns
7619 cperl-maybe-white-and-comment-rex ; whitespace/comments?
7620 "[{;]")
7621 5 (if cperl-font-lock-multiline
7622 '(if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
7623 'font-lock-function-name-face
7624 'font-lock-variable-name-face)
7625 ;; need to manually set 'multiline' for older font-locks
7626 '(progn
7627 (if (< 1 (count-lines (match-beginning 0)
7628 (match-end 0)))
7629 (put-text-property
7630 (+ 3 (match-beginning 0)) (match-end 0)
7631 'syntax-type 'multiline))
7632 (if (eq (char-after (cperl-1- (match-end 0))) ?\{ )
7633 'font-lock-function-name-face
7634 'font-lock-variable-name-face))))
7635 '("\\<\\(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;
7636 2 font-lock-function-name-face)
7637 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
7638 1 font-lock-function-name-face)
7639 (cond ((featurep 'font-lock-extra)
7640 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7641 (2 font-lock-string-face t)
7642 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
7643 (font-lock-anchored
7644 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7645 (2 font-lock-string-face t)
7646 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7647 nil nil
7648 (1 font-lock-string-face t))))
7649 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
7650 2 font-lock-string-face t)))
7651 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
7652 font-lock-string-face t)
7653 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
7654 font-lock-constant-face) ; labels
7655 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
7656 2 font-lock-constant-face)
7657 ;; Uncomment to get perl-mode-like vars
7658 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
7659 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
7660 ;;; (2 (cons font-lock-variable-name-face '(underline))))
7661 (cond ((featurep 'font-lock-extra)
7662 '("^[ \t]*\\(has\\|my\\|local\\|our\\|state\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
7663 (3 font-lock-variable-name-face)
7664 (4 '(another 4 nil
7665 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
7666 (1 font-lock-variable-name-face)
7667 (2 '(restart 2 nil) nil t)))
7668 nil t))) ; local variables, multiple
7669 (font-lock-anchored
7670 ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
7671 (` ((, (concat "\\<\\(has\\|my\\|local\\|our\\|state\\)"
7672 cperl-maybe-white-and-comment-rex
7673 "\\(("
7674 cperl-maybe-white-and-comment-rex
7675 "\\)?\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
7676 (5 (, (if cperl-font-lock-multiline
7677 'font-lock-variable-name-face
7678 '(progn (setq cperl-font-lock-multiline-start
7679 (match-beginning 0))
7680 'font-lock-variable-name-face))))
7681 ((, (concat "\\="
7682 cperl-maybe-white-and-comment-rex
7684 cperl-maybe-white-and-comment-rex
7685 "\\([$@%*]\\([a-zA-Z0-9_:]+\\|[^a-zA-Z0-9_]\\)\\)"))
7686 ;; Bug in font-lock: limit is used not only to limit
7687 ;; searches, but to set the "extend window for
7688 ;; facification" property. Thus we need to minimize.
7689 (, (if cperl-font-lock-multiline
7690 '(if (match-beginning 3)
7691 (save-excursion
7692 (goto-char (match-beginning 3))
7693 (condition-case nil
7694 (forward-sexp 1)
7695 (error
7696 (condition-case nil
7697 (forward-char 200)
7698 (error nil)))) ; typeahead
7699 (1- (point))) ; report limit
7700 (forward-char -2)) ; disable continued expr
7701 '(if (match-beginning 3)
7702 (point-max) ; No limit for continuation
7703 (forward-char -2)))) ; disable continued expr
7704 (, (if cperl-font-lock-multiline
7706 '(progn ; Do at end
7707 ;; "my" may be already fontified (POD),
7708 ;; so cperl-font-lock-multiline-start is nil
7709 (if (or (not cperl-font-lock-multiline-start)
7710 (> 2 (count-lines
7711 cperl-font-lock-multiline-start
7712 (point))))
7714 (put-text-property
7715 (1+ cperl-font-lock-multiline-start) (point)
7716 'syntax-type 'multiline))
7717 (setq cperl-font-lock-multiline-start nil))))
7718 (3 font-lock-variable-name-face)))))
7719 (t '("^[ \t{}]*\\(has\\|my\\|local\\|our\\|state\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
7720 3 font-lock-variable-name-face)))
7721 '("\\<for\\(each\\)?\\([ \t]+\\(has\\|my\\|local\\|our\\|state\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
7722 4 font-lock-variable-name-face)))
7723 (if (not cperl-use-v6)
7724 (setq
7725 t-font-lock-keywords-1
7726 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
7727 ;; not yet as of XEmacs 19.12, works with 21.1.11
7729 (not cperl-xemacs-p)
7730 (string< "21.1.9" emacs-version)
7731 (and (string< "21.1.10" emacs-version)
7732 (string< emacs-version "21.1.2")))
7734 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
7735 (if (eq (char-after (match-beginning 2)) ?%)
7736 cperl-hash-face
7737 cperl-array-face)
7738 t) ; arrays and hashes
7739 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
7741 (if (= (- (match-end 2) (match-beginning 2)) 1)
7742 (if (eq (char-after (match-beginning 3)) ?{)
7743 cperl-hash-face
7744 cperl-array-face) ; arrays and hashes
7745 font-lock-variable-name-face)) ; Just to put something
7746 ("\\(@\\|\\$#\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
7747 (1 cperl-array-face)
7748 (2 font-lock-variable-name-face))
7749 ("\\(%\\)\\(\\$+\\([a-zA-Z_:][a-zA-Z0-9_:]*\\|[^ \t\n]\\)\\)"
7750 (1 cperl-hash-face)
7751 (2 font-lock-variable-name-face))
7752 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
7753 ;;; Too much noise from \s* @s[ and friends
7754 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
7755 ;;(3 font-lock-function-name-face t t)
7756 ;;(4
7757 ;; (if (cperl-slash-is-regexp)
7758 ;; font-lock-function-name-face 'default) nil t))
7760 (setq ; perl6: no whitespace allowed before subscripts in Perl6
7761 t-font-lock-keywords-1
7762 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
7763 ;; not yet as of XEmacs 19.12, works with 21.1.11
7765 (not cperl-xemacs-p)
7766 (string< "21.1.9" emacs-version)
7767 (and (string< "21.1.10" emacs-version)
7768 (string< emacs-version "21.1.2")))
7770 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:.^*+?=!][a-zA-Z0-9_:]*\\)" 1 ; perl6: Twigils %.name %:name %^name, %*name, %+name, %?name, %=name, %!name
7771 (if (eq (char-after (match-beginning 2)) ?%)
7772 cperl-hash-face
7773 cperl-array-face)
7774 t) ; arrays and hashes
7775 ("\\(\\([$@]+\\)[a-zA-Z_:.^*+?=!][a-zA-Z0-9_:]*\\)\\([[{]\\)" ; perl6: Twigils $.name $:name $^name, $*name, $+name, $?name, $=name, $!name
7777 (if (= (- (match-end 2) (match-beginning 2)) 1)
7778 (if (eq (char-after (match-beginning 3)) ?{)
7779 cperl-hash-face
7780 cperl-array-face) ; arrays and hashes
7781 font-lock-variable-name-face)) ; Just to put something
7782 ))))
7784 (if cperl-highlight-variables-indiscriminately
7785 (setq t-font-lock-keywords-1
7786 (append t-font-lock-keywords-1
7787 (list '("[$*][{:.^*+?=!]?\\(\\sw+\\)" 1 ; perl6: Twigils $.name $:name $^name, $*name, $+name, $?name, $=name, $!name
7788 font-lock-variable-name-face)))))
7789 (setq perl-font-lock-keywords-1
7790 (if cperl-syntaxify-by-font-lock
7791 (cons 'cperl-fontify-update
7792 t-font-lock-keywords)
7793 t-font-lock-keywords)
7794 perl-font-lock-keywords perl-font-lock-keywords-1
7795 perl-font-lock-keywords-2 (append
7796 perl-font-lock-keywords-1
7797 t-font-lock-keywords-1)))
7798 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
7799 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
7800 (eval ; Avoid a warning
7801 '(font-lock-require-faces
7802 (list
7803 ;; Color-light Color-dark Gray-light Gray-dark Mono
7804 (list 'font-lock-comment-face
7805 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
7807 [nil nil t t t]
7808 [nil nil t t t]
7809 nil)
7810 (list 'font-lock-string-face
7811 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
7814 [nil nil t t t]
7815 nil)
7816 (list 'font-lock-function-name-face
7817 (vector
7818 "Blue" "LightSkyBlue" "Gray50" "LightGray"
7819 (cdr (assq 'background-color ; if mono
7820 (frame-parameters))))
7821 (vector
7822 nil nil nil nil
7823 (cdr (assq 'foreground-color ; if mono
7824 (frame-parameters))))
7825 [nil nil t t t]
7827 nil)
7828 (list 'font-lock-variable-name-face
7829 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
7831 [nil nil t t t]
7832 [nil nil t t t]
7833 nil)
7834 (list 'font-lock-type-face
7835 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
7837 [nil nil t t t]
7839 [nil nil t t t])
7840 (list 'font-lock-warning-face
7841 ["Pink" "Red" "Gray50" "LightGray"]
7842 ["gray20" "gray90"
7843 "gray80" "gray20"]
7844 [nil nil t t t]
7846 [nil nil t t t]
7848 (list 'font-lock-constant-face
7849 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
7851 [nil nil t t t]
7853 [nil nil t t t])
7854 (list 'cperl-nonoverridable-face
7855 ["chartreuse3" ("orchid1" "orange")
7856 nil "Gray80"]
7857 [nil nil "gray90"]
7858 [nil nil nil t t]
7859 [nil nil t t]
7860 [nil nil t t t])
7861 (list 'cperl-array-face
7862 ["blue" "yellow" nil "Gray80"]
7863 ["lightyellow2" ("navy" "os2blue" "darkgreen")
7864 "gray90"]
7867 nil)
7868 (list 'cperl-hash-face
7869 ["red" "red" nil "Gray80"]
7870 ["lightyellow2" ("navy" "os2blue" "darkgreen")
7871 "gray90"]
7874 nil))))
7875 ;; Do it the dull way, without choose-color
7876 (defvar cperl-guessed-background nil
7877 "Display characteristics as guessed by cperl.")
7878 ;; (or (fboundp 'x-color-defined-p)
7879 ;; (defalias 'x-color-defined-p
7880 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
7881 ;; ;; XEmacs >= 19.12
7882 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
7883 ;; ;; XEmacs 19.11
7884 ;; (t 'x-valid-color-name-p))))
7885 (cperl-force-face font-lock-constant-face
7886 "Face for constant and label names")
7887 (cperl-force-face font-lock-variable-name-face
7888 "Face for variable names")
7889 (cperl-force-face font-lock-type-face
7890 "Face for data types")
7891 (cperl-force-face cperl-nonoverridable-face
7892 "Face for data types from another group")
7893 (cperl-force-face font-lock-warning-face
7894 "Face for things which should stand out")
7895 (cperl-force-face font-lock-comment-face
7896 "Face for comments")
7897 (cperl-force-face font-lock-function-name-face
7898 "Face for function names")
7899 (cperl-force-face cperl-hash-face
7900 "Face for hashes")
7901 (cperl-force-face cperl-array-face
7902 "Face for arrays")
7903 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
7904 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
7905 ;;(or (boundp 'font-lock-type-face)
7906 ;; (defconst font-lock-type-face
7907 ;; 'font-lock-type-face
7908 ;; "Face to use for data types."))
7909 ;;(or (boundp 'cperl-nonoverridable-face)
7910 ;; (defconst cperl-nonoverridable-face
7911 ;; 'cperl-nonoverridable-face
7912 ;; "Face to use for data types from another group."))
7913 ;;(if (not cperl-xemacs-p) nil
7914 ;; (or (boundp 'font-lock-comment-face)
7915 ;; (defconst font-lock-comment-face
7916 ;; 'font-lock-comment-face
7917 ;; "Face to use for comments."))
7918 ;; (or (boundp 'font-lock-keyword-face)
7919 ;; (defconst font-lock-keyword-face
7920 ;; 'font-lock-keyword-face
7921 ;; "Face to use for keywords."))
7922 ;; (or (boundp 'font-lock-function-name-face)
7923 ;; (defconst font-lock-function-name-face
7924 ;; 'font-lock-function-name-face
7925 ;; "Face to use for function names.")))
7926 (if (and
7927 (not (cperl-is-face 'cperl-array-face))
7928 (cperl-is-face 'font-lock-emphasized-face))
7929 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
7930 (if (and
7931 (not (cperl-is-face 'cperl-hash-face))
7932 (cperl-is-face 'font-lock-other-emphasized-face))
7933 (copy-face 'font-lock-other-emphasized-face
7934 'cperl-hash-face))
7935 (if (and
7936 (not (cperl-is-face 'cperl-nonoverridable-face))
7937 (cperl-is-face 'font-lock-other-type-face))
7938 (copy-face 'font-lock-other-type-face
7939 'cperl-nonoverridable-face))
7940 ;;(or (boundp 'cperl-hash-face)
7941 ;; (defconst cperl-hash-face
7942 ;; 'cperl-hash-face
7943 ;; "Face to use for hashes."))
7944 ;;(or (boundp 'cperl-array-face)
7945 ;; (defconst cperl-array-face
7946 ;; 'cperl-array-face
7947 ;; "Face to use for arrays."))
7948 ;; Here we try to guess background
7949 (let ((background
7950 (if (boundp 'font-lock-background-mode)
7951 font-lock-background-mode
7952 'light))
7953 (face-list (and (fboundp 'face-list) (face-list))))
7954 ;;;; (fset 'cperl-is-face
7955 ;;;; (cond ((fboundp 'find-face)
7956 ;;;; (symbol-function 'find-face))
7957 ;;;; (face-list
7958 ;;;; (function (lambda (face) (member face face-list))))
7959 ;;;; (t
7960 ;;;; (function (lambda (face) (boundp face))))))
7961 (defvar cperl-guessed-background
7962 (if (and (boundp 'font-lock-display-type)
7963 (eq font-lock-display-type 'grayscale))
7964 'gray
7965 background)
7966 "Background as guessed by CPerl mode")
7967 (and (not (cperl-is-face 'font-lock-constant-face))
7968 (cperl-is-face 'font-lock-reference-face)
7969 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
7970 (if (cperl-is-face 'font-lock-type-face) nil
7971 (copy-face 'default 'font-lock-type-face)
7972 (cond
7973 ((eq background 'light)
7974 (set-face-foreground 'font-lock-type-face
7975 (if (x-color-defined-p "seagreen")
7976 "seagreen"
7977 "sea green")))
7978 ((eq background 'dark)
7979 (set-face-foreground 'font-lock-type-face
7980 (if (x-color-defined-p "os2pink")
7981 "os2pink"
7982 "pink")))
7984 (set-face-background 'font-lock-type-face "gray90"))))
7985 (if (cperl-is-face 'cperl-nonoverridable-face)
7987 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
7988 (cond
7989 ((eq background 'light)
7990 (set-face-foreground 'cperl-nonoverridable-face
7991 (if (x-color-defined-p "chartreuse3")
7992 "chartreuse3"
7993 "chartreuse")))
7994 ((eq background 'dark)
7995 (set-face-foreground 'cperl-nonoverridable-face
7996 (if (x-color-defined-p "orchid1")
7997 "orchid1"
7998 "orange")))))
7999 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
8000 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
8001 ;;; (cond
8002 ;;; ((eq background 'light)
8003 ;;; (set-face-background 'font-lock-other-emphasized-face
8004 ;;; (if (x-color-defined-p "lightyellow2")
8005 ;;; "lightyellow2"
8006 ;;; (if (x-color-defined-p "lightyellow")
8007 ;;; "lightyellow"
8008 ;;; "light yellow"))))
8009 ;;; ((eq background 'dark)
8010 ;;; (set-face-background 'font-lock-other-emphasized-face
8011 ;;; (if (x-color-defined-p "navy")
8012 ;;; "navy"
8013 ;;; (if (x-color-defined-p "darkgreen")
8014 ;;; "darkgreen"
8015 ;;; "dark green"))))
8016 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
8017 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
8018 ;;; (copy-face 'bold 'font-lock-emphasized-face)
8019 ;;; (cond
8020 ;;; ((eq background 'light)
8021 ;;; (set-face-background 'font-lock-emphasized-face
8022 ;;; (if (x-color-defined-p "lightyellow2")
8023 ;;; "lightyellow2"
8024 ;;; "lightyellow")))
8025 ;;; ((eq background 'dark)
8026 ;;; (set-face-background 'font-lock-emphasized-face
8027 ;;; (if (x-color-defined-p "navy")
8028 ;;; "navy"
8029 ;;; (if (x-color-defined-p "darkgreen")
8030 ;;; "darkgreen"
8031 ;;; "dark green"))))
8032 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
8033 (if (cperl-is-face 'font-lock-variable-name-face) nil
8034 (copy-face 'italic 'font-lock-variable-name-face))
8035 (if (cperl-is-face 'font-lock-constant-face) nil
8036 (copy-face 'italic 'font-lock-constant-face))))
8037 (setq cperl-faces-init t))
8038 (error (message "cperl-init-faces (ignored): %s" errs))))
8041 (defun cperl-ps-print-init ()
8042 "Initialization of `ps-print' components for faces used in CPerl."
8043 (eval-after-load "ps-print"
8044 '(setq ps-bold-faces
8045 ;; font-lock-variable-name-face
8046 ;; font-lock-constant-face
8047 (append '(cperl-array-face
8048 cperl-hash-face)
8049 ps-bold-faces)
8050 ps-italic-faces
8051 ;; font-lock-constant-face
8052 (append '(cperl-nonoverridable-face
8053 cperl-hash-face)
8054 ps-italic-faces)
8055 ps-underlined-faces
8056 ;; font-lock-type-face
8057 (append '(cperl-array-face
8058 cperl-hash-face
8059 underline
8060 cperl-nonoverridable-face)
8061 ps-underlined-faces))))
8063 (defvar ps-print-face-extension-alist)
8065 (defun cperl-ps-print (&optional file)
8066 "Pretty-print in CPerl style.
8067 If optional argument FILE is an empty string, prints to printer, otherwise
8068 to the file FILE. If FILE is nil, prompts for a file name.
8070 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
8071 (interactive)
8072 (or file
8073 (setq file (read-from-minibuffer
8074 "Print to file (if empty - to printer): "
8075 (concat (buffer-file-name) ".ps")
8076 nil nil 'file-name-history)))
8077 (or (> (length file) 0)
8078 (setq file nil))
8079 (require 'ps-print) ; To get ps-print-face-extension-alist
8080 (let ((ps-print-color-p t)
8081 (ps-print-face-extension-alist ps-print-face-extension-alist))
8082 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
8083 (ps-print-buffer-with-faces file)))
8085 ;;; (defun cperl-ps-print-init ()
8086 ;;; "Initialization of `ps-print' components for faces used in CPerl."
8087 ;;; ;; Guard against old versions
8088 ;;; (defvar ps-underlined-faces nil)
8089 ;;; (defvar ps-bold-faces nil)
8090 ;;; (defvar ps-italic-faces nil)
8091 ;;; (setq ps-bold-faces
8092 ;;; (append '(font-lock-emphasized-face
8093 ;;; cperl-array-face
8094 ;;; font-lock-keyword-face
8095 ;;; font-lock-variable-name-face
8096 ;;; font-lock-constant-face
8097 ;;; font-lock-reference-face
8098 ;;; font-lock-other-emphasized-face
8099 ;;; cperl-hash-face)
8100 ;;; ps-bold-faces))
8101 ;;; (setq ps-italic-faces
8102 ;;; (append '(cperl-nonoverridable-face
8103 ;;; font-lock-constant-face
8104 ;;; font-lock-reference-face
8105 ;;; font-lock-other-emphasized-face
8106 ;;; cperl-hash-face)
8107 ;;; ps-italic-faces))
8108 ;;; (setq ps-underlined-faces
8109 ;;; (append '(font-lock-emphasized-face
8110 ;;; cperl-array-face
8111 ;;; font-lock-other-emphasized-face
8112 ;;; cperl-hash-face
8113 ;;; cperl-nonoverridable-face font-lock-type-face)
8114 ;;; ps-underlined-faces))
8115 ;;; (cons 'font-lock-type-face ps-underlined-faces))
8118 (if (cperl-enable-font-lock) (cperl-windowed-init))
8120 (defconst cperl-styles-entries
8121 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
8122 cperl-label-offset cperl-extra-newline-before-brace
8123 cperl-extra-newline-before-brace-multiline
8124 cperl-merge-trailing-else
8125 cperl-continued-statement-offset))
8127 (defconst cperl-style-examples
8128 "##### Numbers etc are: cperl-indent-level cperl-brace-offset
8129 ##### cperl-continued-brace-offset cperl-label-offset
8130 ##### cperl-continued-statement-offset
8131 ##### cperl-merge-trailing-else cperl-extra-newline-before-brace
8133 ########### (Do not forget cperl-extra-newline-before-brace-multiline)
8135 ### CPerl (=GNU - extra-newline-before-brace + merge-trailing-else) 2/0/0/-2/2/t/nil
8136 if (foo) {
8138 baz;
8139 label:
8141 boon;
8143 } else {
8144 stop;
8147 ### PerlStyle (=CPerl with 4 as indent) 4/0/0/-4/4/t/nil
8148 if (foo) {
8150 baz;
8151 label:
8153 boon;
8155 } else {
8156 stop;
8159 ### GNU 2/0/0/-2/2/nil/t
8160 if (foo)
8163 baz;
8164 label:
8166 boon;
8169 else
8171 stop;
8174 ### C++ (=PerlStyle with braces aligned with control words) 4/0/-4/-4/4/nil/t
8175 if (foo)
8178 baz;
8179 label:
8181 boon;
8184 else
8186 stop;
8189 ### BSD (=C++, but will not change preexisting merge-trailing-else
8190 ### and extra-newline-before-brace ) 4/0/-4/-4/4
8191 if (foo)
8194 baz;
8195 label:
8197 boon;
8200 else
8202 stop;
8205 ### K&R (=C++ with indent 5 - merge-trailing-else, but will not
8206 ### change preexisting extra-newline-before-brace) 5/0/-5/-5/5/nil
8207 if (foo)
8210 baz;
8211 label:
8213 boon;
8216 else
8218 stop;
8221 ### Whitesmith (=PerlStyle, but will not change preexisting
8222 ### extra-newline-before-brace and merge-trailing-else) 4/0/0/-4/4
8223 if (foo)
8226 baz;
8227 label:
8229 boon;
8232 else
8234 stop;
8237 "Examples of if/else with different indent styles (with v4.23).")
8239 (defconst cperl-style-alist
8240 '(("CPerl" ;; =GNU - extra-newline-before-brace + cperl-merge-trailing-else
8241 (cperl-indent-level . 2)
8242 (cperl-brace-offset . 0)
8243 (cperl-continued-brace-offset . 0)
8244 (cperl-label-offset . -2)
8245 (cperl-continued-statement-offset . 2)
8246 (cperl-extra-newline-before-brace . nil)
8247 (cperl-extra-newline-before-brace-multiline . nil)
8248 (cperl-merge-trailing-else . t))
8250 ("PerlStyle" ; CPerl with 4 as indent
8251 (cperl-indent-level . 4)
8252 (cperl-brace-offset . 0)
8253 (cperl-continued-brace-offset . 0)
8254 (cperl-label-offset . -4)
8255 (cperl-continued-statement-offset . 4)
8256 (cperl-extra-newline-before-brace . nil)
8257 (cperl-extra-newline-before-brace-multiline . nil)
8258 (cperl-merge-trailing-else . t))
8260 ("Pugs"
8261 (indent-tabs-mode . nil)
8262 (cperl-indent-level . 4)
8263 (cperl-brace-offset . 0)
8264 (cperl-continued-brace-offset . -4)
8265 (cperl-label-offset . -4)
8266 (cperl-extra-newline-before-brace-multiline . nil)
8267 (cperl-merge-trailing-else . t))
8269 ("GNU"
8270 (cperl-indent-level . 2)
8271 (cperl-brace-offset . 0)
8272 (cperl-continued-brace-offset . 0)
8273 (cperl-label-offset . -2)
8274 (cperl-continued-statement-offset . 2)
8275 (cperl-extra-newline-before-brace . t)
8276 (cperl-extra-newline-before-brace-multiline . t)
8277 (cperl-merge-trailing-else . nil))
8279 ("K&R"
8280 (cperl-indent-level . 5)
8281 (cperl-brace-offset . 0)
8282 (cperl-continued-brace-offset . -5)
8283 (cperl-label-offset . -5)
8284 (cperl-continued-statement-offset . 5)
8285 ;;(cperl-extra-newline-before-brace . nil) ; ???
8286 ;;(cperl-extra-newline-before-brace-multiline . nil)
8287 (cperl-merge-trailing-else . nil))
8289 ("BSD"
8290 (cperl-indent-level . 4)
8291 (cperl-brace-offset . 0)
8292 (cperl-continued-brace-offset . -4)
8293 (cperl-label-offset . -4)
8294 (cperl-continued-statement-offset . 4)
8295 ;;(cperl-extra-newline-before-brace . nil) ; ???
8296 ;;(cperl-extra-newline-before-brace-multiline . nil)
8297 ;;(cperl-merge-trailing-else . nil) ; ???
8300 ("C++"
8301 (cperl-indent-level . 4)
8302 (cperl-brace-offset . 0)
8303 (cperl-continued-brace-offset . -4)
8304 (cperl-label-offset . -4)
8305 (cperl-continued-statement-offset . 4)
8306 (cperl-extra-newline-before-brace . t)
8307 (cperl-extra-newline-before-brace-multiline . t)
8308 (cperl-merge-trailing-else . nil))
8310 ("Whitesmith"
8311 (cperl-indent-level . 4)
8312 (cperl-brace-offset . 0)
8313 (cperl-continued-brace-offset . 0)
8314 (cperl-label-offset . -4)
8315 (cperl-continued-statement-offset . 4)
8316 ;;(cperl-extra-newline-before-brace . nil) ; ???
8317 ;;(cperl-extra-newline-before-brace-multiline . nil)
8318 ;;(cperl-merge-trailing-else . nil) ; ???
8320 ("Current"))
8321 "List of variables to set to get a particular indentation style.
8322 Should be used via `cperl-set-style' or via Perl menu.
8324 See examples in `cperl-style-examples'.")
8326 (defun cperl-set-style (style)
8327 "Set CPerl mode variables to use one of several different indentation styles.
8328 The arguments are a string representing the desired style.
8329 The list of styles is in `cperl-style-alist', available styles
8330 are CPerl, PerlStyle, GNU, K&R, BSD, C++ and Whitesmith.
8332 The current value of style is memorized (unless there is a memorized
8333 data already), may be restored by `cperl-set-style-back'.
8335 Chosing \"Current\" style will not change style, so this may be used for
8336 side-effect of memorizing only. Examples in `cperl-style-examples'."
8337 (interactive
8338 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
8339 cperl-style-alist)))
8340 (list (completing-read "Enter style: " list nil 'insist))))
8341 (or cperl-old-style
8342 (setq cperl-old-style
8343 (mapcar (function
8344 (lambda (name)
8345 (cons name (eval name))))
8346 cperl-styles-entries)))
8347 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
8348 (while style
8349 (setq setting (car style) style (cdr style))
8350 (set (car setting) (cdr setting)))))
8352 (defun cperl-set-style-back ()
8353 "Restore a style memorised by `cperl-set-style'."
8354 (interactive)
8355 (or cperl-old-style (error "The style was not changed"))
8356 (let (setting)
8357 (while cperl-old-style
8358 (setq setting (car cperl-old-style)
8359 cperl-old-style (cdr cperl-old-style))
8360 (set (car setting) (cdr setting)))))
8362 (defun cperl-check-syntax ()
8363 (interactive)
8364 (require 'mode-compile)
8365 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
8366 (eval '(mode-compile)))) ; Avoid a warning
8368 (defun cperl-info-buffer (type)
8369 ;; Returns buffer with documentation. Creates if missing.
8370 ;; If TYPE, this vars buffer.
8371 ;; Special care is taken to not stomp over an existing info buffer
8372 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
8373 (info (get-buffer bname))
8374 (oldbuf (get-buffer "*info*")))
8375 (if info info
8376 (save-window-excursion
8377 ;; Get Info running
8378 (require 'info)
8379 (cond (oldbuf
8380 (set-buffer oldbuf)
8381 (rename-buffer "*info-perl-tmp*")))
8382 (save-window-excursion
8383 (info))
8384 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
8385 (set-buffer "*info*")
8386 (rename-buffer bname)
8387 (cond (oldbuf
8388 (set-buffer "*info-perl-tmp*")
8389 (rename-buffer "*info*")
8390 (set-buffer bname)))
8391 (make-local-variable 'window-min-height)
8392 (setq window-min-height 2)
8393 (current-buffer)))))
8395 (defun cperl-word-at-point (&optional p)
8396 "Return the word at point or at P."
8397 (save-excursion
8398 (if p (goto-char p))
8399 (or (cperl-word-at-point-hard)
8400 (progn
8401 (require 'etags)
8402 (funcall (or (and (boundp 'find-tag-default-function)
8403 find-tag-default-function)
8404 (get major-mode 'find-tag-default-function)
8405 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
8406 ;; automatically used within `find-tag-default':
8407 'find-tag-default))))))
8409 (defun cperl-info-on-command (command)
8410 "Show documentation for Perl command COMMAND in other window.
8411 If perl-info buffer is shown in some frame, uses this frame.
8412 Customized by setting variables `cperl-shrink-wrap-info-frame',
8413 `cperl-max-help-size'."
8414 (interactive
8415 (let* ((default (cperl-word-at-point))
8416 (read (read-string
8417 (format "Find doc for Perl function (default %s): "
8418 default))))
8419 (list (if (equal read "")
8420 default
8421 read))))
8423 (let ((buffer (current-buffer))
8424 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
8425 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
8426 max-height char-height buf-list)
8427 (if (string-match "^-[a-zA-Z]$" command)
8428 (setq cmd-desc "^-X[ \t\n]"))
8429 (setq isvar (string-match "^[$@%]" command)
8430 buf (cperl-info-buffer isvar)
8431 iniwin (selected-window)
8432 fr1 (window-frame iniwin))
8433 (set-buffer buf)
8434 (goto-char (point-min))
8435 (or isvar
8436 (progn (re-search-forward "^-X[ \t\n]")
8437 (forward-line -1)))
8438 (if (re-search-forward cmd-desc nil t)
8439 (progn
8440 ;; Go back to beginning of the group (ex, for qq)
8441 (if (re-search-backward "^[ \t\n\f]")
8442 (forward-line 1))
8443 (beginning-of-line)
8444 ;; Get some of
8445 (setq pos (point)
8446 buf-list (list buf "*info-perl-var*" "*info-perl*"))
8447 (while (and (not win) buf-list)
8448 (setq win (get-buffer-window (car buf-list) t))
8449 (setq buf-list (cdr buf-list)))
8450 (or (not win)
8451 (eq (window-buffer win) buf)
8452 (set-window-buffer win buf))
8453 (and win (setq fr2 (window-frame win)))
8454 (if (or (not fr2) (eq fr1 fr2))
8455 (pop-to-buffer buf)
8456 (special-display-popup-frame buf) ; Make it visible
8457 (select-window win))
8458 (goto-char pos) ; Needed (?!).
8459 ;; Resize
8460 (setq iniheight (window-height)
8461 frheight (frame-height)
8462 not-loner (< iniheight (1- frheight))) ; Are not alone
8463 (cond ((if not-loner cperl-max-help-size
8464 cperl-shrink-wrap-info-frame)
8465 (setq height
8466 (+ 2
8467 (count-lines
8469 (save-excursion
8470 (if (re-search-forward
8471 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
8472 (match-beginning 0) (point-max)))))
8473 max-height
8474 (if not-loner
8475 (/ (* (- frheight 3) cperl-max-help-size) 100)
8476 (setq char-height (frame-char-height))
8477 ;; Non-functioning under OS/2:
8478 (if (eq char-height 1) (setq char-height 18))
8479 ;; Title, menubar, + 2 for slack
8480 (- (/ (x-display-pixel-height) char-height) 4)))
8481 (if (> height max-height) (setq height max-height))
8482 ;;(message "was %s doing %s" iniheight height)
8483 (if not-loner
8484 (enlarge-window (- height iniheight))
8485 (set-frame-height (window-frame win) (1+ height)))))
8486 (set-window-start (selected-window) pos))
8487 (message "No entry for %s found." command))
8488 ;;(pop-to-buffer buffer)
8489 (select-window iniwin)))
8491 (defun cperl-info-on-current-command ()
8492 "Show documentation for Perl command at point in other window."
8493 (interactive)
8494 (cperl-info-on-command (cperl-word-at-point)))
8496 (defun cperl-imenu-info-imenu-search ()
8497 (if (looking-at "^-X[ \t\n]") nil
8498 (re-search-backward
8499 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
8500 (forward-line 1)))
8502 (defun cperl-imenu-info-imenu-name ()
8503 (buffer-substring
8504 (match-beginning 1) (match-end 1)))
8506 (defun cperl-imenu-on-info ()
8507 "Shows imenu for Perl Info Buffer.
8508 Opens Perl Info buffer if needed."
8509 (interactive)
8510 (let* ((buffer (current-buffer))
8511 imenu-create-index-function
8512 imenu-prev-index-position-function
8513 imenu-extract-index-name-function
8514 (index-item (save-restriction
8515 (save-window-excursion
8516 (set-buffer (cperl-info-buffer nil))
8517 (setq imenu-create-index-function
8518 'imenu-default-create-index-function
8519 imenu-prev-index-position-function
8520 'cperl-imenu-info-imenu-search
8521 imenu-extract-index-name-function
8522 'cperl-imenu-info-imenu-name)
8523 (imenu-choose-buffer-index)))))
8524 (and index-item
8525 (progn
8526 (push-mark)
8527 (pop-to-buffer "*info-perl*")
8528 (cond
8529 ((markerp (cdr index-item))
8530 (goto-char (marker-position (cdr index-item))))
8532 (goto-char (cdr index-item))))
8533 (set-window-start (selected-window) (point))
8534 (pop-to-buffer buffer)))))
8536 (defun cperl-lineup (beg end &optional step minshift)
8537 "Lineup construction in a region.
8538 Beginning of region should be at the start of a construction.
8539 All first occurrences of this construction in the lines that are
8540 partially contained in the region are lined up at the same column.
8542 MINSHIFT is the minimal amount of space to insert before the construction.
8543 STEP is the tabwidth to position constructions.
8544 If STEP is nil, `cperl-lineup-step' will be used
8545 \(or `cperl-indent-level', if `cperl-lineup-step' is `nil').
8546 Will not move the position at the start to the left."
8547 (interactive "r")
8548 (let (search col tcol seen b)
8549 (save-excursion
8550 (goto-char end)
8551 (end-of-line)
8552 (setq end (point-marker))
8553 (goto-char beg)
8554 (skip-chars-forward " \t\f")
8555 (setq beg (point-marker))
8556 (indent-region beg end nil)
8557 (goto-char beg)
8558 (setq col (current-column))
8559 (if (looking-at "[a-zA-Z0-9_]")
8560 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
8561 (setq search
8562 (concat "\\<"
8563 (regexp-quote
8564 (buffer-substring (match-beginning 0)
8565 (match-end 0))) "\\>"))
8566 (error "Cannot line up in a middle of the word"))
8567 (if (looking-at "$")
8568 (error "Cannot line up end of line"))
8569 (setq search (regexp-quote (char-to-string (following-char)))))
8570 (setq step (or step cperl-lineup-step cperl-indent-level))
8571 (or minshift (setq minshift 1))
8572 (while (progn
8573 (beginning-of-line 2)
8574 (and (< (point) end)
8575 (re-search-forward search end t)
8576 (goto-char (match-beginning 0))))
8577 (setq tcol (current-column) seen t)
8578 (if (> tcol col) (setq col tcol)))
8579 (or seen
8580 (error "The construction to line up occurred only once"))
8581 (goto-char beg)
8582 (setq col (+ col minshift))
8583 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
8584 (while
8585 (progn
8586 (cperl-make-indent col)
8587 (beginning-of-line 2)
8588 (and (< (point) end)
8589 (re-search-forward search end t)
8590 (goto-char (match-beginning 0)))))))) ; No body
8592 (defun cperl-etags (&optional add all files) ;; NOT USED???
8593 "Run etags with appropriate options for Perl files.
8594 If optional argument ALL is `recursive', will process Perl files
8595 in subdirectories too."
8596 (interactive)
8597 (let ((cmd "etags")
8598 (args '("-l" "none" "-r"
8599 ;; 1=fullname 2=package? 3=name 4=proto? 5=attrs? (VERY APPROX!)
8600 "/\\<sub[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([ \t]*:[^#{;]*\\)?\\([{#]\\|$\\)/\\3/"
8601 "-r"
8602 "/\\<\\(package\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\)[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)\\)[ \\t]*\\([#;]\\|$\\)/\\2/"; perl6
8603 "-r"
8604 "/\\<\\(package\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\)[ \\t]*;/\\1;/"))
8605 res)
8606 (if add (setq args (cons "-a" args)))
8607 (or files (setq files (list buffer-file-name)))
8608 (cond
8609 ((eq all 'recursive)
8610 ;;(error "Not implemented: recursive")
8611 (setq args (append (list "-e"
8612 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][LlmM6]6?$/}
8613 use File::Find;
8614 find(\\&wanted, '.');
8615 exec @ARGV;"
8616 cmd) args)
8617 cmd "perl"))
8618 (all
8619 ;;(error "Not implemented: all")
8620 (setq args (append (list "-e"
8621 "push @ARGV, <*.PL *.pl *.pm>;
8622 exec @ARGV;"
8623 cmd) args)
8624 cmd "perl"))
8626 (setq args (append args files))))
8627 (setq res (apply 'call-process cmd nil nil nil args))
8628 (or (eq res 0)
8629 (message "etags returned \"%s\"" res))))
8631 (defun cperl-toggle-auto-newline ()
8632 "Toggle the state of `cperl-auto-newline'."
8633 (interactive)
8634 (setq cperl-auto-newline (not cperl-auto-newline))
8635 (message "Newlines will %sbe auto-inserted now."
8636 (if cperl-auto-newline "" "not ")))
8638 (defun cperl-toggle-abbrev ()
8639 "Toggle the state of automatic keyword expansion in CPerl mode."
8640 (interactive)
8641 (abbrev-mode (if abbrev-mode 0 1))
8642 (message "Perl control structure will %sbe auto-inserted now."
8643 (if abbrev-mode "" "not ")))
8646 (defun cperl-toggle-electric ()
8647 "Toggle the state of parentheses doubling in CPerl mode."
8648 (interactive)
8649 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
8650 (message "Parentheses will %sbe auto-doubled now."
8651 (if (cperl-val 'cperl-electric-parens) "" "not ")))
8653 (defun cperl-toggle-autohelp ()
8654 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
8655 Delay of auto-help controlled by `cperl-lazy-help-time'."
8656 (interactive)
8657 (if (fboundp 'run-with-idle-timer)
8658 (progn
8659 (if cperl-lazy-installed
8660 (cperl-lazy-unstall)
8661 (cperl-lazy-install))
8662 (message "Perl help messages will %sbe automatically shown now."
8663 (if cperl-lazy-installed "" "not ")))
8664 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
8666 (defun cperl-toggle-construct-fix ()
8667 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
8668 (interactive)
8669 (setq cperl-indent-region-fix-constructs
8670 (if cperl-indent-region-fix-constructs
8673 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
8674 (if cperl-indent-region-fix-constructs "" "not ")))
8676 (defun cperl-toggle-set-debug-unwind (arg &optional backtrace)
8677 "Toggle (or, with numeric argument, set) debugging state of syntaxification.
8678 Nonpositive numeric argument disables debugging messages. The message
8679 summarizes which regions it was decided to rescan for syntactic constructs.
8681 The message looks like this:
8683 Syxify req=123..138 actual=101..146 done-to: 112=>146 statepos: 73=>117
8685 Numbers are character positions in the buffer. REQ provides the range to
8686 rescan requested by `font-lock'. ACTUAL is the range actually resyntaxified;
8687 for correct operation it should start and end outside any special syntactic
8688 construct. DONE-TO and STATEPOS indicate changes to internal caches maintained
8689 by CPerl."
8690 (interactive "P")
8691 (or arg
8692 (setq arg (if (eq cperl-syntaxify-by-font-lock
8693 (if backtrace 'backtrace 'message)) 0 1)))
8694 (setq arg (if (> arg 0) (if backtrace 'backtrace 'message) t))
8695 (setq cperl-syntaxify-by-font-lock arg)
8696 (message "Debugging messages of syntax unwind %sabled."
8697 (if (eq arg t) "dis" "en")))
8699 ;;;; Tags file creation.
8701 (defvar cperl-tmp-buffer " *cperl-tmp*")
8703 (defun cperl-setup-tmp-buf ()
8704 (set-buffer (get-buffer-create cperl-tmp-buffer))
8705 (set-syntax-table cperl-mode-syntax-table)
8706 (buffer-disable-undo)
8707 (auto-fill-mode 0)
8708 (if cperl-use-syntax-table-text-property-for-tags
8709 (progn
8710 (make-local-variable 'parse-sexp-lookup-properties)
8711 ;; Do not introduce variable if not needed, we check it!
8712 (set 'parse-sexp-lookup-properties t))))
8714 (defun cperl-xsub-scan ()
8715 (require 'cl)
8716 (require 'imenu)
8717 (let ((index-alist '())
8718 (prev-pos 0) index index1 name package prefix)
8719 (goto-char (point-min))
8720 (if noninteractive
8721 (message "Scanning XSUB for index")
8722 (imenu-progress-message prev-pos 0))
8723 ;; Search for the function
8724 (progn ;;save-match-data
8725 (while (re-search-forward
8726 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
8727 nil t)
8728 (or noninteractive
8729 (imenu-progress-message prev-pos))
8730 (cond
8731 ((match-beginning 2) ; SECTION
8732 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
8733 (goto-char (match-beginning 0))
8734 (skip-chars-forward " \t")
8735 (forward-char 1)
8736 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
8737 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
8738 (setq prefix nil)))
8739 ((not package) nil) ; C language section
8740 ((match-beginning 3) ; XSUB
8741 (goto-char (1+ (match-beginning 3)))
8742 (setq index (imenu-example--name-and-position))
8743 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
8744 (if (and prefix (string-match (concat "^" prefix) name))
8745 (setq name (substring name (length prefix))))
8746 (cond ((string-match "::" name) nil)
8748 (setq index1 (cons (concat package "::" name) (cdr index)))
8749 (push index1 index-alist)))
8750 (setcar index name)
8751 (push index index-alist))
8752 (t ; BOOT: section
8753 ;; (beginning-of-line)
8754 (setq index (imenu-example--name-and-position))
8755 (setcar index (concat package "::BOOT:"))
8756 (push index index-alist)))))
8757 (or noninteractive
8758 (imenu-progress-message prev-pos 100))
8759 index-alist))
8761 (defvar cperl-unreadable-ok nil)
8763 (defun cperl-find-tags (ifile xs topdir)
8764 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
8765 (cperl-pod-here-fontify nil) f file)
8766 (save-excursion
8767 (if b (set-buffer b)
8768 (cperl-setup-tmp-buf))
8769 (erase-buffer)
8770 (condition-case err
8771 (setq file (car (insert-file-contents ifile)))
8772 (error (if cperl-unreadable-ok nil
8773 (if (y-or-n-p
8774 (format "File %s unreadable. Continue? " ifile))
8775 (setq cperl-unreadable-ok t)
8776 (error "Aborting: unreadable file %s" ifile)))))
8777 (if (not file)
8778 (message "Unreadable file %s" ifile)
8779 (message "Scanning file %s ..." file)
8780 (if (and cperl-use-syntax-table-text-property-for-tags
8781 (not xs))
8782 (condition-case err ; after __END__ may have garbage
8783 (cperl-find-pods-heres nil nil noninteractive)
8784 (error (message "While scanning for syntax: %s" err))))
8785 (if xs
8786 (setq lst (cperl-xsub-scan))
8787 (setq ind (cperl-imenu--create-perl-index))
8788 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
8789 (setq lst
8790 (mapcar
8791 (function
8792 (lambda (elt)
8793 (cond ((string-match "^[_a-zA-Z]" (car elt))
8794 (goto-char (cdr elt))
8795 (beginning-of-line) ; pos should be of the start of the line
8796 (list (car elt)
8797 (point)
8798 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
8799 (buffer-substring (progn
8800 (goto-char (cdr elt))
8801 ;; After name now...
8802 (or (eolp) (forward-char 1))
8803 (point))
8804 (progn
8805 (beginning-of-line)
8806 (point))))))))
8807 lst))
8808 (erase-buffer)
8809 (while lst
8810 (setq elt (car lst) lst (cdr lst))
8811 (if elt
8812 (progn
8813 (insert (elt elt 3)
8815 (if (string-match "^\\(package\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\) " (car elt)) ; perl6
8816 (substring (car elt) 8)
8817 (car elt) )
8819 (number-to-string (elt elt 2)) ; Line
8821 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
8822 "\n")
8823 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
8824 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]" ; perl6: TODO: multi|proto submethods
8825 (elt elt 3)))
8826 ;; Need to insert the name without package as well
8827 (setq lst (cons (cons (substring (elt elt 3)
8828 (match-beginning 1)
8829 (match-end 1))
8830 (cdr elt))
8831 lst))))))
8832 (setq pos (point))
8833 (goto-char 1)
8834 (setq rel file)
8835 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
8836 (set-text-properties 0 (length rel) nil rel)
8837 (and (equal topdir (substring rel 0 (length topdir)))
8838 (setq rel (substring file (length topdir))))
8839 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
8840 (setq ret (buffer-substring 1 (point-max)))
8841 (erase-buffer)
8842 (or noninteractive
8843 (message "Scanning file %s finished" file))
8844 ret))))
8846 (defun cperl-add-tags-recurse-noxs ()
8847 "Add to TAGS data for \"pure\" Perl files in the current directory and kids.
8848 Use as
8849 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8850 -f cperl-add-tags-recurse-noxs
8852 (cperl-write-tags nil nil t t nil t))
8854 (defun cperl-add-tags-recurse-noxs-fullpath ()
8855 "Add to TAGS data for \"pure\" Perl in the current directory and kids.
8856 Writes down fullpath, so TAGS is relocatable (but if the build directory
8857 is relocated, the file TAGS inside it breaks). Use as
8858 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8859 -f cperl-add-tags-recurse-noxs-fullpath
8861 (cperl-write-tags nil nil t t nil t ""))
8863 (defun cperl-add-tags-recurse ()
8864 "Add to TAGS file data for Perl files in the current directory and kids.
8865 Use as
8866 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
8867 -f cperl-add-tags-recurse
8869 (cperl-write-tags nil nil t t))
8871 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
8872 ;; If INBUFFER, do not select buffer, and do not save
8873 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
8874 (require 'etags)
8875 (if file nil
8876 (setq file (if dir default-directory (buffer-file-name)))
8877 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
8878 (or topdir
8879 (setq topdir default-directory))
8880 (let ((tags-file-name "TAGS")
8881 (case-fold-search (eq system-type 'emx))
8882 xs rel tm)
8883 (save-excursion
8884 (cond (inbuffer nil) ; Already there
8885 ((file-exists-p tags-file-name)
8886 (if cperl-xemacs-p
8887 (visit-tags-table-buffer)
8888 (visit-tags-table-buffer tags-file-name)))
8889 (t (set-buffer (find-file-noselect tags-file-name))))
8890 (cond
8891 (dir
8892 (cond ((eq erase 'ignore))
8893 (erase
8894 (erase-buffer)
8895 (setq erase 'ignore)))
8896 (let ((files
8897 (condition-case err
8898 (directory-files file t
8899 (if recurse nil cperl-scan-files-regexp)
8901 (error
8902 (if cperl-unreadable-ok nil
8903 (if (y-or-n-p
8904 (format "Directory %s unreadable. Continue? " file))
8905 (setq cperl-unreadable-ok t
8906 tm nil) ; Return empty list
8907 (error "Aborting: unreadable directory %s" file)))))))
8908 (mapcar (function
8909 (lambda (file)
8910 (cond
8911 ((string-match cperl-noscan-files-regexp file)
8912 nil)
8913 ((not (file-directory-p file))
8914 (if (string-match cperl-scan-files-regexp file)
8915 (cperl-write-tags file erase recurse nil t noxs topdir)))
8916 ((not recurse) nil)
8917 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
8918 files)))
8920 (setq xs (string-match "\\.xs$" file))
8921 (if (not (and xs noxs))
8922 (progn
8923 (cond ((eq erase 'ignore) (goto-char (point-max)))
8924 (erase (erase-buffer))
8926 (goto-char 1)
8927 (setq rel file)
8928 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
8929 (set-text-properties 0 (length rel) nil rel)
8930 (and (equal topdir (substring rel 0 (length topdir)))
8931 (setq rel (substring file (length topdir))))
8932 (if (search-forward (concat "\f\n" rel ",") nil t)
8933 (progn
8934 (search-backward "\f\n")
8935 (delete-region (point)
8936 (save-excursion
8937 (forward-char 1)
8938 (if (search-forward "\f\n"
8939 nil 'toend)
8940 (- (point) 2)
8941 (point-max)))))
8942 (goto-char (point-max)))))
8943 (insert (cperl-find-tags file xs topdir))))))
8944 (if inbuffer nil ; Delegate to the caller
8945 (save-buffer 0) ; No backup
8946 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
8947 (initialize-new-tags-table))))))
8949 (defvar cperl-tags-hier-regexp-list
8950 (concat
8951 "^\\("
8952 "\\(package\\|class\\|module\\|role\\|grammar\\|rule\\|token\\|regex\\)\\>"
8953 "\\|"
8954 "sub\\>[^\n]+::"
8955 "\\|"
8956 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
8957 "\\|"
8958 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
8959 "\\)"))
8961 (defvar cperl-hierarchy '(() ())
8962 "Global hierarchy of classes.")
8964 (defun cperl-tags-hier-fill ()
8965 ;; Suppose we are in a tag table cooked by cperl.
8966 (goto-char 1)
8967 (let (type pack name pos line chunk ord cons1 file str info fileind)
8968 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
8969 (setq pos (match-beginning 0)
8970 pack (match-beginning 2))
8971 (beginning-of-line)
8972 (if (looking-at (concat
8973 "\\([^\n]+\\)"
8974 "\C-?"
8975 "\\([^\n]+\\)"
8976 "\C-a"
8977 "\\([0-9]+\\)"
8979 "\\([0-9]+\\)"))
8980 (progn
8981 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
8982 name (buffer-substring (match-beginning 2) (match-end 2))
8983 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
8984 line (buffer-substring (match-beginning 3) (match-end 3))
8985 ord (if pack 1 0)
8986 file (file-of-tag)
8987 fileind (format "%s:%s" file line)
8988 ;; Moves to beginning of the next line:
8989 info (cperl-etags-snarf-tag file line))
8990 ;; Move back
8991 (forward-char -1)
8992 ;; Make new member of hierarchy name ==> file ==> pos if needed
8993 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
8994 ;; Name known
8995 (setcdr cons1 (cons (cons fileind (vector file info))
8996 (cdr cons1)))
8997 ;; First occurrence of the name, start alist
8998 (setq cons1 (cons name (list (cons fileind (vector file info)))))
8999 (if pack
9000 (setcar (cdr cperl-hierarchy)
9001 (cons cons1 (nth 1 cperl-hierarchy)))
9002 (setcar cperl-hierarchy
9003 (cons cons1 (car cperl-hierarchy)))))))
9004 (end-of-line))))
9006 (defun cperl-tags-hier-init (&optional update)
9007 "Show hierarchical menu of classes and methods.
9008 Finds info about classes by a scan of loaded TAGS files.
9009 Supposes that the TAGS files contain fully qualified function names.
9010 One may build such TAGS files from CPerl mode menu."
9011 (interactive)
9012 (require 'etags)
9013 (require 'imenu)
9014 (if (or update (null (nth 2 cperl-hierarchy)))
9015 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
9016 (or (nthcdr 2 elt)
9017 ;; Only in one file
9018 (setcdr elt (cdr (nth 1 elt)))))))
9019 pack name cons1 to l1 l2 l3 l4 b)
9020 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
9021 (setq cperl-hierarchy (list l1 l2 l3))
9022 (if cperl-xemacs-p ; Not checked
9023 (progn
9024 (or tags-file-name
9025 ;; Does this work in XEmacs?
9026 (call-interactively 'visit-tags-table))
9027 (message "Updating list of classes...")
9028 (set-buffer (get-file-buffer tags-file-name))
9029 (cperl-tags-hier-fill))
9030 (or tags-table-list
9031 (call-interactively 'visit-tags-table))
9032 (mapcar
9033 (function
9034 (lambda (tagsfile)
9035 (message "Updating list of classes... %s" tagsfile)
9036 (set-buffer (get-file-buffer tagsfile))
9037 (cperl-tags-hier-fill)))
9038 tags-table-list)
9039 (message "Updating list of classes... postprocessing..."))
9040 (mapcar remover (car cperl-hierarchy))
9041 (mapcar remover (nth 1 cperl-hierarchy))
9042 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
9043 (cons "Methods: " (car cperl-hierarchy))))
9044 (cperl-tags-treeify to 1)
9045 (setcar (nthcdr 2 cperl-hierarchy)
9046 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
9047 (message "Updating list of classes: done, requesting display...")
9048 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
9050 (or (nth 2 cperl-hierarchy)
9051 (error "No items found"))
9052 (setq update
9053 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
9054 (if (if (fboundp 'display-popup-menus-p)
9055 (let ((f 'display-popup-menus-p))
9056 (funcall f))
9057 window-system)
9058 (x-popup-menu t (nth 2 cperl-hierarchy))
9059 (require 'tmm)
9060 (tmm-prompt (nth 2 cperl-hierarchy))))
9061 (if (and update (listp update))
9062 (progn (while (cdr update) (setq update (cdr update)))
9063 (setq update (car update)))) ; Get the last from the list
9064 (if (vectorp update)
9065 (progn
9066 (find-file (elt update 0))
9067 (cperl-etags-goto-tag-location (elt update 1))))
9068 (if (eq update -999) (cperl-tags-hier-init t)))
9070 (defun cperl-tags-treeify (to level)
9071 ;; cadr of `to' is read-write. On start it is a cons
9072 (let* ((regexp (concat "^\\(" (mapconcat
9073 'identity
9074 (make-list level "[_a-zA-Z0-9]+")
9075 "::")
9076 "\\)\\(::\\)?"))
9077 (packages (cdr (nth 1 to)))
9078 (methods (cdr (nth 2 to)))
9079 l1 head tail cons1 cons2 ord writeto packs recurse
9080 root-packages root-functions ms many_ms same_name ps
9081 (move-deeper
9082 (function
9083 (lambda (elt)
9084 (cond ((and (string-match regexp (car elt))
9085 (or (eq ord 1) (match-end 2)))
9086 (setq head (substring (car elt) 0 (match-end 1))
9087 tail (if (match-end 2) (substring (car elt)
9088 (match-end 2)))
9089 recurse t)
9090 (if (setq cons1 (assoc head writeto)) nil
9091 ;; Need to init new head
9092 (setcdr writeto (cons (list head (list "Packages: ")
9093 (list "Methods: "))
9094 (cdr writeto)))
9095 (setq cons1 (nth 1 writeto)))
9096 (setq cons2 (nth ord cons1)) ; Either packs or meths
9097 (setcdr cons2 (cons elt (cdr cons2))))
9098 ((eq ord 2)
9099 (setq root-functions (cons elt root-functions)))
9101 (setq root-packages (cons elt root-packages))))))))
9102 (setcdr to l1) ; Init to dynamic space
9103 (setq writeto to)
9104 (setq ord 1)
9105 (mapcar move-deeper packages)
9106 (setq ord 2)
9107 (mapcar move-deeper methods)
9108 (if recurse
9109 (mapcar (function (lambda (elt)
9110 (cperl-tags-treeify elt (1+ level))))
9111 (cdr to)))
9112 ;;Now clean up leaders with one child only
9113 (mapcar (function (lambda (elt)
9114 (if (not (and (listp (cdr elt))
9115 (eq (length elt) 2))) nil
9116 (setcar elt (car (nth 1 elt)))
9117 (setcdr elt (cdr (nth 1 elt))))))
9118 (cdr to))
9119 ;; Sort the roots of subtrees
9120 (if (default-value 'imenu-sort-function)
9121 (setcdr to
9122 (sort (cdr to) (default-value 'imenu-sort-function))))
9123 ;; Now add back functions removed from display
9124 (mapcar (function (lambda (elt)
9125 (setcdr to (cons elt (cdr to)))))
9126 (if (default-value 'imenu-sort-function)
9127 (nreverse
9128 (sort root-functions (default-value 'imenu-sort-function)))
9129 root-functions))
9130 ;; Now add back packages removed from display
9131 (mapcar (function (lambda (elt)
9132 (setcdr to (cons (cons (concat "package " (car elt))
9133 (cdr elt))
9134 (cdr to)))))
9135 (if (default-value 'imenu-sort-function)
9136 (nreverse
9137 (sort root-packages (default-value 'imenu-sort-function)))
9138 root-packages))))
9140 ;;;(x-popup-menu t
9141 ;;; '(keymap "Name1"
9142 ;;; ("Ret1" "aa")
9143 ;;; ("Head1" "ab"
9144 ;;; keymap "Name2"
9145 ;;; ("Tail1" "x") ("Tail2" "y"))))
9147 (defun cperl-list-fold (list name limit)
9148 (let (list1 list2 elt1 (num 0))
9149 (if (<= (length list) limit) list
9150 (setq list1 nil list2 nil)
9151 (while list
9152 (setq num (1+ num)
9153 elt1 (car list)
9154 list (cdr list))
9155 (if (<= num imenu-max-items)
9156 (setq list2 (cons elt1 list2))
9157 (setq list1 (cons (cons name
9158 (nreverse list2))
9159 list1)
9160 list2 (list elt1)
9161 num 1)))
9162 (nreverse (cons (cons name
9163 (nreverse list2))
9164 list1)))))
9166 (defun cperl-menu-to-keymap (menu &optional name)
9167 (let (list)
9168 (cons 'keymap
9169 (mapcar
9170 (function
9171 (lambda (elt)
9172 (cond ((listp (cdr elt))
9173 (setq list (cperl-list-fold
9174 (cdr elt) (car elt) imenu-max-items))
9175 (cons nil
9176 (cons (car elt)
9177 (cperl-menu-to-keymap list))))
9179 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
9180 (cperl-list-fold menu "Root" imenu-max-items)))))
9183 (defvar cperl-bad-style-regexp
9184 (mapconcat 'identity
9185 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
9186 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
9187 "\\|")
9188 "Finds places such that insertion of a whitespace may help a lot.")
9190 (defvar cperl-not-bad-style-regexp
9191 (mapconcat
9192 'identity
9193 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
9194 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
9195 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
9196 "<\\$?\\sw+\\(\\.\\(\\sw\\|_\\)+\\)?>" ; <IN> <stdin.h>
9197 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
9198 "-[0-9]" ; -5
9199 "\\+\\+" ; ++var
9200 "--" ; --var
9201 ".->" ; a->b
9202 "->" ; a SPACE ->b
9203 "\\[-" ; a[-1]
9204 "\\\\[&$@*\\\\]" ; \&func
9205 "^=" ; =head
9206 "\\$." ; $|
9207 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
9208 "||"
9209 "&&"
9210 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
9211 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
9212 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
9213 ;;"[*/+-|&<.]+="
9215 "\\|")
9216 "If matches at the start of match found by `my-bad-c-style-regexp',
9217 insertion of a whitespace will not help.")
9219 (defvar found-bad)
9221 (defun cperl-find-bad-style ()
9222 "Find places in the buffer where insertion of a whitespace may help.
9223 Prompts user for insertion of spaces.
9224 Currently it is tuned to C and Perl syntax."
9225 (interactive)
9226 (let (found-bad (p (point)))
9227 (setq last-nonmenu-event 13) ; To disable popup
9228 (goto-char (point-min))
9229 (map-y-or-n-p "Insert space here? "
9230 (lambda (arg) (insert " "))
9231 'cperl-next-bad-style
9232 '("location" "locations" "insert a space into")
9233 '((?\C-r (lambda (arg)
9234 (let ((buffer-quit-function
9235 'exit-recursive-edit))
9236 (message "Exit with Esc Esc")
9237 (recursive-edit)
9238 t)) ; Consider acted upon
9239 "edit, exit with Esc Esc")
9240 (?e (lambda (arg)
9241 (let ((buffer-quit-function
9242 'exit-recursive-edit))
9243 (message "Exit with Esc Esc")
9244 (recursive-edit)
9245 t)) ; Consider acted upon
9246 "edit, exit with Esc Esc"))
9248 (if found-bad (goto-char found-bad)
9249 (goto-char p)
9250 (message "No appropriate place found"))))
9252 (defun cperl-next-bad-style ()
9253 (let (p (not-found t) (point (point)) found)
9254 (while (and not-found
9255 (re-search-forward cperl-bad-style-regexp nil 'to-end))
9256 (setq p (point))
9257 (goto-char (match-beginning 0))
9258 (if (or
9259 (looking-at cperl-not-bad-style-regexp)
9260 ;; Check for a < -b and friends
9261 (and (eq (following-char) ?\-)
9262 (save-excursion
9263 (skip-chars-backward " \t\n")
9264 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
9265 ;; Now check for syntax type
9266 (save-match-data
9267 (setq found (point))
9268 (beginning-of-defun)
9269 (let ((pps (parse-partial-sexp (point) found)))
9270 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
9271 (goto-char (match-end 0))
9272 (goto-char (1- p))
9273 (setq not-found nil
9274 found-bad found)))
9275 (not not-found)))
9278 ;;; Getting help
9279 (defvar cperl-have-help-regexp
9280 ;;(concat "\\("
9281 (mapconcat
9282 'identity
9283 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
9284 "[$@]\\^[a-zA-Z]" ; Special variable
9285 "[$@][^ \n\t]" ; Special variable
9286 "-[a-zA-Z]" ; File test
9287 "\\\\[a-zA-Z0]" ; Special chars
9288 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
9289 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
9290 "[a-zA-Z_0-9:]+" ; symbol or number
9291 "x="
9292 "#!")
9293 ;;"\\)\\|\\("
9294 "\\|")
9295 ;;"\\)"
9297 "Matches places in the buffer we can find help for.")
9299 (defvar cperl-message-on-help-error t)
9300 (defvar cperl-help-from-timer nil)
9302 (defun cperl-word-at-point-hard ()
9303 ;; Does not save-excursion
9304 ;; Get to the something meaningful
9305 (or (eobp) (eolp) (forward-char 1))
9306 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
9307 (save-excursion (beginning-of-line) (point))
9308 'to-beg)
9309 ;; (cond
9310 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
9311 ;; (skip-chars-backward " \n\t\r({[]});,")
9312 ;; (or (bobp) (backward-char 1))))
9313 ;; Try to backtrace
9314 (cond
9315 ((looking-at "[a-zA-Z0-9_:]") ; symbol
9316 (skip-chars-backward "a-zA-Z0-9_:")
9317 (cond
9318 ((and (eq (preceding-char) ?^) ; $^I
9319 (eq (char-after (- (point) 2)) ?\$))
9320 (forward-char -2))
9321 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
9322 (forward-char -1))
9323 ((and (eq (preceding-char) ?\=)
9324 (eq (current-column) 1))
9325 (forward-char -1))) ; =head1
9326 (if (and (eq (preceding-char) ?\<)
9327 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
9328 (forward-char -1)))
9329 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
9330 (forward-char -1))
9331 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
9332 (forward-char -1))
9333 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
9334 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
9335 (cond
9336 ((and (eq (preceding-char) ?\$)
9337 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
9338 (forward-char -1))
9339 ((and (eq (following-char) ?\>)
9340 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
9341 (save-excursion
9342 (forward-sexp -1)
9343 (and (eq (preceding-char) ?\<)
9344 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
9345 (search-backward "<"))))
9346 ((and (eq (following-char) ?\$)
9347 (eq (preceding-char) ?\<)
9348 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
9349 (forward-char -1)))
9350 (if (looking-at cperl-have-help-regexp)
9351 (buffer-substring (match-beginning 0) (match-end 0))))
9353 (defun cperl-get-help ()
9354 "Get one-line docs on the symbol at the point.
9355 The data for these docs is a little bit obsolete and may be in fact longer
9356 than a line. Your contribution to update/shorten it is appreciated."
9357 (interactive)
9358 (save-match-data ; May be called "inside" query-replace
9359 (save-excursion
9360 (let ((word (cperl-word-at-point-hard)))
9361 (if word
9362 (if (and cperl-help-from-timer ; Bail out if not in mainland
9363 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
9364 (or (memq (get-text-property (point) 'face)
9365 '(font-lock-comment-face font-lock-string-face))
9366 (memq (get-text-property (point) 'syntax-type)
9367 '(pod here-doc format))))
9369 (cperl-describe-perl-symbol word))
9370 (if cperl-message-on-help-error
9371 (message "Nothing found for %s..."
9372 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
9374 ;;; Stolen from perl-descr.el by Johan Vromans:
9376 (defvar cperl-doc-buffer " *perl-doc*"
9377 "Where the documentation can be found.")
9379 (defun cperl-describe-perl-symbol (val)
9380 "Display the documentation of symbol at point, a Perl operator."
9381 (let ((enable-recursive-minibuffers t)
9382 args-file regexp)
9383 (cond
9384 ((string-match "^[&*][a-zA-Z_]" val)
9385 (setq val (concat (substring val 0 1) "NAME")))
9386 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
9387 (setq val (concat "@" (substring val 1 (match-end 1)))))
9388 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
9389 (setq val (concat "%" (substring val 1 (match-end 1)))))
9390 ((and (string= val "x") (string-match "^x=" val))
9391 (setq val "x="))
9392 ((string-match "^\\$[\C-a-\C-z]" val)
9393 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
9394 ((string-match "^CORE::" val)
9395 (setq val "CORE::"))
9396 ((string-match "^SUPER::" val)
9397 (setq val "SUPER::"))
9398 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
9399 (setq val "<NAME>")))
9400 (setq regexp (concat "^"
9401 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
9402 (regexp-quote val)
9403 "\\([ \t([/]\\|$\\)"))
9405 ;; get the buffer with the documentation text
9406 (cperl-switch-to-doc-buffer)
9408 ;; lookup in the doc
9409 (goto-char (point-min))
9410 (let ((case-fold-search nil))
9411 (list
9412 (if (re-search-forward regexp (point-max) t)
9413 (save-excursion
9414 (beginning-of-line 1)
9415 (let ((lnstart (point)))
9416 (end-of-line)
9417 (message "%s" (buffer-substring lnstart (point)))))
9418 (if cperl-message-on-help-error
9419 (message "No definition for %s" val)))))))
9421 (defvar cperl-short-docs 'please-ignore-this-line
9422 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
9423 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
9424 ... Range (list context); flip/flop [no flop when flip] (scalar context).
9425 ! ... Logical negation.
9426 ... != ... Numeric inequality.
9427 ... !~ ... Search pattern, substitution, or translation (negated).
9428 $! In numeric context: errno. In a string context: error string.
9429 $\" The separator which joins elements of arrays interpolated in strings.
9430 $# The output format for printed numbers. Default is %.15g or close.
9431 $$ Process number of this script. Changes in the fork()ed child process.
9432 $% The current page number of the currently selected output channel.
9434 The following variables are always local to the current block:
9436 $1 Match of the 1st set of parentheses in the last match (auto-local).
9437 $2 Match of the 2nd set of parentheses in the last match (auto-local).
9438 $3 Match of the 3rd set of parentheses in the last match (auto-local).
9439 $4 Match of the 4th set of parentheses in the last match (auto-local).
9440 $5 Match of the 5th set of parentheses in the last match (auto-local).
9441 $6 Match of the 6th set of parentheses in the last match (auto-local).
9442 $7 Match of the 7th set of parentheses in the last match (auto-local).
9443 $8 Match of the 8th set of parentheses in the last match (auto-local).
9444 $9 Match of the 9th set of parentheses in the last match (auto-local).
9445 $& The string matched by the last pattern match (auto-local).
9446 $' The string after what was matched by the last match (auto-local).
9447 $` The string before what was matched by the last match (auto-local).
9449 $( The real gid of this process.
9450 $) The effective gid of this process.
9451 $* Deprecated: Set to 1 to do multiline matching within a string.
9452 $+ The last bracket matched by the last search pattern.
9453 $, The output field separator for the print operator.
9454 $- The number of lines left on the page.
9455 $. The current input line number of the last filehandle that was read.
9456 $/ The input record separator, newline by default.
9457 $0 Name of the file containing the current perl script (read/write).
9458 $: String may be broken after these characters to fill ^-lines in a format.
9459 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
9460 $< The real uid of this process.
9461 $= The page length of the current output channel. Default is 60 lines.
9462 $> The effective uid of this process.
9463 $? The status returned by the last ``, pipe close or `system'.
9464 $@ The perl error message from the last eval or do @var{EXPR} command.
9465 $ARGV The name of the current file used with <> .
9466 $[ Deprecated: The index of the first element/char in an array/string.
9467 $\\ The output record separator for the print operator.
9468 $] The perl version string as displayed with perl -v.
9469 $^ The name of the current top-of-page format.
9470 $^A The current value of the write() accumulator for format() lines.
9471 $^D The value of the perl debug (-D) flags.
9472 $^E Information about the last system error other than that provided by $!.
9473 $^F The highest system file descriptor, ordinarily 2.
9474 $^H The current set of syntax checks enabled by `use strict'.
9475 $^I The value of the in-place edit extension (perl -i option).
9476 $^L What formats output to perform a formfeed. Default is \f.
9477 $^M A buffer for emergency memory allocation when running out of memory.
9478 $^O The operating system name under which this copy of Perl was built.
9479 $^P Internal debugging flag.
9480 $^T The time the script was started. Used by -A/-M/-C file tests.
9481 $^W True if warnings are requested (perl -w flag).
9482 $^X The name under which perl was invoked (argv[0] in C-speech).
9483 $_ The default input and pattern-searching space.
9484 $| Auto-flush after write/print on current output channel? Default 0.
9485 $~ The name of the current report format.
9486 ... % ... Modulo division.
9487 ... %= ... Modulo division assignment.
9488 %ENV Contains the current environment.
9489 %INC List of files that have been require-d or do-ne.
9490 %SIG Used to set signal handlers for various signals.
9491 ... & ... Bitwise and.
9492 ... && ... Logical and.
9493 ... &&= ... Logical and assignment.
9494 ... &= ... Bitwise and assignment.
9495 ... * ... Multiplication.
9496 ... ** ... Exponentiation.
9497 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
9498 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
9499 ... + ... Addition. +EXPR Makes EXPR into scalar context.
9500 ++ Auto-increment (magical on strings). ++EXPR EXPR++
9501 ... += ... Addition assignment.
9502 , Comma operator.
9503 ... - ... Subtraction.
9504 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
9505 ... -= ... Subtraction assignment.
9506 -A Access time in days since script started.
9507 -B File is a non-text (binary) file.
9508 -C Inode change time in days since script started.
9509 -M Age in days since script started.
9510 -O File is owned by real uid.
9511 -R File is readable by real uid.
9512 -S File is a socket .
9513 -T File is a text file.
9514 -W File is writable by real uid.
9515 -X File is executable by real uid.
9516 -b File is a block special file.
9517 -c File is a character special file.
9518 -d File is a directory.
9519 -e File exists .
9520 -f File is a plain file.
9521 -g File has setgid bit set.
9522 -k File has sticky bit set.
9523 -l File is a symbolic link.
9524 -o File is owned by effective uid.
9525 -p File is a named pipe (FIFO).
9526 -r File is readable by effective uid.
9527 -s File has non-zero size.
9528 -t Tests if filehandle (STDIN by default) is opened to a tty.
9529 -u File has setuid bit set.
9530 -w File is writable by effective uid.
9531 -x File is executable by effective uid.
9532 -z File has zero size.
9533 . Concatenate strings.
9534 .. Range (list context); flip/flop (scalar context) operator.
9535 .= Concatenate assignment strings
9536 ... / ... Division. /PATTERN/ioxsmg Pattern match
9537 ... /= ... Division assignment.
9538 /PATTERN/ioxsmg Pattern match.
9539 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
9540 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
9541 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
9542 <> Reads line from union of files in @ARGV (= command line) and STDIN.
9543 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
9544 ... <= ... Numeric less than or equal to.
9545 ... <=> ... Numeric compare.
9546 ... = ... Assignment.
9547 ... == ... Numeric equality.
9548 ... =~ ... Search pattern, substitution, or translation
9549 ... > ... Numeric greater than.
9550 ... >= ... Numeric greater than or equal to.
9551 ... >> ... Bitwise shift right.
9552 ... >>= ... Bitwise shift right assignment.
9553 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
9554 ?PATTERN? One-time pattern match.
9555 @ARGV Command line arguments (not including the command name - see $0).
9556 @INC List of places to look for perl scripts during do/include/use.
9557 @_ Parameter array for subroutines; result of split() unless in list context.
9558 \\ Creates reference to what follows, like \$var, or quotes non-\w in strings.
9559 \\0 Octal char, e.g. \\033.
9560 \\E Case modification terminator. See \\Q, \\L, and \\U.
9561 \\L Lowercase until \\E . See also \\l, lc.
9562 \\U Upcase until \\E . See also \\u, uc.
9563 \\Q Quote metacharacters until \\E . See also quotemeta.
9564 \\a Alarm character (octal 007).
9565 \\b Backspace character (octal 010).
9566 \\c Control character, e.g. \\c[ .
9567 \\e Escape character (octal 033).
9568 \\f Formfeed character (octal 014).
9569 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
9570 \\n Newline character (octal 012 on most systems).
9571 \\r Return character (octal 015 on most systems).
9572 \\t Tab character (octal 011).
9573 \\u Upcase the next character. See also \\U and \\l, ucfirst.
9574 \\x Hex character, e.g. \\x1b.
9575 ... ^ ... Bitwise exclusive or.
9576 __END__ Ends program source.
9577 __DATA__ Ends program source.
9578 __FILE__ Current (source) filename.
9579 __LINE__ Current line in current source.
9580 __PACKAGE__ Current package.
9581 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
9582 ARGVOUT Output filehandle with -i flag.
9583 BEGIN { ... } Immediately executed (during compilation) piece of code.
9584 END { ... } Pseudo-subroutine executed after the script finishes.
9585 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
9586 INIT { ... } Pseudo-subroutine executed before the script starts running.
9587 DATA Input filehandle for what follows after __END__ or __DATA__.
9588 accept(NEWSOCKET,GENERICSOCKET)
9589 alarm(SECONDS)
9590 atan2(X,Y)
9591 bind(SOCKET,NAME)
9592 binmode(FILEHANDLE)
9593 caller[(LEVEL)]
9594 chdir(EXPR)
9595 chmod(LIST)
9596 chop[(LIST|VAR)]
9597 chown(LIST)
9598 chroot(FILENAME)
9599 close(FILEHANDLE)
9600 closedir(DIRHANDLE)
9601 ... cmp ... String compare.
9602 connect(SOCKET,NAME)
9603 continue of { block } continue { block }. Is executed after `next' or at end.
9604 cos(EXPR)
9605 crypt(PLAINTEXT,SALT)
9606 dbmclose(%HASH)
9607 dbmopen(%HASH,DBNAME,MODE)
9608 defined(EXPR)
9609 delete($HASH{KEY})
9610 die(LIST)
9611 do { ... }|SUBR while|until EXPR executes at least once
9612 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
9613 dump LABEL
9614 each(%HASH)
9615 endgrent
9616 endhostent
9617 endnetent
9618 endprotoent
9619 endpwent
9620 endservent
9621 eof[([FILEHANDLE])]
9622 ... eq ... String equality.
9623 eval(EXPR) or eval { BLOCK }
9624 exec([TRUENAME] ARGV0, ARGVs) or exec(SHELL_COMMAND_LINE)
9625 exit(EXPR)
9626 exp(EXPR)
9627 fcntl(FILEHANDLE,FUNCTION,SCALAR)
9628 fileno(FILEHANDLE)
9629 flock(FILEHANDLE,OPERATION)
9630 for (EXPR;EXPR;EXPR) { ... }
9631 foreach [VAR] (@ARRAY) { ... }
9632 fork
9633 ... ge ... String greater than or equal.
9634 getc[(FILEHANDLE)]
9635 getgrent
9636 getgrgid(GID)
9637 getgrnam(NAME)
9638 gethostbyaddr(ADDR,ADDRTYPE)
9639 gethostbyname(NAME)
9640 gethostent
9641 getlogin
9642 getnetbyaddr(ADDR,ADDRTYPE)
9643 getnetbyname(NAME)
9644 getnetent
9645 getpeername(SOCKET)
9646 getpgrp(PID)
9647 getppid
9648 getpriority(WHICH,WHO)
9649 getprotobyname(NAME)
9650 getprotobynumber(NUMBER)
9651 getprotoent
9652 getpwent
9653 getpwnam(NAME)
9654 getpwuid(UID)
9655 getservbyname(NAME,PROTO)
9656 getservbyport(PORT,PROTO)
9657 getservent
9658 getsockname(SOCKET)
9659 getsockopt(SOCKET,LEVEL,OPTNAME)
9660 gmtime(EXPR)
9661 goto LABEL
9662 ... gt ... String greater than.
9663 hex(EXPR)
9664 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
9665 index(STR,SUBSTR[,OFFSET])
9666 int(EXPR)
9667 ioctl(FILEHANDLE,FUNCTION,SCALAR)
9668 join(EXPR,LIST)
9669 keys(%HASH)
9670 kill(LIST)
9671 last [LABEL]
9672 ... le ... String less than or equal.
9673 length(EXPR)
9674 link(OLDFILE,NEWFILE)
9675 listen(SOCKET,QUEUESIZE)
9676 local(LIST)
9677 localtime(EXPR)
9678 log(EXPR)
9679 lstat(EXPR|FILEHANDLE|VAR)
9680 ... lt ... String less than.
9681 m/PATTERN/iogsmx
9682 mkdir(FILENAME,MODE)
9683 msgctl(ID,CMD,ARG)
9684 msgget(KEY,FLAGS)
9685 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
9686 msgsnd(ID,MSG,FLAGS)
9687 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
9688 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
9689 ... ne ... String inequality.
9690 next [LABEL]
9691 oct(EXPR)
9692 open(FILEHANDLE[,EXPR])
9693 opendir(DIRHANDLE,EXPR)
9694 ord(EXPR) ASCII value of the first char of the string.
9695 pack(TEMPLATE,LIST)
9696 package NAME Introduces package context.
9697 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
9698 pop(ARRAY)
9699 print [FILEHANDLE] [(LIST)]
9700 printf [FILEHANDLE] (FORMAT,LIST)
9701 push(ARRAY,LIST)
9702 q/STRING/ Synonym for 'STRING'
9703 qq/STRING/ Synonym for \"STRING\"
9704 qx/STRING/ Synonym for `STRING`
9705 rand[(EXPR)]
9706 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9707 readdir(DIRHANDLE)
9708 readlink(EXPR)
9709 recv(SOCKET,SCALAR,LEN,FLAGS)
9710 redo [LABEL]
9711 rename(OLDNAME,NEWNAME)
9712 require [FILENAME | PERL_VERSION]
9713 reset[(EXPR)]
9714 return(LIST)
9715 reverse(LIST)
9716 rewinddir(DIRHANDLE)
9717 rindex(STR,SUBSTR[,OFFSET])
9718 rmdir(FILENAME)
9719 s/PATTERN/REPLACEMENT/gieoxsm
9720 scalar(EXPR)
9721 seek(FILEHANDLE,POSITION,WHENCE)
9722 seekdir(DIRHANDLE,POS)
9723 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
9724 semctl(ID,SEMNUM,CMD,ARG)
9725 semget(KEY,NSEMS,SIZE,FLAGS)
9726 semop(KEY,...)
9727 send(SOCKET,MSG,FLAGS[,TO])
9728 setgrent
9729 sethostent(STAYOPEN)
9730 setnetent(STAYOPEN)
9731 setpgrp(PID,PGRP)
9732 setpriority(WHICH,WHO,PRIORITY)
9733 setprotoent(STAYOPEN)
9734 setpwent
9735 setservent(STAYOPEN)
9736 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
9737 shift[(ARRAY)]
9738 shmctl(ID,CMD,ARG)
9739 shmget(KEY,SIZE,FLAGS)
9740 shmread(ID,VAR,POS,SIZE)
9741 shmwrite(ID,STRING,POS,SIZE)
9742 shutdown(SOCKET,HOW)
9743 sin(EXPR)
9744 sleep[(EXPR)]
9745 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
9746 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
9747 sort [SUBROUTINE] (LIST)
9748 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
9749 split[(/PATTERN/[,EXPR[,LIMIT]])]
9750 sprintf(FORMAT,LIST)
9751 sqrt(EXPR)
9752 srand(EXPR)
9753 stat(EXPR|FILEHANDLE|VAR)
9754 study[(SCALAR)]
9755 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
9756 substr(EXPR,OFFSET[,LEN])
9757 symlink(OLDFILE,NEWFILE)
9758 syscall(LIST)
9759 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9760 system([TRUENAME] ARGV0 [,ARGV]) or system(SHELL_COMMAND_LINE)
9761 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
9762 tell[(FILEHANDLE)]
9763 telldir(DIRHANDLE)
9764 time
9765 times
9766 tr/SEARCHLIST/REPLACEMENTLIST/cds
9767 truncate(FILE|EXPR,LENGTH)
9768 umask[(EXPR)]
9769 undef[(EXPR)]
9770 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
9771 unlink(LIST)
9772 unpack(TEMPLATE,EXPR)
9773 unshift(ARRAY,LIST)
9774 until (EXPR) { ... } EXPR until EXPR
9775 utime(LIST)
9776 values(%HASH)
9777 vec(EXPR,OFFSET,BITS)
9778 wait
9779 waitpid(PID,FLAGS)
9780 wantarray Returns true if the sub/eval is called in list context.
9781 warn(LIST)
9782 while (EXPR) { ... } EXPR while EXPR
9783 write[(EXPR|FILEHANDLE)]
9784 ... x ... Repeat string or array.
9785 x= ... Repetition assignment.
9786 y/SEARCHLIST/REPLACEMENTLIST/
9787 ... | ... Bitwise or.
9788 ... || ... Logical or.
9789 ~ ... Unary bitwise complement.
9790 #! OS interpreter indicator. If contains `perl', used for options, and -x.
9791 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
9792 CORE:: Prefix to access builtin function if imported sub obscures it.
9793 SUPER:: Prefix to lookup for a method in @ISA classes.
9794 DESTROY Shorthand for `sub DESTROY {...}'.
9795 ... EQ ... Obsolete synonym of `eq'.
9796 ... GE ... Obsolete synonym of `ge'.
9797 ... GT ... Obsolete synonym of `gt'.
9798 ... LE ... Obsolete synonym of `le'.
9799 ... LT ... Obsolete synonym of `lt'.
9800 ... NE ... Obsolete synonym of `ne'.
9801 abs [ EXPR ] absolute value
9802 ... and ... Low-precedence synonym for &&.
9803 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
9804 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
9805 chr Converts a number to char with the same ordinal.
9806 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
9807 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
9808 exists $HASH{KEY} True if the key exists.
9809 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
9810 formline PICTURE, LIST Backdoor into \"format\" processing.
9811 glob EXPR Synonym of <EXPR>.
9812 lc [ EXPR ] Returns lowercased EXPR.
9813 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
9814 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
9815 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
9816 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
9817 not ... Low-precedence synonym for ! - negation.
9818 ... or ... Low-precedence synonym for ||.
9819 pos STRING Set/Get end-position of the last match over this string, see \\G.
9820 quotemeta [ EXPR ] Quote regexp metacharacters.
9821 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
9822 readline FH Synonym of <FH>.
9823 readpipe CMD Synonym of `CMD`.
9824 ref [ EXPR ] Type of EXPR when dereferenced.
9825 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
9826 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
9827 tied Returns internal object for a tied data.
9828 uc [ EXPR ] Returns upcased EXPR.
9829 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
9830 untie VAR Unlink an object from a simple Perl variable.
9831 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
9832 ... xor ... Low-precedence synonym for exclusive or.
9833 prototype \&SUB Returns prototype of the function given a reference.
9834 =head1 Top-level heading.
9835 =head2 Second-level heading.
9836 =head3 Third-level heading (is there such?).
9837 =over [ NUMBER ] Start list.
9838 =item [ TITLE ] Start new item in the list.
9839 =back End list.
9840 =cut Switch from POD to Perl.
9841 =pod Switch from Perl to POD.
9844 (defun cperl-switch-to-doc-buffer ()
9845 "Go to the perl documentation buffer and insert the documentation."
9846 (interactive)
9847 (let ((buf (get-buffer-create cperl-doc-buffer)))
9848 (if (interactive-p)
9849 (switch-to-buffer-other-window buf)
9850 (set-buffer buf))
9851 (if (= (buffer-size) 0)
9852 (progn
9853 (insert (documentation-property 'cperl-short-docs
9854 'variable-documentation))
9855 (setq buffer-read-only t)))))
9857 (defun cperl-beautify-regexp-piece (b e embed level)
9858 ;; b is before the starting delimiter, e before the ending
9859 ;; e should be a marker, may be changed, but remains "correct".
9860 ;; EMBED is nil iff we process the whole REx.
9861 ;; The REx is guaranteed to have //x
9862 ;; LEVEL shows how many levels deep to go
9863 ;; position at enter and at leave is not defined
9864 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
9865 (if embed
9866 (progn
9867 (goto-char b)
9868 (setq c (if (eq embed t) (current-indentation) (current-column)))
9869 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
9870 (forward-char 2)
9871 (delete-char 1)
9872 (forward-char 1))
9873 ((looking-at "(\\?[^a-zA-Z]")
9874 (forward-char 3))
9875 ((looking-at "(\\?") ; (?i)
9876 (forward-char 2))
9878 (forward-char 1))))
9879 (goto-char (1+ b))
9880 (setq c (1- (current-column))))
9881 (setq c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
9882 (or (looking-at "[ \t]*[\n#]")
9883 (progn
9884 (insert "\n")))
9885 (goto-char e)
9886 (beginning-of-line)
9887 (if (re-search-forward "[^ \t]" e t)
9888 (progn ; Something before the ending delimiter
9889 (goto-char e)
9890 (delete-horizontal-space)
9891 (insert "\n")
9892 (cperl-make-indent c)
9893 (set-marker e (point))))
9894 (goto-char b)
9895 (end-of-line 2)
9896 (while (< (point) (marker-position e))
9897 (beginning-of-line)
9898 (setq s (point)
9899 inline t)
9900 (skip-chars-forward " \t")
9901 (delete-region s (point))
9902 (cperl-make-indent c1)
9903 (while (and
9904 inline
9905 (looking-at
9906 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
9907 "\\|" ; Embedded variable
9908 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
9909 "\\|" ; $ ^
9910 "[$^]"
9911 "\\|" ; simple-code simple-code*?
9912 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
9913 "\\|" ; Class
9914 "\\(\\[\\)" ; 6
9915 "\\|" ; Grouping
9916 "\\((\\(\\?\\)?\\)" ; 7 8
9917 "\\|" ; |
9918 "\\(|\\)"))) ; 9
9919 (goto-char (match-end 0))
9920 (setq spaces t)
9921 (cond ((match-beginning 1) ; Alphanum word + junk
9922 (forward-char -1))
9923 ((or (match-beginning 3) ; $ab[12]
9924 (and (match-beginning 5) ; X* X+ X{2,3}
9925 (eq (preceding-char) ?\{)))
9926 (forward-char -1)
9927 (forward-sexp 1))
9928 ((and ; [], already syntaxified
9929 (match-beginning 6)
9930 cperl-regexp-scan
9931 cperl-use-syntax-table-text-property)
9932 (forward-char -1)
9933 (forward-sexp 1)
9934 (or (eq (preceding-char) ?\])
9935 (error "[]-group not terminated"))
9936 (re-search-forward
9937 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
9938 ((match-beginning 6) ; []
9939 (setq tmp (point))
9940 (if (looking-at "\\^?\\]")
9941 (goto-char (match-end 0)))
9942 ;; XXXX POSIX classes?!
9943 (while (and (not pos)
9944 (re-search-forward "\\[:\\|\\]" e t))
9945 (if (eq (preceding-char) ?:)
9946 (or (re-search-forward ":\\]" e t)
9947 (error "[:POSIX:]-group in []-group not terminated"))
9948 (setq pos t)))
9949 (or (eq (preceding-char) ?\])
9950 (error "[]-group not terminated"))
9951 (re-search-forward
9952 "\\=\\([*+?]\\|{[0-9]+\\(,[0-9]*\\)?}\\)\\??" e t))
9953 ((match-beginning 7) ; ()
9954 (goto-char (match-beginning 0))
9955 (setq pos (current-column))
9956 (or (eq pos c1)
9957 (progn
9958 (delete-horizontal-space)
9959 (insert "\n")
9960 (cperl-make-indent c1)))
9961 (setq tmp (point))
9962 (forward-sexp 1)
9963 ;; (or (forward-sexp 1)
9964 ;; (progn
9965 ;; (goto-char tmp)
9966 ;; (error "()-group not terminated")))
9967 (set-marker m (1- (point)))
9968 (set-marker m1 (point))
9969 (if (= level 1)
9970 (if (progn ; indent rigidly if multiline
9971 ;; In fact does not make a lot of sense, since
9972 ;; the starting position can be already lost due
9973 ;; to insertion of "\n" and " "
9974 (goto-char tmp)
9975 (search-forward "\n" m1 t))
9976 (indent-rigidly (point) m1 (- c1 pos)))
9977 (setq level (1- level))
9978 (cond
9979 ((not (match-beginning 8))
9980 (cperl-beautify-regexp-piece tmp m t level))
9981 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
9983 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
9984 (goto-char (+ 2 tmp))
9985 (forward-sexp 1)
9986 (cperl-beautify-regexp-piece (point) m t level))
9987 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
9988 (goto-char (+ 3 tmp))
9989 (cperl-beautify-regexp-piece (point) m t level))
9991 (cperl-beautify-regexp-piece tmp m t level))))
9992 (goto-char m1)
9993 (cond ((looking-at "[*+?]\\??")
9994 (goto-char (match-end 0)))
9995 ((eq (following-char) ?\{)
9996 (forward-sexp 1)
9997 (if (eq (following-char) ?\?)
9998 (forward-char))))
9999 (skip-chars-forward " \t")
10000 (setq spaces nil)
10001 (if (looking-at "[#\n]")
10002 (progn
10003 (or (eolp) (indent-for-comment))
10004 (beginning-of-line 2))
10005 (delete-horizontal-space)
10006 (insert "\n"))
10007 (end-of-line)
10008 (setq inline nil))
10009 ((match-beginning 9) ; |
10010 (forward-char -1)
10011 (setq tmp (point))
10012 (beginning-of-line)
10013 (if (re-search-forward "[^ \t]" tmp t)
10014 (progn
10015 (goto-char tmp)
10016 (delete-horizontal-space)
10017 (insert "\n"))
10018 ;; first at line
10019 (delete-region (point) tmp))
10020 (cperl-make-indent c)
10021 (forward-char 1)
10022 (skip-chars-forward " \t")
10023 (setq spaces nil)
10024 (if (looking-at "[#\n]")
10025 (beginning-of-line 2)
10026 (delete-horizontal-space)
10027 (insert "\n"))
10028 (end-of-line)
10029 (setq inline nil)))
10030 (or (looking-at "[ \t\n]")
10031 (not spaces)
10032 (insert " "))
10033 (skip-chars-forward " \t"))
10034 (or (looking-at "[#\n]")
10035 (error "Unknown code `%s' in a regexp"
10036 (buffer-substring (point) (1+ (point)))))
10037 (and inline (end-of-line 2)))
10038 ;; Special-case the last line of group
10039 (if (and (>= (point) (marker-position e))
10040 (/= (current-indentation) c))
10041 (progn
10042 (beginning-of-line)
10043 (cperl-make-indent c)))))
10045 (defun cperl-make-regexp-x ()
10046 ;; Returns position of the start
10047 ;; XXX this is called too often! Need to cache the result!
10048 (save-excursion
10049 (or cperl-use-syntax-table-text-property
10050 (error "I need to have a regexp marked!"))
10051 ;; Find the start
10052 (if (looking-at "\\s|")
10053 nil ; good already
10054 (if (or (looking-at "\\([smy]\\|qr|rx\\)\\s|") ; perl6: rx
10055 (and (eq (preceding-char) ?q)
10056 (looking-at "\\(r\\)\\s|")))
10057 (goto-char (match-end 1))
10058 (re-search-backward "\\s|"))) ; Assume it is scanned already.
10059 ;;(forward-char 1)
10060 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
10061 (sub-p (eq (preceding-char) ?s)) s)
10062 (forward-sexp 1)
10063 (set-marker e (1- (point)))
10064 (setq delim (preceding-char))
10065 (if (and sub-p (eq delim (char-after (- (point) 2))))
10066 (error "Possible s/blah// - do not know how to deal with"))
10067 (if sub-p (forward-sexp 1))
10068 (if (looking-at "\\sw*x")
10069 (setq have-x t)
10070 (insert "x"))
10071 ;; Protect fragile " ", "#"
10072 (if have-x nil
10073 (goto-char (1+ b))
10074 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
10075 (forward-char -1)
10076 (insert "\\")
10077 (forward-char 1)))
10078 b)))
10080 (defun cperl-beautify-regexp (&optional deep)
10081 "Do it. (Experimental, may change semantics, recheck the result.)
10082 We suppose that the regexp is scanned already."
10083 (interactive "P")
10084 (setq deep (if deep (prefix-numeric-value deep) -1))
10085 (save-excursion
10086 (goto-char (cperl-make-regexp-x))
10087 (let ((b (point)) (e (make-marker)))
10088 (forward-sexp 1)
10089 (set-marker e (1- (point)))
10090 (cperl-beautify-regexp-piece b e nil deep))))
10092 (defun cperl-regext-to-level-start ()
10093 "Goto start of an enclosing group in regexp.
10094 We suppose that the regexp is scanned already."
10095 (interactive)
10096 (let ((limit (cperl-make-regexp-x)) done)
10097 (while (not done)
10098 (or (eq (following-char) ?\()
10099 (search-backward "(" (1+ limit) t)
10100 (error "Cannot find `(' which starts a group"))
10101 (setq done
10102 (save-excursion
10103 (skip-chars-backward "\\")
10104 (looking-at "\\(\\\\\\\\\\)*(")))
10105 (or done (forward-char -1)))))
10107 (defun cperl-contract-level ()
10108 "Find an enclosing group in regexp and contract it.
10109 \(Experimental, may change semantics, recheck the result.)
10110 We suppose that the regexp is scanned already."
10111 (interactive)
10112 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
10113 (cperl-regext-to-level-start)
10114 (let ((b (point)) (e (make-marker)) c)
10115 (forward-sexp 1)
10116 (set-marker e (1- (point)))
10117 (goto-char b)
10118 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
10119 (cond
10120 ((match-beginning 1) ; #-comment
10121 (or c (setq c (current-indentation)))
10122 (beginning-of-line 2) ; Skip
10123 (cperl-make-indent c))
10125 (delete-char -1)
10126 (just-one-space))))))
10128 (defun cperl-contract-levels ()
10129 "Find an enclosing group in regexp and contract all the kids.
10130 \(Experimental, may change semantics, recheck the result.)
10131 We suppose that the regexp is scanned already."
10132 (interactive)
10133 (save-excursion
10134 (condition-case nil
10135 (cperl-regext-to-level-start)
10136 (error ; We are outside outermost group
10137 (goto-char (cperl-make-regexp-x))))
10138 (let ((b (point)) (e (make-marker)) s c)
10139 (forward-sexp 1)
10140 (set-marker e (1- (point)))
10141 (goto-char (1+ b))
10142 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
10143 (cond
10144 ((match-beginning 1) ; Skip
10145 nil)
10146 (t ; Group
10147 (cperl-contract-level)))))))
10149 (defun cperl-beautify-level (&optional deep)
10150 "Find an enclosing group in regexp and beautify it.
10151 \(Experimental, may change semantics, recheck the result.)
10152 We suppose that the regexp is scanned already."
10153 (interactive "P")
10154 (setq deep (if deep (prefix-numeric-value deep) -1))
10155 (save-excursion
10156 (cperl-regext-to-level-start)
10157 (let ((b (point)) (e (make-marker)))
10158 (forward-sexp 1)
10159 (set-marker e (1- (point)))
10160 (cperl-beautify-regexp-piece b e 'level deep))))
10162 (defun cperl-invert-if-unless-modifiers ()
10163 "Change `B if A;' into `if (A) {B}' etc if possible.
10164 \(Unfinished.)"
10165 (interactive) ;
10166 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string
10167 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>"))
10168 (and (= (char-syntax (preceding-char)) ?w)
10169 (forward-sexp -1))
10170 (setq pre-if (point))
10171 (cperl-backward-to-start-of-expr)
10172 (setq pre-B (point))
10173 (forward-sexp 1) ; otherwise forward-to-end-of-expr is NOP
10174 (cperl-forward-to-end-of-expr)
10175 (setq post-A (point))
10176 (goto-char pre-if)
10177 (or (looking-at w-rex)
10178 ;; Find the position
10179 (progn (goto-char post-A)
10180 (while (and
10181 (not (looking-at w-rex))
10182 (> (point) pre-B))
10183 (forward-sexp -1))
10184 (setq pre-if (point))))
10185 (or (looking-at w-rex)
10186 (error "Can't find `if', `unless', `while', `until', `for' or `foreach'"))
10187 ;; 1 B 2 ... 3 B-com ... 4 if 5 ... if-com 6 ... 7 A 8
10188 (setq if-string (buffer-substring (match-beginning 0) (match-end 0)))
10189 ;; First, simple part: find code boundaries
10190 (forward-sexp 1)
10191 (setq post-if (point))
10192 (forward-sexp -2)
10193 (forward-sexp 1)
10194 (setq post-B (point))
10195 (cperl-backward-to-start-of-expr)
10196 (setq pre-B (point))
10197 (setq B (buffer-substring pre-B post-B))
10198 (goto-char pre-if)
10199 (forward-sexp 2)
10200 (forward-sexp -1)
10201 ;; May be after $, @, $# etc of a variable
10202 (skip-chars-backward "$@%#")
10203 (setq pre-A (point))
10204 (cperl-forward-to-end-of-expr)
10205 (setq post-A (point))
10206 (setq A (buffer-substring pre-A post-A))
10207 ;; Now modify (from end, to not break the stuff)
10208 (skip-chars-forward " \t;")
10209 (delete-region pre-A (point)) ; we move to pre-A
10210 (insert "\n" B ";\n}")
10211 (and (looking-at "[ \t]*#") (cperl-indent-for-comment))
10212 (delete-region pre-if post-if)
10213 (delete-region pre-B post-B)
10214 (goto-char pre-B)
10215 (insert if-string " (" A ") {")
10216 (setq post-B (point))
10217 (if (looking-at "[ \t]+$")
10218 (delete-horizontal-space)
10219 (if (looking-at "[ \t]*#")
10220 (cperl-indent-for-comment)
10221 (just-one-space)))
10222 (forward-line 1)
10223 (if (looking-at "[ \t]*$")
10224 (progn ; delete line
10225 (delete-horizontal-space)
10226 (delete-region (point) (1+ (point)))))
10227 (cperl-indent-line)
10228 (goto-char (1- post-B))
10229 (forward-sexp 1)
10230 (cperl-indent-line)
10231 (goto-char pre-B)))
10233 (defun cperl-invert-if-unless ()
10234 "Change `if (A) {B}' into `B if A;' etc (or visa versa) if possible.
10235 If the cursor is not on the leading keyword of the BLOCK flavor of
10236 construct, will assume it is the STATEMENT flavor, so will try to find
10237 the appropriate statement modifier."
10238 (interactive)
10239 (and (= (char-syntax (preceding-char)) ?w)
10240 (forward-sexp -1))
10241 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
10242 (let ((pre-if (point))
10243 pre-A post-A pre-B post-B A B state p end-B-code is-block B-comment
10244 (if-string (buffer-substring (match-beginning 0) (match-end 0))))
10245 (forward-sexp 2)
10246 (setq post-A (point))
10247 (forward-sexp -1)
10248 (setq pre-A (point))
10249 (setq is-block (and (eq (following-char) ?\( )
10250 (save-excursion
10251 (condition-case nil
10252 (progn
10253 (forward-sexp 2)
10254 (forward-sexp -1)
10255 (eq (following-char) ?\{ ))
10256 (error nil)))))
10257 (if is-block
10258 (progn
10259 (goto-char post-A)
10260 (forward-sexp 1)
10261 (setq post-B (point))
10262 (forward-sexp -1)
10263 (setq pre-B (point))
10264 (if (and (eq (following-char) ?\{ )
10265 (progn
10266 (cperl-backward-to-noncomment post-A)
10267 (eq (preceding-char) ?\) )))
10268 (if (condition-case nil
10269 (progn
10270 (goto-char post-B)
10271 (forward-sexp 1)
10272 (forward-sexp -1)
10273 (looking-at "\\<els\\(e\\|if\\)\\>"))
10274 (error nil))
10275 (error
10276 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" if-string)
10277 (goto-char (1- post-B))
10278 (cperl-backward-to-noncomment pre-B)
10279 (if (eq (preceding-char) ?\;)
10280 (forward-char -1))
10281 (setq end-B-code (point))
10282 (goto-char pre-B)
10283 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" end-B-code t)
10284 (setq p (match-beginning 0)
10285 A (buffer-substring p (match-end 0))
10286 state (parse-partial-sexp pre-B p))
10287 (or (nth 3 state)
10288 (nth 4 state)
10289 (nth 5 state)
10290 (error "`%s' inside `%s' BLOCK" A if-string))
10291 (goto-char (match-end 0)))
10292 ;; Finally got it
10293 (goto-char (1+ pre-B))
10294 (skip-chars-forward " \t\n")
10295 (setq B (buffer-substring (point) end-B-code))
10296 (goto-char end-B-code)
10297 (or (looking-at ";?[ \t\n]*}")
10298 (progn
10299 (skip-chars-forward "; \t\n")
10300 (setq B-comment
10301 (buffer-substring (point) (1- post-B)))))
10302 (and (equal B "")
10303 (setq B "1"))
10304 (goto-char (1- post-A))
10305 (cperl-backward-to-noncomment pre-A)
10306 (or (looking-at "[ \t\n]*)")
10307 (goto-char (1- post-A)))
10308 (setq p (point))
10309 (goto-char (1+ pre-A))
10310 (skip-chars-forward " \t\n")
10311 (setq A (buffer-substring (point) p))
10312 (delete-region pre-B post-B)
10313 (delete-region pre-A post-A)
10314 (goto-char pre-if)
10315 (insert B " ")
10316 (and B-comment (insert B-comment " "))
10317 (just-one-space)
10318 (forward-word 1)
10319 (setq pre-A (point))
10320 (insert " " A ";")
10321 (delete-horizontal-space)
10322 (setq post-B (point))
10323 (if (looking-at "#")
10324 (indent-for-comment))
10325 (goto-char post-B)
10326 (forward-char -1)
10327 (delete-horizontal-space)
10328 (goto-char pre-A)
10329 (just-one-space)
10330 (goto-char pre-if)
10331 (setq pre-A (set-marker (make-marker) pre-A))
10332 (while (<= (point) (marker-position pre-A))
10333 (cperl-indent-line)
10334 (forward-line 1))
10335 (goto-char (marker-position pre-A))
10336 (if B-comment
10337 (progn
10338 (forward-line -1)
10339 (indent-for-comment)
10340 (goto-char (marker-position pre-A)))))
10341 (error "`%s' (EXPR) not with an {BLOCK}" if-string)))
10342 ;; (error "`%s' not with an (EXPR)" if-string)
10343 (forward-sexp -1)
10344 (cperl-invert-if-unless-modifiers)))
10345 ;;(error "Not at `if', `unless', `while', `until', `for' or `foreach'")
10346 (cperl-invert-if-unless-modifiers)))
10348 ;;; By Anthony Foiani <afoiani@uswest.com>
10349 ;;; Getting help on modules in C-h f ?
10350 ;;; This is a modified version of `man'.
10351 ;;; Need to teach it how to lookup functions
10352 ;;;###autoload
10353 (defun cperl-perldoc (word)
10354 "Run `perldoc' on WORD."
10355 (interactive
10356 (list (let* ((default-entry (cperl-word-at-point))
10357 (input (read-string
10358 (format "perldoc entry%s: "
10359 (if (string= default-entry "")
10361 (format " (default %s)" default-entry))))))
10362 (if (string= input "")
10363 (if (string= default-entry "")
10364 (error "No perldoc args given")
10365 default-entry)
10366 input))))
10367 (require 'man)
10368 (let* ((case-fold-search nil)
10369 (is-func (and
10370 (string-match "^[a-z]+$" word)
10371 (string-match (concat "^" word "\\>")
10372 (documentation-property
10373 'cperl-short-docs
10374 'variable-documentation))))
10375 (Man-switches "")
10376 (manual-program (if is-func "perldoc -f" "perldoc")))
10377 (cond
10378 (cperl-xemacs-p
10379 (let ((Manual-program "perldoc")
10380 (Manual-switches (if is-func (list "-f"))))
10381 (manual-entry word)))
10383 (Man-getpage-in-background word))))) ; uses `Man-switches'
10385 ;;;###autoload
10386 (defun cperl-perldoc-at-point ()
10387 "Run a `perldoc' on the word around point."
10388 (interactive)
10389 (cperl-perldoc (cperl-word-at-point)))
10391 (defcustom pod2man-program "pod2man"
10392 "*File name for `pod2man'."
10393 :type 'file
10394 :group 'cperl)
10396 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
10397 (defun cperl-pod-to-manpage ()
10398 "Create a virtual manpage in Emacs from the Perl Online Documentation."
10399 (interactive)
10400 (require 'man)
10401 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
10402 (bufname (concat "Man " buffer-file-name))
10403 (buffer (generate-new-buffer bufname)))
10404 (save-excursion
10405 (set-buffer buffer)
10406 (let ((process-environment (copy-sequence process-environment)))
10407 ;; Prevent any attempt to use display terminal fanciness.
10408 (setenv "TERM" "dumb")
10409 (set-process-sentinel
10410 (start-process pod2man-program buffer "sh" "-c"
10411 (format (cperl-pod2man-build-command) pod2man-args))
10412 'Man-bgproc-sentinel)))))
10414 ;;; Updated version by him too
10415 (defun cperl-build-manpage ()
10416 "Create a virtual manpage in Emacs from the POD in the file."
10417 (interactive)
10418 (require 'man)
10419 (cond
10420 (cperl-xemacs-p
10421 (let ((Manual-program "perldoc"))
10422 (manual-entry buffer-file-name)))
10424 (let* ((manual-program "perldoc")
10425 (Man-switches ""))
10426 (Man-getpage-in-background buffer-file-name)))))
10428 (defun cperl-pod2man-build-command ()
10429 "Builds the entire background manpage and cleaning command."
10430 (let ((command (concat pod2man-program " %s 2>/dev/null"))
10431 (flist (and (boundp 'Man-filter-list) Man-filter-list)))
10432 (while (and flist (car flist))
10433 (let ((pcom (car (car flist)))
10434 (pargs (cdr (car flist))))
10435 (setq command
10436 (concat command " | " pcom " "
10437 (mapconcat '(lambda (phrase)
10438 (if (not (stringp phrase))
10439 (error "Malformed Man-filter-list"))
10440 phrase)
10441 pargs " ")))
10442 (setq flist (cdr flist))))
10443 command))
10446 (defun cperl-next-interpolated-REx-1 ()
10447 "Move point to next REx which has interpolated parts without //o.
10448 Skips RExes consisting of one interpolated variable.
10450 Note that skipped RExen are not performance hits."
10451 (interactive "")
10452 (cperl-next-interpolated-REx 1))
10454 (defun cperl-next-interpolated-REx-0 ()
10455 "Move point to next REx which has interpolated parts without //o."
10456 (interactive "")
10457 (cperl-next-interpolated-REx 0))
10459 (defun cperl-next-interpolated-REx (&optional skip beg limit)
10460 "Move point to next REx which has interpolated parts.
10461 SKIP is a list of possible types to skip, BEG and LIMIT are the starting
10462 point and the limit of search (default to point and end of buffer).
10464 SKIP may be a number, then it behaves as list of numbers up to SKIP; this
10465 semantic may be used as a numeric argument.
10467 Types are 0 for / $rex /o (interpolated once), 1 for /$rex/ (if $rex is
10468 a result of qr//, this is not a performance hit), t for the rest."
10469 (interactive "P")
10470 (if (numberp skip) (setq skip (list 0 skip)))
10471 (or beg (setq beg (point)))
10472 (or limit (setq limit (point-max))) ; needed for n-s-p-c
10473 (let (pp)
10474 (and (eq (get-text-property beg 'syntax-type) 'string)
10475 (setq beg (next-single-property-change beg 'syntax-type nil limit)))
10476 (cperl-map-pods-heres
10477 (function (lambda (s e p)
10478 (if (memq (get-text-property s 'REx-interpolated) skip)
10480 (setq pp s)
10481 nil))) ; nil stops
10482 'REx-interpolated beg limit)
10483 (if pp (goto-char pp)
10484 (message "No more interpolated REx"))))
10486 ;;; Initial version contributed by Trey Belew
10487 (defun cperl-here-doc-spell (&optional beg end)
10488 "Spell-check HERE-documents in the Perl buffer.
10489 If a region is highlighted, restricts to the region."
10490 (interactive "")
10491 (cperl-pod-spell t beg end))
10493 (defun cperl-pod-spell (&optional do-heres beg end)
10494 "Spell-check POD documentation.
10495 If invoked with prefix argument, will do HERE-DOCs instead.
10496 If a region is highlighted, restricts to the region."
10497 (interactive "P")
10498 (save-excursion
10499 (let (beg end)
10500 (if (cperl-mark-active)
10501 (setq beg (min (mark) (point))
10502 end (max (mark) (point)))
10503 (setq beg (point-min)
10504 end (point-max)))
10505 (cperl-map-pods-heres (function
10506 (lambda (s e p)
10507 (if do-heres
10508 (setq e (save-excursion
10509 (goto-char e)
10510 (forward-line -1)
10511 (point))))
10512 (ispell-region s e)
10514 (if do-heres 'here-doc-group 'in-pod)
10515 beg end))))
10517 (defun cperl-map-pods-heres (func &optional prop s end)
10518 "Executes a function over regions of pods or here-documents.
10519 PROP is the text-property to search for; default to `in-pod'. Stop when
10520 function returns nil."
10521 (let (pos posend has-prop (cont t))
10522 (or prop (setq prop 'in-pod))
10523 (or s (setq s (point-min)))
10524 (or end (setq end (point-max)))
10525 (cperl-update-syntaxification end end)
10526 (save-excursion
10527 (goto-char (setq pos s))
10528 (while (and cont (< pos end))
10529 (setq has-prop (get-text-property pos prop))
10530 (setq posend (next-single-property-change pos prop nil end))
10531 (and has-prop
10532 (setq cont (funcall func pos posend prop)))
10533 (setq pos posend)))))
10535 ;;; Based on code by Masatake YAMATO:
10536 (defun cperl-get-here-doc-region (&optional pos pod)
10537 "Return HERE document region around the point.
10538 Return nil if the point is not in a HERE document region. If POD is non-nil,
10539 will return a POD section if point is in a POD section."
10540 (or pos (setq pos (point)))
10541 (cperl-update-syntaxification pos pos)
10542 (if (or (eq 'here-doc (get-text-property pos 'syntax-type))
10543 (and pod
10544 (eq 'pod (get-text-property pos 'syntax-type))))
10545 (let ((b (cperl-beginning-of-property pos 'syntax-type))
10546 (e (next-single-property-change pos 'syntax-type)))
10547 (cons b (or e (point-max))))))
10549 (defun cperl-narrow-to-here-doc (&optional pos)
10550 "Narrows editing region to the HERE-DOC at POS.
10551 POS defaults to the point."
10552 (interactive "d")
10553 (or pos (setq pos (point)))
10554 (let ((p (cperl-get-here-doc-region pos)))
10555 (or p (error "Not inside a HERE document"))
10556 (narrow-to-region (car p) (cdr p))
10557 (message
10558 "When you are finished with narrow editing, type C-x n w")))
10560 (defun cperl-select-this-pod-or-here-doc (&optional pos)
10561 "Select the HERE-DOC (or POD section) at POS.
10562 POS defaults to the point."
10563 (interactive "d")
10564 (let ((p (cperl-get-here-doc-region pos t)))
10565 (if p
10566 (progn
10567 (goto-char (car p))
10568 (push-mark (cdr p) nil t)) ; Message, activate in transient-mode
10569 (message "I do not think POS is in POD or a HERE-doc..."))))
10571 (defun cperl-facemenu-add-face-function (face end)
10572 "A callback to process user-initiated font-change requests.
10573 Translates `bold', `italic', and `bold-italic' requests to insertion of
10574 corresponding POD directives, and `underline' to C<> POD directive.
10576 Such requests are usually bound to M-o LETTER."
10577 (or (get-text-property (point) 'in-pod)
10578 (error "Faces can only be set within POD"))
10579 (setq facemenu-end-add-face (if (eq face 'bold-italic) ">>" ">"))
10580 (cdr (or (assq face '((bold . "B<")
10581 (italic . "I<")
10582 (bold-italic . "B<I<")
10583 (underline . "C<")))
10584 (error "Face %s not configured for cperl-mode"
10585 face))))
10587 (defun cperl-time-fontification (&optional l step lim)
10588 "Times how long it takes to do incremental fontification in a region.
10589 L is the line to start at, STEP is the number of lines to skip when
10590 doing next incremental fontification, LIM is the maximal number of
10591 incremental fontification to perform. Messages are accumulated in
10592 *Messages* buffer.
10594 May be used for pinpointing which construct slows down buffer fontification:
10595 start with default arguments, then refine the slowdown regions."
10596 (interactive "nLine to start at: \nnStep to do incremental fontification: ")
10597 (or l (setq l 1))
10598 (or step (setq step 500))
10599 (or lim (setq lim 40))
10600 (let* ((timems (function (lambda ()
10601 (let ((tt (current-time)))
10602 (+ (* 1000 (nth 1 tt)) (/ (nth 2 tt) 1000))))))
10603 (tt (funcall timems)) (c 0) delta tot)
10604 (goto-line l)
10605 (cperl-mode)
10606 (setq tot (- (- tt (setq tt (funcall timems)))))
10607 (message "cperl-mode at %s: %s" l tot)
10608 (while (and (< c lim) (not (eobp)))
10609 (forward-line step)
10610 (setq l (+ l step))
10611 (setq c (1+ c))
10612 (cperl-update-syntaxification (point) (point))
10613 (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
10614 (message "to %s:%6s,%7s" l delta tot))
10615 tot))
10617 (defun cperl-emulate-lazy-lock (&optional window-size)
10618 "Emulate `lazy-lock' without `condition-case', so `debug-on-error' works.
10619 Start fontifying the buffer from the start (or end) using the given
10620 WINDOW-SIZE (units is lines). Negative WINDOW-SIZE starts at end, and
10621 goes backwards; default is -50. This function is not CPerl-specific; it
10622 may be used to debug problems with delayed incremental fontification."
10623 (interactive
10624 "nSize of window for incremental fontification, negative goes backwards: ")
10625 (or window-size (setq window-size -50))
10626 (let ((pos (if (> window-size 0)
10627 (point-min)
10628 (point-max)))
10630 (goto-char pos)
10631 (normal-mode)
10632 ;; Why needed??? With older font-locks???
10633 (set (make-local-variable 'font-lock-cache-position) (make-marker))
10634 (while (if (> window-size 0)
10635 (< pos (point-max))
10636 (> pos (point-min)))
10637 (setq p (progn
10638 (forward-line window-size)
10639 (point)))
10640 (font-lock-fontify-region (min p pos) (max p pos))
10641 (setq pos p))))
10644 (defun cperl-lazy-install ()) ; Avoid a warning
10645 (defun cperl-lazy-unstall ()) ; Avoid a warning
10647 (if (fboundp 'run-with-idle-timer)
10648 (progn
10649 (defvar cperl-help-shown nil
10650 "Non-nil means that the help was already shown now.")
10652 (defvar cperl-lazy-installed nil
10653 "Non-nil means that the lazy-help handlers are installed now.")
10655 (defun cperl-lazy-install ()
10656 "Switches on Auto-Help on Perl constructs (put in the message area).
10657 Delay of auto-help controlled by `cperl-lazy-help-time'."
10658 (interactive)
10659 (make-variable-buffer-local 'cperl-help-shown)
10660 (if (and (cperl-val 'cperl-lazy-help-time)
10661 (not cperl-lazy-installed))
10662 (progn
10663 (add-hook 'post-command-hook 'cperl-lazy-hook)
10664 (run-with-idle-timer
10665 (cperl-val 'cperl-lazy-help-time 1000000 5)
10667 'cperl-get-help-defer)
10668 (setq cperl-lazy-installed t))))
10670 (defun cperl-lazy-unstall ()
10671 "Switches off Auto-Help on Perl constructs (put in the message area).
10672 Delay of auto-help controlled by `cperl-lazy-help-time'."
10673 (interactive)
10674 (remove-hook 'post-command-hook 'cperl-lazy-hook)
10675 (cancel-function-timers 'cperl-get-help-defer)
10676 (setq cperl-lazy-installed nil))
10678 (defun cperl-lazy-hook ()
10679 (setq cperl-help-shown nil))
10681 (defun cperl-get-help-defer ()
10682 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
10683 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
10684 (cperl-get-help)
10685 (setq cperl-help-shown t))))
10686 (cperl-lazy-install)))
10689 ;;; Plug for wrong font-lock:
10691 (defun cperl-font-lock-unfontify-region-function (beg end)
10692 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
10693 (inhibit-read-only t) (inhibit-point-motion-hooks t)
10694 before-change-functions after-change-functions
10695 deactivate-mark buffer-file-name buffer-file-truename)
10696 (remove-text-properties beg end '(face nil))
10697 (if (and (not modified) (buffer-modified-p))
10698 (set-buffer-modified-p nil))))
10700 (defun cperl-font-lock-fontify-region-function (beg end loudly)
10701 "Extends the region to safe positions, then calls the default function.
10702 Newer `font-lock's can do it themselves.
10703 We unwind only as far as needed for fontification. Syntaxification may
10704 do extra unwind via `cperl-unwind-to-safe'."
10705 (save-excursion
10706 (goto-char beg)
10707 (while (and beg
10708 (progn
10709 (beginning-of-line)
10710 (eq (get-text-property (setq beg (point)) 'syntax-type)
10711 'multiline)))
10712 (if (setq beg (cperl-beginning-of-property beg 'syntax-type))
10713 (goto-char beg)))
10714 (setq beg (point))
10715 (goto-char end)
10716 (while (and end
10717 (progn
10718 (or (bolp) (condition-case nil
10719 (forward-line 1)
10720 (error nil)))
10721 (eq (get-text-property (setq end (point)) 'syntax-type)
10722 'multiline)))
10723 (setq end (next-single-property-change end 'syntax-type nil (point-max)))
10724 (goto-char end))
10725 (setq end (point)))
10726 (font-lock-default-fontify-region beg end loudly))
10728 (defvar cperl-d-l nil)
10729 (defun cperl-fontify-syntaxically (end)
10730 ;; Some vars for debugging only
10731 ;; (message "Syntaxifying...")
10732 (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
10733 (istate (car cperl-syntax-state))
10734 start from-start edebug-backtrace-buffer)
10735 (if (eq cperl-syntaxify-by-font-lock 'backtrace)
10736 (progn
10737 (require 'edebug)
10738 (let ((f 'edebug-backtrace))
10739 (funcall f)))) ; Avoid compile-time warning
10740 (or cperl-syntax-done-to
10741 (setq cperl-syntax-done-to (point-min)
10742 from-start t))
10743 (setq start (if (and cperl-hook-after-change
10744 (not from-start))
10745 cperl-syntax-done-to ; Fontify without change; ignore start
10746 ;; Need to forget what is after `start'
10747 (min cperl-syntax-done-to (point))))
10748 (goto-char start)
10749 (beginning-of-line)
10750 (setq start (point))
10751 (and cperl-syntaxify-unwind
10752 (setq end (cperl-unwind-to-safe t end)
10753 start (point)))
10754 (and (> end start)
10755 (setq cperl-syntax-done-to start) ; In case what follows fails
10756 (cperl-find-pods-heres start end t nil t))
10757 (if (memq cperl-syntaxify-by-font-lock '(backtrace message))
10758 (message "Syxify req=%s..%s actual=%s..%s done-to: %s=>%s statepos: %s=>%s"
10759 dbg iend start end idone cperl-syntax-done-to
10760 istate (car cperl-syntax-state))) ; For debugging
10761 nil)) ; Do not iterate
10763 (defun cperl-fontify-update (end)
10764 (let ((pos (point-min)) prop posend)
10765 (setq end (point-max))
10766 (while (< pos end)
10767 (setq prop (get-text-property pos 'cperl-postpone)
10768 posend (next-single-property-change pos 'cperl-postpone nil end))
10769 (and prop (put-text-property pos posend (car prop) (cdr prop)))
10770 (setq pos posend)))
10771 nil) ; Do not iterate
10773 (defun cperl-fontify-update-bad (end)
10774 ;; Since fontification happens with different region than syntaxification,
10775 ;; do to the end of buffer, not to END;;; likewise, start earlier if needed
10776 (let* ((pos (point)) (prop (get-text-property pos 'cperl-postpone)) posend)
10777 (if prop
10778 (setq pos (or (cperl-beginning-of-property
10779 (cperl-1+ pos) 'cperl-postpone)
10780 (point-min))))
10781 (while (< pos end)
10782 (setq posend (next-single-property-change pos 'cperl-postpone))
10783 (and prop (put-text-property pos posend (car prop) (cdr prop)))
10784 (setq pos posend)
10785 (setq prop (get-text-property pos 'cperl-postpone))))
10786 nil) ; Do not iterate
10788 ;; Called when any modification is made to buffer text.
10789 (defun cperl-after-change-function (beg end old-len)
10790 ;; We should have been informed about changes by `font-lock'. Since it
10791 ;; does not inform as which calls are defered, do it ourselves
10792 (if cperl-syntax-done-to
10793 (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
10795 (defun cperl-update-syntaxification (from to)
10796 (if (and cperl-use-syntax-table-text-property
10797 cperl-syntaxify-by-font-lock
10798 (or (null cperl-syntax-done-to)
10799 (< cperl-syntax-done-to to)))
10800 (progn
10801 (save-excursion
10802 (goto-char from)
10803 (cperl-fontify-syntaxically to)))))
10805 (defvar cperl-version
10806 (let ((v "Revision: 6.2-Pugs/Github "))
10807 (string-match ":\\s *\\([-/0-9a-z.]+\\)" v)
10808 (substring v (match-beginning 1) (match-end 1)))
10809 "Version of IZ-supported CPerl package this file is based on.")
10811 (if cperl-xemacs-p ;; backwards compatibility for XEmacs old POD spelling stuff
10812 (let ((f 'define-obsolete-function-alias))
10813 (funcall f 'pod-spell 'cperl-pod-spell))) ; Avoid "not defined"
10815 ;; XEmacs additions
10816 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.\\([pP][LlMm6]6?\\|al\\)\\'" . perl-mode))
10817 ;;;###autoload(add-to-list 'interpreter-mode-alist '("perl" . perl-mode))
10819 (provide 'cperl-mode)
10821 ;;; cperl-mode.el ends here