2008-11-08 10:30:04 -05:00
|
|
|
import commands, os.path, string, sys, traceback
|
2007-10-21 20:55:29 -04:00
|
|
|
import color, completer, default, mode, method, regex, tab
|
2007-10-21 20:50:11 -04:00
|
|
|
from point import Point
|
2007-10-21 20:52:48 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
|
2008-10-01 16:58:43 -04:00
|
|
|
from mode.python import StringGrammar2
|
2008-09-11 18:26:41 -04:00
|
|
|
from method import CommentRegion, UncommentRegion
|
2007-08-03 18:19:16 -04:00
|
|
|
|
|
|
|
class LispGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'comment', r';.*$'),
|
2007-08-06 11:36:49 -04:00
|
|
|
PatternRule(r'delimiter', r'[()]'),
|
2008-10-01 16:58:43 -04:00
|
|
|
RegionRule(r'string', r'"', StringGrammar2, r'"'),
|
2007-08-06 11:36:49 -04:00
|
|
|
PatternRule(r'spaces', r' +'),
|
|
|
|
PatternRule(r'eol', r'\n'),
|
2007-08-03 18:19:16 -04:00
|
|
|
]
|
|
|
|
|
2008-09-11 18:26:41 -04:00
|
|
|
class LispCommentRegion(CommentRegion):
|
|
|
|
commentc = ';'
|
|
|
|
class LispUncommentRegion(UncommentRegion):
|
|
|
|
commentc = ';'
|
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class LispTabber(tab.StackTabber):
|
2007-08-15 18:37:49 -04:00
|
|
|
wsre = regex.whitespace
|
|
|
|
wst = ('spaces', 'null', 'eol',)
|
|
|
|
sre = regex.space
|
|
|
|
st = ('spaces', 'null',)
|
2007-08-06 11:36:49 -04:00
|
|
|
def _handle_open_token(self, currlvl, y, i):
|
2007-08-15 18:37:49 -04:00
|
|
|
token = self.get_token(y, i)
|
|
|
|
rtoken = self.get_next_right_token(y, i)
|
|
|
|
if rtoken is None:
|
2007-08-16 10:21:37 -04:00
|
|
|
level = self.get_curr_level() + self.mode.tabwidth
|
2008-07-19 16:00:11 -04:00
|
|
|
elif rtoken.string not in ('(', 'define', 'lambda'):
|
|
|
|
rtoken = self.get_next_right_token(y, i + 1)
|
|
|
|
if rtoken is None or rtoken.string != '(':
|
|
|
|
level = self.get_curr_level() + self.mode.tabwidth
|
|
|
|
else:
|
|
|
|
level = rtoken.x
|
2007-08-15 18:37:49 -04:00
|
|
|
else:
|
2008-07-19 16:00:11 -04:00
|
|
|
level = self.get_curr_level() + self.mode.tabwidth
|
2007-08-15 18:37:49 -04:00
|
|
|
self._append(token.string, level)
|
2007-08-06 11:36:49 -04:00
|
|
|
return currlvl
|
2007-08-03 18:19:16 -04:00
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class Lisp(mode.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'Lisp'
|
2007-08-16 10:21:37 -04:00
|
|
|
tabwidth = 2
|
2007-08-03 18:19:16 -04:00
|
|
|
tabbercls = LispTabber
|
|
|
|
grammar = LispGrammar
|
|
|
|
opentokens = ('delimiter',)
|
2007-08-06 11:36:49 -04:00
|
|
|
opentags = {'(': ')'}
|
2007-08-03 18:19:16 -04:00
|
|
|
closetokens = ('delimiter',)
|
2007-08-06 11:36:49 -04:00
|
|
|
closetags = {')': '('}
|
2008-09-11 18:26:41 -04:00
|
|
|
actions = [LispCommentRegion, LispUncommentRegion]
|
|
|
|
|
2007-08-03 18:19:16 -04:00
|
|
|
def __init__(self, w):
|
2007-10-21 20:55:29 -04:00
|
|
|
mode.Fundamental.__init__(self, w)
|
2007-08-03 18:19:16 -04:00
|
|
|
self.add_bindings('close-paren', (')',))
|
|
|
|
self.add_bindings('close-brace', ('}',))
|
|
|
|
self.add_bindings('close-bracket', (']',))
|
2009-02-13 22:36:38 -05:00
|
|
|
self.add_bindings('lisp-comment-region', ('C-c #',))
|
|
|
|
self.add_bindings('lisp-uncomment-region', ('C-u C-C #',))
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Lisp.install
|