aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2001-06-10 18:02:43 +0000
committerStefan Monnier2001-06-10 18:02:43 +0000
commit4a0aa1d93a3f69ce96ae52a39fe8c96d2318d68c (patch)
tree9e102ac796ad553f0067053e252ac92dbc64e195
parent9f6f30898d9d12bbc37a96bb94f7d3ac9786b9ec (diff)
downloademacs-4a0aa1d93a3f69ce96ae52a39fe8c96d2318d68c.tar.gz
emacs-4a0aa1d93a3f69ce96ae52a39fe8c96d2318d68c.zip
(perl-font-lock-syntactic-keywords): New var, to recognize ${ $' and PODs.
(perl-font-lock-syntactic-face-function): New function. (perl-mode): Use them. (perl-continuation-line-p): New function, from perl-calculate-indent. (perl-calculate-indent): Use it, to properly handle continuation lines of continuation lines.
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/progmodes/perl-mode.el73
2 files changed, 60 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f69a26bec8b..1fc30e7bf36 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12001-06-10 Stefan Monnier <monnier@cs.yale.edu>
2
3 * progmodes/perl-mode.el (perl-font-lock-syntactic-keywords):
4 New var, to recognize ${ $' and PODs.
5 (perl-font-lock-syntactic-face-function): New function.
6 (perl-mode): Use them.
7 (perl-continuation-line-p): New function, from perl-calculate-indent.
8 (perl-calculate-indent): Use it, to properly handle continuation
9 lines of continuation lines.
10
12001-06-10 Eli Zaretskii <eliz@is.elta.co.il> 112001-06-10 Eli Zaretskii <eliz@is.elta.co.il>
2 12
3 * server.el (server-process, server-buffer-clients): Doc fix. 13 * server.el (server-process, server-buffer-clients): Doc fix.
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index 98d2035112a..33ff6364390 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -72,14 +72,16 @@
72;; 2) The globbing syntax <pattern> is not recognized, so special 72;; 2) The globbing syntax <pattern> is not recognized, so special
73;; characters in the pattern string must be backslashed. 73;; characters in the pattern string must be backslashed.
74;; 3) The q, qq, and << quoting operators are not recognized; see below. 74;; 3) The q, qq, and << quoting operators are not recognized; see below.
75;; 4) \ (backslash) always quotes the next character, so '\' is 75;; 5) To make '$' work correctly, $' is not recognized as a variable.
76;; treated as the start of a string. Use "\\" as a work-around. 76;; Use "$'" or $POSTMATCH instead.
77;; 7) When ' (quote) is used as a package name separator, perl-mode
78;; doesn't understand, and thinks it is seeing a quoted string.
79;;
80;; If you don't use font-lock, additional problems will appear:
77;; 5) To make variables such a $' and $#array work, perl-mode treats 81;; 5) To make variables such a $' and $#array work, perl-mode treats
78;; $ just like backslash, so '$' is the same as problem 5. 82;; $ just like backslash, so '$' is not treated correctly.
79;; 6) Unfortunately, treating $ like \ makes ${var} be treated as an 83;; 6) Unfortunately, treating $ like \ makes ${var} be treated as an
80;; unmatched }. See below. 84;; unmatched }. See below.
81;; 7) When ' (quote) is used as a package name separator, perl-mode
82;; doesn't understand, and thinks it is seeing a quoted string.
83 85
84;; Here are some ugly tricks to bypass some of these problems: the perl 86;; Here are some ugly tricks to bypass some of these problems: the perl
85;; expression /`/ (that's a back-tick) usually evaluates harmlessly, 87;; expression /`/ (that's a back-tick) usually evaluates harmlessly,
@@ -116,7 +118,7 @@
116 (define-key map "\177" 'backward-delete-char-untabify) 118 (define-key map "\177" 'backward-delete-char-untabify)
117 (define-key map "\t" 'perl-indent-command) 119 (define-key map "\t" 'perl-indent-command)
118 map) 120 map)
119 "Keymap used in `perl-mode'.") 121 "Keymap used in Perl mode.")
120 122
121(autoload 'c-macro-expand "cmacexp" 123(autoload 'c-macro-expand "cmacexp"
122 "Display the result of expanding all C macros occurring in the region. 124 "Display the result of expanding all C macros occurring in the region.
@@ -211,6 +213,17 @@ The expansion is entirely correct because it uses the C preprocessor."
211(defvar perl-font-lock-keywords perl-font-lock-keywords-1 213(defvar perl-font-lock-keywords perl-font-lock-keywords-1
212 "Default expressions to highlight in Perl mode.") 214 "Default expressions to highlight in Perl mode.")
213 215
216(defvar perl-font-lock-syntactic-keywords
217 ;; Turn POD into b-style comments
218 '(("^\\(=\\)\\(head1\\|pod\\)\\([ \t]\\|$\\)" (1 "< b"))
219 ("^=cut[ \t]*\\(\n\\)" (1 "> b"))
220 ;; Catch ${ so that ${var} doesn't screw up indentation.
221 ("\\(\\$\\)[{']" (1 "."))))
222
223(defun perl-font-lock-syntactic-face-function (state)
224 (if (nth 3 state)
225 font-lock-string-face
226 (if (nth 7 state) font-lock-doc-face font-lock-comment-face)))
214 227
215(defcustom perl-indent-level 4 228(defcustom perl-indent-level 4
216 "*Indentation of Perl statements with respect to containing block." 229 "*Indentation of Perl statements with respect to containing block."
@@ -327,11 +340,15 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'."
327 (make-local-variable 'parse-sexp-ignore-comments) 340 (make-local-variable 'parse-sexp-ignore-comments)
328 (setq parse-sexp-ignore-comments t) 341 (setq parse-sexp-ignore-comments t)
329 ;; Tell font-lock.el how to handle Perl. 342 ;; Tell font-lock.el how to handle Perl.
330 (make-local-variable 'font-lock-defaults)
331 (setq font-lock-defaults '((perl-font-lock-keywords 343 (setq font-lock-defaults '((perl-font-lock-keywords
332 perl-font-lock-keywords-1 344 perl-font-lock-keywords-1
333 perl-font-lock-keywords-2) 345 perl-font-lock-keywords-2)
334 nil nil ((?\_ . "w")))) 346 nil nil ((?\_ . "w")) nil
347 (font-lock-syntactic-keywords
348 . perl-font-lock-syntactic-keywords)
349 (font-lock-syntactic-face-function
350 . perl-font-lock-syntactic-face-function)
351 (parse-sexp-lookup-properties . t)))
335 ;; Tell imenu how to handle Perl. 352 ;; Tell imenu how to handle Perl.
336 (make-local-variable 'imenu-generic-expression) 353 (make-local-variable 'imenu-generic-expression)
337 (setq imenu-generic-expression perl-imenu-generic-expression) 354 (setq imenu-generic-expression perl-imenu-generic-expression)
@@ -480,6 +497,24 @@ changed by, or (parse-state) if line starts in a quoted string."
480 (goto-char (- (point-max) pos))) 497 (goto-char (- (point-max) pos)))
481 shift-amt)) 498 shift-amt))
482 499
500(defun perl-continuation-line-p (limit)
501 "Move to end of previous line and return non-nil if continued."
502 ;; Statement level. Is it a continuation or a new statement?
503 ;; Find previous non-comment character.
504 (perl-backward-to-noncomment)
505 ;; Back up over label lines, since they don't
506 ;; affect whether our line is a continuation.
507 (while (or (eq (preceding-char) ?\,)
508 (and (eq (preceding-char) ?:)
509 (memq (char-syntax (char-after (- (point) 2)))
510 '(?w ?_))))
511 (if (eq (preceding-char) ?\,)
512 (perl-backward-to-start-of-continued-exp limit)
513 (beginning-of-line))
514 (perl-backward-to-noncomment))
515 ;; Now we get the answer.
516 (not (memq (preceding-char) '(?\; ?\} ?\{))))
517
483(defun perl-calculate-indent (&optional parse-start) 518(defun perl-calculate-indent (&optional parse-start)
484 "Return appropriate indentation for current line as Perl code. 519 "Return appropriate indentation for current line as Perl code.
485In usual case returns an integer: the column to indent to. 520In usual case returns an integer: the column to indent to.
@@ -528,26 +563,18 @@ Returns (parse-state) if line starts inside a string."
528 (current-column)) 563 (current-column))
529 (t 564 (t
530 ;; Statement level. Is it a continuation or a new statement? 565 ;; Statement level. Is it a continuation or a new statement?
531 ;; Find previous non-comment character. 566 (if (perl-continuation-line-p containing-sexp)
532 (perl-backward-to-noncomment)
533 ;; Back up over label lines, since they don't
534 ;; affect whether our line is a continuation.
535 (while (or (eq (preceding-char) ?\,)
536 (and (eq (preceding-char) ?:)
537 (memq (char-syntax (char-after (- (point) 2)))
538 '(?w ?_))))
539 (if (eq (preceding-char) ?\,)
540 (perl-backward-to-start-of-continued-exp containing-sexp)
541 (beginning-of-line))
542 (perl-backward-to-noncomment))
543 ;; Now we get the answer.
544 (if (not (memq (preceding-char) '(?\; ?\} ?\{)))
545 ;; This line is continuation of preceding line's statement; 567 ;; This line is continuation of preceding line's statement;
546 ;; indent perl-continued-statement-offset more than the 568 ;; indent perl-continued-statement-offset more than the
547 ;; previous line of the statement. 569 ;; previous line of the statement.
548 (progn 570 (progn
549 (perl-backward-to-start-of-continued-exp containing-sexp) 571 (perl-backward-to-start-of-continued-exp containing-sexp)
550 (+ perl-continued-statement-offset (current-column) 572 (+ (if (save-excursion
573 (perl-continuation-line-p containing-sexp))
574 ;; If the continued line is itself a continuation
575 ;; line, then align, otherwise add an offset.
576 0 perl-continued-statement-offset)
577 (current-column)
551 (if (save-excursion (goto-char indent-point) 578 (if (save-excursion (goto-char indent-point)
552 (looking-at "[ \t]*{")) 579 (looking-at "[ \t]*{"))
553 perl-continued-brace-offset 0))) 580 perl-continued-brace-offset 0)))