comparison lisp/modes/cperl-mode.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents ac2d302a0011
children 859a2309aef8
comparison
equal deleted inserted replaced
3:30df88044ec6 4:b82b59fe008d
4 ;;; Newsgroups: comp.lang.perl 4 ;;; Newsgroups: comp.lang.perl
5 ;;; Subject: cperl-mode: Another perl mode for Gnuemacs 5 ;;; Subject: cperl-mode: Another perl mode for Gnuemacs
6 ;;; Date: 14 Aug 91 15:20:01 GMT 6 ;;; Date: 14 Aug 91 15:20:01 GMT
7 7
8 ;; Perl code editing commands for Emacs 8 ;; Perl code editing commands for Emacs
9 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc. 9 ;; Copyright (C) 1985-1996 Bob Olson, Ilya Zakharevich
10 10
11 ;; This file is not (yet) part of GNU Emacs. 11 ;; This file is not (yet) part of GNU Emacs. It may be distributed
12 ;; either under the same terms as GNU Emacs, or under the same terms
13 ;; as Perl. You should have received a copy of Perl Artistic license
14 ;; along with the Perl distribution.
12 15
13 ;; GNU Emacs is free software; you can redistribute it and/or modify 16 ;; 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 17 ;; 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) 18 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version. 19 ;; any later version.
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details. 24 ;; GNU General Public License for more details.
22 25
23 ;; You should have received a copy of the GNU General Public License 26 ;; 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 27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 29 ;; Boston, MA 02111-1307, USA.
27 ;;; Synched up with: Not in FSF. 30
28 31
29 ;;; Corrections made by Ilya Zakharevich ilya@math.mps.ohio-state.edu 32 ;;; Corrections made by Ilya Zakharevich ilya@math.mps.ohio-state.edu
30 ;;; XEmacs changes by Peter Arius arius@informatik.uni-erlangen.de 33 ;;; XEmacs changes by Peter Arius arius@informatik.uni-erlangen.de
31 34
32 ;; $Id: cperl-mode.el,v 1.1.1.2 1996/12/18 03:44:44 steve Exp $ 35 ;; $Id: cperl-mode.el,v 1.1.1.3 1996/12/18 03:53:13 steve Exp $
33 36
34 ;;; To use this mode put the following into your .emacs file: 37 ;;; To use this mode put the following into your .emacs file:
35 38
36 ;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t) 39 ;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)
37 40
50 ;; (setq interpreter-mode-alist (append interpreter-mode-alist 53 ;; (setq interpreter-mode-alist (append interpreter-mode-alist
51 ;; '(("miniperl" . perl-mode)))) 54 ;; '(("miniperl" . perl-mode))))
52 55
53 ;;; The mode information (on C-h m) provides customization help. 56 ;;; The mode information (on C-h m) provides customization help.
54 ;;; If you use font-lock feature of this mode, it is advisable to use 57 ;;; If you use font-lock feature of this mode, it is advisable to use
55 ;;; eather lazy-lock-mode or fast-lock-mode (available on ELisp 58 ;;; either lazy-lock-mode or fast-lock-mode (available on ELisp
56 ;;; archive in files lazy-lock.el and fast-lock.el). I prefer lazy-lock. 59 ;;; archive in files lazy-lock.el and fast-lock.el). I prefer lazy-lock.
57 60
58 ;;; Faces used now: three faces for first-class and second-class keywords 61 ;;; Faces used now: three faces for first-class and second-class keywords
59 ;;; and control flow words, one for each: comments, string, labels, 62 ;;; and control flow words, one for each: comments, string, labels,
60 ;;; functions definitions and packages, arrays, hashes, and variable 63 ;;; functions definitions and packages, arrays, hashes, and variable
61 ;;; definitions. If you do not see all these faces, your font-lock does 64 ;;; definitions. If you do not see all these faces, your font-lock does
62 ;;; not define them, so you need to define them manually. Maybe you have 65 ;;; not define them, so you need to define them manually. Maybe you have
63 ;;; an obsolete font-lock from 19.28 or earlier. Upgrade. 66 ;;; an obsolete font-lock from 19.28 or earlier. Upgrade.
64 67
65 ;;; If you have grayscale monitor, and do not have the variable 68 ;;; If you have a grayscale monitor, and do not have the variable
66 ;;; font-lock-display-type bound to 'grayscale, insert 69 ;;; font-lock-display-type bound to 'grayscale, insert
67 70
68 ;;; (setq font-lock-display-type 'grayscale) 71 ;;; (setq font-lock-display-type 'grayscale)
69 72
70 ;;; to your .emacs file. 73 ;;; into your .emacs file.
71 74
72 ;;;; This mode supports font-lock, imenu and mode-compile. In the 75 ;;;; This mode supports font-lock, imenu and mode-compile. In the
73 ;;;; hairy version font-lock is on, but you should activate imenu 76 ;;;; hairy version font-lock is on, but you should activate imenu
74 ;;;; yourself (note that mode-compile is not standard yet). Well, you 77 ;;;; yourself (note that mode-compile is not standard yet). Well, you
75 ;;;; can use imenu from keyboard anyway (M-x imenu), but it is better 78 ;;;; can use imenu from keyboard anyway (M-x imenu), but it is better
264 267
265 ;;;; After 1.21 268 ;;;; After 1.21
266 ;;; Auto-newline grants `cperl-extra-newline-before-brace' if "{" is typed 269 ;;; Auto-newline grants `cperl-extra-newline-before-brace' if "{" is typed
267 ;;; after ")". 270 ;;; after ")".
268 ;;; {} is recognized as expression after `tr' and friends. 271 ;;; {} is recognized as expression after `tr' and friends.
269 ;;; Works with XEmacs again. 272
273 ;;;; After 1.22
274 ;;; Entry Hierarchy added to imenu. Very primitive so far.
275 ;;; One needs newer `imenu-go'.el. A patch to `imenu' is needed as well.
276 ;;; Writes its own TAGS files.
277 ;;; Class viewer based on TAGS files. Does not trace @ISA so far.
278 ;;; 19.31: Problems with scan for PODs corrected.
279 ;;; First POD header correctly fontified.
280 ;;; I needed (setq imenu-use-keymap-menu t) to get good imenu in 19.31.
281 ;;; Apparently it makes a lot of hierarchy code obsolete...
282
283 ;;;; After 1.23
284 ;;; Tags filler now scans *.xs as well.
285 ;;; The info from *.xs scan is used by the hierarchy viewer.
286 ;;; Hierarchy viewer documented.
287 ;;; Bug in 19.31 imenu documented.
288
289 ;;;; After 1.24
290 ;;; New location for info-files mentioned,
291 ;;; Electric-; should work better.
292 ;;; Minor bugs with POD marking.
293
294 ;;;; After 1.25 (probably not...)
295 ;;; `cperl-info-page' introduced.
296 ;;; To make `uncomment-region' working, `comment-region' would
297 ;;; not insert extra space.
298 ;;; Here documents delimiters better recognized
299 ;;; (empty one, and non-alphanums in quotes handled). May be wrong with 1<<14?
300 ;;; `cperl-db' added, used in menu.
301 ;;; imenu scan removes text-properties, for better debugging
302 ;;; - but the bug is in 19.31 imenu.
303 ;;; formats highlighted by font-lock and prescan, embedded comments
304 ;;; are not treated.
305 ;;; POD/friends scan merged in one pass.
306 ;;; Syntax class is not used for analyzing the code, only char-syntax
307 ;;; may be checked against _ or'ed with w.
308 ;;; Syntax class of `:' changed to be _.
309 ;;; `cperl-find-bad-style' added.
310
311 ;;;; After 1.25
312 ;;; When search for here-documents, we ignore commented << in simplest cases.
313 ;;; `cperl-get-help' added, available on C-h v and from menu.
314 ;;; Auto-help added. Default with `cperl-hairy', switchable on/off
315 ;;; with startup variable `cperl-lazy-help-time' and from
316 ;;; menu. Requires `run-with-idle-timer'.
317 ;;; Highlighting of @abc{@efg} was wrong - interchanged two regexps.
318
319 ;;;; After 1.27
320 ;;; Indentation: At toplevel after a label - fixed.
321 ;;; 1.27 was put to archives in binary mode ===> DOSish :-(
322
323 ;;;; After 1.28
324 ;;; Thanks to Martin Buchholz <mrb@Eng.Sun.COM>: misprints in
325 ;;; comments and docstrings corrected, XEmacs support cleaned up.
326 ;;; The closing parenths would enclose the region into matching
327 ;;; parens under the same conditions as the opening ones.
328 ;;; Minor updates to `cperl-short-docs'.
329 ;;; Will not consider <<= as start of here-doc.
270 330
271 (defvar cperl-extra-newline-before-brace nil 331 (defvar cperl-extra-newline-before-brace nil
272 "*Non-nil means that if, elsif, while, until, else, for, foreach 332 "*Non-nil means that if, elsif, while, until, else, for, foreach
273 and do constructs look like: 333 and do constructs look like:
274 334
332 "*String of parentheses that should be electric in CPerl.") 392 "*String of parentheses that should be electric in CPerl.")
333 393
334 (defvar cperl-electric-parens nil 394 (defvar cperl-electric-parens nil
335 "*Non-nil (and non-null) means parentheses should be electric in CPerl. 395 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
336 Can be overwritten by `cperl-hairy' if nil.") 396 Can be overwritten by `cperl-hairy' if nil.")
337 397 (defvar cperl-electric-parens-mark
338 (defvar cperl-electric-parens-mark (and window-system 398 (and window-system
339 (or (and ; Emacs 399 (or (and (boundp 'transient-mark-mode) ; For Emacs
340 (boundp 'transient-mark-mode) 400 transient-mark-mode)
341 transient-mark-mode) 401 (and (boundp 'zmacs-regions) ; For XEmacs
342 (and ; XEmacs 402 zmacs-regions)))
343 (boundp 'zmacs-regions) 403 "*Not-nil means that electric parens look for active mark.
344 zmacs-regions))) 404 Default is yes if there is visual feedback on mark.")
405
406 (defvar cperl-electric-parens-mark (and window-system transient-mark-mode)
345 "*Not-nil means that electric parens look for active mark. 407 "*Not-nil means that electric parens look for active mark.
346 Default is yes if there is visual feedback on mark.") 408 Default is yes if there is visual feedback on mark.")
347 409
348 (defvar cperl-electric-linefeed nil 410 (defvar cperl-electric-linefeed nil
349 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy. 411 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
367 (defvar cperl-info-on-command-no-prompt nil 429 (defvar cperl-info-on-command-no-prompt nil
368 "*Not-nil (and non-null) means not to prompt on C-h f. 430 "*Not-nil (and non-null) means not to prompt on C-h f.
369 The opposite behaviour is always available if prefixed with C-c. 431 The opposite behaviour is always available if prefixed with C-c.
370 Can be overwritten by `cperl-hairy' if nil.") 432 Can be overwritten by `cperl-hairy' if nil.")
371 433
434 (defvar cperl-lazy-help-time nil
435 "*Not-nil (and non-null) means to show lazy help after given idle time.")
436
372 (defvar cperl-pod-face 'font-lock-comment-face 437 (defvar cperl-pod-face 'font-lock-comment-face
373 "*The result of evaluation of this expression is used for pod highlighting.") 438 "*The result of evaluation of this expression is used for pod highlighting.")
374 439
375 (defvar cperl-pod-head-face 'font-lock-variable-name-face 440 (defvar cperl-pod-head-face 'font-lock-variable-name-face
376 "*The result of evaluation of this expression is used for pod highlighting. 441 "*The result of evaluation of this expression is used for pod highlighting.
383 "*Not-nil after evaluation means to highlight pod and here-docs sections.") 448 "*Not-nil after evaluation means to highlight pod and here-docs sections.")
384 449
385 (defvar cperl-pod-here-scan t 450 (defvar cperl-pod-here-scan t
386 "*Not-nil means look for pod and here-docs sections during startup. 451 "*Not-nil means look for pod and here-docs sections during startup.
387 You can always make lookup from menu or using \\[cperl-find-pods-heres].") 452 You can always make lookup from menu or using \\[cperl-find-pods-heres].")
453
454 (defvar cperl-imenu-addback nil
455 "*Not-nil means add backreferences to generated `imenu's.
456 May require patched `imenu' and `imenu-go'.")
457
458 (defvar cperl-info-page "perl"
459 "Name of the info page containing perl docs.
460 Older version of this page was called `perl5', newer `perl'.")
388 461
389 462
390 463
391 ;;; Short extra-docs. 464 ;;; Short extra-docs.
392 465
394 "Get newest version of this package from 467 "Get newest version of this package from
395 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs 468 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs
396 and/or 469 and/or
397 ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl 470 ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
398 471
399 Get support packages font-lock-extra.el, imenu-go.el from the same place. 472 Get support packages choose-color.el (or font-lock-extra.el before
400 \(Look for other files there too... ;-) Get a patch for imenu.el in 19.29. 473 19.30), imenu-go.el from the same place. \(Look for other files there
401 Note that for 19.30 you should use choose-color.el *instead* of 474 too... ;-) Get a patch for imenu.el in 19.29. Note that for 19.30 and
402 font-lock-extra.el (and you will not get smart highlighting in C :-(). 475 later you should use choose-color.el *instead* of font-lock-extra.el
476 \(and you will not get smart highlighting in C :-().
403 477
404 Note that to enable Compile choices in the menu you need to install 478 Note that to enable Compile choices in the menu you need to install
405 mode-compile.el. 479 mode-compile.el.
406 480
407 Get perl5-info from 481 Get perl5-info from
482 $CPAN/doc/manual/info/perl-info.tar.gz
483 older version was on
408 http://www.metronet.com:70/9/perlinfo/perl5/manual/perl5-info.tar.gz 484 http://www.metronet.com:70/9/perlinfo/perl5/manual/perl5-info.tar.gz
409 \(may be quite obsolete, but still useful). 485
410 486 If you use imenu-go, run imenu on perl5-info buffer (you can do it
411 If you use imenu-go, run imenu on perl5-info buffer (you can do it from 487 from CPerl menu). If many files are related, generate TAGS files from
412 CPerl menu). 488 Tools/Tags submenu in CPerl menu.
489
490 If some class structure is too complicated, use Tools/Hierarchy-view
491 from CPerl menu, or hierarchic view of imenu. The second one uses the
492 current buffer only, the first one requires generation of TAGS from
493 CPerl/Tools/Tags menu beforehand.
494
495 Run CPerl/Tools/Insert-spaces-if-needed to fix your lazy typing.
496
497 Switch auto-help on/off with CPerl/Tools/Auto-help.
413 498
414 Before reporting (non-)problems look in the problem section on what I 499 Before reporting (non-)problems look in the problem section on what I
415 know about them.") 500 know about them.")
416 501
417 (defvar cperl-problems 'please-ignore-this-line 502 (defvar cperl-problems 'please-ignore-this-line
419 504
420 It may be corrected on the level of C code, please look in the 505 It may be corrected on the level of C code, please look in the
421 `non-problems' section if you want to volunteer. 506 `non-problems' section if you want to volunteer.
422 507
423 CPerl mode tries to corrects some Emacs misunderstandings, however, 508 CPerl mode tries to corrects some Emacs misunderstandings, however,
424 for effeciency reasons the degree of correction is different for 509 for efficiency reasons the degree of correction is different for
425 different operations. The partially corrected problems are: POD 510 different operations. The partially corrected problems are: POD
426 sections, here-documents, regexps. The operations are: highlighting, 511 sections, here-documents, regexps. The operations are: highlighting,
427 indentation, electric keywords, electric braces. 512 indentation, electric keywords, electric braces.
428 513
429 This may be confusing, since the regexp s#//#/#\; may be highlighted 514 This may be confusing, since the regexp s#//#/#\; may be highlighted
430 as a comment, but it will recognized as a regexp by the indentation 515 as a comment, but it will be recognized as a regexp by the indentation
431 code. Or the opposite case, when a pod section is highlighted, but 516 code. Or the opposite case, when a pod section is highlighted, but
432 breaks the indentation of the following code. 517 breaks the indentation of the following code.
433 518
434 The main trick (to make $ a \"backslash\") makes constructions like 519 The main trick (to make $ a \"backslash\") makes constructions like
435 ${aaa} look like unbalanced braces. The only trick I can think out is 520 ${aaa} look like unbalanced braces. The only trick I can think of is
436 to insert it as $ {aaa} (legal in perl5, not in perl4). 521 to insert it as $ {aaa} (legal in perl5, not in perl4).
437 522
438 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten 523 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
439 as /($|\\s)/. Note that such a transpositinon is not always possible 524 as /($|\\s)/. Note that such a transposition is not always possible
440 :-(. " ) 525 :-(. " )
441 526
442 (defvar cperl-non-problems 'please-ignore-this-line 527 (defvar cperl-non-problems 'please-ignore-this-line
443 "As you know from `problems' section, Perl syntax too hard for CPerl. 528 "As you know from `problems' section, Perl syntax is too hard for CPerl.
444 529
445 Most the time, if you write your own code, you may find an equivalent 530 Most the time, if you write your own code, you may find an equivalent
446 \(and almost as readable) expression. 531 \(and almost as readable) expression.
447 532
448 Try to help it: add comments with embedded quotes to fix CPerl 533 Try to help it: add comments with embedded quotes to fix CPerl
470 b) Supply the code to me (IZ). 555 b) Supply the code to me (IZ).
471 556
472 Pods are treated _very_ rudimentally. Here-documents are not treated 557 Pods are treated _very_ rudimentally. Here-documents are not treated
473 at all (except highlighting and inhibiting indentation). (This may 558 at all (except highlighting and inhibiting indentation). (This may
474 change some time. RMS approved making syntax lookup recognize text 559 change some time. RMS approved making syntax lookup recognize text
475 attributes, but volonteers are needed to change Emacs C code.) 560 attributes, but volunteers are needed to change Emacs C code.)
476 561
477 To speed up coloring the following compromises exist: 562 To speed up coloring the following compromises exist:
478 a) sub in $mypackage::sub may be highlighted. 563 a) sub in $mypackage::sub may be highlighted.
479 b) -z in [a-z] may be highlighted. 564 b) -z in [a-z] may be highlighted.
480 c) if your regexp contains a keyword (like \"s\"), it may be highlighted. 565 c) if your regexp contains a keyword (like \"s\"), it may be highlighted.
566
567
568 Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove
569 `car' before `imenu-choose-buffer-index' in `imenu'.
481 ") 570 ")
482 571
483 572
484 573
485 ;;; Portability stuff: 574 ;;; Portability stuff:
486 575
487 (defsubst cperl-xemacs-p () 576 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
488 (string-match "XEmacs\\|Lucid" emacs-version)) 577 (defmacro cperl-define-key (fsf-key definition &optional xemacs-key)
578 `(define-key cperl-mode-map
579 ,(if xemacs-key
580 `(if cperl-xemacs-p ,xemacs-key ,fsf-key)
581 fsf-key)
582 ,definition))
489 583
490 (defvar del-back-ch (car (append (where-is-internal 'delete-backward-char) 584 (defvar del-back-ch (car (append (where-is-internal 'delete-backward-char)
491 (where-is-internal 'backward-delete-char-untabify))) 585 (where-is-internal 'backward-delete-char-untabify)))
492 "Character generated by key bound to delete-backward-char.") 586 "Character generated by key bound to delete-backward-char.")
493 587
494 (and (vectorp del-back-ch) (= (length del-back-ch) 1) 588 (and (vectorp del-back-ch) (= (length del-back-ch) 1)
495 (setq del-back-ch (aref del-back-ch 0))) 589 (setq del-back-ch (aref del-back-ch 0)))
496 590
497 (if (cperl-xemacs-p) 591 (if cperl-xemacs-p
498 (progn 592 (progn
499 ;; "Active regions" are on: use region only if active 593 ;; "Active regions" are on: use region only if active
500 ;; "Active regions" are off: use region unconditionally 594 ;; "Active regions" are off: use region unconditionally
501 (defun cperl-use-region-p () 595 (defun cperl-use-region-p ()
502 (if zmacs-regions (mark) t)) 596 (if zmacs-regions (mark) t))
504 (defun cperl-use-region-p () 598 (defun cperl-use-region-p ()
505 (if transient-mark-mode mark-active t)) 599 (if transient-mark-mode mark-active t))
506 (defun cperl-mark-active () mark-active)) 600 (defun cperl-mark-active () mark-active))
507 601
508 (defsubst cperl-enable-font-lock () 602 (defsubst cperl-enable-font-lock ()
509 (or (cperl-xemacs-p) window-system)) 603 (or cperl-xemacs-p window-system))
510 604
511 (if (boundp 'unread-command-events) 605 (if (boundp 'unread-command-events)
512 (if (cperl-xemacs-p) 606 (if cperl-xemacs-p
513 (defun cperl-putback-char (c) ; XEmacs >= 19.12 607 (defun cperl-putback-char (c) ; XEmacs >= 19.12
514 (setq unread-command-events (list (character-to-event c)))) 608 (setq unread-command-events (list (character-to-event c))))
515 (defun cperl-putback-char (c) ; Emacs 19 609 (defun cperl-putback-char (c) ; Emacs 19
516 (setq unread-command-events (list c)))) 610 (setq unread-command-events (list c))))
517 (defun cperl-putback-char (c) ; XEmacs <= 19.11 611 (defun cperl-putback-char (c) ; XEmacs <= 19.11
525 (defvar cperl-do-not-fontify 619 (defvar cperl-do-not-fontify
526 (if (string< emacs-version "19.30") 620 (if (string< emacs-version "19.30")
527 'fontified 621 'fontified
528 'lazy-lock) 622 'lazy-lock)
529 "Text property which inhibits refontification.") 623 "Text property which inhibits refontification.")
624
625 (defsubst cperl-put-do-not-fontify (from to)
626 (put-text-property (max (point-min) (1- from))
627 to cperl-do-not-fontify t))
530 628
531 629
532 ;;; Probably it is too late to set these guys already, but it can help later: 630 ;;; Probably it is too late to set these guys already, but it can help later:
533 631
534 (setq auto-mode-alist 632 (setq auto-mode-alist
560 658
561 (defvar cperl-mode-map () "Keymap used in CPerl mode.") 659 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
562 660
563 (if cperl-mode-map nil 661 (if cperl-mode-map nil
564 (setq cperl-mode-map (make-sparse-keymap)) 662 (setq cperl-mode-map (make-sparse-keymap))
565 (define-key cperl-mode-map "{" 'cperl-electric-lbrace) 663 (cperl-define-key "{" 'cperl-electric-lbrace)
566 (define-key cperl-mode-map "[" 'cperl-electric-paren) 664 (cperl-define-key "[" 'cperl-electric-paren)
567 (define-key cperl-mode-map "(" 'cperl-electric-paren) 665 (cperl-define-key "(" 'cperl-electric-paren)
568 (define-key cperl-mode-map "<" 'cperl-electric-paren) 666 (cperl-define-key "<" 'cperl-electric-paren)
569 (define-key cperl-mode-map "}" 'cperl-electric-brace) 667 (cperl-define-key "}" 'cperl-electric-brace)
570 (define-key cperl-mode-map ";" 'cperl-electric-semi) 668 (cperl-define-key "]" 'cperl-electric-rparen)
571 (define-key cperl-mode-map ":" 'cperl-electric-terminator) 669 (cperl-define-key ")" 'cperl-electric-rparen)
572 (define-key cperl-mode-map "\C-j" 'newline-and-indent) 670 (cperl-define-key ";" 'cperl-electric-semi)
573 (define-key cperl-mode-map "\C-c\C-j" 'cperl-linefeed) 671 (cperl-define-key ":" 'cperl-electric-terminator)
574 (define-key cperl-mode-map "\C-c\C-a" 'cperl-toggle-auto-newline) 672 (cperl-define-key "\C-j" 'newline-and-indent)
575 (define-key cperl-mode-map "\C-c\C-k" 'cperl-toggle-abbrev) 673 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
576 (define-key cperl-mode-map "\C-c\C-e" 'cperl-toggle-electric) 674 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
577 (define-key cperl-mode-map "\e\C-q" 'cperl-indent-exp) ; Usually not bound 675 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
578 ;;(define-key cperl-mode-map "\M-q" 'cperl-fill-paragraph) 676 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
579 ;;(define-key cperl-mode-map "\e;" 'cperl-indent-for-comment) 677 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
580 (define-key cperl-mode-map "\177" 'cperl-electric-backspace) 678 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
581 (define-key cperl-mode-map "\t" 'cperl-indent-command) 679 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
582 (if (cperl-xemacs-p) 680 (cperl-define-key "\177" 'cperl-electric-backspace)
583 ;; don't clobber the backspace binding: 681 (cperl-define-key "\t" 'cperl-indent-command)
584 (define-key cperl-mode-map [(control h) f] 'cperl-info-on-command) 682 ;; don't clobber the backspace binding:
585 (define-key cperl-mode-map "\C-hf" 'cperl-info-on-command)) 683 (cperl-define-key "\C-hf" 'cperl-info-on-command [(control h) f])
586 (if (cperl-xemacs-p) 684 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
587 ;; don't clobber the backspace binding: 685 [(control c) (control h) f])
588 (define-key cperl-mode-map [(control c) (control h) f] 686 (cperl-define-key "\C-hv" 'cperl-get-help [(control h) v])
589 'cperl-info-on-current-command) 687 (if (and cperl-xemacs-p
590 (define-key cperl-mode-map "\C-c\C-hf" 'cperl-info-on-current-command))
591 (if (and (cperl-xemacs-p)
592 (<= emacs-minor-version 11) (<= emacs-major-version 19)) 688 (<= emacs-minor-version 11) (<= emacs-major-version 19))
593 (progn 689 (progn
594 ;; substitute-key-definition is usefulness-deenhanced... 690 ;; substitute-key-definition is usefulness-deenhanced...
595 (define-key cperl-mode-map "\M-q" 'cperl-fill-paragraph) 691 (cperl-define-key "\M-q" 'cperl-fill-paragraph)
596 (define-key cperl-mode-map "\e;" 'cperl-indent-for-comment) 692 (cperl-define-key "\e;" 'cperl-indent-for-comment)
597 (define-key cperl-mode-map "\e\C-\\" 'cperl-indent-region)) 693 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
598 (substitute-key-definition 694 (substitute-key-definition
599 'indent-sexp 'cperl-indent-exp 695 'indent-sexp 'cperl-indent-exp
600 cperl-mode-map global-map) 696 cperl-mode-map global-map)
601 (substitute-key-definition 697 (substitute-key-definition
602 'fill-paragraph 'cperl-fill-paragraph 698 'fill-paragraph 'cperl-fill-paragraph
619 ["Indent expression" cperl-indent-exp t] 715 ["Indent expression" cperl-indent-exp t]
620 ["Fill paragraph/comment" cperl-fill-paragraph t] 716 ["Fill paragraph/comment" cperl-fill-paragraph t]
621 ["Line up a construction" cperl-lineup (cperl-use-region-p)] 717 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
622 "----" 718 "----"
623 ["Indent region" cperl-indent-region (cperl-use-region-p)] 719 ["Indent region" cperl-indent-region (cperl-use-region-p)]
624 ["Comment region" comment-region (cperl-use-region-p)] 720 ["Comment region" cperl-comment-region (cperl-use-region-p)]
625 ["Uncomment region" uncomment-region (cperl-use-region-p)] 721 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
626 "----" 722 "----"
627 ["Run" mode-compile (fboundp 'mode-compile)] 723 ["Run" mode-compile (fboundp 'mode-compile)]
628 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill) 724 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
629 (get-buffer "*compilation*"))] 725 (get-buffer "*compilation*"))]
630 ["Next error" next-error (get-buffer "*compilation*")] 726 ["Next error" next-error (get-buffer "*compilation*")]
631 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)] 727 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
632 "----" 728 "----"
633 ["Debugger" perldb t] 729 ["Debugger" cperl-db t]
634 "----" 730 "----"
635 ("Tools" 731 ("Tools"
636 ["Imenu" imenu (fboundp 'imenu)] 732 ["Imenu" imenu (fboundp 'imenu)]
733 ["Insert spaces if needed" cperl-find-bad-style t]
734 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
735 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
637 ["Imenu on info" cperl-imenu-on-info (featurep 'imenu)] 736 ["Imenu on info" cperl-imenu-on-info (featurep 'imenu)]
638 ("Tags" 737 ("Tags"
639 ["Create tags for current file" cperl-etags t] 738 ;;; ["Create tags for current file" cperl-etags t]
640 ["Add tags for current file" (cperl-etags t) t] 739 ;;; ["Add tags for current file" (cperl-etags t) t]
641 ["Create tags for Perl files in directory" (cperl-etags nil t) t] 740 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
642 ["Add tags for Perl files in directory" (cperl-etags t t) t] 741 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
742 ;;; ["Create tags for Perl files in (sub)directories"
743 ;;; (cperl-etags nil 'recursive) t]
744 ;;; ["Add tags for Perl files in (sub)directories"
745 ;;; (cperl-etags t 'recursive) t])
746 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
747 ["Create tags for current file" (cperl-write-tags nil t) t]
748 ["Add tags for current file" (cperl-write-tags) t]
749 ["Create tags for Perl files in directory"
750 (cperl-write-tags nil t nil t) t]
751 ["Add tags for Perl files in directory"
752 (cperl-write-tags nil nil nil t) t]
643 ["Create tags for Perl files in (sub)directories" 753 ["Create tags for Perl files in (sub)directories"
644 (cperl-etags nil 'recursive) t] 754 (cperl-write-tags nil t t t) t]
645 ["Add tags for Perl files in (sub)directories" 755 ["Add tags for Perl files in (sub)directories"
646 (cperl-etags t 'recursive) t]) 756 (cperl-write-tags nil nil t t) t])
647 ["Recalculate PODs" cperl-find-pods-heres t] 757 ["Recalculate PODs and HEREs" cperl-find-pods-heres t]
648 ["Define word at point" imenu-go-find-at-position 758 ["Define word at point" imenu-go-find-at-position
649 (fboundp 'imenu-go-find-at-position)] 759 (fboundp 'imenu-go-find-at-position)]
650 ["Help on function" cperl-info-on-command t] 760 ["Help on function" cperl-info-on-command t]
651 ["Help on function at point" cperl-info-on-current-command t]) 761 ["Help on function at point" cperl-info-on-current-command t]
762 ["Help on symbol at point" cperl-get-help t]
763 ["Auto-help on" cperl-lazy-install (fboundp 'run-with-idle-timer)]
764 ["Auto-help off" cperl-lazy-unstall
765 (fboundp 'run-with-idle-timer)])
652 ("Toggle..." 766 ("Toggle..."
653 ["Auto newline" cperl-toggle-auto-newline t] 767 ["Auto newline" cperl-toggle-auto-newline t]
654 ["Electric parens" cperl-toggle-electric t] 768 ["Electric parens" cperl-toggle-electric t]
655 ["Electric keywords" cperl-toggle-abbrev t] 769 ["Electric keywords" cperl-toggle-abbrev t]
656 ) 770 )
691 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table) 805 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
692 (modify-syntax-entry ?# "<" cperl-mode-syntax-table) 806 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
693 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table) 807 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
694 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table) 808 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
695 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table) 809 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table)
810 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
696 (modify-syntax-entry ?| "." cperl-mode-syntax-table)) 811 (modify-syntax-entry ?| "." cperl-mode-syntax-table))
697 812
698 813
699 814
700 ;; Make customization possible "in reverse" 815 ;; Make customization possible "in reverse"
747 \"English\" style construct like 862 \"English\" style construct like
748 bite if angry; 863 bite if angry;
749 it will not do any expansion. See also help on variable 864 it will not do any expansion. See also help on variable
750 `cperl-extra-newline-before-brace'. 865 `cperl-extra-newline-before-brace'.
751 866
752 \\[cperl-linefeed] is a convinience replacement for typing carriage 867 \\[cperl-linefeed] is a convenience replacement for typing carriage
753 return. It places you in the next line with proper indentation, or if 868 return. It places you in the next line with proper indentation, or if
754 you type it inside the inline block of control construct, like 869 you type it inside the inline block of control construct, like
755 foreach (@lines) {print; print} 870 foreach (@lines) {print; print}
756 and you are on a boundary of a statement inside braces, it will 871 and you are on a boundary of a statement inside braces, it will
757 transform the construct into a multiline and will place you into an 872 transform the construct into a multiline and will place you into an
758 apporpriately indented blank line. If you need a usual 873 appropriately indented blank line. If you need a usual
759 `newline-and-indent' behaviour, it is on \\[newline-and-indent], 874 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
760 see documentation on `cperl-electric-linefeed'. 875 see documentation on `cperl-electric-linefeed'.
761 876
762 \\{cperl-mode-map} 877 \\{cperl-mode-map}
763 878
778 If your site has perl5 documentation in info format, you can use commands 893 If your site has perl5 documentation in info format, you can use commands
779 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it. 894 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
780 These keys run commands `cperl-info-on-current-command' and 895 These keys run commands `cperl-info-on-current-command' and
781 `cperl-info-on-command', which one is which is controlled by variable 896 `cperl-info-on-command', which one is which is controlled by variable
782 `cperl-info-on-command-no-prompt' (in turn affected by `cperl-hairy'). 897 `cperl-info-on-command-no-prompt' (in turn affected by `cperl-hairy').
898
899 Even if you have no info-format documentation, short one-liner-style
900 help is available on \\[cperl-get-help].
901
902 It is possible to show this help automatically after some idle
903 time. This is regulated by variable `cperl-lazy-help-time'. Default
904 with `cperl-hairy' is 5 secs idle time if the value of this variable
905 is nil. It is also possible to switch this on/off from the
906 menu. Requires `run-with-idle-timer'.
783 907
784 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify', 908 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
785 `cperl-pod-face', `cperl-pod-head-face' control processing of pod and 909 `cperl-pod-face', `cperl-pod-head-face' control processing of pod and
786 here-docs sections. In a future version results of scan may be used 910 here-docs sections. In a future version results of scan may be used
787 for indentation too, currently they are used for highlighting only. 911 for indentation too, currently they are used for highlighting only.
843 (progn 967 (progn
844 (local-set-key "\C-J" 'cperl-linefeed) 968 (local-set-key "\C-J" 'cperl-linefeed)
845 (local-set-key "\C-C\C-J" 'newline-and-indent))) 969 (local-set-key "\C-C\C-J" 'newline-and-indent)))
846 (if (cperl-val 'cperl-info-on-command-no-prompt) 970 (if (cperl-val 'cperl-info-on-command-no-prompt)
847 (progn 971 (progn
848 (if (cperl-xemacs-p) 972 ;; don't clobber the backspace binding:
849 ;; don't clobber the backspace binding: 973 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
850 (local-set-key [(control h) f] 'cperl-info-on-current-command) 974 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
851 (local-set-key "\C-hf" 'cperl-info-on-current-command)) 975 [(control c) (control h) f])))
852 (if (cperl-xemacs-p)
853 ;; don't clobber the backspace binding:
854 (local-set-key [(control c) (control h) f]
855 'cperl-info-on-command)
856 (local-set-key "\C-c\C-hf" 'cperl-info-on-command))))
857 (setq major-mode 'perl-mode) 976 (setq major-mode 'perl-mode)
858 (setq mode-name "CPerl") 977 (setq mode-name "CPerl")
859 (if (not cperl-mode-abbrev-table) 978 (if (not cperl-mode-abbrev-table)
860 (let ((prev-a-c abbrevs-changed)) 979 (let ((prev-a-c abbrevs-changed))
861 (define-abbrev-table 'cperl-mode-abbrev-table '( 980 (define-abbrev-table 'cperl-mode-abbrev-table '(
889 (make-local-variable 'comment-column) 1008 (make-local-variable 'comment-column)
890 (setq comment-column cperl-comment-column) 1009 (setq comment-column cperl-comment-column)
891 (make-local-variable 'comment-start-skip) 1010 (make-local-variable 'comment-start-skip)
892 (setq comment-start-skip "#+ *") 1011 (setq comment-start-skip "#+ *")
893 (make-local-variable 'defun-prompt-regexp) 1012 (make-local-variable 'defun-prompt-regexp)
894 (setq defun-prompt-regexp "^[ \t]*sub\\s +\\([^ \t\n{;]+\\)\\s *") 1013 (setq defun-prompt-regexp "^[ \t]*sub[ \t]+\\([^ \t\n{;]+\\)[ \t]*")
895 (make-local-variable 'comment-indent-function) 1014 (make-local-variable 'comment-indent-function)
896 (setq comment-indent-function 'cperl-comment-indent) 1015 (setq comment-indent-function 'cperl-comment-indent)
897 (make-local-variable 'parse-sexp-ignore-comments) 1016 (make-local-variable 'parse-sexp-ignore-comments)
898 (setq parse-sexp-ignore-comments t) 1017 (setq parse-sexp-ignore-comments t)
899 (make-local-variable 'indent-region-function) 1018 (make-local-variable 'indent-region-function)
926 (progn (or cperl-faces-init (cperl-init-faces)) 1045 (progn (or cperl-faces-init (cperl-init-faces))
927 (font-lock-mode 1)))) 1046 (font-lock-mode 1))))
928 (and (boundp 'msb-menu-cond) 1047 (and (boundp 'msb-menu-cond)
929 (not cperl-msb-fixed) 1048 (not cperl-msb-fixed)
930 (cperl-msb-fix)) 1049 (cperl-msb-fix))
1050 (if (featurep 'easymenu)
1051 (easy-menu-add cperl-menu)) ; A NOP under FSF Emacs.
931 (run-hooks 'cperl-mode-hook) 1052 (run-hooks 'cperl-mode-hook)
932 ;; After hooks since fontification will break this 1053 ;; After hooks since fontification will break this
933 (if cperl-pod-here-scan (cperl-find-pods-heres))) 1054 (if cperl-pod-here-scan (cperl-find-pods-heres)))
1055
1056 ;; Fix for perldb - make default reasonable
1057 (defun cperl-db ()
1058 (interactive)
1059 (require 'gud)
1060 (perldb (read-from-minibuffer "Run perldb (like this): "
1061 (if (consp gud-perldb-history)
1062 (car gud-perldb-history)
1063 (concat "perl " ;;(file-name-nondirectory
1064 ;; I have problems
1065 ;; in OS/2
1066 ;; otherwise
1067 (buffer-file-name)))
1068 nil nil
1069 '(gud-perldb-history . 1))))
934 1070
935 ;; Fix for msb.el 1071 ;; Fix for msb.el
936 (defvar cperl-msb-fixed nil) 1072 (defvar cperl-msb-fixed nil)
937 1073
938 (defun cperl-msb-fix () 1074 (defun cperl-msb-fix ()
991 ;;; (while (< prevc target) 1127 ;;; (while (< prevc target)
992 ;;; (insert " ") 1128 ;;; (insert " ")
993 ;;; (setq prevc (current-column))))))) 1129 ;;; (setq prevc (current-column)))))))
994 1130
995 (defun cperl-indent-for-comment () 1131 (defun cperl-indent-for-comment ()
996 "Substite for `indent-for-comment' in CPerl." 1132 "Substitute for `indent-for-comment' in CPerl."
997 (interactive) 1133 (interactive)
998 (let (cperl-wrong-comment) 1134 (let (cperl-wrong-comment)
999 (indent-for-comment) 1135 (indent-for-comment)
1000 (if cperl-wrong-comment 1136 (if cperl-wrong-comment
1001 (progn (cperl-to-comment-or-eol) 1137 (progn (cperl-to-comment-or-eol)
1002 (forward-char (length comment-start)))))) 1138 (forward-char (length comment-start))))))
1139
1140 (defun cperl-comment-region (b e arg)
1141 "Comment or uncomment each line in the region in CPerl mode.
1142 See `comment-region'."
1143 (interactive "r\np")
1144 (let ((comment-start "#"))
1145 (comment-region b e arg)))
1146
1147 (defun cperl-uncomment-region (b e arg)
1148 "Uncomment or comment each line in the region in CPerl mode.
1149 See `comment-region'."
1150 (interactive "r\np")
1151 (let ((comment-start "#"))
1152 (comment-region b e (- arg))))
1153
1154 (defvar cperl-brace-recursing nil)
1003 1155
1004 (defun cperl-electric-brace (arg &optional only-before) 1156 (defun cperl-electric-brace (arg &optional only-before)
1005 "Insert character and correct line's indentation. 1157 "Insert character and correct line's indentation.
1006 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the 1158 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
1007 place (even in empty line), but not after. If after \")\" and the inserted 1159 place (even in empty line), but not after. If after \")\" and the inserted
1008 char is \"{\", insert extra newline before only if 1160 char is \"{\", insert extra newline before only if
1009 `cperl-extra-newline-before-brace'." 1161 `cperl-extra-newline-before-brace'."
1010 (interactive "P") 1162 (interactive "P")
1011 (let (insertpos) 1163 (let (insertpos
1012 (if (and (not arg) ; No args, end (of empty line or auto) 1164 (other-end (if (and cperl-electric-parens-mark
1013 (eolp) 1165 (cperl-mark-active)
1014 (or (and (null only-before) 1166 (< (mark) (point)))
1015 (save-excursion 1167 (mark)
1016 (skip-chars-backward " \t") 1168 nil)))
1017 (bolp))) 1169 (if (and other-end
1018 (and (eq last-command-char ?\{) ; Do not insert newline 1170 (not cperl-brace-recursing)
1019 ;; if after ")" and `cperl-extra-newline-before-brace' 1171 (cperl-val 'cperl-electric-parens)
1020 ;; is nil, do not insert extra newline. 1172 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
1021 (not cperl-extra-newline-before-brace) 1173 ;; Need to insert a matching pair
1022 (save-excursion
1023 (skip-chars-backward " \t")
1024 (eq (preceding-char) ?\))))
1025 (if cperl-auto-newline
1026 (progn (cperl-indent-line) (newline) t) nil)))
1027 (progn 1174 (progn
1028 (if cperl-auto-newline
1029 (setq insertpos (point)))
1030 (insert last-command-char)
1031 (cperl-indent-line)
1032 (if (and cperl-auto-newline (null only-before))
1033 (progn
1034 (newline)
1035 (cperl-indent-line)))
1036 (save-excursion 1175 (save-excursion
1037 (if insertpos (progn (goto-char insertpos) 1176 (setq insertpos (point-marker))
1038 (search-forward (make-string 1177 (goto-char other-end)
1039 1 last-command-char)) 1178 (setq last-command-char ?\{)
1040 (setq insertpos (1- (point))))) 1179 (cperl-electric-lbrace arg insertpos))
1041 (delete-char -1)))) 1180 (forward-char 1))
1042 (if insertpos 1181 (if (and (not arg) ; No args, end (of empty line or auto)
1043 (save-excursion 1182 (eolp)
1044 (goto-char insertpos) 1183 (or (and (null only-before)
1045 (self-insert-command (prefix-numeric-value arg))) 1184 (save-excursion
1046 (self-insert-command (prefix-numeric-value arg))))) 1185 (skip-chars-backward " \t")
1047 1186 (bolp)))
1048 (defun cperl-electric-lbrace (arg) 1187 (and (eq last-command-char ?\{) ; Do not insert newline
1188 ;; if after ")" and `cperl-extra-newline-before-brace'
1189 ;; is nil, do not insert extra newline.
1190 (not cperl-extra-newline-before-brace)
1191 (save-excursion
1192 (skip-chars-backward " \t")
1193 (eq (preceding-char) ?\))))
1194 (if cperl-auto-newline
1195 (progn (cperl-indent-line) (newline) t) nil)))
1196 (progn
1197 (if cperl-auto-newline
1198 (setq insertpos (point)))
1199 (insert last-command-char)
1200 (cperl-indent-line)
1201 (if (and cperl-auto-newline (null only-before))
1202 (progn
1203 (newline)
1204 (cperl-indent-line)))
1205 (save-excursion
1206 (if insertpos (progn (goto-char insertpos)
1207 (search-forward (make-string
1208 1 last-command-char))
1209 (setq insertpos (1- (point)))))
1210 (delete-char -1))))
1211 (if insertpos
1212 (save-excursion
1213 (goto-char insertpos)
1214 (self-insert-command (prefix-numeric-value arg)))
1215 (self-insert-command (prefix-numeric-value arg))))))
1216
1217 (defun cperl-electric-lbrace (arg &optional end)
1049 "Insert character, correct line's indentation, correct quoting by space." 1218 "Insert character, correct line's indentation, correct quoting by space."
1050 (interactive "P") 1219 (interactive "P")
1051 (let (pos after 1220 (let (pos after
1221 (cperl-brace-recursing t)
1052 (cperl-auto-newline cperl-auto-newline) 1222 (cperl-auto-newline cperl-auto-newline)
1053 (other-end (if (and cperl-electric-parens-mark 1223 (other-end (or end
1054 (cperl-mark-active) 1224 (if (and cperl-electric-parens-mark
1055 (> (mark) (point))) 1225 (cperl-mark-active)
1056 (save-excursion 1226 (> (mark) (point)))
1057 (goto-char (mark)) 1227 (save-excursion
1058 (point-marker)) 1228 (goto-char (mark))
1059 nil))) 1229 (point-marker))
1230 nil))))
1060 (and (cperl-val 'cperl-electric-lbrace-space) 1231 (and (cperl-val 'cperl-electric-lbrace-space)
1061 (eq (preceding-char) ?$) 1232 (eq (preceding-char) ?$)
1062 (save-excursion 1233 (save-excursion
1063 (skip-chars-backward "$") 1234 (skip-chars-backward "$")
1064 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)")) 1235 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
1103 (?< . ?>))))) 1274 (?< . ?>)))))
1104 (forward-char -1)) 1275 (forward-char -1))
1105 (insert last-command-char) 1276 (insert last-command-char)
1106 ))) 1277 )))
1107 1278
1279 (defun cperl-electric-rparen (arg)
1280 "Insert a matching pair of parentheses if marking is active.
1281 If not, or if we are not at the end of marking range, would self-insert."
1282 (interactive "P")
1283 (let ((beg (save-excursion (beginning-of-line) (point)))
1284 (other-end (if (and cperl-electric-parens-mark
1285 (cperl-mark-active)
1286 (< (mark) (point)))
1287 (mark)
1288 nil))
1289 p)
1290 (if (and other-end
1291 (cperl-val 'cperl-electric-parens)
1292 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
1293 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
1294 ;;(not (save-excursion (search-backward "#" beg t)))
1295 )
1296 (progn
1297 (insert last-command-char)
1298 (setq p (point))
1299 (if other-end (goto-char other-end))
1300 (insert (cdr (assoc last-command-char '((?\} . ?\{)
1301 (?\] . ?\[)
1302 (?\) . ?\()
1303 (?\> . ?\<)))))
1304 (goto-char (1+ p)))
1305 (call-interactively 'self-insert-command)
1306 )))
1307
1108 (defun cperl-electric-keyword () 1308 (defun cperl-electric-keyword ()
1109 "Insert a construction appropriate after a keyword." 1309 "Insert a construction appropriate after a keyword."
1110 (let ((beg (save-excursion (beginning-of-line) (point))) 1310 (let ((beg (save-excursion (beginning-of-line) (point)))
1111 (dollar (eq (preceding-char) ?$))) 1311 (dollar (eq last-command-char ?$)))
1112 (and (save-excursion 1312 (and (save-excursion
1113 (backward-sexp 1) 1313 (backward-sexp 1)
1114 (cperl-after-expr-p nil "{};:")) 1314 (cperl-after-expr-p nil "{};:"))
1115 (save-excursion 1315 (save-excursion
1116 (not 1316 (not
1179 (end (save-excursion (end-of-line) (point))) 1379 (end (save-excursion (end-of-line) (point)))
1180 (pos (point)) start) 1380 (pos (point)) start)
1181 (if (and ; Check if we need to split: 1381 (if (and ; Check if we need to split:
1182 ; i.e., on a boundary and inside "{...}" 1382 ; i.e., on a boundary and inside "{...}"
1183 (save-excursion (cperl-to-comment-or-eol) 1383 (save-excursion (cperl-to-comment-or-eol)
1184 (>= (point) pos)) 1384 (>= (point) pos)) ; Not in a comment
1185 (or (save-excursion 1385 (or (save-excursion
1186 (skip-chars-backward " \t" beg) 1386 (skip-chars-backward " \t" beg)
1187 (forward-char -1) 1387 (forward-char -1)
1188 (looking-at "[;{]")) 1388 (looking-at "[;{]")) ; After { or ; + spaces
1189 (looking-at "[ \t]*}") 1389 (looking-at "[ \t]*}") ; Before }
1190 (re-search-forward "\\=[ \t]*;" end t)) 1390 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
1191 (save-excursion 1391 (save-excursion
1192 (and 1392 (and
1193 (eq (car (parse-partial-sexp pos end -1)) -1) 1393 (eq (car (parse-partial-sexp pos end -1)) -1)
1394 ; Leave the level of parens
1194 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr 1395 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
1396 ; Are at end
1195 (progn 1397 (progn
1196 (backward-sexp 1) 1398 (backward-sexp 1)
1197 (setq start (point-marker)) 1399 (setq start (point-marker))
1198 (<= start pos))))) 1400 (<= start pos))))) ; Redundant? Are after the
1401 ; start of parens group.
1199 (progn 1402 (progn
1200 (skip-chars-backward " \t") 1403 (skip-chars-backward " \t")
1201 (or (memq (preceding-char) (append ";{" nil)) 1404 (or (memq (preceding-char) (append ";{" nil))
1202 (insert ";")) 1405 (insert ";"))
1203 (insert "\n") 1406 (insert "\n")
1226 (forward-line -1))) 1429 (forward-line -1)))
1227 (forward-line -1) ; We are on the line before target 1430 (forward-line -1) ; We are on the line before target
1228 (end-of-line) 1431 (end-of-line)
1229 (newline-and-indent)) 1432 (newline-and-indent))
1230 (end-of-line) ; else 1433 (end-of-line) ; else
1231 (if (not (looking-at "\n[ \t]*$")) 1434 (cond
1232 (newline-and-indent) 1435 ((and (looking-at "\n[ \t]*{$")
1233 (forward-line 1) 1436 (save-excursion
1234 (cperl-indent-line))))) 1437 (skip-chars-backward " \t")
1438 (eq (preceding-char) ?\)))) ; Probably if () {} group
1439 ; with an extra newline.
1440 (forward-line 2)
1441 (cperl-indent-line))
1442 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
1443 (forward-line 1)
1444 (cperl-indent-line))
1445 (t
1446 (newline-and-indent))))))
1235 1447
1236 (defun cperl-electric-semi (arg) 1448 (defun cperl-electric-semi (arg)
1237 "Insert character and correct line's indentation." 1449 "Insert character and correct line's indentation."
1238 (interactive "P") 1450 (interactive "P")
1239 (if cperl-auto-newline 1451 (if cperl-auto-newline
1245 (interactive "P") 1457 (interactive "P")
1246 (let (insertpos (end (point)) 1458 (let (insertpos (end (point))
1247 (auto (and cperl-auto-newline 1459 (auto (and cperl-auto-newline
1248 (or (not (eq last-command-char ?:)) 1460 (or (not (eq last-command-char ?:))
1249 cperl-auto-newline-after-colon)))) 1461 cperl-auto-newline-after-colon))))
1250 (if (and (not arg) (eolp) 1462 (if (and ;;(not arg)
1463 (eolp)
1251 (not (save-excursion 1464 (not (save-excursion
1252 (beginning-of-line) 1465 (beginning-of-line)
1253 (skip-chars-forward " \t") 1466 (skip-chars-forward " \t")
1254 (or 1467 (or
1255 ;; Ignore in comment lines 1468 ;; Ignore in comment lines
1268 (beginning-of-defun) 1481 (beginning-of-defun)
1269 (let ((pps (parse-partial-sexp (point) end))) 1482 (let ((pps (parse-partial-sexp (point) end)))
1270 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))))) 1483 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
1271 (progn 1484 (progn
1272 (insert last-command-char) 1485 (insert last-command-char)
1273 (forward-char -1) 1486 ;;(forward-char -1)
1274 (if auto (setq insertpos (point-marker))) 1487 (if auto (setq insertpos (point-marker)))
1275 (forward-char 1) 1488 ;;(forward-char 1)
1276 (cperl-indent-line) 1489 (cperl-indent-line)
1277 (if auto 1490 (if auto
1278 (progn 1491 (progn
1279 (newline) 1492 (newline)
1280 (cperl-indent-line))) 1493 (cperl-indent-line)))
1283 ;; (search-forward (make-string 1496 ;; (search-forward (make-string
1284 ;; 1 last-command-char)) 1497 ;; 1 last-command-char))
1285 ;; (setq insertpos (1- (point))))) 1498 ;; (setq insertpos (1- (point)))))
1286 ;; (delete-char -1)))) 1499 ;; (delete-char -1))))
1287 (save-excursion 1500 (save-excursion
1288 (if insertpos (goto-char (marker-position insertpos)) 1501 (if insertpos (goto-char (1- (marker-position insertpos)))
1289 (forward-char -1)) 1502 (forward-char -1))
1290 (delete-char 1)))) 1503 (delete-char 1))))
1291 (if insertpos 1504 (if insertpos
1292 (save-excursion 1505 (save-excursion
1293 (goto-char insertpos) 1506 (goto-char insertpos)
1319 (goto-char (point-max)) 1532 (goto-char (point-max))
1320 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\())) 1533 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
1321 (error nil))) 1534 (error nil)))
1322 1535
1323 (defun cperl-indent-command (&optional whole-exp) 1536 (defun cperl-indent-command (&optional whole-exp)
1324 (interactive "P")
1325 "Indent current line as Perl code, or in some cases insert a tab character. 1537 "Indent current line as Perl code, or in some cases insert a tab character.
1326 If `cperl-tab-always-indent' is non-nil (the default), always indent current line. 1538 If `cperl-tab-always-indent' is non-nil (the default), always indent current line.
1327 Otherwise, indent the current line only if point is at the left margin 1539 Otherwise, indent the current line only if point is at the left margin
1328 or in the line's indentation; otherwise insert a tab. 1540 or in the line's indentation; otherwise insert a tab.
1329 1541
1330 A numeric argument, regardless of its value, 1542 A numeric argument, regardless of its value,
1331 means indent rigidly all the lines of the expression starting after point 1543 means indent rigidly all the lines of the expression starting after point
1332 so that this line becomes properly indented. 1544 so that this line becomes properly indented.
1333 The relative indentation among the lines of the expression are preserved." 1545 The relative indentation among the lines of the expression are preserved."
1546 (interactive "P")
1334 (if whole-exp 1547 (if whole-exp
1335 ;; If arg, always indent this line as Perl 1548 ;; If arg, always indent this line as Perl
1336 ;; and shift remaining lines of expression the same amount. 1549 ;; and shift remaining lines of expression the same amount.
1337 (let ((shift-amt (cperl-indent-line)) 1550 (let ((shift-amt (cperl-indent-line))
1338 beg end) 1551 beg end)
1401 (and (eq (preceding-char) ?:) 1614 (and (eq (preceding-char) ?:)
1402 (memq (char-syntax (char-after (- (point) 2))) 1615 (memq (char-syntax (char-after (- (point) 2)))
1403 '(?w ?_)) 1616 '(?w ?_))
1404 (progn 1617 (progn
1405 (backward-sexp) 1618 (backward-sexp)
1406 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:")))) 1619 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
1407 1620
1408 (defun cperl-get-state (&optional parse-start start-state) 1621 (defun cperl-get-state (&optional parse-start start-state)
1409 ;; returns list (START STATE DEPTH PRESTART), START is a good place 1622 ;; returns list (START STATE DEPTH PRESTART), START is a good place
1410 ;; to start parsing, STATE is what is returned by 1623 ;; to start parsing, STATE is what is returned by
1411 ;; `parse-partial-sexp'. DEPTH is true is we are immediately after 1624 ;; `parse-partial-sexp'. DEPTH is true is we are immediately after
1439 (cperl-backward-to-noncomment (point-min)) 1652 (cperl-backward-to-noncomment (point-min))
1440 ;;(skip-chars-backward " \t\n\f") 1653 ;;(skip-chars-backward " \t\n\f")
1441 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp 1654 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
1442 ; Label may be mixed up with `$blah :' 1655 ; Label may be mixed up with `$blah :'
1443 (save-excursion (cperl-after-label)) 1656 (save-excursion (cperl-after-label))
1444 (and (eq (char-syntax (preceding-char)) ?w) 1657 (and (memq (char-syntax (preceding-char)) '(?w ?_))
1445 (progn 1658 (progn
1446 (backward-sexp) 1659 (backward-sexp)
1447 ;; Need take into account `bless', `return', `tr',... 1660 ;; Need take into account `bless', `return', `tr',...
1448 (or (and (looking-at "\\sw+[ \t\n\f]*[{#]") ; Method call syntax 1661 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
1449 (not (looking-at "\\(bless\\|return\\|qw\\|tr\\|[smy]\\)\\>"))) 1662 (not (looking-at "\\(bless\\|return\\|qw\\|tr\\|[smy]\\)\\>")))
1450 (progn 1663 (progn
1451 (skip-chars-backward " \t\n\f") 1664 (skip-chars-backward " \t\n\f")
1452 (and (eq (char-syntax (preceding-char)) ?w) 1665 (and (memq (char-syntax (preceding-char)) '(?w ?_))
1453 (progn 1666 (progn
1454 (backward-sexp) 1667 (backward-sexp)
1455 (looking-at 1668 (looking-at
1456 "sub[ \t]+\\sw+[ \t\n\f]*[#{]"))))))))) 1669 "sub[ \t]+[a-zA-Z0-9_:]+[ \t\n\f]*[#{]")))))))))
1457 1670
1458 (defun cperl-calculate-indent (&optional parse-start symbol) 1671 (defun cperl-calculate-indent (&optional parse-start symbol)
1459 "Return appropriate indentation for current line as Perl code. 1672 "Return appropriate indentation for current line as Perl code.
1460 In usual case returns an integer: the column to indent to. 1673 In usual case returns an integer: the column to indent to.
1461 Returns nil if line starts inside a string, t if in a comment." 1674 Returns nil if line starts inside a string, t if in a comment."
1534 ;; to determine whether we are in top-level decls 1747 ;; to determine whether we are in top-level decls
1535 ;; or function's arg decls. Set basic-indent accordingly. 1748 ;; or function's arg decls. Set basic-indent accordingly.
1536 ;; Now add a little if this is a continuation line. 1749 ;; Now add a little if this is a continuation line.
1537 (if (or (bobp) 1750 (if (or (bobp)
1538 (memq (preceding-char) (append " ;}" nil)) ; Was ?\) 1751 (memq (preceding-char) (append " ;}" nil)) ; Was ?\)
1539 (memq char-after (append ")]}" nil))) 1752 (memq char-after (append ")]}" nil))
1753 (and (eq (preceding-char) ?\:) ; label
1754 (progn
1755 (forward-sexp -1)
1756 (skip-chars-backward " \t")
1757 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:"))))
1540 0 1758 0
1541 cperl-continued-statement-offset)))) 1759 cperl-continued-statement-offset))))
1542 ((/= (char-after containing-sexp) ?{) 1760 ((/= (char-after containing-sexp) ?{)
1543 ;; line is expression, not statement: 1761 ;; line is expression, not statement:
1544 ;; indent to just after the surrounding open, 1762 ;; indent to just after the surrounding open,
1596 (goto-char containing-sexp) 1814 (goto-char containing-sexp)
1597 ;; Is line first statement after an open-brace? 1815 ;; Is line first statement after an open-brace?
1598 (or 1816 (or
1599 ;; If no, find that first statement and indent like 1817 ;; If no, find that first statement and indent like
1600 ;; it. If the first statement begins with label, do 1818 ;; it. If the first statement begins with label, do
1601 ;; not belive when the indentation of the label is too 1819 ;; not believe when the indentation of the label is too
1602 ;; small. 1820 ;; small.
1603 (save-excursion 1821 (save-excursion
1604 (forward-char 1) 1822 (forward-char 1)
1605 (setq old-indent (current-indentation)) 1823 (setq old-indent (current-indentation))
1606 (let ((colon-line-end 0)) 1824 (let ((colon-line-end 0))
1619 (and (< (point) indent-point) 1837 (and (< (point) indent-point)
1620 (if (> colon-line-end (point)) ; After label 1838 (if (> colon-line-end (point)) ; After label
1621 (if (> (current-indentation) 1839 (if (> (current-indentation)
1622 cperl-min-label-indent) 1840 cperl-min-label-indent)
1623 (- (current-indentation) cperl-label-offset) 1841 (- (current-indentation) cperl-label-offset)
1624 ;; Do not belive: `max' is involved 1842 ;; Do not believe: `max' is involved
1625 (+ old-indent cperl-indent-level)) 1843 (+ old-indent cperl-indent-level))
1626 (current-column))))) 1844 (current-column)))))
1627 ;; If no previous statement, 1845 ;; If no previous statement,
1628 ;; indent it relative to line brace is on. 1846 ;; indent it relative to line brace is on.
1629 ;; For open brace in column zero, don't let statement 1847 ;; For open brace in column zero, don't let statement
1646 ;; possibly a different line 1864 ;; possibly a different line
1647 (progn 1865 (progn
1648 (if (eq (preceding-char) ?\)) 1866 (if (eq (preceding-char) ?\))
1649 (forward-sexp -1)) 1867 (forward-sexp -1))
1650 ;; In the case it starts a subroutine, indent with 1868 ;; In the case it starts a subroutine, indent with
1651 ;; respect to `sub', not with respect to the 1869 ;; respect to `sub', not with respect to the the
1652 ;; first thing on the line, say in the case of 1870 ;; first thing on the line, say in the case of
1653 ;; anonymous sub in a hash. 1871 ;; anonymous sub in a hash.
1654 ;; 1872 ;;
1655 (skip-chars-backward " \t") 1873 (skip-chars-backward " \t")
1656 (if (and (eq (preceding-char) ?b) 1874 (if (and (eq (preceding-char) ?b)
1769 (goto-char containing-sexp) 1987 (goto-char containing-sexp)
1770 ;; Is line first statement after an open-brace? 1988 ;; Is line first statement after an open-brace?
1771 (or 1989 (or
1772 ;; If no, find that first statement and indent like 1990 ;; If no, find that first statement and indent like
1773 ;; it. If the first statement begins with label, do 1991 ;; it. If the first statement begins with label, do
1774 ;; not belive when the indentation of the label is too 1992 ;; not believe when the indentation of the label is too
1775 ;; small. 1993 ;; small.
1776 (save-excursion 1994 (save-excursion
1777 (forward-char 1) 1995 (forward-char 1)
1778 (let ((colon-line-end 0)) 1996 (let ((colon-line-end 0))
1779 (while (progn (skip-chars-forward " \t\n" start-point) 1997 (while (progn (skip-chars-forward " \t\n" start-point)
1795 (if (> colon-line-end (point)) 2013 (if (> colon-line-end (point))
1796 ;; Before statement after label 2014 ;; Before statement after label
1797 (if (> (current-indentation) 2015 (if (> (current-indentation)
1798 cperl-min-label-indent) 2016 cperl-min-label-indent)
1799 (list (list 'label-in-block (point))) 2017 (list (list 'label-in-block (point)))
1800 ;; Do not belive: `max' is involved 2018 ;; Do not believe: `max' is involved
1801 (list 2019 (list
1802 (list 'label-in-block-min-indent (point)))) 2020 (list 'label-in-block-min-indent (point))))
1803 ;; Before statement 2021 ;; Before statement
1804 (list 'statement-in-block (point)))))) 2022 (list 'statement-in-block (point))))))
1805 ;; If no previous statement, 2023 ;; If no previous statement,
1907 the sections using `cperl-pod-head-face', `cperl-pod-face', 2125 the sections using `cperl-pod-head-face', `cperl-pod-face',
1908 `cperl-here-face'." 2126 `cperl-here-face'."
1909 (interactive) 2127 (interactive)
1910 (or min (setq min (point-min))) 2128 (or min (setq min (point-min)))
1911 (or max (setq max (point-max))) 2129 (or max (setq max (point-max)))
1912 (let (face head-face here-face b e bb tag err 2130 (let (face head-face here-face b e bb tag qtag err b1 e1 argument
1913 (cperl-pod-here-fontify (eval cperl-pod-here-fontify)) 2131 (cperl-pod-here-fontify (eval cperl-pod-here-fontify))
1914 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t) 2132 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
1915 (modified (buffer-modified-p))) 2133 (modified (buffer-modified-p))
2134 (after-change-functions nil)
2135 (search
2136 (concat
2137 "\\(\\`\n?\\|\n\n\\)="
2138 "\\|"
2139 ;; One extra () before this:
2140 "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\3\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)[^=]\\)" ; [^=] to avoid <<=.
2141 "\\|"
2142 ;; 1+5 extra () before this:
2143 "^[ \t]*format[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$")))
1916 (unwind-protect 2144 (unwind-protect
1917 (progn 2145 (progn
1918 (save-excursion 2146 (save-excursion
1919 (message "Scanning for pods and here-docs...") 2147 (message "Scanning for pods, formats and here-docs...")
1920 (if cperl-pod-here-fontify 2148 (if cperl-pod-here-fontify
1921 (setq face (eval cperl-pod-face) 2149 ;; We had evals here, do not know why...
1922 head-face (eval cperl-pod-head-face) 2150 (setq face cperl-pod-face
1923 here-face (eval cperl-here-face))) 2151 head-face cperl-pod-head-face
2152 here-face cperl-here-face))
1924 (remove-text-properties min max '(syntax-type t)) 2153 (remove-text-properties min max '(syntax-type t))
1925 ;; Need to remove face as well... 2154 ;; Need to remove face as well...
1926 (goto-char min) 2155 (goto-char min)
1927 (while (re-search-forward "\\(\\`\n?\\|\n\n\\)=" max t) 2156 (while (re-search-forward search max t)
1928 (if (looking-at "\n*cut\\>") 2157 (cond
1929 (progn 2158 ((match-beginning 1) ; POD section
1930 (message "=cut is not preceeded by a pod section") 2159 ;; "\\(\\`\n?\\|\n\n\\)="
1931 (setq err (point))) 2160 (if (looking-at "\n*cut\\>")
2161 (progn
2162 (message "=cut is not preceeded by a pod section")
2163 (setq err (point)))
2164 (beginning-of-line)
2165
2166 (setq b (point) bb b)
2167 (or (re-search-forward "\n\n=cut\\>" max 'toend)
2168 (message "Cannot find the end of a pod section"))
2169 (beginning-of-line 3)
2170 (setq e (point))
2171 (put-text-property b e 'in-pod t)
2172 (goto-char b)
2173 (while (re-search-forward "\n\n[ \t]" e t)
2174 (beginning-of-line)
2175 (put-text-property b (point) 'syntax-type 'pod)
2176 (cperl-put-do-not-fontify b (point))
2177 ;;(put-text-property (max (point-min) (1- b))
2178 ;; (point) cperl-do-not-fontify t)
2179 (if cperl-pod-here-fontify (put-text-property b (point) 'face face))
2180 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
2181 (beginning-of-line)
2182 (setq b (point)))
2183 (put-text-property (point) e 'syntax-type 'pod)
2184 (cperl-put-do-not-fontify (point) e)
2185 ;;(put-text-property (max (point-min) (1- (point)))
2186 ;; e cperl-do-not-fontify t)
2187 (if cperl-pod-here-fontify
2188 (progn (put-text-property (point) e 'face face)
2189 (goto-char bb)
2190 (if (looking-at
2191 "=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
2192 (put-text-property
2193 (match-beginning 1) (match-end 1)
2194 'face head-face))
2195 (while (re-search-forward
2196 ;; One paragraph
2197 "\n\n=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
2198 e 'toend)
2199 (put-text-property
2200 (match-beginning 1) (match-end 1)
2201 'face head-face))))
2202 (goto-char e)))
2203 ;; Here document
2204 ;; 1 () ahead
2205 ;; "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\3\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)\\)"
2206 ((match-beginning 2) ; 1 + 1
2207 ;; Abort in comment (_extremely_ simplified):
2208 (setq b (point))
2209 (if (save-excursion
2210 (beginning-of-line)
2211 (search-forward "#" b t))
2212 nil
2213 (if (match-beginning 5) ;4 + 1
2214 (setq b1 (match-beginning 5) ; 4 + 1
2215 e1 (match-end 5)) ; 4 + 1
2216 (setq b1 (match-beginning 4) ; 3 + 1
2217 e1 (match-end 4))) ; 3 + 1
2218 (setq tag (buffer-substring b1 e1)
2219 qtag (regexp-quote tag))
2220 (cond (cperl-pod-here-fontify
2221 (put-text-property b1 e1 'face font-lock-reference-face)
2222 (cperl-put-do-not-fontify b1 e1)))
2223 (forward-line)
2224 (setq b (point))
2225 (cond ((re-search-forward (concat "^" qtag "$") max 'toend)
2226 (if cperl-pod-here-fontify
2227 (progn
2228 (put-text-property (match-beginning 0) (match-end 0)
2229 'face font-lock-reference-face)
2230 (cperl-put-do-not-fontify b (match-end 0))
2231 ;;(put-text-property (max (point-min) (1- b))
2232 ;; (min (point-max)
2233 ;; (1+ (match-end 0)))
2234 ;; cperl-do-not-fontify t)
2235 (put-text-property b (match-beginning 0)
2236 'face here-face)))
2237 (put-text-property b (match-beginning 0)
2238 'syntax-type 'here-doc)
2239 (cperl-put-do-not-fontify b (match-beginning 0)))
2240 (t (message "End of here-document `%s' not found." tag)))))
2241 ;; format
2242 (t
2243 ;; 1+5=6 extra () before this:
2244 ;; "^[ \t]*format[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$")))
2245 (setq b (point)
2246 name (if (match-beginning 7) ; 6 + 1
2247 (buffer-substring (match-beginning 7) ; 6 + 1
2248 (match-end 7)) ; 6 + 1
2249 ""))
2250 (setq argument nil)
2251 (if cperl-pod-here-fontify
2252 (while (and (eq (forward-line) 0)
2253 (not (looking-at "^[.;]$")))
2254 (cond
2255 ((looking-at "^#")) ; Skip comments
2256 ((and argument ; Skip argument multi-lines
2257 (looking-at "^[ \t]*{"))
2258 (forward-sexp 1)
2259 (setq argument nil))
2260 (argument ; Skip argument lines
2261 (setq argument nil))
2262 (t ; Format line
2263 (setq b1 (point))
2264 (setq argument (looking-at "^[^\n]*[@^]"))
2265 (end-of-line)
2266 (put-text-property b1 (point)
2267 'face font-lock-string-face)
2268 (cperl-put-do-not-fontify b1 (point)))))
2269 (re-search-forward (concat "^[.;]$") max 'toend))
1932 (beginning-of-line) 2270 (beginning-of-line)
1933 (setq b (point) bb b) 2271 (if (looking-at "^[.;]$")
1934 (or (re-search-forward "\n\n=cut\\>" max 'toend) 2272 (progn
1935 (message "Cannot find the end of a pod section")) 2273 (put-text-property (point) (+ (point) 2)
1936 (beginning-of-line 4) 2274 'face font-lock-string-face)
1937 (setq e (point)) 2275 (cperl-put-do-not-fontify (point) (+ (point) 2)))
1938 (put-text-property b e 'in-pod t) 2276 (message "End of format `%s' not found." name))
1939 (goto-char b) 2277 (forward-line)
1940 (while (re-search-forward "\n\n[ \t]" e t) 2278 (put-text-property b (point) 'syntax-type 'format)
1941 (beginning-of-line) 2279 ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend)
1942 (put-text-property b (point) 'syntax-type 'pod) 2280 ;;; (if cperl-pod-here-fontify
1943 (put-text-property (max (point-min) (1- b)) 2281 ;;; (progn
1944 (point) cperl-do-not-fontify t) 2282 ;;; (put-text-property b (match-end 0)
1945 (if cperl-pod-here-fontify (put-text-property b (point) 'face face)) 2283 ;;; 'face font-lock-string-face)
1946 (re-search-forward "\n\n[^ \t\f]" e 'toend) 2284 ;;; (cperl-put-do-not-fontify b (match-end 0))))
1947 (beginning-of-line) 2285 ;;; (put-text-property b (match-end 0)
1948 (setq b (point))) 2286 ;;; 'syntax-type 'format)
1949 (put-text-property (point) e 'syntax-type 'pod) 2287 ;;; (cperl-put-do-not-fontify b (match-beginning 0)))
1950 (put-text-property (max (point-min) (1- (point))) 2288 ;;; (t (message "End of format `%s' not found." name)))
1951 e cperl-do-not-fontify t) 2289 )))
1952 (if cperl-pod-here-fontify 2290 ;;; (while (re-search-forward "\\(\\`\n?\\|\n\n\\)=" max t)
1953 (progn (put-text-property (point) e 'face face) 2291 ;;; (if (looking-at "\n*cut\\>")
1954 (goto-char bb) 2292 ;;; (progn
1955 (while (re-search-forward 2293 ;;; (message "=cut is not preceeded by a pod section")
1956 ;; One paragraph 2294 ;;; (setq err (point)))
1957 "\n\n=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$" 2295 ;;; (beginning-of-line)
1958 e 'toend) 2296
1959 (put-text-property 2297 ;;; (setq b (point) bb b)
1960 (match-beginning 1) (match-end 1) 2298 ;;; (or (re-search-forward "\n\n=cut\\>" max 'toend)
1961 'face head-face)))) 2299 ;;; (message "Cannot find the end of a pod section"))
1962 (goto-char e))) 2300 ;;; (beginning-of-line 3)
1963 (goto-char min) 2301 ;;; (setq e (point))
1964 (while (re-search-forward 2302 ;;; (put-text-property b e 'in-pod t)
1965 "<<\\(\\([\"'`]\\)?\\)\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\1" 2303 ;;; (goto-char b)
1966 max t) 2304 ;;; (while (re-search-forward "\n\n[ \t]" e t)
1967 (setq tag (buffer-substring (match-beginning 3) 2305 ;;; (beginning-of-line)
1968 (match-end 3))) 2306 ;;; (put-text-property b (point) 'syntax-type 'pod)
1969 (if cperl-pod-here-fontify 2307 ;;; (cperl-put-do-not-fontify b (point))
1970 (put-text-property (match-beginning 3) (match-end 3) 2308 ;;; ;;(put-text-property (max (point-min) (1- b))
1971 'face font-lock-reference-face)) 2309 ;;; ;; (point) cperl-do-not-fontify t)
1972 (forward-line) 2310 ;;; (if cperl-pod-here-fontify (put-text-property b (point) 'face face))
1973 (setq b (point)) 2311 ;;; (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
1974 (and (re-search-forward (concat "^" tag "$") max 'toend) 2312 ;;; (beginning-of-line)
1975 (progn 2313 ;;; (setq b (point)))
1976 (if cperl-pod-here-fontify 2314 ;;; (put-text-property (point) e 'syntax-type 'pod)
1977 (progn 2315 ;;; (cperl-put-do-not-fontify (point) e)
1978 (put-text-property (match-beginning 0) (match-end 0) 2316 ;;; ;;(put-text-property (max (point-min) (1- (point)))
1979 'face font-lock-reference-face) 2317 ;;; ;; e cperl-do-not-fontify t)
1980 (put-text-property (max (point-min) (1- b)) 2318 ;;; (if cperl-pod-here-fontify
1981 (min (point-max) 2319 ;;; (progn (put-text-property (point) e 'face face)
1982 (1+ (match-end 0))) 2320 ;;; (goto-char bb)
1983 cperl-do-not-fontify t) 2321 ;;; (if (looking-at
1984 (put-text-property b (match-beginning 0) 2322 ;;; "=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
1985 'face here-face))) 2323 ;;; (put-text-property
1986 (put-text-property b (match-beginning 0) 2324 ;;; (match-beginning 1) (match-end 1)
1987 'syntax-type 'here-doc))))) 2325 ;;; 'face head-face))
2326 ;;; (while (re-search-forward
2327 ;;; ;; One paragraph
2328 ;;; "\n\n=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
2329 ;;; e 'toend)
2330 ;;; (put-text-property
2331 ;;; (match-beginning 1) (match-end 1)
2332 ;;; 'face head-face))))
2333 ;;; (goto-char e)))
2334 ;;; (goto-char min)
2335 ;;; (while (re-search-forward
2336 ;;; ;; We exclude \n to avoid misrecognition inside quotes.
2337 ;;; "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\2\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)\\)"
2338 ;;; max t)
2339 ;;; (if (match-beginning 4)
2340 ;;; (setq b1 (match-beginning 4)
2341 ;;; e1 (match-end 4))
2342 ;;; (setq b1 (match-beginning 3)
2343 ;;; e1 (match-end 3)))
2344 ;;; (setq tag (buffer-substring b1 e1)
2345 ;;; qtag (regexp-quote tag))
2346 ;;; (cond (cperl-pod-here-fontify
2347 ;;; (put-text-property b1 e1 'face font-lock-reference-face)
2348 ;;; (cperl-put-do-not-fontify b1 e1)))
2349 ;;; (forward-line)
2350 ;;; (setq b (point))
2351 ;;; (cond ((re-search-forward (concat "^" qtag "$") max 'toend)
2352 ;;; (if cperl-pod-here-fontify
2353 ;;; (progn
2354 ;;; (put-text-property (match-beginning 0) (match-end 0)
2355 ;;; 'face font-lock-reference-face)
2356 ;;; (cperl-put-do-not-fontify b (match-end 0))
2357 ;;; ;;(put-text-property (max (point-min) (1- b))
2358 ;;; ;; (min (point-max)
2359 ;;; ;; (1+ (match-end 0)))
2360 ;;; ;; cperl-do-not-fontify t)
2361 ;;; (put-text-property b (match-beginning 0)
2362 ;;; 'face here-face)))
2363 ;;; (put-text-property b (match-beginning 0)
2364 ;;; 'syntax-type 'here-doc)
2365 ;;; (cperl-put-do-not-fontify b (match-beginning 0)))
2366 ;;; (t (message "End of here-document `%s' not found." tag))))
2367 ;;; (goto-char min)
2368 ;;; (while (re-search-forward
2369 ;;; "^[ \t]*format[ \t]*\\(\\([a-zA-Z0-9_]+[ \t]*\\)?\\)=[ \t]*$"
2370 ;;; max t)
2371 ;;; (setq b (point)
2372 ;;; name (buffer-substring (match-beginning 1)
2373 ;;; (match-end 1)))
2374 ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend)
2375 ;;; (if cperl-pod-here-fontify
2376 ;;; (progn
2377 ;;; (put-text-property b (match-end 0)
2378 ;;; 'face font-lock-string-face)
2379 ;;; (cperl-put-do-not-fontify b (match-end 0))))
2380 ;;; (put-text-property b (match-end 0)
2381 ;;; 'syntax-type 'format)
2382 ;;; (cperl-put-do-not-fontify b (match-beginning 0)))
2383 ;;; (t (message "End of format `%s' not found." name))))
2384 )
1988 (if err (goto-char err) 2385 (if err (goto-char err)
1989 (message "Scan for pods and here-docs completed."))) 2386 (message "Scan for pods, formats and here-docs completed.")))
1990 (and (buffer-modified-p) 2387 (and (buffer-modified-p)
1991 (not modified) 2388 (not modified)
1992 (set-buffer-modified-p nil))))) 2389 (set-buffer-modified-p nil)))))
1993 2390
1994 (defun cperl-backward-to-noncomment (lim) 2391 (defun cperl-backward-to-noncomment (lim)
2232 (or (memq (preceding-char) '(?\ ?\t)) (insert " ")))))) 2629 (or (memq (preceding-char) '(?\ ?\t)) (insert " "))))))
2233 2630
2234 (defvar imenu-example--function-name-regexp-perl 2631 (defvar imenu-example--function-name-regexp-perl
2235 "^\\([ \t]*\\(sub\\|package\\)[ \t\n]+\\([a-zA-Z_0-9:']+\\)[ \t]*\\|=head\\([12]\\)[ \t]+\\([^\n]+\\)$\\)") 2632 "^\\([ \t]*\\(sub\\|package\\)[ \t\n]+\\([a-zA-Z_0-9:']+\\)[ \t]*\\|=head\\([12]\\)[ \t]+\\([^\n]+\\)$\\)")
2236 2633
2634 (defun cperl-imenu-addback (lst &optional isback name)
2635 ;; We suppose that the lst is a DAG, unless the first element only
2636 ;; loops back, and ISBACK is set. Thus this function cannot be
2637 ;; applied twice without ISBACK set.
2638 (cond ((not cperl-imenu-addback) lst)
2639 (t
2640 (or name
2641 (setq name "+++BACK+++"))
2642 (mapcar (function (lambda (elt)
2643 (if (and (listp elt) (listp (cdr elt)))
2644 (progn
2645 ;; In the other order it goes up
2646 ;; one level only ;-(
2647 (setcdr elt (cons (cons name lst)
2648 (cdr elt)))
2649 (cperl-imenu-addback (cdr elt) t name)
2650 ))))
2651 (if isback (cdr lst) lst))
2652 lst)))
2653
2237 (defun imenu-example--create-perl-index (&optional regexp) 2654 (defun imenu-example--create-perl-index (&optional regexp)
2238 (require 'cl) 2655 (require 'cl)
2239 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '()) 2656 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
2240 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function)) 2657 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
2658 (index-meth-alist '()) meth
2241 packages ends-ranges p 2659 packages ends-ranges p
2242 (prev-pos 0) char fchar index index1 name (end-range 0) package) 2660 (prev-pos 0) char fchar index index1 name (end-range 0) package)
2243 (goto-char (point-min)) 2661 (goto-char (point-min))
2244 (imenu-progress-message prev-pos 0) 2662 (imenu-progress-message prev-pos 0)
2245 ;; Search for the function 2663 ;; Search for the function
2246 (save-match-data 2664 (progn ;;save-match-data
2247 (while (re-search-forward 2665 (while (re-search-forward
2248 (or regexp imenu-example--function-name-regexp-perl) 2666 (or regexp imenu-example--function-name-regexp-perl)
2249 nil t) 2667 nil t)
2250 (imenu-progress-message prev-pos) 2668 (imenu-progress-message prev-pos)
2251 ;;(backward-up-list 1) 2669 ;;(backward-up-list 1)
2253 ((match-beginning 2) ; package or sub 2671 ((match-beginning 2) ; package or sub
2254 (save-excursion 2672 (save-excursion
2255 (goto-char (match-beginning 2)) 2673 (goto-char (match-beginning 2))
2256 (setq fchar (following-char)) 2674 (setq fchar (following-char))
2257 ) 2675 )
2258 (setq char (following-char)) 2676 (setq char (following-char) meth nil)
2259 (setq p (point)) 2677 (setq p (point))
2260 (while (and ends-ranges (>= p (car ends-ranges))) 2678 (while (and ends-ranges (>= p (car ends-ranges)))
2261 ;; delete obsolete entries 2679 ;; delete obsolete entries
2262 (setq ends-ranges (cdr ends-ranges) packages (cdr packages))) 2680 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
2263 (setq package (or (car packages) "") 2681 (setq package (or (car packages) "")
2264 end-range (or (car ends-ranges) 0)) 2682 end-range (or (car ends-ranges) 0))
2265 (if (eq fchar ?p) 2683 (if (eq fchar ?p)
2266 (progn 2684 (setq name (buffer-substring (match-beginning 3) (match-end 3))
2267 (setq name (buffer-substring (match-beginning 3) (match-end 3)) 2685 name (progn
2268 package (concat name "::") 2686 (set-text-properties 0 (length name) nil name)
2269 name (concat "package " name) 2687 name)
2270 end-range 2688 package (concat name "::")
2271 (save-excursion 2689 name (concat "package " name)
2272 (parse-partial-sexp (point) (point-max) -1) (point)) 2690 end-range
2273 ends-ranges (cons end-range ends-ranges) 2691 (save-excursion
2274 packages (cons package packages)))) 2692 (parse-partial-sexp (point) (point-max) -1) (point))
2693 ends-ranges (cons end-range ends-ranges)
2694 packages (cons package packages)))
2275 ;; ) 2695 ;; )
2276 ;; Skip this function name if it is a prototype declaration. 2696 ;; Skip this function name if it is a prototype declaration.
2277 (if (and (eq fchar ?s) (eq char ?\;)) nil 2697 (if (and (eq fchar ?s) (eq char ?\;)) nil
2698 (setq index (imenu-example--name-and-position))
2278 (if (eq fchar ?p) nil 2699 (if (eq fchar ?p) nil
2279 (setq name (buffer-substring (match-beginning 3) (match-end 3))) 2700 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
2280 (if (or (> p end-range) (string-match "[:']" name)) nil 2701 (set-text-properties 0 (length name) nil name)
2281 (setq name (concat package name)))) 2702 (cond ((string-match "[:']" name)
2282 (setq index (imenu-example--name-and-position)) 2703 (setq meth t))
2704 ((> p end-range) nil)
2705 (t
2706 (setq name (concat package name) meth t))))
2283 (setcar index name) 2707 (setcar index name)
2284 (if (eq fchar ?p) 2708 (if (eq fchar ?p)
2285 (push index index-pack-alist) 2709 (push index index-pack-alist)
2286 (push index index-alist)) 2710 (push index index-alist))
2711 (if meth (push index index-meth-alist))
2287 (push index index-unsorted-alist))) 2712 (push index index-unsorted-alist)))
2288 (t ; Pod section 2713 (t ; Pod section
2289 ;; (beginning-of-line) 2714 ;; (beginning-of-line)
2290 (setq index (imenu-example--name-and-position) 2715 (setq index (imenu-example--name-and-position)
2291 name (buffer-substring (match-beginning 5) (match-end 5))) 2716 name (buffer-substring (match-beginning 5) (match-end 5)))
2717 (set-text-properties 0 (length name) nil name)
2292 (if (eq (char-after (match-beginning 4)) ?2) 2718 (if (eq (char-after (match-beginning 4)) ?2)
2293 (setq name (concat " " name))) 2719 (setq name (concat " " name)))
2294 (setcar index name) 2720 (setcar index name)
2295 (setq index1 (cons (concat "=" name) (cdr index))) 2721 (setq index1 (cons (concat "=" name) (cdr index)))
2296 (push index index-pod-alist) 2722 (push index index-pod-alist)
2299 (setq index-alist 2725 (setq index-alist
2300 (if (default-value 'imenu-sort-function) 2726 (if (default-value 'imenu-sort-function)
2301 (sort index-alist (default-value 'imenu-sort-function)) 2727 (sort index-alist (default-value 'imenu-sort-function))
2302 (nreverse index-alist))) 2728 (nreverse index-alist)))
2303 (and index-pod-alist 2729 (and index-pod-alist
2304 (push (cons (imenu-create-submenu-name "+POD headers+") 2730 (push (cons "+POD headers+..."
2305 (nreverse index-pod-alist)) 2731 (nreverse index-pod-alist))
2306 index-alist)) 2732 index-alist))
2733 (and (or index-pack-alist index-meth-alist)
2734 (let ((lst index-pack-alist) hier-list pack elt group name)
2735 ;; Remove "package ", reverse and uniquify.
2736 (while lst
2737 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
2738 (if (assoc name hier-list) nil
2739 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
2740 (setq lst index-meth-alist)
2741 (while lst
2742 (setq elt (car lst) lst (cdr lst))
2743 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
2744 (setq pack (substring (car elt) 0 (match-beginning 0)))
2745 (if (setq group (assoc pack hier-list))
2746 (if (listp (cdr group))
2747 ;; Have some functions already
2748 (setcdr group
2749 (cons (cons (substring
2750 (car elt)
2751 (+ 2 (match-beginning 0)))
2752 (cdr elt))
2753 (cdr group)))
2754 (setcdr group (list (cons (substring
2755 (car elt)
2756 (+ 2 (match-beginning 0)))
2757 (cdr elt)))))
2758 (setq hier-list
2759 (cons (cons pack
2760 (list (cons (substring
2761 (car elt)
2762 (+ 2 (match-beginning 0)))
2763 (cdr elt))))
2764 hier-list))))))
2765 (push (cons "+Hierarchy+..."
2766 hier-list)
2767 index-alist)))
2307 (and index-pack-alist 2768 (and index-pack-alist
2308 (push (cons (imenu-create-submenu-name "+Packages+") 2769 (push (cons "+Packages+..."
2309 (nreverse index-pack-alist)) 2770 (nreverse index-pack-alist))
2310 index-alist)) 2771 index-alist))
2311 (and (or index-pack-alist index-pod-alist 2772 (and (or index-pack-alist index-pod-alist
2312 (default-value 'imenu-sort-function)) 2773 (default-value 'imenu-sort-function))
2313 index-unsorted-alist 2774 index-unsorted-alist
2314 (push (cons (imenu-create-submenu-name "+Unsorted List+") 2775 (push (cons "+Unsorted List+..."
2315 (nreverse index-unsorted-alist)) 2776 (nreverse index-unsorted-alist))
2316 index-alist)) 2777 index-alist))
2317 index-alist)) 2778 (cperl-imenu-addback index-alist)))
2318 2779
2319 (defvar cperl-compilation-error-regexp-alist 2780 (defvar cperl-compilation-error-regexp-alist
2320 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK). 2781 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK).
2321 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]" 2782 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
2322 2 3)) 2783 2 3))
2374 "redo" "return" "local" "exec" "sub" "do" "dump" "use" 2835 "redo" "return" "local" "exec" "sub" "do" "dump" "use"
2375 "require" "package" "eval" "my" "BEGIN" "END") 2836 "require" "package" "eval" "my" "BEGIN" "END")
2376 "\\|") ; Flow control 2837 "\\|") ; Flow control
2377 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]" 2838 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
2378 ; In what follows we use `type' style 2839 ; In what follows we use `type' style
2379 ; for overwritable buildins 2840 ; for overwritable builtins
2380 (list 2841 (list
2381 (concat 2842 (concat
2382 "\\(^\\|[^$@%&\\]\\)\\<\\(" 2843 "\\(^\\|[^$@%&\\]\\)\\<\\("
2383 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm" "and" "atan2" 2844 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
2384 ;; "bind" "binmode" "bless" "caller" "chdir" "chmod" "chown" "chr" 2845 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
2385 ;; "chroot" "close" "closedir" "cmp" "connect" "continue" "cos" 2846 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
2386 ;; "crypt" "dbmclose" "dbmopen" "die" "dump" "endgrent" "endhostent" 2847 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
2387 ;; "endnetent" "endprotoent" "endpwent" "endservent" "eof" "eq" "exec" 2848 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
2388 ;; "exit" "exp" "fcntl" "fileno" "flock" "fork" "formline" "ge" "getc" 2849 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
2389 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr" "gethostbyname" 2850 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
2390 ;; "gethostent" "getlogin" "getnetbyaddr" "getnetbyname" "getnetent" 2851 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
2391 ;; "getpeername" "getpgrp" "getppid" "getpriority" "getprotobyname" 2852 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
2392 ;; "getprotobynumber" "getprotoent" "getpwent" "getpwnam" "getpwuid" 2853 ;; "gethostbyname" "gethostent" "getlogin"
2393 ;; "getservbyname" "getservbyport" "getservent" "getsockname" 2854 ;; "getnetbyaddr" "getnetbyname" "getnetent"
2394 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int" "ioctl" 2855 ;; "getpeername" "getpgrp" "getppid" "getpriority"
2395 ;; "join" "kill" "lc" "lcfirst" "le" "length" "link" "listen" 2856 ;; "getprotobyname" "getprotobynumber" "getprotoent"
2396 ;; "localtime" "log" "lstat" "lt" "mkdir" "msgctl" "msgget" "msgrcv" 2857 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
2397 ;; "msgsnd" "ne" "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe" 2858 ;; "getservbyport" "getservent" "getsockname"
2398 ;; "quotemeta" "rand" "read" "readdir" "readline" "readlink" 2859 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
2399 ;; "readpipe" "recv" "ref" "rename" "require" "reset" "reverse" 2860 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
2400 ;; "rewinddir" "rindex" "rmdir" "seek" "seekdir" "select" "semctl" 2861 ;; "link" "listen" "localtime" "log" "lstat" "lt"
2401 ;; "semget" "semop" "send" "setgrent" "sethostent" "setnetent" 2862 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
2402 ;; "setpgrp" "setpriority" "setprotoent" "setpwent" "setservent" 2863 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
2403 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite" "shutdown" 2864 ;; "quotemeta" "rand" "read" "readdir" "readline"
2404 ;; "sin" "sleep" "socket" "socketpair" "sprintf" "sqrt" "srand" "stat" 2865 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
2405 ;; "substr" "symlink" "syscall" "sysread" "system" "syswrite" "tell" 2866 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
2406 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst" "umask" "unlink" 2867 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
2407 ;; "unpack" "utime" "values" "vec" "wait" "waitpid" "wantarray" "warn" 2868 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
2408 ;; "write" "x" "xor" 2869 ;; "setpriority" "setprotoent" "setpwent" "setservent"
2870 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
2871 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
2872 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
2873 ;; "syscall" "sysread" "system" "syswrite" "tell"
2874 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
2875 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
2876 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
2409 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|" 2877 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
2410 "b\\(in\\(d\\|mode\\)\\|less\\)\\|" 2878 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
2411 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|" 2879 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
2412 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|" 2880 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
2413 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|" 2881 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
2437 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|" 2905 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
2438 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|" 2906 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
2439 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\)" 2907 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\)"
2440 "\\)\\>") 2 'font-lock-type-face) 2908 "\\)\\>") 2 'font-lock-type-face)
2441 ;; In what follows we use `other' style 2909 ;; In what follows we use `other' style
2442 ;; for nonoverwritable buildins 2910 ;; for nonoverwritable builtins
2443 ;; Somehow 's', 'm' are not autogenerated??? 2911 ;; Somehow 's', 'm' are not auto-generated???
2444 (list 2912 (list
2445 (concat 2913 (concat
2446 "\\(^\\|[^$@%&\\]\\)\\<\\(" 2914 "\\(^\\|[^$@%&\\]\\)\\<\\("
2447 ;; "AUTOLOAD" "BEGIN" "DESTROY" "END" "__END__" "chomp" "chop" 2915 ;; "AUTOLOAD" "BEGIN" "DESTROY" "END" "__END__" "chomp"
2448 ;; "defined" "delete" "do" "each" "else" "elsif" "eval" "exists" "for" 2916 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
2449 ;; "foreach" "format" "goto" "grep" "if" "keys" "last" "local" "map" 2917 ;; "eval" "exists" "for" "foreach" "format" "goto"
2450 ;; "my" "next" "no" "package" "pop" "pos" "print" "printf" "push" "q" 2918 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
2451 ;; "qq" "qw" "qx" "redo" "return" "scalar" "shift" "sort" "splice" 2919 ;; "no" "package" "pop" "pos" "print" "printf" "push"
2452 ;; "split" "study" "sub" "tie" "tr" "undef" "unless" "unshift" "untie" 2920 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
2453 ;; "until" "use" "while" "y" 2921 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
2922 ;; "undef" "unless" "unshift" "untie" "until" "use"
2923 ;; "while" "y"
2454 "AUTOLOAD\\|BEGIN\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|" 2924 "AUTOLOAD\\|BEGIN\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
2455 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|" 2925 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
2456 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|if\\|keys\\|" 2926 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|if\\|keys\\|"
2457 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|" 2927 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|"
2458 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|" 2928 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
2465 ;; (mapconcat 'identity 2935 ;; (mapconcat 'identity
2466 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if" 2936 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
2467 ;; "#include" "#define" "#undef") 2937 ;; "#include" "#define" "#undef")
2468 ;; "\\|") 2938 ;; "\\|")
2469 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0 2939 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
2470 font-lock-function-name-face) ; Not very good, triggers at "[a-z]" 2940 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
2471 '("\\<sub[ \t]+\\([^ \t{;]+\\)[ \t]*[{\n]" 1 2941 '("\\<sub[ \t]+\\([^ \t{;]+\\)[ \t]*[{\n]" 1
2472 font-lock-function-name-face) 2942 font-lock-function-name-face)
2473 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B; 2943 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
2474 2 font-lock-function-name-face) 2944 2 font-lock-function-name-face)
2945 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
2946 1 font-lock-function-name-face)
2475 (cond ((featurep 'font-lock-extra) 2947 (cond ((featurep 'font-lock-extra)
2476 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}" 2948 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
2477 (2 font-lock-string-face t) 2949 (2 font-lock-string-face t)
2478 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef} 2950 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
2479 (font-lock-anchored 2951 (font-lock-anchored
2509 '("\\<for\\(each\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*(" 2981 '("\\<for\\(each\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
2510 2 font-lock-variable-name-face))) 2982 2 font-lock-variable-name-face)))
2511 (setq 2983 (setq
2512 t-font-lock-keywords-1 2984 t-font-lock-keywords-1
2513 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock 2985 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
2514 (not (cperl-xemacs-p)) ; not yet as of XEmacs 19.12 2986 (not cperl-xemacs-p) ; not yet as of XEmacs 19.12
2515 '(("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)" 2987 '(
2988 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
2989 (if (eq (char-after (match-beginning 2)) ?%)
2990 font-lock-other-emphasized-face
2991 font-lock-emphasized-face)
2992 t) ; arrays and hashes
2993 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
2516 1 2994 1
2517 (if (= (- (match-end 2) (match-beginning 2)) 1) 2995 (if (= (- (match-end 2) (match-beginning 2)) 1)
2518 (if (eq (char-after (match-beginning 3)) ?{) 2996 (if (eq (char-after (match-beginning 3)) ?{)
2519 font-lock-other-emphasized-face 2997 font-lock-other-emphasized-face
2520 font-lock-emphasized-face) ; arrays and hashes 2998 font-lock-emphasized-face) ; arrays and hashes
2521 font-lock-variable-name-face) ; Just to put something 2999 font-lock-variable-name-face) ; Just to put something
2522 t) 3000 t)
2523 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
2524 (if (eq (char-after (match-beginning 2)) ?%)
2525 font-lock-other-emphasized-face
2526 font-lock-emphasized-face)
2527 t) ; arrays and hashes
2528 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2") 3001 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
2529 ;;; Too much noise from \s* @s[ and friends 3002 ;;; Too much noise from \s* @s[ and friends
2530 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)" 3003 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
2531 ;;(3 font-lock-function-name-face t t) 3004 ;;(3 font-lock-function-name-face t t)
2532 ;;(4 3005 ;;(4
2634 (or (boundp 'font-lock-other-type-face) 3107 (or (boundp 'font-lock-other-type-face)
2635 (defconst font-lock-other-type-face 3108 (defconst font-lock-other-type-face
2636 'font-lock-other-type-face 3109 'font-lock-other-type-face
2637 "Face to use for data types from another group.") 3110 "Face to use for data types from another group.")
2638 ) 3111 )
2639 (if (not (cperl-xemacs-p)) nil 3112 (if (not cperl-xemacs-p) nil
2640 (or (boundp 'font-lock-comment-face) 3113 (or (boundp 'font-lock-comment-face)
2641 (defconst font-lock-comment-face 3114 (defconst font-lock-comment-face
2642 'font-lock-comment-face 3115 'font-lock-comment-face
2643 "Face to use for comments.") 3116 "Face to use for comments.")
2644 ) 3117 )
2821 (require 'mode-compile) 3294 (require 'mode-compile)
2822 (let ((perl-dbg-flags "-wc")) 3295 (let ((perl-dbg-flags "-wc"))
2823 (mode-compile))) 3296 (mode-compile)))
2824 3297
2825 (defun cperl-info-buffer () 3298 (defun cperl-info-buffer ()
2826 ;; Returns buffer with documentation. Creats if missing 3299 ;; Returns buffer with documentation. Creates if missing
2827 (let ((info (get-buffer "*info-perl*"))) 3300 (let ((info (get-buffer "*info-perl*")))
2828 (if info info 3301 (if info info
2829 (save-window-excursion 3302 (save-window-excursion
2830 ;; Get Info running 3303 ;; Get Info running
2831 (require 'info) 3304 (require 'info)
2832 (save-window-excursion 3305 (save-window-excursion
2833 (info)) 3306 (info))
2834 (Info-find-node "perl5" "perlfunc") 3307 (Info-find-node cperl-info-page "perlfunc")
2835 (set-buffer "*info*") 3308 (set-buffer "*info*")
2836 (rename-buffer "*info-perl*") 3309 (rename-buffer "*info-perl*")
2837 (current-buffer))))) 3310 (current-buffer)))))
2838 3311
2839 (defun cperl-word-at-point (&optional p) 3312 (defun cperl-word-at-point (&optional p)
2921 (pop-to-buffer buffer))))) 3394 (pop-to-buffer buffer)))))
2922 3395
2923 (defun cperl-lineup (beg end &optional step minshift) 3396 (defun cperl-lineup (beg end &optional step minshift)
2924 "Lineup construction in a region. 3397 "Lineup construction in a region.
2925 Beginning of region should be at the start of a construction. 3398 Beginning of region should be at the start of a construction.
2926 All first occurences of this construction in the lines that are 3399 All first occurrences of this construction in the lines that are
2927 partially contained in the region are lined up at the same column. 3400 partially contained in the region are lined up at the same column.
2928 3401
2929 MINSHIFT is the minimal amount of space to insert before the construction. 3402 MINSHIFT is the minimal amount of space to insert before the construction.
2930 STEP is the tabwidth to position constructions. 3403 STEP is the tabwidth to position constructions.
2931 If STEP is `nil', `cperl-lineup-step' will be used 3404 If STEP is `nil', `cperl-lineup-step' will be used
2941 (skip-chars-forward " \t\f") 3414 (skip-chars-forward " \t\f")
2942 (setq beg (point-marker)) 3415 (setq beg (point-marker))
2943 (indent-region beg end nil) 3416 (indent-region beg end nil)
2944 (goto-char beg) 3417 (goto-char beg)
2945 (setq col (current-column)) 3418 (setq col (current-column))
2946 (if (looking-at "\\sw") 3419 (if (looking-at "[a-zA-Z0-9_]")
2947 (if (looking-at "\\<\\sw+\\>") 3420 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
2948 (setq search 3421 (setq search
2949 (concat "\\<" 3422 (concat "\\<"
2950 (regexp-quote 3423 (regexp-quote
2951 (buffer-substring (match-beginning 0) 3424 (buffer-substring (match-beginning 0)
2952 (match-end 0))) "\\>")) 3425 (match-end 0))) "\\>"))
2962 (re-search-forward search end t) 3435 (re-search-forward search end t)
2963 (goto-char (match-beginning 0)))) 3436 (goto-char (match-beginning 0))))
2964 (setq tcol (current-column) seen t) 3437 (setq tcol (current-column) seen t)
2965 (if (> tcol col) (setq col tcol))) 3438 (if (> tcol col) (setq col tcol)))
2966 (or seen 3439 (or seen
2967 (error "The construction to line up occured only once")) 3440 (error "The construction to line up occurred only once"))
2968 (goto-char beg) 3441 (goto-char beg)
2969 (setq col (+ col minshift)) 3442 (setq col (+ col minshift))
2970 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step))))) 3443 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
2971 (while 3444 (while
2972 (progn 3445 (progn
3032 (interactive) 3505 (interactive)
3033 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t)) 3506 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
3034 (message "Parentheses will %sbe auto-doubled now." 3507 (message "Parentheses will %sbe auto-doubled now."
3035 (if (cperl-val 'cperl-electric-parens) "" "not "))) 3508 (if (cperl-val 'cperl-electric-parens) "" "not ")))
3036 3509
3510 ;;;; Tags file creation.
3511
3512 (defvar cperl-tmp-buffer " *cperl-tmp*")
3513
3514 (defun cperl-setup-tmp-buf ()
3515 (set-buffer (get-buffer-create cperl-tmp-buffer))
3516 (set-syntax-table cperl-mode-syntax-table)
3517 (buffer-disable-undo)
3518 (auto-fill-mode 0))
3519
3520 (defun cperl-xsub-scan ()
3521 (require 'cl)
3522 (require 'imenu)
3523 (let ((index-alist '())
3524 (prev-pos 0) index index1 name package prefix)
3525 (goto-char (point-min))
3526 (imenu-progress-message prev-pos 0)
3527 ;; Search for the function
3528 (progn ;;save-match-data
3529 (while (re-search-forward
3530 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
3531 nil t)
3532 (imenu-progress-message prev-pos)
3533 (cond
3534 ((match-beginning 2) ; SECTION
3535 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
3536 (goto-char (match-beginning 0))
3537 (skip-chars-forward " \t")
3538 (forward-char 1)
3539 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
3540 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
3541 (setq prefix nil)))
3542 ((not package) nil) ; C language section
3543 ((match-beginning 3) ; XSUB
3544 (goto-char (1+ (match-beginning 3)))
3545 (setq index (imenu-example--name-and-position))
3546 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
3547 (if (and prefix (string-match (concat "^" prefix) name))
3548 (setq name (substring name (length prefix))))
3549 (cond ((string-match "::" name) nil)
3550 (t
3551 (setq index1 (cons (concat package "::" name) (cdr index)))
3552 (push index1 index-alist)))
3553 (setcar index name)
3554 (push index index-alist))
3555 (t ; BOOT: section
3556 ;; (beginning-of-line)
3557 (setq index (imenu-example--name-and-position))
3558 (setcar index (concat package "::BOOT:"))
3559 (push index index-alist)))))
3560 (imenu-progress-message prev-pos 100)
3561 ;;(setq index-alist
3562 ;; (if (default-value 'imenu-sort-function)
3563 ;; (sort index-alist (default-value 'imenu-sort-function))
3564 ;; (nreverse index-alist)))
3565 index-alist))
3566
3567 (defun cperl-find-tags (file xs)
3568 (let (ind (b (get-buffer cperl-tmp-buffer)) lst elt pos ret)
3569 (save-excursion
3570 (if b (set-buffer b)
3571 (cperl-setup-tmp-buf))
3572 (erase-buffer)
3573 (setq file (car (insert-file-contents file)))
3574 (message "Scanning file %s..." file)
3575 (if xs
3576 (setq lst (cperl-xsub-scan))
3577 (setq ind (imenu-example--create-perl-index))
3578 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
3579 (setq lst
3580 (mapcar
3581 (function
3582 (lambda (elt)
3583 (cond ((string-match "^[_a-zA-Z]" (car elt))
3584 (goto-char (cdr elt))
3585 (list (car elt)
3586 (point) (count-lines 1 (point))
3587 (buffer-substring (progn
3588 (skip-chars-forward
3589 ":_a-zA-Z0-9")
3590 (or (eolp) (forward-char 1))
3591 (point))
3592 (progn
3593 (beginning-of-line)
3594 (point))))))))
3595 lst))
3596 (erase-buffer)
3597 (while lst
3598 (setq elt (car lst) lst (cdr lst))
3599 (if elt
3600 (progn
3601 (insert (elt elt 3)
3602 127
3603 (if (string-match "^package " (car elt))
3604 (substring (car elt) 8)
3605 (car elt) )
3606 1
3607 (number-to-string (elt elt 1))
3608 ","
3609 (number-to-string (elt elt 2))
3610 "\n")
3611 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
3612 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
3613 (elt elt 3)))
3614 ;; Need to insert the name without package as well
3615 (setq lst (cons (cons (substring (elt elt 3)
3616 (match-beginning 1)
3617 (match-end 1))
3618 (cdr elt))
3619 lst))))))
3620 (setq pos (point))
3621 (goto-char 1)
3622 (insert "\f\n" file "," (number-to-string (1- pos)) "\n")
3623 (setq ret (buffer-substring 1 (point-max)))
3624 (erase-buffer)
3625 (message "Scanning file %s finished" file)
3626 ret)))
3627
3628 (defun cperl-write-tags (&optional file erase recurse dir inbuffer)
3629 ;; If INBUFFER, do not select buffer, and do not save
3630 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
3631 (require 'etags)
3632 (if file nil
3633 (setq file (if dir default-directory (buffer-file-name)))
3634 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
3635 (let ((tags-file-name "TAGS")
3636 (case-fold-search (eq system-type 'emx))
3637 xs)
3638 (save-excursion
3639 (cond (inbuffer nil) ; Already there
3640 ((file-exists-p tags-file-name)
3641 (visit-tags-table-buffer tags-file-name))
3642 (t (set-buffer (find-file-noselect tags-file-name))))
3643 (cond
3644 (dir
3645 (cond ((eq erase 'ignore))
3646 (erase
3647 (erase-buffer)
3648 (setq erase 'ignore)))
3649 (let ((files
3650 (directory-files file t (if recurse nil "\\.[Pp][Llm]$") t)))
3651 (mapcar (function (lambda (file)
3652 (cond
3653 ((string-match "/\\.\\.?$" file) nil)
3654 ((not (file-directory-p file))
3655 (if (string-match "\\.\\([Pp][Llm]\\|xs\\)$" file)
3656 (cperl-write-tags file erase recurse nil t)))
3657 ((not recurse) nil)
3658 (t (cperl-write-tags file erase recurse t t)))))
3659 files))
3660 )
3661 (t
3662 (setq xs (string-match "\\.xs$" file))
3663 (cond ((eq erase 'ignore) nil)
3664 (erase (erase-buffer))
3665 (t
3666 (goto-char 1)
3667 (if (search-forward (concat "\f\n" file ",") nil t)
3668 (progn
3669 (search-backward "\f\n")
3670 (delete-region (point)
3671 (progn
3672 (forward-char 1)
3673 (search-forward "\f\n" nil 'toend)
3674 (point)))
3675 (goto-char 1)))))
3676 (insert (cperl-find-tags file xs))))
3677 (if inbuffer nil ; Delegate to the caller
3678 (save-buffer 0) ; No backup
3679 (initialize-new-tags-table)))))
3680
3681 (defvar cperl-tags-hier-regexp-list
3682 "^\\(\\(package\\)\\>\\|sub\\>[^\n]+::\\|[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::\\|[ \t]*BOOT:\C-?[^\n]+::\\)")
3683
3684 (defvar cperl-hierarchy '(() ())
3685 "Global hierarchy of classes")
3686
3687 (defun cperl-tags-hier-fill ()
3688 ;; Suppose we are in a tag table cooked by cperl.
3689 (goto-char 1)
3690 (let (type pack name pos line chunk ord cons1 file str info fileind)
3691 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
3692 (setq pos (match-beginning 0)
3693 pack (match-beginning 2))
3694 (beginning-of-line)
3695 (if (looking-at "\\([^\n]+\\)\C-?\\([^\n]+\\)\C-a\\([0-9]+\\),\\([0-9]+\\)")
3696 (progn
3697 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
3698 name (buffer-substring (match-beginning 2) (match-end 2))
3699 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
3700 line (buffer-substring (match-beginning 4) (match-end 4))
3701 ord (if pack 1 0)
3702 info (etags-snarf-tag) ; Moves to beginning of the next line
3703 file (file-of-tag)
3704 fileind (format "%s:%s" file line))
3705 ;; Move back
3706 (forward-char -1)
3707 ;; Make new member of hierarchy name ==> file ==> pos if needed
3708 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
3709 ;; Name known
3710 (setcdr cons1 (cons (cons fileind (vector file info))
3711 (cdr cons1)))
3712 ;; First occurrence of the name, start alist
3713 (setq cons1 (cons name (list (cons fileind (vector file info)))))
3714 (if pack
3715 (setcar (cdr cperl-hierarchy)
3716 (cons cons1 (nth 1 cperl-hierarchy)))
3717 (setcar cperl-hierarchy
3718 (cons cons1 (car cperl-hierarchy)))))))
3719 (end-of-line))))
3720
3721 (defun cperl-tags-hier-init (&optional update)
3722 "Show hierarchical menu of classes and methods.
3723 Finds info about classes by a scan of loaded TAGS files.
3724 Supposes that the TAGS files contain fully qualified function names.
3725 One may build such TAGS files from CPerl mode menu."
3726 (interactive)
3727 (require 'etags)
3728 (require 'imenu)
3729 (if (or update (null (nth 2 cperl-hierarchy)))
3730 (let (pack name cons1 to l1 l2 l3 l4
3731 (remover (function (lambda (elt) ; (name (file1...) (file2..))
3732 (or (nthcdr 2 elt)
3733 ;; Only in one file
3734 (setcdr elt (cdr (nth 1 elt))))))))
3735 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
3736 (setq cperl-hierarchy (list l1 l2 l3))
3737 (or tags-table-list
3738 (call-interactively 'visit-tags-table))
3739 (message "Updating list of classes...")
3740 (mapcar
3741 (function
3742 (lambda (tagsfile)
3743 (set-buffer (get-file-buffer tagsfile))
3744 (cperl-tags-hier-fill)))
3745 tags-table-list)
3746 (mapcar remover (car cperl-hierarchy))
3747 (mapcar remover (nth 1 cperl-hierarchy))
3748 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
3749 (cons "Methods: " (car cperl-hierarchy))))
3750 (cperl-tags-treeify to 1)
3751 (setcar (nthcdr 2 cperl-hierarchy)
3752 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
3753 (message "Updating list of classes: done, requesting display...")
3754 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
3755 ))
3756 (or (nth 2 cperl-hierarchy)
3757 (error "No items found"))
3758 (setq update
3759 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
3760 (if window-system
3761 (x-popup-menu t (nth 2 cperl-hierarchy))
3762 (require 'tmm)
3763 (tmm-prompt t (nth 2 cperl-hierarchy))))
3764 (if (and update (listp update))
3765 (progn (while (cdr update) (setq update (cdr update)))
3766 (setq update (car update)))) ; Get the last from the list
3767 (if (vectorp update)
3768 (progn
3769 (find-file (elt update 0))
3770 (etags-goto-tag-location (elt update 1))))
3771 (if (eq update -999) (cperl-tags-hier-init t)))
3772
3773 (defun cperl-tags-treeify (to level)
3774 ;; cadr of to is read-write. On start it is a cons
3775 (let* ((regexp (concat "^\\(" (mapconcat
3776 'identity
3777 (make-list level "[_a-zA-Z0-9]+")
3778 "::")
3779 "\\)\\(::\\)?"))
3780 (packages (cdr (nth 1 to)))
3781 (methods (cdr (nth 2 to)))
3782 l1 head tail cons1 cons2 ord writeto packs recurse
3783 root-packages root-functions ms many_ms same_name ps
3784 (move-deeper
3785 (function
3786 (lambda (elt)
3787 (cond ((and (string-match regexp (car elt))
3788 (or (eq ord 1) (match-end 2)))
3789 (setq head (substring (car elt) 0 (match-end 1))
3790 tail (if (match-end 2) (substring (car elt)
3791 (match-end 2)))
3792 recurse t)
3793 (if (setq cons1 (assoc head writeto)) nil
3794 ;; Need to init new head
3795 (setcdr writeto (cons (list head (list "Packages: ")
3796 (list "Methods: "))
3797 (cdr writeto)))
3798 (setq cons1 (nth 1 writeto)))
3799 (setq cons2 (nth ord cons1)) ; Either packs or meths
3800 (setcdr cons2 (cons elt (cdr cons2))))
3801 ((eq ord 2)
3802 (setq root-functions (cons elt root-functions)))
3803 (t
3804 (setq root-packages (cons elt root-packages))))))))
3805 (setcdr to l1) ; Init to dynamic space
3806 (setq writeto to)
3807 (setq ord 1)
3808 (mapcar move-deeper packages)
3809 (setq ord 2)
3810 (mapcar move-deeper methods)
3811 (if recurse
3812 (mapcar (function (lambda (elt)
3813 (cperl-tags-treeify elt (1+ level))))
3814 (cdr to)))
3815 ;; Now add back functions removed from display
3816 (mapcar (function (lambda (elt)
3817 (setcdr to (cons elt (cdr to)))))
3818 root-functions)
3819 ;; Now add back packages removed from display
3820 (mapcar (function (lambda (elt)
3821 (setcdr to (cons (cons (concat "package " (car elt))
3822 (cdr elt))
3823 (cdr to)))))
3824 root-packages)
3825 ;;Now clean up leaders with one child only
3826 (mapcar (function (lambda (elt)
3827 (if (not (and (listp (cdr elt))
3828 (eq (length elt) 2))) nil
3829 (setcar elt (car (nth 1 elt)))
3830 (setcdr elt (cdr (nth 1 elt))))))
3831 (cdr to))
3832 ))
3833
3834 ;;;(x-popup-menu t
3835 ;;; '(keymap "Name1"
3836 ;;; ("Ret1" "aa")
3837 ;;; ("Head1" "ab"
3838 ;;; keymap "Name2"
3839 ;;; ("Tail1" "x") ("Tail2" "y"))))
3840
3841 (defun cperl-list-fold (list name limit)
3842 (let (list1 list2 elt1 (num 0))
3843 (if (<= (length list) limit) list
3844 (setq list1 nil list2 nil)
3845 (while list
3846 (setq num (1+ num)
3847 elt1 (car list)
3848 list (cdr list))
3849 (if (<= num imenu-max-items)
3850 (setq list2 (cons elt1 list2))
3851 (setq list1 (cons (cons name
3852 (nreverse list2))
3853 list1)
3854 list2 (list elt1)
3855 num 1)))
3856 (nreverse (cons (cons name
3857 (nreverse list2))
3858 list1)))))
3859
3860 (defun cperl-menu-to-keymap (menu &optional name)
3861 (let (list)
3862 (cons 'keymap
3863 (mapcar
3864 (function
3865 (lambda (elt)
3866 (cond ((listp (cdr elt))
3867 (setq list (cperl-list-fold
3868 (cdr elt) (car elt) imenu-max-items))
3869 (cons nil
3870 (cons (car elt)
3871 (cperl-menu-to-keymap list))))
3872 (t
3873 (list (cdr elt) (car elt))))))
3874 (cperl-list-fold menu "Root" imenu-max-items)))))
3875
3876
3877 (defvar cperl-bad-style-regexp
3878 (mapconcat 'identity
3879 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
3880 "[-<>=+^&|]+[^- \t\n=+<>~]" ; sign+ char
3881 )
3882 "\\|")
3883 "Finds places such that insertion of a whitespace may help a lot.")
3884
3885 (defvar cperl-not-bad-style-regexp
3886 (mapconcat 'identity
3887 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
3888 "[a-zA-Z0-9][|&][a-zA-Z0-9$]" ; abc|def abc&def are often used.
3889 "&[(a-zA-Z0-9$]" ; &subroutine &(var->field)
3890 "<\\$?\\sw+\\(\\.\\sw+\\)?>" ; <IN> <stdin.h>
3891 "-[a-zA-Z][ \t]+[_$\"'`]" ; -f file
3892 "-[0-9]" ; -5
3893 "\\+\\+" ; ++var
3894 "--" ; --var
3895 ".->" ; a->b
3896 "->" ; a SPACE ->b
3897 "\\[-" ; a[-1]
3898 "^=" ; =head
3899 "||"
3900 "&&"
3901 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
3902 "-[a-zA-Z0-9]+[ \t]*=>" ; -option => value
3903 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
3904 ;;"[*/+-|&<.]+="
3905 )
3906 "\\|")
3907 "If matches at the start of match found by `my-bad-c-style-regexp',
3908 insertion of a whitespace will not help.")
3909
3910 (defvar found-bad)
3911
3912 (defun cperl-find-bad-style ()
3913 "Find places in the buffer where insertion of a whitespace may help.
3914 Prompts user for insertion of spaces.
3915 Currently it is tuned to C and Perl syntax."
3916 (interactive)
3917 (let (found-bad (p (point)))
3918 (setq last-nonmenu-event 13) ; To disable popup
3919 (beginning-of-buffer)
3920 (map-y-or-n-p "Insert space here? "
3921 (function (lambda (arg) (insert " ")))
3922 'cperl-next-bad-style
3923 '("location" "locations" "insert a space into")
3924 '((?\C-r (lambda (arg)
3925 (let ((buffer-quit-function
3926 'exit-recursive-edit))
3927 (message "Exit with Esc Esc")
3928 (recursive-edit)
3929 t)) ; Consider acted upon
3930 "edit, exit with Esc Esc")
3931 (?e (lambda (arg)
3932 (let ((buffer-quit-function
3933 'exit-recursive-edit))
3934 (message "Exit with Esc Esc")
3935 (recursive-edit)
3936 t)) ; Consider acted upon
3937 "edit, exit with Esc Esc"))
3938 t)
3939 (if found-bad (goto-char found-bad)
3940 (goto-char p)
3941 (message "No appropriate place found"))))
3942
3943 (defun cperl-next-bad-style ()
3944 (let (p (not-found t) (point (point)) found)
3945 (while (and not-found
3946 (re-search-forward cperl-bad-style-regexp nil 'to-end))
3947 (setq p (point))
3948 (goto-char (match-beginning 0))
3949 (if (or
3950 (looking-at cperl-not-bad-style-regexp)
3951 ;; Check for a < -b and friends
3952 (and (eq (following-char) ?\-)
3953 (save-excursion
3954 (skip-chars-backward " \t\n")
3955 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\(, ?\[, ?\{))))
3956 ;; Now check for syntax type
3957 (save-match-data
3958 (setq found (point))
3959 (beginning-of-defun)
3960 (let ((pps (parse-partial-sexp (point) found)))
3961 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
3962 (goto-char (match-end 0))
3963 (goto-char (1- p))
3964 (setq not-found nil
3965 found-bad found)))
3966 (not not-found)))
3967
3968 
3969 ;;; Getting help
3970 (defvar cperl-have-help-regexp
3971 ;;(concat "\\("
3972 (mapconcat
3973 'identity
3974 '("[$@%*&][0-9a-zA-Z_:]+" ; Usual variable
3975 "[$@]\\^[a-zA-Z]" ; Special variable
3976 "[$@][^ \n\t]" ; Special variable
3977 "-[a-zA-Z]" ; File test
3978 "\\\\[a-zA-Z0]" ; Special chars
3979 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
3980 "[a-zA-Z_0-9:]+" ; symbol or number
3981 "x="
3982 "#!"
3983 )
3984 ;;"\\)\\|\\("
3985 "\\|"
3986 )
3987 ;;"\\)"
3988 ;;)
3989 "Matches places in the buffer we can find help for.")
3990
3991 (defvar cperl-message-on-help-error t)
3992
3993 (defun cperl-get-help ()
3994 "Get one-line docs on the symbol at the point.
3995 The data for these docs is a little bit obsolete and may be in fact longer
3996 than a line. Your contribution to update/shorten it is appreciated."
3997 (interactive)
3998 (save-excursion
3999 ;; Get to the something meaningful
4000 (or (eobp) (eolp) (forward-char 1))
4001 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
4002 (save-excursion (beginning-of-line) (point))
4003 'to-beg)
4004 ;; (cond
4005 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
4006 ;; (skip-chars-backward " \n\t\r({[]});,")
4007 ;; (or (bobp) (backward-char 1))))
4008 ;; Try to backtrace
4009 (cond
4010 ((looking-at "[a-zA-Z0-9_:]") ; symbol
4011 (skip-chars-backward "[a-zA-Z0-9_:]")
4012 (cond
4013 ((and (eq (preceding-char) ?^) ; $^I
4014 (eq (char-after (- (point) 2)) ?\$))
4015 (forward-char -2))
4016 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
4017 (forward-char -1)))
4018 (if (and (eq (preceding-char) ?\<)
4019 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
4020 (forward-char -1)))
4021 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
4022 (forward-char -1))
4023 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
4024 (forward-char -1))
4025 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
4026 (skip-chars-backward "[-!&*+,-./<=>?\\\\^|~]")
4027 (cond
4028 ((and (eq (preceding-char) ?\$)
4029 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
4030 (forward-char -1))
4031 ((and (eq (following-char) ?\>)
4032 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
4033 (save-excursion
4034 (forward-sexp -1)
4035 (and (eq (preceding-char) ?\<)
4036 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
4037 (search-backward "<"))))
4038 ((and (eq (following-char) ?\$)
4039 (eq (preceding-char) ?\<)
4040 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
4041 (forward-char -1)))
4042 ;;(or (eobp) (forward-char 1))
4043 (if (looking-at cperl-have-help-regexp)
4044 (cperl-describe-perl-symbol
4045 (buffer-substring (match-beginning 0) (match-end 0)))
4046 (if cperl-message-on-help-error
4047 (message "Nothing found for %s..."
4048 (buffer-substring (point) (+ 5 (point))))))))
4049
4050 ;;; Stolen from perl-descr.el by Johan Vromans:
4051
4052 (defvar cperl-doc-buffer " *perl-doc*"
4053 "Where the documentation can be found.")
4054
4055 (defun cperl-describe-perl-symbol (val)
4056 "Display the documentation of symbol at point, a Perl operator."
4057 ;; We suppose that the current position is at the start of the symbol
4058 ;; when we convert $_[5] to @_
4059 (let (;;(fn (perl-symbol-at-point))
4060 (enable-recursive-minibuffers t)
4061 ;;val
4062 args-file regexp)
4063 ;; (interactive
4064 ;; (let ((fn (perl-symbol-at-point))
4065 ;; (enable-recursive-minibuffers t)
4066 ;; val args-file regexp)
4067 ;; (setq val (read-from-minibuffer
4068 ;; (if fn
4069 ;; (format "Symbol (default %s): " fn)
4070 ;; "Symbol: ")))
4071 ;; (if (string= val "")
4072 ;; (setq val fn))
4073 (cond
4074 ((string-match "^[&*][a-zA-Z_]" val)
4075 (setq val (concat (substring val 0 1) "NAME")))
4076 ((looking-at "[$@][a-zA-Z_:0-9]+\\([[{]\\)")
4077 (if (= ?\[ (char-after (match-beginning 1)))
4078 (setq val (concat "@" (substring val 1)))
4079 (setq val (concat "%" (substring val 1)))))
4080 ((and (string= val "x") (looking-at "x="))
4081 (setq val "x="))
4082 ((string-match "^\\$[\C-a-\C-z]" val)
4083 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
4084 ((and (string= "<" val) (looking-at "<\\$?[a-zA-Z0-9_:]+>"))
4085 (setq val "<NAME>")))
4086 ;;; (if (string-match "^[&*][a-zA-Z_]" val)
4087 ;;; (setq val (concat (substring val 0 1) "NAME"))
4088 ;;; (if (looking-at "[$@][a-zA-Z_:0-9]+\\([[{]\\)")
4089 ;;; (if (= ?\[ (char-after (match-beginning 1)))
4090 ;;; (setq val (concat "@" (substring val 1)))
4091 ;;; (setq val (concat "%" (substring val 1))))
4092 ;;; (if (and (string= val "x") (looking-at "x="))
4093 ;;; (setq val "x=")
4094 ;;; (if (looking-at "[$@][a-zA-Z_:0-9]")
4095 ;;; ))))
4096 (setq regexp (concat "^" "\\([^a-zA-Z0-9_:]+[ \t]\\)?"
4097 (regexp-quote val)
4098 "\\([ \t([/]\\|$\\)"))
4099
4100 ;; get the buffer with the documentation text
4101 (cperl-switch-to-doc-buffer)
4102
4103 ;; lookup in the doc
4104 (goto-char (point-min))
4105 (let ((case-fold-search nil))
4106 (list
4107 (if (re-search-forward regexp (point-max) t)
4108 (save-excursion
4109 (beginning-of-line 1)
4110 (let ((lnstart (point)))
4111 (end-of-line)
4112 (message "%s" (buffer-substring lnstart (point)))))
4113 (if cperl-message-on-help-error
4114 (message "No definition for %s" val)))))))
4115
4116 (defvar cperl-short-docs "Ignore my value"
4117 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
4118 ! Logical negation.
4119 != Numeric inequality.
4120 !~ Search pattern, substitution, or translation (negated).
4121 $! In numeric context: errno. In a string context: error string.
4122 $\" The separator which joins elements of arrays interpolated in strings.
4123 $# The output format for printed numbers. Initial value is %.20g.
4124 $$ The process number of the perl running this script. Altered (in the child process) by fork().
4125 $% The current page number of the currently selected output channel.
4126
4127 The following variables are always local to the current block:
4128
4129 $1 Match of the 1st set of parentheses in the last match (auto-local).
4130 $2 Match of the 2nd set of parentheses in the last match (auto-local).
4131 $3 Match of the 3rd set of parentheses in the last match (auto-local).
4132 $4 Match of the 4th set of parentheses in the last match (auto-local).
4133 $5 Match of the 5th set of parentheses in the last match (auto-local).
4134 $6 Match of the 6th set of parentheses in the last match (auto-local).
4135 $7 Match of the 7th set of parentheses in the last match (auto-local).
4136 $8 Match of the 8th set of parentheses in the last match (auto-local).
4137 $9 Match of the 9th set of parentheses in the last match (auto-local).
4138 $& The string matched by the last pattern match (auto-local).
4139 $' The string after what was matched by the last match (auto-local).
4140 $` The string before what was matched by the last match (auto-local).
4141
4142 $( The real gid of this process.
4143 $) The effective gid of this process.
4144 $* Deprecated: Set to 1 to do multiline matching within a string.
4145 $+ The last bracket matched by the last search pattern.
4146 $, The output field separator for the print operator.
4147 $- The number of lines left on the page.
4148 $. The current input line number of the last filehandle that was read.
4149 $/ The input record separator, newline by default.
4150 $0 The name of the file containing the perl script being executed. May be set
4151 $: The set of characters after which a string may be broken to fill continuation fields (starting with ^) in a format.
4152 $; The subscript separator for multi-dimensional array emulation. Default is \"\\034\".
4153 $< The real uid of this process.
4154 $= The page length of the current output channel. Default is 60 lines.
4155 $> The effective uid of this process.
4156 $? The status returned by the last ``, pipe close or `system'.
4157 $@ The perl error message from the last eval or do @var{EXPR} command.
4158 $ARGV The name of the current file used with <> .
4159 $[ Deprecated: The index of the first element/char in an array/string.
4160 $\\ The output record separator for the print operator.
4161 $] The perl version string as displayed with perl -v.
4162 $^ The name of the current top-of-page format.
4163 $^A The current value of the write() accumulator for format() lines.
4164 $^D The value of the perl debug (-D) flags.
4165 $^E Information about the last system error other than that provided by $!.
4166 $^F The highest system file descriptor, ordinarily 2.
4167 $^H The current set of syntax checks enabled by `use strict'.
4168 $^I The value of the in-place edit extension (perl -i option).
4169 $^L What formats output to perform a formfeed. Default is \f.
4170 $^O The operating system name under which this copy of Perl was built.
4171 $^P Internal debugging flag.
4172 $^T The time the script was started. Used by -A/-M/-C file tests.
4173 $^W True if warnings are requested (perl -w flag).
4174 $^X The name under which perl was invoked (argv[0] in C-speech).
4175 $_ The default input and pattern-searching space.
4176 $| Flag for auto-flush after write/print on the currently selected output channel. Default is 0.
4177 $~ The name of the current report format.
4178 % Modulo division.
4179 %= Modulo division assignment.
4180 %ENV Contains the current environment.
4181 %INC List of files that have been require-d or do-ne.
4182 %SIG Used to set signal handlers for various signals.
4183 & Bitwise and.
4184 && Logical and.
4185 &&= Logical and assignment.
4186 &= Bitwise and assignment.
4187 * Multiplication.
4188 ** Exponentiation.
4189 *NAME Refers to all objects represented by NAME. *NAM1 = *NAM2 makes NAM1 a reference to NAM2.
4190 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
4191 + Addition.
4192 ++ Auto-increment (magical on strings).
4193 += Addition assignment.
4194 , Comma operator.
4195 - Subtraction.
4196 -- Auto-decrement.
4197 -= Subtraction assignment.
4198 -A Access time in days since script started.
4199 -B File is a non-text (binary) file.
4200 -C Inode change time in days since script started.
4201 -M Age in days since script started.
4202 -O File is owned by real uid.
4203 -R File is readable by real uid.
4204 -S File is a socket .
4205 -T File is a text file.
4206 -W File is writable by real uid.
4207 -X File is executable by real uid.
4208 -b File is a block special file.
4209 -c File is a character special file.
4210 -d File is a directory.
4211 -e File exists .
4212 -f File is a plain file.
4213 -g File has setgid bit set.
4214 -k File has sticky bit set.
4215 -l File is a symbolic link.
4216 -o File is owned by effective uid.
4217 -p File is a named pipe (FIFO).
4218 -r File is readable by effective uid.
4219 -s File has non-zero size.
4220 -t Tests if filehandle (STDIN by default) is opened to a tty.
4221 -u File has setuid bit set.
4222 -w File is writable by effective uid.
4223 -x File is executable by effective uid.
4224 -z File has zero size.
4225 . Concatenate strings.
4226 .. Alternation, also range operator.
4227 .= Concatenate assignment strings
4228 / Division. /PATTERN/ioxsmg Pattern match
4229 /= Division assignment.
4230 /PATTERN/ioxsmg Pattern match.
4231 < Numeric less than. <pattern> Glob. See <NAME>, <> as well.
4232 <NAME> Reads line from filehandle NAME. NAME must be bareword/dollar-bareword.
4233 <pattern> Glob. (Unless pattern is bareword/dollar-bareword - see <NAME>)
4234 <> Reads line from union of files in @ARGV (= command line) and STDIN.
4235 << Bitwise shift left. << start of HERE-DOCUMENT.
4236 <= Numeric less than or equal to.
4237 <=> Numeric compare.
4238 = Assignment.
4239 == Numeric equality.
4240 =~ Search pattern, substitution, or translation
4241 > Numeric greater than.
4242 >= Numeric greater than or equal to.
4243 >> Bitwise shift right.
4244 >>= Bitwise shift right assignment.
4245 ? : Alternation (if-then-else) operator. ?PAT? Backwards pattern match.
4246 ?PATTERN? Backwards pattern match.
4247 @ARGV Command line arguments (not including the command name - see $0).
4248 @INC List of places to look for perl scripts during do/include/use.
4249 @_ Parameter array for subroutines. Also used by split unless in array context.
4250 \\ Creates a reference to whatever follows, like \$var.
4251 \\0 Octal char, e.g. \\033.
4252 \\E Case modification terminator. See \\Q, \\L, and \\U.
4253 \\L Lowercase until \\E .
4254 \\U Upcase until \\E .
4255 \\Q Quote metacharacters until \\E .
4256 \\a Alarm character (octal 007).
4257 \\b Backspace character (octal 010).
4258 \\c Control character, e.g. \\c[ .
4259 \\e Escape character (octal 033).
4260 \\f Formfeed character (octal 014).
4261 \\l Lowercase of next character. See also \\L and \\u,
4262 \\n Newline character (octal 012).
4263 \\r Return character (octal 015).
4264 \\t Tab character (octal 011).
4265 \\u Upcase of next character. See also \\U and \\l,
4266 \\x Hex character, e.g. \\x1b.
4267 ^ Bitwise exclusive or.
4268 __END__ End of program source.
4269 __DATA__ End of program source.
4270 __FILE__ Current (source) filename.
4271 __LINE__ Current line in current source.
4272 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
4273 ARGVOUT Output filehandle with -i flag.
4274 BEGIN { block } Immediately executed (during compilation) piece of code.
4275 END { block } Pseudo-subroutine executed after the script finishes.
4276 DATA Input filehandle for what follows after __END__ or __DATA__.
4277 accept(NEWSOCKET,GENERICSOCKET)
4278 alarm(SECONDS)
4279 atan2(X,Y)
4280 bind(SOCKET,NAME)
4281 binmode(FILEHANDLE)
4282 caller[(LEVEL)]
4283 chdir(EXPR)
4284 chmod(LIST)
4285 chop[(LIST|VAR)]
4286 chown(LIST)
4287 chroot(FILENAME)
4288 close(FILEHANDLE)
4289 closedir(DIRHANDLE)
4290 cmp String compare.
4291 connect(SOCKET,NAME)
4292 continue of { block } continue { block }. Is executed after `next' or at end.
4293 cos(EXPR)
4294 crypt(PLAINTEXT,SALT)
4295 dbmclose(ASSOC_ARRAY)
4296 dbmopen(ASSOC,DBNAME,MODE)
4297 defined(EXPR)
4298 delete($ASSOC{KEY})
4299 die(LIST)
4300 do { ... }|SUBR while|until EXPR executes at least once
4301 do(EXPR|SUBR([LIST]))
4302 dump LABEL
4303 each(ASSOC_ARRAY)
4304 endgrent
4305 endhostent
4306 endnetent
4307 endprotoent
4308 endpwent
4309 endservent
4310 eof[([FILEHANDLE])]
4311 eq String equality.
4312 eval(EXPR) or eval { BLOCK }
4313 exec(LIST)
4314 exit(EXPR)
4315 exp(EXPR)
4316 fcntl(FILEHANDLE,FUNCTION,SCALAR)
4317 fileno(FILEHANDLE)
4318 flock(FILEHANDLE,OPERATION)
4319 for (EXPR;EXPR;EXPR) { ... }
4320 foreach [VAR] (@ARRAY) { ... }
4321 fork
4322 ge String greater than or equal.
4323 getc[(FILEHANDLE)]
4324 getgrent
4325 getgrgid(GID)
4326 getgrnam(NAME)
4327 gethostbyaddr(ADDR,ADDRTYPE)
4328 gethostbyname(NAME)
4329 gethostent
4330 getlogin
4331 getnetbyaddr(ADDR,ADDRTYPE)
4332 getnetbyname(NAME)
4333 getnetent
4334 getpeername(SOCKET)
4335 getpgrp(PID)
4336 getppid
4337 getpriority(WHICH,WHO)
4338 getprotobyname(NAME)
4339 getprotobynumber(NUMBER)
4340 getprotoent
4341 getpwent
4342 getpwnam(NAME)
4343 getpwuid(UID)
4344 getservbyname(NAME,PROTO)
4345 getservbyport(PORT,PROTO)
4346 getservent
4347 getsockname(SOCKET)
4348 getsockopt(SOCKET,LEVEL,OPTNAME)
4349 gmtime(EXPR)
4350 goto LABEL
4351 grep(EXPR,LIST)
4352 gt String greater than.
4353 hex(EXPR)
4354 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
4355 index(STR,SUBSTR[,OFFSET])
4356 int(EXPR)
4357 ioctl(FILEHANDLE,FUNCTION,SCALAR)
4358 join(EXPR,LIST)
4359 keys(ASSOC_ARRAY)
4360 kill(LIST)
4361 last [LABEL]
4362 le String less than or equal.
4363 length(EXPR)
4364 link(OLDFILE,NEWFILE)
4365 listen(SOCKET,QUEUESIZE)
4366 local(LIST)
4367 localtime(EXPR)
4368 log(EXPR)
4369 lstat(EXPR|FILEHANDLE|VAR)
4370 lt String less than.
4371 m/PATTERN/iogsmx
4372 mkdir(FILENAME,MODE)
4373 msgctl(ID,CMD,ARG)
4374 msgget(KEY,FLAGS)
4375 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
4376 msgsnd(ID,MSG,FLAGS)
4377 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
4378 ne String inequality.
4379 next [LABEL]
4380 oct(EXPR)
4381 open(FILEHANDLE[,EXPR])
4382 opendir(DIRHANDLE,EXPR)
4383 ord(EXPR)
4384 pack(TEMPLATE,LIST)
4385 package Introduces package context.
4386 pipe(READHANDLE,WRITEHANDLE)
4387 pop(ARRAY)
4388 print [FILEHANDLE] [(LIST)]
4389 printf [FILEHANDLE] (FORMAT,LIST)
4390 push(ARRAY,LIST)
4391 q/STRING/ Synonym for 'STRING'
4392 qq/STRING/ Synonym for \"STRING\"
4393 qx/STRING/ Synonym for `STRING`
4394 rand[(EXPR)]
4395 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
4396 readdir(DIRHANDLE)
4397 readlink(EXPR)
4398 recv(SOCKET,SCALAR,LEN,FLAGS)
4399 redo [LABEL]
4400 rename(OLDNAME,NEWNAME)
4401 require [FILENAME | PERL_VERSION]
4402 reset[(EXPR)]
4403 return(LIST)
4404 reverse(LIST)
4405 rewinddir(DIRHANDLE)
4406 rindex(STR,SUBSTR[,OFFSET])
4407 rmdir(FILENAME)
4408 s/PATTERN/REPLACEMENT/gieoxsm
4409 scalar(EXPR)
4410 seek(FILEHANDLE,POSITION,WHENCE)
4411 seekdir(DIRHANDLE,POS)
4412 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
4413 semctl(ID,SEMNUM,CMD,ARG)
4414 semget(KEY,NSEMS,SIZE,FLAGS)
4415 semop(KEY,...)
4416 send(SOCKET,MSG,FLAGS[,TO])
4417 setgrent
4418 sethostent(STAYOPEN)
4419 setnetent(STAYOPEN)
4420 setpgrp(PID,PGRP)
4421 setpriority(WHICH,WHO,PRIORITY)
4422 setprotoent(STAYOPEN)
4423 setpwent
4424 setservent(STAYOPEN)
4425 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
4426 shift[(ARRAY)]
4427 shmctl(ID,CMD,ARG)
4428 shmget(KEY,SIZE,FLAGS)
4429 shmread(ID,VAR,POS,SIZE)
4430 shmwrite(ID,STRING,POS,SIZE)
4431 shutdown(SOCKET,HOW)
4432 sin(EXPR)
4433 sleep[(EXPR)]
4434 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
4435 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
4436 sort [SUBROUTINE] (LIST)
4437 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
4438 split[(/PATTERN/[,EXPR[,LIMIT]])]
4439 sprintf(FORMAT,LIST)
4440 sqrt(EXPR)
4441 srand(EXPR)
4442 stat(EXPR|FILEHANDLE|VAR)
4443 study[(SCALAR)]
4444 sub [NAME [(format)]] { BODY } or sub [NAME [(format)]];
4445 substr(EXPR,OFFSET[,LEN])
4446 symlink(OLDFILE,NEWFILE)
4447 syscall(LIST)
4448 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
4449 system(LIST)
4450 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
4451 tell[(FILEHANDLE)]
4452 telldir(DIRHANDLE)
4453 time
4454 times
4455 tr/SEARCHLIST/REPLACEMENTLIST/cds
4456 truncate(FILE|EXPR,LENGTH)
4457 umask[(EXPR)]
4458 undef[(EXPR)]
4459 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
4460 unlink(LIST)
4461 unpack(TEMPLATE,EXPR)
4462 unshift(ARRAY,LIST)
4463 until (EXPR) { ... } or EXPR until EXPR
4464 utime(LIST)
4465 values(ASSOC_ARRAY)
4466 vec(EXPR,OFFSET,BITS)
4467 wait
4468 waitpid(PID,FLAGS)
4469 wantarray
4470 warn(LIST)
4471 while (EXPR) { ... } or EXPR while EXPR
4472 write[(EXPR|FILEHANDLE)]
4473 x Repeat string or array.
4474 x= Repetition assignment.
4475 y/SEARCHLIST/REPLACEMENTLIST/
4476 | Bitwise or.
4477 || Logical or.
4478 ~ Unary bitwise complement.
4479 #! OS interpreter indicator. If contains `perl', used for options, and -x.
4480 ")
4481
4482 (defun cperl-switch-to-doc-buffer ()
4483 "Go to the perl documentation buffer and insert the documentation."
4484 (interactive)
4485 (let ((buf (get-buffer-create cperl-doc-buffer)))
4486 (if (interactive-p)
4487 (switch-to-buffer-other-window buf)
4488 (set-buffer buf))
4489 (if (= (buffer-size) 0)
4490 (progn
4491 (insert (documentation-property 'cperl-short-docs
4492 'variable-documentation))
4493 (setq buffer-read-only t)))))
4494
4495 (if (fboundp 'run-with-idle-timer)
4496 (progn
4497 (defvar cperl-help-shown nil
4498 "Non-nil means that the help was already shown now.")
4499
4500 (defvar cperl-help-timer nil
4501 "Non-nil means that the help was already shown now.")
4502
4503 (defun cperl-lazy-install ()
4504 (interactive)
4505 (make-variable-buffer-local 'cperl-help-shown)
4506 (if (cperl-val cperl-lazy-help-time)
4507 (progn
4508 (add-hook 'post-command-hook 'cperl-lazy-hook)
4509 (setq cperl-help-timer
4510 (run-with-idle-timer
4511 (cperl-val cperl-lazy-help-time 1000000 5)
4512 t
4513 'cperl-get-help-defer)))))
4514
4515 (defun cperl-lazy-unstall ()
4516 (interactive)
4517 (remove-hook 'post-command-hook 'cperl-lazy-hook)
4518 (cancel-timer cperl-help-timer))
4519
4520 (defun cperl-lazy-hook ()
4521 (setq cperl-help-shown nil))
4522
4523 (defun cperl-get-help-defer ()
4524 (if (not (eq major-mode 'perl-mode)) nil
4525 (let ((cperl-message-on-help-error nil))
4526 (cperl-get-help)
4527 (setq cperl-help-shown t))))
4528 (cperl-lazy-install)))