On Fri, Jan 17, 2014 at 10:28 AM, Edward K. Ream <[email protected]>wrote:
I am writing this in the middle of the night, hoping I can get back to
sleep when I'm finished ;-)
>
I am going to completely rewrite phase 2.
Still true, and for the reasons given. However, the details are
different, and much simpler.
Yesterday, after writing the previous post, I tried to explain the new
scheme to my brother Speed. Afterwards, I realized that attempting to
maintain a "virtual" outline position was a bad idea. Instead, it's much
simpler to ground all processing on the *actual* positions visited during
the one and only traversal of the outline in the new demote method.
In other words, dropping parts of unls, as is done presently, *is* a good
idea.
===== Distinctions
Four new distinctions, based on unls, completely eliminate all difficult
"if" statements in the program. All special cases based on the various
flavors of organizer nodes will disappear. This surely is the last collapse
in complexity in this project. No difficult code will remain.
Here are the four new distinctions:
1. For any unl U, the **real unl**, vc.real_unl(U), is U stripped of all
headlines that do not appear in the imported outline, that is, stripped of
all organizer headlines. Note: for existing organizer nodes O, the
following is true: real_unl(O).endswith(O.h).
2. For any unl U, vc.unl_to_position(U) is the position corresponding to
vc.real_unl(U). If no corresponding node exists, vc.unl_to_position(U)
returns None.
3. For any organizer node O, O's **anchor**, vc.anchor(U), is the position
in the imported outline that causes O to be added to the outline. For
existing organizer nodes, anchor(O) == O.p. Nested organizer nodes have
the same anchor.
4. For any position p in the imported outline, **anchors(p)** is the list
of organizer nodes whose anchor is p. This can be implemented as a Python
dict, say vc.anchors_dict. Keys are positions, values are *sorted* lists.
The first item on the list is the unique organizer that has no parent
organizer. The second is the first item's direct child, and so on.
===== vc.demote
The demote method will have almost *exactly* the same code as the old
demote_helper method, with the following differences:
1. It traverses the entire tree, starting at the root position, rather than
the children or siblings of a particular organizer node. This is
important! It eliminates all doubt about the order in which imported nodes
are visited.
2. The code will maintain a list of organizer nodes that are "open", that
is, might still have nodes added to them.
For any position p (in the traversal), it is trivial to determine the
already open organizer nodes that must be closed as the result of visiting
p. They are the nodes O for which O.anchor is neither p nor a descendant
of p. vc.terminate_organizers(p) will close these open nodes.
For any position p, it is trivial to determine the organizer nodes that
should be opened as the result of visiting p: they are the nodes in
vc.anchors_dict.get(p). vc.enter_organizers(p) will open these organizer
nodes *in order*, thereby ensuring that organizers appear in the expected
order on the global moved nodes list. vc.enter_organizers will return the
last organizer on the list.
In short, the all-important demote method will look something like this::
def demote(self,root):
active = None # The active od.
self.demote_pending = [] # Lists of pending demotions.
n = 0
for p in root.subtree():
self.terminate_organizers(p)
found = self.enter_organizers(p)
<< a case statement, almost exactly as in demote_helper >>
Yes, there are still "if" statements in the case statements, but they are
clearly required to determine whether p is to be placed on the global node
list or on a pending list.
===== Summary
It's much simpler to ground everything in the actual imported nodes, *not*
a simulated tree that includes organizer nodes. Dropping organizer
headlines from unls *is* a good idea.
Four new distinctions clarify what should be done. Phase 1 can easily
compute data based on these distinctions. These data associate unls and
organizer nodes with positions in the imported outline.
vc.demote will traverse the entire tree of *actual* imported nodes. The
new data makes it easy to open and close organizer nodes as each position
is visited.
Phase 3 will remain unchanged.
EKR
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.