From: "vy" <volkan.yazici@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Macro Problem
Date: 4 Apr 2007 02:53:56 -0700 [thread overview]
Message-ID: <1175680436.088279.146130@p77g2000hsh.googlegroups.com> (raw)
In-Reply-To: <87hcrxswri.fsf@voyager.informatimago.com>
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.
next prev parent reply other threads:[~2007-04-04 9:53 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
2007-04-04 9:53 ` vy [this message]
-- 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1175680436.088279.146130@p77g2000hsh.googlegroups.com \
--to=volkan.yazici@gmail.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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.