From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "vy" Newsgroups: gmane.emacs.help Subject: Re: Macro Problem Date: 4 Apr 2007 02:53:56 -0700 Organization: http://groups.google.com Message-ID: <1175680436.088279.146130@p77g2000hsh.googlegroups.com> References: <1175548506.345646.47790@l77g2000hsb.googlegroups.com> <87hcrxswri.fsf@voyager.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: sea.gmane.org 1175683072 14614 80.91.229.12 (4 Apr 2007 10:37:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 4 Apr 2007 10:37:52 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 04 12:37:49 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HZ2s9-0008C9-G8 for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Apr 2007 12:37:49 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HZ2vO-0004FT-Hl for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Apr 2007 06:41:10 -0400 Original-Path: shelby.stanford.edu!newshub.stanford.edu!postnews.google.com!p77g2000hsh.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 93 Original-NNTP-Posting-Host: 88.235.89.71 Original-X-Trace: posting.google.com 1175680442 12016 127.0.0.1 (4 Apr 2007 09:54:02 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 4 Apr 2007 09:54:02 +0000 (UTC) In-Reply-To: <87hcrxswri.fsf@voyager.informatimago.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20061208 Firefox/2.0.0.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: p77g2000hsh.googlegroups.com; posting-host=88.235.89.71; posting-account=HHrEMg0AAACMYZfIqFwwc5QTq8zdr7dq Original-Xref: shelby.stanford.edu gnu.emacs.help:146805 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:42409 Archived-At: On Apr 3, 11:11 am, Pascal Bourguignon 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.