pmacs3/mode/elisp.py

67 lines
2.9 KiB
Python

import commands, os.path, sets, string, sys, traceback
import color, completer, default, mode, method, regex, tab
from point import Point
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
class StringGrammar(Grammar):
rules = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
]
class ELispGrammar(Grammar):
rules = [
PatternRule(r'comment', r';.*$'),
PatternRule(r'reserved', r'(?:nil)(?![a-zA-Z0-9_])'),
PatternRule(r'keyword', r'(?:while|when|unless|setq|require|or|not|mapcar|list|let|lambda|if|exists|equal|defvar|defun|defalias|count|cons|cdr|car|apply|and)(?![a-zA-Z0-9_])'),
PatternRule(r'symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'type', r":[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'attribute', r"&[a-zA-Z_][a-zA-Z0-9-_]*"),
PatternRule(r'bareword', r"[a-zA-Z_][a-zA-Z0-9-_]*"),
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_])"),
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$'),
]
class ELispTabber(tab.StackTabber):
pass
class ELisp(mode.Fundamental):
modename = 'ELisp'
basenames = ['.emacs']
extensions = ['.el']
tabbercls = ELispTabber
grammar = ELispGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'keyword': ('cyan', 'default'),
'reserved': ('blue', 'default'),
'symbol': ('magenta', 'default'),
'type': ('blue', 'default'),
'string.start': ('green', 'default'),
'string.null': ('green', 'default'),
'string.octal': ('magenta', 'default'),
'string.escaped': ('magenta', 'default'),
'string.format': ('yellow', 'default'),
'string.end': ('green', 'default'),
'integer': ('default', 'default'),
'float': ('default', 'default'),
'imaginary': ('default', 'default'),
'comment': ('red', 'default'),
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
# tag matching
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
## add lisp-specific methods
#self.add_action_and_bindings(LispCheckSyntax(), ('C-c s',))
install = ELisp.install