On 03/05/2021 04:08, Christian Moe wrote:

I frequently need to escape commas in macros, which is a bit of a pain
and easy to forget.

Maybe it is not convenient, but if unescaped comma is a real pain, you could detect it and report an error

# single line may be wrapped by mailer
#+MACRO: extraerror (eval (if (not $2) (concat "*" $1 "*") (error (format "%s: unescaped comma %S" (line-number-at-pos) $2))))

{{{extraerror(valid)}}}
{{{extraerror(valid\, with escaped comma)}}}
{{{extraerror(missed, comma)}}}

Org gurus might suggest a recipe how to convert error into warning, that is easily noticeable but still not fatal, to get all problems after single export attempt. Preferably it should act similar to compiler errors allowing to jump between problem points.

Org 9.3 requires a bit different macro
#MACRO: extraerror (eval (if (equal "" $2) (concat "*" $1 "*") (error (format "%s: unescaped comma %S" (line-number-at-pos) $2))))

Another point: Something that would help, without adding new syntax, is
making macro expansion smart enough to *ignore* separators when the
macro definition contains only *one* argument anyway, as in the cases
above.

I think, this is an idea of the best approach. Unsure concerning precise form. Maybe e.g. "$_" could expand into all arguments greater than maximum referenced number. No promise of forward compatibility of the following hack since it relies on undocumented implementation details.

#+MACRO: allargshack (eval (format "- /%s/ :: %s" $1 (mapconcat #'identity _ ",")))

{{{allargshack(one, two, three)}}}

I do not know if Eric can swap order of arguments of his credits macro. Extracting namely last argument requires a bit more lisp code.


Reply via email to