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