diff --git a/mode_javascript.py b/mode_javascript.py index 082ed58..f34ae25 100644 --- a/mode_javascript.py +++ b/mode_javascript.py @@ -1,4 +1,4 @@ -import color, mode2 +import color, mode2, tab2 from lex2 import Grammar, PatternRule, RegionRule from point2 import Point from mode_python import StringGrammar @@ -6,7 +6,7 @@ from mode_python import StringGrammar class JavascriptGrammar(Grammar): rules = [ PatternRule(name=r'comment', pattern=r'//.*$'), - RegionRule(name=r'comment', start='/\*', grammar=Grammar(), end='\*/'), + RegionRule(name=r'comment', start='/\*', grammar=Grammar, end='\*/'), PatternRule(name=r'continuation', pattern=r'\\(?= *$)'), PatternRule(name=r'function', pattern=r"(?<=function )[a-zA-Z_][a-zA-Z0-9_]*"), PatternRule(name=r'class', pattern=r"(?<=class )[a-zA-Z_][a-zA-Z0-9_]*"), @@ -29,13 +29,36 @@ class JavascriptGrammar(Grammar): PatternRule(name=r'delimiter', pattern=r'%=|&&=|&=|\(|\)|\*=|\+=|,|-=|\.{3}|\.|/=(?= |$)|::|:|;|<<=|>>=|>>>=|\?|\[|\]|^=|^^=|\{|\}|\|=|\|\|='), PatternRule(name=r'operator', pattern=r'!==|!=|!|%|&&|&|\*|\+\+|\+|--|-|/(?= |$)|<<=|<<|<=|<|===|==|=|>>>=|>>>|>>=|>>|>=|>|\\'), - RegionRule(name='regex', start="/", grammar=StringGrammar(), end="/"), - RegionRule(name='string', start="'", grammar=StringGrammar(), end="'"), - RegionRule(name='string', start='"', grammar=StringGrammar(), end='"'), + RegionRule(name='regex', start="/", grammar=StringGrammar, end="/"), + RegionRule(name='string', start="'", grammar=StringGrammar, end="'"), + RegionRule(name='string', start='"', grammar=StringGrammar, end='"'), ] +class JavascriptTabber(tab2.StackTabber): + 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 + t = highlighter.tokens[y][0] + return t.name == 'reserved1' and t.string == 'function' + def _handle_other_token(self, currlvl, y, i): + token = self.get_token(y, i) + fqname = token.fqname() + if token.name == 'operator' and token.string == '=': + self._opt_append("cont", currlvl + 4) + elif token.name == 'delimiter' and token.string == ";": + self._opt_pop("cont") + return currlvl + class Javascript(mode2.Fundamental): - grammar = JavascriptGrammar() + grammar = JavascriptGrammar + tabbercls = JavascriptTabber + opentoken = 'delimiter' + opentags = {'(': ')', '[': ']', '{': '}'} + closetoken = 'delimiter' + closetags = {')': '(', ']': '[', '}': '{'} def __init__(self, w): mode2.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) diff --git a/mode_search.py b/mode_search.py index 1646c8c..3ebc075 100644 --- a/mode_search.py +++ b/mode_search.py @@ -136,3 +136,4 @@ def _end(w): w.application.last_search = w.buffer.make_string() w.buffer.method.old_cursor = None w.buffer.method.old_window = None + w.buffer.method.is_literal = None