From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id sMxoKSEGjGCxbwEAgWs5BA (envelope-from ) for ; Fri, 30 Apr 2021 15:29:05 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id sB8LJSEGjGDaIwAAB5/wlQ (envelope-from ) for ; Fri, 30 Apr 2021 13:29:05 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 069311CA9E for ; Fri, 30 Apr 2021 15:29:05 +0200 (CEST) Received: from localhost ([::1]:34990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcTCZ-0005Zb-R1 for larch@yhetil.org; Fri, 30 Apr 2021 09:29:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcTAG-0004Y8-R6 for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 09:26:40 -0400 Received: from mout01.posteo.de ([185.67.36.65]:53929) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcTAC-0003EH-Hb for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 09:26:40 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 0FE62240028 for ; Fri, 30 Apr 2021 15:26:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1619789193; bh=3Tv9jH0iBL92MTnuLLfKx3Cn/u+LERbWIkK4/fWpr6w=; h=From:To:Subject:Date:From; b=oUzHL0PswDjrrm0F+qCS9DfPSM4VMbnQb2N/zxUR3Hp3y7iDUIbEzoPxgjOUtDaG4 slKSGexTq6moXdqGia+am88+pXP7mc7CFLn9Zn+Gy6pudhgxZUDxt6NFEOo3Gc/Rdq QEW5LjBCyxVLTYBy4+F4qE3iIcgksOojv7GklAYZ+A2gXLDfLwxpa6QH+DlcfI+BfF Lw7kH+hi+Blc17YiwJFoOFHjaa3cn+MPt3yc9bqWWCZ5qoTdq1sD7z3moalmJB5dqf js7RF7O/7d2PTQzvJ+NuxRS9rCdZQbq8vJcLevqTDtNayj7pZ7Pyh7zXzf9HbU46P5 RlkhBFiRUr/GA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4FWtS82xg0z9rxH for ; Fri, 30 Apr 2021 15:26:32 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [PATCH] Possibility of using alternative separators in macros Date: Fri, 30 Apr 2021 13:26:31 +0000 Message-ID: <87wnsjx5rs.fsf@posteo.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=maciaschain@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619789345; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=ZvS3TRBYn4niKYsZaiQVqK2l/s8sW22nAkw3/VxQRpU=; b=FrxdYET51nNrGtK8cCfFY7+gTXCpDrQr8afgErFosgIMjiJfBeZYNjWWQKuSyFm+aROz2m jaWfesxpvP6v5+1aK2+3uhUIPI0h5KFNmh+ayR7kVhNqDxbkMcDqUe+w7+IBQm6J1OTE3P O1aI4G+fsT04Py45QjtU26JCOaSD19LOHLvU/pn1JySiwKd//RkqcOug0bLqzf9sZxG4FO WScsF/gF3/t51RF7QfeFtivKJXSYCkAusvVhOT4/fXw6QsiVI8cdkrYQznLnPAQY72GsEx nfmcOMxSJrmvvAV4bpfwBxPALXY3OZcdOR94TeHWMayxMYJOIGWwcKdWmgmK5A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619789345; a=rsa-sha256; cv=none; b=b0RElBhGk3xlP7Vbn20rUDFhiDutAvBu4HBlJx0QFF5YZXHyfcnm1UyBQYu1NVwShlDYSy YQmQWi2YxznACFmkPOLZzA/H8CJaiK+fnXEsCz6hbU5EWO++IJ6jje6Lg2363dUuEMWY0L w4eXWLZLejqkG/roMCSp+ycOJI8G1iNuYxkPdgDJbFiu6mDEwjrHDqXwJfdgm6G5tiaN6n jCkBvNTeLv/N+sLrWpHS4VIUzeOgs3X+iawQMfFWJpUcG/DzWQ4nLMOJOJ622357YeTykh XC6R6j9MrYjDOJa+TzaEEXP6lxl7pYBTacSEMvFlcU/eaQ0PKmIJnVuqCB5hfw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=oUzHL0Ps; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.65 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=oUzHL0Ps; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 069311CA9E X-Spam-Score: -2.65 X-Migadu-Scanner: scn0.migadu.com X-TUID: qDKA+KRg9Nos --=-=-= Content-Type: text/plain Hi all, I would like to propose (patch attached) the possibility of using an alternate character for separate arguments in replacement macros, following a suggestion from Nicolas Goaziou in this (closed) thread: https://orgmode.org/list/87o8ead42u.fsf@nicolasgoaziou.fr/ The idea would be to explicitly indicate the separator just before the parentheses. The allowed characters are any character other than a letter, a number, a space, a dash, a low line or a parenthesis. A new property `:sep' is added to `org-element-macro-parser', whose default value is a comma. Example of use. Suppose we define this macro: #+MACRO: foo (eval (format "%s and %s" $1 $2)) Under normal conditions, the expected separator will be the comma: {{{foo(x,z\, y)}}} => x and z, y But we can also do this: {{{foo@(x@z, y \@)}}} => x and z, y @ I think sometimes it may be preferable to separate the arguments by an alternative character. For example, let's imagine we define a macro (named 'lg') for LaTeX export, which admits two arguments, exactly the same args as the Babel (LaTeX) macro \foreignlanguage{lang}{short-text}: {{{lg(lang,short-text)}}}. It would be much more comfortable something like: {{{lg|(latin|trado, tradidi, traditur)}}} instead of having to escape commas in: {{{lg(latin,trado\, tradidi\, traditur)}}} Best regards, Juan Manuel --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Alternative-args-separator-for-replacement-macros.patch >From 400d5779508fd7206a353bdb444c3cba382b8f01 Mon Sep 17 00:00:00 2001 From: juanmanuel Date: Fri, 30 Apr 2021 14:45:54 +0200 Subject: [PATCH] Alternative args separator for replacement macros --- lisp/org-element.el | 9 +++++++-- lisp/org-macro.el | 9 +++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index a675bf512..34a9b880a 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]*?\\))\\)?}}}") + (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 --=-=-=--