From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: Re: [RFC] [PATCH] Automatically quote the arguments to an eval macro Date: Thu, 05 Nov 2015 14:29:08 +0000 Message-ID: <87pozov7t7.fsf@gmail.com> References: <874mh1x2eu.fsf@gmail.com> <874mh0q1of.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuLXP-0001Mi-MP for emacs-orgmode@gnu.org; Thu, 05 Nov 2015 09:29:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZuLXL-0000SR-Hc for emacs-orgmode@gnu.org; Thu, 05 Nov 2015 09:29:15 -0500 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:37943) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuLXL-0000SL-B8 for emacs-orgmode@gnu.org; Thu, 05 Nov 2015 09:29:11 -0500 Received: by wmeg8 with SMTP id g8so14974781wme.1 for ; Thu, 05 Nov 2015 06:29:10 -0800 (PST) In-Reply-To: <874mh0q1of.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nicolas Goaziou , orgmode 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=E2=80=99s impossible to pass arguments with a " character to a mac= ro >=20 > This can be fixed by removing the `literal' optional argument from > `replace-regexp-in-string' call in `org-macro-expand'. I=E2=80=99ve actually managed to make it work with the code as-is, by escap= ing 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=E2=80=99s a test case (works with current master): ,---- | #+macro: foo $1 |=20 | {{{foo(xyz\"abc)}}} |=20 | #+macro: bar (eval "$1") |=20 | {{{bar(xyz\"abc)}}} `---- Ascii export yields: ,---- | Foo is: xyz\"abc |=20 | Bar is: xyz"abc `---- >=20 >> 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): >>=20 >> #+macro: identity (eval $1) >=20 > 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. >=20 > Is there any strong reason to force string? I=E2=80=99d say the reason is that (AIUI) macros are for string manipulation during export. I=E2=80=99m hard-pressed to come up with a good usage of a = macro that treats its arguments as non-strings. But maybe that=E2=80=99s just a function of my limited creativity. :) >=20 >> * lisp/org-macro.el (org-macro-expand): Automatically quote the >> arguments to an eval macro. >=20 > You would also need to update `org-macro-initialize-templates' and > `org-export-as'. >=20 >> + (cond >> + (evalp (format "%S" arg-val)) >> + (arg-val arg-val) >=20 > Nitpick: this is equivalent to (arg-val) I didn=E2=80=99t know this usage of cond.... Thanks again, --=20 Aaron Ecay