annotate lisp/progmodes/cperl-mode.el @ 20733:079907c59fb2

(set-language-info): Doc-string describes `coding-priority' KEY. (set-language-environment-coding-systems): New function. (list-subset-p): New function. (select-safe-coding-system): New function. (set-language-info): New optional args DESCRIBE-MAP and SETUP-MAP. (set-language-info-alist): New optionla arg PARENTS. Call set-language-info with apropriate DESCRIBE-MAP and SETUP-MAP args. (set-language-environment-coding-systems): New function. (prefer-coding-system): Call update-iso-coding-systems.
author Kenichi Handa <handa@m17n.org>
date Thu, 22 Jan 1998 01:42:20 +0000
parents eae9c49831e4
children f3f9df46d008
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20323
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1 ;;; cperl-mode.el --- Perl code editing commands for Emacs
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 91, 92, 93, 94, 95, 96, 1997
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4 ;; Free Software Foundation, Inc.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6 ;; Author: Ilya Zakharevich and Bob Olson
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7 ;; Maintainer: Ilya Zakharevich <ilya@math.ohio-state.edu>
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8 ;; Keywords: languages, Perl
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15 ;; any later version.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 ;;; Corrections made by Ilya Zakharevich ilya@math.mps.ohio-state.edu
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 ;;; XEmacs changes by Peter Arius arius@informatik.uni-erlangen.de
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 ;;; Commentary:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32 ;;; You can either fine-tune the bells and whistles of this mode or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33 ;;; bulk enable them by putting
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 ;; (setq cperl-hairy t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 ;;; in your .emacs file. (Emacs rulers do not consider it politically
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38 ;;; correct to make whistles enabled by default.)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40 ;;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 ;;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 ;;; `cperl-non-problems', `cperl-praise'. <<<<<<
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 ;;; The mode information (on C-h m) provides some customization help.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45 ;;; If you use font-lock feature of this mode, it is advisable to use
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 ;;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48 ;;; Faces used now: three faces for first-class and second-class keywords
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49 ;;; and control flow words, one for each: comments, string, labels,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
50 ;;; functions definitions and packages, arrays, hashes, and variable
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51 ;;; definitions. If you do not see all these faces, your font-lock does
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52 ;;; not define them, so you need to define them manually.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54 ;;; into your .emacs file.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56 ;;;; This mode supports font-lock, imenu and mode-compile. In the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57 ;;;; hairy version font-lock is on, but you should activate imenu
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58 ;;;; yourself (note that mode-compile is not standard yet). Well, you
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
59 ;;;; can use imenu from keyboard anyway (M-x imenu), but it is better
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 ;;;; to bind it like that:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62 ;; (define-key global-map [M-S-down-mouse-3] 'imenu)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
63
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
64 ;;; Code:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
65
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
66 (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68 (defvar cperl-extra-newline-before-brace nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 "*Non-nil means that if, elsif, while, until, else, for, foreach
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70 and do constructs look like:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72 if ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
73 {
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 }
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
75
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
76 instead of:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
77
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
78 if () {
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
79 }
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
80 ")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
81
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
82 (defvar cperl-indent-level 2
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
83 "*Indentation of CPerl statements with respect to containing block.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
84 (defvar cperl-lineup-step nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85 "*`cperl-lineup' will always lineup at multiple of this number.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86 If `nil', the value of `cperl-indent-level' will be used.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 (defvar cperl-brace-imaginary-offset 0
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 "*Imagined indentation of a Perl open brace that actually follows a statement.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 An open brace following other text is treated as if it were this far
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 to the right of the start of its line.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91 (defvar cperl-brace-offset 0
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
92 "*Extra indentation for braces, compared with other text in same context.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93 (defvar cperl-label-offset -2
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 "*Offset of CPerl label lines relative to usual indentation.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95 (defvar cperl-min-label-indent 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
96 "*Minimal offset of CPerl label lines.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97 (defvar cperl-continued-statement-offset 2
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98 "*Extra indent for lines not starting new statements.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
99 (defvar cperl-continued-brace-offset 0
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
100 "*Extra indent for substatements that start with open-braces.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101 This is in addition to cperl-continued-statement-offset.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102 (defvar cperl-close-paren-offset -1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103 "*Extra indent for substatements that start with close-parenthesis.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105 (defvar cperl-auto-newline nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 "*Non-nil means automatically newline before and after braces,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 and after colons and semicolons, inserted in CPerl code. The following
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 \\[cperl-electric-backspace] will remove the inserted whitespace.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 Insertion after colons requires both this variable and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 `cperl-auto-newline-after-colon' set.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112 (defvar cperl-auto-newline-after-colon nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 "*Non-nil means automatically newline even after colons.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 Subject to `cperl-auto-newline' setting.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 (defvar cperl-tab-always-indent t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 "*Non-nil means TAB in CPerl mode should always reindent the current line,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 regardless of where in the line point is when the TAB command is used.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120 (defvar cperl-font-lock nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
121 "*Non-nil (and non-null) means CPerl buffers will use font-lock-mode.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 Can be overwritten by `cperl-hairy' if nil.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 (defvar cperl-electric-lbrace-space nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 "*Non-nil (and non-null) means { after $ in CPerl buffers should be preceded by ` '.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126 Can be overwritten by `cperl-hairy' if nil.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 (defvar cperl-electric-parens-string "({[]})<"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 "*String of parentheses that should be electric in CPerl.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 Closing ones are electric only if the region is highlighted.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 (defvar cperl-electric-parens nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 "*Non-nil (and non-null) means parentheses should be electric in CPerl.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134 Can be overwritten by `cperl-hairy' if nil.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 (defvar cperl-electric-parens-mark
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 (and window-system
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 (or (and (boundp 'transient-mark-mode) ; For Emacs
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138 transient-mark-mode)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 (and (boundp 'zmacs-regions) ; For XEmacs
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 zmacs-regions)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 "*Not-nil means that electric parens look for active mark.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 Default is yes if there is visual feedback on mark.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (defvar cperl-electric-linefeed nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 In any case these two mean plain and hairy linefeeds together.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 Can be overwritten by `cperl-hairy' if nil.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 (defvar cperl-electric-keywords nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 "*Not-nil (and non-null) means keywords are electric in CPerl.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 Can be overwritten by `cperl-hairy' if nil.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 (defvar cperl-hairy nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 "*Not-nil means all the bells and whistles are enabled in CPerl.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 (defvar cperl-comment-column 32
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 "*Column to put comments in CPerl (use \\[cperl-indent]' to lineup with code).")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 (defvar cperl-vc-header-alist '((SCCS "$sccs = '%W\%' ;")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 (RCS "$rcs = ' $Id\$ ' ;"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 "*What to use as `vc-header-alist' in CPerl.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 (defvar cperl-info-on-command-no-prompt nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 "*Not-nil (and non-null) means not to prompt on C-h f.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 The opposite behaviour is always available if prefixed with C-c.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 Can be overwritten by `cperl-hairy' if nil.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 (defvar cperl-lazy-help-time nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 "*Not-nil (and non-null) means to show lazy help after given idle time.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 (defvar cperl-pod-face 'font-lock-comment-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 "*The result of evaluation of this expression is used for pod highlighting.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 (defvar cperl-pod-head-face 'font-lock-variable-name-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 "*The result of evaluation of this expression is used for pod highlighting.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 Font for POD headers.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 (defvar cperl-here-face 'font-lock-string-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 "*The result of evaluation of this expression is used for here-docs highlighting.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 (defvar cperl-pod-here-fontify '(featurep 'font-lock)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 "*Not-nil after evaluation means to highlight pod and here-docs sections.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 (defvar cperl-pod-here-scan t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 "*Not-nil means look for pod and here-docs sections during startup.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 You can always make lookup from menu or using \\[cperl-find-pods-heres].")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 (defvar cperl-imenu-addback nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 "*Not-nil means add backreferences to generated `imenu's.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 May require patched `imenu' and `imenu-go'.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 (defvar cperl-max-help-size 66
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 (defvar cperl-shrink-wrap-info-frame t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 "*Non-nil means shrink-wrapping of info-buffer-frame allowed.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 (defvar cperl-info-page "perl"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 "*Name of the info page containing perl docs.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 Older version of this page was called `perl5', newer `perl'.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 (defvar cperl-use-syntax-table-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 (boundp 'parse-sexp-lookup-properties)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 "*Non-nil means CPerl sets up and uses `syntax-table' text property.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 (defvar cperl-use-syntax-table-text-property-for-tags
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
207 cperl-use-syntax-table-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 "*Non-nil means: set up and use `syntax-table' text property generating TAGS.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210 (defvar cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211 "*Regexp to match files to scan when generating TAGS.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 (defvar cperl-noscan-files-regexp "/\\(\\.\\.?\\|SCCS\\|RCS\\|blib\\)$"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
214 "*Regexp to match files/dirs to skip when generating TAGS.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
215
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
216 (defvar cperl-regexp-indent-step nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
217 "*indentation used when beautifying regexps.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
218 If `nil', the value of `cperl-indent-level' will be used.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
219
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
220 (defvar cperl-indent-left-aligned-comments t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
221 "*Non-nil means that the comment starting in leftmost column should indent.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
222
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223 (defvar cperl-under-as-char t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 "*Non-nil means that the _ (underline) should be treated as word char.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
228
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
229 ;;; Short extra-docs.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
230
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
231 (defvar cperl-tips 'please-ignore-this-line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
232 "Get newest version of this package from
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
233 ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
234 and/or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
235 ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
236
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
237 Get support packages choose-color.el (or font-lock-extra.el before
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
238 19.30), imenu-go.el from the same place. \(Look for other files there
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
239 too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
240 later you should use choose-color.el *instead* of font-lock-extra.el
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
241 \(and you will not get smart highlighting in C :-().
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
243 Note that to enable Compile choices in the menu you need to install
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
244 mode-compile.el.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
245
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
246 Get perl5-info from
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
247 $CPAN/doc/manual/info/perl-info.tar.gz
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
248 older version was on
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
249 http://www.metronet.com:70/9/perlinfo/perl5/manual/perl5-info.tar.gz
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
250
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
251 If you use imenu-go, run imenu on perl5-info buffer (you can do it
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
252 from CPerl menu). If many files are related, generate TAGS files from
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
253 Tools/Tags submenu in CPerl menu.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
254
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
255 If some class structure is too complicated, use Tools/Hierarchy-view
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
256 from CPerl menu, or hierarchic view of imenu. The second one uses the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
257 current buffer only, the first one requires generation of TAGS from
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258 CPerl/Tools/Tags menu beforehand.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260 Run CPerl/Tools/Insert-spaces-if-needed to fix your lazy typing.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
261
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
262 Switch auto-help on/off with CPerl/Tools/Auto-help.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
263
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
264 Before reporting (non-)problems look in the problem section on what I
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
265 know about them.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
266
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
267 (defvar cperl-problems 'please-ignore-this-line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
268 "Emacs has a _very_ restricted syntax parsing engine.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
269
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
270 It may be corrected on the level of C code, please look in the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
271 `non-problems' section if you want to volunteer.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
272
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
273 CPerl mode tries to corrects some Emacs misunderstandings, however,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
274 for efficiency reasons the degree of correction is different for
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
275 different operations. The partially corrected problems are: POD
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
276 sections, here-documents, regexps. The operations are: highlighting,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
277 indentation, electric keywords, electric braces.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
278
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
279 This may be confusing, since the regexp s#//#/#\; may be highlighted
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
280 as a comment, but it will be recognized as a regexp by the indentation
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
281 code. Or the opposite case, when a pod section is highlighted, but
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
282 may break the indentation of the following code (though indentation
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
283 should work if the balance of delimiters is not broken by POD).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
284
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
285 The main trick (to make $ a \"backslash\") makes constructions like
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
286 ${aaa} look like unbalanced braces. The only trick I can think of is
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
287 to insert it as $ {aaa} (legal in perl5, not in perl4).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
288
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
289 Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
290 as /($|\\s)/. Note that such a transposition is not always possible
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
291 :-(. " )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
292
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
293 (defvar cperl-non-problems 'please-ignore-this-line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
294 "As you know from `problems' section, Perl syntax is too hard for CPerl.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
295
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
296 Most the time, if you write your own code, you may find an equivalent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
297 \(and almost as readable) expression.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
298
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
299 Try to help CPerl: add comments with embedded quotes to fix CPerl
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
300 misunderstandings about the end of quotation:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
301
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
302 $a='500$'; # ';
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
303
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
304 You won't need it too often. The reason: $ \"quotes\" the following
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
305 character (this saves a life a lot of times in CPerl), thus due to
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
306 Emacs parsing rules it does not consider tick (i.e., ' ) after a
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
307 dollar as a closing one, but as a usual character.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
308
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
309 Now the indentation code is pretty wise. The only drawback is that it
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
310 relies on Emacs parsing to find matching parentheses. And Emacs
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
311 *cannot* match parentheses in Perl 100% correctly. So
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
312 1 if s#//#/#;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
313 will not break indentation, but
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
314 1 if ( s#//#/# );
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
315 will.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
316
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
317 By similar reasons
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
318 s\"abc\"def\";
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
319 will confuse CPerl a lot.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
320
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
321 If you still get wrong indentation in situation that you think the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
322 code should be able to parse, try:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
323
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
324 a) Check what Emacs thinks about balance of your parentheses.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
325 b) Supply the code to me (IZ).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
326
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
327 Pods are treated _very_ rudimentally. Here-documents are not treated
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
328 at all (except highlighting and inhibiting indentation). (This may
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
329 change some time. RMS approved making syntax lookup recognize text
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
330 attributes, but volunteers are needed to change Emacs C code.)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
331
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
332 To speed up coloring the following compromises exist:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
333 a) sub in $mypackage::sub may be highlighted.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
334 b) -z in [a-z] may be highlighted.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
335 c) if your regexp contains a keyword (like \"s\"), it may be highlighted.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
336
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
337
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
338 Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
339 `car' before `imenu-choose-buffer-index' in `imenu'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
340 ")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
341
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
342 (defvar cperl-praise 'please-ignore-this-line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
343 "RMS asked me to list good things about CPerl. Here they go:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
344
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
345 0) It uses the newest `syntax-table' property ;-);
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
346
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
347 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
348 mode - but the latter number may have improved too in last years) even
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
349 without `syntax-table' property; When using this property, it should
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
350 handle 99.995% of lines correct - or somesuch.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
351
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
352 2) It is generally belived to be \"the most user-friendly Emacs
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
353 package\" whatever it may mean (I doubt that the people who say similar
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
354 things tried _all_ the rest of Emacs ;-), but this was not a lonely
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
355 voice);
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
356
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
357 3) Everything is customizable, one-by-one or in a big sweep;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
358
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
359 4) It has many easily-accessable \"tools\":
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
360 a) Can run program, check syntax, start debugger;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
361 b) Can lineup vertically \"middles\" of rows, like `=' in
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
362 a = b;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
363 cc = d;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
364 c) Can insert spaces where this impoves readability (in one
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
365 interactive sweep over the buffer);
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
366 d) Has support for imenu, including:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
367 1) Separate unordered list of \"interesting places\";
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
368 2) Separate TOC of POD sections;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
369 3) Separate list of packages;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
370 4) Hierarchical view of methods in (sub)packages;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
371 5) and functions (by the full name - with package);
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
372 e) Has an interface to INFO docs for Perl; The interface is
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
373 very flexible, including shrink-wrapping of
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
374 documentation buffer/frame;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
375 f) Has a builtin list of one-line explanations for perl constructs.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
376 g) Can show these explanations if you stay long enough at the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
377 corresponding place (or on demand);
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
378 h) Has an enhanced fontification (using 3 or 4 additional faces
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
379 comparing to font-lock - basically, different
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
380 namespaces in Perl have different colors);
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
381 i) Can construct TAGS basing on its knowledge of Perl syntax,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
382 the standard menu has 6 different way to generate
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
383 TAGS (if by directory, .xs files - with C-language
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
384 bindings - are included in the scan);
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
385 j) Can build a hierarchical view of classes (via imenu) basing
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
386 on generated TAGS file;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
387 k) Has electric parentheses, electric newlines, uses Abbrev
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
388 for electric logical constructs
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
389 while () {}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
390 with different styles of expansion (context sensitive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
391 to be not so bothering). Electric parentheses behave
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
392 \"as they should\" in a presence of a visible region.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
393 l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
394
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
395 5) The indentation engine was very smart, but most of tricks may be
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
396 not needed anymore with the support for `syntax-table' property. Has
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
397 progress indicator for indentation (with `imenu' loaded).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
398
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
399 6) Indent-region improves inline-comments as well;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
400
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
401 7) Fill-paragraph correctly handles multi-line comments;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
402 ")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
403
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
404
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
405
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
406 ;;; Portability stuff:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
407
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
408 (defmacro cperl-define-key (emacs-key definition &optional xemacs-key)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
409 (` (define-key cperl-mode-map
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
410 (, (if xemacs-key
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
411 (` (if cperl-xemacs-p (, xemacs-key) (, emacs-key)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
412 emacs-key))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
413 (, definition))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
414
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
415 (defvar cperl-del-back-ch
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
416 (car (append (where-is-internal 'delete-backward-char)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
417 (where-is-internal 'backward-delete-char-untabify)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
418 "Character generated by key bound to delete-backward-char.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
419
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
420 (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
421 (setq cperl-del-back-ch (aref cperl-del-back-ch 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
422
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
423 (if cperl-xemacs-p
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
424 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
425 ;; "Active regions" are on: use region only if active
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
426 ;; "Active regions" are off: use region unconditionally
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
427 (defun cperl-use-region-p ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
428 (if zmacs-regions (mark) t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
429 (defun cperl-mark-active () (mark)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
430 (defun cperl-use-region-p ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
431 (if transient-mark-mode mark-active t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
432 (defun cperl-mark-active () mark-active))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
433
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
434 (defsubst cperl-enable-font-lock ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
435 (or cperl-xemacs-p window-system))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
436
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
437 (if (boundp 'unread-command-events)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
438 (if cperl-xemacs-p
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
439 (defun cperl-putback-char (c) ; XEmacs >= 19.12
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
440 (setq unread-command-events (list (character-to-event c))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
441 (defun cperl-putback-char (c) ; Emacs 19
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
442 (setq unread-command-events (list c))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
443 (defun cperl-putback-char (c) ; XEmacs <= 19.11
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
444 (setq unread-command-event (character-to-event c))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
445
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
446 (or (fboundp 'uncomment-region)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
447 (defun uncomment-region (beg end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
448 (interactive "r")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
449 (comment-region beg end -1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
450
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
451 (defvar cperl-do-not-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
452 (if (string< emacs-version "19.30")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
453 'fontified
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
454 'lazy-lock)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
455 "Text property which inhibits refontification.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
456
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
457 (defsubst cperl-put-do-not-fontify (from to)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
458 (put-text-property (max (point-min) (1- from))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
459 to cperl-do-not-fontify t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
460
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
461 (defvar cperl-mode-hook nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
462 "Hook run by `cperl-mode'.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
463
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
464
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
465 ;;; Probably it is too late to set these guys already, but it can help later:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
466
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
467 ;;;(setq auto-mode-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
468 ;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist ))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
469 ;;;(and (boundp 'interpreter-mode-alist)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
470 ;;; (setq interpreter-mode-alist (append interpreter-mode-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
471 '(("miniperl" . perl-mode)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
472 (if (fboundp 'eval-when-compile)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
473 (eval-when-compile
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
474 (condition-case nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
475 (require 'imenu)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
476 (error nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
477 (condition-case nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
478 (require 'easymenu)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
479 (error nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
480 ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
481 ;; macros instead of defsubsts don't work on Emacs, so we do the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
482 ;; expansion manually. Any other suggestions?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
483 (if (or (string-match "XEmacs\\|Lucid" emacs-version)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
484 window-system)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
485 (require 'font-lock))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
486 (require 'cl)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
487 ))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
488
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
489 (defvar cperl-mode-abbrev-table nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
490 "Abbrev table in use in Cperl-mode buffers.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
491
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
492 (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
493
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
494 (defvar cperl-mode-map () "Keymap used in CPerl mode.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
495
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
496 (if cperl-mode-map nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
497 (setq cperl-mode-map (make-sparse-keymap))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
498 (cperl-define-key "{" 'cperl-electric-lbrace)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
499 (cperl-define-key "[" 'cperl-electric-paren)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
500 (cperl-define-key "(" 'cperl-electric-paren)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
501 (cperl-define-key "<" 'cperl-electric-paren)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
502 (cperl-define-key "}" 'cperl-electric-brace)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
503 (cperl-define-key "]" 'cperl-electric-rparen)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
504 (cperl-define-key ")" 'cperl-electric-rparen)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
505 (cperl-define-key ";" 'cperl-electric-semi)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
506 (cperl-define-key ":" 'cperl-electric-terminator)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
507 (cperl-define-key "\C-j" 'newline-and-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
508 (cperl-define-key "\C-c\C-j" 'cperl-linefeed)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
509 (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
510 (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
511 (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
512 (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
513 (cperl-define-key [?\C-\M-\|] 'cperl-lineup
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
514 [(control meta |)])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
515 ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
516 ;;(cperl-define-key "\e;" 'cperl-indent-for-comment)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
517 (cperl-define-key "\177" 'cperl-electric-backspace)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
518 (cperl-define-key "\t" 'cperl-indent-command)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
519 ;; don't clobber the backspace binding:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
520 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
521 [(control c) (control h) f])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
522 (cperl-define-key "\C-hf"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
523 ;;(concat (char-to-string help-char) "f") ; does not work
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
524 'cperl-info-on-command
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
525 [(control h) f])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
526 (cperl-define-key "\C-hv"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
527 ;;(concat (char-to-string help-char) "v") ; does not work
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
528 'cperl-get-help
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
529 [(control h) v])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
530 (if (and cperl-xemacs-p
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
531 (<= emacs-minor-version 11) (<= emacs-major-version 19))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
532 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
533 ;; substitute-key-definition is usefulness-deenhanced...
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
534 (cperl-define-key "\M-q" 'cperl-fill-paragraph)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
535 (cperl-define-key "\e;" 'cperl-indent-for-comment)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
536 (cperl-define-key "\e\C-\\" 'cperl-indent-region))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
537 (substitute-key-definition
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
538 'indent-sexp 'cperl-indent-exp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
539 cperl-mode-map global-map)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
540 (substitute-key-definition
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
541 'fill-paragraph 'cperl-fill-paragraph
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
542 cperl-mode-map global-map)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
543 (substitute-key-definition
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
544 'indent-region 'cperl-indent-region
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
545 cperl-mode-map global-map)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
546 (substitute-key-definition
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
547 'indent-for-comment 'cperl-indent-for-comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
548 cperl-mode-map global-map)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
549
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
550 (defvar cperl-menu)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
551 (condition-case nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
552 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
553 (require 'easymenu)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
554 (easy-menu-define cperl-menu cperl-mode-map "Menu for CPerl mode"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
555 '("Perl"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
556 ["Beginning of function" beginning-of-defun t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
557 ["End of function" end-of-defun t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
558 ["Mark function" mark-defun t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
559 ["Indent expression" cperl-indent-exp t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
560 ["Fill paragraph/comment" cperl-fill-paragraph t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
561 "----"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
562 ["Line up a construction" cperl-lineup (cperl-use-region-p)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
563 ["Beautify a regexp" cperl-beautify-regexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
564 cperl-use-syntax-table-text-property]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
565 ["Beautify a group in regexp" cperl-beautify-level
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
566 cperl-use-syntax-table-text-property]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
567 ["Contract a group in regexp" cperl-contract-level
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
568 cperl-use-syntax-table-text-property]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
569 ["Refresh \"hard\" constructions" cperl-find-pods-heres t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
570 "----"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
571 ["Indent region" cperl-indent-region (cperl-use-region-p)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
572 ["Comment region" cperl-comment-region (cperl-use-region-p)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
573 ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
574 "----"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
575 ["Run" mode-compile (fboundp 'mode-compile)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
576 ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
577 (get-buffer "*compilation*"))]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
578 ["Next error" next-error (get-buffer "*compilation*")]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
579 ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
580 "----"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
581 ["Debugger" cperl-db t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
582 "----"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
583 ("Tools"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
584 ["Imenu" imenu (fboundp 'imenu)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
585 ["Insert spaces if needed" cperl-find-bad-style t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
586 ["Class Hierarchy from TAGS" cperl-tags-hier-init t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
587 ;;["Update classes" (cperl-tags-hier-init t) tags-table-list]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
588 ["Imenu on info" cperl-imenu-on-info (featurep 'imenu)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
589 ("Tags"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
590 ;;; ["Create tags for current file" cperl-etags t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
591 ;;; ["Add tags for current file" (cperl-etags t) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
592 ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
593 ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
594 ;;; ["Create tags for Perl files in (sub)directories"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
595 ;;; (cperl-etags nil 'recursive) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
596 ;;; ["Add tags for Perl files in (sub)directories"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
597 ;;; (cperl-etags t 'recursive) t])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
598 ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
599 ["Create tags for current file" (cperl-write-tags nil t) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
600 ["Add tags for current file" (cperl-write-tags) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
601 ["Create tags for Perl files in directory"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
602 (cperl-write-tags nil t nil t) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
603 ["Add tags for Perl files in directory"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
604 (cperl-write-tags nil nil nil t) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
605 ["Create tags for Perl files in (sub)directories"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
606 (cperl-write-tags nil t t t) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
607 ["Add tags for Perl files in (sub)directories"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
608 (cperl-write-tags nil nil t t) t])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
609 ["Define word at point" imenu-go-find-at-position
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
610 (fboundp 'imenu-go-find-at-position)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
611 ["Help on function" cperl-info-on-command t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
612 ["Help on function at point" cperl-info-on-current-command t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
613 ["Help on symbol at point" cperl-get-help t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
614 ["Auto-help on" cperl-lazy-install (fboundp 'run-with-idle-timer)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
615 ["Auto-help off" cperl-lazy-unstall
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
616 (fboundp 'run-with-idle-timer)])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
617 ("Toggle..."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
618 ["Auto newline" cperl-toggle-auto-newline t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
619 ["Electric parens" cperl-toggle-electric t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
620 ["Electric keywords" cperl-toggle-abbrev t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
621 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
622 ("Indent styles..."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
623 ["GNU" (cperl-set-style "GNU") t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
624 ["C++" (cperl-set-style "C++") t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
625 ["FSF" (cperl-set-style "FSF") t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
626 ["BSD" (cperl-set-style "BSD") t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
627 ["Whitesmith" (cperl-set-style "Whitesmith") t])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
628 ("Micro-docs"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
629 ["Tips" (describe-variable 'cperl-tips) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
630 ["Problems" (describe-variable 'cperl-problems) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
631 ["Non-problems" (describe-variable 'cperl-non-problems) t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
632 ["Praise" (describe-variable 'cperl-praise) t]))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
633 (error nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
634
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
635 (autoload 'c-macro-expand "cmacexp"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
636 "Display the result of expanding all C macros occurring in the region.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
637 The expansion is entirely correct because it uses the C preprocessor."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
638 t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
639
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
640 (defvar cperl-mode-syntax-table nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
641 "Syntax table in use in Cperl-mode buffers.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
642
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
643 (defvar cperl-string-syntax-table nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
644 "Syntax table in use in Cperl-mode string-like chunks.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
645
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
646 (if cperl-mode-syntax-table
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
647 ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
648 (setq cperl-mode-syntax-table (make-syntax-table))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
649 (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
650 (modify-syntax-entry ?/ "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
651 (modify-syntax-entry ?* "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
652 (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
653 (modify-syntax-entry ?- "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
654 (modify-syntax-entry ?= "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
655 (modify-syntax-entry ?% "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
656 (modify-syntax-entry ?< "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
657 (modify-syntax-entry ?> "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
658 (modify-syntax-entry ?& "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
659 (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
660 (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
661 (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
662 (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
663 (modify-syntax-entry ?` "\"" cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
664 (if cperl-under-as-char
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
665 (modify-syntax-entry ?_ "w" cperl-mode-syntax-table))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
666 (modify-syntax-entry ?: "_" cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
667 (modify-syntax-entry ?| "." cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
668 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
669 (modify-syntax-entry ?$ "." cperl-string-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
670 (modify-syntax-entry ?# "." cperl-string-syntax-table) ; (?# comment )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
671 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
672
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
673
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
674
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
675 ;; Make customization possible "in reverse"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
676 ;;(defun cperl-set (symbol to)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
677 ;; (or (eq (symbol-value symbol) 'null) (set symbol to)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
678 (defsubst cperl-val (symbol &optional default hairy)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
679 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
680 ((eq (symbol-value symbol) 'null) default)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
681 (cperl-hairy (or hairy t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
682 (t (symbol-value symbol))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
683
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
684 ;; provide an alias for working with emacs 19. the perl-mode that comes
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
685 ;; with it is really bad, and this lets us seamlessly replace it.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
686 ;;;###autoload
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
687 (fset 'perl-mode 'cperl-mode)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
688 (defvar cperl-faces-init)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
689 ;; Fix for msb.el
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
690 (defvar cperl-msb-fixed nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
691 ;;;###autoload
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
692 (defun cperl-mode ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
693 "Major mode for editing Perl code.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
694 Expression and list commands understand all C brackets.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
695 Tab indents for Perl code.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
696 Paragraphs are separated by blank lines only.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
697 Delete converts tabs to spaces as it moves back.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
698
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
699 Various characters in Perl almost always come in pairs: {}, (), [],
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
700 sometimes <>. When the user types the first, she gets the second as
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
701 well, with optional special formatting done on {}. (Disabled by
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
702 default.) You can always quote (with \\[quoted-insert]) the left
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
703 \"paren\" to avoid the expansion. The processing of < is special,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
704 since most the time you mean \"less\". Cperl mode tries to guess
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
705 whether you want to type pair <>, and inserts is if it
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
706 appropriate. You can set `cperl-electric-parens-string' to the string that
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
707 contains the parenths from the above list you want to be electrical.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
708 Electricity of parenths is controlled by `cperl-electric-parens'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
709 You may also set `cperl-electric-parens-mark' to have electric parens
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
710 look for active mark and \"embrace\" a region if possible.'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
711
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
712 CPerl mode provides expansion of the Perl control constructs:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
713 if, else, elsif, unless, while, until, for, and foreach.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
714 =========(Disabled by default, see `cperl-electric-keywords'.)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
715 The user types the keyword immediately followed by a space, which causes
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
716 the construct to be expanded, and the user is positioned where she is most
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
717 likely to want to be.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
718 eg. when the user types a space following \"if\" the following appears in
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
719 the buffer:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
720 if () { or if ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
721 } {
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
722 }
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
723 and the cursor is between the parentheses. The user can then type some
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
724 boolean expression within the parens. Having done that, typing
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
725 \\[cperl-linefeed] places you, appropriately indented on a new line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
726 between the braces. If CPerl decides that you want to insert
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
727 \"English\" style construct like
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
728 bite if angry;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
729 it will not do any expansion. See also help on variable
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
730 `cperl-extra-newline-before-brace'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
731
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
732 \\[cperl-linefeed] is a convenience replacement for typing carriage
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
733 return. It places you in the next line with proper indentation, or if
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
734 you type it inside the inline block of control construct, like
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
735 foreach (@lines) {print; print}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
736 and you are on a boundary of a statement inside braces, it will
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
737 transform the construct into a multiline and will place you into an
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
738 appropriately indented blank line. If you need a usual
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
739 `newline-and-indent' behaviour, it is on \\[newline-and-indent],
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
740 see documentation on `cperl-electric-linefeed'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
741
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
742 \\{cperl-mode-map}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
743
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
744 Setting the variable `cperl-font-lock' to t switches on
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
745 font-lock-mode, `cperl-electric-lbrace-space' to t switches on
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
746 electric space between $ and {, `cperl-electric-parens-string' is the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
747 string that contains parentheses that should be electric in CPerl (see
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
748 also `cperl-electric-parens-mark' and `cperl-electric-parens'),
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
749 setting `cperl-electric-keywords' enables electric expansion of
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
750 control structures in CPerl. `cperl-electric-linefeed' governs which
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
751 one of two linefeed behavior is preferable. You can enable all these
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
752 options simultaneously (recommended mode of use) by setting
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
753 `cperl-hairy' to t. In this case you can switch separate options off
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
754 by setting them to `null'. Note that one may undo the extra whitespace
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
755 inserted by semis and braces in `auto-newline'-mode by consequent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
756 \\[cperl-electric-backspace].
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
757
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
758 If your site has perl5 documentation in info format, you can use commands
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
759 \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
760 These keys run commands `cperl-info-on-current-command' and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
761 `cperl-info-on-command', which one is which is controlled by variable
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
762 `cperl-info-on-command-no-prompt' (in turn affected by `cperl-hairy').
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
763
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
764 Even if you have no info-format documentation, short one-liner-style
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
765 help is available on \\[cperl-get-help].
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
766
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
767 It is possible to show this help automatically after some idle
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
768 time. This is regulated by variable `cperl-lazy-help-time'. Default
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
769 with `cperl-hairy' is 5 secs idle time if the value of this variable
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
770 is nil. It is also possible to switch this on/off from the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
771 menu. Requires `run-with-idle-timer'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
772
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
773 Use \\[cperl-lineup] to vertically lineup some construction - put the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
774 beginning of the region at the start of construction, and make region
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
775 span the needed amount of lines.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
776
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
777 Variables `cperl-pod-here-scan', `cperl-pod-here-fontify',
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
778 `cperl-pod-face', `cperl-pod-head-face' control processing of pod and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
779 here-docs sections. In a future version results of scan may be used
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
780 for indentation too, currently they are used for highlighting only.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
781
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
782 Variables controlling indentation style:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
783 `cperl-tab-always-indent'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
784 Non-nil means TAB in CPerl mode should always reindent the current line,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
785 regardless of where in the line point is when the TAB command is used.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
786 `cperl-auto-newline'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
787 Non-nil means automatically newline before and after braces,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
788 and after colons and semicolons, inserted in Perl code. The following
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
789 \\[cperl-electric-backspace] will remove the inserted whitespace.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
790 Insertion after colons requires both this variable and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
791 `cperl-auto-newline-after-colon' set.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
792 `cperl-auto-newline-after-colon'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
793 Non-nil means automatically newline even after colons.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
794 Subject to `cperl-auto-newline' setting.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
795 `cperl-indent-level'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
796 Indentation of Perl statements within surrounding block.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
797 The surrounding block's indentation is the indentation
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
798 of the line on which the open-brace appears.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
799 `cperl-continued-statement-offset'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
800 Extra indentation given to a substatement, such as the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
801 then-clause of an if, or body of a while, or just a statement continuation.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
802 `cperl-continued-brace-offset'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
803 Extra indentation given to a brace that starts a substatement.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
804 This is in addition to `cperl-continued-statement-offset'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
805 `cperl-brace-offset'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
806 Extra indentation for line if it starts with an open brace.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
807 `cperl-brace-imaginary-offset'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
808 An open brace following other text is treated as if it the line started
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
809 this far to the right of the actual line indentation.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
810 `cperl-label-offset'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
811 Extra indentation for line that is a label.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
812 `cperl-min-label-indent'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
813 Minimal indentation for line that is a label.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
814
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
815 Settings for K&R and BSD indentation styles are
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
816 `cperl-indent-level' 5 8
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
817 `cperl-continued-statement-offset' 5 8
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
818 `cperl-brace-offset' -5 -8
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
819 `cperl-label-offset' -5 -8
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
820
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
821 If `cperl-indent-level' is 0, the statement after opening brace in column 0 is indented on `cperl-brace-offset'+`cperl-continued-statement-offset'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
822
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
823 Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
824 with no args."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
825 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
826 (kill-all-local-variables)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
827 ;;(if cperl-hairy
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
828 ;; (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
829 ;; (cperl-set 'cperl-font-lock cperl-hairy)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
830 ;; (cperl-set 'cperl-electric-lbrace-space cperl-hairy)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
831 ;; (cperl-set 'cperl-electric-parens "{[(<")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
832 ;; (cperl-set 'cperl-electric-keywords cperl-hairy)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
833 ;; (cperl-set 'cperl-electric-linefeed cperl-hairy)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
834 (use-local-map cperl-mode-map)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
835 (if (cperl-val 'cperl-electric-linefeed)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
836 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
837 (local-set-key "\C-J" 'cperl-linefeed)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
838 (local-set-key "\C-C\C-J" 'newline-and-indent)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
839 (if (cperl-val 'cperl-info-on-command-no-prompt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
840 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
841 ;; don't clobber the backspace binding:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
842 (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
843 (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
844 [(control c) (control h) f])))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
845 (setq major-mode 'perl-mode)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
846 (setq mode-name "CPerl")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
847 (if (not cperl-mode-abbrev-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
848 (let ((prev-a-c abbrevs-changed))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
849 (define-abbrev-table 'cperl-mode-abbrev-table '(
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
850 ("if" "if" cperl-electric-keyword 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
851 ("elsif" "elsif" cperl-electric-keyword 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
852 ("while" "while" cperl-electric-keyword 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
853 ("until" "until" cperl-electric-keyword 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
854 ("unless" "unless" cperl-electric-keyword 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
855 ("else" "else" cperl-electric-else 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
856 ("for" "for" cperl-electric-keyword 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
857 ("foreach" "foreach" cperl-electric-keyword 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
858 ("do" "do" cperl-electric-keyword 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
859 (setq abbrevs-changed prev-a-c)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
860 (setq local-abbrev-table cperl-mode-abbrev-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
861 (abbrev-mode (if (cperl-val 'cperl-electric-keywords) 1 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
862 (set-syntax-table cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
863 (make-local-variable 'paragraph-start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
864 (setq paragraph-start (concat "^$\\|" page-delimiter))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
865 (make-local-variable 'paragraph-separate)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
866 (setq paragraph-separate paragraph-start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
867 (make-local-variable 'paragraph-ignore-fill-prefix)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
868 (setq paragraph-ignore-fill-prefix t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
869 (make-local-variable 'indent-line-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
870 (setq indent-line-function 'cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
871 (make-local-variable 'require-final-newline)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
872 (setq require-final-newline t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
873 (make-local-variable 'comment-start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
874 (setq comment-start "# ")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
875 (make-local-variable 'comment-end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
876 (setq comment-end "")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
877 (make-local-variable 'comment-column)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
878 (setq comment-column cperl-comment-column)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
879 (make-local-variable 'comment-start-skip)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
880 (setq comment-start-skip "#+ *")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
881 (make-local-variable 'defun-prompt-regexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
882 (setq defun-prompt-regexp "^[ \t]*sub[ \t]+\\([^ \t\n{(;]+\\)[ \t]*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
883 (make-local-variable 'comment-indent-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
884 (setq comment-indent-function 'cperl-comment-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
885 (make-local-variable 'parse-sexp-ignore-comments)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
886 (setq parse-sexp-ignore-comments t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
887 (make-local-variable 'indent-region-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
888 (setq indent-region-function 'cperl-indent-region)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
889 ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
890 (make-local-variable 'imenu-create-index-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
891 (setq imenu-create-index-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
892 (function imenu-example--create-perl-index))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
893 (make-local-variable 'imenu-sort-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
894 (setq imenu-sort-function nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
895 (make-local-variable 'vc-header-alist)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
896 (setq vc-header-alist cperl-vc-header-alist)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
897 (make-local-variable 'font-lock-defaults)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
898 (setq font-lock-defaults
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
899 (if (string< emacs-version "19.30")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
900 '(perl-font-lock-keywords-2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
901 '((perl-font-lock-keywords
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
902 perl-font-lock-keywords-1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
903 perl-font-lock-keywords-2))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
904 (if cperl-use-syntax-table-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
905 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
906 (make-variable-buffer-local 'parse-sexp-lookup-properties)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
907 ;; Do not introduce variable if not needed, we check it!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
908 (set 'parse-sexp-lookup-properties t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
909 (or (fboundp 'cperl-old-auto-fill-mode)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
910 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
911 (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
912 (defun auto-fill-mode (&optional arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
913 (interactive "P")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
914 (cperl-old-auto-fill-mode arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
915 (and auto-fill-function (eq major-mode 'perl-mode)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
916 (setq auto-fill-function 'cperl-do-auto-fill)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
917 (if (cperl-enable-font-lock)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
918 (if (cperl-val 'cperl-font-lock)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
919 (progn (or cperl-faces-init (cperl-init-faces))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
920 (font-lock-mode 1))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
921 (and (boundp 'msb-menu-cond)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
922 (not cperl-msb-fixed)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
923 (cperl-msb-fix))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
924 (if (featurep 'easymenu)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
925 (easy-menu-add cperl-menu)) ; A NOP in Emacs.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
926 (run-hooks 'cperl-mode-hook)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
927 ;; After hooks since fontification will break this
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
928 (if cperl-pod-here-scan (cperl-find-pods-heres)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
929
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
930 ;; Fix for perldb - make default reasonable
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
931 (defun cperl-db ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
932 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
933 (require 'gud)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
934 (perldb (read-from-minibuffer "Run perldb (like this): "
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
935 (if (consp gud-perldb-history)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
936 (car gud-perldb-history)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
937 (concat "perl " ;;(file-name-nondirectory
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
938 ;; I have problems
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
939 ;; in OS/2
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
940 ;; otherwise
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
941 (buffer-file-name)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
942 nil nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
943 '(gud-perldb-history . 1))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
944
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
945
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
946 (defun cperl-msb-fix ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
947 ;; Adds perl files to msb menu, supposes that msb is already loaded
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
948 (setq cperl-msb-fixed t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
949 (let* ((l (length msb-menu-cond))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
950 (last (nth (1- l) msb-menu-cond))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
951 (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
952 (handle (1- (nth 1 last))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
953 (setcdr precdr (list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
954 (list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
955 '(eq major-mode 'perl-mode)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
956 handle
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
957 "Perl Files (%d)")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
958 last))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
959
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
960 ;; This is used by indent-for-comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
961 ;; to decide how much to indent a comment in CPerl code
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
962 ;; based on its context. Do fallback if comment is found wrong.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
963
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
964 (defvar cperl-wrong-comment)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
965
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
966 (defun cperl-comment-indent ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
967 (let ((p (point)) (c (current-column)) was)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
968 (if (looking-at "^#") 0 ; Existing comment at bol stays there.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
969 ;; Wrong comment found
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
970 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
971 (setq was (cperl-to-comment-or-eol))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
972 (if (= (point) p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
973 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
974 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
975 (max (1+ (current-column)) ; Else indent at comment column
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
976 comment-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
977 (if was nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
978 (insert comment-start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
979 (backward-char (length comment-start)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
980 (setq cperl-wrong-comment t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
981 (indent-to comment-column 1) ; Indent minimum 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
982 c))))) ; except leave at least one space.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
983
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
984 ;;;(defun cperl-comment-indent-fallback ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
985 ;;; "Is called if the standard comment-search procedure fails.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
986 ;;;Point is at start of real comment."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
987 ;;; (let ((c (current-column)) target cnt prevc)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
988 ;;; (if (= c comment-column) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
989 ;;; (setq cnt (skip-chars-backward "[ \t]"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
990 ;;; (setq target (max (1+ (setq prevc
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
991 ;;; (current-column))) ; Else indent at comment column
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
992 ;;; comment-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
993 ;;; (if (= c comment-column) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
994 ;;; (delete-backward-char cnt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
995 ;;; (while (< prevc target)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
996 ;;; (insert "\t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
997 ;;; (setq prevc (current-column)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
998 ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
999 ;;; (while (< prevc target)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1000 ;;; (insert " ")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1001 ;;; (setq prevc (current-column)))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1002
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1003 (defun cperl-indent-for-comment ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1004 "Substitute for `indent-for-comment' in CPerl."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1005 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1006 (let (cperl-wrong-comment)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1007 (indent-for-comment)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1008 (if cperl-wrong-comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1009 (progn (cperl-to-comment-or-eol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1010 (forward-char (length comment-start))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1011
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1012 (defun cperl-comment-region (b e arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1013 "Comment or uncomment each line in the region in CPerl mode.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1014 See `comment-region'."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1015 (interactive "r\np")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1016 (let ((comment-start "#"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1017 (comment-region b e arg)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1018
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1019 (defun cperl-uncomment-region (b e arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1020 "Uncomment or comment each line in the region in CPerl mode.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1021 See `comment-region'."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1022 (interactive "r\np")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1023 (let ((comment-start "#"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1024 (comment-region b e (- arg))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1025
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1026 (defvar cperl-brace-recursing nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1027
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1028 (defun cperl-electric-brace (arg &optional only-before)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1029 "Insert character and correct line's indentation.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1030 If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1031 place (even in empty line), but not after. If after \")\" and the inserted
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1032 char is \"{\", insert extra newline before only if
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1033 `cperl-extra-newline-before-brace'."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1034 (interactive "P")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1035 (let (insertpos
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1036 (other-end (if (and cperl-electric-parens-mark
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1037 (cperl-mark-active)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1038 (< (mark) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1039 (mark)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1040 nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1041 (if (and other-end
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1042 (not cperl-brace-recursing)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1043 (cperl-val 'cperl-electric-parens)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1044 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1045 ;; Need to insert a matching pair
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1046 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1047 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1048 (setq insertpos (point-marker))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1049 (goto-char other-end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1050 (setq last-command-char ?\{)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1051 (cperl-electric-lbrace arg insertpos))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1052 (forward-char 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1053 (if (and (not arg) ; No args, end (of empty line or auto)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1054 (eolp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1055 (or (and (null only-before)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1056 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1057 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1058 (bolp)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1059 (and (eq last-command-char ?\{) ; Do not insert newline
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1060 ;; if after ")" and `cperl-extra-newline-before-brace'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1061 ;; is nil, do not insert extra newline.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1062 (not cperl-extra-newline-before-brace)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1063 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1064 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1065 (eq (preceding-char) ?\))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1066 (if cperl-auto-newline
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1067 (progn (cperl-indent-line) (newline) t) nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1068 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1069 (self-insert-command (prefix-numeric-value arg))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1070 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1071 (if cperl-auto-newline
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1072 (setq insertpos (1- (point))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1073 (if (and cperl-auto-newline (null only-before))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1074 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1075 (newline)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1076 (cperl-indent-line)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1077 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1078 (if insertpos (progn (goto-char insertpos)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1079 (search-forward (make-string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1080 1 last-command-char))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1081 (setq insertpos (1- (point)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1082 (delete-char -1))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1083 (if insertpos
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1084 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1085 (goto-char insertpos)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1086 (self-insert-command (prefix-numeric-value arg)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1087 (self-insert-command (prefix-numeric-value arg))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1088
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1089 (defun cperl-electric-lbrace (arg &optional end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1090 "Insert character, correct line's indentation, correct quoting by space."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1091 (interactive "P")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1092 (let (pos after
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1093 (cperl-brace-recursing t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1094 (cperl-auto-newline cperl-auto-newline)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1095 (other-end (or end
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1096 (if (and cperl-electric-parens-mark
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1097 (cperl-mark-active)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1098 (> (mark) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1099 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1100 (goto-char (mark))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1101 (point-marker))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1102 nil))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1103 (and (cperl-val 'cperl-electric-lbrace-space)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1104 (eq (preceding-char) ?$)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1105 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1106 (skip-chars-backward "$")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1107 (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1108 (insert ?\ ))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1109 (if (cperl-after-expr-p nil "{;)") nil (setq cperl-auto-newline nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1110 (cperl-electric-brace arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1111 (and (cperl-val 'cperl-electric-parens)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1112 (eq last-command-char ?{)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1113 (memq last-command-char
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1114 (append cperl-electric-parens-string nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1115 (or (if other-end (goto-char (marker-position other-end)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1116 t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1117 (setq last-command-char ?} pos (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1118 (progn (cperl-electric-brace arg t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1119 (goto-char pos)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1120
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1121 (defun cperl-electric-paren (arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1122 "Insert a matching pair of parentheses."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1123 (interactive "P")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1124 (let ((beg (save-excursion (beginning-of-line) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1125 (other-end (if (and cperl-electric-parens-mark
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1126 (cperl-mark-active)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1127 (> (mark) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1128 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1129 (goto-char (mark))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1130 (point-marker))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1131 nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1132 (if (and (cperl-val 'cperl-electric-parens)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1133 (memq last-command-char
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1134 (append cperl-electric-parens-string nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1135 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1136 ;;(not (save-excursion (search-backward "#" beg t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1137 (if (eq last-command-char ?<)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1138 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1139 (and abbrev-mode ; later it is too late, may be after `for'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1140 (expand-abbrev))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1141 (cperl-after-expr-p nil "{;(,:="))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1142 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1143 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1144 (self-insert-command (prefix-numeric-value arg))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1145 (if other-end (goto-char (marker-position other-end)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1146 (insert (make-string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1147 (prefix-numeric-value arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1148 (cdr (assoc last-command-char '((?{ .?})
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1149 (?[ . ?])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1150 (?( . ?))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1151 (?< . ?>))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1152 (forward-char (- (prefix-numeric-value arg))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1153 (self-insert-command (prefix-numeric-value arg)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1154
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1155 (defun cperl-electric-rparen (arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1156 "Insert a matching pair of parentheses if marking is active.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1157 If not, or if we are not at the end of marking range, would self-insert."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1158 (interactive "P")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1159 (let ((beg (save-excursion (beginning-of-line) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1160 (other-end (if (and cperl-electric-parens-mark
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1161 (cperl-val 'cperl-electric-parens)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1162 (memq last-command-char
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1163 (append cperl-electric-parens-string nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1164 (cperl-mark-active)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1165 (< (mark) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1166 (mark)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1167 nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1168 p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1169 (if (and other-end
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1170 (cperl-val 'cperl-electric-parens)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1171 (memq last-command-char '( ?\) ?\] ?\} ?\> ))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1172 (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1173 ;;(not (save-excursion (search-backward "#" beg t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1174 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1175 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1176 (self-insert-command (prefix-numeric-value arg))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1177 (setq p (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1178 (if other-end (goto-char other-end))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1179 (insert (make-string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1180 (prefix-numeric-value arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1181 (cdr (assoc last-command-char '((?\} . ?\{)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1182 (?\] . ?\[)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1183 (?\) . ?\()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1184 (?\> . ?\<))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1185 (goto-char (1+ p)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1186 (self-insert-command (prefix-numeric-value arg)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1187
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1188 (defun cperl-electric-keyword ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1189 "Insert a construction appropriate after a keyword."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1190 (let ((beg (save-excursion (beginning-of-line) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1191 (dollar (and (eq last-command-char ?$)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1192 (eq this-command 'self-insert-command)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1193 (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1194 (memq this-command '(self-insert-command newline)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1195 (and (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1196 (backward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1197 (cperl-after-expr-p nil "{;:"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1198 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1199 (not
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1200 (re-search-backward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1201 "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1202 beg t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1203 (save-excursion (or (not (re-search-backward "^=" nil t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1204 (looking-at "=cut")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1205 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1206 (and dollar (insert " $"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1207 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1208 ;;(insert " () {\n}")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1209 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1210 (cperl-extra-newline-before-brace
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1211 (insert " ()\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1212 (insert "{")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1213 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1214 (insert "\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1215 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1216 (insert "\n}"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1217 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1218 (insert " () {\n}"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1219 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1220 (or (looking-at "[ \t]\\|$") (insert " "))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1221 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1222 (if dollar (progn (search-backward "$")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1223 (delete-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1224 (forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1225 (forward-char 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1226 (search-backward ")"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1227 (if delete
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1228 (cperl-putback-char cperl-del-back-ch))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1229
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1230 (defun cperl-electric-else ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1231 "Insert a construction appropriate after a keyword."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1232 (let ((beg (save-excursion (beginning-of-line) (point))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1233 (and (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1234 (backward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1235 (cperl-after-expr-p nil "{;:"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1236 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1237 (not
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1238 (re-search-backward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1239 "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1240 beg t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1241 (save-excursion (or (not (re-search-backward "^=" nil t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1242 (looking-at "=cut")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1243 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1244 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1245 ;;(insert " {\n\n}")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1246 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1247 (cperl-extra-newline-before-brace
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1248 (insert "\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1249 (insert "{")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1250 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1251 (insert "\n\n}"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1252 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1253 (insert " {\n\n}"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1254 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1255 (or (looking-at "[ \t]\\|$") (insert " "))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1256 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1257 (forward-line -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1258 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1259 (cperl-putback-char cperl-del-back-ch)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1260
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1261 (defun cperl-linefeed ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1262 "Go to end of line, open a new line and indent appropriately."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1263 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1264 (let ((beg (save-excursion (beginning-of-line) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1265 (end (save-excursion (end-of-line) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1266 (pos (point)) start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1267 (if (and ; Check if we need to split:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1268 ; i.e., on a boundary and inside "{...}"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1269 (save-excursion (cperl-to-comment-or-eol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1270 (>= (point) pos)) ; Not in a comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1271 (or (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1272 (skip-chars-backward " \t" beg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1273 (forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1274 (looking-at "[;{]")) ; After { or ; + spaces
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1275 (looking-at "[ \t]*}") ; Before }
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1276 (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1277 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1278 (and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1279 (eq (car (parse-partial-sexp pos end -1)) -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1280 ; Leave the level of parens
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1281 (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1282 ; Are at end
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1283 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1284 (backward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1285 (setq start (point-marker))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1286 (<= start pos))))) ; RedundantAre after the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1287 ; start of parens group.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1288 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1289 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1290 (or (memq (preceding-char) (append ";{" nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1291 (insert ";"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1292 (insert "\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1293 (forward-line -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1294 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1295 (goto-char start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1296 (or (looking-at "{[ \t]*$") ; If there is a statement
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1297 ; before, move it to separate line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1298 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1299 (forward-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1300 (insert "\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1301 (cperl-indent-line)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1302 (forward-line 1) ; We are on the target line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1303 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1304 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1305 (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1306 ; after, move it to separate line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1307 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1308 (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1309 (search-backward "}" beg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1310 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1311 (or (memq (preceding-char) (append ";{" nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1312 (insert ";"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1313 (insert "\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1314 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1315 (forward-line -1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1316 (forward-line -1) ; We are on the line before target
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1317 (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1318 (newline-and-indent))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1319 (end-of-line) ; else
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1320 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1321 ((and (looking-at "\n[ \t]*{$")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1322 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1323 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1324 (eq (preceding-char) ?\)))) ; Probably if () {} group
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1325 ; with an extra newline.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1326 (forward-line 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1327 (cperl-indent-line))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1328 ((looking-at "\n[ \t]*$") ; Next line is empty - use it.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1329 (forward-line 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1330 (cperl-indent-line))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1331 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1332 (newline-and-indent))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1333
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1334 (defun cperl-electric-semi (arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1335 "Insert character and correct line's indentation."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1336 (interactive "P")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1337 (if cperl-auto-newline
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1338 (cperl-electric-terminator arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1339 (self-insert-command (prefix-numeric-value arg))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1340
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1341 (defun cperl-electric-terminator (arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1342 "Insert character and correct line's indentation."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1343 (interactive "P")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1344 (let (insertpos (end (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1345 (auto (and cperl-auto-newline
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1346 (or (not (eq last-command-char ?:))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1347 cperl-auto-newline-after-colon))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1348 (if (and ;;(not arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1349 (eolp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1350 (not (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1351 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1352 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1353 (or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1354 ;; Ignore in comment lines
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1355 (= (following-char) ?#)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1356 ;; Colon is special only after a label
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1357 ;; So quickly rule out most other uses of colon
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1358 ;; and do no indentation for them.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1359 (and (eq last-command-char ?:)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1360 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1361 (forward-word 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1362 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1363 (and (< (point) end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1364 (progn (goto-char (- end 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1365 (not (looking-at ":"))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1366 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1367 (beginning-of-defun)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1368 (let ((pps (parse-partial-sexp (point) end)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1369 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1370 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1371 (self-insert-command (prefix-numeric-value arg))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1372 ;;(forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1373 (if auto (setq insertpos (point-marker)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1374 ;;(forward-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1375 (cperl-indent-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1376 (if auto
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1377 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1378 (newline)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1379 (cperl-indent-line)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1380 ;; (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1381 ;; (if insertpos (progn (goto-char (marker-position insertpos))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1382 ;; (search-forward (make-string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1383 ;; 1 last-command-char))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1384 ;; (setq insertpos (1- (point)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1385 ;; (delete-char -1))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1386 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1387 (if insertpos (goto-char (1- (marker-position insertpos)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1388 (forward-char -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1389 (delete-char 1))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1390 (if insertpos
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1391 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1392 (goto-char insertpos)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1393 (self-insert-command (prefix-numeric-value arg)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1394 (self-insert-command (prefix-numeric-value arg)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1395
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1396 (defun cperl-electric-backspace (arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1397 "Backspace-untabify, or remove the whitespace inserted by an electric key."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1398 (interactive "p")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1399 (if (and cperl-auto-newline
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1400 (memq last-command '(cperl-electric-semi
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1401 cperl-electric-terminator
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1402 cperl-electric-lbrace))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1403 (memq (preceding-char) '(?\ ?\t ?\n)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1404 (let (p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1405 (if (eq last-command 'cperl-electric-lbrace)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1406 (skip-chars-forward " \t\n"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1407 (setq p (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1408 (skip-chars-backward " \t\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1409 (delete-region (point) p))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1410 (backward-delete-char-untabify arg)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1411
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1412 (defun cperl-inside-parens-p ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1413 (condition-case ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1414 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1415 (save-restriction
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1416 (narrow-to-region (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1417 (progn (beginning-of-defun) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1418 (goto-char (point-max))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1419 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1420 (error nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1421
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1422 (defun cperl-indent-command (&optional whole-exp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1423 "Indent current line as Perl code, or in some cases insert a tab character.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1424 If `cperl-tab-always-indent' is non-nil (the default), always indent current line.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1425 Otherwise, indent the current line only if point is at the left margin
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1426 or in the line's indentation; otherwise insert a tab.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1427
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1428 A numeric argument, regardless of its value,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1429 means indent rigidly all the lines of the expression starting after point
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1430 so that this line becomes properly indented.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1431 The relative indentation among the lines of the expression are preserved."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1432 (interactive "P")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1433 (if whole-exp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1434 ;; If arg, always indent this line as Perl
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1435 ;; and shift remaining lines of expression the same amount.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1436 (let ((shift-amt (cperl-indent-line))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1437 beg end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1438 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1439 (if cperl-tab-always-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1440 (beginning-of-line))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1441 (setq beg (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1442 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1443 (setq end (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1444 (goto-char beg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1445 (forward-line 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1446 (setq beg (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1447 (if (> end beg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1448 (indent-code-rigidly beg end shift-amt "#")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1449 (if (and (not cperl-tab-always-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1450 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1451 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1452 (not (bolp))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1453 (insert-tab)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1454 (cperl-indent-line))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1455
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1456 (defun cperl-indent-line (&optional symbol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1457 "Indent current line as Perl code.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1458 Return the amount the indentation changed by."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1459 (let (indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1460 beg shift-amt
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1461 (case-fold-search nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1462 (pos (- (point-max) (point))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1463 (setq indent (cperl-calculate-indent nil symbol))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1464 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1465 (setq beg (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1466 (cond ((or (eq indent nil) (eq indent t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1467 (setq indent (current-indentation)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1468 ;;((eq indent t) ; Never?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1469 ;; (setq indent (cperl-calculate-indent-within-comment)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1470 ;;((looking-at "[ \t]*#")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1471 ;; (setq indent 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1472 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1473 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1474 (if (listp indent) (setq indent (car indent)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1475 (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1476 (and (> indent 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1477 (setq indent (max cperl-min-label-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1478 (+ indent cperl-label-offset)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1479 ((= (following-char) ?})
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1480 (setq indent (- indent cperl-indent-level)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1481 ((memq (following-char) '(?\) ?\])) ; To line up with opening paren.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1482 (setq indent (+ indent cperl-close-paren-offset)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1483 ((= (following-char) ?{)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1484 (setq indent (+ indent cperl-brace-offset))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1485 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1486 (setq shift-amt (- indent (current-column)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1487 (if (zerop shift-amt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1488 (if (> (- (point-max) pos) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1489 (goto-char (- (point-max) pos)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1490 (delete-region beg (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1491 (indent-to indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1492 ;; If initial point was within line's indentation,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1493 ;; position after the indentation. Else stay at same point in text.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1494 (if (> (- (point-max) pos) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1495 (goto-char (- (point-max) pos))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1496 shift-amt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1497
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1498 (defun cperl-after-label ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1499 ;; Returns true if the point is after label. Does not do save-excursion.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1500 (and (eq (preceding-char) ?:)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1501 (memq (char-syntax (char-after (- (point) 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1502 '(?w ?_))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1503 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1504 (backward-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1505 (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1506
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1507 (defun cperl-get-state (&optional parse-start start-state)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1508 ;; returns list (START STATE DEPTH PRESTART), START is a good place
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1509 ;; to start parsing, STATE is what is returned by
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1510 ;; `parse-partial-sexp'. DEPTH is true is we are immediately after
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1511 ;; end of block which contains START. PRESTART is the position
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1512 ;; basing on which START was found.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1513 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1514 (let ((start-point (point)) depth state start prestart)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1515 (if parse-start
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1516 (goto-char parse-start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1517 (beginning-of-defun))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1518 (setq prestart (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1519 (if start-state nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1520 ;; Try to go out, if sub is not on the outermost level
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1521 (while (< (point) start-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1522 (setq start (point) parse-start start depth nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1523 state (parse-partial-sexp start start-point -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1524 (if (> (car state) -1) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1525 ;; The current line could start like }}}, so the indentation
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1526 ;; corresponds to a different level than what we reached
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1527 (setq depth t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1528 (beginning-of-line 2))) ; Go to the next line.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1529 (if start (goto-char start))) ; Not at the start of file
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1530 (setq start (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1531 (if (< start start-point) (setq parse-start start))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1532 (or state (setq state (parse-partial-sexp start start-point -1 nil start-state)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1533 (list start state depth prestart))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1534
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1535 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1536 ;; Positions is before ?\{. Checks whether it starts a block.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1537 ;; No save-excursion!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1538 (cperl-backward-to-noncomment (point-min))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1539 ;;(skip-chars-backward " \t\n\f")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1540 (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1541 ; Label may be mixed up with `$blah :'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1542 (save-excursion (cperl-after-label))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1543 (and (memq (char-syntax (preceding-char)) '(?w ?_))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1544 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1545 (backward-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1546 ;; Need take into account `bless', `return', `tr',...
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1547 (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1548 (not (looking-at "\\(bless\\|return\\|qw\\|tr\\|[smy]\\)\\>")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1549 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1550 (skip-chars-backward " \t\n\f")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1551 (and (memq (char-syntax (preceding-char)) '(?w ?_))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1552 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1553 (backward-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1554 (looking-at
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1555 "sub[ \t]+[a-zA-Z0-9_:]+[ \t\n\f]*\\(([^()]*)[ \t\n\f]*\\)?[#{]")))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1556
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1557 (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1558
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1559 (defun cperl-calculate-indent (&optional parse-start symbol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1560 "Return appropriate indentation for current line as Perl code.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1561 In usual case returns an integer: the column to indent to.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1562 Returns nil if line starts inside a string, t if in a comment."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1563 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1564 (if (or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1565 (memq (get-text-property (point) 'syntax-type)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1566 '(pod here-doc here-doc-delim format))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1567 ;; before start of POD - whitespace found since do not have 'pod!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1568 (and (looking-at "[ \t]*\n=")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1569 (error "Spaces before pod section!"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1570 (and (not cperl-indent-left-aligned-comments)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1571 (looking-at "^#")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1572 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1573 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1574 (let ((indent-point (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1575 (char-after (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1576 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1577 (following-char)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1578 (in-pod (get-text-property (point) 'in-pod))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1579 (pre-indent-point (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1580 p prop look-prop)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1581 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1582 (in-pod
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1583 ;; In the verbatim part, probably code example. What to do???
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1584 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1585 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1586 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1587 ;; Not in pod
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1588 (cperl-backward-to-noncomment nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1589 (setq p (max (point-min) (1- (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1590 prop (get-text-property p 'syntax-type)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1591 look-prop (or (nth 1 (assoc prop cperl-look-for-prop))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1592 'syntax-type))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1593 (if (memq prop '(pod here-doc format here-doc-delim))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1594 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1595 (goto-char (or (previous-single-property-change p look-prop)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1596 (point-min)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1597 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1598 (setq pre-indent-point (point)))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1599 (goto-char pre-indent-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1600 (let* ((case-fold-search nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1601 (s-s (cperl-get-state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1602 (start (nth 0 s-s))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1603 (state (nth 1 s-s))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1604 (containing-sexp (car (cdr state)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1605 (start-indent (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1606 (goto-char start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1607 (- (current-indentation)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1608 (if (nth 2 s-s) cperl-indent-level 0))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1609 old-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1610 ;; (or parse-start (null symbol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1611 ;; (setq parse-start (symbol-value symbol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1612 ;; start-indent (nth 2 parse-start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1613 ;; parse-start (car parse-start)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1614 ;; (if parse-start
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1615 ;; (goto-char parse-start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1616 ;; (beginning-of-defun))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1617 ;; ;; Try to go out
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1618 ;; (while (< (point) indent-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1619 ;; (setq start (point) parse-start start moved nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1620 ;; state (parse-partial-sexp start indent-point -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1621 ;; (if (> (car state) -1) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1622 ;; ;; The current line could start like }}}, so the indentation
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1623 ;; ;; corresponds to a different level than what we reached
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1624 ;; (setq moved t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1625 ;; (beginning-of-line 2))) ; Go to the next line.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1626 ;; (if start ; Not at the start of file
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1627 ;; (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1628 ;; (goto-char start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1629 ;; (setq start-indent (current-indentation))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1630 ;; (if moved ; Should correct...
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1631 ;; (setq start-indent (- start-indent cperl-indent-level))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1632 ;; (setq start-indent 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1633 ;; (if (< (point) indent-point) (setq parse-start (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1634 ;; (or state (setq state (parse-partial-sexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1635 ;; (point) indent-point -1 nil start-state)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1636 ;; (setq containing-sexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1637 ;; (or (car (cdr state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1638 ;; (and (>= (nth 6 state) 0) old-containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1639 ;; old-containing-sexp nil start-state nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1640 ;;;; (while (< (point) indent-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1641 ;;;; (setq parse-start (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1642 ;;;; (setq state (parse-partial-sexp (point) indent-point -1 nil start-state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1643 ;;;; (setq containing-sexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1644 ;;;; (or (car (cdr state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1645 ;;;; (and (>= (nth 6 state) 0) old-containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1646 ;;;; old-containing-sexp nil start-state nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1647 ;; (if symbol (set symbol (list indent-point state start-indent)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1648 ;; (goto-char indent-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1649 (cond ((or (nth 3 state) (nth 4 state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1650 ;; return nil or t if should not change this line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1651 (nth 4 state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1652 ((null containing-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1653 ;; Line is at top level. May be data or function definition,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1654 ;; or may be function argument declaration.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1655 ;; Indent like the previous top level line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1656 ;; unless that ends in a closeparen without semicolon,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1657 ;; in which case this line is the first argument decl.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1658 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1659 (+ start-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1660 (if (= (following-char) ?{) cperl-continued-brace-offset 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1661 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1662 (cperl-backward-to-noncomment (or parse-start (point-min)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1663 ;;(skip-chars-backward " \t\f\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1664 ;; Look at previous line that's at column 0
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1665 ;; to determine whether we are in top-level decls
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1666 ;; or function's arg decls. Set basic-indent accordingly.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1667 ;; Now add a little if this is a continuation line.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1668 (if (or (bobp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1669 (memq (preceding-char) (append " ;}" nil)) ; Was ?\)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1670 (memq char-after (append ")]}" nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1671 (and (eq (preceding-char) ?\:) ; label
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1672 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1673 (forward-sexp -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1674 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1675 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1676 0
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1677 cperl-continued-statement-offset))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1678 ((/= (char-after containing-sexp) ?{)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1679 ;; line is expression, not statement:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1680 ;; indent to just after the surrounding open,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1681 ;; skip blanks if we do not close the expression.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1682 (goto-char (1+ containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1683 (or (memq char-after (append ")]}" nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1684 (looking-at "[ \t]*\\(#\\|$\\)")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1685 (skip-chars-forward " \t"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1686 (current-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1687 ((progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1688 ;; Containing-expr starts with \{. Check whether it is a hash.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1689 (goto-char containing-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1690 (not (cperl-block-p)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1691 (goto-char (1+ containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1692 (or (eq char-after ?\})
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1693 (looking-at "[ \t]*\\(#\\|$\\)")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1694 (skip-chars-forward " \t"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1695 (+ (current-column) ; Correct indentation of trailing ?\}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1696 (if (eq char-after ?\}) (+ cperl-indent-level
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1697 cperl-close-paren-offset)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1698 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1699 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1700 ;; Statement level. Is it a continuation or a new statement?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1701 ;; Find previous non-comment character.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1702 (goto-char pre-indent-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1703 (cperl-backward-to-noncomment containing-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1704 ;; Back up over label lines, since they don't
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1705 ;; affect whether our line is a continuation.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1706 (while (or (eq (preceding-char) ?\,)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1707 (and (eq (preceding-char) ?:)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1708 (or;;(eq (char-after (- (point) 2)) ?\') ; ????
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1709 (memq (char-syntax (char-after (- (point) 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1710 '(?w ?_)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1711 (if (eq (preceding-char) ?\,)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1712 ;; Will go to beginning of line, essentially.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1713 ;; Will ignore embedded sexpr XXXX.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1714 (cperl-backward-to-start-of-continued-exp containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1715 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1716 (cperl-backward-to-noncomment containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1717 ;; Now we get the answer.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1718 (if (not (memq (preceding-char) (append ", ;}{" '(nil)))) ; Was ?\,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1719 ;; This line is continuation of preceding line's statement;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1720 ;; indent `cperl-continued-statement-offset' more than the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1721 ;; previous line of the statement.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1722 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1723 (cperl-backward-to-start-of-continued-exp containing-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1724 (+ (if (memq char-after (append "}])" nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1725 0 ; Closing parenth
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1726 cperl-continued-statement-offset)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1727 (current-column)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1728 (if (eq char-after ?\{)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1729 cperl-continued-brace-offset 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1730 ;; This line starts a new statement.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1731 ;; Position following last unclosed open.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1732 (goto-char containing-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1733 ;; Is line first statement after an open-brace?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1734 (or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1735 ;; If no, find that first statement and indent like
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1736 ;; it. If the first statement begins with label, do
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1737 ;; not believe when the indentation of the label is too
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1738 ;; small.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1739 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1740 (forward-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1741 (setq old-indent (current-indentation))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1742 (let ((colon-line-end 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1743 (while (progn (skip-chars-forward " \t\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1744 (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1745 ;; Skip over comments and labels following openbrace.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1746 (cond ((= (following-char) ?\#)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1747 (forward-line 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1748 ;; label:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1749 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1750 (save-excursion (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1751 (setq colon-line-end (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1752 (search-forward ":"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1753 ;; The first following code counts
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1754 ;; if it is before the line we want to indent.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1755 (and (< (point) indent-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1756 (if (> colon-line-end (point)) ; After label
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1757 (if (> (current-indentation)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1758 cperl-min-label-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1759 (- (current-indentation) cperl-label-offset)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1760 ;; Do not believe: `max' is involved
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1761 (+ old-indent cperl-indent-level))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1762 (current-column)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1763 ;; If no previous statement,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1764 ;; indent it relative to line brace is on.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1765 ;; For open brace in column zero, don't let statement
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1766 ;; start there too. If cperl-indent-level is zero,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1767 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1768 ;; For open-braces not the first thing in a line,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1769 ;; add in cperl-brace-imaginary-offset.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1770
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1771 ;; If first thing on a line: ?????
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1772 (+ (if (and (bolp) (zerop cperl-indent-level))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1773 (+ cperl-brace-offset cperl-continued-statement-offset)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1774 cperl-indent-level)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1775 ;; Move back over whitespace before the openbrace.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1776 ;; If openbrace is not first nonwhite thing on the line,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1777 ;; add the cperl-brace-imaginary-offset.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1778 (progn (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1779 (if (bolp) 0 cperl-brace-imaginary-offset))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1780 ;; If the openbrace is preceded by a parenthesized exp,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1781 ;; move to the beginning of that;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1782 ;; possibly a different line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1783 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1784 (if (eq (preceding-char) ?\))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1785 (forward-sexp -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1786 ;; In the case it starts a subroutine, indent with
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1787 ;; respect to `sub', not with respect to the the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1788 ;; first thing on the line, say in the case of
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1789 ;; anonymous sub in a hash.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1790 ;;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1791 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1792 (if (and (eq (preceding-char) ?b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1793 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1794 (forward-sexp -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1795 (looking-at "sub\\>"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1796 (setq old-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1797 (nth 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1798 (parse-partial-sexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1799 (save-excursion (beginning-of-line) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1800 (point)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1801 (progn (goto-char (1+ old-indent))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1802 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1803 (current-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1804 ;; Get initial indentation of the line we are on.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1805 ;; If line starts with label, calculate label indentation
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1806 (if (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1807 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1808 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1809 (if (> (current-indentation) cperl-min-label-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1810 (- (current-indentation) cperl-label-offset)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1811 (cperl-calculate-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1812 (if (and parse-start (<= parse-start (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1813 parse-start)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1814 (current-indentation))))))))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1815
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1816 (defvar cperl-indent-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1817 '((string nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1818 (comment nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1819 (toplevel 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1820 (toplevel-after-parenth 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1821 (toplevel-continued 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1822 (expression 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1823 "Alist of indentation rules for CPerl mode.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1824 The values mean:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1825 nil: do not indent;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1826 number: add this amount of indentation.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1827
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1828 (defun cperl-where-am-i (&optional parse-start start-state)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1829 ;; Unfinished
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1830 "Return a list of lists ((TYPE POS)...) of good points before the point.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1831 POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1832 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1833 (let* ((start-point (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1834 (s-s (cperl-get-state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1835 (start (nth 0 s-s))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1836 (state (nth 1 s-s))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1837 (prestart (nth 3 s-s))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1838 (containing-sexp (car (cdr state)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1839 (case-fold-search nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1840 (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1841 (cond ((nth 3 state) ; In string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1842 (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1843 ((nth 4 state) ; In comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1844 (setq res (cons '(comment) res)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1845 ((null containing-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1846 ;; Line is at top level.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1847 ;; Indent like the previous top level line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1848 ;; unless that ends in a closeparen without semicolon,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1849 ;; in which case this line is the first argument decl.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1850 (cperl-backward-to-noncomment (or parse-start (point-min)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1851 ;;(skip-chars-backward " \t\f\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1852 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1853 ((or (bobp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1854 (memq (preceding-char) (append ";}" nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1855 (setq res (cons (list 'toplevel start) res)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1856 ((eq (preceding-char) ?\) )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1857 (setq res (cons (list 'toplevel-after-parenth start) res)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1858 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1859 (setq res (cons (list 'toplevel-continued start) res)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1860 ((/= (char-after containing-sexp) ?{)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1861 ;; line is expression, not statement:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1862 ;; indent to just after the surrounding open.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1863 ;; skip blanks if we do not close the expression.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1864 (setq res (cons (list 'expression-blanks
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1865 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1866 (goto-char (1+ containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1867 (or (looking-at "[ \t]*\\(#\\|$\\)")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1868 (skip-chars-forward " \t"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1869 (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1870 (cons (list 'expression containing-sexp) res))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1871 ((progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1872 ;; Containing-expr starts with \{. Check whether it is a hash.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1873 (goto-char containing-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1874 (not (cperl-block-p)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1875 (setq res (cons (list 'expression-blanks
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1876 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1877 (goto-char (1+ containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1878 (or (looking-at "[ \t]*\\(#\\|$\\)")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1879 (skip-chars-forward " \t"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1880 (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1881 (cons (list 'expression containing-sexp) res))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1882 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1883 ;; Statement level.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1884 (setq res (cons (list 'in-block containing-sexp) res))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1885 ;; Is it a continuation or a new statement?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1886 ;; Find previous non-comment character.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1887 (cperl-backward-to-noncomment containing-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1888 ;; Back up over label lines, since they don't
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1889 ;; affect whether our line is a continuation.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1890 ;; Back up comma-delimited lines too ?????
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1891 (while (or (eq (preceding-char) ?\,)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1892 (save-excursion (cperl-after-label)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1893 (if (eq (preceding-char) ?\,)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1894 ;; Will go to beginning of line, essentially
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1895 ;; Will ignore embedded sexpr XXXX.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1896 (cperl-backward-to-start-of-continued-exp containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1897 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1898 (cperl-backward-to-noncomment containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1899 ;; Now we get the answer.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1900 (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1901 ;; This line is continuation of preceding line's statement.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1902 (list (list 'statement-continued containing-sexp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1903 ;; This line starts a new statement.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1904 ;; Position following last unclosed open.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1905 (goto-char containing-sexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1906 ;; Is line first statement after an open-brace?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1907 (or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1908 ;; If no, find that first statement and indent like
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1909 ;; it. If the first statement begins with label, do
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1910 ;; not believe when the indentation of the label is too
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1911 ;; small.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1912 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1913 (forward-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1914 (let ((colon-line-end 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1915 (while (progn (skip-chars-forward " \t\n" start-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1916 (and (< (point) start-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1917 (looking-at
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1918 "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1919 ;; Skip over comments and labels following openbrace.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1920 (cond ((= (following-char) ?\#)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1921 ;;(forward-line 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1922 (end-of-line))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1923 ;; label:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1924 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1925 (save-excursion (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1926 (setq colon-line-end (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1927 (search-forward ":"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1928 ;; Now at the point, after label, or at start
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1929 ;; of first statement in the block.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1930 (and (< (point) start-point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1931 (if (> colon-line-end (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1932 ;; Before statement after label
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1933 (if (> (current-indentation)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1934 cperl-min-label-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1935 (list (list 'label-in-block (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1936 ;; Do not believe: `max' is involved
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1937 (list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1938 (list 'label-in-block-min-indent (point))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1939 ;; Before statement
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1940 (list 'statement-in-block (point))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1941 ;; If no previous statement,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1942 ;; indent it relative to line brace is on.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1943 ;; For open brace in column zero, don't let statement
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1944 ;; start there too. If cperl-indent-level is zero,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1945 ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1946 ;; For open-braces not the first thing in a line,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1947 ;; add in cperl-brace-imaginary-offset.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1948
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1949 ;; If first thing on a line: ?????
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1950 (+ (if (and (bolp) (zerop cperl-indent-level))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1951 (+ cperl-brace-offset cperl-continued-statement-offset)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1952 cperl-indent-level)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1953 ;; Move back over whitespace before the openbrace.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1954 ;; If openbrace is not first nonwhite thing on the line,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1955 ;; add the cperl-brace-imaginary-offset.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1956 (progn (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1957 (if (bolp) 0 cperl-brace-imaginary-offset))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1958 ;; If the openbrace is preceded by a parenthesized exp,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1959 ;; move to the beginning of that;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1960 ;; possibly a different line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1961 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1962 (if (eq (preceding-char) ?\))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1963 (forward-sexp -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1964 ;; Get initial indentation of the line we are on.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1965 ;; If line starts with label, calculate label indentation
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1966 (if (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1967 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1968 (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1969 (if (> (current-indentation) cperl-min-label-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1970 (- (current-indentation) cperl-label-offset)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1971 (cperl-calculate-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1972 (if (and parse-start (<= parse-start (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1973 parse-start)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1974 (current-indentation))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1975 res)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1976
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1977 (defun cperl-calculate-indent-within-comment ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1978 "Return the indentation amount for line, assuming that
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1979 the current line is to be regarded as part of a block comment."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1980 (let (end star-start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1981 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1982 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1983 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1984 (setq end (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1985 (and (= (following-char) ?#)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1986 (forward-line -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1987 (cperl-to-comment-or-eol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1988 (setq end (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1989 (goto-char end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1990 (current-column))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1991
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1992
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1993 (defun cperl-to-comment-or-eol ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1994 "Goes to position before comment on the current line, or to end of line.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1995 Returns true if comment is found."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1996 (let (state stop-in cpoint (lim (progn (end-of-line) (point))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1997 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1998 (if (or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1999 (eq (get-text-property (point) 'syntax-type) 'pod)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2000 (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2001 (if (eq (preceding-char) ?\#) (progn (backward-char 1) t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2002 ;; Else
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2003 (while (not stop-in)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2004 (setq state (parse-partial-sexp (point) lim nil nil nil t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2005 ; stop at comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2006 ;; If fails (beginning-of-line inside sexp), then contains not-comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2007 ;; Do simplified processing
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2008 ;;(if (re-search-forward "[^$]#" lim 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2009 ;; (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2010 ;; (forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2011 ;; (skip-chars-backward " \t\n\f" lim))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2012 ;; (goto-char lim)) ; No `#' at all
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2013 ;;)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2014 (if (nth 4 state) ; After `#';
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2015 ; (nth 2 state) can be
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2016 ; beginning of m,s,qq and so
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2017 ; on
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2018 (if (nth 2 state)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2019 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2020 (setq cpoint (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2021 (goto-char (nth 2 state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2022 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2023 ((looking-at "\\(s\\|tr\\)\\>")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2024 (or (re-search-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2025 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2026 lim 'move)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2027 (setq stop-in t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2028 ((looking-at "\\(m\\|q\\([qxw]\\)?\\)\\>")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2029 (or (re-search-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2030 "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2031 lim 'move)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2032 (setq stop-in t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2033 (t ; It was fair comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2034 (setq stop-in t) ; Finish
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2035 (goto-char (1- cpoint)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2036 (setq stop-in t) ; Finish
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2037 (forward-char -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2038 (setq stop-in t)) ; Finish
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2039 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2040 (nth 4 state))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2041
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2042 (defsubst cperl-1- (p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2043 (max (point-min) (1- p)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2044
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2045 (defsubst cperl-1+ (p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2046 (min (point-max) (1+ p)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2047
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2048 (defvar cperl-st-cfence '(14)) ; Comment-fence
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2049 (defvar cperl-st-sfence '(15)) ; String-fence
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2050 (defvar cperl-st-punct '(1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2051 (defvar cperl-st-word '(2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2052 (defvar cperl-st-bra '(4 . ?\>))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2053 (defvar cperl-st-ket '(5 . ?\<))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2054
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2055 (defsubst cperl-modify-syntax-type (at how)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2056 (if (< at (point-max))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2057 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2058 (put-text-property at (1+ at) 'syntax-table how)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2059 (put-text-property at (1+ at) 'rear-nonsticky t))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2060
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2061 (defun cperl-protect-defun-start (s e)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2062 ;; C code looks for "^\\s(" to skip comment backward in "hard" situations
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2063 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2064 (goto-char s)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2065 (while (re-search-forward "^\\s(" e 'to-end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2066 (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2067
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2068 (defun cperl-commentify (bb e string)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2069 (if cperl-use-syntax-table-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2070 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2071 ;; We suppose that e is _after_ the end of construction, as after eol.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2072 (setq string (if string cperl-st-sfence cperl-st-cfence))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2073 (cperl-modify-syntax-type bb string)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2074 (cperl-modify-syntax-type (1- e) string)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2075 (if (and (eq string cperl-st-sfence) (> (- e 2) bb))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2076 (put-text-property (1+ bb) (1- e)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2077 'syntax-table cperl-string-syntax-table))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2078 (cperl-protect-defun-start bb e))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2079
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2080 (defun cperl-forward-re (lim end is-2arg set-st st-l err-l argument
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2081 &optional ostart oend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2082 ;; Works *before* syntax recognition is done
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2083 ;; May modify syntax-type text property if the situation is too hard
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2084 (let (b starter ender st i i2 go-forward)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2085 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2086 ;; ender means matching-char matcher.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2087 (setq b (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2088 starter (char-after b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2089 ;; ender:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2090 ender (cdr (assoc starter '(( ?\( . ?\) )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2091 ( ?\[ . ?\] )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2092 ( ?\{ . ?\} )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2093 ( ?\< . ?\> )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2094 ))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2095 ;; What if starter == ?\\ ????
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2096 (if set-st
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2097 (if (car st-l)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2098 (setq st (car st-l))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2099 (setcar st-l (make-syntax-table))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2100 (setq i 0 st (car st-l))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2101 (while (< i 256)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2102 (modify-syntax-entry i "." st)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2103 (setq i (1+ i)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2104 (modify-syntax-entry ?\\ "\\" st)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2105 (setq set-st t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2106 ;; Whether we have an intermediate point
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2107 (setq i nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2108 ;; Prepare the syntax table:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2109 (and set-st
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2110 (if (not ender) ; m/blah/, s/x//, s/x/y/
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2111 (modify-syntax-entry starter "$" st)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2112 (modify-syntax-entry starter (concat "(" (list ender)) st)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2113 (modify-syntax-entry ender (concat ")" (list starter)) st)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2114 (condition-case bb
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2115 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2116 (if (and (eq starter (char-after (cperl-1+ b)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2117 (not ender))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2118 ;; $ has TeXish matching rules, so $$ equiv $...
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2119 (forward-char 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2120 (set-syntax-table st)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2121 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2122 (set-syntax-table cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2123 ;; Now the problem is with m;blah;;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2124 (and (not ender)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2125 (eq (preceding-char)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2126 (char-after (- (point) 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2127 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2128 (forward-char -2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2129 (= 0 (% (skip-chars-backward "\\\\") 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2130 (forward-char -1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2131 (and is-2arg ; Have trailing part
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2132 (not ender)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2133 (eq (following-char) starter) ; Empty trailing part
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2134 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2135 (or (eq (char-syntax (following-char)) ?.)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2136 ;; Make trailing letter into punctuation
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2137 (cperl-modify-syntax-type (point) cperl-st-punct))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2138 (setq is-2arg nil go-forward t))) ; Ignore the tail
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2139 (if is-2arg ; Not number => have second part
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2140 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2141 (setq i (point) i2 i)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2142 (if ender
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2143 (if (memq (following-char) '(?\ ?\t ?\n ?\f))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2144 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2145 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2146 (goto-char (match-end 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2147 (skip-chars-forward " \t\n\f"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2148 (setq i2 (point))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2149 (forward-char -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2150 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2151 (if ender (modify-syntax-entry ender "." st))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2152 (setq set-st nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2153 (setq
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2154 ender
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2155 (cperl-forward-re lim end nil t st-l err-l argument starter ender)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2156 ender (nth 2 ender)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2157 (error (goto-char lim)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2158 (setq set-st nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2159 (or end
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2160 (message
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2161 "End of `%s%s%c ... %c' string not found: %s"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2162 argument
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2163 (if ostart (format "%c ... %c" ostart (or oend ostart)) "")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2164 starter (or ender starter) bb)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2165 (or (car err-l) (setcar err-l b)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2166 (if set-st
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2167 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2168 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2169 (if ender (modify-syntax-entry ender "." st))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2170 (list i i2 ender starter go-forward)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2171
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2172 (defun cperl-find-pods-heres (&optional min max non-inter end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2173 "Scans the buffer for hard-to-parse Perl constructions.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2174 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2175 the sections using `cperl-pod-head-face', `cperl-pod-face',
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2176 `cperl-here-face'."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2177 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2178 (or min (setq min (point-min)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2179 (or max (setq max (point-max)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2180 (let (face head-face here-face b e bb tag qtag b1 e1 argument i c tail state
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2181 (cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2182 (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2183 (modified (buffer-modified-p))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2184 (after-change-functions nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2185 (state-point (point-min))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2186 (st-l '(nil)) (err-l '(nil)) i2
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2187 ;; Somehow font-lock may be not loaded yet...
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2188 (font-lock-string-face (if (boundp 'font-lock-string-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2189 font-lock-string-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2190 'font-lock-string-face))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2191 (search
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2192 (concat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2193 "\\(\\`\n?\\|\n\n\\)="
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2194 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2195 ;; One extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2196 "<<"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2197 "\\("
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2198 ;; First variant "BLAH" or just ``.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2199 "\\([\"'`]\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2200 "\\([^\"'`\n]*\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2201 "\\3"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2202 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2203 ;; Second variant: Identifier or empty
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2204 "\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2205 ;; Check that we do not have <<= or << 30 or << $blah.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2206 "\\([^= \t$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2207 "\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2208 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2209 ;; 1+6 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2210 "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2211 (if cperl-use-syntax-table-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2212 (concat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2213 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2214 ;; 1+6+2=9 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2215 "\\<\\(q[wxq]?\\|[msy]\\|tr\\)\\>"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2216 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2217 ;; 1+6+2+1=10 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2218 "\\([?/]\\)" ; /blah/ or ?blah?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2219 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2220 ;; 1+6+2+1+1=11 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2221 "\\<sub\\>[ \t]*\\([a-zA-Z_:'0-9]+[ \t]*\\)?\\(([^()]*)\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2222 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2223 ;; 1+6+2+1+1+2=13 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2224 "\\$\\(['{]\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2225 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2226 ;; 1+6+2+1+1+2+1=14 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2227 "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2228 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2229 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2230 "__\\(END\\|DATA\\)__" ; Commented - does not help with indent...
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2231 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2232 ""))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2233 (unwind-protect
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2234 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2235 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2236 (or non-inter
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2237 (message "Scanning for \"hard\" Perl constructions..."))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2238 (if cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2239 ;; We had evals here, do not know why...
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2240 (setq face cperl-pod-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2241 head-face cperl-pod-head-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2242 here-face cperl-here-face))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2243 (remove-text-properties min max
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2244 '(syntax-type t in-pod t syntax-table t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2245 ;; Need to remove face as well...
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2246 (goto-char min)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2247 (if (and (eq system-type 'emx)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2248 (looking-at "extproc[ \t]")) ; Analogue of #!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2249 (cperl-commentify min
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2250 (save-excursion (end-of-line) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2251 nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2252 (while (re-search-forward search max t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2253 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2254 ((match-beginning 1) ; POD section
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2255 ;; "\\(\\`\n?\\|\n\n\\)="
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2256 (if (looking-at "\n*cut\\>")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2257 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2258 (message "=cut is not preceded by a POD section")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2259 (or (car err-l) (setcar err-l (point))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2260 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2261
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2262 (setq b (point) bb b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2263 (or (re-search-forward "\n\n=cut\\>" max 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2264 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2265 (message "End of a POD section not marked by =cut")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2266 (or (car err-l) (setcar err-l b))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2267 (beginning-of-line 2) ; An empty line after =cut is not POD!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2268 (setq e (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2269 (put-text-property b e 'in-pod t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2270 (goto-char b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2271 (while (re-search-forward "\n\n[ \t]" e t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2272 ;; We start 'pod 1 char earlier to include the preceding line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2273 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2274 (put-text-property (cperl-1- b) (point) 'syntax-type 'pod)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2275 (cperl-put-do-not-fontify b (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2276 ;;(put-text-property (max (point-min) (1- b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2277 ;; (point) cperl-do-not-fontify t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2278 (if cperl-pod-here-fontify (put-text-property b (point) 'face face))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2279 (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2280 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2281 (setq b (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2282 (put-text-property (cperl-1- (point)) e 'syntax-type 'pod)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2283 (cperl-put-do-not-fontify (point) e)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2284 ;;(put-text-property (max (point-min) (1- (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2285 ;; e cperl-do-not-fontify t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2286 (if cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2287 (progn (put-text-property (point) e 'face face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2288 (goto-char bb)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2289 (if (looking-at
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2290 "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2291 (put-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2292 (match-beginning 1) (match-end 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2293 'face head-face))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2294 (while (re-search-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2295 ;; One paragraph
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2296 "\n\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2297 e 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2298 (put-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2299 (match-beginning 1) (match-end 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2300 'face head-face))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2301 (cperl-commentify bb e nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2302 (goto-char e)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2303 (or (eq e (point-max))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2304 (forward-char -1)))) ; Prepare for immediate pod start.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2305 ;; Here document
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2306 ;; We do only one here-per-line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2307 ;; 1 () ahead
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2308 ;; "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\3\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2309 ((match-beginning 2) ; 1 + 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2310 ;; Abort in comment:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2311 (setq b (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2312 (setq state (parse-partial-sexp state-point b nil nil state)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2313 state-point b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2314 (if ;;(save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2315 ;; (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2316 ;; (search-forward "#" b t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2317 (or (nth 3 state) (nth 4 state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2318 (goto-char (match-end 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2319 (if (match-beginning 5) ;4 + 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2320 (setq b1 (match-beginning 5) ; 4 + 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2321 e1 (match-end 5)) ; 4 + 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2322 (setq b1 (match-beginning 4) ; 3 + 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2323 e1 (match-end 4))) ; 3 + 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2324 (setq tag (buffer-substring b1 e1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2325 qtag (regexp-quote tag))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2326 (cond (cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2327 (put-text-property b1 e1 'face font-lock-reference-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2328 (cperl-put-do-not-fontify b1 e1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2329 (forward-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2330 (setq b (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2331 (cond ((re-search-forward (concat "^" qtag "$") max 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2332 (if cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2333 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2334 (put-text-property (match-beginning 0) (match-end 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2335 'face font-lock-reference-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2336 (cperl-put-do-not-fontify b (match-end 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2337 ;;(put-text-property (max (point-min) (1- b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2338 ;; (min (point-max)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2339 ;; (1+ (match-end 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2340 ;; cperl-do-not-fontify t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2341 (put-text-property b (match-beginning 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2342 'face here-face)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2343 (setq e1 (cperl-1+ (match-end 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2344 (put-text-property b (match-beginning 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2345 'syntax-type 'here-doc)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2346 (put-text-property (match-beginning 0) e1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2347 'syntax-type 'here-doc-delim)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2348 (put-text-property b e1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2349 'here-doc-group t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2350 (cperl-commentify b e1 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2351 (cperl-put-do-not-fontify b (match-end 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2352 (t (message "End of here-document `%s' not found." tag)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2353 (or (car err-l) (setcar err-l b))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2354 ;; format
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2355 ((match-beginning 8)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2356 ;; 1+6=7 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2357 ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2358 (setq b (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2359 name (if (match-beginning 8) ; 7 + 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2360 (buffer-substring (match-beginning 8) ; 7 + 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2361 (match-end 8)) ; 7 + 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2362 ""))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2363 (setq argument nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2364 (if cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2365 (while (and (eq (forward-line) 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2366 (not (looking-at "^[.;]$")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2367 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2368 ((looking-at "^#")) ; Skip comments
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2369 ((and argument ; Skip argument multi-lines
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2370 (looking-at "^[ \t]*{"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2371 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2372 (setq argument nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2373 (argument ; Skip argument lines
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2374 (setq argument nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2375 (t ; Format line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2376 (setq b1 (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2377 (setq argument (looking-at "^[^\n]*[@^]"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2378 (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2379 (put-text-property b1 (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2380 'face font-lock-string-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2381 (cperl-commentify b1 (point) nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2382 (cperl-put-do-not-fontify b1 (point)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2383 (re-search-forward (concat "^[.;]$") max 'toend))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2384 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2385 (if (looking-at "^[.;]$")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2386 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2387 (put-text-property (point) (+ (point) 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2388 'face font-lock-string-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2389 (cperl-commentify (point) (+ (point) 2) nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2390 (cperl-put-do-not-fontify (point) (+ (point) 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2391 (message "End of format `%s' not found." name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2392 (or (car err-l) (setcar err-l b)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2393 (forward-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2394 (put-text-property b (point) 'syntax-type 'format)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2395 ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2396 ;;; (if cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2397 ;;; (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2398 ;;; (put-text-property b (match-end 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2399 ;;; 'face font-lock-string-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2400 ;;; (cperl-put-do-not-fontify b (match-end 0))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2401 ;;; (put-text-property b (match-end 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2402 ;;; 'syntax-type 'format)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2403 ;;; (cperl-put-do-not-fontify b (match-beginning 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2404 ;;; (t (message "End of format `%s' not found." name)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2405 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2406 ;; Regexp:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2407 ((or (match-beginning 10) (match-beginning 11))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2408 ;; 1+6+2=9 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2409 ;; "\\<\\(q[wxq]?\\|[msy]\\|tr\\)\\>"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2410 ;; "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2411 ;; "\\([?/]\\)" ; /blah/ or ?blah?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2412 (setq b1 (if (match-beginning 10) 10 11)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2413 argument (buffer-substring
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2414 (match-beginning b1) (match-end b1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2415 b (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2416 i b
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2417 c (char-after (match-beginning b1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2418 bb (char-after (1- (match-beginning b1))) ; tmp holder
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2419 bb (and ; user variables/whatever
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2420 (match-beginning 10)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2421 (or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2422 (memq bb '(?\$ ?\@ ?\% ?\* ?\#)) ; $#y
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2423 (and (eq bb ?-) (eq c ?s)) ; -s file test
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2424 (and (eq bb ?\&) ; &&m/blah/
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2425 (not (eq (char-after
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2426 (- (match-beginning b1) 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2427 ?\&))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2428 (or bb
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2429 (if (eq b1 11) ; bare /blah/ or ?blah?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2430 (setq argument ""
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2431 bb ; Not a regexp?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2432 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2433 (goto-char (match-beginning b1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2434 (cperl-backward-to-noncomment (point-min))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2435 (not
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2436 ;; What is below: regexp-p?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2437 (and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2438 (or (memq (preceding-char)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2439 (append (if (eq c ?\?)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2440 ;; $a++ ? 1 : 2
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2441 "~{(=|&*!,;"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2442 "~{(=|&+-*!,;") nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2443 (and (eq (preceding-char) ?\})
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2444 (cperl-after-block-p (point-min)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2445 (and (eq (char-syntax (preceding-char)) ?w)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2446 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2447 (forward-sexp -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2448 (looking-at
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2449 "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2450 (and (eq (preceding-char) ?.)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2451 (eq (char-after (- (point) 2)) ?.))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2452 (bobp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2453 ;; m|blah| ? foo : bar;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2454 (not
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2455 (and (eq c ?\?)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2456 cperl-use-syntax-table-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2457 (not (bobp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2458 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2459 (forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2460 (looking-at "\\s|")))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2461 b (1- b))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2462 (or bb (setq state (parse-partial-sexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2463 state-point b nil nil state)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2464 state-point b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2465 (goto-char b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2466 (if (or bb (nth 3 state) (nth 4 state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2467 (goto-char i)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2468 (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2469 (goto-char (match-end 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2470 (skip-chars-forward " \t\n\f"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2471 ;; qtag means two-arg matcher, may be reset to
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2472 ;; 2 or 3 later if some special quoting is needed.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2473 ;; e1 means matching-char matcher.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2474 (setq b (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2475 i (cperl-forward-re max end
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2476 (string-match "^\\([sy]\\|tr\\)$" argument)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2477 t st-l err-l argument)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2478 i2 (nth 1 i) ; start of the second part
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2479 e1 (nth 2 i) ; ender, true if matching second part
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2480 go (nth 4 i) ; There is a 1-char part after the end
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2481 i (car i) ; intermediate point
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2482 tail (if (and i (not e1)) (1- (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2483 e nil) ; need to preserve backslashitis
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2484 ;; Commenting \\ is dangerous, what about ( ?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2485 (and i tail
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2486 (eq (char-after i) ?\\)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2487 (setq e t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2488 (if (null i)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2489 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2490 (cperl-commentify b (point) t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2491 (if go (forward-char 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2492 (cperl-commentify b i t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2493 (if (looking-at "\\sw*e") ; s///e
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2494 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2495 (and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2496 ;; silent:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2497 (cperl-find-pods-heres i2 (1- (point)) t end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2498 ;; Error
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2499 (goto-char (1+ max)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2500 (if (and e1 (eq (preceding-char) ?\>))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2501 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2502 (cperl-modify-syntax-type (1- (point)) cperl-st-ket)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2503 (cperl-modify-syntax-type i cperl-st-bra))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2504 (cperl-commentify i2 (point) t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2505 (if e
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2506 (cperl-modify-syntax-type (1+ i) cperl-st-punct))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2507 (setq tail nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2508 (if (eq (char-syntax (following-char)) ?w)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2509 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2510 (forward-word 1) ; skip modifiers s///s
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2511 (if tail (cperl-commentify tail (point) t))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2512 ((match-beginning 13) ; sub with prototypes
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2513 (setq b (match-beginning 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2514 (if (memq (char-after (1- b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2515 '(?\$ ?\@ ?\% ?\& ?\*))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2516 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2517 (setq state (parse-partial-sexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2518 state-point (1- b) nil nil state)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2519 state-point (1- b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2520 (if (or (nth 3 state) (nth 4 state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2521 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2522 ;; Mark as string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2523 (cperl-commentify (match-beginning 13) (match-end 13) t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2524 (goto-char (match-end 0))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2525 ;; 1+6+2+1+1+2=13 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2526 ;; "\\$\\(['{]\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2527 ((and (match-beginning 14)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2528 (eq (preceding-char) ?\')) ; $'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2529 (setq b (1- (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2530 state (parse-partial-sexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2531 state-point (1- b) nil nil state)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2532 state-point (1- b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2533 (if (nth 3 state) ; in string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2534 (cperl-modify-syntax-type (1- b) cperl-st-punct))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2535 (goto-char (1+ b)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2536 ;; 1+6+2+1+1+2=13 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2537 ;; "\\$\\(['{]\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2538 ((match-beginning 14) ; ${
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2539 (setq bb (match-beginning 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2540 (cperl-modify-syntax-type bb cperl-st-punct))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2541 ;; 1+6+2+1+1+2+1=14 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2542 ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2543 ((match-beginning 15) ; old $abc'efg syntax
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2544 (setq bb (match-end 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2545 b (match-beginning 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2546 state (parse-partial-sexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2547 state-point b nil nil state)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2548 state-point b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2549 (if (nth 3 state) ; in string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2550 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2551 (put-text-property (1- bb) bb 'syntax-table cperl-st-word))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2552 (goto-char bb))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2553 ;; 1+6+2+1+1+2+1+1=15 extra () before this:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2554 ;; "__\\(END\\|DATA\\)__"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2555 (t ; __END__, __DATA__
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2556 (setq bb (match-end 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2557 b (match-beginning 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2558 state (parse-partial-sexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2559 state-point b nil nil state)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2560 state-point b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2561 (if (or (nth 3 state) (nth 4 state))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2562 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2563 ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2564 (cperl-commentify b bb nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2565 (setq end t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2566 (goto-char bb)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2567 (if (> (point) max)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2568 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2569 (if end
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2570 (message "Garbage after __END__/__DATA__ ignored")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2571 (message "Unbalanced syntax found while scanning")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2572 (or (car err-l) (setcar err-l b)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2573 (goto-char max))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2574 ;;; (while (re-search-forward "\\(\\`\n?\\|\n\n\\)=" max t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2575 ;;; (if (looking-at "\n*cut\\>")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2576 ;;; (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2577 ;;; (message "=cut is not preceded by a pod section")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2578 ;;; (setq err (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2579 ;;; (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2580
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2581 ;;; (setq b (point) bb b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2582 ;;; (or (re-search-forward "\n\n=cut\\>" max 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2583 ;;; (message "Cannot find the end of a pod section"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2584 ;;; (beginning-of-line 3)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2585 ;;; (setq e (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2586 ;;; (put-text-property b e 'in-pod t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2587 ;;; (goto-char b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2588 ;;; (while (re-search-forward "\n\n[ \t]" e t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2589 ;;; (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2590 ;;; (put-text-property b (point) 'syntax-type 'pod)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2591 ;;; (cperl-put-do-not-fontify b (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2592 ;;; ;;(put-text-property (max (point-min) (1- b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2593 ;;; ;; (point) cperl-do-not-fontify t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2594 ;;; (if cperl-pod-here-fontify (put-text-property b (point) 'face face))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2595 ;;; (re-search-forward "\n\n[^ \t\f\n]" e 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2596 ;;; (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2597 ;;; (setq b (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2598 ;;; (put-text-property (point) e 'syntax-type 'pod)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2599 ;;; (cperl-put-do-not-fontify (point) e)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2600 ;;; ;;(put-text-property (max (point-min) (1- (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2601 ;;; ;; e cperl-do-not-fontify t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2602 ;;; (if cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2603 ;;; (progn (put-text-property (point) e 'face face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2604 ;;; (goto-char bb)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2605 ;;; (if (looking-at
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2606 ;;; "=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2607 ;;; (put-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2608 ;;; (match-beginning 1) (match-end 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2609 ;;; 'face head-face))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2610 ;;; (while (re-search-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2611 ;;; ;; One paragraph
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2612 ;;; "\n\n=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2613 ;;; e 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2614 ;;; (put-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2615 ;;; (match-beginning 1) (match-end 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2616 ;;; 'face head-face))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2617 ;;; (goto-char e)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2618 ;;; (goto-char min)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2619 ;;; (while (re-search-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2620 ;;; ;; We exclude \n to avoid misrecognition inside quotes.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2621 ;;; "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\2\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2622 ;;; max t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2623 ;;; (if (match-beginning 4)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2624 ;;; (setq b1 (match-beginning 4)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2625 ;;; e1 (match-end 4))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2626 ;;; (setq b1 (match-beginning 3)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2627 ;;; e1 (match-end 3)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2628 ;;; (setq tag (buffer-substring b1 e1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2629 ;;; qtag (regexp-quote tag))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2630 ;;; (cond (cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2631 ;;; (put-text-property b1 e1 'face font-lock-reference-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2632 ;;; (cperl-put-do-not-fontify b1 e1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2633 ;;; (forward-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2634 ;;; (setq b (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2635 ;;; (cond ((re-search-forward (concat "^" qtag "$") max 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2636 ;;; (if cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2637 ;;; (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2638 ;;; (put-text-property (match-beginning 0) (match-end 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2639 ;;; 'face font-lock-reference-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2640 ;;; (cperl-put-do-not-fontify b (match-end 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2641 ;;; ;;(put-text-property (max (point-min) (1- b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2642 ;;; ;; (min (point-max)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2643 ;;; ;; (1+ (match-end 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2644 ;;; ;; cperl-do-not-fontify t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2645 ;;; (put-text-property b (match-beginning 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2646 ;;; 'face here-face)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2647 ;;; (put-text-property b (match-beginning 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2648 ;;; 'syntax-type 'here-doc)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2649 ;;; (cperl-put-do-not-fontify b (match-beginning 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2650 ;;; (t (message "End of here-document `%s' not found." tag))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2651 ;;; (goto-char min)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2652 ;;; (while (re-search-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2653 ;;; "^[ \t]*format[ \t]*\\(\\([a-zA-Z0-9_]+[ \t]*\\)?\\)=[ \t]*$"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2654 ;;; max t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2655 ;;; (setq b (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2656 ;;; name (buffer-substring (match-beginning 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2657 ;;; (match-end 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2658 ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2659 ;;; (if cperl-pod-here-fontify
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2660 ;;; (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2661 ;;; (put-text-property b (match-end 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2662 ;;; 'face font-lock-string-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2663 ;;; (cperl-put-do-not-fontify b (match-end 0))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2664 ;;; (put-text-property b (match-end 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2665 ;;; 'syntax-type 'format)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2666 ;;; (cperl-put-do-not-fontify b (match-beginning 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2667 ;;; (t (message "End of format `%s' not found." name))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2668 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2669 (if (car err-l) (goto-char (car err-l))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2670 (or noninteractive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2671 (message "Scan for \"hard\" Perl constructions completed."))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2672 (and (buffer-modified-p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2673 (not modified)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2674 (set-buffer-modified-p nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2675 (set-syntax-table cperl-mode-syntax-table))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2676 (car err-l)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2677
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2678 (defun cperl-backward-to-noncomment (lim)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2679 ;; Stops at lim or after non-whitespace that is not in comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2680 (let (stop p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2681 (while (and (not stop) (> (point) (or lim 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2682 (skip-chars-backward " \t\n\f" lim)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2683 (setq p (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2684 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2685 (if (or (looking-at "^[ \t]*\\(#\\|$\\)")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2686 (progn (cperl-to-comment-or-eol) (bolp)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2687 nil ; Only comment, skip
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2688 ;; Else
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2689 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2690 (if (< p (point)) (goto-char p))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2691 (setq stop t)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2692
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2693 (defun cperl-after-block-p (lim)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2694 ;; We suppose that the preceding char is }.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2695 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2696 (condition-case nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2697 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2698 (forward-sexp -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2699 (cperl-backward-to-noncomment lim)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2700 (or (eq (preceding-char) ?\) ) ; if () {}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2701 (and (eq (char-syntax (preceding-char)) ?w) ; else {}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2702 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2703 (forward-sexp -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2704 (looking-at "\\(else\\|grep\\|map\\)\\>")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2705 (cperl-after-expr-p lim)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2706 (error nil))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2707
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2708 (defun cperl-after-expr-p (&optional lim chars test)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2709 "Returns true if the position is good for start of expression.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2710 TEST is the expression to evaluate at the found position. If absent,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2711 CHARS is a string that contains good characters to have before us (however,
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2712 `}' is treated \"smartly\" if it is not in the list)."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2713 (let (stop p
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2714 (lim (or lim (point-min))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2715 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2716 (while (and (not stop) (> (point) lim))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2717 (skip-chars-backward " \t\n\f" lim)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2718 (setq p (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2719 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2720 (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2721 ;; Else: last iteration (What to do with labels?)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2722 (cperl-to-comment-or-eol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2723 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2724 (if (< p (point)) (goto-char p))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2725 (setq stop t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2726 (or (bobp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2727 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2728 (if test (eval test)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2729 (or (memq (preceding-char) (append (or chars "{;") nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2730 (and (eq (preceding-char) ?\})
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2731 (cperl-after-block-p lim)))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2732
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2733 (defun cperl-backward-to-start-of-continued-exp (lim)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2734 (if (memq (preceding-char) (append ")]}\"'`" nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2735 (forward-sexp -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2736 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2737 (if (<= (point) lim)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2738 (goto-char (1+ lim)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2739 (skip-chars-forward " \t"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2740
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2741
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2742 (defvar innerloop-done nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2743 (defvar last-depth nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2744
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2745 (defun cperl-indent-exp ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2746 "Simple variant of indentation of continued-sexp.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2747 Should be slow. Will not indent comment if it starts at `comment-indent'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2748 or looks like continuation of the comment on the previous line."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2749 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2750 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2751 (let ((tmp-end (progn (end-of-line) (point))) top done)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2752 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2753 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2754 (while (null done)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2755 (setq top (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2756 (while (= (nth 0 (parse-partial-sexp (point) tmp-end
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2757 -1)) -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2758 (setq top (point))) ; Get the outermost parenths in line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2759 (goto-char top)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2760 (while (< (point) tmp-end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2761 (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2762 (or (eolp) (forward-sexp 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2763 (if (> (point) tmp-end) (progn (end-of-line) (setq tmp-end (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2764 (setq done t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2765 (goto-char tmp-end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2766 (setq tmp-end (point-marker)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2767 (cperl-indent-region (point) tmp-end))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2768
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2769 (defun cperl-indent-region (start end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2770 "Simple variant of indentation of region in CPerl mode.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2771 Should be slow. Will not indent comment if it starts at `comment-indent'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2772 or looks like continuation of the comment on the previous line.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2773 Indents all the lines whose first character is between START and END
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2774 inclusive."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2775 (interactive "r")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2776 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2777 (let (st comm indent-info old-comm-indent new-comm-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2778 (pm 0) (imenu-scanning-message "Indenting... (%3d%%)"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2779 (goto-char start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2780 (setq old-comm-indent (and (cperl-to-comment-or-eol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2781 (current-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2782 new-comm-indent old-comm-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2783 (goto-char start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2784 (or (bolp) (beginning-of-line 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2785 (or (fboundp 'imenu-progress-message)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2786 (message "Indenting... For feedback load `imenu'..."))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2787 (while (and (<= (point) end) (not (eobp))) ; bol to check start
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2788 (and (fboundp 'imenu-progress-message)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2789 (imenu-progress-message
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2790 pm (/ (* 100 (- (point) start)) (- end start -1))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2791 (setq st (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2792 indent-info nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2793 ) ; Believe indentation of the current
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2794 (if (and (setq comm (looking-at "[ \t]*#"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2795 (or (eq (current-indentation) (or old-comm-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2796 comment-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2797 (setq old-comm-indent nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2798 (if (and old-comm-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2799 (= (current-indentation) old-comm-indent)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2800 (not (eq (get-text-property (point) 'syntax-type) 'pod)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2801 (let ((comment-column new-comm-indent))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2802 (indent-for-comment)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2803 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2804 (cperl-indent-line 'indent-info)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2805 (or comm
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2806 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2807 (if (setq old-comm-indent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2808 (and (cperl-to-comment-or-eol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2809 (not (memq (get-text-property (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2810 'syntax-type)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2811 '(pod here-doc)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2812 (current-column)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2813 (progn (indent-for-comment)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2814 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2815 (skip-chars-backward "#")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2816 (setq new-comm-indent (current-column))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2817 (beginning-of-line 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2818 (if (fboundp 'imenu-progress-message)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2819 (imenu-progress-message pm 100)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2820 (message nil)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2821
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2822 ;;(defun cperl-slash-is-regexp (&optional pos)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2823 ;; (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2824 ;; (goto-char (if pos pos (1- (point))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2825 ;; (and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2826 ;; (not (memq (get-text-property (point) 'face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2827 ;; '(font-lock-string-face font-lock-comment-face)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2828 ;; (cperl-after-expr-p nil nil '
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2829 ;; (or (looking-at "[^]a-zA-Z0-9_)}]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2830 ;; (eq (get-text-property (point) 'face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2831 ;; 'font-lock-keyword-face))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2832
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2833 ;; Stolen from lisp-mode with a lot of improvements
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2834
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2835 (defun cperl-fill-paragraph (&optional justify iteration)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2836 "Like \\[fill-paragraph], but handle CPerl comments.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2837 If any of the current line is a comment, fill the comment or the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2838 block of it that point is in, preserving the comment's initial
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2839 indentation and initial hashes. Behaves usually outside of comment."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2840 (interactive "P")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2841 (let (
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2842 ;; Non-nil if the current line contains a comment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2843 has-comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2844
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2845 ;; If has-comment, the appropriate fill-prefix for the comment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2846 comment-fill-prefix
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2847 ;; Line that contains code and comment (or nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2848 start
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2849 c spaces len dc (comment-column comment-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2850 ;; Figure out what kind of comment we are looking at.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2851 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2852 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2853 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2854
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2855 ;; A line with nothing but a comment on it?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2856 ((looking-at "[ \t]*#[# \t]*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2857 (setq has-comment t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2858 comment-fill-prefix (buffer-substring (match-beginning 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2859 (match-end 0))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2860
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2861 ;; A line with some code, followed by a comment? Remember that the
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2862 ;; semi which starts the comment shouldn't be part of a string or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2863 ;; character.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2864 ((cperl-to-comment-or-eol)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2865 (setq has-comment t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2866 (looking-at "#+[ \t]*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2867 (setq start (point) c (current-column)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2868 comment-fill-prefix
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2869 (concat (make-string (current-column) ?\ )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2870 (buffer-substring (match-beginning 0) (match-end 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2871 spaces (progn (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2872 (buffer-substring (point) start))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2873 dc (- c (current-column)) len (- start (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2874 start (point-marker))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2875 (delete-char len)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2876 (insert (make-string dc ?-)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2877 (if (not has-comment)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2878 (fill-paragraph justify) ; Do the usual thing outside of comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2879 ;; Narrow to include only the comment, and then fill the region.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2880 (save-restriction
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2881 (narrow-to-region
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2882 ;; Find the first line we should include in the region to fill.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2883 (if start (progn (beginning-of-line) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2884 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2885 (while (and (zerop (forward-line -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2886 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2887 ;; We may have gone to far. Go forward again.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2888 (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2889 (forward-line 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2890 (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2891 ;; Find the beginning of the first line past the region to fill.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2892 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2893 (while (progn (forward-line 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2894 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2895 (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2896 ;; Remove existing hashes
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2897 (goto-char (point-min))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2898 (while (progn (forward-line 1) (< (point) (point-max)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2899 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2900 (and (looking-at "#+")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2901 (delete-char (- (match-end 0) (match-beginning 0)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2902
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2903 ;; Lines with only hashes on them can be paragraph boundaries.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2904 (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2905 (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2906 (fill-prefix comment-fill-prefix))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2907 (fill-paragraph justify)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2908 (if (and start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2909 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2910 (goto-char start)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2911 (if (> dc 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2912 (progn (delete-char dc) (insert spaces)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2913 (if (or (= (current-column) c) iteration) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2914 (setq comment-column c)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2915 (indent-for-comment)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2916 ;; Repeat once more, flagging as iteration
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2917 (cperl-fill-paragraph justify t)))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2918
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2919 (defun cperl-do-auto-fill ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2920 ;; Break out if the line is short enough
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2921 (if (> (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2922 (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2923 (current-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2924 fill-column)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2925 (let ((c (save-excursion (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2926 (cperl-to-comment-or-eol) (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2927 (s (memq (following-char) '(?\ ?\t))) marker)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2928 (if (>= c (point)) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2929 (setq marker (point-marker))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2930 (cperl-fill-paragraph)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2931 (goto-char marker)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2932 ;; Is not enough, sometimes marker is a start of line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2933 (if (bolp) (progn (re-search-forward "#+[ \t]*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2934 (goto-char (match-end 0))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2935 ;; Following space could have gone:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2936 (if (or (not s) (memq (following-char) '(?\ ?\t))) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2937 (insert " ")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2938 (backward-char 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2939 ;; Previous space could have gone:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2940 (or (memq (preceding-char) '(?\ ?\t)) (insert " "))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2941
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2942 (defvar imenu-example--function-name-regexp-perl
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2943 (concat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2944 "^\\("
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2945 "[ \t]*\\(sub\\|package\\)[ \t\n]+\\([a-zA-Z_0-9:']+\\)[ \t]*\\(([^()]*)[ \t]*\\)?"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2946 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2947 "=head\\([12]\\)[ \t]+\\([^\n]+\\)$"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2948 "\\)"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2949
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2950 (defun cperl-imenu-addback (lst &optional isback name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2951 ;; We suppose that the lst is a DAG, unless the first element only
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2952 ;; loops back, and ISBACK is set. Thus this function cannot be
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2953 ;; applied twice without ISBACK set.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2954 (cond ((not cperl-imenu-addback) lst)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2955 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2956 (or name
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2957 (setq name "+++BACK+++"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2958 (mapcar (function (lambda (elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2959 (if (and (listp elt) (listp (cdr elt)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2960 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2961 ;; In the other order it goes up
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2962 ;; one level only ;-(
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2963 (setcdr elt (cons (cons name lst)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2964 (cdr elt)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2965 (cperl-imenu-addback (cdr elt) t name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2966 ))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2967 (if isback (cdr lst) lst))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2968 lst)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2969
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2970 (defun imenu-example--create-perl-index (&optional regexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2971 (require 'cl)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2972 (require 'imenu) ; May be called from TAGS creator
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2973 (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '())
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2974 (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2975 (index-meth-alist '()) meth
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2976 packages ends-ranges p
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2977 (prev-pos 0) char fchar index index1 name (end-range 0) package)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2978 (goto-char (point-min))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2979 (if noninteractive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2980 (message "Scanning Perl for index")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2981 (imenu-progress-message prev-pos 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2982 ;; Search for the function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2983 (progn ;;save-match-data
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2984 (while (re-search-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2985 (or regexp imenu-example--function-name-regexp-perl)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2986 nil t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2987 (or noninteractive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2988 (imenu-progress-message prev-pos))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2989 ;;(backward-up-list 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2990 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2991 ((and ; Skip some noise if building tags
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2992 (match-beginning 2) ; package or sub
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2993 (eq (char-after (match-beginning 2)) ?p) ; package
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2994 (not (save-match-data
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2995 (looking-at "[ \t\n]*;")))) ; Plain text word 'package'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2996 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2997 ((and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2998 (match-beginning 2) ; package or sub
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2999 ;; Skip if quoted (will not skip multi-line ''-comments :-():
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3000 (null (get-text-property (match-beginning 1) 'syntax-table))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3001 (null (get-text-property (match-beginning 1) 'syntax-type))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3002 (null (get-text-property (match-beginning 1) 'in-pod)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3003 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3004 (goto-char (match-beginning 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3005 (setq fchar (following-char))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3006 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3007 ;; (if (looking-at "([^()]*)[ \t\n\f]*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3008 ;; (goto-char (match-end 0))) ; Messes what follows
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3009 (setq char (following-char)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3010 meth nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3011 p (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3012 (while (and ends-ranges (>= p (car ends-ranges)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3013 ;; delete obsolete entries
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3014 (setq ends-ranges (cdr ends-ranges) packages (cdr packages)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3015 (setq package (or (car packages) "")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3016 end-range (or (car ends-ranges) 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3017 (if (eq fchar ?p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3018 (setq name (buffer-substring (match-beginning 3) (match-end 3))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3019 name (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3020 (set-text-properties 0 (length name) nil name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3021 name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3022 package (concat name "::")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3023 name (concat "package " name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3024 end-range
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3025 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3026 (parse-partial-sexp (point) (point-max) -1) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3027 ends-ranges (cons end-range ends-ranges)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3028 packages (cons package packages)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3029 ;; )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3030 ;; Skip this function name if it is a prototype declaration.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3031 (if (and (eq fchar ?s) (eq char ?\;)) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3032 (setq index (imenu-example--name-and-position))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3033 (if (eq fchar ?p) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3034 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3035 (set-text-properties 0 (length name) nil name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3036 (cond ((string-match "[:']" name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3037 (setq meth t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3038 ((> p end-range) nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3039 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3040 (setq name (concat package name) meth t))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3041 (setcar index name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3042 (if (eq fchar ?p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3043 (push index index-pack-alist)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3044 (push index index-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3045 (if meth (push index index-meth-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3046 (push index index-unsorted-alist)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3047 ((match-beginning 5) ; Pod section
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3048 ;; (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3049 (setq index (imenu-example--name-and-position)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3050 name (buffer-substring (match-beginning 6) (match-end 6)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3051 (set-text-properties 0 (length name) nil name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3052 (if (eq (char-after (match-beginning 5)) ?2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3053 (setq name (concat " " name)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3054 (setcar index name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3055 (setq index1 (cons (concat "=" name) (cdr index)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3056 (push index index-pod-alist)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3057 (push index1 index-unsorted-alist)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3058 (or noninteractive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3059 (imenu-progress-message prev-pos 100))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3060 (setq index-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3061 (if (default-value 'imenu-sort-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3062 (sort index-alist (default-value 'imenu-sort-function))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3063 (nreverse index-alist)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3064 (and index-pod-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3065 (push (cons "+POD headers+..."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3066 (nreverse index-pod-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3067 index-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3068 (and (or index-pack-alist index-meth-alist)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3069 (let ((lst index-pack-alist) hier-list pack elt group name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3070 ;; Remove "package ", reverse and uniquify.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3071 (while lst
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3072 (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3073 (if (assoc name hier-list) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3074 (setq hier-list (cons (cons name (cdr elt)) hier-list))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3075 (setq lst index-meth-alist)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3076 (while lst
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3077 (setq elt (car lst) lst (cdr lst))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3078 (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3079 (setq pack (substring (car elt) 0 (match-beginning 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3080 (if (setq group (assoc pack hier-list))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3081 (if (listp (cdr group))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3082 ;; Have some functions already
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3083 (setcdr group
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3084 (cons (cons (substring
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3085 (car elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3086 (+ 2 (match-beginning 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3087 (cdr elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3088 (cdr group)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3089 (setcdr group (list (cons (substring
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3090 (car elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3091 (+ 2 (match-beginning 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3092 (cdr elt)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3093 (setq hier-list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3094 (cons (cons pack
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3095 (list (cons (substring
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3096 (car elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3097 (+ 2 (match-beginning 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3098 (cdr elt))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3099 hier-list))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3100 (push (cons "+Hierarchy+..."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3101 hier-list)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3102 index-alist)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3103 (and index-pack-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3104 (push (cons "+Packages+..."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3105 (nreverse index-pack-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3106 index-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3107 (and (or index-pack-alist index-pod-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3108 (default-value 'imenu-sort-function))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3109 index-unsorted-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3110 (push (cons "+Unsorted List+..."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3111 (nreverse index-unsorted-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3112 index-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3113 (cperl-imenu-addback index-alist)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3114
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3115 (defvar cperl-compilation-error-regexp-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3116 ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3117 '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3118 2 3))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3119 "Alist that specifies how to match errors in perl output.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3120
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3121 (if (fboundp 'eval-after-load)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3122 (eval-after-load
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3123 "mode-compile"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3124 '(setq perl-compilation-error-regexp-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3125 cperl-compilation-error-regexp-alist)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3126
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3127
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3128 (defvar cperl-faces-init nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3129
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3130 (defun cperl-windowed-init ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3131 "Initialization under windowed version."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3132 (add-hook 'font-lock-mode-hook
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3133 (function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3134 (lambda ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3135 (if (or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3136 (eq major-mode 'perl-mode)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3137 (eq major-mode 'cperl-mode))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3138 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3139 (or cperl-faces-init (cperl-init-faces))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3140
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3141 (defvar perl-font-lock-keywords-1 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3142 "Additional expressions to highlight in Perl mode. Minimal set.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3143 (defvar perl-font-lock-keywords nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3144 "Additional expressions to highlight in Perl mode. Default set.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3145 (defvar perl-font-lock-keywords-2 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3146 "Additional expressions to highlight in Perl mode. Maximal set")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3147
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3148 (defun cperl-init-faces ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3149 (condition-case nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3150 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3151 (require 'font-lock)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3152 (and (fboundp 'font-lock-fontify-anchored-keywords)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3153 (featurep 'font-lock-extra)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3154 (message "You have an obsolete package `font-lock-extra'. Install `choose-color'."))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3155 (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3156 ;;(defvar cperl-font-lock-enhanced nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3157 ;; "Set to be non-nil if font-lock allows active highlights.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3158 (if (fboundp 'font-lock-fontify-anchored-keywords)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3159 (setq font-lock-anchored t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3160 (setq
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3161 t-font-lock-keywords
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3162 (list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3163 (cons
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3164 (concat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3165 "\\(^\\|[^$@%&\\]\\)\\<\\("
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3166 (mapconcat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3167 'identity
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3168 '("if" "until" "while" "elsif" "else" "unless" "for"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3169 "foreach" "continue" "exit" "die" "last" "goto" "next"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3170 "redo" "return" "local" "exec" "sub" "do" "dump" "use"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3171 "require" "package" "eval" "my" "BEGIN" "END")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3172 "\\|") ; Flow control
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3173 "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3174 ; In what follows we use `type' style
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3175 ; for overwritable builtins
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3176 (list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3177 (concat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3178 "\\(^\\|[^$@%&\\]\\)\\<\\("
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3179 ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3180 ;; "and" "atan2" "bind" "binmode" "bless" "caller"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3181 ;; "chdir" "chmod" "chown" "chr" "chroot" "close"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3182 ;; "closedir" "cmp" "connect" "continue" "cos" "crypt"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3183 ;; "dbmclose" "dbmopen" "die" "dump" "endgrent"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3184 ;; "endhostent" "endnetent" "endprotoent" "endpwent"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3185 ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3186 ;; "fileno" "flock" "fork" "formline" "ge" "getc"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3187 ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3188 ;; "gethostbyname" "gethostent" "getlogin"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3189 ;; "getnetbyaddr" "getnetbyname" "getnetent"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3190 ;; "getpeername" "getpgrp" "getppid" "getpriority"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3191 ;; "getprotobyname" "getprotobynumber" "getprotoent"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3192 ;; "getpwent" "getpwnam" "getpwuid" "getservbyname"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3193 ;; "getservbyport" "getservent" "getsockname"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3194 ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3195 ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3196 ;; "link" "listen" "localtime" "log" "lstat" "lt"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3197 ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3198 ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3199 ;; "quotemeta" "rand" "read" "readdir" "readline"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3200 ;; "readlink" "readpipe" "recv" "ref" "rename" "require"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3201 ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3202 ;; "seekdir" "select" "semctl" "semget" "semop" "send"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3203 ;; "setgrent" "sethostent" "setnetent" "setpgrp"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3204 ;; "setpriority" "setprotoent" "setpwent" "setservent"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3205 ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3206 ;; "shutdown" "sin" "sleep" "socket" "socketpair"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3207 ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3208 ;; "syscall" "sysread" "system" "syswrite" "tell"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3209 ;; "telldir" "time" "times" "truncate" "uc" "ucfirst"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3210 ;; "umask" "unlink" "unpack" "utime" "values" "vec"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3211 ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3212 "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3213 "b\\(in\\(d\\|mode\\)\\|less\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3214 "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3215 "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3216 "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3217 "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3218 "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3219 "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3220 "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3221 "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3222 "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3223 "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3224 "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3225 "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3226 "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3227 "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3228 "\\(\\|ngth\\)\\|o\\(caltime\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3229 "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3230 "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3231 "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3232 "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3233 "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3234 "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3235 "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3236 "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3237 "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|tem\\|write\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3238 "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3239 "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3240 "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3241 "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3242 "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3243 "\\)\\>") 2 'font-lock-type-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3244 ;; In what follows we use `other' style
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3245 ;; for nonoverwritable builtins
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3246 ;; Somehow 's', 'm' are not auto-generated???
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3247 (list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3248 (concat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3249 "\\(^\\|[^$@%&\\]\\)\\<\\("
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3250 ;; "AUTOLOAD" "BEGIN" "DESTROY" "END" "__END__" "chomp"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3251 ;; "chop" "defined" "delete" "do" "each" "else" "elsif"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3252 ;; "eval" "exists" "for" "foreach" "format" "goto"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3253 ;; "grep" "if" "keys" "last" "local" "map" "my" "next"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3254 ;; "no" "package" "pop" "pos" "print" "printf" "push"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3255 ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3256 ;; "sort" "splice" "split" "study" "sub" "tie" "tr"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3257 ;; "undef" "unless" "unshift" "untie" "until" "use"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3258 ;; "while" "y"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3259 "AUTOLOAD\\|BEGIN\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3260 "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3261 "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|if\\|keys\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3262 "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3263 "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3264 "q\\(\\|q\\|w\\|x\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3265 "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3266 "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3267 "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3268 "\\|[sm]" ; Added manually
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3269 "\\)\\>") 2 'font-lock-other-type-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3270 ;; (mapconcat 'identity
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3271 ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3272 ;; "#include" "#define" "#undef")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3273 ;; "\\|")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3274 '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3275 font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3276 '("\\<sub[ \t]+\\([^ \t{;]+\\)[ \t]*\\(([^()]*)[ \t]*\\)?[#{\n]" 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3277 font-lock-function-name-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3278 '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3279 2 font-lock-function-name-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3280 '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3281 1 font-lock-function-name-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3282 (cond ((featurep 'font-lock-extra)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3283 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3284 (2 font-lock-string-face t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3285 (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3286 (font-lock-anchored
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3287 '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3288 (2 font-lock-string-face t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3289 ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3290 nil nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3291 (1 font-lock-string-face t))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3292 (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3293 2 font-lock-string-face t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3294 '("[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3295 font-lock-string-face t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3296 '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3297 font-lock-reference-face) ; labels
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3298 '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3299 2 font-lock-reference-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3300 (cond ((featurep 'font-lock-extra)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3301 '("^[ \t]*\\(my\\|local\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3302 (3 font-lock-variable-name-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3303 (4 '(another 4 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3304 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3305 (1 font-lock-variable-name-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3306 (2 '(restart 2 nil) nil t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3307 nil t))) ; local variables, multiple
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3308 (font-lock-anchored
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3309 '("^[ \t{}]*\\(my\\|local\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3310 (3 font-lock-variable-name-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3311 ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3312 nil nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3313 (1 font-lock-variable-name-face))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3314 (t '("^[ \t{}]*\\(my\\|local\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3315 3 font-lock-variable-name-face)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3316 '("\\<for\\(each\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*("
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3317 2 font-lock-variable-name-face)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3318 (setq
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3319 t-font-lock-keywords-1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3320 (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3321 (not cperl-xemacs-p) ; not yet as of XEmacs 19.12
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3322 '(
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3323 ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3324 (if (eq (char-after (match-beginning 2)) ?%)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3325 font-lock-other-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3326 font-lock-emphasized-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3327 t) ; arrays and hashes
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3328 ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3329 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3330 (if (= (- (match-end 2) (match-beginning 2)) 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3331 (if (eq (char-after (match-beginning 3)) ?{)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3332 font-lock-other-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3333 font-lock-emphasized-face) ; arrays and hashes
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3334 font-lock-variable-name-face) ; Just to put something
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3335 t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3336 ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3337 ;;; Too much noise from \s* @s[ and friends
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3338 ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3339 ;;(3 font-lock-function-name-face t t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3340 ;;(4
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3341 ;; (if (cperl-slash-is-regexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3342 ;; font-lock-function-name-face 'default) nil t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3343 )))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3344 (setq perl-font-lock-keywords-1 t-font-lock-keywords
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3345 perl-font-lock-keywords perl-font-lock-keywords-1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3346 perl-font-lock-keywords-2 (append
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3347 t-font-lock-keywords
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3348 t-font-lock-keywords-1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3349 (if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3350 (if (or (featurep 'choose-color) (featurep 'font-lock-extra))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3351 (font-lock-require-faces
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3352 (list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3353 ;; Color-light Color-dark Gray-light Gray-dark Mono
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3354 (list 'font-lock-comment-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3355 ["Firebrick" "OrangeRed" "DimGray" "Gray80"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3356 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3357 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3358 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3359 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3360 (list 'font-lock-string-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3361 ["RosyBrown" "LightSalmon" "Gray50" "LightGray"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3362 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3363 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3364 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3365 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3366 (list 'font-lock-keyword-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3367 ["Purple" "LightSteelBlue" "DimGray" "Gray90"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3368 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3369 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3370 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3371 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3372 (list 'font-lock-function-name-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3373 (vector
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3374 "Blue" "LightSkyBlue" "Gray50" "LightGray"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3375 (cdr (assq 'background-color ; if mono
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3376 (frame-parameters))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3377 (vector
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3378 nil nil nil nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3379 (cdr (assq 'foreground-color ; if mono
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3380 (frame-parameters))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3381 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3382 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3383 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3384 (list 'font-lock-variable-name-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3385 ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3386 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3387 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3388 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3389 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3390 (list 'font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3391 ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3392 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3393 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3394 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3395 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3396 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3397 (list 'font-lock-reference-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3398 ["CadetBlue" "Aquamarine" "Gray50" "LightGray"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3399 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3400 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3401 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3402 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3403 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3404 (list 'font-lock-other-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3405 ["chartreuse3" ("orchid1" "orange")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3406 nil "Gray80"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3407 [nil nil "gray90"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3408 [nil nil nil t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3409 [nil nil t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3410 [nil nil t t t]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3411 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3412 (list 'font-lock-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3413 ["blue" "yellow" nil "Gray80"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3414 ["lightyellow2" ("navy" "os2blue" "darkgreen")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3415 "gray90"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3416 t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3417 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3418 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3419 (list 'font-lock-other-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3420 ["red" "red" nil "Gray80"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3421 ["lightyellow2" ("navy" "os2blue" "darkgreen")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3422 "gray90"]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3423 t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3424 t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3425 nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3426 (defvar cperl-guessed-background nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3427 "Display characteristics as guessed by cperl.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3428 (or (fboundp 'x-color-defined-p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3429 (defalias 'x-color-defined-p
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3430 (cond ((fboundp 'color-defined-p) 'color-defined-p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3431 ;; XEmacs >= 19.12
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3432 ((fboundp 'valid-color-name-p) 'valid-color-name-p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3433 ;; XEmacs 19.11
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3434 (t 'x-valid-color-name-p))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3435 (defvar font-lock-reference-face 'font-lock-reference-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3436 (defvar font-lock-variable-name-face 'font-lock-variable-name-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3437 (or (boundp 'font-lock-type-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3438 (defconst font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3439 'font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3440 "Face to use for data types.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3441 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3442 (or (boundp 'font-lock-other-type-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3443 (defconst font-lock-other-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3444 'font-lock-other-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3445 "Face to use for data types from another group.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3446 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3447 (if (not cperl-xemacs-p) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3448 (or (boundp 'font-lock-comment-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3449 (defconst font-lock-comment-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3450 'font-lock-comment-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3451 "Face to use for comments.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3452 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3453 (or (boundp 'font-lock-keyword-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3454 (defconst font-lock-keyword-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3455 'font-lock-keyword-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3456 "Face to use for keywords.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3457 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3458 (or (boundp 'font-lock-function-name-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3459 (defconst font-lock-function-name-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3460 'font-lock-function-name-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3461 "Face to use for function names.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3462 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3463 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3464 ;;(if (featurep 'font-lock)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3465 (if (face-equal font-lock-type-face font-lock-comment-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3466 (defconst font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3467 'font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3468 "Face to use for basic data types.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3469 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3470 ;;; (if (fboundp 'eval-after-load)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3471 ;;; (eval-after-load "font-lock"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3472 ;;; '(if (face-equal font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3473 ;;; font-lock-comment-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3474 ;;; (defconst font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3475 ;;; 'font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3476 ;;; "Face to use for basic data types.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3477 ;;; ))) ; This does not work :-( Why?!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3478 ;;; ; Workaround: added to font-lock-m-h
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3479 ;;; )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3480 (or (boundp 'font-lock-other-emphasized-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3481 (defconst font-lock-other-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3482 'font-lock-other-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3483 "Face to use for another type of emphasizing.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3484 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3485 (or (boundp 'font-lock-emphasized-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3486 (defconst font-lock-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3487 'font-lock-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3488 "Face to use for emphasizing.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3489 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3490 ;; Here we try to guess background
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3491 (let ((background
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3492 (if (boundp 'font-lock-background-mode)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3493 font-lock-background-mode
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3494 'light))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3495 (face-list (and (fboundp 'face-list) (face-list)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3496 is-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3497 (fset 'is-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3498 (cond ((fboundp 'find-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3499 (symbol-function 'find-face))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3500 (face-list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3501 (function (lambda (face) (member face face-list))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3502 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3503 (function (lambda (face) (boundp face))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3504 (defvar cperl-guessed-background
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3505 (if (and (boundp 'font-lock-display-type)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3506 (eq font-lock-display-type 'grayscale))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3507 'gray
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3508 background)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3509 "Background as guessed by CPerl mode")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3510 (if (is-face 'font-lock-type-face) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3511 (copy-face 'default 'font-lock-type-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3512 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3513 ((eq background 'light)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3514 (set-face-foreground 'font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3515 (if (x-color-defined-p "seagreen")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3516 "seagreen"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3517 "sea green")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3518 ((eq background 'dark)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3519 (set-face-foreground 'font-lock-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3520 (if (x-color-defined-p "os2pink")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3521 "os2pink"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3522 "pink")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3523 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3524 (set-face-background 'font-lock-type-face "gray90"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3525 (if (is-face 'font-lock-other-type-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3526 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3527 (copy-face 'font-lock-type-face 'font-lock-other-type-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3528 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3529 ((eq background 'light)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3530 (set-face-foreground 'font-lock-other-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3531 (if (x-color-defined-p "chartreuse3")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3532 "chartreuse3"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3533 "chartreuse")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3534 ((eq background 'dark)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3535 (set-face-foreground 'font-lock-other-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3536 (if (x-color-defined-p "orchid1")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3537 "orchid1"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3538 "orange")))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3539 (if (is-face 'font-lock-other-emphasized-face) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3540 (copy-face 'bold-italic 'font-lock-other-emphasized-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3541 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3542 ((eq background 'light)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3543 (set-face-background 'font-lock-other-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3544 (if (x-color-defined-p "lightyellow2")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3545 "lightyellow2"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3546 (if (x-color-defined-p "lightyellow")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3547 "lightyellow"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3548 "light yellow"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3549 ((eq background 'dark)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3550 (set-face-background 'font-lock-other-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3551 (if (x-color-defined-p "navy")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3552 "navy"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3553 (if (x-color-defined-p "darkgreen")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3554 "darkgreen"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3555 "dark green"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3556 (t (set-face-background 'font-lock-other-emphasized-face "gray90"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3557 (if (is-face 'font-lock-emphasized-face) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3558 (copy-face 'bold 'font-lock-emphasized-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3559 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3560 ((eq background 'light)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3561 (set-face-background 'font-lock-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3562 (if (x-color-defined-p "lightyellow2")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3563 "lightyellow2"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3564 "lightyellow")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3565 ((eq background 'dark)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3566 (set-face-background 'font-lock-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3567 (if (x-color-defined-p "navy")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3568 "navy"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3569 (if (x-color-defined-p "darkgreen")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3570 "darkgreen"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3571 "dark green"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3572 (t (set-face-background 'font-lock-emphasized-face "gray90"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3573 (if (is-face 'font-lock-variable-name-face) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3574 (copy-face 'italic 'font-lock-variable-name-face))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3575 (if (is-face 'font-lock-reference-face) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3576 (copy-face 'italic 'font-lock-reference-face))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3577 (setq cperl-faces-init t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3578 (error nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3579
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3580
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3581 (defun cperl-ps-print-init ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3582 "Initialization of `ps-print' components for faces used in CPerl."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3583 ;; Guard against old versions
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3584 (defvar ps-underlined-faces nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3585 (defvar ps-bold-faces nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3586 (defvar ps-italic-faces nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3587 (setq ps-bold-faces
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3588 (append '(font-lock-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3589 font-lock-keyword-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3590 font-lock-variable-name-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3591 font-lock-reference-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3592 font-lock-other-emphasized-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3593 ps-bold-faces))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3594 (setq ps-italic-faces
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3595 (append '(font-lock-other-type-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3596 font-lock-reference-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3597 font-lock-other-emphasized-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3598 ps-italic-faces))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3599 (setq ps-underlined-faces
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3600 (append '(font-lock-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3601 font-lock-other-emphasized-face
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3602 font-lock-other-type-face font-lock-type-face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3603 ps-underlined-faces))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3604 (cons 'font-lock-type-face ps-underlined-faces))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3605
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3606
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3607 (if (cperl-enable-font-lock) (cperl-windowed-init))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3608
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3609 (defun cperl-set-style (style)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3610 "Set CPerl-mode variables to use one of several different indentation styles.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3611 The arguments are a string representing the desired style.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3612 Available styles are GNU, K&R, BSD and Whitesmith."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3613 (interactive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3614 (let ((list (mapcar (function (lambda (elt) (list (car elt))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3615 c-style-alist)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3616 (list (completing-read "Enter style: " list nil 'insist))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3617 (let ((style (cdr (assoc style c-style-alist))) setting str sym)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3618 (while style
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3619 (setq setting (car style) style (cdr style))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3620 (setq str (symbol-name (car setting)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3621 (and (string-match "^c-" str)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3622 (setq str (concat "cperl-" (substring str 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3623 (setq sym (intern-soft str))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3624 (boundp sym)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3625 (set sym (cdr setting))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3626
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3627 (defun cperl-check-syntax ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3628 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3629 (require 'mode-compile)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3630 (let ((perl-dbg-flags "-wc"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3631 (mode-compile)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3632
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3633 (defun cperl-info-buffer (type)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3634 ;; Returns buffer with documentation. Creates if missing.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3635 ;; If TYPE, this vars buffer.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3636 ;; Special care is taken to not stomp over an existing info buffer
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3637 (let* ((bname (if type "*info-perl-var*" "*info-perl*"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3638 (info (get-buffer bname))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3639 (oldbuf (get-buffer "*info*")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3640 (if info info
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3641 (save-window-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3642 ;; Get Info running
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3643 (require 'info)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3644 (cond (oldbuf
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3645 (set-buffer oldbuf)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3646 (rename-buffer "*info-perl-tmp*")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3647 (save-window-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3648 (info))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3649 (Info-find-node cperl-info-page (if type "perlvar" "perlfunc"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3650 (set-buffer "*info*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3651 (rename-buffer bname)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3652 (cond (oldbuf
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3653 (set-buffer "*info-perl-tmp*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3654 (rename-buffer "*info*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3655 (set-buffer bname)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3656 (make-variable-buffer-local 'window-min-height)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3657 (setq window-min-height 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3658 (current-buffer)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3659
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3660 (defun cperl-word-at-point (&optional p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3661 ;; Returns the word at point or at P.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3662 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3663 (if p (goto-char p))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3664 (or (cperl-word-at-point-hard)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3665 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3666 (require 'etags)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3667 (funcall (or (and (boundp 'find-tag-default-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3668 find-tag-default-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3669 (get major-mode 'find-tag-default-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3670 ;; XEmacs 19.12 has `find-tag-default-hook'; it is
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3671 ;; automatically used within `find-tag-default':
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3672 'find-tag-default))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3673
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3674 (defun cperl-info-on-command (command)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3675 "Shows documentation for Perl command in other window.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3676 If perl-info buffer is shown in some frame, uses this frame.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3677 Customized by setting variables `cperl-shrink-wrap-info-frame',
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3678 `cperl-max-help-size'."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3679 (interactive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3680 (let* ((default (cperl-word-at-point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3681 (read (read-string
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3682 (format "Find doc for Perl function (default %s): "
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3683 default))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3684 (list (if (equal read "")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3685 default
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3686 read))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3687
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3688 (let ((buffer (current-buffer))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3689 (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3690 pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3691 max-height char-height buf-list)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3692 (if (string-match "^-[a-zA-Z]$" command)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3693 (setq cmd-desc "^-X[ \t\n]"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3694 (setq isvar (string-match "^[$@%]" command)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3695 buf (cperl-info-buffer isvar)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3696 iniwin (selected-window)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3697 fr1 (window-frame iniwin))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3698 (set-buffer buf)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3699 (beginning-of-buffer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3700 (or isvar
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3701 (progn (re-search-forward "^-X[ \t\n]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3702 (forward-line -1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3703 (if (re-search-forward cmd-desc nil t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3704 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3705 ;; Go back to beginning of the group (ex, for qq)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3706 (if (re-search-backward "^[ \t\n\f]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3707 (forward-line 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3708 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3709 ;; Get some of
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3710 (setq pos (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3711 buf-list (list buf "*info-perl-var*" "*info-perl*"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3712 (while (and (not win) buf-list)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3713 (setq win (get-buffer-window (car buf-list) t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3714 (setq buf-list (cdr buf-list)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3715 (or (not win)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3716 (eq (window-buffer win) buf)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3717 (set-window-buffer win buf))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3718 (and win (setq fr2 (window-frame win)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3719 (if (or (not fr2) (eq fr1 fr2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3720 (pop-to-buffer buf)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3721 (special-display-popup-frame buf) ; Make it visible
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3722 (select-window win))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3723 (goto-char pos) ; Needed (?!).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3724 ;; Resize
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3725 (setq iniheight (window-height)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3726 frheight (frame-height)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3727 not-loner (< iniheight (1- frheight))) ; Are not alone
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3728 (cond ((if not-loner cperl-max-help-size
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3729 cperl-shrink-wrap-info-frame)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3730 (setq height
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3731 (+ 2
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3732 (count-lines
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3733 pos
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3734 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3735 (if (re-search-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3736 "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3737 (match-beginning 0) (point-max)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3738 max-height
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3739 (if not-loner
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3740 (/ (* (- frheight 3) cperl-max-help-size) 100)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3741 (setq char-height (frame-char-height))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3742 ;; Non-functioning under OS/2:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3743 (if (eq char-height 1) (setq char-height 18))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3744 ;; Title, menubar, + 2 for slack
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3745 (- (/ (x-display-pixel-height) char-height) 4)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3746 ))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3747 (if (> height max-height) (setq height max-height))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3748 ;;(message "was %s doing %s" iniheight height)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3749 (if not-loner
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3750 (enlarge-window (- height iniheight))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3751 (set-frame-height (window-frame win) (1+ height)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3752 (set-window-start (selected-window) pos))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3753 (message "No entry for %s found." command))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3754 ;;(pop-to-buffer buffer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3755 (select-window iniwin)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3756
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3757 (defun cperl-info-on-current-command ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3758 "Shows documentation for Perl command at point in other window."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3759 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3760 (cperl-info-on-command (cperl-word-at-point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3761
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3762 (defun cperl-imenu-info-imenu-search ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3763 (if (looking-at "^-X[ \t\n]") nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3764 (re-search-backward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3765 "^\n\\([-a-zA-Z_]+\\)[ \t\n]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3766 (forward-line 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3767
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3768 (defun cperl-imenu-info-imenu-name ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3769 (buffer-substring
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3770 (match-beginning 1) (match-end 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3771
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3772 (defun cperl-imenu-on-info ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3773 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3774 (let* ((buffer (current-buffer))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3775 imenu-create-index-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3776 imenu-prev-index-position-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3777 imenu-extract-index-name-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3778 (index-item (save-restriction
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3779 (save-window-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3780 (set-buffer (cperl-info-buffer nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3781 (setq imenu-create-index-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3782 'imenu-default-create-index-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3783 imenu-prev-index-position-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3784 'cperl-imenu-info-imenu-search
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3785 imenu-extract-index-name-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3786 'cperl-imenu-info-imenu-name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3787 (imenu-choose-buffer-index)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3788 (and index-item
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3789 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3790 (push-mark)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3791 (pop-to-buffer "*info-perl*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3792 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3793 ((markerp (cdr index-item))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3794 (goto-char (marker-position (cdr index-item))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3795 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3796 (goto-char (cdr index-item))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3797 (set-window-start (selected-window) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3798 (pop-to-buffer buffer)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3799
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3800 (defun cperl-lineup (beg end &optional step minshift)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3801 "Lineup construction in a region.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3802 Beginning of region should be at the start of a construction.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3803 All first occurrences of this construction in the lines that are
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3804 partially contained in the region are lined up at the same column.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3805
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3806 MINSHIFT is the minimal amount of space to insert before the construction.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3807 STEP is the tabwidth to position constructions.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3808 If STEP is `nil', `cperl-lineup-step' will be used
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3809 \(or `cperl-indent-level', if `cperl-lineup-step' is `nil').
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3810 Will not move the position at the start to the left."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3811 (interactive "r")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3812 (let (search col tcol seen b e)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3813 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3814 (goto-char end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3815 (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3816 (setq end (point-marker))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3817 (goto-char beg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3818 (skip-chars-forward " \t\f")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3819 (setq beg (point-marker))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3820 (indent-region beg end nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3821 (goto-char beg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3822 (setq col (current-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3823 (if (looking-at "[a-zA-Z0-9_]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3824 (if (looking-at "\\<[a-zA-Z0-9_]+\\>")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3825 (setq search
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3826 (concat "\\<"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3827 (regexp-quote
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3828 (buffer-substring (match-beginning 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3829 (match-end 0))) "\\>"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3830 (error "Cannot line up in a middle of the word"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3831 (if (looking-at "$")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3832 (error "Cannot line up end of line"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3833 (setq search (regexp-quote (char-to-string (following-char)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3834 (setq step (or step cperl-lineup-step cperl-indent-level))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3835 (or minshift (setq minshift 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3836 (while (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3837 (beginning-of-line 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3838 (and (< (point) end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3839 (re-search-forward search end t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3840 (goto-char (match-beginning 0))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3841 (setq tcol (current-column) seen t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3842 (if (> tcol col) (setq col tcol)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3843 (or seen
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3844 (error "The construction to line up occurred only once"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3845 (goto-char beg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3846 (setq col (+ col minshift))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3847 (if (/= (% col step) 0) (setq step (* step (1+ (/ col step)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3848 (while
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3849 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3850 (setq e (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3851 (skip-chars-backward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3852 (delete-region (point) e)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3853 (indent-to-column col); (make-string (- col (current-column)) ?\ ))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3854 (beginning-of-line 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3855 (and (< (point) end)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3856 (re-search-forward search end t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3857 (goto-char (match-beginning 0)))))))) ; No body
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3858
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3859 (defun cperl-etags (&optional add all files)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3860 "Run etags with appropriate options for Perl files.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3861 If optional argument ALL is `recursive', will process Perl files
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3862 in subdirectories too."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3863 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3864 (let ((cmd "etags")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3865 (args '("-l" "none" "-r" "/\\<\\(package\\|sub\\)[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([{#]\\|$\\)\\)/\\4/"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3866 res)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3867 (if add (setq args (cons "-a" args)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3868 (or files (setq files (list buffer-file-name)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3869 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3870 ((eq all 'recursive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3871 ;;(error "Not implemented: recursive")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3872 (setq args (append (list "-e"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3873 "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3874 use File::Find;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3875 find(\\&wanted, '.');
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3876 exec @ARGV;"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3877 cmd) args)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3878 cmd "perl"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3879 (all
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3880 ;;(error "Not implemented: all")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3881 (setq args (append (list "-e"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3882 "push @ARGV, <*.PL *.pl *.pm>;
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3883 exec @ARGV;"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3884 cmd) args)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3885 cmd "perl"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3886 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3887 (setq args (append args files))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3888 (setq res (apply 'call-process cmd nil nil nil args))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3889 (or (eq res 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3890 (message "etags returned \"%s\"" res))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3891
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3892 (defun cperl-toggle-auto-newline ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3893 "Toggle the state of `cperl-auto-newline'."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3894 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3895 (setq cperl-auto-newline (not cperl-auto-newline))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3896 (message "Newlines will %sbe auto-inserted now."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3897 (if cperl-auto-newline "" "not ")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3898
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3899 (defun cperl-toggle-abbrev ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3900 "Toggle the state of automatic keyword expansion in CPerl mode."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3901 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3902 (abbrev-mode (if abbrev-mode 0 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3903 (message "Perl control structure will %sbe auto-inserted now."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3904 (if abbrev-mode "" "not ")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3905
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3906
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3907 (defun cperl-toggle-electric ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3908 "Toggle the state of parentheses doubling in CPerl mode."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3909 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3910 (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3911 (message "Parentheses will %sbe auto-doubled now."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3912 (if (cperl-val 'cperl-electric-parens) "" "not ")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3913
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3914 ;;;; Tags file creation.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3915
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3916 (defvar cperl-tmp-buffer " *cperl-tmp*")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3917
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3918 (defun cperl-setup-tmp-buf ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3919 (set-buffer (get-buffer-create cperl-tmp-buffer))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3920 (set-syntax-table cperl-mode-syntax-table)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3921 (buffer-disable-undo)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3922 (auto-fill-mode 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3923 (if cperl-use-syntax-table-text-property-for-tags
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3924 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3925 (make-variable-buffer-local 'parse-sexp-lookup-properties)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3926 ;; Do not introduce variable if not needed, we check it!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3927 (set 'parse-sexp-lookup-properties t))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3928
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3929 (defun cperl-xsub-scan ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3930 (require 'cl)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3931 (require 'imenu)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3932 (let ((index-alist '())
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3933 (prev-pos 0) index index1 name package prefix)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3934 (goto-char (point-min))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3935 (if noninteractive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3936 (message "Scanning XSUB for index")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3937 (imenu-progress-message prev-pos 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3938 ;; Search for the function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3939 (progn ;;save-match-data
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3940 (while (re-search-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3941 "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3942 nil t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3943 (or noninteractive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3944 (imenu-progress-message prev-pos))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3945 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3946 ((match-beginning 2) ; SECTION
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3947 (setq package (buffer-substring (match-beginning 2) (match-end 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3948 (goto-char (match-beginning 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3949 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3950 (forward-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3951 (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3952 (setq prefix (buffer-substring (match-beginning 1) (match-end 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3953 (setq prefix nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3954 ((not package) nil) ; C language section
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3955 ((match-beginning 3) ; XSUB
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3956 (goto-char (1+ (match-beginning 3)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3957 (setq index (imenu-example--name-and-position))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3958 (setq name (buffer-substring (match-beginning 3) (match-end 3)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3959 (if (and prefix (string-match (concat "^" prefix) name))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3960 (setq name (substring name (length prefix))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3961 (cond ((string-match "::" name) nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3962 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3963 (setq index1 (cons (concat package "::" name) (cdr index)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3964 (push index1 index-alist)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3965 (setcar index name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3966 (push index index-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3967 (t ; BOOT: section
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3968 ;; (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3969 (setq index (imenu-example--name-and-position))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3970 (setcar index (concat package "::BOOT:"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3971 (push index index-alist)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3972 (or noninteractive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3973 (imenu-progress-message prev-pos 100))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3974 ;;(setq index-alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3975 ;; (if (default-value 'imenu-sort-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3976 ;; (sort index-alist (default-value 'imenu-sort-function))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3977 ;; (nreverse index-alist)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3978 index-alist))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3979
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3980 (defun cperl-find-tags (file xs topdir)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3981 (let (ind (b (get-buffer cperl-tmp-buffer)) lst elt pos ret rel
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3982 (cperl-pod-here-fontify nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3983 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3984 (if b (set-buffer b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3985 (cperl-setup-tmp-buf))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3986 (erase-buffer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3987 (setq file (car (insert-file-contents file)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3988 (message "Scanning file %s ..." file)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3989 (if (and cperl-use-syntax-table-text-property-for-tags
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3990 (not xs))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3991 (condition-case err ; after __END__ may have garbage
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3992 (cperl-find-pods-heres)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3993 (error (message "While scanning for syntax: %s" err))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3994 (if xs
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3995 (setq lst (cperl-xsub-scan))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3996 (setq ind (imenu-example--create-perl-index))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3997 (setq lst (cdr (assoc "+Unsorted List+..." ind))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3998 (setq lst
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3999 (mapcar
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4000 (function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4001 (lambda (elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4002 (cond ((string-match "^[_a-zA-Z]" (car elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4003 (goto-char (cdr elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4004 (list (car elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4005 (point) (count-lines 1 (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4006 (buffer-substring (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4007 (skip-chars-forward
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4008 ":_a-zA-Z0-9")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4009 (or (eolp) (forward-char 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4010 (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4011 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4012 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4013 (point))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4014 lst))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4015 (erase-buffer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4016 (while lst
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4017 (setq elt (car lst) lst (cdr lst))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4018 (if elt
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4019 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4020 (insert (elt elt 3)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4021 127
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4022 (if (string-match "^package " (car elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4023 (substring (car elt) 8)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4024 (car elt) )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4025 1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4026 (number-to-string (elt elt 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4027 ","
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4028 (number-to-string (elt elt 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4029 "\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4030 (if (and (string-match "^[_a-zA-Z]+::" (car elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4031 (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4032 (elt elt 3)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4033 ;; Need to insert the name without package as well
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4034 (setq lst (cons (cons (substring (elt elt 3)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4035 (match-beginning 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4036 (match-end 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4037 (cdr elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4038 lst))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4039 (setq pos (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4040 (goto-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4041 (setq rel file)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4042 ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4043 (set-text-properties 0 (length rel) nil rel)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4044 (and (equal topdir (substring rel 0 (length topdir)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4045 (setq rel (substring file (length topdir))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4046 (insert "\f\n" rel "," (number-to-string (1- pos)) "\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4047 (setq ret (buffer-substring 1 (point-max)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4048 (erase-buffer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4049 (or noninteractive
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4050 (message "Scanning file %s finished" file))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4051 ret)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4052
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4053 (defun cperl-add-tags-recurse-noxs ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4054 "Add to TAGS data for Perl and XSUB files in the current directory and kids.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4055 Use as
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4056 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4057 -f cperl-add-tags-recurse
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4058 "
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4059 (cperl-write-tags nil nil t t nil t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4060
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4061 (defun cperl-add-tags-recurse ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4062 "Add to TAGS file data for Perl files in the current directory and kids.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4063 Use as
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4064 emacs -batch -q -no-site-file -l emacs/cperl-mode.el \
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4065 -f cperl-add-tags-recurse
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4066 "
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4067 (cperl-write-tags nil nil t t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4068
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4069 (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4070 ;; If INBUFFER, do not select buffer, and do not save
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4071 ;; If ERASE is `ignore', do not erase, and do not try to delete old info.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4072 (require 'etags)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4073 (if file nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4074 (setq file (if dir default-directory (buffer-file-name)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4075 (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4076 (or topdir
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4077 (setq topdir default-directory))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4078 (let ((tags-file-name "TAGS")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4079 (case-fold-search (eq system-type 'emx))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4080 xs)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4081 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4082 (cond (inbuffer nil) ; Already there
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4083 ((file-exists-p tags-file-name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4084 (visit-tags-table-buffer tags-file-name))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4085 (t (set-buffer (find-file-noselect tags-file-name))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4086 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4087 (dir
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4088 (cond ((eq erase 'ignore))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4089 (erase
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4090 (erase-buffer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4091 (setq erase 'ignore)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4092 (let ((files
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4093 (directory-files file t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4094 (if recurse nil cperl-scan-files-regexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4095 t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4096 (mapcar (function (lambda (file)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4097 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4098 ((string-match cperl-noscan-files-regexp file)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4099 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4100 ((not (file-directory-p file))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4101 (if (string-match cperl-scan-files-regexp file)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4102 (cperl-write-tags file erase recurse nil t noxs topdir)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4103 ((not recurse) nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4104 (t (cperl-write-tags file erase recurse t t noxs topdir)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4105 files))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4106 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4107 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4108 (setq xs (string-match "\\.xs$" file))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4109 (if (not (and xs noxs))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4110 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4111 (cond ((eq erase 'ignore) (goto-char (point-max)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4112 (erase (erase-buffer))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4113 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4114 (goto-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4115 (if (search-forward (concat "\f\n" file ",") nil t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4116 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4117 (search-backward "\f\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4118 (delete-region (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4119 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4120 (forward-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4121 (if (search-forward "\f\n"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4122 nil 'toend)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4123 (- (point) 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4124 (point-max)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4125 (goto-char (point-max)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4126 (insert (cperl-find-tags file xs topdir))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4127 (if inbuffer nil ; Delegate to the caller
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4128 (save-buffer 0) ; No backup
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4129 (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4130 (initialize-new-tags-table))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4131
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4132 (defvar cperl-tags-hier-regexp-list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4133 (concat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4134 "^\\("
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4135 "\\(package\\)\\>"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4136 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4137 "sub\\>[^\n]+::"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4138 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4139 "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4140 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4141 "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4142 "\\)"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4143
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4144 (defvar cperl-hierarchy '(() ())
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4145 "Global hierarchy of classes")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4146
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4147 (defun cperl-tags-hier-fill ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4148 ;; Suppose we are in a tag table cooked by cperl.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4149 (goto-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4150 (let (type pack name pos line chunk ord cons1 file str info fileind)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4151 (while (re-search-forward cperl-tags-hier-regexp-list nil t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4152 (setq pos (match-beginning 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4153 pack (match-beginning 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4154 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4155 (if (looking-at (concat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4156 "\\([^\n]+\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4157 "\C-?"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4158 "\\([^\n]+\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4159 "\C-a"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4160 "\\([0-9]+\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4161 ","
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4162 "\\([0-9]+\\)"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4163 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4164 (setq ;;str (buffer-substring (match-beginning 1) (match-end 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4165 name (buffer-substring (match-beginning 2) (match-end 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4166 ;;pos (buffer-substring (match-beginning 3) (match-end 3))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4167 line (buffer-substring (match-beginning 4) (match-end 4))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4168 ord (if pack 1 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4169 info (etags-snarf-tag) ; Moves to beginning of the next line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4170 file (file-of-tag)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4171 fileind (format "%s:%s" file line))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4172 ;; Move back
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4173 (forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4174 ;; Make new member of hierarchy name ==> file ==> pos if needed
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4175 (if (setq cons1 (assoc name (nth ord cperl-hierarchy)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4176 ;; Name known
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4177 (setcdr cons1 (cons (cons fileind (vector file info))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4178 (cdr cons1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4179 ;; First occurrence of the name, start alist
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4180 (setq cons1 (cons name (list (cons fileind (vector file info)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4181 (if pack
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4182 (setcar (cdr cperl-hierarchy)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4183 (cons cons1 (nth 1 cperl-hierarchy)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4184 (setcar cperl-hierarchy
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4185 (cons cons1 (car cperl-hierarchy)))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4186 (end-of-line))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4187
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4188 (defun cperl-tags-hier-init (&optional update)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4189 "Show hierarchical menu of classes and methods.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4190 Finds info about classes by a scan of loaded TAGS files.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4191 Supposes that the TAGS files contain fully qualified function names.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4192 One may build such TAGS files from CPerl mode menu."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4193 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4194 (require 'etags)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4195 (require 'imenu)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4196 (if (or update (null (nth 2 cperl-hierarchy)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4197 (let (pack name cons1 to l1 l2 l3 l4
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4198 (remover (function (lambda (elt) ; (name (file1...) (file2..))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4199 (or (nthcdr 2 elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4200 ;; Only in one file
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4201 (setcdr elt (cdr (nth 1 elt))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4202 ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4203 (setq cperl-hierarchy (list l1 l2 l3))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4204 (or tags-table-list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4205 (call-interactively 'visit-tags-table))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4206 (message "Updating list of classes...")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4207 (mapcar
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4208 (function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4209 (lambda (tagsfile)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4210 (set-buffer (get-file-buffer tagsfile))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4211 (cperl-tags-hier-fill)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4212 tags-table-list)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4213 (mapcar remover (car cperl-hierarchy))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4214 (mapcar remover (nth 1 cperl-hierarchy))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4215 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4216 (cons "Methods: " (car cperl-hierarchy))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4217 (cperl-tags-treeify to 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4218 (setcar (nthcdr 2 cperl-hierarchy)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4219 (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4220 (message "Updating list of classes: done, requesting display...")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4221 ;;(cperl-imenu-addback (nth 2 cperl-hierarchy))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4222 ))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4223 (or (nth 2 cperl-hierarchy)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4224 (error "No items found"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4225 (setq update
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4226 ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4227 (if window-system
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4228 (x-popup-menu t (nth 2 cperl-hierarchy))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4229 (require 'tmm)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4230 (tmm-prompt (nth 2 cperl-hierarchy))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4231 (if (and update (listp update))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4232 (progn (while (cdr update) (setq update (cdr update)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4233 (setq update (car update)))) ; Get the last from the list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4234 (if (vectorp update)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4235 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4236 (find-file (elt update 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4237 (etags-goto-tag-location (elt update 1))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4238 (if (eq update -999) (cperl-tags-hier-init t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4239
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4240 (defun cperl-tags-treeify (to level)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4241 ;; cadr of `to' is read-write. On start it is a cons
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4242 (let* ((regexp (concat "^\\(" (mapconcat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4243 'identity
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4244 (make-list level "[_a-zA-Z0-9]+")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4245 "::")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4246 "\\)\\(::\\)?"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4247 (packages (cdr (nth 1 to)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4248 (methods (cdr (nth 2 to)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4249 l1 head tail cons1 cons2 ord writeto packs recurse
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4250 root-packages root-functions ms many_ms same_name ps
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4251 (move-deeper
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4252 (function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4253 (lambda (elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4254 (cond ((and (string-match regexp (car elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4255 (or (eq ord 1) (match-end 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4256 (setq head (substring (car elt) 0 (match-end 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4257 tail (if (match-end 2) (substring (car elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4258 (match-end 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4259 recurse t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4260 (if (setq cons1 (assoc head writeto)) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4261 ;; Need to init new head
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4262 (setcdr writeto (cons (list head (list "Packages: ")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4263 (list "Methods: "))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4264 (cdr writeto)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4265 (setq cons1 (nth 1 writeto)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4266 (setq cons2 (nth ord cons1)) ; Either packs or meths
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4267 (setcdr cons2 (cons elt (cdr cons2))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4268 ((eq ord 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4269 (setq root-functions (cons elt root-functions)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4270 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4271 (setq root-packages (cons elt root-packages))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4272 (setcdr to l1) ; Init to dynamic space
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4273 (setq writeto to)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4274 (setq ord 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4275 (mapcar move-deeper packages)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4276 (setq ord 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4277 (mapcar move-deeper methods)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4278 (if recurse
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4279 (mapcar (function (lambda (elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4280 (cperl-tags-treeify elt (1+ level))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4281 (cdr to)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4282 ;;Now clean up leaders with one child only
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4283 (mapcar (function (lambda (elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4284 (if (not (and (listp (cdr elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4285 (eq (length elt) 2))) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4286 (setcar elt (car (nth 1 elt)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4287 (setcdr elt (cdr (nth 1 elt))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4288 (cdr to))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4289 ;; Sort the roots of subtrees
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4290 (if (default-value 'imenu-sort-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4291 (setcdr to
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4292 (sort (cdr to) (default-value 'imenu-sort-function))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4293 ;; Now add back functions removed from display
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4294 (mapcar (function (lambda (elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4295 (setcdr to (cons elt (cdr to)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4296 (if (default-value 'imenu-sort-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4297 (nreverse
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4298 (sort root-functions (default-value 'imenu-sort-function)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4299 root-functions))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4300 ;; Now add back packages removed from display
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4301 (mapcar (function (lambda (elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4302 (setcdr to (cons (cons (concat "package " (car elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4303 (cdr elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4304 (cdr to)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4305 (if (default-value 'imenu-sort-function)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4306 (nreverse
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4307 (sort root-packages (default-value 'imenu-sort-function)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4308 root-packages))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4309 ))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4310
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4311 ;;;(x-popup-menu t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4312 ;;; '(keymap "Name1"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4313 ;;; ("Ret1" "aa")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4314 ;;; ("Head1" "ab"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4315 ;;; keymap "Name2"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4316 ;;; ("Tail1" "x") ("Tail2" "y"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4317
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4318 (defun cperl-list-fold (list name limit)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4319 (let (list1 list2 elt1 (num 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4320 (if (<= (length list) limit) list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4321 (setq list1 nil list2 nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4322 (while list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4323 (setq num (1+ num)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4324 elt1 (car list)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4325 list (cdr list))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4326 (if (<= num imenu-max-items)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4327 (setq list2 (cons elt1 list2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4328 (setq list1 (cons (cons name
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4329 (nreverse list2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4330 list1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4331 list2 (list elt1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4332 num 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4333 (nreverse (cons (cons name
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4334 (nreverse list2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4335 list1)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4336
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4337 (defun cperl-menu-to-keymap (menu &optional name)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4338 (let (list)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4339 (cons 'keymap
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4340 (mapcar
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4341 (function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4342 (lambda (elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4343 (cond ((listp (cdr elt))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4344 (setq list (cperl-list-fold
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4345 (cdr elt) (car elt) imenu-max-items))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4346 (cons nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4347 (cons (car elt)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4348 (cperl-menu-to-keymap list))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4349 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4350 (list (cdr elt) (car elt) t))))) ; t is needed in 19.34
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4351 (cperl-list-fold menu "Root" imenu-max-items)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4352
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4353
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4354 (defvar cperl-bad-style-regexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4355 (mapconcat 'identity
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4356 '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4357 "[-<>=+^&|]+[^- \t\n=+<>~]" ; sign+ char
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4358 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4359 "\\|")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4360 "Finds places such that insertion of a whitespace may help a lot.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4361
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4362 (defvar cperl-not-bad-style-regexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4363 (mapconcat 'identity
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4364 '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4365 "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4366 "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4367 "<\\$?\\sw+\\(\\.\\sw+\\)?>" ; <IN> <stdin.h>
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4368 "-[a-zA-Z][ \t]+[_$\"'`]" ; -f file
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4369 "-[0-9]" ; -5
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4370 "\\+\\+" ; ++var
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4371 "--" ; --var
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4372 ".->" ; a->b
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4373 "->" ; a SPACE ->b
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4374 "\\[-" ; a[-1]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4375 "^=" ; =head
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4376 "||"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4377 "&&"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4378 "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text>
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4379 "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4380 ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4381 ;;"[*/+-|&<.]+="
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4382 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4383 "\\|")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4384 "If matches at the start of match found by `my-bad-c-style-regexp',
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4385 insertion of a whitespace will not help.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4386
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4387 (defvar found-bad)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4388
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4389 (defun cperl-find-bad-style ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4390 "Find places in the buffer where insertion of a whitespace may help.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4391 Prompts user for insertion of spaces.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4392 Currently it is tuned to C and Perl syntax."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4393 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4394 (let (found-bad (p (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4395 (setq last-nonmenu-event 13) ; To disable popup
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4396 (beginning-of-buffer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4397 (map-y-or-n-p "Insert space here? "
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4398 (function (lambda (arg) (insert " ")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4399 'cperl-next-bad-style
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4400 '("location" "locations" "insert a space into")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4401 '((?\C-r (lambda (arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4402 (let ((buffer-quit-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4403 'exit-recursive-edit))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4404 (message "Exit with Esc Esc")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4405 (recursive-edit)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4406 t)) ; Consider acted upon
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4407 "edit, exit with Esc Esc")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4408 (?e (lambda (arg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4409 (let ((buffer-quit-function
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4410 'exit-recursive-edit))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4411 (message "Exit with Esc Esc")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4412 (recursive-edit)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4413 t)) ; Consider acted upon
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4414 "edit, exit with Esc Esc"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4415 t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4416 (if found-bad (goto-char found-bad)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4417 (goto-char p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4418 (message "No appropriate place found"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4419
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4420 (defun cperl-next-bad-style ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4421 (let (p (not-found t) (point (point)) found)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4422 (while (and not-found
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4423 (re-search-forward cperl-bad-style-regexp nil 'to-end))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4424 (setq p (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4425 (goto-char (match-beginning 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4426 (if (or
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4427 (looking-at cperl-not-bad-style-regexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4428 ;; Check for a < -b and friends
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4429 (and (eq (following-char) ?\-)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4430 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4431 (skip-chars-backward " \t\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4432 (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\(, ?\[, ?\{))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4433 ;; Now check for syntax type
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4434 (save-match-data
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4435 (setq found (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4436 (beginning-of-defun)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4437 (let ((pps (parse-partial-sexp (point) found)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4438 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4439 (goto-char (match-end 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4440 (goto-char (1- p))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4441 (setq not-found nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4442 found-bad found)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4443 (not not-found)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4444
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4445 =06
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4446 ;;; Getting help
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4447 (defvar cperl-have-help-regexp
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4448 ;;(concat "\\("
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4449 (mapconcat
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4450 'identity
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4451 '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4452 "[$@]\\^[a-zA-Z]" ; Special variable
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4453 "[$@][^ \n\t]" ; Special variable
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4454 "-[a-zA-Z]" ; File test
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4455 "\\\\[a-zA-Z0]" ; Special chars
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4456 "^=[a-z][a-zA-Z0-9_]*" ; Pod sections
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4457 "[-!&*+,-./<=>?\\\\^|~]+" ; Operator
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4458 "[a-zA-Z_0-9:]+" ; symbol or number
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4459 "x="
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4460 "#!"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4461 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4462 ;;"\\)\\|\\("
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4463 "\\|"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4464 )
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4465 ;;"\\)"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4466 ;;)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4467 "Matches places in the buffer we can find help for.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4468
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4469 (defvar cperl-message-on-help-error t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4470 (defvar cperl-help-from-timer nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4471
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4472 (defun cperl-word-at-point-hard ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4473 ;; Does not save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4474 ;; Get to the something meaningful
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4475 (or (eobp) (eolp) (forward-char 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4476 (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4477 (save-excursion (beginning-of-line) (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4478 'to-beg)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4479 ;; (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4480 ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4481 ;; (skip-chars-backward " \n\t\r({[]});,")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4482 ;; (or (bobp) (backward-char 1))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4483 ;; Try to backtrace
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4484 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4485 ((looking-at "[a-zA-Z0-9_:]") ; symbol
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4486 (skip-chars-backward "a-zA-Z0-9_:")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4487 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4488 ((and (eq (preceding-char) ?^) ; $^I
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4489 (eq (char-after (- (point) 2)) ?\$))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4490 (forward-char -2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4491 ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4492 (forward-char -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4493 ((and (eq (preceding-char) ?\=)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4494 (eq (current-column) 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4495 (forward-char -1))) ; =head1
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4496 (if (and (eq (preceding-char) ?\<)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4497 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH>
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4498 (forward-char -1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4499 ((and (looking-at "=") (eq (preceding-char) ?x)) ; x=
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4500 (forward-char -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4501 ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4502 (forward-char -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4503 ((looking-at "[-!&*+,-./<=>?\\\\^|~]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4504 (skip-chars-backward "-!&*+,-./<=>?\\\\^|~")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4505 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4506 ((and (eq (preceding-char) ?\$)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4507 (not (eq (char-after (- (point) 2)) ?\$))) ; $-
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4508 (forward-char -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4509 ((and (eq (following-char) ?\>)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4510 (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4511 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4512 (forward-sexp -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4513 (and (eq (preceding-char) ?\<)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4514 (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH>
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4515 (search-backward "<"))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4516 ((and (eq (following-char) ?\$)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4517 (eq (preceding-char) ?\<)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4518 (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh>
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4519 (forward-char -1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4520 (if (looking-at cperl-have-help-regexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4521 (buffer-substring (match-beginning 0) (match-end 0))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4522
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4523 (defun cperl-get-help ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4524 "Get one-line docs on the symbol at the point.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4525 The data for these docs is a little bit obsolete and may be in fact longer
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4526 than a line. Your contribution to update/shorten it is appreciated."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4527 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4528 (save-match-data ; May be called "inside" query-replace
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4529 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4530 (let ((word (cperl-word-at-point-hard)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4531 (if word
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4532 (if (and cperl-help-from-timer ; Bail out if not in mainland
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4533 (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4534 (or (memq (get-text-property (point) 'face)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4535 '(font-lock-comment-face font-lock-string-face))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4536 (memq (get-text-property (point) 'syntax-type)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4537 '(pod here-doc format))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4538 nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4539 (cperl-describe-perl-symbol word))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4540 (if cperl-message-on-help-error
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4541 (message "Nothing found for %s..."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4542 (buffer-substring (point) (min (+ 5 (point)) (point-max))))))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4543
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4544 ;;; Stolen from perl-descr.el by Johan Vromans:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4545
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4546 (defvar cperl-doc-buffer " *perl-doc*"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4547 "Where the documentation can be found.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4548
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4549 (defun cperl-describe-perl-symbol (val)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4550 "Display the documentation of symbol at point, a Perl operator."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4551 (let ((enable-recursive-minibuffers t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4552 args-file regexp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4553 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4554 ((string-match "^[&*][a-zA-Z_]" val)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4555 (setq val (concat (substring val 0 1) "NAME")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4556 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4557 (setq val (concat "@" (substring val 1 (match-end 1)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4558 ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4559 (setq val (concat "%" (substring val 1 (match-end 1)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4560 ((and (string= val "x") (string-match "^x=" val))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4561 (setq val "x="))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4562 ((string-match "^\\$[\C-a-\C-z]" val)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4563 (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4564 ((string-match "^CORE::" val)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4565 (setq val "CORE::"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4566 ((string-match "^SUPER::" val)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4567 (setq val "SUPER::"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4568 ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4569 (setq val "<NAME>")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4570 (setq regexp (concat "^"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4571 "\\([^a-zA-Z0-9_:]+[ \t]+\\)?"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4572 (regexp-quote val)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4573 "\\([ \t([/]\\|$\\)"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4574
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4575 ;; get the buffer with the documentation text
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4576 (cperl-switch-to-doc-buffer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4577
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4578 ;; lookup in the doc
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4579 (goto-char (point-min))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4580 (let ((case-fold-search nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4581 (list
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4582 (if (re-search-forward regexp (point-max) t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4583 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4584 (beginning-of-line 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4585 (let ((lnstart (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4586 (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4587 (message "%s" (buffer-substring lnstart (point)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4588 (if cperl-message-on-help-error
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4589 (message "No definition for %s" val)))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4590
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4591 (defvar cperl-short-docs "Ignore my value"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4592 ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4593 "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4594 ! ... Logical negation.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4595 ... != ... Numeric inequality.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4596 ... !~ ... Search pattern, substitution, or translation (negated).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4597 $! In numeric context: errno. In a string context: error string.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4598 $\" The separator which joins elements of arrays interpolated in strings.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4599 $# The output format for printed numbers. Initial value is %.15g or close.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4600 $$ Process number of this script. Changes in the fork()ed child process.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4601 $% The current page number of the currently selected output channel.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4602
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4603 The following variables are always local to the current block:
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4604
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4605 $1 Match of the 1st set of parentheses in the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4606 $2 Match of the 2nd set of parentheses in the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4607 $3 Match of the 3rd set of parentheses in the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4608 $4 Match of the 4th set of parentheses in the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4609 $5 Match of the 5th set of parentheses in the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4610 $6 Match of the 6th set of parentheses in the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4611 $7 Match of the 7th set of parentheses in the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4612 $8 Match of the 8th set of parentheses in the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4613 $9 Match of the 9th set of parentheses in the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4614 $& The string matched by the last pattern match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4615 $' The string after what was matched by the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4616 $` The string before what was matched by the last match (auto-local).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4617
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4618 $( The real gid of this process.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4619 $) The effective gid of this process.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4620 $* Deprecated: Set to 1 to do multiline matching within a string.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4621 $+ The last bracket matched by the last search pattern.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4622 $, The output field separator for the print operator.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4623 $- The number of lines left on the page.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4624 $. The current input line number of the last filehandle that was read.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4625 $/ The input record separator, newline by default.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4626 $0 Name of the file containing the perl script being executed. May be set.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4627 $: String may be broken after these characters to fill ^-lines in a format.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4628 $; Subscript separator for multi-dim array emulation. Default \"\\034\".
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4629 $< The real uid of this process.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4630 $= The page length of the current output channel. Default is 60 lines.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4631 $> The effective uid of this process.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4632 $? The status returned by the last ``, pipe close or `system'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4633 $@ The perl error message from the last eval or do @var{EXPR} command.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4634 $ARGV The name of the current file used with <> .
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4635 $[ Deprecated: The index of the first element/char in an array/string.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4636 $\\ The output record separator for the print operator.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4637 $] The perl version string as displayed with perl -v.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4638 $^ The name of the current top-of-page format.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4639 $^A The current value of the write() accumulator for format() lines.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4640 $^D The value of the perl debug (-D) flags.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4641 $^E Information about the last system error other than that provided by $!.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4642 $^F The highest system file descriptor, ordinarily 2.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4643 $^H The current set of syntax checks enabled by `use strict'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4644 $^I The value of the in-place edit extension (perl -i option).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4645 $^L What formats output to perform a formfeed. Default is \f.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4646 $^O The operating system name under which this copy of Perl was built.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4647 $^P Internal debugging flag.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4648 $^T The time the script was started. Used by -A/-M/-C file tests.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4649 $^W True if warnings are requested (perl -w flag).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4650 $^X The name under which perl was invoked (argv[0] in C-speech).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4651 $_ The default input and pattern-searching space.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4652 $| Auto-flush after write/print on current output channel? Default 0.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4653 $~ The name of the current report format.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4654 ... % ... Modulo division.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4655 ... %= ... Modulo division assignment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4656 %ENV Contains the current environment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4657 %INC List of files that have been require-d or do-ne.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4658 %SIG Used to set signal handlers for various signals.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4659 ... & ... Bitwise and.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4660 ... && ... Logical and.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4661 ... &&= ... Logical and assignment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4662 ... &= ... Bitwise and assignment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4663 ... * ... Multiplication.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4664 ... ** ... Exponentiation.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4665 *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4666 &NAME(arg0, ...) Subroutine call. Arguments go to @_.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4667 ... + ... Addition. +EXPR Makes EXPR into scalar context.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4668 ++ Auto-increment (magical on strings). ++EXPR EXPR++
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4669 ... += ... Addition assignment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4670 , Comma operator.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4671 ... - ... Subtraction.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4672 -- Auto-decrement (NOT magical on strings). --EXPR EXPR--
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4673 ... -= ... Subtraction assignment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4674 -A Access time in days since script started.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4675 -B File is a non-text (binary) file.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4676 -C Inode change time in days since script started.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4677 -M Age in days since script started.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4678 -O File is owned by real uid.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4679 -R File is readable by real uid.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4680 -S File is a socket .
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4681 -T File is a text file.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4682 -W File is writable by real uid.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4683 -X File is executable by real uid.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4684 -b File is a block special file.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4685 -c File is a character special file.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4686 -d File is a directory.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4687 -e File exists .
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4688 -f File is a plain file.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4689 -g File has setgid bit set.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4690 -k File has sticky bit set.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4691 -l File is a symbolic link.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4692 -o File is owned by effective uid.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4693 -p File is a named pipe (FIFO).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4694 -r File is readable by effective uid.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4695 -s File has non-zero size.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4696 -t Tests if filehandle (STDIN by default) is opened to a tty.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4697 -u File has setuid bit set.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4698 -w File is writable by effective uid.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4699 -x File is executable by effective uid.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4700 -z File has zero size.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4701 . Concatenate strings.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4702 .. Alternation, also range operator.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4703 .= Concatenate assignment strings
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4704 ... / ... Division. /PATTERN/ioxsmg Pattern match
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4705 ... /= ... Division assignment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4706 /PATTERN/ioxsmg Pattern match.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4707 ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4708 <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4709 <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4710 <> Reads line from union of files in @ARGV (= command line) and STDIN.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4711 ... << ... Bitwise shift left. << start of HERE-DOCUMENT.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4712 ... <= ... Numeric less than or equal to.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4713 ... <=> ... Numeric compare.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4714 ... = ... Assignment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4715 ... == ... Numeric equality.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4716 ... =~ ... Search pattern, substitution, or translation
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4717 ... > ... Numeric greater than.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4718 ... >= ... Numeric greater than or equal to.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4719 ... >> ... Bitwise shift right.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4720 ... >>= ... Bitwise shift right assignment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4721 ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4722 ?PATTERN? One-time pattern match.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4723 @ARGV Command line arguments (not including the command name - see $0).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4724 @INC List of places to look for perl scripts during do/include/use.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4725 @_ Parameter array for subroutines. Also used by split unless in array context.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4726 \\ Creates reference to what follows, like \$var, or quotes non-\w in strings.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4727 \\0 Octal char, e.g. \\033.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4728 \\E Case modification terminator. See \\Q, \\L, and \\U.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4729 \\L Lowercase until \\E . See also \l, lc.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4730 \\U Upcase until \\E . See also \u, uc.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4731 \\Q Quote metacharacters until \\E . See also quotemeta.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4732 \\a Alarm character (octal 007).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4733 \\b Backspace character (octal 010).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4734 \\c Control character, e.g. \\c[ .
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4735 \\e Escape character (octal 033).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4736 \\f Formfeed character (octal 014).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4737 \\l Lowercase the next character. See also \\L and \\u, lcfirst.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4738 \\n Newline character (octal 012 on most systems).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4739 \\r Return character (octal 015 on most systems).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4740 \\t Tab character (octal 011).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4741 \\u Upcase the next character. See also \\U and \\l, ucfirst.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4742 \\x Hex character, e.g. \\x1b.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4743 ... ^ ... Bitwise exclusive or.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4744 __END__ Ends program source.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4745 __DATA__ Ends program source.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4746 __FILE__ Current (source) filename.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4747 __LINE__ Current line in current source.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4748 __PACKAGE__ Current package.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4749 ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4750 ARGVOUT Output filehandle with -i flag.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4751 BEGIN { ... } Immediately executed (during compilation) piece of code.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4752 END { ... } Pseudo-subroutine executed after the script finishes.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4753 DATA Input filehandle for what follows after __END__ or __DATA__.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4754 accept(NEWSOCKET,GENERICSOCKET)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4755 alarm(SECONDS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4756 atan2(X,Y)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4757 bind(SOCKET,NAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4758 binmode(FILEHANDLE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4759 caller[(LEVEL)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4760 chdir(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4761 chmod(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4762 chop[(LIST|VAR)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4763 chown(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4764 chroot(FILENAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4765 close(FILEHANDLE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4766 closedir(DIRHANDLE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4767 ... cmp ... String compare.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4768 connect(SOCKET,NAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4769 continue of { block } continue { block }. Is executed after `next' or at end.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4770 cos(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4771 crypt(PLAINTEXT,SALT)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4772 dbmclose(%HASH)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4773 dbmopen(%HASH,DBNAME,MODE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4774 defined(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4775 delete($HASH{KEY})
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4776 die(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4777 do { ... }|SUBR while|until EXPR executes at least once
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4778 do(EXPR|SUBR([LIST])) (with while|until executes at least once)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4779 dump LABEL
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4780 each(%HASH)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4781 endgrent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4782 endhostent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4783 endnetent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4784 endprotoent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4785 endpwent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4786 endservent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4787 eof[([FILEHANDLE])]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4788 ... eq ... String equality.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4789 eval(EXPR) or eval { BLOCK }
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4790 exec(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4791 exit(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4792 exp(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4793 fcntl(FILEHANDLE,FUNCTION,SCALAR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4794 fileno(FILEHANDLE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4795 flock(FILEHANDLE,OPERATION)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4796 for (EXPR;EXPR;EXPR) { ... }
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4797 foreach [VAR] (@ARRAY) { ... }
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4798 fork
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4799 ... ge ... String greater than or equal.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4800 getc[(FILEHANDLE)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4801 getgrent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4802 getgrgid(GID)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4803 getgrnam(NAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4804 gethostbyaddr(ADDR,ADDRTYPE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4805 gethostbyname(NAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4806 gethostent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4807 getlogin
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4808 getnetbyaddr(ADDR,ADDRTYPE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4809 getnetbyname(NAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4810 getnetent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4811 getpeername(SOCKET)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4812 getpgrp(PID)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4813 getppid
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4814 getpriority(WHICH,WHO)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4815 getprotobyname(NAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4816 getprotobynumber(NUMBER)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4817 getprotoent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4818 getpwent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4819 getpwnam(NAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4820 getpwuid(UID)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4821 getservbyname(NAME,PROTO)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4822 getservbyport(PORT,PROTO)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4823 getservent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4824 getsockname(SOCKET)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4825 getsockopt(SOCKET,LEVEL,OPTNAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4826 gmtime(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4827 goto LABEL
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4828 grep(EXPR,LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4829 ... gt ... String greater than.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4830 hex(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4831 if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4832 index(STR,SUBSTR[,OFFSET])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4833 int(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4834 ioctl(FILEHANDLE,FUNCTION,SCALAR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4835 join(EXPR,LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4836 keys(%HASH)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4837 kill(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4838 last [LABEL]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4839 ... le ... String less than or equal.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4840 length(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4841 link(OLDFILE,NEWFILE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4842 listen(SOCKET,QUEUESIZE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4843 local(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4844 localtime(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4845 log(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4846 lstat(EXPR|FILEHANDLE|VAR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4847 ... lt ... String less than.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4848 m/PATTERN/iogsmx
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4849 mkdir(FILENAME,MODE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4850 msgctl(ID,CMD,ARG)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4851 msgget(KEY,FLAGS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4852 msgrcv(ID,VAR,SIZE,TYPE.FLAGS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4853 msgsnd(ID,MSG,FLAGS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4854 my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4855 ... ne ... String inequality.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4856 next [LABEL]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4857 oct(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4858 open(FILEHANDLE[,EXPR])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4859 opendir(DIRHANDLE,EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4860 ord(EXPR) ASCII value of the first char of the string.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4861 pack(TEMPLATE,LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4862 package NAME Introduces package context.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4863 pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4864 pop(ARRAY)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4865 print [FILEHANDLE] [(LIST)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4866 printf [FILEHANDLE] (FORMAT,LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4867 push(ARRAY,LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4868 q/STRING/ Synonym for 'STRING'
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4869 qq/STRING/ Synonym for \"STRING\"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4870 qx/STRING/ Synonym for `STRING`
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4871 rand[(EXPR)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4872 read(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4873 readdir(DIRHANDLE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4874 readlink(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4875 recv(SOCKET,SCALAR,LEN,FLAGS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4876 redo [LABEL]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4877 rename(OLDNAME,NEWNAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4878 require [FILENAME | PERL_VERSION]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4879 reset[(EXPR)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4880 return(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4881 reverse(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4882 rewinddir(DIRHANDLE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4883 rindex(STR,SUBSTR[,OFFSET])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4884 rmdir(FILENAME)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4885 s/PATTERN/REPLACEMENT/gieoxsm
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4886 scalar(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4887 seek(FILEHANDLE,POSITION,WHENCE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4888 seekdir(DIRHANDLE,POS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4889 select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4890 semctl(ID,SEMNUM,CMD,ARG)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4891 semget(KEY,NSEMS,SIZE,FLAGS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4892 semop(KEY,...)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4893 send(SOCKET,MSG,FLAGS[,TO])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4894 setgrent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4895 sethostent(STAYOPEN)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4896 setnetent(STAYOPEN)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4897 setpgrp(PID,PGRP)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4898 setpriority(WHICH,WHO,PRIORITY)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4899 setprotoent(STAYOPEN)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4900 setpwent
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4901 setservent(STAYOPEN)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4902 setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4903 shift[(ARRAY)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4904 shmctl(ID,CMD,ARG)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4905 shmget(KEY,SIZE,FLAGS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4906 shmread(ID,VAR,POS,SIZE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4907 shmwrite(ID,STRING,POS,SIZE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4908 shutdown(SOCKET,HOW)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4909 sin(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4910 sleep[(EXPR)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4911 socket(SOCKET,DOMAIN,TYPE,PROTOCOL)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4912 socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4913 sort [SUBROUTINE] (LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4914 splice(ARRAY,OFFSET[,LENGTH[,LIST]])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4915 split[(/PATTERN/[,EXPR[,LIMIT]])]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4916 sprintf(FORMAT,LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4917 sqrt(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4918 srand(EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4919 stat(EXPR|FILEHANDLE|VAR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4920 study[(SCALAR)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4921 sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4922 substr(EXPR,OFFSET[,LEN])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4923 symlink(OLDFILE,NEWFILE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4924 syscall(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4925 sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4926 system(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4927 syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET])
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4928 tell[(FILEHANDLE)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4929 telldir(DIRHANDLE)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4930 time
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4931 times
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4932 tr/SEARCHLIST/REPLACEMENTLIST/cds
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4933 truncate(FILE|EXPR,LENGTH)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4934 umask[(EXPR)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4935 undef[(EXPR)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4936 unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4937 unlink(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4938 unpack(TEMPLATE,EXPR)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4939 unshift(ARRAY,LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4940 until (EXPR) { ... } EXPR until EXPR
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4941 utime(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4942 values(%HASH)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4943 vec(EXPR,OFFSET,BITS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4944 wait
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4945 waitpid(PID,FLAGS)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4946 wantarray Returns true if the sub/eval is called in list context.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4947 warn(LIST)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4948 while (EXPR) { ... } EXPR while EXPR
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4949 write[(EXPR|FILEHANDLE)]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4950 ... x ... Repeat string or array.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4951 x= ... Repetition assignment.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4952 y/SEARCHLIST/REPLACEMENTLIST/
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4953 ... | ... Bitwise or.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4954 ... || ... Logical or.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4955 ~ ... Unary bitwise complement.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4956 #! OS interpreter indicator. If has `perl', used for options, and -x.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4957 AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4958 CORE:: Prefix to access builtin function if imported sub obscures it.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4959 SUPER:: Prefix to lookup for a method in @ISA classes.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4960 DESTROY Shorthand for `sub DESTROY {...}'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4961 ... EQ ... Obsolete synonym of `eq'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4962 ... GE ... Obsolete synonym of `ge'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4963 ... GT ... Obsolete synonym of `gt'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4964 ... LE ... Obsolete synonym of `le'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4965 ... LT ... Obsolete synonym of `lt'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4966 ... NE ... Obsolete synonym of `ne'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4967 abs [ EXPR ] absolute value
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4968 ... and ... Low-precedence synonym for &&.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4969 bless REFERENCE [, PACKAGE] Makes reference into an object of a package.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4970 chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''!
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4971 chr Converts a number to char with the same ordinal.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4972 else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4973 elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4974 exists $HASH{KEY} True if the key exists.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4975 format [NAME] = Start of output format. Ended by a single dot (.) on a line.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4976 formline PICTURE, LIST Backdoor into \"format\" processing.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4977 glob EXPR Synonym of <EXPR>.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4978 lc [ EXPR ] Returns lowercased EXPR.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4979 lcfirst [ EXPR ] Returns EXPR with lower-cased first letter.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4980 map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4981 no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4982 not ... Low-precedence synonym for ! - negation.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4983 ... or ... Low-precedence synonym for ||.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4984 pos STRING Set/Get end-position of the last match over this string, see \\G.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4985 quotemeta [ EXPR ] Quote regexp metacharacters.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4986 qw/WORD1 .../ Synonym of split('', 'WORD1 ...')
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4987 readline FH Synonym of <FH>.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4988 readpipe CMD Synonym of `CMD`.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4989 ref [ EXPR ] Type of EXPR when dereferenced.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4990 sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4991 tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4992 tied Returns internal object for a tied data.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4993 uc [ EXPR ] Returns upcased EXPR.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4994 ucfirst [ EXPR ] Returns EXPR with upcased first letter.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4995 untie VAR Unlink an object from a simple Perl variable.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4996 use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4997 ... xor ... Low-precedence synonym for exclusive or.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4998 prototype \&SUB Returns prototype of the function given a reference.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4999 =head1 Top-level heading.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5000 =head2 Second-level heading.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5001 =head3 Third-level heading (is there such?).
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5002 =over [ NUMBER ] Start list.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5003 =item [ TITLE ] Start new item in the list.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5004 =back End list.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5005 =cut Switch from POD to Perl.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5006 =pod Switch from Perl to POD.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5007 ")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5008
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5009 (defun cperl-switch-to-doc-buffer ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5010 "Go to the perl documentation buffer and insert the documentation."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5011 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5012 (let ((buf (get-buffer-create cperl-doc-buffer)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5013 (if (interactive-p)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5014 (switch-to-buffer-other-window buf)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5015 (set-buffer buf))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5016 (if (= (buffer-size) 0)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5017 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5018 (insert (documentation-property 'cperl-short-docs
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5019 'variable-documentation))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5020 (setq buffer-read-only t)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5021
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5022 (defun cperl-beautify-regexp-piece (b e embed)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5023 ;; b is before the starting delimiter, e before the ending
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5024 ;; e should be a marker, may be changed, but remains "correct".
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5025 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5026 (if (not embed)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5027 (goto-char (1+ b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5028 (goto-char b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5029 (cond ((looking-at "(\\?\\\\#") ; badly commented (?#)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5030 (forward-char 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5031 (delete-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5032 (forward-char 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5033 ((looking-at "(\\?[^a-zA-Z]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5034 (forward-char 3))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5035 ((looking-at "(\\?") ; (?i)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5036 (forward-char 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5037 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5038 (forward-char 1))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5039 (setq c (if embed (current-indentation) (1- (current-column)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5040 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5041 (or (looking-at "[ \t]*[\n#]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5042 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5043 (insert "\n")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5044 (goto-char e)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5045 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5046 (if (re-search-forward "[^ \t]" e t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5047 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5048 (goto-char e)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5049 (insert "\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5050 (indent-to-column c)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5051 (set-marker e (point))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5052 (goto-char b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5053 (end-of-line 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5054 (while (< (point) (marker-position e))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5055 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5056 (setq s (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5057 inline t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5058 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5059 (delete-region s (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5060 (indent-to-column c1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5061 (while (and
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5062 inline
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5063 (looking-at
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5064 (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5065 "\\|" ; Embedded variable
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5066 "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5067 "\\|" ; $ ^
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5068 "[$^]"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5069 "\\|" ; simple-code simple-code*?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5070 "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5071 "\\|" ; Class
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5072 "\\(\\[\\)" ; 6
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5073 "\\|" ; Grouping
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5074 "\\((\\(\\?\\)?\\)" ; 7 8
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5075 "\\|" ; |
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5076 "\\(|\\)" ; 9
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5077 )))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5078 (goto-char (match-end 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5079 (setq spaces t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5080 (cond ((match-beginning 1) ; Alphanum word + junk
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5081 (forward-char -1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5082 ((or (match-beginning 3) ; $ab[12]
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5083 (and (match-beginning 5) ; X* X+ X{2,3}
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5084 (eq (preceding-char) ?\{)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5085 (forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5086 (forward-sexp 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5087 ((match-beginning 6) ; []
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5088 (setq tmp (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5089 (if (looking-at "\\^?\\]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5090 (goto-char (match-end 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5091 (or (re-search-forward "\\]\\([*+{?]\\)?" e t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5092 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5093 (goto-char (1- tmp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5094 (error "[]-group not terminated")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5095 (if (not (eq (preceding-char) ?\{)) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5096 (forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5097 (forward-sexp 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5098 ((match-beginning 7) ; ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5099 (goto-char (match-beginning 0))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5100 (or (eq (current-column) c1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5101 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5102 (insert "\n")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5103 (indent-to-column c1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5104 (setq tmp (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5105 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5106 ;; (or (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5107 ;; (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5108 ;; (goto-char tmp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5109 ;; (error "()-group not terminated")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5110 (set-marker m (1- (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5111 (set-marker m1 (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5112 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5113 ((not (match-beginning 8))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5114 (cperl-beautify-regexp-piece tmp m t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5115 ((eq (char-after (+ 2 tmp)) ?\{) ; Code
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5116 t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5117 ((eq (char-after (+ 2 tmp)) ?\() ; Conditional
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5118 (goto-char (+ 2 tmp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5119 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5120 (cperl-beautify-regexp-piece (point) m t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5121 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5122 (cperl-beautify-regexp-piece tmp m t)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5123 (goto-char m1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5124 (cond ((looking-at "[*+?]\\??")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5125 (goto-char (match-end 0)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5126 ((eq (following-char) ?\{)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5127 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5128 (if (eq (following-char) ?\?)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5129 (forward-char))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5130 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5131 (setq spaces nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5132 (if (looking-at "[#\n]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5133 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5134 (or (eolp) (indent-for-comment))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5135 (beginning-of-line 2))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5136 (insert "\n"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5137 (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5138 (setq inline nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5139 ((match-beginning 9) ; |
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5140 (forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5141 (setq tmp (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5142 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5143 (if (re-search-forward "[^ \t]" tmp t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5144 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5145 (goto-char tmp)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5146 (insert "\n"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5147 ;; first at line
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5148 (delete-region (point) tmp))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5149 (indent-to-column c)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5150 (forward-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5151 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5152 (setq spaces nil)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5153 (if (looking-at "[#\n]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5154 (beginning-of-line 2)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5155 (insert "\n"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5156 (end-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5157 (setq inline nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5158 (or (looking-at "[ \t\n]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5159 (not spaces)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5160 (insert " "))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5161 (skip-chars-forward " \t"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5162 (or (looking-at "[#\n]")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5163 (error "unknown code \"%s\" in a regexp" (buffer-substring (point)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5164 (1+ (point)))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5165 (and inline (end-of-line 2)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5166 ;; Special-case the last line of group
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5167 (if (and (>= (point) (marker-position e))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5168 (/= (current-indentation) c))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5169 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5170 (beginning-of-line)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5171 (setq s (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5172 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5173 (delete-region s (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5174 (indent-to-column c)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5175 ))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5176
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5177 (defun cperl-make-regexp-x ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5178 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5179 (or cperl-use-syntax-table-text-property
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5180 (error "I need to have regex marked!"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5181 ;; Find the start
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5182 (re-search-backward "\\s|") ; Assume it is scanned already.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5183 ;;(forward-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5184 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5185 (sub-p (eq (preceding-char) ?s)) s)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5186 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5187 (set-marker e (1- (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5188 (setq delim (preceding-char))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5189 (if (and sub-p (eq delim (char-after (- (point) 2))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5190 (error "Possible s/blah// - do not know how to deal with"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5191 (if sub-p (forward-sexp 1))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5192 (if (looking-at "\\sw*x")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5193 (setq have-x t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5194 (insert "x"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5195 ;; Protect fragile " ", "#"
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5196 (if have-x nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5197 (goto-char (1+ b))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5198 (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too?
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5199 (forward-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5200 (insert "\\")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5201 (forward-char 1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5202 b)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5203
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5204 (defun cperl-beautify-regexp ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5205 "do it. (Experimental, may change semantics, recheck the result.)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5206 We suppose that the regexp is scanned already."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5207 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5208 (cperl-make-regexp-x)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5209 (re-search-backward "\\s|") ; Assume it is scanned already.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5210 ;;(forward-char 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5211 (let ((b (point)) (e (make-marker)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5212 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5213 (set-marker e (1- (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5214 (cperl-beautify-regexp-piece b e nil)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5215
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5216 (defun cperl-contract-level ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5217 "Find an enclosing group in regexp and contract it. Unfinished.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5218 \(Experimental, may change semantics, recheck the result.)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5219 We suppose that the regexp is scanned already."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5220 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5221 (let ((bb (cperl-make-regexp-x)) done)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5222 (while (not done)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5223 (or (eq (following-char) ?\()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5224 (search-backward "(" (1+ bb) t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5225 (error "Cannot find `(' which starts a group"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5226 (setq done
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5227 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5228 (skip-chars-backward "\\")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5229 (looking-at "\\(\\\\\\\\\\)*(")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5230 (or done (forward-char -1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5231 (let ((b (point)) (e (make-marker)) s c)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5232 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5233 (set-marker e (1- (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5234 (goto-char b)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5235 (while (re-search-forward "\\(#\\)\\|\n" e t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5236 (cond
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5237 ((match-beginning 1) ; #-comment
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5238 (or c (setq c (current-indentation)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5239 (beginning-of-line 2) ; Skip
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5240 (setq s (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5241 (skip-chars-forward " \t")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5242 (delete-region s (point))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5243 (indent-to-column c))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5244 (t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5245 (delete-char -1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5246 (just-one-space)))))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5247
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5248 (defun cperl-beautify-level ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5249 "Find an enclosing group in regexp and beautify it.
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5250 \(Experimental, may change semantics, recheck the result.)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5251 We suppose that the regexp is scanned already."
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5252 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5253 (let ((bb (cperl-make-regexp-x)) done)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5254 (while (not done)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5255 (or (eq (following-char) ?\()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5256 (search-backward "(" (1+ bb) t)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5257 (error "Cannot find `(' which starts a group"))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5258 (setq done
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5259 (save-excursion
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5260 (skip-chars-backward "\\")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5261 (looking-at "\\(\\\\\\\\\\)*(")))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5262 (or done (forward-char -1)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5263 (let ((b (point)) (e (make-marker)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5264 (forward-sexp 1)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5265 (set-marker e (1- (point)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5266 (cperl-beautify-regexp-piece b e nil))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5267
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5268 (if (fboundp 'run-with-idle-timer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5269 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5270 (defvar cperl-help-shown nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5271 "Non-nil means that the help was already shown now.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5272
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5273 (defvar cperl-lazy-installed nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5274 "Non-nil means that the lazy-help handlers are installed now.")
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5275
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5276 (defun cperl-lazy-install ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5277 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5278 (make-variable-buffer-local 'cperl-help-shown)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5279 (if (and (cperl-val 'cperl-lazy-help-time)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5280 (not cperl-lazy-installed))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5281 (progn
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5282 (add-hook 'post-command-hook 'cperl-lazy-hook)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5283 (run-with-idle-timer
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5284 (cperl-val 'cperl-lazy-help-time 1000000 5)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5285 t
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5286 'cperl-get-help-defer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5287 (setq cperl-lazy-installed t))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5288
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5289 (defun cperl-lazy-unstall ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5290 (interactive)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5291 (remove-hook 'post-command-hook 'cperl-lazy-hook)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5292 (cancel-function-timers 'cperl-get-help-defer)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5293 (setq cperl-lazy-installed nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5294
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5295 (defun cperl-lazy-hook ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5296 (setq cperl-help-shown nil))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5297
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5298 (defun cperl-get-help-defer ()
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5299 (if (not (eq major-mode 'perl-mode)) nil
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5300 (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5301 (cperl-get-help)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5302 (setq cperl-help-shown t))))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5303 (cperl-lazy-install)))
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5304
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5305 (provide 'cperl-mode)
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5306
eae9c49831e4 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5307 ;;; cperl-mode.el ends here