[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Orgmode] Re: [babel] After Tangle Change File Permission
From: |
Eric Schulte |
Subject: |
Re: [Orgmode] Re: [babel] After Tangle Change File Permission |
Date: |
Wed, 09 Feb 2011 18:10:24 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Dan Davison <address@hidden> writes:
> Ian Barton <address@hidden> 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.
>
True this is probably the easiest way.
>
> 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
>
The org-babel-post-tangle-hook is evaluated in the tangled file, so the
following should work as well...
#+begin_src emacs-lisp
(defun eric/make-tangled-files-executable ()
(set-file-modes (buffer-file-name) #o755))
(add-hook 'org-babel-post-tangle-hook 'eric/make-tangled-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,
true
> 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.
>
yes, I think the solution above should be a little bit more efficient.
Cheers -- Eric
>
> Dan
>
>>
>> Ian.
>>
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> address@hidden
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> address@hidden
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode