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