emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Automatically adding local variables to tangled file


From: Rainer M Krug
Subject: Re: [O] Automatically adding local variables to tangled file
Date: Fri, 07 Jun 2013 09:57:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Eric Schulte <address@hidden> 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 buffer
>> 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 (= #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 set
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.

>>> 

[snip (7 lines)]

>>> 
>>> ,----
>>> |  (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)
>>> |    
>>> |    (defun org-babel-mark-file-as-tangled ()
>>> |      (add-file-local-variable 'org-babel-tangled-file t)
>>> |      (basic-save-buffer))
>>> | 
>>> |    (add-hook 'org-babel-post-tangle-hook 'org-babel-mark-file-as-tangled)
>>> `----
>>> 
>
> 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 values.

For the time being, I will add the suggested code to my emacs.org.

>

[snip (19 lines)]

>>> 
>
> 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,
>
>>> 
>>> Cheers,
>>> 
>>> Rainer
>>> 
>>> -- 
>>> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, 
>>> UCT), Dipl. Phys. (Germany)
>>> 
>>> Centre of Excellence for Invasion Biology
>>> Stellenbosch University
>>> South Africa
>>> 
>>> Tel :       +33 - (0)9 53 10 27 44
>>> Cell:       +33 - (0)6 85 62 59 98
>>> Fax :       +33 - (0)9 58 10 27 44
>>> 
>>> Fax (D):    +49 - (0)3 21 21 25 22 44
>>> 
>>> email:      address@hidden
>>> 
>>> Skype:      RMkrug

-- 
Rainer M. Krug

email: RMKrug<at>gmail<dot>com

Attachment: pgpi_Q84TdcwS.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]