On Mon, 23 Sep 2013 10:00:25 -0500
"Edward K. Ream" <edream...@gmail.com> wrote:

> On Mon, Sep 23, 2013 at 9:15 AM, Terry Brown <terry_n_br...@yahoo.com>wrote:
> 
> > I've run in to this many times, the 'insertBefore' example was just the
> > most recent.
> 
> Your complaint is understandable, but I am not likely to consider a fix
> now, with 4.11b1 so near.

Given how long Leo has survived with its API, I don't think this is
critically urgent :)

> > It seems to me that the API for handling top-level nodes is
> > inconveniently inconsistent with the API for handling non-top-level
> > nodes.
> 
> Maybe, but the underlying vnode methods can't be change now: they are too
> important and too fragile.

I'm not proposing changing anything that exists, including existing
behaviors.

> > What's the simplest way to make it work when invoked on a top level
> > node?  For top level nodes, p.parent() == None.

>     parent = current.parent()
>     if current.hasBack():
>         back = current.getBack()
>         p = back.insertAfter()
>     elif parent:
>         p = parent.insertAsNthChild(0)
>     else:
>         p = current.insertAfter()
>         p.moveToRoot(oldRoot=current)

So if this convenience wrapper was possible, that would be

    p = (p.parent() or c.virtualRootPosition()).insertAsNthChild(p.childIndex())

or maybe

    parent = p.parent() or c.virtualRootPosition()
    p = parent.insertAsNthChild(p.childIndex())

to keep the pylint line length monster at bay.
 
> Yes, this is a bit less elegant than one might hope for, but it's not
> nearly bad enough to worry about, imo.  

I think it would be very useful if it was possible, particularly in
light weight scripts and because it allows people of code without
surprises / the need to know the idiosyncrasies of Leo's tree API.

> In particular, the call to p.moveToRoot handles a lot of details 
> not likely to be handled by a virtual root position.
 
There's the nub, can a specially constructed position work this way?
I'm not familiar enough with positions / vnodes to know.

Cheers -Terry

> Again, see c.insertHeadlineBefore for full details.
> 
> Edward
> 

-- 
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 post to this group, send email to leo-editor@googlegroups.com.
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