f3a602d: editFileCommands.compareTrees, kinda like c.recursiveImport

15 views
Skip to first unread message

Edward K. Ream

unread,
Jul 23, 2015, 10:40:43 AM7/23/15
to leo-editor
efc.compareTrees is a helper script, not a command.  I am using it to compare corresponding classes in viewrendered.py and viewrendered2.py.  Here is the code from leoPlugins.leo:

p1 = g.findNodeAnywhere(c, 'class ViewRenderedController (QWidget) (vr)')
p2
= g.findNodeAnywhere(c, 'class ViewRenderedController (QWidget) (vr2)')
assert p1 and p2
tag
= 'compare vr1 & vr2'
c
.editFileCommands.compareTrees(p1, p2, tag)


This creates a tree whose root headline is the given tag.  The format of tree is much like "Recovered Nodes" trees.  That is, the body text of child nodes show the diff produced by difflib.unified_diff. Grand children are clones of the compared nodes, or a single clone if a node in one class has no analog in the other class.

At present, this code is not undoable.  The workaround is simply to cut the node ;-)

It might be good to create a command based on this code, but this isn't real important, imo.

As I write this, I realize that documenting c.recursiveImport is important.  It should be mentioned in the scripting miscellany. I'll be documenting efc.compareTrees there as well.

The code finds corresponding nodes by munging headlines.  It works well enough for vr and vr2, but the munging could be improved to find more corresponding nodes.  Otoh, I expect to rearrange the resulting tree by hand while studying the results, so getting close is all that is really required.

This code much better than trying to used multiple body editors to compare code.  The combination of diff-oriented text combined with clones of the corresponding nodes is pretty much exactly right.

Edward
Reply all
Reply to author
Forward
0 new messages