unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Richard Stallman <rms@gnu.org>
Subject: Re: [BUG] No fontification when font-lock-add-keywords is passed nil as the mode
Date: Sun, 20 Jun 2004 22:54:36 -0400	[thread overview]
Message-ID: <E1BcExA-0008Br-Gt@fencepost.gnu.org> (raw)
In-Reply-To: <u7juagkbb.fsf@world.std.com> (message from Francis Litterio on Mon, 14 Jun 2004 12:35:56 -0400)

Does this fix it?  Could people who are more familiar
with font-lock mode verify this is correct?  I have changed
the format of a "compiled" keywords list, which might have introduced
some bugs.

*** font-lock.el	29 May 2004 15:23:35 -0400	1.220
--- font-lock.el	20 Jun 2004 21:02:44 -0400	
***************
*** 340,346 ****
  
  (defvar font-lock-keywords nil
    "A list of the keywords to highlight.
! Each element should have one of these forms:
  
   MATCHER
   (MATCHER . MATCH)
--- 340,354 ----
  
  (defvar font-lock-keywords nil
    "A list of the keywords to highlight.
! There are two kinds of values: user-level, and compiled.
! 
! A user-level keywords list is what a major mode or the user would
! set up.  Normally the list would come from `font-lock-defaults'.
! through selection of a fontification level and evaluation of any
! contained expressions.  You can also alter it by calling
! `font-lock-add-keywords' or `font-lock-remove-keywords' with MODE = nil.
! 
! Each element in a user-level keywords list should have one of these forms:
  
   MATCHER
   (MATCHER . MATCH)
***************
*** 438,444 ****
  
  This variable is set by major modes via the variable `font-lock-defaults'.
  Be careful when composing regexps for this list; a poorly written pattern can
! dramatically slow things down!")
  
  (defvar font-lock-keywords-alist nil
    "*Alist of `font-lock-keywords' local to a `major-mode'.
--- 446,459 ----
  
  This variable is set by major modes via the variable `font-lock-defaults'.
  Be careful when composing regexps for this list; a poorly written pattern can
! dramatically slow things down!
! 
! A compiled keywords list starts with t.  It is produced internal
! by `font-lock-compile-keywords' from a user-level keywords list.
! Its second element is the user-level keywords list that was
! compiled.  The remaining elements have the same form as
! user-level keywords, but normally their values have been
! optimized.")
  
  (defvar font-lock-keywords-alist nil
    "*Alist of `font-lock-keywords' local to a `major-mode'.
***************
*** 659,674 ****
  	 (font-lock-update-removed-keyword-alist mode keywords append))
  	(t
  	 ;; Otherwise set or add the keywords now.
  	 (font-lock-set-defaults)
!  	 (if (eq append 'set)
!  	     (setq font-lock-keywords keywords)
! 	   (font-lock-remove-keywords nil keywords) ;to avoid duplicates
! 	   (let ((old (if (eq (car-safe font-lock-keywords) t)
! 			  (cdr font-lock-keywords)
! 			font-lock-keywords)))
! 	     (setq font-lock-keywords (if append
! 					  (append old keywords)
! 					(append keywords old))))))))
  
  (defun font-lock-update-removed-keyword-alist (mode keywords append)
    ;; Update `font-lock-removed-keywords-alist' when adding new
--- 674,699 ----
  	 (font-lock-update-removed-keyword-alist mode keywords append))
  	(t
  	 ;; Otherwise set or add the keywords now.
+ 	 ;; This is a no-op if it has been done already in this buffer.
  	 (font-lock-set-defaults)
! 	 (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)))
! 	   ;; Now modify or replace them.
! 	   (if (eq append 'set)
! 	       (setq font-lock-keywords keywords)
! 	     (font-lock-remove-keywords nil keywords) ;to avoid duplicates
! 	     (let ((old (if (eq (car-safe font-lock-keywords) t)
! 			    (cdr font-lock-keywords)
! 			  font-lock-keywords)))
! 	       (setq font-lock-keywords (if append
! 					    (append old keywords)
! 					  (append keywords old)))))
! 	   ;; If the keywords were compiled before, compile them again.
! 	   (if was-compiled
! 	       (set (make-local-variable 'font-lock-keywords)
! 		    (font-lock-compile-keywords keywords t)))))))
  
  (defun font-lock-update-removed-keyword-alist (mode keywords append)
    ;; Update `font-lock-removed-keywords-alist' when adding new
***************
*** 762,774 ****
  	(t
  	 ;; Otherwise remove it immediately.
  	 (font-lock-set-defaults)
! 	 (setq font-lock-keywords (copy-sequence font-lock-keywords))
! 	 (dolist (keyword keywords)
! 	   (setq font-lock-keywords
! 		 (delete keyword
! 			 ;; The keywords might be compiled.
! 			 (delete (font-lock-compile-keyword keyword)
! 				 font-lock-keywords)))))))
  \f
  ;;; Font Lock Support mode.
  
--- 787,807 ----
  	(t
  	 ;; Otherwise remove it immediately.
  	 (font-lock-set-defaults)
! 	 (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)))
! 
! 	   ;; Edit them.
! 	   (setq font-lock-keywords (copy-sequence font-lock-keywords))
! 	   (dolist (keyword keywords)
! 	     (setq font-lock-keywords
! 		   (delete keyword font-lock-keywords)))
! 
! 	   ;; If the keywords were compiled before, compile them again.
! 	   (if was-compiled
! 	       (set (make-local-variable 'font-lock-keywords)
! 		    (font-lock-compile-keywords keywords t)))))))
  \f
  ;;; Font Lock Support mode.
  
***************
*** 1349,1355 ****
      (setq font-lock-keywords
  	  (font-lock-compile-keywords font-lock-keywords t)))
    (let ((case-fold-search font-lock-keywords-case-fold-search)
! 	(keywords (cdr font-lock-keywords))
  	(bufname (buffer-name)) (count 0)
  	keyword matcher highlights)
      ;;
--- 1382,1388 ----
      (setq font-lock-keywords
  	  (font-lock-compile-keywords font-lock-keywords t)))
    (let ((case-fold-search font-lock-keywords-case-fold-search)
! 	(keywords (cddr font-lock-keywords))
  	(bufname (buffer-name)) (count 0)
  	keyword matcher highlights)
      ;;
***************
*** 1394,1407 ****
  ;; Various functions.
  
  (defun font-lock-compile-keywords (keywords &optional regexp)
!   "Compile KEYWORDS into the form (t KEYWORD ...).
! Here KEYWORD is of the form (MATCHER HIGHLIGHT ...) as shown in the
  `font-lock-keywords' doc string.
  If REGEXP is non-nil, it means these keywords are used for
  `font-lock-keywords' rather than for `font-lock-syntactic-keywords'."
    (if (eq (car-safe keywords) t)
        keywords
!     (setq keywords (cons t (mapcar 'font-lock-compile-keyword keywords)))
      (if (and regexp
  	     (eq (or syntax-begin-function
  		     font-lock-beginning-of-syntax-function)
--- 1427,1442 ----
  ;; Various functions.
  
  (defun font-lock-compile-keywords (keywords &optional regexp)
!   "Compile KEYWORDS into the form (t KEYWORDS COMPILED...)
! Here each COMPILED is of the form (MATCHER HIGHLIGHT ...) as shown in the
  `font-lock-keywords' doc string.
  If REGEXP is non-nil, it means these keywords are used for
  `font-lock-keywords' rather than for `font-lock-syntactic-keywords'."
    (if (eq (car-safe keywords) t)
        keywords
!     (setq keywords
! 	  (cons t (cons keywords
! 			(mapcar 'font-lock-compile-keyword keywords))))
      (if (and regexp
  	     (eq (or syntax-begin-function
  		     font-lock-beginning-of-syntax-function)
***************
*** 1512,1528 ****
        ;; Variable alist?
        (dolist (x (nthcdr 5 defaults))
  	(set (make-local-variable (car x)) (cdr x)))
!       ;; Setup `font-lock-keywords' last because its value might depend
        ;; on other settings (e.g. font-lock-compile-keywords uses
        ;; font-lock-beginning-of-syntax-function).
        (set (make-local-variable 'font-lock-keywords)
! 	   (font-lock-compile-keywords (font-lock-eval-keywords keywords) t))
        ;; Local fontification?
        (while local
  	(font-lock-add-keywords nil (car (car local)) (cdr (car local)))
  	(setq local (cdr local)))
        (when removed-keywords
! 	(font-lock-remove-keywords nil removed-keywords)))))
  \f
  ;;; Colour etc. support.
  
--- 1547,1567 ----
        ;; Variable alist?
        (dolist (x (nthcdr 5 defaults))
  	(set (make-local-variable (car x)) (cdr x)))
!       ;; Set up `font-lock-keywords' last because its value might depend
        ;; on other settings (e.g. font-lock-compile-keywords uses
        ;; font-lock-beginning-of-syntax-function).
        (set (make-local-variable 'font-lock-keywords)
! 	   (font-lock-eval-keywords keywords))
        ;; Local fontification?
        (while local
  	(font-lock-add-keywords nil (car (car local)) (cdr (car local)))
  	(setq local (cdr local)))
        (when removed-keywords
! 	(font-lock-remove-keywords nil removed-keywords))
!       ;; Now compile the keywords.
!       (unless (eq (car font-lock-keywords) t)
! 	(set (make-local-variable 'font-lock-keywords)
! 	     (font-lock-compile-keywords keywords t))))))
  \f
  ;;; Colour etc. support.

  reply	other threads:[~2004-06-21  2:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-14 16:35 [BUG] No fontification when font-lock-add-keywords is passed nil as the mode Francis Litterio
2004-06-21  2:54 ` Richard Stallman [this message]
2004-06-23 18:16   ` Francis Litterio
2004-06-24 23:49     ` Richard Stallman
2004-06-23 18:25   ` Francis Litterio
2004-06-24 23:49     ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1BcExA-0008Br-Gt@fencepost.gnu.org \
    --to=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).