2008-03-17 03:16:15 -04:00
|
|
|
import os, commands, re, sets, tempfile
|
|
|
|
from subprocess import Popen, PIPE, STDOUT
|
|
|
|
|
|
|
|
import buffer, default, dirutil, regex, util, window
|
|
|
|
from point import Point
|
|
|
|
|
|
|
|
from method import DATATYPES, Method, Argument
|
|
|
|
|
2008-05-12 18:12:56 -04:00
|
|
|
class DumpContext(Method):
|
|
|
|
'''debug context'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
lines = []
|
|
|
|
if w.mode.context:
|
|
|
|
for i in range(0, len(w.mode.context.namelines)):
|
|
|
|
lines.append("LINE %d: %r" % (i + 1, repr(w.mode.context.namelines[i])))
|
|
|
|
else:
|
|
|
|
lines.append("no context")
|
|
|
|
output = "\n".join(lines)
|
|
|
|
w.application.data_buffer("context-dump", output, switch_to=True)
|
|
|
|
|
2008-03-17 03:16:15 -04:00
|
|
|
class DumpRegions(Method):
|
|
|
|
'''debug region highlighting'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
lines = []
|
2008-05-03 16:22:12 -04:00
|
|
|
for hr in w.application.highlighted_ranges:
|
|
|
|
(w, p1, p2, fg, bg) = hr
|
2008-03-17 03:16:15 -04:00
|
|
|
lines.append("%r %s %s" % (w, p1, p2))
|
|
|
|
output = "\n".join(lines)
|
|
|
|
w.application.data_buffer("region-dump", output, switch_to=True)
|
|
|
|
|
|
|
|
class DumpMarkers(Method):
|
|
|
|
'''Dump all tab markers (tab debugging)'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
lines = []
|
|
|
|
if w.mode.tabber:
|
|
|
|
keys = w.mode.tabber.lines.keys()
|
|
|
|
keys.sort()
|
|
|
|
for i in keys:
|
|
|
|
line = w.mode.tabber.lines[i]
|
2008-05-12 18:12:56 -04:00
|
|
|
lines.append("LINE %d: %r" % (i + 1, line))
|
2008-03-17 03:16:15 -04:00
|
|
|
lines.append(" %s" % repr(w.mode.tabber.record[i]))
|
|
|
|
else:
|
|
|
|
lines.append("no tokens")
|
|
|
|
output = "\n".join(lines)
|
|
|
|
w.application.data_buffer("marker-dump", output, switch_to=True)
|
|
|
|
|
|
|
|
class DumpTokens(Method):
|
|
|
|
'''Dump all lexical tokens (syntax highlighting debugging)'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
modename = w.mode.name()
|
|
|
|
lines = []
|
|
|
|
if modename in w.buffer.highlights:
|
|
|
|
tokens = w.buffer.highlights[modename].tokens
|
|
|
|
for i in range(0, len(tokens)):
|
2008-05-12 18:12:56 -04:00
|
|
|
lines.append("LINE %d" % i + 1)
|
2008-03-17 03:16:15 -04:00
|
|
|
group = tokens[i]
|
|
|
|
for token in group:
|
|
|
|
fqname = token.fqname()
|
|
|
|
p1 = Point(token.x, token.y)
|
|
|
|
if token.parent is None:
|
|
|
|
pcoord = ''
|
|
|
|
else:
|
|
|
|
pcoord = '[%d, %d]' % (token.parent.x, token.parent.y)
|
|
|
|
if fqname in w.mode.ghist and p1 in w.mode.ghist[fqname]:
|
|
|
|
g = '[' + w.mode.ghist[fqname][p1].name() + ']'
|
|
|
|
else:
|
|
|
|
g = ''
|
|
|
|
fields = (str(p1), pcoord, token.fqname(), g, token.string)
|
|
|
|
lines.append(' %-10s %-10s %-20s %-10s %r' % fields)
|
|
|
|
else:
|
|
|
|
lines.append("no tokens")
|
|
|
|
output = "\n".join(lines)
|
|
|
|
w.application.data_buffer("token-dump", output, switch_to=True)
|
|
|
|
|
|
|
|
class GetToken(Method):
|
|
|
|
'''View type and data of the "current" token'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
token = w.get_token()
|
|
|
|
if token is None:
|
|
|
|
w.set_error('No Token')
|
|
|
|
else:
|
|
|
|
w.set_error('Token: %r (%s)' % (token.string, token.fqname()))
|
|
|
|
|
|
|
|
class TokenComplete(Method):
|
|
|
|
'''Complete token names based on other tokens in the buffer'''
|
|
|
|
name_overrides = {}
|
|
|
|
def _min_completion(self, w, t):
|
|
|
|
h = w.get_highlighter()
|
|
|
|
minlen = None
|
|
|
|
if t.name in self.name_overrides:
|
|
|
|
ok = name_overrides[t.name]
|
|
|
|
else:
|
|
|
|
ok = (t.name,)
|
|
|
|
|
|
|
|
strings = {}
|
|
|
|
for line in h.tokens:
|
|
|
|
for t2 in line:
|
|
|
|
if t2 is t:
|
|
|
|
continue
|
|
|
|
elif False and t2.name not in ok:
|
|
|
|
continue
|
|
|
|
elif t2.string.startswith(t.string):
|
|
|
|
strings[t2.string] = 1
|
|
|
|
if minlen is None:
|
|
|
|
minlen = len(t2.string)
|
|
|
|
else:
|
|
|
|
minlen = min(minlen, len(t2.string))
|
|
|
|
|
|
|
|
strings = strings.keys()
|
|
|
|
if not strings:
|
|
|
|
return ([], t.string)
|
|
|
|
|
|
|
|
i = len(t.string)
|
|
|
|
while i < minlen:
|
|
|
|
c = strings[0][i]
|
|
|
|
for s in strings:
|
|
|
|
if s[i] != c:
|
|
|
|
return (strings, strings[0][:i])
|
|
|
|
i += 1
|
|
|
|
return (strings, strings[0][:minlen])
|
|
|
|
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
t = w.get_token2()
|
|
|
|
|
|
|
|
if t is None:
|
|
|
|
w.set_error("No token to complete!")
|
|
|
|
return
|
|
|
|
elif regex.reserved_token_names.match(t.name):
|
|
|
|
w.set_error("Will not complete reserved token")
|
|
|
|
return
|
|
|
|
|
|
|
|
(candidates, result) = self._min_completion(w, t)
|
|
|
|
|
|
|
|
if candidates:
|
|
|
|
p1 = Point(t.x, t.y)
|
|
|
|
p2 = Point(t.end_x(), t.y)
|
|
|
|
w.buffer.delete(p1, p2)
|
|
|
|
w.insert_string(p1, result)
|
|
|
|
|
|
|
|
if not candidates:
|
|
|
|
w.set_error("No completion: %r" % result)
|
|
|
|
elif len(candidates) == 1:
|
|
|
|
w.set_error("Unique completion: %r" % result)
|
|
|
|
elif result in candidates:
|
|
|
|
w.set_error("Ambiguous completion: %r" % candidates)
|
|
|
|
else:
|
|
|
|
w.set_error("Partial completion: %r" % candidates)
|
|
|
|
|
|
|
|
class OpenConsole(Method):
|
|
|
|
'''Evaluate python expressions (for advanced use and debugging only)'''
|
|
|
|
def execute(self, w, **vargs):
|
|
|
|
a = w.application
|
|
|
|
if not a.has_buffer_name('*Console*'):
|
|
|
|
b = buffer.ConsoleBuffer()
|
|
|
|
a.add_buffer(b)
|
|
|
|
window.Window(b, a)
|
|
|
|
b = a.bufferlist.get_buffer_by_name('*Console*')
|
|
|
|
if a.window().buffer is not b:
|
|
|
|
a.switch_buffer(b)
|
|
|
|
f = lambda x: None
|
|
|
|
w.application.open_mini_buffer('>>> ', f, self, None, 'consolemini')
|