emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode][babel] How-to realise a simplified usage scenario?


From: Eric Schulte
Subject: Re: [Orgmode][babel] How-to realise a simplified usage scenario?
Date: Fri, 25 Feb 2011 17:47:16 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

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 <address@hidden> 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 <<var_sessioname[%2.3g]{myfunction(10)}>>. Which 
> gives me the return value of myfunction for x = 10 and formats it into 
> scientific notation. I also could write <<var_sessionname{y}>> which 
> would be replaced by the standard integer representation 5.
> Sure I could write <<var_sessionname[%2.3g]{myfunction(y)}>> 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 
> <<src_sessionname{z=5}>> print it z= <<var_sessionname{z}>> and show the 
> result for myfunction: <<var_sessionname{myfunction(z)}>>.
> 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 <<var_sessioname{y}>>)
>        (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 (<<var_sessioname[elisp:integer]{y}>>))
>        (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.
> address@hidden
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode



reply via email to

[Prev in Thread] Current Thread [Next in Thread]