a bunch of fixes to c-tabber and stacktabber2
--HG-- branch : pmacs2
This commit is contained in:
parent
16d55b4bc9
commit
72bdc0915a
19
mode/c.py
19
mode/c.py
|
@ -100,29 +100,34 @@ class CTabber2(tab.StackTabber2):
|
||||||
end_free_tokens = {'c.string.end': 'c.string.start'}
|
end_free_tokens = {'c.string.end': 'c.string.start'}
|
||||||
start_macro_tokens = {'c.macro.start': 'c.macro.end'}
|
start_macro_tokens = {'c.macro.start': 'c.macro.end'}
|
||||||
end_macro_tokens = {'c.macro.end': 'c.macro.start'}
|
end_macro_tokens = {'c.macro.end': 'c.macro.start'}
|
||||||
def is_base(self, y):
|
def _is_base(self, y):
|
||||||
if y == 0:
|
if y == 0:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# if there are no tokens we don't really have any info
|
||||||
tokens = self._get_tokens(y)
|
tokens = self._get_tokens(y)
|
||||||
|
if not tokens:
|
||||||
|
return False
|
||||||
|
|
||||||
# this assumes that people aren't gonna use these macros inside of
|
# this assumes that people aren't gonna use these macros inside of
|
||||||
# blocks, which is probably ok.
|
# blocks, which is probably ok.
|
||||||
t = tokens[0]
|
t = tokens[0]
|
||||||
if t.fqmatchs('c.macro.start', '#define', '#include'):
|
if t.fqmatchs('c.macro.start', ('#define', '#include')):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# detecting function declarations is annoying; this assumes that people
|
# detecting function declarations is annoying; this assumes that people
|
||||||
# won't put a variable type and name on different lines, but that they
|
# won't put a variable type and name on different lines, but that they
|
||||||
# might do that for function return type and name.
|
# might do that for function return type and name.
|
||||||
#
|
#
|
||||||
# unfortunately, valid function return types might include any of the
|
# unfortunately, valid function return types might include any of the
|
||||||
# four types of tokens below
|
# types of tokens below
|
||||||
decl = False
|
decl = False
|
||||||
for t in tokens:
|
for t in tokens:
|
||||||
if t.isa('c.keyword', 'c.identifier', 'c.type'):
|
if decl and self._is_ignored(t):
|
||||||
|
pass
|
||||||
|
elif t.isa('c.keyword', 'c.identifier', 'c.type'):
|
||||||
decl = True
|
decl = True
|
||||||
continue
|
elif decl and t.name == 'c.function':
|
||||||
if decl and t.name == 'c.function':
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
decl = False
|
decl = False
|
||||||
|
|
9
tab.py
9
tab.py
|
@ -386,6 +386,11 @@ class StackTabber2(Tabber):
|
||||||
if self.end_at_eof:
|
if self.end_at_eof:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# ok, if we are closing a block then this will end a "single-statement"
|
||||||
|
# block. e.g. else switch() { ... }
|
||||||
|
if t.string in self.close_scope_tokens.get(t.fqname(), set()):
|
||||||
|
self._pop('control')
|
||||||
|
|
||||||
# if we do want implicit continuation, see if we need it.
|
# if we do want implicit continuation, see if we need it.
|
||||||
name, s = t.fqname(), t.string
|
name, s = t.fqname(), t.string
|
||||||
top = self._peek()
|
top = self._peek()
|
||||||
|
@ -406,7 +411,8 @@ class StackTabber2(Tabber):
|
||||||
if i == 0 and self.stack and self.stack[-1].name == 'continue':
|
if i == 0 and self.stack and self.stack[-1].name == 'continue':
|
||||||
self.stack.pop()
|
self.stack.pop()
|
||||||
if t.string in self.open_scope_tokens.get(t.name, set()):
|
if t.string in self.open_scope_tokens.get(t.name, set()):
|
||||||
self._pop_while('continue', 'control')
|
#self._pop_while('continue', 'control')
|
||||||
|
self._pop_while('continue')
|
||||||
if i == 0 and t.string in self.open_scope_tokens.get(t.name, set()):
|
if i == 0 and t.string in self.open_scope_tokens.get(t.name, set()):
|
||||||
self._save_curr_level()
|
self._save_curr_level()
|
||||||
|
|
||||||
|
@ -465,4 +471,5 @@ class StackTabber2(Tabber):
|
||||||
# handle control keywords
|
# handle control keywords
|
||||||
if i == start:
|
if i == start:
|
||||||
self._save_curr_level()
|
self._save_curr_level()
|
||||||
|
self._pop_while('continue');
|
||||||
self._append('control', name, self._get_next_level(), y)
|
self._append('control', name, self._get_next_level(), y)
|
||||||
|
|
Loading…
Reference in New Issue