3 Name: 'Suggest All | Ctrl Space'
7 Tooltip: 'Performs suggestions based on the context of the cursor'
10 # Only run if we have the required modules
13 from BPyTextPlugin import *
19 def check_membersuggest(line, c):
20 pos = line.rfind('.', 0, c)
23 for s in line[pos+1:c]:
24 if not s.isalnum() and s != '_':
28 def check_imports(line, c):
29 pos = line.rfind('import ', 0, c)
31 for s in line[pos+7:c]:
32 if not s.isalnum() and s != '_':
35 pos = line.rfind('from ', 0, c)
37 for s in line[pos+5:c]:
38 if not s.isalnum() and s != '_':
44 txt = bpy.data.texts.active
48 line, c = current_line(txt)
50 # Check we are in a normal context
51 if get_context(txt) != CTX_NORMAL:
54 # Check the character preceding the cursor and execute the corresponding script
56 if check_membersuggest(line, c):
57 import textplugin_membersuggest
58 textplugin_membersuggest.main()
61 elif check_imports(line, c):
62 import textplugin_imports
63 textplugin_imports.main()
66 # Otherwise we suggest globals, keywords, etc.
68 targets = get_targets(line, c)
69 desc = get_cached_descriptor(txt)
74 for k, v in get_builtins().items():
75 list.append((k, type_char(v)))
77 for k, v in desc.imports.items():
78 list.append((k, type_char(v)))
80 for k, v in desc.classes.items():
83 for k, v in desc.defs.items():
86 for k, v in desc.vars.items():
89 list.sort(cmp = suggest_cmp)
90 txt.suggest(list, targets[-1])
92 # Check we are running as a script and not imported as a module
93 if __name__ == "__main__" and OK: