From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Need some education on defmacro define-toggle Date: Mon, 28 Dec 2009 22:33:49 +0100 Organization: Informatimago Message-ID: <87d41yzsua.fsf@hubble.informatimago.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1262036458 15156 80.91.229.12 (28 Dec 2009 21:40:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Dec 2009 21:40:58 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 28 22:40:51 2009 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 1NPNKc-0000vf-DT for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Dec 2009 22:40:50 +0100 Original-Received: from localhost ([127.0.0.1]:48562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPNKc-0003o1-QL for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Dec 2009 16:40:50 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 65 Original-X-Trace: individual.net mTH9VBk2pg/rVV5UQZB0YAS4jDc/U5tKdyEnYF6Hn5iGDcJPmg Cancel-Lock: sha1:NDg3Y2UxYWQ2OGY2YjY4NmJkYzdhMDNmMTRhYjFhZWM5YThmZDBiNg== sha1:2etkhBnRp+B3l3HcYe4OlVdSFKs= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux) Original-Xref: news.stanford.edu gnu.emacs.help:175841 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:70913 Archived-At: Lennart Borgman writes: > On Mon, Dec 28, 2009 at 6:16 AM, Lennart Borgman > wrote: >> I just got into some trouble because of a badly written macro I >> believe. After the long discussions about defmacro here I wonder if >> anyone wants to help me out. How should I write the defmacro below? > > > I resorted to self education (which is not too bad). However I still > got problems - just on a more complicated level. The macro now looks > like this: > > (defmacro define-toggle (symbol value doc &rest args) > "Declare SYMBOL as a customizable variable with a toggle function." > (declare (doc-string 3) (debug t)) > (let* ((SYMBOL-toggle (intern (concat (symbol-name symbol) "-toggle"))) > (SYMBOL-name (symbol-name symbol)) > (var-doc doc) > (fun-doc (concat "Toggles the \(boolean) value of `" SYMBOL-name > "'.\nFor how to set it permanently see this > variable.\n"))) > (let ((var (append `(defcustom ,symbol ,value ,var-doc) > args > nil)) > (fun `(defun ,SYMBOL-toggle () > ,fun-doc > (interactive) > (customize-set-variable (quote ,symbol) (not ,symbol))))) > `(list 'progn ,var ,fun)))) > > This seems to work, but if the call to define-toggle already has been > done then loading a file with this define-toggle gives trouble: > > Debugger entered--Lisp error: (void-variable rngalt-display-validation-header-toggle) > (progn rngalt-display-validation-header rngalt-display-validation-header-toggle) > (define-toggle rngalt-display-validation-header t "Display XML validation headers at the top of buffer when t.\nThe validation header is only displayed in buffers where the main\nmajor mode is derivd from `nxml-mode'." :set (lambda (sym val) (set-default sym val) (rngalt-update-validation-header-overlay-everywhere)) :group (quote relax-ng) :group (quote nxhtml)) > > ... > > There is obviously something I got wrong in the evaluation order since > now, in this situation, the macro now tries to evaluate > > (progn rngalt-display-validation-header rngalt-display-validation-header-toggle) > > I expected it to redefine the defcustom and the defun instead. > Can someone please try to explain what is going on? There must be an eval somewhere that tries to evaluate one time too many. That said, why doesn't your macro just return `(progn ,var ,fun) instead of returning a list form that evaluates to something such as (progn rngalt-display-validation-header rngalt-display-validation-header-toggle) that needs to be evaluated (and of course fails since you didn't define these symbols as variables)? -- __Pascal Bourguignon__ http://www.informatimago.com/