[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Macro Problem
From: |
Pascal Bourguignon |
Subject: |
Re: Macro Problem |
Date: |
Tue, 03 Apr 2007 10:11:13 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.94 (gnu/linux) |
"vy" <volkan.yazici@gmail.com> writes:
> Hi,
>
> I'm trying to fix a macro for a simple task but still couldn't figure
> out the solution to the problem emacs complains about. Here's the
> related macro:
>
> (defun adhoc-make-font-face (face spec)
> `(,face ((((class color)
> (min-colors 8))
> ,spec))))
>
> (defmacro adhoc-custom-set-faces (faces)
> `(custom-set-faces
> ,@(loop for face in faces
> collect (adhoc-make-font-face (first face) (second
> face)))))
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. ;-)
--
__Pascal Bourguignon__
http://www.informatimago.com
http://pjb.ogamita.org
- Macro Problem, vy, 2007/04/02
- Re: Macro Problem,
Pascal Bourguignon <=