aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-02-07 01:49:33 +0000
committerStefan Monnier2000-02-07 01:49:33 +0000
commit6e1d0d151dbcb24c71654345358be05f797a7841 (patch)
tree1c9cca60feff8d0b11ffb04a161d747844472236
parent66e4690ffa2438bc74a082d614206a877f4a97e2 (diff)
downloademacs-6e1d0d151dbcb24c71654345358be05f797a7841.tar.gz
emacs-6e1d0d151dbcb24c71654345358be05f797a7841.zip
(font-lock-keywords): Fix doc for multiline matches.
(font-lock-add-keywords): Make it work even if font-lock-mode is nil, so that it can be used more easily in <foo>-mode-hook. Also make sure to avoid duplicate entries. (font-lock-update-removed-keyword-alist): Renamed `major-mode'->`mode'. (font-lock-remove-keywords): Just as was done for `add', allow it to work even if font-lock-mode is nil. Also make sure we don't modify any pre-existing list by forcing a copy-sequence. Finally rename `major-mode' to `mode'. (font-lock-fontify-syntactic-anchored-keywords) (font-lock-fontify-anchored-keywords) (font-lock-fontify-keywords-region): Use line-end-position. Don't make `font-lock-multiline' local (it's now done in font-lock-set-defaults). (font-lock-set-defaults): Make `font-lock-multiline' local. Also move the `font-lock-fontified' creation to inside the `unless'.
-rw-r--r--lisp/ChangeLog19
-rw-r--r--lisp/font-lock.el77
2 files changed, 60 insertions, 36 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5948451a086..121ea011e45 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,22 @@
12000-02-06 Stefan Monnier <monnier@cs.yale.edu>
2
3 * font-lock.el (font-lock-keywords): Fix doc for multiline matches.
4 (font-lock-add-keywords): Make it work even if font-lock-mode is nil,
5 so that it can be used more easily in <foo>-mode-hook. Also make sure
6 to avoid duplicate entries.
7 (font-lock-update-removed-keyword-alist): Renamed `major-mode'->`mode'.
8 (font-lock-remove-keywords): Just as was done for `add', allow it to
9 work even if font-lock-mode is nil. Also make sure we don't modify
10 any pre-existing list by forcing a copy-sequence. Finally rename
11 `major-mode' to `mode'.
12 (font-lock-fontify-syntactic-anchored-keywords)
13 (font-lock-fontify-anchored-keywords)
14 (font-lock-fontify-keywords-region): Use line-end-position.
15 Don't make `font-lock-multiline' local (it's now done in
16 font-lock-set-defaults).
17 (font-lock-set-defaults): Make `font-lock-multiline' local. Also
18 move the `font-lock-fontified' creation to inside the `unless'.
19
12000-02-06 Andrew Innes <andrewi@gnu.org> 202000-02-06 Andrew Innes <andrewi@gnu.org>
2 21
3 * term/w32-win.el (x-handle-args): Comment out call to message, 22 * term/w32-win.el (x-handle-args): Comment out call to message,
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index cecc933b621..f264805f3d7 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -389,9 +389,10 @@ PRE-MATCH-FORM is evaluated, that position is used as the limit of the search.
389It is generally a bad idea to return a position greater than the end of the 389It is generally a bad idea to return a position greater than the end of the
390line, i.e., cause the MATCHER search to span lines. 390line, i.e., cause the MATCHER search to span lines.
391 391
392These regular expressions should not match text which spans lines. While 392These regular expressions can match text which spans lines, although
393\\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating 393it is better to avoid it if possible since updating them while editing
394when you edit the buffer does not, since it considers text one line at a time. 394text is slower, and it is not guaranteed to be always correct when using
395support modes like jit-lock or lazy-lock.
395 396
396This variable is set by major modes via the variable `font-lock-defaults'. 397This variable is set by major modes via the variable `font-lock-defaults'.
397Be careful when composing regexps for this list; a poorly written pattern can 398Be careful when composing regexps for this list; a poorly written pattern can
@@ -768,11 +769,12 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
768 ;; Make sure that `font-lock-removed-keywords-alist' does not 769 ;; Make sure that `font-lock-removed-keywords-alist' does not
769 ;; contain the new keywords. 770 ;; contain the new keywords.
770 (font-lock-update-removed-keyword-alist mode keywords append)) 771 (font-lock-update-removed-keyword-alist mode keywords append))
771 (font-lock-mode 772 (t
772 ;; Otherwise if Font Lock mode is on, set or add the keywords now. 773 ;; Otherwise set or add the keywords now.
773 (if (eq append 'set) 774 (font-lock-set-defaults)
774 (setq font-lock-keywords keywords) 775 (if (eq append 'set)
775 (font-lock-remove-keywords mode keywords) 776 (setq font-lock-keywords keywords)
777 (font-lock-remove-keywords nil keywords) ;to avoid duplicates
776 (let ((old (if (eq (car-safe font-lock-keywords) t) 778 (let ((old (if (eq (car-safe font-lock-keywords) t)
777 (cdr font-lock-keywords) 779 (cdr font-lock-keywords)
778 font-lock-keywords))) 780 font-lock-keywords)))
@@ -780,9 +782,9 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
780 (append old keywords) 782 (append old keywords)
781 (append keywords old)))))))) 783 (append keywords old))))))))
782 784
783(defun font-lock-update-removed-keyword-alist (major-mode keywords append) 785(defun font-lock-update-removed-keyword-alist (mode keywords append)
784 ;; Update `font-lock-removed-keywords-alist' when adding new 786 ;; Update `font-lock-removed-keywords-alist' when adding new
785 ;; KEYWORDS to MAJOR-MODE. 787 ;; KEYWORDS to MODE.
786 ;; 788 ;;
787 ;; When font-lock is enabled first all keywords in the list 789 ;; When font-lock is enabled first all keywords in the list
788 ;; `font-lock-keywords-alist' are added, then all keywords in the 790 ;; `font-lock-keywords-alist' are added, then all keywords in the
@@ -790,7 +792,7 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
790 ;; keyword was once added, removed, and then added again it must be 792 ;; keyword was once added, removed, and then added again it must be
791 ;; removed from the removed-keywords list. Otherwise the second add 793 ;; removed from the removed-keywords list. Otherwise the second add
792 ;; will not take effect. 794 ;; will not take effect.
793 (let ((cell (assq major-mode font-lock-removed-keywords-alist))) 795 (let ((cell (assq mode font-lock-removed-keywords-alist)))
794 (if cell 796 (if cell
795 (if (eq append 'set) 797 (if (eq append 'set)
796 ;; A new set of keywords is defined. Forget all about 798 ;; A new set of keywords is defined. Forget all about
@@ -800,7 +802,7 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
800 ;; Delete all previously removed keywords. 802 ;; Delete all previously removed keywords.
801 (dolist (kword keywords) 803 (dolist (kword keywords)
802 (setcdr cell (delete kword (cdr cell)))) 804 (setcdr cell (delete kword (cdr cell))))
803 ;; Delete the major-mode cell if empty. 805 ;; Delete the mode cell if empty.
804 (if (null (cdr cell)) 806 (if (null (cdr cell))
805 (setq font-lock-removed-keywords-alist 807 (setq font-lock-removed-keywords-alist
806 (delq cell font-lock-removed-keywords-alist))))))) 808 (delq cell font-lock-removed-keywords-alist)))))))
@@ -825,16 +827,16 @@ see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
825;; 827;;
826;; (II) The keywords are removed from the current buffer. 828;; (II) The keywords are removed from the current buffer.
827;;;###autoload 829;;;###autoload
828(defun font-lock-remove-keywords (major-mode keywords) 830(defun font-lock-remove-keywords (mode keywords)
829 "Remove highlighting KEYWORDS for MAJOR-MODE. 831 "Remove highlighting KEYWORDS for MODE.
830 832
831MAJOR-MODE should be a symbol, the major mode command name, such as `c-mode' 833MODE should be a symbol, the major mode command name, such as `c-mode'
832or nil. If nil, highlighting keywords are removed for the current buffer." 834or nil. If nil, highlighting keywords are removed for the current buffer."
833 (dolist (keyword keywords) 835 (cond (mode
834 ;; Remove one keyword at the time. 836 ;; Remove one keyword at the time.
835 (cond (major-mode 837 (dolist (keyword keywords)
836 (let ((top-cell (assq major-mode font-lock-keywords-alist))) 838 (let ((top-cell (assq mode font-lock-keywords-alist)))
837 ;; If MAJOR-MODE is non-nil, remove the KEYWORD from 839 ;; If MODE is non-nil, remove the KEYWORD from
838 ;; `font-lock-keywords-alist'. 840 ;; `font-lock-keywords-alist'.
839 (when top-cell 841 (when top-cell
840 (dolist (keyword-list-append-pair (cdr top-cell)) 842 (dolist (keyword-list-append-pair (cdr top-cell))
@@ -859,19 +861,22 @@ or nil. If nil, highlighting keywords are removed for the current buffer."
859 (setq font-lock-keywords-alist 861 (setq font-lock-keywords-alist
860 (delq top-cell font-lock-keywords-alist)))) 862 (delq top-cell font-lock-keywords-alist))))
861 ;; Remember the keyword in case it is not local. 863 ;; Remember the keyword in case it is not local.
862 (let ((cell (assq major-mode font-lock-removed-keywords-alist))) 864 (let ((cell (assq mode font-lock-removed-keywords-alist)))
863 (if cell 865 (if cell
864 (unless (member keyword (cdr cell)) 866 (unless (member keyword (cdr cell))
865 (nconc cell (list keyword))) 867 (nconc cell (list keyword)))
866 (push (cons major-mode (list keyword)) 868 (push (cons mode (list keyword))
867 font-lock-removed-keywords-alist))))) 869 font-lock-removed-keywords-alist))))))
868 (font-lock-mode 870 (t
869 ;; Otherwise if Font Lock mode is on, remove it immediately. 871 ;; Otherwise remove it immediately.
870 (setq font-lock-keywords (delete keyword font-lock-keywords)) 872 (font-lock-set-defaults)
871 ;; The keywords might be compiled. 873 (setq font-lock-keywords (copy-sequence font-lock-keywords))
874 (dolist (keyword keywords)
872 (setq font-lock-keywords 875 (setq font-lock-keywords
873 (delete (font-lock-compile-keyword keyword) 876 (delete keyword
874 font-lock-keywords)))))) 877 ;; The keywords might be compiled.
878 (delete (font-lock-compile-keyword keyword)
879 font-lock-keywords)))))))
875 880
876;;; Global Font Lock mode. 881;;; Global Font Lock mode.
877 882
@@ -1412,7 +1417,7 @@ LIMIT can be modified by the value of its PRE-MATCH-FORM."
1412 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line. 1417 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
1413 (if (and (numberp pre-match-value) (> pre-match-value (point))) 1418 (if (and (numberp pre-match-value) (> pre-match-value (point)))
1414 (setq limit pre-match-value) 1419 (setq limit pre-match-value)
1415 (save-excursion (end-of-line) (setq limit (point)))) 1420 (setq limit (line-end-position)))
1416 (save-match-data 1421 (save-match-data
1417 ;; Find an occurrence of `matcher' before `limit'. 1422 ;; Find an occurrence of `matcher' before `limit'.
1418 (while (if (stringp matcher) 1423 (while (if (stringp matcher)
@@ -1561,14 +1566,14 @@ LIMIT can be modified by the value of its PRE-MATCH-FORM."
1561 (pre-match-value (eval (nth 1 keywords)))) 1566 (pre-match-value (eval (nth 1 keywords))))
1562 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line. 1567 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
1563 (if (not (and (numberp pre-match-value) (> pre-match-value (point)))) 1568 (if (not (and (numberp pre-match-value) (> pre-match-value (point))))
1564 (save-excursion (end-of-line) (setq limit (point))) 1569 (setq limit (line-end-position))
1565 (setq limit pre-match-value) 1570 (setq limit pre-match-value)
1566 (when (and font-lock-multiline 1571 (when (and font-lock-multiline
1567 (funcall (if (eq font-lock-multiline t) '>= '>) 1572 (funcall (if (eq font-lock-multiline t) '>= '>)
1568 pre-match-value 1573 pre-match-value
1569 (save-excursion (forward-line 1) (point)))) 1574 (save-excursion (forward-line 1) (point))))
1570 ;; this is a multiline anchored match 1575 ;; this is a multiline anchored match
1571 (set (make-local-variable 'font-lock-multiline) t) 1576 (setq font-lock-multiline t)
1572 (put-text-property (point) limit 'font-lock-multiline t))) 1577 (put-text-property (point) limit 'font-lock-multiline t)))
1573 (save-match-data 1578 (save-match-data
1574 ;; Find an occurrence of `matcher' before `limit'. 1579 ;; Find an occurrence of `matcher' before `limit'.
@@ -1612,7 +1617,7 @@ START should be at the beginning of a line."
1612 (save-excursion (goto-char (match-beginning 0)) 1617 (save-excursion (goto-char (match-beginning 0))
1613 (forward-line 1) (point)))) 1618 (forward-line 1) (point))))
1614 ;; this is a multiline regexp match 1619 ;; this is a multiline regexp match
1615 (set (make-local-variable 'font-lock-multiline) t) 1620 (setq font-lock-multiline t)
1616 (put-text-property (match-beginning 0) (point) 1621 (put-text-property (match-beginning 0) (point)
1617 'font-lock-multiline t)) 1622 'font-lock-multiline t))
1618 ;; Apply each highlight to this instance of `matcher', which may be 1623 ;; Apply each highlight to this instance of `matcher', which may be
@@ -1690,13 +1695,13 @@ A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to
1690 "Set fontification defaults appropriately for this mode. 1695 "Set fontification defaults appropriately for this mode.
1691Sets various variables using `font-lock-defaults' (or, if nil, using 1696Sets various variables using `font-lock-defaults' (or, if nil, using
1692`font-lock-defaults-alist') and `font-lock-maximum-decoration'." 1697`font-lock-defaults-alist') and `font-lock-maximum-decoration'."
1693 ;; Set fontification defaults. 1698 ;; Set fontification defaults iff not previously set.
1694 (make-local-variable 'font-lock-fontified)
1695 ;; Set iff not previously set.
1696 (unless font-lock-set-defaults 1699 (unless font-lock-set-defaults
1697 (set (make-local-variable 'font-lock-set-defaults) t) 1700 (set (make-local-variable 'font-lock-set-defaults) t)
1698 (set (make-local-variable 'font-lock-cache-state) nil) 1701 (set (make-local-variable 'font-lock-cache-state) nil)
1699 (set (make-local-variable 'font-lock-cache-position) (make-marker)) 1702 (set (make-local-variable 'font-lock-cache-position) (make-marker))
1703 (make-local-variable 'font-lock-fontified)
1704 (make-local-variable 'font-lock-multiline)
1700 (let* ((defaults (or font-lock-defaults 1705 (let* ((defaults (or font-lock-defaults
1701 (cdr (assq major-mode font-lock-defaults-alist)))) 1706 (cdr (assq major-mode font-lock-defaults-alist))))
1702 (keywords 1707 (keywords