parent
03105557a6
commit
18686df3d2
|
@ -342,71 +342,6 @@ class UppercaseWord(Method):
|
||||||
w.insert_string(p1, word.upper())
|
w.insert_string(p1, word.upper())
|
||||||
|
|
||||||
class MetaX(Method):
|
class MetaX(Method):
|
||||||
'''Invoke commands by name'''
|
|
||||||
args = [arg('method', dt="method", p="M-x ", h='Method to execute')]
|
|
||||||
name_re = re.compile(r'^ *([a-z0-9_-]+) *(?:\( *\))? *$')
|
|
||||||
full_re = re.compile(r'^ *([a-z0-9_-]+) *\((.*)\) *$')
|
|
||||||
arg_re = re.compile(r' *(-?[0-9\.]+|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\\"])*") *')
|
|
||||||
varg_re = re.compile(r' *([a-zA-Z0-9_]+) *= *(-?[0-9\.]+|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\\"])*") *')
|
|
||||||
def _execute(self, w, **vargs):
|
|
||||||
m = self.name_re.match(vargs['method'])
|
|
||||||
if m:
|
|
||||||
name2 = m.group(1)
|
|
||||||
self._sub_execute(w, name2, {})
|
|
||||||
return
|
|
||||||
m = self.full_re.match(vargs['method'])
|
|
||||||
if m:
|
|
||||||
vargs2 = {}
|
|
||||||
if '=' in m.group(2):
|
|
||||||
name2, vargs_str = m.group(1), m.group(2)
|
|
||||||
i = 0
|
|
||||||
m = self.varg_re.search(vargs_str, i)
|
|
||||||
while m:
|
|
||||||
i = m.end()
|
|
||||||
vargs2[m.group(1)] = eval(m.group(2))
|
|
||||||
if i == len(vargs_str):
|
|
||||||
break
|
|
||||||
elif vargs_str[i] != ',':
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
i += 1
|
|
||||||
m = self.varg_re.search(vargs_str, i)
|
|
||||||
if i == len(vargs_str):
|
|
||||||
self._sub_execute(w, name2, vargs2)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
name2, args_str = m.group(1), m.group(2)
|
|
||||||
i = 0
|
|
||||||
m = self.arg_re.search(args_str, i)
|
|
||||||
args = []
|
|
||||||
while m:
|
|
||||||
i = m.end()
|
|
||||||
args.append(eval(m.group(1)))
|
|
||||||
if i == len(args_str):
|
|
||||||
break
|
|
||||||
elif args_str[i] != ',':
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
i += 1
|
|
||||||
m = self.arg_re.search(args_str, i)
|
|
||||||
d = {}
|
|
||||||
try:
|
|
||||||
meth = w.application.methods[name2]
|
|
||||||
for (arg, value) in zip(meth.args, args):
|
|
||||||
vargs2[arg.name] = value
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
if i == len(args_str):
|
|
||||||
self._sub_execute(w, name2, vargs2)
|
|
||||||
return
|
|
||||||
w.set_error('could not parse argument %r' % vargs['method'])
|
|
||||||
def _sub_execute(self, w, name, vargs):
|
|
||||||
if name in w.application.methods:
|
|
||||||
w.application.methods[name].execute(w, **vargs)
|
|
||||||
else:
|
|
||||||
w.set_error('no method named %r found' % name)
|
|
||||||
|
|
||||||
class MetaXTwo(MetaX):
|
|
||||||
args = [arg('method', dt="method", p="M-x ", h='Method to execute')]
|
args = [arg('method', dt="method", p="M-x ", h='Method to execute')]
|
||||||
name_re = re.compile(r'[a-z0-9_-]+')
|
name_re = re.compile(r'[a-z0-9_-]+')
|
||||||
|
|
||||||
|
@ -485,7 +420,16 @@ class MetaXTwo(MetaX):
|
||||||
else:
|
else:
|
||||||
args.append(value)
|
args.append(value)
|
||||||
|
|
||||||
w.set_error("func %r; other %r; args %r; vargs %r" % (func, other, args, vargs))
|
meth = w.application.methods.get(func)
|
||||||
|
if meth is None:
|
||||||
|
w.set_error("method %r not found" % func)
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
for (arg, value) in zip(meth.args, args): vargs[arg.name] = value
|
||||||
|
except:
|
||||||
|
w.set_error("4fail")
|
||||||
|
return
|
||||||
|
meth.execute(w, **vargs)
|
||||||
|
|
||||||
class ToggleMargins(Method):
|
class ToggleMargins(Method):
|
||||||
'''Show or hide column margins'''
|
'''Show or hide column margins'''
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import commands, os.path, string, sys, traceback
|
from mode import Fundamental
|
||||||
import color, completer, default, mode, method, regex, tab
|
|
||||||
from point import Point
|
from point import Point
|
||||||
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
|
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
|
||||||
from mode.lisp import LispTabber
|
from mode.lisp import Lisp, LispTabber
|
||||||
|
|
||||||
class StringGrammar(Grammar):
|
class StringGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
|
@ -15,41 +14,36 @@ class ELispGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'comment', r';.*$'),
|
PatternRule(r'comment', r';.*$'),
|
||||||
PatternRule(r'delimiter', r'[()]'),
|
PatternRule(r'delimiter', r'[()]'),
|
||||||
PatternRule(r'elisp_reserved', r'(?:nil)(?![a-zA-Z0-9_])'),
|
PatternRule(r'spaces', r' +'),
|
||||||
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_])'),
|
PatternRule(r'eol', r'\n'),
|
||||||
|
PatternRule(r'elisp_reserved', r'(?:t|nil)(?![^\"\' \t()])'),
|
||||||
|
PatternRule(r'keyword', r'(?:while|when|unless|setq-default|setq|setcar|require|provide|or|not|mapcar|list|let\*|let|lambda|if|exists|equal|defvar|defun|defstruct|defface|defalias|count|cons|c[ad]+r|apply|and)(?![^\"\' \t()])'),
|
||||||
PatternRule(r'elisp_symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"),
|
PatternRule(r'elisp_symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"),
|
||||||
|
PatternRule(r'delimiter', r"'"),
|
||||||
PatternRule(r'elisp_type', r":[a-zA-Z_][a-zA-Z0-9-_]*"),
|
PatternRule(r'elisp_type', r":[a-zA-Z_][a-zA-Z0-9-_]*"),
|
||||||
PatternRule(r'attribute', 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"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"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_])"),
|
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_])"),
|
||||||
|
PatternRule(r'elisp_word', r"[^\"' \t()]+"),
|
||||||
RegionRule(r'string', r'"', StringGrammar, r'"'),
|
RegionRule(r'string', r'"', StringGrammar, r'"'),
|
||||||
PatternRule(r'eol', r'\n$'),
|
PatternRule(r'eol', r'\n$'),
|
||||||
]
|
]
|
||||||
|
|
||||||
class ELisp(mode.Fundamental):
|
class ELisp(Lisp):
|
||||||
name = 'ELisp'
|
name = 'ELisp'
|
||||||
tabwidth = 2
|
|
||||||
basenames = ['.emacs']
|
basenames = ['.emacs']
|
||||||
extensions = ['.el']
|
extensions = ['.el']
|
||||||
tabbercls = LispTabber
|
|
||||||
grammar = ELispGrammar
|
grammar = ELispGrammar
|
||||||
commentc = ';'
|
|
||||||
opentokens = ('delimiter',)
|
opentokens = ('delimiter',)
|
||||||
opentags = {'(': ')', '[': ']', '{': '}'}
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
||||||
closetokens = ('delimiter',)
|
closetokens = ('delimiter',)
|
||||||
closetags = {')': '(', ']': '[', '}': '{'}
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||||||
colors = {
|
colors = {
|
||||||
'elisp_keyword': ('cyan', 'default', 'bold'),
|
|
||||||
'elisp_reserved': ('blue', 'default', 'bold'),
|
'elisp_reserved': ('blue', 'default', 'bold'),
|
||||||
'elisp_symbol': ('magenta', 'default', 'bold'),
|
'elisp_symbol': ('magenta', 'default', 'bold'),
|
||||||
'elisp_type': ('blue', 'default', 'bold'),
|
'elisp_type': ('blue', 'default', 'bold'),
|
||||||
}
|
'elisp_word': ('default', 'default'),
|
||||||
_bindings = {
|
|
||||||
'close-paren': (')',),
|
|
||||||
'close-brace': ('}',),
|
|
||||||
'close-bracket': (']',),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install = ELisp.install
|
install = ELisp.install
|
||||||
|
|
16
mode/lisp.py
16
mode/lisp.py
|
@ -1,20 +1,21 @@
|
||||||
import commands, os.path, string, sys, traceback
|
import regex
|
||||||
import color, completer, default, mode, method, regex, tab
|
from mode import Fundamental
|
||||||
from point import Point
|
from tab import StackTabber
|
||||||
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
|
from lex import Grammar, PatternRule, RegionRule
|
||||||
from mode.python import StringGrammar2
|
from mode.python import StringGrammar2
|
||||||
from method import CommentRegion, UncommentRegion
|
|
||||||
|
|
||||||
class LispGrammar(Grammar):
|
class LispGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'comment', r';.*$'),
|
PatternRule(r'comment', r';.*$'),
|
||||||
PatternRule(r'delimiter', r'[()]'),
|
PatternRule(r'delimiter', r'[()]'),
|
||||||
|
PatternRule(r'keyword', r'(?:or|not|list|let\*|let|lambda|if|cons|c[ad]+r|apply|and)(?![^\"\' \t()])'),
|
||||||
|
PatternRule(r'lisp_word', r"[^\"' \t()]+"),
|
||||||
RegionRule(r'string', r'"', StringGrammar2, r'"'),
|
RegionRule(r'string', r'"', StringGrammar2, r'"'),
|
||||||
PatternRule(r'spaces', r' +'),
|
PatternRule(r'spaces', r' +'),
|
||||||
PatternRule(r'eol', r'\n'),
|
PatternRule(r'eol', r'\n'),
|
||||||
]
|
]
|
||||||
|
|
||||||
class LispTabber(tab.StackTabber):
|
class LispTabber(StackTabber):
|
||||||
wsre = regex.whitespace
|
wsre = regex.whitespace
|
||||||
wst = ('spaces', 'null', 'eol',)
|
wst = ('spaces', 'null', 'eol',)
|
||||||
sre = regex.space
|
sre = regex.space
|
||||||
|
@ -35,11 +36,12 @@ class LispTabber(tab.StackTabber):
|
||||||
self._append(token.string, level)
|
self._append(token.string, level)
|
||||||
return currlvl
|
return currlvl
|
||||||
|
|
||||||
class Lisp(mode.Fundamental):
|
class Lisp(Fundamental):
|
||||||
name = 'Lisp'
|
name = 'Lisp'
|
||||||
tabwidth = 2
|
tabwidth = 2
|
||||||
tabbercls = LispTabber
|
tabbercls = LispTabber
|
||||||
grammar = LispGrammar
|
grammar = LispGrammar
|
||||||
|
commentc = ';'
|
||||||
opentokens = ('delimiter',)
|
opentokens = ('delimiter',)
|
||||||
opentags = {'(': ')'}
|
opentags = {'(': ')'}
|
||||||
closetokens = ('delimiter',)
|
closetokens = ('delimiter',)
|
||||||
|
|
21
mode/mbox.py
21
mode/mbox.py
|
@ -192,21 +192,14 @@ class MboxOpenPath(Method):
|
||||||
|
|
||||||
class MailListGrammar(Grammar):
|
class MailListGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternGroupRule(r'xyz',
|
PatternGroupRule(
|
||||||
r'index', r'^ *[0-9]+',
|
r'xyz', r'index', r'^ *[0-9]+', r'spaces', r' ',
|
||||||
r'spaces', r' ',
|
r'flag', r'.', r'spaces', r' ',
|
||||||
r'flag', r'.',
|
|
||||||
r'spaces', r' ',
|
|
||||||
r'month', r'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec',
|
r'month', r'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec',
|
||||||
#r'dow', r'Mon|Tue|Wed|Thu|Fri|Sat|Sun',
|
r'spaces', r' +', r'day', r'[0-9]+', r'spaces', r' +',
|
||||||
r'spaces', r' +',
|
r'sender', r'.{16}', r'spaces', r' +', r'size', r'[0-9]+',
|
||||||
r'day', r'[0-9]+',
|
r'spaces', ' +', r'subject', r'.+$',
|
||||||
r'spaces', r' +',
|
),
|
||||||
r'sender', r'.{16}',
|
|
||||||
r'spaces', r' +',
|
|
||||||
r'size', r'[0-9]+',
|
|
||||||
r'spaces', ' +',
|
|
||||||
r'subject', r'.+$'),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
class MboxMsg(mode.Fundamental):
|
class MboxMsg(mode.Fundamental):
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import commands, os.path, string, sys, traceback
|
from method import Method
|
||||||
import color, completer, default, mode, method, regex, tab
|
from method.shell import Interact
|
||||||
from point import Point
|
from point import Point
|
||||||
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
|
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
|
||||||
import mode.lisp
|
from mode.lisp import StringGrammar2, Lisp, LispTabber
|
||||||
|
|
||||||
class SchemeGrammar(Grammar):
|
class SchemeGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'comment', r';.*$'),
|
PatternRule(r'comment', r';.*$'),
|
||||||
PatternRule(r'delimiter', r'[()]'),
|
PatternRule(r'delimiter', r'[()]'),
|
||||||
RegionRule(r'string', r'"', mode.lisp.StringGrammar2, r'"'),
|
RegionRule(r'string', r'"', StringGrammar2, r'"'),
|
||||||
PatternRule(r'spaces', r' +'),
|
PatternRule(r'spaces', r' +'),
|
||||||
PatternRule(r'eol', r'\n'),
|
PatternRule(r'eol', r'\n'),
|
||||||
PatternRule(r'abbrev', r"'|`|,\@|,"),
|
PatternRule(r'abbrev', r"'|`|,\@|,"),
|
||||||
|
@ -25,7 +25,7 @@ class SchemeGrammar(Grammar):
|
||||||
PatternRule(r'variable', r'[a-zA-Z!$%&*/:<=>?\^_~][-a-zA-Z0-9!$%&*/:<=>?^_~+.@]*|\+|-|\.\.\.'),
|
PatternRule(r'variable', r'[a-zA-Z!$%&*/:<=>?\^_~][-a-zA-Z0-9!$%&*/:<=>?^_~+.@]*|\+|-|\.\.\.'),
|
||||||
]
|
]
|
||||||
|
|
||||||
class SchemeCheckSyntax(method.Method):
|
class SchemeCheckSyntax(Method):
|
||||||
'''Check the syntax of a scheme file'''
|
'''Check the syntax of a scheme file'''
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
app = w.application
|
app = w.application
|
||||||
|
@ -37,30 +37,23 @@ class SchemeCheckSyntax(method.Method):
|
||||||
else:
|
else:
|
||||||
app.data_buffer("*Scheme-Check-Syntax*", output)
|
app.data_buffer("*Scheme-Check-Syntax*", output)
|
||||||
|
|
||||||
class GuileStart(method.shell.Interact):
|
class GuileStart(Interact):
|
||||||
args = []
|
args = []
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
method.shell.Interact._execute(self, w, bname='*Guile*', cmd='guile')
|
Interact._execute(self, w, bname='*Guile*', cmd='guile')
|
||||||
|
|
||||||
class GuileLoadFile(method.shell.Interact):
|
class GuileLoadFile(Interact):
|
||||||
args = []
|
args = []
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
method.shell.Interact._execute(self, w, bname='*Guile*', cmd='guile')
|
Interact._execute(self, w, bname='*Guile*', cmd='guile')
|
||||||
b = w.application.get_buffer_by_name('*Guile*')
|
b = w.application.get_buffer_by_name('*Guile*')
|
||||||
path = os.path.realpath(w.buffer.path)
|
path = os.path.realpath(w.buffer.path)
|
||||||
b.pipe_write('(load "%s")\n' % path)
|
b.pipe_write('(load "%s")\n' % path)
|
||||||
|
|
||||||
class Scheme(mode.Fundamental):
|
class Scheme(Lisp):
|
||||||
name = 'Scheme'
|
name = 'Scheme'
|
||||||
extensions = ['.scm']
|
extensions = ['.scm']
|
||||||
tabwidth = 2
|
|
||||||
tabbercls = mode.lisp.LispTabber
|
|
||||||
grammar = SchemeGrammar
|
grammar = SchemeGrammar
|
||||||
commentc = ';'
|
|
||||||
opentokens = ('delimiter',)
|
|
||||||
opentags = {'(': ')'}
|
|
||||||
closetokens = ('delimiter',)
|
|
||||||
closetags = {')': '('}
|
|
||||||
colors = {
|
colors = {
|
||||||
'scheme_keyword': ('cyan', 'default', 'bold'),
|
'scheme_keyword': ('cyan', 'default', 'bold'),
|
||||||
'scheme_char': ('green', 'default', 'bold'),
|
'scheme_char': ('green', 'default', 'bold'),
|
||||||
|
|
Loading…
Reference in New Issue