parent
10abc6661a
commit
e536800327
|
@ -13,6 +13,15 @@ drop table foog;
|
||||||
select cast(plunk as timestamp) from blarg join plarg using(id_what) where x = 3;
|
select cast(plunk as timestamp) from blarg join plarg using(id_what) where x = 3;
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
|
# gwiejgwe gwe gwe gwejig weig weig wegji weg weig wegi wegjiwe gjweig weig
|
||||||
|
# wejig wejgi wejgiwe jgiwe gjiwej gwei gweig jweig jweig wig wejgiewj ge giwej
|
||||||
|
# gweijg weigj weigjwe giwej gwe
|
||||||
|
# 1. gewj gweig weigweigewiiiiiiiiiiiiiiiiiiiii iiiiiiiiiiiii iiiigewigweigwi
|
||||||
|
# iweigiwigigewigewgweigi
|
||||||
|
# 2. gweii XXXXX a e gwejgiwe jiaw jhw
|
||||||
|
# gwe gjiwegij wegiwe jgiwe giwej gweigj wiegjwei gjweig weigj weig jwegi
|
||||||
|
# wejgiwe jgiweg jweigewgj we gwee e e e ee e
|
||||||
|
|
||||||
my $foo = {
|
my $foo = {
|
||||||
#@@:string:mode.sql.Sql
|
#@@:string:mode.sql.Sql
|
||||||
'drop table ',
|
'drop table ',
|
||||||
|
|
157
mode/perl.py
157
mode/perl.py
|
@ -529,95 +529,98 @@ class PerlHashCleanup(Method):
|
||||||
|
|
||||||
class PerlWrapLine(Method):
|
class PerlWrapLine(Method):
|
||||||
'''Wrap Comments and POD'''
|
'''Wrap Comments and POD'''
|
||||||
margin = 80
|
# enumerations for line types
|
||||||
comment_re = re.compile('(#+)( *)(.*)')
|
LT_COMMENT = 1
|
||||||
|
LT_POD = 2
|
||||||
|
|
||||||
|
margin = 80
|
||||||
|
comment_re = re.compile('( *)(#+)( *)(.*)')
|
||||||
|
|
||||||
def _is_newline(self, t):
|
def _is_newline(self, t):
|
||||||
return t.name == 'eol'
|
return t.name == 'eol'
|
||||||
def _is_space(self, t):
|
def _is_space(self, t):
|
||||||
return t.name == 'null' and regex.space.match(t.string)
|
return t.name == 'null' and regex.space.match(t.string)
|
||||||
|
|
||||||
def _detect_line_type(self, w, y):
|
def _detect_line_type(self, w, y):
|
||||||
c = w.logical_cursor()
|
h = w.buffer.highlights[w.mode.name()]
|
||||||
highlighter = w.buffer.highlights[w.mode.name()]
|
|
||||||
ltype = None
|
ltype = None
|
||||||
for t in highlighter.tokens[c.y]:
|
for t in h.tokens[y]:
|
||||||
if self._is_space(t):
|
fqname = t.fqname()
|
||||||
|
if t.name == 'null' or t.name == 'eol':
|
||||||
pass
|
pass
|
||||||
elif t.name == 'comment':
|
elif fqname.startswith('comment'):
|
||||||
if ltype:
|
if ltype and ltype != 'comment':
|
||||||
return None
|
ltype = None
|
||||||
else:
|
break
|
||||||
ltype = 'comment'
|
ltype = self.LT_COMMENT
|
||||||
elif t.name == 'eol':
|
elif fqname.startswith('pod'):
|
||||||
return ltype
|
if ltype and ltype != 'pod':
|
||||||
|
ltype = None
|
||||||
|
break
|
||||||
|
ltype = self.LT_POD
|
||||||
else:
|
else:
|
||||||
return None
|
ltype = None
|
||||||
|
break
|
||||||
|
return ltype
|
||||||
|
|
||||||
|
def _fix_comments(self, c, w):
|
||||||
|
h = w.buffer.highlights[w.mode.name()]
|
||||||
|
y1 = c.y
|
||||||
|
y2 = c.y
|
||||||
|
while y2 < len(w.buffer.lines) - 1:
|
||||||
|
if self._detect_line_type(w, y2 + 1):
|
||||||
|
y2 += 1
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
lines = w.buffer.lines[y1:y2 + 1]
|
||||||
|
m = self.comment_re.match(lines[0])
|
||||||
|
assert m
|
||||||
|
prepend = m.group(1) + m.group(2)
|
||||||
|
rmargin = self.margin - len(prepend)
|
||||||
|
dpad = m.group(3)
|
||||||
|
|
||||||
|
segments = []
|
||||||
|
for line in lines:
|
||||||
|
m = self.comment_re.match(line)
|
||||||
|
assert m
|
||||||
|
pad, data = m.group(3), m.group(4)
|
||||||
|
if segments and pad == dpad and segments[-1][0] == dpad and segments[-1][1]:
|
||||||
|
data = segments.pop(-1)[1] + ' ' + data
|
||||||
|
i = 0
|
||||||
|
while len(pad) + len(data[i:]) > rmargin:
|
||||||
|
while data[i] == ' ':
|
||||||
|
i += 1
|
||||||
|
j = rmargin - len(pad)
|
||||||
|
while j >= 0 and data[i + j] != ' ':
|
||||||
|
j -= 1
|
||||||
|
if j < 0:
|
||||||
|
j = rmargin - len(pad)
|
||||||
|
segments.append([pad, data[i:i + j]])
|
||||||
|
i += j
|
||||||
|
if data:
|
||||||
|
while data[i] == ' ':
|
||||||
|
i += 1
|
||||||
|
segments.append([pad, data[i:]])
|
||||||
|
else:
|
||||||
|
segments.append(['', ''])
|
||||||
|
|
||||||
|
lines2 = [prepend + x[0] + x[1] for x in segments]
|
||||||
|
p1 = Point(0, y1)
|
||||||
|
p2 = Point(len(w.buffer.lines[y2]), y2)
|
||||||
|
w.buffer.delete(p1, p2)
|
||||||
|
w.buffer.insert_lines(p1, lines2)
|
||||||
|
w.set_error("wrapped comment lines %d-%d" % (y1 + 1, y2 + 1))
|
||||||
|
|
||||||
|
def _fix_pod(self, c, w):
|
||||||
|
w.set_error("pod wrapping not yet supported")
|
||||||
|
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
c = w.logical_cursor()
|
c = w.logical_cursor()
|
||||||
ltype = self._detect_line_type(w, c.y)
|
ltype = self._detect_line_type(w, c.y)
|
||||||
if ltype == 'comment':
|
if ltype == self.LT_COMMENT:
|
||||||
return self._fix_comments(c, w)
|
self._fix_comments(c, w)
|
||||||
elif ltype == 'pod':
|
elif ltype == self.LT_POD:
|
||||||
return self._fix_pod(c, w)
|
self._fix_pod(c, w)
|
||||||
else:
|
else:
|
||||||
w.set_error("did not detect comment or pod lines")
|
w.set_error("did not detect comment or pod lines")
|
||||||
return
|
|
||||||
def _fix_comments(self, c, w):
|
|
||||||
w.set_error("comment!")
|
|
||||||
def _fix_pod(self, c, w):
|
|
||||||
pass
|
|
||||||
#class PerlWrapLine(Method):
|
|
||||||
# '''Wrap lines, comments, POD'''
|
|
||||||
# margin = 80
|
|
||||||
# comment_re = re.compile('^( *)(#+)( *)([^ ].*)$')
|
|
||||||
# def _execute(self, w, **vargs):
|
|
||||||
# pcursor = w.physical_cursor()
|
|
||||||
# r = w.get_region(pcursor)
|
|
||||||
# if r is None:
|
|
||||||
# return
|
|
||||||
#
|
|
||||||
# t = r[4]
|
|
||||||
# if t == 'pod':
|
|
||||||
# assert False, 'POD: %s' % repr(r)
|
|
||||||
# elif t == 'comment':
|
|
||||||
# self._wrap_comment(w)
|
|
||||||
# else:
|
|
||||||
# return
|
|
||||||
#
|
|
||||||
# def _wrap_comment(self, w):
|
|
||||||
# l = w.logical_cursor()
|
|
||||||
# m = self.comment_re.match(w.buffer.lines[l.y])
|
|
||||||
# if not m:
|
|
||||||
# assert False, 'no match oh geez'
|
|
||||||
#
|
|
||||||
# pad = m.group(1) + m.group(2) + m.group(3)
|
|
||||||
# data = m.group(4) + ' '
|
|
||||||
#
|
|
||||||
# start = l.y
|
|
||||||
# end = l.y + 1
|
|
||||||
#
|
|
||||||
# while end < len(w.buffer.lines):
|
|
||||||
# m = self.comment_re.match(w.buffer.lines[end])
|
|
||||||
# if m:
|
|
||||||
# data += m.group(4) + ' '
|
|
||||||
# end += 1
|
|
||||||
# else:
|
|
||||||
# break
|
|
||||||
#
|
|
||||||
# words = [word for word in data.split() if word]
|
|
||||||
#
|
|
||||||
# lines = [pad]
|
|
||||||
# for word in words:
|
|
||||||
# if len(lines[-1]) == len(pad):
|
|
||||||
# lines[-1] += word
|
|
||||||
# elif len(lines[-1]) + 1 + len(word) <= self.margin:
|
|
||||||
# lines[-1] += ' ' + word
|
|
||||||
# else:
|
|
||||||
# lines.append(pad + word)
|
|
||||||
#
|
|
||||||
# # remove the old text and add the new
|
|
||||||
# start_p = Point(0, start)
|
|
||||||
# end_p = Point(len(w.buffer.lines[end-1]), end-1)
|
|
||||||
# w.kill(start_p, end_p)
|
|
||||||
# w.insert(start_p, '\n'.join(lines))
|
|
||||||
|
|
Loading…
Reference in New Issue