emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Macro that calls external program
@ 2019-03-10 22:37 Josh
  2019-03-11  7:46 ` Eric S Fraga
  2019-03-11 19:24 ` Ken Mankoff
  0 siblings, 2 replies; 7+ messages in thread
From: Josh @ 2019-03-10 22:37 UTC (permalink / raw)
  To: emacs-orgmode

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

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

* Re: Macro that calls external program
  2019-03-10 22:37 Macro that calls external program Josh
@ 2019-03-11  7:46 ` Eric S Fraga
  2019-03-11 11:19   ` Josh
  2019-03-11 19:24 ` Ken Mankoff
  1 sibling, 1 reply; 7+ messages in thread
From: Eric S Fraga @ 2019-03-11  7:46 UTC (permalink / raw)
  To: Josh; +Cc: emacs-orgmode

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

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

* Re: Macro that calls external program
  2019-03-11  7:46 ` Eric S Fraga
@ 2019-03-11 11:19   ` Josh
  2019-03-11 19:03     ` Eric Abrahamsen
  2019-03-11 20:48     ` John Kitchin
  0 siblings, 2 replies; 7+ messages in thread
From: Josh @ 2019-03-11 11:19 UTC (permalink / raw)
  Cc: emacs-orgmode

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
>

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

* Re: Macro that calls external program
  2019-03-11 19:24 ` Ken Mankoff
@ 2019-03-11 13:28   ` Josh
  0 siblings, 0 replies; 7+ messages in thread
From: Josh @ 2019-03-11 13:28 UTC (permalink / raw)
  To: emacs-orgmode

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 <jnfo-d@grauman.com> 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.
>

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

* Re: Macro that calls external program
  2019-03-11 11:19   ` Josh
@ 2019-03-11 19:03     ` Eric Abrahamsen
  2019-03-11 20:48     ` John Kitchin
  1 sibling, 0 replies; 7+ messages in thread
From: Eric Abrahamsen @ 2019-03-11 19:03 UTC (permalink / raw)
  To: emacs-orgmode

Josh <jnfo-d@grauman.com> 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.

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

* Re: Macro that calls external program
  2019-03-10 22:37 Macro that calls external program Josh
  2019-03-11  7:46 ` Eric S Fraga
@ 2019-03-11 19:24 ` Ken Mankoff
  2019-03-11 13:28   ` Josh
  1 sibling, 1 reply; 7+ messages in thread
From: Ken Mankoff @ 2019-03-11 19:24 UTC (permalink / raw)
  To: Josh; +Cc: emacs-orgmode

Hi Josh,

On 2019-03-10 at 23:37 +0100, Josh <jnfo-d@grauman.com> 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.

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

* Re: Macro that calls external program
  2019-03-11 11:19   ` Josh
  2019-03-11 19:03     ` Eric Abrahamsen
@ 2019-03-11 20:48     ` John Kitchin
  1 sibling, 0 replies; 7+ messages in thread
From: John Kitchin @ 2019-03-11 20:48 UTC (permalink / raw)
  To: Josh; +Cc: emacs-orgmode

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 <jnfo-d@grauman.com> 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

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

end of thread, other threads:[~2019-03-11 20:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-10 22:37 Macro that calls external program Josh
2019-03-11  7:46 ` Eric S Fraga
2019-03-11 11:19   ` Josh
2019-03-11 19:03     ` Eric Abrahamsen
2019-03-11 20:48     ` John Kitchin
2019-03-11 19:24 ` Ken Mankoff
2019-03-11 13:28   ` Josh

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