improve javascript indenting; improve fixed_indent mode a bit
--HG-- branch : pmacs2
This commit is contained in:
parent
1ea5d18fa5
commit
57ae9a21e0
|
@ -67,6 +67,7 @@ class JavascriptGrammar(Grammar):
|
|||
]
|
||||
|
||||
class JavascriptTabber2(tab.StackTabber2):
|
||||
fixed_indent = True
|
||||
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
|
||||
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
|
||||
control_tokens = {'js.keyword': {'if': 1, 'else': 1, 'while': 1,
|
||||
|
@ -118,6 +119,7 @@ class JavascriptTagManager(TagManager):
|
|||
class Javascript(Fundamental):
|
||||
name = 'Javascript'
|
||||
extensions = ['.js', '.json']
|
||||
tabwidth = 2
|
||||
grammar = JavascriptGrammar
|
||||
tabbercls = JavascriptTabber2
|
||||
tagcls = JavascriptTagManager
|
||||
|
|
15
tab.py
15
tab.py
|
@ -384,8 +384,23 @@ class StackTabber2(Tabber):
|
|||
raise Exception, msg % (t.string, y, s)
|
||||
else:
|
||||
raise Exception, "what? %r (%r)" % (marker, t)
|
||||
|
||||
# if we start a line with a closing token (e.g. "}") we may want to
|
||||
# shift the indentation left to "close" the indent. if we're using
|
||||
# fixed indentation then we may want to do this shift multiple times
|
||||
# (e.g. "})").
|
||||
if i == 0:
|
||||
self._save_curr_level()
|
||||
elif self.fixed_indent:
|
||||
all_closed = True
|
||||
for j in xrange(0, i):
|
||||
if self._is_ignored(tokens[j]) or self._is_close_token(tokens[j]):
|
||||
pass
|
||||
else:
|
||||
all_closed = False
|
||||
break
|
||||
if all_closed:
|
||||
self._save_curr_level()
|
||||
|
||||
# if we need to end at eof and we're at the EOF and we have a control
|
||||
# token, then we need to pop it.
|
||||
|
|
Loading…
Reference in New Issue