As I was writing some code and refactoring it into multiple functions,
I found it easiest to just create the extracted functions in the same
body as the original, larger function.  Then I wanted the functions to
each be in a node by themselves.  Doing it manually seemed tedious and
I wondered how Leo's already existing import functionality could be
used to automate it.  Here is the code I came up with:

    # Find the scanner/importer function for the current language
    # Until I research how to auto-detect, just hard-code for python
    ext = ".py"
    i = c.importCommands.importDispatchDict.get(ext)

    if i:
        # Insert the splitted/imported code as sibling to original
        p2 = p.insertAfter()
        p2.h = p.h + " (imported)"
        i(p.b, p2)
    else:
        g.es ("Importer not found for extension '%s'" % ext)
    c.redraw()

Any pointers on how I can automatically detect the proper extension of
the current node?

Brian

-- 
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