From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Executing bash bash script from emacs / elisp Date: Fri, 03 Sep 2010 14:03:21 +0200 Organization: Informatimago Message-ID: <87fwxrhw52.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291866322 32364 80.91.229.12 (9 Dec 2010 03:45:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 03:45:22 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 04:45:17 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQXRU-0004lm-4E for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 04:45:16 +0100 Original-Received: from localhost ([127.0.0.1]:50319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQXRT-0003nH-JV for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 22:45:15 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 48 Original-X-Trace: individual.net 3LvCcjRqCsaPPaCL5g4ITAXivdTowfmr8CcOnXxd5Pj2ZHgs05 Cancel-Lock: sha1:ZDhjMDFhZTdkNjg0ODAyYjM2OGQxNTI5MDIxNzZlODE5ZDhjNWYwYg== sha1:GlH64pBHchgq6PkGnIc5HlnG4SE= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.2 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:181106 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:76573 Archived-At: Rainer M Krug 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/