all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Oliver Scholz <alkibiades@gmx.de>
Cc: boris@gnu.org, eliz@gnu.org, alex@emacswiki.org, emacs-devel@gnu.org
Subject: Re: enriched-mode and switching major modes.
Date: Wed, 22 Sep 2004 12:01:27 +0200	[thread overview]
Message-ID: <ud60e1v2g.fsf@ID-87814.user.uni-berlin.de> (raw)
In-Reply-To: <E1C9pPh-0005DY-Gz@fencepost.gnu.org> (Richard Stallman's message of "Tue, 21 Sep 2004 14:30:53 -0400")

Richard Stallman <rms@gnu.org> writes:

>     When rendered by a graphical, CSS2-enabled browser, you'll see two
>     paragraphs on a gray background sourounded by a dashed border.  Those
>     two paragraphs are again contained in a larger paragraph on a purple
>     background surounded by a solid border.
>
> It will be very hard to implement this in a way that fits in with
> Emacs.

Okay, maybe this is the time to lay out the design on which I am
spending thought and code since I ditched the approach that I already
mentioned (as in `wp-example.el').  I fear, though, that you won't
like it.

The idea crossed my mind when I thought about how to implement a
data structure fit for XML + CSS in Emacs Lisp.  In other words: how
to make Emacs a /rendering/ XML editor.

XML is by nature a tree-like format.  The W3C has specified the
structure of information contained in XML documents in a way that
abstracts from the pointy brackets syntax; this abstract data set is
called the "XML Information Set":

http://www.w3.org/TR/xml-infoset/

For simplicity, I focus on elements and character data here and talk
about them as "nodes" in a tree; thus we have "element nodes" and
"text nodes".  An XHTML fragment like

<h1>Some <em>meaningless</em> text</h1>

Would be regarded as a `h1' element node which has three children: a
text node "Some ", an element node `em' (which has itself a text node
as its single child) an another text node " text".

I found out that I can translate any RTF document into an instance of
the XML info set.  So I can reduce the problem of designing a data
structure for word processing in Emacs to the question of how to
implement the XML info set in a way that text nodes are stored in a
buffer rather than in a string and that they are /editable/.  And that
question I can reduce to: how can I implement a tree-like data
structure with text properties?

So far I have considered two ways to do this. Both have specific
disadvantages.  But I'll come to that in a minute.

[If desired, I have prototype code for each of those two approaches to
experiment with. :-/ ]

One way is to have a single, unique Lisp object, a vector for example,
stored in a text property, say `text-node'.  That vector (or list)
would store a reference to its immeditate parent (which is always an
element node).  That parent would have a reference both to its
children and to its own parent and so on.  In addition, a buffer-local
variable would store the root element.

This has the advantage that I have two views of the document: One as a
Lisp Object, a tree of vectors or of lists, stored in a variable; the
other one as the content of a buffer with specific text properties.
The former allows to implement an API for accessing the contents of
the document and modifying it---I am thinking of XPath, DOM and other
W3C standards here that many people are familiar with.  If I have a
text node (the vector or list), then I can find its text in the buffer
with

`(text-property-any (point-min) (point-max) 'text-node TEXT-NODE)'

This should be fast.

But this solution has an undesirable fragility: care must be taken,
when killing and yanking, that both the text properties and the tree
be updated accordingly (for example if the killing results in the
entire deletion of a text node).  And if the tree is modified directly
(via the API), then the buffer contents need to be updated, too (for
example when this leads to transfering text nodes to another place in
the tree).  Basically this is again the problem of keeping two
structures in sync again.

The other way is to have a text property `parents' on each text
node in the buffer.  This would hold a list of all ancestor nodes
in the tree, starting with the immediate parent.  The
disadvantage here is that finding nodes takes much more time.
Especially finding all the children or descendants of a node
takes time.  Whereas in #1 I have a reference to the children in
the node, here I have to scan several ranges of text properties
to determine the children, e.g.

    1. Find the first position in the buffer where NODE is a
       member of the value of the text property `parents'.

    2. Push the value of `parents' to a list.

    3. Find the next single property change of `parents'.
    
    4. Determine if NODE is a member of the value of `parents'.
       If yes, goto 2.  If no, got 5.

    5. Determine children or descendants from the collected
       values.

Some care is necessary with copying and inserting text.  But we avoid
to keep to separate structures in sync at the cost that the access of
nodes (and thus the API) is inefficient.


So how to handle formatting in the buffer?  The element nodes would
store formatting information---either after applying a CSS stylesheet
to the tree, or, in the case of RTF, right away when parsing the file.
Functions that apply the formatting in the buffer (i.e. filling and
jit-lock) scan the tree upwards until they find the information they
need.

I have not yet determined whether #2 requires too much time for this.
The idea of #2 is rather new and not fully thought out and tested.  I
am not certain if I am aware of all possible pitfalls.  Moreover, I
have not yet figured out every detail of handling formatting
information in general.  I am still in the process of reading
specifications in order to get an overview.  I have to admit that I
have also been wondering, whether something could be done on the C
level to provide for such tree-like documents in an Emacs buffer.  I
don't have a clue here, though.

[Yesterday or so, a third way how to handle nested blocks crossed my
mind.  Maybe each paragraph could have a `nesting-level' text property
whose value is an integer.  For each nesting-level N, with N > 0, the
first preceeding block with a nesting level N - 1 is the immediate
parent.  I have no idea yet how, if at all, that would translate to
the XML info set, though.]


    Oliver
--
Oliver Scholz               1 Vendémiaire an 213 de la Révolution
Ostendstr. 61               Liberté, Egalité, Fraternité!
60314 Frankfurt a. M.

  parent reply	other threads:[~2004-09-22 10:01 UTC|newest]

Thread overview: 150+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-04 23:58 enriched-mode and switching major modes Luc Teirlinck
2004-09-05 17:25 ` Richard Stallman
2004-09-06  0:59   ` Luc Teirlinck
2004-09-06 16:42     ` Stefan
2004-09-06 16:53       ` Luc Teirlinck
2004-09-10 17:40     ` Richard Stallman
2004-09-11  2:14       ` Luc Teirlinck
2004-09-11 16:56         ` Stefan
2004-09-11 21:51           ` Luc Teirlinck
2004-09-11 22:55             ` Stefan
2004-09-12  1:46               ` Luc Teirlinck
2004-09-12 18:18                 ` Stefan
2004-09-12  2:50               ` Luc Teirlinck
2004-09-13  7:00               ` Richard Stallman
2004-09-12  9:10         ` Richard Stallman
2004-09-12 16:51           ` Luc Teirlinck
2004-09-12 17:08             ` Oliver Scholz
2004-09-12 18:36             ` Kim F. Storm
2004-09-12 20:01               ` Luc Teirlinck
2004-09-13  7:32                 ` Kim F. Storm
2004-09-13 23:03             ` Richard Stallman
2004-09-14  3:46               ` Luc Teirlinck
2004-09-14 12:26                 ` Stefan Monnier
2004-09-14 22:12                   ` Luc Teirlinck
2004-09-15  9:32                 ` Richard Stallman
2004-09-17  9:36                 ` Richard Stallman
2004-09-19 20:07                   ` Luc Teirlinck
2004-09-06  7:36   ` Oliver Scholz
2004-09-06 19:01     ` Alex Schroeder
2004-09-10 17:40       ` Richard Stallman
2004-09-10 19:30         ` Oliver Scholz
2004-09-13 23:04           ` Richard Stallman
2004-09-14 14:41             ` Oliver Scholz
2004-09-14 16:31               ` Oliver Scholz
2004-09-15  1:39               ` Luc Teirlinck
2004-09-15  1:47                 ` Luc Teirlinck
2004-09-15  8:06                 ` Oliver Scholz
2004-09-15 15:42               ` Richard Stallman
2004-09-16 13:20                 ` Kai Grossjohann
2004-09-17 23:22                   ` Richard Stallman
2004-09-16 17:04                 ` Oliver Scholz
2004-09-17  5:15                   ` Eli Zaretskii
2004-09-17 14:34                     ` Oliver Scholz
2004-09-17 20:43                       ` Kai Grossjohann
2004-09-17 22:05                         ` Kim F. Storm
2004-09-18 19:07                           ` Richard Stallman
2004-09-18 15:37                         ` Robert J. Chassell
2004-09-18 11:14                       ` Eli Zaretskii
2004-09-18 12:04                         ` David Kastrup
2004-09-18 13:32                           ` Eli Zaretskii
2004-09-18 13:46                             ` David Kastrup
2004-09-18 15:57                               ` Eli Zaretskii
2004-09-19 17:19                                 ` Kai Grossjohann
2004-09-18 22:55                           ` Richard Stallman
2004-09-18 17:08                         ` Oliver Scholz
2004-09-18 17:48                           ` Eli Zaretskii
2004-09-18 20:02                             ` Oliver Scholz
2004-09-18 21:25                               ` Eli Zaretskii
2004-09-18 21:54                                 ` Oliver Scholz
2004-09-20  0:06                                   ` Richard Stallman
2004-09-20 11:48                                     ` Oliver Scholz
2004-09-21 18:30                                       ` Richard Stallman
2004-09-21 19:08                                         ` Eli Zaretskii
2004-09-21 20:06                                           ` Stefan Monnier
2004-09-22  4:54                                             ` Eli Zaretskii
2004-09-22 18:20                                           ` Richard Stallman
2004-09-22 18:39                                             ` Eli Zaretskii
2004-09-23 16:44                                               ` Richard Stallman
2004-09-22 10:01                                         ` Oliver Scholz [this message]
2004-09-22 13:08                                           ` Stefan Monnier
2004-09-22 13:11                                           ` Stefan Monnier
2004-09-22 13:14                                             ` Oliver Scholz
2004-09-22 16:27                                               ` Stefan Monnier
2004-09-23  1:48                                               ` Luc Teirlinck
2004-09-23  9:29                                             ` Richard Stallman
2004-09-23  9:48                                               ` David Kastrup
2004-09-23 16:44                                                 ` Richard Stallman
2004-09-23 11:35                                               ` Stefan
2004-09-23 12:46                                                 ` David Kastrup
2004-09-23 12:59                                                 ` Oliver Scholz
2004-09-24 12:08                                                 ` Richard Stallman
2004-09-24 12:50                                                   ` Stefan
2004-09-25 15:34                                                     ` Richard Stallman
2004-09-24 10:59                                           ` Eli Zaretskii
2004-09-24 11:53                                             ` Oliver Scholz
2004-09-24 15:51                                               ` Oliver Scholz
2004-09-24 20:55                                                 ` Alex Schroeder
2004-09-24 21:11                                                   ` Oliver Scholz
2004-09-25 16:36                                                 ` Eli Zaretskii
2004-09-22 10:35                                         ` Oliver Scholz
2004-09-22 18:21                                           ` Richard Stallman
2004-09-20  0:05                               ` Richard Stallman
2004-09-18 22:11                             ` Kim F. Storm
2004-09-19  3:47                               ` Eli Zaretskii
2004-09-20  0:05                               ` Richard Stallman
2004-09-20 11:07                                 ` Oliver Scholz
2004-09-20 11:55                                   ` Kim F. Storm
2004-09-21 18:30                                   ` Richard Stallman
2004-09-22  7:44                                     ` Kim F. Storm
2004-09-22 18:14                                       ` Eli Zaretskii
2004-09-22 21:53                                         ` Kim F. Storm
2004-09-23  4:47                                           ` Eli Zaretskii
2004-09-23  7:13                                             ` Kim F. Storm
2004-09-22 18:20                                       ` Richard Stallman
2004-09-22 21:58                                         ` Kim F. Storm
2004-09-20 12:47                                 ` Kai Grossjohann
2004-09-17 15:08                   ` Robert J. Chassell
2004-09-18 17:34                     ` Oliver Scholz
2004-09-18 23:05                       ` Robert J. Chassell
2004-09-19 11:07                         ` Oliver Scholz
2004-09-19 11:24                           ` David Kastrup
2004-09-19 13:14                           ` Robert J. Chassell
2004-09-20  5:49                           ` Stefan
2004-09-20  6:17                             ` David Kastrup
2004-09-20  6:26                               ` Stefan
2004-09-20 11:00                             ` Oliver Scholz
2004-09-20 13:24                               ` Stefan Monnier
2004-09-20 14:17                                 ` Oliver Scholz
2004-09-20 14:55                                   ` Stefan Monnier
2004-09-20 19:18                                     ` David Kastrup
2004-09-20 19:49                                       ` Stefan Monnier
2004-09-20 19:37                                     ` Oliver Scholz
2004-09-20 20:04                                       ` Stefan Monnier
2004-09-21  9:07                                         ` Oliver Scholz
2004-09-21 14:43                                           ` Robert J. Chassell
2004-09-20 21:44                                   ` Robert J. Chassell
2004-09-17 23:22                   ` Richard Stallman
2004-09-18 16:57                     ` Oliver Scholz
2004-09-18 17:12                       ` Oliver Scholz
2004-09-20  0:05                       ` Richard Stallman
2004-09-20 11:35                         ` Oliver Scholz
2004-09-20 11:47                           ` Kim F. Storm
2004-09-20 13:27                             ` Oliver Scholz
2004-09-20 14:23                               ` Kim F. Storm
2004-09-20 19:35                                 ` Oliver Scholz
2004-09-20 19:35                               ` Oliver Scholz
2004-09-20 20:21                                 ` Kim F. Storm
2004-09-21  9:07                                   ` Oliver Scholz
2004-09-21 11:20                                     ` Kim F. Storm
2004-09-22  7:11                                   ` Richard Stallman
2004-09-21 18:30                             ` Richard Stallman
2004-09-21 20:31                               ` Miles Bader
2004-09-22  3:20                               ` James Clark
2004-09-23  9:30                                 ` Richard Stallman
2004-09-21  9:53                         ` Kai Grossjohann
2004-09-21 11:32                           ` Kim F. Storm
2004-09-21 18:53                           ` Eli Zaretskii
2004-09-21 20:34                             ` Miles Bader
2004-09-22  0:31                             ` David Kastrup
2004-09-22 14:00                           ` Richard Stallman

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ud60e1v2g.fsf@ID-87814.user.uni-berlin.de \
    --to=alkibiades@gmx.de \
    --cc=alex@emacswiki.org \
    --cc=boris@gnu.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.