From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Lennart Borgman (gmail)" Newsgroups: gmane.emacs.help Subject: defmacro is worse than my neighbours cat Date: Fri, 12 Sep 2008 23:13:10 +0200 Message-ID: <48CADB66.3030807@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1221254026 6803 80.91.229.12 (12 Sep 2008 21:13:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Sep 2008 21:13:46 +0000 (UTC) To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 12 23:14:42 2008 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 1KeFyR-0007D9-Bf for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Sep 2008 23:14:39 +0200 Original-Received: from localhost ([127.0.0.1]:45124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KeFxQ-0005MV-HH for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Sep 2008 17:13:36 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KeFx6-0005Kf-LF for help-gnu-emacs@gnu.org; Fri, 12 Sep 2008 17:13:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KeFx4-0005Jy-VE for help-gnu-emacs@gnu.org; Fri, 12 Sep 2008 17:13:16 -0400 Original-Received: from [199.232.76.173] (port=50217 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KeFx4-0005Jt-Qf for help-gnu-emacs@gnu.org; Fri, 12 Sep 2008 17:13:14 -0400 Original-Received: from ch-smtp02.sth.basefarm.net ([80.76.149.213]:49638) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KeFx4-0003v6-5A for help-gnu-emacs@gnu.org; Fri, 12 Sep 2008 17:13:14 -0400 Original-Received: from c83-254-151-87.bredband.comhem.se ([83.254.151.87]:63471 helo=[127.0.0.1]) by ch-smtp02.sth.basefarm.net with esmtp (Exim 4.68) (envelope-from ) id 1KeFx2-0003Tx-7k for help-gnu-emacs@gnu.org; Fri, 12 Sep 2008 23:13:12 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666 X-Enigmail-Version: 0.95.7 X-Antivirus: avast! (VPS 080912-0, 2008-09-12), Outbound message X-Antivirus-Status: Clean X-Originating-IP: 83.254.151.87 X-Scan-Result: No virus found in message 1KeFx2-0003Tx-7k. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1KeFx2-0003Tx-7k bec71f646d9b2177d3e574b7656cafec X-detected-kernel: by monty-python.gnu.org: Linux 2.6? (barebone, rare!) 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:57491 Archived-At: defmacro is worse than my neighbour's cat. When I think I everything is fine and I calm down they bite. I have a defmacro where I define a function and I want to build the doc string for this function in a certain way. This works fine - until I byte compile it. Can someone please try to explain to me how I can do what I want? Below is the defmacro. Look for "fix-me". (defmacro define-mumamo-multi-major-mode (fun-sym spec-doc chunks) "Define a function that turn on support for multiple major modes." (let* ((mumamo-describe-chunks (make-symbol "mumamo-describe-chunks")) (turn-on-fun (if (symbolp fun-sym) (symbol-value (intern (symbol-name (quote fun-sym)))) (error "Parameter FUN-SYM must be a symbol"))) (turn-on-fun-alias (intern (concat "mumamo-alias-" (symbol-name (symbol-value (intern (symbol-name (quote fun-sym)))))))) (turn-on-hook (intern (concat (symbol-name turn-on-fun) "-hook"))) (turn-on-map (intern (concat (symbol-name turn-on-fun) "-map"))) (turn-on-hook-doc (concat "Hook run at the very end of `" (symbol-name turn-on-fun) "'.")) (chunks2 (if (symbolp chunks) (symbol-value chunks) chunks)) (docstring (concat spec-doc " This function is called a multi major mode. The main use for it is in `auto-mode-alist' to have Emacs do this setup whenever you open a file named in a certain way. \(You can of course call this function directly yourself too.) It sets up for multiple mode in the following way: " ;; Fix-me: During byte compilation the next line is not ;; expanded as I thought because the functions in CHUNK is ;; not defined. How do I fix this? (funcall 'mumamo-describe-chunks chunks2) " At the very end this multi major mode function runs first the hook `mumamo-turn-on-hook' and then `" (symbol-name turn-on-hook) "'. There is a keymap specific to this multi major mode, but it is not returned by `current-local-map' which returns the chunk's major mode's local keymap. The keymap is named `" (symbol-name turn-on-map) "'. This major mode has an alias `mumamo-alias-" (symbol-name turn-on-fun) "'. For more information see `define-mumamo-multi-major-mode'." ))) `(progn (add-to-list 'mumamo-defined-turn-on-functions (cons (car ',chunks2) ',turn-on-fun)) (defvar ,turn-on-hook nil ,turn-on-hook-doc) (defvar ,turn-on-map (make-sparse-keymap) ,(concat "Keymap for multi major mode function `" (symbol-name turn-on-fun) "'")) (defvar ,turn-on-fun nil) (make-variable-buffer-local ',turn-on-fun) (put ',turn-on-fun 'permanent-local t) (defun ,turn-on-fun nil ,docstring (interactive) (let ((old-major-mode (or mumamo-major-mode major-mode))) (kill-all-local-variables) (run-hooks 'change-major-mode-hook) (setq mumamo-multi-major-mode ',turn-on-fun) (setq ,turn-on-fun t) (mumamo-add-multi-keymap ',turn-on-fun ,turn-on-map) (setq mumamo-current-chunk-family (copy-tree ',chunks2)) (mumamo-turn-on-actions old-major-mode) (run-hooks ',turn-on-hook))) (defalias ',turn-on-fun-alias ',turn-on-fun) )))