help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: problem understanding font-lock-defaults structure


From: Nikolaj Schumacher
Subject: Re: problem understanding font-lock-defaults structure
Date: Thu, 09 Oct 2008 19:16:37 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin)

Xah <xahlee@gmail.com> wrote:

> (setq myKeywordsLevel1
>   (list
>     ("Sin\\|Cos" . font-lock-function-name-face)
>     ("π\\|∞" . font-lock-constant-face)
>     ("x\\|y" . font-lock-variable-name-face)))
>
> Are you sure? It gives (invalid-function "Sin\\|Cos").

You're right.

(setq myKeywordsLevel1
      (list (cons "Sin\\|Cos" font-lock-function-name-face)
            (cons "π\\|∞" font-lock-constant-face)
            (cons "x\\|y" font-lock-variable-name-face)))

I was looking only at the "(quote" line.

>> There's no need to use `, here.  `font-lock-keywords' accepts symbols.
>> (setq font-lock-keywords '((myKeywordsLevel1 nil nil)))
>
> after eval that form, than i looked at the value of font-lock-keywords
> using describe-variable, it says:

My bad, too.  I meant `font-lock-defaults' -- the variable you were
already using, and we were talking about.  -keywords just crept in from
finger memory.

Here's a complete, working example:

(setq myKeywordsLevel1
 '(("Sin\\|Cos" . font-lock-function-name-face)
   ("π\\|∞" . font-lock-constant-face)
   ("x\\|y" . font-lock-variable-name-face)))

(define-derived-mode foo-mode fundamental-mode
  (setq font-lock-defaults '(myKeywordsLevel1)))

> Its value is
> (t
>  (myKeywordsLevel1)
>  (myKeywordsLevel1
>   (0 font-lock-keyword-face)))
>
> Local in buffer untitled<3>;
> »
>
> Where did all the extra came from?

The list has been "compiled".  The t marks it as such, so it isn't
processed twice.  Due to this kind of voodoo, I avoid touching
`font-lock-keywords'.  I use `font-lock-add-keywords'.



regards,
Nikolaj Schumacher




reply via email to

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