emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* TIL about use of eval in user Org macros.. Documentation?
@ 2017-12-20 22:30 Kaushal Modi
  2017-12-21  9:45 ` Rasmus
  2017-12-25 10:26 ` Nicolas Goaziou
  0 siblings, 2 replies; 4+ messages in thread
From: Kaushal Modi @ 2017-12-20 22:30 UTC (permalink / raw)
  To: emacs-org list

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

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 "<span class=\"section-num\">" (number-to-string
(org-macro--counter-increment $1 $2)) "</span>"))

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

[-- Attachment #2: Type: text/html, Size: 1293 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TIL about use of eval in user Org macros.. Documentation?
  2017-12-20 22:30 TIL about use of eval in user Org macros.. Documentation? Kaushal Modi
@ 2017-12-21  9:45 ` Rasmus
  2017-12-22 20:10   ` Samuel Wales
  2017-12-25 10:26 ` Nicolas Goaziou
  1 sibling, 1 reply; 4+ messages in thread
From: Rasmus @ 2017-12-21  9:45 UTC (permalink / raw)
  To: emacs-orgmode

Kaushal Modi <kaushal.modi@gmail.com> 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 "<span class=\"section-num\">" (number-to-string (org-macro--counter-increment $1 $2)) "</span>"))
>
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TIL about use of eval in user Org macros.. Documentation?
  2017-12-21  9:45 ` Rasmus
@ 2017-12-22 20:10   ` Samuel Wales
  0 siblings, 0 replies; 4+ messages in thread
From: Samuel Wales @ 2017-12-22 20:10 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

note that this feature overlaps babel:

head src_emacs-lisp[]{(shell-command-to-string "git rev-parse HEAD" )}\\
time {{{time(%F)}}}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TIL about use of eval in user Org macros.. Documentation?
  2017-12-20 22:30 TIL about use of eval in user Org macros.. Documentation? Kaushal Modi
  2017-12-21  9:45 ` Rasmus
@ 2017-12-25 10:26 ` Nicolas Goaziou
  1 sibling, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2017-12-25 10:26 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: emacs-org list

Hello,

Kaushal Modi <kaushal.modi@gmail.com> writes:

> #+MACRO: sec (eval (concat "<span class=\"section-num\">" (number-to-string
> (org-macro--counter-increment $1 $2)) "</span>"))

Or,

#+MACRO: sec @@html:<span class="section-num">@@{{{n($1,$2)}}}@@html:</span>@@

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-25 10:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-20 22:30 TIL about use of eval in user Org macros.. Documentation? Kaushal Modi
2017-12-21  9:45 ` Rasmus
2017-12-22 20:10   ` Samuel Wales
2017-12-25 10:26 ` Nicolas Goaziou

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).