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: Macro used for dynamic setting of font-lock-keywords Date: Sun, 27 May 2007 13:30:07 +1000 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <87d50n3pvk.fsf@lion.rapttech.com.au> References: <874pm0573o.fsf@lion.rapttech.com.au> <87lkfb4nj4.fsf@lion.rapttech.com.au> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1180237268 8970 80.91.229.12 (27 May 2007 03:41:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 27 May 2007 03:41:08 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun May 27 05:41:07 2007 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 1Hs9cw-0006K9-KG for geh-help-gnu-emacs@m.gmane.org; Sun, 27 May 2007 05:41:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hs9cw-0008Vn-6j for geh-help-gnu-emacs@m.gmane.org; Sat, 26 May 2007 23:41:06 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!newscon04.news.prodigy.net!prodigy.net!news.astraweb.com!router1.astraweb.com!sn-xt-sjc-05!sn-xt-sjc-06!sn-post-sjc-02!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:SJ99pnpAqSLTqVmuE6050WWkfdY= Original-X-Complaints-To: abuse@supernews.com Original-Lines: 41 Original-Xref: shelby.stanford.edu gnu.emacs.help:148887 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor 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:44475 Archived-At: Sebastian Tennant writes: > Quoth Tim X : >> symbol word is getting added to the list. Try this >> >> (defun my-add-keyword (word) >> (font-lock-add-keywords nil (cons word font-lock-warning-face)) t)) > > > Your function (above) needs an extra cons but now it works: > > (defun my-add-keyword (word) > (font-lock-add-keywords nil (cons (cons word font-lock-warning-face) '(t)))) > > Thanks for pointing out the obvious, although I enjoyed cobbling > together my macro kludge. I can't believe it didn't occur to me to > use cons. I suppose it's because I'm thinking macros generally at the > moment, and hell... why use a simple cons or two, when you can write a > complicated macro! > Its funny, people are often excited about writing a macro - I certainly was when I first learnt about them. However, while I've done it to prove that I could, in reality, I've not yet come across anywhere that I needed a macro or where a macro could do something better than just a plain old function. I suspect that until you start writing really quite large or complex stuff, you won't come across many places wehre you really need a macro or where it will make code more readable etc. When working at customizing or updating existing behavior in emacs, one of my favorite facilities is 'defadvice'. I've used this facility to work around bugs, stop a mode from reporting pointless/uninteresting messages, temporarily modify behavior on the fly etc. Its a really handy little feature which doesn't seem to get used as often as it probably should. I've seen people post 20+ lines of elisp to this list to do something which could be achieved more reliably with 4 or five lines of defadvice. Tim -- tcross (at) rapttech dot com dot au