From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: TIL about use of eval in user Org macros.. Documentation? Date: Thu, 21 Dec 2017 10:45:38 +0100 Message-ID: <87tvwkh0sd.fsf@gmx.us> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRxQP-0005Aq-MT for emacs-orgmode@gnu.org; Thu, 21 Dec 2017 04:46:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRxQK-00042O-Vi for emacs-orgmode@gnu.org; Thu, 21 Dec 2017 04:46:01 -0500 Received: from [195.159.176.226] (port=35149 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eRxQK-000401-Nz for emacs-orgmode@gnu.org; Thu, 21 Dec 2017 04:45:56 -0500 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eRxOJ-0007Dr-5S for emacs-orgmode@gnu.org; Thu, 21 Dec 2017 10:43:51 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Kaushal Modi writes: > Hello, > > The commit message in this commit is golden: > http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=3ac619c8ac9934a2a1368f3de8ffad951f900067 > > Using that info, I came up with a "classified" version of n macro for markdown/HTML: > > #+MACRO: sec (eval (concat "" (number-to-string (org-macro--counter-increment $1 $2)) "")) > > Based on that I have two questions: > 1. Can you please document the use of eval form in Org macro definitions > in the Org manual(.org)? Its awesome wasn't evident to me until I read > that commit message. I guess it isn’t documented in the manual... I agree, there could be a second example and the mention of using lisp or at least a mention of the ‘org-export-global-macros’ docstring. > 2. (Another question on canonical approach) What would be the recommended approach for an exporter backend to add new > macros or override existing macros (like "n" macro to wrap the string with HTML class as an example)? Should it update > org-macro-templates in org-export-before-processing-hook? or something similar? Do you really need to overwrite an old macro? Couldn’t you define a new macro? org-export-before-processing-hook is definitely the right hook, cf. ‘org-export-as’. (defun fooreplace (backend) (when (eq backend 'mybackend) (goto-char (point-min)) (while (search-forward-regexp "{{{foo\\((?\\)" nil t) (replace-match "{{{myfoo\\1")) (goto-char (point-max)) (insert "\n#+macro: myfoo mybar\n")))) Rasmus -- May contains speling mistake