changeset 25596:359d6e7a6ffc

(font-lock-multiline): New text property contains a boolean to indicate if the char is part of a multiline match. (font-lock-default-fontify-region): Extend the region appropriately for multiline keywords. (font-lock-default-unfontify-region): Also remove the new font-lock-multiline text property. (font-lock-fontify-anchored-keywords): Mark multiline anchored matches. (font-lock-fontify-keywords-region): Mark multiline regexp matches.
author Richard M. Stallman <rms@gnu.org>
date Tue, 07 Sep 1999 19:21:50 +0000
parents 6671095a2649
children 16a9c3c6f90e
files lisp/font-lock.el
diffstat 1 files changed, 28 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/font-lock.el	Tue Sep 07 18:20:27 1999 +0000
+++ b/lisp/font-lock.el	Tue Sep 07 19:21:50 1999 +0000
@@ -1093,6 +1093,16 @@
 	  ;; Use the fontification syntax table, if any.
 	  (when font-lock-syntax-table
 	    (set-syntax-table font-lock-syntax-table))
+	  ;; check to see if we should expand the beg/end area for
+	  ;; proper multiline matches
+	  (setq beg (if (get-text-property beg 'font-lock-multiline)
+			(or (previous-single-property-change
+			     beg 'font-lock-multiline)
+			    (point-min))
+		      beg))
+	  (setq end (or (text-property-any end (point-max)
+					   'font-lock-multiline nil)
+			(point-max)))
 	  ;; Now do the fontification.
 	  (font-lock-unfontify-region beg end)
 	  (when font-lock-syntactic-keywords
@@ -1113,9 +1123,10 @@
 
 (defun font-lock-default-unfontify-region (beg end)
   (save-buffer-state nil
-    (if font-lock-syntactic-keywords
-	(remove-text-properties beg end '(face nil syntax-table nil))
-      (remove-text-properties beg end '(face nil)))))
+    (remove-text-properties beg end
+			    (if font-lock-syntactic-keywords
+				'(face nil syntax-table nil font-lock-multiline nil)
+			      '(face nil font-lock-multiline nil)))))
 
 ;; Called when any modification is made to buffer text.
 (defun font-lock-after-change-function (beg end old-len)
@@ -1425,12 +1436,16 @@
 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
 LIMIT can be modified by the value of its PRE-MATCH-FORM."
   (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
+	(lead-start (match-beginning 0))
 	;; Evaluate PRE-MATCH-FORM.
 	(pre-match-value (eval (nth 1 keywords))))
     ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
-    (if (and (numberp pre-match-value) (> pre-match-value (point)))
-	(setq limit pre-match-value)
-      (save-excursion (end-of-line) (setq limit (point))))
+    (if (not (and (numberp pre-match-value) (> pre-match-value (point))))
+	(save-excursion (end-of-line) (setq limit (point)))
+      (setq limit pre-match-value)
+      (when (>= pre-match-value (save-excursion (forward-line 1) (point)))
+	;; this is a multiline anchored match
+	(put-text-property (point) limit 'font-lock-multiline t)))
     (save-match-data
       ;; Find an occurrence of `matcher' before `limit'.
       (while (if (stringp matcher)
@@ -1466,6 +1481,13 @@
 		  (if (stringp matcher)
 		      (re-search-forward matcher end t)
 		    (funcall matcher end)))
+	(when (and (match-beginning 0)
+		   (>= (point)
+		       (save-excursion (goto-char (match-beginning 0))
+				       (forward-line 1) (point))))
+	  ;; this is a multiline regexp match
+	  (put-text-property (match-beginning 0) (point)
+			     'font-lock-multiline t))
 	;; Apply each highlight to this instance of `matcher', which may be
 	;; specific highlights or more keywords anchored to `matcher'.
 	(setq highlights (cdr keyword))