"*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,
(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))
(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)
(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)))
(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
;;; 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)
(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)) ?.))))
;;; 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)
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 <...>