From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Macro that calls external program Date: Mon, 11 Mar 2019 16:48:10 -0400 Message-ID: References: <87pnqxsvir.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([209.51.188.92]:51389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3RqO-0005c5-AB for emacs-orgmode@gnu.org; Mon, 11 Mar 2019 16:48:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3RqN-0004Du-Ak for emacs-orgmode@gnu.org; Mon, 11 Mar 2019 16:48:20 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:42506) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3RqN-0004DP-2c for emacs-orgmode@gnu.org; Mon, 11 Mar 2019 16:48:19 -0400 Received: by mail-qt1-x82d.google.com with SMTP id u7so132680qtg.9 for ; Mon, 11 Mar 2019 13:48:18 -0700 (PDT) In-reply-to: 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: Josh Cc: emacs-orgmode@gnu.org 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