emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Thorsten Jolitz <tjolitz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [RFC] [PATCH] [babel] read description lists as	lists	of	lists
Date: Sun, 28 Sep 2014 12:49:23 +0200	[thread overview]
Message-ID: <877g0ot3yk.fsf@gmail.com> (raw)
In-Reply-To: 87tx3sl254.fsf@gmail.com

Aaron Ecay <aaronecay@gmail.com> writes:

Hi Aaron,

> So the question is, how to provide a consistent language-agnostic view
> of org structure to other languages. 

well, that would be the parse-tree normally, its a nested list
containing all info about org structure. 

I tried to make two Lisps talk to each other (Emacs Lisp and PicoLisp),
and initially thought it would be easy - just send lists back and
forth. But when these lists are parse-trees produced by the Org parser
framework, its not that straight-forward anymore, because these lists
are send as strings and then read again by the other side, and there are
lots of peculiarities in the string representation of Org parse-trees
that make other languages choke, even if they otherwise understand lists
very well.

As an example, this nested list representation of this "created"
headline is simple enough, PicoLisp can read it "as-is":

#+NAME: hl1
#+BEGIN_SRC emacs-lisp :results verbatim
  (org-dp-create 'headline "Hallo World" 'data '(:name "foo")
                 :level 2
                 :title "2nd level"
                 :todo-keyword "NEXT"
                 :tags '("office")
                 :priority ?B)
#+END_SRC

#+results: hl1
: (headline (:level 2 :title "2nd level" :todo-keyword "NEXT" :tags
("office") :priority 66 :name "foo") (section nil "Hallo World"))

#+BEGIN_SRC emacs-lisp :var lst=hl1
 (length lst)
#+END_SRC

#+results:
: 131

#+BEGIN_SRC picolisp :var lst=hl1 :results pp
 (in NIL (length lst))
#+END_SRC

#+results:
: 131

#+BEGIN_SRC picolisp :var lst=hl1 :results pp
 (in NIL (last (car (str lst))))
#+END_SRC

#+results:
: (section nil "Hallo World")

So this can be read by PicoLisp (and probably many other list
processing languages), except that nil is not NIL in PicoLisp.

But when parsing this Org buffer its easy to see that syntax and
semantics of Emacs Lisp circular lists as well as of strings with
text-properties cannot easily be consumed by other languages (expecially
when # is their comment-start character). Some post-processing is
necessary, e.g. suppressing text properties, nil -> NIL, \n -> ^J, ^ ->
\^, # -> \# etc., and I doubt this can be done in a language agnostic
way. And then the circular relationships needs to be resolved to
something the target language can understand...

#+BEGIN_SRC emacs-lisp :results pp
 (org-element-parse-buffer)
#+END_SRC

#+results: (org-data nil (headline (:raw-value "--text follows this
line--" :begin 1 :end 17295 :pre-blank 0 :contents-begin 30
:contents-end 17295 :level 1 :priority nil :tags nil :todo-keyword nil
:todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil
:commentedp nil :post-affiliated 1 :title (#("--text follows this
line--" 0 26 (:parent #1))) :parent #0) [...cut...] (paragraph (:begin
17274 :end 17295 :contents-begin 17274 :contents-end 17295 :post-blank 0
:post-affiliated 17274 :parent #3) #("-- \ncheers,\nThorsten\n" 0 21
(:parent #4)))))

-- 
cheers,
Thorsten

  reply	other threads:[~2014-09-28 10:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-19 19:17 [RFC] [PATCH] [babel] read description lists as lists of lists Aaron Ecay
2014-09-20  0:30 ` Charles Berry
2014-09-20 11:52 ` Nicolas Goaziou
2014-09-23  4:02   ` Aaron Ecay
2014-09-24 19:56     ` Nicolas Goaziou
2014-09-24 22:49       ` Aaron Ecay
2014-09-26  9:03         ` Nicolas Goaziou
2014-09-28  5:55           ` Aaron Ecay
2014-09-28 10:49             ` Thorsten Jolitz [this message]
2014-09-28 22:09             ` Nicolas Goaziou

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=877g0ot3yk.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).