class KeystrokeRule(CompoundRule): spec = "[<mod1>] [<mod2>] <raw_keystroke> [<times>]" extras = [ RuleRef(name="raw_keystroke", rule=_KeystrokeRule()), RuleRef(name="mod1", rule=_ModifierRule(name="m1")), RuleRef(name="mod2", rule=_ModifierRule(name="m2")), RuleRef(name="times", rule=repeat_count_rule), ] def value(self, node): root = node.children[0].children[0] mod1 = root.children[0].value() mod2 = root.children[1].value() stroke = root.children[2].value() times = root.children[3].value() mod = "" if mod1: mod += mod1 if mod2: mod += mod2 if mod: stroke = "{}-{}".format(mod, stroke) stroke = Key(stroke) if times: return stroke * times else: return stroke
def __init__(self, *args, **kwargs): self.spec = '<character>' self.extras = [ Alternative(name='character', children=(RuleRef(rule=UppercaseCharacter()), RuleRef(rule=LowercaseCharacter()), RuleRef(rule=Number()), RuleRef(rule=Symbol()))) ] CompoundRule.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.spec = _('open process [<cmd>]') self.extras = [ Alternative(name='cmd', children=( RuleRef(name='ssh', rule=SshRule()), RuleRef(name='command', rule=Command()), )), ] CompoundRule.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.spec = _("S S H [<ssh_options>] <server> [<command>]") self.extras = [ Repetition(name='ssh_options', min=0, max=10, child=RuleRef(name='ssh_option', rule=SshOptions())), RuleRef(name='server', rule=SshServer()), RuleRef(name='command', rule=Command()) ] CompoundRule.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.spec = _("<cmd>") self.extras = [ Alternative(name='cmd', children=( RuleRef(name='motion_operator', rule=MotionOperatorRule()), RuleRef(name='motion', rule=MotionRule()), RuleRef(name='normal', rule=VimNormalRule()), RuleRef(name='number', rule=Number()), )) ] CompoundRule.__init__(self, *args, **kwargs)
def _create_repeat_rule(self, rule): ORIGINAL, SEQ, TERMINAL = "original", "caster_base_sequence", "terminal" alts = [RuleRef(rule=rule)] #+[RuleRef(rule=sm) for sm in selfmod] single_action = Alternative(alts) print(settings.MAGNETO) max = settings.MAGNETO["performance"]["max_ccr_repetitions"] sequence = Repetition(single_action, min=1, max=max, name=SEQ) original = Alternative(alts, name=ORIGINAL) terminal = Alternative(alts, name=TERMINAL) class RepeatRule(CompoundRule): spec = "[<" + ORIGINAL + "> original] [<" + SEQ + ">] [terminal <" + TERMINAL + ">]" extras = [sequence, original, terminal] def _process_recognition(self, node, extras): original = extras[ORIGINAL] if ORIGINAL in extras else None sequence = extras[SEQ] if SEQ in extras else None terminal = extras[TERMINAL] if TERMINAL in extras else None if original is not None: original.execute() if sequence is not None: for action in sequence: action.execute() if terminal is not None: terminal.execute() return RepeatRule(name="Repeater" + MergeRule.get_merge_name())
def __init__(self, *args, **kwargs): self.spec = _("command <command>") self.extras = [ Alternative(name='command', children=(RuleRef(rule=SimpleCommand()), )) ] CompoundRule.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.spec = _('spell <characters>') self.extras = [ Repetition(name='characters', child=RuleRef(rule=AnyCharacter()), min=1, max=80) ] CompoundRule.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.spec = _("<cmds>") self.extras = [ Repetition(name='cmds', child=RuleRef(rule=TrueVimNormalRule()), min=1, max=5) ] CompoundRule.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.spec = _("<operator> " "(<line>|[to] " "(<motion>|<operatormotion>) " "[<numbers>] " "[<mode> mode])") self.extras = [ Choice(name='operator', choices={ _('change'): Key('c'), _('delete'): Key('d'), _('yank'): Key('y'), _('swap case'): Key('g,tilde'), _('make lowercase'): Key('g,u'), _('make uppercase'): Key('g,s-u'), _('filter'): Key('exclamation'), _('C filter'): Key('equal'), _('text formatting'): Key('g,q'), _('rotation 13 encoding'): Key('g,question'), _('shift right'): Key('rangle'), _('shift left'): Key('langle'), _('define fold'): Key('z,f'), _('call function'): 'g,at' }), Literal(name='line', text=_('line')), Repetition(name='numbers', child=RuleRef(rule=Number()), min=0, max=3), RuleRef(name='motion', rule=MotionRule()), RuleRef(name='operatormotion', rule=VisualMotionRule()), Choice(name='mode', choices={ _("character"): Key("v"), _("line"): Key("s-v"), _("block"): Key("c-v"), }) ] CompoundRule.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): # technically we should not accept uppercase chars here self.spec = _('press [<modifiers>] <character>') self.extras = [ Repetition(name='modifiers', child=Choice(name='modifier', choices={ _('control'): 'c', _('shift'): 's', _('alt'): 'a', _('(command|super)'): 'w', }), min=0, max=4), RuleRef(name='character', rule=AnyCharacter()) ] CompoundRule.__init__(self, *args, **kwargs)
class DynamicCountRule(CompoundRule): spec = '<dynamic> [<times>]' extras = [ DictListRef( 'dynamic', aenea.vocabulary.register_dynamic_vocabulary('multiedit.count')), RuleRef(name="times", rule=repeat_count_rule) ] def value(self, node): root = node.children[0].children[0] stroke = root.children[0].value() times = root.children[1].value() if times: return stroke * times else: return stroke def _process_recognition(self, node, extras): # @UnusedVariable node.value().execute()
if lowercase: words = [word.lower() for word in words] if uppercase: words = [word.upper() for word in words] words = [word.split('\\', 1)[0].replace('-', '') for word in words] if words[0].lower() in ('upper', 'natural'): del words[0] function = getattr(aenea.format, 'format_%s' % words[0].lower()) formatted = function(words[1:]) return Text(formatted) my_format_rule = RuleRef(name="my_format_rule", rule=FormatRule()) class DynamicCountRule(CompoundRule): spec = '<dynamic> [<times>]' extras = [ DictListRef( 'dynamic', aenea.vocabulary.register_dynamic_vocabulary('multiedit.count')), RuleRef(name="times", rule=repeat_count_rule) ] def value(self, node): root = node.children[0].children[0] stroke = root.children[0].value()
def __init__(self, *args, **kwargs): self.mapping = { _("interrupt"): Key("c-c"), _("display file name"): Key("c-g"), _("redraw screen"): Key("c-l"), _("suspend"): Key("c-z"), _("store and exit"): Key("s-z,s-z"), _("unsafe exit"): Key("s-z,s-q"), _("edit alternate"): Key("c-caret"), _("help"): Key("f1"), ########### # jumps # ########### _("next jumplist"): Key("c-i"), _("previous jumplist"): Key("c-o"), _("previous changelist"): Key("g,semicolon"), _("next changlist"): Key("g,comma"), ########### # marks # ########### _("set mark <char>"): Key("m,%(char)s"), _("set previous mark"): Key("m,apostrophe"), _("set (open|left) [square] bracket mark"): Key("m,lbracket"), _("set (close|right) [square] bracket mark"): Key("m,rbracket"), _("set (open|left) angle bracket mark"): Key("m,langle"), _("set (close|right) angle bracket mark"): Key("m,rangle"), ############### # scrolling # ############### _("scroll down half"): Key("c-d"), _("scroll extra up"): Key("c-e"), _("scroll forward screen"): Key("c-f"), _("scroll back screen"): Key("c-b"), _("scroll down"): Key("c-y"), _("scroll half up"): Key("c-u"), ########### # modes # ########### _("insert"): Key("i"), _("insertmode"): Key("c-backslash,c-g"), _("insert at start of line"): Key("s-i"), _("insert on newline"): Key("o"), _("insert on newline before"): Key("s-o"), _("append"): Key("a"), _("(cap|big) append"): Key("s-a"), _("substitute"): Key("s"), _("replace [mode]"): Key("s-r"), _("external [mode]"): Key("s-q"), _("visual"): Key("v"), _("visual line"): Key("s-v"), _("visual block"): Key("c-v"), ###################### # undo/redo/repeat # ###################### _("redo"): Key("c-r"), _("undo"): Key("u"), _("undo on line"): Key("s-u"), _("(repeat|period)"): Key("dot"), _("(at|repeat register <register>)"): Key("at,%(register)s"), _("repeat previous register repeat"): Key("at,at"), _("repeat ex"): Key("at,colon"), _("(ampersand|repeat [last] (search|replace))"): Key("ampersand"), _("(semicolon|repeat (find|tag))"): Key("semicolon"), _("(comma|reverse repeat (find|tag))"): Key("comma"), _("record <register>"): Key("q,%(register)s"), _("stop recording"): Key("q"), _("edit ex"): Key("q,colon"), _("edit search"): Key("q,slash"), _("edit backward search"): Key("q,question"), ################## # text editing # ################## _("addition"): Key("c-a"), _("subtract"): Key("c-x"), _("indent"): Key("c-rbracket"), _("join lines"): Key("s-j"), _("delete char[acter]"): Key("x"), _("backwards delete char[acter]"): Key("s-x"), _("replace <char>"): Key("r,%(char)s"), _("(tilde|switch case)"): Key("tilde"), #################### # copy and paste # #################### _("copy to end of line"): Key("s-c"), _("paste"): Key("p"), _("paste before"): Key("s-p"), _("register <register>"): Key("dquote,%(register)s"), _("diff get"): Key("d,o"), _("diff put"): Key("d,p"), ############ # search # ############ _("lookup keyword"): Key("s-k"), _("backward next"): Key("s-n"), _("next"): Key("n"), _("after <char>"): Key("t,%(char)s"), _("backward move after <char>"): Key("s-t,%(char)s"), _("tag older"): Key("c-t"), _("(hash|backward search)"): Key("hash"), _("(asterisk|forward search)"): Key("asterisk"), _("(slash|search)"): Key("slash"), _("(question [mark]|backward search)"): Key("question"), ############ # window # ############ _("window increase height"): Key("c-w,plus"), _("window decrease height"): Key("c-w,hyphen"), _("window increase width"): Key("c-w,rangle"), _("window decrease width"): Key("c-w,langle"), _("window equalise"): Key("c-w,equal"), _("window move (H|hotel|left)"): Key("c-w,s-h"), _("window move (J|juliet|down)"): Key("c-w,s-j"), _("window move (K|kilo|up)"): Key("c-w,s-k"), _("window move (L|lima|right)"): Key("c-w,s-l"), _("window preview"): Key("c-w,s-p"), _("window rotate up"): Key("c-w,s-r"), _("window move to [new] tab"): Key("c-w,s-t"), _("window previous"): Key("c-w,s-w"), _("window split and jump"): Key("c-w,rbracket"), _("window split and edit alternate"): Key("c-w,caret"), _("window set height"): Key("c-w,underscore"), _("window bottom"): Key("c-w,b"), _("window close"): Key("c-w,c"), _("window split and jump to definition"): Key("c-w,d"), _("window split and edit file"): Key("c-w,f"), _("window split edit file and jump"): Key("c-w,s-f"), # TODO: add c-w,g,] and c-w,g,} _("window tab and edit file"): Key("c-w,g,f"), _("window tab edit file and jump"): Key("c-w,g,s-f"), _("window (H|hotel|left)"): Key("c-w,h"), _("window split and jump to declaration"): Key("c-w,i"), _("window (J|juliet|down)"): Key("c-w,j"), _("window (K|kilo|up)"): Key("c-w,k"), _("window (L|lima|right)"): Key("c-w,l"), _("window new"): Key("c-w,n"), _("window only"): Key("c-w,o"), _("window last"): Key("c-w,p"), _("window rotate"): Key("c-w,r"), _("window split [horizontal]"): Key("c-w,s"), _("window top"): Key("c-w,t"), _("window split vertical"): Key("c-w,v"), _("window next"): Key("c-w,w"), _("window exchange"): Key("c-w,x"), _("window close preview"): Key("c-w,z"), _("window width"): Key("c-w,bar"), _("window tag in preview"): Key("c-w,rbrace"), } self.extras = [ # TODO: tighten register to [a-zA-Zs-9.%#:-"] RuleRef(name='register', rule=AnyCharacter()), RuleRef(name='char', rule=AnyCharacter()) ] MappingRule.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.mapping = { ################ # left/right # ################ _("(backward|left)"): Key("h"), _("(forward|right)"): Key("l"), _("(zero|first char[acter])"): Key("0"), _("(caret|first non-blank char[acter])"): Key("caret"), _("(dollar|last char[acter])"): Key("dollar"), _("last visible non-blank char[acter]"): Key("g,underscore"), _("fist visible char[acter]"): Key("g,0"), _("first visible non-blank char[acter]"): Key("g,caret"), _("middle of line"): Key("g,m"), _("last visible char[acter]"): Key("g,dollar"), _("(pipe|column)"): Key("bar"), _("find <char>"): Key("f,%(char)s"), _("backwards find <char>"): Key("s-f,%(char)s"), ############# # up/down # ############# _("up"): Key("k"), _("down"): Key("j"), _("visible up"): Key("g,k"), _("visible down"): Key("g,j"), _("(minus|linewise non-blank up)"): Key("minus"), _("(plus|linewise non-blank down)"): Key("plus"), _("(underscore|first non-blank line down)"): Key("underscore"), _("line"): Key("s-g"), _("end of [last] line"): Key("c-end"), _("first non-blank char[acter] on line"): Key("g,g"), _("percent"): Key("percent"), ########## # word # ########## _("word"): Key("w"), _("(big|cap) word"): Key("s-w"), _("end"): Key("e"), _("(big|cap) end"): Key("s-e"), _("back"): Key("b"), _("(big|cap) back"): Key("s-b"), _("backward end"): Key("g,e"), _("backward (big|cap) end"): Key("g,s-e"), ################# # text object # ################# _("((open|left) paren|previous sentence)"): Key("lparen"), _("((close|right) paren|next sentence)"): Key("rparen"), _("((left|open) curly brace|previous paragraph)"): Key("lbrace"), _("((right|close) curly brace|next paragraph)"): Key("rbrace"), _("next section start"): Key("rbracket,rbracket"), _("next section end"): Key("rbracket,lbracket"), _("previous section start"): Key("lbracket,rbracket"), _("previous section end"): Key("lbracket,lbracket"), ########### # other # ########### _("ex"): Key("colon"), ########### # marks # ########### # TODO: tighten char to [a-vA-Z0-9] _("mark <char>"): Key("backtick,%(char)s"), _("mark <char> first non-blank"): Key("apostrophe,%(char)s"), _("mark <char> [and] keep jumps"): Key("g,backtick,%(char)s"), _("mark <char> first non-blank [and] keep jumps"): Key("g,apostrophe,%(char)s"), _("first char[acter] of last (change|yank)"): Key("apostrophe,lbracket"), _("last char[acter] of last (change|yank)"): Key("apostrophe,rbracket"), _("start of last selection"): Key("apostrophe,langle"), _("end of last selection"): Key("apostrophe,rangle"), _("restore position"): Key("apostrophe,apostrophe"), _("restore position at last buffer exit"): Key("apostrophe,dquote"), _("restore position at last insert"): Key("apostrophe,caret"), _("restore position at last change"): Key("apostrophe,dot"), _("first non-blank char[acater] of next lowercase mark"): Key("rbracket,apostrophe"), _("next lowercase mark"): Key("rbracket,backtick"), _("first non-blank char[acter] of previous lowercase mark"): Key("lbracket,apostrophe"), _("previous lowercase mark"): Key("lbracket,backtick"), ##################### # various motions # ##################### _("(percent|match of next item)"): Key("percent"), _("previous unmatched (open|left) paren"): Key("lbracket,lparen"), _("previous unmatched (open|left) [curly] brace"): Key("lbracket,lbrace"), _("next unmatched (close|right) paren"): Key("rbracket,rparen"), _("next unmatched (close|right) [curly] brace"): Key("rbracket,rbrace"), _("next start of method"): Key("rbracket,m"), _("next end of method"): Key("rbracket,s-m"), _("previous start of method"): Key("lbracket,m"), _("previous end of method"): Key("lbracket,s-m"), _("previous unmatched macro"): Key("lbracket,hash"), _("next unmatched macro"): Key("rbracket,hash"), _("previous start of comment"): Key("lbracket,asterisk"), _("next end of comment"): Key("rbracket,asterisk"), _("line from top"): Key("s-h"), _("middle [of (window|screen)]"): Key("s-m"), _("line from bottom"): Key("s-l"), } self.extras = [RuleRef(name='char', rule=AnyCharacter())] MappingRule.__init__(self, *args, **kwargs)
Choice("letters", letterMap), Choice("modifier1", modifierMap), Choice("modifier2", modifierMap), Choice("modifierSingle", singleModifierMap), Choice("pressKey", pressKeyMap), Choice("formatType", formatMap), Choice("abbreviation", abbreviationMap), Choice("reservedWord", reservedWord), ] defaults = { "n": 1, } alternatives = [] alternatives.append(RuleRef(rule=KeystrokeRule())) single_action = Alternative(alternatives) sequence = Repetition(single_action, min=1, max=16, name="sequence") class RepeatRule(CompoundRule): # Here we define this rule's spoken-form and special elements. spec = "<sequence> [[[and] repeat [that]] <n> times]" extras = [ sequence, # Sequence of actions defined above. IntegerRef("n", 1, 100), # Times to repeat the sequence. ] defaults = { "n": 1, # Default repeat count.
defaults = { 'n': 1, } #--------------------------------------------------------------------------- # Here we create an element which is the sequence of keystrokes. # First we create an element that references the keystroke rule. # Note: when processing a recognition, the *value* of this element # will be the value of the referenced rule: an action. mapping = dict((key, val) for (key, val) in command_table.iteritems()) format_rule = RuleRef(name='format_rule', rule=FormatRule(name='i')) alternatives = [ RuleRef(rule=KeystrokeRule(mapping=mapping, name='c')), DictListRef( 'dynamic multiedit', aenea.vocabulary.register_dynamic_vocabulary('multiedit') ), DictListRef( 'static multiedit', DictList( 'static multiedit', aenea.vocabulary.get_static_vocabulary('multiedit') ), ), RuleRef(rule=DynamicCountRule(name='aoeuazzzxt'), name='aouxxxazsemi'), RuleRef(rule=StaticCountRule(name='aioeuazzzxt'), name='aouxxxazsemii'),
def __init__(self, *args, **kwargs): self.spec = _("sudo <command>") self.extras = [ RuleRef(name='command', rule=Command()), ] CompoundRule.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): self.spec = _('cap <lowercase_letter>') self.extras = [ RuleRef(name='lowercase_letter', rule=LowercaseCharacter()) ] CompoundRule.__init__(self, *args, **kwargs)