Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Is there a way to ignore a node in an outline

45 views
Skip to first unread message

Karthik Suresh

unread,
Mar 9, 2025, 10:33:33 AMMar 9
to leo-editor
Hi,

I'm using Leo to develop small programs and occasionally it's useful to copy a node and work on a new version of a function to try it out. I know I can use @ to comment out all the code in the old node so it's ignored, but I was wondering if there was an equivalent approach that could simply ignore one of the nodes in an outline so I could swap between one and the other? I couldn't find an obvious answer in the documentation.

Thanks,
Karthik

Jacob Peck

unread,
Mar 9, 2025, 11:57:35 AMMar 9
to leo-e...@googlegroups.com, leo-editor
One way in Python would be, in a parent node to both your old and new nodes:

if False:
  << old node name >>
else:
  << new node name >>

(Using << section references >> to pull in the contents of those nodes at the proper indentation levels.)

The node isn’t truly *ignored*, but since the False is effectively a constant in this situation, it will never be executed.

I use this pattern all the time when refactoring things. I believe Edward uses it in the Leo code base quite frequently as well.

Jake


On Mar 9, 2025, at 10:33 AM, Karthik Suresh <k.su...@jayamony.co.uk> wrote:

Hi,

I'm using eLeo to develop small programs and occasionally it's useful to copy a node and work on a new version of a function to try it out. I know I can use @ to comment out all the code in the old node so it's ignored, but I was wondering if there was an equivalent approach that could simply ignore one of the nodes in an outline so I could swap between one and the other? I couldn't find an obvious answer in the documentation.

Thanks,
Karthik

--
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+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/leo-editor/d076b698-f109-43a7-96b8-77f868547dc7n%40googlegroups.com.

Thomas Passin

unread,
Mar 9, 2025, 11:58:22 AMMar 9
to leo-editor
In what way do you want to ignore a node?  Do you mean you want to run the code but use that other node instead of the original one?  Is the node part of an external file (i.e., @file, @clean)?

Sometimes I just rename a function/method and use the new version in a new node with the original name.  With the different name, the old one doesn't get called.  That's not much different from using @/@c, is it?

With an external file, if the changes are larger than I want to deal with using @/@c, I may copy the @file to a new @file tree with a different name, and make my changes there.

Karthik Suresh

unread,
Mar 9, 2025, 1:41:06 PMMar 9
to leo-editor
Thanks - both are good suggestions. The reason I was thinking this would be useful is that I create a function to do something - say def get_details(). Then I want to try this a different way, but so I create a copy of the node, tell Leo to ignore the first one, and then change the content of the function in the second. Nothing else changes, but I can test the new one without having to lose the old version. I could comment it, but then the final code ends up with a large commented section with the old code. I could also use conditional sections to manage this, but that again requires an additional step. I just thought that if there was an option to have an @ignore in the node, then Leo could just skip over that one and process the other nodes as normal - and that could be useful if we wanted to try three or four variants of a function before settling on a final one.

Edward K. Ream

unread,
Mar 17, 2025, 3:33:22 PMMar 17
to leo-editor
On Sunday, March 9, 2025 at 9:33:33 AM UTC-5 k.su...@jayamony.co.uk wrote:

> I'm using Leo to develop small programs and occasionally it's useful to copy a node and work on a new version of a function to try it out. I know I can use @ to comment out all the code in the old node so it's ignored, but I was wondering if there was an equivalent approach that could simply ignore one of the nodes in an outline so I could swap between one and the other? I couldn't find an obvious answer in the documentation.
...
> The reason I was thinking this would be useful is that I create a function to do something...Then I want to try this a different way, but so I create a copy of the node, tell Leo to ignore the first one, and then change the content of the function in the second.

Jake's suggestion seems like the best approach. It's best not to try to be overly clever.

When I start on a major refactoring I often define a constant in leoGlobals.py, say NEW. Then I refactor with tests on g.NEW.

This seems like the full answer to your original question.  However, I'd like mention a completely different way of "customizing" nodes. The rst3 command supports filters that allow scripts to chose which parts of a node (and its subtree) to include. This feature gives the effect of the often-requested "half clone" feature. See this post and the example_rst_filter plugin.

Edward
Reply all
Reply to author
Forward
0 new messages