On Thu, Jan 9, 2014 at 10:55 AM, Edward K. Ream <[email protected]> wrote:


> When the time comes to do the actual moves, we do the following:
>
> -  Reverse the global list, thereby guaranteeing that positions that
> appear later in the reversed list remain valid.
>

There is a small, easily corrected, hole in this argument.  It assumes
that positions appear in the list in outline order.  That's usually so, but
not always.  Indeed, @organizer: nodes *are* written in outline order, as
are their contents, but rearrangements in the imported outline could
conceivably mean that the nodes corresponding to @organizer nodes would not
be handled in the *new* outline order.

This is easily remedied: just sort the list in (imported) outline order
before reversing it. Rev 6536 adds the following tested method of the
position class:

def sort_key(self,p):
    return [int(s.split(':')[1]) for s in p.key().split('.')]

To see why this works, look at the p.key method.

Here is an example test script::

    aList = [p.copy() for p in c.all_positions()]
    aList2 = sorted(reversed(aList),key=p.sort_key)
    i = 0
    for p in aList2:
        p2 = aList[i]
        i += 1
        assert p == p2,'\n%s:%s\n%s:%s' % (
            p.sort_key(),p.h,p2.sort_key(),p2.h)

It's not a great test, but it failed a few times before passing ;-)

Edward

P.S.  Contrary to a comment in p.key(), there is not, in fact, a need for
p.key() to add id(p.v) to the key.  Nevertheless, it's too late to change
p.key.

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.

Reply via email to