From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: Automatically adding local variables to tangled file Date: Wed, 05 Jun 2013 19:10:17 +0200 Message-ID: <87obbkh4au.fsf@gmail.com> References: <878v2omz5g.fsf@krugs.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkHEL-0006nd-0h for emacs-orgmode@gnu.org; Wed, 05 Jun 2013 13:10:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkHEF-0002Nj-QD for emacs-orgmode@gnu.org; Wed, 05 Jun 2013 13:10:36 -0400 Received: from plane.gmane.org ([80.91.229.3]:33410) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkHEF-0002Nd-FM for emacs-orgmode@gnu.org; Wed, 05 Jun 2013 13:10:31 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UkHED-0001im-R8 for emacs-orgmode@gnu.org; Wed, 05 Jun 2013 19:10:29 +0200 Received: from e178054238.adsl.alicedsl.de ([85.178.54.238]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 05 Jun 2013 19:10:29 +0200 Received: from tjolitz by e178054238.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 05 Jun 2013 19:10:29 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Rainer M Krug 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