emacs-devel
[Top][All Lists]
Advanced

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

Re: font-lock basics?


From: Stefan Monnier
Subject: Re: font-lock basics?
Date: Mon, 31 Jan 2005 11:29:52 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

>>> (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?

Actually the docstrings are sufficiently vague that it's not clear whether
it should work or not.  In any case one of the problems is that
font-lock-add-keywords is meant to add to a *preexisting* list of keywords.
So the above only makes sense if the font-lock-add-keywords is called from
some minor mode which simply assumes that the major mode has setup
font-lock-defaults.  And even that doesn't work so well because the minor
mode has no control over font-lock-case-fold-search.

Maybe the patch below papers over this particular manifestation of the more
general problem.

Miles, what is the context of your question?


        Stefan


Index: font-core.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/font-core.el,v
retrieving revision 1.23
diff -u -u -b -r1.23 font-core.el
--- font-core.el        1 Sep 2003 15:45:12 -0000       1.23
+++ font-core.el        31 Jan 2005 16:24:56 -0000
@@ -1,7 +1,7 @@
 ;;; font-core.el --- Core interface to font-lock
 
-;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000, 2001, 02, 2003
-;;  Free Software Foundation, Inc.
+;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+;;   2002, 2003, 2005  Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: languages, faces
@@ -202,6 +202,7 @@
   ;; Only do hard work if the mode has specified stuff in
   ;; `font-lock-defaults'.
   (when (or font-lock-defaults
+           (and (boundp 'font-lock-keywords) font-lock-keywords)
            (cdr (assq major-mode font-lock-defaults-alist)))
     (font-lock-mode-internal mode)))
 
@@ -295,6 +296,5 @@
 
 (provide 'font-core)
 
+;; arch-tag: f8c286e1-02f7-41d9-b89b-1b67780aed71
 ;;; font-core.el ends here
-
-;;; arch-tag: f8c286e1-02f7-41d9-b89b-1b67780aed71




reply via email to

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