Mercurial > emacs
changeset 4727:ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
(font-lock-unfontify-region): Don't remove `font-lock' props.
(font-lock-hack-keywords): Don't add `font-lock' props.
Handle values other than t and nil for allow-overlap-p specially.
(c-font-lock-keywords-1): Don't override how comments in #if... appear.
Highlight text after #else or #endif.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 16 Sep 1993 14:56:45 +0000 |
parents | f7a2f8a2f883 |
children | 49643e1db119 |
files | lisp/font-lock.el |
diffstat | 1 files changed, 31 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/font-lock.el Wed Sep 15 23:19:13 1993 +0000 +++ b/lisp/font-lock.el Thu Sep 16 14:56:45 1993 +0000 @@ -87,13 +87,17 @@ "*The keywords to highlight. If this is a list, then elements may be of the forms: - \"string\" ; a regexp to highlight in the + \"string\" ; A regexp to highlight in the ; `font-lock-keyword-face'. - (\"string\" . integer) ; match N of the regexp will be highlighted - (\"string\" . face-name) ; use the named face - (\"string\" integer face-name) ; both of the above - (\"string\" integer face-name t) ; this allows highlighting to overlap - ; with already-highlighted regions. + (\"string\" . N) ; Highlight subexpression N of the regexp. + (\"string\" . face-name) ; Use the named face + (\"string\" N face-name) ; Both of the above + (\"string\" N face-name t) ; This allows highlighting to override + ; already-highlighted regions. + (\"string\" N face-name keep) ; This allows highlighting to occur + ; even if some parts of what STRING matches + ; are already highlighted--but does not alter + ; the existing highlighting of those parts. These regular expressions should not match text which spans lines. While \\[font-lock-fontify-buffer] handles multi-line patterns correctly, @@ -150,7 +154,6 @@ (nth 3 (parse-partial-sexp beg (point) nil nil state)))) (put-text-property beg (point) 'face font-lock-string-face) - (put-text-property beg (point) 'font-lock t) (setq state (parse-partial-sexp beg (point) nil nil state)))) ;; Likewise for a comment. (if (or (nth 4 state) (nth 7 state)) @@ -163,7 +166,6 @@ (nth 3 (parse-partial-sexp beg (point) nil nil state)))) (put-text-property beg (point) 'face font-lock-comment-face) - (put-text-property beg (point) 'font-lock t) (setq state (parse-partial-sexp beg (point) nil nil state)))) ;; Find each interesting place between here and END. (while (and (< (point) end) @@ -193,7 +195,6 @@ (skip-chars-backward " \t")) (error (goto-char end)))) (put-text-property beg (point) 'face font-lock-comment-face) - (put-text-property beg (point) 'font-lock t) (setq state (parse-partial-sexp here (point) nil nil state))) (if (nth 3 state) (let ((beg (match-beginning 0))) @@ -201,7 +202,6 @@ (nth 3 (parse-partial-sexp here (point) nil nil state)))) (put-text-property beg (point) 'face font-lock-string-face) - (put-text-property beg (point) 'font-lock t) (setq state (parse-partial-sexp here (point) nil nil state)))) )) ;; Make sure PREV is non-nil after the loop @@ -265,8 +265,8 @@ ;;; Fontifying arbitrary patterns (defsubst font-lock-any-properties-p (start end) - (or (get-text-property start 'font-lock) - (let ((next (next-single-property-change start 'font-lock))) + (or (get-text-property start 'face) + (let ((next (next-single-property-change start 'face))) (and next (< next end))))) (defun font-lock-hack-keywords (start end &optional loudly) @@ -303,9 +303,19 @@ (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)) - (progn - (put-text-property s e 'face face) - (put-text-property s e 'font-lock t)))) + (if (not (memq allow-overlap-p '(t nil))) + (save-excursion + (goto-char s) + (save-restriction + (narrow-to-region s e) + (while (not (eobp)) + (let ((next (next-single-property-change (point) 'face))) + (if (> next (point-max)) + (setq next (point-max))) + (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)) ?.)))) @@ -399,7 +409,7 @@ ;;; Various mode-specific information. (defun font-lock-set-defaults () - "sets font-lock-keywords to something appropriate for this mode." + "Set `font-lock-keywords' to something appropriate for this mode." (setq font-lock-keywords (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords) ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords) @@ -482,7 +492,11 @@ font-lock-function-name-face) ;; ;; fontify other preprocessor lines. - '("^#[ \t]*\\(if\\|ifn?def\\)[ \t]+\\([^\n]+\\)" + '("^#[ \t]*\\(if\\)[ \t]+\\([^\n]+\\)" + 2 font-lock-function-name-face keep) + '("^#[ \t]*\\(endif\\|else\\)[ \t]+\\([^\n]+\\)" + 2 font-lock-function-name-face keep) + '("^#[ \t]*\\(ifn?def\\)[ \t]+\\([^ \t\n]+\\)" 2 font-lock-function-name-face t) ;; ;; fontify the filename in #include <...>