From ef56ae12bc22ffd88ea0f2328a6b39da5e2fd367 Mon Sep 17 00:00:00 2001 From: moculus Date: Mon, 2 Feb 2009 22:08:33 +0000 Subject: [PATCH] more better javascript --HG-- branch : pmacs2 --- mode/javascript.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/mode/javascript.py b/mode/javascript.py index 91c0dee..b3caf56 100644 --- a/mode/javascript.py +++ b/mode/javascript.py @@ -59,7 +59,19 @@ class JavascriptGrammar(Grammar): 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): if y == 0: return True @@ -67,22 +79,18 @@ class JavascriptTabber(tab.StackTabber): if not highlighter.tokens[y]: return False t = highlighter.tokens[y][0] - return t.name == 'reserved' and t.string == 'function' - def _handle_other_token(self, currlvl, y, i): - w = self.mode.tabwidth - token = self.get_token(y, i) - fqname = token.fqname() - if token.name == 'operator' and token.string == '=': - self._opt_append("cont", currlvl + w) - elif token.name == 'delimiter' and token.string == ";": - self._opt_pop("cont") - return currlvl + return t.name == 'js_reserved' and t.string == 'function' + def _is_indent(self, t): + return t.name == 'spaces' + def _is_ignored(self, t): + return t.fqname() in ('spaces', 'eol', 'comment', 'comment.start', + 'comment.data', 'comment.null', 'comment.end') class Javascript(mode.Fundamental): modename = 'Javascript' extensions = ['.js'] grammar = JavascriptGrammar - tabbercls = JavascriptTabber + tabbercls = JavascriptTabber2 opentokens = ('delimiter',) opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',)