a bunch of fixes to c-tabber and stacktabber2
--HG-- branch : pmacs2
This commit is contained in:
parent
16d55b4bc9
commit
72bdc0915a
17
mode/c.py
17
mode/c.py
|
@ -100,15 +100,19 @@ class CTabber2(tab.StackTabber2):
|
|||
end_free_tokens = {'c.string.end': 'c.string.start'}
|
||||
start_macro_tokens = {'c.macro.start': 'c.macro.end'}
|
||||
end_macro_tokens = {'c.macro.end': 'c.macro.start'}
|
||||
def is_base(self, y):
|
||||
def _is_base(self, y):
|
||||
if y == 0:
|
||||
return True
|
||||
|
||||
# if there are no tokens we don't really have any info
|
||||
tokens = self._get_tokens(y)
|
||||
if not tokens:
|
||||
return False
|
||||
|
||||
# this assumes that people aren't gonna use these macros inside of
|
||||
# blocks, which is probably ok.
|
||||
t = tokens[0]
|
||||
if t.fqmatchs('c.macro.start', '#define', '#include'):
|
||||
if t.fqmatchs('c.macro.start', ('#define', '#include')):
|
||||
return True
|
||||
|
||||
# detecting function declarations is annoying; this assumes that people
|
||||
|
@ -116,13 +120,14 @@ class CTabber2(tab.StackTabber2):
|
|||
# might do that for function return type and name.
|
||||
#
|
||||
# unfortunately, valid function return types might include any of the
|
||||
# four types of tokens below
|
||||
# types of tokens below
|
||||
decl = False
|
||||
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
|
||||
continue
|
||||
if decl and t.name == 'c.function':
|
||||
elif decl and t.name == 'c.function':
|
||||
break
|
||||
else:
|
||||
decl = False
|
||||
|
|
9
tab.py
9
tab.py
|
@ -386,6 +386,11 @@ class StackTabber2(Tabber):
|
|||
if self.end_at_eof:
|
||||
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.
|
||||
name, s = t.fqname(), t.string
|
||||
top = self._peek()
|
||||
|
@ -406,7 +411,8 @@ class StackTabber2(Tabber):
|
|||
if i == 0 and self.stack and self.stack[-1].name == 'continue':
|
||||
self.stack.pop()
|
||||
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()):
|
||||
self._save_curr_level()
|
||||
|
||||
|
@ -465,4 +471,5 @@ class StackTabber2(Tabber):
|
|||
# handle control keywords
|
||||
if i == start:
|
||||
self._save_curr_level()
|
||||
self._pop_while('continue');
|
||||
self._append('control', name, self._get_next_level(), y)
|
||||
|
|
Loading…
Reference in New Issue