From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: Automatically adding local variables to tangled file Date: Fri, 07 Jun 2013 09:57:13 +0200 Message-ID: <87ehcewdye.fsf@krugs.de> References: <878v2omz5g.fsf@krugs.de> <51af4bfd.0c95ec0a.2372.097e@mx.google.com> <87ehcf6xey.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkrYL-00010N-UQ for emacs-orgmode@gnu.org; Fri, 07 Jun 2013 03:57:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkrYH-0001yI-Hf for emacs-orgmode@gnu.org; Fri, 07 Jun 2013 03:57:41 -0400 Received: from plane.gmane.org ([80.91.229.3]:59859) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkrYH-0001xx-7L for emacs-orgmode@gnu.org; Fri, 07 Jun 2013 03:57:37 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UkrYA-0003dv-Kv for emacs-orgmode@gnu.org; Fri, 07 Jun 2013 09:57:30 +0200 Received: from arn78-1-88-186-171-7.fbx.proxad.net ([88.186.171.7]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 07 Jun 2013 09:57:30 +0200 Received: from Rainer by arn78-1-88-186-171-7.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 07 Jun 2013 09:57:30 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Eric Schulte writes: [snip (4 lines)] >> > > I personally prefer the solution shown below of adding a file-local > variable using the post-tangle hook. As mentioned previously this makes > the detection of tangled code much faster, simpler and less error prone > than grepping the file for comments. > +1 >> >> On the other hand, a local variable in the tangled files to set the buff= er >> to read-only could be very useful to avoid the mistake of editing the >> tangled files directly. >> > > We already set the permission of tangled files to be executable when > they include a shebang line. Perhaps we could add an option (or change > the default) to set the permissions of tangled files to be read only. > > Perhaps this could be done using the post-tangle hook with something > like the following. > > ;; -*- emacs-lisp -*- > (defun org-babel-mark-tangled-as-read-only () > "Mark the current file read only. > If it is executable keep it executable." > (if (=3D #o755 (file-modes (buffer-file-name))) > (set-file-modes (buffer-file-name) #o555) > (set-file-modes (buffer-file-name) #o444))) > > (add-hook 'org-babel-post-tangle-hook 'org-babel-mark-tangled-as-read= -only) > I think that would be a good idea to add this in a way so that it is controled by a variable - if the variable is t, all tangled files will be s= et read-only, if it is nil, none will. It might be useful to also allow string / list of strings, which then would individual file names which could be set as read-only. I would leave the default as it is to guarantee backward compatibility, although I agree that the org file is the source, and the tangled file should not be changed. For the time being, I will just add this code above to my emacs.org. >>>=20 [snip (7 lines)] >>>=20 >>> ,---- >>> | (defvar org-babel-tangled-file nil >>> | "If non-nill, current file was tangled with org-babel-tangle") >>> | (put 'org-babel-tangled-file 'safe-local-variable 'booleanp) >>> |=20=20=20=20 >>> | (defun org-babel-mark-file-as-tangled () >>> | (add-file-local-variable 'org-babel-tangled-file t) >>> | (basic-save-buffer)) >>> |=20 >>> | (add-hook 'org-babel-post-tangle-hook 'org-babel-mark-file-as-tang= led) >>> `---- >>>=20 > > I think the above code should be considered an implementation rather > than simply a test. This is exactly what the post-tangle hook is > intended to support. Is there a motivating reason for this behavior to > be "built in"? As pointed out, I think the possibility to easily add local variables to the tangled file, will be valuable. I would opt for an the buil-in option, as this could e.g. be used to set the file read-only in emacs, adding svn information, etc. This could be achieved by supplying one variable containing strings, which contains the names of the local variables to be added and their value= s. For the time being, I will add the suggested code to my emacs.org. > [snip (19 lines)] >>>=20 > > I agree that local-file variables show much promise, although I think > (at least for now) the best way to set such variables is through the > post-tangle-hook as Vitalie has already done. Ok - I'll stick to the solutions outlined above for now. Thanks a lot everybody, Rainer > > Best, > >>>=20 >>> Cheers, >>>=20 >>> Rainer >>>=20 >>> --=20 >>> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biol= ogy, UCT), Dipl. Phys. (Germany) >>>=20 >>> Centre of Excellence for Invasion Biology >>> Stellenbosch University >>> South Africa >>>=20 >>> Tel : +33 - (0)9 53 10 27 44 >>> Cell: +33 - (0)6 85 62 59 98 >>> Fax : +33 - (0)9 58 10 27 44 >>>=20 >>> Fax (D): +49 - (0)3 21 21 25 22 44 >>>=20 >>> email: Rainer@krugs.de >>>=20 >>> Skype: RMkrug =2D-=20 Rainer M. Krug email: RMKruggmailcom --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iQEcBAEBAgAGBQJRsZJbAAoJENvXNx4PUvmC/XwH/2DFkPPtpvpa01DJ6Sr30+9B h7g5Xh1MH9r0ILqkdgn3w1a2GgnWA/Y63bJ/N+8tiKeR6QWW/ACsURYqF/bLx05b osuH+JxHE+2dAalUnPiTumBo+nDRXLCtuuNm8r1zDEqniTPK5p6peTBzXhCIjpvv 1LUAkXAzICp8i/BX075+Gfai1ecASi6PtZqSXk6Tx0HUBYlFdqHr0Wk0HAUkessf h5zk8rIgsBwXJlb4n/bsemZQgaqELRvwZjB2+E+0cY04/dMzDqaSOv35AooSBte+ 1Jxh/c1kH+MpbjNRMvmTpp2ICP12jvT4ByjvjomlRzKOUZ7YDbxWtf788mCFs6w= =wiGw -----END PGP SIGNATURE----- --=-=-=--