btheado 
<https://groups.google.com/d/msg/leo-editor/dFrhAitxOnM/D1qGrCtdDQAJ>,

On Thursday, October 10, 2019 at 4:08:06 AM UTC-7, btheado wrote:
>
> I've been thinking about this a lot and I've come to the conclusion that 
> there should be a separate command that will display all the clone 
> positions of a given node. Maybe the original could be renamed from 
> 'show-clones' to 'show-clone-parents' and this one could be called 
> 'show-clone-ancestors'
>
> g.es(f"Ancestors of '{p.h}':")
> for clone in c.all_positions():
>     if clone.v == p.v:
>         unl = clone.get_UNL(with_file=False, with_index=False)
>         runl = " <- ".join(unl.split("-->")[::-1][1:]) # reverse and drop 
> first
>         g.es("  ", newline = False)
>         g.es_clickable_link(c, clone, 1, runl + "\n")
>
> SegundoBob, this one should work better for your clone structure, though 
> in general there will be more output from this one than the other one.
>

 Brian,

You give a correct implementation of vnode2allPositions().

Based on Brian's code, here is the code I suggest for replacing 
leoCommands.vnode2allPositions():
```
def vnode2allPositions(self, v):
    """Given a VNode v, find all valid positions p such that p.v = v.

    """
    c = self
    context = v.context # v's commander.
    assert(c == context)
    return [posX.copy() for posX in c.all_positions() if posX.v == v]
```

Edward,

The implementation of vnode2allPositions() in leoCommand.py is seriously 
flawed. Correcting it would probably change it extensively.

You can see the problem by considering the case of one parent node A with 
one position X, one clone node B with with positions Y and Z that are 
immediate children of X.  Node B.parents has two members both of which are 
A.  Hence leoCommands. vnode2allPositions() returns 2 positions because the 
outermost loop is on the members of B.parents.  But, both positions 
returned position Y because A.children.index(B) is used to determine the 
index for each position and the index(self, z) is always the first 
occurrence of z in the list self.

My best guess is that the implementation in leoCommands.py is complicated 
by trying to be efficient.  But vnode2allPositions() is not used by 
Leo-Editor core, so there is probably no need for it to be particularly 
efficient.

Brian,

So far all Leo-Editor UNL's have been presented in left-to-right (root to 
target position) order.  Like you I have written code that presents the UNL 
is right-to-left (target position to root) order because usually the target 
position is of much more interest than the root and the right-to-left order 
always places the the target position at the same column (the left side of 
the screen).

Here is a function that guarantees positions Y and Z display as different 
UNL's by appending/prepending the child index for Y or Z (child index in 
brackets)  to the headline of X. 
```
def unlpc(posX, r2l=False):
    """ Append/Prepend the child index to the parent of the last node
    in the UNL.

    Arguments:
        posX:  Target position
        r2l: Right to Left
            False --> UNL in root to posX direction.
            True --> UNL in posX to root direction.

    Returns:
        unlpc: A UNL with the child index of the last node
            in the UNL appended in brackets to the parent's headline.
            If the parent is the hidden root node, then
            the bracketed child index is appended to the
            empty string.

    Suppose a cloned-node has several positions that are
    immediate children of one node.  This function produces
    unique UNL's for each of these positions.

    This function can produce equal UNL's for several cloned-node
    positions if several nodes have the same headline.
    """

    unl = posX.get_UNL(with_file=False, with_index=False)
    unlList = unl.split("-->")
    uLen = len(unlList)
    if uLen == 1:
        parent = ''
        uBefore = list()
    else:
        parent = unlList[-2]
        uBefore = unlList[:-2]
    if r2l:
        unlList = uBefore + [f'[{posX.childIndex()}]' + parent, unlList[-1]]
        unlList.reverse()
        arrow = '<--'
    else:
        unlList = uBefore + [parent + f'[{posX.childIndex()}]', unlList[-1]]
        arrow = '-->'
    return arrow.join(unlList)
```

I hope this helps,
SegundoBob

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/731001bf-9dc3-4ebf-95cb-239432c3ccb0%40googlegroups.com.

Reply via email to