Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Thompson <quornian@googlemail.com>2008-08-12 19:17:08 +0400
committerIan Thompson <quornian@googlemail.com>2008-08-12 19:17:08 +0400
commit65d0ef3e746dd43e1f5480cd70434d34cecb6459 (patch)
tree23b030d12833eaeae6681a89f95eadc1a959e89c /release/scripts
parent0410775e2ed739a580a2a7cc7ff4a7ae374c24b1 (diff)
Speed improvements for reading text lines and the option to specify a range for Text.asLines([start[, end]]) Also some tweaks for the plug-in scripts and updates to pydocs.
Diffstat (limited to 'release/scripts')
-rw-r--r--release/scripts/bpymodules/BPyTextPlugin.py9
-rw-r--r--release/scripts/textplugin_imports.py6
-rw-r--r--release/scripts/textplugin_outliner.py14
-rw-r--r--release/scripts/textplugin_suggest.py10
-rw-r--r--release/scripts/textplugin_templates.py2
5 files changed, 25 insertions, 16 deletions
diff --git a/release/scripts/bpymodules/BPyTextPlugin.py b/release/scripts/bpymodules/BPyTextPlugin.py
index 94a2b8be38a..9d33eca9de7 100644
--- a/release/scripts/bpymodules/BPyTextPlugin.py
+++ b/release/scripts/bpymodules/BPyTextPlugin.py
@@ -449,7 +449,7 @@ def parse_text(txt):
desc.set_time()
global _parse_cache
- _parse_cache[hash(txt.name)] = desc
+ _parse_cache[hash(txt)] = desc
return desc
def get_modules(since=1):
@@ -511,9 +511,12 @@ def get_context(txt):
"""
- global CTX_NORMAL, CTX_SINGLE_QUOTE, CTX_DOUBLE_QUOTE, CTX_COMMENT
l, cursor = txt.getCursorPos()
- lines = txt.asLines()[:l+1]
+ lines = txt.asLines(0, l+1)
+
+ # FIXME: This method is too slow in large files for it to be called as often
+ # as it is. So for lines below the 1000th line we do this... (quorn)
+ if l > 1000: return CTX_NORMAL
# Detect context (in string or comment)
in_str = CTX_NORMAL
diff --git a/release/scripts/textplugin_imports.py b/release/scripts/textplugin_imports.py
index 0e32a6fb2a6..ec608243c2b 100644
--- a/release/scripts/textplugin_imports.py
+++ b/release/scripts/textplugin_imports.py
@@ -49,9 +49,7 @@ def main():
immediate = True
pos += 5
for i in range(pos, c):
- if line[i]=='.':
- pos = i+1
- elif not line[i].isalnum() and line[i] != '_':
+ if not line[i].isalnum() and line[i] != '_' and line[i] != '.':
immediate = False
break
@@ -59,7 +57,7 @@ def main():
if immediate:
items = [(m, 'm') for m in get_modules()]
items.sort(cmp = suggest_cmp)
- txt.suggest(items, '')
+ txt.suggest(items, line[pos:c])
return
# Found 'from' earlier, suggest import if not already there
diff --git a/release/scripts/textplugin_outliner.py b/release/scripts/textplugin_outliner.py
index 345361b47d4..3879a2819a5 100644
--- a/release/scripts/textplugin_outliner.py
+++ b/release/scripts/textplugin_outliner.py
@@ -30,23 +30,27 @@ def make_menu(items, eventoffs):
letters.append(c)
break
- dict = {}
+ entries = {}
i = 0
for item in items:
i += 1
c = item[0].lower()
- if not dict.has_key(c): dict[c] = []
- dict[c].append((item, i+eventoffs))
+ entries.setdefault(c, []).append((item, i+eventoffs))
subs = []
for c in letters:
- subs.append((c, dict[c]))
+ subs.append((c, entries[c]))
return subs
def find_word(txt, word):
i = 0
- for line in txt.asLines():
+ txt.reset()
+ while True:
+ try:
+ line = txt.readline()
+ except StopIteration:
+ break
c = line.find(word)
if c != -1:
txt.setCursorPos(i, c)
diff --git a/release/scripts/textplugin_suggest.py b/release/scripts/textplugin_suggest.py
index 0e83e1e8cc7..1e011a2e82d 100644
--- a/release/scripts/textplugin_suggest.py
+++ b/release/scripts/textplugin_suggest.py
@@ -66,6 +66,7 @@ def main():
# Otherwise we suggest globals, keywords, etc.
list = []
pre = get_targets(line, c)
+ desc = get_cached_descriptor(txt)
for k in KEYWORDS:
list.append((k, 'k'))
@@ -73,13 +74,16 @@ def main():
for k, v in get_builtins().items():
list.append((k, type_char(v)))
- for k, v in get_imports(txt).items():
+ for k, v in desc.imports.items():
list.append((k, type_char(v)))
- for k, v in get_defs(txt).items():
+ for k, v in desc.classes.items():
list.append((k, 'f'))
- for k in get_vars(txt):
+ for k, v in desc.defs.items():
+ list.append((k, 'f'))
+
+ for k, v in desc.vars.items():
list.append((k, 'v'))
list.sort(cmp = suggest_cmp)
diff --git a/release/scripts/textplugin_templates.py b/release/scripts/textplugin_templates.py
index 508ede11ddc..25dadf4de54 100644
--- a/release/scripts/textplugin_templates.py
+++ b/release/scripts/textplugin_templates.py
@@ -49,7 +49,7 @@ def main():
return
row, c = txt.getCursorPos()
- line = txt.asLines()[row]
+ line = txt.asLines(row, row+1)[0]
indent=0
while indent<c and (line[indent]==' ' or line[indent]=='\t'):
indent += 1