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: Need some education on defmacro define-toggle Date: Mon, 28 Dec 2009 06:16:59 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1261977482 22683 80.91.229.12 (28 Dec 2009 05:18:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Dec 2009 05:18:02 +0000 (UTC) To: emacs help Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 28 06:17:55 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 1NP7zL-0004aB-QX for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Dec 2009 06:17:52 +0100 Original-Received: from localhost ([127.0.0.1]:35670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NP7zK-0000iL-A2 for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Dec 2009 00:17:50 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NP7yy-0000i8-9x for help-gnu-emacs@gnu.org; Mon, 28 Dec 2009 00:17:28 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NP7ys-0000f0-F7 for help-gnu-emacs@gnu.org; Mon, 28 Dec 2009 00:17:26 -0500 Original-Received: from [199.232.76.173] (port=55713 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NP7ys-0000eo-Bk for help-gnu-emacs@gnu.org; Mon, 28 Dec 2009 00:17:22 -0500 Original-Received: from mail-gx0-f224.google.com ([209.85.217.224]:56617) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NP7yr-0004UI-VV for help-gnu-emacs@gnu.org; Mon, 28 Dec 2009 00:17:22 -0500 Original-Received: by gxk24 with SMTP id 24so9205929gxk.6 for ; Sun, 27 Dec 2009 21:17:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:content-type; bh=TT09H/lAznFXgzaPfERDEO69A3GsrUD3+OQUiadltGM=; b=fL6S+dNOuNiZcRWyDhjOlzAHqxXo7NSgkkYIoZrP1HN5GX9siXqnXuoSBcv1DBI+f3 Jh/qO3qnW3yz4WuPeKKWe1DgMgI1G5Vs0AbBEEOyuY7lErlnJFEDaiWtdGR1lt25eyon 2vwpCOFjP8g9QJPngYJMiRx/J6kA6TNVdRFLs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=mD4d8Y/zCQaGafJCAgyG3c5oghAm2mLf79r+dy1Jly49EqPWxFZ5O65Kefuft6iA5K L9WHRrIf4uWsLVd7q+CFDoBNA/Ecqc/lv1P42akoOOK+0i2HEi+CEWe0TGEDdeVPKuGz gJSs9ycBTvhATJ8M2TSCmh0QAp4iRKWYZb6wk= Original-Received: by 10.101.139.7 with SMTP id r7mr16795720ann.41.1261977439072; Sun, 27 Dec 2009 21:17:19 -0800 (PST) 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:70900 Archived-At: 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 need to be able to autolad the defmacro in a little bit strange way too. It is not a normal autoload. I want to redefine it. I do something like: (defun web-autoload (fun src docstring interactive type) "Similar to autoload, but the SRC arg is different." (let ((int (when interactive '(interactive)))) (cond ((eq type 'macro) (setq type 'defmacro)) (t (setq type 'defun))) (eval `(web-autoload-1 ,fun ,src ,docstring ,int ,type)))) (defmacro web-autoload-1 (fun src docstring interactive type) .... (let ((the-macro (append '(,fun) args nil))) (eval the-macro)) ) Here is the troublesome macro: (defmacro define-toggle (symbol value doc &rest args) "Declare SYMBOL as a customizable variable with a toggle function. The purpose of this macro is to define a defcustom and a toggle function suitable for use in a menu. The arguments have the same meaning as for `defcustom' with these restrictions: - The :type keyword cannot be used. Type is always 'boolean. - VALUE must be t or nil. DOC and ARGS are just passed to `defcustom'. A `defcustom' named SYMBOL with doc-string DOC and a function named SYMBOL-toggle is defined. The function toggles the value of SYMBOL. It takes no parameters. To create a menu item something similar to this can be used: \(define-key map [SYMBOL] \(list 'menu-item \"Toggle nice SYMBOL\" 'SYMBOL-toggle :button '(:toggle . SYMBOL)))" (declare (doc-string 3)) (list 'progn (let ((var-decl (list 'custom-declare-variable (list 'quote symbol) (list 'quote value) doc))) (while args (let ((arg (car args))) (setq args (cdr args)) (unless (symbolp arg) (error "Junk in args %S" args)) (let ((keyword arg) (value (car args))) (unless args (error "Keyword %s is missing an argument" keyword)) (setq args (cdr args)) (cond ((not (memq keyword '(:type))) (setq var-decl (append var-decl (list keyword value)))) (t (lwarn '(define-toggle) :error "Keyword %s can't be used here" keyword)))))) (when (assoc :type var-decl) (error ":type is set. Should not happen!")) (setq var-decl (append var-decl (list :type '(quote boolean)))) var-decl) (let* ((SYMBOL-toggle (intern (concat (symbol-name symbol) "-toggle"))) (SYMBOL-name (symbol-name symbol)) (fun-doc (concat "Toggles the \(boolean) value of `" SYMBOL-name "'.\n" "For how to set it permanently see this variable.\n" ;;"\nDescription of `" SYMBOL-name "':\n" doc ))) `(defun ,SYMBOL-toggle () ,fun-doc (interactive) (customize-set-variable (quote ,symbol) (not ,symbol))) )))