emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] [RFC] [PATCH] [babel] read description lists as lists of lists


From: Thorsten Jolitz
Subject: Re: [O] [RFC] [PATCH] [babel] read description lists as lists of lists
Date: Sun, 28 Sep 2014 12:49:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Aaron Ecay <address@hidden> 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 via email to

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