[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem understanding font-lock-defaults structure
From: |
Tim X |
Subject: |
Re: problem understanding font-lock-defaults structure |
Date: |
Fri, 10 Oct 2008 11:45:11 +1100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Xah <xahlee@gmail.com> writes:
> On Oct 9, 10:16 am, Nikolaj Schumacher <m...@nschum.de> wrote:
>
>> 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'.
>
> Thanks a lot. That's helpful and much info in this thread.
>
> possibly begging, is it possible to get this to work with using font-
> lock-keywords?
>
> Here's what i have now based on all the info in this thread. I
> couldn't see where it went wrong.
>
> ; Sin[x]^2 + Cos[y]^2 = 1
> ; π^2/6 == Sum[1/x^2,{x,1,∞}]
>
> (setq myKeywordsLevel1
> (quote
> (
> ("Sin\\|Cos" . font-lock-function-name-face)
> ("π\\|∞" . font-lock-constant-face)
> ("x\\|y" . font-lock-variable-name-face)
> )
> )
> )
>
> (setq font-lock-keywords
> (
> myKeywordsLevel1
> nil
> nil
> )
> )
>
> (font-lock-fontify-buffer)
>
> In the “setq font-lock-keywords”, block, i tried various quoting and
> nesting but no go.
>
> Xah
> ∑ http://xahlee.org/
Have a look at sql.el in the lisp/progmodes directory. It has very clear
examples of how you can do what you want. As the mode supports different
font-locking depending on the type of database your connecting to, it
has a mechanism for setting what keywords are font locked dynamically,
which seems to be close to what you are wanting to do (i.e. assign the
words to be font-locked to a variable and then use that in setting up
font locking). Also, Alex's code
is quite clear and well structured, making it quite easy to follow what
he is doing.
Tim
☄
--
tcross (at) rapttech dot com dot au
- Re: problem understanding font-lock-defaults structure, (continued)
- Re: problem understanding font-lock-defaults structure, Nikolaj Schumacher, 2008/10/09
- Message not available
- Re: problem understanding font-lock-defaults structure, Xah, 2008/10/09
- Re: problem understanding font-lock-defaults structure, harven, 2008/10/09
- Re: problem understanding font-lock-defaults structure, Nikolaj Schumacher, 2008/10/09
- Message not available
- Re: problem understanding font-lock-defaults structure, Xah, 2008/10/09
- Re: problem understanding font-lock-defaults structure, Nikolaj Schumacher, 2008/10/09
- Message not available
- Re: problem understanding font-lock-defaults structure, Xah, 2008/10/09
- Re: problem understanding font-lock-defaults structure, Nikolaj Schumacher, 2008/10/09
- Message not available
- Re: problem understanding font-lock-defaults structure, Xah, 2008/10/09
- Re: problem understanding font-lock-defaults structure,
Tim X <=