unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [BUG] No fontification when font-lock-add-keywords is passed nil as the mode
@ 2004-06-14 16:35 Francis Litterio
  2004-06-21  2:54 ` Richard Stallman
  0 siblings, 1 reply; 6+ messages in thread
From: Francis Litterio @ 2004-06-14 16:35 UTC (permalink / raw)


This bug is a regression from Emacs 21.3.1.  When font-lock-add-keywords is
passed nil as the mode, fontification does not happen when font-lock-mode is
turned on.  Evaluate this form to reproduce the problem:

(progn
  (require 'font-lock)	
  (ignore-errors (kill-buffer "font-lock-bug-demo"))
  (switch-to-buffer "font-lock-bug-demo")

  (font-lock-add-keywords nil '(("hello" 0 font-lock-keyword-face t)))
  (turn-on-font-lock)

  (insert "The word 'hello' in this sentence should be fontified, but it isn't.\n\n")
  (insert (format "font-lock-mode == %s\n" font-lock-mode))
  (insert (format "font-lock-defaults == %s\n" font-lock-defaults))
  (insert (format "font-lock-defaults-alist == %s\n" font-lock-defaults-alist)))


In GNU Emacs 21.3.50.1 (i386-msvc-nt5.1.2600)
 of 2004-06-11 on LT371-FRAN
configured using `configure --with-msvc (12.00)'

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: nil
  locale-coding-system: cp1252
  default-enable-multibyte-characters: t

Major mode: Emacs-Lisp

Minor modes in effect:
  erc-button-mode: t
  erc-ring-mode: t
  erc-pcomplete-mode: t
  erc-match-mode: t
  erc-fill-mode: t
  erc-netsplit-mode: t
  show-paren-mode: t
  auto-image-file-mode: t
  encoded-kbd-mode: t
  mouse-wheel-mode: t
  font-lock-mode: t
  unify-8859-on-encoding-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: 1

Recent input:
SPC f a i l s SPC w h e n SPC C-e SPC p a s s e d SPC 
a SPC m o d e SPC o f SPC n i l M-> C-p C-SPC C-p C-p 
C-p C-w M-> C-x C-k y e s <return> <switch-frame> M-h 
f b <backspace> s u b m i t <M-backspace> s e n d - 
b u SPC <M-backspace> <M-backspace> b u g <M-backspace> 
r e p o r t - e SPC m SPC <return> C-x 1 M-x r e p 
o r t - e m SPC <return>

Recent messages:
>> Calling font-lock-set-defaults (in *mail to emacs-devel@gnu.org*) [2 times]
Parsing c:/franl/.mailrc...
Parsing c:/franl/.mail_aliases... done
Parsing c:/franl/.mailrc... done
>> Calling font-lock-set-defaults (in *mail to emacs-devel@gnu.org*) [2 times]
Auto-saving...done
Type C-x 4 b RET to restore the other window.  C-M-v to scroll the help.
Mark set [3 times]
Making completion list...
Loading emacsbug...done

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] No fontification when font-lock-add-keywords is passed nil as the mode
  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
  2004-06-23 18:16   ` Francis Litterio
  2004-06-23 18:25   ` Francis Litterio
  0 siblings, 2 replies; 6+ messages in thread
From: Richard Stallman @ 2004-06-21  2:54 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] No fontification when font-lock-add-keywords is passed nil as the mode
  2004-06-21  2:54 ` Richard Stallman
@ 2004-06-23 18:16   ` Francis Litterio
  2004-06-24 23:49     ` Richard Stallman
  2004-06-23 18:25   ` Francis Litterio
  1 sibling, 1 reply; 6+ messages in thread
From: Francis Litterio @ 2004-06-23 18:16 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman wrote:

> 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.

[patch omitted]

No, that patch did not fix it.  I tested your patch by evaluating this form:

(progn
  (require 'font-lock)	
  (if (get-buffer "font-lock-bug-demo")
      (kill-buffer "font-lock-bug-demo"))
  (switch-to-buffer "font-lock-bug-demo")

  (set-face-foreground 'font-lock-keyword-face "red")
  (font-lock-add-keywords nil '(("hello" 0 font-lock-keyword-face t)))
  (turn-on-font-lock)

  (insert "The word 'hello' in this sentence should be red, but it isn't.\n"))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] No fontification when font-lock-add-keywords is passed nil as the mode
  2004-06-21  2:54 ` Richard Stallman
  2004-06-23 18:16   ` Francis Litterio
@ 2004-06-23 18:25   ` Francis Litterio
  2004-06-24 23:49     ` Richard Stallman
  1 sibling, 1 reply; 6+ messages in thread
From: Francis Litterio @ 2004-06-23 18:25 UTC (permalink / raw)


Richard Stallman wrote:

> 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.

[patch omitted]

In addition to not fixing the original bug, the above patch to
font-lock.el introduced a new bug.  Eval this form to see the below
backtrace:

(progn
  (require 'font-lock)
  (defun my-dired-mode-hook ()
    (font-lock-add-keywords nil '(("^  d" 2 'highlight nil)))
    (turn-on-font-lock))
  (add-hook 'dired-mode-hook 'my-dired-mode-hook)
  (dired "/"))


Debugger entered--Lisp error: (wrong-type-argument sequencep dired-font-lock-keywords)
  mapcar(font-lock-compile-keyword dired-font-lock-keywords)
  (cons keywords (mapcar (quote font-lock-compile-keyword) keywords))
  (cons t (cons keywords (mapcar ... keywords)))
  (setq keywords (cons t (cons keywords ...)))
  (if (eq (car-safe keywords) t) keywords (setq keywords (cons t ...)) (if (and regexp ... ...) (nconc keywords ...)) keywords)
  font-lock-compile-keywords(dired-font-lock-keywords t)
  (set (make-local-variable (quote font-lock-keywords)) (font-lock-compile-keywords keywords t))
  (if (eq (car font-lock-keywords) t) nil (set (make-local-variable ...) (font-lock-compile-keywords keywords t)))
  (unless (eq (car font-lock-keywords) t) (set (make-local-variable ...) (font-lock-compile-keywords keywords t)))
  (let* ((defaults ...) (keywords ...) (local ...) (removed-keywords ...)) (set (make-local-variable ...) defaults) (when (nth 1 defaults) (set ... t)) (when (nth 2 defaults) (set ... t)) (when (nth 3 defaults) (set ... ...) (dolist ... ...)) (when (nth 4 defaults) (set ... ...)) (dolist (x ...) (set ... ...)) (set (make-local-variable ...) (font-lock-eval-keywords keywords)) (while local (font-lock-add-keywords nil ... ...) (setq local ...)) (when removed-keywords (font-lock-remove-keywords nil removed-keywords)) (unless (eq ... t) (set ... ...)))
  (if font-lock-set-defaults nil (set (make-local-variable ...) t) (make-local-variable (quote font-lock-fontified)) (make-local-variable (quote font-lock-multiline)) (let* (... ... ... ...) (set ... defaults) (when ... ...) (when ... ...) (when ... ... ...) (when ... ...) (dolist ... ...) (set ... ...) (while local ... ...) (when removed-keywords ...) (unless ... ...)))
  (unless font-lock-set-defaults (set (make-local-variable ...) t) (make-local-variable (quote font-lock-fontified)) (make-local-variable (quote font-lock-multiline)) (let* (... ... ... ...) (set ... defaults) (when ... ...) (when ... ...) (when ... ... ...) (when ... ...) (dolist ... ...) (set ... ...) (while local ... ...) (when removed-keywords ...) (unless ... ...)))
  font-lock-set-defaults()
  (cond (mode (let ... ...) (font-lock-update-removed-keyword-alist mode keywords append)) (t (font-lock-set-defaults) (let ... ... ... ...)))
  font-lock-add-keywords(nil (("^  d" 2 (quote highlight) nil)))
  my-dired-mode-hook()
  run-hooks(dired-mode-hook)
  apply(run-hooks dired-mode-hook)
  run-mode-hooks(dired-mode-hook)
  dired-mode("c:/" "-al")
  dired-internal-noselect("c:/" nil)
  dired-noselect("/" nil)
  dired("/")
  (progn (require (quote font-lock)) (defun my-dired-mode-hook nil (font-lock-add-keywords nil ...) (turn-on-font-lock)) (add-hook (quote dired-mode-hook) (quote my-dired-mode-hook)) (dired "/"))
  eval((progn (require (quote font-lock)) (defun my-dired-mode-hook nil (font-lock-add-keywords nil ...) (turn-on-font-lock)) (add-hook (quote dired-mode-hook) (quote my-dired-mode-hook)) (dired "/")))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] No fontification when font-lock-add-keywords is passed nil as the mode
  2004-06-23 18:16   ` Francis Litterio
@ 2004-06-24 23:49     ` Richard Stallman
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2004-06-24 23:49 UTC (permalink / raw)
  Cc: emacs-devel

    No, that patch did not fix it.  I tested your patch by evaluating this form:

Strange, it worked for me.  However, I had to type M-g M-g to make
it fontify.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] No fontification when font-lock-add-keywords is passed nil as the mode
  2004-06-23 18:25   ` Francis Litterio
@ 2004-06-24 23:49     ` Richard Stallman
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2004-06-24 23:49 UTC (permalink / raw)
  Cc: emacs-devel

      Eval this form to see the below
    backtrace:

    (progn
      (require 'font-lock)
      (defun my-dired-mode-hook ()
	(font-lock-add-keywords nil '(("^  d" 2 'highlight nil)))
	(turn-on-font-lock))
      (add-hook 'dired-mode-hook 'my-dired-mode-hook)
      (dired "/"))

This should fix the bug.

*** font-lock.el	20 Jun 2004 21:02:44 -0400	1.221
--- font-lock.el	24 Jun 2004 19:32:27 -0400	
***************
*** 1561,1567 ****
        ;; 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.
  
--- 1561,1567 ----
        ;; Now compile the keywords.
        (unless (eq (car font-lock-keywords) t)
  	(set (make-local-variable 'font-lock-keywords)
! 	     (font-lock-compile-keywords font-lock-keywords t))))))
  \f
  ;;; Colour etc. support.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-06-24 23:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).