0
|
1 ;;; This code started from the following message of long time ago (IZ):
|
|
2
|
193
|
3 ;;;; From: olson@mcs.anl.gov (Bob Olson)
|
|
4 ;;;; Newsgroups: comp.lang.perl
|
|
5 ;;;; Subject: cperl-mode: Another perl mode for Gnuemacs
|
|
6 ;;;; Date: 14 Aug 91 15:20:01 GMT
|
|
7
|
|
8 ;; Perl code editing commands for XEmacs
|
4
|
9 ;; Copyright (C) 1985-1996 Bob Olson, Ilya Zakharevich
|
193
|
10 ;; Copyright (C) 1997 granted to FSF for changes made by
|
|
11 ;; Karl M. Hegbloom <karlheg@inetarena.com>
|
|
12
|
|
13 ;; This file is part of XEmacs. It may be distributed either under the
|
|
14 ;; same terms as XEmacs, or under the same terms as Perl. You should
|
|
15 ;; have received a copy of Perl Artistic license along with the Perl
|
|
16 ;; distribution.
|
|
17
|
|
18 ;; XEmacs is free software; you can redistribute it and/or modify
|
0
|
19 ;; it under the terms of the GNU General Public License as published by
|
|
20 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
21 ;; any later version.
|
|
22
|
|
23 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26 ;; GNU General Public License for more details.
|
|
27
|
|
28 ;; You should have received a copy of the GNU General Public License
|
4
|
29 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
31 ;; Boston, MA 02111-1307, USA.
|
|
32
|
0
|
33 ;;; Corrections made by Ilya Zakharevich ilya@math.mps.ohio-state.edu
|
|
34 ;;; XEmacs changes by Peter Arius arius@informatik.uni-erlangen.de
|
167
|
35 ;;; XEmacs 'delete key behavior handling added for XEmacs 20.x by
|
|
36 ;;; Gary D. Foster <Gary.Foster@corp.sun.com>
|
203
|
37 ;;; Karl M. Hegbloom <karlheg@inetarena.com>
|
167
|
38
|
193
|
39 ;; Original Vendor Version Number: (mostly based on...)
|
207
|
40 ;; $Id: cperl-mode.el,v 1.15 1997/10/31 14:52:54 steve Exp $
|
193
|
41
|
|
42 ;; Increment the final digit once per XEmacs-only revision, the other
|
|
43 ;; for merges. (sound ok?)
|
|
44 ;;; XEmacs Version Number: 1.35-1
|
|
45
|
|
46 ;; This mode should autoload when you edit a perl file under XEmacs.
|
0
|
47
|
110
|
48 ;;; DO NOT FORGET to read micro-docs. (available from `Perl' menu). <<<<<<
|
|
49 ;;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
|
193
|
50 ;;; `cperl-non-problems', `cperl-praise'. <<<<<<
|
|
51
|
|
52 ;;; The mode information (on C-h m) provides some customization help.
|
0
|
53 ;;; If you use font-lock feature of this mode, it is advisable to use
|
4
|
54 ;;; either lazy-lock-mode or fast-lock-mode (available on ELisp
|
0
|
55 ;;; archive in files lazy-lock.el and fast-lock.el). I prefer lazy-lock.
|
|
56
|
|
57 ;;; Faces used now: three faces for first-class and second-class keywords
|
|
58 ;;; and control flow words, one for each: comments, string, labels,
|
|
59 ;;; functions definitions and packages, arrays, hashes, and variable
|
|
60 ;;; definitions. If you do not see all these faces, your font-lock does
|
193
|
61 ;;; not define them, so you need to define them manually.
|
0
|
62
|
4
|
63 ;;; If you have a grayscale monitor, and do not have the variable
|
0
|
64 ;;; font-lock-display-type bound to 'grayscale, insert
|
|
65
|
|
66 ;;; (setq font-lock-display-type 'grayscale)
|
|
67
|
193
|
68 ;;; into your .xemacs/init.el file.
|
|
69
|
|
70 ;;;; ? what about this `imenu' stuff? Is it worth it?
|
0
|
71
|
|
72 ;;;; This mode supports font-lock, imenu and mode-compile. In the
|
|
73 ;;;; hairy version font-lock is on, but you should activate imenu
|
|
74 ;;;; yourself (note that mode-compile is not standard yet). Well, you
|
|
75 ;;;; can use imenu from keyboard anyway (M-x imenu), but it is better
|
|
76 ;;;; to bind it like that:
|
|
77
|
|
78 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
|
|
79
|
|
80 ;;; In fact the version of font-lock that this version supports can be
|
|
81 ;;; much newer than the version you actually have. This means that a
|
|
82 ;;; lot of faces can be set up, but are not visible on your screen
|
|
83 ;;; since the coloring rules for this faces are not defined.
|
|
84
|
|
85 ;;; Updates: ========================================
|
|
86
|
|
87 ;;; Made less hairy by default: parentheses not electric,
|
|
88 ;;; linefeed not magic. Bug with abbrev-mode corrected.
|
|
89
|
|
90 ;;;; After 1.4:
|
|
91 ;;; Better indentation:
|
|
92 ;;; subs inside braces should work now,
|
|
93 ;;; Toplevel braces obey customization.
|
|
94 ;;; indent-for-comment knows about bad cases, cperl-indent-for-comment
|
|
95 ;;; moves cursor to a correct place.
|
|
96 ;;; cperl-indent-exp written from the scratch! Slow... (quadratic!) :-(
|
|
97 ;;; (50 secs on DB::DB (sub of 430 lines), 486/66)
|
|
98 ;;; Minor documentation fixes.
|
|
99 ;;; Imenu understands packages as prefixes (including nested).
|
|
100 ;;; Hairy options can be switched off one-by-one by setting to null.
|
|
101 ;;; Names of functions and variables changed to conform to `cperl-' style.
|
|
102
|
|
103 ;;;; After 1.5:
|
|
104 ;;; Some bugs with indentation of labels (and embedded subs) corrected.
|
|
105 ;;; `cperl-indent-region' done (slow :-()).
|
|
106 ;;; `cperl-fill-paragraph' done.
|
|
107 ;;; Better package support for `imenu'.
|
|
108 ;;; Progress indicator for indentation (with `imenu' loaded).
|
|
109 ;;; `Cperl-set' was busted, now setting the individual hairy option
|
|
110 ;;; should be better.
|
|
111
|
|
112 ;;;; After 1.6:
|
|
113 ;;; `cperl-set-style' done.
|
|
114 ;;; `cperl-check-syntax' done.
|
|
115 ;;; Menu done.
|
|
116 ;;; New config variables `cperl-close-paren-offset' and `cperl-comment-column'.
|
|
117 ;;; Bugs with `cperl-auto-newline' corrected.
|
|
118 ;;; `cperl-electric-lbrace' can work with `cperl-auto-newline' in situation
|
|
119 ;;; like $hash{.
|
|
120
|
|
121 ;;;; 1.7 XEmacs (arius@informatik.uni-erlangen.de):
|
|
122 ;;; - use `next-command-event', if `next-command-events' does not exist
|
|
123 ;;; - use `find-face' as def. of `is-face'
|
|
124 ;;; - corrected def. of `x-color-defined-p'
|
|
125 ;;; - added const defs for font-lock-comment-face,
|
|
126 ;;; font-lock-keyword-face and font-lock-function-name-face
|
|
127 ;;; - added def. of font-lock-variable-name-face
|
|
128 ;;; - added (require 'easymenu) inside an `eval-when-compile'
|
|
129 ;;; - replaced 4-argument `substitute-key-definition' with ordinary
|
|
130 ;;; `define-key's
|
|
131 ;;; - replaced `mark-active' in menu definition by `cperl-use-region-p'.
|
|
132 ;;; Todo (at least):
|
|
133 ;;; - use emacs-vers.el (http://www.cs.utah.edu/~eeide/emacs/emacs-vers.el.gz)
|
|
134 ;;; for portable code?
|
|
135 ;;; - should `cperl-mode' do a
|
|
136 ;;; (if (featurep 'easymenu) (easy-menu-add cperl-menu))
|
|
137 ;;; or should this be left to the user's `cperl-mode-hook'?
|
|
138
|
|
139 ;;; Some bugs introduced by the above fix corrected (IZ ;-).
|
|
140 ;;; Some bugs under XEmacs introduced by the correction corrected.
|
|
141
|
|
142 ;;; Some more can remain since there are two many different variants.
|
|
143 ;;; Please feedback!
|
|
144
|
|
145 ;;; We do not support fontification of arrays and hashes under
|
|
146 ;;; obsolete font-lock any more. Upgrade.
|
|
147
|
|
148 ;;;; after 1.8 Minor bug with parentheses.
|
|
149 ;;;; after 1.9 Improvements from Joe Marzot.
|
|
150 ;;;; after 1.10
|
|
151 ;;; Does not need easymenu to compile under XEmacs.
|
|
152 ;;; `vc-insert-headers' should work better.
|
|
153 ;;; Should work with 19.29 and 19.12.
|
|
154 ;;; Small improvements to fontification.
|
|
155 ;;; Expansion of keywords does not depend on C-? being backspace.
|
|
156
|
|
157 ;;; after 1.10+
|
|
158 ;;; 19.29 and 19.12 supported.
|
|
159 ;;; `cperl-font-lock-enhanced' deprecated. Use font-lock-extra.el.
|
|
160 ;;; Support for font-lock-extra.el.
|
|
161
|
|
162 ;;;; After 1.11:
|
|
163 ;;; Tools submenu.
|
|
164 ;;; Support for perl5-info.
|
|
165 ;;; `imenu-go-find-at-position' in Tools requires imenu-go.el (see hints above)
|
|
166 ;;; Imenu entries do not work with stock imenu.el. Patch sent to maintainers.
|
|
167 ;;; Fontifies `require a if b;', __DATA__.
|
|
168 ;;; Arglist for auto-fill-mode was incorrect.
|
|
169
|
|
170 ;;;; After 1.12:
|
|
171 ;;; `cperl-lineup-step' and `cperl-lineup' added: lineup constructions
|
|
172 ;;; vertically.
|
|
173 ;;; `cperl-do-auto-fill' updated for 19.29 style.
|
|
174 ;;; `cperl-info-on-command' now has a default.
|
|
175 ;;; Workaround for broken C-h on XEmacs.
|
|
176 ;;; VC strings escaped.
|
|
177 ;;; C-h f now may prompt for function name instead of going on,
|
|
178 ;;; controlled by `cperl-info-on-command-no-prompt'.
|
|
179
|
|
180 ;;;; After 1.13:
|
|
181 ;;; Msb buffer list includes perl files
|
|
182 ;;; Indent-for-comment uses indent-to
|
|
183 ;;; Can write tag files using etags.
|
|
184
|
|
185 ;;;; After 1.14:
|
|
186 ;;; Recognizes (tries to ;-) {...} which are not blocks during indentation.
|
|
187 ;;; `cperl-close-paren-offset' affects ?\] too (and ?\} if not block)
|
|
188 ;;; Bug with auto-filling comments started with "##" corrected.
|
|
189
|
|
190 ;;;; Very slow now: on DB::DB 0.91, 486/66:
|
|
191
|
|
192 ;;;Function Name Call Count Elapsed Time Average Time
|
|
193 ;;;======================================== ========== ============ ============
|
|
194 ;;;cperl-block-p 469 3.7799999999 0.0080597014
|
|
195 ;;;cperl-get-state 505 163.39000000 0.3235445544
|
|
196 ;;;cperl-comment-indent 12 0.0299999999 0.0024999999
|
|
197 ;;;cperl-backward-to-noncomment 939 4.4599999999 0.0047497337
|
|
198 ;;;cperl-calculate-indent 505 172.22000000 0.3410297029
|
|
199 ;;;cperl-indent-line 505 172.88000000 0.3423366336
|
|
200 ;;;cperl-use-region-p 40 0.0299999999 0.0007499999
|
|
201 ;;;cperl-indent-exp 1 177.97000000 177.97000000
|
|
202 ;;;cperl-to-comment-or-eol 1453 3.9800000000 0.0027391603
|
|
203 ;;;cperl-backward-to-start-of-continued-exp 9 0.0300000000 0.0033333333
|
|
204 ;;;cperl-indent-region 1 177.94000000 177.94000000
|
|
205
|
|
206 ;;;; After 1.15:
|
|
207 ;;; Takes into account white space after opening parentheses during indent.
|
|
208 ;;; May highlight pods and here-documents: see `cperl-pod-here-scan',
|
|
209 ;;; `cperl-pod-here-fontify', `cperl-pod-face'. Does not use this info
|
|
210 ;;; for indentation so far.
|
|
211 ;;; Fontification updated to 19.30 style.
|
|
212 ;;; The change 19.29->30 did not add all the required functionality,
|
|
213 ;;; but broke "font-lock-extra.el". Get "choose-color.el" from
|
|
214 ;;; ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs
|
|
215
|
|
216 ;;;; After 1.16:
|
|
217 ;;; else # comment
|
|
218 ;;; recognized as a start of a block.
|
|
219 ;;; Two different font-lock-levels provided.
|
|
220 ;;; `cperl-pod-head-face' introduced. Used for highlighting.
|
|
221 ;;; `imenu' marks pods, +Packages moved to the head.
|
|
222
|
|
223 ;;;; After 1.17:
|
|
224 ;;; Scan for pods highlights here-docs too.
|
|
225 ;;; Note that the tag of here-doc may be rehighlighted later by lazy-lock.
|
|
226 ;;; Only one here-doc-tag per line is supported, and one in comment
|
|
227 ;;; or a string may break fontification.
|
|
228 ;;; POD headers were supposed to fill one line only.
|
|
229
|
|
230 ;;;; After 1.18:
|
|
231 ;;; `font-lock-keywords' were set in 19.30 style _always_. Current scheme
|
|
232 ;;; may break under XEmacs.
|
|
233 ;;; `cperl-calculate-indent' dis suppose that `parse-start' was defined.
|
|
234 ;;; `fontified' tag is added to fontified text as well as `lazy-lock' (for
|
|
235 ;;; compatibility with older lazy-lock.el) (older one overfontifies
|
|
236 ;;; something nevertheless :-().
|
|
237 ;;; Will not indent something inside pod and here-documents.
|
|
238 ;;; Fontifies the package name after import/no/bootstrap.
|
|
239 ;;; Added new entry to menu with meta-info about the mode.
|
|
240
|
|
241 ;;;; After 1.19:
|
|
242 ;;; Prefontification works much better with 19.29. Should be checked
|
|
243 ;;; with 19.30 as well.
|
|
244 ;;; Some misprints in docs corrected.
|
|
245 ;;; Now $a{-text} and -text => "blah" are fontified as strings too.
|
|
246 ;;; Now the pod search is much stricter, so it can help you to find
|
|
247 ;;; pod sections which are broken because of whitespace before =blah
|
|
248 ;;; - just observe the fontification.
|
|
249
|
|
250 ;;;; After 1.20
|
|
251 ;;; Anonymous subs are indented with respect to the level of
|
|
252 ;;; indentation of `sub' now.
|
|
253 ;;; {} is recognized as hash after `bless' and `return'.
|
|
254 ;;; Anonymous subs are split by `cperl-linefeed' as well.
|
|
255 ;;; Electric parens embrace a region if present.
|
|
256 ;;; To make `cperl-auto-newline' useful,
|
|
257 ;;; `cperl-auto-newline-after-colon' is introduced.
|
|
258 ;;; `cperl-electric-parens' is now t or nul. The old meaning is moved to
|
|
259 ;;; `cperl-electric-parens-string'.
|
|
260 ;;; `cperl-toggle-auto-newline' introduced, put on C-c C-a.
|
|
261 ;;; `cperl-toggle-abbrev' introduced, put on C-c C-k.
|
|
262 ;;; `cperl-toggle-electric' introduced, put on C-c C-e.
|
|
263 ;;; Beginning-of-defun-regexp was not anchored.
|
|
264
|
|
265 ;;;; After 1.21
|
|
266 ;;; Auto-newline grants `cperl-extra-newline-before-brace' if "{" is typed
|
|
267 ;;; after ")".
|
|
268 ;;; {} is recognized as expression after `tr' and friends.
|
4
|
269
|
|
270 ;;;; After 1.22
|
|
271 ;;; Entry Hierarchy added to imenu. Very primitive so far.
|
|
272 ;;; One needs newer `imenu-go'.el. A patch to `imenu' is needed as well.
|
|
273 ;;; Writes its own TAGS files.
|
|
274 ;;; Class viewer based on TAGS files. Does not trace @ISA so far.
|
|
275 ;;; 19.31: Problems with scan for PODs corrected.
|
|
276 ;;; First POD header correctly fontified.
|
|
277 ;;; I needed (setq imenu-use-keymap-menu t) to get good imenu in 19.31.
|
|
278 ;;; Apparently it makes a lot of hierarchy code obsolete...
|
|
279
|
|
280 ;;;; After 1.23
|
|
281 ;;; Tags filler now scans *.xs as well.
|
|
282 ;;; The info from *.xs scan is used by the hierarchy viewer.
|
|
283 ;;; Hierarchy viewer documented.
|
|
284 ;;; Bug in 19.31 imenu documented.
|
|
285
|
|
286 ;;;; After 1.24
|
|
287 ;;; New location for info-files mentioned,
|
|
288 ;;; Electric-; should work better.
|
|
289 ;;; Minor bugs with POD marking.
|
|
290
|
|
291 ;;;; After 1.25 (probably not...)
|
|
292 ;;; `cperl-info-page' introduced.
|
|
293 ;;; To make `uncomment-region' working, `comment-region' would
|
|
294 ;;; not insert extra space.
|
|
295 ;;; Here documents delimiters better recognized
|
|
296 ;;; (empty one, and non-alphanums in quotes handled). May be wrong with 1<<14?
|
|
297 ;;; `cperl-db' added, used in menu.
|
|
298 ;;; imenu scan removes text-properties, for better debugging
|
|
299 ;;; - but the bug is in 19.31 imenu.
|
|
300 ;;; formats highlighted by font-lock and prescan, embedded comments
|
|
301 ;;; are not treated.
|
|
302 ;;; POD/friends scan merged in one pass.
|
|
303 ;;; Syntax class is not used for analyzing the code, only char-syntax
|
|
304 ;;; may be checked against _ or'ed with w.
|
|
305 ;;; Syntax class of `:' changed to be _.
|
|
306 ;;; `cperl-find-bad-style' added.
|
|
307
|
|
308 ;;;; After 1.25
|
|
309 ;;; When search for here-documents, we ignore commented << in simplest cases.
|
|
310 ;;; `cperl-get-help' added, available on C-h v and from menu.
|
|
311 ;;; Auto-help added. Default with `cperl-hairy', switchable on/off
|
|
312 ;;; with startup variable `cperl-lazy-help-time' and from
|
|
313 ;;; menu. Requires `run-with-idle-timer'.
|
|
314 ;;; Highlighting of @abc{@efg} was wrong - interchanged two regexps.
|
|
315
|
|
316 ;;;; After 1.27
|
|
317 ;;; Indentation: At toplevel after a label - fixed.
|
|
318 ;;; 1.27 was put to archives in binary mode ===> DOSish :-(
|
|
319
|
|
320 ;;;; After 1.28
|
|
321 ;;; Thanks to Martin Buchholz <mrb@Eng.Sun.COM>: misprints in
|
|
322 ;;; comments and docstrings corrected, XEmacs support cleaned up.
|
|
323 ;;; The closing parenths would enclose the region into matching
|
|
324 ;;; parens under the same conditions as the opening ones.
|
|
325 ;;; Minor updates to `cperl-short-docs'.
|
|
326 ;;; Will not consider <<= as start of here-doc.
|
0
|
327
|
110
|
328 ;;;; After 1.29
|
|
329 ;;; Added an extra advice to look into Micro-docs. ;-).
|
|
330 ;;; Enclosing of region when you press a closing parenth is regulated by
|
|
331 ;;; `cperl-electric-parens-string'.
|
|
332 ;;; Minor updates to `cperl-short-docs'.
|
|
333 ;;; `initialize-new-tags-table' called only if present (Does this help
|
|
334 ;;; with generation of tags under XEmacs?).
|
|
335 ;;; When creating/updating tag files, new info is written at the old place,
|
|
336 ;;; or at the end (is this a wanted behaviour? I need this in perl build directory).
|
|
337
|
|
338 ;;;; After 1.30
|
|
339 ;;; All the keywords from keywords.pl included (maybe with dummy explanation).
|
|
340 ;;; No auto-help inside strings, comment, here-docs, formats, and pods.
|
193
|
341 ;;; Shrinkwrapping of info, regulated by `cperl-max-help-size',
|
|
342 ;;; `cperl-shrink-wrap-info-frame'.
|
110
|
343 ;;; Info on variables as well.
|
|
344 ;;; Recognision of HERE-DOCS improved yet more.
|
|
345 ;;; Autonewline works on `}' without warnings.
|
|
346 ;;; Autohelp works again on $_[0].
|
|
347
|
|
348 ;;;; After 1.31
|
|
349 ;;; perl-descr.el found its author - hi, Johan!
|
193
|
350 ;;; Some support for correct indent after here-docs and friends (may
|
|
351 ;;; be superseeded by eminent change to Emacs internals).
|
|
352 ;;; Should work with older Emaxen as well ( `-style stuff removed).
|
|
353
|
|
354 ;;;; After 1.32
|
|
355
|
|
356 ;;; Started to add support for `syntax-table' property (should work
|
|
357 ;;; with patched Emaxen), controlled by
|
|
358 ;;; `cperl-use-syntax-table-text-property'. Currently recognized:
|
|
359 ;;; All quote-like operators: m, s, y, tr, qq, qw, qx, q,
|
|
360 ;;; // in most frequent context:
|
|
361 ;;; after block or
|
|
362 ;;; ~ { ( = | & + - * ! , ;
|
|
363 ;;; or
|
|
364 ;;; while if unless until and or not xor split grep map
|
|
365 ;;; Here-documents, formats, PODs,
|
|
366 ;;; ${...}
|
|
367 ;;; 'abc$'
|
|
368 ;;; sub a ($); sub a ($) {}
|
|
369 ;;; (provide 'cperl-mode) was missing!
|
|
370 ;;; `cperl-after-expr-p' is now much smarter after `}'.
|
|
371 ;;; `cperl-praise' added to mini-docs.
|
|
372 ;;; Utilities try to support subs-with-prototypes.
|
|
373
|
|
374 ;;;; After 1.32.1
|
|
375 ;;; `cperl-after-expr-p' is now much smarter after "() {}" and "word {}":
|
|
376 ;;; if word is "else, map, grep".
|
|
377 ;;; Updated for new values of syntax-table constants.
|
|
378 ;;; Uses `help-char' (at last!) (disabled, does not work?!)
|
|
379 ;;; A couple of regexps where missing _ in character classes.
|
|
380 ;;; -s could be considered as start of regexp, 1../blah/ was not,
|
|
381 ;;; as was not /blah/ at start of file.
|
|
382
|
|
383 ;;;; After 1.32.2
|
|
384 ;;; "\C-hv" was wrongly "\C-hf"
|
|
385 ;;; C-hv was not working on `[index()]' because of [] in skip-chars-*.
|
|
386 ;;; `__PACKAGE__' supported.
|
|
387 ;;; Thanks for Greg Badros: `cperl-lazy-unstall' is more complete,
|
|
388 ;;; `cperl-get-help' is made compatible with `query-replace'.
|
|
389
|
|
390 ;;;; As of Apr 15, development version of 19.34 supports
|
|
391 ;;;; `syntax-table' text properties. Try setting
|
|
392 ;;;; `cperl-use-syntax-table-text-property'.
|
|
393
|
|
394 ;;;; After 1.32.3
|
|
395 ;;; We scan for s{}[] as well.
|
|
396 ;;; We scan for $blah'foo as well.
|
|
397 ;;; The default is to use `syntax-table' text property if Emacs is good enough.
|
|
398 ;;; `cperl-lineup' is put on C-M-| (=C-M-S-\\).
|
|
399 ;;; Start of `cperl-beautify-regexp'.
|
|
400
|
|
401 ;;;; After 1.32.4
|
|
402 ;;; `cperl-tags-hier-init' did not work in text-mode.
|
|
403 ;;; `cperl-noscan-files-regexp' had a misprint.
|
|
404 ;;; Generation of Class Hierarchy was broken due to a bug in `x-popup-menu'
|
|
405 ;;; in 19.34.
|
|
406
|
|
407 ;;;; After 1.33:
|
|
408 ;;; my,local highlight vars after {} too.
|
|
409 ;;; TAGS could not be created before imenu was loaded.
|
|
410 ;;; `cperl-indent-left-aligned-comments' created.
|
|
411 ;;; Logic of `cperl-indent-exp' changed a little bit, should be more
|
|
412 ;;; robust w.r.t. multiline strings.
|
|
413 ;;; Recognition of blah'foo takes into account strings.
|
|
414 ;;; Added '.al' to the list of Perl extensions.
|
|
415 ;;; Class hierarchy is "mostly" sorted (need to rethink algorthm
|
|
416 ;;; of pruning one-root-branch subtrees to get yet better sorting.)
|
|
417 ;;; Regeneration of TAGS was busted.
|
|
418 ;;; Can use `syntax-table' property when generating TAGS
|
|
419 ;;; (governed by `cperl-use-syntax-table-text-property-for-tags').
|
|
420
|
|
421 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
|
|
422
|
|
423
|
|
424 ;;---------------------------------------------------------
|
|
425 (defgroup perl nil
|
|
426 "CPerl mode 1.35 with XEmacs enhancements."
|
|
427 :prefix "cperl"
|
|
428 :group 'languages)
|
|
429
|
|
430 ;;-----------------------------------------------
|
|
431 (defgroup cperl-indent nil
|
|
432 "CPerl indention control variables."
|
|
433 :prefix "cperl"
|
|
434 :group 'perl)
|
|
435
|
|
436 (defcustom cperl-tab-always-indent t
|
|
437 "*Non-nil means TAB in CPerl mode should always reindent the current line,
|
|
438 regardless of where in the line point is when the TAB command is used."
|
|
439 :type 'boolean
|
|
440 :group 'cperl-indent)
|
|
441
|
|
442 (defcustom cperl-extra-newline-before-brace nil
|
0
|
443 "*Non-nil means that if, elsif, while, until, else, for, foreach
|
|
444 and do constructs look like:
|
|
445
|
|
446 if ()
|
|
447 {
|
|
448 }
|
|
449
|
|
450 instead of:
|
|
451
|
|
452 if () {
|
|
453 }
|
193
|
454 "
|
|
455 :type 'boolean
|
|
456 :group 'cperl-indent)
|
|
457
|
|
458 (defcustom cperl-indent-level 2
|
|
459 "*Indentation of CPerl statements with respect to containing block."
|
|
460 :type '(choice (const 1) (const 2) (const 4) (const 6) (const 8))
|
|
461 :group 'cperl-indent)
|
|
462
|
|
463 (defcustom cperl-lineup-step nil
|
0
|
464 "*`cperl-lineup' will always lineup at multiple of this number.
|
193
|
465 If `nil', the value of `cperl-indent-level' will be used."
|
|
466 :type '(choice (const nil) (const 1) (const 2) (const 4) (const 6) (const 8))
|
|
467 :group 'cperl-indent)
|
|
468
|
|
469 (defcustom cperl-brace-imaginary-offset 0
|
0
|
470 "*Imagined indentation of a Perl open brace that actually follows a statement.
|
|
471 An open brace following other text is treated as if it were this far
|
193
|
472 to the right of the start of its line."
|
|
473 :type '(choice (const 0) (const 1) (const 2) (const 4) (const 6) (const 8))
|
|
474 :group 'cperl-indent)
|
|
475
|
|
476 (defcustom cperl-brace-offset 0
|
|
477 "*Extra indentation for braces, compared with other text in same context."
|
|
478 :type '(choice (const 0) (const 1) (const 2) (const 4) (const 6) (const 8))
|
|
479 :group 'cperl-indent)
|
|
480
|
|
481 (defcustom cperl-label-offset -2
|
|
482 "*Offset of CPerl label lines relative to usual indentation."
|
|
483 :type '(choice (const -4) (const -2) (const -1))
|
|
484 :group 'cperl-indent)
|
|
485
|
|
486 (defcustom cperl-min-label-indent 1
|
|
487 "*Minimal offset of CPerl label lines."
|
|
488 :type '(choice (const 1) (const 2) (const 4))
|
|
489 :group 'cperl-indent)
|
|
490
|
|
491 (defcustom cperl-continued-statement-offset 2
|
|
492 "*Extra indent for lines not starting new statements."
|
|
493 :type '(choice (const 2) (const 4) (const 6) (const 8))
|
|
494 :group 'cperl-indent)
|
|
495
|
|
496 (defcustom cperl-continued-brace-offset 0
|
0
|
497 "*Extra indent for substatements that start with open-braces.
|
193
|
498 This is in addition to cperl-continued-statement-offset."
|
|
499 :type '(choice (const 0) (const 1) (const 2) (const 4) (const 6) (const 8))
|
|
500 :group 'cperl-indent)
|
|
501
|
|
502 (defcustom cperl-close-paren-offset -1
|
|
503 "*Extra indent for substatements that start with close-parenthesis."
|
|
504 :type '(choice (const -4) (const -3) (const -2) (const -1) (const 0))
|
|
505 :group 'cperl-indent)
|
|
506
|
|
507 (defcustom cperl-regexp-indent-step nil
|
|
508 "*indentation used when beautifying regexps.
|
|
509 If `nil', the value of `cperl-indent-level' will be used."
|
|
510 :type '(choice (const nil) (const 0) (const 2) (const 4) (const 6) (const 8))
|
|
511 :group 'cperl-indent)
|
|
512
|
|
513 (defcustom cperl-indent-left-aligned-comments t
|
|
514 "*Non-nil means that the comment starting in leftmost column should indent."
|
|
515 :type 'boolean
|
|
516 :group 'cperl-indent)
|
|
517
|
|
518 ;;-------------------------------------------
|
|
519
|
|
520 (defcustom cperl-hairy nil
|
|
521 "*Not-nil means all the bells and whistles are enabled in CPerl."
|
|
522 :type 'boolean
|
|
523 :group 'perl)
|
|
524
|
|
525 (defcustom cperl-auto-newline nil
|
0
|
526 "*Non-nil means automatically newline before and after braces,
|
|
527 and after colons and semicolons, inserted in CPerl code. The following
|
|
528 \\[cperl-electric-backspace] will remove the inserted whitespace.
|
|
529 Insertion after colons requires both this variable and
|
193
|
530 `cperl-auto-newline-after-colon' set."
|
|
531 :type 'boolean
|
|
532 :group 'perl)
|
|
533
|
|
534 (defcustom cperl-auto-newline-after-colon nil
|
0
|
535 "*Non-nil means automatically newline even after colons.
|
193
|
536 Subject to `cperl-auto-newline' setting."
|
|
537 :type 'boolean
|
|
538 :group 'perl)
|
|
539
|
|
540 ;;--------------------------------------
|
|
541 (defgroup cperl-electric nil
|
|
542 "Customizable electric behaviour."
|
|
543 :prefix "cperl"
|
|
544 :group 'perl)
|
|
545
|
|
546 (defcustom cperl-electric-lbrace-space nil
|
|
547 "*Non-nil (and non-null) means { after $ in CPerl buffers should be preceded by ` '.
|
|
548 Can be overwritten by `cperl-hairy' if nil."
|
|
549 :type 'boolean
|
|
550 :group 'cperl-electric)
|
|
551
|
|
552 (defcustom cperl-electric-parens-string "({[]})<"
|
|
553 "*String of parentheses that should be electric in CPerl."
|
|
554 :type 'string
|
|
555 :group 'cperl-electric)
|
|
556
|
|
557 (defcustom cperl-electric-parens nil
|
0
|
558 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
|
193
|
559 Can be overwritten by `cperl-hairy' if nil."
|
|
560 :type 'boolean
|
|
561 :group 'cperl-electric)
|
|
562
|
|
563 (defcustom cperl-electric-parens-mark (and window-system
|
|
564 (boundp 'zmacs-regions)
|
|
565 zmacs-regions)
|
4
|
566 "*Not-nil means that electric parens look for active mark.
|
193
|
567 Default is yes if there is visual feedback on mark."
|
|
568 :type 'boolean
|
|
569 :group 'cperl-electric)
|
|
570
|
|
571 (defcustom cperl-electric-linefeed nil
|
0
|
572 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
|
|
573 In any case these two mean plain and hairy linefeeds together.
|
193
|
574 Can be overwritten by `cperl-hairy' if nil."
|
|
575 :type 'boolean
|
|
576 :group 'cperl-electric)
|
|
577
|
|
578 (defcustom cperl-electric-keywords nil
|
0
|
579 "*Not-nil (and non-null) means keywords are electric in CPerl.
|
193
|
580 Can be overwritten by `cperl-hairy' if nil."
|
|
581 :type 'boolean
|
|
582 :group 'cperl-electric)
|
|
583 ;;-------------------------
|
|
584
|
|
585 (defcustom cperl-comment-column 32
|
|
586 "*Column to put comments in CPerl (use \\[cperl-indent]' to lineup with code)."
|
|
587 :type 'integer
|
|
588 :group 'perl)
|
|
589
|
|
590 (defcustom cperl-vc-header-alist '((RCS "$rcs = ' $Id\$ ' ;")
|
|
591 (CVS "$cvs = ' $Id\$ ' ;")
|
|
592 (SCCS "$sccs = '%W\%' ;"))
|
0
|
593 "*What to use as `vc-header-alist' in CPerl.")
|
|
594
|
193
|
595
|
|
596 (defcustom cperl-info-on-command-no-prompt nil
|
0
|
597 "*Not-nil (and non-null) means not to prompt on C-h f.
|
|
598 The opposite behaviour is always available if prefixed with C-c.
|
193
|
599 Can be overwritten by `cperl-hairy' if nil."
|
|
600 :type 'boolean
|
|
601 :group 'perl)
|
|
602
|
|
603 (defcustom cperl-help nil
|
|
604 "*Not-nil (and non-null) means to show Auto help."
|
|
605 :type 'boolean
|
|
606 :group 'perl)
|
|
607
|
|
608
|
|
609 (defcustom cperl-font-lock (and (boundp 'font-lock-auto-fontify)
|
|
610 font-lock-auto-fontify)
|
|
611 "*Non-nil (and non-null) means CPerl buffers will use font-lock-mode.
|
|
612 Can be overwritten by `cperl-hairy' if nil. If never set, it will be
|
|
613 set to the value of `font-lock-auto-fontify'."
|
|
614 :type 'boolean
|
|
615 :group 'perl)
|
|
616
|
|
617 ;;--------------------------------------------
|
|
618 (defgroup cperl-faces nil
|
|
619 "Font lock faces for CPerl mode."
|
|
620 :group 'perl
|
|
621 :group 'faces)
|
|
622
|
|
623 (defface cperl-pod-face
|
|
624 '(( ((class color) (background light)) (:foreground "brown4") )
|
|
625 ( ((class color) (background dark)) (:foreground "brown1") ))
|
|
626 "*The face used for POD highlighting."
|
|
627 :group 'cperl-faces)
|
|
628
|
|
629 (defface cperl-pod-head-face
|
|
630 '(( ((class color)) (:foreground "steelblue")))
|
|
631 "*The face used for POD headers."
|
|
632 :group 'cperl-faces)
|
|
633
|
|
634 (defface cperl-here-face
|
207
|
635 '((((type x) (class color) (background light))
|
|
636 (:foreground "green4" :background "grey85"))
|
|
637 (t (:foreground "green")))
|
193
|
638 "*The result of evaluation of this expression is used for here-docs highlighting."
|
|
639 :group 'cperl-faces)
|
|
640
|
|
641 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
|
|
642 "*Not-nil after evaluation means to highlight pod and here-docs sections."
|
|
643 :type 'boolean
|
|
644 :group 'perl)
|
|
645
|
|
646 (defcustom cperl-pod-here-scan t
|
0
|
647 "*Not-nil means look for pod and here-docs sections during startup.
|
193
|
648 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
|
|
649 :type 'boolean
|
|
650 :group 'perl)
|
|
651
|
|
652 ;; ToDo: perhaps `imenu' should be ported to XEmacs?
|
|
653 ;;(defcustom cperl-imenu-addback nil
|
|
654 ;; "*Not-nil means add backreferences to generated `imenu's.
|
|
655 ;;May require patched `imenu' and `imenu-go'."
|
|
656 ;; :type 'boolean
|
|
657 ;; :group 'perl)
|
|
658
|
|
659 (defcustom cperl-max-help-size 66
|
|
660 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
|
|
661 :type 'integer
|
|
662 :group 'perl)
|
|
663
|
|
664 (defcustom cperl-shrink-wrap-info-frame t
|
|
665 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
|
|
666 :type 'boolean
|
|
667 :group 'perl)
|
|
668
|
|
669 (defcustom cperl-info-page "perl"
|
|
670 "*Name of the info page containing perl docs.
|
|
671 Older version of this page was called `perl5', newer `perl'."
|
|
672 :type 'string
|
|
673 :group 'perl)
|
|
674
|
|
675 (defvar cperl-use-syntax-table-text-property nil
|
|
676 "Temporary kludge until I find everything connected to this so I can
|
|
677 rip it out.")
|
|
678
|
|
679 ;;(defcustom cperl-use-syntax-table-text-property
|
|
680 ;; (boundp 'parse-sexp-lookup-properties)
|
|
681 ;; "*Non-nil means CPerl sets up and uses `syntax-table' text property."
|
|
682 ;; :type 'boolean
|
|
683 ;; :group 'perl)
|
|
684
|
|
685 (defvar cperl-use-syntax-table-text-property-for-tags
|
|
686 cperl-use-syntax-table-text-property
|
|
687 "*Non-nil means: set up and use `syntax-table' text property generating TAGS.")
|
|
688
|
|
689 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
|
|
690 "*Regexp to match files to scan when generating TAGS."
|
|
691 :type 'regexp
|
|
692 :group 'perl)
|
|
693
|
|
694 (defcustom cperl-noscan-files-regexp "/\\(\\.\\.?\\|SCCS\\|RCS\\|blib\\)$"
|
|
695 "*Regexp to match files/dirs to skip when generating TAGS."
|
|
696 :type 'regexp
|
|
697 :group 'perl)
|
4
|
698
|
0
|
699
|
|
700
|
|
701 ;;; Short extra-docs.
|
|
702
|
|
703 (defvar cperl-tips 'please-ignore-this-line
|
|
704 "Get newest version of this package from
|
|
705 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs
|
|
706 and/or
|
|
707 ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
|
|
708
|
193
|
709 This particular version has been modified for XEmacs 20.
|
|
710
|
4
|
711 Get support packages choose-color.el (or font-lock-extra.el before
|
|
712 19.30), imenu-go.el from the same place. \(Look for other files there
|
|
713 too... ;-) Get a patch for imenu.el in 19.29. Note that for 19.30 and
|
|
714 later you should use choose-color.el *instead* of font-lock-extra.el
|
|
715 \(and you will not get smart highlighting in C :-().
|
0
|
716
|
|
717 Note that to enable Compile choices in the menu you need to install
|
|
718 mode-compile.el.
|
|
719
|
|
720 Get perl5-info from
|
4
|
721 $CPAN/doc/manual/info/perl-info.tar.gz
|
|
722 older version was on
|
0
|
723 http://www.metronet.com:70/9/perlinfo/perl5/manual/perl5-info.tar.gz
|
4
|
724
|
|
725 If you use imenu-go, run imenu on perl5-info buffer (you can do it
|
|
726 from CPerl menu). If many files are related, generate TAGS files from
|
|
727 Tools/Tags submenu in CPerl menu.
|
|
728
|
|
729 If some class structure is too complicated, use Tools/Hierarchy-view
|
|
730 from CPerl menu, or hierarchic view of imenu. The second one uses the
|
|
731 current buffer only, the first one requires generation of TAGS from
|
|
732 CPerl/Tools/Tags menu beforehand.
|
|
733
|
|
734 Run CPerl/Tools/Insert-spaces-if-needed to fix your lazy typing.
|
|
735
|
|
736 Switch auto-help on/off with CPerl/Tools/Auto-help.
|
0
|
737
|
|
738 Before reporting (non-)problems look in the problem section on what I
|
|
739 know about them.")
|
|
740
|
|
741 (defvar cperl-problems 'please-ignore-this-line
|
|
742 "Emacs has a _very_ restricted syntax parsing engine.
|
|
743
|
|
744 It may be corrected on the level of C code, please look in the
|
|
745 `non-problems' section if you want to volunteer.
|
|
746
|
|
747 CPerl mode tries to corrects some Emacs misunderstandings, however,
|
4
|
748 for efficiency reasons the degree of correction is different for
|
0
|
749 different operations. The partially corrected problems are: POD
|
|
750 sections, here-documents, regexps. The operations are: highlighting,
|
|
751 indentation, electric keywords, electric braces.
|
|
752
|
|
753 This may be confusing, since the regexp s#//#/#\; may be highlighted
|
4
|
754 as a comment, but it will be recognized as a regexp by the indentation
|
0
|
755 code. Or the opposite case, when a pod section is highlighted, but
|
193
|
756 may break the indentation of the following code (though indentation
|
|
757 should work if the balance of delimiters is not broken by POD).
|
0
|
758
|
|
759 The main trick (to make $ a \"backslash\") makes constructions like
|
4
|
760 ${aaa} look like unbalanced braces. The only trick I can think of is
|
0
|
761 to insert it as $ {aaa} (legal in perl5, not in perl4).
|
|
762
|
|
763 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
|
4
|
764 as /($|\\s)/. Note that such a transposition is not always possible
|
0
|
765 :-(. " )
|
|
766
|
|
767 (defvar cperl-non-problems 'please-ignore-this-line
|
4
|
768 "As you know from `problems' section, Perl syntax is too hard for CPerl.
|
0
|
769
|
|
770 Most the time, if you write your own code, you may find an equivalent
|
|
771 \(and almost as readable) expression.
|
|
772
|
193
|
773 Try to help CPerl: add comments with embedded quotes to fix CPerl
|
0
|
774 misunderstandings about the end of quotation:
|
|
775
|
|
776 $a='500$'; # ';
|
|
777
|
|
778 You won't need it too often. The reason: $ \"quotes\" the following
|
|
779 character (this saves a life a lot of times in CPerl), thus due to
|
193
|
780 Emacs parsing rules it does not consider tick (i.e., ' ) after a
|
|
781 dollar as a closing one, but as a usual character.
|
0
|
782
|
|
783 Now the indentation code is pretty wise. The only drawback is that it
|
|
784 relies on Emacs parsing to find matching parentheses. And Emacs
|
|
785 *cannot* match parentheses in Perl 100% correctly. So
|
|
786 1 if s#//#/#;
|
|
787 will not break indentation, but
|
|
788 1 if ( s#//#/# );
|
|
789 will.
|
|
790
|
110
|
791 By similar reasons
|
|
792 s\"abc\"def\";
|
|
793 will confuse CPerl a lot.
|
|
794
|
0
|
795 If you still get wrong indentation in situation that you think the
|
|
796 code should be able to parse, try:
|
|
797
|
|
798 a) Check what Emacs thinks about balance of your parentheses.
|
|
799 b) Supply the code to me (IZ).
|
|
800
|
|
801 Pods are treated _very_ rudimentally. Here-documents are not treated
|
|
802 at all (except highlighting and inhibiting indentation). (This may
|
|
803 change some time. RMS approved making syntax lookup recognize text
|
4
|
804 attributes, but volunteers are needed to change Emacs C code.)
|
0
|
805
|
|
806 To speed up coloring the following compromises exist:
|
|
807 a) sub in $mypackage::sub may be highlighted.
|
|
808 b) -z in [a-z] may be highlighted.
|
|
809 c) if your regexp contains a keyword (like \"s\"), it may be highlighted.
|
4
|
810
|
|
811
|
|
812 Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove
|
|
813 `car' before `imenu-choose-buffer-index' in `imenu'.
|
0
|
814 ")
|
|
815
|
193
|
816 (defvar cperl-praise 'please-ignore-this-line
|
|
817 "RMS asked me to list good things about CPerl. Here they go:
|
|
818
|
|
819 0) It uses the newest `syntax-table' property ;-);
|
|
820
|
|
821 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
|
|
822 mode - but the latter number may have improved too in last years) even
|
|
823 without `syntax-table' property; When using this property, it should
|
|
824 handle 99.995% of lines correct - or somesuch.
|
|
825
|
|
826 2) It is generally belived to be \"the most user-friendly Emacs
|
|
827 package\" whatever it may mean (I doubt that the people who say similar
|
|
828 things tried _all_ the rest of Emacs ;-), but this was not a lonely
|
|
829 voice);
|
|
830
|
|
831 3) Everything is customizable, one-by-one or in a big sweep;
|
|
832
|
|
833 4) It has many easily-accessable \"tools\":
|
|
834 a) Can run program, check syntax, start debugger;
|
|
835 b) Can lineup vertically \"middles\" of rows, like `=' in
|
|
836 a = b;
|
|
837 cc = d;
|
|
838 c) Can insert spaces where this impoves readability (in one
|
|
839 interactive sweep over the buffer);
|
|
840 d) Has support for imenu, including:
|
|
841 1) Separate unordered list of \"interesting places\";
|
|
842 2) Separate TOC of POD sections;
|
|
843 3) Separate list of packages;
|
|
844 4) Hierarchical view of methods in (sub)packages;
|
|
845 5) and functions (by the full name - with package);
|
|
846 e) Has an interface to INFO docs for Perl; The interface is
|
|
847 very flexible, including shrink-wrapping of
|
|
848 documentation buffer/frame;
|
|
849 f) Has a builtin list of one-line explanations for perl constructs.
|
|
850 g) Can show these explanations if you stay long enough at the
|
|
851 corresponding place (or on demand);
|
|
852 h) Has an enhanced fontification (using 3 or 4 additional faces
|
|
853 comparing to font-lock - basically, different
|
|
854 namespaces in Perl have different colors);
|
|
855 i) Can construct TAGS basing on its knowledge of Perl syntax,
|
|
856 the standard menu has 6 different way to generate
|
|
857 TAGS (if by directory, .xs files - with C-language
|
|
858 bindings - are included in the scan);
|
|
859 j) Can build a hierarchical view of classes (via imenu) basing
|
|
860 on generated TAGS file;
|
|
861 k) Has electric parentheses, electric newlines, uses Abbrev
|
|
862 for electric logical constructs
|
|
863 while () {}
|
|
864 with different styles of expansion (context sensitive
|
|
865 to be not so bothering). Electric parentheses behave
|
|
866 \"as they should\" in a presence of a visible region.
|
|
867 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
|
|
868
|
|
869 5) The indentation engine was very smart, but most of tricks may be
|
|
870 not needed anymore with the support for `syntax-table' property. Has
|
|
871 progress indicator for indentation (with `imenu' loaded).
|
|
872
|
|
873 6) Indent-region improves inline-comments as well;
|
|
874
|
|
875 7) Fill-paragraph correctly handles multi-line comments;
|
|
876 ")
|
|
877
|
0
|
878
|
|
879
|
|
880 ;;; Portability stuff:
|
|
881
|
4
|
882 (defmacro cperl-define-key (fsf-key definition &optional xemacs-key)
|
193
|
883 (` (define-key cperl-mode-map
|
|
884 (, (if xemacs-key
|
|
885 (` (if cperl-xemacs-p (, xemacs-key) (, fsf-key)))
|
|
886 fsf-key))
|
|
887 (, definition))))
|
0
|
888
|
|
889 (defvar del-back-ch (car (append (where-is-internal 'delete-backward-char)
|
|
890 (where-is-internal 'backward-delete-char-untabify)))
|
|
891 "Character generated by key bound to delete-backward-char.")
|
|
892
|
|
893 (and (vectorp del-back-ch) (= (length del-back-ch) 1)
|
|
894 (setq del-back-ch (aref del-back-ch 0)))
|
|
895
|
4
|
896 (if cperl-xemacs-p
|
0
|
897 (progn
|
|
898 ;; "Active regions" are on: use region only if active
|
|
899 ;; "Active regions" are off: use region unconditionally
|
|
900 (defun cperl-use-region-p ()
|
|
901 (if zmacs-regions (mark) t))
|
|
902 (defun cperl-mark-active () (mark)))
|
|
903 (defun cperl-use-region-p ()
|
|
904 (if transient-mark-mode mark-active t))
|
|
905 (defun cperl-mark-active () mark-active))
|
|
906
|
|
907 (defsubst cperl-enable-font-lock ()
|
4
|
908 (or cperl-xemacs-p window-system))
|
0
|
909
|
|
910 (if (boundp 'unread-command-events)
|
4
|
911 (if cperl-xemacs-p
|
0
|
912 (defun cperl-putback-char (c) ; XEmacs >= 19.12
|
|
913 (setq unread-command-events (list (character-to-event c))))
|
|
914 (defun cperl-putback-char (c) ; Emacs 19
|
|
915 (setq unread-command-events (list c))))
|
|
916 (defun cperl-putback-char (c) ; XEmacs <= 19.11
|
|
917 (setq unread-command-event (character-to-event c))))
|
|
918
|
|
919 (or (fboundp 'uncomment-region)
|
|
920 (defun uncomment-region (beg end)
|
|
921 (interactive "r")
|
|
922 (comment-region beg end -1)))
|
|
923
|
|
924 (defvar cperl-do-not-fontify
|
|
925 (if (string< emacs-version "19.30")
|
|
926 'fontified
|
|
927 'lazy-lock)
|
|
928 "Text property which inhibits refontification.")
|
|
929
|
4
|
930 (defsubst cperl-put-do-not-fontify (from to)
|
|
931 (put-text-property (max (point-min) (1- from))
|
|
932 to cperl-do-not-fontify t))
|
|
933
|
193
|
934 (defcustom cperl-mode-hook nil
|
|
935 "Hook run by `cperl-mode'."
|
|
936 :type 'sexp
|
|
937 :group 'perl)
|
|
938
|
0
|
939
|
|
940 ;;; Probably it is too late to set these guys already, but it can help later:
|
203
|
941 ;;; ####
|
0
|
942 (setq auto-mode-alist
|
193
|
943 (append '(("\\.\\([pP][Llm]\\|al\\)\\'" . perl-mode)) auto-mode-alist ))
|
0
|
944 (and (boundp 'interpreter-mode-alist)
|
|
945 (setq interpreter-mode-alist (append interpreter-mode-alist
|
|
946 '(("miniperl" . perl-mode)))))
|
|
947 (if (fboundp 'eval-when-compile)
|
|
948 (eval-when-compile
|
|
949 (condition-case nil
|
|
950 (require 'imenu)
|
|
951 (error nil))
|
|
952 (condition-case nil
|
|
953 (require 'easymenu)
|
|
954 (error nil))
|
|
955 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
|
|
956 ;; macros instead of defsubsts don't work on Emacs, so we do the
|
|
957 ;; expansion manually. Any other suggestions?
|
|
958 (if (or (string-match "XEmacs\\|Lucid" emacs-version)
|
|
959 window-system)
|
|
960 (require 'font-lock))
|
|
961 (require 'cl)
|
|
962 ))
|
|
963
|
|
964 (defvar cperl-mode-abbrev-table nil
|
|
965 "Abbrev table in use in Cperl-mode buffers.")
|
|
966
|
|
967 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
|
|
968
|
|
969 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
|
|
970
|
|
971 (if cperl-mode-map nil
|
|
972 (setq cperl-mode-map (make-sparse-keymap))
|
4
|
973 (cperl-define-key "{" 'cperl-electric-lbrace)
|
|
974 (cperl-define-key "[" 'cperl-electric-paren)
|
|
975 (cperl-define-key "(" 'cperl-electric-paren)
|
|
976 (cperl-define-key "<" 'cperl-electric-paren)
|
|
977 (cperl-define-key "}" 'cperl-electric-brace)
|
|
978 (cperl-define-key "]" 'cperl-electric-rparen)
|
|
979 (cperl-define-key ")" 'cperl-electric-rparen)
|
|
980 (cperl-define-key ";" 'cperl-electric-semi)
|
|
981 (cperl-define-key ":" 'cperl-electric-terminator)
|
193
|
982 (cperl-define-key "\C-cf" 'cperl-find-pods-heres)
|
4
|
983 (cperl-define-key "\C-j" 'newline-and-indent)
|
|
984 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
|
|
985 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
|
|
986 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
|
|
987 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
|
|
988 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
|
193
|
989 (cperl-define-key [?\C-\M-\|] 'cperl-lineup)
|
4
|
990 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
|
|
991 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
|
193
|
992 (if cperl-xemacs-p
|
|
993 (progn
|
|
994 (cperl-define-key 'backspace 'cperl-electric-backspace)
|
|
995 (cperl-define-key 'delete 'cperl-electric-delete))
|
|
996 (cperl-define-key "\177" 'cperl-electric-backspace))
|
4
|
997 (cperl-define-key "\t" 'cperl-indent-command)
|
|
998 ;; don't clobber the backspace binding:
|
|
999 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
|
|
1000 [(control c) (control h) f])
|
193
|
1001 (cperl-define-key "\C-hf"
|
|
1002 ;;(concat (char-to-string help-char) "f") ; does not work
|
|
1003 'cperl-info-on-command
|
|
1004 [(control h) f])
|
|
1005 (cperl-define-key "\C-hv"
|
|
1006 ;;(concat (char-to-string help-char) "v") ; does not work
|
|
1007 'cperl-get-help
|
|
1008 [(control h) v])
|
4
|
1009 (if (and cperl-xemacs-p
|
0
|
1010 (<= emacs-minor-version 11) (<= emacs-major-version 19))
|
|
1011 (progn
|
|
1012 ;; substitute-key-definition is usefulness-deenhanced...
|
4
|
1013 (cperl-define-key "\M-q" 'cperl-fill-paragraph)
|
|
1014 (cperl-define-key "\e;" 'cperl-indent-for-comment)
|
|
1015 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
|
0
|
1016 (substitute-key-definition
|
|
1017 'indent-sexp 'cperl-indent-exp
|
|
1018 cperl-mode-map global-map)
|
|
1019 (substitute-key-definition
|
|
1020 'fill-paragraph 'cperl-fill-paragraph
|
|
1021 cperl-mode-map global-map)
|
|
1022 (substitute-key-definition
|
|
1023 'indent-region 'cperl-indent-region
|
|
1024 cperl-mode-map global-map)
|
|
1025 (substitute-key-definition
|
|
1026 'indent-for-comment 'cperl-indent-for-comment
|
|
1027 cperl-mode-map global-map)))
|
|
1028
|
|
1029 (condition-case nil
|
|
1030 (progn
|
|
1031 (require 'easymenu)
|
|
1032 (easy-menu-define cperl-menu cperl-mode-map "Menu for CPerl mode"
|
|
1033 '("Perl"
|
|
1034 ["Beginning of function" beginning-of-defun t]
|
|
1035 ["End of function" end-of-defun t]
|
|
1036 ["Mark function" mark-defun t]
|
|
1037 ["Indent expression" cperl-indent-exp t]
|
|
1038 ["Fill paragraph/comment" cperl-fill-paragraph t]
|
193
|
1039 "----"
|
0
|
1040 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
|
193
|
1041 ["Beautify a regexp" cperl-beautify-regexp
|
|
1042 cperl-use-syntax-table-text-property]
|
0
|
1043 "----"
|
|
1044 ["Indent region" cperl-indent-region (cperl-use-region-p)]
|
4
|
1045 ["Comment region" cperl-comment-region (cperl-use-region-p)]
|
|
1046 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
|
0
|
1047 "----"
|
|
1048 ["Run" mode-compile (fboundp 'mode-compile)]
|
|
1049 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
|
|
1050 (get-buffer "*compilation*"))]
|
|
1051 ["Next error" next-error (get-buffer "*compilation*")]
|
|
1052 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
|
|
1053 "----"
|
4
|
1054 ["Debugger" cperl-db t]
|
0
|
1055 "----"
|
|
1056 ("Tools"
|
193
|
1057 ;;; ["Imenu" imenu (fboundp 'imenu)]
|
4
|
1058 ["Insert spaces if needed" cperl-find-bad-style t]
|
|
1059 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
|
|
1060 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
|
193
|
1061 ;;; ["Imenu on info" cperl-imenu-on-info (featurep 'imenu)]
|
0
|
1062 ("Tags"
|
193
|
1063 ["Create tags for current file" cperl-etags t]
|
|
1064 ["Add tags for current file" (cperl-etags t) t]
|
|
1065 ["Create tags for Perl files in directory" (cperl-etags nil t) t]
|
|
1066 ["Add tags for Perl files in directory" (cperl-etags t t) t]
|
|
1067 ["Create tags for Perl files in (sub)directories"
|
|
1068 (cperl-etags nil 'recursive) t]
|
|
1069 ["Add tags for Perl files in (sub)directories"
|
|
1070 (cperl-etags t 'recursive) t])
|
4
|
1071 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
|
193
|
1072 ;;; ["Create tags for current file" (cperl-write-tags nil t) t]
|
|
1073 ;;; ["Add tags for current file" (cperl-write-tags) t]
|
|
1074 ;;; ["Create tags for Perl files in directory"
|
|
1075 ;;; (cperl-write-tags nil t nil t) t]
|
|
1076 ;;; ["Add tags for Perl files in directory"
|
|
1077 ;;; (cperl-write-tags nil nil nil t) t]
|
|
1078 ;;; ["Create tags for Perl files in (sub)directories"
|
|
1079 ;;; (cperl-write-tags nil t t t) t]
|
|
1080 ;;; ["Add tags for Perl files in (sub)directories"
|
|
1081 ;;; (cperl-write-tags nil nil t t) t])
|
4
|
1082 ["Recalculate PODs and HEREs" cperl-find-pods-heres t]
|
193
|
1083 ;;; ["Define word at point" imenu-go-find-at-position
|
|
1084 ;;; (fboundp 'imenu-go-find-at-position)]
|
0
|
1085 ["Help on function" cperl-info-on-command t]
|
4
|
1086 ["Help on function at point" cperl-info-on-current-command t]
|
|
1087 ["Help on symbol at point" cperl-get-help t]
|
193
|
1088 )
|
0
|
1089 ("Toggle..."
|
193
|
1090 ["Auto-help" cperl-toggle-help :style toggle :selected cperl-help]
|
0
|
1091 ["Auto newline" cperl-toggle-auto-newline t]
|
|
1092 ["Electric parens" cperl-toggle-electric t]
|
|
1093 ["Electric keywords" cperl-toggle-abbrev t]
|
|
1094 )
|
|
1095 ("Indent styles..."
|
|
1096 ["GNU" (cperl-set-style "GNU") t]
|
|
1097 ["C++" (cperl-set-style "C++") t]
|
|
1098 ["FSF" (cperl-set-style "FSF") t]
|
|
1099 ["BSD" (cperl-set-style "BSD") t]
|
193
|
1100 ["Whitesmith" (cperl-set-style "Whitesmith") t]
|
|
1101 )
|
0
|
1102 ("Micro-docs"
|
|
1103 ["Tips" (describe-variable 'cperl-tips) t]
|
|
1104 ["Problems" (describe-variable 'cperl-problems) t]
|
193
|
1105 ["Non-problems" (describe-variable 'cperl-non-problems) t]
|
|
1106 ["Praise" (describe-variable 'cperl-praise) t]))))
|
0
|
1107 (error nil))
|
|
1108
|
|
1109 (autoload 'c-macro-expand "cmacexp"
|
|
1110 "Display the result of expanding all C macros occurring in the region.
|
|
1111 The expansion is entirely correct because it uses the C preprocessor."
|
|
1112 t)
|
|
1113
|
|
1114 (defvar cperl-mode-syntax-table nil
|
|
1115 "Syntax table in use in Cperl-mode buffers.")
|
|
1116
|
193
|
1117 (defvar cperl-string-syntax-table nil
|
|
1118 "Syntax table in use in Cperl-mode string-like chunks.")
|
|
1119
|
0
|
1120 (if cperl-mode-syntax-table
|
|
1121 ()
|
|
1122 (setq cperl-mode-syntax-table (make-syntax-table))
|
|
1123 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
|
|
1124 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
|
|
1125 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
|
|
1126 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
|
|
1127 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
|
|
1128 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
|
|
1129 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
|
|
1130 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
|
|
1131 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
|
|
1132 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
|
|
1133 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
|
|
1134 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
|
|
1135 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
|
|
1136 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
|
|
1137 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
|
193
|
1138 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table)
|
4
|
1139 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
|
193
|
1140 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
|
|
1141 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
|
|
1142 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
|
|
1143 (modify-syntax-entry ?# "." cperl-string-syntax-table) ; (?# comment )
|
|
1144 )
|
0
|
1145
|
|
1146
|
|
1147
|
|
1148 ;; Make customization possible "in reverse"
|
|
1149 ;;(defun cperl-set (symbol to)
|
|
1150 ;; (or (eq (symbol-value symbol) 'null) (set symbol to)))
|
|
1151 (defsubst cperl-val (symbol &optional default hairy)
|
|
1152 (cond
|
|
1153 ((eq (symbol-value symbol) 'null) default)
|
|
1154 (cperl-hairy (or hairy t))
|
|
1155 (t (symbol-value symbol))))
|
|
1156
|
|
1157 ;; provide an alias for working with emacs 19. the perl-mode that comes
|
|
1158 ;; with it is really bad, and this lets us seamlessly replace it.
|
203
|
1159 ;;;###autoload
|
|
1160 (defalias 'perl-mode 'cperl-mode)
|
|
1161 ;;;###autoload
|
0
|
1162 (defun cperl-mode ()
|
|
1163 "Major mode for editing Perl code.
|
|
1164 Expression and list commands understand all C brackets.
|
|
1165 Tab indents for Perl code.
|
|
1166 Paragraphs are separated by blank lines only.
|
|
1167 Delete converts tabs to spaces as it moves back.
|
|
1168
|
|
1169 Various characters in Perl almost always come in pairs: {}, (), [],
|
|
1170 sometimes <>. When the user types the first, she gets the second as
|
|
1171 well, with optional special formatting done on {}. (Disabled by
|
|
1172 default.) You can always quote (with \\[quoted-insert]) the left
|
|
1173 \"paren\" to avoid the expansion. The processing of < is special,
|
|
1174 since most the time you mean \"less\". Cperl mode tries to guess
|
|
1175 whether you want to type pair <>, and inserts is if it
|
|
1176 appropriate. You can set `cperl-electric-parens-string' to the string that
|
|
1177 contains the parenths from the above list you want to be electrical.
|
|
1178 Electricity of parenths is controlled by `cperl-electric-parens'.
|
|
1179 You may also set `cperl-electric-parens-mark' to have electric parens
|
|
1180 look for active mark and \"embrace\" a region if possible.'
|
|
1181
|
|
1182 CPerl mode provides expansion of the Perl control constructs:
|
|
1183 if, else, elsif, unless, while, until, for, and foreach.
|
|
1184 =========(Disabled by default, see `cperl-electric-keywords'.)
|
|
1185 The user types the keyword immediately followed by a space, which causes
|
|
1186 the construct to be expanded, and the user is positioned where she is most
|
|
1187 likely to want to be.
|
|
1188 eg. when the user types a space following \"if\" the following appears in
|
|
1189 the buffer:
|
|
1190 if () { or if ()
|
|
1191 } {
|
|
1192 }
|
|
1193 and the cursor is between the parentheses. The user can then type some
|
|
1194 boolean expression within the parens. Having done that, typing
|
|
1195 \\[cperl-linefeed] places you, appropriately indented on a new line
|
|
1196 between the braces. If CPerl decides that you want to insert
|
|
1197 \"English\" style construct like
|
|
1198 bite if angry;
|
|
1199 it will not do any expansion. See also help on variable
|
|
1200 `cperl-extra-newline-before-brace'.
|
|
1201
|
4
|
1202 \\[cperl-linefeed] is a convenience replacement for typing carriage
|
0
|
1203 return. It places you in the next line with proper indentation, or if
|
|
1204 you type it inside the inline block of control construct, like
|
|
1205 foreach (@lines) {print; print}
|
|
1206 and you are on a boundary of a statement inside braces, it will
|
|
1207 transform the construct into a multiline and will place you into an
|
4
|
1208 appropriately indented blank line. If you need a usual
|
0
|
1209 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
|
|
1210 see documentation on `cperl-electric-linefeed'.
|
|
1211
|
|
1212 \\{cperl-mode-map}
|
|
1213
|
|
1214 Setting the variable `cperl-font-lock' to t switches on
|
|
1215 font-lock-mode, `cperl-electric-lbrace-space' to t switches on
|
|
1216 electric space between $ and {, `cperl-electric-parens-string' is the
|
|
1217 string that contains parentheses that should be electric in CPerl (see
|
|
1218 also `cperl-electric-parens-mark' and `cperl-electric-parens'),
|
|
1219 setting `cperl-electric-keywords' enables electric expansion of
|
|
1220 control structures in CPerl. `cperl-electric-linefeed' governs which
|
|
1221 one of two linefeed behavior is preferable. You can enable all these
|
|
1222 options simultaneously (recommended mode of use) by setting
|
|
1223 `cperl-hairy' to t. In this case you can switch separate options off
|
|
1224 by setting them to `null'. Note that one may undo the extra whitespace
|
|
1225 inserted by semis and braces in `auto-newline'-mode by consequent
|
|
1226 \\[cperl-electric-backspace].
|
|
1227
|
|
1228 If your site has perl5 documentation in info format, you can use commands
|
|
1229 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
|
|
1230 These keys run commands `cperl-info-on-current-command' and
|
|
1231 `cperl-info-on-command', which one is which is controlled by variable
|
|
1232 `cperl-info-on-command-no-prompt' (in turn affected by `cperl-hairy').
|
|
1233
|
4
|
1234 Even if you have no info-format documentation, short one-liner-style
|
|
1235 help is available on \\[cperl-get-help].
|
|
1236
|
|
1237 It is possible to show this help automatically after some idle
|
|
1238 time. This is regulated by variable `cperl-lazy-help-time'. Default
|
|
1239 with `cperl-hairy' is 5 secs idle time if the value of this variable
|
|
1240 is nil. It is also possible to switch this on/off from the
|
|
1241 menu. Requires `run-with-idle-timer'.
|
|
1242
|
193
|
1243 Use \\[cperl-lineup] to vertically lineup some construction - put the
|
|
1244 beginning of the region at the start of construction, and make region
|
|
1245 span the needed amount of lines.
|
|
1246
|
0
|
1247 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
|
|
1248 `cperl-pod-face', `cperl-pod-head-face' control processing of pod and
|
|
1249 here-docs sections. In a future version results of scan may be used
|
|
1250 for indentation too, currently they are used for highlighting only.
|
|
1251
|
|
1252 Variables controlling indentation style:
|
|
1253 `cperl-tab-always-indent'
|
|
1254 Non-nil means TAB in CPerl mode should always reindent the current line,
|
|
1255 regardless of where in the line point is when the TAB command is used.
|
|
1256 `cperl-auto-newline'
|
|
1257 Non-nil means automatically newline before and after braces,
|
|
1258 and after colons and semicolons, inserted in Perl code. The following
|
|
1259 \\[cperl-electric-backspace] will remove the inserted whitespace.
|
|
1260 Insertion after colons requires both this variable and
|
|
1261 `cperl-auto-newline-after-colon' set.
|
|
1262 `cperl-auto-newline-after-colon'
|
|
1263 Non-nil means automatically newline even after colons.
|
|
1264 Subject to `cperl-auto-newline' setting.
|
|
1265 `cperl-indent-level'
|
|
1266 Indentation of Perl statements within surrounding block.
|
|
1267 The surrounding block's indentation is the indentation
|
|
1268 of the line on which the open-brace appears.
|
|
1269 `cperl-continued-statement-offset'
|
|
1270 Extra indentation given to a substatement, such as the
|
|
1271 then-clause of an if, or body of a while, or just a statement continuation.
|
|
1272 `cperl-continued-brace-offset'
|
|
1273 Extra indentation given to a brace that starts a substatement.
|
|
1274 This is in addition to `cperl-continued-statement-offset'.
|
|
1275 `cperl-brace-offset'
|
|
1276 Extra indentation for line if it starts with an open brace.
|
|
1277 `cperl-brace-imaginary-offset'
|
|
1278 An open brace following other text is treated as if it the line started
|
|
1279 this far to the right of the actual line indentation.
|
|
1280 `cperl-label-offset'
|
|
1281 Extra indentation for line that is a label.
|
|
1282 `cperl-min-label-indent'
|
|
1283 Minimal indentation for line that is a label.
|
|
1284
|
|
1285 Settings for K&R and BSD indentation styles are
|
|
1286 `cperl-indent-level' 5 8
|
|
1287 `cperl-continued-statement-offset' 5 8
|
|
1288 `cperl-brace-offset' -5 -8
|
|
1289 `cperl-label-offset' -5 -8
|
|
1290
|
|
1291 If `cperl-indent-level' is 0, the statement after opening brace in column 0 is indented on `cperl-brace-offset'+`cperl-continued-statement-offset'.
|
|
1292
|
|
1293 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
|
|
1294 with no args."
|
|
1295 (interactive)
|
|
1296 (kill-all-local-variables)
|
|
1297 ;;(if cperl-hairy
|
|
1298 ;; (progn
|
|
1299 ;; (cperl-set 'cperl-font-lock cperl-hairy)
|
|
1300 ;; (cperl-set 'cperl-electric-lbrace-space cperl-hairy)
|
|
1301 ;; (cperl-set 'cperl-electric-parens "{[(<")
|
|
1302 ;; (cperl-set 'cperl-electric-keywords cperl-hairy)
|
|
1303 ;; (cperl-set 'cperl-electric-linefeed cperl-hairy)))
|
|
1304 (use-local-map cperl-mode-map)
|
|
1305 (if (cperl-val 'cperl-electric-linefeed)
|
|
1306 (progn
|
|
1307 (local-set-key "\C-J" 'cperl-linefeed)
|
|
1308 (local-set-key "\C-C\C-J" 'newline-and-indent)))
|
|
1309 (if (cperl-val 'cperl-info-on-command-no-prompt)
|
|
1310 (progn
|
193
|
1311 ;; don't clobber the backspace binding for Ye Olde Emacs
|
|
1312 ;;(cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
|
|
1313 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [f1 f])
|
4
|
1314 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
|
|
1315 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
|
|
1316 [(control c) (control h) f])))
|
193
|
1317 (setq major-mode 'perl-mode
|
|
1318 mode-name "CPerl"
|
|
1319 cperl-mode t)
|
0
|
1320 (if (not cperl-mode-abbrev-table)
|
|
1321 (let ((prev-a-c abbrevs-changed))
|
|
1322 (define-abbrev-table 'cperl-mode-abbrev-table '(
|
|
1323 ("if" "if" cperl-electric-keyword 0)
|
|
1324 ("elsif" "elsif" cperl-electric-keyword 0)
|
|
1325 ("while" "while" cperl-electric-keyword 0)
|
|
1326 ("until" "until" cperl-electric-keyword 0)
|
|
1327 ("unless" "unless" cperl-electric-keyword 0)
|
|
1328 ("else" "else" cperl-electric-else 0)
|
|
1329 ("for" "for" cperl-electric-keyword 0)
|
|
1330 ("foreach" "foreach" cperl-electric-keyword 0)
|
|
1331 ("do" "do" cperl-electric-keyword 0)))
|
|
1332 (setq abbrevs-changed prev-a-c)))
|
|
1333 (setq local-abbrev-table cperl-mode-abbrev-table)
|
|
1334 (abbrev-mode (if (cperl-val 'cperl-electric-keywords) 1 0))
|
|
1335 (set-syntax-table cperl-mode-syntax-table)
|
|
1336 (make-local-variable 'paragraph-start)
|
|
1337 (setq paragraph-start (concat "^$\\|" page-delimiter))
|
|
1338 (make-local-variable 'paragraph-separate)
|
|
1339 (setq paragraph-separate paragraph-start)
|
|
1340 (make-local-variable 'paragraph-ignore-fill-prefix)
|
|
1341 (setq paragraph-ignore-fill-prefix t)
|
|
1342 (make-local-variable 'indent-line-function)
|
|
1343 (setq indent-line-function 'cperl-indent-line)
|
|
1344 (make-local-variable 'require-final-newline)
|
|
1345 (setq require-final-newline t)
|
|
1346 (make-local-variable 'comment-start)
|
|
1347 (setq comment-start "# ")
|
|
1348 (make-local-variable 'comment-end)
|
|
1349 (setq comment-end "")
|
|
1350 (make-local-variable 'comment-column)
|
|
1351 (setq comment-column cperl-comment-column)
|
|
1352 (make-local-variable 'comment-start-skip)
|
|
1353 (setq comment-start-skip "#+ *")
|
|
1354 (make-local-variable 'defun-prompt-regexp)
|
193
|
1355 (setq defun-prompt-regexp "^[ \t]*sub[ \t]+\\([^ \t\n{(;]+\\)[ \t]*")
|
0
|
1356 (make-local-variable 'comment-indent-function)
|
|
1357 (setq comment-indent-function 'cperl-comment-indent)
|
|
1358 (make-local-variable 'parse-sexp-ignore-comments)
|
|
1359 (setq parse-sexp-ignore-comments t)
|
|
1360 (make-local-variable 'indent-region-function)
|
|
1361 (setq indent-region-function 'cperl-indent-region)
|
|
1362 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
|
|
1363 (make-local-variable 'imenu-create-index-function)
|
|
1364 (setq imenu-create-index-function
|
|
1365 (function imenu-example--create-perl-index))
|
|
1366 (make-local-variable 'imenu-sort-function)
|
|
1367 (setq imenu-sort-function nil)
|
|
1368 (make-local-variable 'vc-header-alist)
|
|
1369 (setq vc-header-alist cperl-vc-header-alist)
|
|
1370 (make-local-variable 'font-lock-defaults)
|
|
1371 (setq font-lock-defaults
|
|
1372 (if (string< emacs-version "19.30")
|
|
1373 '(perl-font-lock-keywords-2)
|
|
1374 '((perl-font-lock-keywords
|
|
1375 perl-font-lock-keywords-1
|
|
1376 perl-font-lock-keywords-2))))
|
193
|
1377 (if cperl-use-syntax-table-text-property
|
|
1378 (progn
|
|
1379 (make-variable-buffer-local 'parse-sexp-lookup-properties)
|
|
1380 ;; Do not introduce variable if not needed, we check it!
|
|
1381 (set 'parse-sexp-lookup-properties t)))
|
0
|
1382 (or (fboundp 'cperl-old-auto-fill-mode)
|
|
1383 (progn
|
|
1384 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
|
|
1385 (defun auto-fill-mode (&optional arg)
|
|
1386 (interactive "P")
|
|
1387 (cperl-old-auto-fill-mode arg)
|
|
1388 (and auto-fill-function (eq major-mode 'perl-mode)
|
|
1389 (setq auto-fill-function 'cperl-do-auto-fill)))))
|
|
1390 (if (cperl-enable-font-lock)
|
|
1391 (if (cperl-val 'cperl-font-lock)
|
|
1392 (progn (or cperl-faces-init (cperl-init-faces))
|
|
1393 (font-lock-mode 1))))
|
|
1394 (and (boundp 'msb-menu-cond)
|
|
1395 (not cperl-msb-fixed)
|
|
1396 (cperl-msb-fix))
|
4
|
1397 (if (featurep 'easymenu)
|
|
1398 (easy-menu-add cperl-menu)) ; A NOP under FSF Emacs.
|
0
|
1399 (run-hooks 'cperl-mode-hook)
|
|
1400 ;; After hooks since fontification will break this
|
|
1401 (if cperl-pod-here-scan (cperl-find-pods-heres)))
|
|
1402
|
4
|
1403 ;; Fix for perldb - make default reasonable
|
|
1404 (defun cperl-db ()
|
|
1405 (interactive)
|
|
1406 (require 'gud)
|
|
1407 (perldb (read-from-minibuffer "Run perldb (like this): "
|
|
1408 (if (consp gud-perldb-history)
|
|
1409 (car gud-perldb-history)
|
|
1410 (concat "perl " ;;(file-name-nondirectory
|
|
1411 ;; I have problems
|
|
1412 ;; in OS/2
|
|
1413 ;; otherwise
|
|
1414 (buffer-file-name)))
|
|
1415 nil nil
|
|
1416 '(gud-perldb-history . 1))))
|
|
1417
|
0
|
1418 ;; Fix for msb.el
|
|
1419 (defvar cperl-msb-fixed nil)
|
|
1420
|
|
1421 (defun cperl-msb-fix ()
|
|
1422 ;; Adds perl files to msb menu, supposes that msb is already loaded
|
|
1423 (setq cperl-msb-fixed t)
|
|
1424 (let* ((l (length msb-menu-cond))
|
|
1425 (last (nth (1- l) msb-menu-cond))
|
|
1426 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
|
|
1427 (handle (1- (nth 1 last))))
|
|
1428 (setcdr precdr (list
|
|
1429 (list
|
|
1430 '(eq major-mode 'perl-mode)
|
|
1431 handle
|
|
1432 "Perl Files (%d)")
|
|
1433 last))))
|
|
1434
|
|
1435 ;; This is used by indent-for-comment
|
|
1436 ;; to decide how much to indent a comment in CPerl code
|
|
1437 ;; based on its context. Do fallback if comment is found wrong.
|
|
1438
|
|
1439 (defvar cperl-wrong-comment)
|
|
1440
|
|
1441 (defun cperl-comment-indent ()
|
|
1442 (let ((p (point)) (c (current-column)) was)
|
|
1443 (if (looking-at "^#") 0 ; Existing comment at bol stays there.
|
|
1444 ;; Wrong comment found
|
|
1445 (save-excursion
|
|
1446 (setq was (cperl-to-comment-or-eol))
|
|
1447 (if (= (point) p)
|
|
1448 (progn
|
|
1449 (skip-chars-backward " \t")
|
|
1450 (max (1+ (current-column)) ; Else indent at comment column
|
|
1451 comment-column))
|
|
1452 (if was nil
|
|
1453 (insert comment-start)
|
|
1454 (backward-char (length comment-start)))
|
|
1455 (setq cperl-wrong-comment t)
|
|
1456 (indent-to comment-column 1) ; Indent minimum 1
|
|
1457 c))))) ; except leave at least one space.
|
|
1458
|
|
1459 ;;;(defun cperl-comment-indent-fallback ()
|
|
1460 ;;; "Is called if the standard comment-search procedure fails.
|
|
1461 ;;;Point is at start of real comment."
|
|
1462 ;;; (let ((c (current-column)) target cnt prevc)
|
|
1463 ;;; (if (= c comment-column) nil
|
|
1464 ;;; (setq cnt (skip-chars-backward "[ \t]"))
|
|
1465 ;;; (setq target (max (1+ (setq prevc
|
|
1466 ;;; (current-column))) ; Else indent at comment column
|
|
1467 ;;; comment-column))
|
|
1468 ;;; (if (= c comment-column) nil
|
|
1469 ;;; (delete-backward-char cnt)
|
|
1470 ;;; (while (< prevc target)
|
|
1471 ;;; (insert "\t")
|
|
1472 ;;; (setq prevc (current-column)))
|
|
1473 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
|
|
1474 ;;; (while (< prevc target)
|
|
1475 ;;; (insert " ")
|
|
1476 ;;; (setq prevc (current-column)))))))
|
|
1477
|
|
1478 (defun cperl-indent-for-comment ()
|
4
|
1479 "Substitute for `indent-for-comment' in CPerl."
|
0
|
1480 (interactive)
|
|
1481 (let (cperl-wrong-comment)
|
|
1482 (indent-for-comment)
|
|
1483 (if cperl-wrong-comment
|
|
1484 (progn (cperl-to-comment-or-eol)
|
|
1485 (forward-char (length comment-start))))))
|
|
1486
|
4
|
1487 (defun cperl-comment-region (b e arg)
|
|
1488 "Comment or uncomment each line in the region in CPerl mode.
|
|
1489 See `comment-region'."
|
|
1490 (interactive "r\np")
|
|
1491 (let ((comment-start "#"))
|
|
1492 (comment-region b e arg)))
|
|
1493
|
|
1494 (defun cperl-uncomment-region (b e arg)
|
|
1495 "Uncomment or comment each line in the region in CPerl mode.
|
|
1496 See `comment-region'."
|
|
1497 (interactive "r\np")
|
|
1498 (let ((comment-start "#"))
|
|
1499 (comment-region b e (- arg))))
|
|
1500
|
|
1501 (defvar cperl-brace-recursing nil)
|
|
1502
|
0
|
1503 (defun cperl-electric-brace (arg &optional only-before)
|
|
1504 "Insert character and correct line's indentation.
|
|
1505 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
|
|
1506 place (even in empty line), but not after. If after \")\" and the inserted
|
|
1507 char is \"{\", insert extra newline before only if
|
|
1508 `cperl-extra-newline-before-brace'."
|
|
1509 (interactive "P")
|
4
|
1510 (let (insertpos
|
|
1511 (other-end (if (and cperl-electric-parens-mark
|
|
1512 (cperl-mark-active)
|
|
1513 (< (mark) (point)))
|
|
1514 (mark)
|
|
1515 nil)))
|
|
1516 (if (and other-end
|
|
1517 (not cperl-brace-recursing)
|
|
1518 (cperl-val 'cperl-electric-parens)
|
|
1519 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
|
|
1520 ;; Need to insert a matching pair
|
0
|
1521 (progn
|
|
1522 (save-excursion
|
4
|
1523 (setq insertpos (point-marker))
|
|
1524 (goto-char other-end)
|
|
1525 (setq last-command-char ?\{)
|
|
1526 (cperl-electric-lbrace arg insertpos))
|
|
1527 (forward-char 1))
|
|
1528 (if (and (not arg) ; No args, end (of empty line or auto)
|
|
1529 (eolp)
|
|
1530 (or (and (null only-before)
|
|
1531 (save-excursion
|
|
1532 (skip-chars-backward " \t")
|
|
1533 (bolp)))
|
|
1534 (and (eq last-command-char ?\{) ; Do not insert newline
|
|
1535 ;; if after ")" and `cperl-extra-newline-before-brace'
|
|
1536 ;; is nil, do not insert extra newline.
|
|
1537 (not cperl-extra-newline-before-brace)
|
|
1538 (save-excursion
|
|
1539 (skip-chars-backward " \t")
|
|
1540 (eq (preceding-char) ?\))))
|
|
1541 (if cperl-auto-newline
|
|
1542 (progn (cperl-indent-line) (newline) t) nil)))
|
|
1543 (progn
|
|
1544 (insert last-command-char)
|
|
1545 (cperl-indent-line)
|
110
|
1546 (if cperl-auto-newline
|
|
1547 (setq insertpos (1- (point))))
|
4
|
1548 (if (and cperl-auto-newline (null only-before))
|
|
1549 (progn
|
|
1550 (newline)
|
|
1551 (cperl-indent-line)))
|
|
1552 (save-excursion
|
|
1553 (if insertpos (progn (goto-char insertpos)
|
|
1554 (search-forward (make-string
|
|
1555 1 last-command-char))
|
|
1556 (setq insertpos (1- (point)))))
|
|
1557 (delete-char -1))))
|
|
1558 (if insertpos
|
|
1559 (save-excursion
|
|
1560 (goto-char insertpos)
|
|
1561 (self-insert-command (prefix-numeric-value arg)))
|
|
1562 (self-insert-command (prefix-numeric-value arg))))))
|
|
1563
|
|
1564 (defun cperl-electric-lbrace (arg &optional end)
|
0
|
1565 "Insert character, correct line's indentation, correct quoting by space."
|
|
1566 (interactive "P")
|
|
1567 (let (pos after
|
4
|
1568 (cperl-brace-recursing t)
|
0
|
1569 (cperl-auto-newline cperl-auto-newline)
|
4
|
1570 (other-end (or end
|
|
1571 (if (and cperl-electric-parens-mark
|
|
1572 (cperl-mark-active)
|
|
1573 (> (mark) (point)))
|
|
1574 (save-excursion
|
|
1575 (goto-char (mark))
|
|
1576 (point-marker))
|
|
1577 nil))))
|
0
|
1578 (and (cperl-val 'cperl-electric-lbrace-space)
|
|
1579 (eq (preceding-char) ?$)
|
|
1580 (save-excursion
|
|
1581 (skip-chars-backward "$")
|
|
1582 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
|
|
1583 (insert ? ))
|
193
|
1584 (if (cperl-after-expr-p nil "{;)") nil (setq cperl-auto-newline nil))
|
0
|
1585 (cperl-electric-brace arg)
|
|
1586 (and (cperl-val 'cperl-electric-parens)
|
|
1587 (eq last-command-char ?{)
|
|
1588 (memq last-command-char
|
|
1589 (append cperl-electric-parens-string nil))
|
|
1590 (or (if other-end (goto-char (marker-position other-end)))
|
|
1591 t)
|
|
1592 (setq last-command-char ?} pos (point))
|
|
1593 (progn (cperl-electric-brace arg t)
|
|
1594 (goto-char pos)))))
|
|
1595
|
|
1596 (defun cperl-electric-paren (arg)
|
|
1597 "Insert a matching pair of parentheses."
|
|
1598 (interactive "P")
|
|
1599 (let ((beg (save-excursion (beginning-of-line) (point)))
|
|
1600 (other-end (if (and cperl-electric-parens-mark
|
|
1601 (cperl-mark-active)
|
|
1602 (> (mark) (point)))
|
|
1603 (save-excursion
|
|
1604 (goto-char (mark))
|
|
1605 (point-marker))
|
|
1606 nil)))
|
|
1607 (if (and (cperl-val 'cperl-electric-parens)
|
|
1608 (memq last-command-char
|
|
1609 (append cperl-electric-parens-string nil))
|
|
1610 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
|
|
1611 ;;(not (save-excursion (search-backward "#" beg t)))
|
|
1612 (if (eq last-command-char ?<)
|
193
|
1613 (cperl-after-expr-p nil "{;(,:=")
|
0
|
1614 1))
|
|
1615 (progn
|
|
1616 (insert last-command-char)
|
|
1617 (if other-end (goto-char (marker-position other-end)))
|
|
1618 (insert (cdr (assoc last-command-char '((?{ .?})
|
|
1619 (?[ . ?])
|
|
1620 (?( . ?))
|
|
1621 (?< . ?>)))))
|
|
1622 (forward-char -1))
|
|
1623 (insert last-command-char)
|
|
1624 )))
|
|
1625
|
4
|
1626 (defun cperl-electric-rparen (arg)
|
|
1627 "Insert a matching pair of parentheses if marking is active.
|
|
1628 If not, or if we are not at the end of marking range, would self-insert."
|
|
1629 (interactive "P")
|
|
1630 (let ((beg (save-excursion (beginning-of-line) (point)))
|
|
1631 (other-end (if (and cperl-electric-parens-mark
|
110
|
1632 (cperl-val 'cperl-electric-parens)
|
|
1633 (memq last-command-char
|
|
1634 (append cperl-electric-parens-string nil))
|
4
|
1635 (cperl-mark-active)
|
|
1636 (< (mark) (point)))
|
|
1637 (mark)
|
|
1638 nil))
|
|
1639 p)
|
|
1640 (if (and other-end
|
|
1641 (cperl-val 'cperl-electric-parens)
|
|
1642 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
|
|
1643 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
|
|
1644 ;;(not (save-excursion (search-backward "#" beg t)))
|
|
1645 )
|
|
1646 (progn
|
|
1647 (insert last-command-char)
|
|
1648 (setq p (point))
|
|
1649 (if other-end (goto-char other-end))
|
|
1650 (insert (cdr (assoc last-command-char '((?\} . ?\{)
|
|
1651 (?\] . ?\[)
|
|
1652 (?\) . ?\()
|
|
1653 (?\> . ?\<)))))
|
|
1654 (goto-char (1+ p)))
|
|
1655 (call-interactively 'self-insert-command)
|
|
1656 )))
|
|
1657
|
0
|
1658 (defun cperl-electric-keyword ()
|
|
1659 "Insert a construction appropriate after a keyword."
|
|
1660 (let ((beg (save-excursion (beginning-of-line) (point)))
|
4
|
1661 (dollar (eq last-command-char ?$)))
|
0
|
1662 (and (save-excursion
|
|
1663 (backward-sexp 1)
|
193
|
1664 (cperl-after-expr-p nil "{;:"))
|
0
|
1665 (save-excursion
|
|
1666 (not
|
|
1667 (re-search-backward
|
|
1668 "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>"
|
|
1669 beg t)))
|
|
1670 (save-excursion (or (not (re-search-backward "^=" nil t))
|
|
1671 (looking-at "=cut")))
|
|
1672 (progn
|
|
1673 (and dollar (insert " $"))
|
|
1674 (cperl-indent-line)
|
|
1675 ;;(insert " () {\n}")
|
|
1676 (cond
|
|
1677 (cperl-extra-newline-before-brace
|
|
1678 (insert " ()\n")
|
|
1679 (insert "{")
|
|
1680 (cperl-indent-line)
|
|
1681 (insert "\n")
|
|
1682 (cperl-indent-line)
|
|
1683 (insert "\n}"))
|
|
1684 (t
|
|
1685 (insert " () {\n}"))
|
|
1686 )
|
|
1687 (or (looking-at "[ \t]\\|$") (insert " "))
|
|
1688 (cperl-indent-line)
|
|
1689 (if dollar (progn (search-backward "$")
|
|
1690 (forward-char 1))
|
|
1691 (search-backward ")"))
|
|
1692 (cperl-putback-char del-back-ch)))))
|
|
1693
|
|
1694 (defun cperl-electric-else ()
|
|
1695 "Insert a construction appropriate after a keyword."
|
|
1696 (let ((beg (save-excursion (beginning-of-line) (point))))
|
|
1697 (and (save-excursion
|
|
1698 (backward-sexp 1)
|
193
|
1699 (cperl-after-expr-p nil "{;:"))
|
0
|
1700 (save-excursion
|
|
1701 (not
|
|
1702 (re-search-backward
|
|
1703 "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>"
|
|
1704 beg t)))
|
|
1705 (save-excursion (or (not (re-search-backward "^=" nil t))
|
|
1706 (looking-at "=cut")))
|
|
1707 (progn
|
|
1708 (cperl-indent-line)
|
|
1709 ;;(insert " {\n\n}")
|
|
1710 (cond
|
|
1711 (cperl-extra-newline-before-brace
|
|
1712 (insert "\n")
|
|
1713 (insert "{")
|
|
1714 (cperl-indent-line)
|
|
1715 (insert "\n\n}"))
|
|
1716 (t
|
|
1717 (insert " {\n\n}"))
|
|
1718 )
|
|
1719 (or (looking-at "[ \t]\\|$") (insert " "))
|
|
1720 (cperl-indent-line)
|
|
1721 (forward-line -1)
|
|
1722 (cperl-indent-line)
|
|
1723 (cperl-putback-char del-back-ch)))))
|
|
1724
|
|
1725 (defun cperl-linefeed ()
|
|
1726 "Go to end of line, open a new line and indent appropriately."
|
|
1727 (interactive)
|
|
1728 (let ((beg (save-excursion (beginning-of-line) (point)))
|
|
1729 (end (save-excursion (end-of-line) (point)))
|
|
1730 (pos (point)) start)
|
|
1731 (if (and ; Check if we need to split:
|
|
1732 ; i.e., on a boundary and inside "{...}"
|
|
1733 (save-excursion (cperl-to-comment-or-eol)
|
4
|
1734 (>= (point) pos)) ; Not in a comment
|
0
|
1735 (or (save-excursion
|
|
1736 (skip-chars-backward " \t" beg)
|
|
1737 (forward-char -1)
|
4
|
1738 (looking-at "[;{]")) ; After { or ; + spaces
|
|
1739 (looking-at "[ \t]*}") ; Before }
|
|
1740 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
|
0
|
1741 (save-excursion
|
|
1742 (and
|
4
|
1743 (eq (car (parse-partial-sexp pos end -1)) -1)
|
|
1744 ; Leave the level of parens
|
0
|
1745 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
|
4
|
1746 ; Are at end
|
0
|
1747 (progn
|
|
1748 (backward-sexp 1)
|
|
1749 (setq start (point-marker))
|
4
|
1750 (<= start pos))))) ; Redundant? Are after the
|
|
1751 ; start of parens group.
|
0
|
1752 (progn
|
|
1753 (skip-chars-backward " \t")
|
|
1754 (or (memq (preceding-char) (append ";{" nil))
|
|
1755 (insert ";"))
|
|
1756 (insert "\n")
|
|
1757 (forward-line -1)
|
|
1758 (cperl-indent-line)
|
|
1759 (goto-char start)
|
|
1760 (or (looking-at "{[ \t]*$") ; If there is a statement
|
|
1761 ; before, move it to separate line
|
|
1762 (progn
|
|
1763 (forward-char 1)
|
|
1764 (insert "\n")
|
|
1765 (cperl-indent-line)))
|
|
1766 (forward-line 1) ; We are on the target line
|
|
1767 (cperl-indent-line)
|
|
1768 (beginning-of-line)
|
|
1769 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
|
|
1770 ; after, move it to separate line
|
|
1771 (progn
|
|
1772 (end-of-line)
|
|
1773 (search-backward "}" beg)
|
|
1774 (skip-chars-backward " \t")
|
|
1775 (or (memq (preceding-char) (append ";{" nil))
|
|
1776 (insert ";"))
|
|
1777 (insert "\n")
|
|
1778 (cperl-indent-line)
|
|
1779 (forward-line -1)))
|
|
1780 (forward-line -1) ; We are on the line before target
|
|
1781 (end-of-line)
|
|
1782 (newline-and-indent))
|
|
1783 (end-of-line) ; else
|
4
|
1784 (cond
|
|
1785 ((and (looking-at "\n[ \t]*{$")
|
|
1786 (save-excursion
|
|
1787 (skip-chars-backward " \t")
|
|
1788 (eq (preceding-char) ?\)))) ; Probably if () {} group
|
|
1789 ; with an extra newline.
|
|
1790 (forward-line 2)
|
|
1791 (cperl-indent-line))
|
|
1792 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
|
|
1793 (forward-line 1)
|
|
1794 (cperl-indent-line))
|
|
1795 (t
|
|
1796 (newline-and-indent))))))
|
0
|
1797
|
|
1798 (defun cperl-electric-semi (arg)
|
|
1799 "Insert character and correct line's indentation."
|
|
1800 (interactive "P")
|
|
1801 (if cperl-auto-newline
|
|
1802 (cperl-electric-terminator arg)
|
|
1803 (self-insert-command (prefix-numeric-value arg))))
|
|
1804
|
|
1805 (defun cperl-electric-terminator (arg)
|
|
1806 "Insert character and correct line's indentation."
|
|
1807 (interactive "P")
|
|
1808 (let (insertpos (end (point))
|
|
1809 (auto (and cperl-auto-newline
|
|
1810 (or (not (eq last-command-char ?:))
|
|
1811 cperl-auto-newline-after-colon))))
|
4
|
1812 (if (and ;;(not arg)
|
|
1813 (eolp)
|
0
|
1814 (not (save-excursion
|
|
1815 (beginning-of-line)
|
|
1816 (skip-chars-forward " \t")
|
|
1817 (or
|
|
1818 ;; Ignore in comment lines
|
|
1819 (= (following-char) ?#)
|
|
1820 ;; Colon is special only after a label
|
|
1821 ;; So quickly rule out most other uses of colon
|
|
1822 ;; and do no indentation for them.
|
|
1823 (and (eq last-command-char ?:)
|
|
1824 (save-excursion
|
|
1825 (forward-word 1)
|
|
1826 (skip-chars-forward " \t")
|
|
1827 (and (< (point) end)
|
|
1828 (progn (goto-char (- end 1))
|
|
1829 (not (looking-at ":"))))))
|
|
1830 (progn
|
|
1831 (beginning-of-defun)
|
|
1832 (let ((pps (parse-partial-sexp (point) end)))
|
|
1833 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
|
|
1834 (progn
|
|
1835 (insert last-command-char)
|
4
|
1836 ;;(forward-char -1)
|
0
|
1837 (if auto (setq insertpos (point-marker)))
|
4
|
1838 ;;(forward-char 1)
|
0
|
1839 (cperl-indent-line)
|
|
1840 (if auto
|
|
1841 (progn
|
|
1842 (newline)
|
|
1843 (cperl-indent-line)))
|
|
1844 ;; (save-excursion
|
|
1845 ;; (if insertpos (progn (goto-char (marker-position insertpos))
|
|
1846 ;; (search-forward (make-string
|
|
1847 ;; 1 last-command-char))
|
|
1848 ;; (setq insertpos (1- (point)))))
|
|
1849 ;; (delete-char -1))))
|
|
1850 (save-excursion
|
4
|
1851 (if insertpos (goto-char (1- (marker-position insertpos)))
|
0
|
1852 (forward-char -1))
|
|
1853 (delete-char 1))))
|
|
1854 (if insertpos
|
|
1855 (save-excursion
|
|
1856 (goto-char insertpos)
|
|
1857 (self-insert-command (prefix-numeric-value arg)))
|
|
1858 (self-insert-command (prefix-numeric-value arg)))))
|
|
1859
|
|
1860 (defun cperl-electric-backspace (arg)
|
|
1861 "Backspace-untabify, or remove the whitespace inserted by an electric key."
|
193
|
1862 (interactive "p")
|
161
|
1863 (if (and cperl-auto-newline
|
|
1864 (memq last-command '(cperl-electric-semi
|
|
1865 cperl-electric-terminator
|
|
1866 cperl-electric-lbrace))
|
|
1867 (memq (preceding-char) '(? ?\t ?\n)))
|
|
1868 (let (p)
|
|
1869 (if (eq last-command 'cperl-electric-lbrace)
|
|
1870 (skip-chars-forward " \t\n"))
|
|
1871 (setq p (point))
|
|
1872 (skip-chars-backward " \t\n")
|
|
1873 (delete-region (point) p))
|
|
1874 (backward-delete-char-untabify arg)))
|
|
1875
|
167
|
1876 ;; helper function for deletion, which honors the desired delete direction
|
|
1877 ;; behavior. Added by Gary D. Foster, <Gary.Foster@corp.sun.com> and bound
|
|
1878 ;; to the 'delete keysym by default.
|
|
1879
|
161
|
1880 (defun cperl-electric-delete (arg)
|
167
|
1881 "Delete, or remove the whitespace inserted by an electric key.
|
|
1882 Delete direction is controlled by the setting of `delete-key-deletes-forward'."
|
161
|
1883 (interactive "*p")
|
0
|
1884 (if (and cperl-auto-newline
|
|
1885 (memq last-command '(cperl-electric-semi
|
|
1886 cperl-electric-terminator
|
|
1887 cperl-electric-lbrace))
|
|
1888 (memq (preceding-char) '(? ?\t ?\n)))
|
|
1889 (let (p)
|
|
1890 (if (eq last-command 'cperl-electric-lbrace)
|
|
1891 (skip-chars-forward " \t\n"))
|
|
1892 (setq p (point))
|
|
1893 (skip-chars-backward " \t\n")
|
|
1894 (delete-region (point) p))
|
159
|
1895 (if (fboundp 'backward-or-forward-delete-char)
|
161
|
1896 (backward-or-forward-delete-char arg)
|
|
1897 (backward-delete-char-untabify arg))))
|
0
|
1898
|
|
1899 (defun cperl-inside-parens-p ()
|
|
1900 (condition-case ()
|
|
1901 (save-excursion
|
|
1902 (save-restriction
|
|
1903 (narrow-to-region (point)
|
|
1904 (progn (beginning-of-defun) (point)))
|
|
1905 (goto-char (point-max))
|
|
1906 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
|
|
1907 (error nil)))
|
|
1908
|
|
1909 (defun cperl-indent-command (&optional whole-exp)
|
|
1910 "Indent current line as Perl code, or in some cases insert a tab character.
|
|
1911 If `cperl-tab-always-indent' is non-nil (the default), always indent current line.
|
|
1912 Otherwise, indent the current line only if point is at the left margin
|
|
1913 or in the line's indentation; otherwise insert a tab.
|
|
1914
|
|
1915 A numeric argument, regardless of its value,
|
|
1916 means indent rigidly all the lines of the expression starting after point
|
|
1917 so that this line becomes properly indented.
|
|
1918 The relative indentation among the lines of the expression are preserved."
|
4
|
1919 (interactive "P")
|
0
|
1920 (if whole-exp
|
|
1921 ;; If arg, always indent this line as Perl
|
|
1922 ;; and shift remaining lines of expression the same amount.
|
|
1923 (let ((shift-amt (cperl-indent-line))
|
|
1924 beg end)
|
|
1925 (save-excursion
|
|
1926 (if cperl-tab-always-indent
|
|
1927 (beginning-of-line))
|
|
1928 (setq beg (point))
|
|
1929 (forward-sexp 1)
|
|
1930 (setq end (point))
|
|
1931 (goto-char beg)
|
|
1932 (forward-line 1)
|
|
1933 (setq beg (point)))
|
|
1934 (if (> end beg)
|
|
1935 (indent-code-rigidly beg end shift-amt "#")))
|
|
1936 (if (and (not cperl-tab-always-indent)
|
|
1937 (save-excursion
|
|
1938 (skip-chars-backward " \t")
|
|
1939 (not (bolp))))
|
|
1940 (insert-tab)
|
|
1941 (cperl-indent-line))))
|
|
1942
|
|
1943 (defun cperl-indent-line (&optional symbol)
|
|
1944 "Indent current line as Perl code.
|
|
1945 Return the amount the indentation changed by."
|
|
1946 (let (indent
|
|
1947 beg shift-amt
|
|
1948 (case-fold-search nil)
|
|
1949 (pos (- (point-max) (point))))
|
|
1950 (setq indent (cperl-calculate-indent nil symbol))
|
|
1951 (beginning-of-line)
|
|
1952 (setq beg (point))
|
193
|
1953 (cond ((or (eq indent nil) (eq indent t))
|
0
|
1954 (setq indent (current-indentation)))
|
|
1955 ;;((eq indent t) ; Never?
|
|
1956 ;; (setq indent (cperl-calculate-indent-within-comment)))
|
|
1957 ;;((looking-at "[ \t]*#")
|
|
1958 ;; (setq indent 0))
|
|
1959 (t
|
|
1960 (skip-chars-forward " \t")
|
|
1961 (if (listp indent) (setq indent (car indent)))
|
193
|
1962 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
|
0
|
1963 (and (> indent 0)
|
|
1964 (setq indent (max cperl-min-label-indent
|
|
1965 (+ indent cperl-label-offset)))))
|
|
1966 ((= (following-char) ?})
|
|
1967 (setq indent (- indent cperl-indent-level)))
|
|
1968 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
|
|
1969 (setq indent (+ indent cperl-close-paren-offset)))
|
|
1970 ((= (following-char) ?{)
|
|
1971 (setq indent (+ indent cperl-brace-offset))))))
|
|
1972 (skip-chars-forward " \t")
|
|
1973 (setq shift-amt (- indent (current-column)))
|
|
1974 (if (zerop shift-amt)
|
|
1975 (if (> (- (point-max) pos) (point))
|
|
1976 (goto-char (- (point-max) pos)))
|
|
1977 (delete-region beg (point))
|
|
1978 (indent-to indent)
|
|
1979 ;; If initial point was within line's indentation,
|
|
1980 ;; position after the indentation. Else stay at same point in text.
|
|
1981 (if (> (- (point-max) pos) (point))
|
|
1982 (goto-char (- (point-max) pos))))
|
|
1983 shift-amt))
|
|
1984
|
|
1985 (defun cperl-after-label ()
|
|
1986 ;; Returns true if the point is after label. Does not do save-excursion.
|
|
1987 (and (eq (preceding-char) ?:)
|
|
1988 (memq (char-syntax (char-after (- (point) 2)))
|
|
1989 '(?w ?_))
|
|
1990 (progn
|
|
1991 (backward-sexp)
|
4
|
1992 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
|
0
|
1993
|
|
1994 (defun cperl-get-state (&optional parse-start start-state)
|
|
1995 ;; returns list (START STATE DEPTH PRESTART), START is a good place
|
|
1996 ;; to start parsing, STATE is what is returned by
|
|
1997 ;; `parse-partial-sexp'. DEPTH is true is we are immediately after
|
|
1998 ;; end of block which contains START. PRESTART is the position
|
|
1999 ;; basing on which START was found.
|
|
2000 (save-excursion
|
|
2001 (let ((start-point (point)) depth state start prestart)
|
|
2002 (if parse-start
|
|
2003 (goto-char parse-start)
|
|
2004 (beginning-of-defun))
|
|
2005 (setq prestart (point))
|
|
2006 (if start-state nil
|
|
2007 ;; Try to go out, if sub is not on the outermost level
|
|
2008 (while (< (point) start-point)
|
|
2009 (setq start (point) parse-start start depth nil
|
|
2010 state (parse-partial-sexp start start-point -1))
|
|
2011 (if (> (car state) -1) nil
|
|
2012 ;; The current line could start like }}}, so the indentation
|
|
2013 ;; corresponds to a different level than what we reached
|
|
2014 (setq depth t)
|
|
2015 (beginning-of-line 2))) ; Go to the next line.
|
|
2016 (if start (goto-char start))) ; Not at the start of file
|
|
2017 (setq start (point))
|
|
2018 (if (< start start-point) (setq parse-start start))
|
|
2019 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
|
|
2020 (list start state depth prestart))))
|
|
2021
|
|
2022 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
|
|
2023 ;; Positions is before ?\{. Checks whether it starts a block.
|
|
2024 ;; No save-excursion!
|
|
2025 (cperl-backward-to-noncomment (point-min))
|
|
2026 ;;(skip-chars-backward " \t\n\f")
|
|
2027 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
|
|
2028 ; Label may be mixed up with `$blah :'
|
|
2029 (save-excursion (cperl-after-label))
|
4
|
2030 (and (memq (char-syntax (preceding-char)) '(?w ?_))
|
0
|
2031 (progn
|
|
2032 (backward-sexp)
|
|
2033 ;; Need take into account `bless', `return', `tr',...
|
4
|
2034 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
|
0
|
2035 (not (looking-at "\\(bless\\|return\\|qw\\|tr\\|[smy]\\)\\>")))
|
|
2036 (progn
|
|
2037 (skip-chars-backward " \t\n\f")
|
4
|
2038 (and (memq (char-syntax (preceding-char)) '(?w ?_))
|
0
|
2039 (progn
|
|
2040 (backward-sexp)
|
|
2041 (looking-at
|
193
|
2042 "sub[ \t]+[a-zA-Z0-9_:]+[ \t\n\f]*\\(([^()]*)[ \t\n\f]*\\)?[#{]")))))))))
|
|
2043
|
|
2044 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
|
0
|
2045
|
|
2046 (defun cperl-calculate-indent (&optional parse-start symbol)
|
|
2047 "Return appropriate indentation for current line as Perl code.
|
|
2048 In usual case returns an integer: the column to indent to.
|
|
2049 Returns nil if line starts inside a string, t if in a comment."
|
|
2050 (save-excursion
|
193
|
2051 (if (or
|
|
2052 (memq (get-text-property (point) 'syntax-type)
|
|
2053 '(pod here-doc here-doc-delim format))
|
|
2054 ;; before start of POD - whitespace found since do not have 'pod!
|
|
2055 (and (looking-at "[ \t]*\n=")
|
|
2056 (error "Spaces before pod section!"))
|
|
2057 (and (not cperl-indent-left-aligned-comments)
|
|
2058 (looking-at "^#")))
|
|
2059 nil
|
|
2060 (beginning-of-line)
|
|
2061 (let ((indent-point (point))
|
|
2062 (char-after (save-excursion
|
|
2063 (skip-chars-forward " \t")
|
|
2064 (following-char)))
|
|
2065 (in-pod (get-text-property (point) 'in-pod))
|
|
2066 (pre-indent-point (point))
|
|
2067 p prop look-prop)
|
|
2068 (cond
|
|
2069 (in-pod
|
|
2070 ;; In the verbatim part, probably code example. What to do???
|
|
2071 )
|
|
2072 (t
|
|
2073 (save-excursion
|
|
2074 ;; Not in pod
|
|
2075 (cperl-backward-to-noncomment nil)
|
|
2076 (setq p (max (point-min) (1- (point)))
|
|
2077 prop (get-text-property p 'syntax-type)
|
|
2078 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
|
|
2079 'syntax-type))
|
|
2080 (if (memq prop '(pod here-doc format here-doc-delim))
|
|
2081 (progn
|
|
2082 (goto-char (or (previous-single-property-change p look-prop)
|
|
2083 (point-min)))
|
|
2084 (beginning-of-line)
|
|
2085 (setq pre-indent-point (point)))))))
|
|
2086 (goto-char pre-indent-point)
|
|
2087 (let* ((case-fold-search nil)
|
0
|
2088 (s-s (cperl-get-state))
|
|
2089 (start (nth 0 s-s))
|
|
2090 (state (nth 1 s-s))
|
|
2091 (containing-sexp (car (cdr state)))
|
|
2092 (start-indent (save-excursion
|
|
2093 (goto-char start)
|
|
2094 (- (current-indentation)
|
|
2095 (if (nth 2 s-s) cperl-indent-level 0))))
|
|
2096 old-indent)
|
|
2097 ;; (or parse-start (null symbol)
|
|
2098 ;; (setq parse-start (symbol-value symbol)
|
|
2099 ;; start-indent (nth 2 parse-start)
|
|
2100 ;; parse-start (car parse-start)))
|
|
2101 ;; (if parse-start
|
|
2102 ;; (goto-char parse-start)
|
|
2103 ;; (beginning-of-defun))
|
|
2104 ;; ;; Try to go out
|
|
2105 ;; (while (< (point) indent-point)
|
|
2106 ;; (setq start (point) parse-start start moved nil
|
|
2107 ;; state (parse-partial-sexp start indent-point -1))
|
|
2108 ;; (if (> (car state) -1) nil
|
|
2109 ;; ;; The current line could start like }}}, so the indentation
|
|
2110 ;; ;; corresponds to a different level than what we reached
|
|
2111 ;; (setq moved t)
|
|
2112 ;; (beginning-of-line 2))) ; Go to the next line.
|
|
2113 ;; (if start ; Not at the start of file
|
|
2114 ;; (progn
|
|
2115 ;; (goto-char start)
|
|
2116 ;; (setq start-indent (current-indentation))
|
|
2117 ;; (if moved ; Should correct...
|
|
2118 ;; (setq start-indent (- start-indent cperl-indent-level))))
|
|
2119 ;; (setq start-indent 0))
|
|
2120 ;; (if (< (point) indent-point) (setq parse-start (point)))
|
|
2121 ;; (or state (setq state (parse-partial-sexp
|
|
2122 ;; (point) indent-point -1 nil start-state)))
|
|
2123 ;; (setq containing-sexp
|
|
2124 ;; (or (car (cdr state))
|
|
2125 ;; (and (>= (nth 6 state) 0) old-containing-sexp))
|
|
2126 ;; old-containing-sexp nil start-state nil)
|
|
2127 ;;;; (while (< (point) indent-point)
|
|
2128 ;;;; (setq parse-start (point))
|
|
2129 ;;;; (setq state (parse-partial-sexp (point) indent-point -1 nil start-state))
|
|
2130 ;;;; (setq containing-sexp
|
|
2131 ;;;; (or (car (cdr state))
|
|
2132 ;;;; (and (>= (nth 6 state) 0) old-containing-sexp))
|
|
2133 ;;;; old-containing-sexp nil start-state nil))
|
|
2134 ;; (if symbol (set symbol (list indent-point state start-indent)))
|
|
2135 ;; (goto-char indent-point)
|
|
2136 (cond ((or (nth 3 state) (nth 4 state))
|
|
2137 ;; return nil or t if should not change this line
|
|
2138 (nth 4 state))
|
|
2139 ((null containing-sexp)
|
|
2140 ;; Line is at top level. May be data or function definition,
|
|
2141 ;; or may be function argument declaration.
|
|
2142 ;; Indent like the previous top level line
|
|
2143 ;; unless that ends in a closeparen without semicolon,
|
|
2144 ;; in which case this line is the first argument decl.
|
|
2145 (skip-chars-forward " \t")
|
|
2146 (+ start-indent
|
|
2147 (if (= (following-char) ?{) cperl-continued-brace-offset 0)
|
|
2148 (progn
|
|
2149 (cperl-backward-to-noncomment (or parse-start (point-min)))
|
|
2150 ;;(skip-chars-backward " \t\f\n")
|
|
2151 ;; Look at previous line that's at column 0
|
|
2152 ;; to determine whether we are in top-level decls
|
|
2153 ;; or function's arg decls. Set basic-indent accordingly.
|
|
2154 ;; Now add a little if this is a continuation line.
|
|
2155 (if (or (bobp)
|
|
2156 (memq (preceding-char) (append " ;}" nil)) ; Was ?\)
|
4
|
2157 (memq char-after (append ")]}" nil))
|
|
2158 (and (eq (preceding-char) ?\:) ; label
|
|
2159 (progn
|
|
2160 (forward-sexp -1)
|
|
2161 (skip-chars-backward " \t")
|
|
2162 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:"))))
|
0
|
2163 0
|
|
2164 cperl-continued-statement-offset))))
|
|
2165 ((/= (char-after containing-sexp) ?{)
|
|
2166 ;; line is expression, not statement:
|
|
2167 ;; indent to just after the surrounding open,
|
|
2168 ;; skip blanks if we do not close the expression.
|
|
2169 (goto-char (1+ containing-sexp))
|
|
2170 (or (memq char-after (append ")]}" nil))
|
|
2171 (looking-at "[ \t]*\\(#\\|$\\)")
|
|
2172 (skip-chars-forward " \t"))
|
|
2173 (current-column))
|
|
2174 ((progn
|
|
2175 ;; Containing-expr starts with \{. Check whether it is a hash.
|
|
2176 (goto-char containing-sexp)
|
|
2177 (not (cperl-block-p)))
|
|
2178 (goto-char (1+ containing-sexp))
|
|
2179 (or (eq char-after ?\})
|
|
2180 (looking-at "[ \t]*\\(#\\|$\\)")
|
|
2181 (skip-chars-forward " \t"))
|
|
2182 (+ (current-column) ; Correct indentation of trailing ?\}
|
|
2183 (if (eq char-after ?\}) (+ cperl-indent-level
|
|
2184 cperl-close-paren-offset)
|
|
2185 0)))
|
|
2186 (t
|
|
2187 ;; Statement level. Is it a continuation or a new statement?
|
|
2188 ;; Find previous non-comment character.
|
193
|
2189 (goto-char pre-indent-point)
|
0
|
2190 (cperl-backward-to-noncomment containing-sexp)
|
|
2191 ;; Back up over label lines, since they don't
|
|
2192 ;; affect whether our line is a continuation.
|
|
2193 (while (or (eq (preceding-char) ?\,)
|
|
2194 (and (eq (preceding-char) ?:)
|
|
2195 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
|
|
2196 (memq (char-syntax (char-after (- (point) 2)))
|
|
2197 '(?w ?_)))))
|
|
2198 (if (eq (preceding-char) ?\,)
|
|
2199 ;; Will go to beginning of line, essentially.
|
|
2200 ;; Will ignore embedded sexpr XXXX.
|
|
2201 (cperl-backward-to-start-of-continued-exp containing-sexp))
|
|
2202 (beginning-of-line)
|
|
2203 (cperl-backward-to-noncomment containing-sexp))
|
|
2204 ;; Now we get the answer.
|
|
2205 (if (not (memq (preceding-char) (append ", ;}{" '(nil)))) ; Was ?\,
|
|
2206 ;; This line is continuation of preceding line's statement;
|
|
2207 ;; indent `cperl-continued-statement-offset' more than the
|
|
2208 ;; previous line of the statement.
|
|
2209 (progn
|
|
2210 (cperl-backward-to-start-of-continued-exp containing-sexp)
|
|
2211 (+ (if (memq char-after (append "}])" nil))
|
|
2212 0 ; Closing parenth
|
|
2213 cperl-continued-statement-offset)
|
|
2214 (current-column)
|
|
2215 (if (eq char-after ?\{)
|
|
2216 cperl-continued-brace-offset 0)))
|
|
2217 ;; This line starts a new statement.
|
|
2218 ;; Position following last unclosed open.
|
|
2219 (goto-char containing-sexp)
|
|
2220 ;; Is line first statement after an open-brace?
|
|
2221 (or
|
|
2222 ;; If no, find that first statement and indent like
|
|
2223 ;; it. If the first statement begins with label, do
|
4
|
2224 ;; not believe when the indentation of the label is too
|
0
|
2225 ;; small.
|
|
2226 (save-excursion
|
|
2227 (forward-char 1)
|
|
2228 (setq old-indent (current-indentation))
|
|
2229 (let ((colon-line-end 0))
|
|
2230 (while (progn (skip-chars-forward " \t\n")
|
|
2231 (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]"))
|
|
2232 ;; Skip over comments and labels following openbrace.
|
|
2233 (cond ((= (following-char) ?\#)
|
|
2234 (forward-line 1))
|
|
2235 ;; label:
|
|
2236 (t
|
|
2237 (save-excursion (end-of-line)
|
|
2238 (setq colon-line-end (point)))
|
|
2239 (search-forward ":"))))
|
|
2240 ;; The first following code counts
|
|
2241 ;; if it is before the line we want to indent.
|
|
2242 (and (< (point) indent-point)
|
|
2243 (if (> colon-line-end (point)) ; After label
|
|
2244 (if (> (current-indentation)
|
|
2245 cperl-min-label-indent)
|
|
2246 (- (current-indentation) cperl-label-offset)
|
4
|
2247 ;; Do not believe: `max' is involved
|
0
|
2248 (+ old-indent cperl-indent-level))
|
|
2249 (current-column)))))
|
|
2250 ;; If no previous statement,
|
|
2251 ;; indent it relative to line brace is on.
|
|
2252 ;; For open brace in column zero, don't let statement
|
|
2253 ;; start there too. If cperl-indent-level is zero,
|
|
2254 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
|
|
2255 ;; For open-braces not the first thing in a line,
|
|
2256 ;; add in cperl-brace-imaginary-offset.
|
|
2257
|
|
2258 ;; If first thing on a line: ?????
|
|
2259 (+ (if (and (bolp) (zerop cperl-indent-level))
|
|
2260 (+ cperl-brace-offset cperl-continued-statement-offset)
|
|
2261 cperl-indent-level)
|
|
2262 ;; Move back over whitespace before the openbrace.
|
|
2263 ;; If openbrace is not first nonwhite thing on the line,
|
|
2264 ;; add the cperl-brace-imaginary-offset.
|
|
2265 (progn (skip-chars-backward " \t")
|
|
2266 (if (bolp) 0 cperl-brace-imaginary-offset))
|
|
2267 ;; If the openbrace is preceded by a parenthesized exp,
|
|
2268 ;; move to the beginning of that;
|
|
2269 ;; possibly a different line
|
|
2270 (progn
|
|
2271 (if (eq (preceding-char) ?\))
|
|
2272 (forward-sexp -1))
|
|
2273 ;; In the case it starts a subroutine, indent with
|
4
|
2274 ;; respect to `sub', not with respect to the the
|
0
|
2275 ;; first thing on the line, say in the case of
|
|
2276 ;; anonymous sub in a hash.
|
|
2277 ;;
|
|
2278 (skip-chars-backward " \t")
|
|
2279 (if (and (eq (preceding-char) ?b)
|
|
2280 (progn
|
193
|
2281 (forward-sexp -1)
|
0
|
2282 (looking-at "sub\\>"))
|
|
2283 (setq old-indent
|
|
2284 (nth 1
|
|
2285 (parse-partial-sexp
|
|
2286 (save-excursion (beginning-of-line) (point))
|
|
2287 (point)))))
|
|
2288 (progn (goto-char (1+ old-indent))
|
|
2289 (skip-chars-forward " \t")
|
|
2290 (current-column))
|
|
2291 ;; Get initial indentation of the line we are on.
|
|
2292 ;; If line starts with label, calculate label indentation
|
|
2293 (if (save-excursion
|
|
2294 (beginning-of-line)
|
193
|
2295 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
|
0
|
2296 (if (> (current-indentation) cperl-min-label-indent)
|
|
2297 (- (current-indentation) cperl-label-offset)
|
|
2298 (cperl-calculate-indent
|
|
2299 (if (and parse-start (<= parse-start (point)))
|
|
2300 parse-start)))
|
193
|
2301 (current-indentation))))))))))))))
|
0
|
2302
|
|
2303 (defvar cperl-indent-alist
|
|
2304 '((string nil)
|
|
2305 (comment nil)
|
|
2306 (toplevel 0)
|
|
2307 (toplevel-after-parenth 2)
|
|
2308 (toplevel-continued 2)
|
|
2309 (expression 1))
|
|
2310 "Alist of indentation rules for CPerl mode.
|
|
2311 The values mean:
|
|
2312 nil: do not indent;
|
|
2313 number: add this amount of indentation.")
|
|
2314
|
|
2315 (defun cperl-where-am-i (&optional parse-start start-state)
|
|
2316 ;; Unfinished
|
|
2317 "Return a list of lists ((TYPE POS)...) of good points before the point.
|
|
2318 POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'."
|
|
2319 (save-excursion
|
|
2320 (let* ((start-point (point))
|
|
2321 (s-s (cperl-get-state))
|
|
2322 (start (nth 0 s-s))
|
|
2323 (state (nth 1 s-s))
|
|
2324 (prestart (nth 3 s-s))
|
|
2325 (containing-sexp (car (cdr state)))
|
|
2326 (case-fold-search nil)
|
|
2327 (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
|
|
2328 (cond ((nth 3 state) ; In string
|
|
2329 (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
|
|
2330 ((nth 4 state) ; In comment
|
|
2331 (setq res (cons '(comment) res)))
|
|
2332 ((null containing-sexp)
|
|
2333 ;; Line is at top level.
|
|
2334 ;; Indent like the previous top level line
|
|
2335 ;; unless that ends in a closeparen without semicolon,
|
|
2336 ;; in which case this line is the first argument decl.
|
|
2337 (cperl-backward-to-noncomment (or parse-start (point-min)))
|
|
2338 ;;(skip-chars-backward " \t\f\n")
|
|
2339 (cond
|
|
2340 ((or (bobp)
|
|
2341 (memq (preceding-char) (append ";}" nil)))
|
|
2342 (setq res (cons (list 'toplevel start) res)))
|
|
2343 ((eq (preceding-char) ?\) )
|
|
2344 (setq res (cons (list 'toplevel-after-parenth start) res)))
|
|
2345 (t
|
|
2346 (setq res (cons (list 'toplevel-continued start) res)))))
|
|
2347 ((/= (char-after containing-sexp) ?{)
|
|
2348 ;; line is expression, not statement:
|
|
2349 ;; indent to just after the surrounding open.
|
|
2350 ;; skip blanks if we do not close the expression.
|
|
2351 (setq res (cons (list 'expression-blanks
|
|
2352 (progn
|
|
2353 (goto-char (1+ containing-sexp))
|
|
2354 (or (looking-at "[ \t]*\\(#\\|$\\)")
|
|
2355 (skip-chars-forward " \t"))
|
|
2356 (point)))
|
|
2357 (cons (list 'expression containing-sexp) res))))
|
|
2358 ((progn
|
|
2359 ;; Containing-expr starts with \{. Check whether it is a hash.
|
|
2360 (goto-char containing-sexp)
|
|
2361 (not (cperl-block-p)))
|
|
2362 (setq res (cons (list 'expression-blanks
|
|
2363 (progn
|
|
2364 (goto-char (1+ containing-sexp))
|
|
2365 (or (looking-at "[ \t]*\\(#\\|$\\)")
|
|
2366 (skip-chars-forward " \t"))
|
|
2367 (point)))
|
|
2368 (cons (list 'expression containing-sexp) res))))
|
|
2369 (t
|
|
2370 ;; Statement level.
|
|
2371 (setq res (cons (list 'in-block containing-sexp) res))
|
|
2372 ;; Is it a continuation or a new statement?
|
|
2373 ;; Find previous non-comment character.
|
|
2374 (cperl-backward-to-noncomment containing-sexp)
|
|
2375 ;; Back up over label lines, since they don't
|
|
2376 ;; affect whether our line is a continuation.
|
|
2377 ;; Back up comma-delimited lines too ?????
|
|
2378 (while (or (eq (preceding-char) ?\,)
|
|
2379 (save-excursion (cperl-after-label)))
|
|
2380 (if (eq (preceding-char) ?\,)
|
|
2381 ;; Will go to beginning of line, essentially
|
|
2382 ;; Will ignore embedded sexpr XXXX.
|
|
2383 (cperl-backward-to-start-of-continued-exp containing-sexp))
|
|
2384 (beginning-of-line)
|
|
2385 (cperl-backward-to-noncomment containing-sexp))
|
|
2386 ;; Now we get the answer.
|
|
2387 (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
|
|
2388 ;; This line is continuation of preceding line's statement.
|
|
2389 (list (list 'statement-continued containing-sexp))
|
|
2390 ;; This line starts a new statement.
|
|
2391 ;; Position following last unclosed open.
|
|
2392 (goto-char containing-sexp)
|
|
2393 ;; Is line first statement after an open-brace?
|
|
2394 (or
|
|
2395 ;; If no, find that first statement and indent like
|
|
2396 ;; it. If the first statement begins with label, do
|
4
|
2397 ;; not believe when the indentation of the label is too
|
0
|
2398 ;; small.
|
|
2399 (save-excursion
|
|
2400 (forward-char 1)
|
|
2401 (let ((colon-line-end 0))
|
|
2402 (while (progn (skip-chars-forward " \t\n" start-point)
|
|
2403 (and (< (point) start-point)
|
|
2404 (looking-at
|
|
2405 "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
|
|
2406 ;; Skip over comments and labels following openbrace.
|
|
2407 (cond ((= (following-char) ?\#)
|
|
2408 ;;(forward-line 1)
|
|
2409 (end-of-line))
|
|
2410 ;; label:
|
|
2411 (t
|
|
2412 (save-excursion (end-of-line)
|
|
2413 (setq colon-line-end (point)))
|
|
2414 (search-forward ":"))))
|
|
2415 ;; Now at the point, after label, or at start
|
|
2416 ;; of first statement in the block.
|
|
2417 (and (< (point) start-point)
|
|
2418 (if (> colon-line-end (point))
|
|
2419 ;; Before statement after label
|
|
2420 (if (> (current-indentation)
|
|
2421 cperl-min-label-indent)
|
|
2422 (list (list 'label-in-block (point)))
|
4
|
2423 ;; Do not believe: `max' is involved
|
0
|
2424 (list
|
|
2425 (list 'label-in-block-min-indent (point))))
|
|
2426 ;; Before statement
|
|
2427 (list 'statement-in-block (point))))))
|
|
2428 ;; If no previous statement,
|
|
2429 ;; indent it relative to line brace is on.
|
|
2430 ;; For open brace in column zero, don't let statement
|
|
2431 ;; start there too. If cperl-indent-level is zero,
|
|
2432 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
|
|
2433 ;; For open-braces not the first thing in a line,
|
|
2434 ;; add in cperl-brace-imaginary-offset.
|
|
2435
|
|
2436 ;; If first thing on a line: ?????
|
|
2437 (+ (if (and (bolp) (zerop cperl-indent-level))
|
|
2438 (+ cperl-brace-offset cperl-continued-statement-offset)
|
|
2439 cperl-indent-level)
|
|
2440 ;; Move back over whitespace before the openbrace.
|
|
2441 ;; If openbrace is not first nonwhite thing on the line,
|
|
2442 ;; add the cperl-brace-imaginary-offset.
|
|
2443 (progn (skip-chars-backward " \t")
|
|
2444 (if (bolp) 0 cperl-brace-imaginary-offset))
|
|
2445 ;; If the openbrace is preceded by a parenthesized exp,
|
|
2446 ;; move to the beginning of that;
|
|
2447 ;; possibly a different line
|
|
2448 (progn
|
|
2449 (if (eq (preceding-char) ?\))
|
|
2450 (forward-sexp -1))
|
|
2451 ;; Get initial indentation of the line we are on.
|
|
2452 ;; If line starts with label, calculate label indentation
|
|
2453 (if (save-excursion
|
|
2454 (beginning-of-line)
|
193
|
2455 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
|
0
|
2456 (if (> (current-indentation) cperl-min-label-indent)
|
|
2457 (- (current-indentation) cperl-label-offset)
|
|
2458 (cperl-calculate-indent
|
|
2459 (if (and parse-start (<= parse-start (point)))
|
|
2460 parse-start)))
|
|
2461 (current-indentation))))))))
|
|
2462 res)))
|
|
2463
|
|
2464 (defun cperl-calculate-indent-within-comment ()
|
|
2465 "Return the indentation amount for line, assuming that
|
|
2466 the current line is to be regarded as part of a block comment."
|
|
2467 (let (end star-start)
|
|
2468 (save-excursion
|
|
2469 (beginning-of-line)
|
|
2470 (skip-chars-forward " \t")
|
|
2471 (setq end (point))
|
|
2472 (and (= (following-char) ?#)
|
|
2473 (forward-line -1)
|
|
2474 (cperl-to-comment-or-eol)
|
|
2475 (setq end (point)))
|
|
2476 (goto-char end)
|
|
2477 (current-column))))
|
|
2478
|
|
2479
|
|
2480 (defun cperl-to-comment-or-eol ()
|
|
2481 "Goes to position before comment on the current line, or to end of line.
|
|
2482 Returns true if comment is found."
|
|
2483 (let (state stop-in cpoint (lim (progn (end-of-line) (point))))
|
|
2484 (beginning-of-line)
|
193
|
2485 (if (or
|
|
2486 (eq (get-text-property (point) 'syntax-type) 'pod)
|
|
2487 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t))
|
0
|
2488 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
|
|
2489 ;; Else
|
|
2490 (while (not stop-in)
|
|
2491 (setq state (parse-partial-sexp (point) lim nil nil nil t))
|
|
2492 ; stop at comment
|
|
2493 ;; If fails (beginning-of-line inside sexp), then contains not-comment
|
|
2494 ;; Do simplified processing
|
|
2495 ;;(if (re-search-forward "[^$]#" lim 1)
|
|
2496 ;; (progn
|
|
2497 ;; (forward-char -1)
|
|
2498 ;; (skip-chars-backward " \t\n\f" lim))
|
|
2499 ;; (goto-char lim)) ; No `#' at all
|
|
2500 ;;)
|
|
2501 (if (nth 4 state) ; After `#';
|
|
2502 ; (nth 2 state) can be
|
|
2503 ; beginning of m,s,qq and so
|
|
2504 ; on
|
|
2505 (if (nth 2 state)
|
|
2506 (progn
|
|
2507 (setq cpoint (point))
|
|
2508 (goto-char (nth 2 state))
|
|
2509 (cond
|
|
2510 ((looking-at "\\(s\\|tr\\)\\>")
|
|
2511 (or (re-search-forward
|
|
2512 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
|
|
2513 lim 'move)
|
|
2514 (setq stop-in t)))
|
|
2515 ((looking-at "\\(m\\|q\\([qxw]\\)?\\)\\>")
|
|
2516 (or (re-search-forward
|
|
2517 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
|
|
2518 lim 'move)
|
|
2519 (setq stop-in t)))
|
|
2520 (t ; It was fair comment
|
|
2521 (setq stop-in t) ; Finish
|
|
2522 (goto-char (1- cpoint)))))
|
|
2523 (setq stop-in t) ; Finish
|
|
2524 (forward-char -1))
|
|
2525 (setq stop-in t)) ; Finish
|
|
2526 )
|
|
2527 (nth 4 state))))
|
|
2528
|
193
|
2529 (defsubst cperl-1- (p)
|
|
2530 (max (point-min) (1- p)))
|
|
2531
|
|
2532 (defsubst cperl-1+ (p)
|
|
2533 (min (point-max) (1+ p)))
|
|
2534
|
|
2535 (defvar cperl-st-cfence '(14)) ; Comment-fence
|
|
2536 (defvar cperl-st-sfence '(15)) ; String-fence
|
|
2537 (defvar cperl-st-punct '(1))
|
|
2538 (defvar cperl-st-word '(2))
|
|
2539
|
|
2540 (defun cperl-protect-defun-start (s e)
|
|
2541 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
|
|
2542 (save-excursion
|
|
2543 (goto-char s)
|
|
2544 (while (re-search-forward "^\\s(" e 'to-end)
|
|
2545 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
|
|
2546
|
|
2547 (defun cperl-commentify (bb e string)
|
|
2548 (if cperl-use-syntax-table-text-property
|
|
2549 (progn
|
|
2550 ;; We suppose that e is _after_ the end of construction, as after eol.
|
|
2551 (setq string (if string cperl-st-sfence cperl-st-cfence))
|
|
2552 (put-text-property bb (1+ bb) 'syntax-table string)
|
|
2553 (put-text-property bb (1+ bb) 'rear-nonsticky t)
|
|
2554 (put-text-property (1- e) e 'syntax-table string)
|
|
2555 (put-text-property (1- e) e 'rear-nonsticky t)
|
|
2556 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
|
|
2557 (put-text-property (1+ bb) (1- e)
|
|
2558 'syntax-table cperl-string-syntax-table))
|
|
2559 (cperl-protect-defun-start bb e))))
|
|
2560
|
0
|
2561 (defun cperl-find-pods-heres (&optional min max)
|
|
2562 "Scans the buffer for POD sections and here-documents.
|
|
2563 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
|
|
2564 the sections using `cperl-pod-head-face', `cperl-pod-face',
|
|
2565 `cperl-here-face'."
|
|
2566 (interactive)
|
|
2567 (or min (setq min (point-min)))
|
|
2568 (or max (setq max (point-max)))
|
193
|
2569 (let (face head-face here-face b e bb tag qtag err b1 e1 argument st i c
|
0
|
2570 (cperl-pod-here-fontify (eval cperl-pod-here-fontify))
|
|
2571 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
|
4
|
2572 (modified (buffer-modified-p))
|
|
2573 (after-change-functions nil)
|
193
|
2574 (state-point (point-min)) state
|
4
|
2575 (search
|
|
2576 (concat
|
|
2577 "\\(\\`\n?\\|\n\n\\)="
|
|
2578 "\\|"
|
|
2579 ;; One extra () before this:
|
110
|
2580 "<<"
|
|
2581 "\\("
|
|
2582 ;; First variant "BLAH" or just ``.
|
|
2583 "\\([\"'`]\\)"
|
|
2584 "\\([^\"'`\n]*\\)"
|
|
2585 "\\3"
|
|
2586 "\\|"
|
|
2587 ;; Second variant: Identifier or empty
|
|
2588 "\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)"
|
|
2589 ;; Check that we do not have <<= or << 30 or << $blah.
|
|
2590 "\\([^= \t$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)"
|
|
2591 "\\)"
|
4
|
2592 "\\|"
|
110
|
2593 ;; 1+6 extra () before this:
|
193
|
2594 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
|
|
2595 (if cperl-use-syntax-table-text-property
|
|
2596 (concat
|
|
2597 "\\|"
|
|
2598 ;; 1+6+2=9 extra () before this:
|
|
2599 "\\<\\(q[wxq]?\\|[msy]\\|tr\\)\\>"
|
|
2600 "\\|"
|
|
2601 ;; 1+6+2+1=10 extra () before this:
|
|
2602 "\\([?/]\\)" ; /blah/ or ?blah?
|
|
2603 "\\|"
|
|
2604 ;; 1+6+2+1+1=11 extra () before this:
|
|
2605 "\\<sub\\>[ \t]*\\([a-zA-Z_:'0-9]+[ \t]*\\)?\\(([^()]*)\\)"
|
|
2606 "\\|"
|
|
2607 ;; 1+6+2+1+1+2=13 extra () before this:
|
|
2608 "\\$\\(['{]\\)"
|
|
2609 "\\|"
|
|
2610 ;; 1+6+2+1+1+2+1=14 extra () before this:
|
|
2611 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
|
|
2612 ""))))
|
0
|
2613 (unwind-protect
|
|
2614 (progn
|
|
2615 (save-excursion
|
4
|
2616 (message "Scanning for pods, formats and here-docs...")
|
0
|
2617 (if cperl-pod-here-fontify
|
4
|
2618 ;; We had evals here, do not know why...
|
193
|
2619 (setq face `cperl-pod-face
|
|
2620 head-face `cperl-pod-head-face
|
|
2621 here-face `cperl-here-face))
|
|
2622 (remove-text-properties min max
|
|
2623 '(syntax-type t in-pod t syntax-table t))
|
0
|
2624 ;; Need to remove face as well...
|
|
2625 (goto-char min)
|
4
|
2626 (while (re-search-forward search max t)
|
|
2627 (cond
|
|
2628 ((match-beginning 1) ; POD section
|
|
2629 ;; "\\(\\`\n?\\|\n\n\\)="
|
|
2630 (if (looking-at "\n*cut\\>")
|
|
2631 (progn
|
193
|
2632 (message "=cut is not preceded by a pod section")
|
|
2633 (or err (setq err (point))))
|
0
|
2634 (beginning-of-line)
|
4
|
2635
|
|
2636 (setq b (point) bb b)
|
|
2637 (or (re-search-forward "\n\n=cut\\>" max 'toend)
|
193
|
2638 (progn
|
|
2639 (message "Cannot find the end of a pod section")
|
|
2640 (or err (setq err b))))
|
|
2641 (beginning-of-line 2) ; An empty line after =cut is not POD!
|
4
|
2642 (setq e (point))
|
|
2643 (put-text-property b e 'in-pod t)
|
|
2644 (goto-char b)
|
|
2645 (while (re-search-forward "\n\n[ \t]" e t)
|
193
|
2646 ;; We start 'pod 1 char earlier to include the preceding line
|
4
|
2647 (beginning-of-line)
|
193
|
2648 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
|
4
|
2649 (cperl-put-do-not-fontify b (point))
|
|
2650 ;;(put-text-property (max (point-min) (1- b))
|
|
2651 ;; (point) cperl-do-not-fontify t)
|
|
2652 (if cperl-pod-here-fontify (put-text-property b (point) 'face face))
|
|
2653 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
|
|
2654 (beginning-of-line)
|
|
2655 (setq b (point)))
|
193
|
2656 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
|
4
|
2657 (cperl-put-do-not-fontify (point) e)
|
|
2658 ;;(put-text-property (max (point-min) (1- (point)))
|
|
2659 ;; e cperl-do-not-fontify t)
|
|
2660 (if cperl-pod-here-fontify
|
|
2661 (progn (put-text-property (point) e 'face face)
|
|
2662 (goto-char bb)
|
|
2663 (if (looking-at
|
193
|
2664 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
|
4
|
2665 (put-text-property
|
|
2666 (match-beginning 1) (match-end 1)
|
|
2667 'face head-face))
|
|
2668 (while (re-search-forward
|
|
2669 ;; One paragraph
|
193
|
2670 "\n\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
|
4
|
2671 e 'toend)
|
|
2672 (put-text-property
|
|
2673 (match-beginning 1) (match-end 1)
|
|
2674 'face head-face))))
|
193
|
2675 (cperl-commentify bb e nil)
|
4
|
2676 (goto-char e)))
|
|
2677 ;; Here document
|
193
|
2678 ;; We do only one here-per-line
|
4
|
2679 ;; 1 () ahead
|
|
2680 ;; "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\3\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)\\)"
|
|
2681 ((match-beginning 2) ; 1 + 1
|
193
|
2682 ;; Abort in comment:
|
4
|
2683 (setq b (point))
|
193
|
2684 (setq state (parse-partial-sexp state-point b nil nil state)
|
|
2685 state-point b)
|
|
2686 (if ;;(save-excursion
|
|
2687 ;; (beginning-of-line)
|
|
2688 ;; (search-forward "#" b t))
|
|
2689 (or (nth 3 state) (nth 4 state))
|
|
2690 (goto-char (match-end 2))
|
4
|
2691 (if (match-beginning 5) ;4 + 1
|
|
2692 (setq b1 (match-beginning 5) ; 4 + 1
|
|
2693 e1 (match-end 5)) ; 4 + 1
|
|
2694 (setq b1 (match-beginning 4) ; 3 + 1
|
|
2695 e1 (match-end 4))) ; 3 + 1
|
|
2696 (setq tag (buffer-substring b1 e1)
|
|
2697 qtag (regexp-quote tag))
|
|
2698 (cond (cperl-pod-here-fontify
|
|
2699 (put-text-property b1 e1 'face font-lock-reference-face)
|
|
2700 (cperl-put-do-not-fontify b1 e1)))
|
|
2701 (forward-line)
|
|
2702 (setq b (point))
|
|
2703 (cond ((re-search-forward (concat "^" qtag "$") max 'toend)
|
|
2704 (if cperl-pod-here-fontify
|
|
2705 (progn
|
|
2706 (put-text-property (match-beginning 0) (match-end 0)
|
|
2707 'face font-lock-reference-face)
|
|
2708 (cperl-put-do-not-fontify b (match-end 0))
|
|
2709 ;;(put-text-property (max (point-min) (1- b))
|
|
2710 ;; (min (point-max)
|
|
2711 ;; (1+ (match-end 0)))
|
|
2712 ;; cperl-do-not-fontify t)
|
|
2713 (put-text-property b (match-beginning 0)
|
|
2714 'face here-face)))
|
193
|
2715 (setq e1 (cperl-1+ (match-end 0)))
|
4
|
2716 (put-text-property b (match-beginning 0)
|
|
2717 'syntax-type 'here-doc)
|
193
|
2718 (put-text-property (match-beginning 0) e1
|
|
2719 'syntax-type 'here-doc-delim)
|
|
2720 (put-text-property b e1
|
|
2721 'here-doc-group t)
|
|
2722 (cperl-commentify b e1 nil)
|
|
2723 (cperl-put-do-not-fontify b (match-end 0)))
|
|
2724 (t (message "End of here-document `%s' not found." tag)
|
|
2725 (or err (setq err b))))))
|
4
|
2726 ;; format
|
193
|
2727 ((match-beginning 8)
|
110
|
2728 ;; 1+6=7 extra () before this:
|
193
|
2729 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
|
4
|
2730 (setq b (point)
|
110
|
2731 name (if (match-beginning 8) ; 7 + 1
|
|
2732 (buffer-substring (match-beginning 8) ; 7 + 1
|
|
2733 (match-end 8)) ; 7 + 1
|
4
|
2734 ""))
|
|
2735 (setq argument nil)
|
0
|
2736 (if cperl-pod-here-fontify
|
4
|
2737 (while (and (eq (forward-line) 0)
|
|
2738 (not (looking-at "^[.;]$")))
|
|
2739 (cond
|
|
2740 ((looking-at "^#")) ; Skip comments
|
|
2741 ((and argument ; Skip argument multi-lines
|
|
2742 (looking-at "^[ \t]*{"))
|
|
2743 (forward-sexp 1)
|
|
2744 (setq argument nil))
|
|
2745 (argument ; Skip argument lines
|
|
2746 (setq argument nil))
|
|
2747 (t ; Format line
|
|
2748 (setq b1 (point))
|
|
2749 (setq argument (looking-at "^[^\n]*[@^]"))
|
|
2750 (end-of-line)
|
|
2751 (put-text-property b1 (point)
|
|
2752 'face font-lock-string-face)
|
193
|
2753 (cperl-commentify b1 (point) nil)
|
4
|
2754 (cperl-put-do-not-fontify b1 (point)))))
|
|
2755 (re-search-forward (concat "^[.;]$") max 'toend))
|
|
2756 (beginning-of-line)
|
|
2757 (if (looking-at "^[.;]$")
|
|
2758 (progn
|
|
2759 (put-text-property (point) (+ (point) 2)
|
|
2760 'face font-lock-string-face)
|
193
|
2761 (cperl-commentify (point) (+ (point) 2) nil)
|
4
|
2762 (cperl-put-do-not-fontify (point) (+ (point) 2)))
|
193
|
2763 (message "End of format `%s' not found." name)
|
|
2764 (or err (setq err b)))
|
4
|
2765 (forward-line)
|
|
2766 (put-text-property b (point) 'syntax-type 'format)
|
|
2767 ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend)
|
|
2768 ;;; (if cperl-pod-here-fontify
|
|
2769 ;;; (progn
|
|
2770 ;;; (put-text-property b (match-end 0)
|
|
2771 ;;; 'face font-lock-string-face)
|
|
2772 ;;; (cperl-put-do-not-fontify b (match-end 0))))
|
|
2773 ;;; (put-text-property b (match-end 0)
|
|
2774 ;;; 'syntax-type 'format)
|
|
2775 ;;; (cperl-put-do-not-fontify b (match-beginning 0)))
|
|
2776 ;;; (t (message "End of format `%s' not found." name)))
|
193
|
2777 )
|
|
2778 ;; Regexp:
|
|
2779 ((or (match-beginning 10) (match-beginning 11))
|
|
2780 ;; 1+6+2=9 extra () before this:
|
|
2781 ;; "\\<\\(q[wxq]?\\|[msy]\\|tr\\)\\>"
|
|
2782 ;; "\\|"
|
|
2783 ;; "\\([?/]\\)" ; /blah/ or ?blah?
|
|
2784 (setq b1 (if (match-beginning 10) 10 11)
|
|
2785 argument (buffer-substring
|
|
2786 (match-beginning b1) (match-end b1))
|
|
2787 b (point)
|
|
2788 i b
|
|
2789 c (char-after (match-beginning b1))
|
|
2790 bb (or
|
|
2791 (memq (char-after (1- (match-beginning b1)))
|
|
2792 '(?\$ ?\@ ?\% ?\& ?\*))
|
|
2793 (and
|
|
2794 (eq (char-after (1- (match-beginning b1))) ?-)
|
|
2795 (eq c ?s))))
|
|
2796 (or bb
|
|
2797 (if (eq b1 11) ; bare /blah/ or ?blah?
|
|
2798 (setq argument ""
|
|
2799 bb ; Not a regexp
|
|
2800 (progn
|
|
2801 (goto-char (match-beginning b1))
|
|
2802 (cperl-backward-to-noncomment (point-min))
|
|
2803 (not (or (memq (preceding-char)
|
|
2804 (append (if (eq c ?\?)
|
|
2805 ;; $a++ ? 1 : 2
|
|
2806 "~{(=|&*!,;"
|
|
2807 "~{(=|&+-*!,;") nil))
|
|
2808 (and (eq (preceding-char) ?\})
|
|
2809 (cperl-after-block-p (point-min)))
|
|
2810 (and (eq (char-syntax (preceding-char)) ?w)
|
|
2811 (progn
|
|
2812 (forward-sexp -1)
|
|
2813 (looking-at
|
|
2814 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\)\\>")))
|
|
2815 (and (eq (preceding-char) ?.)
|
|
2816 (eq (char-after (- (point) 2)) ?.))
|
|
2817 (bobp))))
|
|
2818 b (1- b))))
|
|
2819 (or bb (setq state (parse-partial-sexp
|
|
2820 state-point b nil nil state)
|
|
2821 state-point b))
|
|
2822 (goto-char b)
|
|
2823 (if (or bb (nth 3 state) (nth 4 state))
|
|
2824 (goto-char i)
|
|
2825 (skip-chars-forward " \t")
|
|
2826 ;; qtag means two-arg matcher, may be reset to
|
|
2827 ;; 2 or 3 later if some special quoting is needed.
|
|
2828 ;; e1 means matching-char matcher.
|
|
2829 (setq b (point)
|
|
2830 tag (char-after b)
|
|
2831 qtag (if (string-match "^\\([sy]\\|tr\\)$" argument) t)
|
|
2832 e1 (cdr (assoc tag '(( ?\( . ?\) )
|
|
2833 ( ?\[ . ?\] )
|
|
2834 ( ?\{ . ?\} )
|
|
2835 ( ?\< . ?\> )
|
|
2836 ))))
|
|
2837 ;; What if tag == ?\\ ????
|
|
2838 (or st
|
|
2839 (progn
|
|
2840 (setq st (make-syntax-table) i 0)
|
|
2841 (while (< i 256)
|
|
2842 (modify-syntax-entry i "." st)
|
|
2843 (setq i (1+ i)))
|
|
2844 (modify-syntax-entry ?\\ "\\" st)))
|
|
2845 ;; Whether we have an intermediate point
|
|
2846 (setq i nil)
|
|
2847 ;; Prepare the syntax table:
|
|
2848 (cond
|
|
2849 ;; $ has TeXish matching rules, so $$ equiv $...
|
|
2850 ((and qtag
|
|
2851 (not e1)
|
|
2852 (eq tag (char-after (cperl-1+ b)))
|
|
2853 (eq tag (char-after (+ 2 b))))
|
|
2854 (setq qtag 3)) ; s///
|
|
2855 ((and qtag
|
|
2856 (not e1)
|
|
2857 (eq tag (char-after (cperl-1+ b))))
|
|
2858 (setq qtag nil)) ; s//blah/, will work anyway
|
|
2859 ((and (not e1)
|
|
2860 (eq tag (char-after (cperl-1+ b))))
|
|
2861 (setq qtag 2)) ; m//
|
|
2862 ((not e1)
|
|
2863 (modify-syntax-entry tag "$" st)) ; m/blah/, s/x//, s/x/y/
|
|
2864 (t ; s{}(), m[]
|
|
2865 (modify-syntax-entry tag (concat "(" (list e1)) st)
|
|
2866 (modify-syntax-entry e1 (concat ")" (list tag)) st)))
|
|
2867 (if (numberp qtag)
|
|
2868 (forward-char qtag)
|
|
2869 (condition-case bb
|
|
2870 (progn
|
|
2871 (set-syntax-table st)
|
|
2872 (forward-sexp 1) ; Wrong if m// - taken care of...
|
|
2873 (if qtag
|
|
2874 (if e1
|
|
2875 (progn
|
|
2876 (setq i (point))
|
|
2877 (set-syntax-table cperl-mode-syntax-table)
|
|
2878 (forward-sexp 1)) ; Should be smarter?
|
|
2879 ;; "$" has funny matching rules
|
|
2880 (if (/= (char-after (- (point) 2))
|
|
2881 (preceding-char))
|
|
2882 (progn
|
|
2883 ;; Commenting \\ is dangerous, what about ( ?
|
|
2884 (if (eq (following-char) ?\\) nil
|
|
2885 (setq i (point)))
|
|
2886 (forward-char -1)
|
|
2887 (forward-sexp 1)))
|
|
2888 )))
|
|
2889 (error (goto-char (point-max))
|
|
2890 (message
|
|
2891 "End of `%s%c ... %c' string not found: %s"
|
|
2892 argument tag (or e1 tag) bb)
|
|
2893 (or err (setq err b)))))
|
|
2894 (set-syntax-table cperl-mode-syntax-table)
|
|
2895 (if (null i)
|
|
2896 (cperl-commentify b (point) t)
|
|
2897 (cperl-commentify b i t)
|
|
2898 (if (looking-at "\\sw*e") nil ; s///e
|
|
2899 (cperl-commentify i (point) t)))
|
|
2900 (if (eq (char-syntax (following-char)) ?w)
|
|
2901 (forward-word 1)) ; skip modifiers s///s
|
|
2902 (modify-syntax-entry tag "." st)
|
|
2903 (if e1 (modify-syntax-entry e1 "." st))))
|
|
2904 ((match-beginning 13) ; sub with prototypes
|
|
2905 (setq b (match-beginning 0))
|
|
2906 (if (memq (char-after (1- b))
|
|
2907 '(?\$ ?\@ ?\% ?\& ?\*))
|
|
2908 nil
|
|
2909 (setq state (parse-partial-sexp
|
|
2910 state-point (1- b) nil nil state)
|
|
2911 state-point (1- b))
|
|
2912 (if (or (nth 3 state) (nth 4 state))
|
|
2913 nil
|
|
2914 ;; Mark as string
|
|
2915 (cperl-commentify (match-beginning 13) (match-end 13) t))
|
|
2916 (goto-char (match-end 0))))
|
|
2917 ;; 1+6+2+1+1+2=13 extra () before this:
|
|
2918 ;; "\\$\\(['{]\\)"
|
|
2919 ((and (match-beginning 14)
|
|
2920 (eq (preceding-char) ?\')) ; $'
|
|
2921 (setq b (1- (point))
|
|
2922 state (parse-partial-sexp
|
|
2923 state-point (1- b) nil nil state)
|
|
2924 state-point (1- b))
|
|
2925 (if (nth 3 state) ; in string
|
|
2926 (progn
|
|
2927 (put-text-property (1- b) b 'syntax-table cperl-st-punct)
|
|
2928 (put-text-property (1- b) b 'rear-nonsticky t)))
|
|
2929 (goto-char (1+ b)))
|
|
2930 ;; 1+6+2+1+1+2=13 extra () before this:
|
|
2931 ;; "\\$\\(['{]\\)"
|
|
2932 ((match-beginning 14) ; ${
|
|
2933 (setq bb (match-beginning 0))
|
|
2934 (put-text-property bb (1+ bb) 'syntax-table cperl-st-punct)
|
|
2935 (put-text-property bb (1+ bb) 'rear-nonsticky t))
|
|
2936 ;; 1+6+2+1+1+2+1=14 extra () before this:
|
|
2937 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
|
|
2938 (t ; old $abc'efg syntax
|
|
2939 (setq bb (match-end 0)
|
|
2940 b (match-beginning 0)
|
|
2941 state (parse-partial-sexp
|
|
2942 state-point b nil nil state)
|
|
2943 state-point b)
|
|
2944 (if (nth 3 state) ; in string
|
|
2945 nil
|
|
2946 (put-text-property (1- bb) bb 'syntax-table cperl-st-word))
|
|
2947 (goto-char bb))))
|
4
|
2948 ;;; (while (re-search-forward "\\(\\`\n?\\|\n\n\\)=" max t)
|
|
2949 ;;; (if (looking-at "\n*cut\\>")
|
|
2950 ;;; (progn
|
193
|
2951 ;;; (message "=cut is not preceded by a pod section")
|
4
|
2952 ;;; (setq err (point)))
|
|
2953 ;;; (beginning-of-line)
|
|
2954
|
|
2955 ;;; (setq b (point) bb b)
|
|
2956 ;;; (or (re-search-forward "\n\n=cut\\>" max 'toend)
|
|
2957 ;;; (message "Cannot find the end of a pod section"))
|
|
2958 ;;; (beginning-of-line 3)
|
|
2959 ;;; (setq e (point))
|
|
2960 ;;; (put-text-property b e 'in-pod t)
|
|
2961 ;;; (goto-char b)
|
|
2962 ;;; (while (re-search-forward "\n\n[ \t]" e t)
|
|
2963 ;;; (beginning-of-line)
|
|
2964 ;;; (put-text-property b (point) 'syntax-type 'pod)
|
|
2965 ;;; (cperl-put-do-not-fontify b (point))
|
|
2966 ;;; ;;(put-text-property (max (point-min) (1- b))
|
|
2967 ;;; ;; (point) cperl-do-not-fontify t)
|
|
2968 ;;; (if cperl-pod-here-fontify (put-text-property b (point) 'face face))
|
|
2969 ;;; (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
|
|
2970 ;;; (beginning-of-line)
|
|
2971 ;;; (setq b (point)))
|
|
2972 ;;; (put-text-property (point) e 'syntax-type 'pod)
|
|
2973 ;;; (cperl-put-do-not-fontify (point) e)
|
|
2974 ;;; ;;(put-text-property (max (point-min) (1- (point)))
|
|
2975 ;;; ;; e cperl-do-not-fontify t)
|
|
2976 ;;; (if cperl-pod-here-fontify
|
|
2977 ;;; (progn (put-text-property (point) e 'face face)
|
|
2978 ;;; (goto-char bb)
|
|
2979 ;;; (if (looking-at
|
|
2980 ;;; "=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
|
|
2981 ;;; (put-text-property
|
|
2982 ;;; (match-beginning 1) (match-end 1)
|
|
2983 ;;; 'face head-face))
|
|
2984 ;;; (while (re-search-forward
|
|
2985 ;;; ;; One paragraph
|
|
2986 ;;; "\n\n=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
|
|
2987 ;;; e 'toend)
|
|
2988 ;;; (put-text-property
|
|
2989 ;;; (match-beginning 1) (match-end 1)
|
|
2990 ;;; 'face head-face))))
|
|
2991 ;;; (goto-char e)))
|
|
2992 ;;; (goto-char min)
|
|
2993 ;;; (while (re-search-forward
|
|
2994 ;;; ;; We exclude \n to avoid misrecognition inside quotes.
|
|
2995 ;;; "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\2\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)\\)"
|
|
2996 ;;; max t)
|
|
2997 ;;; (if (match-beginning 4)
|
|
2998 ;;; (setq b1 (match-beginning 4)
|
|
2999 ;;; e1 (match-end 4))
|
|
3000 ;;; (setq b1 (match-beginning 3)
|
|
3001 ;;; e1 (match-end 3)))
|
|
3002 ;;; (setq tag (buffer-substring b1 e1)
|
|
3003 ;;; qtag (regexp-quote tag))
|
|
3004 ;;; (cond (cperl-pod-here-fontify
|
|
3005 ;;; (put-text-property b1 e1 'face font-lock-reference-face)
|
|
3006 ;;; (cperl-put-do-not-fontify b1 e1)))
|
|
3007 ;;; (forward-line)
|
|
3008 ;;; (setq b (point))
|
|
3009 ;;; (cond ((re-search-forward (concat "^" qtag "$") max 'toend)
|
|
3010 ;;; (if cperl-pod-here-fontify
|
|
3011 ;;; (progn
|
|
3012 ;;; (put-text-property (match-beginning 0) (match-end 0)
|
|
3013 ;;; 'face font-lock-reference-face)
|
|
3014 ;;; (cperl-put-do-not-fontify b (match-end 0))
|
|
3015 ;;; ;;(put-text-property (max (point-min) (1- b))
|
|
3016 ;;; ;; (min (point-max)
|
|
3017 ;;; ;; (1+ (match-end 0)))
|
|
3018 ;;; ;; cperl-do-not-fontify t)
|
|
3019 ;;; (put-text-property b (match-beginning 0)
|
|
3020 ;;; 'face here-face)))
|
|
3021 ;;; (put-text-property b (match-beginning 0)
|
|
3022 ;;; 'syntax-type 'here-doc)
|
|
3023 ;;; (cperl-put-do-not-fontify b (match-beginning 0)))
|
|
3024 ;;; (t (message "End of here-document `%s' not found." tag))))
|
|
3025 ;;; (goto-char min)
|
|
3026 ;;; (while (re-search-forward
|
|
3027 ;;; "^[ \t]*format[ \t]*\\(\\([a-zA-Z0-9_]+[ \t]*\\)?\\)=[ \t]*$"
|
|
3028 ;;; max t)
|
|
3029 ;;; (setq b (point)
|
|
3030 ;;; name (buffer-substring (match-beginning 1)
|
|
3031 ;;; (match-end 1)))
|
|
3032 ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend)
|
|
3033 ;;; (if cperl-pod-here-fontify
|
|
3034 ;;; (progn
|
|
3035 ;;; (put-text-property b (match-end 0)
|
|
3036 ;;; 'face font-lock-string-face)
|
|
3037 ;;; (cperl-put-do-not-fontify b (match-end 0))))
|
|
3038 ;;; (put-text-property b (match-end 0)
|
|
3039 ;;; 'syntax-type 'format)
|
|
3040 ;;; (cperl-put-do-not-fontify b (match-beginning 0)))
|
|
3041 ;;; (t (message "End of format `%s' not found." name))))
|
|
3042 )
|
0
|
3043 (if err (goto-char err)
|
4
|
3044 (message "Scan for pods, formats and here-docs completed.")))
|
0
|
3045 (and (buffer-modified-p)
|
|
3046 (not modified)
|
193
|
3047 (set-buffer-modified-p nil))
|
|
3048 (set-syntax-table cperl-mode-syntax-table))))
|
0
|
3049
|
|
3050 (defun cperl-backward-to-noncomment (lim)
|
|
3051 ;; Stops at lim or after non-whitespace that is not in comment
|
|
3052 (let (stop p)
|
|
3053 (while (and (not stop) (> (point) (or lim 1)))
|
|
3054 (skip-chars-backward " \t\n\f" lim)
|
|
3055 (setq p (point))
|
|
3056 (beginning-of-line)
|
|
3057 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
|
|
3058 ;; Else
|
|
3059 (cperl-to-comment-or-eol)
|
|
3060 (skip-chars-backward " \t")
|
|
3061 (if (< p (point)) (goto-char p))
|
|
3062 (setq stop t)))))
|
|
3063
|
193
|
3064 (defun cperl-after-block-p (lim)
|
|
3065 ;; We suppose that the preceding char is }.
|
|
3066 (save-excursion
|
|
3067 (condition-case nil
|
|
3068 (progn
|
|
3069 (forward-sexp -1)
|
|
3070 (cperl-backward-to-noncomment lim)
|
|
3071 (or (eq (preceding-char) ?\) ) ; if () {}
|
|
3072 (and (eq (char-syntax (preceding-char)) ?w) ; else {}
|
|
3073 (progn
|
|
3074 (forward-sexp -1)
|
|
3075 (looking-at "\\(else\\|grep\\|map\\)\\>")))
|
|
3076 (cperl-after-expr-p lim)))
|
|
3077 (error nil))))
|
|
3078
|
0
|
3079 (defun cperl-after-expr-p (&optional lim chars test)
|
|
3080 "Returns true if the position is good for start of expression.
|
|
3081 TEST is the expression to evaluate at the found position. If absent,
|
193
|
3082 CHARS is a string that contains good characters to have before us (however,
|
|
3083 `}' is treated \"smartly\" if it is not in the list)."
|
|
3084 (let (stop p
|
|
3085 (lim (or lim (point-min))))
|
0
|
3086 (save-excursion
|
193
|
3087 (while (and (not stop) (> (point) lim))
|
0
|
3088 (skip-chars-backward " \t\n\f" lim)
|
|
3089 (setq p (point))
|
|
3090 (beginning-of-line)
|
|
3091 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
|
|
3092 ;; Else: last iteration (What to do with labels?)
|
|
3093 (cperl-to-comment-or-eol)
|
|
3094 (skip-chars-backward " \t")
|
|
3095 (if (< p (point)) (goto-char p))
|
|
3096 (setq stop t)))
|
|
3097 (or (bobp)
|
|
3098 (progn
|
|
3099 (if test (eval test)
|
193
|
3100 (or (memq (preceding-char) (append (or chars "{;") nil))
|
|
3101 (and (eq (preceding-char) ?\})
|
|
3102 (cperl-after-block-p lim)))))))))
|
0
|
3103
|
|
3104 (defun cperl-backward-to-start-of-continued-exp (lim)
|
|
3105 (if (memq (preceding-char) (append ")]}\"'`" nil))
|
|
3106 (forward-sexp -1))
|
|
3107 (beginning-of-line)
|
|
3108 (if (<= (point) lim)
|
|
3109 (goto-char (1+ lim)))
|
|
3110 (skip-chars-forward " \t"))
|
|
3111
|
|
3112
|
|
3113 (defvar innerloop-done nil)
|
|
3114 (defvar last-depth nil)
|
|
3115
|
|
3116 (defun cperl-indent-exp ()
|
|
3117 "Simple variant of indentation of continued-sexp.
|
|
3118 Should be slow. Will not indent comment if it starts at `comment-indent'
|
|
3119 or looks like continuation of the comment on the previous line."
|
|
3120 (interactive)
|
|
3121 (save-excursion
|
|
3122 (let ((tmp-end (progn (end-of-line) (point))) top done)
|
|
3123 (save-excursion
|
193
|
3124 (beginning-of-line)
|
0
|
3125 (while (null done)
|
|
3126 (setq top (point))
|
|
3127 (while (= (nth 0 (parse-partial-sexp (point) tmp-end
|
|
3128 -1)) -1)
|
|
3129 (setq top (point))) ; Get the outermost parenths in line
|
|
3130 (goto-char top)
|
|
3131 (while (< (point) tmp-end)
|
|
3132 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
|
|
3133 (or (eolp) (forward-sexp 1)))
|
|
3134 (if (> (point) tmp-end) (progn (end-of-line) (setq tmp-end (point)))
|
|
3135 (setq done t)))
|
|
3136 (goto-char tmp-end)
|
|
3137 (setq tmp-end (point-marker)))
|
|
3138 (cperl-indent-region (point) tmp-end))))
|
|
3139
|
|
3140 (defun cperl-indent-region (start end)
|
|
3141 "Simple variant of indentation of region in CPerl mode.
|
|
3142 Should be slow. Will not indent comment if it starts at `comment-indent'
|
|
3143 or looks like continuation of the comment on the previous line.
|
|
3144 Indents all the lines whose first character is between START and END
|
|
3145 inclusive."
|
|
3146 (interactive "r")
|
|
3147 (save-excursion
|
|
3148 (let (st comm indent-info old-comm-indent new-comm-indent
|
|
3149 (pm 0) (imenu-scanning-message "Indenting... (%3d%%)"))
|
|
3150 (goto-char start)
|
|
3151 (setq old-comm-indent (and (cperl-to-comment-or-eol)
|
|
3152 (current-column))
|
|
3153 new-comm-indent old-comm-indent)
|
|
3154 (goto-char start)
|
|
3155 (or (bolp) (beginning-of-line 2))
|
|
3156 (or (fboundp 'imenu-progress-message)
|
|
3157 (message "Indenting... For feedback load `imenu'..."))
|
|
3158 (while (and (<= (point) end) (not (eobp))) ; bol to check start
|
|
3159 (and (fboundp 'imenu-progress-message)
|
|
3160 (imenu-progress-message
|
|
3161 pm (/ (* 100 (- (point) start)) (- end start -1))))
|
|
3162 (setq st (point)
|
|
3163 indent-info nil
|
|
3164 ) ; Believe indentation of the current
|
|
3165 (if (and (setq comm (looking-at "[ \t]*#"))
|
|
3166 (or (eq (current-indentation) (or old-comm-indent
|
|
3167 comment-column))
|
|
3168 (setq old-comm-indent nil)))
|
|
3169 (if (and old-comm-indent
|
193
|
3170 (= (current-indentation) old-comm-indent)
|
|
3171 (not (eq (get-text-property (point) 'syntax-type) 'pod)))
|
0
|
3172 (let ((comment-column new-comm-indent))
|
|
3173 (indent-for-comment)))
|
|
3174 (progn
|
|
3175 (cperl-indent-line 'indent-info)
|
|
3176 (or comm
|
|
3177 (progn
|
|
3178 (if (setq old-comm-indent (and (cperl-to-comment-or-eol)
|
193
|
3179 (not (eq (get-text-property (point) 'syntax-type) 'pod))
|
0
|
3180 (current-column)))
|
|
3181 (progn (indent-for-comment)
|
|
3182 (skip-chars-backward " \t")
|
|
3183 (skip-chars-backward "#")
|
|
3184 (setq new-comm-indent (current-column))))))))
|
|
3185 (beginning-of-line 2))
|
|
3186 (if (fboundp 'imenu-progress-message)
|
|
3187 (imenu-progress-message pm 100)
|
|
3188 (message nil)))))
|
|
3189
|
193
|
3190 ;;(defun cperl-slash-is-regexp (&optional pos)
|
|
3191 ;; (save-excursion
|
|
3192 ;; (goto-char (if pos pos (1- (point))))
|
|
3193 ;; (and
|
|
3194 ;; (not (memq (get-text-property (point) 'face)
|
|
3195 ;; '(font-lock-string-face font-lock-comment-face)))
|
|
3196 ;; (cperl-after-expr-p nil nil '
|
|
3197 ;; (or (looking-at "[^]a-zA-Z0-9_)}]")
|
|
3198 ;; (eq (get-text-property (point) 'face)
|
|
3199 ;; 'font-lock-keyword-face))))))
|
0
|
3200
|
|
3201 ;; Stolen from lisp-mode with a lot of improvements
|
|
3202
|
|
3203 (defun cperl-fill-paragraph (&optional justify iteration)
|
|
3204 "Like \\[fill-paragraph], but handle CPerl comments.
|
|
3205 If any of the current line is a comment, fill the comment or the
|
|
3206 block of it that point is in, preserving the comment's initial
|
|
3207 indentation and initial hashes. Behaves usually outside of comment."
|
|
3208 (interactive "P")
|
|
3209 (let (
|
|
3210 ;; Non-nil if the current line contains a comment.
|
|
3211 has-comment
|
|
3212
|
|
3213 ;; If has-comment, the appropriate fill-prefix for the comment.
|
|
3214 comment-fill-prefix
|
|
3215 ;; Line that contains code and comment (or nil)
|
|
3216 start
|
|
3217 c spaces len dc (comment-column comment-column))
|
|
3218 ;; Figure out what kind of comment we are looking at.
|
|
3219 (save-excursion
|
|
3220 (beginning-of-line)
|
|
3221 (cond
|
|
3222
|
|
3223 ;; A line with nothing but a comment on it?
|
|
3224 ((looking-at "[ \t]*#[# \t]*")
|
|
3225 (setq has-comment t
|
|
3226 comment-fill-prefix (buffer-substring (match-beginning 0)
|
|
3227 (match-end 0))))
|
|
3228
|
|
3229 ;; A line with some code, followed by a comment? Remember that the
|
|
3230 ;; semi which starts the comment shouldn't be part of a string or
|
|
3231 ;; character.
|
|
3232 ((cperl-to-comment-or-eol)
|
|
3233 (setq has-comment t)
|
|
3234 (looking-at "#+[ \t]*")
|
|
3235 (setq start (point) c (current-column)
|
|
3236 comment-fill-prefix
|
|
3237 (concat (make-string (current-column) ?\ )
|
|
3238 (buffer-substring (match-beginning 0) (match-end 0)))
|
|
3239 spaces (progn (skip-chars-backward " \t")
|
|
3240 (buffer-substring (point) start))
|
|
3241 dc (- c (current-column)) len (- start (point))
|
|
3242 start (point-marker))
|
|
3243 (delete-char len)
|
|
3244 (insert (make-string dc ?-)))))
|
|
3245 (if (not has-comment)
|
|
3246 (fill-paragraph justify) ; Do the usual thing outside of comment
|
|
3247 ;; Narrow to include only the comment, and then fill the region.
|
|
3248 (save-restriction
|
|
3249 (narrow-to-region
|
|
3250 ;; Find the first line we should include in the region to fill.
|
|
3251 (if start (progn (beginning-of-line) (point))
|
|
3252 (save-excursion
|
|
3253 (while (and (zerop (forward-line -1))
|
|
3254 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
|
|
3255 ;; We may have gone to far. Go forward again.
|
|
3256 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
|
|
3257 (forward-line 1))
|
|
3258 (point)))
|
|
3259 ;; Find the beginning of the first line past the region to fill.
|
|
3260 (save-excursion
|
|
3261 (while (progn (forward-line 1)
|
|
3262 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
|
|
3263 (point)))
|
|
3264 ;; Remove existing hashes
|
|
3265 (goto-char (point-min))
|
|
3266 (while (progn (forward-line 1) (< (point) (point-max)))
|
|
3267 (skip-chars-forward " \t")
|
|
3268 (and (looking-at "#+")
|
|
3269 (delete-char (- (match-end 0) (match-beginning 0)))))
|
|
3270
|
|
3271 ;; Lines with only hashes on them can be paragraph boundaries.
|
|
3272 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
|
|
3273 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
|
|
3274 (fill-prefix comment-fill-prefix))
|
|
3275 (fill-paragraph justify)))
|
|
3276 (if (and start)
|
|
3277 (progn
|
|
3278 (goto-char start)
|
|
3279 (if (> dc 0)
|
|
3280 (progn (delete-char dc) (insert spaces)))
|
|
3281 (if (or (= (current-column) c) iteration) nil
|
|
3282 (setq comment-column c)
|
|
3283 (indent-for-comment)
|
|
3284 ;; Repeat once more, flagging as iteration
|
|
3285 (cperl-fill-paragraph justify t)))))))
|
|
3286
|
|
3287 (defun cperl-do-auto-fill ()
|
|
3288 ;; Break out if the line is short enough
|
|
3289 (if (> (save-excursion
|
|
3290 (end-of-line)
|
|
3291 (current-column))
|
|
3292 fill-column)
|
|
3293 (let ((c (save-excursion (beginning-of-line)
|
|
3294 (cperl-to-comment-or-eol) (point)))
|
|
3295 (s (memq (following-char) '(?\ ?\t))) marker)
|
|
3296 (if (>= c (point)) nil
|
|
3297 (setq marker (point-marker))
|
|
3298 (cperl-fill-paragraph)
|
|
3299 (goto-char marker)
|
|
3300 ;; Is not enough, sometimes marker is a start of line
|
|
3301 (if (bolp) (progn (re-search-forward "#+[ \t]*")
|
|
3302 (goto-char (match-end 0))))
|
|
3303 ;; Following space could have gone:
|
|
3304 (if (or (not s) (memq (following-char) '(?\ ?\t))) nil
|
|
3305 (insert " ")
|
|
3306 (backward-char 1))
|
|
3307 ;; Previous space could have gone:
|
|
3308 (or (memq (preceding-char) '(?\ ?\t)) (insert " "))))))
|
|
3309
|
193
|
3310 ;;(defvar imenu-example--function-name-regexp-perl
|
|
3311 ;; (concat
|
|
3312 ;; "^\\("
|
|
3313 ;; "[ \t]*\\(sub\\|package\\)[ \t\n]+\\([a-zA-Z_0-9:']+\\)[ \t]*\\(([^()]*)[ \t]*\\)?"
|
|
3314 ;; "\\|"
|
|
3315 ;; "=head\\([12]\\)[ \t]+\\([^\n]+\\)$"
|
|
3316 ;; "\\)"))
|
|
3317
|
|
3318 ;;(defun cperl-imenu-addback (lst &optional isback name)
|
|
3319 ;; ;; We suppose that the lst is a DAG, unless the first element only
|
|
3320 ;; ;; loops back, and ISBACK is set. Thus this function cannot be
|
|
3321 ;; ;; applied twice without ISBACK set.
|
|
3322 ;; (cond ((not cperl-imenu-addback) lst)
|
|
3323 ;; (t
|
|
3324 ;; (or name
|
|
3325 ;; (setq name "+++BACK+++"))
|
|
3326 ;; (mapcar (function (lambda (elt)
|
|
3327 ;; (if (and (listp elt) (listp (cdr elt)))
|
|
3328 ;; (progn
|
|
3329 ;; ;; In the other order it goes up
|
|
3330 ;; ;; one level only ;-(
|
|
3331 ;; (setcdr elt (cons (cons name lst)
|
|
3332 ;; (cdr elt)))
|
|
3333 ;; (cperl-imenu-addback (cdr elt) t name)
|
|
3334 ;; ))))
|
|
3335 ;; (if isback (cdr lst) lst))
|
|
3336 ;; lst)))
|
|
3337
|
|
3338 ;;(defun imenu-example--create-perl-index (&optional regexp)
|
|
3339 ;; (require 'cl)
|
|
3340 ;; ;; ####
|
|
3341 ;; (require 'imenu) ; May be called from TAGS creator
|
|
3342 ;; (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
|
|
3343 ;; (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
|
|
3344 ;; (index-meth-alist '()) meth
|
|
3345 ;; packages ends-ranges p
|
|
3346 ;; (prev-pos 0) char fchar index index1 name (end-range 0) package)
|
|
3347 ;; (goto-char (point-min))
|
|
3348 ;; (imenu-progress-message prev-pos 0)
|
|
3349 ;; ;; Search for the function
|
|
3350 ;; (progn ;;save-match-data
|
|
3351 ;; (while (re-search-forward
|
|
3352 ;; (or regexp imenu-example--function-name-regexp-perl)
|
|
3353 ;; nil t)
|
|
3354 ;; (imenu-progress-message prev-pos)
|
|
3355 ;; ;;(backward-up-list 1)
|
|
3356 ;; (cond
|
|
3357 ;; ((and ; Skip some noise if building tags
|
|
3358 ;; (match-beginning 2) ; package or sub
|
|
3359 ;; (eq (char-after (match-beginning 2)) ?p) ; package
|
|
3360 ;; (not (save-match-data
|
|
3361 ;; (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
|
|
3362 ;; nil)
|
|
3363 ;; ((and
|
|
3364 ;; (match-beginning 2) ; package or sub
|
|
3365 ;; ;; Skip if quoted (will not skip multi-line ''-comments :-():
|
|
3366 ;; (null (get-text-property (match-beginning 1) 'syntax-table))
|
|
3367 ;; (null (get-text-property (match-beginning 1) 'syntax-type))
|
|
3368 ;; (null (get-text-property (match-beginning 1) 'in-pod)))
|
|
3369 ;; (save-excursion
|
|
3370 ;; (goto-char (match-beginning 2))
|
|
3371 ;; (setq fchar (following-char))
|
|
3372 ;; )
|
|
3373 ;; ;; (if (looking-at "([^()]*)[ \t\n\f]*")
|
|
3374 ;; ;; (goto-char (match-end 0))) ; Messes what follows
|
|
3375 ;; (setq char (following-char)
|
|
3376 ;; meth nil
|
|
3377 ;; p (point))
|
|
3378 ;; (while (and ends-ranges (>= p (car ends-ranges)))
|
|
3379 ;; ;; delete obsolete entries
|
|
3380 ;; (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
|
|
3381 ;; (setq package (or (car packages) "")
|
|
3382 ;; end-range (or (car ends-ranges) 0))
|
|
3383 ;; (if (eq fchar ?p)
|
|
3384 ;; (setq name (buffer-substring (match-beginning 3) (match-end 3))
|
|
3385 ;; name (progn
|
|
3386 ;; (set-text-properties 0 (length name) nil name)
|
|
3387 ;; name)
|
|
3388 ;; package (concat name "::")
|
|
3389 ;; name (concat "package " name)
|
|
3390 ;; end-range
|
|
3391 ;; (save-excursion
|
|
3392 ;; (parse-partial-sexp (point) (point-max) -1) (point))
|
|
3393 ;; ends-ranges (cons end-range ends-ranges)
|
|
3394 ;; packages (cons package packages)))
|
|
3395 ;; ;; )
|
|
3396 ;; ;; Skip this function name if it is a prototype declaration.
|
|
3397 ;; (if (and (eq fchar ?s) (eq char ?\;)) nil
|
|
3398 ;; (setq index (imenu-example--name-and-position))
|
|
3399 ;; (if (eq fchar ?p) nil
|
|
3400 ;; (setq name (buffer-substring (match-beginning 3) (match-end 3)))
|
|
3401 ;; (set-text-properties 0 (length name) nil name)
|
|
3402 ;; (cond ((string-match "[:']" name)
|
|
3403 ;; (setq meth t))
|
|
3404 ;; ((> p end-range) nil)
|
|
3405 ;; (t
|
|
3406 ;; (setq name (concat package name) meth t))))
|
|
3407 ;; (setcar index name)
|
|
3408 ;; (if (eq fchar ?p)
|
|
3409 ;; (push index index-pack-alist)
|
|
3410 ;; (push index index-alist))
|
|
3411 ;; (if meth (push index index-meth-alist))
|
|
3412 ;; (push index index-unsorted-alist)))
|
|
3413 ;; ((match-beginning 5) ; Pod section
|
|
3414 ;; ;; (beginning-of-line)
|
|
3415 ;; (setq index (imenu-example--name-and-position)
|
|
3416 ;; name (buffer-substring (match-beginning 6) (match-end 6)))
|
|
3417 ;; (set-text-properties 0 (length name) nil name)
|
|
3418 ;; (if (eq (char-after (match-beginning 5)) ?2)
|
|
3419 ;; (setq name (concat " " name)))
|
|
3420 ;; (setcar index name)
|
|
3421 ;; (setq index1 (cons (concat "=" name) (cdr index)))
|
|
3422 ;; (push index index-pod-alist)
|
|
3423 ;; (push index1 index-unsorted-alist)))))
|
|
3424 ;; (imenu-progress-message prev-pos 100)
|
|
3425 ;; (setq index-alist
|
|
3426 ;; (if (default-value 'imenu-sort-function)
|
|
3427 ;; (sort index-alist (default-value 'imenu-sort-function))
|
|
3428 ;; (nreverse index-alist)))
|
|
3429 ;; (and index-pod-alist
|
|
3430 ;; (push (cons "+POD headers+..."
|
|
3431 ;; (nreverse index-pod-alist))
|
|
3432 ;; index-alist))
|
|
3433 ;; (and (or index-pack-alist index-meth-alist)
|
|
3434 ;; (let ((lst index-pack-alist) hier-list pack elt group name)
|
|
3435 ;; ;; Remove "package ", reverse and uniquify.
|
|
3436 ;; (while lst
|
|
3437 ;; (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
|
|
3438 ;; (if (assoc name hier-list) nil
|
|
3439 ;; (setq hier-list (cons (cons name (cdr elt)) hier-list))))
|
|
3440 ;; (setq lst index-meth-alist)
|
|
3441 ;; (while lst
|
|
3442 ;; (setq elt (car lst) lst (cdr lst))
|
|
3443 ;; (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
|
|
3444 ;; (setq pack (substring (car elt) 0 (match-beginning 0)))
|
|
3445 ;; (if (setq group (assoc pack hier-list))
|
|
3446 ;; (if (listp (cdr group))
|
|
3447 ;; ;; Have some functions already
|
|
3448 ;; (setcdr group
|
|
3449 ;; (cons (cons (substring
|
|
3450 ;; (car elt)
|
|
3451 ;; (+ 2 (match-beginning 0)))
|
|
3452 ;; (cdr elt))
|
|
3453 ;; (cdr group)))
|
|
3454 ;; (setcdr group (list (cons (substring
|
|
3455 ;; (car elt)
|
|
3456 ;; (+ 2 (match-beginning 0)))
|
|
3457 ;; (cdr elt)))))
|
|
3458 ;; (setq hier-list
|
|
3459 ;; (cons (cons pack
|
|
3460 ;; (list (cons (substring
|
|
3461 ;; (car elt)
|
|
3462 ;; (+ 2 (match-beginning 0)))
|
|
3463 ;; (cdr elt))))
|
|
3464 ;; hier-list))))))
|
|
3465 ;; (push (cons "+Hierarchy+..."
|
|
3466 ;; hier-list)
|
|
3467 ;; index-alist)))
|
|
3468 ;; (and index-pack-alist
|
|
3469 ;; (push (cons "+Packages+..."
|
|
3470 ;; (nreverse index-pack-alist))
|
|
3471 ;; index-alist))
|
|
3472 ;; (and (or index-pack-alist index-pod-alist
|
|
3473 ;; (default-value 'imenu-sort-function))
|
|
3474 ;; index-unsorted-alist
|
|
3475 ;; (push (cons "+Unsorted List+..."
|
|
3476 ;; (nreverse index-unsorted-alist))
|
|
3477 ;; index-alist))
|
|
3478 ;; (cperl-imenu-addback index-alist)))
|
0
|
3479
|
|
3480 (defvar cperl-compilation-error-regexp-alist
|
|
3481 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK).
|
|
3482 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
|
|
3483 2 3))
|
|
3484 "Alist that specifies how to match errors in perl output.")
|
|
3485
|
|
3486 (if (fboundp 'eval-after-load)
|
|
3487 (eval-after-load
|
|
3488 "mode-compile"
|
|
3489 '(setq perl-compilation-error-regexp-alist
|
|
3490 cperl-compilation-error-regexp-alist)))
|
|
3491
|
|
3492
|
|
3493 (defvar cperl-faces-init nil)
|
|
3494
|
|
3495 (defun cperl-windowed-init ()
|
|
3496 "Initialization under windowed version."
|
|
3497 (add-hook 'font-lock-mode-hook
|
|
3498 (function
|
|
3499 (lambda ()
|
|
3500 (if (or
|
|
3501 (eq major-mode 'perl-mode)
|
|
3502 (eq major-mode 'cperl-mode))
|
|
3503 (progn
|
|
3504 (or cperl-faces-init (cperl-init-faces))))))))
|
|
3505
|
|
3506 (defvar perl-font-lock-keywords-1 nil
|
|
3507 "Additional expressions to highlight in Perl mode. Minimal set.")
|
|
3508 (defvar perl-font-lock-keywords nil
|
|
3509 "Additional expressions to highlight in Perl mode. Default set.")
|
|
3510 (defvar perl-font-lock-keywords-2 nil
|
|
3511 "Additional expressions to highlight in Perl mode. Maximal set")
|
|
3512
|
|
3513 (defun cperl-init-faces ()
|
|
3514 (condition-case nil
|
|
3515 (progn
|
|
3516 (require 'font-lock)
|
|
3517 (and (fboundp 'font-lock-fontify-anchored-keywords)
|
|
3518 (featurep 'font-lock-extra)
|
|
3519 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
|
|
3520 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
|
|
3521 ;;(defvar cperl-font-lock-enhanced nil
|
|
3522 ;; "Set to be non-nil if font-lock allows active highlights.")
|
|
3523 (if (fboundp 'font-lock-fontify-anchored-keywords)
|
|
3524 (setq font-lock-anchored t))
|
|
3525 (setq
|
|
3526 t-font-lock-keywords
|
|
3527 (list
|
|
3528 (cons
|
|
3529 (concat
|
|
3530 "\\(^\\|[^$@%&\\]\\)\\<\\("
|
|
3531 (mapconcat
|
|
3532 'identity
|
|
3533 '("if" "until" "while" "elsif" "else" "unless" "for"
|
|
3534 "foreach" "continue" "exit" "die" "last" "goto" "next"
|
|
3535 "redo" "return" "local" "exec" "sub" "do" "dump" "use"
|
|
3536 "require" "package" "eval" "my" "BEGIN" "END")
|
|
3537 "\\|") ; Flow control
|
|
3538 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
|
|
3539 ; In what follows we use `type' style
|
4
|
3540 ; for overwritable builtins
|
0
|
3541 (list
|
|
3542 (concat
|
|
3543 "\\(^\\|[^$@%&\\]\\)\\<\\("
|
4
|
3544 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
|
|
3545 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
|
|
3546 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
|
|
3547 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
|
|
3548 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
|
|
3549 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
|
|
3550 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
|
|
3551 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
|
|
3552 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
|
|
3553 ;; "gethostbyname" "gethostent" "getlogin"
|
|
3554 ;; "getnetbyaddr" "getnetbyname" "getnetent"
|
|
3555 ;; "getpeername" "getpgrp" "getppid" "getpriority"
|
|
3556 ;; "getprotobyname" "getprotobynumber" "getprotoent"
|
|
3557 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
|
|
3558 ;; "getservbyport" "getservent" "getsockname"
|
|
3559 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
|
|
3560 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
|
|
3561 ;; "link" "listen" "localtime" "log" "lstat" "lt"
|
|
3562 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
|
|
3563 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
|
|
3564 ;; "quotemeta" "rand" "read" "readdir" "readline"
|
|
3565 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
|
|
3566 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
|
|
3567 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
|
|
3568 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
|
|
3569 ;; "setpriority" "setprotoent" "setpwent" "setservent"
|
|
3570 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
|
|
3571 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
|
|
3572 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
|
|
3573 ;; "syscall" "sysread" "system" "syswrite" "tell"
|
|
3574 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
|
|
3575 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
|
|
3576 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
|
0
|
3577 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
|
|
3578 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
|
|
3579 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
|
|
3580 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
|
|
3581 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
|
|
3582 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
|
|
3583 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
|
|
3584 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
|
|
3585 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
|
|
3586 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
|
|
3587 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
|
|
3588 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
|
|
3589 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
|
|
3590 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
|
|
3591 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
|
|
3592 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
|
|
3593 "\\(\\|ngth\\)\\|o\\(caltime\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
|
|
3594 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
|
|
3595 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
|
|
3596 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
|
|
3597 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
|
|
3598 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
|
|
3599 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
|
|
3600 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
|
|
3601 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
|
|
3602 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|tem\\|write\\)\\|"
|
|
3603 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
|
|
3604 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
|
|
3605 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
|
|
3606 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
|
193
|
3607 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
|
0
|
3608 "\\)\\>") 2 'font-lock-type-face)
|
|
3609 ;; In what follows we use `other' style
|
4
|
3610 ;; for nonoverwritable builtins
|
|
3611 ;; Somehow 's', 'm' are not auto-generated???
|
0
|
3612 (list
|
|
3613 (concat
|
|
3614 "\\(^\\|[^$@%&\\]\\)\\<\\("
|
4
|
3615 ;; "AUTOLOAD" "BEGIN" "DESTROY" "END" "__END__" "chomp"
|
|
3616 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
|
|
3617 ;; "eval" "exists" "for" "foreach" "format" "goto"
|
|
3618 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
|
|
3619 ;; "no" "package" "pop" "pos" "print" "printf" "push"
|
|
3620 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
|
|
3621 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
|
|
3622 ;; "undef" "unless" "unshift" "untie" "until" "use"
|
|
3623 ;; "while" "y"
|
0
|
3624 "AUTOLOAD\\|BEGIN\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
|
|
3625 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
|
|
3626 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|if\\|keys\\|"
|
|
3627 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|"
|
|
3628 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
|
|
3629 "q\\(\\|q\\|w\\|x\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
|
|
3630 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
|
|
3631 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
|
|
3632 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
|
|
3633 "\\|[sm]" ; Added manually
|
|
3634 "\\)\\>") 2 'font-lock-other-type-face)
|
|
3635 ;; (mapconcat 'identity
|
|
3636 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
|
|
3637 ;; "#include" "#define" "#undef")
|
|
3638 ;; "\\|")
|
|
3639 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
|
4
|
3640 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
|
193
|
3641 '("\\<sub[ \t]+\\([^ \t{;]+\\)[ \t]*\\(([^()]*)[ \t]*\\)?[#{\n]" 1
|
0
|
3642 font-lock-function-name-face)
|
|
3643 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
|
|
3644 2 font-lock-function-name-face)
|
4
|
3645 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
|
|
3646 1 font-lock-function-name-face)
|
0
|
3647 (cond ((featurep 'font-lock-extra)
|
|
3648 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
|
|
3649 (2 font-lock-string-face t)
|
|
3650 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
|
|
3651 (font-lock-anchored
|
|
3652 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
|
|
3653 (2 font-lock-string-face t)
|
|
3654 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
|
|
3655 nil nil
|
|
3656 (1 font-lock-string-face t))))
|
|
3657 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
|
|
3658 2 font-lock-string-face t)))
|
|
3659 '("[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
|
|
3660 font-lock-string-face t)
|
|
3661 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
|
|
3662 font-lock-reference-face) ; labels
|
|
3663 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
|
|
3664 2 font-lock-reference-face)
|
|
3665 (cond ((featurep 'font-lock-extra)
|
|
3666 '("^[ \t]*\\(my\\|local\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
|
|
3667 (3 font-lock-variable-name-face)
|
|
3668 (4 '(another 4 nil
|
|
3669 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
|
|
3670 (1 font-lock-variable-name-face)
|
|
3671 (2 '(restart 2 nil) nil t)))
|
|
3672 nil t))) ; local variables, multiple
|
|
3673 (font-lock-anchored
|
193
|
3674 '("^[ \t{}]*\\(my\\|local\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
|
0
|
3675 (3 font-lock-variable-name-face)
|
|
3676 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)"
|
|
3677 nil nil
|
|
3678 (1 font-lock-variable-name-face))))
|
193
|
3679 (t '("^[ \t{}]*\\(my\\|local\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
|
0
|
3680 3 font-lock-variable-name-face)))
|
|
3681 '("\\<for\\(each\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
|
|
3682 2 font-lock-variable-name-face)))
|
|
3683 (setq
|
|
3684 t-font-lock-keywords-1
|
|
3685 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
|
4
|
3686 (not cperl-xemacs-p) ; not yet as of XEmacs 19.12
|
|
3687 '(
|
|
3688 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
|
|
3689 (if (eq (char-after (match-beginning 2)) ?%)
|
|
3690 font-lock-other-emphasized-face
|
|
3691 font-lock-emphasized-face)
|
|
3692 t) ; arrays and hashes
|
|
3693 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
|
0
|
3694 1
|
|
3695 (if (= (- (match-end 2) (match-beginning 2)) 1)
|
|
3696 (if (eq (char-after (match-beginning 3)) ?{)
|
|
3697 font-lock-other-emphasized-face
|
|
3698 font-lock-emphasized-face) ; arrays and hashes
|
|
3699 font-lock-variable-name-face) ; Just to put something
|
|
3700 t)
|
|
3701 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
|
|
3702 ;;; Too much noise from \s* @s[ and friends
|
|
3703 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
|
|
3704 ;;(3 font-lock-function-name-face t t)
|
|
3705 ;;(4
|
|
3706 ;; (if (cperl-slash-is-regexp)
|
|
3707 ;; font-lock-function-name-face 'default) nil t))
|
|
3708 )))
|
|
3709 (setq perl-font-lock-keywords-1 t-font-lock-keywords
|
|
3710 perl-font-lock-keywords perl-font-lock-keywords-1
|
|
3711 perl-font-lock-keywords-2 (append
|
|
3712 t-font-lock-keywords
|
|
3713 t-font-lock-keywords-1)))
|
|
3714 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
|
|
3715 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
|
|
3716 (font-lock-require-faces
|
|
3717 (list
|
|
3718 ;; Color-light Color-dark Gray-light Gray-dark Mono
|
|
3719 (list 'font-lock-comment-face
|
|
3720 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
|
|
3721 nil
|
|
3722 [nil nil t t t]
|
|
3723 [nil nil t t t]
|
|
3724 nil)
|
|
3725 (list 'font-lock-string-face
|
|
3726 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
|
|
3727 nil
|
|
3728 nil
|
|
3729 [nil nil t t t]
|
|
3730 nil)
|
|
3731 (list 'font-lock-keyword-face
|
|
3732 ["Purple" "LightSteelBlue" "DimGray" "Gray90"]
|
|
3733 nil
|
|
3734 [nil nil t t t]
|
|
3735 nil
|
|
3736 nil)
|
|
3737 (list 'font-lock-function-name-face
|
|
3738 (vector
|
|
3739 "Blue" "LightSkyBlue" "Gray50" "LightGray"
|
|
3740 (cdr (assq 'background-color ; if mono
|
|
3741 (frame-parameters))))
|
|
3742 (vector
|
|
3743 nil nil nil nil
|
|
3744 (cdr (assq 'foreground-color ; if mono
|
|
3745 (frame-parameters))))
|
|
3746 [nil nil t t t]
|
|
3747 nil
|
|
3748 nil)
|
|
3749 (list 'font-lock-variable-name-face
|
|
3750 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
|
|
3751 nil
|
|
3752 [nil nil t t t]
|
|
3753 [nil nil t t t]
|
|
3754 nil)
|
|
3755 (list 'font-lock-type-face
|
|
3756 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
|
|
3757 nil
|
|
3758 [nil nil t t t]
|
|
3759 nil
|
|
3760 [nil nil t t t]
|
|
3761 )
|
|
3762 (list 'font-lock-reference-face
|
|
3763 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
|
|
3764 nil
|
|
3765 [nil nil t t t]
|
|
3766 nil
|
|
3767 [nil nil t t t]
|
|
3768 )
|
|
3769 (list 'font-lock-other-type-face
|
|
3770 ["chartreuse3" ("orchid1" "orange")
|
|
3771 nil "Gray80"]
|
|
3772 [nil nil "gray90"]
|
|
3773 [nil nil nil t t]
|
|
3774 [nil nil t t]
|
|
3775 [nil nil t t t]
|
|
3776 )
|
|
3777 (list 'font-lock-emphasized-face
|
|
3778 ["blue" "yellow" nil "Gray80"]
|
|
3779 ["lightyellow2" ("navy" "os2blue" "darkgreen")
|
|
3780 "gray90"]
|
|
3781 t
|
|
3782 nil
|
|
3783 nil)
|
|
3784 (list 'font-lock-other-emphasized-face
|
|
3785 ["red" "red" nil "Gray80"]
|
|
3786 ["lightyellow2" ("navy" "os2blue" "darkgreen")
|
|
3787 "gray90"]
|
|
3788 t
|
|
3789 t
|
|
3790 nil)))
|
|
3791 (defvar cperl-guessed-background nil
|
|
3792 "Display characteristics as guessed by cperl.")
|
|
3793 (or (fboundp 'x-color-defined-p)
|
|
3794 (defalias 'x-color-defined-p
|
|
3795 (cond ((fboundp 'color-defined-p) 'color-defined-p)
|
|
3796 ;; XEmacs >= 19.12
|
|
3797 ((fboundp 'valid-color-name-p) 'valid-color-name-p)
|
|
3798 ;; XEmacs 19.11
|
|
3799 (t 'x-valid-color-name-p))))
|
|
3800 (defvar font-lock-reference-face 'font-lock-reference-face)
|
|
3801 (defvar font-lock-variable-name-face 'font-lock-variable-name-face)
|
|
3802 (or (boundp 'font-lock-type-face)
|
|
3803 (defconst font-lock-type-face
|
|
3804 'font-lock-type-face
|
|
3805 "Face to use for data types.")
|
|
3806 )
|
|
3807 (or (boundp 'font-lock-other-type-face)
|
|
3808 (defconst font-lock-other-type-face
|
|
3809 'font-lock-other-type-face
|
|
3810 "Face to use for data types from another group.")
|
|
3811 )
|
4
|
3812 (if (not cperl-xemacs-p) nil
|
0
|
3813 (or (boundp 'font-lock-comment-face)
|
|
3814 (defconst font-lock-comment-face
|
|
3815 'font-lock-comment-face
|
|
3816 "Face to use for comments.")
|
|
3817 )
|
|
3818 (or (boundp 'font-lock-keyword-face)
|
|
3819 (defconst font-lock-keyword-face
|
|
3820 'font-lock-keyword-face
|
|
3821 "Face to use for keywords.")
|
|
3822 )
|
|
3823 (or (boundp 'font-lock-function-name-face)
|
|
3824 (defconst font-lock-function-name-face
|
|
3825 'font-lock-function-name-face
|
|
3826 "Face to use for function names.")
|
|
3827 )
|
|
3828 )
|
|
3829 ;;(if (featurep 'font-lock)
|
|
3830 (if (face-equal font-lock-type-face font-lock-comment-face)
|
|
3831 (defconst font-lock-type-face
|
|
3832 'font-lock-type-face
|
|
3833 "Face to use for basic data types.")
|
|
3834 )
|
|
3835 ;;; (if (fboundp 'eval-after-load)
|
|
3836 ;;; (eval-after-load "font-lock"
|
|
3837 ;;; '(if (face-equal font-lock-type-face
|
|
3838 ;;; font-lock-comment-face)
|
|
3839 ;;; (defconst font-lock-type-face
|
|
3840 ;;; 'font-lock-type-face
|
|
3841 ;;; "Face to use for basic data types.")
|
|
3842 ;;; ))) ; This does not work :-( Why?!
|
|
3843 ;;; ; Workaround: added to font-lock-m-h
|
|
3844 ;;; )
|
|
3845 (or (boundp 'font-lock-other-emphasized-face)
|
|
3846 (defconst font-lock-other-emphasized-face
|
|
3847 'font-lock-other-emphasized-face
|
|
3848 "Face to use for another type of emphasizing.")
|
|
3849 )
|
|
3850 (or (boundp 'font-lock-emphasized-face)
|
|
3851 (defconst font-lock-emphasized-face
|
|
3852 'font-lock-emphasized-face
|
|
3853 "Face to use for emphasizing.")
|
|
3854 )
|
|
3855 ;; Here we try to guess background
|
|
3856 (let ((background
|
|
3857 (if (boundp 'font-lock-background-mode)
|
|
3858 font-lock-background-mode
|
|
3859 'light))
|
|
3860 (face-list (and (fboundp 'face-list) (face-list)))
|
|
3861 is-face)
|
|
3862 (fset 'is-face
|
|
3863 (cond ((fboundp 'find-face)
|
|
3864 (symbol-function 'find-face))
|
|
3865 (face-list
|
|
3866 (function (lambda (face) (member face face-list))))
|
|
3867 (t
|
|
3868 (function (lambda (face) (boundp face))))))
|
|
3869 (defvar cperl-guessed-background
|
|
3870 (if (and (boundp 'font-lock-display-type)
|
|
3871 (eq font-lock-display-type 'grayscale))
|
|
3872 'gray
|
|
3873 background)
|
|
3874 "Background as guessed by CPerl mode")
|
|
3875 (if (is-face 'font-lock-type-face) nil
|
|
3876 (copy-face 'default 'font-lock-type-face)
|
|
3877 (cond
|
|
3878 ((eq background 'light)
|
|
3879 (set-face-foreground 'font-lock-type-face
|
|
3880 (if (x-color-defined-p "seagreen")
|
|
3881 "seagreen"
|
|
3882 "sea green")))
|
|
3883 ((eq background 'dark)
|
|
3884 (set-face-foreground 'font-lock-type-face
|
|
3885 (if (x-color-defined-p "os2pink")
|
|
3886 "os2pink"
|
|
3887 "pink")))
|
|
3888 (t
|
|
3889 (set-face-background 'font-lock-type-face "gray90"))))
|
|
3890 (if (is-face 'font-lock-other-type-face)
|
|
3891 nil
|
|
3892 (copy-face 'font-lock-type-face 'font-lock-other-type-face)
|
|
3893 (cond
|
|
3894 ((eq background 'light)
|
|
3895 (set-face-foreground 'font-lock-other-type-face
|
|
3896 (if (x-color-defined-p "chartreuse3")
|
|
3897 "chartreuse3"
|
|
3898 "chartreuse")))
|
|
3899 ((eq background 'dark)
|
|
3900 (set-face-foreground 'font-lock-other-type-face
|
|
3901 (if (x-color-defined-p "orchid1")
|
|
3902 "orchid1"
|
|
3903 "orange")))))
|
|
3904 (if (is-face 'font-lock-other-emphasized-face) nil
|
|
3905 (copy-face 'bold-italic 'font-lock-other-emphasized-face)
|
|
3906 (cond
|
|
3907 ((eq background 'light)
|
|
3908 (set-face-background 'font-lock-other-emphasized-face
|
|
3909 (if (x-color-defined-p "lightyellow2")
|
|
3910 "lightyellow2"
|
|
3911 (if (x-color-defined-p "lightyellow")
|
|
3912 "lightyellow"
|
|
3913 "light yellow"))))
|
|
3914 ((eq background 'dark)
|
|
3915 (set-face-background 'font-lock-other-emphasized-face
|
|
3916 (if (x-color-defined-p "navy")
|
|
3917 "navy"
|
|
3918 (if (x-color-defined-p "darkgreen")
|
|
3919 "darkgreen"
|
|
3920 "dark green"))))
|
|
3921 (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
|
|
3922 (if (is-face 'font-lock-emphasized-face) nil
|
|
3923 (copy-face 'bold 'font-lock-emphasized-face)
|
|
3924 (cond
|
|
3925 ((eq background 'light)
|
|
3926 (set-face-background 'font-lock-emphasized-face
|
|
3927 (if (x-color-defined-p "lightyellow2")
|
|
3928 "lightyellow2"
|
|
3929 "lightyellow")))
|
|
3930 ((eq background 'dark)
|
|
3931 (set-face-background 'font-lock-emphasized-face
|
|
3932 (if (x-color-defined-p "navy")
|
|
3933 "navy"
|
|
3934 (if (x-color-defined-p "darkgreen")
|
|
3935 "darkgreen"
|
|
3936 "dark green"))))
|
|
3937 (t (set-face-background 'font-lock-emphasized-face "gray90"))))
|
|
3938 (if (is-face 'font-lock-variable-name-face) nil
|
|
3939 (copy-face 'italic 'font-lock-variable-name-face))
|
|
3940 (if (is-face 'font-lock-reference-face) nil
|
|
3941 (copy-face 'italic 'font-lock-reference-face))))
|
|
3942 (setq cperl-faces-init t))
|
|
3943 (error nil)))
|
|
3944
|
|
3945
|
|
3946 (defun cperl-ps-print-init ()
|
|
3947 "Initialization of `ps-print' components for faces used in CPerl."
|
|
3948 ;; Guard against old versions
|
|
3949 (defvar ps-underlined-faces nil)
|
|
3950 (defvar ps-bold-faces nil)
|
|
3951 (defvar ps-italic-faces nil)
|
|
3952 (setq ps-bold-faces
|
|
3953 (append '(font-lock-emphasized-face
|
|
3954 font-lock-keyword-face
|
|
3955 font-lock-variable-name-face
|
|
3956 font-lock-reference-face
|
|
3957 font-lock-other-emphasized-face)
|
|
3958 ps-bold-faces))
|
|
3959 (setq ps-italic-faces
|
|
3960 (append '(font-lock-other-type-face
|
|
3961 font-lock-reference-face
|
|
3962 font-lock-other-emphasized-face)
|
|
3963 ps-italic-faces))
|
|
3964 (setq ps-underlined-faces
|
|
3965 (append '(font-lock-emphasized-face
|
|
3966 font-lock-other-emphasized-face
|
|
3967 font-lock-other-type-face font-lock-type-face)
|
|
3968 ps-underlined-faces))
|
|
3969 (cons 'font-lock-type-face ps-underlined-faces))
|
|
3970
|
|
3971
|
|
3972 (if (cperl-enable-font-lock) (cperl-windowed-init))
|
|
3973
|
|
3974 (defun cperl-set-style (style)
|
|
3975 "Set CPerl-mode variables to use one of several different indentation styles.
|
|
3976 The arguments are a string representing the desired style.
|
|
3977 Available styles are GNU, K&R, BSD and Whitesmith."
|
|
3978 (interactive
|
193
|
3979 (let ((list (progn
|
|
3980 (require 'cc-styles)
|
|
3981 (mapcar (function (lambda (elt) (list (car elt))))
|
|
3982 c-style-alist))))
|
0
|
3983 (list (completing-read "Enter style: " list nil 'insist))))
|
|
3984 (let ((style (cdr (assoc style c-style-alist))) setting str sym)
|
|
3985 (while style
|
|
3986 (setq setting (car style) style (cdr style))
|
|
3987 (setq str (symbol-name (car setting)))
|
|
3988 (and (string-match "^c-" str)
|
|
3989 (setq str (concat "cperl-" (substring str 2)))
|
|
3990 (setq sym (intern-soft str))
|
|
3991 (boundp sym)
|
|
3992 (set sym (cdr setting))))))
|
|
3993
|
|
3994 (defun cperl-check-syntax ()
|
|
3995 (interactive)
|
|
3996 (require 'mode-compile)
|
|
3997 (let ((perl-dbg-flags "-wc"))
|
|
3998 (mode-compile)))
|
|
3999
|
110
|
4000 (defun cperl-info-buffer (type)
|
|
4001 ;; Returns buffer with documentation. Creates if missing.
|
|
4002 ;; If TYPE, this vars buffer.
|
|
4003 ;; Special care is taken to not stomp over an existing info buffer
|
|
4004 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
|
|
4005 (info (get-buffer bname))
|
|
4006 (oldbuf (get-buffer "*info*")))
|
0
|
4007 (if info info
|
|
4008 (save-window-excursion
|
|
4009 ;; Get Info running
|
|
4010 (require 'info)
|
110
|
4011 (cond (oldbuf
|
|
4012 (set-buffer oldbuf)
|
|
4013 (rename-buffer "*info-perl-tmp*")))
|
0
|
4014 (save-window-excursion
|
|
4015 (info))
|
110
|
4016 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
|
0
|
4017 (set-buffer "*info*")
|
110
|
4018 (rename-buffer bname)
|
|
4019 (cond (oldbuf
|
|
4020 (set-buffer "*info-perl-tmp*")
|
|
4021 (rename-buffer "*info*")
|
|
4022 (set-buffer bname)))
|
|
4023 (make-variable-buffer-local 'window-min-height)
|
|
4024 (setq window-min-height 2)
|
0
|
4025 (current-buffer)))))
|
|
4026
|
|
4027 (defun cperl-word-at-point (&optional p)
|
|
4028 ;; Returns the word at point or at P.
|
|
4029 (save-excursion
|
|
4030 (if p (goto-char p))
|
110
|
4031 (or (cperl-word-at-point-hard)
|
|
4032 (progn
|
|
4033 (require 'etags)
|
|
4034 (funcall (or (and (boundp 'find-tag-default-function)
|
|
4035 find-tag-default-function)
|
|
4036 (get major-mode 'find-tag-default-function)
|
|
4037 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
|
|
4038 ;; automatically used within `find-tag-default':
|
|
4039 'find-tag-default))))))
|
0
|
4040
|
|
4041 (defun cperl-info-on-command (command)
|
110
|
4042 "Shows documentation for Perl command in other window.
|
|
4043 If perl-info buffer is shown in some frame, uses this frame.
|
|
4044 Customized by setting variables `cperl-shrink-wrap-info-frame',
|
|
4045 `cperl-max-help-size'."
|
0
|
4046 (interactive
|
|
4047 (let* ((default (cperl-word-at-point))
|
|
4048 (read (read-string
|
|
4049 (format "Find doc for Perl function (default %s): "
|
|
4050 default))))
|
|
4051 (list (if (equal read "")
|
|
4052 default
|
|
4053 read))))
|
|
4054
|
|
4055 (let ((buffer (current-buffer))
|
|
4056 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
|
110
|
4057 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
|
|
4058 max-height char-height buf-list)
|
0
|
4059 (if (string-match "^-[a-zA-Z]$" command)
|
|
4060 (setq cmd-desc "^-X[ \t\n]"))
|
110
|
4061 (setq isvar (string-match "^[$@%]" command)
|
|
4062 buf (cperl-info-buffer isvar)
|
|
4063 iniwin (selected-window)
|
|
4064 fr1 (window-frame iniwin))
|
|
4065 (set-buffer buf)
|
0
|
4066 (beginning-of-buffer)
|
110
|
4067 (or isvar
|
|
4068 (progn (re-search-forward "^-X[ \t\n]")
|
|
4069 (forward-line -1)))
|
0
|
4070 (if (re-search-forward cmd-desc nil t)
|
|
4071 (progn
|
110
|
4072 ;; Go back to beginning of the group (ex, for qq)
|
|
4073 (if (re-search-backward "^[ \t\n\f]")
|
|
4074 (forward-line 1))
|
|
4075 (beginning-of-line)
|
|
4076 ;; Get some of
|
|
4077 (setq pos (point)
|
|
4078 buf-list (list buf "*info-perl-var*" "*info-perl*"))
|
|
4079 (while (and (not win) buf-list)
|
|
4080 (setq win (get-buffer-window (car buf-list) t))
|
|
4081 (setq buf-list (cdr buf-list)))
|
|
4082 (or (not win)
|
|
4083 (eq (window-buffer win) buf)
|
|
4084 (set-window-buffer win buf))
|
|
4085 (and win (setq fr2 (window-frame win)))
|
|
4086 (if (or (not fr2) (eq fr1 fr2))
|
|
4087 (pop-to-buffer buf)
|
|
4088 (special-display-popup-frame buf) ; Make it visible
|
|
4089 (select-window win))
|
|
4090 (goto-char pos) ; Needed (?!).
|
|
4091 ;; Resize
|
|
4092 (setq iniheight (window-height)
|
|
4093 frheight (frame-height)
|
|
4094 not-loner (< iniheight (1- frheight))) ; Are not alone
|
|
4095 (cond ((if not-loner cperl-max-help-size
|
|
4096 cperl-shrink-wrap-info-frame)
|
|
4097 (setq height
|
|
4098 (+ 2
|
|
4099 (count-lines
|
|
4100 pos
|
|
4101 (save-excursion
|
|
4102 (if (re-search-forward
|
|
4103 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
|
|
4104 (match-beginning 0) (point-max)))))
|
|
4105 max-height
|
|
4106 (if not-loner
|
|
4107 (/ (* (- frheight 3) cperl-max-help-size) 100)
|
|
4108 (setq char-height (frame-char-height))
|
|
4109 ;; Non-functioning under OS/2:
|
|
4110 (if (eq char-height 1) (setq char-height 18))
|
|
4111 ;; Title, menubar, + 2 for slack
|
|
4112 (- (/ (x-display-pixel-height) char-height) 4)
|
|
4113 ))
|
|
4114 (if (> height max-height) (setq height max-height))
|
|
4115 ;;(message "was %s doing %s" iniheight height)
|
|
4116 (if not-loner
|
|
4117 (enlarge-window (- height iniheight))
|
|
4118 (set-frame-height (window-frame win) (1+ height)))))
|
0
|
4119 (set-window-start (selected-window) pos))
|
|
4120 (message "No entry for %s found." command))
|
110
|
4121 ;;(pop-to-buffer buffer)
|
|
4122 (select-window iniwin)))
|
0
|
4123
|
|
4124 (defun cperl-info-on-current-command ()
|
|
4125 "Shows documentation for Perl command at point in other window."
|
|
4126 (interactive)
|
|
4127 (cperl-info-on-command (cperl-word-at-point)))
|
|
4128
|
193
|
4129 ;;(defun cperl-imenu-info-imenu-search ()
|
|
4130 ;; (if (looking-at "^-X[ \t\n]") nil
|
|
4131 ;; (re-search-backward
|
|
4132 ;; "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
|
|
4133 ;; (forward-line 1)))
|
|
4134
|
|
4135 ;;(defun cperl-imenu-info-imenu-name ()
|
|
4136 ;; (buffer-substring
|
|
4137 ;; (match-beginning 1) (match-end 1)))
|
|
4138
|
|
4139 ;;(defun cperl-imenu-on-info ()
|
|
4140 ;; (interactive)
|
|
4141 ;; (let* ((buffer (current-buffer))
|
|
4142 ;; imenu-create-index-function
|
|
4143 ;; imenu-prev-index-position-function
|
|
4144 ;; imenu-extract-index-name-function
|
|
4145 ;; (index-item (save-restriction
|
|
4146 ;; (save-window-excursion
|
|
4147 ;; (set-buffer (cperl-info-buffer nil))
|
|
4148 ;; (setq imenu-create-index-function
|
|
4149 ;; 'imenu-default-create-index-function
|
|
4150 ;; imenu-prev-index-position-function
|
|
4151 ;; 'cperl-imenu-info-imenu-search
|
|
4152 ;; imenu-extract-index-name-function
|
|
4153 ;; 'cperl-imenu-info-imenu-name)
|
|
4154 ;; (imenu-choose-buffer-index)))))
|
|
4155 ;; (and index-item
|
|
4156 ;; (progn
|
|
4157 ;; (push-mark)
|
|
4158 ;; (pop-to-buffer "*info-perl*")
|
|
4159 ;; (cond
|
|
4160 ;; ((markerp (cdr index-item))
|
|
4161 ;; (goto-char (marker-position (cdr index-item))))
|
|
4162 ;; (t
|
|
4163 ;; (goto-char (cdr index-item))))
|
|
4164 ;; (set-window-start (selected-window) (point))
|
|
4165 ;; (pop-to-buffer buffer)))))
|
0
|
4166
|
|
4167 (defun cperl-lineup (beg end &optional step minshift)
|
|
4168 "Lineup construction in a region.
|
|
4169 Beginning of region should be at the start of a construction.
|
4
|
4170 All first occurrences of this construction in the lines that are
|
0
|
4171 partially contained in the region are lined up at the same column.
|
|
4172
|
|
4173 MINSHIFT is the minimal amount of space to insert before the construction.
|
|
4174 STEP is the tabwidth to position constructions.
|
|
4175 If STEP is `nil', `cperl-lineup-step' will be used
|
|
4176 \(or `cperl-indent-level', if `cperl-lineup-step' is `nil').
|
|
4177 Will not move the position at the start to the left."
|
|
4178 (interactive "r")
|
|
4179 (let (search col tcol seen b e)
|
|
4180 (save-excursion
|
|
4181 (goto-char end)
|
|
4182 (end-of-line)
|
|
4183 (setq end (point-marker))
|
|
4184 (goto-char beg)
|
|
4185 (skip-chars-forward " \t\f")
|
|
4186 (setq beg (point-marker))
|
|
4187 (indent-region beg end nil)
|
|
4188 (goto-char beg)
|
|
4189 (setq col (current-column))
|
4
|
4190 (if (looking-at "[a-zA-Z0-9_]")
|
|
4191 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
|
0
|
4192 (setq search
|
|
4193 (concat "\\<"
|
|
4194 (regexp-quote
|
|
4195 (buffer-substring (match-beginning 0)
|
|
4196 (match-end 0))) "\\>"))
|
|
4197 (error "Cannot line up in a middle of the word"))
|
|
4198 (if (looking-at "$")
|
|
4199 (error "Cannot line up end of line"))
|
|
4200 (setq search (regexp-quote (char-to-string (following-char)))))
|
|
4201 (setq step (or step cperl-lineup-step cperl-indent-level))
|
|
4202 (or minshift (setq minshift 1))
|
|
4203 (while (progn
|
|
4204 (beginning-of-line 2)
|
|
4205 (and (< (point) end)
|
|
4206 (re-search-forward search end t)
|
|
4207 (goto-char (match-beginning 0))))
|
|
4208 (setq tcol (current-column) seen t)
|
|
4209 (if (> tcol col) (setq col tcol)))
|
|
4210 (or seen
|
4
|
4211 (error "The construction to line up occurred only once"))
|
0
|
4212 (goto-char beg)
|
|
4213 (setq col (+ col minshift))
|
|
4214 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
|
|
4215 (while
|
|
4216 (progn
|
|
4217 (setq e (point))
|
|
4218 (skip-chars-backward " \t")
|
|
4219 (delete-region (point) e)
|
|
4220 (indent-to-column col); (make-string (- col (current-column)) ?\ ))
|
|
4221 (beginning-of-line 2)
|
|
4222 (and (< (point) end)
|
|
4223 (re-search-forward search end t)
|
|
4224 (goto-char (match-beginning 0)))))))) ; No body
|
|
4225
|
|
4226 (defun cperl-etags (&optional add all files)
|
|
4227 "Run etags with appropriate options for Perl files.
|
|
4228 If optional argument ALL is `recursive', will process Perl files
|
|
4229 in subdirectories too."
|
|
4230 (interactive)
|
|
4231 (let ((cmd "etags")
|
193
|
4232 (args '("-l" "none" "-r" "/\\<\\(package\\|sub\\)[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([{#]\\|$\\)\\)/\\4/"))
|
0
|
4233 res)
|
|
4234 (if add (setq args (cons "-a" args)))
|
|
4235 (or files (setq files (list buffer-file-name)))
|
|
4236 (cond
|
|
4237 ((eq all 'recursive)
|
|
4238 ;;(error "Not implemented: recursive")
|
|
4239 (setq args (append (list "-e"
|
193
|
4240 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
|
0
|
4241 use File::Find;
|
|
4242 find(\\&wanted, '.');
|
|
4243 exec @ARGV;"
|
|
4244 cmd) args)
|
|
4245 cmd "perl"))
|
|
4246 (all
|
|
4247 ;;(error "Not implemented: all")
|
|
4248 (setq args (append (list "-e"
|
|
4249 "push @ARGV, <*.PL *.pl *.pm>;
|
|
4250 exec @ARGV;"
|
|
4251 cmd) args)
|
|
4252 cmd "perl"))
|
|
4253 (t
|
|
4254 (setq args (append args files))))
|
|
4255 (setq res (apply 'call-process cmd nil nil nil args))
|
|
4256 (or (eq res 0)
|
|
4257 (message "etags returned \"%s\"" res))))
|
|
4258
|
|
4259 (defun cperl-toggle-auto-newline ()
|
|
4260 "Toggle the state of `cperl-auto-newline'."
|
|
4261 (interactive)
|
|
4262 (setq cperl-auto-newline (not cperl-auto-newline))
|
|
4263 (message "Newlines will %sbe auto-inserted now."
|
|
4264 (if cperl-auto-newline "" "not ")))
|
|
4265
|
|
4266 (defun cperl-toggle-abbrev ()
|
|
4267 "Toggle the state of automatic keyword expansion in CPerl mode."
|
|
4268 (interactive)
|
|
4269 (abbrev-mode (if abbrev-mode 0 1))
|
|
4270 (message "Perl control structure will %sbe auto-inserted now."
|
|
4271 (if abbrev-mode "" "not ")))
|
|
4272
|
|
4273
|
|
4274 (defun cperl-toggle-electric ()
|
|
4275 "Toggle the state of parentheses doubling in CPerl mode."
|
|
4276 (interactive)
|
|
4277 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
|
|
4278 (message "Parentheses will %sbe auto-doubled now."
|
|
4279 (if (cperl-val 'cperl-electric-parens) "" "not ")))
|
|
4280
|
4
|
4281 ;;;; Tags file creation.
|
|
4282
|
|
4283 (defvar cperl-tmp-buffer " *cperl-tmp*")
|
|
4284
|
|
4285 (defun cperl-setup-tmp-buf ()
|
|
4286 (set-buffer (get-buffer-create cperl-tmp-buffer))
|
|
4287 (set-syntax-table cperl-mode-syntax-table)
|
|
4288 (buffer-disable-undo)
|
193
|
4289 (auto-fill-mode 0)
|
|
4290 (if cperl-use-syntax-table-text-property-for-tags
|
|
4291 (progn
|
|
4292 (make-variable-buffer-local 'parse-sexp-lookup-properties)
|
|
4293 ;; Do not introduce variable if not needed, we check it!
|
|
4294 (set 'parse-sexp-lookup-properties t))))
|
4
|
4295
|
|
4296 (defun cperl-xsub-scan ()
|
|
4297 (require 'cl)
|
|
4298 (require 'imenu)
|
|
4299 (let ((index-alist '())
|
|
4300 (prev-pos 0) index index1 name package prefix)
|
|
4301 (goto-char (point-min))
|
|
4302 (imenu-progress-message prev-pos 0)
|
|
4303 ;; Search for the function
|
|
4304 (progn ;;save-match-data
|
|
4305 (while (re-search-forward
|
|
4306 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
|
|
4307 nil t)
|
|
4308 (imenu-progress-message prev-pos)
|
|
4309 (cond
|
|
4310 ((match-beginning 2) ; SECTION
|
|
4311 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
|
|
4312 (goto-char (match-beginning 0))
|
|
4313 (skip-chars-forward " \t")
|
|
4314 (forward-char 1)
|
|
4315 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
|
|
4316 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
|
|
4317 (setq prefix nil)))
|
|
4318 ((not package) nil) ; C language section
|
|
4319 ((match-beginning 3) ; XSUB
|
|
4320 (goto-char (1+ (match-beginning 3)))
|
|
4321 (setq index (imenu-example--name-and-position))
|
|
4322 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
|
|
4323 (if (and prefix (string-match (concat "^" prefix) name))
|
|
4324 (setq name (substring name (length prefix))))
|
|
4325 (cond ((string-match "::" name) nil)
|
|
4326 (t
|
|
4327 (setq index1 (cons (concat package "::" name) (cdr index)))
|
|
4328 (push index1 index-alist)))
|
|
4329 (setcar index name)
|
|
4330 (push index index-alist))
|
|
4331 (t ; BOOT: section
|
|
4332 ;; (beginning-of-line)
|
|
4333 (setq index (imenu-example--name-and-position))
|
|
4334 (setcar index (concat package "::BOOT:"))
|
|
4335 (push index index-alist)))))
|
|
4336 (imenu-progress-message prev-pos 100)
|
|
4337 ;;(setq index-alist
|
|
4338 ;; (if (default-value 'imenu-sort-function)
|
|
4339 ;; (sort index-alist (default-value 'imenu-sort-function))
|
|
4340 ;; (nreverse index-alist)))
|
|
4341 index-alist))
|
|
4342
|
|
4343 (defun cperl-find-tags (file xs)
|
193
|
4344 (let (ind (b (get-buffer cperl-tmp-buffer)) lst elt pos ret
|
|
4345 (cperl-pod-here-fontify nil))
|
4
|
4346 (save-excursion
|
|
4347 (if b (set-buffer b)
|
|
4348 (cperl-setup-tmp-buf))
|
|
4349 (erase-buffer)
|
|
4350 (setq file (car (insert-file-contents file)))
|
|
4351 (message "Scanning file %s..." file)
|
193
|
4352 (if cperl-use-syntax-table-text-property-for-tags
|
|
4353 (cperl-find-pods-heres))
|
4
|
4354 (if xs
|
|
4355 (setq lst (cperl-xsub-scan))
|
|
4356 (setq ind (imenu-example--create-perl-index))
|
|
4357 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
|
|
4358 (setq lst
|
|
4359 (mapcar
|
|
4360 (function
|
|
4361 (lambda (elt)
|
|
4362 (cond ((string-match "^[_a-zA-Z]" (car elt))
|
|
4363 (goto-char (cdr elt))
|
|
4364 (list (car elt)
|
|
4365 (point) (count-lines 1 (point))
|
|
4366 (buffer-substring (progn
|
|
4367 (skip-chars-forward
|
|
4368 ":_a-zA-Z0-9")
|
|
4369 (or (eolp) (forward-char 1))
|
|
4370 (point))
|
|
4371 (progn
|
|
4372 (beginning-of-line)
|
|
4373 (point))))))))
|
|
4374 lst))
|
|
4375 (erase-buffer)
|
|
4376 (while lst
|
|
4377 (setq elt (car lst) lst (cdr lst))
|
|
4378 (if elt
|
|
4379 (progn
|
|
4380 (insert (elt elt 3)
|
|
4381 127
|
|
4382 (if (string-match "^package " (car elt))
|
|
4383 (substring (car elt) 8)
|
|
4384 (car elt) )
|
|
4385 1
|
|
4386 (number-to-string (elt elt 1))
|
|
4387 ","
|
|
4388 (number-to-string (elt elt 2))
|
|
4389 "\n")
|
|
4390 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
|
|
4391 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
|
|
4392 (elt elt 3)))
|
|
4393 ;; Need to insert the name without package as well
|
|
4394 (setq lst (cons (cons (substring (elt elt 3)
|
|
4395 (match-beginning 1)
|
|
4396 (match-end 1))
|
|
4397 (cdr elt))
|
|
4398 lst))))))
|
|
4399 (setq pos (point))
|
|
4400 (goto-char 1)
|
|
4401 (insert "\f\n" file "," (number-to-string (1- pos)) "\n")
|
|
4402 (setq ret (buffer-substring 1 (point-max)))
|
|
4403 (erase-buffer)
|
|
4404 (message "Scanning file %s finished" file)
|
|
4405 ret)))
|
|
4406
|
|
4407 (defun cperl-write-tags (&optional file erase recurse dir inbuffer)
|
|
4408 ;; If INBUFFER, do not select buffer, and do not save
|
|
4409 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
|
|
4410 (require 'etags)
|
|
4411 (if file nil
|
|
4412 (setq file (if dir default-directory (buffer-file-name)))
|
|
4413 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
|
|
4414 (let ((tags-file-name "TAGS")
|
|
4415 (case-fold-search (eq system-type 'emx))
|
|
4416 xs)
|
|
4417 (save-excursion
|
|
4418 (cond (inbuffer nil) ; Already there
|
|
4419 ((file-exists-p tags-file-name)
|
203
|
4420 (visit-tags-table-buffer))
|
4
|
4421 (t (set-buffer (find-file-noselect tags-file-name))))
|
|
4422 (cond
|
|
4423 (dir
|
|
4424 (cond ((eq erase 'ignore))
|
|
4425 (erase
|
|
4426 (erase-buffer)
|
|
4427 (setq erase 'ignore)))
|
|
4428 (let ((files
|
193
|
4429 (directory-files file t
|
|
4430 (if recurse nil cperl-scan-files-regexp)
|
|
4431 t)))
|
4
|
4432 (mapcar (function (lambda (file)
|
|
4433 (cond
|
193
|
4434 ((string-match cperl-noscan-files-regexp file)
|
|
4435 nil)
|
4
|
4436 ((not (file-directory-p file))
|
193
|
4437 (if (string-match cperl-scan-files-regexp file)
|
4
|
4438 (cperl-write-tags file erase recurse nil t)))
|
|
4439 ((not recurse) nil)
|
|
4440 (t (cperl-write-tags file erase recurse t t)))))
|
|
4441 files))
|
|
4442 )
|
|
4443 (t
|
|
4444 (setq xs (string-match "\\.xs$" file))
|
110
|
4445 (cond ((eq erase 'ignore) (goto-char (point-max)))
|
4
|
4446 (erase (erase-buffer))
|
|
4447 (t
|
|
4448 (goto-char 1)
|
|
4449 (if (search-forward (concat "\f\n" file ",") nil t)
|
|
4450 (progn
|
|
4451 (search-backward "\f\n")
|
|
4452 (delete-region (point)
|
193
|
4453 (save-excursion
|
4
|
4454 (forward-char 1)
|
193
|
4455 (if (search-forward "\f\n" nil 'toend)
|
|
4456 (- (point) 2)
|
|
4457 (point-max)))))
|
110
|
4458 (goto-char (point-max)))))
|
4
|
4459 (insert (cperl-find-tags file xs))))
|
|
4460 (if inbuffer nil ; Delegate to the caller
|
|
4461 (save-buffer 0) ; No backup
|
110
|
4462 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
|
|
4463 (initialize-new-tags-table))))))
|
4
|
4464
|
|
4465 (defvar cperl-tags-hier-regexp-list
|
193
|
4466 (concat
|
|
4467 "^\\("
|
|
4468 "\\(package\\)\\>"
|
|
4469 "\\|"
|
|
4470 "sub\\>[^\n]+::"
|
|
4471 "\\|"
|
|
4472 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
|
|
4473 "\\|"
|
|
4474 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
|
|
4475 "\\)"))
|
4
|
4476
|
|
4477 (defvar cperl-hierarchy '(() ())
|
|
4478 "Global hierarchy of classes")
|
|
4479
|
|
4480 (defun cperl-tags-hier-fill ()
|
|
4481 ;; Suppose we are in a tag table cooked by cperl.
|
|
4482 (goto-char 1)
|
|
4483 (let (type pack name pos line chunk ord cons1 file str info fileind)
|
|
4484 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
|
|
4485 (setq pos (match-beginning 0)
|
|
4486 pack (match-beginning 2))
|
|
4487 (beginning-of-line)
|
193
|
4488 (if (looking-at (concat
|
|
4489 "\\([^\n]+\\)"
|
|
4490 "\C-?"
|
|
4491 "\\([^\n]+\\)"
|
|
4492 "\C-a"
|
|
4493 "\\([0-9]+\\)"
|
|
4494 ","
|
|
4495 "\\([0-9]+\\)"))
|
4
|
4496 (progn
|
|
4497 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
|
|
4498 name (buffer-substring (match-beginning 2) (match-end 2))
|
|
4499 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
|
|
4500 line (buffer-substring (match-beginning 4) (match-end 4))
|
|
4501 ord (if pack 1 0)
|
|
4502 info (etags-snarf-tag) ; Moves to beginning of the next line
|
|
4503 file (file-of-tag)
|
|
4504 fileind (format "%s:%s" file line))
|
|
4505 ;; Move back
|
|
4506 (forward-char -1)
|
|
4507 ;; Make new member of hierarchy name ==> file ==> pos if needed
|
|
4508 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
|
|
4509 ;; Name known
|
|
4510 (setcdr cons1 (cons (cons fileind (vector file info))
|
|
4511 (cdr cons1)))
|
|
4512 ;; First occurrence of the name, start alist
|
|
4513 (setq cons1 (cons name (list (cons fileind (vector file info)))))
|
|
4514 (if pack
|
|
4515 (setcar (cdr cperl-hierarchy)
|
|
4516 (cons cons1 (nth 1 cperl-hierarchy)))
|
|
4517 (setcar cperl-hierarchy
|
|
4518 (cons cons1 (car cperl-hierarchy)))))))
|
|
4519 (end-of-line))))
|
|
4520
|
|
4521 (defun cperl-tags-hier-init (&optional update)
|
|
4522 "Show hierarchical menu of classes and methods.
|
|
4523 Finds info about classes by a scan of loaded TAGS files.
|
|
4524 Supposes that the TAGS files contain fully qualified function names.
|
|
4525 One may build such TAGS files from CPerl mode menu."
|
|
4526 (interactive)
|
|
4527 (require 'etags)
|
|
4528 (require 'imenu)
|
|
4529 (if (or update (null (nth 2 cperl-hierarchy)))
|
|
4530 (let (pack name cons1 to l1 l2 l3 l4
|
|
4531 (remover (function (lambda (elt) ; (name (file1...) (file2..))
|
|
4532 (or (nthcdr 2 elt)
|
|
4533 ;; Only in one file
|
|
4534 (setcdr elt (cdr (nth 1 elt))))))))
|
|
4535 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
|
|
4536 (setq cperl-hierarchy (list l1 l2 l3))
|
|
4537 (or tags-table-list
|
|
4538 (call-interactively 'visit-tags-table))
|
|
4539 (message "Updating list of classes...")
|
|
4540 (mapcar
|
|
4541 (function
|
|
4542 (lambda (tagsfile)
|
|
4543 (set-buffer (get-file-buffer tagsfile))
|
|
4544 (cperl-tags-hier-fill)))
|
|
4545 tags-table-list)
|
|
4546 (mapcar remover (car cperl-hierarchy))
|
|
4547 (mapcar remover (nth 1 cperl-hierarchy))
|
|
4548 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
|
|
4549 (cons "Methods: " (car cperl-hierarchy))))
|
|
4550 (cperl-tags-treeify to 1)
|
|
4551 (setcar (nthcdr 2 cperl-hierarchy)
|
|
4552 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
|
|
4553 (message "Updating list of classes: done, requesting display...")
|
|
4554 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
|
|
4555 ))
|
|
4556 (or (nth 2 cperl-hierarchy)
|
|
4557 (error "No items found"))
|
|
4558 (setq update
|
|
4559 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
|
|
4560 (if window-system
|
|
4561 (x-popup-menu t (nth 2 cperl-hierarchy))
|
|
4562 (require 'tmm)
|
193
|
4563 (tmm-prompt (nth 2 cperl-hierarchy))))
|
4
|
4564 (if (and update (listp update))
|
|
4565 (progn (while (cdr update) (setq update (cdr update)))
|
|
4566 (setq update (car update)))) ; Get the last from the list
|
|
4567 (if (vectorp update)
|
|
4568 (progn
|
|
4569 (find-file (elt update 0))
|
|
4570 (etags-goto-tag-location (elt update 1))))
|
|
4571 (if (eq update -999) (cperl-tags-hier-init t)))
|
|
4572
|
|
4573 (defun cperl-tags-treeify (to level)
|
193
|
4574 ;; cadr of `to' is read-write. On start it is a cons
|
4
|
4575 (let* ((regexp (concat "^\\(" (mapconcat
|
|
4576 'identity
|
|
4577 (make-list level "[_a-zA-Z0-9]+")
|
|
4578 "::")
|
|
4579 "\\)\\(::\\)?"))
|
|
4580 (packages (cdr (nth 1 to)))
|
|
4581 (methods (cdr (nth 2 to)))
|
|
4582 l1 head tail cons1 cons2 ord writeto packs recurse
|
|
4583 root-packages root-functions ms many_ms same_name ps
|
|
4584 (move-deeper
|
|
4585 (function
|
|
4586 (lambda (elt)
|
|
4587 (cond ((and (string-match regexp (car elt))
|
|
4588 (or (eq ord 1) (match-end 2)))
|
|
4589 (setq head (substring (car elt) 0 (match-end 1))
|
|
4590 tail (if (match-end 2) (substring (car elt)
|
|
4591 (match-end 2)))
|
|
4592 recurse t)
|
|
4593 (if (setq cons1 (assoc head writeto)) nil
|
|
4594 ;; Need to init new head
|
|
4595 (setcdr writeto (cons (list head (list "Packages: ")
|
|
4596 (list "Methods: "))
|
|
4597 (cdr writeto)))
|
|
4598 (setq cons1 (nth 1 writeto)))
|
|
4599 (setq cons2 (nth ord cons1)) ; Either packs or meths
|
|
4600 (setcdr cons2 (cons elt (cdr cons2))))
|
|
4601 ((eq ord 2)
|
|
4602 (setq root-functions (cons elt root-functions)))
|
|
4603 (t
|
|
4604 (setq root-packages (cons elt root-packages))))))))
|
|
4605 (setcdr to l1) ; Init to dynamic space
|
|
4606 (setq writeto to)
|
|
4607 (setq ord 1)
|
|
4608 (mapcar move-deeper packages)
|
|
4609 (setq ord 2)
|
|
4610 (mapcar move-deeper methods)
|
|
4611 (if recurse
|
|
4612 (mapcar (function (lambda (elt)
|
|
4613 (cperl-tags-treeify elt (1+ level))))
|
|
4614 (cdr to)))
|
|
4615 ;;Now clean up leaders with one child only
|
|
4616 (mapcar (function (lambda (elt)
|
|
4617 (if (not (and (listp (cdr elt))
|
|
4618 (eq (length elt) 2))) nil
|
|
4619 (setcar elt (car (nth 1 elt)))
|
|
4620 (setcdr elt (cdr (nth 1 elt))))))
|
|
4621 (cdr to))
|
193
|
4622 ;; Sort the roots of subtrees
|
|
4623 (if (default-value 'imenu-sort-function)
|
|
4624 (setcdr to
|
|
4625 (sort (cdr to) (default-value 'imenu-sort-function))))
|
|
4626 ;; Now add back functions removed from display
|
|
4627 (mapcar (function (lambda (elt)
|
|
4628 (setcdr to (cons elt (cdr to)))))
|
|
4629 (if (default-value 'imenu-sort-function)
|
|
4630 (nreverse
|
|
4631 (sort root-functions (default-value 'imenu-sort-function)))
|
|
4632 root-functions))
|
|
4633 ;; Now add back packages removed from display
|
|
4634 (mapcar (function (lambda (elt)
|
|
4635 (setcdr to (cons (cons (concat "package " (car elt))
|
|
4636 (cdr elt))
|
|
4637 (cdr to)))))
|
|
4638 (if (default-value 'imenu-sort-function)
|
|
4639 (nreverse
|
|
4640 (sort root-packages (default-value 'imenu-sort-function)))
|
|
4641 root-packages))
|
4
|
4642 ))
|
|
4643
|
|
4644 ;;;(x-popup-menu t
|
|
4645 ;;; '(keymap "Name1"
|
|
4646 ;;; ("Ret1" "aa")
|
|
4647 ;;; ("Head1" "ab"
|
|
4648 ;;; keymap "Name2"
|
|
4649 ;;; ("Tail1" "x") ("Tail2" "y"))))
|
|
4650
|
|
4651 (defun cperl-list-fold (list name limit)
|
|
4652 (let (list1 list2 elt1 (num 0))
|
|
4653 (if (<= (length list) limit) list
|
|
4654 (setq list1 nil list2 nil)
|
|
4655 (while list
|
|
4656 (setq num (1+ num)
|
|
4657 elt1 (car list)
|
|
4658 list (cdr list))
|
|
4659 (if (<= num imenu-max-items)
|
|
4660 (setq list2 (cons elt1 list2))
|
|
4661 (setq list1 (cons (cons name
|
|
4662 (nreverse list2))
|
|
4663 list1)
|
|
4664 list2 (list elt1)
|
|
4665 num 1)))
|
|
4666 (nreverse (cons (cons name
|
|
4667 (nreverse list2))
|
|
4668 list1)))))
|
|
4669
|
|
4670 (defun cperl-menu-to-keymap (menu &optional name)
|
|
4671 (let (list)
|
|
4672 (cons 'keymap
|
|
4673 (mapcar
|
|
4674 (function
|
|
4675 (lambda (elt)
|
|
4676 (cond ((listp (cdr elt))
|
|
4677 (setq list (cperl-list-fold
|
|
4678 (cdr elt) (car elt) imenu-max-items))
|
|
4679 (cons nil
|
|
4680 (cons (car elt)
|
|
4681 (cperl-menu-to-keymap list))))
|
|
4682 (t
|
193
|
4683 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
|
4
|
4684 (cperl-list-fold menu "Root" imenu-max-items)))))
|
|
4685
|
|
4686
|
|
4687 (defvar cperl-bad-style-regexp
|
|
4688 (mapconcat 'identity
|
|
4689 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
|
|
4690 "[-<>=+^&|]+[^- \t\n=+<>~]" ; sign+ char
|
|
4691 )
|
|
4692 "\\|")
|
|
4693 "Finds places such that insertion of a whitespace may help a lot.")
|
|
4694
|
|
4695 (defvar cperl-not-bad-style-regexp
|
|
4696 (mapconcat 'identity
|
|
4697 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
|
193
|
4698 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
|
|
4699 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
|
4
|
4700 "<\\$?\\sw+\\(\\.\\sw+\\)?>" ; <IN> <stdin.h>
|
|
4701 "-[a-zA-Z][ \t]+[_$\"'`]" ; -f file
|
|
4702 "-[0-9]" ; -5
|
|
4703 "\\+\\+" ; ++var
|
|
4704 "--" ; --var
|
|
4705 ".->" ; a->b
|
|
4706 "->" ; a SPACE ->b
|
|
4707 "\\[-" ; a[-1]
|
|
4708 "^=" ; =head
|
|
4709 "||"
|
|
4710 "&&"
|
|
4711 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
|
193
|
4712 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
|
4
|
4713 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
|
|
4714 ;;"[*/+-|&<.]+="
|
|
4715 )
|
|
4716 "\\|")
|
|
4717 "If matches at the start of match found by `my-bad-c-style-regexp',
|
|
4718 insertion of a whitespace will not help.")
|
|
4719
|
|
4720 (defvar found-bad)
|
|
4721
|
|
4722 (defun cperl-find-bad-style ()
|
|
4723 "Find places in the buffer where insertion of a whitespace may help.
|
|
4724 Prompts user for insertion of spaces.
|
|
4725 Currently it is tuned to C and Perl syntax."
|
|
4726 (interactive)
|
|
4727 (let (found-bad (p (point)))
|
|
4728 (setq last-nonmenu-event 13) ; To disable popup
|
|
4729 (beginning-of-buffer)
|
|
4730 (map-y-or-n-p "Insert space here? "
|
|
4731 (function (lambda (arg) (insert " ")))
|
|
4732 'cperl-next-bad-style
|
|
4733 '("location" "locations" "insert a space into")
|
|
4734 '((?\C-r (lambda (arg)
|
|
4735 (let ((buffer-quit-function
|
|
4736 'exit-recursive-edit))
|
|
4737 (message "Exit with Esc Esc")
|
|
4738 (recursive-edit)
|
|
4739 t)) ; Consider acted upon
|
|
4740 "edit, exit with Esc Esc")
|
|
4741 (?e (lambda (arg)
|
|
4742 (let ((buffer-quit-function
|
|
4743 'exit-recursive-edit))
|
|
4744 (message "Exit with Esc Esc")
|
|
4745 (recursive-edit)
|
|
4746 t)) ; Consider acted upon
|
|
4747 "edit, exit with Esc Esc"))
|
|
4748 t)
|
|
4749 (if found-bad (goto-char found-bad)
|
|
4750 (goto-char p)
|
|
4751 (message "No appropriate place found"))))
|
|
4752
|
|
4753 (defun cperl-next-bad-style ()
|
|
4754 (let (p (not-found t) (point (point)) found)
|
|
4755 (while (and not-found
|
|
4756 (re-search-forward cperl-bad-style-regexp nil 'to-end))
|
|
4757 (setq p (point))
|
|
4758 (goto-char (match-beginning 0))
|
|
4759 (if (or
|
|
4760 (looking-at cperl-not-bad-style-regexp)
|
|
4761 ;; Check for a < -b and friends
|
|
4762 (and (eq (following-char) ?\-)
|
|
4763 (save-excursion
|
|
4764 (skip-chars-backward " \t\n")
|
|
4765 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\(, ?\[, ?\{))))
|
|
4766 ;; Now check for syntax type
|
|
4767 (save-match-data
|
|
4768 (setq found (point))
|
|
4769 (beginning-of-defun)
|
|
4770 (let ((pps (parse-partial-sexp (point) found)))
|
|
4771 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
|
|
4772 (goto-char (match-end 0))
|
|
4773 (goto-char (1- p))
|
|
4774 (setq not-found nil
|
|
4775 found-bad found)))
|
|
4776 (not not-found)))
|
|
4777
|
|
4778
|
|
4779 ;;; Getting help
|
|
4780 (defvar cperl-have-help-regexp
|
|
4781 ;;(concat "\\("
|
|
4782 (mapconcat
|
|
4783 'identity
|
110
|
4784 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
|
4
|
4785 "[$@]\\^[a-zA-Z]" ; Special variable
|
|
4786 "[$@][^ \n\t]" ; Special variable
|
|
4787 "-[a-zA-Z]" ; File test
|
|
4788 "\\\\[a-zA-Z0]" ; Special chars
|
110
|
4789 "^=[a-z][a-zA-Z0-9_]*" ; Pod sections
|
4
|
4790 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
|
|
4791 "[a-zA-Z_0-9:]+" ; symbol or number
|
|
4792 "x="
|
|
4793 "#!"
|
|
4794 )
|
|
4795 ;;"\\)\\|\\("
|
|
4796 "\\|"
|
|
4797 )
|
|
4798 ;;"\\)"
|
|
4799 ;;)
|
|
4800 "Matches places in the buffer we can find help for.")
|
|
4801
|
|
4802 (defvar cperl-message-on-help-error t)
|
193
|
4803 (defvar cperl-help-from-hook nil)
|
110
|
4804
|
|
4805 (defun cperl-word-at-point-hard ()
|
|
4806 ;; Does not save-excursion
|
|
4807 ;; Get to the something meaningful
|
|
4808 (or (eobp) (eolp) (forward-char 1))
|
|
4809 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
|
|
4810 (save-excursion (beginning-of-line) (point))
|
|
4811 'to-beg)
|
|
4812 ;; (cond
|
|
4813 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
|
|
4814 ;; (skip-chars-backward " \n\t\r({[]});,")
|
|
4815 ;; (or (bobp) (backward-char 1))))
|
|
4816 ;; Try to backtrace
|
|
4817 (cond
|
|
4818 ((looking-at "[a-zA-Z0-9_:]") ; symbol
|
193
|
4819 (skip-chars-backward "a-zA-Z0-9_:")
|
110
|
4820 (cond
|
|
4821 ((and (eq (preceding-char) ?^) ; $^I
|
|
4822 (eq (char-after (- (point) 2)) ?\$))
|
|
4823 (forward-char -2))
|
|
4824 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
|
|
4825 (forward-char -1))
|
|
4826 ((and (eq (preceding-char) ?\=)
|
|
4827 (eq (current-column) 1))
|
|
4828 (forward-char -1))) ; =head1
|
|
4829 (if (and (eq (preceding-char) ?\<)
|
|
4830 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
|
|
4831 (forward-char -1)))
|
|
4832 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
|
|
4833 (forward-char -1))
|
|
4834 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
|
|
4835 (forward-char -1))
|
|
4836 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
|
193
|
4837 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
|
110
|
4838 (cond
|
|
4839 ((and (eq (preceding-char) ?\$)
|
|
4840 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
|
|
4841 (forward-char -1))
|
|
4842 ((and (eq (following-char) ?\>)
|
|
4843 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
|
|
4844 (save-excursion
|
|
4845 (forward-sexp -1)
|
|
4846 (and (eq (preceding-char) ?\<)
|
|
4847 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
|
|
4848 (search-backward "<"))))
|
|
4849 ((and (eq (following-char) ?\$)
|
|
4850 (eq (preceding-char) ?\<)
|
|
4851 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
|
|
4852 (forward-char -1)))
|
|
4853 (if (looking-at cperl-have-help-regexp)
|
|
4854 (buffer-substring (match-beginning 0) (match-end 0))))
|
4
|
4855
|
|
4856 (defun cperl-get-help ()
|
|
4857 "Get one-line docs on the symbol at the point.
|
|
4858 The data for these docs is a little bit obsolete and may be in fact longer
|
|
4859 than a line. Your contribution to update/shorten it is appreciated."
|
|
4860 (interactive)
|
193
|
4861 (save-match-data ; May be called "inside" query-replace
|
|
4862 (save-excursion
|
|
4863 (let ((word (cperl-word-at-point-hard)))
|
|
4864 (if word
|
|
4865 (if (and cperl-help-from-hook ; Bail out if not in mainland
|
|
4866 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
|
|
4867 (or (memq (get-text-property (point) 'face)
|
|
4868 '(font-lock-comment-face font-lock-string-face))
|
|
4869 (memq (get-text-property (point) 'syntax-type)
|
|
4870 '(pod here-doc format))))
|
|
4871 nil
|
|
4872 (cperl-describe-perl-symbol word))
|
|
4873 (if cperl-message-on-help-error
|
|
4874 (message "Nothing found for %s..."
|
|
4875 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
|
4
|
4876
|
|
4877 ;;; Stolen from perl-descr.el by Johan Vromans:
|
|
4878
|
|
4879 (defvar cperl-doc-buffer " *perl-doc*"
|
|
4880 "Where the documentation can be found.")
|
193
|
4881 (defvar cperl-last-help nil
|
|
4882 "The last help message, for echo area refresh.")
|
|
4883 (make-variable-buffer-local 'cperl-last-help)
|
4
|
4884
|
|
4885 (defun cperl-describe-perl-symbol (val)
|
|
4886 "Display the documentation of symbol at point, a Perl operator."
|
110
|
4887 (let ((enable-recursive-minibuffers t)
|
4
|
4888 args-file regexp)
|
|
4889 (cond
|
|
4890 ((string-match "^[&*][a-zA-Z_]" val)
|
|
4891 (setq val (concat (substring val 0 1) "NAME")))
|
110
|
4892 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
|
|
4893 (setq val (concat "@" (substring val 1 (match-end 1)))))
|
|
4894 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
|
|
4895 (setq val (concat "%" (substring val 1 (match-end 1)))))
|
|
4896 ((and (string= val "x") (string-match "^x=" val))
|
4
|
4897 (setq val "x="))
|
|
4898 ((string-match "^\\$[\C-a-\C-z]" val)
|
|
4899 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
|
110
|
4900 ((string-match "^CORE::" val)
|
|
4901 (setq val "CORE::"))
|
|
4902 ((string-match "^SUPER::" val)
|
|
4903 (setq val "SUPER::"))
|
|
4904 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
|
4
|
4905 (setq val "<NAME>")))
|
110
|
4906 (setq regexp (concat "^"
|
|
4907 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
|
4
|
4908 (regexp-quote val)
|
|
4909 "\\([ \t([/]\\|$\\)"))
|
|
4910
|
|
4911 ;; get the buffer with the documentation text
|
|
4912 (cperl-switch-to-doc-buffer)
|
|
4913
|
|
4914 ;; lookup in the doc
|
|
4915 (goto-char (point-min))
|
|
4916 (let ((case-fold-search nil))
|
|
4917 (list
|
|
4918 (if (re-search-forward regexp (point-max) t)
|
|
4919 (save-excursion
|
|
4920 (beginning-of-line 1)
|
|
4921 (let ((lnstart (point)))
|
|
4922 (end-of-line)
|
193
|
4923 (setq cperl-last-help
|
|
4924 (cperl-message "%s" (buffer-substring lnstart (point))))))
|
4
|
4925 (if cperl-message-on-help-error
|
193
|
4926 (cperl-message "No definition for %s" val)))))))
|
4
|
4927
|
|
4928 (defvar cperl-short-docs "Ignore my value"
|
110
|
4929 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
|
4
|
4930 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
|
110
|
4931 ! ... Logical negation.
|
|
4932 ... != ... Numeric inequality.
|
|
4933 ... !~ ... Search pattern, substitution, or translation (negated).
|
4
|
4934 $! In numeric context: errno. In a string context: error string.
|
|
4935 $\" The separator which joins elements of arrays interpolated in strings.
|
|
4936 $# The output format for printed numbers. Initial value is %.20g.
|
110
|
4937 $$ Process number of this script. Changes in the fork()ed child process.
|
4
|
4938 $% The current page number of the currently selected output channel.
|
|
4939
|
|
4940 The following variables are always local to the current block:
|
|
4941
|
|
4942 $1 Match of the 1st set of parentheses in the last match (auto-local).
|
|
4943 $2 Match of the 2nd set of parentheses in the last match (auto-local).
|
|
4944 $3 Match of the 3rd set of parentheses in the last match (auto-local).
|
|
4945 $4 Match of the 4th set of parentheses in the last match (auto-local).
|
|
4946 $5 Match of the 5th set of parentheses in the last match (auto-local).
|
|
4947 $6 Match of the 6th set of parentheses in the last match (auto-local).
|
|
4948 $7 Match of the 7th set of parentheses in the last match (auto-local).
|
|
4949 $8 Match of the 8th set of parentheses in the last match (auto-local).
|
|
4950 $9 Match of the 9th set of parentheses in the last match (auto-local).
|
|
4951 $& The string matched by the last pattern match (auto-local).
|
|
4952 $' The string after what was matched by the last match (auto-local).
|
|
4953 $` The string before what was matched by the last match (auto-local).
|
|
4954
|
|
4955 $( The real gid of this process.
|
|
4956 $) The effective gid of this process.
|
|
4957 $* Deprecated: Set to 1 to do multiline matching within a string.
|
|
4958 $+ The last bracket matched by the last search pattern.
|
|
4959 $, The output field separator for the print operator.
|
|
4960 $- The number of lines left on the page.
|
|
4961 $. The current input line number of the last filehandle that was read.
|
|
4962 $/ The input record separator, newline by default.
|
110
|
4963 $0 Name of the file containing the perl script being executed. May be set.
|
|
4964 $: String may be broken after these characters to fill ^-lines in a format.
|
|
4965 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
|
4
|
4966 $< The real uid of this process.
|
|
4967 $= The page length of the current output channel. Default is 60 lines.
|
|
4968 $> The effective uid of this process.
|
|
4969 $? The status returned by the last ``, pipe close or `system'.
|
|
4970 $@ The perl error message from the last eval or do @var{EXPR} command.
|
|
4971 $ARGV The name of the current file used with <> .
|
|
4972 $[ Deprecated: The index of the first element/char in an array/string.
|
|
4973 $\\ The output record separator for the print operator.
|
|
4974 $] The perl version string as displayed with perl -v.
|
|
4975 $^ The name of the current top-of-page format.
|
|
4976 $^A The current value of the write() accumulator for format() lines.
|
|
4977 $^D The value of the perl debug (-D) flags.
|
|
4978 $^E Information about the last system error other than that provided by $!.
|
|
4979 $^F The highest system file descriptor, ordinarily 2.
|
|
4980 $^H The current set of syntax checks enabled by `use strict'.
|
|
4981 $^I The value of the in-place edit extension (perl -i option).
|
|
4982 $^L What formats output to perform a formfeed. Default is \f.
|
|
4983 $^O The operating system name under which this copy of Perl was built.
|
|
4984 $^P Internal debugging flag.
|
|
4985 $^T The time the script was started. Used by -A/-M/-C file tests.
|
|
4986 $^W True if warnings are requested (perl -w flag).
|
|
4987 $^X The name under which perl was invoked (argv[0] in C-speech).
|
|
4988 $_ The default input and pattern-searching space.
|
110
|
4989 $| Auto-flush after write/print on the current output channel? Default 0.
|
4
|
4990 $~ The name of the current report format.
|
110
|
4991 ... % ... Modulo division.
|
|
4992 ... %= ... Modulo division assignment.
|
4
|
4993 %ENV Contains the current environment.
|
|
4994 %INC List of files that have been require-d or do-ne.
|
|
4995 %SIG Used to set signal handlers for various signals.
|
110
|
4996 ... & ... Bitwise and.
|
|
4997 ... && ... Logical and.
|
|
4998 ... &&= ... Logical and assignment.
|
|
4999 ... &= ... Bitwise and assignment.
|
|
5000 ... * ... Multiplication.
|
|
5001 ... ** ... Exponentiation.
|
|
5002 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
|
4
|
5003 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
|
110
|
5004 ... + ... Addition. +EXPR Makes EXPR into scalar context.
|
|
5005 ++ Auto-increment (magical on strings). ++EXPR EXPR++
|
|
5006 ... += ... Addition assignment.
|
4
|
5007 , Comma operator.
|
110
|
5008 ... - ... Subtraction.
|
|
5009 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
|
|
5010 ... -= ... Subtraction assignment.
|
4
|
5011 -A Access time in days since script started.
|
|
5012 -B File is a non-text (binary) file.
|
|
5013 -C Inode change time in days since script started.
|
|
5014 -M Age in days since script started.
|
|
5015 -O File is owned by real uid.
|
|
5016 -R File is readable by real uid.
|
|
5017 -S File is a socket .
|
|
5018 -T File is a text file.
|
|
5019 -W File is writable by real uid.
|
|
5020 -X File is executable by real uid.
|
|
5021 -b File is a block special file.
|
|
5022 -c File is a character special file.
|
|
5023 -d File is a directory.
|
|
5024 -e File exists .
|
|
5025 -f File is a plain file.
|
|
5026 -g File has setgid bit set.
|
|
5027 -k File has sticky bit set.
|
|
5028 -l File is a symbolic link.
|
|
5029 -o File is owned by effective uid.
|
|
5030 -p File is a named pipe (FIFO).
|
|
5031 -r File is readable by effective uid.
|
|
5032 -s File has non-zero size.
|
|
5033 -t Tests if filehandle (STDIN by default) is opened to a tty.
|
|
5034 -u File has setuid bit set.
|
|
5035 -w File is writable by effective uid.
|
|
5036 -x File is executable by effective uid.
|
|
5037 -z File has zero size.
|
|
5038 . Concatenate strings.
|
|
5039 .. Alternation, also range operator.
|
|
5040 .= Concatenate assignment strings
|
110
|
5041 ... / ... Division. /PATTERN/ioxsmg Pattern match
|
|
5042 ... /= ... Division assignment.
|
4
|
5043 /PATTERN/ioxsmg Pattern match.
|
110
|
5044 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
|
4
|
5045 <NAME> Reads line from filehandle NAME. NAME must be bareword/dollar-bareword.
|
|
5046 <pattern> Glob. (Unless pattern is bareword/dollar-bareword - see <NAME>)
|
|
5047 <> Reads line from union of files in @ARGV (= command line) and STDIN.
|
110
|
5048 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
|
|
5049 ... <= ... Numeric less than or equal to.
|
|
5050 ... <=> ... Numeric compare.
|
|
5051 ... = ... Assignment.
|
|
5052 ... == ... Numeric equality.
|
|
5053 ... =~ ... Search pattern, substitution, or translation
|
|
5054 ... > ... Numeric greater than.
|
|
5055 ... >= ... Numeric greater than or equal to.
|
|
5056 ... >> ... Bitwise shift right.
|
|
5057 ... >>= ... Bitwise shift right assignment.
|
|
5058 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
|
|
5059 ?PATTERN? One-time pattern match.
|
4
|
5060 @ARGV Command line arguments (not including the command name - see $0).
|
|
5061 @INC List of places to look for perl scripts during do/include/use.
|
|
5062 @_ Parameter array for subroutines. Also used by split unless in array context.
|
193
|
5063 \\ Creates reference to what follows, like \$var, or quotes non-\w in strings.
|
4
|
5064 \\0 Octal char, e.g. \\033.
|
|
5065 \\E Case modification terminator. See \\Q, \\L, and \\U.
|
110
|
5066 \\L Lowercase until \\E . See also \l, lc.
|
|
5067 \\U Upcase until \\E . See also \u, uc.
|
|
5068 \\Q Quote metacharacters until \\E . See also quotemeta.
|
4
|
5069 \\a Alarm character (octal 007).
|
|
5070 \\b Backspace character (octal 010).
|
|
5071 \\c Control character, e.g. \\c[ .
|
|
5072 \\e Escape character (octal 033).
|
|
5073 \\f Formfeed character (octal 014).
|
193
|
5074 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
|
|
5075 \\n Newline character (octal 012 on most systems).
|
|
5076 \\r Return character (octal 015 on most systems).
|
4
|
5077 \\t Tab character (octal 011).
|
193
|
5078 \\u Upcase the next character. See also \\U and \\l, ucfirst.
|
4
|
5079 \\x Hex character, e.g. \\x1b.
|
193
|
5080 ... ^ ... Bitwise exclusive or.
|
110
|
5081 __END__ Ends program source.
|
|
5082 __DATA__ Ends program source.
|
4
|
5083 __FILE__ Current (source) filename.
|
|
5084 __LINE__ Current line in current source.
|
193
|
5085 __PACKAGE__ Current package.
|
4
|
5086 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
|
|
5087 ARGVOUT Output filehandle with -i flag.
|
110
|
5088 BEGIN { ... } Immediately executed (during compilation) piece of code.
|
|
5089 END { ... } Pseudo-subroutine executed after the script finishes.
|
4
|
5090 DATA Input filehandle for what follows after __END__ or __DATA__.
|
|
5091 accept(NEWSOCKET,GENERICSOCKET)
|
|
5092 alarm(SECONDS)
|
|
5093 atan2(X,Y)
|
|
5094 bind(SOCKET,NAME)
|
|
5095 binmode(FILEHANDLE)
|
|
5096 caller[(LEVEL)]
|
|
5097 chdir(EXPR)
|
|
5098 chmod(LIST)
|
|
5099 chop[(LIST|VAR)]
|
|
5100 chown(LIST)
|
|
5101 chroot(FILENAME)
|
|
5102 close(FILEHANDLE)
|
|
5103 closedir(DIRHANDLE)
|
110
|
5104 ... cmp ... String compare.
|
4
|
5105 connect(SOCKET,NAME)
|
|
5106 continue of { block } continue { block }. Is executed after `next' or at end.
|
|
5107 cos(EXPR)
|
|
5108 crypt(PLAINTEXT,SALT)
|
110
|
5109 dbmclose(%HASH)
|
|
5110 dbmopen(%HASH,DBNAME,MODE)
|
4
|
5111 defined(EXPR)
|
110
|
5112 delete($HASH{KEY})
|
4
|
5113 die(LIST)
|
|
5114 do { ... }|SUBR while|until EXPR executes at least once
|
193
|
5115 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
|
4
|
5116 dump LABEL
|
110
|
5117 each(%HASH)
|
4
|
5118 endgrent
|
|
5119 endhostent
|
|
5120 endnetent
|
|
5121 endprotoent
|
|
5122 endpwent
|
|
5123 endservent
|
|
5124 eof[([FILEHANDLE])]
|
110
|
5125 ... eq ... String equality.
|
4
|
5126 eval(EXPR) or eval { BLOCK }
|
|
5127 exec(LIST)
|
|
5128 exit(EXPR)
|
|
5129 exp(EXPR)
|
|
5130 fcntl(FILEHANDLE,FUNCTION,SCALAR)
|
|
5131 fileno(FILEHANDLE)
|
|
5132 flock(FILEHANDLE,OPERATION)
|
|
5133 for (EXPR;EXPR;EXPR) { ... }
|
|
5134 foreach [VAR] (@ARRAY) { ... }
|
|
5135 fork
|
110
|
5136 ... ge ... String greater than or equal.
|
4
|
5137 getc[(FILEHANDLE)]
|
|
5138 getgrent
|
|
5139 getgrgid(GID)
|
|
5140 getgrnam(NAME)
|
|
5141 gethostbyaddr(ADDR,ADDRTYPE)
|
|
5142 gethostbyname(NAME)
|
|
5143 gethostent
|
|
5144 getlogin
|
|
5145 getnetbyaddr(ADDR,ADDRTYPE)
|
|
5146 getnetbyname(NAME)
|
|
5147 getnetent
|
|
5148 getpeername(SOCKET)
|
|
5149 getpgrp(PID)
|
|
5150 getppid
|
|
5151 getpriority(WHICH,WHO)
|
|
5152 getprotobyname(NAME)
|
|
5153 getprotobynumber(NUMBER)
|
|
5154 getprotoent
|
|
5155 getpwent
|
|
5156 getpwnam(NAME)
|
|
5157 getpwuid(UID)
|
|
5158 getservbyname(NAME,PROTO)
|
|
5159 getservbyport(PORT,PROTO)
|
|
5160 getservent
|
|
5161 getsockname(SOCKET)
|
|
5162 getsockopt(SOCKET,LEVEL,OPTNAME)
|
|
5163 gmtime(EXPR)
|
|
5164 goto LABEL
|
|
5165 grep(EXPR,LIST)
|
110
|
5166 ... gt ... String greater than.
|
4
|
5167 hex(EXPR)
|
|
5168 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
|
|
5169 index(STR,SUBSTR[,OFFSET])
|
|
5170 int(EXPR)
|
|
5171 ioctl(FILEHANDLE,FUNCTION,SCALAR)
|
|
5172 join(EXPR,LIST)
|
110
|
5173 keys(%HASH)
|
4
|
5174 kill(LIST)
|
|
5175 last [LABEL]
|
110
|
5176 ... le ... String less than or equal.
|
4
|
5177 length(EXPR)
|
|
5178 link(OLDFILE,NEWFILE)
|
|
5179 listen(SOCKET,QUEUESIZE)
|
|
5180 local(LIST)
|
|
5181 localtime(EXPR)
|
|
5182 log(EXPR)
|
|
5183 lstat(EXPR|FILEHANDLE|VAR)
|
110
|
5184 ... lt ... String less than.
|
4
|
5185 m/PATTERN/iogsmx
|
|
5186 mkdir(FILENAME,MODE)
|
|
5187 msgctl(ID,CMD,ARG)
|
|
5188 msgget(KEY,FLAGS)
|
|
5189 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
|
|
5190 msgsnd(ID,MSG,FLAGS)
|
|
5191 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
|
110
|
5192 ... ne ... String inequality.
|
4
|
5193 next [LABEL]
|
|
5194 oct(EXPR)
|
|
5195 open(FILEHANDLE[,EXPR])
|
|
5196 opendir(DIRHANDLE,EXPR)
|
193
|
5197 ord(EXPR) ASCII value of the first char of the string.
|
4
|
5198 pack(TEMPLATE,LIST)
|
110
|
5199 package NAME Introduces package context.
|
193
|
5200 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
|
4
|
5201 pop(ARRAY)
|
|
5202 print [FILEHANDLE] [(LIST)]
|
|
5203 printf [FILEHANDLE] (FORMAT,LIST)
|
|
5204 push(ARRAY,LIST)
|
|
5205 q/STRING/ Synonym for 'STRING'
|
|
5206 qq/STRING/ Synonym for \"STRING\"
|
|
5207 qx/STRING/ Synonym for `STRING`
|
|
5208 rand[(EXPR)]
|
|
5209 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
|
|
5210 readdir(DIRHANDLE)
|
|
5211 readlink(EXPR)
|
|
5212 recv(SOCKET,SCALAR,LEN,FLAGS)
|
|
5213 redo [LABEL]
|
|
5214 rename(OLDNAME,NEWNAME)
|
|
5215 require [FILENAME | PERL_VERSION]
|
|
5216 reset[(EXPR)]
|
|
5217 return(LIST)
|
|
5218 reverse(LIST)
|
|
5219 rewinddir(DIRHANDLE)
|
|
5220 rindex(STR,SUBSTR[,OFFSET])
|
|
5221 rmdir(FILENAME)
|
|
5222 s/PATTERN/REPLACEMENT/gieoxsm
|
|
5223 scalar(EXPR)
|
|
5224 seek(FILEHANDLE,POSITION,WHENCE)
|
|
5225 seekdir(DIRHANDLE,POS)
|
|
5226 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
|
|
5227 semctl(ID,SEMNUM,CMD,ARG)
|
|
5228 semget(KEY,NSEMS,SIZE,FLAGS)
|
|
5229 semop(KEY,...)
|
|
5230 send(SOCKET,MSG,FLAGS[,TO])
|
|
5231 setgrent
|
|
5232 sethostent(STAYOPEN)
|
|
5233 setnetent(STAYOPEN)
|
|
5234 setpgrp(PID,PGRP)
|
|
5235 setpriority(WHICH,WHO,PRIORITY)
|
|
5236 setprotoent(STAYOPEN)
|
|
5237 setpwent
|
|
5238 setservent(STAYOPEN)
|
|
5239 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
|
|
5240 shift[(ARRAY)]
|
|
5241 shmctl(ID,CMD,ARG)
|
|
5242 shmget(KEY,SIZE,FLAGS)
|
|
5243 shmread(ID,VAR,POS,SIZE)
|
|
5244 shmwrite(ID,STRING,POS,SIZE)
|
|
5245 shutdown(SOCKET,HOW)
|
|
5246 sin(EXPR)
|
|
5247 sleep[(EXPR)]
|
|
5248 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
|
|
5249 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
|
|
5250 sort [SUBROUTINE] (LIST)
|
|
5251 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
|
|
5252 split[(/PATTERN/[,EXPR[,LIMIT]])]
|
|
5253 sprintf(FORMAT,LIST)
|
|
5254 sqrt(EXPR)
|
|
5255 srand(EXPR)
|
|
5256 stat(EXPR|FILEHANDLE|VAR)
|
|
5257 study[(SCALAR)]
|
110
|
5258 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
|
4
|
5259 substr(EXPR,OFFSET[,LEN])
|
|
5260 symlink(OLDFILE,NEWFILE)
|
|
5261 syscall(LIST)
|
|
5262 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
|
|
5263 system(LIST)
|
|
5264 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
|
|
5265 tell[(FILEHANDLE)]
|
|
5266 telldir(DIRHANDLE)
|
|
5267 time
|
|
5268 times
|
|
5269 tr/SEARCHLIST/REPLACEMENTLIST/cds
|
|
5270 truncate(FILE|EXPR,LENGTH)
|
|
5271 umask[(EXPR)]
|
|
5272 undef[(EXPR)]
|
|
5273 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
|
|
5274 unlink(LIST)
|
|
5275 unpack(TEMPLATE,EXPR)
|
|
5276 unshift(ARRAY,LIST)
|
110
|
5277 until (EXPR) { ... } EXPR until EXPR
|
4
|
5278 utime(LIST)
|
110
|
5279 values(%HASH)
|
4
|
5280 vec(EXPR,OFFSET,BITS)
|
|
5281 wait
|
|
5282 waitpid(PID,FLAGS)
|
193
|
5283 wantarray Returns true if the sub/eval is called in list context.
|
4
|
5284 warn(LIST)
|
110
|
5285 while (EXPR) { ... } EXPR while EXPR
|
4
|
5286 write[(EXPR|FILEHANDLE)]
|
110
|
5287 ... x ... Repeat string or array.
|
|
5288 x= ... Repetition assignment.
|
4
|
5289 y/SEARCHLIST/REPLACEMENTLIST/
|
110
|
5290 ... | ... Bitwise or.
|
|
5291 ... || ... Logical or.
|
|
5292 ~ ... Unary bitwise complement.
|
4
|
5293 #! OS interpreter indicator. If contains `perl', used for options, and -x.
|
110
|
5294 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
|
|
5295 CORE:: Prefix to access builtin function if imported sub obscures it.
|
|
5296 SUPER:: Prefix to lookup for a method in @ISA classes.
|
|
5297 DESTROY Shorthand for `sub DESTROY {...}'.
|
|
5298 ... EQ ... Obsolete synonym of `eq'.
|
|
5299 ... GE ... Obsolete synonym of `ge'.
|
|
5300 ... GT ... Obsolete synonym of `gt'.
|
|
5301 ... LE ... Obsolete synonym of `le'.
|
|
5302 ... LT ... Obsolete synonym of `lt'.
|
|
5303 ... NE ... Obsolete synonym of `ne'.
|
|
5304 abs [ EXPR ] absolute value
|
|
5305 ... and ... Low-precedence synonym for &&.
|
|
5306 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
|
193
|
5307 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
|
|
5308 chr Converts a number to char with the same ordinal.
|
110
|
5309 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
|
|
5310 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
|
|
5311 exists $HASH{KEY} True if the key exists.
|
193
|
5312 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
|
|
5313 formline PICTURE, LIST Backdoor into \"format\" processing.
|
110
|
5314 glob EXPR Synonym of <EXPR>.
|
|
5315 lc [ EXPR ] Returns lowercased EXPR.
|
|
5316 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
|
193
|
5317 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
|
110
|
5318 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
|
193
|
5319 not ... Low-precedence synonym for ! - negation.
|
110
|
5320 ... or ... Low-precedence synonym for ||.
|
|
5321 pos STRING Set/Get end-position of the last match over this string, see \\G.
|
193
|
5322 quotemeta [ EXPR ] Quote regexp metacharacters.
|
|
5323 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
|
110
|
5324 readline FH Synonym of <FH>.
|
|
5325 readpipe CMD Synonym of `CMD`.
|
|
5326 ref [ EXPR ] Type of EXPR when dereferenced.
|
193
|
5327 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
|
|
5328 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
|
|
5329 tied Returns internal object for a tied data.
|
110
|
5330 uc [ EXPR ] Returns upcased EXPR.
|
|
5331 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
|
193
|
5332 untie VAR Unlink an object from a simple Perl variable.
|
110
|
5333 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
|
|
5334 ... xor ... Low-precedence synonym for exclusive or.
|
|
5335 prototype \&SUB Returns prototype of the function given a reference.
|
|
5336 =head1 Top-level heading.
|
|
5337 =head2 Second-level heading.
|
|
5338 =head3 Third-level heading (is there such?).
|
|
5339 =over [ NUMBER ] Start list.
|
|
5340 =item [ TITLE ] Start new item in the list.
|
|
5341 =back End list.
|
|
5342 =cut Switch from POD to Perl.
|
|
5343 =pod Switch from Perl to POD.
|
4
|
5344 ")
|
|
5345
|
|
5346 (defun cperl-switch-to-doc-buffer ()
|
|
5347 "Go to the perl documentation buffer and insert the documentation."
|
|
5348 (interactive)
|
|
5349 (let ((buf (get-buffer-create cperl-doc-buffer)))
|
|
5350 (if (interactive-p)
|
|
5351 (switch-to-buffer-other-window buf)
|
|
5352 (set-buffer buf))
|
|
5353 (if (= (buffer-size) 0)
|
|
5354 (progn
|
|
5355 (insert (documentation-property 'cperl-short-docs
|
|
5356 'variable-documentation))
|
|
5357 (setq buffer-read-only t)))))
|
|
5358
|
193
|
5359 (defun cperl-beautify-regexp-piece (b e embed)
|
|
5360 ;; b is before the starting delimiter, e before the ending
|
|
5361 ;; e should be a marker, may be changed, but remains "correct".
|
|
5362 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline)
|
|
5363 (if (not embed)
|
|
5364 (goto-char (1+ b))
|
|
5365 (goto-char b)
|
|
5366 (cond ((looking-at "(\\?\\\\#") ; badly commented (?#)
|
|
5367 (forward-char 2)
|
|
5368 (delete-char 1)
|
|
5369 (forward-char 1))
|
|
5370 ((looking-at "(\\?[^a-zA-Z]")
|
|
5371 (forward-char 3))
|
|
5372 ((looking-at "(\\?") ; (?i)
|
|
5373 (forward-char 2))
|
|
5374 (t
|
|
5375 (forward-char 1))))
|
|
5376 (setq c (1- (current-column))
|
|
5377 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
|
|
5378 (or (looking-at "[ \t]*[\n#]")
|
|
5379 (progn
|
|
5380 (insert "\n")))
|
|
5381 (goto-char e)
|
|
5382 (beginning-of-line)
|
|
5383 (if (re-search-forward "[^ \t]" e t)
|
|
5384 (progn
|
|
5385 (goto-char e)
|
|
5386 (insert "\n")
|
|
5387 (indent-to-column c)
|
|
5388 (set-marker e (point))))
|
|
5389 (goto-char b)
|
|
5390 (end-of-line 2)
|
|
5391 (while (< (point) (marker-position e))
|
|
5392 (beginning-of-line)
|
|
5393 (setq s (point)
|
|
5394 inline t)
|
|
5395 (skip-chars-forward " \t")
|
|
5396 (delete-region s (point))
|
|
5397 (indent-to-column c1)
|
|
5398 (while (and
|
|
5399 inline
|
|
5400 (looking-at
|
|
5401 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1
|
|
5402 "\\|"
|
|
5403 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
|
|
5404 "\\|"
|
|
5405 "[$^]"
|
|
5406 "\\|"
|
|
5407 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
|
|
5408 "\\|"
|
|
5409 "\\(\\[\\)" ; 6
|
|
5410 "\\|"
|
|
5411 "\\((\\(\\?\\)?\\)" ; 7 8
|
|
5412 "\\|"
|
|
5413 "\\(|\\)" ; 9
|
|
5414 )))
|
|
5415 (goto-char (match-end 0))
|
|
5416 (setq spaces t)
|
|
5417 (cond ((match-beginning 1) ; Alphanum word + junk
|
|
5418 (forward-char -1))
|
|
5419 ((or (match-beginning 3) ; $ab[12]
|
|
5420 (and (match-beginning 5) ; X* X+ X{2,3}
|
|
5421 (eq (preceding-char) ?\{)))
|
|
5422 (forward-char -1)
|
|
5423 (forward-sexp 1))
|
|
5424 ((match-beginning 6) ; []
|
|
5425 (setq tmp (point))
|
|
5426 (if (looking-at "\\^?\\]")
|
|
5427 (goto-char (match-end 0)))
|
|
5428 (or (re-search-forward "\\]\\([*+{?]\\)?" e t)
|
|
5429 (progn
|
|
5430 (goto-char (1- tmp))
|
|
5431 (error "[]-group not terminated")))
|
|
5432 (if (not (eq (preceding-char) ?\{)) nil
|
|
5433 (forward-char -1)
|
|
5434 (forward-sexp 1)))
|
|
5435 ((match-beginning 7) ; ()
|
|
5436 (goto-char (match-beginning 0))
|
|
5437 (or (eq (current-column) c1)
|
|
5438 (progn
|
|
5439 (insert "\n")
|
|
5440 (indent-to-column c1)))
|
|
5441 (setq tmp (point))
|
|
5442 (forward-sexp 1)
|
|
5443 ;; (or (forward-sexp 1)
|
|
5444 ;; (progn
|
|
5445 ;; (goto-char tmp)
|
|
5446 ;; (error "()-group not terminated")))
|
|
5447 (set-marker m (1- (point)))
|
|
5448 (set-marker m1 (point))
|
|
5449 (cperl-beautify-regexp-piece tmp m t)
|
|
5450 (goto-char m1)
|
|
5451 (cond ((looking-at "[*+?]\\??")
|
|
5452 (goto-char (match-end 0)))
|
|
5453 ((eq (following-char) ?\{)
|
|
5454 (forward-sexp 1)
|
|
5455 (if (eq (following-char) ?\?)
|
|
5456 (forward-char))))
|
|
5457 (skip-chars-forward " \t")
|
|
5458 (setq spaces nil)
|
|
5459 (if (looking-at "[#\n]")
|
|
5460 (beginning-of-line 2)
|
|
5461 (insert "\n"))
|
|
5462 (end-of-line)
|
|
5463 (setq inline nil))
|
|
5464 ((match-beginning 9) ; |
|
|
5465 (forward-char -1)
|
|
5466 (setq tmp (point))
|
|
5467 (beginning-of-line)
|
|
5468 (if (re-search-forward "[^ \t]" tmp t)
|
|
5469 (progn
|
|
5470 (goto-char tmp)
|
|
5471 (insert "\n"))
|
|
5472 ;; first at line
|
|
5473 (delete-region (point) tmp))
|
|
5474 (indent-to-column c)
|
|
5475 (forward-char 1)
|
|
5476 (skip-chars-forward " \t")
|
|
5477 (setq spaces nil)
|
|
5478 (if (looking-at "[#\n]")
|
|
5479 (beginning-of-line 2)
|
|
5480 (insert "\n"))
|
|
5481 (end-of-line)
|
|
5482 (setq inline nil)))
|
|
5483 (or (looking-at "[ \t\n]")
|
|
5484 (not spaces)
|
|
5485 (insert " "))
|
|
5486 (skip-chars-forward " \t"))
|
|
5487 (or (looking-at "[#\n]")
|
|
5488 (error "unknown code in a regexp"))
|
|
5489 (and inline (end-of-line 2)))
|
|
5490 ))
|
|
5491
|
|
5492 (defun cperl-beautify-regexp ()
|
|
5493 "do it. (Experimental, may change semantics, recheck afterwards.)
|
|
5494 We suppose that the regexp is scanned already."
|
|
5495 (interactive)
|
|
5496 (or cperl-use-syntax-table-text-property
|
|
5497 (error "I need to have regex marked!"))
|
|
5498 ;; Find the start
|
|
5499 (re-search-backward "\\s|") ; Assume it is scanned already.
|
|
5500 ;;(forward-char 1)
|
|
5501 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
|
|
5502 (sub-p (eq (preceding-char) ?s)) s)
|
|
5503 (forward-sexp 1)
|
|
5504 (set-marker e (1- (point)))
|
|
5505 (setq delim (preceding-char))
|
|
5506 (if (and sub-p (eq delim (char-after (- (point) 2))))
|
|
5507 (error "Possible s/blah// - do not know how to deal with"))
|
|
5508 (if sub-p (forward-sexp 1))
|
|
5509 (if (looking-at "\\sw*x")
|
|
5510 (setq have-x t)
|
|
5511 (insert "x"))
|
|
5512 ;; Protect fragile " ", "#"
|
|
5513 (if have-x nil
|
|
5514 (goto-char (1+ b))
|
|
5515 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
|
|
5516 (forward-char -1)
|
|
5517 (insert "\\")
|
|
5518 (forward-char 1)))
|
|
5519 (cperl-beautify-regexp-piece b e nil)))
|
|
5520
|
|
5521
|
|
5522 ;; Part from the original `cperl-lazy-*', and part from `eldoc'
|
|
5523 ;; Karl M. Hegbloom <karlheg@inetarena.com>
|
|
5524
|
|
5525 (defun cperl-help (&optional arg)
|
|
5526 (interactive "p")
|
|
5527 (cond ((and arg (<= arg 0))
|
|
5528 (remove-hook 'post-command-hook 'cperl-get-help-defer)
|
|
5529 (remove-hook 'pre-command-hook 'cperl-refresh-echo-area)
|
|
5530 (setq cperl-help nil))
|
|
5531 (t
|
|
5532 (add-hook 'post-command-hook 'cperl-get-help-defer)
|
|
5533 (add-hook 'pre-command-hook 'cperl-refresh-echo-area)
|
|
5534 (setq cperl-help t))))
|
|
5535
|
|
5536 (defun cperl-toggle-help ()
|
|
5537 (interactive)
|
|
5538 (if cperl-help
|
|
5539 (cperl-help 0)
|
|
5540 (cperl-help 1)))
|
|
5541
|
|
5542 (defun cperl-get-help-defer ()
|
|
5543 (if (not (eq major-mode 'perl-mode)) nil
|
|
5544 (let ((cperl-message-on-help-error nil) (cperl-help-from-hook t))
|
|
5545 (cperl-get-help))))
|
|
5546
|
|
5547 ;; from `eldoc-refresh-*'
|
|
5548 (defun cperl-refresh-echo-area ()
|
|
5549 (and cperl-last-help
|
|
5550 (if (and cperl-mode
|
|
5551 (not executing-kbd-macro)
|
|
5552 (not cursor-in-echo-area)
|
|
5553 (not (eq (selected-window) (minibuffer-window))))
|
|
5554 (cperl-message cperl-last-help)
|
|
5555 (setq cperl-last-help nil))))
|
|
5556
|
|
5557 ;; see `eldoc-message'
|
|
5558 (defun cperl-message (&rest args)
|
|
5559 (let ((omessage cperl-last-help))
|
|
5560 (cond ((eq (car args) cperl-last-help))
|
|
5561 ((or (null args)
|
|
5562 (null (car args)))
|
|
5563 (setq cperl-last-help nil))
|
|
5564 (t
|
|
5565 (setq cperl-last-help (apply 'format args))))
|
|
5566 ;; Do not put cperl-help messages in the log
|
|
5567 (if cperl-last-help
|
|
5568 (display-message 'no-log cperl-last-help)
|
|
5569 (and omessage
|
|
5570 (clear-message 'no-log))))
|
|
5571 cperl-last-help)
|
|
5572
|
|
5573 (when cperl-help
|
|
5574 (cperl-help 1))
|
|
5575
|
|
5576 (provide 'cperl-mode)
|