[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [RFC] [PATCH] Automatically quote the arguments to an eval macro

From: Aaron Ecay
Subject: Re: [O] [RFC] [PATCH] Automatically quote the arguments to an eval macro
Date: Thu, 05 Nov 2015 14:29:08 +0000
User-agent: Notmuch/0.20.2+65~gbd5504e (http://notmuchmail.org) Emacs/ (x86_64-unknown-linux-gnu)

Hi Nicolas,

Thanks for your feedback.

2015ko azaroak 5an, Nicolas Goaziou-ek idatzi zuen:


>> This means:
>> 1. Users need to remember to put quotes around $n all the time
>> 2. It’s impossible to pass arguments with a " character to a macro
> This can be fixed by removing the `literal' optional argument from
> `replace-regexp-in-string' call in `org-macro-expand'.

I’ve actually managed to make it work with the code as-is, by escaping
the quote with a single backslash.  I must have been confused about
single- vs. double-escaping.

The inconsistency that remains is that quotes need to be backslash-escaped
for eval macros, but not regular macros.

Here’s a test case (works with current master):

| #+macro: foo $1
| {{{foo(xyz\"abc)}}}
| #+macro: bar (eval "$1")
| {{{bar(xyz\"abc)}}}

Ascii export yields:

| Foo is: xyz\"abc
| Bar is: xyz"abc

>> The attached patch changes the behavior of eval macro arguments so that
>> $1 etc. expand to the argument with quotation marks.  That is, the
>> following is now the correct way to write a macro (note lack of "s):
>> #+macro: identity (eval $1)
> I'm not totally opposed to it but it introduces a limitation: all
> arguments must be strings. This is not strictly required, actually. As
> a consequence, I slightly prefer fixing the current situation instead.
> Is there any strong reason to force string?

I’d say the reason is that (AIUI) macros are for string manipulation
during export.  I’m hard-pressed to come up with a good usage of a macro
that treats its arguments as non-strings.  But maybe that’s just a
function of my limited creativity. :)

>> * lisp/org-macro.el (org-macro-expand): Automatically quote the
>> arguments to an eval macro.
> You would also need to update `org-macro-initialize-templates' and
> `org-export-as'.
>> +                    (cond
>> +                     (evalp (format "%S" arg-val))
>> +                     (arg-val arg-val)
> Nitpick: this is equivalent to (arg-val)

I didn’t know this usage of cond....

Thanks again,

Aaron Ecay

reply via email to

[Prev in Thread] Current Thread [Next in Thread]