From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Clemente Subject: macros which expand to other macros Date: Wed, 02 Sep 2009 23:29:34 +0200 Message-ID: <87ab1d6nnl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MixLR-0000BC-3E for emacs-orgmode@gnu.org; Wed, 02 Sep 2009 17:26:21 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MixLM-0008Vi-7F for emacs-orgmode@gnu.org; Wed, 02 Sep 2009 17:26:20 -0400 Received: from [199.232.76.173] (port=48762 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MixLM-0008VW-3H for emacs-orgmode@gnu.org; Wed, 02 Sep 2009 17:26:16 -0400 Received: from mail-fx0-f226.google.com ([209.85.220.226]:35742) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MixLK-000116-Q2 for emacs-orgmode@gnu.org; Wed, 02 Sep 2009 17:26:15 -0400 Received: by fxm26 with SMTP id 26so1321072fxm.42 for ; Wed, 02 Sep 2009 14:26:07 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: org-mode Mailinglist Hi. I want to include a note in several pages, therefore I created a #+MACRO = for it. The macro must say =E2=80=9EThis file is best viewed when you open = file {{{input-file}}} in org-mode (Emacs).=E2=80=9C, where {{{input-file}}}= would be expanded to the name of the file being expanded. Then I noticed that macros can't expand to other macros. This means: #+MACRO: uno 1 #+MACRO: one {{{uno}}} {{{uno}}} works (1) but {{{one}}} should also be 1, not {{=E2=80=A6uno}}} I attach a patch [1] which adds support for macros which expand to other = macros, so the previous examples would work. It would of course get locked if you wanted macros like #+MACRO: recu {{{= recu}}}, but that's apparently the intended behaviour :-) It will even work for macros that create parts of other macros. #+MACRO: cc1 100001 #+MACRO: cc2 100002 #+MACRO: mycc-start {{{cc #+MACRO: mycc-end 2}}} Yes, it is {{{mycc-start}}}{{{mycc-end}}}. And even: #+MACRO: mycc {{{mycc-start}}}{{{mycc-end}}} {{{mycc}}}. (100002 in both cases). If this is too complex, this partial macro writing can be disallowed by c= hanging the (beginning-of-line) to a (goto-char (match-beginning 0)). -- Daniel [1] diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 3e12e6a..3d2fad8 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -2106,7 +2106,7 @@ TYPE must be a string, any of: (if (and val (not (stringp val))) (setq val (format "%s" val)))) (and (stringp val) - (replace-match val t t)))))) + (prog1 (replace-match val t t) (beginning-of-line))))))) =20 (defun org-export-apply-macros-in-string (s) "Apply the macros in string S."