* Automatically adding local variables to tangled file @ 2013-06-05 14:04 Rainer M Krug 2013-06-05 14:32 ` Darlan Cavalcante Moreira 2013-06-05 17:10 ` Thorsten Jolitz 0 siblings, 2 replies; 25+ messages in thread From: Rainer M Krug @ 2013-06-05 14:04 UTC (permalink / raw) To: Eric Schulte; +Cc: Vitalie Spinu, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 2768 bytes --] 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: Rainer@krugs.de Skype: RMkrug [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-05 14:04 Automatically adding local variables to tangled file Rainer M Krug @ 2013-06-05 14:32 ` Darlan Cavalcante Moreira 2013-06-05 15:41 ` Vitalie Spinu ` (3 more replies) 2013-06-05 17:10 ` Thorsten Jolitz 1 sibling, 4 replies; 25+ messages in thread From: Darlan Cavalcante Moreira @ 2013-06-05 14:32 UTC (permalink / raw) To: Rainer M Krug; +Cc: Vitalie Spinu, emacs-orgmode, 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? 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: Rainer@krugs.de > > Skype: RMkrug ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-05 14:32 ` Darlan Cavalcante Moreira @ 2013-06-05 15:41 ` Vitalie Spinu 2013-06-05 16:15 ` Rainer M Krug ` (2 subsequent siblings) 3 siblings, 0 replies; 25+ messages in thread From: Vitalie Spinu @ 2013-06-05 15:41 UTC (permalink / raw) To: emacs-orgmode >> Darlan Cavalcante Moreira <darcamo@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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-05 14:32 ` Darlan Cavalcante Moreira 2013-06-05 15:41 ` Vitalie Spinu @ 2013-06-05 16:15 ` Rainer M Krug 2013-06-06 7:53 ` Sebastien Vauban 2013-06-06 16:01 ` Eric Schulte 3 siblings, 0 replies; 25+ messages in thread From: Rainer M Krug @ 2013-06-05 16:15 UTC (permalink / raw) To: Darlan Cavalcante Moreira Cc: emacs-orgmode, Rainer M Krug, Vitalie Spinu, Eric Schulte [-- Attachment #1: Type: text/plain, Size: 4258 bytes --] 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: Rainer@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: Rainer@krugs.de Skype: RMkrug [-- Attachment #2: Type: text/html, Size: 5534 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-05 14:32 ` Darlan Cavalcante Moreira 2013-06-05 15:41 ` Vitalie Spinu 2013-06-05 16:15 ` Rainer M Krug @ 2013-06-06 7:53 ` Sebastien Vauban 2013-06-06 16:01 ` Eric Schulte 3 siblings, 0 replies; 25+ messages in thread From: Sebastien Vauban @ 2013-06-06 7:53 UTC (permalink / raw) To: emacs-orgmode-mXXj517/zsQ 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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-05 14:32 ` Darlan Cavalcante Moreira ` (2 preceding siblings ...) 2013-06-06 7:53 ` Sebastien Vauban @ 2013-06-06 16:01 ` Eric Schulte 2013-06-07 7:57 ` Rainer M Krug 2013-06-10 11:32 ` SOLVED: Automatically adding local variables to tangled file Rainer M Krug 3 siblings, 2 replies; 25+ messages in thread From: Eric Schulte @ 2013-06-06 16:01 UTC (permalink / raw) To: Darlan Cavalcante Moreira; +Cc: Rainer M Krug, emacs-orgmode, Vitalie Spinu > 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: Rainer@krugs.de >> >> Skype: RMkrug -- Eric Schulte http://cs.unm.edu/~eschulte ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-06 16:01 ` Eric Schulte @ 2013-06-07 7:57 ` Rainer M Krug 2013-06-07 8:32 ` Rainer M Krug 2013-06-08 18:23 ` Automatically adding local variables to tangled file Eric Schulte 2013-06-10 11:32 ` SOLVED: Automatically adding local variables to tangled file Rainer M Krug 1 sibling, 2 replies; 25+ messages in thread From: Rainer M Krug @ 2013-06-07 7:57 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 3967 bytes --] Eric Schulte <schulte.eric@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: Rainer@krugs.de >>> >>> Skype: RMkrug -- Rainer M. Krug email: RMKrug<at>gmail<dot>com [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-07 7:57 ` Rainer M Krug @ 2013-06-07 8:32 ` Rainer M Krug 2013-06-07 10:57 ` [PATCH] Don't ask "File changed on disk" in org-babel-post-tangle-hook Vitalie Spinu 2013-06-08 18:23 ` Automatically adding local variables to tangled file Eric Schulte 1 sibling, 1 reply; 25+ messages in thread From: Rainer M Krug @ 2013-06-07 8:32 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 2272 bytes --] Rainer M Krug <Rainer@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: RMKrug<at>gmail<dot>com [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH] Don't ask "File changed on disk" in org-babel-post-tangle-hook 2013-06-07 8:32 ` Rainer M Krug @ 2013-06-07 10:57 ` Vitalie Spinu 2013-06-07 13:23 ` Eric Schulte 0 siblings, 1 reply; 25+ messages in thread From: Vitalie Spinu @ 2013-06-07 10:57 UTC (permalink / raw) To: Rainer M Krug; +Cc: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 531 bytes --] The problem with org-babel-post-tangle-hook is that user is always asked yes-or-no-p for file reversion. Calling auto revert (as Rainer tried) will not help. The problem is in find-file-noselect in org-babel-find-file-noselect-refresh. The following patch fixes it by silencing find-file-noselect. Besides reversion question, there are a couple of other warning/questions that are silenced, but given that org-babel-find-file-noselect-refresh is used only for reverting tangled files, this is probably not an issue. Vitalie [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-avoid-file-warnings-in-org-babel-post-tangle-hook.patch --] [-- Type: text/x-diff, Size: 941 bytes --] From 2f408019b940c7e3b742dd2941f725f97645b868 Mon Sep 17 00:00:00 2001 From: Vitalie Spinu <spinuvit@gmail.com> Date: Fri, 7 Jun 2013 12:43:55 +0200 Subject: [PATCH] avoid file warnings in org-babel-post-tangle-hook * lisp/ob-tangle.el (org-babel-find-file-noselect-refresh): call find-file-noselect with 'nowarn argument to surpress yes-or-no-p reversion message. --- lisp/ob-tangle.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 95d518a..82f2c10 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -114,7 +114,7 @@ result. The default value is `org-babel-trim'." (defun org-babel-find-file-noselect-refresh (file) "Find file ensuring that the latest changes on disk are represented in the file." - (find-file-noselect file) + (find-file-noselect file 'nowarn) (with-current-buffer (get-file-buffer file) (revert-buffer t t t))) -- 1.8.1.2 [-- Attachment #3: Type: text/plain, Size: 2376 bytes --] >> Rainer M Krug <Rainer@krugs.de> >> on Fri, 07 Jun 2013 10:32:19 +0200 wrote: > Rainer M Krug <Rainer@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)] ^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH] Don't ask "File changed on disk" in org-babel-post-tangle-hook 2013-06-07 10:57 ` [PATCH] Don't ask "File changed on disk" in org-babel-post-tangle-hook Vitalie Spinu @ 2013-06-07 13:23 ` Eric Schulte 2013-06-07 13:47 ` Rainer M Krug 0 siblings, 1 reply; 25+ messages in thread From: Eric Schulte @ 2013-06-07 13:23 UTC (permalink / raw) To: Vitalie Spinu; +Cc: Rainer M Krug, emacs-orgmode Vitalie Spinu <spinuvit@gmail.com> writes: > The problem with org-babel-post-tangle-hook is that user is always asked > yes-or-no-p for file reversion. Calling auto revert (as Rainer tried) > will not help. > > The problem is in find-file-noselect in org-babel-find-file-noselect-refresh. > > The following patch fixes it by silencing find-file-noselect. Besides > reversion question, there are a couple of other warning/questions that > are silenced, but given that org-babel-find-file-noselect-refresh is > used only for reverting tangled files, this is probably not an issue. > Applied. Thanks, > > Vitalie > > > From 2f408019b940c7e3b742dd2941f725f97645b868 Mon Sep 17 00:00:00 2001 > From: Vitalie Spinu <spinuvit@gmail.com> > Date: Fri, 7 Jun 2013 12:43:55 +0200 > Subject: [PATCH] avoid file warnings in org-babel-post-tangle-hook > > * lisp/ob-tangle.el (org-babel-find-file-noselect-refresh): call > find-file-noselect with 'nowarn argument to surpress yes-or-no-p > reversion message. > --- > lisp/ob-tangle.el | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el > index 95d518a..82f2c10 100644 > --- a/lisp/ob-tangle.el > +++ b/lisp/ob-tangle.el > @@ -114,7 +114,7 @@ result. The default value is `org-babel-trim'." > (defun org-babel-find-file-noselect-refresh (file) > "Find file ensuring that the latest changes on disk are > represented in the file." > - (find-file-noselect file) > + (find-file-noselect file 'nowarn) > (with-current-buffer (get-file-buffer file) > (revert-buffer t t t))) -- Eric Schulte http://cs.unm.edu/~eschulte ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH] Don't ask "File changed on disk" in org-babel-post-tangle-hook 2013-06-07 13:23 ` Eric Schulte @ 2013-06-07 13:47 ` Rainer M Krug 0 siblings, 0 replies; 25+ messages in thread From: Rainer M Krug @ 2013-06-07 13:47 UTC (permalink / raw) To: Eric Schulte; +Cc: Vitalie Spinu, emacs-orgmode Eric Schulte <schulte.eric@gmail.com> writes: > Vitalie Spinu <spinuvit@gmail.com> writes: > >> The problem with org-babel-post-tangle-hook is that user is always asked >> yes-or-no-p for file reversion. Calling auto revert (as Rainer tried) >> will not help. >> >> The problem is in find-file-noselect in org-babel-find-file-noselect-refresh. >> >> The following patch fixes it by silencing find-file-noselect. Besides >> reversion question, there are a couple of other warning/questions that >> are silenced, but given that org-babel-find-file-noselect-refresh is >> used only for reverting tangled files, this is probably not an issue. >> > > Applied. Thanks, Thanks a lot. Will update then and try later. Thanks, Rainer > >> >> Vitalie >> >> >> From 2f408019b940c7e3b742dd2941f725f97645b868 Mon Sep 17 00:00:00 2001 >> From: Vitalie Spinu <spinuvit@gmail.com> >> Date: Fri, 7 Jun 2013 12:43:55 +0200 >> Subject: [PATCH] avoid file warnings in org-babel-post-tangle-hook >> >> * lisp/ob-tangle.el (org-babel-find-file-noselect-refresh): call >> find-file-noselect with 'nowarn argument to surpress yes-or-no-p >> reversion message. >> --- >> lisp/ob-tangle.el | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el >> index 95d518a..82f2c10 100644 >> --- a/lisp/ob-tangle.el >> +++ b/lisp/ob-tangle.el >> @@ -114,7 +114,7 @@ result. The default value is `org-babel-trim'." >> (defun org-babel-find-file-noselect-refresh (file) >> "Find file ensuring that the latest changes on disk are >> represented in the file." >> - (find-file-noselect file) >> + (find-file-noselect file 'nowarn) >> (with-current-buffer (get-file-buffer file) >> (revert-buffer t t t))) <#secure method=pgpmime mode=sign> -- 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: Rainer@krugs.de Skype: RMkrug ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-07 7:57 ` Rainer M Krug 2013-06-07 8:32 ` Rainer M Krug @ 2013-06-08 18:23 ` Eric Schulte 2013-06-08 20:59 ` Achim Gratz 2013-06-10 8:02 ` Rainer M Krug 1 sibling, 2 replies; 25+ messages in thread From: Eric Schulte @ 2013-06-08 18:23 UTC (permalink / raw) To: Rainer M Krug; +Cc: emacs-orgmode >> >> 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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-08 18:23 ` Automatically adding local variables to tangled file Eric Schulte @ 2013-06-08 20:59 ` Achim Gratz 2013-06-08 21:17 ` Eric Schulte 2013-06-10 8:02 ` Rainer M Krug 1 sibling, 1 reply; 25+ messages in thread From: Achim Gratz @ 2013-06-08 20:59 UTC (permalink / raw) To: emacs-orgmode 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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-08 20:59 ` Achim Gratz @ 2013-06-08 21:17 ` Eric Schulte 0 siblings, 0 replies; 25+ messages in thread From: Eric Schulte @ 2013-06-08 21:17 UTC (permalink / raw) To: Achim Gratz; +Cc: emacs-orgmode Achim Gratz <Stromeko@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 ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-08 18:23 ` Automatically adding local variables to tangled file Eric Schulte 2013-06-08 20:59 ` Achim Gratz @ 2013-06-10 8:02 ` Rainer M Krug 2013-06-10 10:12 ` Problem in tangle-mode -- WAS: " Rainer M Krug 1 sibling, 1 reply; 25+ messages in thread From: Rainer M Krug @ 2013-06-10 8:02 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1248 bytes --] Eric Schulte <schulte.eric@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: RMKrug<at>gmail<dot>com [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* Problem in tangle-mode -- WAS: Automatically adding local variables to tangled file 2013-06-10 8:02 ` Rainer M Krug @ 2013-06-10 10:12 ` Rainer M Krug 2013-06-10 15:58 ` Eric Schulte 0 siblings, 1 reply; 25+ messages in thread From: Rainer M Krug @ 2013-06-10 10:12 UTC (permalink / raw) To: Eric Schulte; +Cc: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 2479 bytes --] Rainer M Krug <Rainer@krugs.de> writes: > Eric Schulte <schulte.eric@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. I did, and there is a problem with tangling multiple blocks into a single file: The following does not work: ,---- | #+PROPERTY: tangle-mode (identity #o444) | #+PROPERTY: tangle ./tools.R | * Two blocks | Block 1 | #+begin_src R | suitName <- function(species) | { | return( paste(species$layer, "suitability", sep="_") ) | } | #+end_src | | Block 2 | #+begin_src R | statDistName <- function(species){ | return( paste(species$layer, "disturbances_static", sep="_") ) | } | #+end_src `---- It seems that the second block can not be written, as the file is already set to read-only. For the moment, I exclude this setting again but will try it out as son as it is fixed. Cheers, Rainer > > 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: Rainer@krugs.de Skype: RMkrug [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Problem in tangle-mode -- WAS: Automatically adding local variables to tangled file 2013-06-10 10:12 ` Problem in tangle-mode -- WAS: " Rainer M Krug @ 2013-06-10 15:58 ` Eric Schulte 2013-06-11 7:25 ` BUG - Problem in tangle-mode Rainer M Krug 0 siblings, 1 reply; 25+ messages in thread From: Eric Schulte @ 2013-06-10 15:58 UTC (permalink / raw) To: Rainer M Krug; +Cc: emacs-orgmode >>> >>> 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. > > I did, and there is a problem with tangling multiple blocks into a > single file: > Oh, stupid of me. Thanks for sending this alert, I've just pushed up a change which should fix this problem. We now wait to set the file modes until after all blocks are tangled and after the post-tangle-hook has been run. Thanks, -- Eric Schulte http://cs.unm.edu/~eschulte ^ permalink raw reply [flat|nested] 25+ messages in thread
* BUG - Problem in tangle-mode 2013-06-10 15:58 ` Eric Schulte @ 2013-06-11 7:25 ` Rainer M Krug 2013-06-11 13:09 ` Eric Schulte 0 siblings, 1 reply; 25+ messages in thread From: Rainer M Krug @ 2013-06-11 7:25 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1037 bytes --] Eric Schulte <schulte.eric@gmail.com> 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. >>> >>> >>> Thanks a lot. I will try it out today or tomorrow. >> >> I did, and there is a problem with tangling multiple blocks into a >> single file: >> > > Oh, stupid of me. Thanks for sending this alert, I've just pushed up a > change which should fix this problem. We now wait to set the file modes > until after all blocks are tangled and after the post-tangle-hook has > been run. > > Thanks, Hi Unfortunately, it is now worse, as even without the tangle-mode header, I can't tangle two blocks - the second block overwrites the before tangled blocks. It tells me that two blocks were tangled, but only the last one is in the tangled file. I will for revert for now to the version from yesterday. Cheers, Rainer -- Rainer M. Krug email: RMKrug<at>gmail<dot>com [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: BUG - Problem in tangle-mode 2013-06-11 7:25 ` BUG - Problem in tangle-mode Rainer M Krug @ 2013-06-11 13:09 ` Eric Schulte 2013-06-11 18:25 ` Rainer M Krug 0 siblings, 1 reply; 25+ messages in thread From: Eric Schulte @ 2013-06-11 13:09 UTC (permalink / raw) To: Rainer M Krug; +Cc: emacs-orgmode Rainer M Krug <Rainer@krugs.de> writes: > Eric Schulte <schulte.eric@gmail.com> 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. >>>> >>>> >>>> Thanks a lot. I will try it out today or tomorrow. >>> >>> I did, and there is a problem with tangling multiple blocks into a >>> single file: >>> >> >> Oh, stupid of me. Thanks for sending this alert, I've just pushed up a >> change which should fix this problem. We now wait to set the file modes >> until after all blocks are tangled and after the post-tangle-hook has >> been run. >> >> Thanks, > > Hi > > Unfortunately, it is now worse, as even without the tangle-mode header, > I can't tangle two blocks - the second block overwrites the before > tangled blocks. It tells me that two blocks were tangled, but only the > last one is in the tangled file. > > I will for revert for now to the version from yesterday. > > Cheers, > Just pushed up a fix. Cheers, -- Eric Schulte http://cs.unm.edu/~eschulte ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: BUG - Problem in tangle-mode 2013-06-11 13:09 ` Eric Schulte @ 2013-06-11 18:25 ` Rainer M Krug 2013-06-12 15:15 ` Rainer M Krug 0 siblings, 1 reply; 25+ messages in thread From: Rainer M Krug @ 2013-06-11 18:25 UTC (permalink / raw) To: Eric Schulte; +Cc: Rainer M Krug, emacs-orgmode@gnu.org [-- Attachment #1: Type: text/plain, Size: 1696 bytes --] On Tuesday, June 11, 2013, Eric Schulte wrote: > Rainer M Krug <Rainer@krugs.de <javascript:;>> writes: > > > Eric Schulte <schulte.eric@gmail.com <javascript:;>> 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. > >>>> > >>>> > >>>> Thanks a lot. I will try it out today or tomorrow. > >>> > >>> I did, and there is a problem with tangling multiple blocks into a > >>> single file: > >>> > >> > >> Oh, stupid of me. Thanks for sending this alert, I've just pushed up a > >> change which should fix this problem. We now wait to set the file modes > >> until after all blocks are tangled and after the post-tangle-hook has > >> been run. > >> > >> Thanks, > > > > Hi > > > > Unfortunately, it is now worse, as even without the tangle-mode header, > > I can't tangle two blocks - the second block overwrites the before > > tangled blocks. It tells me that two blocks were tangled, but only the > > last one is in the tangled file. > > > > I will for revert for now to the version from yesterday. > > > > Cheers, > > > > Just pushed up a fix. Cheers, Thanks. Will try it out tomorrow, Cheers, Rainer > > -- > Eric Schulte > http://cs.unm.edu/~eschulte > -- 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: Rainer@krugs.de Skype: RMkrug [-- Attachment #2: Type: text/html, Size: 2716 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: BUG - Problem in tangle-mode 2013-06-11 18:25 ` Rainer M Krug @ 2013-06-12 15:15 ` Rainer M Krug 2013-06-12 21:42 ` Eric Schulte 0 siblings, 1 reply; 25+ messages in thread From: Rainer M Krug @ 2013-06-12 15:15 UTC (permalink / raw) To: Eric Schulte; +Cc: emacs-orgmode@gnu.org [-- Attachment #1: Type: text/plain, Size: 3963 bytes --] Rainer M Krug <r.m.krug@gmail.com> writes: > On Tuesday, June 11, 2013, Eric Schulte wrote: > >> Rainer M Krug <Rainer@krugs.de <javascript:;>> writes: >> >> > Eric Schulte <schulte.eric@gmail.com <javascript:;>> 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. >> >>>> >> >>>> >> >>>> Thanks a lot. I will try it out today or tomorrow. >> >>> >> >>> I did, and there is a problem with tangling multiple blocks into a >> >>> single file: >> >>> >> >> >> >> Oh, stupid of me. Thanks for sending this alert, I've just pushed up a >> >> change which should fix this problem. We now wait to set the file modes >> >> until after all blocks are tangled and after the post-tangle-hook has >> >> been run. >> >> >> >> Thanks, >> > >> > Hi >> > >> > Unfortunately, it is now worse, as even without the tangle-mode header, >> > I can't tangle two blocks - the second block overwrites the before >> > tangled blocks. It tells me that two blocks were tangled, but only the >> > last one is in the tangled file. >> > >> > I will for revert for now to the version from yesterday. >> > >> > Cheers, >> > >> >> Just pushed up a fix. Cheers, > > > Thanks. Will try it out tomorrow, Hi it seems that I have no luck at the moment. Now the post tangle hook does not seem to be called. If I use the file below, evaluate the code to set the hook, the hook is not executed. ,---- | #+PROPERTY: tangle ./test.R | | * Internal configurations :noexport: | ** 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 | | ** Post tangle script | #+begin_src sh :tangle postTangleScript.sh | touch PostTangleScriptHasBeenExecuted | #+end_src | | #+results: | | | * Two blocks | Block 1 | #+begin_src R | suitName <- function(species) | { | return( paste(species$layer, "suitability", sep="_") ) | } | #+end_src | | Block 2 | #+begin_src R | statDistName <- function(species){ | return( paste(species$layer, "disturbances_static", sep="_") ) | } | #+end_src `---- The hook is set: ,---- | Its value is | ((lambda nil | (call-process-shell-command "./postTangleScript.sh" nil 0 nil))) | | Original value was nil `---- Strangely enough, if I use ,---- | #+begin_src emacs-lisp :tangle no | (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 () | | (when (string-match "[.]R" (buffer-file-name)) | (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) | #+end_src `---- and evaluate this block (after resetting the post-tangle-hook), this function is executed? Sorry about all the hassles, Rainer > > Cheers, > > Rainer > >> >> -- >> Eric Schulte >> http://cs.unm.edu/~eschulte >> -- 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: Rainer@krugs.de Skype: RMkrug [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: BUG - Problem in tangle-mode 2013-06-12 15:15 ` Rainer M Krug @ 2013-06-12 21:42 ` Eric Schulte 2013-06-13 7:28 ` Rainer M Krug 0 siblings, 1 reply; 25+ messages in thread From: Eric Schulte @ 2013-06-12 21:42 UTC (permalink / raw) To: Rainer M Krug; +Cc: emacs-orgmode@gnu.org [-- Attachment #1: Type: text/plain, Size: 628 bytes --] > > Hi > > it seems that I have no luck at the moment. > > Now the post tangle hook does not seem to be called. > It is called, however the shell script you are trying to execute is not executing because it is not set as executable. The permissions of tangled files are set *after* the post-tangle hook is called (so that the post-tangle hook has a chance to modify files which will eventually be set to read only). You example is trying to run a tangled shell script before it is set to be executable. This can not work. My attached alternative of your example does run the shell script by not assuming it is executable. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: example.org --] [-- Type: text/x-org, Size: 890 bytes --] #+PROPERTY: tangle ./test.R * Internal configurations :noexport: ** Evaluate to run post tangle script #+begin_src emacs-lisp :results silent :tangle no :exports none (add-hook 'org-babel-post-tangle-hook (lambda () (message "running the post-tangle shell script") (shell-command "bash ./postTangleScript.sh"))) #+end_src ** Post tangle script #+begin_src sh :tangle postTangleScript.sh :results silent touch PostTangleScriptHasBeenExecuted #+end_src * Two blocks Block 1 #+begin_src R suitName <- function(species) { return( paste(species$layer, "suitability", sep="_") ) } #+end_src Block 2 #+begin_src R statDistName <- function(species){ return( paste(species$layer, "disturbances_static", sep="_") ) } #+end_src [-- Attachment #3: Type: text/plain, Size: 46 bytes --] -- Eric Schulte http://cs.unm.edu/~eschulte ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: BUG - Problem in tangle-mode 2013-06-12 21:42 ` Eric Schulte @ 2013-06-13 7:28 ` Rainer M Krug 0 siblings, 0 replies; 25+ messages in thread From: Rainer M Krug @ 2013-06-13 7:28 UTC (permalink / raw) To: Eric Schulte; +Cc: emacs-orgmode@gnu.org Eric Schulte <schulte.eric@gmail.com> writes: >> >> Hi >> >> it seems that I have no luck at the moment. >> >> Now the post tangle hook does not seem to be called. >> > > It is called, however the shell script you are trying to execute is not > executing because it is not set as executable. The permissions of > tangled files are set *after* the post-tangle hook is called (so that > the post-tangle hook has a chance to modify files which will eventually > be set to read only). That makes perfect sense - thanks. > > You example is trying to run a tangled shell script before it is set to > be executable. This can not work. My attached alternative of your > example does run the shell script by not assuming it is executable. OK - I will adapt it accordingly. Thanks a lot, Rainer > > #+PROPERTY: tangle ./test.R > > * Internal configurations :noexport: > ** Evaluate to run post tangle script > #+begin_src emacs-lisp :results silent :tangle no :exports none > (add-hook 'org-babel-post-tangle-hook > (lambda () > (message "running the post-tangle shell script") > (shell-command "bash ./postTangleScript.sh"))) > #+end_src > > ** Post tangle script > #+begin_src sh :tangle postTangleScript.sh :results silent > touch PostTangleScriptHasBeenExecuted > #+end_src > > * Two blocks > Block 1 > #+begin_src R > suitName <- function(species) > { > return( paste(species$layer, "suitability", sep="_") ) > } > #+end_src > > Block 2 > #+begin_src R > statDistName <- function(species){ > return( paste(species$layer, "disturbances_static", sep="_") ) > } > #+end_src <#secure method=pgpmime mode=sign> -- 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: Rainer@krugs.de Skype: RMkrug ^ permalink raw reply [flat|nested] 25+ messages in thread
* SOLVED: Automatically adding local variables to tangled file 2013-06-06 16:01 ` Eric Schulte 2013-06-07 7:57 ` Rainer M Krug @ 2013-06-10 11:32 ` Rainer M Krug 1 sibling, 0 replies; 25+ messages in thread From: Rainer M Krug @ 2013-06-10 11:32 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1521 bytes --] Eric Schulte <schulte.eric@gmail.com> writes: [snip (41 lines)] >>> 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) >>> `---- >>> [snip (5 lines)] I tried the above approach, but I was struggling with setting up the rules in the function definition which files should get the local variables and which not. I ended up with the following: ,---- | (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 () | | (when (string-match "[.]R" (buffer-file-name)) | (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) `---- Thanks everybody for their help, Rainer > -- Rainer M. Krug email: RMKrug<at>gmail<dot>com [-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --] ^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: Automatically adding local variables to tangled file 2013-06-05 14:04 Automatically adding local variables to tangled file Rainer M Krug 2013-06-05 14:32 ` Darlan Cavalcante Moreira @ 2013-06-05 17:10 ` Thorsten Jolitz 1 sibling, 0 replies; 25+ messages in thread From: Thorsten Jolitz @ 2013-06-05 17:10 UTC (permalink / raw) To: emacs-orgmode Rainer M Krug <Rainer@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 look&feel 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 enjoyable. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2013-06-13 7:28 UTC | newest] Thread overview: 25+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-06-05 14:04 Automatically adding local variables to tangled file Rainer M Krug 2013-06-05 14:32 ` Darlan Cavalcante Moreira 2013-06-05 15:41 ` Vitalie Spinu 2013-06-05 16:15 ` Rainer M Krug 2013-06-06 7:53 ` Sebastien Vauban 2013-06-06 16:01 ` Eric Schulte 2013-06-07 7:57 ` Rainer M Krug 2013-06-07 8:32 ` Rainer M Krug 2013-06-07 10:57 ` [PATCH] Don't ask "File changed on disk" in org-babel-post-tangle-hook Vitalie Spinu 2013-06-07 13:23 ` Eric Schulte 2013-06-07 13:47 ` Rainer M Krug 2013-06-08 18:23 ` Automatically adding local variables to tangled file Eric Schulte 2013-06-08 20:59 ` Achim Gratz 2013-06-08 21:17 ` Eric Schulte 2013-06-10 8:02 ` Rainer M Krug 2013-06-10 10:12 ` Problem in tangle-mode -- WAS: " Rainer M Krug 2013-06-10 15:58 ` Eric Schulte 2013-06-11 7:25 ` BUG - Problem in tangle-mode Rainer M Krug 2013-06-11 13:09 ` Eric Schulte 2013-06-11 18:25 ` Rainer M Krug 2013-06-12 15:15 ` Rainer M Krug 2013-06-12 21:42 ` Eric Schulte 2013-06-13 7:28 ` Rainer M Krug 2013-06-10 11:32 ` SOLVED: Automatically adding local variables to tangled file Rainer M Krug 2013-06-05 17:10 ` Thorsten Jolitz
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).