From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: proposal for a tool to translate orgmode outlines into programs Date: Sat, 05 Oct 2013 09:11:33 +0200 Message-ID: <87vc1cmbtm.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VSM1o-0002ui-NX for emacs-orgmode@gnu.org; Sat, 05 Oct 2013 03:11:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VSM1j-0003Sv-71 for emacs-orgmode@gnu.org; Sat, 05 Oct 2013 03:11:52 -0400 Received: from plane.gmane.org ([80.91.229.3]:38241) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VSM1i-0003Sr-Sg for emacs-orgmode@gnu.org; Sat, 05 Oct 2013 03:11:47 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VSM1h-0005H4-ET for emacs-orgmode@gnu.org; Sat, 05 Oct 2013 09:11:45 +0200 Received: from g231111112.adsl.alicedsl.de ([92.231.111.112]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 05 Oct 2013 09:11:45 +0200 Received: from tjolitz by g231111112.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 05 Oct 2013 09:11:45 +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 Isaac writes: Hi Isaac, > Thomas S. Dye tsdye.com> writes: > >> >> Aloha Isaac, >> >> This sounds to me a lot like literate programming, which can be >> accomplished in Org with very many languages, including ruby and python >> (but not lua, yet). See >> http://orgmode.org/worg/org-contrib/babel/languages.html. An advantage >> of literate programming is that it generates documentation in addition >> to the program code. >> >> hth, >> Tom >> > > yes and no - it's literate programming, but rather than programming in > orgmode - it's translating orgmode (thoughts) to build a skeleton of > codes for code generation ... not sure if someone has done something > similar before? it would be good to know. Assume this is file tmp.org: #+begin_src org * A*B*/C/ *Fett* and /Kursiv/ text and some Programmtext: ~var = x + y~ #+end_src eval this in the *scratch* buffer: #+begin_src emacs-lisp (with-current-buffer (find-file "/path/to/tmp.org") (let ((print-circle t)) ; or nil (print (org-element-parse-buffer)))) #+end_src and you get the org-file as a nested list (parse-tree) [fn:1]: #+begin_src emacs-lisp #2=(org-data nil #1=(headline (:raw-value "A*B*/C/" :begin 1 :end 75 :pre-blank 0 :hiddenp nil :contents-begin 11 :contents-end 75 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :quotedp nil :CATEGORY nil :title (#("A*B*/C/" 0 7 (:parent #1#))) :parent #2#) #3=(section (:begin 11 :end 75 :contents-begin 11 :contents-end 75 :post-blank 0 :parent #1#) #4=(paragraph (:begin 11 :end 75 :contents-begin 11 :contents-end 75 :post-blank 0 :post-affiliated 11 :parent #3#) #5=(bold (:begin 11 :end 18 :contents-begin 12 :contents-end 16 :post-blank 1 :parent #4#) #("Fett" 0 4 (:parent #5#))) #("and " 0 4 (:parent #4#)) #6=(italic (:begin 22 :end 31 :contents-begin 23 :contents-end 29 :post-blank 1 :parent #4#) #("Kursiv" 0 6 (:parent #6#))) #("text and some Programmtext: " 0 29 (:parent #4#)) (code (:value "var = x + y" :begin 60 :end 74 :post-blank 1 :parent #4#)) #(" " 0 1 (:parent #4#)))))) #+end_src Checkout Org elements: #+begin_src sh org-element-all-elements is a variable defined in `org-element.el'. Its value is (babel-call center-block clock comment comment-block diary-sexp drawer dynamic-block example-block export-block fixed-width footnote-definition headline horizontal-rule inlinetask item keyword latex-environment node-property paragraph plain-list planning property-drawer quote-block quote-section section special-block src-block table table-row verse-block) Complete list of element types. #+end_src and Org objects: #+begin_src sh org-element-all-objects is a variable defined in `org-element.el'. Its value is (bold code entity export-snippet footnote-reference inline-babel-call inline-src-block italic line-break latex-fragment link macro radio-target statistics-cookie strike-through subscript superscript table-cell target timestamp underline verbatim) Complete list of object types. #+end_src Now in lisp there is the equivalence of code and data, thus this is data #+begin_src emacs-lisp '(paragraph (:begin 11 :end 75 :contents-begin 11 :contents-end 75 :post-blank 0 :post-affiliated 11 :parent nil) #+end_src but the following would be code, if a there would be a #+begin_src emacs-lisp (defun paragraph (plst) (message "I print my argument: %s" plst)) #+end_src #+results: : paragraph defined somewhere => #+begin_src emacs-lisp (eval (paragraph '(:begin 11 :end 75 :contents-begin 11 :contents-end 75 :post-blank 0 :post-affiliated 11 :parent nil))) #+end_src gives #+results: : I print my argument: (:begin 11 :end 75 :contents-begin 11 :contents-end : 75 :post-blank 0 :post-affiliated 11 :parent nil) so in a certain sense, the new org-parser already transforms the plain text of an org document into lisp (code = data), only that nobody has written functions for the elements and objects yet, the parse-tree is just used as data for the exporter. * Footnotes [fn:1] Those #1= and #1# are only print-syntax, otherwise they are references to already defined elisp objects. -- cheers, Thorsten