[Bug: 21.5-b27] font-lock-add-keywords, font-lock-remove-keywords

Katsumi Yamaoka yamaoka at jpl.org
Wed Feb 7 23:42:31 EST 2007


Hi,

I realized `font-lock-add-keywords' and `font-lock-remove-keywords'
don't work properly with compiled font-lock keywords.  Now those
function definitions are the same as the ones in Emacs 22.
However, Emacs uses the `(t KEYWORDS COMPILED...)' form for
compiled font-lock keywords while XEmacs uses the `(t COMPILED...)' 
form.  Because of this, now `font-lock-add-keywords' always
removes compiled keywords except the first one as follows:

--8<---------------cut here---------------start------------->8---
(let ((default-major-mode 'fundamental-mode))
  (with-temp-buffer
    (let ((font-lock-keywords '(t (x) (y)))
	  font-lock-auto-fontify font-lock-mode-enable-list)
      (font-lock-add-keywords nil '((z)))
      font-lock-keywords)))
 => (t (z (0 nil)) (x (0 font-lock-keyword-face)))
--8<---------------cut here---------------end--------------->8---

;; Note that the y keyword is missing in the result.

The attached patch was briefly tested with only the case where
the first argument MODE is not given.

--8<---------------cut here---------------start------------->8---
--- font-lock.el~	2006-11-05 22:08:12 +0000
+++ font-lock.el	2007-02-08 04:38:50 +0000
@@ -954,7 +954,7 @@
 	 (let ((was-compiled (eq (car font-lock-keywords) t)))
 	   ;; Bring back the user-level (uncompiled) keywords.
 	   (if was-compiled
-	       (setq font-lock-keywords (cadr font-lock-keywords)))
+	       (setq font-lock-keywords (cdr font-lock-keywords)))
 	   ;; Now modify or replace them.
 	   (if (eq how 'set)
 	       (setq font-lock-keywords keywords)
@@ -1064,13 +1064,14 @@
 	 (let ((was-compiled (eq (car font-lock-keywords) t)))
 	   ;; Bring back the user-level (uncompiled) keywords.
 	   (if was-compiled
-	       (setq font-lock-keywords (cadr font-lock-keywords)))
+	       (setq font-lock-keywords (cdr font-lock-keywords)))
 
 	   ;; Edit them.
 	   (setq font-lock-keywords (copy-sequence font-lock-keywords))
 	   (dolist (keyword keywords)
 	     (setq font-lock-keywords
-		   (delete keyword font-lock-keywords)))
+		   (delete (font-lock-compile-keyword keyword)
+			   (delete keyword font-lock-keywords))))
 
 	   ;; If the keywords were compiled before, compile them again.
 	   (if was-compiled
--8<---------------cut here---------------end--------------->8---

Regards,



More information about the XEmacs-Beta mailing list