1 ;;; cperl-mode.el --- Perl code editing commands for Emacs
3 ;;;; The following message is relative to GNU version of the module:
5 ;; Copyright (C) 1985, 86, 87, 91, 92, 93, 94, 95, 96, 1997
6 ;; Free Software Foundation, Inc.
8 ;; Author: Ilya Zakharevich and Bob Olson
9 ;; Maintainer: Ilya Zakharevich <ilya@math.ohio-state.edu>
10 ;; Keywords: languages, Perl
12 ;; This file is part of GNU Emacs.
14 ;;; This code started from the following message of long time ago
15 ;;; (IZ), but Bob does not maintain this mode any more:
17 ;;; From: olson@mcs.anl.gov (Bob Olson)
18 ;;; Newsgroups: comp.lang.perl
19 ;;; Subject: cperl-mode: Another perl mode for Gnuemacs
20 ;;; Date: 14 Aug 91 15:20:01 GMT
22 ;; Copyright (C) Ilya Zakharevich and Bob Olson
24 ;; This file may be distributed
25 ;; either under the same terms as GNU Emacs, or under the same terms
26 ;; as Perl. You should have received a copy of Perl Artistic license
27 ;; along with the Perl distribution.
29 ;; GNU Emacs is free software; you can redistribute it and/or modify
30 ;; it under the terms of the GNU General Public License as published by
31 ;; the Free Software Foundation; either version 2, or (at your option)
34 ;; GNU Emacs is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ;; GNU General Public License for more details.
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with GNU Emacs; see the file COPYING. If not, write to the
41 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
42 ;; Boston, MA 02111-1307, USA.
44 ;;; Corrections made by Ilya Zakharevich ilya@math.mps.ohio-state.edu
45 ;;; XEmacs changes by Peter Arius arius@informatik.uni-erlangen.de
49 ;; $Id: cperl-mode.el,v 4.19 1998/12/10 03:31:23 ilya Exp ilya $
51 ;;; Before RMS Emacs 20.3: To use this mode put the following into
54 ;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)
56 ;;; You can either fine-tune the bells and whistles of this mode or
57 ;;; bulk enable them by putting
59 ;; (setq cperl-hairy t)
61 ;;; in your .emacs file. (Emacs rulers do not consider it politically
62 ;;; correct to make whistles enabled by default.)
64 ;;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
65 ;;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
66 ;;; `cperl-non-problems', `cperl-praise', `cperl-speed'. <<<<<<
68 ;;; Additional useful commands to put into your .emacs file (before
71 ;; (setq auto-mode-alist
72 ;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
73 ;; (setq interpreter-mode-alist (append interpreter-mode-alist
74 ;; '(("miniperl" . perl-mode))))
76 ;;; The mode information (on C-h m) provides some customization help.
77 ;;; If you use font-lock feature of this mode, it is advisable to use
78 ;;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
80 ;;; Faces used now: three faces for first-class and second-class keywords
81 ;;; and control flow words, one for each: comments, string, labels,
82 ;;; functions definitions and packages, arrays, hashes, and variable
83 ;;; definitions. If you do not see all these faces, your font-lock does
84 ;;; not define them, so you need to define them manually. Maybe you have
85 ;;; an obsolete font-lock from 19.28 or earlier. Upgrade.
87 ;;; If you have a grayscale monitor, and do not have the variable
88 ;;; font-lock-display-type bound to 'grayscale, insert
90 ;;; (setq font-lock-display-type 'grayscale)
92 ;;; into your .emacs file (this is relevant before RMS Emacs 20).
94 ;;;; This mode supports font-lock, imenu and mode-compile. In the
95 ;;;; hairy version font-lock is on, but you should activate imenu
96 ;;;; yourself (note that mode-compile is not standard yet). Well, you
97 ;;;; can use imenu from keyboard anyway (M-x imenu), but it is better
98 ;;;; to bind it like that:
100 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
102 ;;; In fact the version of font-lock that this version supports can be
103 ;;; much newer than the version you actually have. This means that a
104 ;;; lot of faces can be set up, but are not visible on your screen
105 ;;; since the coloring rules for this faces are not defined.
107 ;;; Updates: ========================================
109 ;;; Made less hairy by default: parentheses not electric,
110 ;;; linefeed not magic. Bug with abbrev-mode corrected.
113 ;;; Better indentation:
114 ;;; subs inside braces should work now,
115 ;;; Toplevel braces obey customization.
116 ;;; indent-for-comment knows about bad cases, cperl-indent-for-comment
117 ;;; moves cursor to a correct place.
118 ;;; cperl-indent-exp written from the scratch! Slow... (quadratic!) :-(
119 ;;; (50 secs on DB::DB (sub of 430 lines), 486/66)
120 ;;; Minor documentation fixes.
121 ;;; Imenu understands packages as prefixes (including nested).
122 ;;; Hairy options can be switched off one-by-one by setting to null.
123 ;;; Names of functions and variables changed to conform to `cperl-' style.
126 ;;; Some bugs with indentation of labels (and embedded subs) corrected.
127 ;;; `cperl-indent-region' done (slow :-()).
128 ;;; `cperl-fill-paragraph' done.
129 ;;; Better package support for `imenu'.
130 ;;; Progress indicator for indentation (with `imenu' loaded).
131 ;;; `Cperl-set' was busted, now setting the individual hairy option
132 ;;; should be better.
135 ;;; `cperl-set-style' done.
136 ;;; `cperl-check-syntax' done.
138 ;;; New config variables `cperl-close-paren-offset' and `cperl-comment-column'.
139 ;;; Bugs with `cperl-auto-newline' corrected.
140 ;;; `cperl-electric-lbrace' can work with `cperl-auto-newline' in situation
143 ;;;; 1.7 XEmacs (arius@informatik.uni-erlangen.de):
144 ;;; - use `next-command-event', if `next-command-events' does not exist
145 ;;; - use `find-face' as def. of `is-face'
146 ;;; - corrected def. of `x-color-defined-p'
147 ;;; - added const defs for font-lock-comment-face,
148 ;;; font-lock-keyword-face and font-lock-function-name-face
149 ;;; - added def. of font-lock-variable-name-face
150 ;;; - added (require 'easymenu) inside an `eval-when-compile'
151 ;;; - replaced 4-argument `substitute-key-definition' with ordinary
153 ;;; - replaced `mark-active' in menu definition by `cperl-use-region-p'.
155 ;;; - use emacs-vers.el (http://www.cs.utah.edu/~eeide/emacs/emacs-vers.el.gz)
156 ;;; for portable code?
157 ;;; - should `cperl-mode' do a
158 ;;; (if (featurep 'easymenu) (easy-menu-add cperl-menu))
159 ;;; or should this be left to the user's `cperl-mode-hook'?
161 ;;; Some bugs introduced by the above fix corrected (IZ ;-).
162 ;;; Some bugs under XEmacs introduced by the correction corrected.
164 ;;; Some more can remain since there are two many different variants.
167 ;;; We do not support fontification of arrays and hashes under
168 ;;; obsolete font-lock any more. Upgrade.
170 ;;;; after 1.8 Minor bug with parentheses.
171 ;;;; after 1.9 Improvements from Joe Marzot.
173 ;;; Does not need easymenu to compile under XEmacs.
174 ;;; `vc-insert-headers' should work better.
175 ;;; Should work with 19.29 and 19.12.
176 ;;; Small improvements to fontification.
177 ;;; Expansion of keywords does not depend on C-? being backspace.
180 ;;; 19.29 and 19.12 supported.
181 ;;; `cperl-font-lock-enhanced' deprecated. Use font-lock-extra.el.
182 ;;; Support for font-lock-extra.el.
186 ;;; Support for perl5-info.
187 ;;; `imenu-go-find-at-position' in Tools requires imenu-go.el (see hints above)
188 ;;; Imenu entries do not work with stock imenu.el. Patch sent to maintainers.
189 ;;; Fontifies `require a if b;', __DATA__.
190 ;;; Arglist for auto-fill-mode was incorrect.
193 ;;; `cperl-lineup-step' and `cperl-lineup' added: lineup constructions
195 ;;; `cperl-do-auto-fill' updated for 19.29 style.
196 ;;; `cperl-info-on-command' now has a default.
197 ;;; Workaround for broken C-h on XEmacs.
198 ;;; VC strings escaped.
199 ;;; C-h f now may prompt for function name instead of going on,
200 ;;; controlled by `cperl-info-on-command-no-prompt'.
203 ;;; Msb buffer list includes perl files
204 ;;; Indent-for-comment uses indent-to
205 ;;; Can write tag files using etags.
208 ;;; Recognizes (tries to ;-) {...} which are not blocks during indentation.
209 ;;; `cperl-close-paren-offset' affects ?\] too (and ?\} if not block)
210 ;;; Bug with auto-filling comments started with "##" corrected.
212 ;;;; Very slow now: on DB::DB 0.91, 486/66:
214 ;;;Function Name Call Count Elapsed Time Average Time
215 ;;;======================================== ========== ============ ============
216 ;;;cperl-block-p 469 3.7799999999 0.0080597014
217 ;;;cperl-get-state 505 163.39000000 0.3235445544
218 ;;;cperl-comment-indent 12 0.0299999999 0.0024999999
219 ;;;cperl-backward-to-noncomment 939 4.4599999999 0.0047497337
220 ;;;cperl-calculate-indent 505 172.22000000 0.3410297029
221 ;;;cperl-indent-line 505 172.88000000 0.3423366336
222 ;;;cperl-use-region-p 40 0.0299999999 0.0007499999
223 ;;;cperl-indent-exp 1 177.97000000 177.97000000
224 ;;;cperl-to-comment-or-eol 1453 3.9800000000 0.0027391603
225 ;;;cperl-backward-to-start-of-continued-exp 9 0.0300000000 0.0033333333
226 ;;;cperl-indent-region 1 177.94000000 177.94000000
229 ;;; Takes into account white space after opening parentheses during indent.
230 ;;; May highlight pods and here-documents: see `cperl-pod-here-scan',
231 ;;; `cperl-pod-here-fontify', `cperl-pod-face'. Does not use this info
232 ;;; for indentation so far.
233 ;;; Fontification updated to 19.30 style.
234 ;;; The change 19.29->30 did not add all the required functionality,
235 ;;; but broke "font-lock-extra.el". Get "choose-color.el" from
236 ;;; ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs
240 ;;; recognized as a start of a block.
241 ;;; Two different font-lock-levels provided.
242 ;;; `cperl-pod-head-face' introduced. Used for highlighting.
243 ;;; `imenu' marks pods, +Packages moved to the head.
246 ;;; Scan for pods highlights here-docs too.
247 ;;; Note that the tag of here-doc may be rehighlighted later by lazy-lock.
248 ;;; Only one here-doc-tag per line is supported, and one in comment
249 ;;; or a string may break fontification.
250 ;;; POD headers were supposed to fill one line only.
253 ;;; `font-lock-keywords' were set in 19.30 style _always_. Current scheme
254 ;;; may break under XEmacs.
255 ;;; `cperl-calculate-indent' dis suppose that `parse-start' was defined.
256 ;;; `fontified' tag is added to fontified text as well as `lazy-lock' (for
257 ;;; compatibility with older lazy-lock.el) (older one overfontifies
258 ;;; something nevertheless :-().
259 ;;; Will not indent something inside pod and here-documents.
260 ;;; Fontifies the package name after import/no/bootstrap.
261 ;;; Added new entry to menu with meta-info about the mode.
264 ;;; Prefontification works much better with 19.29. Should be checked
265 ;;; with 19.30 as well.
266 ;;; Some misprints in docs corrected.
267 ;;; Now $a{-text} and -text => "blah" are fontified as strings too.
268 ;;; Now the pod search is much stricter, so it can help you to find
269 ;;; pod sections which are broken because of whitespace before =blah
270 ;;; - just observe the fontification.
273 ;;; Anonymous subs are indented with respect to the level of
274 ;;; indentation of `sub' now.
275 ;;; {} is recognized as hash after `bless' and `return'.
276 ;;; Anonymous subs are split by `cperl-linefeed' as well.
277 ;;; Electric parens embrace a region if present.
278 ;;; To make `cperl-auto-newline' useful,
279 ;;; `cperl-auto-newline-after-colon' is introduced.
280 ;;; `cperl-electric-parens' is now t or nul. The old meaning is moved to
281 ;;; `cperl-electric-parens-string'.
282 ;;; `cperl-toggle-auto-newline' introduced, put on C-c C-a.
283 ;;; `cperl-toggle-abbrev' introduced, put on C-c C-k.
284 ;;; `cperl-toggle-electric' introduced, put on C-c C-e.
285 ;;; Beginning-of-defun-regexp was not anchored.
288 ;;; Auto-newline grants `cperl-extra-newline-before-brace' if "{" is typed
290 ;;; {} is recognized as expression after `tr' and friends.
293 ;;; Entry Hierarchy added to imenu. Very primitive so far.
294 ;;; One needs newer `imenu-go'.el. A patch to `imenu' is needed as well.
295 ;;; Writes its own TAGS files.
296 ;;; Class viewer based on TAGS files. Does not trace @ISA so far.
297 ;;; 19.31: Problems with scan for PODs corrected.
298 ;;; First POD header correctly fontified.
299 ;;; I needed (setq imenu-use-keymap-menu t) to get good imenu in 19.31.
300 ;;; Apparently it makes a lot of hierarchy code obsolete...
303 ;;; Tags filler now scans *.xs as well.
304 ;;; The info from *.xs scan is used by the hierarchy viewer.
305 ;;; Hierarchy viewer documented.
306 ;;; Bug in 19.31 imenu documented.
309 ;;; New location for info-files mentioned,
310 ;;; Electric-; should work better.
311 ;;; Minor bugs with POD marking.
313 ;;;; After 1.25 (probably not...)
314 ;;; `cperl-info-page' introduced.
315 ;;; To make `uncomment-region' working, `comment-region' would
316 ;;; not insert extra space.
317 ;;; Here documents delimiters better recognized
318 ;;; (empty one, and non-alphanums in quotes handled). May be wrong with 1<<14?
319 ;;; `cperl-db' added, used in menu.
320 ;;; imenu scan removes text-properties, for better debugging
321 ;;; - but the bug is in 19.31 imenu.
322 ;;; formats highlighted by font-lock and prescan, embedded comments
324 ;;; POD/friends scan merged in one pass.
325 ;;; Syntax class is not used for analyzing the code, only char-syntax
326 ;;; may be checked against _ or'ed with w.
327 ;;; Syntax class of `:' changed to be _.
328 ;;; `cperl-find-bad-style' added.
331 ;;; When search for here-documents, we ignore commented << in simplest cases.
332 ;;; `cperl-get-help' added, available on C-h v and from menu.
333 ;;; Auto-help added. Default with `cperl-hairy', switchable on/off
334 ;;; with startup variable `cperl-lazy-help-time' and from
335 ;;; menu. Requires `run-with-idle-timer'.
336 ;;; Highlighting of @abc{@efg} was wrong - interchanged two regexps.
339 ;;; Indentation: At toplevel after a label - fixed.
340 ;;; 1.27 was put to archives in binary mode ===> DOSish :-(
343 ;;; Thanks to Martin Buchholz <mrb@Eng.Sun.COM>: misprints in
344 ;;; comments and docstrings corrected, XEmacs support cleaned up.
345 ;;; The closing parenths would enclose the region into matching
346 ;;; parens under the same conditions as the opening ones.
347 ;;; Minor updates to `cperl-short-docs'.
348 ;;; Will not consider <<= as start of here-doc.
351 ;;; Added an extra advice to look into Micro-docs. ;-).
352 ;;; Enclosing of region when you press a closing parenth is regulated by
353 ;;; `cperl-electric-parens-string'.
354 ;;; Minor updates to `cperl-short-docs'.
355 ;;; `initialize-new-tags-table' called only if present (Does this help
356 ;;; with generation of tags under XEmacs?).
357 ;;; When creating/updating tag files, new info is written at the old place,
358 ;;; or at the end (is this a wanted behaviour? I need this in perl build directory).
361 ;;; All the keywords from keywords.pl included (maybe with dummy explanation).
362 ;;; No auto-help inside strings, comment, here-docs, formats, and pods.
363 ;;; Shrinkwrapping of info, regulated by `cperl-max-help-size',
364 ;;; `cperl-shrink-wrap-info-frame'.
365 ;;; Info on variables as well.
366 ;;; Recognision of HERE-DOCS improved yet more.
367 ;;; Autonewline works on `}' without warnings.
368 ;;; Autohelp works again on $_[0].
371 ;;; perl-descr.el found its author - hi, Johan!
372 ;;; Some support for correct indent after here-docs and friends (may
373 ;;; be superseeded by eminent change to Emacs internals).
374 ;;; Should work with older Emaxen as well ( `-style stuff removed).
378 ;;; Started to add support for `syntax-table' property (should work
379 ;;; with patched Emaxen), controlled by
380 ;;; `cperl-use-syntax-table-text-property'. Currently recognized:
381 ;;; All quote-like operators: m, s, y, tr, qq, qw, qx, q,
382 ;;; // in most frequent context:
384 ;;; ~ { ( = | & + - * ! , ;
386 ;;; while if unless until and or not xor split grep map
387 ;;; Here-documents, formats, PODs,
390 ;;; sub a ($); sub a ($) {}
391 ;;; (provide 'cperl-mode) was missing!
392 ;;; `cperl-after-expr-p' is now much smarter after `}'.
393 ;;; `cperl-praise' added to mini-docs.
394 ;;; Utilities try to support subs-with-prototypes.
397 ;;; `cperl-after-expr-p' is now much smarter after "() {}" and "word {}":
398 ;;; if word is "else, map, grep".
399 ;;; Updated for new values of syntax-table constants.
400 ;;; Uses `help-char' (at last!) (disabled, does not work?!)
401 ;;; A couple of regexps where missing _ in character classes.
402 ;;; -s could be considered as start of regexp, 1../blah/ was not,
403 ;;; as was not /blah/ at start of file.
406 ;;; "\C-hv" was wrongly "\C-hf"
407 ;;; C-hv was not working on `[index()]' because of [] in skip-chars-*.
408 ;;; `__PACKAGE__' supported.
409 ;;; Thanks for Greg Badros: `cperl-lazy-unstall' is more complete,
410 ;;; `cperl-get-help' is made compatible with `query-replace'.
412 ;;;; As of Apr 15, development version of 19.34 supports
413 ;;;; `syntax-table' text properties. Try setting
414 ;;;; `cperl-use-syntax-table-text-property'.
417 ;;; We scan for s{}[] as well (in simplest situations).
418 ;;; We scan for $blah'foo as well.
419 ;;; The default is to use `syntax-table' text property if Emacs is good enough.
420 ;;; `cperl-lineup' is put on C-M-| (=C-M-S-\\).
421 ;;; Start of `cperl-beautify-regexp'.
424 ;;; `cperl-tags-hier-init' did not work in text-mode.
425 ;;; `cperl-noscan-files-regexp' had a misprint.
426 ;;; Generation of Class Hierarchy was broken due to a bug in `x-popup-menu'
430 ;;; my,local highlight vars after {} too.
431 ;;; TAGS could not be created before imenu was loaded.
432 ;;; `cperl-indent-left-aligned-comments' created.
433 ;;; Logic of `cperl-indent-exp' changed a little bit, should be more
434 ;;; robust w.r.t. multiline strings.
435 ;;; Recognition of blah'foo takes into account strings.
436 ;;; Added '.al' to the list of Perl extensions.
437 ;;; Class hierarchy is "mostly" sorted (need to rethink algorthm
438 ;;; of pruning one-root-branch subtrees to get yet better sorting.)
439 ;;; Regeneration of TAGS was busted.
440 ;;; Can use `syntax-table' property when generating TAGS
441 ;;; (governed by `cperl-use-syntax-table-text-property-for-tags').
444 ;;; Can process several =pod/=cut sections one after another.
445 ;;; Knows of `extproc' when under `emx', indents with `__END__' and `__DATA__'.
446 ;;; `cperl-under-as-char' implemented (XEmacs people like broken behaviour).
447 ;;; Beautifier for regexps fixed.
448 ;;; `cperl-beautify-level', `cperl-contract-level' coded
450 ;;;; Emacs's 20.2 problems:
451 ;;; `imenu.el' has bugs, `imenu-add-to-menubar' does not work.
452 ;;; Couple of others problems with 20.2 were reported, my ability to check/fix
453 ;;; them is very reduced now.
456 ;;; 'C-M-|' in XEmacs fixed
459 ;;; &&s was not recognized as start of regular expression;
460 ;;; Will "preprocess" the contents of //e part of s///e too;
461 ;;; What to do with s# blah # foo #e ?
462 ;;; Should handle s;blah;foo;; better.
463 ;;; Now the only known problems with regular expression recognition:
464 ;;;;;;; s<foo>/bar/ - different delimiters (end ignored)
465 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into one chunk)
466 ;;;;;;; s/foo// - empty subst (made into one chunk + '/')
467 ;;;;;;; s/foo/(bar)/ - start-group at start of subst (internal group will not match backwards)
470 ;;; We highlight closing / of s/blah/foo/e;
471 ;;; This handles s# blah # foo #e too;
472 ;;; s//blah/, s///, s/blah// works again, and s#blah## too, the algorithm
473 ;;; is much simpler now;
474 ;;; Next round of changes: s\\\ works, s<blah>/foo/,
475 ;;; comments between the first and the second part allowed
476 ;;; Another problem discovered:
477 ;;;;;;; s[foo] <blah>e - e part delimited by different <> (will not match)
478 ;;; `cperl-find-pods-heres' somehow maybe called when string-face is undefined
479 ;;; - put a stupid workaround for 20.1
482 ;;; Could indent here-docs for comments;
483 ;;; These problems fixed:
484 ;;;;;;; s/foo/\\bar/ - backslash at start of subst (made into two chunk)
485 ;;;;;;; s[foo] <blah>e - "e" part delimited by "different" <> (will match)
486 ;;; Matching brackets honor prefices, may expand abbreviations;
487 ;;; When expanding abbrevs, will remove last char only after
488 ;;; self-inserted whitespace;
489 ;;; More convenient "Refress hard constructs" in menu;
490 ;;; `cperl-add-tags-recurse', `cperl-add-tags-recurse-noxs'
491 ;;; added (for -batch mode);
492 ;;; Better handling of errors when scanning for Perl constructs;
493 ;;;;;;; Possible "problem" with class hierarchy in Perl distribution
494 ;;;;;;; directory: ./ext duplicates ./lib;
495 ;;; Write relative paths for generated TAGS;
498 ;;; s /// may be separated by "\n\f" too;
499 ;;; `s #blah' recognized as a comment;
500 ;;; Would highlight s/abc//s wrong;
501 ;;; Debugging code in `cperl-electric-keywords' was leaking a message;
504 ;;; RMS changes for 20.3 merged
506 ;;;; 2.0.1.0: RMS mode (has 3 misprints)
509 ;;; RMS whitespace changes for 20.3 merged
515 ;;; Merge `c-style-alist' since `c-mode' is no more. (Somebody who
516 ;;; uses the styles should check that they work OK!)
517 ;;; All the variable warnings go away, some undef functions too.
520 ;;; Added `cperl-perldoc' (thanks to Anthony Foiani <afoiani@uswest.com>)
521 ;;; Added `cperl-pod-to-manpage' (thanks to Nick Roberts <Nick.Roberts@src.bae.co.uk>)
522 ;;; All the function warnings go away.
525 ;;; `Perl doc', `Regexp' submenus created (latter to allow short displays).
526 ;;; `cperl-clobber-lisp-bindings' added.
527 ;;; $a->y() is not y///.
528 ;;; `cperl-after-block-p' was missing a `save-excursion' => wrong results.
529 ;;; `cperl-val' was defined too late.
530 ;;; `cperl-init-faces' was failing.
531 ;;; Init faces when loading `ps-print'.
534 ;;; `cperl-toggle-autohelp' implemented.
535 ;;; `while SPACE LESS' was buggy.
536 ;;; `-text' in `[-text => 1]' was not highlighted.
537 ;;; `cperl-after-block-p' was FALSE after `sub f {}'.
540 ;;; `foreachmy', `formy' expanded too.
541 ;;; Expand `=pod-directive'.
542 ;;; `cperl-linefeed' behaves reasonable in POD-directive lines.
543 ;;; `cperl-electric-keyword' prints a message, governed by
544 ;;; `cperl-message-electric-keyword'.
547 ;;; Typing `}' was not checking for being block or not.
548 ;;; Beautifying levels in RE: Did not know about lookbehind;
549 ;;; finding *which* level was not intuitive;
550 ;;; `cperl-beautify-levels' added.
551 ;;; Allow here-docs contain `=head1' and friends (at least for keywords).
554 ;;; Fix for broken `font-lock-unfontify-region-function'. Should
555 ;;; preserve `syntax-table' properties even with `lazy-lock'.
558 ;;; Some more compile time warnings crept in.
559 ;;; `cperl-indent-region-fix-else' implemented.
560 ;;; `cperl-fix-line-spacing' implemented.
561 ;;; `cperl-invert-if-unless' implemented (C-c C-t and in Menu).
562 ;;; Upgraded hints to mention 20.2's goods/bads.
563 ;;; Started to use `cperl-extra-newline-before-brace-multiline',
564 ;;; `cperl-break-one-line-blocks-when-indent',
565 ;;; `cperl-fix-hanging-brace-when-indent', `cperl-merge-trailing-else'.
568 ;;; Workaround for another `font-lock's `syntax-table' text-property bug.
569 ;;; `zerop' could be applied to nil.
570 ;;; At last, may work with `font-lock' without setting `cperl-font-lock'.
571 ;;; (We expect that starting from 19.33, `font-lock' supports keywords
572 ;;; being a function - what is a correct version?)
573 ;;; Rename `cperl-indent-region-fix-else' to
574 ;;; `cperl-indent-region-fix-constructs'.
575 ;;; `cperl-fix-line-spacing' could be triggered inside strings, would not
576 ;;; know what to do with BLOCKs of map/printf/etc.
577 ;;; `cperl-merge-trailing-else' and `cperl-fix-line-spacing' handle
579 ;;; Indentation after {BLOCK} knows about map/printf/etc.
580 ;;; Finally: treat after-comma lines as continuation lines.
583 ;;; `continue' made electric.
584 ;;; Electric `do' inserts `do/while'.
585 ;;; Some extra compile-time warnings crept in.
586 ;;; `font-lock' of 19.33 could not handle font-lock-keywords being a function
587 ;;; returning a symbol.
590 ;;; Changes to make syntaxification to be autoredone via `font-lock'.
591 ;;; Switched on by `cperl-syntaxify-by-font-lock', off by default so far.
594 ;;; Remove some commented out chunks.
595 ;;; Styles are slightly updated (a lot of work is needed, especially
596 ;;; with new `cperl-fix-line-spacing').
599 ;;; Old value of style is memorized when choosing a new style, may be
600 ;;; restored from the same menu.
601 ;;; Mode-documentation added to micro-docs.
602 ;;; `cperl-praise' updated.
603 ;;; `cperl-toggle-construct-fix' added on C-c C-w and menu.
604 ;;; `auto-fill-mode' added on C-c C-f and menu.
605 ;;; `PerlStyle' style added.
606 ;;; Message for termination of scan corrected.
610 ;;; Did not work with -q
614 ;;; `cperl-speed' hints added.
615 ;;; Minor style fixes.
618 ;;; Make backspace electric after expansion of `else/continue' too.
621 ;;; Starting to merge changes to RMS emacs version.
624 ;;; Merged custom stuff and darn `font-lock-constant-face'.
627 ;;; Bumped the version to 3.1
630 ;;; Fixed customization to honor cperl-hairy.
631 ;;; Created customization groups. Sent to RMS to include into 2.3.
634 ;;; Interaction of `font-lock-hot-pass' and `cperl-syntaxify-by-font-lock'.
635 ;;; (`cperl-after-block-and-statement-beg'):
636 ;;; (`cperl-after-block-p'):
637 ;;; (`cperl-after-expr-p'): It is BLOCK if we reach lim when backup sexp.
638 ;;; (`cperl-indent-region'): Make a marker for END - text added/removed.
639 ;;; (`cperl-style-alist', `cperl-styles-entries')
640 ;;; Include `cperl-merge-trailing-else' where the value is clear.
644 ;;; (`cperl-problems'): Improvements to docs.
647 ;;; (`cperl-mode'): Make lazy syntaxification possible.
648 ;;; (`cperl-find-pods-heres'): Safe a position in buffer where it is safe to
649 ;;; restart syntaxification.
650 ;;; (`cperl-syntaxify-by-font-lock'): Set to t, should be safe now.
653 ;;; (`cperl-syntaxify-by-font-lock'): Better default, customizes to
657 ;;; (`cperl-find-pods-heres'): changed so that -d ?foo? is a RE.
658 ;;; (`cperl-array-face'): changed name from `font-lock-emphasized-face'.
659 ;;; (`cperl-hash-face'): changed name from `font-lock-other-emphasized-face'.
660 ;;; Use `defface' to define these two extra faces.
663 ;;; Can use linear algorithm for indentation if Emacs supports it:
664 ;;; indenting DB::DB (800+ lines) improved from 69 sec to 11 sec
665 ;;; (73 vs 15 with imenu).
666 ;;; (`cperl-emacs-can-parse'): New state.
667 ;;; (`cperl-indent-line'): Corrected to use global state.
668 ;;; (`cperl-calculate-indent'): Likewise.
669 ;;; (`cperl-fix-line-spacing'): Likewise (not used yet).
672 ;;; (`cperl-choose-color'): Converted to a function (to be compilable in text-mode).
675 ;;; (`cperl-dark-background '): Disable without window-system.
678 ;;; Do `defface' only if window-system.
681 ;;; (`cperl-fix-line-spacing'): sped up to bail out early.
682 ;;; (`cperl-indent-region'): Disable hooks during the call (how to call them later?).
684 ;;; Now indents 820-line-long function in 6.5 sec (including syntaxification) the first time
685 ;;; (when buffer has few properties), 7.1 sec the second time.
687 ;;;Function Name Call Count Elapsed Time Average Time
688 ;;;========================================= ========== ============ ============
689 ;;;cperl-indent-exp 1 10.039999999 10.039999999
690 ;;;cperl-indent-region 1 10.0 10.0
691 ;;;cperl-indent-line 821 6.2100000000 0.0075639464
692 ;;;cperl-calculate-indent 821 5.0199999999 0.0061144945
693 ;;;cperl-backward-to-noncomment 2856 2.0500000000 0.0007177871
694 ;;;cperl-fontify-syntaxically 2 1.78 0.8900000000
695 ;;;cperl-find-pods-heres 2 1.78 0.8900000000
696 ;;;cperl-update-syntaxification 1 1.78 1.78
697 ;;;cperl-fix-line-spacing 769 1.4800000000 0.0019245773
698 ;;;cperl-after-block-and-statement-beg 163 1.4100000000 0.0086503067
699 ;;;cperl-block-p 775 1.1800000000 0.0015225806
700 ;;;cperl-to-comment-or-eol 3652 1.1200000000 0.0003066812
701 ;;;cperl-after-block-p 165 1.0500000000 0.0063636363
702 ;;;cperl-commentify 141 0.22 0.0015602836
703 ;;;cperl-get-state 813 0.16 0.0001968019
704 ;;;cperl-backward-to-start-of-continued-exp 26 0.12 0.0046153846
705 ;;;cperl-delay-update-hook 2107 0.0899999999 4.271...e-05
706 ;;;cperl-protect-defun-start 141 0.0700000000 0.0004964539
707 ;;;cperl-after-label 407 0.0599999999 0.0001474201
708 ;;;cperl-forward-re 139 0.0299999999 0.0002158273
709 ;;;cperl-comment-indent 26 0.0299999999 0.0011538461
710 ;;;cperl-use-region-p 8 0.0 0.0
711 ;;;cperl-lazy-hook 15 0.0 0.0
712 ;;;cperl-after-expr-p 8 0.0 0.0
713 ;;;cperl-font-lock-unfontify-region-function 1 0.0 0.0
715 ;;;Function Name Call Count Elapsed Time Average Time
716 ;;;========================================= ========== ============ ============
717 ;;;cperl-fix-line-spacing 769 1.4500000000 0.0018855656
718 ;;;cperl-indent-line 13 0.3100000000 0.0238461538
719 ;;;cperl-after-block-and-statement-beg 69 0.2700000000 0.0039130434
720 ;;;cperl-after-block-p 69 0.2099999999 0.0030434782
721 ;;;cperl-calculate-indent 13 0.1000000000 0.0076923076
722 ;;;cperl-backward-to-noncomment 177 0.0700000000 0.0003954802
723 ;;;cperl-get-state 13 0.0 0.0
724 ;;;cperl-to-comment-or-eol 179 0.0 0.0
725 ;;;cperl-get-help-defer 1 0.0 0.0
726 ;;;cperl-lazy-hook 11 0.0 0.0
727 ;;;cperl-after-expr-p 2 0.0 0.0
728 ;;;cperl-block-p 13 0.0 0.0
729 ;;;cperl-after-label 5 0.0 0.0
732 ;;; (`cperl-find-pods-heres'): do not warn on `=cut' if doing a chunk only.
735 ;;; (`cperl-mode'): load pseudo-faces on `cperl-find-pods-heres' (for 19.30).
736 ;;; (`x-color-defined-p'): was not compiling on XEmacs
737 ;;; (`cperl-find-pods-heres'): 1 << 6 was OK, but 1<<6 was considered as HERE
738 ;;; <file/glob> made into a string.
741 ;;; (`cperl-find-pods-heres'): Postpone addition of faces after syntactic step
742 ;;; Recognition of <FH> was wrong.
743 ;;; (`cperl-clobber-lisp-bindings'): if set, C-c variants are the old ones
744 ;;; (`cperl-unwind-to-safe'): New function.
745 ;;; (`cperl-fontify-syntaxically'): Use `cperl-unwind-to-safe' to start at reasonable position.
748 ;;; (`cperl-forward-re'): Highlight the trailing / in s/foo// as string.
749 ;;; Highlight the starting // in s//foo/ as function-name.
752 ;;; (`cperl-find-pods-heres'): Highlight `gem' in s///gem as a keyword.
755 ;;; (`cperl-find-pods-heres'): `qr' added
756 ;;; (`cperl-electric-keyword'): Likewise
757 ;;; (`cperl-electric-else'): Likewise
758 ;;; (`cperl-to-comment-or-eol'): Likewise
759 ;;; (`cperl-make-regexp-x'): Likewise
760 ;;; (`cperl-init-faces'): Likewise, and `lock' (as overridable?).
761 ;;; (`cperl-find-pods-heres'): Knows that split// is null-RE.
762 ;;; Highlights separators in 3-parts expressions
766 ;;; (`cperl-find-pods-heres'): <> was considered as a glob
767 ;;; (`cperl-syntaxify-unwind'): New configuration variable
768 ;;; (`cperl-fontify-m-as-s'): New configuration variable
771 ;;; (`cperl-find-pods-heres'): of the last line being `=head1' fixed.
773 ;;; Handling of a long construct is still buggy if only the part of
774 ;;; construct touches the updated region (we unwind to the start of
775 ;;; long construct, but the end may have residual properties).
777 ;;; (`cperl-unwind-to-safe'): would not go to beginning of buffer.
778 ;;; (`cperl-electric-pod'): check for after-expr was performed
779 ;;; inside of POD too.
782 ;;; (`cperl-backward-to-noncomment'): better treatment of PODs and HEREs.
784 ;;; Indent-line works good, but indent-region does not - at toplevel...
785 ;;; (`cperl-unwind-to-safe'): Signature changed.
786 ;;; (`x-color-defined-p'): was defmacro'ed with a tick. Remove another def.
787 ;;; (`cperl-clobber-mode-lists'): New configuration variable.
788 ;;; (`cperl-array-face'): One of definitions was garbled.
791 ;;; (`cperl-not-bad-regexp'): Updated.
792 ;;; (`cperl-make-regexp-x'): Misprint in a message.
793 ;;; (`cperl-find-pods-heres'): $a-1 ? foo : bar; was a regexp.
794 ;;; `<< (' was considered a start of POD.
795 ;;; Init: `cperl-is-face' was busted.
796 ;;; (`cperl-make-face'): New macros.
797 ;;; (`cperl-force-face'): New macros.
798 ;;; (`cperl-init-faces'): Corrected to use new macros;
799 ;;; `if' for copying `reference-face' to
800 ;;; `constant-face' was backward.
801 ;;; (`font-lock-other-type-face'): Done via `defface' too.
804 ;;; (`cperl-init-faces-weak'): use `cperl-force-face'.
805 ;;; (`cperl-after-block-p'): After END/BEGIN we are a block.
806 ;;; (`cperl-mode'): `font-lock-unfontify-region-function'
807 ;;; was set to a wrong function.
808 ;;; (`cperl-comment-indent'): Commenting __END__ was not working.
809 ;;; (`cperl-indent-for-comment'): Likewise.
810 ;;; (Indenting is still misbehaving at toplevel.)
813 ;;; (`cperl-unwind-to-safe'): Signature changed, unwinds end too.
814 ;;; (`cperl-find-pods-heres'): mark qq[]-etc sections as syntax-type=string
815 ;;; (`cperl-fontify-syntaxically'): Unwinds start and end to go out of
816 ;;; long strings (not very successful).
818 ;;; >>>> CPerl should be usable in write mode too now <<<<
820 ;;; (`cperl-syntaxify-by-font-lock'): Better default - off in text-mode.
821 ;;; (`cperl-tips'): Updated docs.
822 ;;; (`cperl-problems'): Updated docs.
825 ;;; (`cperl-calculate-indent'): Did not consider `,' as continuation mark for statements.
826 ;;; (`cperl-write-tags'): Correct for XEmacs's `visit-tags-table-buffer'.
829 ;;; (`cperl-calculate-indent'): Avoid parse-data optimization at toplevel.
830 ;;; Should indent correctly at toplevel too.
831 ;;; (`cperl-tags-hier-init'): Gross hack to pretend we work (are we?).
832 ;;; (`cperl-find-pods-heres'): Was not processing sub protos after a comment ine.
833 ;;; Was treating $a++ <= 5 as a glob.
836 ;;; (toplevel): require custom unprotected => failure on 19.28.
837 ;;; (`cperl-xemacs-p') defined when compile too
838 ;;; (`cperl-tags-hier-init'): Another try to work around XEmacs problems
839 ;;; Better progress messages.
840 ;;; (`cperl-find-tags'): Was writing line/pos in a wrong order,
841 ;;; pos off by 1 and not at beg-of-line.
842 ;;; (`cperl-etags-snarf-tag'): New macro
843 ;;; (`cperl-etags-goto-tag-location'): New macro
844 ;;; (`cperl-write-tags'): When removing old TAGS info was not
845 ;;; relativizing filename
848 ;;; (`cperl-version'): New variable. New menu entry
851 ;;; (`cperl-tips'): Updated.
852 ;;; (`cperl-non-problems'): Updated.
853 ;;; random: References to future 20.3 removed.
856 ;;; (`perl-font-lock-keywords'): Would not highlight `sub foo($$);'.
857 ;;; Docstrings: Menu was described as `CPerl' instead of `Perl'
860 ;;; (`cperl-toggle-construct-fix'): Was toggling to t instead of 1.
861 ;;; (`cperl-ps-print-init'): Associate `cperl-array-face', `cperl-hash-face'
862 ;;; remove `font-lock-emphasized-face'.
863 ;;; remove `font-lock-other-emphasized-face'.
864 ;;; remove `font-lock-reference-face'.
865 ;;; remove `font-lock-keyword-face'.
866 ;;; Use `eval-after-load'.
867 ;;; (`cperl-init-faces'): remove init `font-lock-other-emphasized-face'.
868 ;;; remove init `font-lock-emphasized-face'.
869 ;;; remove init `font-lock-keyword-face'.
870 ;;; (`cperl-tips-faces'): New variable and an entry into Mini-docs.
871 ;;; (`cperl-indent-region'): Do not indent whitespace lines
872 ;;; (`cperl-indent-exp'): Was not processing else-blocks.
873 ;;; (`cperl-calculate-indent'): Remove another parse-data optimization
874 ;;; at toplevel: would indent correctly.
875 ;;; (`cperl-get-state'): NOP line removed.
878 ;;; (`cperl-ps-print-init'): Remove not-CPerl-related faces.
879 ;;; (`cperl-ps-print'): New function and menu entry.
880 ;;; (`cperl-ps-print-face-properties'): New configuration variable.
881 ;;; (`cperl-invalid-face'): New configuration variable.
882 ;;; (`cperl-nonoverridable-face'): New face. Renamed from
883 ;;; `font-lock-other-type-face'.
884 ;;; (`perl-font-lock-keywords'): Highlight trailing whitespace
885 ;;; (`cperl-contract-levels'): Documentation corrected.
886 ;;; (`cperl-contract-level'): Likewise.
889 ;;; (`cperl-ps-print'): `ps-print-face-extension-alist' was not in old Emaxen,
890 ;;; same with `ps-extend-face-list'
891 ;;; (`cperl-ps-extend-face-list'): New macro.
894 ;;; (`cperl-init-faces'): Interpolate `cperl-invalid-face'.
895 ;;; (`cperl-forward-re'): Emit a meaningful error instead of a cryptic
896 ;;; one for uncomplete REx near end-of-buffer.
897 ;;; (`cperl-find-pods-heres'): Tolerate unfinished REx at end-of-buffer.
900 ;;; (`cperl-find-pods-heres'): `unwind-protect' was left commented.
903 ;;; (`cperl-invalid-face'): Change to ''underline.
906 ;;; (`cperl-find-pods-heres'): / and ? after : start a REx.
907 ;;; (`cperl-after-expr-p'): Skip labels when checking
908 ;;; (`cperl-calculate-indent'): Correct for labels when calculating
909 ;;; indentation of continuations.
910 ;;; Docstring updated.
914 (if (fboundp 'eval-when-compile)
919 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
920 (or (fboundp 'defgroup)
921 (defmacro defgroup (name val doc &rest arr)
923 (or (fboundp 'custom-declare-variable)
924 (defmacro defcustom (name val doc &rest arr)
925 (` (defvar (, name) (, val) (, doc)))))
926 (or (and (fboundp 'custom-declare-variable)
927 (string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
928 (defmacro defface (&rest arr)
930 ;; Avoid warning (tmp definitions)
931 (or (fboundp 'x-color-defined-p)
932 (defmacro x-color-defined-p (col)
933 (cond ((fboundp 'color-defined-p) (` (color-defined-p (, col))))
935 ((fboundp 'valid-color-name-p) (` (valid-color-name-p (, col))))
937 (t (` (x-valid-color-name-p (, col)))))))
938 (if (fboundp 'ps-extend-face-list)
939 (defmacro cperl-ps-extend-face-list (arg)
940 (` (ps-extend-face-list (, arg))))
941 (defmacro cperl-ps-extend-face-list (arg)
942 (` (error "This version of Emacs has no `ps-extend-face-list'."))))
943 (defmacro cperl-is-face (arg) ; Takes quoted arg
944 (cond ((fboundp 'find-face)
945 (` (find-face (, arg))))
946 (;;(and (fboundp 'face-list)
949 (` (member (, arg) (and (fboundp 'face-list)
952 (` (boundp (, arg))))))
953 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
954 (cond ((fboundp 'make-face)
955 (` (make-face (quote (, arg)))))
957 (` (defconst (, arg) (quote (, arg)) (, descr))))))
958 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
960 (or (cperl-is-face (quote (, arg)))
961 (cperl-make-face (, arg) (, descr)))
962 (or (boundp (quote (, arg))) ; We use unquoted variants too
963 (defconst (, arg) (quote (, arg)) (, descr))))))
965 (defmacro cperl-etags-snarf-tag (file line)
967 (beginning-of-line 2)
968 (list (, file) (, line)))))
969 (defmacro cperl-etags-snarf-tag (file line)
970 (` (etags-snarf-tag))))
972 (defmacro cperl-etags-goto-tag-location (elt)
974 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
975 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
976 ;; Probably will not work due to some save-excursion???
977 ;; Or save-file-position?
978 ;; (message "Did I get to line %s?" (elt (, elt) 1))
979 (goto-line (string-to-int (elt (, elt) 1)))))
981 (defmacro cperl-etags-goto-tag-location (elt)
982 (` (etags-goto-tag-location (, elt)))))))
986 (error nil)) ; Already fixed by eval-when-compile
988 (defun cperl-choose-color (&rest list)
992 (if (or (x-color-defined-p (car list))
994 (setq answer (car list))))
995 (setq list (cdr list)))
1000 "Major mode for editing Perl code."
1004 (defgroup cperl-indentation-details nil
1009 (defgroup cperl-affected-by-hairy nil
1010 "Variables affected by `cperl-hairy'."
1014 (defgroup cperl-autoinsert-details nil
1015 "Auto-insert tuneup."
1019 (defgroup cperl-faces nil
1020 "Fontification colors."
1024 (defgroup cperl-speed nil
1025 "Speed vs. validity tuneup."
1029 (defgroup cperl-help-system nil
1030 "Help system tuneup."
1035 (defcustom cperl-extra-newline-before-brace nil
1036 "*Non-nil means that if, elsif, while, until, else, for, foreach
1037 and do constructs look like:
1049 :group 'cperl-autoinsert-details)
1051 (defcustom cperl-extra-newline-before-brace-multiline
1052 cperl-extra-newline-before-brace
1053 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
1054 for constructs with multiline if/unless/while/until/for/foreach condition."
1056 :group 'cperl-autoinsert-details)
1058 (defcustom cperl-indent-level 2
1059 "*Indentation of CPerl statements with respect to containing block."
1061 :group 'cperl-indentation-details)
1063 (defcustom cperl-lineup-step nil
1064 "*`cperl-lineup' will always lineup at multiple of this number.
1065 If `nil', the value of `cperl-indent-level' will be used."
1066 :type '(choice (const nil) integer)
1067 :group 'cperl-indentation-details)
1069 (defcustom cperl-brace-imaginary-offset 0
1070 "*Imagined indentation of a Perl open brace that actually follows a statement.
1071 An open brace following other text is treated as if it were this far
1072 to the right of the start of its line."
1074 :group 'cperl-indentation-details)
1076 (defcustom cperl-brace-offset 0
1077 "*Extra indentation for braces, compared with other text in same context."
1079 :group 'cperl-indentation-details)
1080 (defcustom cperl-label-offset -2
1081 "*Offset of CPerl label lines relative to usual indentation."
1083 :group 'cperl-indentation-details)
1084 (defcustom cperl-min-label-indent 1
1085 "*Minimal offset of CPerl label lines."
1087 :group 'cperl-indentation-details)
1088 (defcustom cperl-continued-statement-offset 2
1089 "*Extra indent for lines not starting new statements."
1091 :group 'cperl-indentation-details)
1092 (defcustom cperl-continued-brace-offset 0
1093 "*Extra indent for substatements that start with open-braces.
1094 This is in addition to cperl-continued-statement-offset."
1096 :group 'cperl-indentation-details)
1097 (defcustom cperl-close-paren-offset -1
1098 "*Extra indent for substatements that start with close-parenthesis."
1100 :group 'cperl-indentation-details)
1102 (defcustom cperl-auto-newline nil
1103 "*Non-nil means automatically newline before and after braces,
1104 and after colons and semicolons, inserted in CPerl code. The following
1105 \\[cperl-electric-backspace] will remove the inserted whitespace.
1106 Insertion after colons requires both this variable and
1107 `cperl-auto-newline-after-colon' set."
1109 :group 'cperl-autoinsert-details)
1111 (defcustom cperl-auto-newline-after-colon nil
1112 "*Non-nil means automatically newline even after colons.
1113 Subject to `cperl-auto-newline' setting."
1115 :group 'cperl-autoinsert-details)
1117 (defcustom cperl-tab-always-indent t
1118 "*Non-nil means TAB in CPerl mode should always reindent the current line,
1119 regardless of where in the line point is when the TAB command is used."
1121 :group 'cperl-indentation-details)
1123 (defcustom cperl-font-lock nil
1124 "*Non-nil (and non-null) means CPerl buffers will use font-lock-mode.
1125 Can be overwritten by `cperl-hairy' if nil."
1126 :type '(choice (const null) boolean)
1127 :group 'cperl-affected-by-hairy)
1129 (defcustom cperl-electric-lbrace-space nil
1130 "*Non-nil (and non-null) means { after $ in CPerl buffers should be preceded by ` '.
1131 Can be overwritten by `cperl-hairy' if nil."
1132 :type '(choice (const null) boolean)
1133 :group 'cperl-affected-by-hairy)
1135 (defcustom cperl-electric-parens-string "({[]})<"
1136 "*String of parentheses that should be electric in CPerl.
1137 Closing ones are electric only if the region is highlighted."
1139 :group 'cperl-affected-by-hairy)
1141 (defcustom cperl-electric-parens nil
1142 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
1143 Can be overwritten by `cperl-hairy' if nil."
1144 :type '(choice (const null) boolean)
1145 :group 'cperl-affected-by-hairy)
1147 (defvar zmacs-regions) ; Avoid warning
1149 (defcustom cperl-electric-parens-mark
1151 (or (and (boundp 'transient-mark-mode) ; For Emacs
1152 transient-mark-mode)
1153 (and (boundp 'zmacs-regions) ; For XEmacs
1155 "*Not-nil means that electric parens look for active mark.
1156 Default is yes if there is visual feedback on mark."
1158 :group 'cperl-autoinsert-details)
1160 (defcustom cperl-electric-linefeed nil
1161 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
1162 In any case these two mean plain and hairy linefeeds together.
1163 Can be overwritten by `cperl-hairy' if nil."
1164 :type '(choice (const null) boolean)
1165 :group 'cperl-affected-by-hairy)
1167 (defcustom cperl-electric-keywords nil
1168 "*Not-nil (and non-null) means keywords are electric in CPerl.
1169 Can be overwritten by `cperl-hairy' if nil."
1170 :type '(choice (const null) boolean)
1171 :group 'cperl-affected-by-hairy)
1173 (defcustom cperl-hairy nil
1174 "*Not-nil means most of the bells and whistles are enabled in CPerl.
1175 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
1176 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
1177 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
1178 `cperl-lazy-help-time'."
1180 :group 'cperl-affected-by-hairy)
1182 (defcustom cperl-comment-column 32
1183 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
1185 :group 'cperl-indentation-details)
1187 (defcustom cperl-vc-header-alist '((SCCS "$sccs = '%W\%' ;")
1188 (RCS "$rcs = ' $Id\$ ' ;"))
1189 "*What to use as `vc-header-alist' in CPerl."
1190 :type '(repeat (list symbol string))
1193 (defcustom cperl-clobber-mode-lists
1196 (boundp 'interpreter-mode-alist)
1197 (assoc "miniperl" interpreter-mode-alist)
1198 (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
1199 "*Whether to install us into `interpreter-' and `extension' mode lists."
1203 (defcustom cperl-info-on-command-no-prompt nil
1204 "*Not-nil (and non-null) means not to prompt on C-h f.
1205 The opposite behaviour is always available if prefixed with C-c.
1206 Can be overwritten by `cperl-hairy' if nil."
1207 :type '(choice (const null) boolean)
1208 :group 'cperl-affected-by-hairy)
1210 (defcustom cperl-clobber-lisp-bindings nil
1211 "*Not-nil (and non-null) means not overwrite C-h f.
1212 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
1213 Can be overwritten by `cperl-hairy' if nil."
1214 :type '(choice (const null) boolean)
1215 :group 'cperl-affected-by-hairy)
1217 (defcustom cperl-lazy-help-time nil
1218 "*Not-nil (and non-null) means to show lazy help after given idle time.
1219 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
1220 :type '(choice (const null) integer)
1221 :group 'cperl-affected-by-hairy)
1223 (defcustom cperl-pod-face 'font-lock-comment-face
1224 "*The result of evaluation of this expression is used for pod highlighting."
1226 :group 'cperl-faces)
1228 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
1229 "*The result of evaluation of this expression is used for pod highlighting.
1230 Font for POD headers."
1232 :group 'cperl-faces)
1234 (defcustom cperl-here-face 'font-lock-string-face
1235 "*The result of evaluation of this expression is used for here-docs highlighting."
1237 :group 'cperl-faces)
1239 (defcustom cperl-invalid-face ''underline ; later evaluated by `font-lock'
1240 "*The result of evaluation of this expression highlights trailing whitespace."
1242 :group 'cperl-faces)
1244 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
1245 "*Not-nil after evaluation means to highlight pod and here-docs sections."
1247 :group 'cperl-faces)
1249 (defcustom cperl-fontify-m-as-s t
1250 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
1252 :group 'cperl-faces)
1254 (defcustom cperl-pod-here-scan t
1255 "*Not-nil means look for pod and here-docs sections during startup.
1256 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
1258 :group 'cperl-speed)
1260 (defcustom cperl-imenu-addback nil
1261 "*Not-nil means add backreferences to generated `imenu's.
1262 May require patched `imenu' and `imenu-go'. Obsolete."
1264 :group 'cperl-help-system)
1266 (defcustom cperl-max-help-size 66
1267 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
1268 :type '(choice integer (const nil))
1269 :group 'cperl-help-system)
1271 (defcustom cperl-shrink-wrap-info-frame t
1272 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
1274 :group 'cperl-help-system)
1276 (defcustom cperl-info-page "perl"
1277 "*Name of the info page containing perl docs.
1278 Older version of this page was called `perl5', newer `perl'."
1280 :group 'cperl-help-system)
1282 (defcustom cperl-use-syntax-table-text-property
1283 (boundp 'parse-sexp-lookup-properties)
1284 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
1286 :group 'cperl-speed)
1288 (defcustom cperl-use-syntax-table-text-property-for-tags
1289 cperl-use-syntax-table-text-property
1290 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
1292 :group 'cperl-speed)
1294 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
1295 "*Regexp to match files to scan when generating TAGS."
1299 (defcustom cperl-noscan-files-regexp "/\\(\\.\\.?\\|SCCS\\|RCS\\|blib\\)$"
1300 "*Regexp to match files/dirs to skip when generating TAGS."
1304 (defcustom cperl-regexp-indent-step nil
1305 "*Indentation used when beautifying regexps.
1306 If `nil', the value of `cperl-indent-level' will be used."
1307 :type '(choice integer (const nil))
1308 :group 'cperl-indentation-details)
1310 (defcustom cperl-indent-left-aligned-comments t
1311 "*Non-nil means that the comment starting in leftmost column should indent."
1313 :group 'cperl-indentation-details)
1315 (defcustom cperl-under-as-char t
1316 "*Non-nil means that the _ (underline) should be treated as word char."
1320 (defcustom cperl-extra-perl-args ""
1321 "*Extra arguments to use when starting Perl.
1322 Currently used with `cperl-check-syntax' only."
1326 (defcustom cperl-message-electric-keyword t
1327 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
1329 :group 'cperl-help-system)
1331 (defcustom cperl-indent-region-fix-constructs 1
1332 "*Amount of space to insert between `}' and `else' or `elsif'
1333 in `cperl-indent-region'. Set to nil to leave as is. Values other
1334 than 1 and nil will probably not work."
1335 :type '(choice (const nil) (const 1))
1336 :group 'cperl-indentation-details)
1338 (defcustom cperl-break-one-line-blocks-when-indent t
1339 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
1340 need to be reformated into multiline ones when indenting a region."
1342 :group 'cperl-indentation-details)
1344 (defcustom cperl-fix-hanging-brace-when-indent t
1345 "*Non-nil means that BLOCK-end `}' may be put on a separate line
1346 when indenting a region.
1347 Braces followed by else/elsif/while/until are excepted."
1349 :group 'cperl-indentation-details)
1351 (defcustom cperl-merge-trailing-else t
1352 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
1353 may be merged to be on the same line when indenting a region."
1355 :group 'cperl-indentation-details)
1357 (defcustom cperl-syntaxify-by-font-lock
1359 (boundp 'parse-sexp-lookup-properties))
1360 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification.
1361 Having it TRUE may be not completely debugged yet."
1362 :type '(choice (const message) boolean)
1363 :group 'cperl-speed)
1365 (defcustom cperl-syntaxify-unwind
1367 "*Non-nil means that CPerl unwinds to a start of along construction
1368 when syntaxifying a chunk of buffer."
1370 :group 'cperl-speed)
1372 (defcustom cperl-ps-print-face-properties
1373 '((font-lock-keyword-face nil nil bold shadow)
1374 (font-lock-variable-name-face nil nil bold)
1375 (font-lock-function-name-face nil nil bold italic box)
1376 (font-lock-constant-face nil "LightGray" bold)
1377 (cperl-array-face nil "LightGray" bold underline)
1378 (cperl-hash-face nil "LightGray" bold italic underline)
1379 (font-lock-comment-face nil "LightGray" italic)
1380 (font-lock-string-face nil nil italic underline)
1381 (cperl-nonoverridable-face nil nil italic underline)
1382 (font-lock-type-face nil nil underline)
1383 (underline nil "LightGray" strikeout))
1384 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
1385 :type '(repeat (cons symbol
1386 (cons (choice (const nil) string)
1387 (cons (choice (const nil) string)
1389 :group 'cperl-faces)
1393 (defvar cperl-dark-background
1394 (cperl-choose-color "navy" "os2blue" "darkgreen"))
1395 (defvar cperl-dark-foreground
1396 (cperl-choose-color "orchid1" "orange"))
1398 (defface cperl-nonoverridable-face
1399 (` ((((class grayscale) (background light))
1400 (:background "Gray90" :italic t :underline t))
1401 (((class grayscale) (background dark))
1402 (:foreground "Gray80" :italic t :underline t :bold t))
1403 (((class color) (background light))
1404 (:foreground "chartreuse3"))
1405 (((class color) (background dark))
1406 (:foreground (, cperl-dark-foreground)))
1407 (t (:bold t :underline t))))
1408 "Font Lock mode face used to highlight array names."
1409 :group 'cperl-faces)
1411 (defface cperl-array-face
1412 (` ((((class grayscale) (background light))
1413 (:background "Gray90" :bold t))
1414 (((class grayscale) (background dark))
1415 (:foreground "Gray80" :bold t))
1416 (((class color) (background light))
1417 (:foreground "Blue" :background "lightyellow2" :bold t))
1418 (((class color) (background dark))
1419 (:foreground "yellow" :background (, cperl-dark-background) :bold t))
1421 "Font Lock mode face used to highlight array names."
1422 :group 'cperl-faces)
1424 (defface cperl-hash-face
1425 (` ((((class grayscale) (background light))
1426 (:background "Gray90" :bold t :italic t))
1427 (((class grayscale) (background dark))
1428 (:foreground "Gray80" :bold t :italic t))
1429 (((class color) (background light))
1430 (:foreground "Red" :background "lightyellow2" :bold t :italic t))
1431 (((class color) (background dark))
1432 (:foreground "Red" :background (, cperl-dark-background) :bold t :italic t))
1433 (t (:bold t :italic t))))
1434 "Font Lock mode face used to highlight hash names."
1435 :group 'cperl-faces)))
1439 ;;; Short extra-docs.
1441 (defvar cperl-tips 'please-ignore-this-line
1442 "Get newest version of this package from
1443 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs
1445 ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
1446 Subdirectory `cperl-mode' may contain yet newer development releases and/or
1447 patches to related files.
1449 For best results apply to an older Emacs the patches from
1450 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
1451 \(this upgrades syntax-parsing abilities of RMS Emaxen v19.34 and
1452 v20.2 up to the level of RMS Emacs v20.3 - a must for a good Perl
1453 mode.) You will not get much from XEmacs, it's syntax abilities are
1456 Get support packages choose-color.el (or font-lock-extra.el before
1457 19.30), imenu-go.el from the same place. \(Look for other files there
1458 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
1459 later you should use choose-color.el *instead* of font-lock-extra.el
1460 \(and you will not get smart highlighting in C :-().
1462 Note that to enable Compile choices in the menu you need to install
1466 $CPAN/doc/manual/info/perl-info.tar.gz
1467 older version was on
1468 http://www.metronet.com:70/9/perlinfo/perl5/manual/perl5-info.tar.gz
1470 If you use imenu-go, run imenu on perl5-info buffer (you can do it
1471 from Perl menu). If many files are related, generate TAGS files from
1472 Tools/Tags submenu in Perl menu.
1474 If some class structure is too complicated, use Tools/Hierarchy-view
1475 from Perl menu, or hierarchic view of imenu. The second one uses the
1476 current buffer only, the first one requires generation of TAGS from
1477 Perl/Tools/Tags menu beforehand.
1479 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
1481 Switch auto-help on/off with Perl/Tools/Auto-help.
1483 Though with contemporary Emaxen CPerl mode should maintain the correct
1484 parsing of Perl even when editing, sometimes it may be lost. Fix this by
1488 Before reporting (non-)problems look in the problem section of online
1489 micro-docs on what I know about CPerl problems.")
1491 (defvar cperl-problems 'please-ignore-this-line
1492 "Some faces will not be shown on some versions of Emacs unless you
1493 install choose-color.el, available from
1494 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs/
1496 Emacs had a _very_ restricted syntax parsing engine until RMS's Emacs
1497 20.1. Most problems below are corrected starting from this version of
1498 Emacs, and all of them should go with RMS's version 20.3.
1499 (Or apply patches to Emacs 19.33/34 - see tips.)
1501 Note that even with newer Emacsen interaction of `font-lock' and
1502 syntaxification is not cleaned up. You may get slightly different
1503 colors basing on the order of fontification and syntaxification. This
1504 might be corrected by setting `cperl-syntaxify-by-font-lock' to t, but
1505 the corresponding code may still contain some bugs.
1507 Even with older Emacsen CPerl mode tries to corrects some Emacs
1508 misunderstandings, however, for efficiency reasons the degree of
1509 correction is different for different operations. The partially
1510 corrected problems are: POD sections, here-documents, regexps. The
1511 operations are: highlighting, indentation, electric keywords, electric
1514 This may be confusing, since the regexp s#//#/#\; may be highlighted
1515 as a comment, but it will be recognized as a regexp by the indentation
1516 code. Or the opposite case, when a pod section is highlighted, but
1517 may break the indentation of the following code (though indentation
1518 should work if the balance of delimiters is not broken by POD).
1520 The main trick (to make $ a \"backslash\") makes constructions like
1521 ${aaa} look like unbalanced braces. The only trick I can think of is
1522 to insert it as $ {aaa} (legal in perl5, not in perl4).
1524 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
1525 as /($|\\s)/. Note that such a transposition is not always possible.
1527 The solution is to upgrade your Emacs or patch an older one. Note
1528 that RMS's 20.2 has some bugs related to `syntax-table' text
1529 properties. Patches are available on the main CPerl download site,
1532 If these bugs cannot be fixed on your machine (say, you have an inferior
1533 environment and cannot recompile), you may still disable all the fancy stuff
1534 via `cperl-use-syntax-table-text-property'." )
1536 (defvar cperl-non-problems 'please-ignore-this-line
1537 "As you know from `problems' section, Perl syntax is too hard for CPerl on
1538 older Emacsen. Here is what you can do if you cannot upgrade, or if
1539 you want to switch off these capabilities on RMS Emacs 20.2 (+patches) or 20.3
1540 or better. Please skip this docs if you run a capable Emacs already.
1542 Most of the time, if you write your own code, you may find an equivalent
1543 \(and almost as readable) expression (what is discussed below is usually
1544 not relevant on newer Emacsen, since they can do it automatically).
1546 Try to help CPerl: add comments with embedded quotes to fix CPerl
1547 misunderstandings about the end of quotation:
1551 You won't need it too often. The reason: $ \"quotes\" the following
1552 character (this saves a life a lot of times in CPerl), thus due to
1553 Emacs parsing rules it does not consider tick (i.e., ' ) after a
1554 dollar as a closing one, but as a usual character. This is usually
1555 correct, but not in the above context.
1557 Even with older Emacsen the indentation code is pretty wise. The only
1558 drawback is that it relied on Emacs parsing to find matching
1559 parentheses. And Emacs *could not* match parentheses in Perl 100%
1562 would not break indentation, but
1568 would confuse CPerl a lot.
1570 If you still get wrong indentation in situation that you think the
1571 code should be able to parse, try:
1573 a) Check what Emacs thinks about balance of your parentheses.
1574 b) Supply the code to me (IZ).
1576 Pods were treated _very_ rudimentally. Here-documents were not
1577 treated at all (except highlighting and inhibiting indentation). Upgrade.
1579 To speed up coloring the following compromises exist:
1580 a) sub in $mypackage::sub may be highlighted.
1581 b) -z in [a-z] may be highlighted.
1582 c) if your regexp contains a keyword (like \"s\"), it may be highlighted.
1585 Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove
1586 `car' before `imenu-choose-buffer-index' in `imenu'.
1587 `imenu-add-to-menubar' in 20.2 is broken.
1588 A lot of things on XEmacs may be broken too, judging by bug reports I
1589 recieve. Note that some releases of XEmacs are better than the others
1590 as far as bugs reports I see are concerned.")
1592 (defvar cperl-praise 'please-ignore-this-line
1593 "RMS asked me to list good things about CPerl. Here they go:
1595 0) It uses the newest `syntax-table' property ;-);
1597 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
1598 mode - but the latter number may have improved too in last years) even
1599 with old Emaxen which do not support `syntax-table' property.
1601 When using `syntax-table' property for syntax assist hints, it should
1602 handle 99.995% of lines correct - or somesuch. It automatically
1603 updates syntax assist hints when you edit your script.
1605 2) It is generally believed to be \"the most user-friendly Emacs
1606 package\" whatever it may mean (I doubt that the people who say similar
1607 things tried _all_ the rest of Emacs ;-), but this was not a lonely
1610 3) Everything is customizable, one-by-one or in a big sweep;
1612 4) It has many easily-accessable \"tools\":
1613 a) Can run program, check syntax, start debugger;
1614 b) Can lineup vertically \"middles\" of rows, like `=' in
1617 c) Can insert spaces where this impoves readability (in one
1618 interactive sweep over the buffer);
1619 d) Has support for imenu, including:
1620 1) Separate unordered list of \"interesting places\";
1621 2) Separate TOC of POD sections;
1622 3) Separate list of packages;
1623 4) Hierarchical view of methods in (sub)packages;
1624 5) and functions (by the full name - with package);
1625 e) Has an interface to INFO docs for Perl; The interface is
1626 very flexible, including shrink-wrapping of
1627 documentation buffer/frame;
1628 f) Has a builtin list of one-line explanations for perl constructs.
1629 g) Can show these explanations if you stay long enough at the
1630 corresponding place (or on demand);
1631 h) Has an enhanced fontification (using 3 or 4 additional faces
1632 comparing to font-lock - basically, different
1633 namespaces in Perl have different colors);
1634 i) Can construct TAGS basing on its knowledge of Perl syntax,
1635 the standard menu has 6 different way to generate
1636 TAGS (if \"by directory\", .xs files - with C-language
1637 bindings - are included in the scan);
1638 j) Can build a hierarchical view of classes (via imenu) basing
1639 on generated TAGS file;
1640 k) Has electric parentheses, electric newlines, uses Abbrev
1641 for electric logical constructs
1643 with different styles of expansion (context sensitive
1644 to be not so bothering). Electric parentheses behave
1645 \"as they should\" in a presence of a visible region.
1646 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
1652 n) Highlights (by user-choice) either 3-delimiters constructs
1653 (such as tr/a/b/), or regular expressions and `y/tr'.
1654 m) Highlights trailing whitespace.
1656 5) The indentation engine was very smart, but most of tricks may be
1657 not needed anymore with the support for `syntax-table' property. Has
1658 progress indicator for indentation (with `imenu' loaded).
1660 6) Indent-region improves inline-comments as well; also corrects
1661 whitespace *inside* the conditional/loop constructs.
1663 7) Fill-paragraph correctly handles multi-line comments;
1665 8) Can switch to different indentation styles by one command, and restore
1666 the settings present before the switch.
1668 9) When doing indentation of control constructs, may correct
1669 line-breaks/spacing between elements of the construct.
1672 (defvar cperl-speed 'please-ignore-this-line
1673 "This is an incomplete compendium of what is available in other parts
1674 of CPerl documentation. (Please inform me if I skept anything.)
1676 There is a perception that CPerl is slower than alternatives. This part
1677 of documentation is designed to overcome this misconception.
1679 *By default* CPerl tries to enable the most comfortable settings.
1680 From most points of view, correctly working package is infinitely more
1681 comfortable than a non-correctly working one, thus by default CPerl
1682 prefers correctness over speed. Below is the guide how to change
1683 settings if your preferences are different.
1685 A) Speed of loading the file. When loading file, CPerl may perform a
1686 scan which indicates places which cannot be parsed by primitive Emacs
1687 syntax-parsing routines, and marks them up so that either
1689 A1) CPerl may work around these deficiencies (for big chunks, mostly
1690 PODs and HERE-documents), or
1691 A2) On capable Emaxen CPerl will use improved syntax-handlings
1692 which reads mark-up hints directly.
1694 The scan in case A2 is much more comprehensive, thus may be slower.
1696 User can disable syntax-engine-helping scan of A2 by setting
1697 `cperl-use-syntax-table-text-property'
1698 variable to nil (if it is set to t).
1700 One can disable the scan altogether (both A1 and A2) by setting
1701 `cperl-pod-here-scan'
1704 B) Speed of editing operations.
1706 One can add a (minor) speedup to editing operations by setting
1707 `cperl-use-syntax-table-text-property'
1708 variable to nil (if it is set to t). This will disable
1709 syntax-engine-helping scan, thus will make many more Perl
1710 constructs be wrongly recognized by CPerl, thus may lead to
1711 wrongly matched parentheses, wrong indentation, etc.
1713 One can unset `cperl-syntaxify-unwind'. This might speed up editing
1714 of, say, long POD sections.
1717 (defvar cperl-tips-faces 'please-ignore-this-line
1718 "CPerl mode uses following faces for highlighting:
1720 cperl-array-face Array names
1721 cperl-hash-face Hash names
1722 font-lock-comment-face Comments, PODs and whatever is considered
1723 syntaxically to be not code
1724 font-lock-constant-face HERE-doc delimiters, labels, delimiters of
1725 2-arg operators s/y/tr/ or of RExen,
1726 font-lock-function-name-face Special-cased m// and s//foo/, _ as
1727 a target of a file tests, file tests,
1728 subroutine names at the moment of definition
1729 (except those conflicting with Perl operators),
1730 package names (when recognized), format names
1731 font-lock-keyword-face Control flow switch constructs, declarators
1732 cperl-nonoverridable-face Non-overridable keywords, modifiers of RExen
1733 font-lock-string-face Strings, qw() constructs, RExen, POD sections,
1734 literal parts and the terminator of formats
1735 and whatever is syntaxically considered
1737 font-lock-type-face Overridable keywords
1738 font-lock-variable-name-face Variable declarations, indirect array and
1739 hash names, POD headers/item names
1740 cperl-invalid-face Trailing whitespace
1742 Note that in several situations the highlighting tries to inform about
1743 possible confusion, such as different colors for function names in
1744 declarations depending on what they (do not) override, or special cases
1745 m// and s/// which do not do what one would expect them to do.
1747 Help with best setup of these faces for printout requested (for each of
1748 the faces: please specify bold, italic, underline, shadow and box.)
1754 ;;; Portability stuff:
1756 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
1758 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
1759 (` (define-key cperl-mode-map
1761 (` (if cperl-xemacs-p (, xemacs-key) (, emacs-key)))
1765 (defvar cperl-del-back-ch
1766 (car (append (where-is-internal 'delete-backward-char)
1767 (where-is-internal 'backward-delete-char-untabify)))
1768 "Character generated by key bound to delete-backward-char.")
1770 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
1771 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
1773 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
1776 ;; "Active regions" are on: use region only if active
1777 ;; "Active regions" are off: use region unconditionally
1778 (defun cperl-use-region-p ()
1779 (if zmacs-regions (mark) t)))
1780 (defun cperl-use-region-p ()
1781 (if transient-mark-mode mark-active t))
1782 (defun cperl-mark-active () mark-active))
1784 (defsubst cperl-enable-font-lock ()
1785 (or cperl-xemacs-p window-system))
1787 (defun cperl-putback-char (c) ; Emacs 19
1788 (set 'unread-command-events (list c))) ; Avoid undefined warning
1790 (if (boundp 'unread-command-events)
1792 (defun cperl-putback-char (c) ; XEmacs >= 19.12
1793 (setq unread-command-events (list (eval '(character-to-event c))))))
1794 (defun cperl-putback-char (c) ; XEmacs <= 19.11
1795 (set 'unread-command-event (eval '(character-to-event c))))) ; Avoid warnings
1797 (or (fboundp 'uncomment-region)
1798 (defun uncomment-region (beg end)
1800 (comment-region beg end -1)))
1802 (defvar cperl-do-not-fontify
1803 (if (string< emacs-version "19.30")
1806 "Text property which inhibits refontification.")
1808 (defsubst cperl-put-do-not-fontify (from to &optional post)
1809 ;; If POST, do not do it with postponed fontification
1810 (if (and post cperl-syntaxify-by-font-lock)
1812 (put-text-property (max (point-min) (1- from))
1813 to cperl-do-not-fontify t)))
1815 (defcustom cperl-mode-hook nil
1816 "Hook run by `cperl-mode'."
1820 (defvar cperl-syntax-state nil)
1821 (defvar cperl-syntax-done-to nil)
1822 (defvar cperl-emacs-can-parse (> (length (save-excursion
1823 (parse-partial-sexp 1 1))) 9))
1825 ;; Make customization possible "in reverse"
1826 (defsubst cperl-val (symbol &optional default hairy)
1828 ((eq (symbol-value symbol) 'null) default)
1829 (cperl-hairy (or hairy t))
1830 (t (symbol-value symbol))))
1832 ;;; Probably it is too late to set these guys already, but it can help later:
1834 (and cperl-clobber-mode-lists
1835 (setq auto-mode-alist
1836 (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
1837 (and (boundp 'interpreter-mode-alist)
1838 (setq interpreter-mode-alist (append interpreter-mode-alist
1839 '(("miniperl" . perl-mode))))))
1840 (if (fboundp 'eval-when-compile)
1860 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
1861 ;; macros instead of defsubsts don't work on Emacs, so we do the
1862 ;; expansion manually. Any other suggestions?
1863 (if (or (string-match "XEmacs\\|Lucid" emacs-version)
1865 (require 'font-lock))
1868 (defvar cperl-mode-abbrev-table nil
1869 "Abbrev table in use in Cperl-mode buffers.")
1871 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
1873 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
1875 (if cperl-mode-map nil
1876 (setq cperl-mode-map (make-sparse-keymap))
1877 (cperl-define-key "{" 'cperl-electric-lbrace)
1878 (cperl-define-key "[" 'cperl-electric-paren)
1879 (cperl-define-key "(" 'cperl-electric-paren)
1880 (cperl-define-key "<" 'cperl-electric-paren)
1881 (cperl-define-key "}" 'cperl-electric-brace)
1882 (cperl-define-key "]" 'cperl-electric-rparen)
1883 (cperl-define-key ")" 'cperl-electric-rparen)
1884 (cperl-define-key ";" 'cperl-electric-semi)
1885 (cperl-define-key ":" 'cperl-electric-terminator)
1886 (cperl-define-key "\C-j" 'newline-and-indent)
1887 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
1888 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
1889 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
1890 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
1891 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
1892 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
1893 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
1894 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
1895 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
1896 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
1898 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1899 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
1900 (cperl-define-key "\177" 'cperl-electric-backspace)
1901 (cperl-define-key "\t" 'cperl-indent-command)
1902 ;; don't clobber the backspace binding:
1903 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
1904 [(control c) (control h) F])
1905 (if (cperl-val 'cperl-clobber-lisp-bindings)
1907 (cperl-define-key "\C-hf"
1908 ;;(concat (char-to-string help-char) "f") ; does not work
1909 'cperl-info-on-command
1911 (cperl-define-key "\C-hv"
1912 ;;(concat (char-to-string help-char) "v") ; does not work
1915 (cperl-define-key "\C-c\C-hf"
1916 ;;(concat (char-to-string help-char) "f") ; does not work
1917 (key-binding "\C-hf")
1918 [(control c) (control h) f])
1919 (cperl-define-key "\C-c\C-hv"
1920 ;;(concat (char-to-string help-char) "v") ; does not work
1921 (key-binding "\C-hv")
1922 [(control c) (control h) v]))
1923 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
1924 [(control c) (control h) f])
1925 (cperl-define-key "\C-c\C-hv"
1926 ;;(concat (char-to-string help-char) "v") ; does not work
1928 [(control c) (control h) v]))
1929 (if (and cperl-xemacs-p
1930 (<= emacs-minor-version 11) (<= emacs-major-version 19))
1932 ;; substitute-key-definition is usefulness-deenhanced...
1933 (cperl-define-key "\M-q" 'cperl-fill-paragraph)
1934 (cperl-define-key "\e;" 'cperl-indent-for-comment)
1935 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
1936 (substitute-key-definition
1937 'indent-sexp 'cperl-indent-exp
1938 cperl-mode-map global-map)
1939 (substitute-key-definition
1940 'fill-paragraph 'cperl-fill-paragraph
1941 cperl-mode-map global-map)
1942 (substitute-key-definition
1943 'indent-region 'cperl-indent-region
1944 cperl-mode-map global-map)
1945 (substitute-key-definition
1946 'indent-for-comment 'cperl-indent-for-comment
1947 cperl-mode-map global-map)))
1950 (defvar cperl-lazy-installed)
1951 (defvar cperl-old-style nil)
1955 (easy-menu-define cperl-menu cperl-mode-map "Menu for CPerl mode"
1957 ["Beginning of function" beginning-of-defun t]
1958 ["End of function" end-of-defun t]
1959 ["Mark function" mark-defun t]
1960 ["Indent expression" cperl-indent-exp t]
1961 ["Fill paragraph/comment" cperl-fill-paragraph t]
1963 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
1964 ["Invert if/unless/while/until" cperl-invert-if-unless t]
1966 ["Beautify" cperl-beautify-regexp
1967 cperl-use-syntax-table-text-property]
1968 ["Beautify a group" cperl-beautify-level
1969 cperl-use-syntax-table-text-property]
1970 ["Contract a group" cperl-contract-level
1971 cperl-use-syntax-table-text-property]
1972 ["Contract groups" cperl-contract-levels
1973 cperl-use-syntax-table-text-property])
1974 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
1976 ["Indent region" cperl-indent-region (cperl-use-region-p)]
1977 ["Comment region" cperl-comment-region (cperl-use-region-p)]
1978 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
1980 ["Run" mode-compile (fboundp 'mode-compile)]
1981 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
1982 (get-buffer "*compilation*"))]
1983 ["Next error" next-error (get-buffer "*compilation*")]
1984 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
1986 ["Debugger" cperl-db t]
1989 ["Imenu" imenu (fboundp 'imenu)]
1990 ["Insert spaces if needed" cperl-find-bad-style t]
1991 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
1992 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
1993 ["CPerl pretty print (exprmntl)" cperl-ps-print
1994 (fboundp 'ps-extend-face-list)]
1995 ["Imenu on info" cperl-imenu-on-info (featurep 'imenu)]
1997 ;;; ["Create tags for current file" cperl-etags t]
1998 ;;; ["Add tags for current file" (cperl-etags t) t]
1999 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
2000 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
2001 ;;; ["Create tags for Perl files in (sub)directories"
2002 ;;; (cperl-etags nil 'recursive) t]
2003 ;;; ["Add tags for Perl files in (sub)directories"
2004 ;;; (cperl-etags t 'recursive) t])
2005 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
2006 ["Create tags for current file" (cperl-write-tags nil t) t]
2007 ["Add tags for current file" (cperl-write-tags) t]
2008 ["Create tags for Perl files in directory"
2009 (cperl-write-tags nil t nil t) t]
2010 ["Add tags for Perl files in directory"
2011 (cperl-write-tags nil nil nil t) t]
2012 ["Create tags for Perl files in (sub)directories"
2013 (cperl-write-tags nil t t t) t]
2014 ["Add tags for Perl files in (sub)directories"
2015 (cperl-write-tags nil nil t t) t]))
2017 ["Define word at point" imenu-go-find-at-position
2018 (fboundp 'imenu-go-find-at-position)]
2019 ["Help on function" cperl-info-on-command t]
2020 ["Help on function at point" cperl-info-on-current-command t]
2021 ["Help on symbol at point" cperl-get-help t]
2022 ["Perldoc" cperl-perldoc t]
2023 ["Perldoc on word at point" cperl-perldoc-at-point t]
2024 ["View manpage of POD in this file" cperl-pod-to-manpage t]
2025 ["Auto-help on" cperl-lazy-install
2026 (and (fboundp 'run-with-idle-timer)
2027 (not cperl-lazy-installed))]
2028 ["Auto-help off" (eval '(cperl-lazy-unstall))
2029 (and (fboundp 'run-with-idle-timer)
2030 cperl-lazy-installed)])
2032 ["Auto newline" cperl-toggle-auto-newline t]
2033 ["Electric parens" cperl-toggle-electric t]
2034 ["Electric keywords" cperl-toggle-abbrev t]
2035 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
2036 ["Auto fill" auto-fill-mode t])
2038 ["CPerl" (cperl-set-style "CPerl") t]
2039 ["PerlStyle" (cperl-set-style "PerlStyle") t]
2040 ["GNU" (cperl-set-style "GNU") t]
2041 ["C++" (cperl-set-style "C++") t]
2042 ["FSF" (cperl-set-style "FSF") t]
2043 ["BSD" (cperl-set-style "BSD") t]
2044 ["Whitesmith" (cperl-set-style "Whitesmith") t]
2045 ["Current" (cperl-set-style "Current") t]
2046 ["Memorized" (cperl-set-style-back) cperl-old-style])
2048 ["Tips" (describe-variable 'cperl-tips) t]
2049 ["Problems" (describe-variable 'cperl-problems) t]
2050 ["Non-problems" (describe-variable 'cperl-non-problems) t]
2051 ["Speed" (describe-variable 'cperl-speed) t]
2052 ["Praise" (describe-variable 'cperl-praise) t]
2053 ["Faces" (describe-variable 'cperl-tips-faces) t]
2054 ["CPerl mode" (describe-function 'cperl-mode) t]
2056 (message "The version of master-file for this CPerl is %s"
2057 cperl-version) t]))))
2060 (autoload 'c-macro-expand "cmacexp"
2061 "Display the result of expanding all C macros occurring in the region.
2062 The expansion is entirely correct because it uses the C preprocessor."
2065 (defvar cperl-mode-syntax-table nil
2066 "Syntax table in use in Cperl-mode buffers.")
2068 (defvar cperl-string-syntax-table nil
2069 "Syntax table in use in Cperl-mode string-like chunks.")
2071 (if cperl-mode-syntax-table
2073 (setq cperl-mode-syntax-table (make-syntax-table))
2074 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
2075 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
2076 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
2077 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
2078 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
2079 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
2080 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
2081 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
2082 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
2083 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
2084 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
2085 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
2086 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
2087 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
2088 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
2089 (if cperl-under-as-char
2090 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
2091 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
2092 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
2093 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
2094 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
2095 (modify-syntax-entry ?# "." cperl-string-syntax-table) ; (?# comment )
2100 ;; provide an alias for working with emacs 19. the perl-mode that comes
2101 ;; with it is really bad, and this lets us seamlessly replace it.
2103 (fset 'perl-mode 'cperl-mode)
2104 (defvar cperl-faces-init nil)
2106 (defvar cperl-msb-fixed nil)
2107 (defvar font-lock-syntactic-keywords)
2108 (defvar perl-font-lock-keywords)
2109 (defvar perl-font-lock-keywords-1)
2110 (defvar perl-font-lock-keywords-2)
2112 (defun cperl-mode ()
2113 "Major mode for editing Perl code.
2114 Expression and list commands understand all C brackets.
2115 Tab indents for Perl code.
2116 Paragraphs are separated by blank lines only.
2117 Delete converts tabs to spaces as it moves back.
2119 Various characters in Perl almost always come in pairs: {}, (), [],
2120 sometimes <>. When the user types the first, she gets the second as
2121 well, with optional special formatting done on {}. (Disabled by
2122 default.) You can always quote (with \\[quoted-insert]) the left
2123 \"paren\" to avoid the expansion. The processing of < is special,
2124 since most the time you mean \"less\". Cperl mode tries to guess
2125 whether you want to type pair <>, and inserts is if it
2126 appropriate. You can set `cperl-electric-parens-string' to the string that
2127 contains the parenths from the above list you want to be electrical.
2128 Electricity of parenths is controlled by `cperl-electric-parens'.
2129 You may also set `cperl-electric-parens-mark' to have electric parens
2130 look for active mark and \"embrace\" a region if possible.'
2132 CPerl mode provides expansion of the Perl control constructs:
2134 if, else, elsif, unless, while, until, continue, do,
2135 for, foreach, formy and foreachmy.
2137 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
2139 The user types the keyword immediately followed by a space, which
2140 causes the construct to be expanded, and the point is positioned where
2141 she is most likely to want to be. eg. when the user types a space
2142 following \"if\" the following appears in the buffer: if () { or if ()
2143 } { } and the cursor is between the parentheses. The user can then
2144 type some boolean expression within the parens. Having done that,
2145 typing \\[cperl-linefeed] places you - appropriately indented - on a
2146 new line between the braces (if you typed \\[cperl-linefeed] in a POD
2147 directive line, then appropriate number of new lines is inserted).
2149 If CPerl decides that you want to insert \"English\" style construct like
2153 it will not do any expansion. See also help on variable
2154 `cperl-extra-newline-before-brace'. (Note that one can switch the
2155 help message on expansion by setting `cperl-message-electric-keyword'
2158 \\[cperl-linefeed] is a convenience replacement for typing carriage
2159 return. It places you in the next line with proper indentation, or if
2160 you type it inside the inline block of control construct, like
2162 foreach (@lines) {print; print}
2164 and you are on a boundary of a statement inside braces, it will
2165 transform the construct into a multiline and will place you into an
2166 appropriately indented blank line. If you need a usual
2167 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
2168 see documentation on `cperl-electric-linefeed'.
2170 Use \\[cperl-invert-if-unless] to change a construction of the form
2180 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
2181 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
2182 on electric space between $ and {, `cperl-electric-parens-string' is
2183 the string that contains parentheses that should be electric in CPerl
2184 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
2185 setting `cperl-electric-keywords' enables electric expansion of
2186 control structures in CPerl. `cperl-electric-linefeed' governs which
2187 one of two linefeed behavior is preferable. You can enable all these
2188 options simultaneously (recommended mode of use) by setting
2189 `cperl-hairy' to t. In this case you can switch separate options off
2190 by setting them to `null'. Note that one may undo the extra
2191 whitespace inserted by semis and braces in `auto-newline'-mode by
2192 consequent \\[cperl-electric-backspace].
2194 If your site has perl5 documentation in info format, you can use commands
2195 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
2196 These keys run commands `cperl-info-on-current-command' and
2197 `cperl-info-on-command', which one is which is controlled by variable
2198 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
2199 \(in turn affected by `cperl-hairy').
2201 Even if you have no info-format documentation, short one-liner-style
2202 help is available on \\[cperl-get-help], and one can run perldoc or
2205 It is possible to show this help automatically after some idle time.
2206 This is regulated by variable `cperl-lazy-help-time'. Default with
2207 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
2208 secs idle time . It is also possible to switch this on/off from the
2209 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
2211 Use \\[cperl-lineup] to vertically lineup some construction - put the
2212 beginning of the region at the start of construction, and make region
2213 span the needed amount of lines.
2215 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
2216 `cperl-pod-face', `cperl-pod-head-face' control processing of pod and
2217 here-docs sections. With capable Emaxen results of scan are used
2218 for indentation too, otherwise they are used for highlighting only.
2220 Variables controlling indentation style:
2221 `cperl-tab-always-indent'
2222 Non-nil means TAB in CPerl mode should always reindent the current line,
2223 regardless of where in the line point is when the TAB command is used.
2224 `cperl-indent-left-aligned-comments'
2225 Non-nil means that the comment starting in leftmost column should indent.
2226 `cperl-auto-newline'
2227 Non-nil means automatically newline before and after braces,
2228 and after colons and semicolons, inserted in Perl code. The following
2229 \\[cperl-electric-backspace] will remove the inserted whitespace.
2230 Insertion after colons requires both this variable and
2231 `cperl-auto-newline-after-colon' set.
2232 `cperl-auto-newline-after-colon'
2233 Non-nil means automatically newline even after colons.
2234 Subject to `cperl-auto-newline' setting.
2235 `cperl-indent-level'
2236 Indentation of Perl statements within surrounding block.
2237 The surrounding block's indentation is the indentation
2238 of the line on which the open-brace appears.
2239 `cperl-continued-statement-offset'
2240 Extra indentation given to a substatement, such as the
2241 then-clause of an if, or body of a while, or just a statement continuation.
2242 `cperl-continued-brace-offset'
2243 Extra indentation given to a brace that starts a substatement.
2244 This is in addition to `cperl-continued-statement-offset'.
2245 `cperl-brace-offset'
2246 Extra indentation for line if it starts with an open brace.
2247 `cperl-brace-imaginary-offset'
2248 An open brace following other text is treated as if it the line started
2249 this far to the right of the actual line indentation.
2250 `cperl-label-offset'
2251 Extra indentation for line that is a label.
2252 `cperl-min-label-indent'
2253 Minimal indentation for line that is a label.
2255 Settings for K&R and BSD indentation styles are
2256 `cperl-indent-level' 5 8
2257 `cperl-continued-statement-offset' 5 8
2258 `cperl-brace-offset' -5 -8
2259 `cperl-label-offset' -5 -8
2261 CPerl knows several indentation styles, and may bulk set the
2262 corresponding variables. Use \\[cperl-set-style] to do this. Use
2263 \\[cperl-set-style-back] to restore the memorized preexisting values
2264 \(both available from menu).
2266 If `cperl-indent-level' is 0, the statement after opening brace in
2267 column 0 is indented on
2268 `cperl-brace-offset'+`cperl-continued-statement-offset'.
2270 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
2273 DO NOT FORGET to read micro-docs (available from `Perl' menu)
2274 or as help on variables `cperl-tips', `cperl-problems',
2275 `cperl-non-problems', `cperl-praise', `cperl-speed'."
2277 (kill-all-local-variables)
2278 (use-local-map cperl-mode-map)
2279 (if (cperl-val 'cperl-electric-linefeed)
2281 (local-set-key "\C-J" 'cperl-linefeed)
2282 (local-set-key "\C-C\C-J" 'newline-and-indent)))
2284 (cperl-val 'cperl-clobber-lisp-bindings)
2285 (cperl-val 'cperl-info-on-command-no-prompt))
2287 ;; don't clobber the backspace binding:
2288 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
2289 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
2290 [(control c) (control h) f])))
2291 (setq major-mode 'perl-mode)
2292 (setq mode-name "CPerl")
2293 (if (not cperl-mode-abbrev-table)
2294 (let ((prev-a-c abbrevs-changed))
2295 (define-abbrev-table 'cperl-mode-abbrev-table '(
2296 ("if" "if" cperl-electric-keyword 0)
2297 ("elsif" "elsif" cperl-electric-keyword 0)
2298 ("while" "while" cperl-electric-keyword 0)
2299 ("until" "until" cperl-electric-keyword 0)
2300 ("unless" "unless" cperl-electric-keyword 0)
2301 ("else" "else" cperl-electric-else 0)
2302 ("continue" "continue" cperl-electric-else 0)
2303 ("for" "for" cperl-electric-keyword 0)
2304 ("foreach" "foreach" cperl-electric-keyword 0)
2305 ("formy" "formy" cperl-electric-keyword 0)
2306 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
2307 ("do" "do" cperl-electric-keyword 0)
2308 ("pod" "pod" cperl-electric-pod 0)
2309 ("over" "over" cperl-electric-pod 0)
2310 ("head1" "head1" cperl-electric-pod 0)
2311 ("head2" "head2" cperl-electric-pod 0)))
2312 (setq abbrevs-changed prev-a-c)))
2313 (setq local-abbrev-table cperl-mode-abbrev-table)
2314 (abbrev-mode (if (cperl-val 'cperl-electric-keywords) 1 0))
2315 (set-syntax-table cperl-mode-syntax-table)
2316 (make-local-variable 'paragraph-start)
2317 (setq paragraph-start (concat "^$\\|" page-delimiter))
2318 (make-local-variable 'paragraph-separate)
2319 (setq paragraph-separate paragraph-start)
2320 (make-local-variable 'paragraph-ignore-fill-prefix)
2321 (setq paragraph-ignore-fill-prefix t)
2322 (make-local-variable 'indent-line-function)
2323 (setq indent-line-function 'cperl-indent-line)
2324 (make-local-variable 'require-final-newline)
2325 (setq require-final-newline t)
2326 (make-local-variable 'comment-start)
2327 (setq comment-start "# ")
2328 (make-local-variable 'comment-end)
2329 (setq comment-end "")
2330 (make-local-variable 'comment-column)
2331 (setq comment-column cperl-comment-column)
2332 (make-local-variable 'comment-start-skip)
2333 (setq comment-start-skip "#+ *")
2334 (make-local-variable 'defun-prompt-regexp)
2335 (setq defun-prompt-regexp "^[ \t]*sub[ \t]+\\([^ \t\n{(;]+\\)[ \t]*")
2336 (make-local-variable 'comment-indent-function)
2337 (setq comment-indent-function 'cperl-comment-indent)
2338 (make-local-variable 'parse-sexp-ignore-comments)
2339 (setq parse-sexp-ignore-comments t)
2340 (make-local-variable 'indent-region-function)
2341 (setq indent-region-function 'cperl-indent-region)
2342 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
2343 (make-local-variable 'imenu-create-index-function)
2344 (setq imenu-create-index-function
2345 (function imenu-example--create-perl-index))
2346 (make-local-variable 'imenu-sort-function)
2347 (setq imenu-sort-function nil)
2348 (make-local-variable 'vc-header-alist)
2349 (set 'vc-header-alist cperl-vc-header-alist) ; Avoid warning
2350 (make-local-variable 'font-lock-defaults)
2351 (setq font-lock-defaults
2353 ((string< emacs-version "19.30")
2354 '(perl-font-lock-keywords-2))
2355 ((string< emacs-version "19.33") ; Which one to use?
2356 '((perl-font-lock-keywords
2357 perl-font-lock-keywords-1
2358 perl-font-lock-keywords-2)))
2360 '((cperl-load-font-lock-keywords
2361 cperl-load-font-lock-keywords-1
2362 cperl-load-font-lock-keywords-2)))))
2363 (make-local-variable 'cperl-syntax-state)
2364 (if cperl-use-syntax-table-text-property
2366 (make-variable-buffer-local 'parse-sexp-lookup-properties)
2367 ;; Do not introduce variable if not needed, we check it!
2368 (set 'parse-sexp-lookup-properties t)
2369 ;; Fix broken font-lock:
2370 (or (boundp 'font-lock-unfontify-region-function)
2371 (set 'font-lock-unfontify-region-function
2372 'font-lock-default-unfontify-region))
2373 (make-variable-buffer-local 'font-lock-unfontify-region-function)
2374 (set 'font-lock-unfontify-region-function
2375 'cperl-font-lock-unfontify-region-function)
2376 (make-variable-buffer-local 'cperl-syntax-done-to)
2377 ;; Another bug: unless font-lock-syntactic-keywords, font-lock
2378 ;; ignores syntax-table text-property. (t) is a hack
2379 ;; to make font-lock think that font-lock-syntactic-keywords
2381 (make-variable-buffer-local 'font-lock-syntactic-keywords)
2382 (setq font-lock-syntactic-keywords
2383 (if cperl-syntaxify-by-font-lock
2384 '(t (cperl-fontify-syntaxically))
2386 (make-local-variable 'cperl-old-style)
2387 (or (fboundp 'cperl-old-auto-fill-mode)
2389 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
2390 (defun auto-fill-mode (&optional arg)
2392 (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
2393 (and auto-fill-function (eq major-mode 'perl-mode)
2394 (setq auto-fill-function 'cperl-do-auto-fill)))))
2395 (if (cperl-enable-font-lock)
2396 (if (cperl-val 'cperl-font-lock)
2397 (progn (or cperl-faces-init (cperl-init-faces))
2398 (font-lock-mode 1))))
2399 (and (boundp 'msb-menu-cond)
2400 (not cperl-msb-fixed)
2402 (if (featurep 'easymenu)
2403 (easy-menu-add cperl-menu)) ; A NOP in RMS Emacs.
2404 (run-hooks 'cperl-mode-hook)
2405 ;; After hooks since fontification will break this
2406 (if cperl-pod-here-scan
2407 (or ;;(and (boundp 'font-lock-mode)
2408 ;; (eval 'font-lock-mode) ; Avoid warning
2409 ;; (boundp 'font-lock-hot-pass) ; Newer font-lock
2410 cperl-syntaxify-by-font-lock ;;)
2411 (progn (or cperl-faces-init (cperl-init-faces-weak))
2412 (cperl-find-pods-heres)))))
2414 ;; Fix for perldb - make default reasonable
2415 (defvar gud-perldb-history)
2419 (perldb (read-from-minibuffer "Run perldb (like this): "
2420 (if (consp gud-perldb-history)
2421 (car gud-perldb-history)
2422 (concat "perl " ;;(file-name-nondirectory
2426 (buffer-file-name)))
2428 '(gud-perldb-history . 1))))
2430 (defvar msb-menu-cond)
2431 (defun cperl-msb-fix ()
2432 ;; Adds perl files to msb menu, supposes that msb is already loaded
2433 (setq cperl-msb-fixed t)
2434 (let* ((l (length msb-menu-cond))
2435 (last (nth (1- l) msb-menu-cond))
2436 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
2437 (handle (1- (nth 1 last))))
2438 (setcdr precdr (list
2440 '(eq major-mode 'perl-mode)
2445 ;; This is used by indent-for-comment
2446 ;; to decide how much to indent a comment in CPerl code
2447 ;; based on its context. Do fallback if comment is found wrong.
2449 (defvar cperl-wrong-comment)
2450 (defvar cperl-st-cfence '(14)) ; Comment-fence
2451 (defvar cperl-st-sfence '(15)) ; String-fence
2452 (defvar cperl-st-punct '(1))
2453 (defvar cperl-st-word '(2))
2454 (defvar cperl-st-bra '(4 . ?\>))
2455 (defvar cperl-st-ket '(5 . ?\<))
2458 (defun cperl-comment-indent ()
2459 (let ((p (point)) (c (current-column)) was phony)
2460 (if (looking-at "^#") 0 ; Existing comment at bol stays there.
2461 ;; Wrong comment found
2463 (setq was (cperl-to-comment-or-eol)
2464 phony (eq (get-text-property (point) 'syntax-table)
2468 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
2469 (if (eq (preceding-char) ?\#)
2474 (skip-chars-backward " \t")
2475 (max (1+ (current-column)) ; Else indent at comment column
2478 (insert comment-start)
2479 (backward-char (length comment-start)))
2480 (setq cperl-wrong-comment t)
2481 (indent-to comment-column 1) ; Indent minimum 1
2482 c))))) ; except leave at least one space.
2484 ;;;(defun cperl-comment-indent-fallback ()
2485 ;;; "Is called if the standard comment-search procedure fails.
2486 ;;;Point is at start of real comment."
2487 ;;; (let ((c (current-column)) target cnt prevc)
2488 ;;; (if (= c comment-column) nil
2489 ;;; (setq cnt (skip-chars-backward "[ \t]"))
2490 ;;; (setq target (max (1+ (setq prevc
2491 ;;; (current-column))) ; Else indent at comment column
2492 ;;; comment-column))
2493 ;;; (if (= c comment-column) nil
2494 ;;; (delete-backward-char cnt)
2495 ;;; (while (< prevc target)
2497 ;;; (setq prevc (current-column)))
2498 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
2499 ;;; (while (< prevc target)
2501 ;;; (setq prevc (current-column)))))))
2503 (defun cperl-indent-for-comment ()
2504 "Substitute for `indent-for-comment' in CPerl."
2506 (let (cperl-wrong-comment)
2507 (indent-for-comment)
2508 (if cperl-wrong-comment
2509 (progn (cperl-to-comment-or-eol)
2510 (forward-char (length comment-start))))))
2512 (defun cperl-comment-region (b e arg)
2513 "Comment or uncomment each line in the region in CPerl mode.
2514 See `comment-region'."
2515 (interactive "r\np")
2516 (let ((comment-start "#"))
2517 (comment-region b e arg)))
2519 (defun cperl-uncomment-region (b e arg)
2520 "Uncomment or comment each line in the region in CPerl mode.
2521 See `comment-region'."
2522 (interactive "r\np")
2523 (let ((comment-start "#"))
2524 (comment-region b e (- arg))))
2526 (defvar cperl-brace-recursing nil)
2528 (defun cperl-electric-brace (arg &optional only-before)
2529 "Insert character and correct line's indentation.
2530 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
2531 place (even in empty line), but not after. If after \")\" and the inserted
2532 char is \"{\", insert extra newline before only if
2533 `cperl-extra-newline-before-brace'."
2536 (other-end (if (and cperl-electric-parens-mark
2542 (not cperl-brace-recursing)
2543 (cperl-val 'cperl-electric-parens)
2544 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
2545 ;; Need to insert a matching pair
2548 (setq insertpos (point-marker))
2549 (goto-char other-end)
2550 (setq last-command-char ?\{)
2551 (cperl-electric-lbrace arg insertpos))
2553 ;: Check whether we close something "usual" with `}'
2554 (if (and (eq last-command-char ?\})
2558 (up-list (- (prefix-numeric-value arg)))
2559 ;;(cperl-after-block-p (point-min))
2560 (cperl-after-expr-p nil "{;)"))
2562 ;; Just insert the guy
2563 (self-insert-command (prefix-numeric-value arg))
2564 (if (and (not arg) ; No args, end (of empty line or auto)
2566 (or (and (null only-before)
2568 (skip-chars-backward " \t")
2570 (and (eq last-command-char ?\{) ; Do not insert newline
2571 ;; if after ")" and `cperl-extra-newline-before-brace'
2572 ;; is nil, do not insert extra newline.
2573 (not cperl-extra-newline-before-brace)
2575 (skip-chars-backward " \t")
2576 (eq (preceding-char) ?\))))
2577 (if cperl-auto-newline
2578 (progn (cperl-indent-line) (newline) t) nil)))
2580 (self-insert-command (prefix-numeric-value arg))
2582 (if cperl-auto-newline
2583 (setq insertpos (1- (point))))
2584 (if (and cperl-auto-newline (null only-before))
2587 (cperl-indent-line)))
2589 (if insertpos (progn (goto-char insertpos)
2590 (search-forward (make-string
2591 1 last-command-char))
2592 (setq insertpos (1- (point)))))
2596 (goto-char insertpos)
2597 (self-insert-command (prefix-numeric-value arg)))
2598 (self-insert-command (prefix-numeric-value arg)))))))
2600 (defun cperl-electric-lbrace (arg &optional end)
2601 "Insert character, correct line's indentation, correct quoting by space."
2604 (cperl-brace-recursing t)
2605 (cperl-auto-newline cperl-auto-newline)
2607 (if (and cperl-electric-parens-mark
2614 (and (cperl-val 'cperl-electric-lbrace-space)
2615 (eq (preceding-char) ?$)
2617 (skip-chars-backward "$")
2618 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
2620 ;; Check whether we are in comment
2624 (not (looking-at "[ \t]*#")))
2625 (cperl-after-expr-p nil "{;)"))
2627 (setq cperl-auto-newline nil))
2628 (cperl-electric-brace arg)
2629 (and (cperl-val 'cperl-electric-parens)
2630 (eq last-command-char ?{)
2631 (memq last-command-char
2632 (append cperl-electric-parens-string nil))
2633 (or (if other-end (goto-char (marker-position other-end)))
2635 (setq last-command-char ?} pos (point))
2636 (progn (cperl-electric-brace arg t)
2639 (defun cperl-electric-paren (arg)
2640 "Insert a matching pair of parentheses."
2642 (let ((beg (save-excursion (beginning-of-line) (point)))
2643 (other-end (if (and cperl-electric-parens-mark
2650 (if (and (cperl-val 'cperl-electric-parens)
2651 (memq last-command-char
2652 (append cperl-electric-parens-string nil))
2653 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2654 ;;(not (save-excursion (search-backward "#" beg t)))
2655 (if (eq last-command-char ?<)
2657 (and abbrev-mode ; later it is too late, may be after `for'
2659 (cperl-after-expr-p nil "{;(,:="))
2662 (self-insert-command (prefix-numeric-value arg))
2663 (if other-end (goto-char (marker-position other-end)))
2664 (insert (make-string
2665 (prefix-numeric-value arg)
2666 (cdr (assoc last-command-char '((?{ .?})
2670 (forward-char (- (prefix-numeric-value arg))))
2671 (self-insert-command (prefix-numeric-value arg)))))
2673 (defun cperl-electric-rparen (arg)
2674 "Insert a matching pair of parentheses if marking is active.
2675 If not, or if we are not at the end of marking range, would self-insert."
2677 (let ((beg (save-excursion (beginning-of-line) (point)))
2678 (other-end (if (and cperl-electric-parens-mark
2679 (cperl-val 'cperl-electric-parens)
2680 (memq last-command-char
2681 (append cperl-electric-parens-string nil))
2688 (cperl-val 'cperl-electric-parens)
2689 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
2690 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
2691 ;;(not (save-excursion (search-backward "#" beg t)))
2694 (self-insert-command (prefix-numeric-value arg))
2696 (if other-end (goto-char other-end))
2697 (insert (make-string
2698 (prefix-numeric-value arg)
2699 (cdr (assoc last-command-char '((?\} . ?\{)
2704 (self-insert-command (prefix-numeric-value arg)))))
2706 (defun cperl-electric-keyword ()
2707 "Insert a construction appropriate after a keyword.
2708 Help message may be switched off by setting `cperl-message-electric-keyword'
2710 (let ((beg (save-excursion (beginning-of-line) (point)))
2711 (dollar (and (eq last-command-char ?$)
2712 (eq this-command 'self-insert-command)))
2713 (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
2714 (memq this-command '(self-insert-command newline))))
2716 (and (save-excursion
2720 (setq do (looking-at "do\\>")))
2722 (cperl-after-expr-p nil "{;:"))
2726 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2728 (save-excursion (or (not (re-search-backward "^=" nil t))
2731 (and cperl-use-syntax-table-text-property
2732 (not (eq (get-text-property (point)
2736 (and (eq (preceding-char) ?y)
2737 (progn ; "foreachmy"
2743 (memq this-command '(self-insert-command newline)))))
2744 (and dollar (insert " $"))
2746 ;;(insert " () {\n}")
2748 (cperl-extra-newline-before-brace
2749 (insert (if do "\n" " ()\n"))
2755 (and do (insert " while ();")))
2757 (insert (if do " {\n} while ();" " () {\n}")))
2759 (or (looking-at "[ \t]\\|$") (insert " "))
2761 (if dollar (progn (search-backward "$")
2765 (search-backward ")"))
2767 (cperl-putback-char cperl-del-back-ch))
2768 (if cperl-message-electric-keyword
2769 (message "Precede char by C-q to avoid expansion"))))))
2771 (defun cperl-ensure-newlines (n &optional pos)
2772 "Make sure there are N newlines after the point."
2773 (or pos (setq pos (point)))
2774 (if (looking-at "\n")
2778 (cperl-ensure-newlines (1- n) pos)
2781 (defun cperl-electric-pod ()
2782 "Insert a POD chunk appropriate after a =POD directive."
2783 (let ((delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
2784 (memq this-command '(self-insert-command newline))))
2785 head1 notlast name p really-delete over)
2786 (and (save-excursion
2791 (eq (preceding-char) ?=)
2793 (setq head1 (looking-at "head1\\>"))
2794 (setq over (looking-at "over\\>"))
2798 (get-text-property (point) 'in-pod)
2799 (cperl-after-expr-p nil "{;:")
2800 (and (re-search-backward
2801 "\\(\\`\n?\\|\n\n\\)=\\sw+" (point-min) t)
2804 (and cperl-use-syntax-table-text-property
2805 (not (eq (get-text-property (point) 'syntax-type)
2809 (setq notlast (search-forward "\n\n=" nil t)))
2813 (cperl-ensure-newlines 2)
2819 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
2820 nil t)))) ; Only one
2823 (setq name (file-name-sans-extension
2824 (file-name-nondirectory (buffer-file-name)))
2826 (insert " NAME\n\n" name
2827 " - \n\n=head1 SYNOPSYS\n\n\n\n"
2828 "=head1 DESCRIPTION")
2829 (cperl-ensure-newlines 4)
2833 (setq really-delete t))
2838 (insert "\n\n=item \n\n\n\n"
2840 (cperl-ensure-newlines 2)
2844 (setq really-delete t)))
2845 (if (and delete really-delete)
2846 (cperl-putback-char cperl-del-back-ch))))))
2848 (defun cperl-electric-else ()
2849 "Insert a construction appropriate after a keyword.
2850 Help message may be switched off by setting `cperl-message-electric-keyword'
2852 (let ((beg (save-excursion (beginning-of-line) (point))))
2853 (and (save-excursion
2855 (cperl-after-expr-p nil "{;:"))
2859 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2861 (save-excursion (or (not (re-search-backward "^=" nil t))
2863 (and cperl-use-syntax-table-text-property
2864 (not (eq (get-text-property (point)
2869 ;;(insert " {\n\n}")
2871 (cperl-extra-newline-before-brace
2879 (or (looking-at "[ \t]\\|$") (insert " "))
2883 (cperl-putback-char cperl-del-back-ch)
2884 (setq this-command 'cperl-electric-else)
2885 (if cperl-message-electric-keyword
2886 (message "Precede char by C-q to avoid expansion"))))))
2888 (defun cperl-linefeed ()
2889 "Go to end of line, open a new line and indent appropriately.
2890 If in POD, insert appropriate lines."
2892 (let ((beg (save-excursion (beginning-of-line) (point)))
2893 (end (save-excursion (end-of-line) (point)))
2894 (pos (point)) start over cut res)
2895 (if (and ; Check if we need to split:
2896 ; i.e., on a boundary and inside "{...}"
2897 (save-excursion (cperl-to-comment-or-eol)
2898 (>= (point) pos)) ; Not in a comment
2900 (skip-chars-backward " \t" beg)
2902 (looking-at "[;{]")) ; After { or ; + spaces
2903 (looking-at "[ \t]*}") ; Before }
2904 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
2907 (eq (car (parse-partial-sexp pos end -1)) -1)
2908 ; Leave the level of parens
2909 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
2913 (setq start (point-marker))
2914 (<= start pos))))) ; Redundant? Are after the
2915 ; start of parens group.
2917 (skip-chars-backward " \t")
2918 (or (memq (preceding-char) (append ";{" nil))
2924 (or (looking-at "{[ \t]*$") ; If there is a statement
2925 ; before, move it to separate line
2929 (cperl-indent-line)))
2930 (forward-line 1) ; We are on the target line
2933 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
2934 ; after, move it to separate line
2937 (search-backward "}" beg)
2938 (skip-chars-backward " \t")
2939 (or (memq (preceding-char) (append ";{" nil))
2944 (forward-line -1) ; We are on the line before target
2946 (newline-and-indent))
2947 (end-of-line) ; else - no splitting
2949 ((and (looking-at "\n[ \t]*{$")
2951 (skip-chars-backward " \t")
2952 (eq (preceding-char) ?\)))) ; Probably if () {} group
2953 ; with an extra newline.
2955 (cperl-indent-line))
2956 ((save-excursion ; In POD header
2957 (forward-paragraph -1)
2958 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
2959 ;; We are after \n now, so look for the rest
2960 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
2962 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
2963 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
2967 (forward-paragraph -1)
2970 (setq cut (buffer-substring (point)
2974 (delete-char (- (save-excursion (end-of-line) (point))
2976 (setq res (expand-abbrev))
2982 (cperl-ensure-newlines (if cut 2 4))
2984 ((get-text-property (point) 'in-pod) ; In POD section
2985 (cperl-ensure-newlines 4)
2987 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
2989 (cperl-indent-line))
2991 (newline-and-indent))))))
2993 (defun cperl-electric-semi (arg)
2994 "Insert character and correct line's indentation."
2996 (if cperl-auto-newline
2997 (cperl-electric-terminator arg)
2998 (self-insert-command (prefix-numeric-value arg))))
3000 (defun cperl-electric-terminator (arg)
3001 "Insert character and correct line's indentation."
3003 (let (insertpos (end (point))
3004 (auto (and cperl-auto-newline
3005 (or (not (eq last-command-char ?:))
3006 cperl-auto-newline-after-colon))))
3007 (if (and ;;(not arg)
3009 (not (save-excursion
3011 (skip-chars-forward " \t")
3013 ;; Ignore in comment lines
3014 (= (following-char) ?#)
3015 ;; Colon is special only after a label
3016 ;; So quickly rule out most other uses of colon
3017 ;; and do no indentation for them.
3018 (and (eq last-command-char ?:)
3021 (skip-chars-forward " \t")
3022 (and (< (point) end)
3023 (progn (goto-char (- end 1))
3024 (not (looking-at ":"))))))
3026 (beginning-of-defun)
3027 (let ((pps (parse-partial-sexp (point) end)))
3028 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
3030 (self-insert-command (prefix-numeric-value arg))
3032 (if auto (setq insertpos (point-marker)))
3038 (cperl-indent-line)))
3040 (if insertpos (goto-char (1- (marker-position insertpos)))
3045 (goto-char insertpos)
3046 (self-insert-command (prefix-numeric-value arg)))
3047 (self-insert-command (prefix-numeric-value arg)))))
3049 (defun cperl-electric-backspace (arg)
3050 "Backspace-untabify, or remove the whitespace around the point inserted
3051 by an electric key."
3053 (if (and cperl-auto-newline
3054 (memq last-command '(cperl-electric-semi
3055 cperl-electric-terminator
3056 cperl-electric-lbrace))
3057 (memq (preceding-char) '(?\ ?\t ?\n)))
3059 (if (eq last-command 'cperl-electric-lbrace)
3060 (skip-chars-forward " \t\n"))
3062 (skip-chars-backward " \t\n")
3063 (delete-region (point) p))
3064 (and (eq last-command 'cperl-electric-else)
3065 ;; We are removing the whitespace *inside* cperl-electric-else
3066 (setq this-command 'cperl-electric-else-really))
3067 (if (and cperl-auto-newline
3068 (eq last-command 'cperl-electric-else-really)
3069 (memq (preceding-char) '(?\ ?\t ?\n)))
3071 (skip-chars-forward " \t\n")
3073 (skip-chars-backward " \t\n")
3074 (delete-region (point) p))
3075 (backward-delete-char-untabify arg))))
3077 (defun cperl-inside-parens-p ()
3081 (narrow-to-region (point)
3082 (progn (beginning-of-defun) (point)))
3083 (goto-char (point-max))
3084 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
3087 (defun cperl-indent-command (&optional whole-exp)
3088 "Indent current line as Perl code, or in some cases insert a tab character.
3089 If `cperl-tab-always-indent' is non-nil (the default), always indent current
3090 line. Otherwise, indent the current line only if point is at the left margin
3091 or in the line's indentation; otherwise insert a tab.
3093 A numeric argument, regardless of its value,
3094 means indent rigidly all the lines of the expression starting after point
3095 so that this line becomes properly indented.
3096 The relative indentation among the lines of the expression are preserved."
3098 (cperl-update-syntaxification (point) (point))
3100 ;; If arg, always indent this line as Perl
3101 ;; and shift remaining lines of expression the same amount.
3102 (let ((shift-amt (cperl-indent-line))
3105 (if cperl-tab-always-indent
3106 (beginning-of-line))
3113 (if (and shift-amt (> end beg))
3114 (indent-code-rigidly beg end shift-amt "#")))
3115 (if (and (not cperl-tab-always-indent)
3117 (skip-chars-backward " \t")
3120 (cperl-indent-line))))
3122 (defun cperl-indent-line (&optional parse-data)
3123 "Indent current line as Perl code.
3124 Return the amount the indentation changed by."
3125 (let (indent i beg shift-amt
3126 (case-fold-search nil)
3127 (pos (- (point-max) (point))))
3128 (setq indent (cperl-calculate-indent parse-data)
3132 (cond ((or (eq indent nil) (eq indent t))
3133 (setq indent (current-indentation) i nil))
3134 ;;((eq indent t) ; Never?
3135 ;; (setq indent (cperl-calculate-indent-within-comment)))
3136 ;;((looking-at "[ \t]*#")
3139 (skip-chars-forward " \t")
3140 (if (listp indent) (setq indent (car indent)))
3141 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
3143 (setq indent (max cperl-min-label-indent
3144 (+ indent cperl-label-offset)))))
3145 ((= (following-char) ?})
3146 (setq indent (- indent cperl-indent-level)))
3147 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
3148 (setq indent (+ indent cperl-close-paren-offset)))
3149 ((= (following-char) ?{)
3150 (setq indent (+ indent cperl-brace-offset))))))
3151 (skip-chars-forward " \t")
3152 (setq shift-amt (and i (- indent (current-column))))
3153 (if (or (not shift-amt)
3155 (if (> (- (point-max) pos) (point))
3156 (goto-char (- (point-max) pos)))
3157 (delete-region beg (point))
3159 ;; If initial point was within line's indentation,
3160 ;; position after the indentation. Else stay at same point in text.
3161 (if (> (- (point-max) pos) (point))
3162 (goto-char (- (point-max) pos))))
3165 (defun cperl-after-label ()
3166 ;; Returns true if the point is after label. Does not do save-excursion.
3167 (and (eq (preceding-char) ?:)
3168 (memq (char-syntax (char-after (- (point) 2)))
3172 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
3174 (defun cperl-get-state (&optional parse-start start-state)
3175 ;; returns list (START STATE DEPTH PRESTART),
3176 ;; START is a good place to start parsing, or equal to
3177 ;; PARSE-START if preset,
3178 ;; STATE is what is returned by `parse-partial-sexp'.
3179 ;; DEPTH is true is we are immediately after end of block
3180 ;; which contains START.
3181 ;; PRESTART is the position basing on which START was found.
3183 (let ((start-point (point)) depth state start prestart)
3184 (if (and parse-start
3185 (<= parse-start start-point))
3186 (goto-char parse-start)
3187 (beginning-of-defun)
3188 (setq start-state nil))
3189 (setq prestart (point))
3191 ;; Try to go out, if sub is not on the outermost level
3192 (while (< (point) start-point)
3193 (setq start (point) parse-start start depth nil
3194 state (parse-partial-sexp start start-point -1))
3195 (if (> (car state) -1) nil
3196 ;; The current line could start like }}}, so the indentation
3197 ;; corresponds to a different level than what we reached
3199 (beginning-of-line 2))) ; Go to the next line.
3200 (if start (goto-char start))) ; Not at the start of file
3201 (setq start (point))
3202 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
3203 (list start state depth prestart))))
3205 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
3206 ;; Positions is before ?\{. Checks whether it starts a block.
3207 ;; No save-excursion!
3208 (cperl-backward-to-noncomment (point-min))
3209 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
3210 ; Label may be mixed up with `$blah :'
3211 (save-excursion (cperl-after-label))
3212 (and (memq (char-syntax (preceding-char)) '(?w ?_))
3215 ;; Need take into account `bless', `return', `tr',...
3216 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
3217 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
3219 (skip-chars-backward " \t\n\f")
3220 (and (memq (char-syntax (preceding-char)) '(?w ?_))
3224 "sub[ \t]+[a-zA-Z0-9_:]+[ \t\n\f]*\\(([^()]*)[ \t\n\f]*\\)?[#{]")))))))))
3226 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
3228 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
3229 "Return appropriate indentation for current line as Perl code.
3230 In usual case returns an integer: the column to indent to.
3231 Returns nil if line starts inside a string, t if in a comment.
3233 Will not correct the indentation for labels, but will correct it for braces
3234 and closing parentheses and brackets.."
3237 (memq (get-text-property (point) 'syntax-type)
3238 '(pod here-doc here-doc-delim format))
3239 ;; before start of POD - whitespace found since do not have 'pod!
3240 (and (looking-at "[ \t]*\n=")
3241 (error "Spaces before pod section!"))
3242 (and (not cperl-indent-left-aligned-comments)
3246 (let ((indent-point (point))
3247 (char-after (save-excursion
3248 (skip-chars-forward " \t")
3250 (in-pod (get-text-property (point) 'in-pod))
3251 (pre-indent-point (point))
3255 ;; In the verbatim part, probably code example. What to do???
3260 (cperl-backward-to-noncomment nil)
3261 (setq p (max (point-min) (1- (point)))
3262 prop (get-text-property p 'syntax-type)
3263 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
3265 (if (memq prop '(pod here-doc format here-doc-delim))
3267 (goto-char (or (previous-single-property-change p look-prop)
3270 (setq pre-indent-point (point)))))))
3271 (goto-char pre-indent-point)
3272 (let* ((case-fold-search nil)
3273 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
3274 (start (or (nth 2 parse-data)
3277 (containing-sexp (car (cdr state)))
3280 ;;containing-sexp ;; We are buggy at toplevel :-(
3283 (setcar parse-data pre-indent-point)
3284 (setcar (cdr parse-data) state)
3285 (or (nth 2 parse-data)
3286 (setcar (cddr parse-data) start))
3287 ;; Before this point: end of statement
3288 (setq old-indent (nth 3 parse-data))))
3289 ;; (or parse-start (null symbol)
3290 ;; (setq parse-start (symbol-value symbol)
3291 ;; start-indent (nth 2 parse-start)
3292 ;; parse-start (car parse-start)))
3294 ;; (goto-char parse-start)
3295 ;; (beginning-of-defun))
3297 ;; (while (< (point) indent-point)
3298 ;; (setq start (point) parse-start start moved nil
3299 ;; state (parse-partial-sexp start indent-point -1))
3300 ;; (if (> (car state) -1) nil
3301 ;; ;; The current line could start like }}}, so the indentation
3302 ;; ;; corresponds to a different level than what we reached
3304 ;; (beginning-of-line 2))) ; Go to the next line.
3305 ;; (if start ; Not at the start of file
3307 ;; (goto-char start)
3308 ;; (setq start-indent (current-indentation))
3309 ;; (if moved ; Should correct...
3310 ;; (setq start-indent (- start-indent cperl-indent-level))))
3311 ;; (setq start-indent 0))
3312 ;; (if (< (point) indent-point) (setq parse-start (point)))
3313 ;; (or state (setq state (parse-partial-sexp
3314 ;; (point) indent-point -1 nil start-state)))
3315 ;; (setq containing-sexp
3316 ;; (or (car (cdr state))
3317 ;; (and (>= (nth 6 state) 0) old-containing-sexp))
3318 ;; old-containing-sexp nil start-state nil)
3319 ;;;; (while (< (point) indent-point)
3320 ;;;; (setq parse-start (point))
3321 ;;;; (setq state (parse-partial-sexp (point) indent-point -1 nil start-state))
3322 ;;;; (setq containing-sexp
3323 ;;;; (or (car (cdr state))
3324 ;;;; (and (>= (nth 6 state) 0) old-containing-sexp))
3325 ;;;; old-containing-sexp nil start-state nil))
3326 ;; (if symbol (set symbol (list indent-point state start-indent)))
3327 ;; (goto-char indent-point)
3328 (cond ((or (nth 3 state) (nth 4 state))
3329 ;; return nil or t if should not change this line
3331 ((null containing-sexp)
3332 ;; Line is at top level. May be data or function definition,
3333 ;; or may be function argument declaration.
3334 ;; Indent like the previous top level line
3335 ;; unless that ends in a closeparen without semicolon,
3336 ;; in which case this line is the first argument decl.
3337 (skip-chars-forward " \t")
3340 (- (current-indentation)
3341 (if (nth 2 s-s) cperl-indent-level 0)))
3342 (if (= char-after ?{) cperl-continued-brace-offset 0)
3344 (cperl-backward-to-noncomment (or old-indent (point-min)))
3345 ;; Look at previous line that's at column 0
3346 ;; to determine whether we are in top-level decls
3347 ;; or function's arg decls. Set basic-indent accordingly.
3348 ;; Now add a little if this is a continuation line.
3350 (eq (point) old-indent) ; old-indent was at comment
3351 (eq (preceding-char) ?\;)
3353 (and (eq (preceding-char) ?\})
3354 (cperl-after-block-and-statement-beg
3355 (point-min))) ; Was start - too close
3356 (memq char-after (append ")]}" nil))
3357 (and (eq (preceding-char) ?\:) ; label
3360 (skip-chars-backward " \t")
3361 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:"))))
3364 (not (eq char-after ?\C-j)))
3365 (setcdr (cddr parse-data)
3366 (list pre-indent-point)))
3368 cperl-continued-statement-offset))))
3369 ((/= (char-after containing-sexp) ?{)
3370 ;; line is expression, not statement:
3371 ;; indent to just after the surrounding open,
3372 ;; skip blanks if we do not close the expression.
3373 (goto-char (1+ containing-sexp))
3374 (or (memq char-after (append ")]}" nil))
3375 (looking-at "[ \t]*\\(#\\|$\\)")
3376 (skip-chars-forward " \t"))
3379 ;; Containing-expr starts with \{. Check whether it is a hash.
3380 (goto-char containing-sexp)
3381 (not (cperl-block-p)))
3382 (goto-char (1+ containing-sexp))
3383 (or (eq char-after ?\})
3384 (looking-at "[ \t]*\\(#\\|$\\)")
3385 (skip-chars-forward " \t"))
3386 (+ (current-column) ; Correct indentation of trailing ?\}
3387 (if (eq char-after ?\}) (+ cperl-indent-level
3388 cperl-close-paren-offset)
3391 ;; Statement level. Is it a continuation or a new statement?
3392 ;; Find previous non-comment character.
3393 (goto-char pre-indent-point)
3394 (cperl-backward-to-noncomment containing-sexp)
3395 ;; Back up over label lines, since they don't
3396 ;; affect whether our line is a continuation.
3398 (while ;;(or (eq (preceding-char) ?\,)
3399 (and (eq (preceding-char) ?:)
3400 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
3401 (memq (char-syntax (char-after (- (point) 2)))
3404 (if (eq (preceding-char) ?\,)
3405 ;; Will go to beginning of line, essentially.
3406 ;; Will ignore embedded sexpr XXXX.
3407 (cperl-backward-to-start-of-continued-exp containing-sexp))
3409 (cperl-backward-to-noncomment containing-sexp))
3410 ;; Now we get the answer.
3412 (if (not (or (memq (preceding-char) (append " ;{" '(nil)))
3413 (and (eq (preceding-char) ?\})
3414 (cperl-after-block-and-statement-beg
3415 containing-sexp)))) ; Was ?\,
3416 ;; This line is continuation of preceding line's statement;
3417 ;; indent `cperl-continued-statement-offset' more than the
3418 ;; previous line of the statement.
3420 ;; There might be a label on this line, just
3421 ;; consider it bad style and ignore it.
3423 (cperl-backward-to-start-of-continued-exp containing-sexp)
3424 (+ (if (memq char-after (append "}])" nil))
3426 cperl-continued-statement-offset)
3427 (if (looking-at "\\w+[ \t]*:")
3428 (if (> (current-indentation) cperl-min-label-indent)
3429 (- (current-indentation) cperl-label-offset)
3430 ;; Do not move `parse-data', this should
3431 ;; be quick anyway (this comment comes
3432 ;;from different location):
3433 (cperl-calculate-indent))
3435 (if (eq char-after ?\{)
3436 cperl-continued-brace-offset 0)))
3437 ;; This line starts a new statement.
3438 ;; Position following last unclosed open.
3439 (goto-char containing-sexp)
3440 ;; Is line first statement after an open-brace?
3442 ;; If no, find that first statement and indent like
3443 ;; it. If the first statement begins with label, do
3444 ;; not believe when the indentation of the label is too
3448 (setq old-indent (current-indentation))
3449 (let ((colon-line-end 0))
3450 (while (progn (skip-chars-forward " \t\n")
3451 (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]"))
3452 ;; Skip over comments and labels following openbrace.
3453 (cond ((= (following-char) ?\#)
3457 (save-excursion (end-of-line)
3458 (setq colon-line-end (point)))
3459 (search-forward ":"))))
3460 ;; The first following code counts
3461 ;; if it is before the line we want to indent.
3462 (and (< (point) indent-point)
3463 (if (> colon-line-end (point)) ; After label
3464 (if (> (current-indentation)
3465 cperl-min-label-indent)
3466 (- (current-indentation) cperl-label-offset)
3467 ;; Do not believe: `max' is involved
3468 (+ old-indent cperl-indent-level))
3469 (current-column)))))
3470 ;; If no previous statement,
3471 ;; indent it relative to line brace is on.
3472 ;; For open brace in column zero, don't let statement
3473 ;; start there too. If cperl-indent-level is zero,
3474 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3475 ;; For open-braces not the first thing in a line,
3476 ;; add in cperl-brace-imaginary-offset.
3478 ;; If first thing on a line: ?????
3479 (+ (if (and (bolp) (zerop cperl-indent-level))
3480 (+ cperl-brace-offset cperl-continued-statement-offset)
3482 ;; Move back over whitespace before the openbrace.
3483 ;; If openbrace is not first nonwhite thing on the line,
3484 ;; add the cperl-brace-imaginary-offset.
3485 (progn (skip-chars-backward " \t")
3486 (if (bolp) 0 cperl-brace-imaginary-offset))
3487 ;; If the openbrace is preceded by a parenthesized exp,
3488 ;; move to the beginning of that;
3489 ;; possibly a different line
3491 (if (eq (preceding-char) ?\))
3493 ;; In the case it starts a subroutine, indent with
3494 ;; respect to `sub', not with respect to the the
3495 ;; first thing on the line, say in the case of
3496 ;; anonymous sub in a hash.
3498 (skip-chars-backward " \t")
3499 (if (and (eq (preceding-char) ?b)
3502 (looking-at "sub\\>"))
3506 (save-excursion (beginning-of-line) (point))
3508 (progn (goto-char (1+ old-indent))
3509 (skip-chars-forward " \t")
3511 ;; Get initial indentation of the line we are on.
3512 ;; If line starts with label, calculate label indentation
3515 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3516 (if (> (current-indentation) cperl-min-label-indent)
3517 (- (current-indentation) cperl-label-offset)
3518 ;; Do not move `parse-data', this should
3520 (cperl-calculate-indent))
3521 (current-indentation))))))))))))))
3523 (defvar cperl-indent-alist
3527 (toplevel-after-parenth 2)
3528 (toplevel-continued 2)
3530 "Alist of indentation rules for CPerl mode.
3533 number: add this amount of indentation.
3535 Not finished, not used.")
3537 (defun cperl-where-am-i (&optional parse-start start-state)
3539 "Return a list of lists ((TYPE POS)...) of good points before the point.
3540 POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'.
3542 Not finished, not used."
3544 (let* ((start-point (point))
3545 (s-s (cperl-get-state))
3548 (prestart (nth 3 s-s))
3549 (containing-sexp (car (cdr state)))
3550 (case-fold-search nil)
3551 (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
3552 (cond ((nth 3 state) ; In string
3553 (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
3554 ((nth 4 state) ; In comment
3555 (setq res (cons '(comment) res)))
3556 ((null containing-sexp)
3557 ;; Line is at top level.
3558 ;; Indent like the previous top level line
3559 ;; unless that ends in a closeparen without semicolon,
3560 ;; in which case this line is the first argument decl.
3561 (cperl-backward-to-noncomment (or parse-start (point-min)))
3562 ;;(skip-chars-backward " \t\f\n")
3565 (memq (preceding-char) (append ";}" nil)))
3566 (setq res (cons (list 'toplevel start) res)))
3567 ((eq (preceding-char) ?\) )
3568 (setq res (cons (list 'toplevel-after-parenth start) res)))
3570 (setq res (cons (list 'toplevel-continued start) res)))))
3571 ((/= (char-after containing-sexp) ?{)
3572 ;; line is expression, not statement:
3573 ;; indent to just after the surrounding open.
3574 ;; skip blanks if we do not close the expression.
3575 (setq res (cons (list 'expression-blanks
3577 (goto-char (1+ containing-sexp))
3578 (or (looking-at "[ \t]*\\(#\\|$\\)")
3579 (skip-chars-forward " \t"))
3581 (cons (list 'expression containing-sexp) res))))
3583 ;; Containing-expr starts with \{. Check whether it is a hash.
3584 (goto-char containing-sexp)
3585 (not (cperl-block-p)))
3586 (setq res (cons (list 'expression-blanks
3588 (goto-char (1+ containing-sexp))
3589 (or (looking-at "[ \t]*\\(#\\|$\\)")
3590 (skip-chars-forward " \t"))
3592 (cons (list 'expression containing-sexp) res))))
3595 (setq res (cons (list 'in-block containing-sexp) res))
3596 ;; Is it a continuation or a new statement?
3597 ;; Find previous non-comment character.
3598 (cperl-backward-to-noncomment containing-sexp)
3599 ;; Back up over label lines, since they don't
3600 ;; affect whether our line is a continuation.
3601 ;; Back up comma-delimited lines too ?????
3602 (while (or (eq (preceding-char) ?\,)
3603 (save-excursion (cperl-after-label)))
3604 (if (eq (preceding-char) ?\,)
3605 ;; Will go to beginning of line, essentially
3606 ;; Will ignore embedded sexpr XXXX.
3607 (cperl-backward-to-start-of-continued-exp containing-sexp))
3609 (cperl-backward-to-noncomment containing-sexp))
3610 ;; Now we get the answer.
3611 (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
3612 ;; This line is continuation of preceding line's statement.
3613 (list (list 'statement-continued containing-sexp))
3614 ;; This line starts a new statement.
3615 ;; Position following last unclosed open.
3616 (goto-char containing-sexp)
3617 ;; Is line first statement after an open-brace?
3619 ;; If no, find that first statement and indent like
3620 ;; it. If the first statement begins with label, do
3621 ;; not believe when the indentation of the label is too
3625 (let ((colon-line-end 0))
3626 (while (progn (skip-chars-forward " \t\n" start-point)
3627 (and (< (point) start-point)
3629 "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
3630 ;; Skip over comments and labels following openbrace.
3631 (cond ((= (following-char) ?\#)
3636 (save-excursion (end-of-line)
3637 (setq colon-line-end (point)))
3638 (search-forward ":"))))
3639 ;; Now at the point, after label, or at start
3640 ;; of first statement in the block.
3641 (and (< (point) start-point)
3642 (if (> colon-line-end (point))
3643 ;; Before statement after label
3644 (if (> (current-indentation)
3645 cperl-min-label-indent)
3646 (list (list 'label-in-block (point)))
3647 ;; Do not believe: `max' is involved
3649 (list 'label-in-block-min-indent (point))))
3651 (list 'statement-in-block (point))))))
3652 ;; If no previous statement,
3653 ;; indent it relative to line brace is on.
3654 ;; For open brace in column zero, don't let statement
3655 ;; start there too. If cperl-indent-level is zero,
3656 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
3657 ;; For open-braces not the first thing in a line,
3658 ;; add in cperl-brace-imaginary-offset.
3660 ;; If first thing on a line: ?????
3661 (+ (if (and (bolp) (zerop cperl-indent-level))
3662 (+ cperl-brace-offset cperl-continued-statement-offset)
3664 ;; Move back over whitespace before the openbrace.
3665 ;; If openbrace is not first nonwhite thing on the line,
3666 ;; add the cperl-brace-imaginary-offset.
3667 (progn (skip-chars-backward " \t")
3668 (if (bolp) 0 cperl-brace-imaginary-offset))
3669 ;; If the openbrace is preceded by a parenthesized exp,
3670 ;; move to the beginning of that;
3671 ;; possibly a different line
3673 (if (eq (preceding-char) ?\))
3675 ;; Get initial indentation of the line we are on.
3676 ;; If line starts with label, calculate label indentation
3679 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
3680 (if (> (current-indentation) cperl-min-label-indent)
3681 (- (current-indentation) cperl-label-offset)
3682 (cperl-calculate-indent))
3683 (current-indentation))))))))
3686 (defun cperl-calculate-indent-within-comment ()
3687 "Return the indentation amount for line, assuming that
3688 the current line is to be regarded as part of a block comment."
3689 (let (end star-start)
3692 (skip-chars-forward " \t")
3694 (and (= (following-char) ?#)
3696 (cperl-to-comment-or-eol)
3702 (defun cperl-to-comment-or-eol ()
3703 "Goes to position before comment on the current line, or to end of line.
3704 Returns true if comment is found."
3705 (let (state stop-in cpoint (lim (progn (end-of-line) (point))))
3708 (eq (get-text-property (point) 'syntax-type) 'pod)
3709 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t))
3710 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
3712 (while (not stop-in)
3713 (setq state (parse-partial-sexp (point) lim nil nil nil t))
3715 ;; If fails (beginning-of-line inside sexp), then contains not-comment
3716 (if (nth 4 state) ; After `#';
3717 ; (nth 2 state) can be
3718 ; beginning of m,s,qq and so
3722 (setq cpoint (point))
3723 (goto-char (nth 2 state))
3725 ((looking-at "\\(s\\|tr\\)\\>")
3726 (or (re-search-forward
3727 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
3730 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
3731 (or (re-search-forward
3732 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
3735 (t ; It was fair comment
3736 (setq stop-in t) ; Finish
3737 (goto-char (1- cpoint)))))
3738 (setq stop-in t) ; Finish
3740 (setq stop-in t)) ; Finish
3744 (defsubst cperl-1- (p)
3745 (max (point-min) (1- p)))
3747 (defsubst cperl-1+ (p)
3748 (min (point-max) (1+ p)))
3750 (defsubst cperl-modify-syntax-type (at how)
3751 (if (< at (point-max))
3753 (put-text-property at (1+ at) 'syntax-table how)
3754 (put-text-property at (1+ at) 'rear-nonsticky t))))
3756 (defun cperl-protect-defun-start (s e)
3757 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
3760 (while (re-search-forward "^\\s(" e 'to-end)
3761 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
3763 (defun cperl-commentify (bb e string &optional noface)
3764 (if cperl-use-syntax-table-text-property
3765 (if (eq noface 'n) ; Only immediate
3767 ;; We suppose that e is _after_ the end of construction, as after eol.
3768 (setq string (if string cperl-st-sfence cperl-st-cfence))
3769 (cperl-modify-syntax-type bb string)
3770 (cperl-modify-syntax-type (1- e) string)
3771 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
3772 (put-text-property (1+ bb) (1- e)
3773 'syntax-table cperl-string-syntax-table))
3774 (cperl-protect-defun-start bb e))
3777 (not cperl-pod-here-fontify)
3778 (put-text-property bb e 'face (if string 'font-lock-string-face
3779 'font-lock-comment-face)))))
3780 (defvar cperl-starters '(( ?\( . ?\) )
3785 (defun cperl-forward-re (lim end is-2arg set-st st-l err-l argument
3786 &optional ostart oend)
3787 ;; Works *before* syntax recognition is done
3788 ;; May modify syntax-type text property if the situation is too hard
3789 (let (b starter ender st i i2 go-forward)
3790 (skip-chars-forward " \t")
3791 ;; ender means matching-char matcher.
3793 starter (if (eobp) 0 (char-after b))
3794 ender (cdr (assoc starter cperl-starters)))
3795 ;; What if starter == ?\\ ????
3798 (setq st (car st-l))
3799 (setcar st-l (make-syntax-table))
3800 (setq i 0 st (car st-l))
3802 (modify-syntax-entry i "." st)
3804 (modify-syntax-entry ?\\ "\\" st)))
3806 ;; Whether we have an intermediate point
3808 ;; Prepare the syntax table:
3810 (if (not ender) ; m/blah/, s/x//, s/x/y/
3811 (modify-syntax-entry starter "$" st)
3812 (modify-syntax-entry starter (concat "(" (list ender)) st)
3813 (modify-syntax-entry ender (concat ")" (list starter)) st)))
3816 ;; We use `$' syntax class to find matching stuff, but $$
3817 ;; is recognized the same as $, so we need to check this manually.
3818 (if (and (eq starter (char-after (cperl-1+ b)))
3820 ;; $ has TeXish matching rules, so $$ equiv $...
3822 (set-syntax-table st)
3824 (set-syntax-table cperl-mode-syntax-table)
3825 ;; Now the problem is with m;blah;;
3827 (eq (preceding-char)
3828 (char-after (- (point) 2)))
3831 (= 0 (% (skip-chars-backward "\\\\") 2)))
3833 ;; Now we are after the first part.
3834 (and is-2arg ; Have trailing part
3836 (eq (following-char) starter) ; Empty trailing part
3838 (or (eq (char-syntax (following-char)) ?.)
3839 ;; Make trailing letter into punctuation
3840 (cperl-modify-syntax-type (point) cperl-st-punct))
3841 (setq is-2arg nil go-forward t))) ; Ignore the tail
3842 (if is-2arg ; Not number => have second part
3844 (setq i (point) i2 i)
3846 (if (memq (following-char) '(?\ ?\t ?\n ?\f))
3848 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3849 (goto-char (match-end 0))
3850 (skip-chars-forward " \t\n\f"))
3853 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3854 (if ender (modify-syntax-entry ender "." st))
3856 (setq ender (cperl-forward-re lim end nil t st-l err-l
3857 argument starter ender)
3858 ender (nth 2 ender)))))
3859 (error (goto-char lim)
3863 "End of `%s%s%c ... %c' string/RE not found: %s"
3865 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
3866 starter (or ender starter) bb)
3867 (or (car err-l) (setcar err-l b)))))
3870 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3871 (if ender (modify-syntax-entry ender "." st))))
3872 ;; i: have 2 args, after end of the first arg
3873 ;; i2: start of the second arg, if any (before delim iff `ender').
3874 ;; ender: the last arg bounded by parens-like chars, the second one of them
3875 ;; starter: the starting delimiter of the first arg
3876 ;; go-forward: has 2 args, and the second part is empth
3877 (list i i2 ender starter go-forward)))
3879 (defvar font-lock-string-face)
3880 ;;(defvar font-lock-reference-face)
3881 (defvar font-lock-constant-face)
3882 (defsubst cperl-postpone-fontification (b e type val &optional now)
3883 ;; Do after syntactic fontification?
3884 (if cperl-syntaxify-by-font-lock
3885 (or now (put-text-property b e 'cperl-postpone (cons type val)))
3886 (put-text-property b e type val)))
3888 ;;; Here is how the global structures (those which cannot be
3889 ;;; recognized locally) are marked:
3891 ;; Start-to-end is marked `in-pod' ==> t
3892 ;; Each non-literal part is marked `syntax-type' ==> `pod'
3893 ;; Each literal part is marked `syntax-type' ==> `in-pod'
3895 ;; Start-to-end is marked `here-doc-group' ==> t
3896 ;; The body is marked `syntax-type' ==> `here-doc'
3897 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
3899 ;; After-initial-line--to-end is marked `syntax-type' ==> `format'
3900 ;; d) 'Q'uoted string:
3901 ;; part between markers inclusive is marked `syntax-type' ==> `string'
3903 (defun cperl-unwind-to-safe (before &optional end)
3904 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
3905 (let ((pos (point)) opos)
3907 (while (and pos (get-text-property pos 'syntax-type))
3908 (setq pos (previous-single-property-change pos 'syntax-type))
3912 (goto-char (cperl-1- pos))
3915 (goto-char (setq pos (cperl-1- pos))))
3917 (goto-char (point-min))))
3919 ;; Do the same for end, going small steps
3921 (while (and end (get-text-property end 'syntax-type))
3923 end (next-single-property-change end 'syntax-type)))
3926 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max)
3927 "Scans the buffer for hard-to-parse Perl constructions.
3928 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
3929 the sections using `cperl-pod-head-face', `cperl-pod-face',
3932 (or min (setq min (point-min)
3933 cperl-syntax-state nil
3934 cperl-syntax-done-to min))
3935 (or max (setq max (point-max)))
3936 (let* (face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
3937 (cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
3938 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
3939 (modified (buffer-modified-p))
3940 (after-change-functions nil)
3941 (use-syntax-state (and cperl-syntax-state
3942 (>= min (car cperl-syntax-state))))
3943 (state-point (if use-syntax-state
3944 (car cperl-syntax-state)
3946 (state (if use-syntax-state
3947 (cdr cperl-syntax-state)))
3948 (st-l '(nil)) (err-l '(nil)) i2
3949 ;; Somehow font-lock may be not loaded yet...
3950 (font-lock-string-face (if (boundp 'font-lock-string-face)
3951 font-lock-string-face
3952 'font-lock-string-face))
3953 (font-lock-constant-face (if (boundp 'font-lock-constant-face)
3954 font-lock-constant-face
3955 'font-lock-constant-face))
3956 (font-lock-function-name-face
3957 (if (boundp 'font-lock-function-name-face)
3958 font-lock-function-name-face
3959 'font-lock-function-name-face))
3960 (cperl-nonoverridable-face
3961 (if (boundp 'cperl-nonoverridable-face)
3962 cperl-nonoverridable-face
3963 'cperl-nonoverridable-face))
3964 (stop-point (if ignore-max
3969 "\\(\\`\n?\\|\n\n\\)="
3971 ;; One extra () before this:
3974 ;; First variant "BLAH" or just ``.
3975 "\\([\"'`]\\)" ; 2 + 1
3976 "\\([^\"'`\n]*\\)" ; 3 + 1
3979 ;; Second variant: Identifier or \ID or empty
3980 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3981 ;; Do not have <<= or << 30 or <<30 or << $blah.
3982 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3983 "\\(\\)" ; To preserve count of pars :-( 6 + 1
3986 ;; 1+6 extra () before this:
3987 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
3988 (if cperl-use-syntax-table-text-property
3991 ;; 1+6+2=9 extra () before this:
3992 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
3994 ;; 1+6+2+1=10 extra () before this:
3995 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3997 ;; 1+6+2+1+1=11 extra () before this:
3998 "\\<sub\\>[ \t]*\\([a-zA-Z_:'0-9]+[ \t]*\\)?\\(([^()]*)\\)"
4000 ;; 1+6+2+1+1+2=13 extra () before this:
4003 ;; 1+6+2+1+1+2+1=14 extra () before this:
4004 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
4005 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
4007 "__\\(END\\|DATA\\)__" ; Commented - does not help with indent...
4014 (message "Scanning for \"hard\" Perl constructions..."))
4015 (and cperl-pod-here-fontify
4016 ;; We had evals here, do not know why...
4017 (setq face cperl-pod-face
4018 head-face cperl-pod-head-face
4019 here-face cperl-here-face))
4020 (remove-text-properties min max
4021 '(syntax-type t in-pod t syntax-table t
4023 ;; Need to remove face as well...
4025 (and (eq system-type 'emx)
4026 (looking-at "extproc[ \t]") ; Analogue of #!
4027 (cperl-commentify min
4028 (save-excursion (end-of-line) (point))
4032 (re-search-forward search max t))
4033 (setq tmpend nil) ; Valid for most cases
4035 ((match-beginning 1) ; POD section
4036 ;; "\\(\\`\n?\\|\n\n\\)="
4037 (if (looking-at "\n*cut\\>")
4039 nil ; Doing a chunk only
4040 (message "=cut is not preceded by a POD section")
4041 (or (car err-l) (setcar err-l (point))))
4046 tb (match-beginning 0)
4047 b1 nil) ; error condition
4048 ;; We do not search to max, since we may be called from
4049 ;; some hook of fontification, and max is random
4050 (or (re-search-forward "\n\n=cut\\>" stop-point 'toend)
4052 (message "End of a POD section not marked by =cut")
4054 (or (car err-l) (setcar err-l b))))
4055 (beginning-of-line 2) ; An empty line after =cut is not POD!
4058 ;; Unrecoverable error
4062 (remove-text-properties
4063 max e '(syntax-type t in-pod t syntax-table t
4066 (put-text-property b e 'in-pod t)
4067 (put-text-property b e 'syntax-type 'in-pod)
4069 (while (re-search-forward "\n\n[ \t]" e t)
4070 ;; We start 'pod 1 char earlier to include the preceding line
4072 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
4073 (cperl-put-do-not-fontify b (point) t)
4074 ;; mark the non-literal parts as PODs
4075 (if cperl-pod-here-fontify
4076 (cperl-postpone-fontification b (point) 'face face t))
4077 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
4080 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
4081 (cperl-put-do-not-fontify (point) e t)
4082 (if cperl-pod-here-fontify
4084 ;; mark the non-literal parts as PODs
4085 (cperl-postpone-fontification (point) e 'face face t)
4088 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
4090 (cperl-postpone-fontification
4091 (match-beginning 1) (match-end 1)
4093 (while (re-search-forward
4095 "\n\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
4098 (cperl-postpone-fontification
4099 (match-beginning 1) (match-end 1)
4101 (cperl-commentify bb e nil)
4103 (or (eq e (point-max))
4104 (forward-char -1))))) ; Prepare for immediate pod start.
4106 ;; We do only one here-per-line
4107 ;; ;; One extra () before this:
4110 ;; ;; First variant "BLAH" or just ``.
4111 ;; "\\([\"'`]\\)" ; 2 + 1
4112 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
4115 ;; ;; Second variant: Identifier or \ID or empty
4116 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
4117 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
4118 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
4119 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
4121 ((match-beginning 2) ; 1 + 1
4122 ;; Abort in comment:
4124 (setq state (parse-partial-sexp state-point b nil nil state)
4126 tb (match-beginning 0)
4127 i (or (nth 3 state) (nth 4 state)))
4132 (not (match-beginning 6)) ; Empty
4134 "[ \t]*[=0-9$@%&(]"))))
4135 (if c ; Not here-doc
4137 (if (match-beginning 5) ;4 + 1
4138 (setq b1 (match-beginning 5) ; 4 + 1
4139 e1 (match-end 5)) ; 4 + 1
4140 (setq b1 (match-beginning 4) ; 3 + 1
4141 e1 (match-end 4))) ; 3 + 1
4142 (setq tag (buffer-substring b1 e1)
4143 qtag (regexp-quote tag))
4144 (cond (cperl-pod-here-fontify
4145 ;; Highlight the starting delimiter
4146 (cperl-postpone-fontification b1 e1 'face font-lock-constant-face)
4147 (cperl-put-do-not-fontify b1 e1 t)))
4150 ;; We do not search to max, since we may be called from
4151 ;; some hook of fontification, and max is random
4152 (cond ((re-search-forward (concat "^" qtag "$")
4154 (if cperl-pod-here-fontify
4156 ;; Highlight the ending delimiter
4157 (cperl-postpone-fontification (match-beginning 0) (match-end 0)
4158 'face font-lock-constant-face)
4159 (cperl-put-do-not-fontify b (match-end 0) t)
4160 ;; Highlight the HERE-DOC
4161 (cperl-postpone-fontification b (match-beginning 0)
4163 (setq e1 (cperl-1+ (match-end 0)))
4164 (put-text-property b (match-beginning 0)
4165 'syntax-type 'here-doc)
4166 (put-text-property (match-beginning 0) e1
4167 'syntax-type 'here-doc-delim)
4168 (put-text-property b e1
4170 (cperl-commentify b e1 nil)
4171 (cperl-put-do-not-fontify b (match-end 0) t)
4174 (t (message "End of here-document `%s' not found." tag)
4175 (or (car err-l) (setcar err-l b))))))
4177 ((match-beginning 8)
4178 ;; 1+6=7 extra () before this:
4179 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
4181 name (if (match-beginning 8) ; 7 + 1
4182 (buffer-substring (match-beginning 8) ; 7 + 1
4183 (match-end 8)) ; 7 + 1
4185 tb (match-beginning 0))
4187 (if cperl-pod-here-fontify
4188 (while (and (eq (forward-line) 0)
4189 (not (looking-at "^[.;]$")))
4191 ((looking-at "^#")) ; Skip comments
4192 ((and argument ; Skip argument multi-lines
4193 (looking-at "^[ \t]*{"))
4195 (setq argument nil))
4196 (argument ; Skip argument lines
4197 (setq argument nil))
4200 (setq argument (looking-at "^[^\n]*[@^]"))
4202 ;; Highlight the format line
4203 (cperl-postpone-fontification b1 (point)
4204 'face font-lock-string-face)
4205 (cperl-commentify b1 (point) nil)
4206 (cperl-put-do-not-fontify b1 (point) t))))
4207 ;; We do not search to max, since we may be called from
4208 ;; some hook of fontification, and max is random
4209 (re-search-forward "^[.;]$" stop-point 'toend))
4211 (if (looking-at "^\\.$") ; ";" is not supported yet
4213 ;; Highlight the ending delimiter
4214 (cperl-postpone-fontification (point) (+ (point) 2)
4215 'face font-lock-string-face)
4216 (cperl-commentify (point) (+ (point) 2) nil)
4217 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
4218 (message "End of format `%s' not found." name)
4219 (or (car err-l) (setcar err-l b)))
4223 (put-text-property b (point) 'syntax-type 'format))
4225 ((or (match-beginning 10) (match-beginning 11))
4226 ;; 1+6+2=9 extra () before this:
4227 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
4229 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
4230 (setq b1 (if (match-beginning 10) 10 11)
4231 argument (buffer-substring
4232 (match-beginning b1) (match-end b1))
4235 c (char-after (match-beginning b1))
4236 bb (char-after (1- (match-beginning b1))) ; tmp holder
4237 ;; bb == "Not a stringy"
4238 bb (if (eq b1 10) ; user variables/whatever
4240 (memq bb '(?\$ ?\@ ?\% ?\* ?\#)) ; $#y
4241 (and (eq bb ?-) (eq c ?s)) ; -s file test
4242 (and (eq bb ?\&) ; &&m/blah/
4243 (not (eq (char-after
4244 (- (match-beginning b1) 2))
4246 ;; <file> or <$file>
4248 ;; Do not stringify <FH> :
4251 "\\s *\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\s *\\)?>"))))
4252 tb (match-beginning 0))
4253 (goto-char (match-beginning b1))
4254 (cperl-backward-to-noncomment (point-min))
4256 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
4261 ;; What is below: regexp-p?
4263 (or (memq (preceding-char)
4264 (append (if (memq c '(?\? ?\<))
4267 "~{(=|&+-*!,;:") nil))
4268 (and (eq (preceding-char) ?\})
4269 (cperl-after-block-p (point-min)))
4270 (and (eq (char-syntax (preceding-char)) ?w)
4273 ;;; After these keywords `/' starts a RE. One should add all the
4274 ;;; functions/builtins which expect an argument, but ...
4275 (if (eq (preceding-char) ?-)
4277 (looking-at "[a-zA-Z]\\>")
4279 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>"))))
4280 (and (eq (preceding-char) ?.)
4281 (eq (char-after (- (point) 2)) ?.))
4283 ;; m|blah| ? foo : bar;
4286 cperl-use-syntax-table-text-property
4290 (looking-at "\\s|")))))))
4294 (if (and (eq (preceding-char) ?>)
4295 (eq (char-after (- (point) 2)) ?-))
4298 (or bb (setq state (parse-partial-sexp
4299 state-point b nil nil state)
4302 (if (or bb (nth 3 state) (nth 4 state))
4304 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
4305 (goto-char (match-end 0))
4306 (skip-chars-forward " \t\n\f"))
4307 ;; qtag means two-arg matcher, may be reset to
4308 ;; 2 or 3 later if some special quoting is needed.
4309 ;; e1 means matching-char matcher.
4312 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
4313 ;; We do not search to max, since we may be called from
4314 ;; some hook of fontification, and max is random
4315 i (cperl-forward-re stop-point end
4317 t st-l err-l argument)
4318 ;; Note that if `go', then it is considered as 1-arg
4319 b1 (nth 1 i) ; start of the second part
4320 tag (nth 2 i) ; ender-char, true if second part
4321 ; is with matching chars []
4322 go (nth 4 i) ; There is a 1-char part after the end
4323 i (car i) ; intermediate point
4325 ;; Before end of the second part if non-matching: ///
4326 tail (if (and i (not tag))
4328 e (if i i e1) ; end of the first part
4329 qtag nil) ; need to preserve backslashitis
4330 ;; Commenting \\ is dangerous, what about ( ?
4332 (eq (char-after i) ?\\)
4335 ;; Considered as 1arg form
4337 (cperl-commentify b (point) t)
4338 (put-text-property b (point) 'syntax-type 'string)
4340 (setq e1 (cperl-1+ e1))
4343 (cperl-commentify b i t)
4344 (if (looking-at "\\sw*e") ; s///e
4348 (cperl-find-pods-heres b1 (1- (point)) t end)
4350 (goto-char (1+ max)))
4351 (if (and tag (eq (preceding-char) ?\>))
4353 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
4354 (cperl-modify-syntax-type i cperl-st-bra)))
4355 (put-text-property b i 'syntax-type 'string))
4356 (cperl-commentify b1 (point) t)
4357 (put-text-property b (point) 'syntax-type 'string)
4359 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
4361 ;; Now: tail: if the second part is non-matching without ///e
4362 (if (eq (char-syntax (following-char)) ?w)
4364 (forward-word 1) ; skip modifiers s///s
4365 (if tail (cperl-commentify tail (point) t))
4366 (cperl-postpone-fontification
4367 e1 (point) 'face cperl-nonoverridable-face)))
4368 ;; Check whether it is m// which means "previous match"
4369 ;; and highlight differently
4370 (if (and (eq e (+ 2 b))
4371 (string-match "^\\([sm]?\\|qr\\)$" argument)
4372 ;; <> is already filtered out
4373 ;; split // *is* using zero-pattern
4379 (not (looking-at "split\\>")))
4381 (cperl-postpone-fontification
4382 b e 'face font-lock-function-name-face)
4383 (if (or i2 ; Has 2 args
4384 (and cperl-fontify-m-as-s
4386 (string-match "^\\(m\\|qr\\)$" argument)
4387 (and (eq 0 (length argument))
4388 (not (eq ?\< (char-after b)))))))
4390 (cperl-postpone-fontification
4391 b (cperl-1+ b) 'face font-lock-constant-face)
4392 (cperl-postpone-fontification
4393 (1- e) e 'face font-lock-constant-face))))
4396 (cperl-postpone-fontification
4397 (1- e1) e1 'face font-lock-constant-face)
4398 (if (assoc (char-after b) cperl-starters)
4399 (cperl-postpone-fontification
4400 b1 (1+ b1) 'face font-lock-constant-face))))
4403 ((match-beginning 13) ; sub with prototypes
4404 (setq b (match-beginning 0))
4405 (if (memq (char-after (1- b))
4406 '(?\$ ?\@ ?\% ?\& ?\*))
4408 (setq state (parse-partial-sexp
4409 state-point b nil nil state)
4411 (if (or (nth 3 state) (nth 4 state))
4414 (cperl-commentify (match-beginning 13) (match-end 13) t))
4415 (goto-char (match-end 0))))
4416 ;; 1+6+2+1+1+2=13 extra () before this:
4418 ((and (match-beginning 14)
4419 (eq (preceding-char) ?\')) ; $'
4420 (setq b (1- (point))
4421 state (parse-partial-sexp
4422 state-point (1- b) nil nil state)
4424 (if (nth 3 state) ; in string
4425 (cperl-modify-syntax-type (1- b) cperl-st-punct))
4427 ;; 1+6+2+1+1+2=13 extra () before this:
4429 ((match-beginning 14) ; ${
4430 (setq bb (match-beginning 0))
4431 (cperl-modify-syntax-type bb cperl-st-punct))
4432 ;; 1+6+2+1+1+2+1=14 extra () before this:
4433 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
4434 ((match-beginning 15) ; old $abc'efg syntax
4435 (setq bb (match-end 0)
4436 b (match-beginning 0)
4437 state (parse-partial-sexp
4438 state-point b nil nil state)
4440 (if (nth 3 state) ; in string
4442 (put-text-property (1- bb) bb 'syntax-table cperl-st-word))
4444 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
4445 ;; "__\\(END\\|DATA\\)__"
4446 (t ; __END__, __DATA__
4447 (setq bb (match-end 0)
4448 b (match-beginning 0)
4449 state (parse-partial-sexp
4450 state-point b nil nil state)
4452 (if (or (nth 3 state) (nth 4 state))
4454 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
4455 (cperl-commentify b bb nil)
4458 (if (> (point) stop-point)
4461 (message "Garbage after __END__/__DATA__ ignored")
4462 (message "Unbalanced syntax found while scanning")
4463 (or (car err-l) (setcar err-l b)))
4464 (goto-char stop-point))))
4465 (setq cperl-syntax-state (cons state-point state)
4466 cperl-syntax-done-to (or tmpend (max (point) max))))
4467 (if (car err-l) (goto-char (car err-l))
4469 (message "Scanning for \"hard\" Perl constructions... done"))))
4470 (and (buffer-modified-p)
4472 (set-buffer-modified-p nil))
4473 (set-syntax-table cperl-mode-syntax-table))
4476 (defun cperl-backward-to-noncomment (lim)
4477 ;; Stops at lim or after non-whitespace that is not in comment
4479 (while (and (not stop) (> (point) (or lim 1)))
4480 (skip-chars-backward " \t\n\f" lim)
4483 (if (memq (setq pr (get-text-property (point) 'syntax-type))
4484 '(pod here-doc here-doc-delim))
4485 (cperl-unwind-to-safe nil)
4486 (if (or (looking-at "^[ \t]*\\(#\\|$\\)")
4487 (progn (cperl-to-comment-or-eol) (bolp)))
4488 nil ; Only comment, skip
4490 (skip-chars-backward " \t")
4491 (if (< p (point)) (goto-char p))
4494 (defun cperl-after-block-p (lim)
4495 ;; We suppose that the preceding char is }.
4500 (cperl-backward-to-noncomment lim)
4501 (or (eq (point) lim)
4502 (eq (preceding-char) ?\) ) ; if () {} sub f () {}
4503 (if (eq (char-syntax (preceding-char)) ?w) ; else {}
4506 (or (looking-at "\\(else\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
4509 (cperl-backward-to-noncomment lim)
4510 (and (eq (char-syntax (preceding-char)) ?w)
4513 (looking-at "sub\\>"))))))
4514 (cperl-after-expr-p lim))))
4517 (defun cperl-after-expr-p (&optional lim chars test)
4518 "Returns true if the position is good for start of expression.
4519 TEST is the expression to evaluate at the found position. If absent,
4520 CHARS is a string that contains good characters to have before us (however,
4521 `}' is treated \"smartly\" if it is not in the list)."
4523 (lim (or lim (point-min))))
4525 (while (and (not stop) (> (point) lim))
4526 (skip-chars-backward " \t\n\f" lim)
4529 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
4530 ;; Else: last iteration, or a label
4531 (cperl-to-comment-or-eol)
4532 (skip-chars-backward " \t")
4533 (if (< p (point)) (goto-char p))
4535 (if (and (eq (preceding-char) ?:)
4538 (skip-chars-backward " \t\n\f" lim)
4539 (eq (char-syntax (preceding-char)) ?w)))
4540 (forward-sexp -1) ; Possibly label. Skip it
4543 (or (bobp) ; ???? Needed
4546 (if test (eval test)
4547 (or (memq (preceding-char) (append (or chars "{;") nil))
4548 (and (eq (preceding-char) ?\})
4549 (cperl-after-block-p lim)))))))))
4551 (defun cperl-backward-to-start-of-continued-exp (lim)
4552 (if (memq (preceding-char) (append ")]}\"'`" nil))
4555 (if (<= (point) lim)
4556 (goto-char (1+ lim)))
4557 (skip-chars-forward " \t"))
4559 (defun cperl-after-block-and-statement-beg (lim)
4560 ;; We assume that we are after ?\}
4562 (cperl-after-block-p lim)
4565 (cperl-backward-to-noncomment (point-min))
4568 (not (= (char-syntax (preceding-char)) ?w))
4573 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
4576 (defvar innerloop-done nil)
4577 (defvar last-depth nil)
4579 (defun cperl-indent-exp ()
4580 "Simple variant of indentation of continued-sexp.
4582 Will not indent comment if it starts at `comment-indent' or looks like
4583 continuation of the comment on the previous line.
4585 If `cperl-indent-region-fix-constructs', will improve spacing on
4586 conditional/loop constructs."
4589 (let ((tmp-end (progn (end-of-line) (point))) top done)
4594 (while (= (nth 0 (parse-partial-sexp (point) tmp-end
4596 (setq top (point))) ; Get the outermost parenths in line
4598 (while (< (point) tmp-end)
4599 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
4600 (or (eolp) (forward-sexp 1)))
4601 (if (> (point) tmp-end)
4604 (setq tmp-end (point)))
4607 (setq tmp-end (point-marker)))
4608 (if cperl-indent-region-fix-constructs
4609 (cperl-fix-line-spacing tmp-end))
4610 (cperl-indent-region (point) tmp-end))))
4612 (defun cperl-fix-line-spacing (&optional end parse-data)
4613 "Improve whitespace in a conditional/loop construct.
4614 Returns some position at the last line."
4617 (setq end (point-max)))
4618 (let (p pp ml have-brace ret
4619 (ee (save-excursion (end-of-line) (point)))
4620 (cperl-indent-region-fix-constructs
4621 (or cperl-indent-region-fix-constructs 1)))
4628 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
4629 (setq have-brace (save-excursion (search-forward "}" ee t)))))
4630 nil ; Do not need to do anything
4634 (if (and cperl-merge-trailing-else
4636 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>"))
4638 (search-forward "}")
4640 (skip-chars-forward " \t\n")
4641 (delete-region p (point))
4642 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
4643 (beginning-of-line)))
4646 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
4648 (search-forward "}")
4649 (delete-horizontal-space)
4650 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
4651 (beginning-of-line)))
4655 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
4658 (delete-horizontal-space)
4659 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
4660 (beginning-of-line)))
4664 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
4667 (delete-horizontal-space)
4668 (insert (make-string cperl-indent-region-fix-constructs ?\ ))
4669 (beginning-of-line)))
4671 ;; foreach my $var (
4673 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
4676 (delete-horizontal-space)
4678 (make-string cperl-indent-region-fix-constructs ?\ ))
4679 (beginning-of-line)))
4681 ;; } foreach my $var () {
4683 "[ \t]*\\(}[ \t]*\\)?\\<\\(\\els\\(e\\|if\\)\\|continue\\|if\\|unless\\|while\\|for\\(each\\)?\\(\\([ t]+\\(my\\|local\\)\\)?[ \t]*\\$[_a-zA-Z0-9]+\\)?\\|until\\)\\>\\([ \t]*(\\|[ \t\n]*{\\)\\|[ \t]*{")
4685 (setq ml (match-beginning 8))
4686 (re-search-forward "[({]")
4689 (if (eq (following-char) ?\( )
4693 ;; after `else' or nothing
4694 (if ml ; after `else'
4695 (skip-chars-backward " \t\n")
4696 (beginning-of-line))
4698 ;; Now after the sexp before the brace
4699 ;; Multiline expr should be special
4700 (setq ml (and pp (save-excursion (goto-char p)
4701 (search-forward "\n" pp t))))
4702 (if (and (or (not pp) (< pp end))
4703 (looking-at "[ \t\n]*{"))
4706 ((bolp) ; Were before `{', no if/else/etc
4708 ((looking-at "\\(\t*\\| [ \t]+\\){")
4709 (delete-horizontal-space)
4711 cperl-extra-newline-before-brace-multiline
4712 cperl-extra-newline-before-brace)
4714 (delete-horizontal-space)
4717 (if (cperl-indent-line parse-data)
4719 (cperl-fix-line-spacing end parse-data)
4720 (setq ret (point)))))
4722 (make-string cperl-indent-region-fix-constructs ?\ ))))
4723 ((and (looking-at "[ \t]*\n")
4725 cperl-extra-newline-before-brace-multiline
4726 cperl-extra-newline-before-brace)))
4728 (skip-chars-forward " \t\n")
4729 (delete-region pp (point))
4731 (make-string cperl-indent-region-fix-constructs ?\ ))))
4732 ;; Now we are before `{'
4733 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
4735 (skip-chars-forward " \t\n")
4740 (setq ml (search-forward "\n" p t))
4741 (if (or cperl-break-one-line-blocks-when-indent ml)
4742 ;; not good: multi-line BLOCK
4745 (delete-horizontal-space)
4748 (if (cperl-indent-line parse-data)
4749 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
4751 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
4752 ;; Now check whether there is a hanging `}'
4756 cperl-fix-hanging-brace-when-indent
4758 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
4762 (if (and (<= (point) pp)
4763 (eq (preceding-char) ?\} )
4764 (cperl-after-block-and-statement-beg (point-min)))
4771 (skip-chars-backward " \t")
4773 ;; `}' was the first thing on the line, insert NL *after* it.
4775 (cperl-indent-line parse-data)
4776 (search-forward "}")
4777 (delete-horizontal-space)
4779 (delete-horizontal-space)
4780 (or (eq (preceding-char) ?\;)
4782 (and (eq (preceding-char) ?\} )
4783 (cperl-after-block-p (point-min)))
4787 (if (cperl-indent-line parse-data)
4788 (setq ret (cperl-fix-line-spacing end parse-data)))
4789 (beginning-of-line)))))
4792 (defvar cperl-update-start) ; Do not need to make them local
4793 (defvar cperl-update-end)
4794 (defun cperl-delay-update-hook (beg end old-len)
4795 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
4796 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
4798 (defun cperl-indent-region (start end)
4799 "Simple variant of indentation of region in CPerl mode.
4800 Should be slow. Will not indent comment if it starts at `comment-indent'
4801 or looks like continuation of the comment on the previous line.
4802 Indents all the lines whose first character is between START and END
4805 If `cperl-indent-region-fix-constructs', will improve spacing on
4806 conditional/loop constructs."
4808 (cperl-update-syntaxification end end)
4810 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
4811 (let (st comm old-comm-indent new-comm-indent p pp i empty
4812 (indent-info (if cperl-emacs-can-parse
4813 (list nil nil nil) ; Cannot use '(), since will modify
4815 after-change-functions ; Speed it up!
4816 (pm 0) (imenu-scanning-message "Indenting... (%3d%%)"))
4817 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
4819 (setq old-comm-indent (and (cperl-to-comment-or-eol)
4821 new-comm-indent old-comm-indent)
4823 (setq end (set-marker (make-marker) end)) ; indentation changes pos
4824 (or (bolp) (beginning-of-line 2))
4825 (or (fboundp 'imenu-progress-message)
4826 (message "Indenting... For feedback load `imenu'..."))
4827 (while (and (<= (point) end) (not (eobp))) ; bol to check start
4828 (and (fboundp 'imenu-progress-message)
4829 (imenu-progress-message
4830 pm (/ (* 100 (- (point) start)) (- end start -1))))
4833 (setq empty (looking-at "[ \t]*\n"))
4834 (and (setq comm (looking-at "[ \t]*#"))
4835 (or (eq (current-indentation) (or old-comm-indent
4837 (setq old-comm-indent nil))))
4838 (if (and old-comm-indent
4840 (= (current-indentation) old-comm-indent)
4841 (not (eq (get-text-property (point) 'syntax-type) 'pod))
4842 (not (eq (get-text-property (point) 'syntax-table)
4844 (let ((comment-column new-comm-indent))
4845 (indent-for-comment)))
4847 (setq i (cperl-indent-line indent-info))
4851 (if cperl-indent-region-fix-constructs
4852 (goto-char (cperl-fix-line-spacing end indent-info)))
4853 (if (setq old-comm-indent
4854 (and (cperl-to-comment-or-eol)
4855 (not (memq (get-text-property (point)
4858 (not (eq (get-text-property (point)
4862 (progn (indent-for-comment)
4863 (skip-chars-backward " \t")
4864 (skip-chars-backward "#")
4865 (setq new-comm-indent (current-column))))))))
4866 (beginning-of-line 2))
4867 (if (fboundp 'imenu-progress-message)
4868 (imenu-progress-message pm 100)
4870 ;; Now run the update hooks
4871 (if after-change-functions
4873 (if cperl-update-end
4875 (goto-char cperl-update-end)
4878 (goto-char cperl-update-start)
4880 (delete-char -1))))))))
4882 ;; Stolen from lisp-mode with a lot of improvements
4884 (defun cperl-fill-paragraph (&optional justify iteration)
4885 "Like \\[fill-paragraph], but handle CPerl comments.
4886 If any of the current line is a comment, fill the comment or the
4887 block of it that point is in, preserving the comment's initial
4888 indentation and initial hashes. Behaves usually outside of comment."
4891 ;; Non-nil if the current line contains a comment.
4894 ;; If has-comment, the appropriate fill-prefix for the comment.
4896 ;; Line that contains code and comment (or nil)
4898 c spaces len dc (comment-column comment-column))
4899 ;; Figure out what kind of comment we are looking at.
4904 ;; A line with nothing but a comment on it?
4905 ((looking-at "[ \t]*#[# \t]*")
4907 comment-fill-prefix (buffer-substring (match-beginning 0)
4910 ;; A line with some code, followed by a comment? Remember that the
4911 ;; semi which starts the comment shouldn't be part of a string or
4913 ((cperl-to-comment-or-eol)
4914 (setq has-comment t)
4915 (looking-at "#+[ \t]*")
4916 (setq start (point) c (current-column)
4918 (concat (make-string (current-column) ?\ )
4919 (buffer-substring (match-beginning 0) (match-end 0)))
4920 spaces (progn (skip-chars-backward " \t")
4921 (buffer-substring (point) start))
4922 dc (- c (current-column)) len (- start (point))
4923 start (point-marker))
4925 (insert (make-string dc ?-)))))
4926 (if (not has-comment)
4927 (fill-paragraph justify) ; Do the usual thing outside of comment
4928 ;; Narrow to include only the comment, and then fill the region.
4931 ;; Find the first line we should include in the region to fill.
4932 (if start (progn (beginning-of-line) (point))
4934 (while (and (zerop (forward-line -1))
4935 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
4936 ;; We may have gone to far. Go forward again.
4937 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
4940 ;; Find the beginning of the first line past the region to fill.
4942 (while (progn (forward-line 1)
4943 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
4945 ;; Remove existing hashes
4946 (goto-char (point-min))
4947 (while (progn (forward-line 1) (< (point) (point-max)))
4948 (skip-chars-forward " \t")
4949 (and (looking-at "#+")
4950 (delete-char (- (match-end 0) (match-beginning 0)))))
4952 ;; Lines with only hashes on them can be paragraph boundaries.
4953 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
4954 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
4955 (fill-prefix comment-fill-prefix))
4956 (fill-paragraph justify)))
4961 (progn (delete-char dc) (insert spaces)))
4962 (if (or (= (current-column) c) iteration) nil
4963 (setq comment-column c)
4964 (indent-for-comment)
4965 ;; Repeat once more, flagging as iteration
4966 (cperl-fill-paragraph justify t)))))))
4968 (defun cperl-do-auto-fill ()
4969 ;; Break out if the line is short enough
4970 (if (> (save-excursion
4974 (let ((c (save-excursion (beginning-of-line)
4975 (cperl-to-comment-or-eol) (point)))
4976 (s (memq (following-char) '(?\ ?\t))) marker)
4977 (if (>= c (point)) nil
4978 (setq marker (point-marker))
4979 (cperl-fill-paragraph)
4981 ;; Is not enough, sometimes marker is a start of line
4982 (if (bolp) (progn (re-search-forward "#+[ \t]*")
4983 (goto-char (match-end 0))))
4984 ;; Following space could have gone:
4985 (if (or (not s) (memq (following-char) '(?\ ?\t))) nil
4988 ;; Previous space could have gone:
4989 (or (memq (preceding-char) '(?\ ?\t)) (insert " "))))))
4991 (defvar imenu-example--function-name-regexp-perl
4994 "[ \t]*\\(sub\\|package\\)[ \t\n]+\\([a-zA-Z_0-9:']+\\)[ \t]*\\(([^()]*)[ \t]*\\)?"
4996 "=head\\([12]\\)[ \t]+\\([^\n]+\\)$"
4999 (defun cperl-imenu-addback (lst &optional isback name)
5000 ;; We suppose that the lst is a DAG, unless the first element only
5001 ;; loops back, and ISBACK is set. Thus this function cannot be
5002 ;; applied twice without ISBACK set.
5003 (cond ((not cperl-imenu-addback) lst)
5006 (setq name "+++BACK+++"))
5007 (mapcar (function (lambda (elt)
5008 (if (and (listp elt) (listp (cdr elt)))
5010 ;; In the other order it goes up
5011 ;; one level only ;-(
5012 (setcdr elt (cons (cons name lst)
5014 (cperl-imenu-addback (cdr elt) t name)
5016 (if isback (cdr lst) lst))
5019 (defun imenu-example--create-perl-index (&optional regexp)
5021 (require 'imenu) ; May be called from TAGS creator
5022 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
5023 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
5024 (index-meth-alist '()) meth
5025 packages ends-ranges p
5026 (prev-pos 0) char fchar index index1 name (end-range 0) package)
5027 (goto-char (point-min))
5029 (message "Scanning Perl for index")
5030 (imenu-progress-message prev-pos 0))
5031 ;; Search for the function
5032 (progn ;;save-match-data
5033 (while (re-search-forward
5034 (or regexp imenu-example--function-name-regexp-perl)
5037 (imenu-progress-message prev-pos))
5039 ((and ; Skip some noise if building tags
5040 (match-beginning 2) ; package or sub
5041 (eq (char-after (match-beginning 2)) ?p) ; package
5042 (not (save-match-data
5043 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
5046 (match-beginning 2) ; package or sub
5047 ;; Skip if quoted (will not skip multi-line ''-comments :-():
5048 (null (get-text-property (match-beginning 1) 'syntax-table))
5049 (null (get-text-property (match-beginning 1) 'syntax-type))
5050 (null (get-text-property (match-beginning 1) 'in-pod)))
5052 (goto-char (match-beginning 2))
5053 (setq fchar (following-char))
5055 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
5056 ;; (goto-char (match-end 0))) ; Messes what follows
5057 (setq char (following-char)
5060 (while (and ends-ranges (>= p (car ends-ranges)))
5061 ;; delete obsolete entries
5062 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
5063 (setq package (or (car packages) "")
5064 end-range (or (car ends-ranges) 0))
5066 (setq name (buffer-substring (match-beginning 3) (match-end 3))
5068 (set-text-properties 0 (length name) nil name)
5070 package (concat name "::")
5071 name (concat "package " name)
5074 (parse-partial-sexp (point) (point-max) -1) (point))
5075 ends-ranges (cons end-range ends-ranges)
5076 packages (cons package packages)))
5078 ;; Skip this function name if it is a prototype declaration.
5079 (if (and (eq fchar ?s) (eq char ?\;)) nil
5080 (setq index (imenu-example--name-and-position))
5081 (if (eq fchar ?p) nil
5082 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
5083 (set-text-properties 0 (length name) nil name)
5084 (cond ((string-match "[:']" name)
5086 ((> p end-range) nil)
5088 (setq name (concat package name) meth t))))
5091 (push index index-pack-alist)
5092 (push index index-alist))
5093 (if meth (push index index-meth-alist))
5094 (push index index-unsorted-alist)))
5095 ((match-beginning 5) ; Pod section
5096 ;; (beginning-of-line)
5097 (setq index (imenu-example--name-and-position)
5098 name (buffer-substring (match-beginning 6) (match-end 6)))
5099 (set-text-properties 0 (length name) nil name)
5100 (if (eq (char-after (match-beginning 5)) ?2)
5101 (setq name (concat " " name)))
5103 (setq index1 (cons (concat "=" name) (cdr index)))
5104 (push index index-pod-alist)
5105 (push index1 index-unsorted-alist)))))
5107 (imenu-progress-message prev-pos 100))
5109 (if (default-value 'imenu-sort-function)
5110 (sort index-alist (default-value 'imenu-sort-function))
5111 (nreverse index-alist)))
5112 (and index-pod-alist
5113 (push (cons "+POD headers+..."
5114 (nreverse index-pod-alist))
5116 (and (or index-pack-alist index-meth-alist)
5117 (let ((lst index-pack-alist) hier-list pack elt group name)
5118 ;; Remove "package ", reverse and uniquify.
5120 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
5121 (if (assoc name hier-list) nil
5122 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
5123 (setq lst index-meth-alist)
5125 (setq elt (car lst) lst (cdr lst))
5126 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
5127 (setq pack (substring (car elt) 0 (match-beginning 0)))
5128 (if (setq group (assoc pack hier-list))
5129 (if (listp (cdr group))
5130 ;; Have some functions already
5132 (cons (cons (substring
5134 (+ 2 (match-beginning 0)))
5137 (setcdr group (list (cons (substring
5139 (+ 2 (match-beginning 0)))
5143 (list (cons (substring
5145 (+ 2 (match-beginning 0)))
5148 (push (cons "+Hierarchy+..."
5151 (and index-pack-alist
5152 (push (cons "+Packages+..."
5153 (nreverse index-pack-alist))
5155 (and (or index-pack-alist index-pod-alist
5156 (default-value 'imenu-sort-function))
5157 index-unsorted-alist
5158 (push (cons "+Unsorted List+..."
5159 (nreverse index-unsorted-alist))
5161 (cperl-imenu-addback index-alist)))
5163 (defvar cperl-compilation-error-regexp-alist
5164 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK).
5165 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
5167 "Alist that specifies how to match errors in perl output.")
5169 (if (fboundp 'eval-after-load)
5172 '(setq perl-compilation-error-regexp-alist
5173 cperl-compilation-error-regexp-alist)))
5176 (defun cperl-windowed-init ()
5177 "Initialization under windowed version."
5178 (if (or (featurep 'ps-print) cperl-faces-init)
5179 ;; Need to init anyway:
5180 (or cperl-faces-init (cperl-init-faces))
5181 (add-hook 'font-lock-mode-hook
5185 (eq major-mode 'perl-mode)
5186 (eq major-mode 'cperl-mode))
5188 (or cperl-faces-init (cperl-init-faces)))))))
5189 (if (fboundp 'eval-after-load)
5192 '(or cperl-faces-init (cperl-init-faces))))))
5194 (defun cperl-load-font-lock-keywords ()
5195 (or cperl-faces-init (cperl-init-faces))
5196 perl-font-lock-keywords)
5198 (defun cperl-load-font-lock-keywords-1 ()
5199 (or cperl-faces-init (cperl-init-faces))
5200 perl-font-lock-keywords-1)
5202 (defun cperl-load-font-lock-keywords-2 ()
5203 (or cperl-faces-init (cperl-init-faces))
5204 perl-font-lock-keywords-2)
5206 (defvar perl-font-lock-keywords-1 nil
5207 "Additional expressions to highlight in Perl mode. Minimal set.")
5208 (defvar perl-font-lock-keywords nil
5209 "Additional expressions to highlight in Perl mode. Default set.")
5210 (defvar perl-font-lock-keywords-2 nil
5211 "Additional expressions to highlight in Perl mode. Maximal set")
5213 (defvar font-lock-background-mode)
5214 (defvar font-lock-display-type)
5215 (defun cperl-init-faces-weak ()
5216 ;; Allow `cperl-find-pods-heres' to run.
5217 (or (boundp 'font-lock-constant-face)
5218 (cperl-force-face font-lock-constant-face
5219 "Face for constant and label names")
5220 ;;(setq font-lock-constant-face 'font-lock-constant-face)
5223 (defun cperl-init-faces ()
5224 (condition-case errs
5226 (require 'font-lock)
5227 (and (fboundp 'font-lock-fontify-anchored-keywords)
5228 (featurep 'font-lock-extra)
5229 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
5230 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
5231 (if (fboundp 'font-lock-fontify-anchored-keywords)
5232 (setq font-lock-anchored t))
5234 t-font-lock-keywords
5236 (list "[ \t]+$" 0 cperl-invalid-face t)
5239 "\\(^\\|[^$@%&\\]\\)\\<\\("
5242 '("if" "until" "while" "elsif" "else" "unless" "for"
5243 "foreach" "continue" "exit" "die" "last" "goto" "next"
5244 "redo" "return" "local" "exec" "sub" "do" "dump" "use"
5245 "require" "package" "eval" "my" "our"
5246 "BEGIN" "END" "CHECK" "INIT")
5247 "\\|") ; Flow control
5248 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
5249 ; In what follows we use `type' style
5250 ; for overwritable builtins
5253 "\\(^\\|[^$@%&\\]\\)\\<\\("
5254 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
5255 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
5256 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
5257 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
5258 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
5259 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
5260 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
5261 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
5262 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
5263 ;; "gethostbyname" "gethostent" "getlogin"
5264 ;; "getnetbyaddr" "getnetbyname" "getnetent"
5265 ;; "getpeername" "getpgrp" "getppid" "getpriority"
5266 ;; "getprotobyname" "getprotobynumber" "getprotoent"
5267 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
5268 ;; "getservbyport" "getservent" "getsockname"
5269 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
5270 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
5271 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
5272 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
5273 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
5274 ;; "quotemeta" "rand" "read" "readdir" "readline"
5275 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
5276 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
5277 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
5278 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
5279 ;; "setpriority" "setprotoent" "setpwent" "setservent"
5280 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
5281 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
5282 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
5283 ;; "syscall" "sysread" "system" "syswrite" "tell"
5284 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
5285 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
5286 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
5287 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
5288 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
5289 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
5290 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
5291 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
5292 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
5293 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
5294 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
5295 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
5296 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
5297 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
5298 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
5299 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
5300 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
5301 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
5302 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
5303 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
5304 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
5305 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
5306 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
5307 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
5308 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
5309 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
5310 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
5311 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
5312 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|tem\\|write\\)\\|"
5313 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
5314 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
5315 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
5316 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
5317 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
5318 "\\)\\>") 2 'font-lock-type-face)
5319 ;; In what follows we use `other' style
5320 ;; for nonoverwritable builtins
5321 ;; Somehow 's', 'm' are not auto-generated???
5324 "\\(^\\|[^$@%&\\]\\)\\<\\("
5325 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "__END__" "INIT" "chomp"
5326 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
5327 ;; "eval" "exists" "for" "foreach" "format" "goto"
5328 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
5329 ;; "no" "our" "package" "pop" "pos" "print" "printf" "push"
5330 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
5331 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
5332 ;; "undef" "unless" "unshift" "untie" "until" "use"
5334 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
5335 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
5336 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|if\\|INIT\\|keys\\|"
5337 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our|"
5338 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
5339 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
5340 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
5341 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
5342 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
5343 "\\|[sm]" ; Added manually
5344 "\\)\\>") 2 'cperl-nonoverridable-face)
5345 ;; (mapconcat 'identity
5346 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
5347 ;; "#include" "#define" "#undef")
5349 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
5350 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
5351 '("\\<sub[ \t]+\\([^ \t{;()]+\\)[ \t]*\\(([^()]*)[ \t]*\\)?[#{\n]" 1
5352 font-lock-function-name-face)
5353 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
5354 2 font-lock-function-name-face)
5355 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
5356 1 font-lock-function-name-face)
5357 (cond ((featurep 'font-lock-extra)
5358 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5359 (2 font-lock-string-face t)
5360 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
5362 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5363 (2 font-lock-string-face t)
5364 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5366 (1 font-lock-string-face t))))
5367 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
5368 2 font-lock-string-face t)))
5369 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
5370 font-lock-string-face t)
5371 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
5372 font-lock-constant-face) ; labels
5373 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
5374 2 font-lock-constant-face)
5375 (cond ((featurep 'font-lock-extra)
5376 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5377 (3 font-lock-variable-name-face)
5379 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
5380 (1 font-lock-variable-name-face)
5381 (2 '(restart 2 nil) nil t)))
5382 nil t))) ; local variables, multiple
5384 '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
5385 (3 font-lock-variable-name-face)
5386 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)"
5388 (1 font-lock-variable-name-face))))
5389 (t '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
5390 3 font-lock-variable-name-face)))
5391 '("\\<for\\(each\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
5392 2 font-lock-variable-name-face)))
5394 t-font-lock-keywords-1
5395 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
5396 (not cperl-xemacs-p) ; not yet as of XEmacs 19.12
5398 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
5399 (if (eq (char-after (match-beginning 2)) ?%)
5402 t) ; arrays and hashes
5403 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
5405 (if (= (- (match-end 2) (match-beginning 2)) 1)
5406 (if (eq (char-after (match-beginning 3)) ?{)
5408 cperl-array-face) ; arrays and hashes
5409 font-lock-variable-name-face) ; Just to put something
5411 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
5412 ;;; Too much noise from \s* @s[ and friends
5413 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
5414 ;;(3 font-lock-function-name-face t t)
5416 ;; (if (cperl-slash-is-regexp)
5417 ;; font-lock-function-name-face 'default) nil t))
5419 (setq perl-font-lock-keywords-1
5420 (if cperl-syntaxify-by-font-lock
5421 (cons 'cperl-fontify-update
5422 t-font-lock-keywords)
5423 t-font-lock-keywords)
5424 perl-font-lock-keywords perl-font-lock-keywords-1
5425 perl-font-lock-keywords-2 (append
5426 perl-font-lock-keywords-1
5427 t-font-lock-keywords-1)))
5428 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
5429 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
5430 (eval ; Avoid a warning
5431 '(font-lock-require-faces
5433 ;; Color-light Color-dark Gray-light Gray-dark Mono
5434 (list 'font-lock-comment-face
5435 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
5440 (list 'font-lock-string-face
5441 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
5446 (list 'font-lock-function-name-face
5448 "Blue" "LightSkyBlue" "Gray50" "LightGray"
5449 (cdr (assq 'background-color ; if mono
5450 (frame-parameters))))
5453 (cdr (assq 'foreground-color ; if mono
5454 (frame-parameters))))
5458 (list 'font-lock-variable-name-face
5459 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
5464 (list 'font-lock-type-face
5465 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
5471 (list 'font-lock-constant-face
5472 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
5478 (list 'cperl-nonoverridable-face
5479 ["chartreuse3" ("orchid1" "orange")
5486 (list 'cperl-array-face
5487 ["blue" "yellow" nil "Gray80"]
5488 ["lightyellow2" ("navy" "os2blue" "darkgreen")
5493 (list 'cperl-hash-face
5494 ["red" "red" nil "Gray80"]
5495 ["lightyellow2" ("navy" "os2blue" "darkgreen")
5500 ;; Do it the dull way, without choose-color
5501 (defvar cperl-guessed-background nil
5502 "Display characteristics as guessed by cperl.")
5503 ;; (or (fboundp 'x-color-defined-p)
5504 ;; (defalias 'x-color-defined-p
5505 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
5506 ;; ;; XEmacs >= 19.12
5507 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
5509 ;; (t 'x-valid-color-name-p))))
5510 (cperl-force-face font-lock-constant-face
5511 "Face for constant and label names")
5512 (cperl-force-face font-lock-variable-name-face
5513 "Face for variable names")
5514 (cperl-force-face font-lock-type-face
5515 "Face for data types")
5516 (cperl-force-face cperl-nonoverridable-face
5517 "Face for data types from another group")
5518 (cperl-force-face font-lock-comment-face
5519 "Face for comments")
5520 (cperl-force-face font-lock-function-name-face
5521 "Face for function names")
5522 (cperl-force-face cperl-hash-face
5524 (cperl-force-face cperl-array-face
5526 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
5527 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
5528 ;;(or (boundp 'font-lock-type-face)
5529 ;; (defconst font-lock-type-face
5530 ;; 'font-lock-type-face
5531 ;; "Face to use for data types."))
5532 ;;(or (boundp 'cperl-nonoverridable-face)
5533 ;; (defconst cperl-nonoverridable-face
5534 ;; 'cperl-nonoverridable-face
5535 ;; "Face to use for data types from another group."))
5536 ;;(if (not cperl-xemacs-p) nil
5537 ;; (or (boundp 'font-lock-comment-face)
5538 ;; (defconst font-lock-comment-face
5539 ;; 'font-lock-comment-face
5540 ;; "Face to use for comments."))
5541 ;; (or (boundp 'font-lock-keyword-face)
5542 ;; (defconst font-lock-keyword-face
5543 ;; 'font-lock-keyword-face
5544 ;; "Face to use for keywords."))
5545 ;; (or (boundp 'font-lock-function-name-face)
5546 ;; (defconst font-lock-function-name-face
5547 ;; 'font-lock-function-name-face
5548 ;; "Face to use for function names.")))
5550 (not (cperl-is-face 'cperl-array-face))
5551 (cperl-is-face 'font-lock-emphasized-face))
5552 (copy-face 'font-lock-emphasized-face 'cperl-array-face))
5554 (not (cperl-is-face 'cperl-hash-face))
5555 (cperl-is-face 'font-lock-other-emphasized-face))
5556 (copy-face 'font-lock-other-emphasized-face
5559 (not (cperl-is-face 'cperl-nonoverridable-face))
5560 (cperl-is-face 'font-lock-other-type-face))
5561 (copy-face 'font-lock-other-type-face
5562 'cperl-nonoverridable-face))
5563 ;;(or (boundp 'cperl-hash-face)
5564 ;; (defconst cperl-hash-face
5566 ;; "Face to use for hashes."))
5567 ;;(or (boundp 'cperl-array-face)
5568 ;; (defconst cperl-array-face
5569 ;; 'cperl-array-face
5570 ;; "Face to use for arrays."))
5571 ;; Here we try to guess background
5573 (if (boundp 'font-lock-background-mode)
5574 font-lock-background-mode
5576 (face-list (and (fboundp 'face-list) (face-list)))
5579 ;;;; (fset 'cperl-is-face
5580 ;;;; (cond ((fboundp 'find-face)
5581 ;;;; (symbol-function 'find-face))
5583 ;;;; (function (lambda (face) (member face face-list))))
5585 ;;;; (function (lambda (face) (boundp face))))))
5586 (defvar cperl-guessed-background
5587 (if (and (boundp 'font-lock-display-type)
5588 (eq font-lock-display-type 'grayscale))
5591 "Background as guessed by CPerl mode")
5593 (not (cperl-is-face 'font-lock-constant-face))
5594 (cperl-is-face 'font-lock-reference-face))
5595 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
5596 (if (cperl-is-face 'font-lock-type-face) nil
5597 (copy-face 'default 'font-lock-type-face)
5599 ((eq background 'light)
5600 (set-face-foreground 'font-lock-type-face
5601 (if (x-color-defined-p "seagreen")
5604 ((eq background 'dark)
5605 (set-face-foreground 'font-lock-type-face
5606 (if (x-color-defined-p "os2pink")
5610 (set-face-background 'font-lock-type-face "gray90"))))
5611 (if (cperl-is-face 'cperl-nonoverridable-face)
5613 (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
5615 ((eq background 'light)
5616 (set-face-foreground 'cperl-nonoverridable-face
5617 (if (x-color-defined-p "chartreuse3")
5620 ((eq background 'dark)
5621 (set-face-foreground 'cperl-nonoverridable-face
5622 (if (x-color-defined-p "orchid1")
5625 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
5626 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
5628 ;;; ((eq background 'light)
5629 ;;; (set-face-background 'font-lock-other-emphasized-face
5630 ;;; (if (x-color-defined-p "lightyellow2")
5632 ;;; (if (x-color-defined-p "lightyellow")
5634 ;;; "light yellow"))))
5635 ;;; ((eq background 'dark)
5636 ;;; (set-face-background 'font-lock-other-emphasized-face
5637 ;;; (if (x-color-defined-p "navy")
5639 ;;; (if (x-color-defined-p "darkgreen")
5641 ;;; "dark green"))))
5642 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
5643 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
5644 ;;; (copy-face 'bold 'font-lock-emphasized-face)
5646 ;;; ((eq background 'light)
5647 ;;; (set-face-background 'font-lock-emphasized-face
5648 ;;; (if (x-color-defined-p "lightyellow2")
5650 ;;; "lightyellow")))
5651 ;;; ((eq background 'dark)
5652 ;;; (set-face-background 'font-lock-emphasized-face
5653 ;;; (if (x-color-defined-p "navy")
5655 ;;; (if (x-color-defined-p "darkgreen")
5657 ;;; "dark green"))))
5658 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
5659 (if (cperl-is-face 'font-lock-variable-name-face) nil
5660 (copy-face 'italic 'font-lock-variable-name-face))
5661 (if (cperl-is-face 'font-lock-constant-face) nil
5662 (copy-face 'italic 'font-lock-constant-face))))
5663 (setq cperl-faces-init t))
5664 (error (message "cperl-init-faces (ignored): %s" errs))))
5667 (defun cperl-ps-print-init ()
5668 "Initialization of `ps-print' components for faces used in CPerl."
5669 (eval-after-load "ps-print"
5670 '(setq ps-bold-faces
5671 ;; font-lock-variable-name-face
5672 ;; font-lock-constant-face
5673 (append '(cperl-array-face
5677 ;; font-lock-constant-face
5678 (append '(cperl-nonoverridable-face
5682 ;; font-lock-type-face
5683 (append '(cperl-array-face
5686 cperl-nonoverridable-face)
5687 ps-underlined-faces))))
5689 (defvar ps-print-face-extension-alist)
5691 (defun cperl-ps-print (&optional file)
5692 "Pretty-print in CPerl style.
5693 If optional argument FILE is an empty string, prints to printer, otherwise
5694 to the file FILE. If FILE is nil, prompts for a file name.
5696 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
5699 (setq file (read-from-minibuffer
5700 "Print to file (if empty - to printer): "
5701 (concat (buffer-file-name) ".ps")
5702 nil nil 'file-name-history)))
5703 (or (> (length file) 0)
5705 (require 'ps-print) ; To get ps-print-face-extension-alist
5706 (let ((ps-print-color-p t)
5707 (ps-print-face-extension-alist ps-print-face-extension-alist))
5708 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
5709 (ps-print-buffer-with-faces file)))
5711 ;;; (defun cperl-ps-print-init ()
5712 ;;; "Initialization of `ps-print' components for faces used in CPerl."
5713 ;;; ;; Guard against old versions
5714 ;;; (defvar ps-underlined-faces nil)
5715 ;;; (defvar ps-bold-faces nil)
5716 ;;; (defvar ps-italic-faces nil)
5717 ;;; (setq ps-bold-faces
5718 ;;; (append '(font-lock-emphasized-face
5719 ;;; cperl-array-face
5720 ;;; font-lock-keyword-face
5721 ;;; font-lock-variable-name-face
5722 ;;; font-lock-constant-face
5723 ;;; font-lock-reference-face
5724 ;;; font-lock-other-emphasized-face
5725 ;;; cperl-hash-face)
5727 ;;; (setq ps-italic-faces
5728 ;;; (append '(cperl-nonoverridable-face
5729 ;;; font-lock-constant-face
5730 ;;; font-lock-reference-face
5731 ;;; font-lock-other-emphasized-face
5732 ;;; cperl-hash-face)
5733 ;;; ps-italic-faces))
5734 ;;; (setq ps-underlined-faces
5735 ;;; (append '(font-lock-emphasized-face
5736 ;;; cperl-array-face
5737 ;;; font-lock-other-emphasized-face
5739 ;;; cperl-nonoverridable-face font-lock-type-face)
5740 ;;; ps-underlined-faces))
5741 ;;; (cons 'font-lock-type-face ps-underlined-faces))
5744 (if (cperl-enable-font-lock) (cperl-windowed-init))
5746 (defconst cperl-styles-entries
5747 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
5748 cperl-label-offset cperl-extra-newline-before-brace
5749 cperl-merge-trailing-else
5750 cperl-continued-statement-offset))
5752 (defconst cperl-style-alist
5753 '(("CPerl" ; =GNU without extra-newline-before-brace
5754 (cperl-indent-level . 2)
5755 (cperl-brace-offset . 0)
5756 (cperl-continued-brace-offset . 0)
5757 (cperl-label-offset . -2)
5758 (cperl-extra-newline-before-brace . nil)
5759 (cperl-merge-trailing-else . t)
5760 (cperl-continued-statement-offset . 2))
5761 ("PerlStyle" ; CPerl with 4 as indent
5762 (cperl-indent-level . 4)
5763 (cperl-brace-offset . 0)
5764 (cperl-continued-brace-offset . 0)
5765 (cperl-label-offset . -4)
5766 (cperl-extra-newline-before-brace . nil)
5767 (cperl-merge-trailing-else . t)
5768 (cperl-continued-statement-offset . 4))
5770 (cperl-indent-level . 2)
5771 (cperl-brace-offset . 0)
5772 (cperl-continued-brace-offset . 0)
5773 (cperl-label-offset . -2)
5774 (cperl-extra-newline-before-brace . t)
5775 (cperl-merge-trailing-else . nil)
5776 (cperl-continued-statement-offset . 2))
5778 (cperl-indent-level . 5)
5779 (cperl-brace-offset . 0)
5780 (cperl-continued-brace-offset . -5)
5781 (cperl-label-offset . -5)
5782 ;;(cperl-extra-newline-before-brace . nil) ; ???
5783 (cperl-merge-trailing-else . nil)
5784 (cperl-continued-statement-offset . 5))
5786 (cperl-indent-level . 4)
5787 (cperl-brace-offset . 0)
5788 (cperl-continued-brace-offset . -4)
5789 (cperl-label-offset . -4)
5790 ;;(cperl-extra-newline-before-brace . nil) ; ???
5791 (cperl-continued-statement-offset . 4))
5793 (cperl-indent-level . 4)
5794 (cperl-brace-offset . 0)
5795 (cperl-continued-brace-offset . -4)
5796 (cperl-label-offset . -4)
5797 (cperl-continued-statement-offset . 4)
5798 (cperl-merge-trailing-else . nil)
5799 (cperl-extra-newline-before-brace . t))
5802 (cperl-indent-level . 4)
5803 (cperl-brace-offset . 0)
5804 (cperl-continued-brace-offset . 0)
5805 (cperl-label-offset . -4)
5806 ;;(cperl-extra-newline-before-brace . nil) ; ???
5807 (cperl-continued-statement-offset . 4)))
5808 "(Experimental) list of variables to set to get a particular indentation style.
5809 Should be used via `cperl-set-style' or via Perl menu.")
5811 (defun cperl-set-style (style)
5812 "Set CPerl-mode variables to use one of several different indentation styles.
5813 The arguments are a string representing the desired style.
5814 The list of styles is in `cperl-style-alist', available styles
5815 are GNU, K&R, BSD, C++ and Whitesmith.
5817 The current value of style is memorized (unless there is a memorized
5818 data already), may be restored by `cperl-set-style-back'.
5820 Chosing \"Current\" style will not change style, so this may be used for
5821 side-effect of memorizing only."
5823 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
5824 cperl-style-alist)))
5825 (list (completing-read "Enter style: " list nil 'insist))))
5827 (setq cperl-old-style
5830 (cons name (eval name))))
5831 cperl-styles-entries)))
5832 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
5834 (setq setting (car style) style (cdr style))
5835 (set (car setting) (cdr setting)))))
5837 (defun cperl-set-style-back ()
5838 "Restore a style memorised by `cperl-set-style'."
5840 (or cperl-old-style (error "The style was not changed"))
5842 (while cperl-old-style
5843 (setq setting (car cperl-old-style)
5844 cperl-old-style (cdr cperl-old-style))
5845 (set (car setting) (cdr setting)))))
5847 (defun cperl-check-syntax ()
5849 (require 'mode-compile)
5850 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
5851 (eval '(mode-compile)))) ; Avoid a warning
5853 (defun cperl-info-buffer (type)
5854 ;; Returns buffer with documentation. Creates if missing.
5855 ;; If TYPE, this vars buffer.
5856 ;; Special care is taken to not stomp over an existing info buffer
5857 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
5858 (info (get-buffer bname))
5859 (oldbuf (get-buffer "*info*")))
5861 (save-window-excursion
5866 (rename-buffer "*info-perl-tmp*")))
5867 (save-window-excursion
5869 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
5870 (set-buffer "*info*")
5871 (rename-buffer bname)
5873 (set-buffer "*info-perl-tmp*")
5874 (rename-buffer "*info*")
5875 (set-buffer bname)))
5876 (make-variable-buffer-local 'window-min-height)
5877 (setq window-min-height 2)
5878 (current-buffer)))))
5880 (defun cperl-word-at-point (&optional p)
5881 ;; Returns the word at point or at P.
5883 (if p (goto-char p))
5884 (or (cperl-word-at-point-hard)
5887 (funcall (or (and (boundp 'find-tag-default-function)
5888 find-tag-default-function)
5889 (get major-mode 'find-tag-default-function)
5890 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
5891 ;; automatically used within `find-tag-default':
5892 'find-tag-default))))))
5894 (defun cperl-info-on-command (command)
5895 "Shows documentation for Perl command in other window.
5896 If perl-info buffer is shown in some frame, uses this frame.
5897 Customized by setting variables `cperl-shrink-wrap-info-frame',
5898 `cperl-max-help-size'."
5900 (let* ((default (cperl-word-at-point))
5902 (format "Find doc for Perl function (default %s): "
5904 (list (if (equal read "")
5908 (let ((buffer (current-buffer))
5909 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
5910 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
5911 max-height char-height buf-list)
5912 (if (string-match "^-[a-zA-Z]$" command)
5913 (setq cmd-desc "^-X[ \t\n]"))
5914 (setq isvar (string-match "^[$@%]" command)
5915 buf (cperl-info-buffer isvar)
5916 iniwin (selected-window)
5917 fr1 (window-frame iniwin))
5919 (beginning-of-buffer)
5921 (progn (re-search-forward "^-X[ \t\n]")
5923 (if (re-search-forward cmd-desc nil t)
5925 ;; Go back to beginning of the group (ex, for qq)
5926 (if (re-search-backward "^[ \t\n\f]")
5931 buf-list (list buf "*info-perl-var*" "*info-perl*"))
5932 (while (and (not win) buf-list)
5933 (setq win (get-buffer-window (car buf-list) t))
5934 (setq buf-list (cdr buf-list)))
5936 (eq (window-buffer win) buf)
5937 (set-window-buffer win buf))
5938 (and win (setq fr2 (window-frame win)))
5939 (if (or (not fr2) (eq fr1 fr2))
5941 (special-display-popup-frame buf) ; Make it visible
5942 (select-window win))
5943 (goto-char pos) ; Needed (?!).
5945 (setq iniheight (window-height)
5946 frheight (frame-height)
5947 not-loner (< iniheight (1- frheight))) ; Are not alone
5948 (cond ((if not-loner cperl-max-help-size
5949 cperl-shrink-wrap-info-frame)
5955 (if (re-search-forward
5956 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
5957 (match-beginning 0) (point-max)))))
5960 (/ (* (- frheight 3) cperl-max-help-size) 100)
5961 (setq char-height (frame-char-height))
5962 ;; Non-functioning under OS/2:
5963 (if (eq char-height 1) (setq char-height 18))
5964 ;; Title, menubar, + 2 for slack
5965 (- (/ (x-display-pixel-height) char-height) 4)
5967 (if (> height max-height) (setq height max-height))
5968 ;;(message "was %s doing %s" iniheight height)
5970 (enlarge-window (- height iniheight))
5971 (set-frame-height (window-frame win) (1+ height)))))
5972 (set-window-start (selected-window) pos))
5973 (message "No entry for %s found." command))
5974 ;;(pop-to-buffer buffer)
5975 (select-window iniwin)))
5977 (defun cperl-info-on-current-command ()
5978 "Shows documentation for Perl command at point in other window."
5980 (cperl-info-on-command (cperl-word-at-point)))
5982 (defun cperl-imenu-info-imenu-search ()
5983 (if (looking-at "^-X[ \t\n]") nil
5985 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
5988 (defun cperl-imenu-info-imenu-name ()
5990 (match-beginning 1) (match-end 1)))
5992 (defun cperl-imenu-on-info ()
5994 (let* ((buffer (current-buffer))
5995 imenu-create-index-function
5996 imenu-prev-index-position-function
5997 imenu-extract-index-name-function
5998 (index-item (save-restriction
5999 (save-window-excursion
6000 (set-buffer (cperl-info-buffer nil))
6001 (setq imenu-create-index-function
6002 'imenu-default-create-index-function
6003 imenu-prev-index-position-function
6004 'cperl-imenu-info-imenu-search
6005 imenu-extract-index-name-function
6006 'cperl-imenu-info-imenu-name)
6007 (imenu-choose-buffer-index)))))
6011 (pop-to-buffer "*info-perl*")
6013 ((markerp (cdr index-item))
6014 (goto-char (marker-position (cdr index-item))))
6016 (goto-char (cdr index-item))))
6017 (set-window-start (selected-window) (point))
6018 (pop-to-buffer buffer)))))
6020 (defun cperl-lineup (beg end &optional step minshift)
6021 "Lineup construction in a region.
6022 Beginning of region should be at the start of a construction.
6023 All first occurrences of this construction in the lines that are
6024 partially contained in the region are lined up at the same column.
6026 MINSHIFT is the minimal amount of space to insert before the construction.
6027 STEP is the tabwidth to position constructions.
6028 If STEP is `nil', `cperl-lineup-step' will be used
6029 \(or `cperl-indent-level', if `cperl-lineup-step' is `nil').
6030 Will not move the position at the start to the left."
6032 (let (search col tcol seen b e)
6036 (setq end (point-marker))
6038 (skip-chars-forward " \t\f")
6039 (setq beg (point-marker))
6040 (indent-region beg end nil)
6042 (setq col (current-column))
6043 (if (looking-at "[a-zA-Z0-9_]")
6044 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
6048 (buffer-substring (match-beginning 0)
6049 (match-end 0))) "\\>"))
6050 (error "Cannot line up in a middle of the word"))
6051 (if (looking-at "$")
6052 (error "Cannot line up end of line"))
6053 (setq search (regexp-quote (char-to-string (following-char)))))
6054 (setq step (or step cperl-lineup-step cperl-indent-level))
6055 (or minshift (setq minshift 1))
6057 (beginning-of-line 2)
6058 (and (< (point) end)
6059 (re-search-forward search end t)
6060 (goto-char (match-beginning 0))))
6061 (setq tcol (current-column) seen t)
6062 (if (> tcol col) (setq col tcol)))
6064 (error "The construction to line up occurred only once"))
6066 (setq col (+ col minshift))
6067 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
6071 (skip-chars-backward " \t")
6072 (delete-region (point) e)
6073 (indent-to-column col); (make-string (- col (current-column)) ?\ ))
6074 (beginning-of-line 2)
6075 (and (< (point) end)
6076 (re-search-forward search end t)
6077 (goto-char (match-beginning 0)))))))) ; No body
6079 (defun cperl-etags (&optional add all files)
6080 "Run etags with appropriate options for Perl files.
6081 If optional argument ALL is `recursive', will process Perl files
6082 in subdirectories too."
6085 (args '("-l" "none" "-r" "/\\<\\(package\\|sub\\)[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([{#]\\|$\\)\\)/\\4/"))
6087 (if add (setq args (cons "-a" args)))
6088 (or files (setq files (list buffer-file-name)))
6090 ((eq all 'recursive)
6091 ;;(error "Not implemented: recursive")
6092 (setq args (append (list "-e"
6093 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
6095 find(\\&wanted, '.');
6100 ;;(error "Not implemented: all")
6101 (setq args (append (list "-e"
6102 "push @ARGV, <*.PL *.pl *.pm>;
6107 (setq args (append args files))))
6108 (setq res (apply 'call-process cmd nil nil nil args))
6110 (message "etags returned \"%s\"" res))))
6112 (defun cperl-toggle-auto-newline ()
6113 "Toggle the state of `cperl-auto-newline'."
6115 (setq cperl-auto-newline (not cperl-auto-newline))
6116 (message "Newlines will %sbe auto-inserted now."
6117 (if cperl-auto-newline "" "not ")))
6119 (defun cperl-toggle-abbrev ()
6120 "Toggle the state of automatic keyword expansion in CPerl mode."
6122 (abbrev-mode (if abbrev-mode 0 1))
6123 (message "Perl control structure will %sbe auto-inserted now."
6124 (if abbrev-mode "" "not ")))
6127 (defun cperl-toggle-electric ()
6128 "Toggle the state of parentheses doubling in CPerl mode."
6130 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
6131 (message "Parentheses will %sbe auto-doubled now."
6132 (if (cperl-val 'cperl-electric-parens) "" "not ")))
6134 (defun cperl-toggle-autohelp ()
6135 "Toggle the state of automatic help message in CPerl mode.
6136 See `cperl-lazy-help-time' too."
6138 (if (fboundp 'run-with-idle-timer)
6140 (if cperl-lazy-installed
6141 (eval '(cperl-lazy-unstall))
6142 (cperl-lazy-install))
6143 (message "Perl help messages will %sbe automatically shown now."
6144 (if cperl-lazy-installed "" "not ")))
6145 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
6147 (defun cperl-toggle-construct-fix ()
6148 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
6150 (setq cperl-indent-region-fix-constructs
6151 (if cperl-indent-region-fix-constructs
6154 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
6155 (if cperl-indent-region-fix-constructs "" "not ")))
6157 ;;;; Tags file creation.
6159 (defvar cperl-tmp-buffer " *cperl-tmp*")
6161 (defun cperl-setup-tmp-buf ()
6162 (set-buffer (get-buffer-create cperl-tmp-buffer))
6163 (set-syntax-table cperl-mode-syntax-table)
6164 (buffer-disable-undo)
6166 (if cperl-use-syntax-table-text-property-for-tags
6168 (make-variable-buffer-local 'parse-sexp-lookup-properties)
6169 ;; Do not introduce variable if not needed, we check it!
6170 (set 'parse-sexp-lookup-properties t))))
6172 (defun cperl-xsub-scan ()
6175 (let ((index-alist '())
6176 (prev-pos 0) index index1 name package prefix)
6177 (goto-char (point-min))
6179 (message "Scanning XSUB for index")
6180 (imenu-progress-message prev-pos 0))
6181 ;; Search for the function
6182 (progn ;;save-match-data
6183 (while (re-search-forward
6184 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
6187 (imenu-progress-message prev-pos))
6189 ((match-beginning 2) ; SECTION
6190 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
6191 (goto-char (match-beginning 0))
6192 (skip-chars-forward " \t")
6194 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
6195 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
6197 ((not package) nil) ; C language section
6198 ((match-beginning 3) ; XSUB
6199 (goto-char (1+ (match-beginning 3)))
6200 (setq index (imenu-example--name-and-position))
6201 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
6202 (if (and prefix (string-match (concat "^" prefix) name))
6203 (setq name (substring name (length prefix))))
6204 (cond ((string-match "::" name) nil)
6206 (setq index1 (cons (concat package "::" name) (cdr index)))
6207 (push index1 index-alist)))
6209 (push index index-alist))
6211 ;; (beginning-of-line)
6212 (setq index (imenu-example--name-and-position))
6213 (setcar index (concat package "::BOOT:"))
6214 (push index index-alist)))))
6216 (imenu-progress-message prev-pos 100))
6219 (defun cperl-find-tags (file xs topdir)
6220 (let (ind (b (get-buffer cperl-tmp-buffer)) lst elt pos ret rel
6221 (cperl-pod-here-fontify nil))
6223 (if b (set-buffer b)
6224 (cperl-setup-tmp-buf))
6226 (setq file (car (insert-file-contents file)))
6227 (message "Scanning file %s ..." file)
6228 (if (and cperl-use-syntax-table-text-property-for-tags
6230 (condition-case err ; after __END__ may have garbage
6231 (cperl-find-pods-heres)
6232 (error (message "While scanning for syntax: %s" err))))
6234 (setq lst (cperl-xsub-scan))
6235 (setq ind (imenu-example--create-perl-index))
6236 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
6241 (cond ((string-match "^[_a-zA-Z]" (car elt))
6242 (goto-char (cdr elt))
6243 (beginning-of-line) ; pos should be of the start of the line
6246 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
6247 (buffer-substring (progn
6250 (or (eolp) (forward-char 1))
6258 (setq elt (car lst) lst (cdr lst))
6263 (if (string-match "^package " (car elt))
6264 (substring (car elt) 8)
6267 (number-to-string (elt elt 2)) ; Line
6269 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
6271 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
6272 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
6274 ;; Need to insert the name without package as well
6275 (setq lst (cons (cons (substring (elt elt 3)
6283 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
6284 (set-text-properties 0 (length rel) nil rel)
6285 (and (equal topdir (substring rel 0 (length topdir)))
6286 (setq rel (substring file (length topdir))))
6287 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
6288 (setq ret (buffer-substring 1 (point-max)))
6291 (message "Scanning file %s finished" file))
6294 (defun cperl-add-tags-recurse-noxs ()
6295 "Add to TAGS data for Perl and XSUB files in the current directory and kids.
6297 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
6298 -f cperl-add-tags-recurse
6300 (cperl-write-tags nil nil t t nil t))
6302 (defun cperl-add-tags-recurse ()
6303 "Add to TAGS file data for Perl files in the current directory and kids.
6305 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
6306 -f cperl-add-tags-recurse
6308 (cperl-write-tags nil nil t t))
6310 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
6311 ;; If INBUFFER, do not select buffer, and do not save
6312 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
6315 (setq file (if dir default-directory (buffer-file-name)))
6316 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
6318 (setq topdir default-directory))
6319 (let ((tags-file-name "TAGS")
6320 (case-fold-search (eq system-type 'emx))
6323 (cond (inbuffer nil) ; Already there
6324 ((file-exists-p tags-file-name)
6326 (visit-tags-table-buffer)
6327 (visit-tags-table-buffer tags-file-name)))
6328 (t (set-buffer (find-file-noselect tags-file-name))))
6331 (cond ((eq erase 'ignore))
6334 (setq erase 'ignore)))
6336 (directory-files file t
6337 (if recurse nil cperl-scan-files-regexp)
6339 (mapcar (function (lambda (file)
6341 ((string-match cperl-noscan-files-regexp file)
6343 ((not (file-directory-p file))
6344 (if (string-match cperl-scan-files-regexp file)
6345 (cperl-write-tags file erase recurse nil t noxs topdir)))
6347 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
6351 (setq xs (string-match "\\.xs$" file))
6352 (if (not (and xs noxs))
6354 (cond ((eq erase 'ignore) (goto-char (point-max)))
6355 (erase (erase-buffer))
6359 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
6360 (set-text-properties 0 (length rel) nil rel)
6361 (and (equal topdir (substring rel 0 (length topdir)))
6362 (setq rel (substring file (length topdir))))
6363 (if (search-forward (concat "\f\n" rel ",") nil t)
6365 (search-backward "\f\n")
6366 (delete-region (point)
6369 (if (search-forward "\f\n"
6373 (goto-char (point-max)))))
6374 (insert (cperl-find-tags file xs topdir))))))
6375 (if inbuffer nil ; Delegate to the caller
6376 (save-buffer 0) ; No backup
6377 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
6378 (initialize-new-tags-table))))))
6380 (defvar cperl-tags-hier-regexp-list
6387 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
6389 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
6392 (defvar cperl-hierarchy '(() ())
6393 "Global hierarchy of classes")
6395 (defun cperl-tags-hier-fill ()
6396 ;; Suppose we are in a tag table cooked by cperl.
6398 (let (type pack name pos line chunk ord cons1 file str info fileind)
6399 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
6400 (setq pos (match-beginning 0)
6401 pack (match-beginning 2))
6403 (if (looking-at (concat
6412 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
6413 name (buffer-substring (match-beginning 2) (match-end 2))
6414 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
6415 line (buffer-substring (match-beginning 3) (match-end 3))
6418 fileind (format "%s:%s" file line)
6419 ;; Moves to beginning of the next line:
6420 info (cperl-etags-snarf-tag file line))
6423 ;; Make new member of hierarchy name ==> file ==> pos if needed
6424 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
6426 (setcdr cons1 (cons (cons fileind (vector file info))
6428 ;; First occurrence of the name, start alist
6429 (setq cons1 (cons name (list (cons fileind (vector file info)))))
6431 (setcar (cdr cperl-hierarchy)
6432 (cons cons1 (nth 1 cperl-hierarchy)))
6433 (setcar cperl-hierarchy
6434 (cons cons1 (car cperl-hierarchy)))))))
6437 (defun cperl-tags-hier-init (&optional update)
6438 "Show hierarchical menu of classes and methods.
6439 Finds info about classes by a scan of loaded TAGS files.
6440 Supposes that the TAGS files contain fully qualified function names.
6441 One may build such TAGS files from CPerl mode menu."
6445 (if (or update (null (nth 2 cperl-hierarchy)))
6446 (let (pack name cons1 to l1 l2 l3 l4 b
6447 (remover (function (lambda (elt) ; (name (file1...) (file2..))
6450 (setcdr elt (cdr (nth 1 elt))))))))
6451 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
6452 (setq cperl-hierarchy (list l1 l2 l3))
6453 (if cperl-xemacs-p ; Not checked
6456 ;; Does this work in XEmacs?
6457 (call-interactively 'visit-tags-table))
6458 (message "Updating list of classes...")
6459 (set-buffer (get-file-buffer tags-file-name))
6460 (cperl-tags-hier-fill))
6462 (call-interactively 'visit-tags-table))
6466 (message "Updating list of classes... %s" tagsfile)
6467 (set-buffer (get-file-buffer tagsfile))
6468 (cperl-tags-hier-fill)))
6470 (message "Updating list of classes... postprocessing..."))
6471 (mapcar remover (car cperl-hierarchy))
6472 (mapcar remover (nth 1 cperl-hierarchy))
6473 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
6474 (cons "Methods: " (car cperl-hierarchy))))
6475 (cperl-tags-treeify to 1)
6476 (setcar (nthcdr 2 cperl-hierarchy)
6477 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
6478 (message "Updating list of classes: done, requesting display...")
6479 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
6481 (or (nth 2 cperl-hierarchy)
6482 (error "No items found"))
6484 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
6486 (x-popup-menu t (nth 2 cperl-hierarchy))
6488 (tmm-prompt (nth 2 cperl-hierarchy))))
6489 (if (and update (listp update))
6490 (progn (while (cdr update) (setq update (cdr update)))
6491 (setq update (car update)))) ; Get the last from the list
6492 (if (vectorp update)
6494 (find-file (elt update 0))
6495 (cperl-etags-goto-tag-location (elt update 1))))
6496 (if (eq update -999) (cperl-tags-hier-init t)))
6498 (defun cperl-tags-treeify (to level)
6499 ;; cadr of `to' is read-write. On start it is a cons
6500 (let* ((regexp (concat "^\\(" (mapconcat
6502 (make-list level "[_a-zA-Z0-9]+")
6505 (packages (cdr (nth 1 to)))
6506 (methods (cdr (nth 2 to)))
6507 l1 head tail cons1 cons2 ord writeto packs recurse
6508 root-packages root-functions ms many_ms same_name ps
6512 (cond ((and (string-match regexp (car elt))
6513 (or (eq ord 1) (match-end 2)))
6514 (setq head (substring (car elt) 0 (match-end 1))
6515 tail (if (match-end 2) (substring (car elt)
6518 (if (setq cons1 (assoc head writeto)) nil
6519 ;; Need to init new head
6520 (setcdr writeto (cons (list head (list "Packages: ")
6523 (setq cons1 (nth 1 writeto)))
6524 (setq cons2 (nth ord cons1)) ; Either packs or meths
6525 (setcdr cons2 (cons elt (cdr cons2))))
6527 (setq root-functions (cons elt root-functions)))
6529 (setq root-packages (cons elt root-packages))))))))
6530 (setcdr to l1) ; Init to dynamic space
6533 (mapcar move-deeper packages)
6535 (mapcar move-deeper methods)
6537 (mapcar (function (lambda (elt)
6538 (cperl-tags-treeify elt (1+ level))))
6540 ;;Now clean up leaders with one child only
6541 (mapcar (function (lambda (elt)
6542 (if (not (and (listp (cdr elt))
6543 (eq (length elt) 2))) nil
6544 (setcar elt (car (nth 1 elt)))
6545 (setcdr elt (cdr (nth 1 elt))))))
6547 ;; Sort the roots of subtrees
6548 (if (default-value 'imenu-sort-function)
6550 (sort (cdr to) (default-value 'imenu-sort-function))))
6551 ;; Now add back functions removed from display
6552 (mapcar (function (lambda (elt)
6553 (setcdr to (cons elt (cdr to)))))
6554 (if (default-value 'imenu-sort-function)
6556 (sort root-functions (default-value 'imenu-sort-function)))
6558 ;; Now add back packages removed from display
6559 (mapcar (function (lambda (elt)
6560 (setcdr to (cons (cons (concat "package " (car elt))
6563 (if (default-value 'imenu-sort-function)
6565 (sort root-packages (default-value 'imenu-sort-function)))
6570 ;;; '(keymap "Name1"
6574 ;;; ("Tail1" "x") ("Tail2" "y"))))
6576 (defun cperl-list-fold (list name limit)
6577 (let (list1 list2 elt1 (num 0))
6578 (if (<= (length list) limit) list
6579 (setq list1 nil list2 nil)
6584 (if (<= num imenu-max-items)
6585 (setq list2 (cons elt1 list2))
6586 (setq list1 (cons (cons name
6591 (nreverse (cons (cons name
6595 (defun cperl-menu-to-keymap (menu &optional name)
6601 (cond ((listp (cdr elt))
6602 (setq list (cperl-list-fold
6603 (cdr elt) (car elt) imenu-max-items))
6606 (cperl-menu-to-keymap list))))
6608 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
6609 (cperl-list-fold menu "Root" imenu-max-items)))))
6612 (defvar cperl-bad-style-regexp
6613 (mapconcat 'identity
6614 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
6615 "[-<>=+^&|]+[^- \t\n=+<>~]" ; sign+ char
6618 "Finds places such that insertion of a whitespace may help a lot.")
6620 (defvar cperl-not-bad-style-regexp
6621 (mapconcat 'identity
6622 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
6623 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
6624 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
6625 "<\\$?\\sw+\\(\\.\\sw+\\)?>" ; <IN> <stdin.h>
6626 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
6633 "\\\\[&$@*\\\\]" ; \&func
6636 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
6639 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
6640 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
6641 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
6645 "If matches at the start of match found by `my-bad-c-style-regexp',
6646 insertion of a whitespace will not help.")
6650 (defun cperl-find-bad-style ()
6651 "Find places in the buffer where insertion of a whitespace may help.
6652 Prompts user for insertion of spaces.
6653 Currently it is tuned to C and Perl syntax."
6655 (let (found-bad (p (point)))
6656 (setq last-nonmenu-event 13) ; To disable popup
6657 (beginning-of-buffer)
6658 (map-y-or-n-p "Insert space here? "
6659 (function (lambda (arg) (insert " ")))
6660 'cperl-next-bad-style
6661 '("location" "locations" "insert a space into")
6662 '((?\C-r (lambda (arg)
6663 (let ((buffer-quit-function
6664 'exit-recursive-edit))
6665 (message "Exit with Esc Esc")
6667 t)) ; Consider acted upon
6668 "edit, exit with Esc Esc")
6670 (let ((buffer-quit-function
6671 'exit-recursive-edit))
6672 (message "Exit with Esc Esc")
6674 t)) ; Consider acted upon
6675 "edit, exit with Esc Esc"))
6677 (if found-bad (goto-char found-bad)
6679 (message "No appropriate place found"))))
6681 (defun cperl-next-bad-style ()
6682 (let (p (not-found t) (point (point)) found)
6683 (while (and not-found
6684 (re-search-forward cperl-bad-style-regexp nil 'to-end))
6686 (goto-char (match-beginning 0))
6688 (looking-at cperl-not-bad-style-regexp)
6689 ;; Check for a < -b and friends
6690 (and (eq (following-char) ?\-)
6692 (skip-chars-backward " \t\n")
6693 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\(, ?\[, ?\{))))
6694 ;; Now check for syntax type
6696 (setq found (point))
6697 (beginning-of-defun)
6698 (let ((pps (parse-partial-sexp (point) found)))
6699 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
6700 (goto-char (match-end 0))
6708 (defvar cperl-have-help-regexp
6712 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
6713 "[$@]\\^[a-zA-Z]" ; Special variable
6714 "[$@][^ \n\t]" ; Special variable
6715 "-[a-zA-Z]" ; File test
6716 "\\\\[a-zA-Z0]" ; Special chars
6717 "^=[a-z][a-zA-Z0-9_]*" ; Pod sections
6718 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
6719 "[a-zA-Z_0-9:]+" ; symbol or number
6728 "Matches places in the buffer we can find help for.")
6730 (defvar cperl-message-on-help-error t)
6731 (defvar cperl-help-from-timer nil)
6733 (defun cperl-word-at-point-hard ()
6734 ;; Does not save-excursion
6735 ;; Get to the something meaningful
6736 (or (eobp) (eolp) (forward-char 1))
6737 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
6738 (save-excursion (beginning-of-line) (point))
6741 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
6742 ;; (skip-chars-backward " \n\t\r({[]});,")
6743 ;; (or (bobp) (backward-char 1))))
6746 ((looking-at "[a-zA-Z0-9_:]") ; symbol
6747 (skip-chars-backward "a-zA-Z0-9_:")
6749 ((and (eq (preceding-char) ?^) ; $^I
6750 (eq (char-after (- (point) 2)) ?\$))
6752 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
6754 ((and (eq (preceding-char) ?\=)
6755 (eq (current-column) 1))
6756 (forward-char -1))) ; =head1
6757 (if (and (eq (preceding-char) ?\<)
6758 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
6760 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
6762 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
6764 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
6765 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
6767 ((and (eq (preceding-char) ?\$)
6768 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
6770 ((and (eq (following-char) ?\>)
6771 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
6774 (and (eq (preceding-char) ?\<)
6775 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
6776 (search-backward "<"))))
6777 ((and (eq (following-char) ?\$)
6778 (eq (preceding-char) ?\<)
6779 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
6781 (if (looking-at cperl-have-help-regexp)
6782 (buffer-substring (match-beginning 0) (match-end 0))))
6784 (defun cperl-get-help ()
6785 "Get one-line docs on the symbol at the point.
6786 The data for these docs is a little bit obsolete and may be in fact longer
6787 than a line. Your contribution to update/shorten it is appreciated."
6789 (save-match-data ; May be called "inside" query-replace
6791 (let ((word (cperl-word-at-point-hard)))
6793 (if (and cperl-help-from-timer ; Bail out if not in mainland
6794 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
6795 (or (memq (get-text-property (point) 'face)
6796 '(font-lock-comment-face font-lock-string-face))
6797 (memq (get-text-property (point) 'syntax-type)
6798 '(pod here-doc format))))
6800 (cperl-describe-perl-symbol word))
6801 (if cperl-message-on-help-error
6802 (message "Nothing found for %s..."
6803 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
6805 ;;; Stolen from perl-descr.el by Johan Vromans:
6807 (defvar cperl-doc-buffer " *perl-doc*"
6808 "Where the documentation can be found.")
6810 (defun cperl-describe-perl-symbol (val)
6811 "Display the documentation of symbol at point, a Perl operator."
6812 (let ((enable-recursive-minibuffers t)
6815 ((string-match "^[&*][a-zA-Z_]" val)
6816 (setq val (concat (substring val 0 1) "NAME")))
6817 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
6818 (setq val (concat "@" (substring val 1 (match-end 1)))))
6819 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
6820 (setq val (concat "%" (substring val 1 (match-end 1)))))
6821 ((and (string= val "x") (string-match "^x=" val))
6823 ((string-match "^\\$[\C-a-\C-z]" val)
6824 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
6825 ((string-match "^CORE::" val)
6826 (setq val "CORE::"))
6827 ((string-match "^SUPER::" val)
6828 (setq val "SUPER::"))
6829 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
6830 (setq val "<NAME>")))
6831 (setq regexp (concat "^"
6832 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
6834 "\\([ \t([/]\\|$\\)"))
6836 ;; get the buffer with the documentation text
6837 (cperl-switch-to-doc-buffer)
6839 ;; lookup in the doc
6840 (goto-char (point-min))
6841 (let ((case-fold-search nil))
6843 (if (re-search-forward regexp (point-max) t)
6845 (beginning-of-line 1)
6846 (let ((lnstart (point)))
6848 (message "%s" (buffer-substring lnstart (point)))))
6849 (if cperl-message-on-help-error
6850 (message "No definition for %s" val)))))))
6852 (defvar cperl-short-docs "Ignore my value"
6853 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
6854 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
6855 ! ... Logical negation.
6856 ... != ... Numeric inequality.
6857 ... !~ ... Search pattern, substitution, or translation (negated).
6858 $! In numeric context: errno. In a string context: error string.
6859 $\" The separator which joins elements of arrays interpolated in strings.
6860 $# The output format for printed numbers. Initial value is %.15g or close.
6861 $$ Process number of this script. Changes in the fork()ed child process.
6862 $% The current page number of the currently selected output channel.
6864 The following variables are always local to the current block:
6866 $1 Match of the 1st set of parentheses in the last match (auto-local).
6867 $2 Match of the 2nd set of parentheses in the last match (auto-local).
6868 $3 Match of the 3rd set of parentheses in the last match (auto-local).
6869 $4 Match of the 4th set of parentheses in the last match (auto-local).
6870 $5 Match of the 5th set of parentheses in the last match (auto-local).
6871 $6 Match of the 6th set of parentheses in the last match (auto-local).
6872 $7 Match of the 7th set of parentheses in the last match (auto-local).
6873 $8 Match of the 8th set of parentheses in the last match (auto-local).
6874 $9 Match of the 9th set of parentheses in the last match (auto-local).
6875 $& The string matched by the last pattern match (auto-local).
6876 $' The string after what was matched by the last match (auto-local).
6877 $` The string before what was matched by the last match (auto-local).
6879 $( The real gid of this process.
6880 $) The effective gid of this process.
6881 $* Deprecated: Set to 1 to do multiline matching within a string.
6882 $+ The last bracket matched by the last search pattern.
6883 $, The output field separator for the print operator.
6884 $- The number of lines left on the page.
6885 $. The current input line number of the last filehandle that was read.
6886 $/ The input record separator, newline by default.
6887 $0 Name of the file containing the perl script being executed. May be set.
6888 $: String may be broken after these characters to fill ^-lines in a format.
6889 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
6890 $< The real uid of this process.
6891 $= The page length of the current output channel. Default is 60 lines.
6892 $> The effective uid of this process.
6893 $? The status returned by the last ``, pipe close or `system'.
6894 $@ The perl error message from the last eval or do @var{EXPR} command.
6895 $ARGV The name of the current file used with <> .
6896 $[ Deprecated: The index of the first element/char in an array/string.
6897 $\\ The output record separator for the print operator.
6898 $] The perl version string as displayed with perl -v.
6899 $^ The name of the current top-of-page format.
6900 $^A The current value of the write() accumulator for format() lines.
6901 $^D The value of the perl debug (-D) flags.
6902 $^E Information about the last system error other than that provided by $!.
6903 $^F The highest system file descriptor, ordinarily 2.
6904 $^H The current set of syntax checks enabled by `use strict'.
6905 $^I The value of the in-place edit extension (perl -i option).
6906 $^L What formats output to perform a formfeed. Default is \f.
6907 $^M A buffer for emergency memory allocation when running out of memory.
6908 $^O The operating system name under which this copy of Perl was built.
6909 $^P Internal debugging flag.
6910 $^T The time the script was started. Used by -A/-M/-C file tests.
6911 $^W True if warnings are requested (perl -w flag).
6912 $^X The name under which perl was invoked (argv[0] in C-speech).
6913 $_ The default input and pattern-searching space.
6914 $| Auto-flush after write/print on current output channel? Default 0.
6915 $~ The name of the current report format.
6916 ... % ... Modulo division.
6917 ... %= ... Modulo division assignment.
6918 %ENV Contains the current environment.
6919 %INC List of files that have been require-d or do-ne.
6920 %SIG Used to set signal handlers for various signals.
6921 ... & ... Bitwise and.
6922 ... && ... Logical and.
6923 ... &&= ... Logical and assignment.
6924 ... &= ... Bitwise and assignment.
6925 ... * ... Multiplication.
6926 ... ** ... Exponentiation.
6927 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
6928 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
6929 ... + ... Addition. +EXPR Makes EXPR into scalar context.
6930 ++ Auto-increment (magical on strings). ++EXPR EXPR++
6931 ... += ... Addition assignment.
6933 ... - ... Subtraction.
6934 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
6935 ... -= ... Subtraction assignment.
6936 -A Access time in days since script started.
6937 -B File is a non-text (binary) file.
6938 -C Inode change time in days since script started.
6939 -M Age in days since script started.
6940 -O File is owned by real uid.
6941 -R File is readable by real uid.
6942 -S File is a socket .
6943 -T File is a text file.
6944 -W File is writable by real uid.
6945 -X File is executable by real uid.
6946 -b File is a block special file.
6947 -c File is a character special file.
6948 -d File is a directory.
6950 -f File is a plain file.
6951 -g File has setgid bit set.
6952 -k File has sticky bit set.
6953 -l File is a symbolic link.
6954 -o File is owned by effective uid.
6955 -p File is a named pipe (FIFO).
6956 -r File is readable by effective uid.
6957 -s File has non-zero size.
6958 -t Tests if filehandle (STDIN by default) is opened to a tty.
6959 -u File has setuid bit set.
6960 -w File is writable by effective uid.
6961 -x File is executable by effective uid.
6962 -z File has zero size.
6963 . Concatenate strings.
6964 .. Alternation, also range operator.
6965 .= Concatenate assignment strings
6966 ... / ... Division. /PATTERN/ioxsmg Pattern match
6967 ... /= ... Division assignment.
6968 /PATTERN/ioxsmg Pattern match.
6969 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
6970 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
6971 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
6972 <> Reads line from union of files in @ARGV (= command line) and STDIN.
6973 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
6974 ... <= ... Numeric less than or equal to.
6975 ... <=> ... Numeric compare.
6976 ... = ... Assignment.
6977 ... == ... Numeric equality.
6978 ... =~ ... Search pattern, substitution, or translation
6979 ... > ... Numeric greater than.
6980 ... >= ... Numeric greater than or equal to.
6981 ... >> ... Bitwise shift right.
6982 ... >>= ... Bitwise shift right assignment.
6983 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
6984 ?PATTERN? One-time pattern match.
6985 @ARGV Command line arguments (not including the command name - see $0).
6986 @INC List of places to look for perl scripts during do/include/use.
6987 @_ Parameter array for subroutines. Also used by split unless in array context.
6988 \\ Creates reference to what follows, like \$var, or quotes non-\w in strings.
6989 \\0 Octal char, e.g. \\033.
6990 \\E Case modification terminator. See \\Q, \\L, and \\U.
6991 \\L Lowercase until \\E . See also \l, lc.
6992 \\U Upcase until \\E . See also \u, uc.
6993 \\Q Quote metacharacters until \\E . See also quotemeta.
6994 \\a Alarm character (octal 007).
6995 \\b Backspace character (octal 010).
6996 \\c Control character, e.g. \\c[ .
6997 \\e Escape character (octal 033).
6998 \\f Formfeed character (octal 014).
6999 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
7000 \\n Newline character (octal 012 on most systems).
7001 \\r Return character (octal 015 on most systems).
7002 \\t Tab character (octal 011).
7003 \\u Upcase the next character. See also \\U and \\l, ucfirst.
7004 \\x Hex character, e.g. \\x1b.
7005 ... ^ ... Bitwise exclusive or.
7006 __END__ Ends program source.
7007 __DATA__ Ends program source.
7008 __FILE__ Current (source) filename.
7009 __LINE__ Current line in current source.
7010 __PACKAGE__ Current package.
7011 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
7012 ARGVOUT Output filehandle with -i flag.
7013 BEGIN { ... } Immediately executed (during compilation) piece of code.
7014 END { ... } Pseudo-subroutine executed after the script finishes.
7015 DATA Input filehandle for what follows after __END__ or __DATA__.
7016 accept(NEWSOCKET,GENERICSOCKET)
7029 ... cmp ... String compare.
7030 connect(SOCKET,NAME)
7031 continue of { block } continue { block }. Is executed after `next' or at end.
7033 crypt(PLAINTEXT,SALT)
7035 dbmopen(%HASH,DBNAME,MODE)
7039 do { ... }|SUBR while|until EXPR executes at least once
7040 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
7050 ... eq ... String equality.
7051 eval(EXPR) or eval { BLOCK }
7055 fcntl(FILEHANDLE,FUNCTION,SCALAR)
7057 flock(FILEHANDLE,OPERATION)
7058 for (EXPR;EXPR;EXPR) { ... }
7059 foreach [VAR] (@ARRAY) { ... }
7061 ... ge ... String greater than or equal.
7066 gethostbyaddr(ADDR,ADDRTYPE)
7070 getnetbyaddr(ADDR,ADDRTYPE)
7076 getpriority(WHICH,WHO)
7077 getprotobyname(NAME)
7078 getprotobynumber(NUMBER)
7083 getservbyname(NAME,PROTO)
7084 getservbyport(PORT,PROTO)
7087 getsockopt(SOCKET,LEVEL,OPTNAME)
7090 ... gt ... String greater than.
7092 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
7093 index(STR,SUBSTR[,OFFSET])
7095 ioctl(FILEHANDLE,FUNCTION,SCALAR)
7100 ... le ... String less than or equal.
7102 link(OLDFILE,NEWFILE)
7103 listen(SOCKET,QUEUESIZE)
7107 lstat(EXPR|FILEHANDLE|VAR)
7108 ... lt ... String less than.
7110 mkdir(FILENAME,MODE)
7113 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
7114 msgsnd(ID,MSG,FLAGS)
7115 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
7116 ... ne ... String inequality.
7119 open(FILEHANDLE[,EXPR])
7120 opendir(DIRHANDLE,EXPR)
7121 ord(EXPR) ASCII value of the first char of the string.
7123 package NAME Introduces package context.
7124 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
7126 print [FILEHANDLE] [(LIST)]
7127 printf [FILEHANDLE] (FORMAT,LIST)
7129 q/STRING/ Synonym for 'STRING'
7130 qq/STRING/ Synonym for \"STRING\"
7131 qx/STRING/ Synonym for `STRING`
7133 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7136 recv(SOCKET,SCALAR,LEN,FLAGS)
7138 rename(OLDNAME,NEWNAME)
7139 require [FILENAME | PERL_VERSION]
7143 rewinddir(DIRHANDLE)
7144 rindex(STR,SUBSTR[,OFFSET])
7146 s/PATTERN/REPLACEMENT/gieoxsm
7148 seek(FILEHANDLE,POSITION,WHENCE)
7149 seekdir(DIRHANDLE,POS)
7150 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
7151 semctl(ID,SEMNUM,CMD,ARG)
7152 semget(KEY,NSEMS,SIZE,FLAGS)
7154 send(SOCKET,MSG,FLAGS[,TO])
7156 sethostent(STAYOPEN)
7159 setpriority(WHICH,WHO,PRIORITY)
7160 setprotoent(STAYOPEN)
7162 setservent(STAYOPEN)
7163 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
7166 shmget(KEY,SIZE,FLAGS)
7167 shmread(ID,VAR,POS,SIZE)
7168 shmwrite(ID,STRING,POS,SIZE)
7169 shutdown(SOCKET,HOW)
7172 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
7173 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
7174 sort [SUBROUTINE] (LIST)
7175 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
7176 split[(/PATTERN/[,EXPR[,LIMIT]])]
7177 sprintf(FORMAT,LIST)
7180 stat(EXPR|FILEHANDLE|VAR)
7182 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
7183 substr(EXPR,OFFSET[,LEN])
7184 symlink(OLDFILE,NEWFILE)
7186 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7188 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
7193 tr/SEARCHLIST/REPLACEMENTLIST/cds
7194 truncate(FILE|EXPR,LENGTH)
7197 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
7199 unpack(TEMPLATE,EXPR)
7201 until (EXPR) { ... } EXPR until EXPR
7204 vec(EXPR,OFFSET,BITS)
7207 wantarray Returns true if the sub/eval is called in list context.
7209 while (EXPR) { ... } EXPR while EXPR
7210 write[(EXPR|FILEHANDLE)]
7211 ... x ... Repeat string or array.
7212 x= ... Repetition assignment.
7213 y/SEARCHLIST/REPLACEMENTLIST/
7214 ... | ... Bitwise or.
7215 ... || ... Logical or.
7216 ~ ... Unary bitwise complement.
7217 #! OS interpreter indicator. If contains `perl', used for options, and -x.
7218 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
7219 CORE:: Prefix to access builtin function if imported sub obscures it.
7220 SUPER:: Prefix to lookup for a method in @ISA classes.
7221 DESTROY Shorthand for `sub DESTROY {...}'.
7222 ... EQ ... Obsolete synonym of `eq'.
7223 ... GE ... Obsolete synonym of `ge'.
7224 ... GT ... Obsolete synonym of `gt'.
7225 ... LE ... Obsolete synonym of `le'.
7226 ... LT ... Obsolete synonym of `lt'.
7227 ... NE ... Obsolete synonym of `ne'.
7228 abs [ EXPR ] absolute value
7229 ... and ... Low-precedence synonym for &&.
7230 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
7231 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
7232 chr Converts a number to char with the same ordinal.
7233 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
7234 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
7235 exists $HASH{KEY} True if the key exists.
7236 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
7237 formline PICTURE, LIST Backdoor into \"format\" processing.
7238 glob EXPR Synonym of <EXPR>.
7239 lc [ EXPR ] Returns lowercased EXPR.
7240 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
7241 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
7242 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
7243 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
7244 not ... Low-precedence synonym for ! - negation.
7245 ... or ... Low-precedence synonym for ||.
7246 pos STRING Set/Get end-position of the last match over this string, see \\G.
7247 quotemeta [ EXPR ] Quote regexp metacharacters.
7248 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
7249 readline FH Synonym of <FH>.
7250 readpipe CMD Synonym of `CMD`.
7251 ref [ EXPR ] Type of EXPR when dereferenced.
7252 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
7253 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
7254 tied Returns internal object for a tied data.
7255 uc [ EXPR ] Returns upcased EXPR.
7256 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
7257 untie VAR Unlink an object from a simple Perl variable.
7258 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
7259 ... xor ... Low-precedence synonym for exclusive or.
7260 prototype \&SUB Returns prototype of the function given a reference.
7261 =head1 Top-level heading.
7262 =head2 Second-level heading.
7263 =head3 Third-level heading (is there such?).
7264 =over [ NUMBER ] Start list.
7265 =item [ TITLE ] Start new item in the list.
7267 =cut Switch from POD to Perl.
7268 =pod Switch from Perl to POD.
7271 (defun cperl-switch-to-doc-buffer ()
7272 "Go to the perl documentation buffer and insert the documentation."
7274 (let ((buf (get-buffer-create cperl-doc-buffer)))
7276 (switch-to-buffer-other-window buf)
7278 (if (= (buffer-size) 0)
7280 (insert (documentation-property 'cperl-short-docs
7281 'variable-documentation))
7282 (setq buffer-read-only t)))))
7284 (defun cperl-beautify-regexp-piece (b e embed)
7285 ;; b is before the starting delimiter, e before the ending
7286 ;; e should be a marker, may be changed, but remains "correct".
7287 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code)
7291 (cond ((looking-at "(\\?\\\\#") ; badly commented (?#)
7295 ((looking-at "(\\?[^a-zA-Z]")
7297 ((looking-at "(\\?") ; (?i)
7301 (setq c (if embed (current-indentation) (1- (current-column)))
7302 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
7303 (or (looking-at "[ \t]*[\n#]")
7308 (if (re-search-forward "[^ \t]" e t)
7312 (indent-to-column c)
7313 (set-marker e (point))))
7316 (while (< (point) (marker-position e))
7320 (skip-chars-forward " \t")
7321 (delete-region s (point))
7322 (indent-to-column c1)
7326 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
7327 "\\|" ; Embedded variable
7328 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
7331 "\\|" ; simple-code simple-code*?
7332 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
7336 "\\((\\(\\?\\)?\\)" ; 7 8
7340 (goto-char (match-end 0))
7342 (cond ((match-beginning 1) ; Alphanum word + junk
7344 ((or (match-beginning 3) ; $ab[12]
7345 (and (match-beginning 5) ; X* X+ X{2,3}
7346 (eq (preceding-char) ?\{)))
7349 ((match-beginning 6) ; []
7351 (if (looking-at "\\^?\\]")
7352 (goto-char (match-end 0)))
7353 (or (re-search-forward "\\]\\([*+{?]\\)?" e t)
7355 (goto-char (1- tmp))
7356 (error "[]-group not terminated")))
7357 (if (not (eq (preceding-char) ?\{)) nil
7360 ((match-beginning 7) ; ()
7361 (goto-char (match-beginning 0))
7362 (or (eq (current-column) c1)
7365 (indent-to-column c1)))
7368 ;; (or (forward-sexp 1)
7371 ;; (error "()-group not terminated")))
7372 (set-marker m (1- (point)))
7373 (set-marker m1 (point))
7375 ((not (match-beginning 8))
7376 (cperl-beautify-regexp-piece tmp m t))
7377 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
7379 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
7380 (goto-char (+ 2 tmp))
7382 (cperl-beautify-regexp-piece (point) m t))
7383 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
7384 (goto-char (+ 3 tmp))
7385 (cperl-beautify-regexp-piece (point) m t))
7387 (cperl-beautify-regexp-piece tmp m t)))
7389 (cond ((looking-at "[*+?]\\??")
7390 (goto-char (match-end 0)))
7391 ((eq (following-char) ?\{)
7393 (if (eq (following-char) ?\?)
7395 (skip-chars-forward " \t")
7397 (if (looking-at "[#\n]")
7399 (or (eolp) (indent-for-comment))
7400 (beginning-of-line 2))
7404 ((match-beginning 9) ; |
7408 (if (re-search-forward "[^ \t]" tmp t)
7413 (delete-region (point) tmp))
7414 (indent-to-column c)
7416 (skip-chars-forward " \t")
7418 (if (looking-at "[#\n]")
7419 (beginning-of-line 2)
7423 (or (looking-at "[ \t\n]")
7426 (skip-chars-forward " \t"))
7427 (or (looking-at "[#\n]")
7428 (error "unknown code \"%s\" in a regexp" (buffer-substring (point)
7430 (and inline (end-of-line 2)))
7431 ;; Special-case the last line of group
7432 (if (and (>= (point) (marker-position e))
7433 (/= (current-indentation) c))
7437 (skip-chars-forward " \t")
7438 (delete-region s (point))
7439 (indent-to-column c)))
7442 (defun cperl-make-regexp-x ()
7443 ;; Returns position of the start
7445 (or cperl-use-syntax-table-text-property
7446 (error "I need to have a regexp marked!"))
7448 (if (looking-at "\\s|")
7450 (if (looking-at "\\([smy]\\|qr\\)\\s|")
7452 (re-search-backward "\\s|"))) ; Assume it is scanned already.
7454 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
7455 (sub-p (eq (preceding-char) ?s)) s)
7457 (set-marker e (1- (point)))
7458 (setq delim (preceding-char))
7459 (if (and sub-p (eq delim (char-after (- (point) 2))))
7460 (error "Possible s/blah// - do not know how to deal with"))
7461 (if sub-p (forward-sexp 1))
7462 (if (looking-at "\\sw*x")
7465 ;; Protect fragile " ", "#"
7468 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
7474 (defun cperl-beautify-regexp ()
7475 "do it. (Experimental, may change semantics, recheck the result.)
7476 We suppose that the regexp is scanned already."
7478 (goto-char (cperl-make-regexp-x))
7479 (let ((b (point)) (e (make-marker)))
7481 (set-marker e (1- (point)))
7482 (cperl-beautify-regexp-piece b e nil)))
7484 (defun cperl-regext-to-level-start ()
7485 "Goto start of an enclosing group in regexp.
7486 We suppose that the regexp is scanned already."
7488 (let ((limit (cperl-make-regexp-x)) done)
7490 (or (eq (following-char) ?\()
7491 (search-backward "(" (1+ limit) t)
7492 (error "Cannot find `(' which starts a group"))
7495 (skip-chars-backward "\\")
7496 (looking-at "\\(\\\\\\\\\\)*(")))
7497 (or done (forward-char -1)))))
7499 (defun cperl-contract-level ()
7500 "Find an enclosing group in regexp and contract it.
7501 \(Experimental, may change semantics, recheck the result.)
7502 We suppose that the regexp is scanned already."
7504 (cperl-regext-to-level-start)
7505 (let ((b (point)) (e (make-marker)) s c)
7507 (set-marker e (1- (point)))
7509 (while (re-search-forward "\\(#\\)\\|\n" e t)
7511 ((match-beginning 1) ; #-comment
7512 (or c (setq c (current-indentation)))
7513 (beginning-of-line 2) ; Skip
7515 (skip-chars-forward " \t")
7516 (delete-region s (point))
7517 (indent-to-column c))
7520 (just-one-space))))))
7522 (defun cperl-contract-levels ()
7523 "Find an enclosing group in regexp and contract all the kids.
7524 \(Experimental, may change semantics, recheck the result.)
7525 We suppose that the regexp is scanned already."
7528 (cperl-regext-to-level-start)
7529 (error ; We are outside outermost group
7530 (goto-char (cperl-make-regexp-x))))
7531 (let ((b (point)) (e (make-marker)) s c)
7533 (set-marker e (1- (point)))
7535 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
7537 ((match-beginning 1) ; Skip
7540 (cperl-contract-level))))))
7542 (defun cperl-beautify-level ()
7543 "Find an enclosing group in regexp and beautify it.
7544 \(Experimental, may change semantics, recheck the result.)
7545 We suppose that the regexp is scanned already."
7547 (cperl-regext-to-level-start)
7548 (let ((b (point)) (e (make-marker)))
7550 (set-marker e (1- (point)))
7551 (cperl-beautify-regexp-piece b e nil)))
7553 (defun cperl-invert-if-unless ()
7554 "Changes `if (A) {B}' into `B if A;' if possible."
7556 (or (looking-at "\\<")
7558 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\)\\>")
7559 (let ((pos1 (point))
7560 pos2 pos3 pos4 pos5 s1 s2 state p pos45
7561 (s0 (buffer-substring (match-beginning 0) (match-end 0))))
7566 (if (eq (following-char) ?\( )
7573 ;; XXXX In fact may be `A if (B); {C}' ...
7574 (if (and (eq (following-char) ?\{ )
7576 (cperl-backward-to-noncomment pos3)
7577 (eq (preceding-char) ?\) )))
7578 (if (condition-case nil
7583 (looking-at "\\<els\\(e\\|if\\)\\>"))
7586 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" s0)
7587 (goto-char (1- pos5))
7588 (cperl-backward-to-noncomment pos4)
7589 (if (eq (preceding-char) ?\;)
7591 (setq pos45 (point))
7593 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" pos45 t)
7594 (setq p (match-beginning 0)
7595 s1 (buffer-substring p (match-end 0))
7596 state (parse-partial-sexp pos4 p))
7600 (error "`%s' inside `%s' BLOCK" s1 s0))
7601 (goto-char (match-end 0)))
7603 (goto-char (1+ pos4))
7604 (skip-chars-forward " \t\n")
7605 (setq s2 (buffer-substring (point) pos45))
7607 (or (looking-at ";?[ \t\n]*}")
7609 (skip-chars-forward "; \t\n")
7610 (setq s2 (concat s2 "\n" (buffer-substring (point) (1- pos5))))))
7613 (goto-char (1- pos3))
7614 (cperl-backward-to-noncomment pos2)
7615 (or (looking-at "[ \t\n]*)")
7616 (goto-char (1- pos3)))
7618 (goto-char (1+ pos2))
7619 (skip-chars-forward " \t\n")
7620 (setq s1 (buffer-substring (point) p))
7621 (delete-region pos4 pos5)
7622 (delete-region pos2 pos3)
7630 (delete-horizontal-space)
7633 (cperl-indent-line))
7634 (error "`%s' (EXPR) not with an {BLOCK}" s0)))
7635 (error "`%s' not with an (EXPR)" s0)))
7636 (error "Not at `if', `unless', `while', or `unless'")))
7638 ;;; By Anthony Foiani <afoiani@uswest.com>
7639 ;;; Getting help on modules in C-h f ?
7640 ;;; Need to teach it how to lookup functions
7641 (defvar Man-filter-list)
7642 (defun cperl-perldoc (word)
7643 "Run a 'perldoc' on WORD."
7645 (list (let* ((default-entry (cperl-word-at-point))
7647 (format "perldoc entry%s: "
7648 (if (string= default-entry "")
7650 (format " (default %s)" default-entry))))))
7651 (if (string= input "")
7652 (if (string= default-entry "")
7653 (error "No perldoc args given")
7656 (let* ((is-func (and
7657 (string-match "^[a-z]+$" word)
7658 (string-match (concat "^" word "\\>")
7659 (documentation-property
7661 'variable-documentation))))
7662 (manual-program (if is-func "perldoc -f" "perldoc")))
7664 (Man-getpage-in-background word)))
7666 (defun cperl-perldoc-at-point ()
7667 "Run a 'perldoc' on WORD."
7669 (cperl-perldoc (cperl-word-at-point)))
7671 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
7672 (defvar pod2man-program "pod2man")
7674 (defun cperl-pod-to-manpage ()
7675 "Create a virtual manpage in emacs from the Perl Online Documentation"
7678 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
7679 (bufname (concat "Man " buffer-file-name))
7680 (buffer (generate-new-buffer bufname)))
7683 (let ((process-environment (copy-sequence process-environment)))
7684 ;; Prevent any attempt to use display terminal fanciness.
7685 (setenv "TERM" "dumb")
7686 (set-process-sentinel
7687 (start-process pod2man-program buffer "sh" "-c"
7688 (format (cperl-pod2man-build-command) pod2man-args))
7689 'Man-bgproc-sentinel)))))
7691 (defun cperl-pod2man-build-command ()
7692 "Builds the entire background manpage and cleaning command."
7693 (let ((command (concat pod2man-program " %s 2>/dev/null"))
7694 (flist Man-filter-list))
7695 (while (and flist (car flist))
7696 (let ((pcom (car (car flist)))
7697 (pargs (cdr (car flist))))
7699 (concat command " | " pcom " "
7700 (mapconcat '(lambda (phrase)
7701 (if (not (stringp phrase))
7702 (error "Malformed Man-filter-list"))
7705 (setq flist (cdr flist))))
7708 (defun cperl-lazy-install ()) ; Avoid a warning
7710 (if (fboundp 'run-with-idle-timer)
7712 (defvar cperl-help-shown nil
7713 "Non-nil means that the help was already shown now.")
7715 (defvar cperl-lazy-installed nil
7716 "Non-nil means that the lazy-help handlers are installed now.")
7718 (defun cperl-lazy-install ()
7720 (make-variable-buffer-local 'cperl-help-shown)
7721 (if (and (cperl-val 'cperl-lazy-help-time)
7722 (not cperl-lazy-installed))
7724 (add-hook 'post-command-hook 'cperl-lazy-hook)
7725 (run-with-idle-timer
7726 (cperl-val 'cperl-lazy-help-time 1000000 5)
7728 'cperl-get-help-defer)
7729 (setq cperl-lazy-installed t))))
7731 (defun cperl-lazy-unstall ()
7733 (remove-hook 'post-command-hook 'cperl-lazy-hook)
7734 (cancel-function-timers 'cperl-get-help-defer)
7735 (setq cperl-lazy-installed nil))
7737 (defun cperl-lazy-hook ()
7738 (setq cperl-help-shown nil))
7740 (defun cperl-get-help-defer ()
7741 (if (not (eq major-mode 'perl-mode)) nil
7742 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
7744 (setq cperl-help-shown t))))
7745 (cperl-lazy-install)))
7748 ;;; Plug for wrong font-lock:
7750 (defun cperl-font-lock-unfontify-region-function (beg end)
7751 (let* ((modified (buffer-modified-p)) (buffer-undo-list t)
7752 (inhibit-read-only t) (inhibit-point-motion-hooks t)
7753 before-change-functions after-change-functions
7754 deactivate-mark buffer-file-name buffer-file-truename)
7755 (remove-text-properties beg end '(face nil))
7756 (when (and (not modified) (buffer-modified-p))
7757 (set-buffer-modified-p nil))))
7759 (defvar cperl-d-l nil)
7760 (defun cperl-fontify-syntaxically (end)
7761 ;; Some vars for debugging only
7762 (let (start (dbg (point)) (iend end)
7763 (istate (car cperl-syntax-state)))
7764 (and cperl-syntaxify-unwind
7765 (setq end (cperl-unwind-to-safe t end)))
7766 (setq start (point))
7767 (or cperl-syntax-done-to
7768 (setq cperl-syntax-done-to (point-min)))
7769 (if (or (not (boundp 'font-lock-hot-pass))
7770 (eval 'font-lock-hot-pass)
7771 t) ; Not debugged otherwise
7772 ;; Need to forget what is after `start'
7773 (setq start (min cperl-syntax-done-to start))
7774 ;; Fontification without a change
7775 (setq start (max cperl-syntax-done-to start)))
7777 (setq cperl-syntax-done-to start) ; In case what follows fails
7778 (cperl-find-pods-heres start end t nil t))
7779 ;;(setq cperl-d-l (cons (format "Syntaxifying %s..%s from %s to %s\n"
7780 ;; dbg end start cperl-syntax-done-to)
7782 ;;(let ((standard-output (get-buffer "*Messages*")))
7783 ;;(princ (format "Syntaxifying %s..%s from %s to %s\n"
7784 ;; dbg end start cperl-syntax-done-to)))
7785 (if (eq cperl-syntaxify-by-font-lock 'message)
7786 (message "Syntaxified %s..%s from %s to %s(%s), state %s-->%s"
7788 start end cperl-syntax-done-to
7789 istate (car cperl-syntax-state))) ; For debugging
7790 nil)) ; Do not iterate
7792 (defun cperl-fontify-update (end)
7793 (let ((pos (point)) prop posend)
7795 (setq prop (get-text-property pos 'cperl-postpone))
7796 (setq posend (next-single-property-change pos 'cperl-postpone nil end))
7797 (and prop (put-text-property pos posend (car prop) (cdr prop)))
7799 nil) ; Do not iterate
7801 (defun cperl-update-syntaxification (from to)
7802 (if (and cperl-use-syntax-table-text-property
7803 cperl-syntaxify-by-font-lock
7804 (or (null cperl-syntax-done-to)
7805 (< cperl-syntax-done-to to)))
7809 (cperl-fontify-syntaxically to)))))
7811 (defvar cperl-version
7812 (let ((v "$Revision: 4.19 $"))
7813 (string-match ":\\s *\\([0-9.]+\\)" v)
7814 (substring v (match-beginning 1) (match-end 1)))
7815 "Version of IZ-supported CPerl package this file is based on.")
7817 (provide 'cperl-mode)
7819 ;;; cperl-mode.el ends here