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: Sat, 26 May 2007 18:20:27 +1000 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <874pm0573o.fsf@lion.rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1180168892 1317 80.91.229.12 (26 May 2007 08:41:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 26 May 2007 08:41:32 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat May 26 10:41:31 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 1Hrrq3-0007cQ-5J for geh-help-gnu-emacs@m.gmane.org; Sat, 26 May 2007 10:41:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hrrq1-00065S-R9 for geh-help-gnu-emacs@m.gmane.org; Sat, 26 May 2007 04:41:25 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!news.astraweb.com!border1.newsrouter.astraweb.com!sn-xt-sjc-05!sn-xt-sjc-01!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:rrbArW/3Y5/jHq+7VNnt6UUE4pw= Original-X-Complaints-To: abuse@supernews.com Original-Lines: 62 Original-Xref: shelby.stanford.edu gnu.emacs.help:148858 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:44446 Archived-At: Sebastian Tennant writes: > Subject: Macro used for dynamic setting of font-lock-keywords > > Hi all, > > This works: > > (defun foo (word) > (display-buffer (set-buffer (get-buffer-create "*bar*"))) > (insert (format "baz\n")) > (unless (fboundp 'foo-dynamic-add-keyword) ;only define it once > (defmacro foo-dynamic-add-keyword () > `(font-lock-add-keywords nil '((,word . font-lock-warning-face)) 'set))) > (foo-dynamic-add-keyword) ;call the macro > (font-lock-mode 1)) > > (foo "baz") > > in that the string argument to foo is added to the buffer's > font-lock-keywords and the string is highlighted wherever it occurs, > but it seems like something of a kludge to me. > > Just out of interest really, is there a better way of passing the > value of a variable as an argument to the function > font-lock-add-keywords? I must be missing something - I don't understand why you are using a macro or what the issue is with passing an argument. Doesn't something like (not tested) (defun my-add-keyword (word) (font-lock-add-keywords nil ((word . font-lock-warning-face)) 'set)) and use it like (my-add-keyword "FIXME") I can't see any reason for the macro. I often use something like the following in my .emacs (add-hook xxx-mode-hook (lambda () .... ; various mode specific struff (font-lock-add-keywords nil '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend))))) which highlights FIXME: in the warning face. To be honest, I can't see any benefit in defining a function just to define a simple additional word as you have done and certainly cannot see any justification for a macro being defined in that function. If what you want to do is define a function you can call interactively to add keywords, then look into the 'interactive' function to see how it can be used to prompt the user (for lets say the word and the face to use. Tim -- tcross (at) rapttech dot com dot au