Backslash cleanup in Elisp source files
[emacs.git] / lisp / progmodes / perl-mode.el
blob55d69bfddff44d844ce01f1270adf7249c64c15f
1 ;;; perl-mode.el --- Perl code editing commands for GNU Emacs -*- lexical-binding:t -*-
3 ;; Copyright (C) 1990, 1994, 2001-2015 Free Software Foundation, Inc.
5 ;; Author: William F. Mann
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Adapted-By: ESR
8 ;; Keywords: languages
10 ;; Adapted from C code editing commands 'c-mode.el', Copyright 1987 by the
11 ;; Free Software Foundation, under terms of its General Public License.
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;;; Commentary:
30 ;; To enter perl-mode automatically, add (autoload 'perl-mode "perl-mode")
31 ;; to your init file and change the first line of your perl script to:
32 ;; #!/usr/bin/perl -- # -*-Perl-*-
33 ;; With arguments to perl:
34 ;; #!/usr/bin/perl -P- # -*-Perl-*-
35 ;; To handle files included with do 'filename.pl';, add something like
36 ;; (setq auto-mode-alist (append (list (cons "\\.pl\\'" 'perl-mode))
37 ;; auto-mode-alist))
38 ;; to your init file; otherwise the .pl suffix defaults to prolog-mode.
40 ;; This code is based on the 18.53 version c-mode.el, with extensive
41 ;; rewriting. Most of the features of c-mode survived intact.
43 ;; I added a new feature which adds functionality to TAB; it is controlled
44 ;; by the variable perl-tab-to-comment. With it enabled, TAB does the
45 ;; first thing it can from the following list: change the indentation;
46 ;; move past leading white space; delete an empty comment; reindent a
47 ;; comment; move to end of line; create an empty comment; tell you that
48 ;; the line ends in a quoted string, or has a # which should be a \#.
50 ;; If your machine is slow, you may want to remove some of the bindings
51 ;; to perl-electric-terminator. I changed the indenting defaults to be
52 ;; what Larry Wall uses in perl/lib, but left in all the options.
54 ;; I also tuned a few things: comments and labels starting in column
55 ;; zero are left there by perl-indent-exp; perl-beginning-of-function
56 ;; goes back to the first open brace/paren in column zero, the open brace
57 ;; in 'sub ... {', or the equal sign in 'format ... ='; perl-indent-exp
58 ;; (meta-^q) indents from the current line through the close of the next
59 ;; brace/paren, so you don't need to start exactly at a brace or paren.
61 ;; It may be good style to put a set of redundant braces around your
62 ;; main program. This will let you reindent it with meta-^q.
64 ;; Known problems (these are all caused by limitations in the Emacs Lisp
65 ;; parsing routine (parse-partial-sexp), which was not designed for such
66 ;; a rich language; writing a more suitable parser would be a big job):
67 ;; 2) The globbing syntax <pattern> is not recognized, so special
68 ;; characters in the pattern string must be backslashed.
70 ;; Here are some ugly tricks to bypass some of these problems: the perl
71 ;; expression /`/ (that's a back-tick) usually evaluates harmlessly,
72 ;; but will trick perl-mode into starting a quoted string, which
73 ;; can be ended with another /`/. Assuming you have no embedded
74 ;; back-ticks, this can used to help solve problem 3:
76 ;; /`/; $ugly = q?"'$?; /`/;
78 ;; The same trick can be used for problem 6 as in:
79 ;; /{/; while (<${glob_me}>)
80 ;; but a simpler solution is to add a space between the $ and the {:
81 ;; while (<$ {glob_me}>)
83 ;; Problem 7 is even worse, but this 'fix' does work :-(
84 ;; $DB'stop#'
85 ;; [$DB'line#'
86 ;; ] =~ s/;9$//;
88 ;;; Code:
90 (defgroup perl nil
91 "Major mode for editing Perl code."
92 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
93 :prefix "perl-"
94 :group 'languages)
96 (defvar perl-mode-abbrev-table nil
97 "Abbrev table in use in perl-mode buffers.")
98 (define-abbrev-table 'perl-mode-abbrev-table ())
100 (defvar perl-mode-map
101 (let ((map (make-sparse-keymap)))
102 (define-key map "\e\C-a" 'perl-beginning-of-function)
103 (define-key map "\e\C-e" 'perl-end-of-function)
104 (define-key map "\e\C-h" 'perl-mark-function)
105 (define-key map "\e\C-q" 'perl-indent-exp)
106 (define-key map "\177" 'backward-delete-char-untabify)
107 map)
108 "Keymap used in Perl mode.")
110 (defvar perl-mode-syntax-table
111 (let ((st (make-syntax-table (standard-syntax-table))))
112 (modify-syntax-entry ?\n ">" st)
113 (modify-syntax-entry ?# "<" st)
114 ;; `$' is also a prefix char so I was tempted to say "/ p",
115 ;; but the `p' thingy basically overrides the `/' :-( -- Stef
116 (modify-syntax-entry ?$ "/" st)
117 (modify-syntax-entry ?% ". p" st)
118 (modify-syntax-entry ?@ ". p" st)
119 (modify-syntax-entry ?& "." st)
120 (modify-syntax-entry ?\' "\"" st)
121 (modify-syntax-entry ?* "." st)
122 (modify-syntax-entry ?+ "." st)
123 (modify-syntax-entry ?- "." st)
124 (modify-syntax-entry ?/ "." st)
125 (modify-syntax-entry ?< "." st)
126 (modify-syntax-entry ?= "." st)
127 (modify-syntax-entry ?> "." st)
128 (modify-syntax-entry ?\\ "\\" st)
129 (modify-syntax-entry ?` "\"" st)
130 (modify-syntax-entry ?| "." st)
132 "Syntax table in use in `perl-mode' buffers.")
134 (defvar perl-imenu-generic-expression
135 '(;; Functions
136 (nil "^[ \t]*sub\\s-+\\([-[:alnum:]+_:]+\\)" 1)
137 ;;Variables
138 ("Variables" "^\\(?:my\\|our\\)\\s-+\\([$@%][-[:alnum:]+_:]+\\)\\s-*=" 1)
139 ("Packages" "^[ \t]*package\\s-+\\([-[:alnum:]+_:]+\\);" 1)
140 ("Doc sections" "^=head[0-9][ \t]+\\(.*\\)" 1))
141 "Imenu generic expression for Perl mode. See `imenu-generic-expression'.")
143 ;; Regexps updated with help from Tom Tromey <tromey@cambric.colorado.edu> and
144 ;; Jim Campbell <jec@murzim.ca.boeing.com>.
146 (defconst perl--prettify-symbols-alist
147 '(("->" . ?→)
148 ("=>" . ?⇒)
149 ("::" . ?∷)))
151 (defconst perl-font-lock-keywords-1
152 '(;; What is this for?
153 ;;("\\(--- .* ---\\|=== .* ===\\)" . font-lock-string-face)
155 ;; Fontify preprocessor statements as we do in `c-font-lock-keywords'.
156 ;; Ilya Zakharevich <ilya@math.ohio-state.edu> thinks this is a bad idea.
157 ;; ("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face)
158 ;; ("^#[ \t]*define[ \t]+\\(\\sw+\\)(" 1 font-lock-function-name-face)
159 ;; ("^#[ \t]*if\\>"
160 ;; ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
161 ;; (1 font-lock-constant-face) (2 font-lock-variable-name-face nil t)))
162 ;; ("^#[ \t]*\\(\\sw+\\)\\>[ \t]*\\(\\sw+\\)?"
163 ;; (1 font-lock-constant-face) (2 font-lock-variable-name-face nil t))
165 ;; Fontify function and package names in declarations.
166 ("\\<\\(package\\|sub\\)\\>[ \t]*\\(\\sw+\\)?"
167 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
168 ("\\<\\(import\\|no\\|require\\|use\\)\\>[ \t]*\\(\\sw+\\)?"
169 (1 font-lock-keyword-face) (2 font-lock-constant-face nil t)))
170 "Subdued level highlighting for Perl mode.")
172 (defconst perl-font-lock-keywords-2
173 (append
174 perl-font-lock-keywords-1
175 `( ;; Fontify keywords, except those fontified otherwise.
176 ,(concat "\\<"
177 (regexp-opt '("if" "until" "while" "elsif" "else" "unless"
178 "do" "dump" "for" "foreach" "exit" "die"
179 "BEGIN" "END" "return" "exec" "eval") t)
180 "\\>")
182 ;; Fontify local and my keywords as types.
183 ("\\<\\(local\\|my\\)\\>" . font-lock-type-face)
185 ;; Fontify function, variable and file name references.
186 ("&\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-function-name-face)
187 ;; Additionally underline non-scalar variables. Maybe this is a bad idea.
188 ;;'("[$@%*][#{]?\\(\\sw+\\)" 1 font-lock-variable-name-face)
189 ("[$*]{?\\(\\sw+\\(::\\sw+\\)*\\)" 1 font-lock-variable-name-face)
190 ("\\([@%]\\|\\$#\\)\\(\\sw+\\(::\\sw+\\)*\\)"
191 (2 (cons font-lock-variable-name-face '(underline))))
192 ("<\\(\\sw+\\)>" 1 font-lock-constant-face)
194 ;; Fontify keywords with/and labels as we do in `c++-font-lock-keywords'.
195 ("\\<\\(continue\\|goto\\|last\\|next\\|redo\\)\\>[ \t]*\\(\\sw+\\)?"
196 (1 font-lock-keyword-face) (2 font-lock-constant-face nil t))
197 ("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-constant-face)))
198 "Gaudy level highlighting for Perl mode.")
200 (defvar perl-font-lock-keywords perl-font-lock-keywords-1
201 "Default expressions to highlight in Perl mode.")
203 (defvar perl-quote-like-pairs
204 '((?\( . ?\)) (?\[ . ?\]) (?\{ . ?\}) (?\< . ?\>)))
206 (eval-and-compile
207 (defconst perl--syntax-exp-intro-keywords
208 '("split" "if" "unless" "until" "while" "print"
209 "grep" "map" "not" "or" "and" "for" "foreach"))
211 (defconst perl--syntax-exp-intro-regexp
212 (concat "\\(?:\\(?:^\\|[^$@&%[:word:]]\\)"
213 (regexp-opt perl--syntax-exp-intro-keywords)
214 "\\|[-?:.,;|&+*=!~({[]\\|\\(^\\)\\)[ \t\n]*")))
216 ;; FIXME: handle here-docs and regexps.
217 ;; <<EOF <<"EOF" <<'EOF' (no space)
218 ;; see `man perlop'
219 ;; ?...?
220 ;; /.../
221 ;; m [...]
222 ;; m /.../
223 ;; q /.../ = '...'
224 ;; qq /.../ = "..."
225 ;; qx /.../ = `...`
226 ;; qr /.../ = precompiled regexp =~=~ m/.../
227 ;; qw /.../
228 ;; s /.../.../
229 ;; s <...> /.../
230 ;; s '...'...'
231 ;; tr /.../.../
232 ;; y /.../.../
234 ;; <file*glob>
235 (defun perl-syntax-propertize-function (start end)
236 (let ((case-fold-search nil))
237 (goto-char start)
238 (perl-syntax-propertize-special-constructs end)
239 (funcall
240 (syntax-propertize-rules
241 ;; Turn POD into b-style comments. Place the cut rule first since it's
242 ;; more specific.
243 ("^=cut\\>.*\\(\n\\)" (1 "> b"))
244 ("^\\(=\\)\\sw" (1 "< b"))
245 ;; Catch ${ so that ${var} doesn't screw up indentation.
246 ;; This also catches $' to handle 'foo$', although it should really
247 ;; check that it occurs inside a '..' string.
248 ("\\(\\$\\)[{']" (1 (unless (and (eq ?\' (char-after (match-end 1)))
249 (save-excursion
250 (not (nth 3 (syntax-ppss
251 (match-beginning 0))))))
252 (string-to-syntax ". p"))))
253 ;; Handle funny names like $DB'stop.
254 ("\\$ ?{?^?[_[:alpha:]][_[:alnum:]]*\\('\\)[_[:alpha:]]" (1 "_"))
255 ;; format statements
256 ("^[ \t]*format.*=[ \t]*\\(\n\\)"
257 (1 (prog1 "\"" (perl-syntax-propertize-special-constructs end))))
258 ;; Funny things in `sub' arg-specs like `sub myfun ($)' or `sub ($)'.
259 ;; Be careful not to match "sub { (...) ... }".
260 ("\\<sub\\(?:[\s\t\n]+\\(?:\\sw\\|\\s_\\)+\\)?[\s\t\n]*(\\([^)]+\\))"
261 (1 "."))
262 ;; Turn __DATA__ trailer into a comment.
263 ("^\\(_\\)_\\(?:DATA\\|END\\)__[ \t]*\\(?:\\(\n\\)#.-\\*-.*perl.*-\\*-\\|\n.*\\)"
264 (1 "< c") (2 "> c")
265 (0 (ignore (put-text-property (match-beginning 0) (match-end 0)
266 'syntax-multiline t))))
267 ;; Regexp and funny quotes. Distinguishing a / that starts a regexp
268 ;; match from the division operator is ...interesting.
269 ;; Basically, / is a regexp match if it's preceded by an infix operator
270 ;; (or some similar separator), or by one of the special keywords
271 ;; corresponding to builtin functions that can take their first arg
272 ;; without parentheses. Of course, that presume we're looking at the
273 ;; *opening* slash. We can afford to mis-match the closing ones
274 ;; here, because they will be re-treated separately later in
275 ;; perl-font-lock-special-syntactic-constructs.
276 ((concat perl--syntax-exp-intro-regexp "\\(/\\)")
277 (2 (ignore
278 (if (and (match-end 1) ; / at BOL.
279 (save-excursion
280 (goto-char (match-end 1))
281 (forward-comment (- (point-max)))
282 (put-text-property (point) (match-end 2)
283 'syntax-multiline t)
284 (not (or (and (eq ?w (char-syntax (preceding-char)))
285 (let ((end (point)))
286 (backward-sexp 1)
287 (member (buffer-substring (point) end)
288 perl--syntax-exp-intro-keywords)))
289 (memq (char-before)
290 '(?? ?: ?. ?, ?\; ?= ?! ?~ ?\( ?\[))))))
291 nil ;; A division sign instead of a regexp-match.
292 (put-text-property (match-beginning 2) (match-end 2)
293 'syntax-table (string-to-syntax "\""))
294 (perl-syntax-propertize-special-constructs end)))))
295 ("\\(^\\|[?:.,;=!~({[ \t]\\)\\([msy]\\|q[qxrw]?\\|tr\\)\\>\\s-*\\(?:\\([^])}>= \n\t]\\)\\|\\(?3:=\\)[^>]\\)"
296 ;; Nasty cases:
297 ;; /foo/m $a->m $#m $m @m %m
298 ;; \s (appears often in regexps).
299 ;; -s file
300 ;; y => 3
301 ;; sub tr {...}
302 (3 (ignore
303 (if (save-excursion (goto-char (match-beginning 0))
304 (forward-word -1)
305 (looking-at-p "sub[ \t\n]"))
306 ;; This is defining a function.
308 (unless (nth 8 (save-excursion (syntax-ppss (match-beginning 1))))
309 ;; Don't add this syntax-table property if
310 ;; within a string, which would misbehave in cases such as
311 ;; $a = "foo y \"toto\" bar" where we'd end up changing the
312 ;; syntax of the backslash and hence de-escaping the embedded
313 ;; double quote.
314 (put-text-property (match-beginning 3) (match-end 3)
315 'syntax-table
316 (if (assoc (char-after (match-beginning 3))
317 perl-quote-like-pairs)
318 (string-to-syntax "|")
319 (string-to-syntax "\"")))
320 (perl-syntax-propertize-special-constructs end))))))
321 ;; Here documents.
322 ((concat
323 "\\(?:"
324 ;; << "EOF", << 'EOF', or << \EOF
325 "<<[ \t]*\\('[^'\n]*'\\|\"[^\"\n]*\"\\|\\\\[[:alpha:]][[:alnum:]]*\\)"
326 ;; The <<EOF case which needs perl--syntax-exp-intro-regexp, to
327 ;; disambiguate with the left-bitshift operator.
328 "\\|" perl--syntax-exp-intro-regexp "<<\\(?1:\\sw+\\)\\)"
329 ".*\\(\n\\)")
330 (3 (let* ((st (get-text-property (match-beginning 3) 'syntax-table))
331 (name (match-string 1)))
332 (goto-char (match-end 1))
333 (if (save-excursion (nth 8 (syntax-ppss (match-beginning 0))))
334 ;; Leave the property of the newline unchanged.
336 (cons (car (string-to-syntax "< c"))
337 ;; Remember the names of heredocs found on this line.
338 (cons (pcase (aref name 0)
339 (`?\\ (substring name 1))
340 ((or `?\" `?\' `?\`) (substring name 1 -1))
341 (_ name))
342 (cdr st)))))))
343 ;; We don't call perl-syntax-propertize-special-constructs directly
344 ;; from the << rule, because there might be other elements (between
345 ;; the << and the \n) that need to be propertized.
346 ("\\(?:$\\)\\s<"
347 (0 (ignore (perl-syntax-propertize-special-constructs end))))
349 (point) end)))
351 (defvar perl-empty-syntax-table
352 (let ((st (copy-syntax-table)))
353 ;; Make all chars be of punctuation syntax.
354 (dotimes (i 256) (aset st i '(1)))
355 (modify-syntax-entry ?\\ "\\" st)
357 "Syntax table used internally for processing quote-like operators.")
359 (defun perl-quote-syntax-table (char)
360 (let ((close (cdr (assq char perl-quote-like-pairs)))
361 (st (copy-syntax-table perl-empty-syntax-table)))
362 (if (not close)
363 (modify-syntax-entry char "\"" st)
364 (modify-syntax-entry char "(" st)
365 (modify-syntax-entry close ")" st))
366 st))
368 (defun perl-syntax-propertize-special-constructs (limit)
369 "Propertize special constructs like regexps and formats."
370 (let ((state (syntax-ppss))
371 char)
372 (cond
373 ((eq 2 (nth 7 state))
374 ;; A Here document.
375 (let ((names (cdr (get-text-property (nth 8 state) 'syntax-table))))
376 (when (cdr names)
377 (setq names (reverse names))
378 ;; Multiple heredocs on a single line, we have to search from the
379 ;; beginning, since we don't know which names might be
380 ;; before point.
381 (goto-char (nth 8 state)))
382 (while (and names
383 (re-search-forward
384 (concat "^" (regexp-quote (pop names)) "\n")
385 limit 'move))
386 (unless names
387 (put-text-property (1- (point)) (point) 'syntax-table
388 (string-to-syntax "> c"))))))
389 ((or (null (setq char (nth 3 state)))
390 (and (characterp char) (eq (char-syntax (nth 3 state)) ?\")))
391 ;; Normal text, or comment, or docstring, or normal string.
392 nil)
393 ((eq (nth 3 state) ?\n)
394 ;; A `format' command.
395 (when (re-search-forward "^\\s *\\.\\s *\n" limit 'move)
396 (put-text-property (1- (point)) (point)
397 'syntax-table (string-to-syntax "\""))))
399 ;; This is regexp like quote thingy.
400 (setq char (char-after (nth 8 state)))
401 (let ((startpos (point))
402 (twoargs (save-excursion
403 (goto-char (nth 8 state))
404 (skip-syntax-backward " ")
405 (skip-syntax-backward "w")
406 (member (buffer-substring
407 (point) (progn (forward-word 1) (point)))
408 '("tr" "s" "y"))))
409 (close (cdr (assq char perl-quote-like-pairs)))
410 (st (perl-quote-syntax-table char)))
411 (when (with-syntax-table st
412 (if close
413 ;; For paired delimiters, Perl allows nesting them, but
414 ;; since we treat them as strings, Emacs does not count
415 ;; those delimiters in `state', so we don't know how deep
416 ;; we are: we have to go back to the beginning of this
417 ;; "string" and count from there.
418 (condition-case nil
419 (progn
420 ;; Start after the first char since it doesn't have
421 ;; paren-syntax (an alternative would be to let-bind
422 ;; parse-sexp-lookup-properties).
423 (goto-char (1+ (nth 8 state)))
424 (up-list 1)
426 ;; In case of error, make sure we don't move backward.
427 (scan-error (goto-char startpos) nil))
428 (not (or (nth 8 (parse-partial-sexp
429 ;; Since we don't know if point is within
430 ;; the first or the scond arg, we have to
431 ;; start from the beginning.
432 (if twoargs (1+ (nth 8 state)) (point))
433 limit nil nil state 'syntax-table))
434 ;; If we have a self-paired opener and a twoargs
435 ;; command, the form is s/../../ so we have to skip
436 ;; a second time.
437 ;; In the case of s{...}{...}, we only handle the
438 ;; first part here and the next below.
439 (when (and twoargs (not close))
440 (nth 8 (parse-partial-sexp
441 (point) limit
442 nil nil state 'syntax-table)))))))
443 ;; Point is now right after the arg(s).
444 (when (eq (char-before (1- (point))) ?$)
445 (put-text-property (- (point) 2) (1- (point))
446 'syntax-table '(1)))
447 (put-text-property (1- (point)) (point)
448 'syntax-table
449 (if close
450 (string-to-syntax "|")
451 (string-to-syntax "\"")))
452 ;; If we have two args with a non-self-paired starter (e.g.
453 ;; s{...}{...}) we're right after the first arg, so we still have to
454 ;; handle the second part.
455 (when (and twoargs close)
456 ;; Skip whitespace and make sure that font-lock will
457 ;; refontify the second part in the proper context.
458 (put-text-property
459 (point) (progn (forward-comment (point-max)) (point))
460 'syntax-multiline t)
462 (when (< (point) limit)
463 (put-text-property (point) (1+ (point))
464 'syntax-table
465 (if (assoc (char-after)
466 perl-quote-like-pairs)
467 ;; Put an `e' in the cdr to mark this
468 ;; char as "second arg starter".
469 (string-to-syntax "|e")
470 (string-to-syntax "\"e")))
471 (forward-char 1)
472 ;; Re-use perl-syntax-propertize-special-constructs to handle the
473 ;; second part (the first delimiter of second part can't be
474 ;; preceded by "s" or "tr" or "y", so it will not be considered
475 ;; as twoarg).
476 (perl-syntax-propertize-special-constructs limit)))))))))
478 (defun perl-font-lock-syntactic-face-function (state)
479 (cond
480 ((and (nth 3 state)
481 (eq ?e (cdr-safe (get-text-property (nth 8 state) 'syntax-table)))
482 ;; This is a second-arg of s{..}{...} form; let's check if this second
483 ;; arg is executable code rather than a string. For that, we need to
484 ;; look for an "e" after this second arg, so we have to hunt for the
485 ;; end of the arg. Depending on whether the whole arg has already
486 ;; been syntax-propertized or not, the end-char will have different
487 ;; syntaxes, so let's ignore syntax-properties temporarily so we can
488 ;; pretend it has not been syntax-propertized yet.
489 (let* ((parse-sexp-lookup-properties nil)
490 (char (char-after (nth 8 state)))
491 (paired (assq char perl-quote-like-pairs)))
492 (with-syntax-table (perl-quote-syntax-table char)
493 (save-excursion
494 (if (not paired)
495 (parse-partial-sexp (point) (point-max)
496 nil nil state 'syntax-table)
497 (condition-case nil
498 (progn
499 (goto-char (1+ (nth 8 state)))
500 (up-list 1))
501 (scan-error (goto-char (point-max)))))
502 (put-text-property (nth 8 state) (point)
503 'jit-lock-defer-multiline t)
504 (looking-at "[ \t]*\\sw*e")))))
505 nil)
506 (t (funcall (default-value 'font-lock-syntactic-face-function) state))))
508 (defcustom perl-indent-level 4
509 "Indentation of Perl statements with respect to containing block."
510 :type 'integer)
512 ;; Is is not unusual to put both things like perl-indent-level and
513 ;; cperl-indent-level in the local variable section of a file. If only
514 ;; one of perl-mode and cperl-mode is in use, a warning will be issued
515 ;; about the variable. Autoload these here, so that no warning is
516 ;; issued when using either perl-mode or cperl-mode.
517 ;;;###autoload(put 'perl-indent-level 'safe-local-variable 'integerp)
518 ;;;###autoload(put 'perl-continued-statement-offset 'safe-local-variable 'integerp)
519 ;;;###autoload(put 'perl-continued-brace-offset 'safe-local-variable 'integerp)
520 ;;;###autoload(put 'perl-brace-offset 'safe-local-variable 'integerp)
521 ;;;###autoload(put 'perl-brace-imaginary-offset 'safe-local-variable 'integerp)
522 ;;;###autoload(put 'perl-label-offset 'safe-local-variable 'integerp)
524 (defcustom perl-continued-statement-offset 4
525 "Extra indent for lines not starting new statements."
526 :type 'integer)
527 (defcustom perl-continued-brace-offset -4
528 "Extra indent for substatements that start with open-braces.
529 This is in addition to `perl-continued-statement-offset'."
530 :type 'integer)
531 (defcustom perl-brace-offset 0
532 "Extra indentation for braces, compared with other text in same context."
533 :type 'integer)
534 (defcustom perl-brace-imaginary-offset 0
535 "Imagined indentation of an open brace that actually follows a statement."
536 :type 'integer)
537 (defcustom perl-label-offset -2
538 "Offset of Perl label lines relative to usual indentation."
539 :type 'integer)
540 (defcustom perl-indent-continued-arguments nil
541 "If non-nil offset of argument lines relative to usual indentation.
542 If nil, continued arguments are aligned with the first argument."
543 :type '(choice integer (const nil)))
545 (defcustom perl-indent-parens-as-block nil
546 "Non-nil means that non-block ()-, {}- and []-groups are indented as blocks.
547 The closing bracket is aligned with the line of the opening bracket,
548 not the contents of the brackets."
549 :version "24.3"
550 :type 'boolean)
552 (defcustom perl-tab-always-indent tab-always-indent
553 "Non-nil means TAB in Perl mode always indents the current line.
554 Otherwise it inserts a tab character if you type it past the first
555 nonwhite character on the line."
556 :type 'boolean)
558 ;; I changed the default to nil for consistency with general Emacs
559 ;; conventions -- rms.
560 (defcustom perl-tab-to-comment nil
561 "Non-nil means TAB moves to eol or makes a comment in some cases.
562 For lines which don't need indenting, TAB either indents an
563 existing comment, moves to end-of-line, or if at end-of-line already,
564 create a new comment."
565 :type 'boolean)
567 (defcustom perl-nochange "\f"
568 "Lines starting with this regular expression are not auto-indented."
569 :type 'regexp
570 :options '(";?#\\|\f\\|\\s(\\|\\(\\w\\|\\s_\\)+:[^:]"))
572 ;; Outline support
574 (defvar perl-outline-regexp
575 (concat (mapconcat 'cadr perl-imenu-generic-expression "\\|")
576 "\\|^=cut\\>"))
578 (defun perl-outline-level ()
579 (cond
580 ((looking-at "[ \t]*\\(package\\)\\s-")
581 (- (match-beginning 1) (match-beginning 0)))
582 ((looking-at "[ \t]*s\\(ub\\)\\s-")
583 (- (match-beginning 1) (match-beginning 0)))
584 ((looking-at "=head[0-9]") (- (char-before (match-end 0)) ?0))
585 ((looking-at "=cut") 1)
586 (t 3)))
588 (defun perl-current-defun-name ()
589 "The `add-log-current-defun' function in Perl mode."
590 (save-excursion
591 (if (re-search-backward "^sub[ \t]+\\([^({ \t\n]+\\)" nil t)
592 (match-string-no-properties 1))))
595 (defvar perl-mode-hook nil
596 "Normal hook to run when entering Perl mode.")
598 ;;;###autoload
599 (define-derived-mode perl-mode prog-mode "Perl"
600 "Major mode for editing Perl code.
601 Expression and list commands understand all Perl brackets.
602 Tab indents for Perl code.
603 Comments are delimited with # ... \\n.
604 Paragraphs are separated by blank lines only.
605 Delete converts tabs to spaces as it moves back.
606 \\{perl-mode-map}
607 Variables controlling indentation style:
608 `perl-tab-always-indent'
609 Non-nil means TAB in Perl mode should always indent the current line,
610 regardless of where in the line point is when the TAB command is used.
611 `perl-tab-to-comment'
612 Non-nil means that for lines which don't need indenting, TAB will
613 either delete an empty comment, indent an existing comment, move
614 to end-of-line, or if at end-of-line already, create a new comment.
615 `perl-nochange'
616 Lines starting with this regular expression are not auto-indented.
617 `perl-indent-level'
618 Indentation of Perl statements within surrounding block.
619 The surrounding block's indentation is the indentation
620 of the line on which the open-brace appears.
621 `perl-continued-statement-offset'
622 Extra indentation given to a substatement, such as the
623 then-clause of an if or body of a while.
624 `perl-continued-brace-offset'
625 Extra indentation given to a brace that starts a substatement.
626 This is in addition to `perl-continued-statement-offset'.
627 `perl-brace-offset'
628 Extra indentation for line if it starts with an open brace.
629 `perl-brace-imaginary-offset'
630 An open brace following other text is treated as if it were
631 this far to the right of the start of its line.
632 `perl-label-offset'
633 Extra indentation for line that is a label.
634 `perl-indent-continued-arguments'
635 Offset of argument lines relative to usual indentation.
637 Various indentation styles: K&R BSD BLK GNU LW
638 perl-indent-level 5 8 0 2 4
639 perl-continued-statement-offset 5 8 4 2 4
640 perl-continued-brace-offset 0 0 0 0 -4
641 perl-brace-offset -5 -8 0 0 0
642 perl-brace-imaginary-offset 0 0 4 0 0
643 perl-label-offset -5 -8 -2 -2 -2
645 Turning on Perl mode runs the normal hook `perl-mode-hook'."
646 :abbrev-table perl-mode-abbrev-table
647 (setq-local paragraph-start (concat "$\\|" page-delimiter))
648 (setq-local paragraph-separate paragraph-start)
649 (setq-local paragraph-ignore-fill-prefix t)
650 (setq-local indent-line-function #'perl-indent-line)
651 (setq-local comment-start "# ")
652 (setq-local comment-end "")
653 (setq-local comment-start-skip "\\(^\\|\\s-\\);?#+ *")
654 (setq-local comment-indent-function #'perl-comment-indent)
655 (setq-local parse-sexp-ignore-comments t)
657 ;; Tell font-lock.el how to handle Perl.
658 (setq font-lock-defaults '((perl-font-lock-keywords
659 perl-font-lock-keywords-1
660 perl-font-lock-keywords-2)
661 nil nil ((?\_ . "w")) nil
662 (font-lock-syntactic-face-function
663 . perl-font-lock-syntactic-face-function)))
664 (setq-local prettify-symbols-alist perl--prettify-symbols-alist)
665 (setq-local syntax-propertize-function #'perl-syntax-propertize-function)
666 (add-hook 'syntax-propertize-extend-region-functions
667 #'syntax-propertize-multiline 'append 'local)
668 ;; Electricity.
669 ;; FIXME: setup electric-layout-rules.
670 (setq-local electric-indent-chars
671 (append '(?\{ ?\} ?\; ?\:) electric-indent-chars))
672 (add-hook 'electric-indent-functions #'perl-electric-noindent-p nil t)
673 ;; Tell imenu how to handle Perl.
674 (setq-local imenu-generic-expression perl-imenu-generic-expression)
675 (setq imenu-case-fold-search nil)
676 ;; Setup outline-minor-mode.
677 (setq-local outline-regexp perl-outline-regexp)
678 (setq-local outline-level 'perl-outline-level)
679 (setq-local add-log-current-defun-function #'perl-current-defun-name))
681 ;; This is used by indent-for-comment
682 ;; to decide how much to indent a comment in Perl code
683 ;; based on its context.
684 (defun perl-comment-indent ()
685 (if (and (bolp) (not (eolp)))
686 0 ;Existing comment at bol stays there.
687 comment-column))
689 (define-obsolete-function-alias 'electric-perl-terminator
690 'perl-electric-terminator "22.1")
691 (defun perl-electric-noindent-p (_char)
692 (unless (eolp) 'no-indent))
694 (defun perl-electric-terminator (arg)
695 "Insert character and maybe adjust indentation.
696 If at end-of-line, and not in a comment or a quote, correct the indentation."
697 (interactive "P")
698 (let ((insertpos (point)))
699 (and (not arg) ; decide whether to indent
700 (eolp)
701 (save-excursion
702 (beginning-of-line)
703 (and (not ; eliminate comments quickly
704 (and comment-start-skip
705 (re-search-forward comment-start-skip insertpos t)) )
706 (or (/= last-command-event ?:)
707 ;; Colon is special only after a label ....
708 (looking-at "\\s-*\\(\\w\\|\\s_\\)+$"))
709 (let ((pps (parse-partial-sexp
710 (perl-beginning-of-function) insertpos)))
711 (not (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))
712 (progn ; must insert, indent, delete
713 (insert-char last-command-event 1)
714 (perl-indent-line)
715 (delete-char -1))))
716 (self-insert-command (prefix-numeric-value arg)))
717 (make-obsolete 'perl-electric-terminator 'electric-indent-mode "24.4")
719 ;; not used anymore, but may be useful someday:
720 ;;(defun perl-inside-parens-p ()
721 ;; (condition-case ()
722 ;; (save-excursion
723 ;; (save-restriction
724 ;; (narrow-to-region (point)
725 ;; (perl-beginning-of-function))
726 ;; (goto-char (point-max))
727 ;; (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
728 ;; (error nil)))
730 (defun perl-indent-command (&optional arg)
731 "Indent Perl code in the active region or current line.
732 In Transient Mark mode, when the region is active, reindent the region.
733 Otherwise, with a prefix argument, reindent the current line
734 unconditionally.
736 Otherwise, if `perl-tab-always-indent' is nil and point is not in
737 the indentation area at the beginning of the line, insert a tab.
739 Otherwise, indent the current line. If point was within the
740 indentation area, it is moved to the end of the indentation area.
741 If the line was already indented properly and point was not
742 within the indentation area, and if `perl-tab-to-comment' is
743 non-nil (the default), then do the first possible action from the
744 following list:
746 1) delete an empty comment
747 2) move forward to start of comment, indenting if necessary
748 3) move forward to end of line
749 4) create an empty comment
750 5) move backward to start of comment, indenting if necessary."
751 (interactive "P")
752 (cond ((use-region-p) ; indent the active region
753 (indent-region (region-beginning) (region-end)))
754 (arg
755 (perl-indent-line "\f")) ; just indent this line
756 ((and (not perl-tab-always-indent)
757 (> (current-column) (current-indentation)))
758 (insert-tab))
760 (let* ((oldpnt (point))
761 (lsexp (progn (beginning-of-line) (point)))
762 (bof (perl-beginning-of-function))
763 (delta (progn
764 (goto-char oldpnt)
765 (perl-indent-line "\f\\|;?#"))))
766 (and perl-tab-to-comment
767 (= oldpnt (point)) ; done if point moved
768 (if (listp delta) ; if line starts in a quoted string
769 (setq lsexp (or (nth 2 delta) bof))
770 (= delta 0)) ; done if indenting occurred
771 (let ((eol (progn (end-of-line) (point)))
772 state)
773 (cond ((= (char-after bof) ?=)
774 (if (= oldpnt eol)
775 (message "In a format statement")))
776 ((progn (setq state (parse-partial-sexp lsexp eol))
777 (nth 3 state))
778 (if (= oldpnt eol) ; already at eol in a string
779 (message "In a string which starts with a %c."
780 (nth 3 state))))
781 ((not (nth 4 state))
782 (if (= oldpnt eol) ; no comment, create one?
783 (indent-for-comment)))
784 ((progn (beginning-of-line)
785 (and comment-start-skip
786 (re-search-forward
787 comment-start-skip eol 'move)))
788 (if (eolp)
789 (progn ; delete existing comment
790 (goto-char (match-beginning 0))
791 (skip-chars-backward " \t")
792 (delete-region (point) eol))
793 (if (or (< oldpnt (point)) (= oldpnt eol))
794 (indent-for-comment) ; indent existing comment
795 (end-of-line))))
796 ((/= oldpnt eol)
797 (end-of-line))
799 (message "Use backslash to quote # characters.")
800 (ding t)))))))))
801 (make-obsolete 'perl-indent-command 'indent-according-to-mode "24.4")
803 (defun perl-indent-line (&optional nochange)
804 "Indent current line as Perl code.
805 Return the amount the indentation
806 changed by, or (parse-state) if line starts in a quoted string."
807 (let ((case-fold-search nil)
808 (pos (- (point-max) (point)))
809 beg indent shift-amt)
810 (beginning-of-line)
811 (setq beg (point))
812 (setq shift-amt
813 (cond ((eq 1 (nth 7 (syntax-ppss))) 0) ;For doc sections!
814 ((listp (setq indent (perl-calculate-indent))) indent)
815 ((eq 'noindent indent) indent)
816 ((looking-at (or nochange perl-nochange)) 0)
818 (skip-chars-forward " \t\f")
819 (setq indent (perl-indent-new-calculate nil indent))
820 (- indent (current-column)))))
821 (skip-chars-forward " \t\f")
822 (if (and (numberp shift-amt) (/= 0 shift-amt))
823 (progn (delete-region beg (point))
824 (indent-to indent)))
825 ;; If initial point was within line's indentation,
826 ;; position after the indentation. Else stay at same point in text.
827 (if (> (- (point-max) pos) (point))
828 (goto-char (- (point-max) pos)))
829 shift-amt))
831 (defun perl-continuation-line-p ()
832 "Move to end of previous line and return non-nil if continued."
833 ;; Statement level. Is it a continuation or a new statement?
834 ;; Find previous non-comment character.
835 (perl-backward-to-noncomment)
836 ;; Back up over label lines, since they don't
837 ;; affect whether our line is a continuation.
838 (while (and (eq (preceding-char) ?:)
839 (memq (char-syntax (char-after (- (point) 2)))
840 '(?w ?_)))
841 (beginning-of-line)
842 (perl-backward-to-noncomment))
843 ;; Now we get the answer.
844 (unless (memq (preceding-char) '(?\; ?\} ?\{))
845 (preceding-char)))
847 (defun perl-hanging-paren-p ()
848 "Non-nil if we are right after a hanging parenthesis-like char."
849 (and (looking-at "[ \t]*$")
850 (save-excursion
851 (skip-syntax-backward " (") (not (bolp)))))
853 (defun perl-indent-new-calculate (&optional virtual default)
855 (and virtual (save-excursion (skip-chars-backward " \t") (bolp))
856 (current-column))
857 (and (looking-at "\\(\\w\\|\\s_\\)+:[^:]")
858 (max 1 (+ (or default (perl-calculate-indent))
859 perl-label-offset)))
860 (and (= (char-syntax (following-char)) ?\))
861 (save-excursion
862 (forward-char 1)
863 (when (condition-case nil (progn (forward-sexp -1) t)
864 (scan-error nil))
865 (perl-indent-new-calculate 'virtual))))
866 (and (and (= (following-char) ?{)
867 (save-excursion (forward-char) (perl-hanging-paren-p)))
868 (+ (or default (perl-calculate-indent))
869 perl-brace-offset))
870 (or default (perl-calculate-indent))))
872 (defun perl-calculate-indent ()
873 "Return appropriate indentation for current line as Perl code.
874 In usual case returns an integer: the column to indent to.
875 Returns (parse-state) if line starts inside a string."
876 (save-excursion
877 (let ((indent-point (point))
878 (case-fold-search nil)
879 (colon-line-end 0)
880 prev-char
881 state containing-sexp)
882 (setq containing-sexp (nth 1 (syntax-ppss indent-point)))
883 (cond
884 ;; Don't auto-indent in a quoted string or a here-document.
885 ((or (nth 3 state) (eq 2 (nth 7 state))) 'noindent)
886 ((null containing-sexp) ; Line is at top level.
887 (skip-chars-forward " \t\f")
888 (if (memq (following-char)
889 (if perl-indent-parens-as-block '(?\{ ?\( ?\[) '(?\{)))
890 0 ; move to beginning of line if it starts a function body
891 ;; indent a little if this is a continuation line
892 (perl-backward-to-noncomment)
893 (if (or (bobp)
894 (memq (preceding-char) '(?\; ?\})))
895 0 perl-continued-statement-offset)))
896 ((/= (char-after containing-sexp) ?{)
897 ;; line is expression, not statement:
898 ;; indent to just after the surrounding open.
899 (goto-char (1+ containing-sexp))
900 (if (perl-hanging-paren-p)
901 ;; We're indenting an arg of a call like:
902 ;; $a = foobarlongnamefun (
903 ;; arg1
904 ;; arg2
905 ;; );
906 (progn
907 (skip-syntax-backward "(")
908 (condition-case nil
909 (while (save-excursion
910 (skip-syntax-backward " ") (not (bolp)))
911 (forward-sexp -1))
912 (scan-error nil))
913 (+ (current-column) perl-indent-level))
914 (if perl-indent-continued-arguments
915 (+ perl-indent-continued-arguments (current-indentation))
916 (skip-chars-forward " \t")
917 (current-column))))
918 ;; Statement level. Is it a continuation or a new statement?
919 ((setq prev-char (perl-continuation-line-p))
920 ;; This line is continuation of preceding line's statement;
921 ;; indent perl-continued-statement-offset more than the
922 ;; previous line of the statement.
923 (perl-backward-to-start-of-continued-exp)
924 (+ (if (or (save-excursion
925 (perl-continuation-line-p))
926 (and (eq prev-char ?\,)
927 (looking-at "[[:alnum:]_]+[ \t\n]*=>")))
928 ;; If the continued line is itself a continuation
929 ;; line, then align, otherwise add an offset.
930 0 perl-continued-statement-offset)
931 (current-column)
932 (if (save-excursion (goto-char indent-point)
933 (looking-at
934 (if perl-indent-parens-as-block
935 "[ \t]*[{([]" "[ \t]*{")))
936 perl-continued-brace-offset 0)))
938 ;; This line starts a new statement.
939 ;; Position at last unclosed open.
940 (goto-char containing-sexp)
942 ;; Is line first statement after an open-brace?
943 ;; If no, find that first statement and indent like it.
944 (save-excursion
945 (forward-char 1)
946 ;; Skip over comments and labels following openbrace.
947 (while (progn
948 (skip-chars-forward " \t\f\n")
949 (cond ((looking-at ";?#")
950 (forward-line 1) t)
951 ((looking-at "\\(\\w\\|\\s_\\)+:[^:]")
952 (setq colon-line-end (line-end-position))
953 (search-forward ":")))))
954 ;; The first following code counts
955 ;; if it is before the line we want to indent.
956 (and (< (point) indent-point)
957 (if (> colon-line-end (point))
958 (- (current-indentation) perl-label-offset)
959 (current-column))))
960 ;; If no previous statement,
961 ;; indent it relative to line brace is on.
962 ;; For open paren in column zero, don't let statement
963 ;; start there too. If perl-indent-level is zero,
964 ;; use perl-brace-offset + perl-continued-statement-offset
965 ;; For open-braces not the first thing in a line,
966 ;; add in perl-brace-imaginary-offset.
967 (+ (if (and (bolp) (zerop perl-indent-level))
968 (+ perl-brace-offset perl-continued-statement-offset)
969 perl-indent-level)
970 ;; Move back over whitespace before the openbrace.
971 ;; If openbrace is not first nonwhite thing on the line,
972 ;; add the perl-brace-imaginary-offset.
973 (progn (skip-chars-backward " \t")
974 (if (bolp) 0 perl-brace-imaginary-offset))
975 ;; If the openbrace is preceded by a parenthesized exp,
976 ;; move to the beginning of that;
977 ;; possibly a different line
978 (progn
979 (if (eq (preceding-char) ?\))
980 (forward-sexp -1))
981 ;; Get initial indentation of the line we are on.
982 (current-indentation)))))))))
984 (defun perl-backward-to-noncomment ()
985 "Move point backward to after the first non-white-space, skipping comments."
986 (forward-comment (- (point-max))))
988 (defun perl-backward-to-start-of-continued-exp ()
989 (while
990 (let ((c (preceding-char)))
991 (cond
992 ((memq c '(?\; ?\{ ?\[ ?\()) (forward-comment (point-max)) nil)
993 ((memq c '(?\) ?\] ?\} ?\"))
994 (forward-sexp -1) (forward-comment (- (point))) t)
995 ((eq ?w (char-syntax c))
996 (forward-word -1) (forward-comment (- (point))) t)
997 (t (forward-char -1) (forward-comment (- (point))) t)))))
999 ;; note: this may be slower than the c-mode version, but I can understand it.
1000 (defalias 'indent-perl-exp 'perl-indent-exp)
1001 (defun perl-indent-exp ()
1002 "Indent each line of the Perl grouping following point."
1003 (interactive)
1004 (let* ((case-fold-search nil)
1005 (oldpnt (point-marker))
1006 (bof-mark (save-excursion
1007 (end-of-line 2)
1008 (perl-beginning-of-function)
1009 (point-marker)))
1010 eol last-mark lsexp-mark delta)
1011 (if (= (char-after (marker-position bof-mark)) ?=)
1012 (message "Can't indent a format statement")
1013 (message "Indenting Perl expression...")
1014 (setq eol (line-end-position))
1015 (save-excursion ; locate matching close paren
1016 (while (and (not (eobp)) (<= (point) eol))
1017 (parse-partial-sexp (point) (point-max) 0))
1018 (setq last-mark (point-marker)))
1019 (setq lsexp-mark bof-mark)
1020 (beginning-of-line)
1021 (while (< (point) (marker-position last-mark))
1022 (setq delta (perl-indent-line nil))
1023 (if (numberp delta) ; unquoted start-of-line?
1024 (progn
1025 (if (eolp)
1026 (delete-horizontal-space))
1027 (setq lsexp-mark (point-marker))))
1028 (end-of-line)
1029 (setq eol (point))
1030 (if (nth 4 (parse-partial-sexp (marker-position lsexp-mark) eol))
1031 (progn ; line ends in a comment
1032 (beginning-of-line)
1033 (if (or (not (looking-at "\\s-*;?#"))
1034 (listp delta)
1035 (and (/= 0 delta)
1036 (= (- (current-indentation) delta) comment-column)))
1037 (if (and comment-start-skip
1038 (re-search-forward comment-start-skip eol t))
1039 (indent-for-comment))))) ; indent existing comment
1040 (forward-line 1))
1041 (goto-char (marker-position oldpnt))
1042 (message "Indenting Perl expression...done"))))
1044 (defun perl-beginning-of-function (&optional arg)
1045 "Move backward to next beginning-of-function, or as far as possible.
1046 With argument, repeat that many times; negative args move forward.
1047 Returns new value of point in all cases."
1048 (interactive "p")
1049 (or arg (setq arg 1))
1050 (if (< arg 0) (forward-char 1))
1051 (and (/= arg 0)
1052 (re-search-backward
1053 "^\\s(\\|^\\s-*sub\\b[ \t\n]*\\_<[^{]+{\\|^\\s-*format\\b[^=]*=\\|^\\."
1054 nil 'move arg)
1055 (goto-char (1- (match-end 0))))
1056 (point))
1058 ;; note: this routine is adapted directly from emacs lisp.el, end-of-defun;
1059 ;; no bugs have been removed :-)
1060 (defun perl-end-of-function (&optional arg)
1061 "Move forward to next end-of-function.
1062 The end of a function is found by moving forward from the beginning of one.
1063 With argument, repeat that many times; negative args move backward."
1064 (interactive "p")
1065 (or arg (setq arg 1))
1066 (let ((first t))
1067 (while (and (> arg 0) (< (point) (point-max)))
1068 (let ((pos (point)))
1069 (while (progn
1070 (if (and first
1071 (progn
1072 (forward-char 1)
1073 (perl-beginning-of-function 1)
1074 (not (bobp))))
1076 (or (bobp) (forward-char -1))
1077 (perl-beginning-of-function -1))
1078 (setq first nil)
1079 (forward-list 1)
1080 (skip-chars-forward " \t")
1081 (if (looking-at "[#\n]")
1082 (forward-line 1))
1083 (<= (point) pos))))
1084 (setq arg (1- arg)))
1085 (while (< arg 0)
1086 (let ((pos (point)))
1087 (perl-beginning-of-function 1)
1088 (forward-sexp 1)
1089 (forward-line 1)
1090 (if (>= (point) pos)
1091 (if (progn (perl-beginning-of-function 2) (not (bobp)))
1092 (progn
1093 (forward-list 1)
1094 (skip-chars-forward " \t")
1095 (if (looking-at "[#\n]")
1096 (forward-line 1)))
1097 (goto-char (point-min)))))
1098 (setq arg (1+ arg)))))
1100 (defalias 'mark-perl-function 'perl-mark-function)
1101 (defun perl-mark-function ()
1102 "Put mark at end of Perl function, point at beginning."
1103 (interactive)
1104 (push-mark (point))
1105 (perl-end-of-function)
1106 (push-mark (point))
1107 (perl-beginning-of-function)
1108 (backward-paragraph))
1110 (provide 'perl-mode)
1112 ;;; perl-mode.el ends here