1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-12 16:23:57 +00:00

(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++.
This commit is contained in:
Richard M. Stallman 1994-08-05 05:11:30 +00:00
parent 168e43e724
commit b056da51fb

View File

@ -112,6 +112,10 @@ slow things down!")
(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 @@ slow things down!")
(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 @@ This does a lot more highlighting.")
(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)