From: Pascal Bourguignon <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Macro Problem
Date: Tue, 03 Apr 2007 10:11:13 +0200 [thread overview]
Message-ID: <87hcrxswri.fsf@voyager.informatimago.com> (raw)
In-Reply-To: 1175548506.345646.47790@l77g2000hsb.googlegroups.com
"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
next prev parent reply other threads:[~2007-04-03 8:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-02 21:15 Macro Problem vy
2007-04-03 8:11 ` Pascal Bourguignon [this message]
2007-04-04 9:53 ` vy
-- strict thread matches above, loose matches on Subject: below --
2018-05-13 20:22 Macro problem Douglas Harter
2018-05-15 15:01 Douglas Harter
2018-05-15 17:13 ` John Mastro
[not found] <mailman.32.1526396527.20804.help-gnu-emacs@gnu.org>
2018-05-15 15:32 ` Barry Margolin
2018-05-15 16:20 ` Paw Writer
2018-05-15 17:13 ` Søren Pilgård
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87hcrxswri.fsf@voyager.informatimago.com \
--to=pjb@informatimago.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).