unofficial mirror of emacs-orgmode@gnu.org
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [PATCH] Startup option to separate macros arguments with an alternative string
Date: Thu, 18 Feb 2021 17:33:46 +0100
Message-ID: <87blchl4id.fsf@posteo.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1065 bytes --]

Hi,

I would like to propose this (possible) patch.

With `#+STARTUP: macro-arg-sep-other' the macros arguments can be
separated by a string other than comma, whose value is defined in
`org-macro-arg-sep-other' (by default it is "'@").

Rationale for this patch: There are many contexts where the comma character can be
inappropriate as an argument separator, since it has to be escaped many times.

If the patch is relevant, I can take care of writing the documentation and docstrings.

Example:

#+begin_src org
  ,#+STARTUP: macro-arg-sep-other
  ,#+MACRO: lg (eval (if (org-export-derived-backend-p org-export-current-backend 'latex) (concat "@@latex:\\foreignlanguage{@@" $1 "@@latex:}{@@" "\u200B" $2 "\u200B" "@@latex:}@@") $2))

  {{{lg(latin'@Lorem ipsum dolor sit amet, consectetuer adipiscing elit, donec hendrerit
  tempor tellus, donec pretium posuere tellus, proin quam nisl, tincidunt et, mattis eget,
  convallis nec, purus.)}}}

  With the escaped character:

 {{{lg(latin'@Lorem ipsum dolor sit amet \'@)}}}
#+end_src

Best regards,

Juan Manuel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-macro-arg-sep.patch --]
[-- Type: text/x-patch, Size: 2302 bytes --]

diff --git a/lisp/org-macro.el b/lisp/org-macro.el
index f914a33d6..311eaf9a5 100644
--- a/lisp/org-macro.el
+++ b/lisp/org-macro.el
@@ -82,6 +82,8 @@ directly, use instead:
 
   #+MACRO: name template")
 
+(defvar org-macro-arg-sep-other "'@")
+
 ;;; Functions
 
 (defun org-macro--set-template (name value templates)
@@ -277,15 +279,19 @@ 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.
+  (let ((sep (cond ((eq org-startup-macro-arg-sep 'comma)
+		      ",")
+		     ((eq org-startup-macro-arg-sep 'other)
+		      org-macro-arg-sep-other))))
   (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"))
+   "\000")))
 
 \f
 ;;; Helper functions and variables for internal macros
diff --git a/lisp/org.el b/lisp/org.el
index 7d8733448..a51893ed3 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -974,6 +974,15 @@ case it is too late to set the variable `org-startup-truncated'."
   :group 'org-startup
   :type 'boolean)
 
+(defcustom org-startup-macro-arg-sep 'comma
+    "TODO"
+    :group 'org-startup
+    :package-version '(Org . "9.0")
+    :version "26.1"
+    :type '(choice
+	    (const :tag "comma" comma)
+	    (const :tag "other" other)))
+
 (defcustom org-startup-indented nil
   "Non-nil means turn on `org-indent-mode' on startup.
 This can also be configured on a per-file basis by adding one of
@@ -4187,7 +4196,8 @@ After a match, the following groups carry important information:
     ("nohideblocks" org-hide-block-startup nil)
     ("beamer" org-startup-with-beamer-mode t)
     ("entitiespretty" org-pretty-entities t)
-    ("entitiesplain" org-pretty-entities nil))
+    ("entitiesplain" org-pretty-entities nil)
+    ("macro-arg-sep-other" org-startup-macro-arg-sep other))
   "Variable associated with STARTUP options for Org.
 Each element is a list of three items: the startup options (as written
 in the #+STARTUP line), the corresponding variable, and the value to set

             reply	other threads:[~2021-02-18 16:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-18 16:33 Juan Manuel Macías [this message]
2021-04-19  9:19 ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87blchl4id.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] Startup option to separate macros arguments with an alternative string' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

unofficial mirror of emacs-orgmode@gnu.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/orgmode/0 orgmode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 orgmode orgmode/ https://yhetil.org/orgmode \
		emacs-orgmode@gnu.org
	public-inbox-index orgmode

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


code repositories for project(s) associated with this inbox:

	orgmode.git.git (no URL configured)

AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git