(tex-font-lock-keywords-2): Fix bug in \bf fontification.
[emacs.git] / lisp / progmodes / cperl-mode.el
blobf25d5c29081cb7c036f74a61e1f595f11cc363fb
1 ;;; cperl-mode.el --- Perl code editing commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 ;; 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
5 ;; Free Software Foundation, Inc.
7 ;; Author: Ilya Zakharevich and Bob Olson
8 ;; Maintainer: Ilya Zakharevich <cperl@ilyaz.org>
9 ;; Keywords: languages, Perl
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
28 ;;; Corrections made by Ilya Zakharevich cperl@ilyaz.org
30 ;;; Commentary:
32 ;; You can either fine-tune the bells and whistles of this mode or
33 ;; bulk enable them by putting
35 ;; (setq cperl-hairy t)
37 ;; in your .emacs file. (Emacs rulers do not consider it politically
38 ;; correct to make whistles enabled by default.)
40 ;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
41 ;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
42 ;; `cperl-praise', `cperl-speed'. <<<<<<
44 ;; The mode information (on C-h m) provides some customization help.
45 ;; If you use font-lock feature of this mode, it is advisable to use
46 ;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
48 ;; Faces used now: three faces for first-class and second-class keywords
49 ;; and control flow words, one for each: comments, string, labels,
50 ;; functions definitions and packages, arrays, hashes, and variable
51 ;; definitions. If you do not see all these faces, your font-lock does
52 ;; not define them, so you need to define them manually.
54 ;; This mode supports font-lock, imenu and mode-compile. In the
55 ;; hairy version font-lock is on, but you should activate imenu
56 ;; yourself (note that mode-compile is not standard yet). Well, you
57 ;; can use imenu from keyboard anyway (M-x imenu), but it is better
58 ;; to bind it like that:
60 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
62 ;;; Font lock bugs as of v4.32:
64 ;; The following kinds of Perl code erroneously start strings:
65 ;; \$` \$' \$"
66 ;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
67 ;; likewise with m, tr, y, q, qX instead of s
69 ;;; Code:
71 (defvar vc-rcs-header)
72 (defvar vc-sccs-header)
74 ;; Some macros are needed for `defcustom'
75 (eval-when-compile
76 (condition-case nil
77 (require 'man)
78 (error nil))
79 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
80 (defvar cperl-can-font-lock
81 (or cperl-xemacs-p
82 (and (boundp 'emacs-major-version)
83 (or window-system
84 (> emacs-major-version 20)))))
85 (if cperl-can-font-lock
86 (require 'font-lock))
87 (defvar msb-menu-cond)
88 (defvar gud-perldb-history)
89 (defvar font-lock-background-mode) ; not in Emacs
90 (defvar font-lock-display-type) ; ditto
91 (defmacro cperl-is-face (arg) ; Takes quoted arg
92 (cond ((fboundp 'find-face)
93 `(find-face ,arg))
94 (;;(and (fboundp 'face-list)
95 ;; (face-list))
96 (fboundp 'face-list)
97 `(member ,arg (and (fboundp 'face-list)
98 (face-list))))
100 `(boundp ,arg))))
101 (defmacro cperl-make-face (arg descr) ; Takes unquoted arg
102 (cond ((fboundp 'make-face)
103 `(make-face (quote ,arg)))
105 `(defvar ,arg (quote ,arg) ,descr))))
106 (defmacro cperl-force-face (arg descr) ; Takes unquoted arg
107 `(progn
108 (or (cperl-is-face (quote ,arg))
109 (cperl-make-face ,arg ,descr))
110 (or (boundp (quote ,arg)) ; We use unquoted variants too
111 (defvar ,arg (quote ,arg) ,descr))))
112 (if cperl-xemacs-p
113 (defmacro cperl-etags-snarf-tag (file line)
114 `(progn
115 (beginning-of-line 2)
116 (list ,file ,line)))
117 (defmacro cperl-etags-snarf-tag (file line)
118 `(etags-snarf-tag)))
119 (if cperl-xemacs-p
120 (defmacro cperl-etags-goto-tag-location (elt)
121 ;;(progn
122 ;; (switch-to-buffer (get-file-buffer (elt (, elt) 0)))
123 ;; (set-buffer (get-file-buffer (elt (, elt) 0)))
124 ;; Probably will not work due to some save-excursion???
125 ;; Or save-file-position?
126 ;; (message "Did I get to line %s?" (elt (, elt) 1))
127 `(goto-line (string-to-number (elt ,elt 1))))
129 (defmacro cperl-etags-goto-tag-location (elt)
130 `(etags-goto-tag-location ,elt))))
132 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
134 (defvar cperl-can-font-lock
135 (or cperl-xemacs-p
136 (and (boundp 'emacs-major-version)
137 (or window-system
138 (> emacs-major-version 20)))))
140 (defun cperl-choose-color (&rest list)
141 (let (answer)
142 (while list
143 (or answer
144 (if (or (x-color-defined-p (car list))
145 (null (cdr list)))
146 (setq answer (car list))))
147 (setq list (cdr list)))
148 answer))
150 (defgroup cperl nil
151 "Major mode for editing Perl code."
152 :prefix "cperl-"
153 :group 'languages
154 :version "20.3")
156 (defgroup cperl-indentation-details nil
157 "Indentation."
158 :prefix "cperl-"
159 :group 'cperl)
161 (defgroup cperl-affected-by-hairy nil
162 "Variables affected by `cperl-hairy'."
163 :prefix "cperl-"
164 :group 'cperl)
166 (defgroup cperl-autoinsert-details nil
167 "Auto-insert tuneup."
168 :prefix "cperl-"
169 :group 'cperl)
171 (defgroup cperl-faces nil
172 "Fontification colors."
173 :prefix "cperl-"
174 :group 'cperl)
176 (defgroup cperl-speed nil
177 "Speed vs. validity tuneup."
178 :prefix "cperl-"
179 :group 'cperl)
181 (defgroup cperl-help-system nil
182 "Help system tuneup."
183 :prefix "cperl-"
184 :group 'cperl)
187 (defcustom cperl-extra-newline-before-brace nil
188 "*Non-nil means that if, elsif, while, until, else, for, foreach
189 and do constructs look like:
191 if ()
195 instead of:
197 if () {
199 :type 'boolean
200 :group 'cperl-autoinsert-details)
202 (defcustom cperl-extra-newline-before-brace-multiline
203 cperl-extra-newline-before-brace
204 "*Non-nil means the same as `cperl-extra-newline-before-brace', but
205 for constructs with multiline if/unless/while/until/for/foreach condition."
206 :type 'boolean
207 :group 'cperl-autoinsert-details)
209 (defcustom cperl-indent-level 2
210 "*Indentation of CPerl statements with respect to containing block."
211 :type 'integer
212 :group 'cperl-indentation-details)
214 (defcustom cperl-lineup-step nil
215 "*`cperl-lineup' will always lineup at multiple of this number.
216 If nil, the value of `cperl-indent-level' will be used."
217 :type '(choice (const nil) integer)
218 :group 'cperl-indentation-details)
220 (defcustom cperl-brace-imaginary-offset 0
221 "*Imagined indentation of a Perl open brace that actually follows a statement.
222 An open brace following other text is treated as if it were this far
223 to the right of the start of its line."
224 :type 'integer
225 :group 'cperl-indentation-details)
227 (defcustom cperl-brace-offset 0
228 "*Extra indentation for braces, compared with other text in same context."
229 :type 'integer
230 :group 'cperl-indentation-details)
231 (defcustom cperl-label-offset -2
232 "*Offset of CPerl label lines relative to usual indentation."
233 :type 'integer
234 :group 'cperl-indentation-details)
235 (defcustom cperl-min-label-indent 1
236 "*Minimal offset of CPerl label lines."
237 :type 'integer
238 :group 'cperl-indentation-details)
239 (defcustom cperl-continued-statement-offset 2
240 "*Extra indent for lines not starting new statements."
241 :type 'integer
242 :group 'cperl-indentation-details)
243 (defcustom cperl-continued-brace-offset 0
244 "*Extra indent for substatements that start with open-braces.
245 This is in addition to cperl-continued-statement-offset."
246 :type 'integer
247 :group 'cperl-indentation-details)
248 (defcustom cperl-close-paren-offset -1
249 "*Extra indent for substatements that start with close-parenthesis."
250 :type 'integer
251 :group 'cperl-indentation-details)
253 (defcustom cperl-auto-newline nil
254 "*Non-nil means automatically newline before and after braces,
255 and after colons and semicolons, inserted in CPerl code. The following
256 \\[cperl-electric-backspace] will remove the inserted whitespace.
257 Insertion after colons requires both this variable and
258 `cperl-auto-newline-after-colon' set."
259 :type 'boolean
260 :group 'cperl-autoinsert-details)
262 (defcustom cperl-autoindent-on-semi nil
263 "*Non-nil means automatically indent after insertion of (semi)colon.
264 Active if `cperl-auto-newline' is false."
265 :type 'boolean
266 :group 'cperl-autoinsert-details)
268 (defcustom cperl-auto-newline-after-colon nil
269 "*Non-nil means automatically newline even after colons.
270 Subject to `cperl-auto-newline' setting."
271 :type 'boolean
272 :group 'cperl-autoinsert-details)
274 (defcustom cperl-tab-always-indent t
275 "*Non-nil means TAB in CPerl mode should always reindent the current line,
276 regardless of where in the line point is when the TAB command is used."
277 :type 'boolean
278 :group 'cperl-indentation-details)
280 (defcustom cperl-font-lock nil
281 "*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
282 Can be overwritten by `cperl-hairy' if nil."
283 :type '(choice (const null) boolean)
284 :group 'cperl-affected-by-hairy)
286 (defcustom cperl-electric-lbrace-space nil
287 "*Non-nil (and non-null) means { after $ should be preceded by ` '.
288 Can be overwritten by `cperl-hairy' if nil."
289 :type '(choice (const null) boolean)
290 :group 'cperl-affected-by-hairy)
292 (defcustom cperl-electric-parens-string "({[]})<"
293 "*String of parentheses that should be electric in CPerl.
294 Closing ones are electric only if the region is highlighted."
295 :type 'string
296 :group 'cperl-affected-by-hairy)
298 (defcustom cperl-electric-parens nil
299 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
300 Can be overwritten by `cperl-hairy' if nil."
301 :type '(choice (const null) boolean)
302 :group 'cperl-affected-by-hairy)
304 (defvar zmacs-regions) ; Avoid warning
306 (defcustom cperl-electric-parens-mark
307 (and window-system
308 (or (and (boundp 'transient-mark-mode) ; For Emacs
309 transient-mark-mode)
310 (and (boundp 'zmacs-regions) ; For XEmacs
311 zmacs-regions)))
312 "*Not-nil means that electric parens look for active mark.
313 Default is yes if there is visual feedback on mark."
314 :type 'boolean
315 :group 'cperl-autoinsert-details)
317 (defcustom cperl-electric-linefeed nil
318 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
319 In any case these two mean plain and hairy linefeeds together.
320 Can be overwritten by `cperl-hairy' if nil."
321 :type '(choice (const null) boolean)
322 :group 'cperl-affected-by-hairy)
324 (defcustom cperl-electric-keywords nil
325 "*Not-nil (and non-null) means keywords are electric in CPerl.
326 Can be overwritten by `cperl-hairy' if nil."
327 :type '(choice (const null) boolean)
328 :group 'cperl-affected-by-hairy)
330 (defcustom cperl-electric-backspace-untabify t
331 "*Not-nil means electric-backspace will untabify in CPerl."
332 :type 'boolean
333 :group 'cperl-autoinsert-details)
335 (defcustom cperl-hairy nil
336 "*Not-nil means most of the bells and whistles are enabled in CPerl.
337 Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
338 `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
339 `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
340 `cperl-lazy-help-time'."
341 :type 'boolean
342 :group 'cperl-affected-by-hairy)
344 (defcustom cperl-comment-column 32
345 "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
346 :type 'integer
347 :group 'cperl-indentation-details)
349 (defvar cperl-vc-header-alist nil)
350 (make-obsolete-variable
351 'cperl-vc-header-alist
352 "use cperl-vc-rcs-header or cperl-vc-sccs-header instead.")
354 (defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
355 "*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
356 :type '(repeat string)
357 :group 'cperl)
359 (defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/) ;")
360 "*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
361 :type '(repeat string)
362 :group 'cperl)
364 (defcustom cperl-clobber-mode-lists
365 (not
366 (and
367 (boundp 'interpreter-mode-alist)
368 (assoc "miniperl" interpreter-mode-alist)
369 (assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
370 "*Whether to install us into `interpreter-' and `extension' mode lists."
371 :type 'boolean
372 :group 'cperl)
374 (defcustom cperl-info-on-command-no-prompt nil
375 "*Not-nil (and non-null) means not to prompt on C-h f.
376 The opposite behavior is always available if prefixed with C-c.
377 Can be overwritten by `cperl-hairy' if nil."
378 :type '(choice (const null) boolean)
379 :group 'cperl-affected-by-hairy)
381 (defcustom cperl-clobber-lisp-bindings nil
382 "*Not-nil (and non-null) means not overwrite C-h f.
383 The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
384 Can be overwritten by `cperl-hairy' if nil."
385 :type '(choice (const null) boolean)
386 :group 'cperl-affected-by-hairy)
388 (defcustom cperl-lazy-help-time nil
389 "*Not-nil (and non-null) means to show lazy help after given idle time.
390 Can be overwritten by `cperl-hairy' to be 5 sec if nil."
391 :type '(choice (const null) (const nil) integer)
392 :group 'cperl-affected-by-hairy)
394 (defcustom cperl-pod-face 'font-lock-comment-face
395 "*Face for POD highlighting."
396 :type 'face
397 :group 'cperl-faces)
399 (defcustom cperl-pod-head-face 'font-lock-variable-name-face
400 "*Face for POD highlighting.
401 Font for POD headers."
402 :type 'face
403 :group 'cperl-faces)
405 (defcustom cperl-here-face 'font-lock-string-face
406 "*Face for here-docs highlighting."
407 :type 'face
408 :group 'cperl-faces)
410 (defcustom cperl-invalid-face 'underline
411 "*Face for highlighting trailing whitespace."
412 :type 'face
413 :version "21.1"
414 :group 'cperl-faces)
416 (defcustom cperl-pod-here-fontify '(featurep 'font-lock)
417 "*Not-nil after evaluation means to highlight POD and here-docs sections."
418 :type 'boolean
419 :group 'cperl-faces)
421 (defcustom cperl-fontify-m-as-s t
422 "*Not-nil means highlight 1arg regular expressions operators same as 2arg."
423 :type 'boolean
424 :group 'cperl-faces)
426 (defcustom cperl-highlight-variables-indiscriminately nil
427 "*Non-nil means perform additional highlighting on variables.
428 Currently only changes how scalar variables are highlighted.
429 Note that that variable is only read at initialization time for
430 the variable `cperl-font-lock-keywords-2', so changing it after you've
431 entered CPerl mode the first time will have no effect."
432 :type 'boolean
433 :group 'cperl)
435 (defcustom cperl-pod-here-scan t
436 "*Not-nil means look for POD and here-docs sections during startup.
437 You can always make lookup from menu or using \\[cperl-find-pods-heres]."
438 :type 'boolean
439 :group 'cperl-speed)
441 (defcustom cperl-regexp-scan t
442 "*Not-nil means make marking of regular expression more thorough.
443 Effective only with `cperl-pod-here-scan'. Not implemented yet."
444 :type 'boolean
445 :group 'cperl-speed)
447 (defcustom cperl-imenu-addback nil
448 "*Not-nil means add backreferences to generated `imenu's.
449 May require patched `imenu' and `imenu-go'. Obsolete."
450 :type 'boolean
451 :group 'cperl-help-system)
453 (defcustom cperl-max-help-size 66
454 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
455 :type '(choice integer (const nil))
456 :group 'cperl-help-system)
458 (defcustom cperl-shrink-wrap-info-frame t
459 "*Non-nil means shrink-wrapping of info-buffer-frame allowed."
460 :type 'boolean
461 :group 'cperl-help-system)
463 (defcustom cperl-info-page "perl"
464 "*Name of the info page containing perl docs.
465 Older version of this page was called `perl5', newer `perl'."
466 :type 'string
467 :group 'cperl-help-system)
469 (defcustom cperl-use-syntax-table-text-property
470 (boundp 'parse-sexp-lookup-properties)
471 "*Non-nil means CPerl sets up and uses `syntax-table' text property."
472 :type 'boolean
473 :group 'cperl-speed)
475 (defcustom cperl-use-syntax-table-text-property-for-tags
476 cperl-use-syntax-table-text-property
477 "*Non-nil means: set up and use `syntax-table' text property generating TAGS."
478 :type 'boolean
479 :group 'cperl-speed)
481 (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
482 "*Regexp to match files to scan when generating TAGS."
483 :type 'regexp
484 :group 'cperl)
486 (defcustom cperl-noscan-files-regexp
487 "/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
488 "*Regexp to match files/dirs to skip when generating TAGS."
489 :type 'regexp
490 :group 'cperl)
492 (defcustom cperl-regexp-indent-step nil
493 "*Indentation used when beautifying regexps.
494 If nil, the value of `cperl-indent-level' will be used."
495 :type '(choice integer (const nil))
496 :group 'cperl-indentation-details)
498 (defcustom cperl-indent-left-aligned-comments t
499 "*Non-nil means that the comment starting in leftmost column should indent."
500 :type 'boolean
501 :group 'cperl-indentation-details)
503 (defcustom cperl-under-as-char nil
504 "*Non-nil means that the _ (underline) should be treated as word char."
505 :type 'boolean
506 :group 'cperl)
508 (defcustom cperl-extra-perl-args ""
509 "*Extra arguments to use when starting Perl.
510 Currently used with `cperl-check-syntax' only."
511 :type 'string
512 :group 'cperl)
514 (defcustom cperl-message-electric-keyword t
515 "*Non-nil means that the `cperl-electric-keyword' prints a help message."
516 :type 'boolean
517 :group 'cperl-help-system)
519 (defcustom cperl-indent-region-fix-constructs 1
520 "*Amount of space to insert between `}' and `else' or `elsif'
521 in `cperl-indent-region'. Set to nil to leave as is. Values other
522 than 1 and nil will probably not work."
523 :type '(choice (const nil) (const 1))
524 :group 'cperl-indentation-details)
526 (defcustom cperl-break-one-line-blocks-when-indent t
527 "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
528 need to be reformatted into multiline ones when indenting a region."
529 :type 'boolean
530 :group 'cperl-indentation-details)
532 (defcustom cperl-fix-hanging-brace-when-indent t
533 "*Non-nil means that BLOCK-end `}' may be put on a separate line
534 when indenting a region.
535 Braces followed by else/elsif/while/until are excepted."
536 :type 'boolean
537 :group 'cperl-indentation-details)
539 (defcustom cperl-merge-trailing-else t
540 "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
541 may be merged to be on the same line when indenting a region."
542 :type 'boolean
543 :group 'cperl-indentation-details)
545 (defcustom cperl-indent-parens-as-block nil
546 "*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
547 but for trailing \",\" inside the group, which won't increase indentation.
548 One should tune up `cperl-close-paren-offset' as well."
549 :type 'boolean
550 :group 'cperl-indentation-details)
552 (defcustom cperl-syntaxify-by-font-lock
553 (and cperl-can-font-lock
554 (boundp 'parse-sexp-lookup-properties))
555 "*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
556 :type '(choice (const message) boolean)
557 :group 'cperl-speed)
559 (defcustom cperl-syntaxify-unwind
561 "*Non-nil means that CPerl unwinds to a start of a long construction
562 when syntaxifying a chunk of buffer."
563 :type 'boolean
564 :group 'cperl-speed)
566 (defcustom cperl-ps-print-face-properties
567 '((font-lock-keyword-face nil nil bold shadow)
568 (font-lock-variable-name-face nil nil bold)
569 (font-lock-function-name-face nil nil bold italic box)
570 (font-lock-constant-face nil "LightGray" bold)
571 (cperl-array nil "LightGray" bold underline)
572 (cperl-hash nil "LightGray" bold italic underline)
573 (font-lock-comment-face nil "LightGray" italic)
574 (font-lock-string-face nil nil italic underline)
575 (cperl-nonoverridable nil nil italic underline)
576 (font-lock-type-face nil nil underline)
577 (underline nil "LightGray" strikeout))
578 "List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
579 :type '(repeat (cons symbol
580 (cons (choice (const nil) string)
581 (cons (choice (const nil) string)
582 (repeat symbol)))))
583 :group 'cperl-faces)
585 (defvar cperl-dark-background
586 (cperl-choose-color "navy" "os2blue" "darkgreen"))
587 (defvar cperl-dark-foreground
588 (cperl-choose-color "orchid1" "orange"))
590 (defface cperl-nonoverridable
591 `((((class grayscale) (background light))
592 (:background "Gray90" :slant italic :underline t))
593 (((class grayscale) (background dark))
594 (:foreground "Gray80" :slant italic :underline t :weight bold))
595 (((class color) (background light))
596 (:foreground "chartreuse3"))
597 (((class color) (background dark))
598 (:foreground ,cperl-dark-foreground))
599 (t (:weight bold :underline t)))
600 "Font Lock mode face used non-overridable keywords and modifiers of regexps."
601 :group 'cperl-faces)
602 ;; backward-compatibility alias
603 (put 'cperl-nonoverridable-face 'face-alias 'cperl-nonoverridable)
605 (defface cperl-array
606 `((((class grayscale) (background light))
607 (:background "Gray90" :weight bold))
608 (((class grayscale) (background dark))
609 (:foreground "Gray80" :weight bold))
610 (((class color) (background light))
611 (:foreground "Blue" :background "lightyellow2" :weight bold))
612 (((class color) (background dark))
613 (:foreground "yellow" :background ,cperl-dark-background :weight bold))
614 (t (:weight bold)))
615 "Font Lock mode face used to highlight array names."
616 :group 'cperl-faces)
617 ;; backward-compatibility alias
618 (put 'cperl-array-face 'face-alias 'cperl-array)
620 (defface cperl-hash
621 `((((class grayscale) (background light))
622 (:background "Gray90" :weight bold :slant italic))
623 (((class grayscale) (background dark))
624 (:foreground "Gray80" :weight bold :slant italic))
625 (((class color) (background light))
626 (:foreground "Red" :background "lightyellow2" :weight bold :slant italic))
627 (((class color) (background dark))
628 (:foreground "Red" :background ,cperl-dark-background :weight bold :slant italic))
629 (t (:weight bold :slant italic)))
630 "Font Lock mode face used to highlight hash names."
631 :group 'cperl-faces)
632 ;; backward-compatibility alias
633 (put 'cperl-hash-face 'face-alias 'cperl-hash)
637 ;;; Short extra-docs.
639 (defvar cperl-tips 'please-ignore-this-line
640 "Get maybe newer version of this package from
641 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs
642 and/or
643 ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
644 Subdirectory `cperl-mode' may contain yet newer development releases and/or
645 patches to related files.
647 For best results apply to an older Emacs the patches from
648 ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
649 \(this upgrades syntax-parsing abilities of Emacsen v19.34 and
650 v20.2 up to the level of Emacs v20.3 - a must for a good Perl
651 mode.) As of beginning of 2003, XEmacs may provide a similar ability.
653 Get support packages choose-color.el (or font-lock-extra.el before
654 19.30), imenu-go.el from the same place. \(Look for other files there
655 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
656 later you should use choose-color.el *instead* of font-lock-extra.el
657 \(and you will not get smart highlighting in C :-().
659 Note that to enable Compile choices in the menu you need to install
660 mode-compile.el.
662 If your Emacs does not default to `cperl-mode' on Perl files, and you
663 want it to: put the following into your .emacs file:
665 (defalias 'perl-mode 'cperl-mode)
667 Get perl5-info from
668 $CPAN/doc/manual/info/perl-info.tar.gz
669 older version was on
670 http://www.metronet.com:70/9/perlinfo/perl5/manual/perl5-info.tar.gz
672 If you use imenu-go, run imenu on perl5-info buffer (you can do it
673 from Perl menu). If many files are related, generate TAGS files from
674 Tools/Tags submenu in Perl menu.
676 If some class structure is too complicated, use Tools/Hierarchy-view
677 from Perl menu, or hierarchic view of imenu. The second one uses the
678 current buffer only, the first one requires generation of TAGS from
679 Perl/Tools/Tags menu beforehand.
681 Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
683 Switch auto-help on/off with Perl/Tools/Auto-help.
685 Though with contemporary Emaxen CPerl mode should maintain the correct
686 parsing of Perl even when editing, sometimes it may be lost. Fix this by
688 \\[normal-mode]
690 In cases of more severe confusion sometimes it is helpful to do
692 \\[load-library] cperl-mode RET
693 \\[normal-mode]
695 Before reporting (non-)problems look in the problem section of online
696 micro-docs on what I know about CPerl problems.")
698 (defvar cperl-problems 'please-ignore-this-line
699 "Description of problems in CPerl mode.
700 Some faces will not be shown on some versions of Emacs unless you
701 install choose-color.el, available from
702 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs/
704 `fill-paragraph' on a comment may leave the point behind the
705 paragraph. Parsing of lines with several <<EOF is not implemented
706 yet.
708 Emacs had a _very_ restricted syntax parsing engine until version
709 20.1. Most problems below are corrected starting from this version of
710 Emacs, and all of them should be fixed in version 20.3. (Or apply
711 patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
712 this respect (until 2003).
714 Note that even with newer Emacsen in some very rare cases the details
715 of interaction of `font-lock' and syntaxification may be not cleaned
716 up yet. You may get slightly different colors basing on the order of
717 fontification and syntaxification. Say, the initial faces is correct,
718 but editing the buffer breaks this.
720 Even with older Emacsen CPerl mode tries to corrects some Emacs
721 misunderstandings, however, for efficiency reasons the degree of
722 correction is different for different operations. The partially
723 corrected problems are: POD sections, here-documents, regexps. The
724 operations are: highlighting, indentation, electric keywords, electric
725 braces.
727 This may be confusing, since the regexp s#//#/#\; may be highlighted
728 as a comment, but it will be recognized as a regexp by the indentation
729 code. Or the opposite case, when a POD section is highlighted, but
730 may break the indentation of the following code (though indentation
731 should work if the balance of delimiters is not broken by POD).
733 The main trick (to make $ a \"backslash\") makes constructions like
734 ${aaa} look like unbalanced braces. The only trick I can think of is
735 to insert it as $ {aaa} (valid in perl5, not in perl4).
737 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
738 as /($|\\s)/. Note that such a transposition is not always possible.
740 The solution is to upgrade your Emacs or patch an older one. Note
741 that Emacs 20.2 has some bugs related to `syntax-table' text
742 properties. Patches are available on the main CPerl download site,
743 and on CPAN.
745 If these bugs cannot be fixed on your machine (say, you have an inferior
746 environment and cannot recompile), you may still disable all the fancy stuff
747 via `cperl-use-syntax-table-text-property'.")
749 (defvar cperl-praise 'please-ignore-this-line
750 "Advantages of CPerl mode.
752 0) It uses the newest `syntax-table' property ;-);
754 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
755 mode - but the latter number may have improved too in last years) even
756 with old Emaxen which do not support `syntax-table' property.
758 When using `syntax-table' property for syntax assist hints, it should
759 handle 99.995% of lines correct - or somesuch. It automatically
760 updates syntax assist hints when you edit your script.
762 2) It is generally believed to be \"the most user-friendly Emacs
763 package\" whatever it may mean (I doubt that the people who say similar
764 things tried _all_ the rest of Emacs ;-), but this was not a lonely
765 voice);
767 3) Everything is customizable, one-by-one or in a big sweep;
769 4) It has many easily-accessable \"tools\":
770 a) Can run program, check syntax, start debugger;
771 b) Can lineup vertically \"middles\" of rows, like `=' in
772 a = b;
773 cc = d;
774 c) Can insert spaces where this impoves readability (in one
775 interactive sweep over the buffer);
776 d) Has support for imenu, including:
777 1) Separate unordered list of \"interesting places\";
778 2) Separate TOC of POD sections;
779 3) Separate list of packages;
780 4) Hierarchical view of methods in (sub)packages;
781 5) and functions (by the full name - with package);
782 e) Has an interface to INFO docs for Perl; The interface is
783 very flexible, including shrink-wrapping of
784 documentation buffer/frame;
785 f) Has a builtin list of one-line explanations for perl constructs.
786 g) Can show these explanations if you stay long enough at the
787 corresponding place (or on demand);
788 h) Has an enhanced fontification (using 3 or 4 additional faces
789 comparing to font-lock - basically, different
790 namespaces in Perl have different colors);
791 i) Can construct TAGS basing on its knowledge of Perl syntax,
792 the standard menu has 6 different way to generate
793 TAGS (if \"by directory\", .xs files - with C-language
794 bindings - are included in the scan);
795 j) Can build a hierarchical view of classes (via imenu) basing
796 on generated TAGS file;
797 k) Has electric parentheses, electric newlines, uses Abbrev
798 for electric logical constructs
799 while () {}
800 with different styles of expansion (context sensitive
801 to be not so bothering). Electric parentheses behave
802 \"as they should\" in a presence of a visible region.
803 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
804 m) Can convert from
805 if (A) { B }
807 B if A;
809 n) Highlights (by user-choice) either 3-delimiters constructs
810 (such as tr/a/b/), or regular expressions and `y/tr';
811 o) Highlights trailing whitespace;
812 p) Is able to manipulate Perl Regular Expressions to ease
813 conversion to a more readable form.
815 5) The indentation engine was very smart, but most of tricks may be
816 not needed anymore with the support for `syntax-table' property. Has
817 progress indicator for indentation (with `imenu' loaded).
819 6) Indent-region improves inline-comments as well; also corrects
820 whitespace *inside* the conditional/loop constructs.
822 7) Fill-paragraph correctly handles multi-line comments;
824 8) Can switch to different indentation styles by one command, and restore
825 the settings present before the switch.
827 9) When doing indentation of control constructs, may correct
828 line-breaks/spacing between elements of the construct.
830 10) Uses a linear-time algorith for indentation of regions (on Emaxen with
831 capable syntax engines).")
833 (defvar cperl-speed 'please-ignore-this-line
834 "This is an incomplete compendium of what is available in other parts
835 of CPerl documentation. (Please inform me if I skept anything.)
837 There is a perception that CPerl is slower than alternatives. This part
838 of documentation is designed to overcome this misconception.
840 *By default* CPerl tries to enable the most comfortable settings.
841 From most points of view, correctly working package is infinitely more
842 comfortable than a non-correctly working one, thus by default CPerl
843 prefers correctness over speed. Below is the guide how to change
844 settings if your preferences are different.
846 A) Speed of loading the file. When loading file, CPerl may perform a
847 scan which indicates places which cannot be parsed by primitive Emacs
848 syntax-parsing routines, and marks them up so that either
850 A1) CPerl may work around these deficiencies (for big chunks, mostly
851 PODs and HERE-documents), or
852 A2) On capable Emaxen CPerl will use improved syntax-handlings
853 which reads mark-up hints directly.
855 The scan in case A2 is much more comprehensive, thus may be slower.
857 User can disable syntax-engine-helping scan of A2 by setting
858 `cperl-use-syntax-table-text-property'
859 variable to nil (if it is set to t).
861 One can disable the scan altogether (both A1 and A2) by setting
862 `cperl-pod-here-scan'
863 to nil.
865 B) Speed of editing operations.
867 One can add a (minor) speedup to editing operations by setting
868 `cperl-use-syntax-table-text-property'
869 variable to nil (if it is set to t). This will disable
870 syntax-engine-helping scan, thus will make many more Perl
871 constructs be wrongly recognized by CPerl, thus may lead to
872 wrongly matched parentheses, wrong indentation, etc.
874 One can unset `cperl-syntaxify-unwind'. This might speed up editing
875 of, say, long POD sections.")
877 (defvar cperl-tips-faces 'please-ignore-this-line
878 "CPerl mode uses following faces for highlighting:
880 `cperl-array' Array names
881 `cperl-hash' Hash names
882 `font-lock-comment-face' Comments, PODs and whatever is considered
883 syntaxically to be not code
884 `font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
885 2-arg operators s/y/tr/ or of RExen,
886 `font-lock-function-name-face' Special-cased m// and s//foo/, _ as
887 a target of a file tests, file tests,
888 subroutine names at the moment of definition
889 (except those conflicting with Perl operators),
890 package names (when recognized), format names
891 `font-lock-keyword-face' Control flow switch constructs, declarators
892 `cperl-nonoverridable' Non-overridable keywords, modifiers of RExen
893 `font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
894 literal parts and the terminator of formats
895 and whatever is syntaxically considered
896 as string literals
897 `font-lock-type-face' Overridable keywords
898 `font-lock-variable-name-face' Variable declarations, indirect array and
899 hash names, POD headers/item names
900 `cperl-invalid' Trailing whitespace
902 Note that in several situations the highlighting tries to inform about
903 possible confusion, such as different colors for function names in
904 declarations depending on what they (do not) override, or special cases
905 m// and s/// which do not do what one would expect them to do.
907 Help with best setup of these faces for printout requested (for each of
908 the faces: please specify bold, italic, underline, shadow and box.)
910 \(Not finished.)")
914 ;;; Portability stuff:
916 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
917 `(define-key cperl-mode-map
918 ,(if xemacs-key
919 `(if cperl-xemacs-p ,xemacs-key ,emacs-key)
920 emacs-key)
921 ,definition))
923 (defvar cperl-del-back-ch
924 (car (append (where-is-internal 'delete-backward-char)
925 (where-is-internal 'backward-delete-char-untabify)))
926 "Character generated by key bound to `delete-backward-char'.")
928 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
929 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
931 (defun cperl-mark-active () (mark)) ; Avoid undefined warning
932 (if cperl-xemacs-p
933 (progn
934 ;; "Active regions" are on: use region only if active
935 ;; "Active regions" are off: use region unconditionally
936 (defun cperl-use-region-p ()
937 (if zmacs-regions (mark) t)))
938 (defun cperl-use-region-p ()
939 (if transient-mark-mode mark-active t))
940 (defun cperl-mark-active () mark-active))
942 (defsubst cperl-enable-font-lock ()
943 cperl-can-font-lock)
945 (defun cperl-putback-char (c) ; Emacs 19
946 (set 'unread-command-events (list c))) ; Avoid undefined warning
948 (if cperl-xemacs-p
949 (defun cperl-putback-char (c) ; XEmacs >= 19.12
950 (setq unread-command-events (list (eval '(character-to-event c))))))
952 (or (fboundp 'uncomment-region)
953 (defun uncomment-region (beg end)
954 (interactive "r")
955 (comment-region beg end -1)))
957 (defvar cperl-do-not-fontify
958 (if (string< emacs-version "19.30")
959 'fontified
960 'lazy-lock)
961 "Text property which inhibits refontification.")
963 (defsubst cperl-put-do-not-fontify (from to &optional post)
964 ;; If POST, do not do it with postponed fontification
965 (if (and post cperl-syntaxify-by-font-lock)
967 (put-text-property (max (point-min) (1- from))
968 to cperl-do-not-fontify t)))
970 (defcustom cperl-mode-hook nil
971 "Hook run by CPerl mode."
972 :type 'hook
973 :group 'cperl)
975 (defvar cperl-syntax-state nil)
976 (defvar cperl-syntax-done-to nil)
977 (defvar cperl-emacs-can-parse (> (length (save-excursion
978 (parse-partial-sexp (point) (point)))) 9))
980 ;; Make customization possible "in reverse"
981 (defsubst cperl-val (symbol &optional default hairy)
982 (cond
983 ((eq (symbol-value symbol) 'null) default)
984 (cperl-hairy (or hairy t))
985 (t (symbol-value symbol))))
987 ;;; Probably it is too late to set these guys already, but it can help later:
989 ;;;(and cperl-clobber-mode-lists
990 ;;;(setq auto-mode-alist
991 ;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
992 ;;;(and (boundp 'interpreter-mode-alist)
993 ;;; (setq interpreter-mode-alist (append interpreter-mode-alist
994 ;;; '(("miniperl" . perl-mode))))))
995 (eval-when-compile
996 (mapcar (lambda (p)
997 (condition-case nil
998 (require p)
999 (error nil)))
1000 '(imenu easymenu etags timer man info))
1001 (if (fboundp 'ps-extend-face-list)
1002 (defmacro cperl-ps-extend-face-list (arg)
1003 `(ps-extend-face-list ,arg))
1004 (defmacro cperl-ps-extend-face-list (arg)
1005 `(error "This version of Emacs has no `ps-extend-face-list'")))
1006 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
1007 ;; macros instead of defsubsts don't work on Emacs, so we do the
1008 ;; expansion manually. Any other suggestions?
1009 (require 'cl))
1011 (defvar cperl-mode-abbrev-table nil
1012 "Abbrev table in use in CPerl mode buffers.")
1014 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
1016 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
1018 (if cperl-mode-map nil
1019 (setq cperl-mode-map (make-sparse-keymap))
1020 (cperl-define-key "{" 'cperl-electric-lbrace)
1021 (cperl-define-key "[" 'cperl-electric-paren)
1022 (cperl-define-key "(" 'cperl-electric-paren)
1023 (cperl-define-key "<" 'cperl-electric-paren)
1024 (cperl-define-key "}" 'cperl-electric-brace)
1025 (cperl-define-key "]" 'cperl-electric-rparen)
1026 (cperl-define-key ")" 'cperl-electric-rparen)
1027 (cperl-define-key ";" 'cperl-electric-semi)
1028 (cperl-define-key ":" 'cperl-electric-terminator)
1029 (cperl-define-key "\C-j" 'newline-and-indent)
1030 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
1031 (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless)
1032 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
1033 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
1034 (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix)
1035 (cperl-define-key "\C-c\C-f" 'auto-fill-mode)
1036 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
1037 (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp)
1038 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
1039 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
1040 [(control meta |)])
1041 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
1042 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
1043 (cperl-define-key "\177" 'cperl-electric-backspace)
1044 (cperl-define-key "\t" 'cperl-indent-command)
1045 ;; don't clobber the backspace binding:
1046 (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command
1047 [(control c) (control h) F])
1048 (if (cperl-val 'cperl-clobber-lisp-bindings)
1049 (progn
1050 (cperl-define-key "\C-hf"
1051 ;;(concat (char-to-string help-char) "f") ; does not work
1052 'cperl-info-on-command
1053 [(control h) f])
1054 (cperl-define-key "\C-hv"
1055 ;;(concat (char-to-string help-char) "v") ; does not work
1056 'cperl-get-help
1057 [(control h) v])
1058 (cperl-define-key "\C-c\C-hf"
1059 ;;(concat (char-to-string help-char) "f") ; does not work
1060 (key-binding "\C-hf")
1061 [(control c) (control h) f])
1062 (cperl-define-key "\C-c\C-hv"
1063 ;;(concat (char-to-string help-char) "v") ; does not work
1064 (key-binding "\C-hv")
1065 [(control c) (control h) v]))
1066 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
1067 [(control c) (control h) f])
1068 (cperl-define-key "\C-c\C-hv"
1069 ;;(concat (char-to-string help-char) "v") ; does not work
1070 'cperl-get-help
1071 [(control c) (control h) v]))
1072 (if (and cperl-xemacs-p
1073 (<= emacs-minor-version 11) (<= emacs-major-version 19))
1074 (progn
1075 ;; substitute-key-definition is usefulness-deenhanced...
1076 (cperl-define-key "\M-q" 'cperl-fill-paragraph)
1077 (cperl-define-key "\e;" 'cperl-indent-for-comment)
1078 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
1079 (substitute-key-definition
1080 'indent-sexp 'cperl-indent-exp
1081 cperl-mode-map global-map)
1082 (substitute-key-definition
1083 'indent-region 'cperl-indent-region
1084 cperl-mode-map global-map)
1085 (substitute-key-definition
1086 'indent-for-comment 'cperl-indent-for-comment
1087 cperl-mode-map global-map)))
1089 (defvar cperl-menu)
1090 (defvar cperl-lazy-installed)
1091 (defvar cperl-old-style nil)
1092 (condition-case nil
1093 (progn
1094 (require 'easymenu)
1095 (easy-menu-define
1096 cperl-menu cperl-mode-map "Menu for CPerl mode"
1097 '("Perl"
1098 ["Beginning of function" beginning-of-defun t]
1099 ["End of function" end-of-defun t]
1100 ["Mark function" mark-defun t]
1101 ["Indent expression" cperl-indent-exp t]
1102 ["Fill paragraph/comment" fill-paragraph t]
1103 "----"
1104 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
1105 ["Invert if/unless/while etc" cperl-invert-if-unless t]
1106 ("Regexp"
1107 ["Beautify" cperl-beautify-regexp
1108 cperl-use-syntax-table-text-property]
1109 ["Beautify one level deep" (cperl-beautify-regexp 1)
1110 cperl-use-syntax-table-text-property]
1111 ["Beautify a group" cperl-beautify-level
1112 cperl-use-syntax-table-text-property]
1113 ["Beautify a group one level deep" (cperl-beautify-level 1)
1114 cperl-use-syntax-table-text-property]
1115 ["Contract a group" cperl-contract-level
1116 cperl-use-syntax-table-text-property]
1117 ["Contract groups" cperl-contract-levels
1118 cperl-use-syntax-table-text-property])
1119 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
1120 "----"
1121 ["Indent region" cperl-indent-region (cperl-use-region-p)]
1122 ["Comment region" cperl-comment-region (cperl-use-region-p)]
1123 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
1124 "----"
1125 ["Run" mode-compile (fboundp 'mode-compile)]
1126 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
1127 (get-buffer "*compilation*"))]
1128 ["Next error" next-error (get-buffer "*compilation*")]
1129 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
1130 "----"
1131 ["Debugger" cperl-db t]
1132 "----"
1133 ("Tools"
1134 ["Imenu" imenu (fboundp 'imenu)]
1135 ["Insert spaces if needed" cperl-find-bad-style t]
1136 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
1137 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
1138 ["CPerl pretty print (exprmntl)" cperl-ps-print
1139 (fboundp 'ps-extend-face-list)]
1140 ["Imenu on info" cperl-imenu-on-info (featurep 'imenu)]
1141 ("Tags"
1142 ;;; ["Create tags for current file" cperl-etags t]
1143 ;;; ["Add tags for current file" (cperl-etags t) t]
1144 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
1145 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
1146 ;;; ["Create tags for Perl files in (sub)directories"
1147 ;;; (cperl-etags nil 'recursive) t]
1148 ;;; ["Add tags for Perl files in (sub)directories"
1149 ;;; (cperl-etags t 'recursive) t])
1150 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
1151 ["Create tags for current file" (cperl-write-tags nil t) t]
1152 ["Add tags for current file" (cperl-write-tags) t]
1153 ["Create tags for Perl files in directory"
1154 (cperl-write-tags nil t nil t) t]
1155 ["Add tags for Perl files in directory"
1156 (cperl-write-tags nil nil nil t) t]
1157 ["Create tags for Perl files in (sub)directories"
1158 (cperl-write-tags nil t t t) t]
1159 ["Add tags for Perl files in (sub)directories"
1160 (cperl-write-tags nil nil t t) t]))
1161 ("Perl docs"
1162 ["Define word at point" imenu-go-find-at-position
1163 (fboundp 'imenu-go-find-at-position)]
1164 ["Help on function" cperl-info-on-command t]
1165 ["Help on function at point" cperl-info-on-current-command t]
1166 ["Help on symbol at point" cperl-get-help t]
1167 ["Perldoc" cperl-perldoc t]
1168 ["Perldoc on word at point" cperl-perldoc-at-point t]
1169 ["View manpage of POD in this file" cperl-build-manpage t]
1170 ["Auto-help on" cperl-lazy-install
1171 (and (fboundp 'run-with-idle-timer)
1172 (not cperl-lazy-installed))]
1173 ["Auto-help off" cperl-lazy-unstall
1174 (and (fboundp 'run-with-idle-timer)
1175 cperl-lazy-installed)])
1176 ("Toggle..."
1177 ["Auto newline" cperl-toggle-auto-newline t]
1178 ["Electric parens" cperl-toggle-electric t]
1179 ["Electric keywords" cperl-toggle-abbrev t]
1180 ["Fix whitespace on indent" cperl-toggle-construct-fix t]
1181 ["Auto-help on Perl constructs" cperl-toggle-autohelp t]
1182 ["Auto fill" auto-fill-mode t])
1183 ("Indent styles..."
1184 ["CPerl" (cperl-set-style "CPerl") t]
1185 ["PerlStyle" (cperl-set-style "PerlStyle") t]
1186 ["GNU" (cperl-set-style "GNU") t]
1187 ["C++" (cperl-set-style "C++") t]
1188 ["FSF" (cperl-set-style "FSF") t]
1189 ["BSD" (cperl-set-style "BSD") t]
1190 ["Whitesmith" (cperl-set-style "Whitesmith") t]
1191 ["Current" (cperl-set-style "Current") t]
1192 ["Memorized" (cperl-set-style-back) cperl-old-style])
1193 ("Micro-docs"
1194 ["Tips" (describe-variable 'cperl-tips) t]
1195 ["Problems" (describe-variable 'cperl-problems) t]
1196 ["Speed" (describe-variable 'cperl-speed) t]
1197 ["Praise" (describe-variable 'cperl-praise) t]
1198 ["Faces" (describe-variable 'cperl-tips-faces) t]
1199 ["CPerl mode" (describe-function 'cperl-mode) t]
1200 ["CPerl version"
1201 (message "The version of master-file for this CPerl is %s-Emacs"
1202 cperl-version) t]))))
1203 (error nil))
1205 (autoload 'c-macro-expand "cmacexp"
1206 "Display the result of expanding all C macros occurring in the region.
1207 The expansion is entirely correct because it uses the C preprocessor."
1210 (defvar cperl-imenu--function-name-regexp-perl
1211 (concat
1212 "^\\("
1213 "[ \t]*\\(sub\\|package\\)[ \t\n]+\\([a-zA-Z_0-9:']+\\)[ \t]*\\(([^()]*)[ \t]*\\)?"
1214 "\\|"
1215 "=head\\([12]\\)[ \t]+\\([^\n]+\\)$"
1216 "\\)"))
1218 (defvar cperl-outline-regexp
1219 (concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))
1221 (defvar cperl-mode-syntax-table nil
1222 "Syntax table in use in CPerl mode buffers.")
1224 (defvar cperl-string-syntax-table nil
1225 "Syntax table in use in CPerl mode string-like chunks.")
1227 (if cperl-mode-syntax-table
1229 (setq cperl-mode-syntax-table (make-syntax-table))
1230 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
1231 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
1232 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
1233 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
1234 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
1235 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
1236 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
1237 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
1238 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
1239 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
1240 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
1241 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
1242 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
1243 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
1244 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
1245 (if cperl-under-as-char
1246 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
1247 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
1248 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
1249 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
1250 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
1251 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment )
1255 (defvar cperl-faces-init nil)
1256 ;; Fix for msb.el
1257 (defvar cperl-msb-fixed nil)
1258 (defvar cperl-use-major-mode 'cperl-mode)
1260 ;;;###autoload
1261 (defun cperl-mode ()
1262 "Major mode for editing Perl code.
1263 Expression and list commands understand all C brackets.
1264 Tab indents for Perl code.
1265 Paragraphs are separated by blank lines only.
1266 Delete converts tabs to spaces as it moves back.
1268 Various characters in Perl almost always come in pairs: {}, (), [],
1269 sometimes <>. When the user types the first, she gets the second as
1270 well, with optional special formatting done on {}. (Disabled by
1271 default.) You can always quote (with \\[quoted-insert]) the left
1272 \"paren\" to avoid the expansion. The processing of < is special,
1273 since most the time you mean \"less\". CPerl mode tries to guess
1274 whether you want to type pair <>, and inserts is if it
1275 appropriate. You can set `cperl-electric-parens-string' to the string that
1276 contains the parenths from the above list you want to be electrical.
1277 Electricity of parenths is controlled by `cperl-electric-parens'.
1278 You may also set `cperl-electric-parens-mark' to have electric parens
1279 look for active mark and \"embrace\" a region if possible.'
1281 CPerl mode provides expansion of the Perl control constructs:
1283 if, else, elsif, unless, while, until, continue, do,
1284 for, foreach, formy and foreachmy.
1286 and POD directives (Disabled by default, see `cperl-electric-keywords'.)
1288 The user types the keyword immediately followed by a space, which
1289 causes the construct to be expanded, and the point is positioned where
1290 she is most likely to want to be. eg. when the user types a space
1291 following \"if\" the following appears in the buffer: if () { or if ()
1292 } { } and the cursor is between the parentheses. The user can then
1293 type some boolean expression within the parens. Having done that,
1294 typing \\[cperl-linefeed] places you - appropriately indented - on a
1295 new line between the braces (if you typed \\[cperl-linefeed] in a POD
1296 directive line, then appropriate number of new lines is inserted).
1298 If CPerl decides that you want to insert \"English\" style construct like
1300 bite if angry;
1302 it will not do any expansion. See also help on variable
1303 `cperl-extra-newline-before-brace'. (Note that one can switch the
1304 help message on expansion by setting `cperl-message-electric-keyword'
1305 to nil.)
1307 \\[cperl-linefeed] is a convenience replacement for typing carriage
1308 return. It places you in the next line with proper indentation, or if
1309 you type it inside the inline block of control construct, like
1311 foreach (@lines) {print; print}
1313 and you are on a boundary of a statement inside braces, it will
1314 transform the construct into a multiline and will place you into an
1315 appropriately indented blank line. If you need a usual
1316 `newline-and-indent' behavior, it is on \\[newline-and-indent],
1317 see documentation on `cperl-electric-linefeed'.
1319 Use \\[cperl-invert-if-unless] to change a construction of the form
1321 if (A) { B }
1323 into
1325 B if A;
1327 \\{cperl-mode-map}
1329 Setting the variable `cperl-font-lock' to t switches on font-lock-mode
1330 \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches
1331 on electric space between $ and {, `cperl-electric-parens-string' is
1332 the string that contains parentheses that should be electric in CPerl
1333 \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'),
1334 setting `cperl-electric-keywords' enables electric expansion of
1335 control structures in CPerl. `cperl-electric-linefeed' governs which
1336 one of two linefeed behavior is preferable. You can enable all these
1337 options simultaneously (recommended mode of use) by setting
1338 `cperl-hairy' to t. In this case you can switch separate options off
1339 by setting them to `null'. Note that one may undo the extra
1340 whitespace inserted by semis and braces in `auto-newline'-mode by
1341 consequent \\[cperl-electric-backspace].
1343 If your site has perl5 documentation in info format, you can use commands
1344 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
1345 These keys run commands `cperl-info-on-current-command' and
1346 `cperl-info-on-command', which one is which is controlled by variable
1347 `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings'
1348 \(in turn affected by `cperl-hairy').
1350 Even if you have no info-format documentation, short one-liner-style
1351 help is available on \\[cperl-get-help], and one can run perldoc or
1352 man via menu.
1354 It is possible to show this help automatically after some idle time.
1355 This is regulated by variable `cperl-lazy-help-time'. Default with
1356 `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5
1357 secs idle time . It is also possible to switch this on/off from the
1358 menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'.
1360 Use \\[cperl-lineup] to vertically lineup some construction - put the
1361 beginning of the region at the start of construction, and make region
1362 span the needed amount of lines.
1364 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
1365 `cperl-pod-face', `cperl-pod-head-face' control processing of POD and
1366 here-docs sections. With capable Emaxen results of scan are used
1367 for indentation too, otherwise they are used for highlighting only.
1369 Variables controlling indentation style:
1370 `cperl-tab-always-indent'
1371 Non-nil means TAB in CPerl mode should always reindent the current line,
1372 regardless of where in the line point is when the TAB command is used.
1373 `cperl-indent-left-aligned-comments'
1374 Non-nil means that the comment starting in leftmost column should indent.
1375 `cperl-auto-newline'
1376 Non-nil means automatically newline before and after braces,
1377 and after colons and semicolons, inserted in Perl code. The following
1378 \\[cperl-electric-backspace] will remove the inserted whitespace.
1379 Insertion after colons requires both this variable and
1380 `cperl-auto-newline-after-colon' set.
1381 `cperl-auto-newline-after-colon'
1382 Non-nil means automatically newline even after colons.
1383 Subject to `cperl-auto-newline' setting.
1384 `cperl-indent-level'
1385 Indentation of Perl statements within surrounding block.
1386 The surrounding block's indentation is the indentation
1387 of the line on which the open-brace appears.
1388 `cperl-continued-statement-offset'
1389 Extra indentation given to a substatement, such as the
1390 then-clause of an if, or body of a while, or just a statement continuation.
1391 `cperl-continued-brace-offset'
1392 Extra indentation given to a brace that starts a substatement.
1393 This is in addition to `cperl-continued-statement-offset'.
1394 `cperl-brace-offset'
1395 Extra indentation for line if it starts with an open brace.
1396 `cperl-brace-imaginary-offset'
1397 An open brace following other text is treated as if it the line started
1398 this far to the right of the actual line indentation.
1399 `cperl-label-offset'
1400 Extra indentation for line that is a label.
1401 `cperl-min-label-indent'
1402 Minimal indentation for line that is a label.
1404 Settings for K&R and BSD indentation styles are
1405 `cperl-indent-level' 5 8
1406 `cperl-continued-statement-offset' 5 8
1407 `cperl-brace-offset' -5 -8
1408 `cperl-label-offset' -5 -8
1410 CPerl knows several indentation styles, and may bulk set the
1411 corresponding variables. Use \\[cperl-set-style] to do this. Use
1412 \\[cperl-set-style-back] to restore the memorized preexisting values
1413 \(both available from menu).
1415 If `cperl-indent-level' is 0, the statement after opening brace in
1416 column 0 is indented on
1417 `cperl-brace-offset'+`cperl-continued-statement-offset'.
1419 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
1420 with no args.
1422 DO NOT FORGET to read micro-docs (available from `Perl' menu)
1423 or as help on variables `cperl-tips', `cperl-problems',
1424 `cperl-praise', `cperl-speed'."
1425 (interactive)
1426 (kill-all-local-variables)
1427 (use-local-map cperl-mode-map)
1428 (if (cperl-val 'cperl-electric-linefeed)
1429 (progn
1430 (local-set-key "\C-J" 'cperl-linefeed)
1431 (local-set-key "\C-C\C-J" 'newline-and-indent)))
1432 (if (and
1433 (cperl-val 'cperl-clobber-lisp-bindings)
1434 (cperl-val 'cperl-info-on-command-no-prompt))
1435 (progn
1436 ;; don't clobber the backspace binding:
1437 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
1438 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
1439 [(control c) (control h) f])))
1440 (setq major-mode cperl-use-major-mode)
1441 (setq mode-name "CPerl")
1442 (if (not cperl-mode-abbrev-table)
1443 (let ((prev-a-c abbrevs-changed))
1444 (define-abbrev-table 'cperl-mode-abbrev-table '(
1445 ("if" "if" cperl-electric-keyword 0)
1446 ("elsif" "elsif" cperl-electric-keyword 0)
1447 ("while" "while" cperl-electric-keyword 0)
1448 ("until" "until" cperl-electric-keyword 0)
1449 ("unless" "unless" cperl-electric-keyword 0)
1450 ("else" "else" cperl-electric-else 0)
1451 ("continue" "continue" cperl-electric-else 0)
1452 ("for" "for" cperl-electric-keyword 0)
1453 ("foreach" "foreach" cperl-electric-keyword 0)
1454 ("formy" "formy" cperl-electric-keyword 0)
1455 ("foreachmy" "foreachmy" cperl-electric-keyword 0)
1456 ("do" "do" cperl-electric-keyword 0)
1457 ("=pod" "=pod" cperl-electric-pod 0)
1458 ("=over" "=over" cperl-electric-pod 0)
1459 ("=head1" "=head1" cperl-electric-pod 0)
1460 ("=head2" "=head2" cperl-electric-pod 0)
1461 ("pod" "pod" cperl-electric-pod 0)
1462 ("over" "over" cperl-electric-pod 0)
1463 ("head1" "head1" cperl-electric-pod 0)
1464 ("head2" "head2" cperl-electric-pod 0)))
1465 (setq abbrevs-changed prev-a-c)))
1466 (setq local-abbrev-table cperl-mode-abbrev-table)
1467 (abbrev-mode (if (cperl-val 'cperl-electric-keywords) 1 0))
1468 (set-syntax-table cperl-mode-syntax-table)
1469 (make-local-variable 'outline-regexp)
1470 ;; (setq outline-regexp imenu-example--function-name-regexp-perl)
1471 (setq outline-regexp cperl-outline-regexp)
1472 (make-local-variable 'outline-level)
1473 (setq outline-level 'cperl-outline-level)
1474 (make-local-variable 'paragraph-start)
1475 (setq paragraph-start (concat "^$\\|" page-delimiter))
1476 (make-local-variable 'paragraph-separate)
1477 (setq paragraph-separate paragraph-start)
1478 (make-local-variable 'paragraph-ignore-fill-prefix)
1479 (setq paragraph-ignore-fill-prefix t)
1480 (set (make-local-variable 'fill-paragraph-function) 'cperl-fill-paragraph)
1481 (make-local-variable 'indent-line-function)
1482 (setq indent-line-function 'cperl-indent-line)
1483 (make-local-variable 'require-final-newline)
1484 (setq require-final-newline mode-require-final-newline)
1485 (make-local-variable 'comment-start)
1486 (setq comment-start "# ")
1487 (make-local-variable 'comment-end)
1488 (setq comment-end "")
1489 (make-local-variable 'comment-column)
1490 (setq comment-column cperl-comment-column)
1491 (make-local-variable 'comment-start-skip)
1492 (setq comment-start-skip "#+ *")
1493 (make-local-variable 'defun-prompt-regexp)
1494 (setq defun-prompt-regexp "^[ \t]*sub[ \t\n]+\\([^ \t\n{(;]+\\)\\([ \t\n]*([^()]*)[ \t\n]*\\)?[ \t\n]*")
1495 (make-local-variable 'comment-indent-function)
1496 (setq comment-indent-function 'cperl-comment-indent)
1497 (make-local-variable 'parse-sexp-ignore-comments)
1498 (setq parse-sexp-ignore-comments t)
1499 (make-local-variable 'indent-region-function)
1500 (setq indent-region-function 'cperl-indent-region)
1501 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
1502 (make-local-variable 'imenu-create-index-function)
1503 (setq imenu-create-index-function
1504 (function cperl-imenu--create-perl-index))
1505 (make-local-variable 'imenu-sort-function)
1506 (setq imenu-sort-function nil)
1507 (make-local-variable 'vc-rcs-header)
1508 (set 'vc-rcs-header cperl-vc-rcs-header)
1509 (make-local-variable 'vc-sccs-header)
1510 (set 'vc-sccs-header cperl-vc-sccs-header)
1511 (make-local-variable 'font-lock-defaults)
1512 (setq font-lock-defaults
1513 (cond
1514 ((string< emacs-version "19.30")
1515 '(cperl-font-lock-keywords-2))
1516 ((string< emacs-version "19.33") ; Which one to use?
1517 '((cperl-font-lock-keywords
1518 cperl-font-lock-keywords-1
1519 cperl-font-lock-keywords-2)))
1521 '((cperl-load-font-lock-keywords
1522 cperl-load-font-lock-keywords-1
1523 cperl-load-font-lock-keywords-2)
1524 nil nil ((?_ . "w"))))))
1525 (make-local-variable 'cperl-syntax-state)
1526 (if cperl-use-syntax-table-text-property
1527 (progn
1528 (make-local-variable 'parse-sexp-lookup-properties)
1529 ;; Do not introduce variable if not needed, we check it!
1530 (set 'parse-sexp-lookup-properties t)
1531 ;; Fix broken font-lock:
1532 (or (boundp 'font-lock-unfontify-region-function)
1533 (set 'font-lock-unfontify-region-function
1534 'font-lock-default-unfontify-region))
1535 (make-local-variable 'font-lock-unfontify-region-function)
1536 (set 'font-lock-unfontify-region-function ; not present with old Emacs
1537 'cperl-font-lock-unfontify-region-function)
1538 (make-local-variable 'cperl-syntax-done-to)
1539 (make-local-variable 'font-lock-syntactic-keywords)
1540 (setq font-lock-syntactic-keywords
1541 (if cperl-syntaxify-by-font-lock
1542 '((cperl-fontify-syntaxically))
1543 ;; unless font-lock-syntactic-keywords, font-lock (pre-22.1)
1544 ;; used to ignore syntax-table text-properties. (t) is a hack
1545 ;; to make font-lock think that font-lock-syntactic-keywords
1546 ;; are defined.
1547 '(t)))))
1548 (make-local-variable 'cperl-old-style)
1549 (if (boundp 'normal-auto-fill-function) ; 19.33 and later
1550 (set (make-local-variable 'normal-auto-fill-function)
1551 'cperl-do-auto-fill) ; RMS has it as #'cperl-do-auto-fill ???
1552 (or (fboundp 'cperl-old-auto-fill-mode)
1553 (progn
1554 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
1555 (defun auto-fill-mode (&optional arg)
1556 (interactive "P")
1557 (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning
1558 (and auto-fill-function (memq major-mode '(perl-mode cperl-mode))
1559 (setq auto-fill-function 'cperl-do-auto-fill))))))
1560 (if (cperl-enable-font-lock)
1561 (if (cperl-val 'cperl-font-lock)
1562 (progn (or cperl-faces-init (cperl-init-faces))
1563 (font-lock-mode 1))))
1564 (and (boundp 'msb-menu-cond)
1565 (not cperl-msb-fixed)
1566 (cperl-msb-fix))
1567 (if (featurep 'easymenu)
1568 (easy-menu-add cperl-menu)) ; A NOP in Emacs.
1569 (run-mode-hooks 'cperl-mode-hook)
1570 ;; After hooks since fontification will break this
1571 (if cperl-pod-here-scan
1572 (or cperl-syntaxify-by-font-lock
1573 (progn (or cperl-faces-init (cperl-init-faces-weak))
1574 (cperl-find-pods-heres)))))
1576 ;; Fix for perldb - make default reasonable
1577 (defun cperl-db ()
1578 (interactive)
1579 (require 'gud)
1580 (perldb (read-from-minibuffer "Run perldb (like this): "
1581 (if (consp gud-perldb-history)
1582 (car gud-perldb-history)
1583 (concat "perl " ;;(file-name-nondirectory
1584 ;; I have problems
1585 ;; in OS/2
1586 ;; otherwise
1587 (buffer-file-name)))
1588 nil nil
1589 '(gud-perldb-history . 1))))
1591 (defun cperl-msb-fix ()
1592 ;; Adds perl files to msb menu, supposes that msb is already loaded
1593 (setq cperl-msb-fixed t)
1594 (let* ((l (length msb-menu-cond))
1595 (last (nth (1- l) msb-menu-cond))
1596 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
1597 (handle (1- (nth 1 last))))
1598 (setcdr precdr (list
1599 (list
1600 '(memq major-mode '(cperl-mode perl-mode))
1601 handle
1602 "Perl Files (%d)")
1603 last))))
1605 ;; This is used by indent-for-comment
1606 ;; to decide how much to indent a comment in CPerl code
1607 ;; based on its context. Do fallback if comment is found wrong.
1609 (defvar cperl-wrong-comment)
1610 (defvar cperl-st-cfence '(14)) ; Comment-fence
1611 (defvar cperl-st-sfence '(15)) ; String-fence
1612 (defvar cperl-st-punct '(1))
1613 (defvar cperl-st-word '(2))
1614 (defvar cperl-st-bra '(4 . ?\>))
1615 (defvar cperl-st-ket '(5 . ?\<))
1618 (defun cperl-comment-indent ()
1619 (let ((p (point)) (c (current-column)) was phony)
1620 (if (looking-at "^#") 0 ; Existing comment at bol stays there.
1621 ;; Wrong comment found
1622 (save-excursion
1623 (setq was (cperl-to-comment-or-eol)
1624 phony (eq (get-text-property (point) 'syntax-table)
1625 cperl-st-cfence))
1626 (if phony
1627 (progn
1628 (re-search-forward "#\\|$") ; Hmm, what about embedded #?
1629 (if (eq (preceding-char) ?\#)
1630 (forward-char -1))
1631 (setq was nil)))
1632 (if (= (point) p)
1633 (progn
1634 (skip-chars-backward " \t")
1635 (max (1+ (current-column)) ; Else indent at comment column
1636 comment-column))
1637 (if was nil
1638 (insert comment-start)
1639 (backward-char (length comment-start)))
1640 (setq cperl-wrong-comment t)
1641 (indent-to comment-column 1) ; Indent minimum 1
1642 c))))) ; except leave at least one space.
1644 ;;;(defun cperl-comment-indent-fallback ()
1645 ;;; "Is called if the standard comment-search procedure fails.
1646 ;;;Point is at start of real comment."
1647 ;;; (let ((c (current-column)) target cnt prevc)
1648 ;;; (if (= c comment-column) nil
1649 ;;; (setq cnt (skip-chars-backward "[ \t]"))
1650 ;;; (setq target (max (1+ (setq prevc
1651 ;;; (current-column))) ; Else indent at comment column
1652 ;;; comment-column))
1653 ;;; (if (= c comment-column) nil
1654 ;;; (delete-backward-char cnt)
1655 ;;; (while (< prevc target)
1656 ;;; (insert "\t")
1657 ;;; (setq prevc (current-column)))
1658 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
1659 ;;; (while (< prevc target)
1660 ;;; (insert " ")
1661 ;;; (setq prevc (current-column)))))))
1663 (defun cperl-indent-for-comment ()
1664 "Substitute for `indent-for-comment' in CPerl."
1665 (interactive)
1666 (let (cperl-wrong-comment)
1667 (indent-for-comment)
1668 (if cperl-wrong-comment
1669 (progn (cperl-to-comment-or-eol)
1670 (forward-char (length comment-start))))))
1672 (defun cperl-comment-region (b e arg)
1673 "Comment or uncomment each line in the region in CPerl mode.
1674 See `comment-region'."
1675 (interactive "r\np")
1676 (let ((comment-start "#"))
1677 (comment-region b e arg)))
1679 (defun cperl-uncomment-region (b e arg)
1680 "Uncomment or comment each line in the region in CPerl mode.
1681 See `comment-region'."
1682 (interactive "r\np")
1683 (let ((comment-start "#"))
1684 (comment-region b e (- arg))))
1686 (defvar cperl-brace-recursing nil)
1688 (defun cperl-electric-brace (arg &optional only-before)
1689 "Insert character and correct line's indentation.
1690 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
1691 place (even in empty line), but not after. If after \")\" and the inserted
1692 char is \"{\", insert extra newline before only if
1693 `cperl-extra-newline-before-brace'."
1694 (interactive "P")
1695 (let (insertpos
1696 (other-end (if (and cperl-electric-parens-mark
1697 (cperl-mark-active)
1698 (< (mark) (point)))
1699 (mark)
1700 nil)))
1701 (if (and other-end
1702 (not cperl-brace-recursing)
1703 (cperl-val 'cperl-electric-parens)
1704 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
1705 ;; Need to insert a matching pair
1706 (progn
1707 (save-excursion
1708 (setq insertpos (point-marker))
1709 (goto-char other-end)
1710 (setq last-command-char ?\{)
1711 (cperl-electric-lbrace arg insertpos))
1712 (forward-char 1))
1713 ;; Check whether we close something "usual" with `}'
1714 (if (and (eq last-command-char ?\})
1715 (not
1716 (condition-case nil
1717 (save-excursion
1718 (up-list (- (prefix-numeric-value arg)))
1719 ;;(cperl-after-block-p (point-min))
1720 (or (cperl-after-expr-p nil "{;)")
1721 ;; after sub, else, continue
1722 (cperl-after-block-p nil 'pre)))
1723 (error nil))))
1724 ;; Just insert the guy
1725 (self-insert-command (prefix-numeric-value arg))
1726 (if (and (not arg) ; No args, end (of empty line or auto)
1727 (eolp)
1728 (or (and (null only-before)
1729 (save-excursion
1730 (skip-chars-backward " \t")
1731 (bolp)))
1732 (and (eq last-command-char ?\{) ; Do not insert newline
1733 ;; if after ")" and `cperl-extra-newline-before-brace'
1734 ;; is nil, do not insert extra newline.
1735 (not cperl-extra-newline-before-brace)
1736 (save-excursion
1737 (skip-chars-backward " \t")
1738 (eq (preceding-char) ?\))))
1739 (if cperl-auto-newline
1740 (progn (cperl-indent-line) (newline) t) nil)))
1741 (progn
1742 (self-insert-command (prefix-numeric-value arg))
1743 (cperl-indent-line)
1744 (if cperl-auto-newline
1745 (setq insertpos (1- (point))))
1746 (if (and cperl-auto-newline (null only-before))
1747 (progn
1748 (newline)
1749 (cperl-indent-line)))
1750 (save-excursion
1751 (if insertpos (progn (goto-char insertpos)
1752 (search-forward (make-string
1753 1 last-command-char))
1754 (setq insertpos (1- (point)))))
1755 (delete-char -1))))
1756 (if insertpos
1757 (save-excursion
1758 (goto-char insertpos)
1759 (self-insert-command (prefix-numeric-value arg)))
1760 (self-insert-command (prefix-numeric-value arg)))))))
1762 (defun cperl-electric-lbrace (arg &optional end)
1763 "Insert character, correct line's indentation, correct quoting by space."
1764 (interactive "P")
1765 (let ((cperl-brace-recursing t)
1766 (cperl-auto-newline cperl-auto-newline)
1767 (other-end (or end
1768 (if (and cperl-electric-parens-mark
1769 (cperl-mark-active)
1770 (> (mark) (point)))
1771 (save-excursion
1772 (goto-char (mark))
1773 (point-marker))
1774 nil)))
1775 pos after)
1776 (and (cperl-val 'cperl-electric-lbrace-space)
1777 (eq (preceding-char) ?$)
1778 (save-excursion
1779 (skip-chars-backward "$")
1780 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
1781 (insert ?\s))
1782 ;; Check whether we are in comment
1783 (if (and
1784 (save-excursion
1785 (beginning-of-line)
1786 (not (looking-at "[ \t]*#")))
1787 (cperl-after-expr-p nil "{;)"))
1789 (setq cperl-auto-newline nil))
1790 (cperl-electric-brace arg)
1791 (and (cperl-val 'cperl-electric-parens)
1792 (eq last-command-char ?{)
1793 (memq last-command-char
1794 (append cperl-electric-parens-string nil))
1795 (or (if other-end (goto-char (marker-position other-end)))
1797 (setq last-command-char ?} pos (point))
1798 (progn (cperl-electric-brace arg t)
1799 (goto-char pos)))))
1801 (defun cperl-electric-paren (arg)
1802 "Insert an opening parenthesis or a matching pair of parentheses.
1803 See `cperl-electric-parens'."
1804 (interactive "P")
1805 (let ((beg (save-excursion (beginning-of-line) (point)))
1806 (other-end (if (and cperl-electric-parens-mark
1807 (cperl-mark-active)
1808 (> (mark) (point)))
1809 (save-excursion
1810 (goto-char (mark))
1811 (point-marker))
1812 nil)))
1813 (if (and (cperl-val 'cperl-electric-parens)
1814 (memq last-command-char
1815 (append cperl-electric-parens-string nil))
1816 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
1817 ;;(not (save-excursion (search-backward "#" beg t)))
1818 (if (eq last-command-char ?<)
1819 (progn
1820 (and abbrev-mode ; later it is too late, may be after `for'
1821 (expand-abbrev))
1822 (cperl-after-expr-p nil "{;(,:="))
1824 (progn
1825 (self-insert-command (prefix-numeric-value arg))
1826 (if other-end (goto-char (marker-position other-end)))
1827 (insert (make-string
1828 (prefix-numeric-value arg)
1829 (cdr (assoc last-command-char '((?{ .?})
1830 (?[ . ?])
1831 (?( . ?))
1832 (?< . ?>))))))
1833 (forward-char (- (prefix-numeric-value arg))))
1834 (self-insert-command (prefix-numeric-value arg)))))
1836 (defun cperl-electric-rparen (arg)
1837 "Insert a matching pair of parentheses if marking is active.
1838 If not, or if we are not at the end of marking range, would self-insert.
1839 Affected by `cperl-electric-parens'."
1840 (interactive "P")
1841 (let ((beg (save-excursion (beginning-of-line) (point)))
1842 (other-end (if (and cperl-electric-parens-mark
1843 (cperl-val 'cperl-electric-parens)
1844 (memq last-command-char
1845 (append cperl-electric-parens-string nil))
1846 (cperl-mark-active)
1847 (< (mark) (point)))
1848 (mark)
1849 nil))
1851 (if (and other-end
1852 (cperl-val 'cperl-electric-parens)
1853 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
1854 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
1855 ;;(not (save-excursion (search-backward "#" beg t)))
1857 (progn
1858 (self-insert-command (prefix-numeric-value arg))
1859 (setq p (point))
1860 (if other-end (goto-char other-end))
1861 (insert (make-string
1862 (prefix-numeric-value arg)
1863 (cdr (assoc last-command-char '((?\} . ?\{)
1864 (?\] . ?\[)
1865 (?\) . ?\()
1866 (?\> . ?\<))))))
1867 (goto-char (1+ p)))
1868 (self-insert-command (prefix-numeric-value arg)))))
1870 (defun cperl-electric-keyword ()
1871 "Insert a construction appropriate after a keyword.
1872 Help message may be switched off by setting `cperl-message-electric-keyword'
1873 to nil."
1874 (let ((beg (save-excursion (beginning-of-line) (point)))
1875 (dollar (and (eq last-command-char ?$)
1876 (eq this-command 'self-insert-command)))
1877 (delete (and (memq last-command-char '(?\s ?\n ?\t ?\f))
1878 (memq this-command '(self-insert-command newline))))
1879 my do)
1880 (and (save-excursion
1881 (condition-case nil
1882 (progn
1883 (backward-sexp 1)
1884 (setq do (looking-at "do\\>")))
1885 (error nil))
1886 (cperl-after-expr-p nil "{;:"))
1887 (save-excursion
1888 (not
1889 (re-search-backward
1890 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
1891 beg t)))
1892 (save-excursion (or (not (re-search-backward "^=" nil t))
1894 (looking-at "=cut")
1895 (and cperl-use-syntax-table-text-property
1896 (not (eq (get-text-property (point)
1897 'syntax-type)
1898 'pod))))))
1899 (save-excursion (forward-sexp -1)
1900 (not (memq (following-char) (append "$@%&*" nil))))
1901 (progn
1902 (and (eq (preceding-char) ?y)
1903 (progn ; "foreachmy"
1904 (forward-char -2)
1905 (insert " ")
1906 (forward-char 2)
1907 (setq my t dollar t
1908 delete
1909 (memq this-command '(self-insert-command newline)))))
1910 (and dollar (insert " $"))
1911 (cperl-indent-line)
1912 ;;(insert " () {\n}")
1913 (cond
1914 (cperl-extra-newline-before-brace
1915 (insert (if do "\n" " ()\n"))
1916 (insert "{")
1917 (cperl-indent-line)
1918 (insert "\n")
1919 (cperl-indent-line)
1920 (insert "\n}")
1921 (and do (insert " while ();")))
1923 (insert (if do " {\n} while ();" " () {\n}"))))
1924 (or (looking-at "[ \t]\\|$") (insert " "))
1925 (cperl-indent-line)
1926 (if dollar (progn (search-backward "$")
1927 (if my
1928 (forward-char 1)
1929 (delete-char 1)))
1930 (search-backward ")")
1931 (if (eq last-command-char ?\()
1932 (progn ; Avoid "if (())"
1933 (delete-backward-char 1)
1934 (delete-backward-char -1))))
1935 (if delete
1936 (cperl-putback-char cperl-del-back-ch))
1937 (if cperl-message-electric-keyword
1938 (message "Precede char by C-q to avoid expansion"))))))
1940 (defun cperl-ensure-newlines (n &optional pos)
1941 "Make sure there are N newlines after the point."
1942 (or pos (setq pos (point)))
1943 (if (looking-at "\n")
1944 (forward-char 1)
1945 (insert "\n"))
1946 (if (> n 1)
1947 (cperl-ensure-newlines (1- n) pos)
1948 (goto-char pos)))
1950 (defun cperl-electric-pod ()
1951 "Insert a POD chunk appropriate after a =POD directive."
1952 (let ((delete (and (memq last-command-char '(?\s ?\n ?\t ?\f))
1953 (memq this-command '(self-insert-command newline))))
1954 head1 notlast name p really-delete over)
1955 (and (save-excursion
1956 (forward-word -1)
1957 (and
1958 (eq (preceding-char) ?=)
1959 (progn
1960 (setq head1 (looking-at "head1\\>[ \t]*$"))
1961 (setq over (and (looking-at "over\\>[ \t]*$")
1962 (not (looking-at "over[ \t]*\n\n\n*=item\\>"))))
1963 (forward-char -1)
1964 (bolp))
1966 (get-text-property (point) 'in-pod)
1967 (cperl-after-expr-p nil "{;:")
1968 (and (re-search-backward
1969 ;; "\\(\\`\n?\\|\n\n\\)=\\sw+"
1970 "\\(\\`\n?\\|^\n\\)=\\sw+"
1971 (point-min) t)
1972 (not (or
1973 (looking-at "=cut")
1974 (and cperl-use-syntax-table-text-property
1975 (not (eq (get-text-property (point) 'syntax-type)
1976 'pod)))))))))
1977 (progn
1978 (save-excursion
1979 (setq notlast (re-search-forward "^\n=" nil t)))
1980 (or notlast
1981 (progn
1982 (insert "\n\n=cut")
1983 (cperl-ensure-newlines 2)
1984 (forward-word -2)
1985 (if (and head1
1986 (not
1987 (save-excursion
1988 (forward-char -1)
1989 (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>"
1990 nil t)))) ; Only one
1991 (progn
1992 (forward-word 1)
1993 (setq name (file-name-sans-extension
1994 (file-name-nondirectory (buffer-file-name)))
1995 p (point))
1996 (insert " NAME\n\n" name
1997 " - \n\n=head1 SYNOPSIS\n\n\n\n"
1998 "=head1 DESCRIPTION")
1999 (cperl-ensure-newlines 4)
2000 (goto-char p)
2001 (forward-word 2)
2002 (end-of-line)
2003 (setq really-delete t))
2004 (forward-word 1))))
2005 (if over
2006 (progn
2007 (setq p (point))
2008 (insert "\n\n=item \n\n\n\n"
2009 "=back")
2010 (cperl-ensure-newlines 2)
2011 (goto-char p)
2012 (forward-word 1)
2013 (end-of-line)
2014 (setq really-delete t)))
2015 (if (and delete really-delete)
2016 (cperl-putback-char cperl-del-back-ch))))))
2018 (defun cperl-electric-else ()
2019 "Insert a construction appropriate after a keyword.
2020 Help message may be switched off by setting `cperl-message-electric-keyword'
2021 to nil."
2022 (let ((beg (save-excursion (beginning-of-line) (point))))
2023 (and (save-excursion
2024 (backward-sexp 1)
2025 (cperl-after-expr-p nil "{;:"))
2026 (save-excursion
2027 (not
2028 (re-search-backward
2029 "[#\"'`]\\|\\<q\\(\\|[wqxr]\\)\\>"
2030 beg t)))
2031 (save-excursion (or (not (re-search-backward "^=" nil t))
2032 (looking-at "=cut")
2033 (and cperl-use-syntax-table-text-property
2034 (not (eq (get-text-property (point)
2035 'syntax-type)
2036 'pod)))))
2037 (progn
2038 (cperl-indent-line)
2039 ;;(insert " {\n\n}")
2040 (cond
2041 (cperl-extra-newline-before-brace
2042 (insert "\n")
2043 (insert "{")
2044 (cperl-indent-line)
2045 (insert "\n\n}"))
2047 (insert " {\n\n}")))
2048 (or (looking-at "[ \t]\\|$") (insert " "))
2049 (cperl-indent-line)
2050 (forward-line -1)
2051 (cperl-indent-line)
2052 (cperl-putback-char cperl-del-back-ch)
2053 (setq this-command 'cperl-electric-else)
2054 (if cperl-message-electric-keyword
2055 (message "Precede char by C-q to avoid expansion"))))))
2057 (defun cperl-linefeed ()
2058 "Go to end of line, open a new line and indent appropriately.
2059 If in POD, insert appropriate lines."
2060 (interactive)
2061 (let ((beg (save-excursion (beginning-of-line) (point)))
2062 (end (save-excursion (end-of-line) (point)))
2063 (pos (point)) start over cut res)
2064 (if (and ; Check if we need to split:
2065 ; i.e., on a boundary and inside "{...}"
2066 (save-excursion (cperl-to-comment-or-eol)
2067 (>= (point) pos)) ; Not in a comment
2068 (or (save-excursion
2069 (skip-chars-backward " \t" beg)
2070 (forward-char -1)
2071 (looking-at "[;{]")) ; After { or ; + spaces
2072 (looking-at "[ \t]*}") ; Before }
2073 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
2074 (save-excursion
2075 (and
2076 (eq (car (parse-partial-sexp pos end -1)) -1)
2077 ; Leave the level of parens
2078 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
2079 ; Are at end
2080 (cperl-after-block-p (point-min))
2081 (progn
2082 (backward-sexp 1)
2083 (setq start (point-marker))
2084 (<= start pos))))) ; Redundant? Are after the
2085 ; start of parens group.
2086 (progn
2087 (skip-chars-backward " \t")
2088 (or (memq (preceding-char) (append ";{" nil))
2089 (insert ";"))
2090 (insert "\n")
2091 (forward-line -1)
2092 (cperl-indent-line)
2093 (goto-char start)
2094 (or (looking-at "{[ \t]*$") ; If there is a statement
2095 ; before, move it to separate line
2096 (progn
2097 (forward-char 1)
2098 (insert "\n")
2099 (cperl-indent-line)))
2100 (forward-line 1) ; We are on the target line
2101 (cperl-indent-line)
2102 (beginning-of-line)
2103 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
2104 ; after, move it to separate line
2105 (progn
2106 (end-of-line)
2107 (search-backward "}" beg)
2108 (skip-chars-backward " \t")
2109 (or (memq (preceding-char) (append ";{" nil))
2110 (insert ";"))
2111 (insert "\n")
2112 (cperl-indent-line)
2113 (forward-line -1)))
2114 (forward-line -1) ; We are on the line before target
2115 (end-of-line)
2116 (newline-and-indent))
2117 (end-of-line) ; else - no splitting
2118 (cond
2119 ((and (looking-at "\n[ \t]*{$")
2120 (save-excursion
2121 (skip-chars-backward " \t")
2122 (eq (preceding-char) ?\)))) ; Probably if () {} group
2123 ; with an extra newline.
2124 (forward-line 2)
2125 (cperl-indent-line))
2126 ((save-excursion ; In POD header
2127 (forward-paragraph -1)
2128 ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b")
2129 ;; We are after \n now, so look for the rest
2130 (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+")
2131 (progn
2132 (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>"))
2133 (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>"))
2134 t)))
2135 (if (and over
2136 (progn
2137 (forward-paragraph -1)
2138 (forward-word 1)
2139 (setq pos (point))
2140 (setq cut (buffer-substring (point)
2141 (save-excursion
2142 (end-of-line)
2143 (point))))
2144 (delete-char (- (save-excursion (end-of-line) (point))
2145 (point)))
2146 (setq res (expand-abbrev))
2147 (save-excursion
2148 (goto-char pos)
2149 (insert cut))
2150 res))
2152 (cperl-ensure-newlines (if cut 2 4))
2153 (forward-line 2)))
2154 ((get-text-property (point) 'in-pod) ; In POD section
2155 (cperl-ensure-newlines 4)
2156 (forward-line 2))
2157 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
2158 (forward-line 1)
2159 (cperl-indent-line))
2161 (newline-and-indent))))))
2163 (defun cperl-electric-semi (arg)
2164 "Insert character and correct line's indentation."
2165 (interactive "P")
2166 (if cperl-auto-newline
2167 (cperl-electric-terminator arg)
2168 (self-insert-command (prefix-numeric-value arg))
2169 (if cperl-autoindent-on-semi
2170 (cperl-indent-line))))
2172 (defun cperl-electric-terminator (arg)
2173 "Insert character and correct line's indentation."
2174 (interactive "P")
2175 (let ((end (point))
2176 (auto (and cperl-auto-newline
2177 (or (not (eq last-command-char ?:))
2178 cperl-auto-newline-after-colon)))
2179 insertpos)
2180 (if (and ;;(not arg)
2181 (eolp)
2182 (not (save-excursion
2183 (beginning-of-line)
2184 (skip-chars-forward " \t")
2186 ;; Ignore in comment lines
2187 (= (following-char) ?#)
2188 ;; Colon is special only after a label
2189 ;; So quickly rule out most other uses of colon
2190 ;; and do no indentation for them.
2191 (and (eq last-command-char ?:)
2192 (save-excursion
2193 (forward-word 1)
2194 (skip-chars-forward " \t")
2195 (and (< (point) end)
2196 (progn (goto-char (- end 1))
2197 (not (looking-at ":"))))))
2198 (progn
2199 (beginning-of-defun)
2200 (let ((pps (parse-partial-sexp (point) end)))
2201 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
2202 (progn
2203 (self-insert-command (prefix-numeric-value arg))
2204 ;;(forward-char -1)
2205 (if auto (setq insertpos (point-marker)))
2206 ;;(forward-char 1)
2207 (cperl-indent-line)
2208 (if auto
2209 (progn
2210 (newline)
2211 (cperl-indent-line)))
2212 (save-excursion
2213 (if insertpos (goto-char (1- (marker-position insertpos)))
2214 (forward-char -1))
2215 (delete-char 1))))
2216 (if insertpos
2217 (save-excursion
2218 (goto-char insertpos)
2219 (self-insert-command (prefix-numeric-value arg)))
2220 (self-insert-command (prefix-numeric-value arg)))))
2222 (defun cperl-electric-backspace (arg)
2223 "Backspace, or remove the whitespace around the point inserted by an electric
2224 key. Will untabify if `cperl-electric-backspace-untabify' is non-nil."
2225 (interactive "p")
2226 (if (and cperl-auto-newline
2227 (memq last-command '(cperl-electric-semi
2228 cperl-electric-terminator
2229 cperl-electric-lbrace))
2230 (memq (preceding-char) '(?\s ?\t ?\n)))
2231 (let (p)
2232 (if (eq last-command 'cperl-electric-lbrace)
2233 (skip-chars-forward " \t\n"))
2234 (setq p (point))
2235 (skip-chars-backward " \t\n")
2236 (delete-region (point) p))
2237 (and (eq last-command 'cperl-electric-else)
2238 ;; We are removing the whitespace *inside* cperl-electric-else
2239 (setq this-command 'cperl-electric-else-really))
2240 (if (and cperl-auto-newline
2241 (eq last-command 'cperl-electric-else-really)
2242 (memq (preceding-char) '(?\s ?\t ?\n)))
2243 (let (p)
2244 (skip-chars-forward " \t\n")
2245 (setq p (point))
2246 (skip-chars-backward " \t\n")
2247 (delete-region (point) p))
2248 (if cperl-electric-backspace-untabify
2249 (backward-delete-char-untabify arg)
2250 (delete-backward-char arg)))))
2252 (put 'cperl-electric-backspace 'delete-selection 'supersede)
2254 (defun cperl-inside-parens-p ()
2255 (condition-case ()
2256 (save-excursion
2257 (save-restriction
2258 (narrow-to-region (point)
2259 (progn (beginning-of-defun) (point)))
2260 (goto-char (point-max))
2261 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
2262 (error nil)))
2264 (defun cperl-indent-command (&optional whole-exp)
2265 "Indent current line as Perl code, or in some cases insert a tab character.
2266 If `cperl-tab-always-indent' is non-nil (the default), always indent current
2267 line. Otherwise, indent the current line only if point is at the left margin
2268 or in the line's indentation; otherwise insert a tab.
2270 A numeric argument, regardless of its value,
2271 means indent rigidly all the lines of the expression starting after point
2272 so that this line becomes properly indented.
2273 The relative indentation among the lines of the expression are preserved."
2274 (interactive "P")
2275 (cperl-update-syntaxification (point) (point))
2276 (if whole-exp
2277 ;; If arg, always indent this line as Perl
2278 ;; and shift remaining lines of expression the same amount.
2279 (let ((shift-amt (cperl-indent-line))
2280 beg end)
2281 (save-excursion
2282 (if cperl-tab-always-indent
2283 (beginning-of-line))
2284 (setq beg (point))
2285 (forward-sexp 1)
2286 (setq end (point))
2287 (goto-char beg)
2288 (forward-line 1)
2289 (setq beg (point)))
2290 (if (and shift-amt (> end beg))
2291 (indent-code-rigidly beg end shift-amt "#")))
2292 (if (and (not cperl-tab-always-indent)
2293 (save-excursion
2294 (skip-chars-backward " \t")
2295 (not (bolp))))
2296 (insert-tab)
2297 (cperl-indent-line))))
2299 (defun cperl-indent-line (&optional parse-data)
2300 "Indent current line as Perl code.
2301 Return the amount the indentation changed by."
2302 (let ((case-fold-search nil)
2303 (pos (- (point-max) (point)))
2304 indent i beg shift-amt)
2305 (setq indent (cperl-calculate-indent parse-data)
2306 i indent)
2307 (beginning-of-line)
2308 (setq beg (point))
2309 (cond ((or (eq indent nil) (eq indent t))
2310 (setq indent (current-indentation) i nil))
2311 ;;((eq indent t) ; Never?
2312 ;; (setq indent (cperl-calculate-indent-within-comment)))
2313 ;;((looking-at "[ \t]*#")
2314 ;; (setq indent 0))
2316 (skip-chars-forward " \t")
2317 (if (listp indent) (setq indent (car indent)))
2318 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
2319 (and (> indent 0)
2320 (setq indent (max cperl-min-label-indent
2321 (+ indent cperl-label-offset)))))
2322 ((= (following-char) ?})
2323 (setq indent (- indent cperl-indent-level)))
2324 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
2325 (setq indent (+ indent cperl-close-paren-offset)))
2326 ((= (following-char) ?{)
2327 (setq indent (+ indent cperl-brace-offset))))))
2328 (skip-chars-forward " \t")
2329 (setq shift-amt (and i (- indent (current-column))))
2330 (if (or (not shift-amt)
2331 (zerop shift-amt))
2332 (if (> (- (point-max) pos) (point))
2333 (goto-char (- (point-max) pos)))
2334 (delete-region beg (point))
2335 (indent-to indent)
2336 ;; If initial point was within line's indentation,
2337 ;; position after the indentation. Else stay at same point in text.
2338 (if (> (- (point-max) pos) (point))
2339 (goto-char (- (point-max) pos))))
2340 shift-amt))
2342 (defun cperl-after-label ()
2343 ;; Returns true if the point is after label. Does not do save-excursion.
2344 (and (eq (preceding-char) ?:)
2345 (memq (char-syntax (char-after (- (point) 2)))
2346 '(?w ?_))
2347 (progn
2348 (backward-sexp)
2349 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
2351 (defun cperl-get-state (&optional parse-start start-state)
2352 ;; returns list (START STATE DEPTH PRESTART),
2353 ;; START is a good place to start parsing, or equal to
2354 ;; PARSE-START if preset,
2355 ;; STATE is what is returned by `parse-partial-sexp'.
2356 ;; DEPTH is true is we are immediately after end of block
2357 ;; which contains START.
2358 ;; PRESTART is the position basing on which START was found.
2359 (save-excursion
2360 (let ((start-point (point)) depth state start prestart)
2361 (if (and parse-start
2362 (<= parse-start start-point))
2363 (goto-char parse-start)
2364 (beginning-of-defun)
2365 (setq start-state nil))
2366 (setq prestart (point))
2367 (if start-state nil
2368 ;; Try to go out, if sub is not on the outermost level
2369 (while (< (point) start-point)
2370 (setq start (point) parse-start start depth nil
2371 state (parse-partial-sexp start start-point -1))
2372 (if (> (car state) -1) nil
2373 ;; The current line could start like }}}, so the indentation
2374 ;; corresponds to a different level than what we reached
2375 (setq depth t)
2376 (beginning-of-line 2))) ; Go to the next line.
2377 (if start (goto-char start))) ; Not at the start of file
2378 (setq start (point))
2379 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
2380 (list start state depth prestart))))
2382 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
2383 ;; Positions is before ?\{. Checks whether it starts a block.
2384 ;; No save-excursion!
2385 (cperl-backward-to-noncomment (point-min))
2386 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
2387 ; Label may be mixed up with `$blah :'
2388 (save-excursion (cperl-after-label))
2389 (and (memq (char-syntax (preceding-char)) '(?w ?_))
2390 (progn
2391 (backward-sexp)
2392 ;; Need take into account `bless', `return', `tr',...
2393 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
2394 (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
2395 (progn
2396 (skip-chars-backward " \t\n\f")
2397 (and (memq (char-syntax (preceding-char)) '(?w ?_))
2398 (progn
2399 (backward-sexp)
2400 (looking-at
2401 "sub[ \t]+[a-zA-Z0-9_:]+[ \t\n\f]*\\(([^()]*)[ \t\n\f]*\\)?[#{]")))))))))
2403 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
2405 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
2406 "Return appropriate indentation for current line as Perl code.
2407 In usual case returns an integer: the column to indent to.
2408 Returns nil if line starts inside a string, t if in a comment.
2410 Will not correct the indentation for labels, but will correct it for braces
2411 and closing parentheses and brackets."
2412 (cperl-update-syntaxification (point) (point))
2413 (save-excursion
2414 (if (or
2415 (and (memq (get-text-property (point) 'syntax-type)
2416 '(pod here-doc here-doc-delim format))
2417 (not (get-text-property (point) 'indentable)))
2418 ;; before start of POD - whitespace found since do not have 'pod!
2419 (and (looking-at "[ \t]*\n=")
2420 (error "Spaces before POD section!"))
2421 (and (not cperl-indent-left-aligned-comments)
2422 (looking-at "^#")))
2424 (beginning-of-line)
2425 (let ((indent-point (point))
2426 (char-after (save-excursion
2427 (skip-chars-forward " \t")
2428 (following-char)))
2429 (in-pod (get-text-property (point) 'in-pod))
2430 (pre-indent-point (point))
2431 p prop look-prop is-block delim)
2432 (cond
2433 (in-pod
2434 ;; In the verbatim part, probably code example. What to do???
2437 (save-excursion
2438 ;; Not in POD
2439 (cperl-backward-to-noncomment nil)
2440 (setq p (max (point-min) (1- (point)))
2441 prop (get-text-property p 'syntax-type)
2442 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
2443 'syntax-type))
2444 (if (memq prop '(pod here-doc format here-doc-delim))
2445 (progn
2446 (goto-char (or (previous-single-property-change p look-prop)
2447 (point-min)))
2448 (beginning-of-line)
2449 (setq pre-indent-point (point)))))))
2450 (goto-char pre-indent-point)
2451 (let* ((case-fold-search nil)
2452 (s-s (cperl-get-state (car parse-data) (nth 1 parse-data)))
2453 (start (or (nth 2 parse-data)
2454 (nth 0 s-s)))
2455 (state (nth 1 s-s))
2456 (containing-sexp (car (cdr state)))
2457 old-indent)
2458 (if (and
2459 ;;containing-sexp ;; We are buggy at toplevel :-(
2460 parse-data)
2461 (progn
2462 (setcar parse-data pre-indent-point)
2463 (setcar (cdr parse-data) state)
2464 (or (nth 2 parse-data)
2465 (setcar (cddr parse-data) start))
2466 ;; Before this point: end of statement
2467 (setq old-indent (nth 3 parse-data))))
2468 (cond ((get-text-property (point) 'indentable)
2469 ;; indent to just after the surrounding open,
2470 ;; skip blanks if we do not close the expression.
2471 (goto-char (1+ (previous-single-property-change (point) 'indentable)))
2472 (or (memq char-after (append ")]}" nil))
2473 (looking-at "[ \t]*\\(#\\|$\\)")
2474 (skip-chars-forward " \t"))
2475 (current-column))
2476 ((or (nth 3 state) (nth 4 state))
2477 ;; return nil or t if should not change this line
2478 (nth 4 state))
2479 ;; XXXX Do we need to special-case this?
2480 ((null containing-sexp)
2481 ;; Line is at top level. May be data or function definition,
2482 ;; or may be function argument declaration.
2483 ;; Indent like the previous top level line
2484 ;; unless that ends in a closeparen without semicolon,
2485 ;; in which case this line is the first argument decl.
2486 (skip-chars-forward " \t")
2487 (+ (save-excursion
2488 (goto-char start)
2489 (- (current-indentation)
2490 (if (nth 2 s-s) cperl-indent-level 0)))
2491 (if (= char-after ?{) cperl-continued-brace-offset 0)
2492 (progn
2493 (cperl-backward-to-noncomment (or old-indent (point-min)))
2494 ;; Look at previous line that's at column 0
2495 ;; to determine whether we are in top-level decls
2496 ;; or function's arg decls. Set basic-indent accordingly.
2497 ;; Now add a little if this is a continuation line.
2498 (if (or (bobp)
2499 (eq (point) old-indent) ; old-indent was at comment
2500 (eq (preceding-char) ?\;)
2501 ;; Had ?\) too
2502 (and (eq (preceding-char) ?\})
2503 (cperl-after-block-and-statement-beg
2504 (point-min))) ; Was start - too close
2505 (memq char-after (append ")]}" nil))
2506 (and (eq (preceding-char) ?\:) ; label
2507 (progn
2508 (forward-sexp -1)
2509 (skip-chars-backward " \t")
2510 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))
2511 (get-text-property (point) 'first-format-line))
2512 (progn
2513 (if (and parse-data
2514 (not (eq char-after ?\C-j)))
2515 (setcdr (cddr parse-data)
2516 (list pre-indent-point)))
2518 cperl-continued-statement-offset))))
2519 ((not
2520 (or (setq is-block
2521 (and (setq delim (= (char-after containing-sexp) ?{))
2522 (save-excursion ; Is it a hash?
2523 (goto-char containing-sexp)
2524 (cperl-block-p))))
2525 cperl-indent-parens-as-block))
2526 ;; group is an expression, not a block:
2527 ;; indent to just after the surrounding open parens,
2528 ;; skip blanks if we do not close the expression.
2529 (goto-char (1+ containing-sexp))
2530 (or (memq char-after
2531 (append (if delim "}" ")]}") nil))
2532 (looking-at "[ \t]*\\(#\\|$\\)")
2533 (skip-chars-forward " \t"))
2534 (+ (current-column)
2535 (if (and delim
2536 (eq char-after ?\}))
2537 ;; Correct indentation of trailing ?\}
2538 (+ cperl-indent-level cperl-close-paren-offset)
2539 0)))
2540 ;;; ((and (/= (char-after containing-sexp) ?{)
2541 ;;; (not cperl-indent-parens-as-block))
2542 ;;; ;; line is expression, not statement:
2543 ;;; ;; indent to just after the surrounding open,
2544 ;;; ;; skip blanks if we do not close the expression.
2545 ;;; (goto-char (1+ containing-sexp))
2546 ;;; (or (memq char-after (append ")]}" nil))
2547 ;;; (looking-at "[ \t]*\\(#\\|$\\)")
2548 ;;; (skip-chars-forward " \t"))
2549 ;;; (current-column))
2550 ;;; ((progn
2551 ;;; ;; Containing-expr starts with \{. Check whether it is a hash.
2552 ;;; (goto-char containing-sexp)
2553 ;;; (and (not (cperl-block-p))
2554 ;;; (not cperl-indent-parens-as-block)))
2555 ;;; (goto-char (1+ containing-sexp))
2556 ;;; (or (eq char-after ?\})
2557 ;;; (looking-at "[ \t]*\\(#\\|$\\)")
2558 ;;; (skip-chars-forward " \t"))
2559 ;;; (+ (current-column) ; Correct indentation of trailing ?\}
2560 ;;; (if (eq char-after ?\}) (+ cperl-indent-level
2561 ;;; cperl-close-paren-offset)
2562 ;;; 0)))
2564 ;; Statement level. Is it a continuation or a new statement?
2565 ;; Find previous non-comment character.
2566 (goto-char pre-indent-point)
2567 (cperl-backward-to-noncomment containing-sexp)
2568 ;; Back up over label lines, since they don't
2569 ;; affect whether our line is a continuation.
2570 ;; (Had \, too)
2571 (while ;;(or (eq (preceding-char) ?\,)
2572 (and (eq (preceding-char) ?:)
2573 (or ;;(eq (char-after (- (point) 2)) ?\') ; ????
2574 (memq (char-syntax (char-after (- (point) 2)))
2575 '(?w ?_))))
2577 (if (eq (preceding-char) ?\,)
2578 ;; Will go to beginning of line, essentially.
2579 ;; Will ignore embedded sexpr XXXX.
2580 (cperl-backward-to-start-of-continued-exp containing-sexp))
2581 (beginning-of-line)
2582 (cperl-backward-to-noncomment containing-sexp))
2583 ;; Now we get the answer.
2584 (if (not (or (eq (1- (point)) containing-sexp)
2585 (memq (preceding-char)
2586 (append (if is-block " ;{" " ,;{") '(nil)))
2587 (and (eq (preceding-char) ?\})
2588 (cperl-after-block-and-statement-beg
2589 containing-sexp))
2590 (get-text-property (point) 'first-format-line)))
2591 ;; This line is continuation of preceding line's statement;
2592 ;; indent `cperl-continued-statement-offset' more than the
2593 ;; previous line of the statement.
2595 ;; There might be a label on this line, just
2596 ;; consider it bad style and ignore it.
2597 (progn
2598 (cperl-backward-to-start-of-continued-exp containing-sexp)
2599 (+ (if (memq char-after (append "}])" nil))
2600 0 ; Closing parenth
2601 cperl-continued-statement-offset)
2602 (if (or is-block
2603 (not delim)
2604 (not (eq char-after ?\})))
2606 ;; Now it is a hash reference
2607 (+ cperl-indent-level cperl-close-paren-offset))
2608 (if (looking-at "\\w+[ \t]*:")
2609 (if (> (current-indentation) cperl-min-label-indent)
2610 (- (current-indentation) cperl-label-offset)
2611 ;; Do not move `parse-data', this should
2612 ;; be quick anyway (this comment comes
2613 ;; from different location):
2614 (cperl-calculate-indent))
2615 (current-column))
2616 (if (eq char-after ?\{)
2617 cperl-continued-brace-offset 0)))
2618 ;; This line starts a new statement.
2619 ;; Position following last unclosed open.
2620 (goto-char containing-sexp)
2621 ;; Is line first statement after an open-brace?
2623 ;; If no, find that first statement and indent like
2624 ;; it. If the first statement begins with label, do
2625 ;; not believe when the indentation of the label is too
2626 ;; small.
2627 (save-excursion
2628 (forward-char 1)
2629 (setq old-indent (current-indentation))
2630 (let ((colon-line-end 0))
2631 (while
2632 (progn (skip-chars-forward " \t\n")
2633 (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]\\|=[a-zA-Z]"))
2634 ;; Skip over comments and labels following openbrace.
2635 (cond ((= (following-char) ?\#)
2636 (forward-line 1))
2637 ((= (following-char) ?\=)
2638 (goto-char
2639 (or (next-single-property-change (point) 'in-pod)
2640 (point-max)))) ; do not loop if no syntaxification
2641 ;; label:
2643 (save-excursion (end-of-line)
2644 (setq colon-line-end (point)))
2645 (search-forward ":"))))
2646 ;; The first following code counts
2647 ;; if it is before the line we want to indent.
2648 (and (< (point) indent-point)
2649 (if (> colon-line-end (point)) ; After label
2650 (if (> (current-indentation)
2651 cperl-min-label-indent)
2652 (- (current-indentation) cperl-label-offset)
2653 ;; Do not believe: `max' is involved
2654 (+ old-indent cperl-indent-level))
2655 (current-column)))))
2656 ;; If no previous statement,
2657 ;; indent it relative to line brace is on.
2658 ;; For open brace in column zero, don't let statement
2659 ;; start there too. If cperl-indent-level is zero,
2660 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
2661 ;; For open-braces not the first thing in a line,
2662 ;; add in cperl-brace-imaginary-offset.
2664 ;; If first thing on a line: ?????
2665 (+ (if (and (bolp) (zerop cperl-indent-level))
2666 (+ cperl-brace-offset cperl-continued-statement-offset)
2667 cperl-indent-level)
2668 (if (or is-block
2669 (not delim)
2670 (not (eq char-after ?\})))
2672 ;; Now it is a hash reference
2673 (+ cperl-indent-level cperl-close-paren-offset))
2674 ;; Move back over whitespace before the openbrace.
2675 ;; If openbrace is not first nonwhite thing on the line,
2676 ;; add the cperl-brace-imaginary-offset.
2677 (progn (skip-chars-backward " \t")
2678 (if (bolp) 0 cperl-brace-imaginary-offset))
2679 ;; If the openbrace is preceded by a parenthesized exp,
2680 ;; move to the beginning of that;
2681 ;; possibly a different line
2682 (progn
2683 (if (eq (preceding-char) ?\))
2684 (forward-sexp -1))
2685 ;; In the case it starts a subroutine, indent with
2686 ;; respect to `sub', not with respect to the
2687 ;; first thing on the line, say in the case of
2688 ;; anonymous sub in a hash.
2690 (skip-chars-backward " \t")
2691 (if (and (eq (preceding-char) ?b)
2692 (progn
2693 (forward-sexp -1)
2694 (looking-at "sub\\>"))
2695 (setq old-indent
2696 (nth 1
2697 (parse-partial-sexp
2698 (save-excursion (beginning-of-line) (point))
2699 (point)))))
2700 (progn (goto-char (1+ old-indent))
2701 (skip-chars-forward " \t")
2702 (current-column))
2703 ;; Get initial indentation of the line we are on.
2704 ;; If line starts with label, calculate label indentation
2705 (if (save-excursion
2706 (beginning-of-line)
2707 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
2708 (if (> (current-indentation) cperl-min-label-indent)
2709 (- (current-indentation) cperl-label-offset)
2710 ;; Do not move `parse-data', this should
2711 ;; be quick anyway:
2712 (cperl-calculate-indent))
2713 (current-indentation))))))))))))))
2715 ;; (defvar cperl-indent-alist
2716 ;; '((string nil)
2717 ;; (comment nil)
2718 ;; (toplevel 0)
2719 ;; (toplevel-after-parenth 2)
2720 ;; (toplevel-continued 2)
2721 ;; (expression 1))
2722 ;; "Alist of indentation rules for CPerl mode.
2723 ;; The values mean:
2724 ;; nil: do not indent;
2725 ;; number: add this amount of indentation.
2727 ;; Not finished, not used.")
2729 ;; (defun cperl-where-am-i (&optional parse-start start-state)
2730 ;; ;; Unfinished
2731 ;; "Return a list of lists ((TYPE POS)...) of good points before the point.
2732 ;; ;; POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'.
2734 ;; ;; Not finished, not used."
2735 ;; (save-excursion
2736 ;; (let* ((start-point (point))
2737 ;; (s-s (cperl-get-state))
2738 ;; (start (nth 0 s-s))
2739 ;; (state (nth 1 s-s))
2740 ;; (prestart (nth 3 s-s))
2741 ;; (containing-sexp (car (cdr state)))
2742 ;; (case-fold-search nil)
2743 ;; (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
2744 ;; (cond ((nth 3 state) ; In string
2745 ;; (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
2746 ;; ((nth 4 state) ; In comment
2747 ;; (setq res (cons '(comment) res)))
2748 ;; ((null containing-sexp)
2749 ;; ;; Line is at top level.
2750 ;; ;; Indent like the previous top level line
2751 ;; ;; unless that ends in a closeparen without semicolon,
2752 ;; ;; in which case this line is the first argument decl.
2753 ;; (cperl-backward-to-noncomment (or parse-start (point-min)))
2754 ;; ;;(skip-chars-backward " \t\f\n")
2755 ;; (cond
2756 ;; ((or (bobp)
2757 ;; (memq (preceding-char) (append ";}" nil)))
2758 ;; (setq res (cons (list 'toplevel start) res)))
2759 ;; ((eq (preceding-char) ?\) )
2760 ;; (setq res (cons (list 'toplevel-after-parenth start) res)))
2761 ;; (t
2762 ;; (setq res (cons (list 'toplevel-continued start) res)))))
2763 ;; ((/= (char-after containing-sexp) ?{)
2764 ;; ;; line is expression, not statement:
2765 ;; ;; indent to just after the surrounding open.
2766 ;; ;; skip blanks if we do not close the expression.
2767 ;; (setq res (cons (list 'expression-blanks
2768 ;; (progn
2769 ;; (goto-char (1+ containing-sexp))
2770 ;; (or (looking-at "[ \t]*\\(#\\|$\\)")
2771 ;; (skip-chars-forward " \t"))
2772 ;; (point)))
2773 ;; (cons (list 'expression containing-sexp) res))))
2774 ;; ((progn
2775 ;; ;; Containing-expr starts with \{. Check whether it is a hash.
2776 ;; (goto-char containing-sexp)
2777 ;; (not (cperl-block-p)))
2778 ;; (setq res (cons (list 'expression-blanks
2779 ;; (progn
2780 ;; (goto-char (1+ containing-sexp))
2781 ;; (or (looking-at "[ \t]*\\(#\\|$\\)")
2782 ;; (skip-chars-forward " \t"))
2783 ;; (point)))
2784 ;; (cons (list 'expression containing-sexp) res))))
2785 ;; (t
2786 ;; ;; Statement level.
2787 ;; (setq res (cons (list 'in-block containing-sexp) res))
2788 ;; ;; Is it a continuation or a new statement?
2789 ;; ;; Find previous non-comment character.
2790 ;; (cperl-backward-to-noncomment containing-sexp)
2791 ;; ;; Back up over label lines, since they don't
2792 ;; ;; affect whether our line is a continuation.
2793 ;; ;; Back up comma-delimited lines too ?????
2794 ;; (while (or (eq (preceding-char) ?\,)
2795 ;; (save-excursion (cperl-after-label)))
2796 ;; (if (eq (preceding-char) ?\,)
2797 ;; ;; Will go to beginning of line, essentially
2798 ;; ;; Will ignore embedded sexpr XXXX.
2799 ;; (cperl-backward-to-start-of-continued-exp containing-sexp))
2800 ;; (beginning-of-line)
2801 ;; (cperl-backward-to-noncomment containing-sexp))
2802 ;; ;; Now we get the answer.
2803 ;; (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
2804 ;; ;; This line is continuation of preceding line's statement.
2805 ;; (list (list 'statement-continued containing-sexp))
2806 ;; ;; This line starts a new statement.
2807 ;; ;; Position following last unclosed open.
2808 ;; (goto-char containing-sexp)
2809 ;; ;; Is line first statement after an open-brace?
2810 ;; (or
2811 ;; ;; If no, find that first statement and indent like
2812 ;; ;; it. If the first statement begins with label, do
2813 ;; ;; not believe when the indentation of the label is too
2814 ;; ;; small.
2815 ;; (save-excursion
2816 ;; (forward-char 1)
2817 ;; (let ((colon-line-end 0))
2818 ;; (while (progn (skip-chars-forward " \t\n" start-point)
2819 ;; (and (< (point) start-point)
2820 ;; (looking-at
2821 ;; "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
2822 ;; ;; Skip over comments and labels following openbrace.
2823 ;; (cond ((= (following-char) ?\#)
2824 ;; ;;(forward-line 1)
2825 ;; (end-of-line))
2826 ;; ;; label:
2827 ;; (t
2828 ;; (save-excursion (end-of-line)
2829 ;; (setq colon-line-end (point)))
2830 ;; (search-forward ":"))))
2831 ;; ;; Now at the point, after label, or at start
2832 ;; ;; of first statement in the block.
2833 ;; (and (< (point) start-point)
2834 ;; (if (> colon-line-end (point))
2835 ;; ;; Before statement after label
2836 ;; (if (> (current-indentation)
2837 ;; cperl-min-label-indent)
2838 ;; (list (list 'label-in-block (point)))
2839 ;; ;; Do not believe: `max' is involved
2840 ;; (list
2841 ;; (list 'label-in-block-min-indent (point))))
2842 ;; ;; Before statement
2843 ;; (list 'statement-in-block (point))))))
2844 ;; ;; If no previous statement,
2845 ;; ;; indent it relative to line brace is on.
2846 ;; ;; For open brace in column zero, don't let statement
2847 ;; ;; start there too. If cperl-indent-level is zero,
2848 ;; ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
2849 ;; ;; For open-braces not the first thing in a line,
2850 ;; ;; add in cperl-brace-imaginary-offset.
2852 ;; ;; If first thing on a line: ?????
2853 ;; (+ (if (and (bolp) (zerop cperl-indent-level))
2854 ;; (+ cperl-brace-offset cperl-continued-statement-offset)
2855 ;; cperl-indent-level)
2856 ;; ;; Move back over whitespace before the openbrace.
2857 ;; ;; If openbrace is not first nonwhite thing on the line,
2858 ;; ;; add the cperl-brace-imaginary-offset.
2859 ;; (progn (skip-chars-backward " \t")
2860 ;; (if (bolp) 0 cperl-brace-imaginary-offset))
2861 ;; ;; If the openbrace is preceded by a parenthesized exp,
2862 ;; ;; move to the beginning of that;
2863 ;; ;; possibly a different line
2864 ;; (progn
2865 ;; (if (eq (preceding-char) ?\))
2866 ;; (forward-sexp -1))
2867 ;; ;; Get initial indentation of the line we are on.
2868 ;; ;; If line starts with label, calculate label indentation
2869 ;; (if (save-excursion
2870 ;; (beginning-of-line)
2871 ;; (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
2872 ;; (if (> (current-indentation) cperl-min-label-indent)
2873 ;; (- (current-indentation) cperl-label-offset)
2874 ;; (cperl-calculate-indent))
2875 ;; (current-indentation))))))))
2876 ;; res)))
2878 (defun cperl-calculate-indent-within-comment ()
2879 "Return the indentation amount for line, assuming that
2880 the current line is to be regarded as part of a block comment."
2881 (let (end star-start)
2882 (save-excursion
2883 (beginning-of-line)
2884 (skip-chars-forward " \t")
2885 (setq end (point))
2886 (and (= (following-char) ?#)
2887 (forward-line -1)
2888 (cperl-to-comment-or-eol)
2889 (setq end (point)))
2890 (goto-char end)
2891 (current-column))))
2894 (defun cperl-to-comment-or-eol ()
2895 "Go to position before comment on the current line, or to end of line.
2896 Returns true if comment is found."
2897 (let (state stop-in cpoint (lim (progn (end-of-line) (point))))
2898 (beginning-of-line)
2899 (if (or
2900 (eq (get-text-property (point) 'syntax-type) 'pod)
2901 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t))
2902 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
2903 ;; Else
2904 (while (not stop-in)
2905 (setq state (parse-partial-sexp (point) lim nil nil nil t))
2906 ; stop at comment
2907 ;; If fails (beginning-of-line inside sexp), then contains not-comment
2908 (if (nth 4 state) ; After `#';
2909 ; (nth 2 state) can be
2910 ; beginning of m,s,qq and so
2911 ; on
2912 (if (nth 2 state)
2913 (progn
2914 (setq cpoint (point))
2915 (goto-char (nth 2 state))
2916 (cond
2917 ((looking-at "\\(s\\|tr\\)\\>")
2918 (or (re-search-forward
2919 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
2920 lim 'move)
2921 (setq stop-in t)))
2922 ((looking-at "\\(m\\|q\\([qxwr]\\)?\\)\\>")
2923 (or (re-search-forward
2924 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
2925 lim 'move)
2926 (setq stop-in t)))
2927 (t ; It was fair comment
2928 (setq stop-in t) ; Finish
2929 (goto-char (1- cpoint)))))
2930 (setq stop-in t) ; Finish
2931 (forward-char -1))
2932 (setq stop-in t))) ; Finish
2933 (nth 4 state))))
2935 (defsubst cperl-1- (p)
2936 (max (point-min) (1- p)))
2938 (defsubst cperl-1+ (p)
2939 (min (point-max) (1+ p)))
2941 (defsubst cperl-modify-syntax-type (at how)
2942 (if (< at (point-max))
2943 (progn
2944 (put-text-property at (1+ at) 'syntax-table how)
2945 (put-text-property at (1+ at) 'rear-nonsticky t))))
2947 (defun cperl-protect-defun-start (s e)
2948 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
2949 (save-excursion
2950 (goto-char s)
2951 (while (re-search-forward "^\\s(" e 'to-end)
2952 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
2954 (defun cperl-commentify (bb e string &optional noface)
2955 (if cperl-use-syntax-table-text-property
2956 (if (eq noface 'n) ; Only immediate
2958 ;; We suppose that e is _after_ the end of construction, as after eol.
2959 (setq string (if string cperl-st-sfence cperl-st-cfence))
2960 (if (> bb (- e 2))
2961 ;; one-char string/comment?!
2962 (cperl-modify-syntax-type bb cperl-st-punct)
2963 (cperl-modify-syntax-type bb string)
2964 (cperl-modify-syntax-type (1- e) string))
2965 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
2966 (put-text-property (1+ bb) (1- e)
2967 'syntax-table cperl-string-syntax-table))
2968 (cperl-protect-defun-start bb e))
2969 ;; Fontify
2970 (or noface
2971 (not cperl-pod-here-fontify)
2972 (put-text-property bb e 'face (if string 'font-lock-string-face
2973 'font-lock-comment-face)))))
2975 (defvar cperl-starters '(( ?\( . ?\) )
2976 ( ?\[ . ?\] )
2977 ( ?\{ . ?\} )
2978 ( ?\< . ?\> )))
2980 (defun cperl-forward-re (lim end is-2arg set-st st-l err-l argument
2981 &optional ostart oend)
2982 ;; Works *before* syntax recognition is done
2983 ;; May modify syntax-type text property if the situation is too hard
2984 (let (b starter ender st i i2 go-forward reset-st)
2985 (skip-chars-forward " \t")
2986 ;; ender means matching-char matcher.
2987 (setq b (point)
2988 starter (if (eobp) 0 (char-after b))
2989 ender (cdr (assoc starter cperl-starters)))
2990 ;; What if starter == ?\\ ????
2991 (if set-st
2992 (if (car st-l)
2993 (setq st (car st-l))
2994 (setcar st-l (make-syntax-table))
2995 (setq i 0 st (car st-l))
2996 (while (< i 256)
2997 (modify-syntax-entry i "." st)
2998 (setq i (1+ i)))
2999 (modify-syntax-entry ?\\ "\\" st)))
3000 (setq set-st t)
3001 ;; Whether we have an intermediate point
3002 (setq i nil)
3003 ;; Prepare the syntax table:
3004 (and set-st
3005 (if (not ender) ; m/blah/, s/x//, s/x/y/
3006 (modify-syntax-entry starter "$" st)
3007 (modify-syntax-entry starter (concat "(" (list ender)) st)
3008 (modify-syntax-entry ender (concat ")" (list starter)) st)))
3009 (condition-case bb
3010 (progn
3011 ;; We use `$' syntax class to find matching stuff, but $$
3012 ;; is recognized the same as $, so we need to check this manually.
3013 (if (and (eq starter (char-after (cperl-1+ b)))
3014 (not ender))
3015 ;; $ has TeXish matching rules, so $$ equiv $...
3016 (forward-char 2)
3017 (setq reset-st (syntax-table))
3018 (set-syntax-table st)
3019 (forward-sexp 1)
3020 (if (<= (point) (1+ b))
3021 (error "Unfinished regular expression"))
3022 (set-syntax-table reset-st)
3023 (setq reset-st nil)
3024 ;; Now the problem is with m;blah;;
3025 (and (not ender)
3026 (eq (preceding-char)
3027 (char-after (- (point) 2)))
3028 (save-excursion
3029 (forward-char -2)
3030 (= 0 (% (skip-chars-backward "\\\\") 2)))
3031 (forward-char -1)))
3032 ;; Now we are after the first part.
3033 (and is-2arg ; Have trailing part
3034 (not ender)
3035 (eq (following-char) starter) ; Empty trailing part
3036 (progn
3037 (or (eq (char-syntax (following-char)) ?.)
3038 ;; Make trailing letter into punctuation
3039 (cperl-modify-syntax-type (point) cperl-st-punct))
3040 (setq is-2arg nil go-forward t))) ; Ignore the tail
3041 (if is-2arg ; Not number => have second part
3042 (progn
3043 (setq i (point) i2 i)
3044 (if ender
3045 (if (memq (following-char) '(?\s ?\t ?\n ?\f))
3046 (progn
3047 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3048 (goto-char (match-end 0))
3049 (skip-chars-forward " \t\n\f"))
3050 (setq i2 (point))))
3051 (forward-char -1))
3052 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3053 (if ender (modify-syntax-entry ender "." st))
3054 (setq set-st nil)
3055 (setq ender (cperl-forward-re lim end nil t st-l err-l
3056 argument starter ender)
3057 ender (nth 2 ender)))))
3058 (error (goto-char lim)
3059 (setq set-st nil)
3060 (if reset-st
3061 (set-syntax-table reset-st))
3062 (or end
3063 (message
3064 "End of `%s%s%c ... %c' string/RE not found: %s"
3065 argument
3066 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
3067 starter (or ender starter) bb)
3068 (or (car err-l) (setcar err-l b)))))
3069 (if set-st
3070 (progn
3071 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
3072 (if ender (modify-syntax-entry ender "." st))))
3073 ;; i: have 2 args, after end of the first arg
3074 ;; i2: start of the second arg, if any (before delim iff `ender').
3075 ;; ender: the last arg bounded by parens-like chars, the second one of them
3076 ;; starter: the starting delimiter of the first arg
3077 ;; go-forward: has 2 args, and the second part is empty
3078 (list i i2 ender starter go-forward)))
3080 (defvar font-lock-string-face)
3081 ;;(defvar font-lock-reference-face)
3082 (defvar font-lock-constant-face)
3083 (defsubst cperl-postpone-fontification (b e type val &optional now)
3084 ;; Do after syntactic fontification?
3085 (if cperl-syntaxify-by-font-lock
3086 (or now (put-text-property b e 'cperl-postpone (cons type val)))
3087 (put-text-property b e type val)))
3089 ;;; Here is how the global structures (those which cannot be
3090 ;;; recognized locally) are marked:
3091 ;; a) PODs:
3092 ;; Start-to-end is marked `in-pod' ==> t
3093 ;; Each non-literal part is marked `syntax-type' ==> `pod'
3094 ;; Each literal part is marked `syntax-type' ==> `in-pod'
3095 ;; b) HEREs:
3096 ;; Start-to-end is marked `here-doc-group' ==> t
3097 ;; The body is marked `syntax-type' ==> `here-doc'
3098 ;; The delimiter is marked `syntax-type' ==> `here-doc-delim'
3099 ;; c) FORMATs:
3100 ;; First line (to =) marked `first-format-line' ==> t
3101 ;; After-this--to-end is marked `syntax-type' ==> `format'
3102 ;; d) 'Q'uoted string:
3103 ;; part between markers inclusive is marked `syntax-type' ==> `string'
3104 ;; part between `q' and the first marker is marked `syntax-type' ==> `prestring'
3106 (defun cperl-unwind-to-safe (before &optional end)
3107 ;; if BEFORE, go to the previous start-of-line on each step of unwinding
3108 (let ((pos (point)) opos)
3109 (setq opos pos)
3110 (while (and pos (get-text-property pos 'syntax-type))
3111 (setq pos (previous-single-property-change pos 'syntax-type))
3112 (if pos
3113 (if before
3114 (progn
3115 (goto-char (cperl-1- pos))
3116 (beginning-of-line)
3117 (setq pos (point)))
3118 (goto-char (setq pos (cperl-1- pos))))
3119 ;; Up to the start
3120 (goto-char (point-min))))
3121 ;; Skip empty lines
3122 (and (looking-at "\n*=")
3123 (/= 0 (skip-chars-backward "\n"))
3124 (forward-char))
3125 (setq pos (point))
3126 (if end
3127 ;; Do the same for end, going small steps
3128 (progn
3129 (while (and end (get-text-property end 'syntax-type))
3130 (setq pos end
3131 end (next-single-property-change end 'syntax-type)))
3132 (or end pos)))))
3134 (defvar cperl-nonoverridable-face)
3135 (defvar font-lock-function-name-face)
3136 (defvar font-lock-comment-face)
3138 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max)
3139 "Scans the buffer for hard-to-parse Perl constructions.
3140 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
3141 the sections using `cperl-pod-head-face', `cperl-pod-face',
3142 `cperl-here-face'."
3143 (interactive)
3144 (or min (setq min (point-min)
3145 cperl-syntax-state nil
3146 cperl-syntax-done-to min))
3147 (or max (setq max (point-max)))
3148 (let* ((cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go tmpend
3149 face head-face here-face b e bb tag qtag b1 e1 argument i c tail tb
3150 is-REx is-x-REx REx-comment-start REx-comment-end was-comment i2
3151 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
3152 (modified (buffer-modified-p))
3153 (after-change-functions nil)
3154 (use-syntax-state (and cperl-syntax-state
3155 (>= min (car cperl-syntax-state))))
3156 (state-point (if use-syntax-state
3157 (car cperl-syntax-state)
3158 (point-min)))
3159 (state (if use-syntax-state
3160 (cdr cperl-syntax-state)))
3161 ;; (st-l '(nil)) (err-l '(nil)) ; Would overwrite - propagates from a function call to a function call!
3162 (st-l (list nil)) (err-l (list nil))
3163 ;; Somehow font-lock may be not loaded yet...
3164 (font-lock-string-face (if (boundp 'font-lock-string-face)
3165 font-lock-string-face
3166 'font-lock-string-face))
3167 (font-lock-constant-face (if (boundp 'font-lock-constant-face)
3168 font-lock-constant-face
3169 'font-lock-constant-face))
3170 (font-lock-function-name-face
3171 (if (boundp 'font-lock-function-name-face)
3172 font-lock-function-name-face
3173 'font-lock-function-name-face))
3174 (font-lock-comment-face
3175 (if (boundp 'font-lock-comment-face)
3176 font-lock-comment-face
3177 'font-lock-comment-face))
3178 (cperl-nonoverridable-face
3179 (if (boundp 'cperl-nonoverridable-face)
3180 cperl-nonoverridable-face
3181 'cperl-nonoverridable))
3182 (stop-point (if ignore-max
3183 (point-max)
3184 max))
3185 (search
3186 (concat
3187 "\\(\\`\n?\\|^\n\\)="
3188 "\\|"
3189 ;; One extra () before this:
3190 "<<"
3191 "\\(" ; 1 + 1
3192 ;; First variant "BLAH" or just ``.
3193 "[ \t]*" ; Yes, whitespace is allowed!
3194 "\\([\"'`]\\)" ; 2 + 1 = 3
3195 "\\([^\"'`\n]*\\)" ; 3 + 1
3196 "\\3"
3197 "\\|"
3198 ;; Second variant: Identifier or \ID (same as 'ID') or empty
3199 "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3200 ;; Do not have <<= or << 30 or <<30 or << $blah.
3201 ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3202 "\\(\\)" ; To preserve count of pars :-( 6 + 1
3203 "\\)"
3204 "\\|"
3205 ;; 1+6 extra () before this:
3206 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
3207 (if cperl-use-syntax-table-text-property
3208 (concat
3209 "\\|"
3210 ;; 1+6+2=9 extra () before this:
3211 "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
3212 "\\|"
3213 ;; 1+6+2+1=10 extra () before this:
3214 "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3215 "\\|"
3216 ;; 1+6+2+1+1=11 extra () before this:
3217 "\\<sub\\>[ \t]*\\([a-zA-Z_:'0-9]+[ \t]*\\)?\\(([^()]*)\\)"
3218 "\\|"
3219 ;; 1+6+2+1+1+2=13 extra () before this:
3220 "\\$\\(['{]\\)"
3221 "\\|"
3222 ;; 1+6+2+1+1+2+1=14 extra () before this:
3223 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
3224 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
3225 "\\|"
3226 "__\\(END\\|DATA\\)__"
3227 ;; 1+6+2+1+1+2+1+1+1=16 extra () before this:
3228 "\\|"
3229 "\\\\\\(['`\"($]\\)")
3230 ""))))
3231 (unwind-protect
3232 (progn
3233 (save-excursion
3234 (or non-inter
3235 (message "Scanning for \"hard\" Perl constructions..."))
3236 (and cperl-pod-here-fontify
3237 ;; We had evals here, do not know why...
3238 (setq face cperl-pod-face
3239 head-face cperl-pod-head-face
3240 here-face cperl-here-face))
3241 (remove-text-properties min max
3242 '(syntax-type t in-pod t syntax-table t
3243 cperl-postpone t
3244 syntax-subtype t
3245 rear-nonsticky t
3246 here-doc-group t
3247 first-format-line t
3248 indentable t))
3249 ;; Need to remove face as well...
3250 (goto-char min)
3251 (and (eq system-type 'emx)
3252 (looking-at "extproc[ \t]") ; Analogue of #!
3253 (cperl-commentify min
3254 (save-excursion (end-of-line) (point))
3255 nil))
3256 (while (and
3257 (< (point) max)
3258 (re-search-forward search max t))
3259 (setq tmpend nil) ; Valid for most cases
3260 (cond
3261 ((match-beginning 1) ; POD section
3262 ;; "\\(\\`\n?\\|^\n\\)="
3263 (if (looking-at "cut\\>")
3264 (if ignore-max
3265 nil ; Doing a chunk only
3266 (message "=cut is not preceded by a POD section")
3267 (or (car err-l) (setcar err-l (point))))
3268 (beginning-of-line)
3270 (setq b (point)
3271 bb b
3272 tb (match-beginning 0)
3273 b1 nil) ; error condition
3274 ;; We do not search to max, since we may be called from
3275 ;; some hook of fontification, and max is random
3276 (or (re-search-forward "^\n=cut\\>" stop-point 'toend)
3277 (progn
3278 (goto-char b)
3279 (if (re-search-forward "\n=cut\\>" stop-point 'toend)
3280 (progn
3281 (message "=cut is not preceded by an empty line")
3282 (setq b1 t)
3283 (or (car err-l) (setcar err-l b))))))
3284 (beginning-of-line 2) ; An empty line after =cut is not POD!
3285 (setq e (point))
3286 (and (> e max)
3287 (progn
3288 (remove-text-properties
3289 max e '(syntax-type t in-pod t syntax-table t
3290 cperl-postpone t
3291 syntax-subtype t
3292 here-doc-group t
3293 rear-nonsticky t
3294 first-format-line t
3295 indentable t))
3296 (setq tmpend tb)))
3297 (put-text-property b e 'in-pod t)
3298 (put-text-property b e 'syntax-type 'in-pod)
3299 (goto-char b)
3300 (while (re-search-forward "\n\n[ \t]" e t)
3301 ;; We start 'pod 1 char earlier to include the preceding line
3302 (beginning-of-line)
3303 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
3304 (cperl-put-do-not-fontify b (point) t)
3305 ;; mark the non-literal parts as PODs
3306 (if cperl-pod-here-fontify
3307 (cperl-postpone-fontification b (point) 'face face t))
3308 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
3309 (beginning-of-line)
3310 (setq b (point)))
3311 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
3312 (cperl-put-do-not-fontify (point) e t)
3313 (if cperl-pod-here-fontify
3314 (progn
3315 ;; mark the non-literal parts as PODs
3316 (cperl-postpone-fontification (point) e 'face face t)
3317 (goto-char bb)
3318 (if (looking-at
3319 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
3320 ;; mark the headers
3321 (cperl-postpone-fontification
3322 (match-beginning 1) (match-end 1)
3323 'face head-face))
3324 (while (re-search-forward
3325 ;; One paragraph
3326 "^\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
3327 e 'toend)
3328 ;; mark the headers
3329 (cperl-postpone-fontification
3330 (match-beginning 1) (match-end 1)
3331 'face head-face))))
3332 (cperl-commentify bb e nil)
3333 (goto-char e)
3334 (or (eq e (point-max))
3335 (forward-char -1)))) ; Prepare for immediate POD start.
3336 ;; Here document
3337 ;; We do only one here-per-line
3338 ;; ;; One extra () before this:
3339 ;;"<<"
3340 ;; "\\(" ; 1 + 1
3341 ;; ;; First variant "BLAH" or just ``.
3342 ;; "[ \t]*" ; Yes, whitespace is allowed!
3343 ;; "\\([\"'`]\\)" ; 2 + 1
3344 ;; "\\([^\"'`\n]*\\)" ; 3 + 1
3345 ;; "\\3"
3346 ;; "\\|"
3347 ;; ;; Second variant: Identifier or \ID or empty
3348 ;; "\\\\?\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" ; 4 + 1, 5 + 1
3349 ;; ;; Do not have <<= or << 30 or <<30 or << $blah.
3350 ;; ;; "\\([^= \t0-9$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" ; 6 + 1
3351 ;; "\\(\\)" ; To preserve count of pars :-( 6 + 1
3352 ;; "\\)"
3353 ((match-beginning 2) ; 1 + 1
3354 ;; Abort in comment:
3355 (setq b (point))
3356 (setq state (parse-partial-sexp state-point b nil nil state)
3357 state-point b
3358 tb (match-beginning 0)
3359 i (or (nth 3 state) (nth 4 state)))
3360 (if i
3361 (setq c t)
3362 (setq c (and
3363 (match-beginning 5)
3364 (not (match-beginning 6)) ; Empty
3365 (looking-at
3366 "[ \t]*[=0-9$@%&(]"))))
3367 (if c ; Not here-doc
3368 nil ; Skip it.
3369 (if (match-beginning 5) ;4 + 1
3370 (setq b1 (match-beginning 5) ; 4 + 1
3371 e1 (match-end 5)) ; 4 + 1
3372 (setq b1 (match-beginning 4) ; 3 + 1
3373 e1 (match-end 4))) ; 3 + 1
3374 (setq tag (buffer-substring b1 e1)
3375 qtag (regexp-quote tag))
3376 (cond (cperl-pod-here-fontify
3377 ;; Highlight the starting delimiter
3378 (cperl-postpone-fontification b1 e1 'face font-lock-constant-face)
3379 (cperl-put-do-not-fontify b1 e1 t)))
3380 (forward-line)
3381 (setq b (point))
3382 ;; We do not search to max, since we may be called from
3383 ;; some hook of fontification, and max is random
3384 (or (and (re-search-forward (concat "^" qtag "$")
3385 stop-point 'toend)
3386 (eq (following-char) ?\n))
3387 (progn ; Pretend we matched at the end
3388 (goto-char (point-max))
3389 (re-search-forward "\\'")
3390 (message "End of here-document `%s' not found." tag)
3391 (or (car err-l) (setcar err-l b))))
3392 (if cperl-pod-here-fontify
3393 (progn
3394 ;; Highlight the ending delimiter
3395 (cperl-postpone-fontification (match-beginning 0) (match-end 0)
3396 'face font-lock-constant-face)
3397 (cperl-put-do-not-fontify b (match-end 0) t)
3398 ;; Highlight the HERE-DOC
3399 (cperl-postpone-fontification b (match-beginning 0)
3400 'face here-face)))
3401 (setq e1 (cperl-1+ (match-end 0)))
3402 (put-text-property b (match-beginning 0)
3403 'syntax-type 'here-doc)
3404 (put-text-property (match-beginning 0) e1
3405 'syntax-type 'here-doc-delim)
3406 (put-text-property b e1
3407 'here-doc-group t)
3408 (cperl-commentify b e1 nil)
3409 (cperl-put-do-not-fontify b (match-end 0) t)
3410 (if (> e1 max)
3411 (setq tmpend tb))))
3412 ;; format
3413 ((match-beginning 8)
3414 ;; 1+6=7 extra () before this:
3415 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
3416 (setq b (point)
3417 name (if (match-beginning 8) ; 7 + 1
3418 (buffer-substring (match-beginning 8) ; 7 + 1
3419 (match-end 8)) ; 7 + 1
3421 tb (match-beginning 0))
3422 (setq argument nil)
3423 (put-text-property (save-excursion
3424 (beginning-of-line)
3425 (point))
3426 b 'first-format-line 't)
3427 (if cperl-pod-here-fontify
3428 (while (and (eq (forward-line) 0)
3429 (not (looking-at "^[.;]$")))
3430 (cond
3431 ((looking-at "^#")) ; Skip comments
3432 ((and argument ; Skip argument multi-lines
3433 (looking-at "^[ \t]*{"))
3434 (forward-sexp 1)
3435 (setq argument nil))
3436 (argument ; Skip argument lines
3437 (setq argument nil))
3438 (t ; Format line
3439 (setq b1 (point))
3440 (setq argument (looking-at "^[^\n]*[@^]"))
3441 (end-of-line)
3442 ;; Highlight the format line
3443 (cperl-postpone-fontification b1 (point)
3444 'face font-lock-string-face)
3445 (cperl-commentify b1 (point) nil)
3446 (cperl-put-do-not-fontify b1 (point) t))))
3447 ;; We do not search to max, since we may be called from
3448 ;; some hook of fontification, and max is random
3449 (re-search-forward "^[.;]$" stop-point 'toend))
3450 (beginning-of-line)
3451 (if (looking-at "^\\.$") ; ";" is not supported yet
3452 (progn
3453 ;; Highlight the ending delimiter
3454 (cperl-postpone-fontification (point) (+ (point) 2)
3455 'face font-lock-string-face)
3456 (cperl-commentify (point) (+ (point) 2) nil)
3457 (cperl-put-do-not-fontify (point) (+ (point) 2) t))
3458 (message "End of format `%s' not found." name)
3459 (or (car err-l) (setcar err-l b)))
3460 (forward-line)
3461 (if (> (point) max)
3462 (setq tmpend tb))
3463 (put-text-property b (point) 'syntax-type 'format))
3464 ;; Regexp:
3465 ((or (match-beginning 10) (match-beginning 11))
3466 ;; 1+6+2=9 extra () before this:
3467 ;; "\\<\\(q[wxqr]?\\|[msy]\\|tr\\)\\>"
3468 ;; "\\|"
3469 ;; "\\([?/<]\\)" ; /blah/ or ?blah? or <file*glob>
3470 (setq b1 (if (match-beginning 10) 10 11)
3471 argument (buffer-substring
3472 (match-beginning b1) (match-end b1))
3473 b (point)
3475 c (char-after (match-beginning b1))
3476 bb (char-after (1- (match-beginning b1))) ; tmp holder
3477 ;; bb == "Not a stringy"
3478 bb (if (eq b1 10) ; user variables/whatever
3479 (and (memq bb (append "$@%*#_:-&>" nil)) ; $#y)
3480 (cond ((eq bb ?-) (eq c ?s)) ; -s file test
3481 ((eq bb ?\:) ; $opt::s
3482 (eq (char-after
3483 (- (match-beginning b1) 2))
3484 ?\:))
3485 ((eq bb ?\>) ; $foo->s
3486 (eq (char-after
3487 (- (match-beginning b1) 2))
3488 ?\-))
3489 ((eq bb ?\&)
3490 (not (eq (char-after ; &&m/blah/
3491 (- (match-beginning b1) 2))
3492 ?\&)))
3493 (t t)))
3494 ;; <file> or <$file>
3495 (and (eq c ?\<)
3496 ;; Do not stringify <FH>, <$fh> :
3497 (save-match-data
3498 (looking-at
3499 "\\$?\\([_a-zA-Z:][_a-zA-Z0-9:]*\\)?>"))))
3500 tb (match-beginning 0))
3501 (goto-char (match-beginning b1))
3502 (cperl-backward-to-noncomment (point-min))
3503 (or bb
3504 (if (eq b1 11) ; bare /blah/ or ?blah? or <foo>
3505 (setq argument ""
3506 b1 nil
3507 bb ; Not a regexp?
3508 (progn
3509 (not
3510 ;; What is below: regexp-p?
3511 (and
3512 (or (memq (preceding-char)
3513 (append (if (memq c '(?\? ?\<))
3514 ;; $a++ ? 1 : 2
3515 "~{(=|&*!,;:"
3516 "~{(=|&+-*!,;:") nil))
3517 (and (eq (preceding-char) ?\})
3518 (cperl-after-block-p (point-min)))
3519 (and (eq (char-syntax (preceding-char)) ?w)
3520 (progn
3521 (forward-sexp -1)
3522 ;; After these keywords `/' starts a RE. One should add all the
3523 ;; functions/builtins which expect an argument, but ...
3524 (if (eq (preceding-char) ?-)
3525 ;; -d ?foo? is a RE
3526 (looking-at "[a-zA-Z]\\>")
3527 (and
3528 (not (memq (preceding-char)
3529 '(?$ ?@ ?& ?%)))
3530 (looking-at
3531 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))))
3532 (and (eq (preceding-char) ?.)
3533 (eq (char-after (- (point) 2)) ?.))
3534 (bobp))
3535 ;; m|blah| ? foo : bar;
3536 (not
3537 (and (eq c ?\?)
3538 cperl-use-syntax-table-text-property
3539 (not (bobp))
3540 (progn
3541 (forward-char -1)
3542 (looking-at "\\s|")))))))
3543 b (1- b))
3544 ;; s y tr m
3545 ;; Check for $a -> y
3546 (setq b1 (preceding-char)
3547 go (point))
3548 (if (and (eq b1 ?>)
3549 (eq (char-after (- go 2)) ?-))
3550 ;; Not a regexp
3551 (setq bb t))))
3552 (or bb (setq state (parse-partial-sexp
3553 state-point b nil nil state)
3554 state-point b))
3555 (setq bb (or bb (nth 3 state) (nth 4 state)))
3556 (goto-char b)
3557 (or bb
3558 (progn
3559 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3560 (goto-char (match-end 0))
3561 (skip-chars-forward " \t\n\f"))
3562 (cond ((and (eq (following-char) ?\})
3563 (eq b1 ?\{))
3564 ;; Check for $a[23]->{ s }, @{s} and *{s::foo}
3565 (goto-char (1- go))
3566 (skip-chars-backward " \t\n\f")
3567 (if (memq (preceding-char) (append "$@%&*" nil))
3568 (setq bb t) ; @{y}
3569 (condition-case nil
3570 (forward-sexp -1)
3571 (error nil)))
3572 (if (or bb
3573 (looking-at ; $foo -> {s}
3574 "[$@]\\$*\\([a-zA-Z0-9_:]+\\|[^{]\\)\\([ \t\n]*->\\)?[ \t\n]*{")
3575 (and ; $foo[12] -> {s}
3576 (memq (following-char) '(?\{ ?\[))
3577 (progn
3578 (forward-sexp 1)
3579 (looking-at "\\([ \t\n]*->\\)?[ \t\n]*{"))))
3580 (setq bb t)
3581 (goto-char b)))
3582 ((and (eq (following-char) ?=)
3583 (eq (char-after (1+ (point))) ?\>))
3584 ;; Check for { foo => 1, s => 2 }
3585 ;; Apparently s=> is never a substitution...
3586 (setq bb t))
3587 ((and (eq (following-char) ?:)
3588 (eq b1 ?\{) ; Check for $ { s::bar }
3589 (looking-at "::[a-zA-Z0-9_:]*[ \t\n\f]*}")
3590 (progn
3591 (goto-char (1- go))
3592 (skip-chars-backward " \t\n\f")
3593 (memq (preceding-char)
3594 (append "$@%&*" nil))))
3595 (setq bb t)))))
3596 (if bb
3597 (goto-char i)
3598 ;; Skip whitespace and comments...
3599 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
3600 (goto-char (match-end 0))
3601 (skip-chars-forward " \t\n\f"))
3602 (if (> (point) b)
3603 (put-text-property b (point) 'syntax-type 'prestring))
3604 ;; qtag means two-arg matcher, may be reset to
3605 ;; 2 or 3 later if some special quoting is needed.
3606 ;; e1 means matching-char matcher.
3607 (setq b (point)
3608 ;; has 2 args
3609 i2 (string-match "^\\([sy]\\|tr\\)$" argument)
3610 ;; We do not search to max, since we may be called from
3611 ;; some hook of fontification, and max is random
3612 i (cperl-forward-re stop-point end
3614 t st-l err-l argument)
3615 ;; Note that if `go', then it is considered as 1-arg
3616 b1 (nth 1 i) ; start of the second part
3617 tag (nth 2 i) ; ender-char, true if second part
3618 ; is with matching chars []
3619 go (nth 4 i) ; There is a 1-char part after the end
3620 i (car i) ; intermediate point
3621 e1 (point) ; end
3622 ;; Before end of the second part if non-matching: ///
3623 tail (if (and i (not tag))
3624 (1- e1))
3625 e (if i i e1) ; end of the first part
3626 qtag nil ; need to preserve backslashitis
3627 is-x-REx nil) ; REx has //x modifier
3628 ;; Commenting \\ is dangerous, what about ( ?
3629 (and i tail
3630 (eq (char-after i) ?\\)
3631 (setq qtag t))
3632 (if (looking-at "\\sw*x") ; qr//x
3633 (setq is-x-REx t))
3634 (if (null i)
3635 ;; Considered as 1arg form
3636 (progn
3637 (cperl-commentify b (point) t)
3638 (put-text-property b (point) 'syntax-type 'string)
3639 (if (or is-x-REx
3640 ;; ignore other text properties:
3641 (string-match "^qw$" argument))
3642 (put-text-property b (point) 'indentable t))
3643 (and go
3644 (setq e1 (cperl-1+ e1))
3645 (or (eobp)
3646 (forward-char 1))))
3647 (cperl-commentify b i t)
3648 (if (looking-at "\\sw*e") ; s///e
3649 (progn
3650 (and
3651 ;; silent:
3652 (cperl-find-pods-heres b1 (1- (point)) t end)
3653 ;; Error
3654 (goto-char (1+ max)))
3655 (if (and tag (eq (preceding-char) ?\>))
3656 (progn
3657 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
3658 (cperl-modify-syntax-type i cperl-st-bra)))
3659 (put-text-property b i 'syntax-type 'string)
3660 (if is-x-REx
3661 (put-text-property b i 'indentable t)))
3662 (cperl-commentify b1 (point) t)
3663 (put-text-property b (point) 'syntax-type 'string)
3664 (if is-x-REx
3665 (put-text-property b i 'indentable t))
3666 (if qtag
3667 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
3668 (setq tail nil)))
3669 ;; Now: tail: if the second part is non-matching without ///e
3670 (if (eq (char-syntax (following-char)) ?w)
3671 (progn
3672 (forward-word 1) ; skip modifiers s///s
3673 (if tail (cperl-commentify tail (point) t))
3674 (cperl-postpone-fontification
3675 e1 (point) 'face 'cperl-nonoverridable)))
3676 ;; Check whether it is m// which means "previous match"
3677 ;; and highlight differently
3678 (setq is-REx
3679 (and (string-match "^\\([sm]?\\|qr\\)$" argument)
3680 (or (not (= (length argument) 0))
3681 (not (eq c ?\<)))))
3682 (if (and is-REx
3683 (eq e (+ 2 b))
3684 ;; split // *is* using zero-pattern
3685 (save-excursion
3686 (condition-case nil
3687 (progn
3688 (goto-char tb)
3689 (forward-sexp -1)
3690 (not (looking-at "split\\>")))
3691 (error t))))
3692 (cperl-postpone-fontification
3693 b e 'face font-lock-function-name-face)
3694 (if (or i2 ; Has 2 args
3695 (and cperl-fontify-m-as-s
3697 (string-match "^\\(m\\|qr\\)$" argument)
3698 (and (eq 0 (length argument))
3699 (not (eq ?\< (char-after b)))))))
3700 (progn
3701 (cperl-postpone-fontification
3702 b (cperl-1+ b) 'face font-lock-constant-face)
3703 (cperl-postpone-fontification
3704 (1- e) e 'face font-lock-constant-face)))
3705 (if (and is-REx cperl-regexp-scan)
3706 ;; Process RExen better
3707 (save-excursion
3708 (goto-char (1+ b))
3709 (while
3710 (and (< (point) e)
3711 (re-search-forward
3712 (if is-x-REx
3713 (if (eq (char-after b) ?\#)
3714 "\\((\\?\\\\#\\)\\|\\(\\\\#\\)"
3715 "\\((\\?#\\)\\|\\(#\\)")
3716 (if (eq (char-after b) ?\#)
3717 "\\((\\?\\\\#\\)"
3718 "\\((\\?#\\)"))
3719 (1- e) 'to-end))
3720 (goto-char (match-beginning 0))
3721 (setq REx-comment-start (point)
3722 was-comment t)
3723 (if (save-excursion
3724 (and
3725 ;; XXX not working if outside delimiter is #
3726 (eq (preceding-char) ?\\)
3727 (= (% (skip-chars-backward "$\\\\") 2) -1)))
3728 ;; Not a comment, avoid loop:
3729 (progn (setq was-comment nil)
3730 (forward-char 1))
3731 (if (match-beginning 2)
3732 (progn
3733 (beginning-of-line 2)
3734 (if (> (point) e)
3735 (goto-char (1- e))))
3736 ;; Works also if the outside delimiters are ().
3737 (or (search-forward ")" (1- e) 'toend)
3738 (message
3739 "Couldn't find end of (?#...)-comment in a REx, pos=%s"
3740 REx-comment-start))))
3741 (if (>= (point) e)
3742 (goto-char (1- e)))
3743 (if was-comment
3744 (progn
3745 (setq REx-comment-end (point))
3746 (cperl-commentify
3747 REx-comment-start REx-comment-end nil)
3748 (cperl-postpone-fontification
3749 REx-comment-start REx-comment-end
3750 'face font-lock-comment-face))))))
3751 (if (and is-REx is-x-REx)
3752 (put-text-property (1+ b) (1- e)
3753 'syntax-subtype 'x-REx)))
3754 (if i2
3755 (progn
3756 (cperl-postpone-fontification
3757 (1- e1) e1 'face font-lock-constant-face)
3758 (if (assoc (char-after b) cperl-starters)
3759 (cperl-postpone-fontification
3760 b1 (1+ b1) 'face font-lock-constant-face))))
3761 (if (> (point) max)
3762 (setq tmpend tb))))
3763 ((match-beginning 13) ; sub with prototypes
3764 (setq b (match-beginning 0))
3765 (if (memq (char-after (1- b))
3766 '(?\$ ?\@ ?\% ?\& ?\*))
3768 (setq state (parse-partial-sexp
3769 state-point b nil nil state)
3770 state-point b)
3771 (if (or (nth 3 state) (nth 4 state))
3773 ;; Mark as string
3774 (cperl-commentify (match-beginning 13) (match-end 13) t))
3775 (goto-char (match-end 0))))
3776 ;; 1+6+2+1+1+2=13 extra () before this:
3777 ;; "\\$\\(['{]\\)"
3778 ((and (match-beginning 14)
3779 (eq (preceding-char) ?\')) ; $'
3780 (setq b (1- (point))
3781 state (parse-partial-sexp
3782 state-point (1- b) nil nil state)
3783 state-point (1- b))
3784 (if (nth 3 state) ; in string
3785 (cperl-modify-syntax-type (1- b) cperl-st-punct))
3786 (goto-char (1+ b)))
3787 ;; 1+6+2+1+1+2=13 extra () before this:
3788 ;; "\\$\\(['{]\\)"
3789 ((match-beginning 14) ; ${
3790 (setq bb (match-beginning 0))
3791 (cperl-modify-syntax-type bb cperl-st-punct))
3792 ;; 1+6+2+1+1+2+1=14 extra () before this:
3793 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
3794 ((match-beginning 15) ; old $abc'efg syntax
3795 (setq bb (match-end 0)
3796 b (match-beginning 0)
3797 state (parse-partial-sexp
3798 state-point b nil nil state)
3799 state-point b)
3800 (if (nth 3 state) ; in string
3802 (put-text-property (1- bb) bb 'syntax-table cperl-st-word))
3803 (goto-char bb))
3804 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
3805 ;; "__\\(END\\|DATA\\)__"
3806 ((match-beginning 16) ; __END__, __DATA__
3807 (setq bb (match-end 0)
3808 b (match-beginning 0)
3809 state (parse-partial-sexp
3810 state-point b nil nil state)
3811 state-point b)
3812 (if (or (nth 3 state) (nth 4 state))
3814 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
3815 (cperl-commentify b bb nil)
3816 (setq end t))
3817 (goto-char bb))
3818 ((match-beginning 17) ; "\\\\\\(['`\"($]\\)"
3819 ;; Trailing backslash ==> non-quoting outside string/comment
3820 (setq bb (match-end 0)
3821 b (match-beginning 0))
3822 (goto-char b)
3823 (skip-chars-backward "\\\\")
3824 ;;;(setq i2 (= (% (skip-chars-backward "\\\\") 2) -1))
3825 (setq state (parse-partial-sexp
3826 state-point b nil nil state)
3827 state-point b)
3828 (if (or (nth 3 state) (nth 4 state) )
3830 (cperl-modify-syntax-type b cperl-st-punct))
3831 (goto-char bb))
3832 (t (error "Error in regexp of the sniffer")))
3833 (if (> (point) stop-point)
3834 (progn
3835 (if end
3836 (message "Garbage after __END__/__DATA__ ignored")
3837 (message "Unbalanced syntax found while scanning")
3838 (or (car err-l) (setcar err-l b)))
3839 (goto-char stop-point))))
3840 (setq cperl-syntax-state (cons state-point state)
3841 cperl-syntax-done-to (or tmpend (max (point) max))))
3842 (if (car err-l) (goto-char (car err-l))
3843 (or non-inter
3844 (message "Scanning for \"hard\" Perl constructions... done"))))
3845 (and (buffer-modified-p)
3846 (not modified)
3847 (set-buffer-modified-p nil))
3848 ;; I do not understand what this is doing here. It breaks font-locking
3849 ;; because it resets the syntax-table from font-lock-syntax-table to
3850 ;; cperl-mode-syntax-table.
3851 ;; (set-syntax-table cperl-mode-syntax-table)
3853 (car err-l)))
3855 (defun cperl-backward-to-noncomment (lim)
3856 ;; Stops at lim or after non-whitespace that is not in comment
3857 (let (stop p pr)
3858 (while (and (not stop) (> (point) (or lim 1)))
3859 (skip-chars-backward " \t\n\f" lim)
3860 (setq p (point))
3861 (beginning-of-line)
3862 (if (memq (setq pr (get-text-property (point) 'syntax-type))
3863 '(pod here-doc here-doc-delim))
3864 (cperl-unwind-to-safe nil)
3865 (or (looking-at "^[ \t]*\\(#\\|$\\)")
3866 (progn (cperl-to-comment-or-eol) (bolp))
3867 (progn
3868 (skip-chars-backward " \t")
3869 (if (< p (point)) (goto-char p))
3870 (setq stop t)))))))
3872 (defun cperl-after-block-p (lim &optional pre-block)
3873 "Return true if the preceeding } ends a block or a following { starts one.
3874 Would not look before LIM. If PRE-BLOCK is nil checks preceeding }.
3875 otherwise following {."
3876 ;; We suppose that the preceding char is }.
3877 (save-excursion
3878 (condition-case nil
3879 (progn
3880 (or pre-block (forward-sexp -1))
3881 (cperl-backward-to-noncomment lim)
3882 (or (eq (point) lim)
3883 (eq (preceding-char) ?\) ) ; if () {} sub f () {}
3884 (if (eq (char-syntax (preceding-char)) ?w) ; else {}
3885 (save-excursion
3886 (forward-sexp -1)
3887 (or (looking-at "\\(else\\|continue\\|grep\\|map\\|BEGIN\\|END\\|CHECK\\|INIT\\)\\>")
3888 ;; sub f {}
3889 (progn
3890 (cperl-backward-to-noncomment lim)
3891 (and (eq (char-syntax (preceding-char)) ?w)
3892 (progn
3893 (forward-sexp -1)
3894 (looking-at "sub\\>"))))))
3895 (cperl-after-expr-p lim))))
3896 (error nil))))
3898 (defun cperl-after-expr-p (&optional lim chars test)
3899 "Return true if the position is good for start of expression.
3900 TEST is the expression to evaluate at the found position. If absent,
3901 CHARS is a string that contains good characters to have before us (however,
3902 `}' is treated \"smartly\" if it is not in the list)."
3903 (let ((lim (or lim (point-min)))
3904 stop p pr)
3905 (cperl-update-syntaxification (point) (point))
3906 (save-excursion
3907 (while (and (not stop) (> (point) lim))
3908 (skip-chars-backward " \t\n\f" lim)
3909 (setq p (point))
3910 (beginning-of-line)
3911 ;;(memq (setq pr (get-text-property (point) 'syntax-type))
3912 ;; '(pod here-doc here-doc-delim))
3913 (if (get-text-property (point) 'here-doc-group)
3914 (progn
3915 (goto-char
3916 (previous-single-property-change (point) 'here-doc-group))
3917 (beginning-of-line 0)))
3918 (if (get-text-property (point) 'in-pod)
3919 (progn
3920 (goto-char
3921 (previous-single-property-change (point) 'in-pod))
3922 (beginning-of-line 0)))
3923 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
3924 ;; Else: last iteration, or a label
3925 (cperl-to-comment-or-eol) ; Will not move past "." after a format
3926 (skip-chars-backward " \t")
3927 (if (< p (point)) (goto-char p))
3928 (setq p (point))
3929 (if (and (eq (preceding-char) ?:)
3930 (progn
3931 (forward-char -1)
3932 (skip-chars-backward " \t\n\f" lim)
3933 (eq (char-syntax (preceding-char)) ?w)))
3934 (forward-sexp -1) ; Possibly label. Skip it
3935 (goto-char p)
3936 (setq stop t))))
3937 (or (bobp) ; ???? Needed
3938 (eq (point) lim)
3939 (looking-at "[ \t]*__\\(END\\|DATA\\)__") ; After this anything goes
3940 (progn
3941 (if test (eval test)
3942 (or (memq (preceding-char) (append (or chars "{;") nil))
3943 (and (eq (preceding-char) ?\})
3944 (cperl-after-block-p lim))
3945 (and (eq (following-char) ?.) ; in format: see comment above
3946 (eq (get-text-property (point) 'syntax-type)
3947 'format)))))))))
3949 (defun cperl-backward-to-start-of-continued-exp (lim)
3950 (if (memq (preceding-char) (append ")]}\"'`" nil))
3951 (forward-sexp -1))
3952 (beginning-of-line)
3953 (if (<= (point) lim)
3954 (goto-char (1+ lim)))
3955 (skip-chars-forward " \t"))
3957 (defun cperl-after-block-and-statement-beg (lim)
3958 ;; We assume that we are after ?\}
3959 (and
3960 (cperl-after-block-p lim)
3961 (save-excursion
3962 (forward-sexp -1)
3963 (cperl-backward-to-noncomment (point-min))
3964 (or (bobp)
3965 (eq (point) lim)
3966 (not (= (char-syntax (preceding-char)) ?w))
3967 (progn
3968 (forward-sexp -1)
3969 (not
3970 (looking-at
3971 "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>")))))))
3974 (defun cperl-indent-exp ()
3975 "Simple variant of indentation of continued-sexp.
3977 Will not indent comment if it starts at `comment-indent' or looks like
3978 continuation of the comment on the previous line.
3980 If `cperl-indent-region-fix-constructs', will improve spacing on
3981 conditional/loop constructs."
3982 (interactive)
3983 (save-excursion
3984 (let ((tmp-end (progn (end-of-line) (point))) top done)
3985 (save-excursion
3986 (beginning-of-line)
3987 (while (null done)
3988 (setq top (point))
3989 (while (= (nth 0 (parse-partial-sexp (point) tmp-end
3990 -1)) -1)
3991 (setq top (point))) ; Get the outermost parenths in line
3992 (goto-char top)
3993 (while (< (point) tmp-end)
3994 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
3995 (or (eolp) (forward-sexp 1)))
3996 (if (> (point) tmp-end)
3997 (save-excursion
3998 (end-of-line)
3999 (setq tmp-end (point)))
4000 (setq done t)))
4001 (goto-char tmp-end)
4002 (setq tmp-end (point-marker)))
4003 (if cperl-indent-region-fix-constructs
4004 (cperl-fix-line-spacing tmp-end))
4005 (cperl-indent-region (point) tmp-end))))
4007 (defun cperl-fix-line-spacing (&optional end parse-data)
4008 "Improve whitespace in a conditional/loop construct.
4009 Returns some position at the last line."
4010 (interactive)
4011 (or end
4012 (setq end (point-max)))
4013 (let ((ee (save-excursion (end-of-line) (point)))
4014 (cperl-indent-region-fix-constructs
4015 (or cperl-indent-region-fix-constructs 1))
4016 p pp ml have-brace ret)
4017 (save-excursion
4018 (beginning-of-line)
4019 (setq ret (point))
4020 ;; }? continue
4021 ;; blah; }
4022 (if (not
4023 (or (looking-at "[ \t]*\\(els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)")
4024 (setq have-brace (save-excursion (search-forward "}" ee t)))))
4025 nil ; Do not need to do anything
4026 ;; Looking at:
4027 ;; }
4028 ;; else
4029 (if (and cperl-merge-trailing-else
4030 (looking-at
4031 "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>"))
4032 (progn
4033 (search-forward "}")
4034 (setq p (point))
4035 (skip-chars-forward " \t\n")
4036 (delete-region p (point))
4037 (insert (make-string cperl-indent-region-fix-constructs ?\s))
4038 (beginning-of-line)))
4039 ;; Looking at:
4040 ;; } else
4041 (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>")
4042 (progn
4043 (search-forward "}")
4044 (delete-horizontal-space)
4045 (insert (make-string cperl-indent-region-fix-constructs ?\s))
4046 (beginning-of-line)))
4047 ;; Looking at:
4048 ;; else {
4049 (if (looking-at
4050 "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|unless\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
4051 (progn
4052 (forward-word 1)
4053 (delete-horizontal-space)
4054 (insert (make-string cperl-indent-region-fix-constructs ?\s))
4055 (beginning-of-line)))
4056 ;; Looking at:
4057 ;; foreach my $var
4058 (if (looking-at
4059 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]")
4060 (progn
4061 (forward-word 2)
4062 (delete-horizontal-space)
4063 (insert (make-string cperl-indent-region-fix-constructs ?\s))
4064 (beginning-of-line)))
4065 ;; Looking at:
4066 ;; foreach my $var (
4067 (if (looking-at
4068 "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\|our\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]")
4069 (progn
4070 (forward-sexp 3)
4071 (delete-horizontal-space)
4072 (insert
4073 (make-string cperl-indent-region-fix-constructs ?\s))
4074 (beginning-of-line)))
4075 ;; Looking at:
4076 ;; } foreach my $var () {
4077 (if (looking-at
4078 "[ \t]*\\(}[ \t]*\\)?\\<\\(\\els\\(e\\|if\\)\\|continue\\|if\\|unless\\|while\\|for\\(each\\)?\\(\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\$[_a-zA-Z0-9]+\\)?\\|until\\)\\>\\([ \t]*(\\|[ \t\n]*{\\)\\|[ \t]*{")
4079 (progn
4080 (setq ml (match-beginning 8))
4081 (re-search-forward "[({]")
4082 (forward-char -1)
4083 (setq p (point))
4084 (if (eq (following-char) ?\( )
4085 (progn
4086 (forward-sexp 1)
4087 (setq pp (point)))
4088 ;; after `else' or nothing
4089 (if ml ; after `else'
4090 (skip-chars-backward " \t\n")
4091 (beginning-of-line))
4092 (setq pp nil))
4093 ;; Now after the sexp before the brace
4094 ;; Multiline expr should be special
4095 (setq ml (and pp (save-excursion (goto-char p)
4096 (search-forward "\n" pp t))))
4097 (if (and (or (not pp) (< pp end))
4098 (looking-at "[ \t\n]*{"))
4099 (progn
4100 (cond
4101 ((bolp) ; Were before `{', no if/else/etc
4102 nil)
4103 ((looking-at "\\(\t*\\| [ \t]+\\){")
4104 (delete-horizontal-space)
4105 (if (if ml
4106 cperl-extra-newline-before-brace-multiline
4107 cperl-extra-newline-before-brace)
4108 (progn
4109 (delete-horizontal-space)
4110 (insert "\n")
4111 (setq ret (point))
4112 (if (cperl-indent-line parse-data)
4113 (progn
4114 (cperl-fix-line-spacing end parse-data)
4115 (setq ret (point)))))
4116 (insert
4117 (make-string cperl-indent-region-fix-constructs ?\s))))
4118 ((and (looking-at "[ \t]*\n")
4119 (not (if ml
4120 cperl-extra-newline-before-brace-multiline
4121 cperl-extra-newline-before-brace)))
4122 (setq pp (point))
4123 (skip-chars-forward " \t\n")
4124 (delete-region pp (point))
4125 (insert
4126 (make-string cperl-indent-region-fix-constructs ?\s))))
4127 ;; Now we are before `{'
4128 (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]")
4129 (progn
4130 (skip-chars-forward " \t\n")
4131 (setq pp (point))
4132 (forward-sexp 1)
4133 (setq p (point))
4134 (goto-char pp)
4135 (setq ml (search-forward "\n" p t))
4136 (if (or cperl-break-one-line-blocks-when-indent ml)
4137 ;; not good: multi-line BLOCK
4138 (progn
4139 (goto-char (1+ pp))
4140 (delete-horizontal-space)
4141 (insert "\n")
4142 (setq ret (point))
4143 (if (cperl-indent-line parse-data)
4144 (setq ret (cperl-fix-line-spacing end parse-data)))))))))))
4145 (beginning-of-line)
4146 (setq p (point) pp (save-excursion (end-of-line) (point))) ; May be different from ee.
4147 ;; Now check whether there is a hanging `}'
4148 ;; Looking at:
4149 ;; } blah
4150 (if (and
4151 cperl-fix-hanging-brace-when-indent
4152 have-brace
4153 (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)"))
4154 (condition-case nil
4155 (progn
4156 (up-list 1)
4157 (if (and (<= (point) pp)
4158 (eq (preceding-char) ?\} )
4159 (cperl-after-block-and-statement-beg (point-min)))
4161 (goto-char p)
4162 nil))
4163 (error nil)))
4164 (progn
4165 (forward-char -1)
4166 (skip-chars-backward " \t")
4167 (if (bolp)
4168 ;; `}' was the first thing on the line, insert NL *after* it.
4169 (progn
4170 (cperl-indent-line parse-data)
4171 (search-forward "}")
4172 (delete-horizontal-space)
4173 (insert "\n"))
4174 (delete-horizontal-space)
4175 (or (eq (preceding-char) ?\;)
4176 (bolp)
4177 (and (eq (preceding-char) ?\} )
4178 (cperl-after-block-p (point-min)))
4179 (insert ";"))
4180 (insert "\n")
4181 (setq ret (point)))
4182 (if (cperl-indent-line parse-data)
4183 (setq ret (cperl-fix-line-spacing end parse-data)))
4184 (beginning-of-line)))))
4185 ret))
4187 (defvar cperl-update-start) ; Do not need to make them local
4188 (defvar cperl-update-end)
4189 (defun cperl-delay-update-hook (beg end old-len)
4190 (setq cperl-update-start (min beg (or cperl-update-start (point-max))))
4191 (setq cperl-update-end (max end (or cperl-update-end (point-min)))))
4193 (defun cperl-indent-region (start end)
4194 "Simple variant of indentation of region in CPerl mode.
4195 Should be slow. Will not indent comment if it starts at `comment-indent'
4196 or looks like continuation of the comment on the previous line.
4197 Indents all the lines whose first character is between START and END
4198 inclusive.
4200 If `cperl-indent-region-fix-constructs', will improve spacing on
4201 conditional/loop constructs."
4202 (interactive "r")
4203 (cperl-update-syntaxification end end)
4204 (save-excursion
4205 (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
4206 (let ((indent-info (if cperl-emacs-can-parse
4207 (list nil nil nil) ; Cannot use '(), since will modify
4208 nil))
4209 (pm 0)
4210 after-change-functions ; Speed it up!
4211 st comm old-comm-indent new-comm-indent p pp i empty)
4212 (if h-a-c (add-hook 'after-change-functions 'cperl-delay-update-hook))
4213 (goto-char start)
4214 (setq old-comm-indent (and (cperl-to-comment-or-eol)
4215 (current-column))
4216 new-comm-indent old-comm-indent)
4217 (goto-char start)
4218 (setq end (set-marker (make-marker) end)) ; indentation changes pos
4219 (or (bolp) (beginning-of-line 2))
4220 (while (and (<= (point) end) (not (eobp))) ; bol to check start
4221 (setq st (point))
4222 (if (or
4223 (setq empty (looking-at "[ \t]*\n"))
4224 (and (setq comm (looking-at "[ \t]*#"))
4225 (or (eq (current-indentation) (or old-comm-indent
4226 comment-column))
4227 (setq old-comm-indent nil))))
4228 (if (and old-comm-indent
4229 (not empty)
4230 (= (current-indentation) old-comm-indent)
4231 (not (eq (get-text-property (point) 'syntax-type) 'pod))
4232 (not (eq (get-text-property (point) 'syntax-table)
4233 cperl-st-cfence)))
4234 (let ((comment-column new-comm-indent))
4235 (indent-for-comment)))
4236 (progn
4237 (setq i (cperl-indent-line indent-info))
4238 (or comm
4239 (not i)
4240 (progn
4241 (if cperl-indent-region-fix-constructs
4242 (goto-char (cperl-fix-line-spacing end indent-info)))
4243 (if (setq old-comm-indent
4244 (and (cperl-to-comment-or-eol)
4245 (not (memq (get-text-property (point)
4246 'syntax-type)
4247 '(pod here-doc)))
4248 (not (eq (get-text-property (point)
4249 'syntax-table)
4250 cperl-st-cfence))
4251 (current-column)))
4252 (progn (indent-for-comment)
4253 (skip-chars-backward " \t")
4254 (skip-chars-backward "#")
4255 (setq new-comm-indent (current-column))))))))
4256 (beginning-of-line 2)))
4257 ;; Now run the update hooks
4258 (and after-change-functions
4259 cperl-update-end
4260 (save-excursion
4261 (goto-char cperl-update-end)
4262 (insert " ")
4263 (delete-char -1)
4264 (goto-char cperl-update-start)
4265 (insert " ")
4266 (delete-char -1))))))
4268 ;; Stolen from lisp-mode with a lot of improvements
4270 (defun cperl-fill-paragraph (&optional justify iteration)
4271 "Like `fill-paragraph', but handle CPerl comments.
4272 If any of the current line is a comment, fill the comment or the
4273 block of it that point is in, preserving the comment's initial
4274 indentation and initial hashes. Behaves usually outside of comment."
4275 ;; (interactive "P") ; Only works when called from fill-paragraph. -stef
4276 (let (;; Non-nil if the current line contains a comment.
4277 has-comment
4279 ;; If has-comment, the appropriate fill-prefix for the comment.
4280 comment-fill-prefix
4281 ;; Line that contains code and comment (or nil)
4282 start
4283 c spaces len dc (comment-column comment-column))
4284 ;; Figure out what kind of comment we are looking at.
4285 (save-excursion
4286 (beginning-of-line)
4287 (cond
4289 ;; A line with nothing but a comment on it?
4290 ((looking-at "[ \t]*#[# \t]*")
4291 (setq has-comment t
4292 comment-fill-prefix (buffer-substring (match-beginning 0)
4293 (match-end 0))))
4295 ;; A line with some code, followed by a comment? Remember that the
4296 ;; semi which starts the comment shouldn't be part of a string or
4297 ;; character.
4298 ((cperl-to-comment-or-eol)
4299 (setq has-comment t)
4300 (looking-at "#+[ \t]*")
4301 (setq start (point) c (current-column)
4302 comment-fill-prefix
4303 (concat (make-string (current-column) ?\s)
4304 (buffer-substring (match-beginning 0) (match-end 0)))
4305 spaces (progn (skip-chars-backward " \t")
4306 (buffer-substring (point) start))
4307 dc (- c (current-column)) len (- start (point))
4308 start (point-marker))
4309 (delete-char len)
4310 (insert (make-string dc ?-)))))
4311 (if (not has-comment)
4312 (fill-paragraph justify) ; Do the usual thing outside of comment
4313 ;; Narrow to include only the comment, and then fill the region.
4314 (save-restriction
4315 (narrow-to-region
4316 ;; Find the first line we should include in the region to fill.
4317 (if start (progn (beginning-of-line) (point))
4318 (save-excursion
4319 (while (and (zerop (forward-line -1))
4320 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
4321 ;; We may have gone to far. Go forward again.
4322 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
4323 (forward-line 1))
4324 (point)))
4325 ;; Find the beginning of the first line past the region to fill.
4326 (save-excursion
4327 (while (progn (forward-line 1)
4328 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
4329 (point)))
4330 ;; Remove existing hashes
4331 (save-excursion
4332 (goto-char (point-min))
4333 (while (progn (forward-line 1) (< (point) (point-max)))
4334 (skip-chars-forward " \t")
4335 (and (looking-at "#+")
4336 (delete-char (- (match-end 0) (match-beginning 0))))))
4338 ;; Lines with only hashes on them can be paragraph boundaries.
4339 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
4340 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
4341 (fill-prefix comment-fill-prefix))
4342 (fill-paragraph justify)))
4343 (if (and start)
4344 (progn
4345 (goto-char start)
4346 (if (> dc 0)
4347 (progn (delete-char dc) (insert spaces)))
4348 (if (or (= (current-column) c) iteration) nil
4349 (setq comment-column c)
4350 (indent-for-comment)
4351 ;; Repeat once more, flagging as iteration
4352 (cperl-fill-paragraph justify t)))))))
4354 (defun cperl-do-auto-fill ()
4355 ;; Break out if the line is short enough
4356 (if (> (save-excursion
4357 (end-of-line)
4358 (current-column))
4359 fill-column)
4360 (let ((c (save-excursion (beginning-of-line)
4361 (cperl-to-comment-or-eol) (point)))
4362 (s (memq (following-char) '(?\s ?\t))) marker)
4363 (if (>= c (point))
4364 ;; Don't break line inside code: only inside comment.
4366 (setq marker (point-marker))
4367 (fill-paragraph nil)
4368 (goto-char marker)
4369 ;; Is not enough, sometimes marker is a start of line
4370 (if (bolp) (progn (re-search-forward "#+[ \t]*")
4371 (goto-char (match-end 0))))
4372 ;; Following space could have gone:
4373 (if (or (not s) (memq (following-char) '(?\s ?\t))) nil
4374 (insert " ")
4375 (backward-char 1))
4376 ;; Previous space could have gone:
4377 (or (memq (preceding-char) '(?\s ?\t)) (insert " "))))))
4379 (defun cperl-imenu-addback (lst &optional isback name)
4380 ;; We suppose that the lst is a DAG, unless the first element only
4381 ;; loops back, and ISBACK is set. Thus this function cannot be
4382 ;; applied twice without ISBACK set.
4383 (cond ((not cperl-imenu-addback) lst)
4385 (or name
4386 (setq name "+++BACK+++"))
4387 (mapcar (lambda (elt)
4388 (if (and (listp elt) (listp (cdr elt)))
4389 (progn
4390 ;; In the other order it goes up
4391 ;; one level only ;-(
4392 (setcdr elt (cons (cons name lst)
4393 (cdr elt)))
4394 (cperl-imenu-addback (cdr elt) t name))))
4395 (if isback (cdr lst) lst))
4396 lst)))
4398 (defun cperl-imenu--create-perl-index (&optional regexp)
4399 (require 'imenu) ; May be called from TAGS creator
4400 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
4401 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
4402 (index-meth-alist '()) meth
4403 packages ends-ranges p marker
4404 (prev-pos 0) char fchar index index1 name (end-range 0) package)
4405 (goto-char (point-min))
4406 (cperl-update-syntaxification (point-max) (point-max))
4407 ;; Search for the function
4408 (progn ;;save-match-data
4409 (while (re-search-forward
4410 (or regexp cperl-imenu--function-name-regexp-perl)
4411 nil t)
4412 (cond
4413 ((and ; Skip some noise if building tags
4414 (match-beginning 2) ; package or sub
4415 (eq (char-after (match-beginning 2)) ?p) ; package
4416 (not (save-match-data
4417 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
4418 nil)
4419 ((and
4420 (match-beginning 2) ; package or sub
4421 ;; Skip if quoted (will not skip multi-line ''-strings :-():
4422 (null (get-text-property (match-beginning 1) 'syntax-table))
4423 (null (get-text-property (match-beginning 1) 'syntax-type))
4424 (null (get-text-property (match-beginning 1) 'in-pod)))
4425 (save-excursion
4426 (goto-char (match-beginning 2))
4427 (setq fchar (following-char)))
4428 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
4429 ;; (goto-char (match-end 0))) ; Messes what follows
4430 (setq char (following-char) ; ?\; for "sub foo () ;"
4431 meth nil
4432 p (point))
4433 (while (and ends-ranges (>= p (car ends-ranges)))
4434 ;; delete obsolete entries
4435 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
4436 (setq package (or (car packages) "")
4437 end-range (or (car ends-ranges) 0))
4438 (if (eq fchar ?p)
4439 (setq name (buffer-substring (match-beginning 3) (match-end 3))
4440 name (progn
4441 (set-text-properties 0 (length name) nil name)
4442 name)
4443 package (concat name "::")
4444 name (concat "package " name)
4445 end-range
4446 (save-excursion
4447 (parse-partial-sexp (point) (point-max) -1) (point))
4448 ends-ranges (cons end-range ends-ranges)
4449 packages (cons package packages)))
4450 ;; )
4451 ;; Skip this function name if it is a prototype declaration.
4452 (if (and (eq fchar ?s) (eq char ?\;)) nil
4453 (setq name (buffer-substring (match-beginning 3) (match-end 3))
4454 marker (make-marker))
4455 (set-text-properties 0 (length name) nil name)
4456 (set-marker marker (match-end 3))
4457 (if (eq fchar ?p)
4458 (setq name (concat "package " name))
4459 (cond ((string-match "[:']" name)
4460 (setq meth t))
4461 ((> p end-range) nil)
4463 (setq name (concat package name) meth t))))
4464 (setq index (cons name marker))
4465 (if (eq fchar ?p)
4466 (push index index-pack-alist)
4467 (push index index-alist))
4468 (if meth (push index index-meth-alist))
4469 (push index index-unsorted-alist)))
4470 ((match-beginning 5) ; POD section
4471 ;; (beginning-of-line)
4472 (setq index (imenu-example--name-and-position)
4473 name (buffer-substring (match-beginning 6) (match-end 6)))
4474 (set-text-properties 0 (length name) nil name)
4475 (if (eq (char-after (match-beginning 5)) ?2)
4476 (setq name (concat " " name)))
4477 (setcar index name)
4478 (setq index1 (cons (concat "=" name) (cdr index)))
4479 (push index index-pod-alist)
4480 (push index1 index-unsorted-alist)))))
4481 (setq index-alist
4482 (if (default-value 'imenu-sort-function)
4483 (sort index-alist (default-value 'imenu-sort-function))
4484 (nreverse index-alist)))
4485 (and index-pod-alist
4486 (push (cons "+POD headers+..."
4487 (nreverse index-pod-alist))
4488 index-alist))
4489 (and (or index-pack-alist index-meth-alist)
4490 (let ((lst index-pack-alist) hier-list pack elt group name)
4491 ;; Remove "package ", reverse and uniquify.
4492 (while lst
4493 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
4494 (if (assoc name hier-list) nil
4495 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
4496 (setq lst index-meth-alist)
4497 (while lst
4498 (setq elt (car lst) lst (cdr lst))
4499 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
4500 (setq pack (substring (car elt) 0 (match-beginning 0)))
4501 (if (setq group (assoc pack hier-list))
4502 (if (listp (cdr group))
4503 ;; Have some functions already
4504 (setcdr group
4505 (cons (cons (substring
4506 (car elt)
4507 (+ 2 (match-beginning 0)))
4508 (cdr elt))
4509 (cdr group)))
4510 (setcdr group (list (cons (substring
4511 (car elt)
4512 (+ 2 (match-beginning 0)))
4513 (cdr elt)))))
4514 (setq hier-list
4515 (cons (cons pack
4516 (list (cons (substring
4517 (car elt)
4518 (+ 2 (match-beginning 0)))
4519 (cdr elt))))
4520 hier-list))))))
4521 (push (cons "+Hierarchy+..."
4522 hier-list)
4523 index-alist)))
4524 (and index-pack-alist
4525 (push (cons "+Packages+..."
4526 (nreverse index-pack-alist))
4527 index-alist))
4528 (and (or index-pack-alist index-pod-alist
4529 (default-value 'imenu-sort-function))
4530 index-unsorted-alist
4531 (push (cons "+Unsorted List+..."
4532 (nreverse index-unsorted-alist))
4533 index-alist))
4534 (cperl-imenu-addback index-alist)))
4537 ;; Suggested by Mark A. Hershberger
4538 (defun cperl-outline-level ()
4539 (looking-at outline-regexp)
4540 (cond ((not (match-beginning 1)) 0) ; beginning-of-file
4541 ((match-beginning 2)
4542 (if (eq (char-after (match-beginning 2)) ?p)
4543 0 ; package
4544 1)) ; sub
4545 ((match-beginning 5)
4546 (if (eq (char-after (match-beginning 5)) ?1)
4547 1 ; head1
4548 2)) ; head2
4549 (t 3))) ; should not happen
4552 (defvar cperl-compilation-error-regexp-alist
4553 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK).
4554 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
4555 2 3))
4556 "Alist that specifies how to match errors in perl output.")
4558 (if (fboundp 'eval-after-load)
4559 (eval-after-load
4560 "mode-compile"
4561 '(setq perl-compilation-error-regexp-alist
4562 cperl-compilation-error-regexp-alist)))
4565 (defun cperl-windowed-init ()
4566 "Initialization under windowed version."
4567 (if (or (featurep 'ps-print) cperl-faces-init)
4568 ;; Need to init anyway:
4569 (or cperl-faces-init (cperl-init-faces))
4570 (add-hook 'font-lock-mode-hook
4571 (function
4572 (lambda ()
4573 (if (memq major-mode '(perl-mode cperl-mode))
4574 (progn
4575 (or cperl-faces-init (cperl-init-faces)))))))
4576 (if (fboundp 'eval-after-load)
4577 (eval-after-load
4578 "ps-print"
4579 '(or cperl-faces-init (cperl-init-faces))))))
4581 (defvar cperl-font-lock-keywords-1 nil
4582 "Additional expressions to highlight in Perl mode. Minimal set.")
4583 (defvar cperl-font-lock-keywords nil
4584 "Additional expressions to highlight in Perl mode. Default set.")
4585 (defvar cperl-font-lock-keywords-2 nil
4586 "Additional expressions to highlight in Perl mode. Maximal set")
4588 (defun cperl-load-font-lock-keywords ()
4589 (or cperl-faces-init (cperl-init-faces))
4590 cperl-font-lock-keywords)
4592 (defun cperl-load-font-lock-keywords-1 ()
4593 (or cperl-faces-init (cperl-init-faces))
4594 cperl-font-lock-keywords-1)
4596 (defun cperl-load-font-lock-keywords-2 ()
4597 (or cperl-faces-init (cperl-init-faces))
4598 cperl-font-lock-keywords-2)
4600 (defun cperl-init-faces-weak ()
4601 ;; Allow `cperl-find-pods-heres' to run.
4602 (or (boundp 'font-lock-constant-face)
4603 (cperl-force-face font-lock-constant-face
4604 "Face for constant and label names")
4605 ;;(setq font-lock-constant-face 'font-lock-constant-face)
4608 (defun cperl-init-faces ()
4609 (condition-case errs
4610 (progn
4611 (require 'font-lock)
4612 (and (fboundp 'font-lock-fontify-anchored-keywords)
4613 (featurep 'font-lock-extra)
4614 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
4615 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
4616 (if (fboundp 'font-lock-fontify-anchored-keywords)
4617 (setq font-lock-anchored t))
4618 (setq
4619 t-font-lock-keywords
4620 (list
4621 `("[ \t]+$" 0 ',cperl-invalid-face t)
4622 (cons
4623 (concat
4624 "\\(^\\|[^$@%&\\]\\)\\<\\("
4625 (mapconcat
4626 'identity
4627 '("if" "until" "while" "elsif" "else" "unless" "for"
4628 "foreach" "continue" "exit" "die" "last" "goto" "next"
4629 "redo" "return" "local" "exec" "sub" "do" "dump" "use"
4630 "require" "package" "eval" "my" "BEGIN" "END" "CHECK" "INIT")
4631 "\\|") ; Flow control
4632 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
4633 ; In what follows we use `type' style
4634 ; for overwritable builtins
4635 (list
4636 (concat
4637 "\\(^\\|[^$@%&\\]\\)\\<\\("
4638 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
4639 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
4640 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
4641 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
4642 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
4643 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
4644 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
4645 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
4646 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
4647 ;; "gethostbyname" "gethostent" "getlogin"
4648 ;; "getnetbyaddr" "getnetbyname" "getnetent"
4649 ;; "getpeername" "getpgrp" "getppid" "getpriority"
4650 ;; "getprotobyname" "getprotobynumber" "getprotoent"
4651 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
4652 ;; "getservbyport" "getservent" "getsockname"
4653 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
4654 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
4655 ;; "link" "listen" "localtime" "lock" "log" "lstat" "lt"
4656 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
4657 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
4658 ;; "quotemeta" "rand" "read" "readdir" "readline"
4659 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
4660 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
4661 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
4662 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
4663 ;; "setpriority" "setprotoent" "setpwent" "setservent"
4664 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
4665 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
4666 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
4667 ;; "syscall" "sysopen" "sysread" "system" "syswrite" "tell"
4668 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
4669 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
4670 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
4671 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
4672 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
4673 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
4674 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
4675 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
4676 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
4677 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
4678 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
4679 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
4680 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
4681 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
4682 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
4683 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
4684 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
4685 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
4686 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
4687 "\\(\\|ngth\\)\\|o\\(c\\(altime\\|k\\)\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
4688 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
4689 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
4690 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
4691 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
4692 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
4693 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
4694 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
4695 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
4696 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|open\\|tem\\|write\\)\\|"
4697 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
4698 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
4699 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
4700 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
4701 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
4702 "\\)\\>") 2 'font-lock-type-face)
4703 ;; In what follows we use `other' style
4704 ;; for nonoverwritable builtins
4705 ;; Somehow 's', 'm' are not auto-generated???
4706 (list
4707 (concat
4708 "\\(^\\|[^$@%&\\]\\)\\<\\("
4709 ;; "AUTOLOAD" "BEGIN" "CHECK" "DESTROY" "END" "INIT" "__END__" "chomp"
4710 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
4711 ;; "eval" "exists" "for" "foreach" "format" "goto"
4712 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
4713 ;; "no" "package" "pop" "pos" "print" "printf" "push"
4714 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
4715 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
4716 ;; "undef" "unless" "unshift" "untie" "until" "use"
4717 ;; "while" "y"
4718 "AUTOLOAD\\|BEGIN\\|CHECK\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
4719 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
4720 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|INIT\\|if\\|keys\\|"
4721 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|our\\|"
4722 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
4723 "q\\(\\|q\\|w\\|x\\|r\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
4724 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
4725 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
4726 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
4727 "\\|[sm]" ; Added manually
4728 "\\)\\>") 2 'cperl-nonoverridable)
4729 ;; (mapconcat 'identity
4730 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
4731 ;; "#include" "#define" "#undef")
4732 ;; "\\|")
4733 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
4734 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
4735 '("\\<sub[ \t]+\\([^ \t{;()]+\\)[ \t]*\\(([^()]*)[ \t]*\\)?[#{\n]" 1
4736 font-lock-function-name-face)
4737 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
4738 2 font-lock-function-name-face)
4739 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
4740 1 font-lock-function-name-face)
4741 (cond ((featurep 'font-lock-extra)
4742 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
4743 (2 font-lock-string-face t)
4744 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
4745 (font-lock-anchored
4746 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
4747 (2 font-lock-string-face t)
4748 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
4749 nil nil
4750 (1 font-lock-string-face t))))
4751 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
4752 2 font-lock-string-face t)))
4753 '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
4754 font-lock-string-face t)
4755 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
4756 font-lock-constant-face) ; labels
4757 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
4758 2 font-lock-constant-face)
4759 ;; Uncomment to get perl-mode-like vars
4760 ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
4761 ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
4762 ;;; (2 (cons font-lock-variable-name-face '(underline))))
4763 (cond ((featurep 'font-lock-extra)
4764 '("^[ \t]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
4765 (3 font-lock-variable-name-face)
4766 (4 '(another 4 nil
4767 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
4768 (1 font-lock-variable-name-face)
4769 (2 '(restart 2 nil) nil t)))
4770 nil t))) ; local variables, multiple
4771 (font-lock-anchored
4772 '("^[ \t{}]*\\(my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
4773 (3 font-lock-variable-name-face)
4774 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)"
4775 nil nil
4776 (1 font-lock-variable-name-face))))
4777 (t '("^[ \t{}]*\\(my\\|local\\our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
4778 3 font-lock-variable-name-face)))
4779 '("\\<for\\(each\\)?\\([ \t]+\\(my\\|local\\|our\\)\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
4780 4 font-lock-variable-name-face)
4781 ;; Avoid $!, and s!!, qq!! etc. when not fontifying syntaxically
4782 '("\\(?:^\\|[^smywqrx$]\\)\\(!\\)" 1 font-lock-negation-char-face)
4783 '("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)))
4784 (setq
4785 t-font-lock-keywords-1
4786 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
4787 (not cperl-xemacs-p) ; not yet as of XEmacs 19.12
4789 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
4790 (if (eq (char-after (match-beginning 2)) ?%)
4791 'cperl-hash
4792 'cperl-array)
4793 t) ; arrays and hashes
4794 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
4796 (if (= (- (match-end 2) (match-beginning 2)) 1)
4797 (if (eq (char-after (match-beginning 3)) ?{)
4798 'cperl-hash
4799 'cperl-array) ; arrays and hashes
4800 font-lock-variable-name-face) ; Just to put something
4802 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
4803 ;;; Too much noise from \s* @s[ and friends
4804 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
4805 ;;(3 font-lock-function-name-face t t)
4806 ;;(4
4807 ;; (if (cperl-slash-is-regexp)
4808 ;; font-lock-function-name-face 'default) nil t))
4810 (if cperl-highlight-variables-indiscriminately
4811 (setq t-font-lock-keywords-1
4812 (append t-font-lock-keywords-1
4813 (list '("[$*]{?\\(\\sw+\\)" 1
4814 font-lock-variable-name-face)))))
4815 (setq cperl-font-lock-keywords-1
4816 (if cperl-syntaxify-by-font-lock
4817 (cons 'cperl-fontify-update
4818 t-font-lock-keywords)
4819 t-font-lock-keywords)
4820 cperl-font-lock-keywords cperl-font-lock-keywords-1
4821 cperl-font-lock-keywords-2 (append
4822 cperl-font-lock-keywords-1
4823 t-font-lock-keywords-1)))
4824 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
4825 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
4826 (eval ; Avoid a warning
4827 '(font-lock-require-faces
4828 (list
4829 ;; Color-light Color-dark Gray-light Gray-dark Mono
4830 (list 'font-lock-comment-face
4831 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
4833 [nil nil t t t]
4834 [nil nil t t t]
4835 nil)
4836 (list 'font-lock-string-face
4837 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
4840 [nil nil t t t]
4841 nil)
4842 (list 'font-lock-function-name-face
4843 (vector
4844 "Blue" "LightSkyBlue" "Gray50" "LightGray"
4845 (cdr (assq 'background-color ; if mono
4846 (frame-parameters))))
4847 (vector
4848 nil nil nil nil
4849 (cdr (assq 'foreground-color ; if mono
4850 (frame-parameters))))
4851 [nil nil t t t]
4853 nil)
4854 (list 'font-lock-variable-name-face
4855 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
4857 [nil nil t t t]
4858 [nil nil t t t]
4859 nil)
4860 (list 'font-lock-type-face
4861 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
4863 [nil nil t t t]
4865 [nil nil t t t])
4866 (list 'font-lock-constant-face
4867 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
4869 [nil nil t t t]
4871 [nil nil t t t])
4872 (list 'cperl-nonoverridable
4873 ["chartreuse3" ("orchid1" "orange")
4874 nil "Gray80"]
4875 [nil nil "gray90"]
4876 [nil nil nil t t]
4877 [nil nil t t]
4878 [nil nil t t t])
4879 (list 'cperl-array
4880 ["blue" "yellow" nil "Gray80"]
4881 ["lightyellow2" ("navy" "os2blue" "darkgreen")
4882 "gray90"]
4885 nil)
4886 (list 'cperl-hash
4887 ["red" "red" nil "Gray80"]
4888 ["lightyellow2" ("navy" "os2blue" "darkgreen")
4889 "gray90"]
4892 nil))))
4893 ;; Do it the dull way, without choose-color
4894 (defvar cperl-guessed-background nil
4895 "Display characteristics as guessed by cperl.")
4896 ;; (or (fboundp 'x-color-defined-p)
4897 ;; (defalias 'x-color-defined-p
4898 ;; (cond ((fboundp 'color-defined-p) 'color-defined-p)
4899 ;; ;; XEmacs >= 19.12
4900 ;; ((fboundp 'valid-color-name-p) 'valid-color-name-p)
4901 ;; ;; XEmacs 19.11
4902 ;; (t 'x-valid-color-name-p))))
4903 (cperl-force-face font-lock-constant-face
4904 "Face for constant and label names")
4905 (cperl-force-face font-lock-variable-name-face
4906 "Face for variable names")
4907 (cperl-force-face font-lock-type-face
4908 "Face for data types")
4909 (cperl-force-face cperl-nonoverridable
4910 "Face for data types from another group")
4911 (cperl-force-face font-lock-comment-face
4912 "Face for comments")
4913 (cperl-force-face font-lock-function-name-face
4914 "Face for function names")
4915 (cperl-force-face cperl-hash
4916 "Face for hashes")
4917 (cperl-force-face cperl-array
4918 "Face for arrays")
4919 ;;(defvar font-lock-constant-face 'font-lock-constant-face)
4920 ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
4921 ;;(or (boundp 'font-lock-type-face)
4922 ;; (defconst font-lock-type-face
4923 ;; 'font-lock-type-face
4924 ;; "Face to use for data types."))
4925 ;;(or (boundp 'cperl-nonoverridable-face)
4926 ;; (defconst cperl-nonoverridable-face
4927 ;; 'cperl-nonoverridable
4928 ;; "Face to use for data types from another group."))
4929 ;;(if (not cperl-xemacs-p) nil
4930 ;; (or (boundp 'font-lock-comment-face)
4931 ;; (defconst font-lock-comment-face
4932 ;; 'font-lock-comment-face
4933 ;; "Face to use for comments."))
4934 ;; (or (boundp 'font-lock-keyword-face)
4935 ;; (defconst font-lock-keyword-face
4936 ;; 'font-lock-keyword-face
4937 ;; "Face to use for keywords."))
4938 ;; (or (boundp 'font-lock-function-name-face)
4939 ;; (defconst font-lock-function-name-face
4940 ;; 'font-lock-function-name-face
4941 ;; "Face to use for function names.")))
4942 (if (and
4943 (not (cperl-is-face 'cperl-array))
4944 (cperl-is-face 'font-lock-emphasized-face))
4945 (copy-face 'font-lock-emphasized-face 'cperl-array))
4946 (if (and
4947 (not (cperl-is-face 'cperl-hash))
4948 (cperl-is-face 'font-lock-other-emphasized-face))
4949 (copy-face 'font-lock-other-emphasized-face 'cperl-hash))
4950 (if (and
4951 (not (cperl-is-face 'cperl-nonoverridable))
4952 (cperl-is-face 'font-lock-other-type-face))
4953 (copy-face 'font-lock-other-type-face 'cperl-nonoverridable))
4954 ;;(or (boundp 'cperl-hash-face)
4955 ;; (defconst cperl-hash-face
4956 ;; 'cperl-hash
4957 ;; "Face to use for hashes."))
4958 ;;(or (boundp 'cperl-array-face)
4959 ;; (defconst cperl-array-face
4960 ;; 'cperl-array
4961 ;; "Face to use for arrays."))
4962 ;; Here we try to guess background
4963 (let ((background
4964 (if (boundp 'font-lock-background-mode)
4965 font-lock-background-mode
4966 'light))
4967 (face-list (and (fboundp 'face-list) (face-list))))
4968 ;;;; (fset 'cperl-is-face
4969 ;;;; (cond ((fboundp 'find-face)
4970 ;;;; (symbol-function 'find-face))
4971 ;;;; (face-list
4972 ;;;; (function (lambda (face) (member face face-list))))
4973 ;;;; (t
4974 ;;;; (function (lambda (face) (boundp face))))))
4975 (defvar cperl-guessed-background
4976 (if (and (boundp 'font-lock-display-type)
4977 (eq font-lock-display-type 'grayscale))
4978 'gray
4979 background)
4980 "Background as guessed by CPerl mode")
4981 (and (not (cperl-is-face 'font-lock-constant-face))
4982 (cperl-is-face 'font-lock-reference-face)
4983 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
4984 (if (cperl-is-face 'font-lock-type-face) nil
4985 (copy-face 'default 'font-lock-type-face)
4986 (cond
4987 ((eq background 'light)
4988 (set-face-foreground 'font-lock-type-face
4989 (if (x-color-defined-p "seagreen")
4990 "seagreen"
4991 "sea green")))
4992 ((eq background 'dark)
4993 (set-face-foreground 'font-lock-type-face
4994 (if (x-color-defined-p "os2pink")
4995 "os2pink"
4996 "pink")))
4998 (set-face-background 'font-lock-type-face "gray90"))))
4999 (if (cperl-is-face 'cperl-nonoverridable)
5001 (copy-face 'font-lock-type-face 'cperl-nonoverridable)
5002 (cond
5003 ((eq background 'light)
5004 (set-face-foreground 'cperl-nonoverridable
5005 (if (x-color-defined-p "chartreuse3")
5006 "chartreuse3"
5007 "chartreuse")))
5008 ((eq background 'dark)
5009 (set-face-foreground 'cperl-nonoverridable
5010 (if (x-color-defined-p "orchid1")
5011 "orchid1"
5012 "orange")))))
5013 ;;; (if (cperl-is-face 'font-lock-other-emphasized-face) nil
5014 ;;; (copy-face 'bold-italic 'font-lock-other-emphasized-face)
5015 ;;; (cond
5016 ;;; ((eq background 'light)
5017 ;;; (set-face-background 'font-lock-other-emphasized-face
5018 ;;; (if (x-color-defined-p "lightyellow2")
5019 ;;; "lightyellow2"
5020 ;;; (if (x-color-defined-p "lightyellow")
5021 ;;; "lightyellow"
5022 ;;; "light yellow"))))
5023 ;;; ((eq background 'dark)
5024 ;;; (set-face-background 'font-lock-other-emphasized-face
5025 ;;; (if (x-color-defined-p "navy")
5026 ;;; "navy"
5027 ;;; (if (x-color-defined-p "darkgreen")
5028 ;;; "darkgreen"
5029 ;;; "dark green"))))
5030 ;;; (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
5031 ;;; (if (cperl-is-face 'font-lock-emphasized-face) nil
5032 ;;; (copy-face 'bold 'font-lock-emphasized-face)
5033 ;;; (cond
5034 ;;; ((eq background 'light)
5035 ;;; (set-face-background 'font-lock-emphasized-face
5036 ;;; (if (x-color-defined-p "lightyellow2")
5037 ;;; "lightyellow2"
5038 ;;; "lightyellow")))
5039 ;;; ((eq background 'dark)
5040 ;;; (set-face-background 'font-lock-emphasized-face
5041 ;;; (if (x-color-defined-p "navy")
5042 ;;; "navy"
5043 ;;; (if (x-color-defined-p "darkgreen")
5044 ;;; "darkgreen"
5045 ;;; "dark green"))))
5046 ;;; (t (set-face-background 'font-lock-emphasized-face "gray90"))))
5047 (if (cperl-is-face 'font-lock-variable-name-face) nil
5048 (copy-face 'italic 'font-lock-variable-name-face))
5049 (if (cperl-is-face 'font-lock-constant-face) nil
5050 (copy-face 'italic 'font-lock-constant-face))))
5051 (setq cperl-faces-init t))
5052 (error (message "cperl-init-faces (ignored): %s" errs))))
5055 (defun cperl-ps-print-init ()
5056 "Initialization of `ps-print' components for faces used in CPerl."
5057 (eval-after-load "ps-print"
5058 '(setq ps-bold-faces
5059 ;; font-lock-variable-name-face
5060 ;; font-lock-constant-face
5061 (append '(cperl-array cperl-hash)
5062 ps-bold-faces)
5063 ps-italic-faces
5064 ;; font-lock-constant-face
5065 (append '(cperl-nonoverridable cperl-hash)
5066 ps-italic-faces)
5067 ps-underlined-faces
5068 ;; font-lock-type-face
5069 (append '(cperl-array cperl-hash underline cperl-nonoverridable)
5070 ps-underlined-faces))))
5072 (defvar ps-print-face-extension-alist)
5074 (defun cperl-ps-print (&optional file)
5075 "Pretty-print in CPerl style.
5076 If optional argument FILE is an empty string, prints to printer, otherwise
5077 to the file FILE. If FILE is nil, prompts for a file name.
5079 Style of printout regulated by the variable `cperl-ps-print-face-properties'."
5080 (interactive)
5081 (or file
5082 (setq file (read-from-minibuffer
5083 "Print to file (if empty - to printer): "
5084 (concat (buffer-file-name) ".ps")
5085 nil nil 'file-name-history)))
5086 (or (> (length file) 0)
5087 (setq file nil))
5088 (require 'ps-print) ; To get ps-print-face-extension-alist
5089 (let ((ps-print-color-p t)
5090 (ps-print-face-extension-alist ps-print-face-extension-alist))
5091 (cperl-ps-extend-face-list cperl-ps-print-face-properties)
5092 (ps-print-buffer-with-faces file)))
5094 ;;; (defun cperl-ps-print-init ()
5095 ;;; "Initialization of `ps-print' components for faces used in CPerl."
5096 ;;; ;; Guard against old versions
5097 ;;; (defvar ps-underlined-faces nil)
5098 ;;; (defvar ps-bold-faces nil)
5099 ;;; (defvar ps-italic-faces nil)
5100 ;;; (setq ps-bold-faces
5101 ;;; (append '(font-lock-emphasized-face
5102 ;;; cperl-array
5103 ;;; font-lock-keyword-face
5104 ;;; font-lock-variable-name-face
5105 ;;; font-lock-constant-face
5106 ;;; font-lock-reference-face
5107 ;;; font-lock-other-emphasized-face
5108 ;;; cperl-hash)
5109 ;;; ps-bold-faces))
5110 ;;; (setq ps-italic-faces
5111 ;;; (append '(cperl-nonoverridable
5112 ;;; font-lock-constant-face
5113 ;;; font-lock-reference-face
5114 ;;; font-lock-other-emphasized-face
5115 ;;; cperl-hash)
5116 ;;; ps-italic-faces))
5117 ;;; (setq ps-underlined-faces
5118 ;;; (append '(font-lock-emphasized-face
5119 ;;; cperl-array
5120 ;;; font-lock-other-emphasized-face
5121 ;;; cperl-hash
5122 ;;; cperl-nonoverridable font-lock-type-face)
5123 ;;; ps-underlined-faces))
5124 ;;; (cons 'font-lock-type-face ps-underlined-faces))
5127 (if (cperl-enable-font-lock) (cperl-windowed-init))
5129 (defconst cperl-styles-entries
5130 '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset
5131 cperl-label-offset cperl-extra-newline-before-brace
5132 cperl-merge-trailing-else
5133 cperl-continued-statement-offset))
5135 (defconst cperl-style-alist
5136 '(("CPerl" ; =GNU without extra-newline-before-brace
5137 (cperl-indent-level . 2)
5138 (cperl-brace-offset . 0)
5139 (cperl-continued-brace-offset . 0)
5140 (cperl-label-offset . -2)
5141 (cperl-extra-newline-before-brace . nil)
5142 (cperl-merge-trailing-else . t)
5143 (cperl-continued-statement-offset . 2))
5144 ("PerlStyle" ; CPerl with 4 as indent
5145 (cperl-indent-level . 4)
5146 (cperl-brace-offset . 0)
5147 (cperl-continued-brace-offset . 0)
5148 (cperl-label-offset . -4)
5149 (cperl-extra-newline-before-brace . nil)
5150 (cperl-merge-trailing-else . t)
5151 (cperl-continued-statement-offset . 4))
5152 ("GNU"
5153 (cperl-indent-level . 2)
5154 (cperl-brace-offset . 0)
5155 (cperl-continued-brace-offset . 0)
5156 (cperl-label-offset . -2)
5157 (cperl-extra-newline-before-brace . t)
5158 (cperl-merge-trailing-else . nil)
5159 (cperl-continued-statement-offset . 2))
5160 ("K&R"
5161 (cperl-indent-level . 5)
5162 (cperl-brace-offset . 0)
5163 (cperl-continued-brace-offset . -5)
5164 (cperl-label-offset . -5)
5165 ;;(cperl-extra-newline-before-brace . nil) ; ???
5166 (cperl-merge-trailing-else . nil)
5167 (cperl-continued-statement-offset . 5))
5168 ("BSD"
5169 (cperl-indent-level . 4)
5170 (cperl-brace-offset . 0)
5171 (cperl-continued-brace-offset . -4)
5172 (cperl-label-offset . -4)
5173 ;;(cperl-extra-newline-before-brace . nil) ; ???
5174 (cperl-continued-statement-offset . 4))
5175 ("C++"
5176 (cperl-indent-level . 4)
5177 (cperl-brace-offset . 0)
5178 (cperl-continued-brace-offset . -4)
5179 (cperl-label-offset . -4)
5180 (cperl-continued-statement-offset . 4)
5181 (cperl-merge-trailing-else . nil)
5182 (cperl-extra-newline-before-brace . t))
5183 ("Current")
5184 ("Whitesmith"
5185 (cperl-indent-level . 4)
5186 (cperl-brace-offset . 0)
5187 (cperl-continued-brace-offset . 0)
5188 (cperl-label-offset . -4)
5189 ;;(cperl-extra-newline-before-brace . nil) ; ???
5190 (cperl-continued-statement-offset . 4)))
5191 "(Experimental) list of variables to set to get a particular indentation style.
5192 Should be used via `cperl-set-style' or via Perl menu.")
5194 (defun cperl-set-style (style)
5195 "Set CPerl mode variables to use one of several different indentation styles.
5196 The arguments are a string representing the desired style.
5197 The list of styles is in `cperl-style-alist', available styles
5198 are GNU, K&R, BSD, C++ and Whitesmith.
5200 The current value of style is memorized (unless there is a memorized
5201 data already), may be restored by `cperl-set-style-back'.
5203 Chosing \"Current\" style will not change style, so this may be used for
5204 side-effect of memorizing only."
5205 (interactive
5206 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
5207 cperl-style-alist)))
5208 (list (completing-read "Enter style: " list nil 'insist))))
5209 (or cperl-old-style
5210 (setq cperl-old-style
5211 (mapcar (function
5212 (lambda (name)
5213 (cons name (eval name))))
5214 cperl-styles-entries)))
5215 (let ((style (cdr (assoc style cperl-style-alist))) setting str sym)
5216 (while style
5217 (setq setting (car style) style (cdr style))
5218 (set (car setting) (cdr setting)))))
5220 (defun cperl-set-style-back ()
5221 "Restore a style memorized by `cperl-set-style'."
5222 (interactive)
5223 (or cperl-old-style (error "The style was not changed"))
5224 (let (setting)
5225 (while cperl-old-style
5226 (setq setting (car cperl-old-style)
5227 cperl-old-style (cdr cperl-old-style))
5228 (set (car setting) (cdr setting)))))
5230 (defun cperl-check-syntax ()
5231 (interactive)
5232 (require 'mode-compile)
5233 (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc")))
5234 (eval '(mode-compile)))) ; Avoid a warning
5236 (defun cperl-info-buffer (type)
5237 ;; Returns buffer with documentation. Creates if missing.
5238 ;; If TYPE, this vars buffer.
5239 ;; Special care is taken to not stomp over an existing info buffer
5240 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
5241 (info (get-buffer bname))
5242 (oldbuf (get-buffer "*info*")))
5243 (if info info
5244 (save-window-excursion
5245 ;; Get Info running
5246 (require 'info)
5247 (cond (oldbuf
5248 (set-buffer oldbuf)
5249 (rename-buffer "*info-perl-tmp*")))
5250 (save-window-excursion
5251 (info))
5252 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
5253 (set-buffer "*info*")
5254 (rename-buffer bname)
5255 (cond (oldbuf
5256 (set-buffer "*info-perl-tmp*")
5257 (rename-buffer "*info*")
5258 (set-buffer bname)))
5259 (make-local-variable 'window-min-height)
5260 (setq window-min-height 2)
5261 (current-buffer)))))
5263 (defun cperl-word-at-point (&optional p)
5264 "Return the word at point or at P."
5265 (save-excursion
5266 (if p (goto-char p))
5267 (or (cperl-word-at-point-hard)
5268 (progn
5269 (require 'etags)
5270 (funcall (or (and (boundp 'find-tag-default-function)
5271 find-tag-default-function)
5272 (get major-mode 'find-tag-default-function)
5273 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
5274 ;; automatically used within `find-tag-default':
5275 'find-tag-default))))))
5277 (defun cperl-info-on-command (command)
5278 "Show documentation for Perl command COMMAND in other window.
5279 If perl-info buffer is shown in some frame, uses this frame.
5280 Customized by setting variables `cperl-shrink-wrap-info-frame',
5281 `cperl-max-help-size'."
5282 (interactive
5283 (let* ((default (cperl-word-at-point))
5284 (read (read-string
5285 (format "Find doc for Perl function (default %s): "
5286 default))))
5287 (list (if (equal read "")
5288 default
5289 read))))
5291 (let ((buffer (current-buffer))
5292 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
5293 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
5294 max-height char-height buf-list)
5295 (if (string-match "^-[a-zA-Z]$" command)
5296 (setq cmd-desc "^-X[ \t\n]"))
5297 (setq isvar (string-match "^[$@%]" command)
5298 buf (cperl-info-buffer isvar)
5299 iniwin (selected-window)
5300 fr1 (window-frame iniwin))
5301 (set-buffer buf)
5302 (goto-char (point-min))
5303 (or isvar
5304 (progn (re-search-forward "^-X[ \t\n]")
5305 (forward-line -1)))
5306 (if (re-search-forward cmd-desc nil t)
5307 (progn
5308 ;; Go back to beginning of the group (ex, for qq)
5309 (if (re-search-backward "^[ \t\n\f]")
5310 (forward-line 1))
5311 (beginning-of-line)
5312 ;; Get some of
5313 (setq pos (point)
5314 buf-list (list buf "*info-perl-var*" "*info-perl*"))
5315 (while (and (not win) buf-list)
5316 (setq win (get-buffer-window (car buf-list) t))
5317 (setq buf-list (cdr buf-list)))
5318 (or (not win)
5319 (eq (window-buffer win) buf)
5320 (set-window-buffer win buf))
5321 (and win (setq fr2 (window-frame win)))
5322 (if (or (not fr2) (eq fr1 fr2))
5323 (pop-to-buffer buf)
5324 (special-display-popup-frame buf) ; Make it visible
5325 (select-window win))
5326 (goto-char pos) ; Needed (?!).
5327 ;; Resize
5328 (setq iniheight (window-height)
5329 frheight (frame-height)
5330 not-loner (< iniheight (1- frheight))) ; Are not alone
5331 (cond ((if not-loner cperl-max-help-size
5332 cperl-shrink-wrap-info-frame)
5333 (setq height
5334 (+ 2
5335 (count-lines
5337 (save-excursion
5338 (if (re-search-forward
5339 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
5340 (match-beginning 0) (point-max)))))
5341 max-height
5342 (if not-loner
5343 (/ (* (- frheight 3) cperl-max-help-size) 100)
5344 (setq char-height (frame-char-height))
5345 ;; Non-functioning under OS/2:
5346 (if (eq char-height 1) (setq char-height 18))
5347 ;; Title, menubar, + 2 for slack
5348 (- (/ (x-display-pixel-height) char-height) 4)))
5349 (if (> height max-height) (setq height max-height))
5350 ;;(message "was %s doing %s" iniheight height)
5351 (if not-loner
5352 (enlarge-window (- height iniheight))
5353 (set-frame-height (window-frame win) (1+ height)))))
5354 (set-window-start (selected-window) pos))
5355 (message "No entry for %s found." command))
5356 ;;(pop-to-buffer buffer)
5357 (select-window iniwin)))
5359 (defun cperl-info-on-current-command ()
5360 "Show documentation for Perl command at point in other window."
5361 (interactive)
5362 (cperl-info-on-command (cperl-word-at-point)))
5364 (defun cperl-imenu-info-imenu-search ()
5365 (if (looking-at "^-X[ \t\n]") nil
5366 (re-search-backward
5367 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
5368 (forward-line 1)))
5370 (defun cperl-imenu-info-imenu-name ()
5371 (buffer-substring
5372 (match-beginning 1) (match-end 1)))
5374 (defun cperl-imenu-on-info ()
5375 (interactive)
5376 (let* ((buffer (current-buffer))
5377 imenu-create-index-function
5378 imenu-prev-index-position-function
5379 imenu-extract-index-name-function
5380 (index-item (save-restriction
5381 (save-window-excursion
5382 (set-buffer (cperl-info-buffer nil))
5383 (setq imenu-create-index-function
5384 'imenu-default-create-index-function
5385 imenu-prev-index-position-function
5386 'cperl-imenu-info-imenu-search
5387 imenu-extract-index-name-function
5388 'cperl-imenu-info-imenu-name)
5389 (imenu-choose-buffer-index)))))
5390 (and index-item
5391 (progn
5392 (push-mark)
5393 (pop-to-buffer "*info-perl*")
5394 (cond
5395 ((markerp (cdr index-item))
5396 (goto-char (marker-position (cdr index-item))))
5398 (goto-char (cdr index-item))))
5399 (set-window-start (selected-window) (point))
5400 (pop-to-buffer buffer)))))
5402 (defun cperl-lineup (beg end &optional step minshift)
5403 "Lineup construction in a region.
5404 Beginning of region should be at the start of a construction.
5405 All first occurrences of this construction in the lines that are
5406 partially contained in the region are lined up at the same column.
5408 MINSHIFT is the minimal amount of space to insert before the construction.
5409 STEP is the tabwidth to position constructions.
5410 If STEP is nil, `cperl-lineup-step' will be used
5411 \(or `cperl-indent-level', if `cperl-lineup-step' is nil).
5412 Will not move the position at the start to the left."
5413 (interactive "r")
5414 (let (search col tcol seen b e)
5415 (save-excursion
5416 (goto-char end)
5417 (end-of-line)
5418 (setq end (point-marker))
5419 (goto-char beg)
5420 (skip-chars-forward " \t\f")
5421 (setq beg (point-marker))
5422 (indent-region beg end nil)
5423 (goto-char beg)
5424 (setq col (current-column))
5425 (if (looking-at "[a-zA-Z0-9_]")
5426 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
5427 (setq search
5428 (concat "\\<"
5429 (regexp-quote
5430 (buffer-substring (match-beginning 0)
5431 (match-end 0))) "\\>"))
5432 (error "Cannot line up in a middle of the word"))
5433 (if (looking-at "$")
5434 (error "Cannot line up end of line"))
5435 (setq search (regexp-quote (char-to-string (following-char)))))
5436 (setq step (or step cperl-lineup-step cperl-indent-level))
5437 (or minshift (setq minshift 1))
5438 (while (progn
5439 (beginning-of-line 2)
5440 (and (< (point) end)
5441 (re-search-forward search end t)
5442 (goto-char (match-beginning 0))))
5443 (setq tcol (current-column) seen t)
5444 (if (> tcol col) (setq col tcol)))
5445 (or seen
5446 (error "The construction to line up occurred only once"))
5447 (goto-char beg)
5448 (setq col (+ col minshift))
5449 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
5450 (while
5451 (progn
5452 (setq e (point))
5453 (skip-chars-backward " \t")
5454 (delete-region (point) e)
5455 (indent-to-column col) ;(make-string (- col (current-column)) ?\s))
5456 (beginning-of-line 2)
5457 (and (< (point) end)
5458 (re-search-forward search end t)
5459 (goto-char (match-beginning 0)))))))) ; No body
5461 (defun cperl-etags (&optional add all files)
5462 "Run etags with appropriate options for Perl files.
5463 If optional argument ALL is `recursive', will process Perl files
5464 in subdirectories too."
5465 (interactive)
5466 (let ((cmd "etags")
5467 (args '("-l" "none" "-r" "/\\<\\(package\\|sub\\)[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([{#]\\|$\\)\\)/\\4/"))
5468 res)
5469 (if add (setq args (cons "-a" args)))
5470 (or files (setq files (list buffer-file-name)))
5471 (cond
5472 ((eq all 'recursive)
5473 ;;(error "Not implemented: recursive")
5474 (setq args (append (list "-e"
5475 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
5476 use File::Find;
5477 find(\\&wanted, '.');
5478 exec @ARGV;"
5479 cmd) args)
5480 cmd "perl"))
5481 (all
5482 ;;(error "Not implemented: all")
5483 (setq args (append (list "-e"
5484 "push @ARGV, <*.PL *.pl *.pm>;
5485 exec @ARGV;"
5486 cmd) args)
5487 cmd "perl"))
5489 (setq args (append args files))))
5490 (setq res (apply 'call-process cmd nil nil nil args))
5491 (or (eq res 0)
5492 (message "etags returned \"%s\"" res))))
5494 (defun cperl-toggle-auto-newline ()
5495 "Toggle the state of `cperl-auto-newline'."
5496 (interactive)
5497 (setq cperl-auto-newline (not cperl-auto-newline))
5498 (message "Newlines will %sbe auto-inserted now."
5499 (if cperl-auto-newline "" "not ")))
5501 (defun cperl-toggle-abbrev ()
5502 "Toggle the state of automatic keyword expansion in CPerl mode."
5503 (interactive)
5504 (abbrev-mode (if abbrev-mode 0 1))
5505 (message "Perl control structure will %sbe auto-inserted now."
5506 (if abbrev-mode "" "not ")))
5509 (defun cperl-toggle-electric ()
5510 "Toggle the state of parentheses doubling in CPerl mode."
5511 (interactive)
5512 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
5513 (message "Parentheses will %sbe auto-doubled now."
5514 (if (cperl-val 'cperl-electric-parens) "" "not ")))
5516 (defun cperl-toggle-autohelp ()
5517 "Toggle the state of Auto-Help on Perl constructs (put in the message area).
5518 Delay of auto-help controlled by `cperl-lazy-help-time'."
5519 (interactive)
5520 (if (fboundp 'run-with-idle-timer)
5521 (progn
5522 (if cperl-lazy-installed
5523 (cperl-lazy-unstall)
5524 (cperl-lazy-install))
5525 (message "Perl help messages will %sbe automatically shown now."
5526 (if cperl-lazy-installed "" "not ")))
5527 (message "Cannot automatically show Perl help messages - run-with-idle-timer missing.")))
5529 (defun cperl-toggle-construct-fix ()
5530 "Toggle whether `indent-region'/`indent-sexp' fix whitespace too."
5531 (interactive)
5532 (setq cperl-indent-region-fix-constructs
5533 (if cperl-indent-region-fix-constructs
5536 (message "indent-region/indent-sexp will %sbe automatically fix whitespace."
5537 (if cperl-indent-region-fix-constructs "" "not ")))
5539 ;;;; Tags file creation.
5541 (defvar cperl-tmp-buffer " *cperl-tmp*")
5543 (defun cperl-setup-tmp-buf ()
5544 (set-buffer (get-buffer-create cperl-tmp-buffer))
5545 (set-syntax-table cperl-mode-syntax-table)
5546 (buffer-disable-undo)
5547 (auto-fill-mode 0)
5548 (if cperl-use-syntax-table-text-property-for-tags
5549 (progn
5550 (make-local-variable 'parse-sexp-lookup-properties)
5551 ;; Do not introduce variable if not needed, we check it!
5552 (set 'parse-sexp-lookup-properties t))))
5554 (defun cperl-xsub-scan ()
5555 (require 'imenu)
5556 (let ((index-alist '())
5557 (prev-pos 0) index index1 name package prefix)
5558 (goto-char (point-min))
5559 ;; Search for the function
5560 (progn ;;save-match-data
5561 (while (re-search-forward
5562 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
5563 nil t)
5564 (cond
5565 ((match-beginning 2) ; SECTION
5566 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
5567 (goto-char (match-beginning 0))
5568 (skip-chars-forward " \t")
5569 (forward-char 1)
5570 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
5571 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
5572 (setq prefix nil)))
5573 ((not package) nil) ; C language section
5574 ((match-beginning 3) ; XSUB
5575 (goto-char (1+ (match-beginning 3)))
5576 (setq index (imenu-example--name-and-position))
5577 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
5578 (if (and prefix (string-match (concat "^" prefix) name))
5579 (setq name (substring name (length prefix))))
5580 (cond ((string-match "::" name) nil)
5582 (setq index1 (cons (concat package "::" name) (cdr index)))
5583 (push index1 index-alist)))
5584 (setcar index name)
5585 (push index index-alist))
5586 (t ; BOOT: section
5587 ;; (beginning-of-line)
5588 (setq index (imenu-example--name-and-position))
5589 (setcar index (concat package "::BOOT:"))
5590 (push index index-alist)))))
5591 index-alist))
5593 (defvar cperl-unreadable-ok nil)
5595 (defun cperl-find-tags (ifile xs topdir)
5596 (let ((b (get-buffer cperl-tmp-buffer)) ind lst elt pos ret rel
5597 (cperl-pod-here-fontify nil) f file)
5598 (save-excursion
5599 (if b (set-buffer b)
5600 (cperl-setup-tmp-buf))
5601 (erase-buffer)
5602 (condition-case err
5603 (setq file (car (insert-file-contents ifile)))
5604 (error (if cperl-unreadable-ok nil
5605 (if (y-or-n-p
5606 (format "File %s unreadable. Continue? " ifile))
5607 (setq cperl-unreadable-ok t)
5608 (error "Aborting: unreadable file %s" ifile)))))
5609 (if (not file)
5610 (message "Unreadable file %s" ifile)
5611 (message "Scanning file %s ..." file)
5612 (if (and cperl-use-syntax-table-text-property-for-tags
5613 (not xs))
5614 (condition-case err ; after __END__ may have garbage
5615 (cperl-find-pods-heres nil nil noninteractive)
5616 (error (message "While scanning for syntax: %s" err))))
5617 (if xs
5618 (setq lst (cperl-xsub-scan))
5619 (setq ind (cperl-imenu--create-perl-index))
5620 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
5621 (setq lst
5622 (mapcar
5623 (function
5624 (lambda (elt)
5625 (cond ((string-match "^[_a-zA-Z]" (car elt))
5626 (goto-char (cdr elt))
5627 (beginning-of-line) ; pos should be of the start of the line
5628 (list (car elt)
5629 (point)
5630 (1+ (count-lines 1 (point))) ; 1+ since at beg-o-l
5631 (buffer-substring (progn
5632 (goto-char (cdr elt))
5633 ;; After name now...
5634 (or (eolp) (forward-char 1))
5635 (point))
5636 (progn
5637 (beginning-of-line)
5638 (point))))))))
5639 lst))
5640 (erase-buffer)
5641 (while lst
5642 (setq elt (car lst) lst (cdr lst))
5643 (if elt
5644 (progn
5645 (insert (elt elt 3)
5647 (if (string-match "^package " (car elt))
5648 (substring (car elt) 8)
5649 (car elt) )
5651 (number-to-string (elt elt 2)) ; Line
5653 (number-to-string (1- (elt elt 1))) ; Char pos 0-based
5654 "\n")
5655 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
5656 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
5657 (elt elt 3)))
5658 ;; Need to insert the name without package as well
5659 (setq lst (cons (cons (substring (elt elt 3)
5660 (match-beginning 1)
5661 (match-end 1))
5662 (cdr elt))
5663 lst))))))
5664 (setq pos (point))
5665 (goto-char 1)
5666 (setq rel file)
5667 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
5668 (set-text-properties 0 (length rel) nil rel)
5669 (and (equal topdir (substring rel 0 (length topdir)))
5670 (setq rel (substring file (length topdir))))
5671 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
5672 (setq ret (buffer-substring 1 (point-max)))
5673 (erase-buffer)
5674 (or noninteractive
5675 (message "Scanning file %s finished" file))
5676 ret))))
5678 (defun cperl-add-tags-recurse-noxs ()
5679 "Add to TAGS data for Perl and XSUB files in the current directory and kids.
5680 Use as
5681 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
5682 -f cperl-add-tags-recurse
5684 (cperl-write-tags nil nil t t nil t))
5686 (defun cperl-add-tags-recurse ()
5687 "Add to TAGS file data for Perl files in the current directory and kids.
5688 Use as
5689 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
5690 -f cperl-add-tags-recurse
5692 (cperl-write-tags nil nil t t))
5694 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
5695 ;; If INBUFFER, do not select buffer, and do not save
5696 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
5697 (require 'etags)
5698 (if file nil
5699 (setq file (if dir default-directory (buffer-file-name)))
5700 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
5701 (or topdir
5702 (setq topdir default-directory))
5703 (let ((tags-file-name "TAGS")
5704 (case-fold-search (eq system-type 'emx))
5705 xs rel tm)
5706 (save-excursion
5707 (cond (inbuffer nil) ; Already there
5708 ((file-exists-p tags-file-name)
5709 (if cperl-xemacs-p
5710 (visit-tags-table-buffer)
5711 (visit-tags-table-buffer tags-file-name)))
5712 (t (set-buffer (find-file-noselect tags-file-name))))
5713 (cond
5714 (dir
5715 (cond ((eq erase 'ignore))
5716 (erase
5717 (erase-buffer)
5718 (setq erase 'ignore)))
5719 (let ((files
5720 (condition-case err
5721 (directory-files file t
5722 (if recurse nil cperl-scan-files-regexp)
5724 (error
5725 (if cperl-unreadable-ok nil
5726 (if (y-or-n-p
5727 (format "Directory %s unreadable. Continue? " file))
5728 (setq cperl-unreadable-ok t
5729 tm nil) ; Return empty list
5730 (error "Aborting: unreadable directory %s" file)))))))
5731 (mapcar (function
5732 (lambda (file)
5733 (cond
5734 ((string-match cperl-noscan-files-regexp file)
5735 nil)
5736 ((not (file-directory-p file))
5737 (if (string-match cperl-scan-files-regexp file)
5738 (cperl-write-tags file erase recurse nil t noxs topdir)))
5739 ((not recurse) nil)
5740 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
5741 files)))
5743 (setq xs (string-match "\\.xs$" file))
5744 (if (not (and xs noxs))
5745 (progn
5746 (cond ((eq erase 'ignore) (goto-char (point-max)))
5747 (erase (erase-buffer))
5749 (goto-char 1)
5750 (setq rel file)
5751 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
5752 (set-text-properties 0 (length rel) nil rel)
5753 (and (equal topdir (substring rel 0 (length topdir)))
5754 (setq rel (substring file (length topdir))))
5755 (if (search-forward (concat "\f\n" rel ",") nil t)
5756 (progn
5757 (search-backward "\f\n")
5758 (delete-region (point)
5759 (save-excursion
5760 (forward-char 1)
5761 (if (search-forward "\f\n"
5762 nil 'toend)
5763 (- (point) 2)
5764 (point-max)))))
5765 (goto-char (point-max)))))
5766 (insert (cperl-find-tags file xs topdir))))))
5767 (if inbuffer nil ; Delegate to the caller
5768 (save-buffer 0) ; No backup
5769 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
5770 (initialize-new-tags-table))))))
5772 (defvar cperl-tags-hier-regexp-list
5773 (concat
5774 "^\\("
5775 "\\(package\\)\\>"
5776 "\\|"
5777 "sub\\>[^\n]+::"
5778 "\\|"
5779 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
5780 "\\|"
5781 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
5782 "\\)"))
5784 (defvar cperl-hierarchy '(() ())
5785 "Global hierarchy of classes.")
5787 (defun cperl-tags-hier-fill ()
5788 ;; Suppose we are in a tag table cooked by cperl.
5789 (goto-char 1)
5790 (let (type pack name pos line chunk ord cons1 file str info fileind)
5791 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
5792 (setq pos (match-beginning 0)
5793 pack (match-beginning 2))
5794 (beginning-of-line)
5795 (if (looking-at (concat
5796 "\\([^\n]+\\)"
5797 "\C-?"
5798 "\\([^\n]+\\)"
5799 "\C-a"
5800 "\\([0-9]+\\)"
5802 "\\([0-9]+\\)"))
5803 (progn
5804 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
5805 name (buffer-substring (match-beginning 2) (match-end 2))
5806 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
5807 line (buffer-substring (match-beginning 3) (match-end 3))
5808 ord (if pack 1 0)
5809 file (file-of-tag)
5810 fileind (format "%s:%s" file line)
5811 ;; Moves to beginning of the next line:
5812 info (cperl-etags-snarf-tag file line))
5813 ;; Move back
5814 (forward-char -1)
5815 ;; Make new member of hierarchy name ==> file ==> pos if needed
5816 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
5817 ;; Name known
5818 (setcdr cons1 (cons (cons fileind (vector file info))
5819 (cdr cons1)))
5820 ;; First occurrence of the name, start alist
5821 (setq cons1 (cons name (list (cons fileind (vector file info)))))
5822 (if pack
5823 (setcar (cdr cperl-hierarchy)
5824 (cons cons1 (nth 1 cperl-hierarchy)))
5825 (setcar cperl-hierarchy
5826 (cons cons1 (car cperl-hierarchy)))))))
5827 (end-of-line))))
5829 (defun cperl-tags-hier-init (&optional update)
5830 "Show hierarchical menu of classes and methods.
5831 Finds info about classes by a scan of loaded TAGS files.
5832 Supposes that the TAGS files contain fully qualified function names.
5833 One may build such TAGS files from CPerl mode menu."
5834 (interactive)
5835 (require 'etags)
5836 (require 'imenu)
5837 (if (or update (null (nth 2 cperl-hierarchy)))
5838 (let ((remover (function (lambda (elt) ; (name (file1...) (file2..))
5839 (or (nthcdr 2 elt)
5840 ;; Only in one file
5841 (setcdr elt (cdr (nth 1 elt)))))))
5842 pack name cons1 to l1 l2 l3 l4 b)
5843 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
5844 (setq cperl-hierarchy (list l1 l2 l3))
5845 (if cperl-xemacs-p ; Not checked
5846 (progn
5847 (or tags-file-name
5848 ;; Does this work in XEmacs?
5849 (call-interactively 'visit-tags-table))
5850 (message "Updating list of classes...")
5851 (set-buffer (get-file-buffer tags-file-name))
5852 (cperl-tags-hier-fill))
5853 (or tags-table-list
5854 (call-interactively 'visit-tags-table))
5855 (mapcar
5856 (function
5857 (lambda (tagsfile)
5858 (message "Updating list of classes... %s" tagsfile)
5859 (set-buffer (get-file-buffer tagsfile))
5860 (cperl-tags-hier-fill)))
5861 tags-table-list)
5862 (message "Updating list of classes... postprocessing..."))
5863 (mapcar remover (car cperl-hierarchy))
5864 (mapcar remover (nth 1 cperl-hierarchy))
5865 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
5866 (cons "Methods: " (car cperl-hierarchy))))
5867 (cperl-tags-treeify to 1)
5868 (setcar (nthcdr 2 cperl-hierarchy)
5869 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
5870 (message "Updating list of classes: done, requesting display...")
5871 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
5873 (or (nth 2 cperl-hierarchy)
5874 (error "No items found"))
5875 (setq update
5876 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
5877 (if (if (fboundp 'display-popup-menus-p)
5878 (let ((f 'display-popup-menus-p))
5879 (funcall f))
5880 window-system)
5881 (x-popup-menu t (nth 2 cperl-hierarchy))
5882 (require 'tmm)
5883 (tmm-prompt (nth 2 cperl-hierarchy))))
5884 (if (and update (listp update))
5885 (progn (while (cdr update) (setq update (cdr update)))
5886 (setq update (car update)))) ; Get the last from the list
5887 (if (vectorp update)
5888 (progn
5889 (find-file (elt update 0))
5890 (cperl-etags-goto-tag-location (elt update 1))))
5891 (if (eq update -999) (cperl-tags-hier-init t)))
5893 (defun cperl-tags-treeify (to level)
5894 ;; cadr of `to' is read-write. On start it is a cons
5895 (let* ((regexp (concat "^\\(" (mapconcat
5896 'identity
5897 (make-list level "[_a-zA-Z0-9]+")
5898 "::")
5899 "\\)\\(::\\)?"))
5900 (packages (cdr (nth 1 to)))
5901 (methods (cdr (nth 2 to)))
5902 l1 head tail cons1 cons2 ord writeto packs recurse
5903 root-packages root-functions ms many_ms same_name ps
5904 (move-deeper
5905 (function
5906 (lambda (elt)
5907 (cond ((and (string-match regexp (car elt))
5908 (or (eq ord 1) (match-end 2)))
5909 (setq head (substring (car elt) 0 (match-end 1))
5910 tail (if (match-end 2) (substring (car elt)
5911 (match-end 2)))
5912 recurse t)
5913 (if (setq cons1 (assoc head writeto)) nil
5914 ;; Need to init new head
5915 (setcdr writeto (cons (list head (list "Packages: ")
5916 (list "Methods: "))
5917 (cdr writeto)))
5918 (setq cons1 (nth 1 writeto)))
5919 (setq cons2 (nth ord cons1)) ; Either packs or meths
5920 (setcdr cons2 (cons elt (cdr cons2))))
5921 ((eq ord 2)
5922 (setq root-functions (cons elt root-functions)))
5924 (setq root-packages (cons elt root-packages))))))))
5925 (setcdr to l1) ; Init to dynamic space
5926 (setq writeto to)
5927 (setq ord 1)
5928 (mapcar move-deeper packages)
5929 (setq ord 2)
5930 (mapcar move-deeper methods)
5931 (if recurse
5932 (mapcar (function (lambda (elt)
5933 (cperl-tags-treeify elt (1+ level))))
5934 (cdr to)))
5935 ;;Now clean up leaders with one child only
5936 (mapcar (function (lambda (elt)
5937 (if (not (and (listp (cdr elt))
5938 (eq (length elt) 2))) nil
5939 (setcar elt (car (nth 1 elt)))
5940 (setcdr elt (cdr (nth 1 elt))))))
5941 (cdr to))
5942 ;; Sort the roots of subtrees
5943 (if (default-value 'imenu-sort-function)
5944 (setcdr to
5945 (sort (cdr to) (default-value 'imenu-sort-function))))
5946 ;; Now add back functions removed from display
5947 (mapcar (function (lambda (elt)
5948 (setcdr to (cons elt (cdr to)))))
5949 (if (default-value 'imenu-sort-function)
5950 (nreverse
5951 (sort root-functions (default-value 'imenu-sort-function)))
5952 root-functions))
5953 ;; Now add back packages removed from display
5954 (mapcar (function (lambda (elt)
5955 (setcdr to (cons (cons (concat "package " (car elt))
5956 (cdr elt))
5957 (cdr to)))))
5958 (if (default-value 'imenu-sort-function)
5959 (nreverse
5960 (sort root-packages (default-value 'imenu-sort-function)))
5961 root-packages))))
5963 ;;;(x-popup-menu t
5964 ;;; '(keymap "Name1"
5965 ;;; ("Ret1" "aa")
5966 ;;; ("Head1" "ab"
5967 ;;; keymap "Name2"
5968 ;;; ("Tail1" "x") ("Tail2" "y"))))
5970 (defun cperl-list-fold (list name limit)
5971 (let (list1 list2 elt1 (num 0))
5972 (if (<= (length list) limit) list
5973 (setq list1 nil list2 nil)
5974 (while list
5975 (setq num (1+ num)
5976 elt1 (car list)
5977 list (cdr list))
5978 (if (<= num imenu-max-items)
5979 (setq list2 (cons elt1 list2))
5980 (setq list1 (cons (cons name
5981 (nreverse list2))
5982 list1)
5983 list2 (list elt1)
5984 num 1)))
5985 (nreverse (cons (cons name
5986 (nreverse list2))
5987 list1)))))
5989 (defun cperl-menu-to-keymap (menu &optional name)
5990 (let (list)
5991 (cons 'keymap
5992 (mapcar
5993 (function
5994 (lambda (elt)
5995 (cond ((listp (cdr elt))
5996 (setq list (cperl-list-fold
5997 (cdr elt) (car elt) imenu-max-items))
5998 (cons nil
5999 (cons (car elt)
6000 (cperl-menu-to-keymap list))))
6002 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
6003 (cperl-list-fold menu "Root" imenu-max-items)))))
6006 (defvar cperl-bad-style-regexp
6007 (mapconcat 'identity
6008 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
6009 "[-<>=+^&|]+[^- \t\n=+<>~]") ; sign+ char
6010 "\\|")
6011 "Finds places such that insertion of a whitespace may help a lot.")
6013 (defvar cperl-not-bad-style-regexp
6014 (mapconcat
6015 'identity
6016 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
6017 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
6018 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
6019 "<\\$?\\sw+\\(\\.\\sw+\\)?>" ; <IN> <stdin.h>
6020 "-[a-zA-Z][ \t]+[_$\"'`a-zA-Z]" ; -f file, -t STDIN
6021 "-[0-9]" ; -5
6022 "\\+\\+" ; ++var
6023 "--" ; --var
6024 ".->" ; a->b
6025 "->" ; a SPACE ->b
6026 "\\[-" ; a[-1]
6027 "\\\\[&$@*\\\\]" ; \&func
6028 "^=" ; =head
6029 "\\$." ; $|
6030 "<<[a-zA-Z_'\"`]" ; <<FOO, <<'FOO'
6031 "||"
6032 "&&"
6033 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
6034 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
6035 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
6036 ;;"[*/+-|&<.]+="
6038 "\\|")
6039 "If matches at the start of match found by `my-bad-c-style-regexp',
6040 insertion of a whitespace will not help.")
6042 (defvar found-bad)
6044 (defun cperl-find-bad-style ()
6045 "Find places in the buffer where insertion of a whitespace may help.
6046 Prompts user for insertion of spaces.
6047 Currently it is tuned to C and Perl syntax."
6048 (interactive)
6049 (let (found-bad (p (point)))
6050 (setq last-nonmenu-event 13) ; To disable popup
6051 (with-no-warnings ; It is useful to push the mark here.
6052 (beginning-of-buffer))
6053 (map-y-or-n-p "Insert space here? "
6054 (lambda (arg) (insert " "))
6055 'cperl-next-bad-style
6056 '("location" "locations" "insert a space into")
6057 '((?\C-r (lambda (arg)
6058 (let ((buffer-quit-function
6059 'exit-recursive-edit))
6060 (message "Exit with Esc Esc")
6061 (recursive-edit)
6062 t)) ; Consider acted upon
6063 "edit, exit with Esc Esc")
6064 (?e (lambda (arg)
6065 (let ((buffer-quit-function
6066 'exit-recursive-edit))
6067 (message "Exit with Esc Esc")
6068 (recursive-edit)
6069 t)) ; Consider acted upon
6070 "edit, exit with Esc Esc"))
6072 (if found-bad (goto-char found-bad)
6073 (goto-char p)
6074 (message "No appropriate place found"))))
6076 (defun cperl-next-bad-style ()
6077 (let (p (not-found t) (point (point)) found)
6078 (while (and not-found
6079 (re-search-forward cperl-bad-style-regexp nil 'to-end))
6080 (setq p (point))
6081 (goto-char (match-beginning 0))
6082 (if (or
6083 (looking-at cperl-not-bad-style-regexp)
6084 ;; Check for a < -b and friends
6085 (and (eq (following-char) ?\-)
6086 (save-excursion
6087 (skip-chars-backward " \t\n")
6088 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\( ?\[ ?\{))))
6089 ;; Now check for syntax type
6090 (save-match-data
6091 (setq found (point))
6092 (beginning-of-defun)
6093 (let ((pps (parse-partial-sexp (point) found)))
6094 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
6095 (goto-char (match-end 0))
6096 (goto-char (1- p))
6097 (setq not-found nil
6098 found-bad found)))
6099 (not not-found)))
6102 ;;; Getting help
6103 (defvar cperl-have-help-regexp
6104 ;;(concat "\\("
6105 (mapconcat
6106 'identity
6107 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
6108 "[$@]\\^[a-zA-Z]" ; Special variable
6109 "[$@][^ \n\t]" ; Special variable
6110 "-[a-zA-Z]" ; File test
6111 "\\\\[a-zA-Z0]" ; Special chars
6112 "^=[a-z][a-zA-Z0-9_]*" ; POD sections
6113 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
6114 "[a-zA-Z_0-9:]+" ; symbol or number
6115 "x="
6116 "#!")
6117 ;;"\\)\\|\\("
6118 "\\|")
6119 ;;"\\)"
6121 "Matches places in the buffer we can find help for.")
6123 (defvar cperl-message-on-help-error t)
6124 (defvar cperl-help-from-timer nil)
6126 (defun cperl-word-at-point-hard ()
6127 ;; Does not save-excursion
6128 ;; Get to the something meaningful
6129 (or (eobp) (eolp) (forward-char 1))
6130 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
6131 (save-excursion (beginning-of-line) (point))
6132 'to-beg)
6133 ;; (cond
6134 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
6135 ;; (skip-chars-backward " \n\t\r({[]});,")
6136 ;; (or (bobp) (backward-char 1))))
6137 ;; Try to backtrace
6138 (cond
6139 ((looking-at "[a-zA-Z0-9_:]") ; symbol
6140 (skip-chars-backward "a-zA-Z0-9_:")
6141 (cond
6142 ((and (eq (preceding-char) ?^) ; $^I
6143 (eq (char-after (- (point) 2)) ?\$))
6144 (forward-char -2))
6145 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
6146 (forward-char -1))
6147 ((and (eq (preceding-char) ?\=)
6148 (eq (current-column) 1))
6149 (forward-char -1))) ; =head1
6150 (if (and (eq (preceding-char) ?\<)
6151 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
6152 (forward-char -1)))
6153 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
6154 (forward-char -1))
6155 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
6156 (forward-char -1))
6157 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
6158 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
6159 (cond
6160 ((and (eq (preceding-char) ?\$)
6161 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
6162 (forward-char -1))
6163 ((and (eq (following-char) ?\>)
6164 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
6165 (save-excursion
6166 (forward-sexp -1)
6167 (and (eq (preceding-char) ?\<)
6168 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
6169 (search-backward "<"))))
6170 ((and (eq (following-char) ?\$)
6171 (eq (preceding-char) ?\<)
6172 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
6173 (forward-char -1)))
6174 (if (looking-at cperl-have-help-regexp)
6175 (buffer-substring (match-beginning 0) (match-end 0))))
6177 (defun cperl-get-help ()
6178 "Get one-line docs on the symbol at the point.
6179 The data for these docs is a little bit obsolete and may be in fact longer
6180 than a line. Your contribution to update/shorten it is appreciated."
6181 (interactive)
6182 (save-match-data ; May be called "inside" query-replace
6183 (save-excursion
6184 (let ((word (cperl-word-at-point-hard)))
6185 (if word
6186 (if (and cperl-help-from-timer ; Bail out if not in mainland
6187 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
6188 (or (memq (get-text-property (point) 'face)
6189 '(font-lock-comment-face font-lock-string-face))
6190 (memq (get-text-property (point) 'syntax-type)
6191 '(pod here-doc format))))
6193 (cperl-describe-perl-symbol word))
6194 (if cperl-message-on-help-error
6195 (message "Nothing found for %s..."
6196 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
6198 ;;; Stolen from perl-descr.el by Johan Vromans:
6200 (defvar cperl-doc-buffer " *perl-doc*"
6201 "Where the documentation can be found.")
6203 (defun cperl-describe-perl-symbol (val)
6204 "Display the documentation of symbol at point, a Perl operator."
6205 (let ((enable-recursive-minibuffers t)
6206 args-file regexp)
6207 (cond
6208 ((string-match "^[&*][a-zA-Z_]" val)
6209 (setq val (concat (substring val 0 1) "NAME")))
6210 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
6211 (setq val (concat "@" (substring val 1 (match-end 1)))))
6212 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
6213 (setq val (concat "%" (substring val 1 (match-end 1)))))
6214 ((and (string= val "x") (string-match "^x=" val))
6215 (setq val "x="))
6216 ((string-match "^\\$[\C-a-\C-z]" val)
6217 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
6218 ((string-match "^CORE::" val)
6219 (setq val "CORE::"))
6220 ((string-match "^SUPER::" val)
6221 (setq val "SUPER::"))
6222 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
6223 (setq val "<NAME>")))
6224 (setq regexp (concat "^"
6225 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
6226 (regexp-quote val)
6227 "\\([ \t([/]\\|$\\)"))
6229 ;; get the buffer with the documentation text
6230 (cperl-switch-to-doc-buffer)
6232 ;; lookup in the doc
6233 (goto-char (point-min))
6234 (let ((case-fold-search nil))
6235 (list
6236 (if (re-search-forward regexp (point-max) t)
6237 (save-excursion
6238 (beginning-of-line 1)
6239 (let ((lnstart (point)))
6240 (end-of-line)
6241 (message "%s" (buffer-substring lnstart (point)))))
6242 (if cperl-message-on-help-error
6243 (message "No definition for %s" val)))))))
6245 (defvar cperl-short-docs 'please-ignore-this-line
6246 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
6247 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
6248 ... Range (list context); flip/flop [no flop when flip] (scalar context).
6249 ! ... Logical negation.
6250 ... != ... Numeric inequality.
6251 ... !~ ... Search pattern, substitution, or translation (negated).
6252 $! In numeric context: errno. In a string context: error string.
6253 $\" The separator which joins elements of arrays interpolated in strings.
6254 $# The output format for printed numbers. Default is %.15g or close.
6255 $$ Process number of this script. Changes in the fork()ed child process.
6256 $% The current page number of the currently selected output channel.
6258 The following variables are always local to the current block:
6260 $1 Match of the 1st set of parentheses in the last match (auto-local).
6261 $2 Match of the 2nd set of parentheses in the last match (auto-local).
6262 $3 Match of the 3rd set of parentheses in the last match (auto-local).
6263 $4 Match of the 4th set of parentheses in the last match (auto-local).
6264 $5 Match of the 5th set of parentheses in the last match (auto-local).
6265 $6 Match of the 6th set of parentheses in the last match (auto-local).
6266 $7 Match of the 7th set of parentheses in the last match (auto-local).
6267 $8 Match of the 8th set of parentheses in the last match (auto-local).
6268 $9 Match of the 9th set of parentheses in the last match (auto-local).
6269 $& The string matched by the last pattern match (auto-local).
6270 $' The string after what was matched by the last match (auto-local).
6271 $` The string before what was matched by the last match (auto-local).
6273 $( The real gid of this process.
6274 $) The effective gid of this process.
6275 $* Deprecated: Set to 1 to do multiline matching within a string.
6276 $+ The last bracket matched by the last search pattern.
6277 $, The output field separator for the print operator.
6278 $- The number of lines left on the page.
6279 $. The current input line number of the last filehandle that was read.
6280 $/ The input record separator, newline by default.
6281 $0 Name of the file containing the current perl script (read/write).
6282 $: String may be broken after these characters to fill ^-lines in a format.
6283 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
6284 $< The real uid of this process.
6285 $= The page length of the current output channel. Default is 60 lines.
6286 $> The effective uid of this process.
6287 $? The status returned by the last ``, pipe close or `system'.
6288 $@ The perl error message from the last eval or do @var{EXPR} command.
6289 $ARGV The name of the current file used with <> .
6290 $[ Deprecated: The index of the first element/char in an array/string.
6291 $\\ The output record separator for the print operator.
6292 $] The perl version string as displayed with perl -v.
6293 $^ The name of the current top-of-page format.
6294 $^A The current value of the write() accumulator for format() lines.
6295 $^D The value of the perl debug (-D) flags.
6296 $^E Information about the last system error other than that provided by $!.
6297 $^F The highest system file descriptor, ordinarily 2.
6298 $^H The current set of syntax checks enabled by `use strict'.
6299 $^I The value of the in-place edit extension (perl -i option).
6300 $^L What formats output to perform a formfeed. Default is \f.
6301 $^M A buffer for emergency memory allocation when running out of memory.
6302 $^O The operating system name under which this copy of Perl was built.
6303 $^P Internal debugging flag.
6304 $^T The time the script was started. Used by -A/-M/-C file tests.
6305 $^W True if warnings are requested (perl -w flag).
6306 $^X The name under which perl was invoked (argv[0] in C-speech).
6307 $_ The default input and pattern-searching space.
6308 $| Auto-flush after write/print on current output channel? Default 0.
6309 $~ The name of the current report format.
6310 ... % ... Modulo division.
6311 ... %= ... Modulo division assignment.
6312 %ENV Contains the current environment.
6313 %INC List of files that have been require-d or do-ne.
6314 %SIG Used to set signal handlers for various signals.
6315 ... & ... Bitwise and.
6316 ... && ... Logical and.
6317 ... &&= ... Logical and assignment.
6318 ... &= ... Bitwise and assignment.
6319 ... * ... Multiplication.
6320 ... ** ... Exponentiation.
6321 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
6322 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
6323 ... + ... Addition. +EXPR Makes EXPR into scalar context.
6324 ++ Auto-increment (magical on strings). ++EXPR EXPR++
6325 ... += ... Addition assignment.
6326 , Comma operator.
6327 ... - ... Subtraction.
6328 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
6329 ... -= ... Subtraction assignment.
6330 -A Access time in days since script started.
6331 -B File is a non-text (binary) file.
6332 -C Inode change time in days since script started.
6333 -M Age in days since script started.
6334 -O File is owned by real uid.
6335 -R File is readable by real uid.
6336 -S File is a socket .
6337 -T File is a text file.
6338 -W File is writable by real uid.
6339 -X File is executable by real uid.
6340 -b File is a block special file.
6341 -c File is a character special file.
6342 -d File is a directory.
6343 -e File exists .
6344 -f File is a plain file.
6345 -g File has setgid bit set.
6346 -k File has sticky bit set.
6347 -l File is a symbolic link.
6348 -o File is owned by effective uid.
6349 -p File is a named pipe (FIFO).
6350 -r File is readable by effective uid.
6351 -s File has non-zero size.
6352 -t Tests if filehandle (STDIN by default) is opened to a tty.
6353 -u File has setuid bit set.
6354 -w File is writable by effective uid.
6355 -x File is executable by effective uid.
6356 -z File has zero size.
6357 . Concatenate strings.
6358 .. Range (list context); flip/flop (scalar context) operator.
6359 .= Concatenate assignment strings
6360 ... / ... Division. /PATTERN/ioxsmg Pattern match
6361 ... /= ... Division assignment.
6362 /PATTERN/ioxsmg Pattern match.
6363 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
6364 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
6365 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
6366 <> Reads line from union of files in @ARGV (= command line) and STDIN.
6367 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
6368 ... <= ... Numeric less than or equal to.
6369 ... <=> ... Numeric compare.
6370 ... = ... Assignment.
6371 ... == ... Numeric equality.
6372 ... =~ ... Search pattern, substitution, or translation
6373 ... > ... Numeric greater than.
6374 ... >= ... Numeric greater than or equal to.
6375 ... >> ... Bitwise shift right.
6376 ... >>= ... Bitwise shift right assignment.
6377 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
6378 ?PATTERN? One-time pattern match.
6379 @ARGV Command line arguments (not including the command name - see $0).
6380 @INC List of places to look for perl scripts during do/include/use.
6381 @_ Parameter array for subroutines; result of split() unless in list context.
6382 \\ Creates reference to what follows, like \$var, or quotes non-\w in strings.
6383 \\0 Octal char, e.g. \\033.
6384 \\E Case modification terminator. See \\Q, \\L, and \\U.
6385 \\L Lowercase until \\E . See also \l, lc.
6386 \\U Upcase until \\E . See also \u, uc.
6387 \\Q Quote metacharacters until \\E . See also quotemeta.
6388 \\a Alarm character (octal 007).
6389 \\b Backspace character (octal 010).
6390 \\c Control character, e.g. \\c[ .
6391 \\e Escape character (octal 033).
6392 \\f Formfeed character (octal 014).
6393 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
6394 \\n Newline character (octal 012 on most systems).
6395 \\r Return character (octal 015 on most systems).
6396 \\t Tab character (octal 011).
6397 \\u Upcase the next character. See also \\U and \\l, ucfirst.
6398 \\x Hex character, e.g. \\x1b.
6399 ... ^ ... Bitwise exclusive or.
6400 __END__ Ends program source.
6401 __DATA__ Ends program source.
6402 __FILE__ Current (source) filename.
6403 __LINE__ Current line in current source.
6404 __PACKAGE__ Current package.
6405 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
6406 ARGVOUT Output filehandle with -i flag.
6407 BEGIN { ... } Immediately executed (during compilation) piece of code.
6408 END { ... } Pseudo-subroutine executed after the script finishes.
6409 CHECK { ... } Pseudo-subroutine executed after the script is compiled.
6410 INIT { ... } Pseudo-subroutine executed before the script starts running.
6411 DATA Input filehandle for what follows after __END__ or __DATA__.
6412 accept(NEWSOCKET,GENERICSOCKET)
6413 alarm(SECONDS)
6414 atan2(X,Y)
6415 bind(SOCKET,NAME)
6416 binmode(FILEHANDLE)
6417 caller[(LEVEL)]
6418 chdir(EXPR)
6419 chmod(LIST)
6420 chop[(LIST|VAR)]
6421 chown(LIST)
6422 chroot(FILENAME)
6423 close(FILEHANDLE)
6424 closedir(DIRHANDLE)
6425 ... cmp ... String compare.
6426 connect(SOCKET,NAME)
6427 continue of { block } continue { block }. Is executed after `next' or at end.
6428 cos(EXPR)
6429 crypt(PLAINTEXT,SALT)
6430 dbmclose(%HASH)
6431 dbmopen(%HASH,DBNAME,MODE)
6432 defined(EXPR)
6433 delete($HASH{KEY})
6434 die(LIST)
6435 do { ... }|SUBR while|until EXPR executes at least once
6436 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
6437 dump LABEL
6438 each(%HASH)
6439 endgrent
6440 endhostent
6441 endnetent
6442 endprotoent
6443 endpwent
6444 endservent
6445 eof[([FILEHANDLE])]
6446 ... eq ... String equality.
6447 eval(EXPR) or eval { BLOCK }
6448 exec(LIST)
6449 exit(EXPR)
6450 exp(EXPR)
6451 fcntl(FILEHANDLE,FUNCTION,SCALAR)
6452 fileno(FILEHANDLE)
6453 flock(FILEHANDLE,OPERATION)
6454 for (EXPR;EXPR;EXPR) { ... }
6455 foreach [VAR] (@ARRAY) { ... }
6456 fork
6457 ... ge ... String greater than or equal.
6458 getc[(FILEHANDLE)]
6459 getgrent
6460 getgrgid(GID)
6461 getgrnam(NAME)
6462 gethostbyaddr(ADDR,ADDRTYPE)
6463 gethostbyname(NAME)
6464 gethostent
6465 getlogin
6466 getnetbyaddr(ADDR,ADDRTYPE)
6467 getnetbyname(NAME)
6468 getnetent
6469 getpeername(SOCKET)
6470 getpgrp(PID)
6471 getppid
6472 getpriority(WHICH,WHO)
6473 getprotobyname(NAME)
6474 getprotobynumber(NUMBER)
6475 getprotoent
6476 getpwent
6477 getpwnam(NAME)
6478 getpwuid(UID)
6479 getservbyname(NAME,PROTO)
6480 getservbyport(PORT,PROTO)
6481 getservent
6482 getsockname(SOCKET)
6483 getsockopt(SOCKET,LEVEL,OPTNAME)
6484 gmtime(EXPR)
6485 goto LABEL
6486 ... gt ... String greater than.
6487 hex(EXPR)
6488 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
6489 index(STR,SUBSTR[,OFFSET])
6490 int(EXPR)
6491 ioctl(FILEHANDLE,FUNCTION,SCALAR)
6492 join(EXPR,LIST)
6493 keys(%HASH)
6494 kill(LIST)
6495 last [LABEL]
6496 ... le ... String less than or equal.
6497 length(EXPR)
6498 link(OLDFILE,NEWFILE)
6499 listen(SOCKET,QUEUESIZE)
6500 local(LIST)
6501 localtime(EXPR)
6502 log(EXPR)
6503 lstat(EXPR|FILEHANDLE|VAR)
6504 ... lt ... String less than.
6505 m/PATTERN/iogsmx
6506 mkdir(FILENAME,MODE)
6507 msgctl(ID,CMD,ARG)
6508 msgget(KEY,FLAGS)
6509 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
6510 msgsnd(ID,MSG,FLAGS)
6511 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
6512 our VAR or our (VAR1,...) Lexically enable a global variable ($V, @A, or %H).
6513 ... ne ... String inequality.
6514 next [LABEL]
6515 oct(EXPR)
6516 open(FILEHANDLE[,EXPR])
6517 opendir(DIRHANDLE,EXPR)
6518 ord(EXPR) ASCII value of the first char of the string.
6519 pack(TEMPLATE,LIST)
6520 package NAME Introduces package context.
6521 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
6522 pop(ARRAY)
6523 print [FILEHANDLE] [(LIST)]
6524 printf [FILEHANDLE] (FORMAT,LIST)
6525 push(ARRAY,LIST)
6526 q/STRING/ Synonym for 'STRING'
6527 qq/STRING/ Synonym for \"STRING\"
6528 qx/STRING/ Synonym for `STRING`
6529 rand[(EXPR)]
6530 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
6531 readdir(DIRHANDLE)
6532 readlink(EXPR)
6533 recv(SOCKET,SCALAR,LEN,FLAGS)
6534 redo [LABEL]
6535 rename(OLDNAME,NEWNAME)
6536 require [FILENAME | PERL_VERSION]
6537 reset[(EXPR)]
6538 return(LIST)
6539 reverse(LIST)
6540 rewinddir(DIRHANDLE)
6541 rindex(STR,SUBSTR[,OFFSET])
6542 rmdir(FILENAME)
6543 s/PATTERN/REPLACEMENT/gieoxsm
6544 scalar(EXPR)
6545 seek(FILEHANDLE,POSITION,WHENCE)
6546 seekdir(DIRHANDLE,POS)
6547 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
6548 semctl(ID,SEMNUM,CMD,ARG)
6549 semget(KEY,NSEMS,SIZE,FLAGS)
6550 semop(KEY,...)
6551 send(SOCKET,MSG,FLAGS[,TO])
6552 setgrent
6553 sethostent(STAYOPEN)
6554 setnetent(STAYOPEN)
6555 setpgrp(PID,PGRP)
6556 setpriority(WHICH,WHO,PRIORITY)
6557 setprotoent(STAYOPEN)
6558 setpwent
6559 setservent(STAYOPEN)
6560 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
6561 shift[(ARRAY)]
6562 shmctl(ID,CMD,ARG)
6563 shmget(KEY,SIZE,FLAGS)
6564 shmread(ID,VAR,POS,SIZE)
6565 shmwrite(ID,STRING,POS,SIZE)
6566 shutdown(SOCKET,HOW)
6567 sin(EXPR)
6568 sleep[(EXPR)]
6569 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
6570 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
6571 sort [SUBROUTINE] (LIST)
6572 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
6573 split[(/PATTERN/[,EXPR[,LIMIT]])]
6574 sprintf(FORMAT,LIST)
6575 sqrt(EXPR)
6576 srand(EXPR)
6577 stat(EXPR|FILEHANDLE|VAR)
6578 study[(SCALAR)]
6579 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
6580 substr(EXPR,OFFSET[,LEN])
6581 symlink(OLDFILE,NEWFILE)
6582 syscall(LIST)
6583 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
6584 system(LIST)
6585 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
6586 tell[(FILEHANDLE)]
6587 telldir(DIRHANDLE)
6588 time
6589 times
6590 tr/SEARCHLIST/REPLACEMENTLIST/cds
6591 truncate(FILE|EXPR,LENGTH)
6592 umask[(EXPR)]
6593 undef[(EXPR)]
6594 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
6595 unlink(LIST)
6596 unpack(TEMPLATE,EXPR)
6597 unshift(ARRAY,LIST)
6598 until (EXPR) { ... } EXPR until EXPR
6599 utime(LIST)
6600 values(%HASH)
6601 vec(EXPR,OFFSET,BITS)
6602 wait
6603 waitpid(PID,FLAGS)
6604 wantarray Returns true if the sub/eval is called in list context.
6605 warn(LIST)
6606 while (EXPR) { ... } EXPR while EXPR
6607 write[(EXPR|FILEHANDLE)]
6608 ... x ... Repeat string or array.
6609 x= ... Repetition assignment.
6610 y/SEARCHLIST/REPLACEMENTLIST/
6611 ... | ... Bitwise or.
6612 ... || ... Logical or.
6613 ~ ... Unary bitwise complement.
6614 #! OS interpreter indicator. If contains `perl', used for options, and -x.
6615 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
6616 CORE:: Prefix to access builtin function if imported sub obscures it.
6617 SUPER:: Prefix to lookup for a method in @ISA classes.
6618 DESTROY Shorthand for `sub DESTROY {...}'.
6619 ... EQ ... Obsolete synonym of `eq'.
6620 ... GE ... Obsolete synonym of `ge'.
6621 ... GT ... Obsolete synonym of `gt'.
6622 ... LE ... Obsolete synonym of `le'.
6623 ... LT ... Obsolete synonym of `lt'.
6624 ... NE ... Obsolete synonym of `ne'.
6625 abs [ EXPR ] absolute value
6626 ... and ... Low-precedence synonym for &&.
6627 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
6628 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
6629 chr Converts a number to char with the same ordinal.
6630 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
6631 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
6632 exists $HASH{KEY} True if the key exists.
6633 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
6634 formline PICTURE, LIST Backdoor into \"format\" processing.
6635 glob EXPR Synonym of <EXPR>.
6636 lc [ EXPR ] Returns lowercased EXPR.
6637 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
6638 grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK.
6639 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
6640 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
6641 not ... Low-precedence synonym for ! - negation.
6642 ... or ... Low-precedence synonym for ||.
6643 pos STRING Set/Get end-position of the last match over this string, see \\G.
6644 quotemeta [ EXPR ] Quote regexp metacharacters.
6645 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
6646 readline FH Synonym of <FH>.
6647 readpipe CMD Synonym of `CMD`.
6648 ref [ EXPR ] Type of EXPR when dereferenced.
6649 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
6650 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
6651 tied Returns internal object for a tied data.
6652 uc [ EXPR ] Returns upcased EXPR.
6653 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
6654 untie VAR Unlink an object from a simple Perl variable.
6655 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
6656 ... xor ... Low-precedence synonym for exclusive or.
6657 prototype \&SUB Returns prototype of the function given a reference.
6658 =head1 Top-level heading.
6659 =head2 Second-level heading.
6660 =head3 Third-level heading (is there such?).
6661 =over [ NUMBER ] Start list.
6662 =item [ TITLE ] Start new item in the list.
6663 =back End list.
6664 =cut Switch from POD to Perl.
6665 =pod Switch from Perl to POD.
6668 (defun cperl-switch-to-doc-buffer (&optional interactive)
6669 "Go to the perl documentation buffer and insert the documentation."
6670 (interactive "p")
6671 (let ((buf (get-buffer-create cperl-doc-buffer)))
6672 (if interactive
6673 (switch-to-buffer-other-window buf)
6674 (set-buffer buf))
6675 (if (= (buffer-size) 0)
6676 (progn
6677 (insert (documentation-property 'cperl-short-docs
6678 'variable-documentation))
6679 (setq buffer-read-only t)))))
6681 (defun cperl-beautify-regexp-piece (b e embed level)
6682 ;; b is before the starting delimiter, e before the ending
6683 ;; e should be a marker, may be changed, but remains "correct".
6684 ;; EMBED is nil iff we process the whole REx.
6685 ;; The REx is guarantied to have //x
6686 ;; LEVEL shows how many levels deep to go
6687 ;; position at enter and at leave is not defined
6688 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos)
6689 (if (not embed)
6690 (goto-char (1+ b))
6691 (goto-char b)
6692 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing
6693 (forward-char 2)
6694 (delete-char 1)
6695 (forward-char 1))
6696 ((looking-at "(\\?[^a-zA-Z]")
6697 (forward-char 3))
6698 ((looking-at "(\\?") ; (?i)
6699 (forward-char 2))
6701 (forward-char 1))))
6702 (setq c (if embed (current-indentation) (1- (current-column)))
6703 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
6704 (or (looking-at "[ \t]*[\n#]")
6705 (progn
6706 (insert "\n")))
6707 (goto-char e)
6708 (beginning-of-line)
6709 (if (re-search-forward "[^ \t]" e t)
6710 (progn ; Something before the ending delimiter
6711 (goto-char e)
6712 (delete-horizontal-space)
6713 (insert "\n")
6714 (indent-to-column c)
6715 (set-marker e (point))))
6716 (goto-char b)
6717 (end-of-line 2)
6718 (while (< (point) (marker-position e))
6719 (beginning-of-line)
6720 (setq s (point)
6721 inline t)
6722 (skip-chars-forward " \t")
6723 (delete-region s (point))
6724 (indent-to-column c1)
6725 (while (and
6726 inline
6727 (looking-at
6728 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
6729 "\\|" ; Embedded variable
6730 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
6731 "\\|" ; $ ^
6732 "[$^]"
6733 "\\|" ; simple-code simple-code*?
6734 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
6735 "\\|" ; Class
6736 "\\(\\[\\)" ; 6
6737 "\\|" ; Grouping
6738 "\\((\\(\\?\\)?\\)" ; 7 8
6739 "\\|" ; |
6740 "\\(|\\)"))) ; 9
6741 (goto-char (match-end 0))
6742 (setq spaces t)
6743 (cond ((match-beginning 1) ; Alphanum word + junk
6744 (forward-char -1))
6745 ((or (match-beginning 3) ; $ab[12]
6746 (and (match-beginning 5) ; X* X+ X{2,3}
6747 (eq (preceding-char) ?\{)))
6748 (forward-char -1)
6749 (forward-sexp 1))
6750 ((match-beginning 6) ; []
6751 (setq tmp (point))
6752 (if (looking-at "\\^?\\]")
6753 (goto-char (match-end 0)))
6754 ;; XXXX POSIX classes?!
6755 (while (and (not pos)
6756 (re-search-forward "\\[:\\|\\]" e t))
6757 (if (eq (preceding-char) ?:)
6758 (or (re-search-forward ":\\]" e t)
6759 (error "[:POSIX:]-group in []-group not terminated"))
6760 (setq pos t)))
6761 (or (eq (preceding-char) ?\])
6762 (error "[]-group not terminated"))
6763 (if (eq (following-char) ?\{)
6764 (progn
6765 (forward-sexp 1)
6766 (and (eq (following-char) ??)
6767 (forward-char 1)))
6768 (re-search-forward "\\=\\([*+?]\\??\\)" e t)))
6769 ((match-beginning 7) ; ()
6770 (goto-char (match-beginning 0))
6771 (setq pos (current-column))
6772 (or (eq pos c1)
6773 (progn
6774 (delete-horizontal-space)
6775 (insert "\n")
6776 (indent-to-column c1)))
6777 (setq tmp (point))
6778 (forward-sexp 1)
6779 ;; (or (forward-sexp 1)
6780 ;; (progn
6781 ;; (goto-char tmp)
6782 ;; (error "()-group not terminated")))
6783 (set-marker m (1- (point)))
6784 (set-marker m1 (point))
6785 (if (= level 1)
6786 (if (progn ; indent rigidly if multiline
6787 ;; In fact does not make a lot of sense, since
6788 ;; the starting position can be already lost due
6789 ;; to insertion of "\n" and " "
6790 (goto-char tmp)
6791 (search-forward "\n" m1 t))
6792 (indent-rigidly (point) m1 (- c1 pos)))
6793 (setq level (1- level))
6794 (cond
6795 ((not (match-beginning 8))
6796 (cperl-beautify-regexp-piece tmp m t level))
6797 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
6799 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
6800 (goto-char (+ 2 tmp))
6801 (forward-sexp 1)
6802 (cperl-beautify-regexp-piece (point) m t level))
6803 ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind
6804 (goto-char (+ 3 tmp))
6805 (cperl-beautify-regexp-piece (point) m t level))
6807 (cperl-beautify-regexp-piece tmp m t level))))
6808 (goto-char m1)
6809 (cond ((looking-at "[*+?]\\??")
6810 (goto-char (match-end 0)))
6811 ((eq (following-char) ?\{)
6812 (forward-sexp 1)
6813 (if (eq (following-char) ?\?)
6814 (forward-char))))
6815 (skip-chars-forward " \t")
6816 (setq spaces nil)
6817 (if (looking-at "[#\n]")
6818 (progn
6819 (or (eolp) (indent-for-comment))
6820 (beginning-of-line 2))
6821 (delete-horizontal-space)
6822 (insert "\n"))
6823 (end-of-line)
6824 (setq inline nil))
6825 ((match-beginning 9) ; |
6826 (forward-char -1)
6827 (setq tmp (point))
6828 (beginning-of-line)
6829 (if (re-search-forward "[^ \t]" tmp t)
6830 (progn
6831 (goto-char tmp)
6832 (delete-horizontal-space)
6833 (insert "\n"))
6834 ;; first at line
6835 (delete-region (point) tmp))
6836 (indent-to-column c)
6837 (forward-char 1)
6838 (skip-chars-forward " \t")
6839 (setq spaces nil)
6840 (if (looking-at "[#\n]")
6841 (beginning-of-line 2)
6842 (delete-horizontal-space)
6843 (insert "\n"))
6844 (end-of-line)
6845 (setq inline nil)))
6846 (or (looking-at "[ \t\n]")
6847 (not spaces)
6848 (insert " "))
6849 (skip-chars-forward " \t"))
6850 (or (looking-at "[#\n]")
6851 (error "Unknown code `%s' in a regexp"
6852 (buffer-substring (point) (1+ (point)))))
6853 (and inline (end-of-line 2)))
6854 ;; Special-case the last line of group
6855 (if (and (>= (point) (marker-position e))
6856 (/= (current-indentation) c))
6857 (progn
6858 (beginning-of-line)
6859 (setq s (point))
6860 (skip-chars-forward " \t")
6861 (delete-region s (point))
6862 (indent-to-column c)))))
6864 (defun cperl-make-regexp-x ()
6865 ;; Returns position of the start
6866 ;; XXX this is called too often! Need to cache the result!
6867 (save-excursion
6868 (or cperl-use-syntax-table-text-property
6869 (error "I need to have a regexp marked!"))
6870 ;; Find the start
6871 (if (looking-at "\\s|")
6872 nil ; good already
6873 (if (looking-at "\\([smy]\\|qr\\)\\s|")
6874 (forward-char 1)
6875 (re-search-backward "\\s|"))) ; Assume it is scanned already.
6876 ;;(forward-char 1)
6877 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
6878 (sub-p (eq (preceding-char) ?s)) s)
6879 (forward-sexp 1)
6880 (set-marker e (1- (point)))
6881 (setq delim (preceding-char))
6882 (if (and sub-p (eq delim (char-after (- (point) 2))))
6883 (error "Possible s/blah// - do not know how to deal with"))
6884 (if sub-p (forward-sexp 1))
6885 (if (looking-at "\\sw*x")
6886 (setq have-x t)
6887 (insert "x"))
6888 ;; Protect fragile " ", "#"
6889 (if have-x nil
6890 (goto-char (1+ b))
6891 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
6892 (forward-char -1)
6893 (insert "\\")
6894 (forward-char 1)))
6895 b)))
6897 (defun cperl-beautify-regexp (&optional deep)
6898 "Do it. (Experimental, may change semantics, recheck the result.)
6899 We suppose that the regexp is scanned already."
6900 (interactive "P")
6901 (setq deep (if deep (prefix-numeric-value deep) -1))
6902 (save-excursion
6903 (goto-char (cperl-make-regexp-x))
6904 (let ((b (point)) (e (make-marker)))
6905 (forward-sexp 1)
6906 (set-marker e (1- (point)))
6907 (cperl-beautify-regexp-piece b e nil deep))))
6909 (defun cperl-regext-to-level-start ()
6910 "Goto start of an enclosing group in regexp.
6911 We suppose that the regexp is scanned already."
6912 (interactive)
6913 (let ((limit (cperl-make-regexp-x)) done)
6914 (while (not done)
6915 (or (eq (following-char) ?\()
6916 (search-backward "(" (1+ limit) t)
6917 (error "Cannot find `(' which starts a group"))
6918 (setq done
6919 (save-excursion
6920 (skip-chars-backward "\\")
6921 (looking-at "\\(\\\\\\\\\\)*(")))
6922 (or done (forward-char -1)))))
6924 (defun cperl-contract-level ()
6925 "Find an enclosing group in regexp and contract it.
6926 \(Experimental, may change semantics, recheck the result.)
6927 We suppose that the regexp is scanned already."
6928 (interactive)
6929 ;; (save-excursion ; Can't, breaks `cperl-contract-levels'
6930 (cperl-regext-to-level-start)
6931 (let ((b (point)) (e (make-marker)) s c)
6932 (forward-sexp 1)
6933 (set-marker e (1- (point)))
6934 (goto-char b)
6935 (while (re-search-forward "\\(#\\)\\|\n" e 'to-end)
6936 (cond
6937 ((match-beginning 1) ; #-comment
6938 (or c (setq c (current-indentation)))
6939 (beginning-of-line 2) ; Skip
6940 (setq s (point))
6941 (skip-chars-forward " \t")
6942 (delete-region s (point))
6943 (indent-to-column c))
6945 (delete-char -1)
6946 (just-one-space))))))
6948 (defun cperl-contract-levels ()
6949 "Find an enclosing group in regexp and contract all the kids.
6950 \(Experimental, may change semantics, recheck the result.)
6951 We suppose that the regexp is scanned already."
6952 (interactive)
6953 (save-excursion
6954 (condition-case nil
6955 (cperl-regext-to-level-start)
6956 (error ; We are outside outermost group
6957 (goto-char (cperl-make-regexp-x))))
6958 (let ((b (point)) (e (make-marker)) s c)
6959 (forward-sexp 1)
6960 (set-marker e (1- (point)))
6961 (goto-char (1+ b))
6962 (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t)
6963 (cond
6964 ((match-beginning 1) ; Skip
6965 nil)
6966 (t ; Group
6967 (cperl-contract-level)))))))
6969 (defun cperl-beautify-level (&optional deep)
6970 "Find an enclosing group in regexp and beautify it.
6971 \(Experimental, may change semantics, recheck the result.)
6972 We suppose that the regexp is scanned already."
6973 (interactive "P")
6974 (setq deep (if deep (prefix-numeric-value deep) -1))
6975 (save-excursion
6976 (cperl-regext-to-level-start)
6977 (let ((b (point)) (e (make-marker)))
6978 (forward-sexp 1)
6979 (set-marker e (1- (point)))
6980 (cperl-beautify-regexp-piece b e nil deep))))
6982 (defun cperl-invert-if-unless ()
6983 "Change `if (A) {B}' into `B if A;' etc if possible."
6984 (interactive)
6985 (or (looking-at "\\<")
6986 (forward-sexp -1))
6987 (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")
6988 (let ((pos1 (point))
6989 pos2 pos3 pos4 pos5 s1 s2 state p pos45
6990 (s0 (buffer-substring (match-beginning 0) (match-end 0))))
6991 (forward-sexp 2)
6992 (setq pos3 (point))
6993 (forward-sexp -1)
6994 (setq pos2 (point))
6995 (if (eq (following-char) ?\( )
6996 (progn
6997 (goto-char pos3)
6998 (forward-sexp 1)
6999 (setq pos5 (point))
7000 (forward-sexp -1)
7001 (setq pos4 (point))
7002 ;; XXXX In fact may be `A if (B); {C}' ...
7003 (if (and (eq (following-char) ?\{ )
7004 (progn
7005 (cperl-backward-to-noncomment pos3)
7006 (eq (preceding-char) ?\) )))
7007 (if (condition-case nil
7008 (progn
7009 (goto-char pos5)
7010 (forward-sexp 1)
7011 (forward-sexp -1)
7012 (looking-at "\\<els\\(e\\|if\\)\\>"))
7013 (error nil))
7014 (error
7015 "`%s' (EXPR) {BLOCK} with `else'/`elsif'" s0)
7016 (goto-char (1- pos5))
7017 (cperl-backward-to-noncomment pos4)
7018 (if (eq (preceding-char) ?\;)
7019 (forward-char -1))
7020 (setq pos45 (point))
7021 (goto-char pos4)
7022 (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" pos45 t)
7023 (setq p (match-beginning 0)
7024 s1 (buffer-substring p (match-end 0))
7025 state (parse-partial-sexp pos4 p))
7026 (or (nth 3 state)
7027 (nth 4 state)
7028 (nth 5 state)
7029 (error "`%s' inside `%s' BLOCK" s1 s0))
7030 (goto-char (match-end 0)))
7031 ;; Finally got it
7032 (goto-char (1+ pos4))
7033 (skip-chars-forward " \t\n")
7034 (setq s2 (buffer-substring (point) pos45))
7035 (goto-char pos45)
7036 (or (looking-at ";?[ \t\n]*}")
7037 (progn
7038 (skip-chars-forward "; \t\n")
7039 (setq s2 (concat s2 "\n" (buffer-substring (point) (1- pos5))))))
7040 (and (equal s2 "")
7041 (setq s2 "1"))
7042 (goto-char (1- pos3))
7043 (cperl-backward-to-noncomment pos2)
7044 (or (looking-at "[ \t\n]*)")
7045 (goto-char (1- pos3)))
7046 (setq p (point))
7047 (goto-char (1+ pos2))
7048 (skip-chars-forward " \t\n")
7049 (setq s1 (buffer-substring (point) p))
7050 (delete-region pos4 pos5)
7051 (delete-region pos2 pos3)
7052 (goto-char pos1)
7053 (insert s2 " ")
7054 (just-one-space)
7055 (forward-word 1)
7056 (setq pos1 (point))
7057 (insert " " s1 ";")
7058 (delete-horizontal-space)
7059 (forward-char -1)
7060 (delete-horizontal-space)
7061 (goto-char pos1)
7062 (just-one-space)
7063 (cperl-indent-line))
7064 (error "`%s' (EXPR) not with an {BLOCK}" s0)))
7065 (error "`%s' not with an (EXPR)" s0)))
7066 (error "Not at `if', `unless', `while', `until', `for' or `foreach'")))
7068 ;;; By Anthony Foiani <afoiani@uswest.com>
7069 ;;; Getting help on modules in C-h f ?
7070 ;;; This is a modified version of `man'.
7071 ;;; Need to teach it how to lookup functions
7072 (defun cperl-perldoc (word)
7073 "Run `perldoc' on WORD."
7074 (interactive
7075 (list (let* ((default-entry (cperl-word-at-point))
7076 (input (read-string
7077 (format "perldoc entry%s: "
7078 (if (string= default-entry "")
7080 (format " (default %s)" default-entry))))))
7081 (if (string= input "")
7082 (if (string= default-entry "")
7083 (error "No perldoc args given")
7084 default-entry)
7085 input))))
7086 (require 'man)
7087 (let* ((case-fold-search nil)
7088 (is-func (and
7089 (string-match "^[a-z]+$" word)
7090 (string-match (concat "^" word "\\>")
7091 (documentation-property
7092 'cperl-short-docs
7093 'variable-documentation))))
7094 (manual-program (if is-func "perldoc -f" "perldoc")))
7095 (cond
7096 (cperl-xemacs-p
7097 (let ((Manual-program "perldoc")
7098 (Manual-switches (if is-func (list "-f"))))
7099 (manual-entry word)))
7101 (Man-getpage-in-background word)))))
7103 (defun cperl-perldoc-at-point ()
7104 "Run a `perldoc' on the word around point."
7105 (interactive)
7106 (cperl-perldoc (cperl-word-at-point)))
7108 (defcustom pod2man-program "pod2man"
7109 "*File name for `pod2man'."
7110 :type 'file
7111 :group 'cperl)
7113 ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes)
7114 (defun cperl-pod-to-manpage ()
7115 "Create a virtual manpage in Emacs from the Perl Online Documentation."
7116 (interactive)
7117 (require 'man)
7118 (let* ((pod2man-args (concat buffer-file-name " | nroff -man "))
7119 (bufname (concat "Man " buffer-file-name))
7120 (buffer (generate-new-buffer bufname)))
7121 (save-excursion
7122 (set-buffer buffer)
7123 (let ((process-environment (copy-sequence process-environment)))
7124 ;; Prevent any attempt to use display terminal fanciness.
7125 (setenv "TERM" "dumb")
7126 (set-process-sentinel
7127 (start-process pod2man-program buffer "sh" "-c"
7128 (format (cperl-pod2man-build-command) pod2man-args))
7129 'Man-bgproc-sentinel)))))
7131 ;;; Updated version by him too
7132 (defun cperl-build-manpage ()
7133 "Create a virtual manpage in Emacs from the POD in the file."
7134 (interactive)
7135 (require 'man)
7136 (cond
7137 (cperl-xemacs-p
7138 (let ((Manual-program "perldoc"))
7139 (manual-entry buffer-file-name)))
7141 (let* ((manual-program "perldoc"))
7142 (Man-getpage-in-background buffer-file-name)))))
7144 (defun cperl-pod2man-build-command ()
7145 "Builds the entire background manpage and cleaning command."
7146 (let ((command (concat pod2man-program " %s 2>/dev/null"))
7147 (flist Man-filter-list))
7148 (while (and flist (car flist))
7149 (let ((pcom (car (car flist)))
7150 (pargs (cdr (car flist))))
7151 (setq command
7152 (concat command " | " pcom " "
7153 (mapconcat '(lambda (phrase)
7154 (if (not (stringp phrase))
7155 (error "Malformed Man-filter-list"))
7156 phrase)
7157 pargs " ")))
7158 (setq flist (cdr flist))))
7159 command))
7161 (defun cperl-lazy-install ()) ; Avoid a warning
7162 (defun cperl-lazy-unstall ()) ; Avoid a warning
7164 (if (fboundp 'run-with-idle-timer)
7165 (progn
7166 (defvar cperl-help-shown nil
7167 "Non-nil means that the help was already shown now.")
7169 (defvar cperl-lazy-installed nil
7170 "Non-nil means that the lazy-help handlers are installed now.")
7172 (defun cperl-lazy-install ()
7173 "Switches on Auto-Help on Perl constructs (put in the message area).
7174 Delay of auto-help controlled by `cperl-lazy-help-time'."
7175 (interactive)
7176 (make-variable-buffer-local 'cperl-help-shown)
7177 (if (and (cperl-val 'cperl-lazy-help-time)
7178 (not cperl-lazy-installed))
7179 (progn
7180 (add-hook 'post-command-hook 'cperl-lazy-hook)
7181 (run-with-idle-timer
7182 (cperl-val 'cperl-lazy-help-time 1000000 5)
7184 'cperl-get-help-defer)
7185 (setq cperl-lazy-installed t))))
7187 (defun cperl-lazy-unstall ()
7188 "Switches off Auto-Help on Perl constructs (put in the message area).
7189 Delay of auto-help controlled by `cperl-lazy-help-time'."
7190 (interactive)
7191 (remove-hook 'post-command-hook 'cperl-lazy-hook)
7192 (cancel-function-timers 'cperl-get-help-defer)
7193 (setq cperl-lazy-installed nil))
7195 (defun cperl-lazy-hook ()
7196 (setq cperl-help-shown nil))
7198 (defun cperl-get-help-defer ()
7199 (if (not (memq major-mode '(perl-mode cperl-mode))) nil
7200 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
7201 (cperl-get-help)
7202 (setq cperl-help-shown t))))
7203 (cperl-lazy-install)))
7206 ;;; Plug for wrong font-lock:
7208 (defun cperl-font-lock-unfontify-region-function (beg end)
7209 ;; Simplified now that font-lock-unfontify-region uses save-buffer-state.
7210 (let (before-change-functions after-change-functions)
7211 (remove-text-properties beg end '(face nil))))
7213 (defvar cperl-d-l nil)
7214 (defun cperl-fontify-syntaxically (end)
7215 ;; Some vars for debugging only
7216 ;; (message "Syntaxifying...")
7217 (let ((dbg (point)) (iend end)
7218 (istate (car cperl-syntax-state))
7219 start)
7220 (and cperl-syntaxify-unwind
7221 (setq end (cperl-unwind-to-safe t end)))
7222 (setq start (point))
7223 (or cperl-syntax-done-to
7224 (setq cperl-syntax-done-to (point-min)))
7225 (if (or (not (boundp 'font-lock-hot-pass))
7226 (eval 'font-lock-hot-pass)
7227 t) ; Not debugged otherwise
7228 ;; Need to forget what is after `start'
7229 (setq start (min cperl-syntax-done-to start))
7230 ;; Fontification without a change
7231 (setq start (max cperl-syntax-done-to start)))
7232 (and (> end start)
7233 (setq cperl-syntax-done-to start) ; In case what follows fails
7234 (cperl-find-pods-heres start end t nil t))
7235 (if (eq cperl-syntaxify-by-font-lock 'message)
7236 (message "Syntaxified %s..%s from %s to %s(%s), state %s-->%s"
7237 dbg iend
7238 start end cperl-syntax-done-to
7239 istate (car cperl-syntax-state))) ; For debugging
7240 nil)) ; Do not iterate
7242 (defun cperl-fontify-update (end)
7243 (let ((pos (point)) prop posend)
7244 (while (< pos end)
7245 (setq prop (get-text-property pos 'cperl-postpone))
7246 (setq posend (next-single-property-change pos 'cperl-postpone nil end))
7247 (and prop (put-text-property pos posend (car prop) (cdr prop)))
7248 (setq pos posend)))
7249 nil) ; Do not iterate
7251 (defun cperl-update-syntaxification (from to)
7252 (if (and cperl-use-syntax-table-text-property
7253 cperl-syntaxify-by-font-lock
7254 (or (null cperl-syntax-done-to)
7255 (< cperl-syntax-done-to to)))
7256 (progn
7257 (save-excursion
7258 (goto-char from)
7259 (cperl-fontify-syntaxically to)))))
7261 (defvar cperl-version
7262 (let ((v "Revision: 5.0"))
7263 (string-match ":\\s *\\([0-9.]+\\)" v)
7264 (substring v (match-beginning 1) (match-end 1)))
7265 "Version of IZ-supported CPerl package this file is based on.")
7267 (provide 'cperl-mode)
7269 ;;; arch-tag: 42e5b19b-e187-4537-929f-1a7408980ce6
7270 ;;; cperl-mode.el ends here