[Top][All Lists]

[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: Sat, 26 May 2007 18:20:27 +1000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

Sebastian Tennant <address@hidden> 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. 


tcross (at) rapttech dot com dot au

reply via email to

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