From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [babel] How-to realise a simplified usage scenario? Date: Fri, 25 Feb 2011 17:47:16 -0700 Message-ID: <87lj13fwdt.fsf@gmail.com> References: <4D675869.9030004@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=60871 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pt8R7-0000ZV-CX for emacs-orgmode@gnu.org; Fri, 25 Feb 2011 19:55:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pt8R6-0006ZC-0W for emacs-orgmode@gnu.org; Fri, 25 Feb 2011 19:55:05 -0500 Received: from mail-qw0-f41.google.com ([209.85.216.41]:61367) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pt8R5-0006Yy-SX for emacs-orgmode@gnu.org; Fri, 25 Feb 2011 19:55:03 -0500 Received: by qwd7 with SMTP id 7so2117457qwd.0 for ; Fri, 25 Feb 2011 16:55:03 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Torsten Wagner Cc: emacs-orgmode Hi Torsten, I found this email extremely hard to parse. Perhaps it would be easier if you first read through the relevant section of the Org-mode manual http://orgmode.org/manual/Working-With-Source-Code.html so that you are aware of what features are already provided by Babel. Then you could share how your suggestions are different from the existing Babel functionality, rather than as a brand new and largely overlapping set of syntax and functionality. I hope this request makes sense and is not unreasonable. Thanks -- Eric Torsten Wagner writes: > Hi, > > I tried to use org-babel (particular with python) several times. > However, I always struggled with the amount of options and it take me > long time to get it right. > I would like to describe my personal perfect scenario and hope that some > of those points could find a way into babel. > > Basically, I would like to use org-babel for some kind of literate > programming. It has not to produce publishing ready manuscripts (maybe, > this might be a final goal). Basically, I would like to keep my more > technically notes together with my calculations. Basically I want > something like this > > ---------------- Example-------------------------- > > * My problem > This is my problem description and I might use all kind of org-madness > to describe it, add todos, deadlines, tag it, add tables and links, etc. > At the beginning I might call some initialisation code > > #+begin_src sessionname > #!/usr/bin/env python > #import modules > import numpy as py > from myreadfile import * > # global variables > constant1 = 5 > loaddata("data") > y=5 > #+end_src > > After even more org-mode text, I come to the point to do some calculus > > #+begin_src sessionname :export > def myfunction(x=1): > # x is a parameter > c1 = 1e-4 > c2 = 3 > c3 = 1e6 > b = 3 > return c1*x**3+c2*x**2+c3*x**x+b > #+end_src > > I just continue writing to say what I just did. Now I want to state that > myfunction result in <>. Which > gives me the return value of myfunction for x = 10 and formats it into > scientific notation. I also could write <> which > would be replaced by the standard integer representation 5. > Sure I could write <> as well to > get the result of my function for the variable y which I defined in the > first code block. I could even create a new variable on the fly > <> print it z= <> and show the > result for myfunction: <>. > I could even switch to another language (however, I doubt that this is > often the case). Either by direct replacement and taking care of the > formatting manually > > #+begin_src elisp_session > #!/usr/bin/emacs --script > (setq a 3) > (setq b <>) > (message "%+3.5f" (* a b)) > #+end_src > > or (esp. for more complex inputs) by additional use of helper functions > defined for the target language > > #+begin_src elisp_session > #!/usr/bin/emacs --script > (setq a 3) > (setq b (<>)) > (message "%+3.5f" (* a b)) > #+end_src > > which would take care to place it in the source code block with the > correct target syntax. > > --------------------End Example------------------------------- > > The key-points are: > * All code blocks belong to a session to allow sharing namespace > * The entire code is still written in a way to execute it "stand-alone" > if tangled, the tangle operation could replace var_sessionname commands > by appropriate print commands in the target language. Functions are real > valid functions of the target language. > * no need to specify the language over and over again since it can be > found by reading the shebang for each session > * var_sessionname commands define were to place output of the target > language and how to format it. Formatting and output could be realized > in the native target language which then returns an appropriate > raw-orgmode string. This would even allow complex scenarios like > embedding a plot created in the target language without the need for the > user to know about that. > * C-c C-c somewhere in a code block refresh the entire session. > Honestly, I had to much problems with python errors due to old running > sessions which were only partially updated and a confused python > interpreter. Keep it simple, close any old session, open a new, rerun > the code. If source code gets to long and computation takes to much time > people might consider to split it into different sessions. > * Tangeling the code could be a org-export function with options to save > it in a file, open it in a buffer or execute it e.g., in ipython > In a similar way like for other exports C-c C-e 1 c (c for code export) > would tangle only the session to which the code under the pointer > belongs and C-c C-e c exports all sessions in different buffers, etc. > * Parts of the source code blocks which should appear in export are > simply marked :export all other will not be exported no resuls will be > exported unlike they are explicit called via the var_sessioname command. > > > I'm aware that babel can do some of the above points already. However, > at least for python is is still very rough sometimes. > I like babel and I really would like to express my grateful thanks to > the developers but I really have a hard time to use it and would like to > see some more simplified usage. > > Hope I have hit a few good points... > > Torsten > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode