Leo's pyflakes and pylint commands can be applied to files that depend on 
the presently selected node.  They first search down c.p's tree, then up 
the tree, looking for @<file> nodes.  If no nodes are found, and c.p is a 
clone, these commands expand the search to the entire tree, looking for an 
@<file> node that has c.p in its tree.

g.findRootWithPredicate now formalizes and regularizes this search 
process.  For example:

    def predicate(p):
        return p.isAnyAtFileNode() and p.h.strip().endswith('.py')
        
    roots = g.findRootsWithPredicate(c, root, predicate)

I added this helper because the rst3 command was not as clever as the 
pylint and pyflakes commands in this regard.  Now it is. It would have been 
unbearable to repeat the pylint/pyflakes code one more time...

Edward

P.S. Here is g.findRootWithPredicate:

def findRootsWithPredicate(c, root, predicate):
    '''
    Commands often want to find one or more **roots**, given a position p.
    A root is the position of any node matching a predicate.
    
    This function formalizes the search order used by the pylint, pyflakes 
and
    the rst3 commands, returning a list of zero or more found roots.
    '''
    roots = set()
    # 1. Search p's tree.
    for p in root.self_and_subtree():
        if predicate(p):
            roots.add(p.copy())
    if roots:
        return list(roots)
    # 2. Look up the tree.
    for p in root.parents():
        if predicate(p):
            return [p.copy()]
    # 3. Expand the search if root is a clone.
    clones = []
    for p in root.self_and_parents():
        if p.isCloned():
            clones.append(p.v)
    if clones:
        for p in c.all_positions():
            if predicate(p):
                # Match if any node in p's tree matches any clone.
                for p2 in p.self_and_subtree():
                    if p2.v in clones:
                        return [p.copy()]
    return []

EKR

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to