On Wed, Oct 5, 2011 at 10:58 AM, mdb <[email protected]> wrote:
> I got the crude code below to work in every case I tried

Sorry, but the code is too important to be guessing.  Furthermore,
your code can delete a node from an already-deleted tree.  I don't
know the implications of doing that, and I don't particularly want to
know either :-)  It's way too edgy code.

Here is the code that I am testing at present::

   while True:
        for p in c.all_positions():
            if p.isMarked():
                p.doDelete()
                break
        else:
            break

This has much better properties.  However, even this code depends on
an important hidden property, namely that p.doDelete (and its helpers)
properly update c.rootPosition() when the root node is deleted.  I
haven't verified that yet.

Edward

P.S.  Happily, the move-marked command is less hazardous.  The command
creates parent as the root node, then does the following::

    # Move marked nodes one node at a time.
    while True:
        assert parent == c.rootPosition()
        for p in c.all_positions():
            # Careful: don't move already-moved nodes.
            if p.isMarked() and not parent.isAncestorOf(p):
                p.moveToLastChildOf(parent)
                break
        else:
            break

EKR

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to