emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Thorsten Jolitz <tjolitz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Automatically adding local variables to tangled file
Date: Wed, 05 Jun 2013 19:10:17 +0200	[thread overview]
Message-ID: <87obbkh4au.fsf@gmail.com> (raw)
In-Reply-To: 878v2omz5g.fsf@krugs.de

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

      parent reply	other threads:[~2013-06-05 17:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87obbkh4au.fsf@gmail.com \
    --to=tjolitz@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).