diff lisp/font-lock.el @ 8457:c0492d7043b2

(font-lock-syntax-table): New syntax table. (font-lock-hack-keywords): Use it temporarily here. (font-lock-set-defaults): Set up special syntax table for C and C++.
author Richard M. Stallman <rms@gnu.org>
date Fri, 05 Aug 1994 05:11:30 +0000
parents 970912d4f413
children a465b1335c0b
line wrap: on
line diff
--- a/lisp/font-lock.el	Fri Aug 05 04:33:20 1994 +0000
+++ b/lisp/font-lock.el	Fri Aug 05 05:11:30 1994 +0000
@@ -112,6 +112,10 @@
 (defvar font-lock-keywords-case-fold-search nil
   "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.")
 
+(defvar font-lock-syntax-table nil
+  "*Non-nil means use this syntax table for fontifying.
+If this is nil, the major mode's syntax table is used.")
+
 (defvar font-lock-verbose t
   "*Non-nil means `font-lock-fontify-buffer' should print status messages.")
 
@@ -282,48 +286,55 @@
 	(count 0)
 	(buffer-read-only nil)
 	(modified (buffer-modified-p))
-	first str match face s e allow-overlap-p)
-    (while rest
-      (setq first (car rest) rest (cdr rest))
-      (goto-char start)
-      (cond ((consp first)
-	     (setq str (car first))
-	     (cond ((consp (cdr first))
-		    (setq match (nth 1 first)
-			  face (eval (nth 2 first))
-			  allow-overlap-p (nth 3 first)))
-		   ((symbolp (cdr first))
-		    (setq match 0 allow-overlap-p nil
-			  face (eval (cdr first))))
-		   (t
-		    (setq match (cdr first)
-			  allow-overlap-p nil
-			  face font-lock-keyword-face))))
-	    (t
-	     (setq str first match 0 allow-overlap-p nil
-		   face font-lock-keyword-face)))
-      ;(message "regexp: %s" str)
-      (while (re-search-forward str end t)
-	(setq s (match-beginning match)
-	      e (match-end match))
-	(or s (error "expression did not match subexpression %d" match))
-	;; don't fontify this keyword if we're already in some other context.
-	(or (if allow-overlap-p nil (font-lock-any-properties-p s e))
-	    (if (not (memq allow-overlap-p '(t nil)))
-		(save-excursion
-		  (goto-char s)
-		  (while (< (point) e)
-		    (let ((next (next-single-property-change (point) 'face
-							     nil e)))
-		      (if (or (null next) (> next e))
-			  (setq next e))
-		      (if (not (get-text-property (point) 'face))
-			  (put-text-property (point) next 'face face))
-		      (goto-char next))))
-	      (put-text-property s e 'face face))))
-      (if loudly (message "Fontifying %s... (regexps...%s)"
-			  (buffer-name)
-			  (make-string (setq count (1+ count)) ?.))))
+	first str match face s e allow-overlap-p
+	(old-syntax (syntax-table)))
+    (unwind-protect
+	(progn
+	  (if font-lock-syntax-table
+	      (set-syntax-table font-lock-syntax-table))
+	  (recursive-edit)
+	  (while rest
+	    (setq first (car rest) rest (cdr rest))
+	    (goto-char start)
+	    (cond ((consp first)
+		   (setq str (car first))
+		   (cond ((consp (cdr first))
+			  (setq match (nth 1 first)
+				face (eval (nth 2 first))
+				allow-overlap-p (nth 3 first)))
+			 ((symbolp (cdr first))
+			  (setq match 0 allow-overlap-p nil
+				face (eval (cdr first))))
+			 (t
+			  (setq match (cdr first)
+				allow-overlap-p nil
+				face font-lock-keyword-face))))
+		  (t
+		   (setq str first match 0 allow-overlap-p nil
+			 face font-lock-keyword-face)))
+	    ;(message "regexp: %s" str)
+	    (while (re-search-forward str end t)
+	      (setq s (match-beginning match)
+		    e (match-end match))
+	      (or s (error "expression did not match subexpression %d" match))
+	      ;; don't fontify this keyword if we're already in some other context.
+	      (or (if allow-overlap-p nil (font-lock-any-properties-p s e))
+		  (if (not (memq allow-overlap-p '(t nil)))
+		      (save-excursion
+			(goto-char s)
+			(while (< (point) e)
+			  (let ((next (next-single-property-change (point) 'face
+								   nil e)))
+			    (if (or (null next) (> next e))
+				(setq next e))
+			    (if (not (get-text-property (point) 'face))
+				(put-text-property (point) next 'face face))
+			    (goto-char next))))
+		    (put-text-property s e 'face face))))
+	    (if loudly (message "Fontifying %s... (regexps...%s)"
+				(buffer-name)
+				(make-string (setq count (1+ count)) ?.)))))
+      (set-syntax-table old-syntax))
     (and (buffer-modified-p)
 	 (not modified)
 	 (set-buffer-modified-p nil))))
@@ -702,8 +713,18 @@
       (setq font-lock-keywords
 	    (cond ((eq major-mode 'lisp-mode)	    lisp-font-lock-keywords)
 		  ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords)
-		  ((eq major-mode 'c-mode)	    c-font-lock-keywords)
-		  ((eq major-mode 'c++-c-mode)	    c-font-lock-keywords)
+		  ((eq major-mode 'c-mode)
+		   (make-local-variable 'font-lock-syntax-table)
+		   (setq font-lock-syntax-table
+			 (copy-syntax-table (syntax-table)))
+		   (modify-syntax-entry ?_ "w" font-lock-syntax-table)
+		   c-font-lock-keywords)
+		  ((eq major-mode 'c++-c-mode)
+		   (make-local-variable 'font-lock-syntax-table)
+		   (setq font-lock-syntax-table
+			 (copy-syntax-table (syntax-table)))
+		   (modify-syntax-entry ?_ "w" font-lock-syntax-table)
+		   c-font-lock-keywords)
 		  ((eq major-mode 'c++-mode)	    c++-font-lock-keywords)
 		  ((eq major-mode 'perl-mode) 	    perl-font-lock-keywords)
 		  ((eq major-mode 'plain-tex-mode)  tex-font-lock-keywords)