Here is a script to replace body.x with body.wrapper.x for all x in the 
WrapperAPI except __init__.

The script is *not undoable* to save massive amounts of memory.

This is bleeding-edge code: please run on an already-saved .leo file, and 
take all other reasonable precautions.

If replace is False, it will just report the changes to be made.

import leo.core.leoFrame as leoFrame
replace = False
aList = sorted([z for z in dir(leoFrame.WrapperAPI) if not 
z.startswith('__')])
# print('\n'.join(aList))
nodes = 0
for p in c.all_unique_positions():
    s = p.b
    nodes += 1
    for target in aList:
        i = 0
        pattern = 'body.' + target
        while True:
            i = s.find(pattern,i)
            if i == -1:
                break
            if g.match_word(s,i,pattern):
                print('found in %s at index %4s: %s' % (p.h,i,pattern))
                i1,i2 = g.getLine(s,i)
                print(s[i1:i2].rstrip())
                if replace:
                    j = i + len('body.')
                    p.b = s = s[:j] + 'wrapper.' + s[j:]
                    i += len('wrapper.') + len(pattern)
                else:
                    i += len(pattern)
            else:
                i += len(pattern)
print('searched %s nodes' % nodes)

HTH.  Please report any problems.

Edward

-- 
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 http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to