emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: font-lock basics?


From: Francis Litterio
Subject: Re: font-lock basics?
Date: Mon, 31 Jan 2005 11:14:22 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (windows-nt)

I wrote:

> Stefan Monnier wrote:
>
>>>   (progn
>>>     (font-lock-mode -1)
>>>     (kill-all-local-variables)
>>>     (font-lock-add-keywords nil '(("high" . font-lock-keyword-face)))
>>>     (font-lock-mode t))
>>
>> Try to set font-lock-defaults instead.
>
> That begs the question: What is wrong with the above code?  According to
> the docstrings for the functions called above, it should work.  Why
> doesn't it?

I think this code in function font-lock-default-function is preventing
the fontification from happening:

  ;; Only do hard work if the mode has specified stuff in
  ;; `font-lock-defaults'.
  (when (or font-lock-defaults
            (cdr (assq major-mode font-lock-defaults-alist)))
    (font-lock-mode-internal mode)))

In a newly-created fundamental-mode buffer, font-lock-defaults is nil if
the user has not explicitly assigned it a value (and the font-lock
documentation does not state that one _must_ set font-lock-defaults for
font-lock-mode to work).

This patch to font-core.el fixes the problem:

--- font-core.el        01 Sep 2003 11:45:12 -0400      1.23
+++ font-core.el        31 Jan 2005 11:18:03 -0500      
@@ -200,8 +200,10 @@
                (delq elt char-property-alias-alist))))))
 
   ;; Only do hard work if the mode has specified stuff in
-  ;; `font-lock-defaults'.
+  ;; `font-lock-defaults' or if `font-lock-keywords' is non-nil
+  ;; in this buffer.
   (when (or font-lock-defaults
+           font-lock-keywords
            (cdr (assq major-mode font-lock-defaults-alist)))
     (font-lock-mode-internal mode)))
 
I hope this helps.
--
Francis Litterio
franl <at> world . std . com





reply via email to

[Prev in Thread] Current Thread [Next in Thread]