emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] After Tangle Change File Permission
@ 2011-02-09  9:16 Ian Barton
  2011-02-09  9:57 ` Rainer M Krug
  2011-02-09 10:18 ` Dan Davison
  0 siblings, 2 replies; 4+ messages in thread
From: Ian Barton @ 2011-02-09  9:16 UTC (permalink / raw)
  To: Org Mode Mailing List

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.

Ian.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [babel] After Tangle Change File Permission
  2011-02-09  9:16 [babel] After Tangle Change File Permission Ian Barton
@ 2011-02-09  9:57 ` Rainer M Krug
  2011-02-09 10:18 ` Dan Davison
  1 sibling, 0 replies; 4+ messages in thread
From: Rainer M Krug @ 2011-02-09  9:57 UTC (permalink / raw)
  To: lists; +Cc: Org Mode Mailing List

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/09/2011 10:16 AM, Ian Barton wrote:
> 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.

Below an example how I use this:
1) I create a postTangleScript.sh, which I want to execute after
tangling. In this script, I put all the things I want to do.
2) I set the post-tangle-hook, so that the script is executed.
3) if you want to have the name of the tangled file automatically in
your post tangle script, you can use variables (but don't ask me how to
get the name of the tangled file)

Hope this helps,

Rainer


* Internal configurations
:noexport:
** Post tangle script
#+begin_src sh :tangle postTangleScript.sh :var
BUFFERFILENAME=(buffer-file-name)
  # do whatever
#+end_src

** Evaluate to run post tangle script
#+begin_src emacs-lisp :results silent :tangle no :exports none
  (add-hook 'org-babel-post-tangle-hook
            (
             lambda ()
                    (call-process-shell-command "./postTangleScript.sh"
nil 0 nil)
                    )
            )
#+end_src

> 
> 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


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:        +33 - (0)9 53 10 27 44
Cell:       +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1SZP0ACgkQoYgNqgF2egogZACeK/GohKqClBenIaVsvqSboC/f
bX4AnA8+lCDUON76x7hFVAGTbmJv9zIA
=WgSG
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [babel] After Tangle Change File Permission
  2011-02-09  9:16 [babel] After Tangle Change File Permission Ian Barton
  2011-02-09  9:57 ` Rainer M Krug
@ 2011-02-09 10:18 ` Dan Davison
  2011-02-10  1:10   ` Eric Schulte
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Davison @ 2011-02-09 10:18 UTC (permalink / raw)
  To: lists; +Cc: Org Mode Mailing List

Ian Barton <lists@manor-farm.org> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [babel] After Tangle Change File Permission
  2011-02-09 10:18 ` Dan Davison
@ 2011-02-10  1:10   ` Eric Schulte
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2011-02-10  1:10 UTC (permalink / raw)
  To: Dan Davison; +Cc: Org Mode Mailing List

Dan Davison <dandavison7@gmail.com> writes:

> Ian Barton <lists@manor-farm.org> 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.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
> _______________________________________________
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-10  1:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-09  9:16 [babel] After Tangle Change File Permission Ian Barton
2011-02-09  9:57 ` Rainer M Krug
2011-02-09 10:18 ` Dan Davison
2011-02-10  1:10   ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).