On Sat, Sep 10, 2011 at 8:36 AM, Edward K. Ream <[email protected]> wrote:
> This thread...is intended for general consumption, and I hope it helps Terry
> with his project of adding Blender completions to Leo.
I'll continue with more "careful" posts tomorrow, but now that I am
more familiar with the code and settings and what they do (or don't
do), I'd like to "jump ahead" with some ideas that Terry might use
immediately.
The main thing to know is that Leo's autocompleter *always* tries
Leo-specific completions, and then falls back to ctags/codewise
completions using Ville's codewise module to "make sense" of the
unified database ~/.codewise.db. Again, I'll leave the details of the
codewise magic for another post.
Indeed, ac.get_completions, leoPy.leo::
class AutoCompleterClass-->Helpers-->get_completions & helpers
computes the list of completions as follows::
aList = (
self.get_leo_completions(prefix) or
self.get_codewise_completions(prefix)
)
Again, notice the dog that isn't barking: no settings or other
switches are involved.
Let's look at get_leo_completions. In essence, it is just::
d = self.get_leo_namespace(prefix)
aList = self.attr_matches(prefix,d)
aList.sort()
Only ac.get_leo_namespace is of real interest. Here it is::
def get_leo_namespace (self,prefix):
'''Return an environment in which to evaluate prefix.
Add some common standard library modules as needed.'''
k = self.k
d = {'c':k.c, 'p':k.c.p, 'g':g}
aList = prefix.split('.')
if len(aList) > 1:
name = aList[0]
m = sys.modules.get(name)
if m: d[name]= m
return d
Ok, so here is my idea. The blender 'bpy' module is the "root" of all
blender scripting code. Suppose we add something like the following
code (untested) right after the definition of d::
if self.use_blender_completions:
<< add path to blender's python library to sys.path >>
import bpy
d['bpy'] = bpy
Now Leo should be able to recognize the 'bpy' module just like Leo
recognizes the 'c', 'g' and 'p' objects, and the various Python
modules that are added to the context.
Wouldn't this be an easy way to adding support for Blender autocompletions?
**Important**: very likely, one could do something almost as simple in
order to add Blender support using ctags/codewise. The choice might
be arbitrary, or it may turn out that the codewise way is a bit better
in general. However, patching get_leo_namespace can be done quickly
as a prototype.
We might want to generalize the hack to get_leo_namespace by adding
other useful symbols for Blender programming. Not exactly sure what
they are, but whatever they are it should be easy to support them.
Otoh, perhaps the generality of the ctags/codewise approach will make
further hacks moot.
Terry, what do you think?
Edward
--
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.