Mercurial > emacs
changeset 26775:ea2b51ce35a7
(font-lock-multiline): New variable.
(font-lock-add-keywords): Rename `major-mode' into `mode'.
(font-lock-remove-keywords): Added a dummy `mode' argument for
potential future support.
(font-lock-fontify-anchored-keywords,
(font-lock-fontify-keywords-region): Only handle multiline strings
if necessary (avoids a pathological behavior in (f.ex) diff-mode).
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 09 Dec 1999 12:52:34 +0000 |
parents | 57be3cdaebfb |
children | 142d6aa7c470 |
files | lisp/font-lock.el |
diffstat | 1 files changed, 30 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/font-lock.el Thu Dec 09 04:49:37 1999 +0000 +++ b/lisp/font-lock.el Thu Dec 09 12:52:34 1999 +0000 @@ -596,6 +596,13 @@ Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and `lazy-lock-mode'. This is normally set via `font-lock-defaults'.") +(defvar font-lock-multiline 'undecided + "Whether font-lock should cater to multiline keywords. +If nil, don't try to handle multiline patterns. +If t, always handle multiline patterns. +If `undecided', don't try to handle multiline patterns until you see one. +Major/minor modes can set this variable if they know which option applies.") + (defvar font-lock-mode nil) ; Whether we are turned on/modeline. (defvar font-lock-fontified nil) ; Whether we have fontified the buffer. @@ -720,9 +727,9 @@ (font-lock-mode))) ;;;###autoload -(defun font-lock-add-keywords (major-mode keywords &optional append) - "Add highlighting KEYWORDS for MAJOR-MODE. -MAJOR-MODE should be a symbol, the major mode command name, such as `c-mode' +(defun font-lock-add-keywords (mode keywords &optional append) + "Add highlighting KEYWORDS for MODE. +MODE should be a symbol, the major mode command name, such as `c-mode' or nil. If nil, highlighting keywords are added for the current buffer. KEYWORDS should be a list; see the variable `font-lock-keywords'. By default they are added at the beginning of the current highlighting list. @@ -742,18 +749,18 @@ Note that some modes have specialised support for additional patterns, e.g., see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types', `objc-font-lock-extra-types' and `java-font-lock-extra-types'." - (cond (major-mode - ;; If MAJOR-MODE is non-nil, add the KEYWORDS and APPEND spec to + (cond (mode + ;; If MODE is non-nil, add the KEYWORDS and APPEND spec to ;; `font-lock-keywords-alist' so `font-lock-set-defaults' uses them. (let ((spec (cons keywords append)) cell) - (if (setq cell (assq major-mode font-lock-keywords-alist)) + (if (setq cell (assq mode font-lock-keywords-alist)) (setcdr cell (append (cdr cell) (list spec))) - (push (list major-mode spec) font-lock-keywords-alist)))) + (push (list mode spec) font-lock-keywords-alist)))) (font-lock-mode ;; Otherwise if Font Lock mode is on, set or add the keywords now. (if (eq append 'set) (setq font-lock-keywords keywords) - (font-lock-remove-keywords keywords) + (font-lock-remove-keywords nil keywords) (let ((old (if (eq (car-safe font-lock-keywords) t) (cdr font-lock-keywords) font-lock-keywords))) @@ -762,8 +769,9 @@ (append keywords old)))))))) ;;;###autoload -(defun font-lock-remove-keywords (keywords) - "Remove highlighting KEYWORDS from the current buffer." +(defun font-lock-remove-keywords (mode keywords) + "Remove highlighting KEYWORDS from the current buffer. +A non-nil MODE is currently unsupported." (setq font-lock-keywords (copy-list font-lock-keywords)) (dolist (keyword keywords) (setq font-lock-keywords @@ -1462,8 +1470,12 @@ (if (not (and (numberp pre-match-value) (> pre-match-value (point)))) (save-excursion (end-of-line) (setq limit (point))) (setq limit pre-match-value) - (when (>= pre-match-value (save-excursion (forward-line 1) (point))) + (when (and font-lock-multiline + (funcall (if (eq font-lock-multiline t) '>= '>) + pre-match-value + (save-excursion (forward-line 1) (point)))) ;; this is a multiline anchored match + (set (make-local-variable 'font-lock-multiline) t) (put-text-property (point) limit 'font-lock-multiline t))) (save-match-data ;; Find an occurrence of `matcher' before `limit'. @@ -1500,11 +1512,14 @@ (if (stringp matcher) (re-search-forward matcher end t) (funcall matcher end))) - (when (and (match-beginning 0) - (>= (point) - (save-excursion (goto-char (match-beginning 0)) - (forward-line 1) (point)))) + (when (and font-lock-multiline + (match-beginning 0) + (funcall (if (eq font-lock-multiline t) '>= '>) + (point) + (save-excursion (goto-char (match-beginning 0)) + (forward-line 1) (point)))) ;; this is a multiline regexp match + (set (make-local-variable 'font-lock-multiline) t) (put-text-property (match-beginning 0) (point) 'font-lock-multiline t)) ;; Apply each highlight to this instance of `matcher', which may be