pmacs3/mode/elisp.py

57 lines
2.6 KiB
Python
Raw Normal View History

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
from point import Point
2007-10-21 20:52:48 -04:00
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
from mode.lisp import LispTabber, LispCommentRegion, LispUncommentRegion
2007-08-04 16:16:30 -04:00
class StringGrammar(Grammar):
rules = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
2008-10-20 19:22:53 -04:00
PatternRule(r'data', r'[^\\"]+'),
2007-08-04 16:16:30 -04:00
]
class ELispGrammar(Grammar):
rules = [
PatternRule(r'comment', r';.*$'),
PatternRule(r'delimiter', r'[()]'),
2008-03-16 11:39:17 -04:00
PatternRule(r'elisp_reserved', r'(?:nil)(?![a-zA-Z0-9_])'),
PatternRule(r'elisp_keyword', r'(?:while|when|unless|setq-default|setq|require|or|not|mapcar|list|let|lambda|if|exists|equal|defvar|defun|defalias|count|cons|cdr|car|apply|and)(?![a-zA-Z0-9_])'),
2008-03-16 11:39:17 -04:00
PatternRule(r'elisp_symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'elisp_type', r":[a-zA-Z_][a-zA-Z0-9-_]*"),
2007-08-04 16:16:30 -04:00
PatternRule(r'attribute', r"&[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'bareword', r"[a-zA-Z_][a-zA-Z0-9-_]*"),
2008-03-16 11:39:17 -04:00
PatternRule(r"integer", r"(?<![\.0-9a-zA-Z_])(?:0|-?[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"),
2007-08-04 16:16:30 -04:00
PatternRule(r"float", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)(?![\.0-9a-zA-Z_])"),
PatternRule(r"imaginary", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+|(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)[jJ])(?![\.0-9a-zA-Z_])"),
RegionRule(r'string', r'"', StringGrammar, r'"'),
PatternRule(r'eol', r'\n$'),
]
2007-10-21 20:55:29 -04:00
class ELisp(mode.Fundamental):
2007-10-18 17:07:35 -04:00
modename = 'ELisp'
tabwidth = 2
2007-10-18 17:07:35 -04:00
basenames = ['.emacs']
extensions = ['.el']
tabbercls = LispTabber
2007-08-04 16:16:30 -04:00
grammar = ELispGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
2007-10-18 17:07:35 -04:00
colors = {
'elisp_keyword': ('cyan', 'default', 'bold'),
'elisp_reserved': ('blue', 'default', 'bold'),
'elisp_symbol': ('magenta', 'default', 'bold'),
'elisp_type': ('blue', 'default', 'bold'),
2007-08-04 16:16:30 -04:00
}
def __init__(self, w):
2007-10-21 20:55:29 -04:00
mode.Fundamental.__init__(self, w)
2007-08-04 16:16:30 -04:00
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
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 = ELisp.install