Re: [O] Macros [was: Re: ATTR_HTML for a clickable image, howto?]
Hi Nicolas, Nicolas Goaziou n.goaz...@gmail.com writes: I'd welcome some improvement of the manual wrt macros -- any taker? Before documenting anything, we should first define them clearly. FWIW, I don't forget this important thread. Let's revive it after the release of Org 7.9, when we will think of moving org-export.el into core. -- Bastien
Re: [O] Macros [was: Re: ATTR_HTML for a clickable image, howto?]
Hello, Sebastien Vauban wxhgmqzgwmuf-genee64ty+gs+fvcfc7...@public.gmane.org writes: Hi Nicolas, Nicolas Goaziou wrote: Bastien bzg-mXXj517/z...@public.gmane.org writes: François Pinard pinard-crdztm1onbswkkpyngo...@public.gmane.org writes: If macros are there to stay in Org, it might be worth documenting a more complete specification about how to define and use them. I'd welcome some improvement of the manual wrt macros -- any taker? Before documenting anything, we should first define them clearly. I think you're right here, seen the latest threads on this. That is, we can define them through documentation, but we shouldn't write documentation by looking at their current implementation. Should macros be allowed anywhere (which means that the user can shoot himself in the foot) or should their expansion happen in a protected environment (thus limiting their power)? If I had to choose, I would opt for the first case... In the first case, can macros generate inline Babel code, that will be executed before export? ... where macros would be pre-processed à la M4 (or C preprocessing): replacing some keyword with some other expression. In the second case, what types of elements are allowed in the protected environment? Also, do we want to allow multiples macros definitions to stack up? I.e. #+MACRO: a-macro First line of the macro. #+MACRO: a-macro Second line of the macro. If so, do we allow blank lines in them, meaning they can break document structure even more? Can the macros be nested? Since macros arguments are comma-separated, how do one insert commas within an argument? Are newline characters allowed in arguments? If not, what else is forbidden there? There are probably other questions, but it should be a good start for a correct implementation. An extra question is: the replacing expression of a macro, must it be pure text, or can it be anything (such as code that will be interpreted, in a further pass, by some back-end)? The first option implies that the expression are inserted in the Org buffer before being parsed. This is mostly what happens in the current exporter. Regards, -- Nicolas Goaziou
Re: [O] Macros [was: Re: ATTR_HTML for a clickable image, howto?]
Hi, François Pinard pin...@iro.umontreal.ca writes: If macros are there to stay in Org, it might be worth documenting a more complete specification about how to define and use them. I'd welcome some improvement of the manual wrt macros -- any taker? Thanks, -- Bastien
Re: [O] Macros [was: Re: ATTR_HTML for a clickable image, howto?]
Hello, Bastien b...@gnu.org writes: François Pinard pin...@iro.umontreal.ca writes: If macros are there to stay in Org, it might be worth documenting a more complete specification about how to define and use them. I'd welcome some improvement of the manual wrt macros -- any taker? Before documenting anything, we should first define them clearly. That is, we can define them through documentation, but we shouldn't write documentation by looking at their current implementation. Should macros be allowed anywhere (which means that the user can shoot himself in the foot) or should their expansion happen in a protected environment (thus limiting their power)? In the first case, can macros generate inline Babel code, that will be executed before export? In the second case, what types of elements are allowed in the protected environment? Also, do we want to allow multiples macros definitions to stack up? I.e. #+MACRO: a-macro First line of the macro. #+MACRO: a-macro Second line of the macro. If so, do we allow blank lines in them, meaning they can break document structure even more? Can the macros be nested? Since macros arguments are comma-separated, how do one insert commas within an argument? Are newline characters allowed in arguments? If not, what else is forbidden there? There are probably other questions, but it should be a good start for a correct implementation. Regards, -- Nicolas Goaziou
Re: [O] Macros [was: Re: ATTR_HTML for a clickable image, howto?]
Hi Nicolas, Nicolas Goaziou wrote: Bastien b...@gnu.org writes: François Pinard pin...@iro.umontreal.ca writes: If macros are there to stay in Org, it might be worth documenting a more complete specification about how to define and use them. I'd welcome some improvement of the manual wrt macros -- any taker? Before documenting anything, we should first define them clearly. I think you're right here, seen the latest threads on this. That is, we can define them through documentation, but we shouldn't write documentation by looking at their current implementation. Should macros be allowed anywhere (which means that the user can shoot himself in the foot) or should their expansion happen in a protected environment (thus limiting their power)? If I had to choose, I would opt for the first case... In the first case, can macros generate inline Babel code, that will be executed before export? ... where macros would be pre-processed à la M4 (or C preprocessing): replacing some keyword with some other expression. In the second case, what types of elements are allowed in the protected environment? Also, do we want to allow multiples macros definitions to stack up? I.e. #+MACRO: a-macro First line of the macro. #+MACRO: a-macro Second line of the macro. If so, do we allow blank lines in them, meaning they can break document structure even more? Can the macros be nested? Since macros arguments are comma-separated, how do one insert commas within an argument? Are newline characters allowed in arguments? If not, what else is forbidden there? There are probably other questions, but it should be a good start for a correct implementation. An extra question is: the replacing expression of a macro, must it be pure text, or can it be anything (such as code that will be interpreted, in a further pass, by some back-end)? Best regards, Seb -- Sebastien Vauban
Re: [O] Macros [was: Re: ATTR_HTML for a clickable image, howto?]
Hi François, François Pinard pin...@iro.umontreal.ca writes: This (partly) replies to the message I sent a few minutes ago. Before sending that message, I checked in the Org manual, and the manual is silent about the possibility of such escaping. The manual is also silent about nesting, which has been mentioned elsewhere in this thread. The examples in the manual do not hint either about whether newlines are allowed or not in macro arguments. Please contribute by sending patches or more readable hints on what should be fixed... If macros are there to stay in Org, it might be worth documenting a more complete specification about how to define and use them. Macros are here to stay. Please also remember the manual cannot cover everything -- Worg can efficiently cover topics like this one. Thanks for your help! -- Bastien
Re: [O] Macros [was: Re: ATTR_HTML for a clickable image, howto?]
Hello, François Pinard pin...@iro.umontreal.ca writes: The examples in the manual do not hint either about whether newlines are allowed or not in macro arguments. They are not. In fact, the manual section Macro replacement says very little, so when I initially read it, I guessed that macros are only usable in very simple cases. However, the last statement says that macros can be used to construct complex HTML code. Yet, the definition method at the beginning suggests that macro definitions have to fit on one line, and this seriously limits the complexity of what we can do with them. So, on initial reading, I just decided I understood nothing about them :-). They can build complex code since you can eval a sexp in a macro: --8---cut here---start-8--- #+TITLE: Macro test #+MACRO: test2 recursive $1 #+MACRO: test A {{{test2(inner)}}} macro, $1. #+MACRO: html-builder (eval (+ $1 $2)) {{{test(and an outer one)}}} Some complex macro {{{html-builder(1,2)}}}. --8---cut here---end---8--- If macros are there to stay in Org, it might be worth documenting a more complete specification about how to define and use them. They are useful. Though, for complex code, I think Babel should be the way to go. Regards, -- Nicolas Goaziou
Re: [O] Macros [was: Re: ATTR_HTML for a clickable image, howto?]
Hello Nicolas, Nicolas Goaziou n.goaz...@gmail.com writes: #+TITLE: Macro test #+MACRO: test2 recursive $1 #+MACRO: test A {{{test2(inner)}}} macro, $1. #+MACRO: html-builder (eval (+ $1 $2)) {{{test(and an outer one)}}} Some complex macro {{{html-builder(1,2)}}}. out of curiosity I tried to export above snippet. it is working nice except for new exporter latex option. (org-export-dispatch and d option) here is the back trace: --8---cut here---start-8--- Debugger entered--Lisp error: (void-variable \1) (+ \1 \2) (eval (+ \1 \2)) eval((eval (+ \1 \2))) (setq value (eval (read value))) (progn (setq value (eval (read value (if (string-match \\`(eval\\ value) (progn (setq value (eval (read value) (when (string-match \\`(eval\\ value) (setq value (eval (read value (let* ((key (org-element-property :key macro)) (args (org-element-property :args macro)) (value (org-export-data (plist-get info (intern (format :macro-%s key))) info))) (let ((s 0) n) (while (string-match \\$\\([0-9]+\\) value s) (setq s (1+ (match-beginning 0)) n (string-to-number (match-string 1 value))) (and (= (length args) n) (setq value (replace-match (nth (1- n) args) t t value) (when (string-match \\`(eval\\ value) (setq value (eval (read value (format %s (or value ))) org-export-expand-macro((macro (:key html-builder :value {{{html-builder(1,2)}}} :args (1 2) :begin 185 :end 208 :post-blank 0)) (:author Yagnesh Raghava Yakkala :creator Generated by Org mode 7.8.10 in Emacs 24.1.50.5. :date \\today :description nil :email yagn...@okhotsk19.lowtem.hokudai.ac.jp :exclude-tags (noexport) :headline-levels 3 :keywords nil :language en :preserve-breaks nil :section-numbers t :select-tags (export) :time-stamp-file t :title (Macro test) :with-archived-trees headline :with-author t :with-clocks nil :with-creator comment :with-drawers t :with-email nil :with-emphasize t :with-entities t :with-fixed-width t :with-footnotes t :with-plannings nil ...)) org-e-latex-macro((macro (:key html-builder :value {{{html-builder(1,2)}}} :args (1 2) :begin 185 :end 208 :post-blank 0)) nil (:author Yagnesh Raghava Yakkala :creator Generated by Org mode 7.8.10 in Emacs 24.1.50.5. :date \\today :description nil :email yagn...@okhotsk19.lowtem.hokudai.ac.jp :exclude-tags (noexport) :headline-levels 3 :keywords nil :language en :preserve-breaks nil :section-numbers t :select-tags (export) :time-stamp-file t :title (Macro test) :with-archived-trees headline :with-author t :with-clocks nil :with-creator comment :with-drawers t :with-email nil :with-emphasize t :with-entities t :with-fixed-width t :with-footnotes t :with-plannings nil ...)) funcall(org-e-latex-macro (macro (:key html-builder :value {{{html-builder(1,2)}}} :args (1 2) :begin 185 :end 208 :post-blank 0)) nil (:author Yagnesh Raghava Yakkala :creator Generated by Org mode 7.8.10 in Emacs 24.1.50.5. :date \\today :description nil :email yagn...@okhotsk19.lowtem.hokudai.ac.jp :exclude-tags (noexport) :headline-levels 3 :keywords nil :language en :preserve-breaks nil :section-numbers t :select-tags (export) :time-stamp-file t :title (Macro test) :with-archived-trees headline :with-author t :with-clocks nil :with-creator comment :with-drawers t :with-email nil :with-emphasize t :with-entities t :with-fixed-width t :with-footnotes t :with-plannings nil ...)) (and (fboundp transcoder) (funcall transcoder data nil info)) (let ((transcoder (org-export-transcoder data info))) (and (fboundp transcoder) (funcall transcoder data nil info))) (cond ((member data (plist-get info :ignore-list)) nil) ((eq type (quote plain-text)) (org-export-filter-apply-functions (plist-get info :filter-plain-text) (let ((transcoder (org-export-transcoder data info))) (if transcoder (funcall transcoder data info) data)) info)) ((not (org-export-interpret-p data info)) (org-export-data (org-export-expand data (mapconcat (lambda (blob) (org-export-data blob info)) (org-element-contents data) )) info)) ((not type) (mapconcat (lambda (obj) (org-export-data obj info)) data )) ((or (not (org-element-contents data)) (and (eq type (quote headline)) (eq (plist-get info :with-archived-trees) (quote headline)) (org-element-property :archivedp data))) (let ((transcoder (org-export-transcoder data info))) (and (fboundp transcoder) (funcall transcoder data nil info (t (let ((transcoder (org-export-transcoder data info))) (when transcoder (let* ((greaterp (memq type org-element-greater-elements)) (objectp (and ... ...)) (contents (mapconcat ... ... ))) (funcall transcoder data (if greaterp (org-element-normalize-string contents) contents) info)) (let* ((type (org-element-type data)) (results (cond ((member data (plist-get info :ignore-list)) nil) ((eq type (quote plain-text)) (org-export-filter-apply-functions (plist-get info :filter-plain-text) (let (...) (if transcoder ... data)) info)) ((not
Re: [O] Macros [was: Re: ATTR_HTML for a clickable image, howto?]
Hello, Yagnesh Raghava Yakkala yagn...@live.com writes: Nicolas Goaziou n.goaz...@gmail.com writes: #+TITLE: Macro test #+MACRO: test2 recursive $1 #+MACRO: test A {{{test2(inner)}}} macro, $1. #+MACRO: html-builder (eval (+ $1 $2)) {{{test(and an outer one)}}} Some complex macro {{{html-builder(1,2)}}}. out of curiosity I tried to export above snippet. it is working nice except for new exporter latex option. (org-export-dispatch and d option) You're right. I was protecting dollar signs before replacing arguments. This should be fixed in master. Thank you for the report. Regards, -- Nicolas Goaziou