bugfix for perl mode and TABBING

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-06-20 21:26:33 +00:00
parent e7c656de45
commit 7d2720f497
5 changed files with 102 additions and 24 deletions

View File

@ -127,10 +127,12 @@ sub build_resource_manager {
}
}
foo()
unless(1);
sub blah {
foo()
unless(1);
}
print 'hi\n';
print 'hi\n';
# this gets an array of hash references, each of which represents a userdata alias
# it stores the result in $self->{aliases}

View File

@ -517,6 +517,17 @@ class InsertSpace(Method):
'''Insert space into buffer at the cursor'''
def _execute(self, w, **vargs):
w.insert_string_at_cursor(' ')
class GetIndentionLevel(Method):
'''Calculate the indention level for this line'''
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
if not w.mode.tabber:
w.application.set_error('No tabber available')
return
else:
i = w.mode.tabber.get_level(cursor.y)
w.application.set_error('Indention level: %r' % i)
class InsertTab(Method):
'''Insert tab into buffer, or tabbify line, depending on mode'''
def _execute(self, w, **vargs):

View File

@ -94,7 +94,7 @@ class PerlGrammar(Grammar):
# some basic stuff
#PatternRule(name=r'delimiter', pattern=r",|;|->|=>|=|\?|(?<!:):(?!=:)"),
PatternRule(name=r'delimiter', pattern=r"[=\?(){}\[\]]|->|=>|(?<!:):(?!=:)"),
PatternRule(name=r'delimiter', pattern=r"[,;=\?(){}\[\]]|->|=>|(?<!:):(?!=:)"),
PatternRule(name=r'operator', pattern=r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule(name=r'operator', pattern=r"\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|=~|!~|!=|%|!|\."),
PatternRule(name=r'bareword', pattern=r'(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*')

103
tab2.py
View File

@ -16,7 +16,7 @@ class Tabber:
def get_next_left_token(self, y, i):
tokens = self.get_tokens(y)
assert i >= 0 and i < len(tokens)
for j in range(0, i):
for j in range(1, i):
m = regex.whitespace.match(tokens[i - j].string)
if not m:
return tokens[i - j]
@ -112,37 +112,104 @@ class StackTabber(Tabber):
s = token.string
if token.name == self.mode.closetoken and s in self.mode.closetags:
currlvl = self._handle_open_token(currlvl, y, i)
elif token.name == self.mode.opentoken and s in self.mode.opentags:
currlvl = self._handle_close_token(currlvl, y, i)
elif token.name == self.mode.opentoken and s in self.mode.opentags:
currlvl = self._handle_open_token(currlvl, y, i)
else:
currlvl = self._handle_other_token(currlvl, y, i)
return currlvl
def _handle_open_token(self, currlvl, y, i):
token = self.get_token(y, i)
s1 = token.string
if not self.markers:
raise Exception, "unmatched closing token %r" % s1
s2 = self.markers[-1].name
if s1 == self.mode.opentags[s2]:
del self.markers[-1]
if self.is_leftmost_token(y, i):
currlvl = self.get_curr_level()
else:
raise Exception, "mismatched closing tag %r vs %r" % (s2, s1)
return currlvl
def _handle_close_token(self, currlvl, y, i):
token = self.get_token(y, i)
rtoken = self.get_next_right_token(y, i)
if rtoken is None:
level = self.get_curr_level() + 4
else:
level = rtoken.x
self.markers.append(Marker(token.string, level))
self._append(token.string, level)
return currlvl
def _handle_close_token(self, currlvl, y, i):
token = self.get_token(y, i)
s1 = token.string
if not self.markers:
raise Exception, "unmatched closing token %r" % s1
s2 = self.markers[-1].name
if s1 == self.mode.opentags[s2]:
self._pop()
if self.is_leftmost_token(y, i):
currlvl = self.get_curr_level()
#else:
# raise Exception, "hmmmm: %r" % self.get_next_left_token(y, i)
else:
raise Exception, "mismatched closing tag %r vs %r" % (s2, s1)
return currlvl
def _handle_other_token(self, currlvl, y, i):
return currlvl
def _append(self, name, level):
self.markers.append(Marker(name, level))
def _pop(self):
self.markers.pop(-1)
def _opt_append(self, name, level):
if self.markers and self.markers[-1].name == name:
pass
else:
self._append(name, level)
def _opt_pop(self, *names):
if self.markers and self.markers[-1].name in names:
self.markers.pop(-1)
class PerlTabber(StackTabber):
pass
def is_base(self, y):
if y == 0:
return True
highlighter = self.mode.window.buffer.highlights[self.mode.name()]
if not highlighter.tokens[y]:
return False
t = highlighter.tokens[y][0]
if t.name == 'keyword' and t.string == 'sub':
return True
return False
def _handle_open_token(self, currlvl, y, i):
currlvl = StackTabber._handle_open_token(self, currlvl, y, i)
return currlvl
def _handle_close_token(self, currlvl, y, i):
self._opt_pop('cont')
currlvl = StackTabber._handle_close_token(self, currlvl, y, i)
token = self.get_token(y, i)
if token.string == '}':
self._opt_pop('cont')
elif self.is_rightmost_token(y, i):
self._opt_append('cont', currlvl + 4)
return currlvl
def _handle_other_token(self, currlvl, y, i):
token = self.get_token(y, i)
fqname = token.fqname()
if fqname == 'delimiter' and token.string == ';':
self._opt_pop('cont')
elif fqname == 'heredoc.start':
self._opt_append('heredoc', None)
elif fqname == 'heredoc.end':
self._opt_pop('heredoc')
self._opt_pop('cont')
elif fqname == 'pod.start':
self._opt_append('pod', None)
elif fqname == 'pod.end':
self._opt_pop('pod')
currlvl = 0
elif fqname == 'string.start':
self._opt_append('string', None)
elif fqname == 'string.end':
self._opt_pop('string')
if self.is_rightmost_token(y, i):
self._opt_append('cont', currlvl + 4)
if self.is_rightmost_token(y, i):
if(not fqname.startswith('pod') and
not fqname.startswith('heredoc') and
not fqname.startswith('string') and
not fqname.startswith('endblock') and
not fqname == 'comment' and
not fqname == 'null' and
token.string not in ('}', ';', '(', '{', '[', ',')):
self._opt_append('cont' % fqname, currlvl + 4)
return currlvl

View File

@ -54,8 +54,6 @@ class PerlTabber(tab.TokenStackTabber):
self.stack_pop_all_const("cont")
else:
pass
elif s == "=" and next_token is None:
self.stack_append_const("cont")
elif s == ";":
self.stack_pop_all_const("cont")
elif name == "heredoc":