help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Executing bash bash script from emacs / elisp


From: Pascal J. Bourguignon
Subject: Re: Executing bash bash script from emacs / elisp
Date: Wed, 08 Dec 2010 15:27:19 -0000
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux)

Rainer M Krug <R.M.Krug@gmail.com> writes:
> I am a complete beginner concerning elisp - so please bear with me if
> this is a simple question.
>
> I would like to execute a shell (bash) script from elisp, which is then
> called from org-babel to do some post-processing of the result of
> tangling. Tangling in org-babel has a hook for post-processing, and I
> know how to set it. Therefore I am simply looking for a way of executing
> my shell script from that hook.
>
> essentially:
>
> this-function-executes-a-shell-script(The_Shell_Script.sh)

The problem is that hook functions are called with no argument, and
should modify the environment (the current buffer or whatever else
they want to modify).

Another problem is that buffers are more than just a sequence of
character: there are text annotation, properties, markers, etc.

In any case the scheme would be to write a hook function that would
gather all the information you want to send to the script, and to
serialize it into a temporary file or a temporary buffer, and to run
the shell script.  Then collect the output of the shell script, and
deserialize it into modifications to the environment.


Hooks in org-babel-post-tangle-hook are called on a temporary buffer,
assuming you only want to process the characters and replace the
contents of that temporary buffer, you could use
shell-command-on-region to filter them.


(require 'cl)

(defun wrap-hook (shell-script)
  (lexical-let ((shell-script shell-script))
    (lambda ()
        (shell-command-on-region (point-min) (point-max)
                                 shell-script
                                 t t "*errors*" t))))

(add-hook -example-hook  (wrap-hook "ls"))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]