aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-08-05 05:11:30 +0000
committerRichard M. Stallman1994-08-05 05:11:30 +0000
commitb056da51fb5b4c2d16f7b1e92ba6025aa6a2b1c9 (patch)
treef10abff86dce587e299832e184b0944417284fbc
parent168e43e7247fc8b3f10b695a7c73f62363c07872 (diff)
downloademacs-b056da51fb5b4c2d16f7b1e92ba6025aa6a2b1c9.tar.gz
emacs-b056da51fb5b4c2d16f7b1e92ba6025aa6a2b1c9.zip
(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++.
-rw-r--r--lisp/font-lock.el109
1 files changed, 65 insertions, 44 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index d7ef4013fcf..26cdc96ad64 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -112,6 +112,10 @@ slow things down!")
112(defvar font-lock-keywords-case-fold-search nil 112(defvar font-lock-keywords-case-fold-search nil
113 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.") 113 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.")
114 114
115(defvar font-lock-syntax-table nil
116 "*Non-nil means use this syntax table for fontifying.
117If this is nil, the major mode's syntax table is used.")
118
115(defvar font-lock-verbose t 119(defvar font-lock-verbose t
116 "*Non-nil means `font-lock-fontify-buffer' should print status messages.") 120 "*Non-nil means `font-lock-fontify-buffer' should print status messages.")
117 121
@@ -282,48 +286,55 @@ slow things down!")
282 (count 0) 286 (count 0)
283 (buffer-read-only nil) 287 (buffer-read-only nil)
284 (modified (buffer-modified-p)) 288 (modified (buffer-modified-p))
285 first str match face s e allow-overlap-p) 289 first str match face s e allow-overlap-p
286 (while rest 290 (old-syntax (syntax-table)))
287 (setq first (car rest) rest (cdr rest)) 291 (unwind-protect
288 (goto-char start) 292 (progn
289 (cond ((consp first) 293 (if font-lock-syntax-table
290 (setq str (car first)) 294 (set-syntax-table font-lock-syntax-table))
291 (cond ((consp (cdr first)) 295 (recursive-edit)
292 (setq match (nth 1 first) 296 (while rest
293 face (eval (nth 2 first)) 297 (setq first (car rest) rest (cdr rest))
294 allow-overlap-p (nth 3 first))) 298 (goto-char start)
295 ((symbolp (cdr first)) 299 (cond ((consp first)
296 (setq match 0 allow-overlap-p nil 300 (setq str (car first))
297 face (eval (cdr first)))) 301 (cond ((consp (cdr first))
298 (t 302 (setq match (nth 1 first)
299 (setq match (cdr first) 303 face (eval (nth 2 first))
300 allow-overlap-p nil 304 allow-overlap-p (nth 3 first)))
301 face font-lock-keyword-face)))) 305 ((symbolp (cdr first))
302 (t 306 (setq match 0 allow-overlap-p nil
303 (setq str first match 0 allow-overlap-p nil 307 face (eval (cdr first))))
304 face font-lock-keyword-face))) 308 (t
305 ;(message "regexp: %s" str) 309 (setq match (cdr first)
306 (while (re-search-forward str end t) 310 allow-overlap-p nil
307 (setq s (match-beginning match) 311 face font-lock-keyword-face))))
308 e (match-end match)) 312 (t
309 (or s (error "expression did not match subexpression %d" match)) 313 (setq str first match 0 allow-overlap-p nil
310 ;; don't fontify this keyword if we're already in some other context. 314 face font-lock-keyword-face)))
311 (or (if allow-overlap-p nil (font-lock-any-properties-p s e)) 315 ;(message "regexp: %s" str)
312 (if (not (memq allow-overlap-p '(t nil))) 316 (while (re-search-forward str end t)
313 (save-excursion 317 (setq s (match-beginning match)
314 (goto-char s) 318 e (match-end match))
315 (while (< (point) e) 319 (or s (error "expression did not match subexpression %d" match))
316 (let ((next (next-single-property-change (point) 'face 320 ;; don't fontify this keyword if we're already in some other context.
317 nil e))) 321 (or (if allow-overlap-p nil (font-lock-any-properties-p s e))
318 (if (or (null next) (> next e)) 322 (if (not (memq allow-overlap-p '(t nil)))
319 (setq next e)) 323 (save-excursion
320 (if (not (get-text-property (point) 'face)) 324 (goto-char s)
321 (put-text-property (point) next 'face face)) 325 (while (< (point) e)
322 (goto-char next)))) 326 (let ((next (next-single-property-change (point) 'face
323 (put-text-property s e 'face face)))) 327 nil e)))
324 (if loudly (message "Fontifying %s... (regexps...%s)" 328 (if (or (null next) (> next e))
325 (buffer-name) 329 (setq next e))
326 (make-string (setq count (1+ count)) ?.)))) 330 (if (not (get-text-property (point) 'face))
331 (put-text-property (point) next 'face face))
332 (goto-char next))))
333 (put-text-property s e 'face face))))
334 (if loudly (message "Fontifying %s... (regexps...%s)"
335 (buffer-name)
336 (make-string (setq count (1+ count)) ?.)))))
337 (set-syntax-table old-syntax))
327 (and (buffer-modified-p) 338 (and (buffer-modified-p)
328 (not modified) 339 (not modified)
329 (set-buffer-modified-p nil)))) 340 (set-buffer-modified-p nil))))
@@ -702,8 +713,18 @@ This does a lot more highlighting.")
702 (setq font-lock-keywords 713 (setq font-lock-keywords
703 (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords) 714 (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords)
704 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords) 715 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords)
705 ((eq major-mode 'c-mode) c-font-lock-keywords) 716 ((eq major-mode 'c-mode)
706 ((eq major-mode 'c++-c-mode) c-font-lock-keywords) 717 (make-local-variable 'font-lock-syntax-table)
718 (setq font-lock-syntax-table
719 (copy-syntax-table (syntax-table)))
720 (modify-syntax-entry ?_ "w" font-lock-syntax-table)
721 c-font-lock-keywords)
722 ((eq major-mode 'c++-c-mode)
723 (make-local-variable 'font-lock-syntax-table)
724 (setq font-lock-syntax-table
725 (copy-syntax-table (syntax-table)))
726 (modify-syntax-entry ?_ "w" font-lock-syntax-table)
727 c-font-lock-keywords)
707 ((eq major-mode 'c++-mode) c++-font-lock-keywords) 728 ((eq major-mode 'c++-mode) c++-font-lock-keywords)
708 ((eq major-mode 'perl-mode) perl-font-lock-keywords) 729 ((eq major-mode 'perl-mode) perl-font-lock-keywords)
709 ((eq major-mode 'plain-tex-mode) tex-font-lock-keywords) 730 ((eq major-mode 'plain-tex-mode) tex-font-lock-keywords)