From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: problem understanding font-lock-defaults structure Date: Fri, 10 Oct 2008 11:45:11 +1100 Organization: Rapt Technologies Message-ID: <87ljwxmg6g.fsf@lion.rapttech.com.au> References: <13173afe-f51c-4c67-b738-1949f2b28b5f@f40g2000pri.googlegroups.com> <296d3d40-598c-4ea4-8394-c69975c0399f@a3g2000prm.googlegroups.com> <5f116baa-33e0-48ed-a27e-8446a7791c1d@a18g2000pra.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1223603002 30047 80.91.229.12 (10 Oct 2008 01:43:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 Oct 2008 01:43:22 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 10 03:44:18 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Ko738-0001Dp-Ll for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Oct 2008 03:44:15 +0200 Original-Received: from localhost ([127.0.0.1]:45610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ko724-0005cR-5k for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Oct 2008 21:43:08 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!news.astraweb.com!border2.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:UjRkK67N8wPgX+kWqiRri9wP2j4= Original-Lines: 81 Original-NNTP-Posting-Host: 9add6c79.news.astraweb.com Original-X-Trace: DXC=mO2GEn0A=5S<>SSnB4kIGXL?0kYOcDh@Z; >GTR`=ZX:R8d7eNK7D9VU58dH4c2`hNQTXjX9L List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58648 Archived-At: Xah writes: > On Oct 9, 10:16 am, Nikolaj Schumacher 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