branch : pmacs2
This commit is contained in:
moculus 2008-10-02 19:30:47 +00:00
parent e47d74aa40
commit de564a4077
1 changed files with 0 additions and 121 deletions

121
mode/c.py
View File

@ -118,127 +118,6 @@ class CTabber2(tab.StackTabber2):
elif t.fqname() in ('comment.start', 'comment.null', 'comment.end'): return True
else: return False
class CTabber(tab.StackTabber):
wst = ('spaces', 'eol', 'comment', 'comment.start', 'comment.null', 'comment.end')
def token_is_whitespace(self, y, i):
token = self.get_token(y, i)
return token.fqname() in self.wst
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
# this assumes that people aren't gonna use these macros inside of
# blocks, which is probably ok.
t0 = highlighter.tokens[y][0]
if t0.name == 'macro.start' and t0.string in ('#define', '#include'):
return True
# detecting function declarations is annoying; this assumes that people
# won't put a variable type and name on different lines, but that they
# might do that for function return type and name.
#
# unfortunately, valid function return types might include any of the
# four types of tokens below
decl = False
for t in highlighter.tokens[y]:
if t.name in ('keyword', 'identifier', 'structname', 'enumname'):
decl = True
continue
if decl and t.name == 'function':
break
else:
decl = False
break
if decl:
return True
return False
def _handle_open_token(self, currlvl, y, i):
self._opt_pop('cont')
token = self.get_token(y, i)
if token.string == '{':
self._pop_while('cond', 'cont', 'case')
if self.is_leftmost_token(y, i):
currlvl = self.get_curr_level()
tab.StackTabber._handle_open_token(self, currlvl, y, i)
return currlvl
def _handle_close_token(self, currlvl, y, i):
w = self.mode.tabwidth
self._opt_pop('cont')
token = self.get_token(y, i)
if token.string == '}':
self._opt_pop('case')
currlvl = tab.StackTabber._handle_close_token(self, currlvl, y, i)
if self.is_rightmost_token(y, i):
if token.string == '}':
self._pop_while('cond', 'cont', 'case')
elif self._has_markers() and self._peek_name() == 'cond':
pass
else:
if token.fqname() != 'macro.delimiter':
self._opt_append('cont', currlvl + w)
return currlvl
def _handle_other_token(self, currlvl, y, i):
w = self.mode.tabwidth
token = self.get_token(y, i)
fqname = token.fqname()
if fqname == 'delimiter' and token.string == ';':
self._pop_while('cond', 'cont')
elif fqname == 'keyword':
if token.string in ('do', 'else', 'for', 'if', 'while'):
self._append('cond', currlvl + w)
elif token.string == 'break':
self._opt_pop('case', 'while', 'for')
elif token.string == 'continue':
self._opt_pop('while', 'for')
elif token.string == 'case':
self._opt_pop('case')
currlvl = self.get_curr_level()
self._opt_append('case', currlvl + w)
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 + w)
# TODO: this could be a lot better
elif fqname == 'macro':
currlvl = 0
elif fqname.startswith('macro.start'):
self._opt_append('macro', None)
currlvl = 0
elif fqname.startswith('macro.end'):
self._opt_pop('macro', None)
elif fqname.startswith('macroblock.start'):
self._opt_append('macroblock', None)
currlvl = 0
elif fqname.startswith('macroblock.end'):
self._opt_pop('macroblock', None)
if self.is_rightmost_token(y, i):
if self._has_markers() and self._peek_name() == 'cond':
pass
elif(not fqname.startswith('string') and
not fqname.startswith('comment') and
not fqname.startswith('macro') and
not fqname == 'delimiter' and
not fqname == 'header' and
#not fqname == 'null' and
not fqname == 'spaces' and
not fqname == 'eol' and
token.string not in ('}', ';', '(', '{', '[', ',')):
self._opt_append('cont', currlvl + w)
return currlvl
class CCheckSyntax(method.shell.Exec):
'''Build this C program (using the mode's make cmd)'''
show_success = False