Isaac <isaac...@gmail.com> writes: Hi Isaac,
> Thomas S. Dye <tsd <at> 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