From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: [babel] After Tangle Change File Permission Date: Wed, 09 Feb 2011 10:18:19 +0000 Message-ID: References: <4D525B84.9060206@manor-farm.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=45535 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pn789-0008Qb-Gg for emacs-orgmode@gnu.org; Wed, 09 Feb 2011 05:18:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pn785-0003t5-5H for emacs-orgmode@gnu.org; Wed, 09 Feb 2011 05:18:34 -0500 Received: from mail-wy0-f169.google.com ([74.125.82.169]:45923) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pn784-0003sv-Vz for emacs-orgmode@gnu.org; Wed, 09 Feb 2011 05:18:33 -0500 Received: by wyj26 with SMTP id 26so2527wyj.0 for ; Wed, 09 Feb 2011 02:18:32 -0800 (PST) In-Reply-To: <4D525B84.9060206@manor-farm.org> (Ian Barton's message of "Wed, 09 Feb 2011 09:16:52 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: lists@manor-farm.org Cc: Org Mode Mailing List Ian Barton writes: > I am starting to use babel to maintain my collection of shell > scripts. I want to automate the process as much as possible, so I > would like to be able to set the execute bit on my tangled .sh scripts > after the tangle process. > > I see that there is an after-tangle hook. Can anyone give me some > hints as to how I might use this to execute a chmod *.sh on the > directory containing my tangles shell scripts. Hi Ian, It looks like Eric has already implemented this particular case in a different way: if the :shebang header arg is set, then the file will be made executable. E.g. :shebang #!/bin/bash. However, to use the hook function, does something like this not work? #+begin_src emacs-lisp (defun dan/make-tangled-shell-files-executable () (shell-command "chmod +x *.sh")) (add-hook 'org-babel-post-tangle-hook 'dan/make-tangled-shell-files-executable) #+end_src I admit I was getting some inconsistent results just then that I didn't understand. It should be possible to use #+begin_src emacs-lisp (add-hook 'org-babel-post-tangle-hook 'dan/make-tangled-shell-files-executable nil 'local) #+end_src so that the hook is set locally for the buffer in question. The code is #+begin_src emacs-lisp (when org-babel-post-tangle-hook (mapc (lambda (file) (org-babel-with-temp-filebuffer file (run-hooks 'org-babel-post-tangle-hook))) path-collector)) #+end_src , where `path-collector' is a list of tangled files. I believe that this implies that, each time the hook is run, default-directory will be equal to the directory containing the file in question, so the shell-command should run in that directory. Otoh, the above shows that the hook is run for each tangled file, so chmod +x *.sh would be executed more times than necessary. Dan > > Ian. > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode