* macros which expand to other macros
@ 2009-09-02 21:29 Daniel Clemente
2009-09-03 6:50 ` Carsten Dominik
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Clemente @ 2009-09-02 21:29 UTC (permalink / raw)
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 „This file is best viewed when you open file {{{input-file}}} in org-mode (Emacs).“, 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 {{…uno}}}
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 changing 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)))))))
(defun org-export-apply-macros-in-string (s)
"Apply the macros in string S."
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: macros which expand to other macros
2009-09-02 21:29 macros which expand to other macros Daniel Clemente
@ 2009-09-03 6:50 ` Carsten Dominik
0 siblings, 0 replies; 2+ messages in thread
From: Carsten Dominik @ 2009-09-03 6:50 UTC (permalink / raw)
To: Daniel Clemente; +Cc: org-mode Mailinglist
Hi Daniel,
I have applied the patch, thanks. I used the more restrictive version
without
allowing partial macros. Seems a bit wired to me. Or can someone come
up with a compelling use case?
- Carsten
On Sep 2, 2009, at 11:29 PM, Daniel Clemente wrote:
>
> Hi.
>
> I want to include a note in several pages, therefore I created a #
> +MACRO for it. The macro must say „This file is best viewed when you
> open file {{{input-file}}} in org-mode (Emacs).“, 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 {{…uno}}}
>
>
> 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 changing 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)))))))
>
> (defun org-export-apply-macros-in-string (s)
> "Apply the macros in string S."
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-09-03 6:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-02 21:29 macros which expand to other macros Daniel Clemente
2009-09-03 6:50 ` Carsten Dominik
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.