Why would you delete nodes that have .h but not .b?

Sent from my Windows Phone
From: Edward K. Ream
Sent: 6/2/2012 5:50 PM
To: leo-editor
Subject: Re: Rev 5378: cleanup-imported-nodes script in scripts.leo &
an Aha
On Jun 2, 6:52 am, "Edward K. Ream" <[email protected]> wrote:

> In short, Leo's node structure drastically simplifies the patterns to
> be discovered.  That's the insight.

With this insight, I am heavily revising the recursive import script I
use to study other programs.

The script now contains a suite of post-processing fixes.  Examples:

- Replacing backslashes with forward slashes in headlines.
- Removing empty nodes.
- Adding @path directives that reduce the needed path specifiers in
descendant nodes.
- Adding @file to nodes or replacing @file with @@file.

Here is the fixer that removes empty nodes.  It uses the simplest
possible algorithm so as not to run into problems with changing a tree
inside an iterator, and also to ensure that parent nodes are deleted
if all children are deleted. It probably takes 0.1 sec or less.

    def remove_empty_nodes (self,c,p):
        # Restart the scan once a node is deleted.
        root = p.copy()
        changed = True
        while changed:
            changed = False
            for p in root.self_and_subtree():
                if not p.b and not p.hasChildren():
                    g.trace('** deleting',p.h)
                    p.doDelete()
                    c.selectPosition(root)
                    changed = True
                    break

The revolution in Leo scripting continues...

EKR

-- 
You received this message because you are subscribed to the Google
Groups "leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to