more mode clean-up

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-03-30 05:10:25 +00:00
parent ef6c9c92e2
commit 9cf785885a
19 changed files with 203 additions and 184 deletions

View File

@ -69,8 +69,7 @@ public class HibernateUtil {
} }
public static void checkData(String sql) { public static void checkData(String sql) {
try { try {
HibernateUtil.outputResultSet(st HibernateUtil.outputResultSet(st.executeQuery(sql));
.executeQuery(sql));
// conn.close(); // conn.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -507,9 +507,9 @@ class TabBuffer(Method):
y = w.logical_cursor().y y = w.logical_cursor().y
it = InsertTab() it = InsertTab()
for i in range(0, len(w.buffer.lines)): for i in range(0, len(w.buffer.lines)):
w.goto_line(i) w.goto_line(i + 1)
it.execute(w) it.execute(w)
w.goto_line(y) w.goto_line(y + 1)
class GetIndentionLevel(Method): class GetIndentionLevel(Method):
'''Calculate the indention level for this line''' '''Calculate the indention level for this line'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):

View File

@ -82,7 +82,7 @@ class CTabber2(tab.StackTabber2):
control_tokens = {'keyword': {'if': 1, 'else': 1, 'while': 1, 'do': 1, 'for': 1}} control_tokens = {'keyword': {'if': 1, 'else': 1, 'while': 1, 'do': 1, 'for': 1}}
end_at_eof = False end_at_eof = False
end_at_tokens = {'delimiter': {';': 1}} end_at_tokens = {'delimiter': {';': 1}}
nocontinue_tokens = {'delimiter': {';': 1}} nocontinue_tokens = {'delimiter': {';': 1, ',': 1}}
start_free_tokens = {'string.start': 'string.end'} start_free_tokens = {'string.start': 'string.end'}
end_free_tokens = {'string.end': 'string.start'} end_free_tokens = {'string.end': 'string.start'}
start_macro_tokens = {'macro.start': 'macro.end'} start_macro_tokens = {'macro.start': 'macro.end'}

View File

@ -10,6 +10,7 @@ class StringGrammar(Grammar):
PatternRule('data', r'[^\\"]+'), PatternRule('data', r'[^\\"]+'),
] ]
# TODO: a lot of these rules need fixing
chr1 = '[a-zA-Z_]' chr1 = '[a-zA-Z_]'
chr2 = '[a-zA-Z0-9-_]' chr2 = '[a-zA-Z0-9-_]'
symb = chr1 + chr2 + '*' symb = chr1 + chr2 + '*'

View File

@ -1,7 +1,8 @@
import commands, os.path, string, sys, traceback import commands, os.path, string, sys, traceback
import color, completer, default, mode, regex, tab import color, completer, default, mode, regex, tab
from point import Point from point import Point
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePatternRule from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
from lex import NocasePatternRule, PatternMatchRule
from method.shell import Interact from method.shell import Interact
class AtomGrammar(Grammar): class AtomGrammar(Grammar):
@ -16,23 +17,28 @@ class StringGrammar(Grammar):
NocasePatternRule(r'data', r'[^\\"]+'), NocasePatternRule(r'data', r'[^\\"]+'),
] ]
chr1 = '[a-z]'
chr2 = '[a-zA-Z0-9_@]'
atom = chr1 + chr2 + '*'
class ErlangGrammar(Grammar): class ErlangGrammar(Grammar):
rules = [ rules = [
PatternRule(r'eol', r'\n'), PatternRule('eol', r'\n'),
PatternRule(r'comment', r'%.*$'), PatternRule('comment', '%.*$'),
PatternRule(r'erl_attribute', r'-[a-z][a-zA-Z0-9_@]+'), PatternRule('erl_attribute', '-' + atom),
PatternRule(r'erl_reserved', r"(?:xor|when|try|rem|receive|query|orelse|or|of|not|let|if|fun|end|div|cond|catch|case|bxor|bsr|bsl|bor|bnot|begin|band|andalso|and|after)(?![a-zA-Z0-9_'])"), RegionRule('erl_attribute', "-'", AtomGrammar ,"'"),
PatternRule(r'erl_arity', r'[a-z][a-zA-Z0-9_@]*/(?:0|[1-9][0-9]*)'), PatternRule('erl_reserved', "(?:xor|when|try|rem|receive|query|orelse|or|of|not|let|if|fun|end|div|cond|catch|case|bxor|bsr|bsl|bor|bnot|begin|band|andalso|and|after)(?!" + chr2 + ")"),
PatternRule(r'erl_function', r'[a-z][a-zA-Z0-9_@]*(?= *\()'), PatternRule('erl_arity', atom + '/(?:0|[1-9][0-9]*)'),
PatternRule(r'erl_namespace', r'[a-z][a-zA-Z0-9_@]*(?=:)'), PatternMatchRule('x', '('+atom+')( *)(\()', 'erl_function', 'spaces', 'delimiter'),
PatternRule(r'erl_builtin', r"whereis|unregister|unlink|tuple_to_list|tuple_size|trunc|tl|time|throw|term_to_binary|term_to_binary|statistics|split_binary|spawn_opt|spawn_opt|spawn_opt|spawn_opt|spawn_monitor|spawn_monitor|spawn_link|spawn_link|spawn_link|spawn_link|spawn|spawn|spawn|spawn|size|setelement|self|round|registered|register|put|purge_module|process_info|process_info|process_flag|process_flag|processes|pre_loaded|port_control|port_connect|port_command|port_close|pid_to_list|open_port|now|nodes|nodes|node|node|monitor_node|module_loaded|make_ref|load_module|list_to_tuple|list_to_pid|list_to_integer|list_to_float|list_to_existing_atom|list_to_bitstring|list_to_binary|list_to_atom|link|length|is_tuple|is_reference|is_record|is_record|is_process_alive|is_port|is_pid|is_number|is_list|is_integer|is_function|is_function|is_float|is_boolean|is_bitstring|is_binary|is_atom|is_alive|iolist_to_binary|iolist_size|iolist|iodata|integer_to_list|hd|halt|halt|group_leader|group_leader|get_keys|get|get|garbage_collect|garbage_collect|float_to_list|float|ext_binary|exit|exit|erase|erase|ence|element|disconnect_node|delete_module|date|concat_binary|check_process_code|byte_size|bitstring_to_list|bit_size|binary_to_term|binary_to_list|binary_to_list|atom_to_list|atom_to_list|apply|apply|apply|abs"), PatternMatchRule('x', '('+atom+')(:)', 'erl_namespace', 'delimiter'),
RegionRule(r'erl_atom', r"'", AtomGrammar, r"'"), PatternRule('erl_builtin', "(?:whereis|unregister|unlink|tuple_to_list|tuple_size|trunc|tl|time|throw|term_to_binary|term_to_binary|statistics|split_binary|spawn_opt|spawn_opt|spawn_opt|spawn_opt|spawn_monitor|spawn_monitor|spawn_link|spawn_link|spawn_link|spawn_link|spawn|spawn|spawn|spawn|size|setelement|self|round|registered|register|put|purge_module|process_info|process_info|process_flag|process_flag|processes|pre_loaded|port_control|port_connect|port_command|port_close|pid_to_list|open_port|now|nodes|nodes|node|node|monitor_node|module_loaded|make_ref|load_module|list_to_tuple|list_to_pid|list_to_integer|list_to_float|list_to_existing_atom|list_to_bitstring|list_to_binary|list_to_atom|link|length|is_tuple|is_reference|is_record|is_record|is_process_alive|is_port|is_pid|is_number|is_list|is_integer|is_function|is_function|is_float|is_boolean|is_bitstring|is_binary|is_atom|is_alive|iolist_to_binary|iolist_size|iolist|iodata|integer_to_list|hd|halt|halt|group_leader|group_leader|get_keys|get|get|garbage_collect|garbage_collect|float_to_list|float|ext_binary|exit|exit|erase|erase|ence|element|disconnect_node|delete_module|date|concat_binary|check_process_code|byte_size|bitstring_to_list|bit_size|binary_to_term|binary_to_list|binary_to_list|atom_to_list|atom_to_list|apply|apply|apply|abs)(?!" + chr2 + ")"),
RegionRule(r'string', r'"', StringGrammar, r'"'), RegionRule('erl_atom', "'", AtomGrammar, "'"),
PatternRule(r'erl_atom', r"[a-z][a-zA-Z0-9_@]*"), RegionRule('string', '"', StringGrammar, '"'),
PatternRule(r'erl_variable', r"[A-Z_][a-zA-Z0-9_@]*"), PatternRule('erl_atom', atom),
PatternRule(r'delimiter', r'->|<<|>>|\(|\)|{|}|\[|\]|\.|;|,|\|'), PatternRule('erl_variable', r"[A-Z_]" + chr2 + "*"),
PatternRule(r'operator', r'\+\+|--|==|/=|=<|<|>=|>|=:=|=/=>|-|\+|\*|/|:|#|!]'), PatternRule('delimiter', r'->|<<|>>|\(|\)|{|}|\[|\]|\.|;|,|\|'),
NocasePatternRule(r'number', r'\$.|[+-]?\d+#[a-z0-9]+|[+-]?\d+\.\d+|[+-]?\.\d+|[+-]?\d+'), PatternRule('operator', r'\+\+|--|==|/=|=<|<|>=|>|=:=|=/=>|-|\+|\*|/|:|#|!]'),
NocasePatternRule('number', r'\$.|[+-]?\d+#[a-z0-9]+|[+-]?\d+\.\d+|[+-]?\.\d+|[+-]?\d+'),
] ]
class ErlangTabber(tab.StackTabber): class ErlangTabber(tab.StackTabber):
@ -106,6 +112,7 @@ class Erlang(mode.Fundamental):
'erl_atom': ('magenta', 'default', 'bold'), 'erl_atom': ('magenta', 'default', 'bold'),
'erl_atom.start': ('magenta', 'default', 'bold'), 'erl_atom.start': ('magenta', 'default', 'bold'),
'erl_atom.null': ('magenta', 'default', 'bold'), 'erl_atom.null': ('magenta', 'default', 'bold'),
'erl_atom.data': ('magenta', 'default', 'bold'),
'erl_atom.end': ('magenta', 'default', 'bold'), 'erl_atom.end': ('magenta', 'default', 'bold'),
} }
actions = [ actions = [

View File

@ -1,6 +1,6 @@
import re import re
from method import Method from method import Method
import mode from mode import Fundamental
_error_regexes = [ _error_regexes = [
r'at (?P<file>\S+) line (?P<line>\d+)\.?$', #perl r'at (?P<file>\S+) line (?P<line>\d+)\.?$', #perl
@ -39,11 +39,11 @@ class ErrorGotoLine(Method):
a.methods['goto-line'].execute(b2.windows[0], lineno=line) a.methods['goto-line'].execute(b2.windows[0], lineno=line)
w.set_error(errline) w.set_error(errline)
class Error(mode.Fundamental): class Error(Fundamental):
name = 'Error' name = 'Error'
actions = [ErrorGotoLine] actions = [ErrorGotoLine]
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) Fundamental.__init__(self, w)
self.add_bindings('error-goto-line', ('RETURN', 'C-c M-g',)) self.add_bindings('error-goto-line', ('RETURN', 'C-c M-g',))
install = Error.install install = Error.install

View File

@ -7,57 +7,52 @@ from mode.python import StringGrammar2
from mode.pipe import Pipe from mode.pipe import Pipe
from method.shell import Interact from method.shell import Interact
class DataGrammar(Grammar): class DataGrammar(Grammar): rules = [PatternRule('data', r'[^)]+')]
rules = [PatternRule(r'data', r'[^)]+')] class LineGrammar(Grammar): rules = [PatternRule('data', r'.+')]
class LineGrammar(Grammar): class StringGrammar3(Grammar): rules = [PatternRule('data', r'[^)]+')]
rules = [PatternRule(r'data', r'.+')]
class StringGrammar3(Grammar):
rules = [PatternRule(r'data', r'[^)]+')]
class ForthGrammar(Grammar): class ForthGrammar(Grammar):
rules = [ rules = [
PatternRule(r'comment', r"\\(?: .*)?\n$"), PatternRule('comment', r"\\(?: .*)?\n$"),
RegionRule(r'comment', r'\((?= |\n)', DataGrammar, r'\)'), RegionRule('comment', r'\((?= |\n)', DataGrammar, r'\)'),
NocaseRegionRule(r'comment', r'0 \[if\]', DataGrammar, r'\[(?:endif|then)\]'), NocaseRegionRule('comment', r'0 \[if\]', DataGrammar, r'\[(?:endif|then)\]'),
RegionRule(r'string', r'[.cs]" ', StringGrammar2, r'"'), RegionRule('string', r'[.cs]" ', StringGrammar2, r'"'),
RegionRule(r'string', r'[.s]\\" ', StringGrammar2, r'"'), RegionRule('string', r'[.s]\\" ', StringGrammar2, r'"'),
RegionRule(r'string', r'\.\( ', StringGrammar3, r'\)'), RegionRule('string', r'\.\( ', StringGrammar3, r'\)'),
# builtin # builtin
NocasePatternRule(r'builtin', r'(?:true|false|on|off)(?= |\n|$)'), NocasePatternRule('builtin', r'(?:true|false|on|off)(?= |\n|$)'),
# mathn # mathn
NocasePatternRule(r'keyword', r'(?:\+|-|\*/mod|\*/|\*|/mod|/|mod|negate|abs|min|max|and|or|xor|not|lshift|rshift|invert|2\*|2/|2\+|2-|1\+|1-|8\*|under\+|m\+|m\*/|m\*|um/mod|um\*|fm/mod|sm/rem|d\+|d-|dnegate|dabs|dmin|dmax|d2\*|d2/|f\+|f-|f\*\*|f\*|f/|fnegate|fabs|fmax|fmin|floor|fround|fsqrt|fexpm1|fexp|flnp1|fln|flog|falog|fsincos|fsinh|fsin|fcosh|fcos|ftanh|ftan|fasinh|fasin|facosh|facos|fatan2|fatanh|fatan|f2\*|f2/|1/f|f~rel|f~abs|f~|0<>|0<=|0<|0=|0>=|0>|<>|<=|<|>=|>|=|u<=|u<|u>=|u>|d0<=|d0<>|d0<|d0=|d0>=|d0>|d<=|d<>|d<|d=|d>=|d>|du<=|du<|du>=|du>|within|\?negate|\?dnegate)(?= |\n|$)'), NocasePatternRule('keyword', r'(?:\+|-|\*/mod|\*/|\*|/mod|/|mod|negate|abs|min|max|and|or|xor|not|lshift|rshift|invert|2\*|2/|2\+|2-|1\+|1-|8\*|under\+|m\+|m\*/|m\*|um/mod|um\*|fm/mod|sm/rem|d\+|d-|dnegate|dabs|dmin|dmax|d2\*|d2/|f\+|f-|f\*\*|f\*|f/|fnegate|fabs|fmax|fmin|floor|fround|fsqrt|fexpm1|fexp|flnp1|fln|flog|falog|fsincos|fsinh|fsin|fcosh|fcos|ftanh|ftan|fasinh|fasin|facosh|facos|fatan2|fatanh|fatan|f2\*|f2/|1/f|f~rel|f~abs|f~|0<>|0<=|0<|0=|0>=|0>|<>|<=|<|>=|>|=|u<=|u<|u>=|u>|d0<=|d0<>|d0<|d0=|d0>=|d0>|d<=|d<>|d<|d=|d>=|d>|du<=|du<|du>=|du>|within|\?negate|\?dnegate)(?= |\n|$)'),
# stack # stack
NocasePatternRule(r'keyword', r'(?:drop|nip|dup|over|tuck|swap|rot|-rot|\?dup|pick|roll|2drop|2nip|2dup|2over|2tuck|2swap|2rot|2-rot|3dup|4dup|5dup|3drop|4drop|5drop|8drop|4swap|4rot|4-rot|4tuck|8swap|8dup|>r|r>|r@|rdrop|2>r|2r>|2r@|2rdrop|4>r|4r>|4r@|4rdrop|fdrop|fnip|fdup|fover|ftuck|fswap|frot)(?= |\n|$)'), NocasePatternRule('keyword', r'(?:drop|nip|dup|over|tuck|swap|rot|-rot|\?dup|pick|roll|2drop|2nip|2dup|2over|2tuck|2swap|2rot|2-rot|3dup|4dup|5dup|3drop|4drop|5drop|8drop|4swap|4rot|4-rot|4tuck|8swap|8dup|>r|r>|r@|rdrop|2>r|2r>|2r@|2rdrop|4>r|4r>|4r@|4rdrop|fdrop|fnip|fdup|fover|ftuck|fswap|frot)(?= |\n|$)'),
# pointer # pointer
NocasePatternRule(r'keyword', r'(?:forthsp|sp@|sp!|fp@|fp!|rp@|rp!|lp@|lp!)(?= |\n|$)'), NocasePatternRule('keyword', r'(?:forthsp|sp@|sp!|fp@|fp!|rp@|rp!|lp@|lp!)(?= |\n|$)'),
# address # address
NocasePatternRule(r'keyword', r'(?:@|!|\+!|c@|c!|2@|2!|f@|f!|sf@|sf!|df@|df!|chars|char\+|cells|cell\+|cell|align|aligned|floats|float\+|float|faligned|falign|sfloats|sfloat\+|sfaligned|sfalign|dfloats|dfloat\+|dfaligned|dfalign|maxaligned|maxalign|cfaligned|cfalign|address-unit-bits|allot|allocate|here|move|erase|cmove>|cmove|fill|blank)(?= |\n|$)'), NocasePatternRule('keyword', r'(?:@|!|\+!|c@|c!|2@|2!|f@|f!|sf@|sf!|df@|df!|chars|char\+|cells|cell\+|cell|align|aligned|floats|float\+|float|faligned|falign|sfloats|sfloat\+|sfaligned|sfalign|dfloats|dfloat\+|dfaligned|dfalign|maxaligned|maxalign|cfaligned|cfalign|address-unit-bits|allot|allocate|here|move|erase|cmove>|cmove|fill|blank)(?= |\n|$)'),
# conditional (*) # conditional (*)
NocasePatternRule(r'builtin', r'(?:if|else|endif|then|case|of|endof|endcase|\?dup-if|\?dup-0=-if|ahead|cs-pick|cs-roll|catch|throw|within)(?= |\n|$)'), NocasePatternRule('builtin', r'(?:if|else|endif|then|case|of|endof|endcase|\?dup-if|\?dup-0=-if|ahead|cs-pick|cs-roll|catch|throw|within)(?= |\n|$)'),
# iter (*) # iter (*)
NocasePatternRule(r'builtin', r'(?:begin|while|repeat|until|again|\?do|loop|i|j|k|\+do|u\+do|u-do|-do|do|\+loop|-loop|unloop|leave|\?leave|exit|done|for|next)(?= |\n|$)'), NocasePatternRule('builtin', r'(?:begin|while|repeat|until|again|\?do|loop|i|j|k|\+do|u\+do|u-do|-do|do|\+loop|-loop|unloop|leave|\?leave|exit|done|for|next)(?= |\n|$)'),
# define # define
NocasePatternRule(r'builtin', r'(?:constant|2constant|fconstant|variable|2variable|fvariable|create|user|to|defer|is|does>|immediate|compile-only|compile|restrict|interpret|postpone|execute|literal|create-interpret/compile|interpretation>|<interpretation|compilation>|<compilation|\]|lastxt|comp\'|postpone|find-name|name>int|name\?int|name>comp|name>string|state|c;|cvariable|,|2,|f,|c,|\[(?:ifdef|ifundef|then|endif|then|else|\?do|do|loop|\+loop|next|begin|until|again|while|repeat|comp\'|\'|compile)\])(?= |\n|$)'), NocasePatternRule('builtin', r'(?:constant|2constant|fconstant|variable|2variable|fvariable|create|user|to|defer|is|does>|immediate|compile-only|compile|restrict|interpret|postpone|execute|literal|create-interpret/compile|interpretation>|<interpretation|compilation>|<compilation|\]|lastxt|comp\'|postpone|find-name|name>int|name\?int|name>comp|name>string|state|c;|cvariable|,|2,|f,|c,|\[(?:ifdef|ifundef|then|endif|then|else|\?do|do|loop|\+loop|next|begin|until|again|while|repeat|comp\'|\'|compile)\])(?= |\n|$)'),
# assembly (*) # assembly (*)
NocasePatternRule(r'builtin', r'(?:assembler|code|end-code|;code|flush-icache|c,)(?= |\n|$)'), NocasePatternRule('builtin', r'(?:assembler|code|end-code|;code|flush-icache|c,)(?= |\n|$)'),
# xyz # xyz
NocasePatternMatchRule(r'x', r'(:)( +)([^ ]+)', r'delimiter', r'spaces', NocasePatternMatchRule('x', r'(:)( +)([^ ]+)', r'delimiter', r'spaces', r'function'),
r'function'), PatternRule('delimiter', r"[:;\[\]]"),
PatternRule(r'delimiter', r"[:;\[\]]"), NocasePatternRule('number', r"'[a-z](?= |$)"),
NocasePatternRule(r'number', r"'[a-z](?= |$)"), NocasePatternRule('number', r'%?-?[0-1]+\.?(?= |$)'),
NocasePatternRule(r'number', r'%?-?[0-1]+\.?(?= |$)'), NocasePatternRule('number', r'[&#]?-?[0-9]+\.?(?= |$)'),
NocasePatternRule(r'number', r'[&#]?-?[0-9]+\.?(?= |$)'), NocasePatternRule('number', r"(?:0x|\$)[0-9a-f]+\.?(?= |$)"),
NocasePatternRule(r'number', r"(?:0x|\$)[0-9a-f]+\.?(?= |$)"), NocasePatternRule('number', r'[+-]?[0-9]+\.?e?[+-][0-9]+(?= |$)'),
NocasePatternRule(r'number', r'[+-]?[0-9]+\.?e?[+-][0-9]+(?= |$)'), PatternRule('forth_word', r'[^ ]+'),
PatternRule(r'forth_word', r'[^ ]+'), PatternRule('spaces', r' +'),
PatternRule(r'spaces', r' +'), PatternRule('eol', r'\n'),
PatternRule(r'eol', r'\n'),
] ]
class GforthStart(Interact): class GforthStart(Interact):
@ -77,15 +72,14 @@ class GforthLoadFile(Interact):
class CodePipeGrammar(Grammar): class CodePipeGrammar(Grammar):
rules = [ rules = [
PatternRule(r'comment', r"\\(?: .*)?\n$"), PatternRule('comment', r"\\(?: .*)?\n$"),
PatternRule(r'addr', r'\$[0-9A-F]+'), PatternRule('addr', r'\$[0-9A-F]+'),
PatternRule(r'addr2', r'\[[a-z]+\]'), PatternRule('addr2', r'\[[a-z]+\]'),
] ]
br = RegionRule('banner', r'^Gforth \d+\.\d+\.\d+', LineGrammar, r"^Type `bye' to exit\n$")
class ForthPipeGrammar(Grammar): class ForthPipeGrammar(Grammar):
rules = list(ForthGrammar.rules) rules = [br] + ForthGrammar.rules
br = RegionRule(r'banner', r'^Gforth \d+\.\d+\.\d+', LineGrammar, r"^Type `bye' to exit\n$")
ForthPipeGrammar.rules.insert(0, br)
class ForthPipe(Pipe): class ForthPipe(Pipe):
name = 'forthpipe' name = 'forthpipe'

View File

@ -1,9 +1,8 @@
import commands, os.path, string, sys, traceback import os.path
import color, completer, default, mode, method, regex, tab from method.shell import Interact
import buffer.emul from mode import Fundamental
import window
from point import Point
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePatternRule from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePatternRule
from tab import Tabber
class CommentGrammar(Grammar): pass class CommentGrammar(Grammar): pass
CommentGrammar.rules = [ CommentGrammar.rules = [
@ -41,27 +40,26 @@ class HaskellGrammar(Grammar):
PatternRule(r'operator', r'@|!|>@>|>>=|>>|=>|::|->|;|<-|\\\\|\.\.|!!|:|\+\+|\||\.|\\|>=|>|/=|==|<=|<|\|\||&&|\^\^|\*\*|##|\^|/|\*|-|\+|='), PatternRule(r'operator', r'@|!|>@>|>>=|>>|=>|::|->|;|<-|\\\\|\.\.|!!|:|\+\+|\||\.|\\|>=|>|/=|==|<=|<|\|\||&&|\^\^|\*\*|##|\^|/|\*|-|\+|='),
] ]
class HugsStart(method.shell.Interact): class HugsStart(Interact):
args = [] args = []
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
method.shell.Interact._execute(self, w, bname='*Hugs*', cmd='hugs') Interact._execute(self, w, bname='*Hugs*', cmd='hugs')
class HugsLoadFile(method.shell.Interact): class HugsLoadFile(Interact):
args = [] args = []
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
method.shell.Interact._execute(self, w, bname='*Hugs*', cmd='hugs') Interact._execute(self, w, bname='*Hugs*', cmd='hugs')
b = w.application.get_buffer_by_name('*Hugs*') b = w.application.get_buffer_by_name('*Hugs*')
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 HaskellTabber(tab.Tabber): class HaskellTabber(Tabber):
pass pass
class Haskell(mode.Fundamental): class Haskell(Fundamental):
name = 'Haskell' name = 'Haskell'
extensions = ['.hs'] extensions = ['.hs']
tabwidth = 4 tabwidth = 4
commentc = '--' commentc = '--'
#tabbercls = mode.lisp.LispTabber
grammar = HaskellGrammar grammar = HaskellGrammar
opentokens = ('delimiter',) opentokens = ('delimiter',)
opentags = {'(': ')', '{': '}', '[': ']'} opentags = {'(': ')', '{': '}', '[': ']'}

View File

@ -1,6 +1,7 @@
import re, string, struct import re, string, struct
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
import color, mode import color
from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule
from method import Method, Argument from method import Method, Argument
from method.move import GotoBeginning, GotoEnd from method.move import GotoBeginning, GotoEnd
@ -216,7 +217,7 @@ class ShowAddress(Method):
addr = w.buffer.get_address(cy, ix) addr = w.buffer.get_address(cy, ix)
w.set_error("Cursor's address is 0x%08x" % addr) w.set_error("Cursor's address is 0x%08x" % addr)
class Hex(mode.Fundamental): class Hex(Fundamental):
name = 'Hex' name = 'Hex'
config = { config = {
'hex.disinst': 'disinst', 'hex.disinst': 'disinst',
@ -249,7 +250,7 @@ class Hex(mode.Fundamental):
format = "%(flag)s %(bname)-18s (%(mname)s) {%(symbolic)s} %(cursor)s %(perc)s" format = "%(flag)s %(bname)-18s (%(mname)s) {%(symbolic)s} %(cursor)s %(perc)s"
def get_status_names(self): def get_status_names(self):
names = mode.Fundamental.get_status_names(self) names = Fundamental.get_status_names(self)
if self.symbolic_edit: if self.symbolic_edit:
names['symbolic'] = 'symbolic' names['symbolic'] = 'symbolic'
else: else:
@ -271,7 +272,7 @@ class Hex(mode.Fundamental):
return [[lo(s0), hi(s1), lo(s2), lo(s3)]] return [[lo(s0), hi(s1), lo(s2), lo(s3)]]
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) Fundamental.__init__(self, w)
self.bindings = {} self.bindings = {}
self.lmargin = 12 self.lmargin = 12

View File

@ -1,5 +1,8 @@
import os, urllib import os
import color, default, method, mode import urllib
import default
import method
from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule
from mode.xml import TagGrammar from mode.xml import TagGrammar
from mode.javascript import JavascriptGrammar from mode.javascript import JavascriptGrammar
@ -72,7 +75,7 @@ class HtmlCheckSpelling(method.Method):
if w.buffer.changed_on_disk(): if w.buffer.changed_on_disk():
w.buffer.reload() w.buffer.reload()
class HTML(mode.Fundamental): class HTML(Fundamental):
name = 'HTML' name = 'HTML'
extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml'] extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml']
grammar = HTMLGrammar grammar = HTMLGrammar

View File

@ -1,35 +1,34 @@
import code, re, string, StringIO, sys, traceback from mode import Fundamental
import color, completer, lex, method, mode from method import Method
from lex import Grammar, PatternRule from lex import Grammar, PatternRule
from mode.python import PythonGrammar from mode.python import PythonGrammar
from point import Point
def insert_line(w): def insert_line(w):
s = w.buffer.make_string() s = w.buffer.make_string()
w.mode.lines.append(s) w.mode.lines.append(s)
w.buffer.set_data('') w.buffer.set_data('')
class MiniInsertTab(method.Method): class MiniInsertTab(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.insert_string_at_cursor(' ' * w.mode.tabwidth) w.insert_string_at_cursor(' ' * w.mode.tabwidth)
class MiniInsertLine(method.Method): class MiniInsertLine(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
insert_line(w) insert_line(w)
class MiniInsertComplete(method.Method): class MiniInsertComplete(Method):
def execute(self, w, **vargs): def execute(self, w, **vargs):
insert_line(w) insert_line(w)
w.buffer.callback('\n'.join(w.mode.lines)) w.buffer.callback('\n'.join(w.mode.lines))
w.application.close_mini_buffer() w.application.close_mini_buffer()
class MiniInsertCancel(method.Method): class MiniInsertCancel(Method):
def execute(self, w, **vargs): def execute(self, w, **vargs):
w.application.close_mini_buffer() w.application.close_mini_buffer()
class InsertMini(mode.Fundamental): class InsertMini(Fundamental):
name = 'InsertMini' name = 'InsertMini'
actions = [MiniInsertLine, MiniInsertComplete, MiniInsertCancel, actions = [MiniInsertLine, MiniInsertComplete, MiniInsertCancel,
MiniInsertTab] MiniInsertTab]
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) Fundamental.__init__(self, w)
self.bindings = {} self.bindings = {}
self.saved_input = "" self.saved_input = ""

View File

@ -1,4 +1,4 @@
import color, mode from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule
from mode.perl import StringGrammar, PerlGrammar from mode.perl import StringGrammar, PerlGrammar
@ -9,15 +9,15 @@ class IperlGrammar(Grammar):
RegionRule(r'iperl_input', r'^(?:>>>|\.\.>)', PerlGrammar, '\n$'), RegionRule(r'iperl_input', r'^(?:>>>|\.\.>)', PerlGrammar, '\n$'),
PatternRule(r'iperl_reserved', r'undef'), PatternRule(r'iperl_reserved', r'undef'),
] ]
class Iperl(mode.Fundamental): class Iperl(Fundamental):
name = 'IPerl' name = 'IPerl'
grammar = IperlGrammar() grammar = IperlGrammar()
colors = { colors = {
'iperl_input.start': ('red', 'default', 'bold'), 'iperl_input.start': ('red', 'default', 'bold'),
'iperl_reserved': ('magenta', 'default', 'bold'), 'iperl_reserved': ('magenta', 'default', 'bold'),
} }
def __init__(self, w): _bindings = {
mode.Fundamental.__init__(self, w) 'iperl-start': ('M-e',),
self.add_bindings('iperl-start', ('M-e',)) }
install = Iperl.install install = Iperl.install

View File

@ -1,5 +1,8 @@
import code, re, string, StringIO, sys, traceback import re, string
import buffer, color, completer, lex, method, mode, mode.mini, mode.consolemini, window import buffer, completer, mode.mini, mode.consolemini
from window import Window
from method import Method
from mode import Fundamental
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
from mode.perl import PerlGrammar from mode.perl import PerlGrammar
from point import Point from point import Point
@ -7,7 +10,7 @@ from point import Point
PAD = ' ' PAD = ' '
LIMIT = 79 LIMIT = 79
class IperlExec(method.Method): class IperlExec(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
if w.application.completion_window_is_open(): if w.application.completion_window_is_open():
w.application.close_completion_buffer() w.application.close_completion_buffer()
@ -30,7 +33,7 @@ class IperlExec(method.Method):
if output: if output:
b.insert_string(b.get_buffer_end(), output, force=True) b.insert_string(b.get_buffer_end(), output, force=True)
class IperlTab(method.Method): class IperlTab(Method):
def execute(self, w, **vargs): def execute(self, w, **vargs):
a = w.application a = w.application
s = w.buffer.make_string() s = w.buffer.make_string()
@ -54,7 +57,7 @@ class IperlTab(method.Method):
w.insert_string_at_cursor(s) w.insert_string_at_cursor(s)
mode.mini.use_completion_window(a, s, [word+s for s in candidates]) mode.mini.use_completion_window(a, s, [word+s for s in candidates])
class IperlPathStart(method.Method): class IperlPathStart(Method):
'''Interactively run perl statements in the context of a buffer''' '''Interactively run perl statements in the context of a buffer'''
def _start(self, w, parent, switch=True): def _start(self, w, parent, switch=True):
a = w.application a = w.application
@ -65,7 +68,7 @@ class IperlPathStart(method.Method):
if not a.has_buffer_name(name): if not a.has_buffer_name(name):
b = buffer.IperlBuffer(parent, a) b = buffer.IperlBuffer(parent, a)
a.add_buffer(b) a.add_buffer(b)
window.Window(b, a) Window(b, a)
else: else:
b = a.get_buffer_by_name(name) b = a.get_buffer_by_name(name)
self.main_buffer = b self.main_buffer = b
@ -90,7 +93,7 @@ class IperlGotoBeginning(mode.consolemini.ConsoleGotoBeginning):
class IperlGotoEnd(mode.consolemini.ConsoleGotoEnd): class IperlGotoEnd(mode.consolemini.ConsoleGotoEnd):
subbuf = '*IPerl*' subbuf = '*IPerl*'
class IperlMini(mode.Fundamental): class IperlMini(Fundamental):
name = 'IperlMini' name = 'IperlMini'
actions = [IperlExec, IperlTab, IperlStart, IperlPathStart, actions = [IperlExec, IperlTab, IperlStart, IperlPathStart,
IperlPageUp, IperlPageDown, IperlGotoBeginning, IperlGotoEnd] IperlPageUp, IperlPageDown, IperlGotoBeginning, IperlGotoEnd]
@ -124,7 +127,7 @@ class IperlMini(mode.Fundamental):
return self.window.buffer.method.main_buffer return self.window.buffer.method.main_buffer
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) Fundamental.__init__(self, w)
self.history = [''] self.history = ['']
self.hindex = 0 self.hindex = 0
b = self.get_iperl() b = self.get_iperl()

View File

@ -1,4 +1,4 @@
import color, mode from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar1, StringGrammar2, PythonGrammar from mode.python import StringGrammar1, StringGrammar2, PythonGrammar
@ -10,15 +10,15 @@ class IpythonGrammar(Grammar):
RegionRule(r'ipython_input', r'^(?:>>>|-->)', PythonGrammar, '\n$'), RegionRule(r'ipython_input', r'^(?:>>>|-->)', PythonGrammar, '\n$'),
PatternRule(r'ipython_reserved', r'undef'), PatternRule(r'ipython_reserved', r'undef'),
] ]
class Ipython(mode.Fundamental): class Ipython(Fundamental):
name = 'IPython' name = 'IPython'
grammar = IpythonGrammar() grammar = IpythonGrammar()
colors = { colors = {
'ipython_input.start': ('red', 'default', 'bold'), 'ipython_input.start': ('red', 'default', 'bold'),
'ipython_reserved': ('magenta', 'default', 'bold'), 'ipython_reserved': ('magenta', 'default', 'bold'),
} }
def __init__(self, w): _bindings = {
mode.Fundamental.__init__(self, w) 'ipython-start': ('M-e',),
self.add_bindings('ipython-start', ('M-e',)) }
install = Ipython.install install = Ipython.install

View File

@ -1,4 +1,4 @@
import color, mode, tab import mode, tab
import context import context
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
from mode.python import StringGrammar2 from mode.python import StringGrammar2
@ -12,27 +12,39 @@ class CommentGrammar(Grammar):
PatternRule(r"data", r"(?:[^@*]|\*(?!/))+"), PatternRule(r"data", r"(?:[^@*]|\*(?!/))+"),
] ]
chr1 = '[a-zA-Z_]'
chr2 = '[a-zA-Z0-9_]'
word1 = chr1 + chr2 + '*'
word2 = '(?:' + word1 + r'\.' + ')*' + word1
class JavaGrammar(Grammar): class JavaGrammar(Grammar):
rules = [ rules = [
PatternRule(r"spaces", r" +"), PatternRule(r"spaces", r" +"),
PatternRule(r'import', r'(?<=import ) *[a-zA-Z0-9_.*]+'), PatternMatchRule('x', r'(import)( +)(' + word2 + '(?:\.\*)?)', 'keyword', 'spaces', 'import'),
PatternRule(r'package', r'(?<=package ) *[a-zA-Z0-9_.*]+'), PatternMatchRule('x', r'(package)( +)(' + word2 + ')', 'keyword', 'spaces', 'package'),
PatternMatchRule('x', r'(class)( +)(' + word1 + ')', 'keyword', 'spaces', 'java_class'),
PatternMatchRule('x', '(new)( +)(' + word2 + ')', 'keyword', 'spaces', 'java_class'),
RegionRule(r'java_comment', '/\*', CommentGrammar, '\*/'), RegionRule(r'java_comment', '/\*', CommentGrammar, '\*/'),
PatternRule(r'java_comment', r'//.*$'), PatternRule(r'comment', r'//.*$'),
PatternRule(r'keyword', r"(?:abstract|assert|boolean|break|byte|case|catch|char|class|continue|default|double|do|else|extends|finally|final|float|for|if|implements|import|instanceof|interface|int|long|native|new|package|private|protected|public|return|short|static|switch|super|synchronized|threadsafe|throws|throw|transient|try|void|while)(?![a-zA-Z_])"), PatternRule(r'keyword', r"(?:abstract|assert|break|case|catch|class|continue|default|do|else|extends|finally|final|for|if|implements|import|instanceof|interface|native|new|package|private|protected|public|return|static|switch|super|synchronized|threadsafe|throws|throw|transient|try|while)(?![a-zA-Z_])"),
PatternRule(r'java_label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'), PatternRule(r'java_label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
PatternMatchRule('x', '(' + word2 + ')((?:\[\])?)( +)(' + word1 + ')( *)(\()',
'java_type', 'delimiter', 'spaces', 'java_function', 'spaces', 'delimiter'),
PatternMatchRule('x', '(' + word2 + ')((?:\[\])?)( +)(' + word1 + ')(?! *\()',
'java_type', 'delimiter', 'spaces', 'identifier'),
PatternRule(r'java_builtin', r"(?:null|true|false|this)"), PatternRule(r'java_builtin', r"(?:null|true|false|this)"),
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"), PatternRule(r'identifier', word1),
PatternRule(r"unop", r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="), PatternRule(r"operator", r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"), PatternRule(r'operator', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"), PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"),
PatternRule(r"java_integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"), PatternRule(r"integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
PatternRule(r"java_float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"), PatternRule(r"float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
RegionRule(r'string', '"', StringGrammar2, '"'), RegionRule(r'string', '"', StringGrammar2, '"'),
PatternRule(r'java_char', r"'.'|'\\.'|'\\[0-7]{3}'"), PatternRule(r'java_char', r"'.'|'\\.'|'\\[0-7]{3}'"),
PatternRule(r"eol", r"\n$"), PatternRule(r"eol", r"\n$"),
@ -44,7 +56,7 @@ CLASS_MATCH = And(Optional(Name('spaces')),
Name('spaces'), Name('spaces'),
Match('keyword', 'class'), Match('keyword', 'class'),
Name('spaces'), Name('spaces'),
Name('identifier')) Name('java_class'))
CLASS_OFFSET = 1 CLASS_OFFSET = 1
METHOD_MATCH = And(Optional(Name('spaces')), METHOD_MATCH = And(Optional(Name('spaces')),
Matchs('keyword', ('public', 'protected', 'private')), Matchs('keyword', ('public', 'protected', 'private')),
@ -52,7 +64,7 @@ METHOD_MATCH = And(Optional(Name('spaces')),
Optional(And(Match('keyword', 'static'), Name('spaces'))), Optional(And(Match('keyword', 'static'), Name('spaces'))),
Any(), Any(),
Name('spaces'), Name('spaces'),
Name('identifier'), Name('java_function'),
Optional(Name('spaces')), Optional(Name('spaces')),
Match('delimiter', '(')) Match('delimiter', '('))
METHOD_OFFSET = 2 METHOD_OFFSET = 2
@ -69,10 +81,8 @@ class JavaTabber2(tab.StackTabber2):
'java_comment.end': 1} 'java_comment.end': 1}
start_free_tokens = {'string.start': 'string.end'} start_free_tokens = {'string.start': 'string.end'}
end_free_tokens = {'string.end': 'string.start'} end_free_tokens = {'string.end': 'string.start'}
def is_base(self, y): def is_base(self, y): return y == 0
return y == 0 def _is_indent(self, t): return t.name == 'spaces'
def _is_indent(self, t):
return t.name == 'spaces'
def _is_ignored(self, t): def _is_ignored(self, t):
return t.fqname() in ('spaces', 'eol', 'comment', 'comment.start', return t.fqname() in ('spaces', 'eol', 'comment', 'comment.start',
'comment.data', 'comment.null', 'comment.end') 'comment.data', 'comment.null', 'comment.end')
@ -134,27 +144,31 @@ class Java(mode.Fundamental):
'java_comment.data': ('red', 'default', 'bold'), 'java_comment.data': ('red', 'default', 'bold'),
'java_comment.null': ('red', 'default', 'bold'), 'java_comment.null': ('red', 'default', 'bold'),
'import': ('blue', 'default', 'bold'), 'import': ('blue', 'default', 'bold'),
'java_class': ('green', 'default', 'bold'),
'java_label': ('magenta', 'default', 'bold'), 'java_label': ('magenta', 'default', 'bold'),
'java_builtin': ('magenta', 'default', 'bold'), 'java_builtin': ('magenta', 'default', 'bold'),
'java_char': ('green', 'default', 'bold'), 'java_char': ('green', 'default', 'bold'),
'java_integer': ('green', 'default', 'bold'), 'java_function': ('blue', 'default', 'bold'),
'java_float': ('green', 'default', 'bold'), 'java_type': ('magenta', 'default', 'bold'),
}
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
} }
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]" format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.context = JavaContext(self)
def get_status_names(self): def get_status_names(self):
names = mode.Fundamental.get_status_names(self) names = mode.Fundamental.get_status_names(self)
c = self.window.logical_cursor() c = self.window.logical_cursor()
names['func'] = self.get_line_function(c.y) names['func'] = self.get_line_function(c.y)
return names return names
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.context = JavaContext(self)
def get_functions(self): def get_functions(self):
return self.context.get_names() return self.context.get_names()
def get_function_names(self): def get_function_names(self):

View File

@ -24,32 +24,36 @@ class RegexGrammar(Grammar):
PatternRule(r'data', r'[^/\\]+'), PatternRule(r'data', r'[^/\\]+'),
] ]
chr1 = '[a-zA-Z_]'
chr2 = '[a-zA-Z_0-9]'
word = chr1 + chr2 + '*'
class JavascriptGrammar(Grammar): class JavascriptGrammar(Grammar):
rules = [ rules = [
PatternRule(r'comment', r'//.*$'), PatternRule(r'comment', r'//.*$'),
RegionRule(r'comment', '/\*', Grammar, '\*/'), RegionRule(r'comment', '/\*', Grammar, '\*/'),
PatternRule(r'continuation', r'\\(?= *$)'), PatternRule(r'continuation', r'\\(?= *$)'),
PatternMatchRule(r'x', r'(function)( +)([a-zA-Z_][a-zA-Z0-9_]*)', 'js_reserved', r'spaces', r'js_function'), PatternMatchRule(r'x', r'(function)( +)('+word+')', 'js_reserved', r'spaces', r'js_function'),
PatternMatchRule(r'x', r'(class|new)( +)([a-zA-Z_][a-zA-Z0-9_]*)', 'js_reserved', r'spaces', r'js_class'), PatternMatchRule(r'x', r'(class|new)( +)('+word+')', 'js_reserved', r'spaces', r'js_class'),
PatternRule(r'js_reserved', r'(?:abstract|as|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|get|goto|if|import|implements|include|instanceof|interface|in|is|namespace|native|new|null|package|private|protected|public|return|set|super|switch|synchronized|this|throws|throw|transient|true|try|typeof|use|var|void|volatile|while|with)(?![a-zA-Z0-9_])'), PatternRule(r'js_reserved', r'(?:abstract|as|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|get|goto|if|import|implements|include|instanceof|interface|in|is|namespace|native|new|null|package|private|protected|public|return|set|super|switch|synchronized|this|throws|throw|transient|true|try|typeof|use|var|void|volatile|while|with)(?!'+chr2+')'),
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"), PatternRule(r'identifier', word),
PatternRule(r'integer', r"(?:0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"), PatternRule(r'integer', r"(?:0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
PatternRule(r'float', r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"), PatternRule(r'float', r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
PatternRule(r'eol', r'\n'),
PatternRule(r'spaces', r' +'),
PatternRule(r'delimiter', r'%=|&&=|&=|\(|\)|\*=|\+=|,|-=|\.{3}|\.|/=(?= |$)|::|:|;|<<=|>>=|>>>=|\?|\[|\]|^=|^^=|\{|\}|\|=|\|\|='),
# fucking javascript! # fucking javascript!
# their lexer grammar requires one-token look-behind in order to know # their lexer grammar requires one-token look-behind in order to know
# whether a "/" starts a literal regex, or is part of a mathematical # whether a "/" starts a literal regex, or is part of a mathematical
# expression/assignment. so for now we will require either a space or $ # expression/assignment.
# after / in order to *not* treat it as a regex. dammit! RegionRule('js_regex', "(?<=[\(=:,]) */", RegexGrammar, "/[a-z]*"),
PatternRule(r'eol', r'\n'), PatternRule(r'operator', r'!==|!=|!|%|&&|&|\*|\+\+|\+|--|-|/|<<=|<<|<=|<|===|==|=|>>>=|>>>|>>=|>>|>=|>|\\|\|\|'),
PatternRule(r'spaces', r' +'),
PatternRule(r'delimiter', r'%=|&&=|&=|\(|\)|\*=|\+=|,|-=|\.{3}|\.|/=(?= |$)|::|:|;|<<=|>>=|>>>=|\?|\[|\]|^=|^^=|\{|\}|\|=|\|\|='),
PatternRule(r'operator', r'!==|!=|!|%|&&|&|\*|\+\+|\+|--|-|/(?= |$)|<<=|<<|<=|<|===|==|=|>>>=|>>>|>>=|>>|>=|>|\\|\|\|'),
RegionRule('js_regex', "/", RegexGrammar, "/[a-z]*"),
RegionRule('string', "'", StringGrammar1, "'"), RegionRule('string', "'", StringGrammar1, "'"),
RegionRule('string', '"', StringGrammar2, '"'), RegionRule('string', '"', StringGrammar2, '"'),
] ]
@ -60,7 +64,7 @@ class JavascriptTabber2(tab.StackTabber2):
control_tokens = {'keyword': {'if': 1, 'else': 1, 'while': 1, 'do': 1, 'for': 1}} control_tokens = {'keyword': {'if': 1, 'else': 1, 'while': 1, 'do': 1, 'for': 1}}
end_at_eof = False end_at_eof = False
end_at_tokens = {'delimiter': {';': 1}} end_at_tokens = {'delimiter': {';': 1}}
nocontinue_tokens = {'delimiter': {';': 1}, nocontinue_tokens = {'delimiter': {';': 1, ',': 1},
'comment': 1, 'comment': 1,
'comment.start': 1, 'comment.start': 1,
'comment.data': 1, 'comment.data': 1,
@ -68,11 +72,9 @@ class JavascriptTabber2(tab.StackTabber2):
start_free_tokens = {'string.start': 'string.end'} start_free_tokens = {'string.start': 'string.end'}
end_free_tokens = {'string.end': 'string.start'} end_free_tokens = {'string.end': 'string.start'}
def is_base(self, y): def is_base(self, y):
if y == 0: if y == 0: return True
return True
highlighter = self.mode.window.buffer.highlights[self.mode.name] highlighter = self.mode.window.buffer.highlights[self.mode.name]
if not highlighter.tokens[y]: if not highlighter.tokens[y]: return False
return False
t = highlighter.tokens[y][0] t = highlighter.tokens[y][0]
return t.name == 'js_reserved' and t.string == 'function' return t.name == 'js_reserved' and t.string == 'function'
def _is_indent(self, t): def _is_indent(self, t):

View File

@ -1,14 +1,13 @@
import commands, curses, os, sys import os
import color, method, mode import sys
from mode import Fundamental
from method import Method
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule
from mode.text import TextInsertSpace from mode.text import TextInsertSpace
class ArgumentGrammar(Grammar): class ArgumentGrammar(Grammar): rules = [PatternRule(r'data', r'[^}]+')]
rules = [PatternRule(r'data', r'[^}]+')] class StringGrammar1(Grammar): rules = [PatternRule(r'data', r"[^']+")]
class StringGrammar1(Grammar): class StringGrammar2(Grammar): rules = [PatternRule(r'data', r"(?:[^']|'(?!'))+")]
rules = [PatternRule(r'data', r"[^']+")]
class StringGrammar2(Grammar):
rules = [PatternRule(r'data', r"(?:[^']|'(?!'))+")]
class LatexGrammar(Grammar): class LatexGrammar(Grammar):
rules = [ rules = [
@ -23,7 +22,7 @@ class LatexGrammar(Grammar):
PatternRule(r'data', r'[^{}$^_%~#&%\\`]+'), PatternRule(r'data', r'[^{}$^_%~#&%\\`]+'),
] ]
class LatexBuild(method.Method): class LatexBuild(Method):
'''Insert a pair of LaTeX-style single-quotes into the buffer''' '''Insert a pair of LaTeX-style single-quotes into the buffer'''
def _getcmd(self, w): def _getcmd(self, w):
return w.application.config.get('latex.buildcmd') return w.application.config.get('latex.buildcmd')
@ -78,23 +77,18 @@ class LatexViewPdf(LatexBuildPdf):
pdfpath = self._modpath(w, '.pdf') pdfpath = self._modpath(w, '.pdf')
os.execvp(viewcmd, (viewcmd, pdfpath)) os.execvp(viewcmd, (viewcmd, pdfpath))
#class LatexCommentRegion(method.CommentRegion): class LatexInsertSquotes(Method):
# commentc = '%'
#class LatexUncommentRegion(method.UncommentRegion):
# commentc = '%'
class LatexInsertSquotes(method.Method):
'''Insert a pair of LaTeX-style single-quotes into the buffer''' '''Insert a pair of LaTeX-style single-quotes into the buffer'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.insert_string_at_cursor("`'") w.insert_string_at_cursor("`'")
w.backward() w.backward()
class LatexInsertDquotes(method.Method): class LatexInsertDquotes(Method):
'''Insert a pair of LaTeX-style double-quotes into the buffer''' '''Insert a pair of LaTeX-style double-quotes into the buffer'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.insert_string_at_cursor("``''") w.insert_string_at_cursor("``''")
w.backward() w.backward()
w.backward() w.backward()
class LatexInsertBraces(method.Method): class LatexInsertBraces(Method):
'''Insert a pair of curly braces into the buffer''' '''Insert a pair of curly braces into the buffer'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.insert_string_at_cursor("{}") w.insert_string_at_cursor("{}")
@ -103,7 +97,7 @@ class LatexInsertBraces(method.Method):
class LatexInsertSpace(TextInsertSpace): class LatexInsertSpace(TextInsertSpace):
pass pass
class LatexCheckSpelling(method.Method): class LatexCheckSpelling(Method):
"""Check the spelling of the document via ispell -t""" """Check the spelling of the document via ispell -t"""
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
# -x no backup file # -x no backup file
@ -113,7 +107,7 @@ class LatexCheckSpelling(method.Method):
if w.buffer.changed_on_disk(): if w.buffer.changed_on_disk():
w.buffer.reload() w.buffer.reload()
class Latex(mode.Fundamental): class Latex(Fundamental):
name = 'Latex' name = 'Latex'
extensions = ['.latex', '.tex'] extensions = ['.latex', '.tex']
commentc = '%' commentc = '%'

View File

@ -1,8 +1,13 @@
import commands import commands
import color, mode, method, tab from method import Method
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
from mode.python import StringGrammar1, StringGrammar2 from mode.python import StringGrammar1, StringGrammar2
chr1 = '[a-zA-Z_]'
chr2 = '[a-zA-Z_0-9]'
word = chr1 + chr2 + '*'
class LuaGrammar(Grammar): class LuaGrammar(Grammar):
rules = [ rules = [
PatternRule(r'comment', r'--.*$'), PatternRule(r'comment', r'--.*$'),
@ -12,11 +17,9 @@ class LuaGrammar(Grammar):
RegionRule(r'string', r"'", StringGrammar1, r"'"), RegionRule(r'string', r"'", StringGrammar1, r"'"),
RegionRule(r'string', r'"', StringGrammar2, r'"'), RegionRule(r'string', r'"', StringGrammar2, r'"'),
PatternRule(r'keyword', r'(?:while|until|true|then|return|repeat|or|not|nil|local|in|if|function|for|false|end|elseif|else|do|break|and)(?![a-zA-Z0-9_])'), PatternRule(r'keyword', r'(?:while|until|true|then|return|repeat|or|not|nil|local|in|if|function|for|false|end|elseif|else|do|break|and)(?!'+chr2+')'),
#PatternRule(r'function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\()'), PatternMatchRule('x', '(function)( +)('+word+')', 'keyword', 'spaces', 'function'),
PatternRule(r'function', r'(?<=function )[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule(r'lua_identifier', word),
#PatternRule(r'identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule(r'lua_identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule(r'delimiter', r'(?:[=(){}\[\];:,.])'), PatternRule(r'delimiter', r'(?:[=(){}\[\];:,.])'),
PatternRule(r'operator', r'(?:\.\.\.|\.\.|==|~=|<=|>=|<|>)'), PatternRule(r'operator', r'(?:\.\.\.|\.\.|==|~=|<=|>=|<|>)'),
@ -25,7 +28,7 @@ class LuaGrammar(Grammar):
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_])"),
] ]
class LuaCheckSyntax(method.Method): class LuaCheckSyntax(Method):
'''Check the syntax of a lua file''' '''Check the syntax of a lua file'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
app = w.application app = w.application
@ -37,7 +40,7 @@ class LuaCheckSyntax(method.Method):
else: else:
app.data_buffer("*Lua-Check-Syntax*", output) app.data_buffer("*Lua-Check-Syntax*", output)
class Lua(mode.Fundamental): class Lua(Fundamental):
name = 'Lua' name = 'Lua'
extensions = ['.lua'] extensions = ['.lua']
#tabbercls = mode.lisp.LispTabber #tabbercls = mode.lisp.LispTabber

View File

@ -1,5 +1,6 @@
import commands, dirutil, grp, mailbox, method, mode, os.path, pwd, re, sys import mailbox, os.path, re, sys
import buffer, default, window import buffer, default, window
from mode import Fundamental
from mode.mutt import MuttGrammar from mode.mutt import MuttGrammar
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
from point import Point from point import Point
@ -200,7 +201,7 @@ class MailListGrammar(Grammar):
), ),
] ]
class MboxMsg(mode.Fundamental): class MboxMsg(Fundamental):
name = 'MboxMsg' name = 'MboxMsg'
colors = { colors = {
'mail_pgp': ('red', 'default', 'bold'), 'mail_pgp': ('red', 'default', 'bold'),
@ -218,9 +219,9 @@ class MboxMsg(mode.Fundamental):
actions = [] actions = []
grammar = MailMsgGrammar grammar = MailMsgGrammar
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) Fundamental.__init__(self, w)
class Mbox(mode.Fundamental): class Mbox(Fundamental):
name = 'Mbox' name = 'Mbox'
grammar = MailListGrammar grammar = MailListGrammar
actions = [MboxRefresh, MboxOpenPath, MboxReadMsg] actions = [MboxRefresh, MboxOpenPath, MboxReadMsg]
@ -235,7 +236,7 @@ class Mbox(mode.Fundamental):
'subject': ('default', 'default', 'bold'), 'subject': ('default', 'default', 'bold'),
} }
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) Fundamental.__init__(self, w)
self.add_bindings('mbox-refresh', ('C-c r',)) self.add_bindings('mbox-refresh', ('C-c r',))
self.add_bindings('mbox-read-msg', ('RETURN',)) self.add_bindings('mbox-read-msg', ('RETURN',))