diff --git a/application.py b/application.py index 527974d..6ff33ce 100755 --- a/application.py +++ b/application.py @@ -10,7 +10,8 @@ from point2 import Point import mode2 import mode.mini, mode.search, mode.replace, mode.which import mode.console, mode.consolemini -import mode.c, mode.python, mode.perl, mode.nasm, mode.sh, mode.sql, mode.java, mode.lisp +import mode.c, mode.python, mode.perl, mode.nasm, mode.sh, mode.sql, mode.java +import mode.elisp, mode.scheme import mode.blame, mode.diff, mode.dir import mode.xml, mode.tt, mode.css, mode.javascript, mode.html import mode.text, mode.mutt @@ -107,7 +108,8 @@ class Application(object): 'bds': mode.bds.BDS, 'rst': mode.rst.RST, 'java': mode.java.Java, - 'lisp': mode.lisp.Lisp, + 'elisp': mode.elisp.ELisp, + 'scheme': mode.scheme.Scheme, } # these are used in this order to determine which mode to open certain @@ -120,6 +122,7 @@ class Application(object): '.bash_profile': 'sh', '.profile': 'sh', 'components.xml': 'bds', + '.emacs': 'elisp', } self.mode_extensions = { '.py': 'python', @@ -141,7 +144,7 @@ class Application(object): '.css': 'css', '.rst': 'rst', '.java': 'java', - '.el': 'lisp', + '.el': 'elisp', } self.mode_detection = { 'python': 'python', diff --git a/mode/elisp.py b/mode/elisp.py new file mode 100644 index 0000000..04b7d87 --- /dev/null +++ b/mode/elisp.py @@ -0,0 +1,63 @@ +import commands, os.path, sets, string, sys, traceback +import color, completer, default, mode2, method, regex, tab2 +from point2 import Point +from lex3 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"(?|define|unquote-splicing|unquote'), + + PatternRule(r'predicate', r'(?:boolean|symbol|char|vector|procedure|pair|number|string|port)\?'), + PatternRule(r'predicate', r'(?:eqv|equal|complex|real|rational|integer|zero|positive|negative|odd|even|null|list|char=|char<=|char>=|char<|char>|char-ci=|char-ci<=|char-ci>=|char-ci<|char-ci>|char-alphabetic|char-numeric|char-whitespace|char-upper-case|char-lower-case)\?'), + + PatternRule(r'procedure', r'max|min|\+|-|\*|/|abs|quotient|remainder|modulo|lcm|gcd|numerator|denominator|floor|ceiling|truncate|round|rationalize|exp|log|sin|cos|tan|asin|acos|atan|make-rectangular|make-polar|real-part|imag-part|magnitude|angle|not|cons|car|cdr|list-tail|list-ref|list|length|append|reverse|memq|memv|member|assq|assv|assoc|char-upcase|char-downcase|make-string|string|string-ref'), + PatternRule(r'procedure', r'char->integer|integer->char'), + + PatternRule(r'mutator', r'(?:set-car|set-cdr|string-set)\!'), + + PatternRule(r'variable', r'[a-zA-Z!$%&*/:<=>?\^_~][a-zA-Z0-9!$%&*/:<=>?^_~+-.@]*|\+|-|...'), + + PatternRule(r'boolean', r'#[tf]'), + PatternRule(r'char', r'#\\space|#\\newline|#\\.'), + + # these are basically right and very easy + PatternRule(r'number', '[+-]?[0-9][^ \n]+'), + PatternRule(r'number', '#[bodx][ie]?[^ \n]+'), + PatternRule(r'number', '#[ie][bodx]?[^ \n]+'), + ] + +class SchemeTabber(tab2.StackTabber): + pass + +class Scheme(mode2.Fundamental): + tabbercls = SchemeTabber + grammar = SchemeGrammar + 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): + mode2.Fundamental.__init__(self, w) + # tag matching + self.add_bindings('close-paren', (')',)) + self.add_bindings('close-brace', ('}',)) + self.add_bindings('close-bracket', (']',)) + ## add scheme-specific methods + #self.add_action_and_bindings(SchemeCheckSyntax(), ('C-c s',)) + def name(self): + return "Scheme"