emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] Startup option to separate macros arguments with an alternative string
Date: Wed, 21 Apr 2021 16:01:35 +0000	[thread overview]
Message-ID: <875z0fzkww.fsf@posteo.net> (raw)
In-Reply-To: <87o8ead42u.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Mon, 19 Apr 2021 11:19:21 +0200")

Hello again.

I forgot to answer this question on your previous message, sorry...

Nicolas Goaziou writes:

> That being said, we can discuss syntax that is not depending upon some
> variable. For example macro names are written with a limited set of
> characters (alphanumeric, dash, underscore). We might allow the optional
> argument separator to be located right before the opening parenthesis,
> e.g.,
>
>   {{{macroname@(latin@Lorem ipsum dolor sit amet, ...)}}}
>   {{{macroname|(latin|Lorem ipsum dolor sit amet, ...)}}}

I think it's a very interesting idea. I've made this sketch (at least
as a proof of concept), what do you think of the approach?

Example (and code below):

#+macro: foo (eval (format "%s and %s" $1 $2))

{{{foo(xxx,zzz\, yyy)}}}

{{{foo|(xxx|zzz, aaa)}}}

{{{foo@(xxx@zzz, sss)}}}

{{{foo|(xxx|zzz\| aaa)}}}

{{{foo@(xxx@zzz\@ sss)}}}

#+begin_src emacs-lisp
  (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
  `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" (format "%s" sep)))))
      s nil t)
     "\000"))

  (defun org-element-macro-parser ()
    "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
  `: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_]*\\)\\([^a-zA-Z]*[^-a-zA-Z0-9_]*\\)\\((\\([^\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))
	      (args (pcase (match-string-no-properties 4)
		      (`nil nil)
		      (a (org-macro-extract-arguments
			  (if (not (equal (match-string-no-properties 2) ""))
			      (match-string-no-properties 2)
			    ",")
			  (replace-regexp-in-string
			   "[ \t\r\n]+" " " (org-trim a)))))))
	  (list 'macro
		(list :key key
		      :value value
		      :args args
		      :begin begin
		      :end end
		      :post-blank post-blank))))))

  (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
  `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" (format "%s" sep)))))
      s nil t)
     "\000"))
#+end_src




  parent reply	other threads:[~2021-04-21 16:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-18 16:33 [PATCH] Startup option to separate macros arguments with an alternative string Juan Manuel Macías
2021-04-19  9:19 ` Nicolas Goaziou
2021-04-20 13:56   ` Juan Manuel Macías
2021-04-21 16:01   ` Juan Manuel Macías [this message]
2021-04-22 12:55     ` Nicolas Goaziou
2021-04-22 13:46       ` Juan Manuel Macías
2021-04-25  3:46         ` Timothy

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=875z0fzkww.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).