From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: TIL about use of eval in user Org macros.. Documentation? Date: Wed, 20 Dec 2017 22:30:16 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c033d1c4bcaa10560cd21d1" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRmsf-0007aj-3M for emacs-orgmode@gnu.org; Wed, 20 Dec 2017 17:30:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRmsd-0007wo-TV for emacs-orgmode@gnu.org; Wed, 20 Dec 2017 17:30:29 -0500 Received: from mail-yw0-x22f.google.com ([2607:f8b0:4002:c05::22f]:36100) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eRmsd-0007wL-My for emacs-orgmode@gnu.org; Wed, 20 Dec 2017 17:30:27 -0500 Received: by mail-yw0-x22f.google.com with SMTP id r205so2294698ywb.3 for ; Wed, 20 Dec 2017 14:30:27 -0800 (PST) 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-org list --94eb2c033d1c4bcaa10560cd21d1 Content-Type: text/plain; charset="UTF-8" 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. 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? -- Kaushal Modi --94eb2c033d1c4bcaa10560cd21d1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Using that info, I came up with a "classifie= d" version of n macro for markdown/HTML:

#+MACRO: sec (eval (co= ncat "<span class=3D\"section-num\">" (number-to-= string (org-macro--counter-increment $1 $2)) "</span>"))
Based on that I have two questions:

1. Can you plea= se 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 messa= ge.
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 clas= s as an example)? Should it update org-macro-templates in org-export-before= -processing-hook? or something similar?
--

Kaushal Modi

--94eb2c033d1c4bcaa10560cd21d1-- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Samuel Wales Subject: Re: TIL about use of eval in user Org macros.. Documentation? Date: Fri, 22 Dec 2017 13:10:50 -0700 Message-ID: References: <87tvwkh0sd.fsf@gmx.us> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38355) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eSTee-0007ve-9m for emacs-orgmode@gnu.org; Fri, 22 Dec 2017 15:10:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eSTed-00046J-Lc for emacs-orgmode@gnu.org; Fri, 22 Dec 2017 15:10:52 -0500 Received: from mail-io0-x233.google.com ([2607:f8b0:4001:c06::233]:39373) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eSTed-00045o-HL for emacs-orgmode@gnu.org; Fri, 22 Dec 2017 15:10:51 -0500 Received: by mail-io0-x233.google.com with SMTP id g70so13141995ioj.6 for ; Fri, 22 Dec 2017 12:10:51 -0800 (PST) In-Reply-To: <87tvwkh0sd.fsf@gmx.us> 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: Rasmus Cc: emacs-orgmode@gnu.org note that this feature overlaps babel: head src_emacs-lisp[]{(shell-command-to-string "git rev-parse HEAD" )}\\ time {{{time(%F)}}} From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: TIL about use of eval in user Org macros.. Documentation? Date: Mon, 25 Dec 2017 11:26:06 +0100 Message-ID: <87tvwf14u9.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eTPxT-0001BC-P3 for emacs-orgmode@gnu.org; Mon, 25 Dec 2017 05:26:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eTPxS-0004Ih-Uy for emacs-orgmode@gnu.org; Mon, 25 Dec 2017 05:26:11 -0500 Received: from relay2-d.mail.gandi.net ([2001:4b98:c:538::194]:45529) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eTPxS-0004HY-OT for emacs-orgmode@gnu.org; Mon, 25 Dec 2017 05:26:10 -0500 In-Reply-To: (Kaushal Modi's message of "Wed, 20 Dec 2017 22:30:16 +0000") 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: Kaushal Modi Cc: emacs-org list Hello, Kaushal Modi writes: > #+MACRO: sec (eval (concat "" (number-to-string > (org-macro--counter-increment $1 $2)) "")) Or, #+MACRO: sec @@html:@@{{{n($1,$2)}}}@@html:@@ > 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. Done. Regards, -- Nicolas Goaziou