Skip to content
This repository
Browse code

''

  • Loading branch information...
commit 0cb84b0f6ec78cc828a0896a26e3fba75d357b01 1 parent 0f8df30
monnier monnier authored

Showing 1 changed file with 61 additions and 203 deletions. Show diff stats Hide diff stats

  1. +61 203 lisp/progmodes/cperl-mode.el
264 lisp/progmodes/cperl-mode.el
@@ -45,7 +45,7 @@
45 45
46 46 ;;; Commentary:
47 47
48   -;; $Id: cperl-mode.el,v 5.22 2006/10/03 08:16:35 vera Exp vera $
  48 +;; $Id: cperl-mode.el,v 5.23 2007/02/15 11:34:23 vera Exp vera $
49 49
50 50 ;;; If your Emacs does not default to `cperl-mode' on Perl files:
51 51 ;;; To use this mode put the following into
@@ -1489,6 +1489,20 @@
1489 1489 ;;; `cperl-comment-indent': Test for `cperl-indent-comment-at-column-0'
1490 1490 ;;; was inverted;
1491 1491 ;;; Support `comment-column' = 0
  1492 +
  1493 +;;; After 5.22:
  1494 +;;; `cperl-where-am-i': Remove function
  1495 +;;; `cperl-backward-to-noncomment': Would go too far when skipping POD/HEREs
  1496 +;;; `cperl-sniff-for-indent': [string] and [comment] were inverted
  1497 +;;; When looking for label, skip s:m:y:tr
  1498 +;;; `cperl-indent-line': Likewise.
  1499 +;;; `cperl-mode': `font-lock-multiline' was assumed auto-local
  1500 +;;; `cperl-windowed-init': Wrong `ps-print' handling
  1501 +;;; (both thanks to Chong Yidong)
  1502 +;;; `cperl-look-at-leading-count': Could fail with unfinished RExen
  1503 +;;; `cperl-find-pods-heres': If the second part of s()[] is missing,
  1504 +;;; could try to highlight delimiters...
  1505 +
1492 1506 ;;; Code:
1493 1507
1494 1508 (if (fboundp 'eval-when-compile)
@@ -3354,7 +3368,7 @@ or as help on variables `cperl-tips', `cperl-problems',
3354 3368 (if (boundp 'font-lock-multiline) ; Newer font-lock; use its facilities
3355 3369 (progn
3356 3370 (setq cperl-font-lock-multiline t) ; Not localized...
3357   - (set 'font-lock-multiline t)) ; not present with old Emacs; auto-local
  3371 + (set (make-local-variable 'font-lock-multiline) t))
3358 3372 (make-local-variable 'font-lock-fontify-region-function)
3359 3373 (set 'font-lock-fontify-region-function ; not present with old Emacs
3360 3374 'cperl-font-lock-fontify-region-function))
@@ -4136,7 +4150,8 @@ Return the amount the indentation changed by."
4136 4150 (t
4137 4151 (skip-chars-forward " \t")
4138 4152 (if (listp indent) (setq indent (car indent)))
4139   - (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
  4153 + (cond ((and (looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]")
  4154 + (not (looking-at "[smy]:\\|tr:")))
4140 4155 (and (> indent 0)
4141 4156 (setq indent (max cperl-min-label-indent
4142 4157 (+ indent cperl-label-offset)))))
@@ -4311,9 +4326,9 @@ Will not look before LIM."
4311 4326 (vector 'indentable 'first-line p))))
4312 4327 ((get-text-property char-after-pos 'REx-part2)
4313 4328 (vector 'REx-part2 (point)))
4314   - ((nth 3 state)
4315   - [comment])
4316 4329 ((nth 4 state)
  4330 + [comment])
  4331 + ((nth 3 state)
4317 4332 [string])
4318 4333 ;; XXXX Do we need to special-case this?
4319 4334 ((null containing-sexp)
@@ -4419,7 +4434,9 @@ Will not look before LIM."
4419 4434 (let ((colon-line-end 0))
4420 4435 (while
4421 4436 (progn (skip-chars-forward " \t\n")
4422   - (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]\\|=[a-zA-Z]"))
  4437 + ;; s: foo : bar :x is NOT label
  4438 + (and (looking-at "#\\|\\([a-zA-Z0-9_$]+\\):[^:]\\|=[a-zA-Z]")
  4439 + (not (looking-at "[sym]:\\|tr:"))))
4423 4440 ;; Skip over comments and labels following openbrace.
4424 4441 (cond ((= (following-char) ?\#)
4425 4442 (forward-line 1))
@@ -4490,8 +4507,7 @@ Will not look before LIM."
4490 4507 (vector 'code-start-in-block containing-sexp char-after
4491 4508 (and delim (not is-block)) ; is a HASH
4492 4509 old-indent ; brace first thing on a line
4493   - nil (point) ; nothing interesting before
4494   - ))))))))))))))
  4510 + nil (point))))))))))))))) ; nothing interesting before
4495 4511
4496 4512 (defvar cperl-indent-rules-alist
4497 4513 '((pod nil) ; via `syntax-type' property
@@ -4505,9 +4521,7 @@ Will not look before LIM."
4505 4521 "Alist of indentation rules for CPerl mode.
4506 4522 The values mean:
4507 4523 nil: do not indent;
4508   - number: add this amount of indentation.
4509   -
4510   -Not finished.")
  4524 + number: add this amount of indentation.")
4511 4525
4512 4526 (defun cperl-calculate-indent (&optional parse-data) ; was parse-start
4513 4527 "Return appropriate indentation for current line as Perl code.
@@ -4632,8 +4646,8 @@ and closing parentheses and brackets."
4632 4646 ;;
4633 4647 ((eq 'have-prev-sibling (elt i 0))
4634 4648 ;; [have-prev-sibling sibling-beg colon-line-end block-start]
4635   - (goto-char (elt i 1))
4636   - (if (> (elt i 2) (point)) ; colon-line-end; After-label, same line
  4649 + (goto-char (elt i 1)) ; sibling-beg
  4650 + (if (> (elt i 2) (point)) ; colon-line-end; have label before point
4637 4651 (if (> (current-indentation)
4638 4652 cperl-min-label-indent)
4639 4653 (- (current-indentation) cperl-label-offset)
@@ -4685,170 +4699,6 @@ and closing parentheses and brackets."
4685 4699 (t
4686 4700 (error (format "Got strange value of indent: " i)))))))
4687 4701
4688   -(defvar cperl-indent-alist
4689   - '((string nil)
4690   - (comment nil)
4691   - (toplevel 0)
4692   - (toplevel-after-parenth 2)
4693   - (toplevel-continued 2)
4694   - (expression 1))
4695   - "Alist of indentation rules for CPerl mode.
4696   -The values mean:
4697   - nil: do not indent;
4698   - number: add this amount of indentation.
4699   -
4700   -Not finished, not used.")
4701   -
4702   -(defun cperl-where-am-i (&optional parse-start start-state)
4703   - ;; Unfinished
4704   - "Return a list of lists ((TYPE POS)...) of good points before the point.
4705   -POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'.
4706   -
4707   -Not finished, not used."
4708   - (save-excursion
4709   - (let* ((start-point (point)) unused
4710   - (s-s (cperl-get-state))
4711   - (start (nth 0 s-s))
4712   - (state (nth 1 s-s))
4713   - (prestart (nth 3 s-s))
4714   - (containing-sexp (car (cdr state)))
4715   - (case-fold-search nil)
4716   - (res (list (list 'parse-start start) (list 'parse-prestart prestart))))
4717   - (cond ((nth 3 state) ; In string
4718   - (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string
4719   - ((nth 4 state) ; In comment
4720   - (setq res (cons '(comment) res)))
4721   - ((null containing-sexp)
4722   - ;; Line is at top level.
4723   - ;; Indent like the previous top level line
4724   - ;; unless that ends in a closeparen without semicolon,
4725   - ;; in which case this line is the first argument decl.
4726   - (cperl-backward-to-noncomment (or parse-start (point-min)))
4727   - ;;(skip-chars-backward " \t\f\n")
4728   - (cond
4729   - ((or (bobp)
4730   - (memq (preceding-char) (append ";}" nil)))
4731   - (setq res (cons (list 'toplevel start) res)))
4732   - ((eq (preceding-char) ?\) )
4733   - (setq res (cons (list 'toplevel-after-parenth start) res)))
4734   - (t
4735   - (setq res (cons (list 'toplevel-continued start) res)))))
4736   - ((/= (char-after containing-sexp) ?{)
4737   - ;; line is expression, not statement:
4738   - ;; indent to just after the surrounding open.
4739   - ;; skip blanks if we do not close the expression.
4740   - (setq res (cons (list 'expression-blanks
4741   - (progn
4742   - (goto-char (1+ containing-sexp))
4743   - (or (looking-at "[ \t]*\\(#\\|$\\)")
4744   - (skip-chars-forward " \t"))
4745   - (point)))
4746   - (cons (list 'expression containing-sexp) res))))
4747   - ((progn
4748   - ;; Containing-expr starts with \{. Check whether it is a hash.
4749   - (goto-char containing-sexp)
4750   - (not (cperl-block-p)))
4751   - (setq res (cons (list 'expression-blanks
4752   - (progn
4753   - (goto-char (1+ containing-sexp))
4754   - (or (looking-at "[ \t]*\\(#\\|$\\)")
4755   - (skip-chars-forward " \t"))
4756   - (point)))
4757   - (cons (list 'expression containing-sexp) res))))
4758   - (t
4759   - ;; Statement level.
4760   - (setq res (cons (list 'in-block containing-sexp) res))
4761   - ;; Is it a continuation or a new statement?
4762   - ;; Find previous non-comment character.
4763   - (cperl-backward-to-noncomment containing-sexp)
4764   - ;; Back up over label lines, since they don't
4765   - ;; affect whether our line is a continuation.
4766   - ;; Back up comma-delimited lines too ?????
4767   - (while (or (eq (preceding-char) ?\,)
4768   - (save-excursion (cperl-after-label)))
4769   - (if (eq (preceding-char) ?\,)
4770   - ;; Will go to beginning of line, essentially
4771   - ;; Will ignore embedded sexpr XXXX.
4772   - (cperl-backward-to-start-of-continued-exp containing-sexp))
4773   - (beginning-of-line)
4774   - (cperl-backward-to-noncomment containing-sexp))
4775   - ;; Now we get the answer.
4776   - (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\,
4777   - ;; This line is continuation of preceding line's statement.
4778   - (list (list 'statement-continued containing-sexp))
4779   - ;; This line starts a new statement.
4780   - ;; Position following last unclosed open.
4781   - (goto-char containing-sexp)
4782   - ;; Is line first statement after an open-brace?
4783   - (or
4784   - ;; If no, find that first statement and indent like
4785   - ;; it. If the first statement begins with label, do
4786   - ;; not believe when the indentation of the label is too
4787   - ;; small.
4788   - (save-excursion
4789   - (forward-char 1)
4790   - (let ((colon-line-end 0))
4791   - (while (progn (skip-chars-forward " \t\n" start-point)
4792   - (and (< (point) start-point)
4793   - (looking-at
4794   - "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))
4795   - ;; Skip over comments and labels following openbrace.
4796   - (cond ((= (following-char) ?\#)
4797   - ;;(forward-line 1)
4798   - (end-of-line))
4799   - ;; label:
4800   - (t
4801   - (save-excursion (end-of-line)
4802   - (setq colon-line-end (point)))
4803   - (search-forward ":"))))
4804   - ;; Now at the point, after label, or at start
4805   - ;; of first statement in the block.
4806   - (and (< (point) start-point)
4807   - (if (> colon-line-end (point))
4808   - ;; Before statement after label
4809   - (if (> (current-indentation)
4810   - cperl-min-label-indent)
4811   - (list (list 'label-in-block (point)))
4812   - ;; Do not believe: `max' is involved
4813   - (list
4814   - (list 'label-in-block-min-indent (point))))
4815   - ;; Before statement
4816   - (list 'statement-in-block (point))))))
4817   - ;; If no previous statement,
4818   - ;; indent it relative to line brace is on.
4819   - ;; For open brace in column zero, don't let statement
4820   - ;; start there too. If cperl-indent-level is zero,
4821   - ;; use cperl-brace-offset + cperl-continued-statement-offset instead.
4822   - ;; For open-braces not the first thing in a line,
4823   - ;; add in cperl-brace-imaginary-offset.
4824   -
4825   - ;; If first thing on a line: ?????
4826   - (setq unused ; This is not finished...
4827   - (+ (if (and (bolp) (zerop cperl-indent-level))
4828   - (+ cperl-brace-offset cperl-continued-statement-offset)
4829   - cperl-indent-level)
4830   - ;; Move back over whitespace before the openbrace.
4831   - ;; If openbrace is not first nonwhite thing on the line,
4832   - ;; add the cperl-brace-imaginary-offset.
4833   - (progn (skip-chars-backward " \t")
4834   - (if (bolp) 0 cperl-brace-imaginary-offset))
4835   - ;; If the openbrace is preceded by a parenthesized exp,
4836   - ;; move to the beginning of that;
4837   - ;; possibly a different line
4838   - (progn
4839   - (if (eq (preceding-char) ?\))
4840   - (forward-sexp -1))
4841   - ;; Get initial indentation of the line we are on.
4842   - ;; If line starts with label, calculate label indentation
4843   - (if (save-excursion
4844   - (beginning-of-line)
4845   - (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]"))
4846   - (if (> (current-indentation) cperl-min-label-indent)
4847   - (- (current-indentation) cperl-label-offset)
4848   - (cperl-calculate-indent))
4849   - (current-indentation)))))))))
4850   - res)))
4851   -
4852 4702 (defun cperl-calculate-indent-within-comment ()
4853 4703 "Return the indentation amount for line, assuming that
4854 4704 the current line is to be regarded as part of a block comment."
@@ -5243,8 +5093,10 @@ Should be called with the point before leading colon of an attribute."
5243 5093 (set-syntax-table reset-st))))
5244 5094
5245 5095 (defsubst cperl-look-at-leading-count (is-x-REx e)
5246   - (if (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
5247   - (1- e) t) ; return nil on failure, no moving
  5096 + (if (and
  5097 + (< (point) e)
  5098 + (re-search-forward (concat "\\=" (if is-x-REx "[ \t\n]*" "") "[{?+*]")
  5099 + (1- e) t)) ; return nil on failure, no moving
5248 5100 (if (eq ?\{ (preceding-char)) nil
5249 5101 (cperl-postpone-fontification
5250 5102 (1- (point)) (point)
@@ -6288,8 +6140,8 @@ the sections using `cperl-pod-head-face', `cperl-pod-face',
6288 6140 (if (and is-REx is-x-REx)
6289 6141 (put-text-property (1+ b) (1- e)
6290 6142 'syntax-subtype 'x-REx)))
6291   - (if i2
6292   - (progn
  6143 + (if (and i2 e1 b1 (> e1 b1))
  6144 + (progn ; No errors finding the second part...
6293 6145 (cperl-postpone-fontification
6294 6146 (1- e1) e1 'face my-cperl-delimiters-face)
6295 6147 (if (assoc (char-after b) cperl-starters)
@@ -6383,14 +6235,16 @@ the sections using `cperl-pod-head-face', `cperl-pod-face',
6383 6235 (beginning-of-line)
6384 6236 (if (memq (setq pr (get-text-property (point) 'syntax-type))
6385 6237 '(pod here-doc here-doc-delim))
6386   - (cperl-unwind-to-safe nil)
6387   - (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
6388   - (not (memq pr '(string prestring))))
6389   - (progn (cperl-to-comment-or-eol) (bolp))
6390   - (progn
6391   - (skip-chars-backward " \t")
6392   - (if (< p (point)) (goto-char p))
6393   - (setq stop t)))))))
  6238 + (progn
  6239 + (cperl-unwind-to-safe nil)
  6240 + (setq pr (get-text-property (point) 'syntax-type))))
  6241 + (or (and (looking-at "^[ \t]*\\(#\\|$\\)")
  6242 + (not (memq pr '(string prestring))))
  6243 + (progn (cperl-to-comment-or-eol) (bolp))
  6244 + (progn
  6245 + (skip-chars-backward " \t")
  6246 + (if (< p (point)) (goto-char p))
  6247 + (setq stop t))))))
6394 6248
6395 6249 ;; Used only in `cperl-calculate-indent'...
6396 6250 (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" !
@@ -7243,19 +7097,23 @@ indentation and initial hashes. Behaves usually outside of comment."
7243 7097
7244 7098 (defun cperl-windowed-init ()
7245 7099 "Initialization under windowed version."
7246   - (if (or (featurep 'ps-print) cperl-faces-init)
7247   - ;; Need to init anyway:
7248   - (or cperl-faces-init (cperl-init-faces))
7249   - (add-hook 'font-lock-mode-hook
7250   - (function
7251   - (lambda ()
7252   - (if (memq major-mode '(perl-mode cperl-mode))
7253   - (progn
7254   - (or cperl-faces-init (cperl-init-faces)))))))
7255   - (if (fboundp 'eval-after-load)
7256   - (eval-after-load
7257   - "ps-print"
7258   - '(or cperl-faces-init (cperl-init-faces))))))
  7100 + (cond ((featurep 'ps-print)
  7101 + (or cperl-faces-init
  7102 + (progn
  7103 + (and (boundp 'font-lock-multiline)
  7104 + (setq cperl-font-lock-multiline t))
  7105 + (cperl-init-faces))))
  7106 + ((not cperl-faces-init)
  7107 + (add-hook 'font-lock-mode-hook
  7108 + (function
  7109 + (lambda ()
  7110 + (if (memq major-mode '(perl-mode cperl-mode))
  7111 + (progn
  7112 + (or cperl-faces-init (cperl-init-faces)))))))
  7113 + (if (fboundp 'eval-after-load)
  7114 + (eval-after-load
  7115 + "ps-print"
  7116 + '(or cperl-faces-init (cperl-init-faces)))))))
7259 7117
7260 7118 (defun cperl-load-font-lock-keywords ()
7261 7119 (or cperl-faces-init (cperl-init-faces))
@@ -10573,7 +10431,7 @@ do extra unwind via `cperl-unwind-to-safe'."
10573 10431 (cperl-fontify-syntaxically to)))))
10574 10432
10575 10433 (defvar cperl-version
10576   - (let ((v "$Revision: 5.22 $"))
  10434 + (let ((v "$Revision: 5.23 $"))
10577 10435 (string-match ":\\s *\\([0-9.]+\\)" v)
10578 10436 (substring v (match-beginning 1) (match-end 1)))
10579 10437 "Version of IZ-supported CPerl package this file is based on.")

0 comments on commit 0cb84b0

Please sign in to comment.
Something went wrong with that request. Please try again.