more better javascript

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-02-02 22:08:33 +00:00
parent 42fb1aebb5
commit ef56ae12bc
1 changed files with 20 additions and 12 deletions

View File

@ -59,7 +59,19 @@ class JavascriptGrammar(Grammar):
RegionRule('string', '"', StringGrammar2, '"'), RegionRule('string', '"', StringGrammar2, '"'),
] ]
class JavascriptTabber(tab.StackTabber): class JavascriptTabber2(tab.StackTabber2):
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
control_tokens = {'keyword': {'if': 1, 'else': 1, 'while': 1, 'do': 1, 'for': 1}}
end_at_eof = False
end_at_tokens = {'delimiter': {';': 1}}
nocontinue_tokens = {'delimiter': {';': 1},
'comment': 1,
'comment.start': 1,
'comment.data': 1,
'comment.end': 1}
start_free_tokens = {'string.start': 'string.end'}
end_free_tokens = {'string.end': 'string.start'}
def is_base(self, y): def is_base(self, y):
if y == 0: if y == 0:
return True return True
@ -67,22 +79,18 @@ class JavascriptTabber(tab.StackTabber):
if not highlighter.tokens[y]: if not highlighter.tokens[y]:
return False return False
t = highlighter.tokens[y][0] t = highlighter.tokens[y][0]
return t.name == 'reserved' and t.string == 'function' return t.name == 'js_reserved' and t.string == 'function'
def _handle_other_token(self, currlvl, y, i): def _is_indent(self, t):
w = self.mode.tabwidth return t.name == 'spaces'
token = self.get_token(y, i) def _is_ignored(self, t):
fqname = token.fqname() return t.fqname() in ('spaces', 'eol', 'comment', 'comment.start',
if token.name == 'operator' and token.string == '=': 'comment.data', 'comment.null', 'comment.end')
self._opt_append("cont", currlvl + w)
elif token.name == 'delimiter' and token.string == ";":
self._opt_pop("cont")
return currlvl
class Javascript(mode.Fundamental): class Javascript(mode.Fundamental):
modename = 'Javascript' modename = 'Javascript'
extensions = ['.js'] extensions = ['.js']
grammar = JavascriptGrammar grammar = JavascriptGrammar
tabbercls = JavascriptTabber tabbercls = JavascriptTabber2
opentokens = ('delimiter',) opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'} opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',) closetokens = ('delimiter',)