From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.help Subject: Re: Need some education on defmacro define-toggle Date: Mon, 28 Dec 2009 20:28:23 +0100 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1262028573 24219 80.91.229.12 (28 Dec 2009 19:29:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Dec 2009 19:29:33 +0000 (UTC) To: emacs help Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 28 20:29:26 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 1NPLHQ-00006C-5c for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Dec 2009 20:29:24 +0100 Original-Received: from localhost ([127.0.0.1]:43704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPLHQ-0000ET-3p for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Dec 2009 14:29:24 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NPLGs-00008K-Jg for help-gnu-emacs@gnu.org; Mon, 28 Dec 2009 14:28:50 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NPLGn-0008Nl-OA for help-gnu-emacs@gnu.org; Mon, 28 Dec 2009 14:28:50 -0500 Original-Received: from [199.232.76.173] (port=36575 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPLGn-0008NS-CM for help-gnu-emacs@gnu.org; Mon, 28 Dec 2009 14:28:45 -0500 Original-Received: from mail-yw0-f177.google.com ([209.85.211.177]:35599) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NPLGm-0006Ik-TU for help-gnu-emacs@gnu.org; Mon, 28 Dec 2009 14:28:45 -0500 Original-Received: by ywh7 with SMTP id 7so782195ywh.24 for ; Mon, 28 Dec 2009 11:28:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type; bh=VGRKTAdYyKCDDHHAuO+ANuth+G4h/RPXMViukSLFwUU=; b=rwyW/oFkh1wxfrfbBIPTIdFukIOm0fa4FB5JOE9BH2I7UaSLN6dorEyVnTyHSJmQbz xLfzWEsFWYjC+oa3CZ6S8zXqMlAe0/xU51Q7N0H1xaXow5TI3P8e43GUEGL4RjaC1J0p kFlsKuJaxvgGSyINeNCY9tiN/OR6lELsH5oeo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=Fpvn4hpb3N8PIF7MpXFxzg24oBNgWFc/+k6U+8gyJLGFACKIbySN/uUKiV3uFltEN9 PA0PHOj5QmkTv2SMvdGtg5XEw7Sx2nb35ASgHg0hiZZKMx6y5C7kyur0PXA/F+m2hRH7 kapm5aWvbxImqMk4hTBr6kp1RQuNyV03JlvVU= Original-Received: by 10.101.135.15 with SMTP id m15mr24403105ann.13.1262028523522; Mon, 28 Dec 2009 11:28:43 -0800 (PST) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:70912 Archived-At: 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 derived from `nxml-mode'." :set (lambda (sym val) (set-default sym val) (rngalt-update-validation-header-overlay-everywhere)) :group (quote relax-ng) :group (quote nxhtml)) eval-buffer(#> nil "c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/rngalt.el" nil t) ; Reading at buffer position 24737 load-with-code-conversion("c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/rngalt.el" "c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/rngalt.el" t t) require(rngalt nil t) (progn (require (quote rngalt) nil t)) (eval-and-compile (require (quote rngalt) nil t)) eval-buffer(#> nil "c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/nxhtml-mode.el" nil t) ; Reading at buffer position 2959 load-with-code-conversion("c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/nxhtml-mode.el" "c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/nxhtml-mode.el" t t) require(nxhtml-mode nil t) (progn (require (quote nxhtml-mode) nil t)) (if (fboundp (quote nxml-mode)) (progn (require ... nil t))) (when (fboundp (quote nxml-mode)) (require (quote nxhtml-mode) nil t)) (progn (when (fboundp ...) (require ... nil t))) (eval-when-compile (when (fboundp ...) (require ... nil t))) eval-buffer(# nil "c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/nxhtml-menu.el" nil t) ; Reading at buffer position 3227 load-with-code-conversion("c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/nxhtml-menu.el" "c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/nxhtml-menu.el" nil nil) load("c:/emacs/p/091204/EmacsW32/nxhtml/nxhtml/nxhtml-menu.el") (let* ((vcs ...) (base-url ...) (rel-url ...) (base-dir ...) (rel-url-el ...) file-url dl-file) (unless (stringp base-url) (setq base-url ...)) (unless (stringp base-dir) (setq base-dir ...)) (setq dl-file (expand-file-name rel-url-el base-dir)) (message "dl-file=%s" dl-file) (unless (file-exists-p dl-file) (web-vcs-get-missing-matching-files vcs base-url base-dir rel-url-el) (unless ... ...)) (load dl-file) (unless (symbol-function ...) (setq err ...))) (if (not (listp ...)) (let (...) (load ...) (unless ... ...)) (let* (... ... ... ... ... file-url dl-file) (unless ... ...) (unless ... ...) (setq dl-file ...) (message "dl-file=%s" dl-file) (unless ... ... ...) (load dl-file) (unless ... ...))) (let* ((lib-web ...) (old-hist-elt ...) (auto-fun ...) err) (fset (quote nxhtml-global-minor-mode) nil) (if (not ...) (let ... ... ...) (let* ... ... ... ... ... ... ... ...)) (if (not err) (progn ... ...) (fset ... auto-fun) (error "web-autoload: %s" err))) nxhtml-global-minor-mode(1) (let* ((util-dir ...) (related-dir ...) (nxhtml-dir ...) (company-dir ...) (tests-dir ...)) (add-to-list (quote load-path) nxhtml-dir) (add-to-list (quote load-path) related-dir) (add-to-list (quote load-path) util-dir) (add-to-list (quote load-path) nxhtml-install-dir) (add-to-list (quote load-path) company-dir) (add-to-list (quote load-path) tests-dir) (setq web-autoload-default-filename-element nxhtml-install-dir) (message "... nXhtml loading %.1f seconds elapsed ..." (- ... nxhtml-load-time-start)) (load (expand-file-name "nxhtml-loaddefs" nxhtml-install-dir)) (message "... nXhtml loading %.1f seconds elapsed ..." (- ... nxhtml-load-time-start)) (message "Turn on `nxhtml-global-minor-mode' unconditionally") (nxhtml-global-minor-mode 1) (message "... nXhtml loading %.1f seconds elapsed ..." (- ... nxhtml-load-time-start)) (when (fboundp ...) (load ...) (rncpp-patch-xhtml-loader)) (message "... nXhtml loading %.1f seconds elapsed ..." (- ... nxhtml-load-time-start)) (load (expand-file-name "nxhtml/nxhtml-autoload" nxhtml-install-dir))) (if nil nil (provide (quote nxhtml-autostart)) (if (< emacs-major-version 23) (load ...) (let ... ...)) (let* (... ... ... ... ...) (add-to-list ... nxhtml-dir) (add-to-list ... related-dir) (add-to-list ... util-dir) (add-to-list ... nxhtml-install-dir) (add-to-list ... company-dir) (add-to-list ... tests-dir) (setq web-autoload-default-filename-element nxhtml-install-dir) (message "... nXhtml loading %.1f seconds elapsed ..." ...) (load ...) (message "... nXhtml loading %.1f seconds elapsed ..." ...) (message "Turn on `nxhtml-global-minor-mode' unconditionally") (nxhtml-global-minor-mode 1) (message "... nXhtml loading %.1f seconds elapsed ..." ...) (when ... ... ...) (message "... nXhtml loading %.1f seconds elapsed ..." ...) (load ...)) (message "... nXhtml loading %.1f seconds elapsed ..." (- ... nxhtml-load-time-start)) (when nxhtml-flymake-setup (flymake-js-load) (flymake-css-load) (flymake-java-1-load) (add-hook ... ...)) (nxhtml-list-loaded-features nil) (message "Nxml/Nxhtml Autostart.el loaded in %.1f seconds" (- ... nxhtml-load-time-start))) (unless nil (provide (quote nxhtml-autostart)) (if (< emacs-major-version 23) (load ...) (let ... ...)) (let* (... ... ... ... ...) (add-to-list ... nxhtml-dir) (add-to-list ... related-dir) (add-to-list ... util-dir) (add-to-list ... nxhtml-install-dir) (add-to-list ... company-dir) (add-to-list ... tests-dir) (setq web-autoload-default-filename-element nxhtml-install-dir) (message "... nXhtml loading %.1f seconds elapsed ..." ...) (load ...) (message "... nXhtml loading %.1f seconds elapsed ..." ...) (message "Turn on `nxhtml-global-minor-mode' unconditionally") (nxhtml-global-minor-mode 1) (message "... nXhtml loading %.1f seconds elapsed ..." ...) (when ... ... ...) (message "... nXhtml loading %.1f seconds elapsed ..." ...) (load ...)) (message "... nXhtml loading %.1f seconds elapsed ..." (- ... nxhtml-load-time-start)) (when nxhtml-flymake-setup (flymake-js-load) (flymake-css-load) (flymake-java-1-load) (add-hook ... ...)) (nxhtml-list-loaded-features nil) (message "Nxml/Nxhtml Autostart.el loaded in %.1f seconds" (- ... nxhtml-load-time-start))) eval-buffer() ; Reading at buffer position 8253 call-interactively(eval-buffer nil nil) 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?