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

2013-06-10 Thread Rainer M Krug

Eric Schulte schulte.e...@gmail.com writes:


 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

 I've added a :tangle-mode header argument which may be used to control
 the permissions of tangled files.  See the manual for instructions on
 it's usage.


Thanks a lot. I will try it out today or tomorrow.

Cheers,

Rainer



-- 
Rainer M. Krug

email: RMKrugatgmaildotcom


pgp1GVTMFuQJL.pgp
Description: PGP signature


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

2013-06-08 Thread Eric Schulte

 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

I've added a :tangle-mode header argument which may be used to control
the permissions of tangled files.  See the manual for instructions on
it's usage.

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



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

2013-06-08 Thread Achim Gratz
Eric Schulte writes:
 I've added a :tangle-mode header argument which may be used to control
 the permissions of tangled files.  See the manual for instructions on
 it's usage.

The change in org-babel-read now requires that :shebang values are
quoted.  I've changed the test file accordingly as otherwise the file
couldn't be ingested.  In general I'd suggest that reading header
arguments as eLisp should at be protected against an error propagating
out of the reader function.


Regards,
Achim.
-- 
+[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]+

SD adaptations for KORG EX-800 and Poly-800MkII V0.9:
http://Synth.Stromeko.net/Downloads.html#KorgSDada




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

2013-06-08 Thread Eric Schulte
Achim Gratz strom...@nexgo.de writes:

 Eric Schulte writes:
 I've added a :tangle-mode header argument which may be used to control
 the permissions of tangled files.  See the manual for instructions on
 it's usage.

 The change in org-babel-read now requires that :shebang values are
 quoted.

Oh, I should have realized that shebang values weren't normally quoted.
I've reverted this portion of my tangle-mode patch, so the reader no
longer tries to read #-prefixed strings a elisp.  Hopefully this won't
affect too many people.

 I've changed the test file accordingly as otherwise the file couldn't
 be ingested.  In general I'd suggest that reading header arguments as
 eLisp should at be protected against an error propagating out of the
 reader function.


I think in most cases it would be better to know if an error has
occurred than not, and I think any sort of message output would quickly
be overwritten by the remainder of the code block execution.

Thanks for catching this quickly!



 Regards,
 Achim.

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



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

2013-06-07 Thread Rainer M Krug

Eric Schulte schulte.e...@gmail.com 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:  rai...@krugs.de
 
 Skype:  RMkrug

-- 
Rainer M. Krug

email: RMKrugatgmaildotcom


pgpoOxdr6ijR1.pgp
Description: PGP signature


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

2013-06-07 Thread Rainer M Krug

Rainer M Krug rai...@krugs.de writes:

[snip (54 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.

I stumbled upon one problem, though: I want to mame the tengled file,
when nopened in emacs, to have the minor mode auto-revert-mode. So I did
the following, which obviously did not work:

,
| (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)
| (add-file-local-variable 'buffer-read-only t)
| (add-file-local-variable 'eval: (auto-revert-mode))
| (basic-save-buffer))
|   
|   (add-hook 'org-babel-post-tangle-hook 'org-babel-mark-file-as-tangled)
`

So is tere a way, of adding the line 

,
| eval: (auto-revert-mode)
`

to the file local variables, so that emacs sutomatically enables
auto-revert-mode?

Thanks,

Rainer





[snip (38 lines)]


-- 
Rainer M. Krug

email: RMKrugatgmaildotcom


pgpmtIV7JMOVI.pgp
Description: PGP signature


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

2013-06-06 Thread Sebastien Vauban
Hi Darlan,

Darlan Cavalcante Moreira wrote:
 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.

Waow! That makes a lot of sense, IMHO, if easily overridable with C-x C-q.
Because, people may want to edit the generated file and untangle it once
they've debugged their problem.

But I'd find that a good _default_ state, for trying to avoid errors.

Best regards,
  Seb

-- 
Sebastien Vauban




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

2013-06-06 Thread Eric Schulte
 It's a good idea to have useful information in the tangled file that can
 help these functions. But since org-mode can already tangle with comments
 containing useful information, isn't this enough to detect that the file
 is a tangled file?


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.


 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)

 
 Therefore my question:
 
 Would it be possible and reasonable, to add a local variable to each
 tangled file which identifies the file as an file tangled from an org
 mode file?
 
 He added the following to his config file to test the approach:
 
 ,
 |  (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?

 
 and he also already added automatic redirection to the org mode file
 via org-babel-tangle-jump-to-org to ESS on SVN.
 
 To keep backwards compatibility, a variable
 org-babel-tangle-add-tangled-file-variable could be introduced, which
 can have the following values:
 
 - nil :: (default) do not add anything
 - t :: org-babel-tangled-file is added as t to the tangled files
 - name :: org-babel-tangled-file is set to the org file name
 - path :: org-babel-tangled-file is set to the path of the org file
 - all :: org-babel-tangled-file is set to the full name including path
of the org file
 
 I can even imagine many more possibilities for the use of local file
 variables to store meta data in the tangled file (VCS info comes to
 mind, which would enable one to even go back to older revisions based on
 the tangled code rather easily).
 

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.

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:  rai...@krugs.de
 
 Skype:  RMkrug

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



[O] Automatically adding local variables to tangled file

2013-06-05 Thread Rainer M Krug
Hi 

I am trying to improve my workflow of literate programming of R in
org. My org file is tangled into many R files and I am using ESS to
debug.

If an error occurs, I can jump via ESS to the .R file, and in a second
step via calling org-babel-tangle-jump-to-org into the org file where
the buggy line sits.


Now this is error prone, as one (or is it only me?) is easily tempted to
edit the R file which is reverted after the next tangle.

So I was thinking: what about calling org-babel-tangle-jump-to-org
directly from ESS. Vitalie Spinu looked into this option, and came up with the
following suggestion:

If the tangled .R file contains a local variable, one could easily
identify that it is a tangled file and call org-babel-tangle-jump-to-org
and would be at the line causing the error.

Therefore my question:

Would it be possible and reasonable, to add a local variable to each
tangled file which identifies the file as an file tangled from an org
mode file?

He added the following to his config file to test the approach:

,
|  (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)
`

and he also already added automatic redirection to the org mode file via
org-babel-tangle-jump-to-org to ESS on SVN.

To keep backwards compatibility, a variable
org-babel-tangle-add-tangled-file-variable could be introduced, which
can have the following values:

- nil :: (default) do not add anything
- t :: org-babel-tangled-file is added as t to the tangled files
- name :: org-babel-tangled-file is set to the org file name
- path :: org-babel-tangled-file is set to the path of the org file
- all :: org-babel-tangled-file is set to the full name including path
   of the org file

I can even imagine many more possibilities for the use of local file
variables to store meta data in the tangled file (VCS info comes to
mind, which would enable one to even go back to older revisions based on
the tangled code rather easily).

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:  rai...@krugs.de

Skype:  RMkrug


pgp94EmsPRbEV.pgp
Description: PGP signature


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

2013-06-05 Thread Darlan Cavalcante Moreira

It's a good idea to have useful information in the tangled file that can
help these functions. But since org-mode can already tangle with comments
containing useful information, isn't this enough to detect that the file
is a tangled file?

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.

--
Darlan

At Wed, 05 Jun 2013 16:04:59 +0200,
Rainer M Krug wrote:
 
 Hi 
 
 I am trying to improve my workflow of literate programming of R in
 org. My org file is tangled into many R files and I am using ESS to
 debug.
 
 If an error occurs, I can jump via ESS to the .R file, and in a second
 step via calling org-babel-tangle-jump-to-org into the org file where
 the buggy line sits.
 
 
 Now this is error prone, as one (or is it only me?) is easily tempted to
 edit the R file which is reverted after the next tangle.
 
 So I was thinking: what about calling org-babel-tangle-jump-to-org
 directly from ESS. Vitalie Spinu looked into this option, and came up with the
 following suggestion:
 
 If the tangled .R file contains a local variable, one could easily
 identify that it is a tangled file and call org-babel-tangle-jump-to-org
 and would be at the line causing the error.
 
 Therefore my question:
 
 Would it be possible and reasonable, to add a local variable to each
 tangled file which identifies the file as an file tangled from an org
 mode file?
 
 He added the following to his config file to test the approach:
 
 ,
 |  (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)
 `
 
 and he also already added automatic redirection to the org mode file via
 org-babel-tangle-jump-to-org to ESS on SVN.
 
 To keep backwards compatibility, a variable
 org-babel-tangle-add-tangled-file-variable could be introduced, which
 can have the following values:
 
 - nil :: (default) do not add anything
 - t :: org-babel-tangled-file is added as t to the tangled files
 - name :: org-babel-tangled-file is set to the org file name
 - path :: org-babel-tangled-file is set to the path of the org file
 - all :: org-babel-tangled-file is set to the full name including path
of the org file
 
 I can even imagine many more possibilities for the use of local file
 variables to store meta data in the tangled file (VCS info comes to
 mind, which would enable one to even go back to older revisions based on
 the tangled code rather easily).
 
 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:  rai...@krugs.de
 
 Skype:  RMkrug



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

2013-06-05 Thread Vitalie Spinu


  Darlan Cavalcante Moreira darc...@gmail.com
  on Wed, 05 Jun 2013 11:32:22 -0300 wrote:

  It's a good idea to have useful information in the tangled file that can
  help these functions. But since org-mode can already tangle with comments
  containing useful information, isn't this enough to detect that the file
  is a tangled file?

In principle yes, but it would be nice to avoid searching the whole
buffer for org comments on every step of the debugger. Especially given
that OP's workflow is very specific and most users won't ever need it.

Instead of local variable it might be just a simple comment at bof and a
function org-babel-tangled-file-p to quickly recognize the file.

Vitlaie




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

2013-06-05 Thread Thorsten Jolitz
Rainer M Krug rai...@krugs.de writes:

Hi,

 I am trying to improve my workflow of literate programming of R in
 org. My org file is tangled into many R files and I am using ESS to
 debug.

[...]

 Now this is error prone, as one (or is it only me?) is easily tempted to
 edit the R file which is reverted after the next tangle.

are you aware that literate programming can be done without any tangling
at all now? I had similar issues like you when using literate
programming for organizing my .emacs, and finally figured out its
actually a conceptual problem:

,
| --- Text --- Text with Code --- | --- Code with (Comment) Text --- Code ---
`

If you write a complex text/book with source code examples, literate
programming is just perfect (see e.g. Bernt Hansens Org-mode tutorial).
But if you write code with some comment text, it becomes burdensome.
Although working with interpreted dynamic languages, your workflow with
all that tangling starts to feel similar like working with compiled
languages (with the frequent tangling step replacing the frequent
compilation step).

So, looking at the line above, right from the '|' you really might want
to work in a source code buffer to enjoy all the advantages of Lisps (or
R's) dynamic. Its about programming with some text then, not vice versa.

You can do this with outshine.el and outorg.el (and optionally
navi-mode.el and poporg.el), see the tutorial on Worg
(http://orgmode.org/worg/org-tutorials/org-outside-org.html).

Short example:

Structure your R file like an Org-mode file:

,-
| ## * my-sources.R --- my R Source file
| ##   :PROPERTIES:
| ##   :copyright: my_name
| ##   :copyright-years: 2013
| ##   :version:  0.9
| ##   :created:  21-01-2013
| ##   :licence:  GPL 2 or later (free software)
| ##   :licence-url: http://www.gnu.org/licenses/
| ##   :author:   my_name
| ##   :author_email: my_email AT gamil DOT com
| ##   :inspiration: foo bar
| ##   :keywords: foo bar
| ##   :END:
|
| ## ** Commentary
|
| ## Geometry Object Model from OGC OpenGIS Simple Features Specification for
| ## SQL Revision. 1.1 [...]
|
| ## ** Changes
|
| ## | author  | version | date|
| ## |-+-+-|
| ## | my_name | 0.9 | 2013-06-05 Mi |
|
| ## * code
| ## ** My first R Function
|
| ## simple example function from the manual
| twosam - function(y1, y2) {
|  n1  - length(y1); n2  - length(y2)
|  yb1 - mean(y1);   yb2 - mean(y2)
|  s1  - var(y1);s2  - var(y2)
|  s - ((n1-1)*s1 + (n2-1)*s2)/(n1+n2-2)
|  tst - (yb1 - yb2)/sqrt(s*(1/n1 + 1/n2))
|  tst
|}
|
| ## ** My second R Function
|
| ## another simple example function from the manual
| bslash - function(X, y) {
|X - qr(X)
|qr.coef(X, y)
|  }
|
| ## my-sources.R ends here
`-

With outline-minor-mode and outshine.el activated, you will have all the
structure-editing and outline-navigation commands you are used to from
Org-mode. But you can program in this buffer directly without any
intermediate steps, and send your functions or whatever via ESS to the R
process-buffer.

The literate programming part comes from outorg.el then. With 

,--
| C-c ’
`--

on or inside any header in this file, the subtree at point is offered
for editing in a temporary Org buffer, with all source code enclosed in
source blocks and all comment text uncommented, e.g. 

,--
| ** My first R Function
| 
| simple example function from the manual
| #+begin_src ess
| twosam - function(y1, y2) {
|  n1  - length(y1); n2  - length(y2)
|  yb1 - mean(y1);   yb2 - mean(y2)
|  s1  - var(y1);s2  - var(y2)
|  s - ((n1-1)*s1 + (n2-1)*s2)/(n1+n2-2)
|  tst - (yb1 - yb2)/sqrt(s*(1/n1 + 1/n2))
|  tst
|}
| #+end_src
`--

With 

,--
| C-u C-c '
`--

the whole buffer is converted to Org. 

You can then do your (comment) text editing will full Org-mode
functionality, and since the headlines are converted too, you can export
to any backend or use other Org functions that act on headlines. 

When you are done, just type 

,
| M-#
`

and the temporary Org-mode buffer is killed and all the changes are
applied to the original source code buffer. 

So you really have the lookfeel of Org-mode in your source code
buffers, but without the annoying and error prone tangling. It works
for all kinds of major modes (emacs-lisp, picolisp, ess, and, at least in
theory, all others).

This way the line between Org-mode and source code buffers is blurring
and literate programming becomes more efficient and 

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

2013-06-05 Thread Rainer M Krug
On Wednesday, June 5, 2013, Darlan Cavalcante Moreira wrote:


 It's a good idea to have useful information in the tangled file that can
 help these functions. But since org-mode can already tangle with comments
 containing useful information, isn't this enough to detect that the file
 is a tangled file?


Yes and no. In regards to jumping to the source code, it would necessitate
a searching in the text, but it would be much easier to have it in a file
local variable. This is more standardized then a comment.



 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.


My reasoning - and I would make all tangled R files read only.

Cheers,

Rainer



 --
 Darlan

 At Wed, 05 Jun 2013 16:04:59 +0200,
 Rainer M Krug wrote:
 
  Hi
 
  I am trying to improve my workflow of literate programming of R in
  org. My org file is tangled into many R files and I am using ESS to
  debug.
 
  If an error occurs, I can jump via ESS to the .R file, and in a second
  step via calling org-babel-tangle-jump-to-org into the org file where
  the buggy line sits.
 
 
  Now this is error prone, as one (or is it only me?) is easily tempted to
  edit the R file which is reverted after the next tangle.
 
  So I was thinking: what about calling org-babel-tangle-jump-to-org
  directly from ESS. Vitalie Spinu looked into this option, and came up
 with the
  following suggestion:
 
  If the tangled .R file contains a local variable, one could easily
  identify that it is a tangled file and call org-babel-tangle-jump-to-org
  and would be at the line causing the error.
 
  Therefore my question:
 
  Would it be possible and reasonable, to add a local variable to each
  tangled file which identifies the file as an file tangled from an org
  mode file?
 
  He added the following to his config file to test the approach:
 
  ,
  |  (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)
  `
 
  and he also already added automatic redirection to the org mode file via
  org-babel-tangle-jump-to-org to ESS on SVN.
 
  To keep backwards compatibility, a variable
  org-babel-tangle-add-tangled-file-variable could be introduced, which
  can have the following values:
 
  - nil :: (default) do not add anything
  - t :: org-babel-tangled-file is added as t to the tangled files
  - name :: org-babel-tangled-file is set to the org file name
  - path :: org-babel-tangled-file is set to the path of the org file
  - all :: org-babel-tangled-file is set to the full name including path
 of the org file
 
  I can even imagine many more possibilities for the use of local file
  variables to store meta data in the tangled file (VCS info comes to
  mind, which would enable one to even go back to older revisions based on
  the tangled code rather easily).
 
  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:  rai...@krugs.de javascript:;
 
  Skype:  RMkrug



-- 
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 (F):   +33 - (0)9 58 10 27 44

Fax (D):+49 - (0)3 21 21 25 22 44

email:  rai...@krugs.de

Skype:  RMkrug