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

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

Re: Macro Problem


From: vy
Subject: Re: Macro Problem
Date: 4 Apr 2007 02:53:56 -0700
User-agent: G2/1.0

On Apr 3, 11:11 am, Pascal Bourguignon <p...@informatimago.com> wrote:
> This will try to _execute_ the value returned by adhoc-make-font-face.
> But a face is not a function, so adhoc-make-font-face should not
> return a function call with face as a function, but a quoted list:
>
>  (defun adhoc-make-font-face (face spec)
>    `(quote (,face ((((class color)
>                      (min-colors 8))
>                     ,spec)))))
>
> Of course you can write it as:
>  (defun adhoc-make-font-face (face spec)
>    `'(,face ((((class color)
>                      (min-colors 8))
>                     ,spec))))
>
> Also, since adhoc-custom-set-face is a macro that doesn't evaluate its
> argument, you shouldn't quote it.
>
> (macroexpand '
>  (adhoc-custom-set-faces
>   ((font-lock-builtin-face (:foreground "yellow"))
>     (font-lock-comment-face (:foreground "red"))
>     (font-lock-function-name-face (:foreground "cyan"
>                                    :underline "cyan"))))
> )
> -->
> (custom-set-faces
>  (quote (font-lock-builtin-face ((#1=((class color) (min-colors 8)) 
> (:foreground "yellow")))))
>  (quote (font-lock-comment-face ((#1# (:foreground "red")))))
>  (quote (font-lock-function-name-face ((#1# (:foreground "cyan" :underline 
> "cyan"))))))
>
> And if you used (&rest faces) instead of (faces) for
> adhoc-custom-set-faces, you could lose one parenthesis:
>
>  (defmacro adhoc-custom-set-faces (&rest faces)
>    `(custom-set-faces
>      ,@(loop for face in faces
>              collect (adhoc-make-font-face (first face) (second face)))))
>
> (macroexpand '
>  (adhoc-custom-set-faces
>     (font-lock-builtin-face       (:foreground "yellow"))
>     (font-lock-comment-face       (:foreground "red"))
>     (font-lock-function-name-face (:foreground "cyan"
>                                    :underline "cyan")))
> )
>
> -->
> (custom-set-faces
>  (quote (font-lock-builtin-face ((#1=((class color) (min-colors 8)) 
> (:foreground "yellow")))))
>  (quote (font-lock-comment-face ((#1# (:foreground "red")))))
>  (quote (font-lock-function-name-face ((#1# (:foreground "cyan" :underline 
> "cyan"))))))
>
> But since custom-set-faces is a function, perhaps you don't want
> macros at all! In that case you don't need to return a quoted list
> from adhoc-make-font-face, since you won't be trying to execute it:
>
> (defun adhoc-make-font-face (face spec)
>   `(,face ((((class color)
>               (min-colors 8))
>              ,spec))))
>
> (defun adhoc-custom-set-faces (faces)
>   (apply (function custom-set-faces)
>      (loop for face in faces
>            collect (adhoc-make-font-face (first face) (second face)))))
>
> and then indeed you'd call it as:
>
>  (adhoc-custom-set-faces
>   '((font-lock-builtin-face (:foreground "yellow"))
>     (font-lock-comment-face (:foreground "red"))
>     (font-lock-function-name-face (:foreground "cyan"
>                                    :underline "cyan"))))
>
> > I'll be appreciated if anybody can give some hints about how to fix
> > the problem.
>
> So the problem was that for some strange reason you used defmacro
> instead of defun. ;-)

Thanks so much for your detailed answer. I really appreciate it.

For about the reason of using a macro, I still don't have a sharp
distinction between where to use a macro and where to use a function.
But as much as I find myself in corner cases about the distinction of
a macro and function, as in this example, I learn more about their
functions.


Regards.



reply via email to

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