Question about cloning nodes

85 views
Skip to first unread message

Joe Orr

unread,
Apr 17, 2018, 8:56:55 AM4/17/18
to leo-editor
Couple of questions about cloning nodes:

On Mac, Ctl+` doesn't work... anyone else having this issue? Is there a workaround?

I have a Leo file with a list of research papers that I'd like to clone and categorize sort into different categories. Is there any way to clone a bunch of nodes at once?

Joe Orr

Edward K. Ream

unread,
Apr 17, 2018, 9:42:38 AM4/17/18
to leo-editor
On Tue, Apr 17, 2018 at 7:56 AM, Joe Orr <joe...@gmail.com> wrote:
Couple of questions about cloning nodes:

On Mac, Ctl+` doesn't work... anyone else having this issue? Is there a workaround?

​I'll look into this today.

Edward

Edward K. Ream

unread,
Apr 17, 2018, 1:09:06 PM4/17/18
to leo-editor
On Tue, Apr 17, 2018 at 8:42 AM, Edward K. Ream <edre...@gmail.com> wrote:

​>
On Mac, Ctl+` doesn't work...


It works for me, with both a Microsoft ergonomic keyboard and the Apple keyboard.

This may be a problem with the overly-intrusive MacOS system-wide key bindings.

I have a half memory that maybe I disabled Ctrl-`, but I don't have any notes
​, and I don't see any evidence for a disabled Ctrl-` binding.​


​>
Is there a workaround?

​Define a new binding.

I have never been able to disable the system binding for Ctrl-H.  I use Ctrl-Shift-H instead. ​


​Alas, ​
Ctrl-H is alarming: it activates the switcher to choose another open window
​, so it briefly looks like Leo has crashed.​


​Edward

Joe Orr

unread,
Apr 18, 2018, 7:52:49 PM4/18/18
to leo-editor
Thanks for checking that, turns out at least on my Mac, Cmd+` works, not Ctrl.

That leaves me with question #2:

I have a node with 120 nodes in it. I want to make a separate node, clone all of the 120 nodes and put in the second node (and then organize them differently).

Any way to clone a bunch of nodes at once?

Joe

Joe Orr

unread,
Apr 18, 2018, 8:21:56 PM4/18/18
to leo-editor
Just realized I can mark a bunch of nodes and then clone. That's faster than individually cloning. 

But if there is a way to mark all nodes in folder, that would also be cool. 

Joe

Edward K. Ream

unread,
Apr 18, 2018, 10:26:29 PM4/18/18
to leo-editor
On Wed, Apr 18, 2018 at 6:52 PM, Joe Orr <joe...@gmail.com> wrote:
Thanks for checking that, turns out at least on my Mac, Cmd+` works, not Ctrl.

That leaves me with question #2:

I have a node with 120 nodes in it. I want to make a separate node, clone all of the 120 nodes and put in the second node (and then organize them differently).

Any way to clone a bunch of nodes at once?

​1. Easy: Select the parent node.  Do mark-subheads, then cffm.

2. More flexible: Use c.cloneFindByPredicate.  Here is tested code:

# Clone all nodes of parent into a new node.
parent = g.findNodeAnywhere(c, 'Test cloneFindByPredicate')
c.cloneFindByPredicate(generator=parent.subtree, predicate=lambda p: True)

HTH.

Edward

Joe Orr

unread,
Apr 19, 2018, 8:52:31 AM4/19/18
to leo-editor
Cool, thanks!

So I've made my folders with cloned nodes, now I need to alphabetize the first folder (can't use the sort command because the node titles have some random numbers at start). Is there a way to move a bunch of nodes at once, like move all marked nodes up?

Joe

Edward K. Ream

unread,
Apr 19, 2018, 12:57:18 PM4/19/18
to leo-editor
​​
On Thu, Apr 19, 2018 at 7:52 AM, Joe Orr <joe...@gmail.com> wrote:

Is there a way to move a bunch of nodes at once, like move all marked nodes up?

​No, there isn't.  There have been numerous requests to support Qt's ability to select multiple nodes at once, but there are conceptual and practical problems in doing so.

A script might be able to detect multiply-selected nodes and act accordingly.  But scripts must be extremely careful when altering multiple nodes, because the positions of nodes change when they move.

For reference, see c.deletePositionsInList. It's not for the faint of heart.

The basic problem is keeping track of to-be-moved nodes. This should work:

- Unmark all nodes: c.clearAllMarked()
- Mark all the the to-be-moved nodes. p.v.setMarked()
- Move one node at a time.
- Unmark the just-moved node. p.v.clearMarked()
- Continue until no more marked nodes exist.
- Redraw the screen: c.redraw()

You could also use the "visited" bit instead of the "marked" bit using c.clearAllVisited(), p.v.setVisited(), and p.v.clearVisited()

Important: the vnode methods are much faster than the position methods because they don't redraw the screen.

Clear?

Edward

Joe Orr

unread,
Apr 19, 2018, 8:07:31 PM4/19/18
to leo-editor
That sound good, but sadly although I've used Leo off and on for 17 years or so, I've never tried the scripting capabilities. Yes, I know I'm missing out, but I'm worried that it would be so cool I'd start playing with it and not get other stuff done.. I'll look into one of these days...

But meanwhile, I realized, thanks to this discussion, that the right way to do this is just to add another Leo Vue directive: @sort. Took me 15 minutes, next will add sort based on params in the node content.

Joe

Edward K. Ream

unread,
Apr 20, 2018, 7:50:43 AM4/20/18
to leo-editor
On Thu, Apr 19, 2018 at 7:07 PM, Joe Orr <joe...@gmail.com> wrote:

But meanwhile, I realized, thanks to this discussion, that the right way to do this is just to add another Leo Vue directive: @sort. Took me 15 minutes, next will add sort based on params in the node content.

​Interesting. There is no @sort directive in Leo itself, but sort-siblings command usually suffices.

Edward
Reply all
Reply to author
Forward
0 new messages