unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tim X <timx@nospam.dev.null>
To: help-gnu-emacs@gnu.org
Subject: Re: problem understanding font-lock-defaults structure
Date: Fri, 10 Oct 2008 11:45:11 +1100	[thread overview]
Message-ID: <87ljwxmg6g.fsf@lion.rapttech.com.au> (raw)
In-Reply-To: 5f116baa-33e0-48ed-a27e-8446a7791c1d@a18g2000pra.googlegroups.com

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


      parent reply	other threads:[~2008-10-10  0:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-08 18:46 problem understanding font-lock-defaults structure Xah
2008-10-08 21:22 ` Nikolaj Schumacher
     [not found] ` <mailman.619.1223500981.25473.help-gnu-emacs@gnu.org>
2008-10-09  0:02   ` Xah
2008-10-09  0:54     ` Lennart Borgman (gmail)
2008-10-09  2:25       ` Kevin Rodgers
     [not found]       ` <mailman.643.1223519147.25473.help-gnu-emacs@gnu.org>
2008-10-09 21:18         ` Xah
2008-10-09 11:13     ` Nikolaj Schumacher
     [not found]     ` <mailman.637.1223513718.25473.help-gnu-emacs@gnu.org>
2008-10-09 15:04       ` Xah
2008-10-09 15:26         ` harven
2008-10-09 17:17           ` Nikolaj Schumacher
     [not found]     ` <mailman.677.1223550826.25473.help-gnu-emacs@gnu.org>
2008-10-09 15:29       ` Xah
2008-10-09 17:16         ` Nikolaj Schumacher
     [not found]         ` <mailman.719.1223572620.25473.help-gnu-emacs@gnu.org>
2008-10-09 21:40           ` Xah
2008-10-09 23:27             ` Nikolaj Schumacher
     [not found]             ` <mailman.739.1223594868.25473.help-gnu-emacs@gnu.org>
2008-10-10  0:20               ` Xah
2008-10-10  0:45             ` Tim X [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ljwxmg6g.fsf@lion.rapttech.com.au \
    --to=timx@nospam.dev.null \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).