From: Thorsten Jolitz <tjolitz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: proposal for a tool to translate orgmode outlines into programs
Date: Sat, 05 Oct 2013 09:11:33 +0200 [thread overview]
Message-ID: <87vc1cmbtm.fsf@gmail.com> (raw)
In-Reply-To: loom.20131005T004008-890@post.gmane.org
Isaac <isaacpei@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
next prev parent reply other threads:[~2013-10-05 7:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-04 16:38 proposal for a tool to translate orgmode outlines into programs Isaac
2013-10-04 17:12 ` Thomas S. Dye
2013-10-04 22:42 ` Isaac
2013-10-05 7:11 ` Thorsten Jolitz [this message]
2013-10-05 13:53 ` Eric Schulte
2013-10-05 17:39 ` Isaac
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=87vc1cmbtm.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).