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

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

Re: Macro used for dynamic setting of font-lock-keywords


From: Tim X
Subject: Re: Macro used for dynamic setting of font-lock-keywords
Date: Sun, 27 May 2007 13:30:07 +1000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

Sebastian Tennant <sebyte@smolny.plus.com> writes:

> Quoth Tim X <timx@nospam.dev.null>:
>> 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


reply via email to

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