Mercurial > emacs
comparison 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 |
comparison
equal
deleted
inserted
replaced
8456:2ca3b54b45b1 | 8457:c0492d7043b2 |
---|---|
109 Be careful composing regexps for this list; the wrong pattern can dramatically | 109 Be careful composing regexps for this list; the wrong pattern can dramatically |
110 slow things down!") | 110 slow things down!") |
111 | 111 |
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 | |
115 (defvar font-lock-syntax-table nil | |
116 "*Non-nil means use this syntax table for fontifying. | |
117 If this is nil, the major mode's syntax table is used.") | |
114 | 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 |
118 ;;;###autoload | 122 ;;;###autoload |
280 (let ((case-fold-search font-lock-keywords-case-fold-search) | 284 (let ((case-fold-search font-lock-keywords-case-fold-search) |
281 (rest font-lock-keywords) | 285 (rest font-lock-keywords) |
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)))) |
330 | 341 |
331 ;; The user level functions | 342 ;; The user level functions |
700 (setq font-lock-no-comments t)) | 711 (setq font-lock-no-comments t)) |
701 (if (not font-lock-keywords) ; if not already set. | 712 (if (not font-lock-keywords) ; if not already set. |
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) |
710 ((eq major-mode 'latex-mode) tex-font-lock-keywords) | 731 ((eq major-mode 'latex-mode) tex-font-lock-keywords) |
711 ((eq major-mode 'slitex-mode) tex-font-lock-keywords) | 732 ((eq major-mode 'slitex-mode) tex-font-lock-keywords) |