Here is the fixed version of the patch. Best regards,
Juan Manuel Eric S Fraga <e.fr...@ucl.ac.uk> writes: > Could you create a new patch so I can try this easily? > > gracias, > eric
>From 4aae61c3600fba136dfa101d54011c0aef9169a3 Mon Sep 17 00:00:00 2001 From: Juan Manuel Macías <maciasch...@posteo.net> Date: Tue, 11 May 2021 18:41:34 +0200 Subject: [PATCH] Alternative args separator for replacement macros --- lisp/org-element.el | 11 ++++++++--- lisp/org-macro.el | 9 +++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index a675bf512..da4035689 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -3279,21 +3279,25 @@ CONTENTS is the contents of the object, or nil." "Parse macro at point, if any. When at a macro, return a list whose car is `macro' and cdr -a plist with `:key', `:args', `:begin', `:end', `:value' and +a plist with `:key', `:args', `:begin', `:end', `:sep', `:value' and `:post-blank' as keywords. Otherwise, return nil. Assume point is at the macro." (save-excursion - (when (looking-at "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\((\\([^\000]*?\\))\\)?}}}") - (let ((begin (point)) + (when (looking-at "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)\\([^a-zA-Z\s()]*[^-a-zA-Z0-9_\s]*\\)\\((\\([^\000]*?\\))\\)?}}}") + (let* ((begin (point)) (key (downcase (match-string-no-properties 1))) (value (match-string-no-properties 0)) (post-blank (progn (goto-char (match-end 0)) (skip-chars-forward " \t"))) (end (point)) + (sep (if (not (equal (match-string-no-properties 2) "")) + (match-string-no-properties 2) + ",")) (args (pcase (match-string-no-properties 3) (`nil nil) (a (org-macro-extract-arguments + sep (replace-regexp-in-string "[ \t\r\n]+" " " (org-trim a))))))) (list 'macro @@ -3302,6 +3306,7 @@ Assume point is at the macro." :args args :begin begin :end end + :sep sep :post-blank post-blank)))))) (defun org-element-macro-interpreter (macro _) diff --git a/lisp/org-macro.el b/lisp/org-macro.el index 29c403658..e047cd78e 100644 --- a/lisp/org-macro.el +++ b/lisp/org-macro.el @@ -294,20 +294,21 @@ of `org-macro-extract-arguments'." nil t) s))))) -(defun org-macro-extract-arguments (s) +(defun org-macro-extract-arguments (sep s) "Extract macro arguments from string S. S is a string containing comma separated values properly escaped. -Return a list of arguments, as strings. This is the opposite of +SEP is the character used to separate arguments. Return a list +of arguments, as strings. This is the opposite of `org-macro-escape-arguments'." ;; Do not use `org-split-string' since empty strings are ;; meaningful here. (split-string (replace-regexp-in-string - "\\(\\\\*\\)," + (format "\\(\\\\*\\)%s" sep) (lambda (str) (let ((len (length (match-string 1 str)))) (concat (make-string (/ len 2) ?\\) - (if (zerop (mod len 2)) "\000" ",")))) + (if (zerop (mod len 2)) "\000" (format "%s" sep))))) s nil t) "\000")) -- 2.26.0