# HG changeset patch # User Richard M. Stallman # Date 776063490 0 # Node ID c0492d7043b2c902af6766a3362031e3586c5e37 # Parent 2ca3b54b45b1707c73e48554518c44a2a02ae5f0 (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++. diff -r 2ca3b54b45b1 -r c0492d7043b2 lisp/font-lock.el --- 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)