From 214507c70f05935aac7cfa811b2e3a47335943fb Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Thu, 16 Sep 1993 14:56:45 +0000 Subject: [PATCH] (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. --- lisp/font-lock.el | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/lisp/font-lock.el b/lisp/font-lock.el index 87a134f1e88..ae8d5764e5d 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -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 @@ slow things down!") (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 @@ slow things down!") (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 @@ slow things down!") (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 @@ slow things down!") (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 @@ slow things down!") ;;; 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 @@ slow things down!") (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 @@ This can take a while for large buffers." ;;; 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 @@ This does a lot more highlighting.") 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 <...> -- 2.11.4.GIT