Re: [O] Macro that calls external program
See the variables org-export-before-processing-hook and org-export-before-parsing-hook. You can put something like this in a noexport tagged build heading in your document. Here I run head on the org-file to just get the first three lines. you can replace that with your external filter.: #+BEGIN_SRC emacs-lisp (let ((org-export-before-parsing-hook '((lambda (backend) "lightly tested" (let ((new-doc (shell-command-to-string (format "head -n 3 \"%s\"" (buffer-file-name) (erase-buffer) (insert new-doc)) (org-open-file (org-html-export-to-html))) #+END_SRC Josh writes: > Thanks! This is very helpful. > > I have a related question. How can I run an external program right before > Export > that takes as input the current buffer and prints out to stdout an updated > version of the org file that then is exported? Basically I want to pipe the > org > file through a filter that is an external program before it is exported. > > Thanks in advance! > > Josh > >> On Sunday, 10 Mar 2019 at 15:37, Josh wrote: >>> Hi, >>> >>> I am new to emacs and orgmode. I spent the last couple days reading most >>> of the docs before diving in, but I didn't see anywhere how I could have a >>> macro that instead of replacing the macro with lisp code, calls an >>> external program instead. >>> >>> Something like: >>> >>> #+MACRO: func call /home/josh/mybinary $1 >> >> You could maybe do something along the lines of >> >> #+macro: func (eval (shell-command (concat "/home/josh/mybinary " "$1"))) >> >> (untested). >> >> -- >> Eric S Fraga via Emacs 27.0.50, Org release_9.2.2-249-g51444a >> -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu
Re: [O] Macro that calls external program
Thanks Ken. Yes, at first I was trying to accomplish my task with Macros, but after finding out that I could run the whole Org file through a pre-filter, I realized that this would be a much cleaner and easier way rather than having multiple types of macros or code blocks. So now I'm trying to figure out how to attach an external program to `org-export-before-parsing-hook' or `org-export-before-processing-hook' to pipe the entire Org file through... Josh On Mon, 11 Mar 2019, Ken Mankoff wrote: Hi Josh, On 2019-03-10 at 23:37 +0100, Josh wrote... I am new to emacs and orgmode. I spent the last couple days reading most of the docs before diving in, Welcome! but I didn't see anywhere how I could have a macro that instead of replacing the macro with lisp code, calls an external program instead. Something like: #+MACRO: func call /home/josh/mybinary $1 {{{func(Text Argument)}}} and this would be setup to call an external program and the output of the program would replace the macro on export. /home/josh/mybinary "Text Argument" I do wonder if you're asking an XY problem, especially after reading your follow-up question about running an entire Org file through a pre-filter. Why does it have to be a macro that you call? Why not #+NAME:'d Babel code block, which can (presumably) run any program you want. -k.
Re: [O] Macro that calls external program
Hi Josh, On 2019-03-10 at 23:37 +0100, Josh wrote... > I am new to emacs and orgmode. I spent the last couple days reading > most of the docs before diving in, Welcome! > but I didn't see anywhere how I could have a macro that instead of > replacing the macro with lisp code, calls an external program instead. > > Something like: > #+MACRO: func call /home/josh/mybinary $1 > > {{{func(Text Argument)}}} > > and this would be setup to call an external program and the output of > the program would replace the macro on export. > > /home/josh/mybinary "Text Argument" I do wonder if you're asking an XY problem, especially after reading your follow-up question about running an entire Org file through a pre-filter. Why does it have to be a macro that you call? Why not #+NAME:'d Babel code block, which can (presumably) run any program you want. -k.
Re: [O] Macro that calls external program
Josh writes: > Thanks! This is very helpful. > > I have a related question. How can I run an external program right > before Export that takes as input the current buffer and prints out to > stdout an updated version of the org file that then is exported? > Basically I want to pipe the org file through a filter that is an > external program before it is exported. Probably one of `org-export-before-parsing-hook' or `org-export-before-processing-hook' is where you'd hang a custom function that does this.
Re: [O] Macro that calls external program
Thanks! This is very helpful. I have a related question. How can I run an external program right before Export that takes as input the current buffer and prints out to stdout an updated version of the org file that then is exported? Basically I want to pipe the org file through a filter that is an external program before it is exported. Thanks in advance! Josh On Sunday, 10 Mar 2019 at 15:37, Josh wrote: Hi, I am new to emacs and orgmode. I spent the last couple days reading most of the docs before diving in, but I didn't see anywhere how I could have a macro that instead of replacing the macro with lisp code, calls an external program instead. Something like: #+MACRO: func call /home/josh/mybinary $1 You could maybe do something along the lines of #+macro: func (eval (shell-command (concat "/home/josh/mybinary " "$1"))) (untested). -- Eric S Fraga via Emacs 27.0.50, Org release_9.2.2-249-g51444a
Re: [O] Macro that calls external program
On Sunday, 10 Mar 2019 at 15:37, Josh wrote: > Hi, > > I am new to emacs and orgmode. I spent the last couple days reading most > of the docs before diving in, but I didn't see anywhere how I could have a > macro that instead of replacing the macro with lisp code, calls an > external program instead. > > Something like: > > #+MACRO: func call /home/josh/mybinary $1 You could maybe do something along the lines of #+macro: func (eval (shell-command (concat "/home/josh/mybinary " "$1"))) (untested). -- Eric S Fraga via Emacs 27.0.50, Org release_9.2.2-249-g51444a
[O] Macro that calls external program
Hi, I am new to emacs and orgmode. I spent the last couple days reading most of the docs before diving in, but I didn't see anywhere how I could have a macro that instead of replacing the macro with lisp code, calls an external program instead. Something like: #+MACRO: func call /home/josh/mybinary $1 {{{func(Text Argument)}}} and this would be setup to call an external program and the output of the program would replace the macro on export. /home/josh/mybinary "Text Argument" Thanks! Josh