Exemplo n.º 1
0
def tags(element):
    elementString = str(element)
    if element in voidElements:
        Text("<%s />" % str(element)).execute()
    else:
        Text("<%s></%s>" % (elementString, elementString)).execute()
        Key("left:%s" % (len(elementString) + 3)).execute()
Exemplo n.º 2
0
    def __init__(self, spec=None, static=False, pause=0.02, autofmt=False):
        Text.__init__(self, spec, static, pause, autofmt)

        # Since we're not actually part of the Dragonfly Action hierarchy and dynamically dispatch to one of two
        # Action implementations, we can't simply subclass and rely on polymorphism to call the correct method.
        # That's because this class is a subclass of the container, not of the Action itself.  So, in order to ensure
        # our overridden method is called on the correct Action, we must add an unbound copy of the method to each
        # of the Actions.
        setattr(self._dragonfly_action, "_parse_spec", self._parse_spec)
        setattr(self._aenea_action, "_parse_spec", self._parse_spec)
Exemplo n.º 3
0
    def __init__(self, spec=None, static=False, pause=0.02, autofmt=False):
        Text.__init__(self, spec, static, pause, autofmt)

        # Since we're not actually part of the Dragonfly Action hierarchy and dynamically dispatch to one of two
        # Action implementations, we can't simply subclass and rely on polymorphism to call the correct method.
        # That's because this class is a subclass of the container, not of the Action itself.  So, in order to ensure
        # our overridden method is called on the correct Action, we must add an unbound copy of the method to each
        # of the Actions.
        setattr(self._dragonfly_action, "_parse_spec", self._parse_spec)
        setattr(self._aenea_action, "_parse_spec", self._parse_spec)
Exemplo n.º 4
0
def template_preamble():
    Key("langle, percent").execute()
    Key("enter").execute()
    Text("  @path = \"\"", static=True).execute()
    Key("enter").execute()
    Key("backspace, backspace, percent, rangle").execute()
    Key("enter, enter").execute()
Exemplo n.º 5
0
def squash_count(n):
    """Formats n words to the left of the cursor with whitespace removed.
    Excepting spaces immediately after comma, colon and percent chars.

    Note: Word count differs between editors and programming languages.
    The examples are all from Eclipse/Python.

    Example:
    "'my new variable' *pause* 'squash 3'" => "mynewvariable".
    "'my<tab>new variable' *pause* 'squash 3'" => "mynewvariable".
    "( foo = bar, fee = fye )", 'squash 9'" => "(foo=bar, fee=fye)"

    """
    saveText = _get_clipboard_text()
    cutText = _select_and_cut_text(n)
    if cutText:
        endSpace = cutText.endswith(' ')
        text = _cleanup_text(cutText)
        newText = ''.join(text.split(' '))
        if endSpace:
            newText = newText + ' '
        newText = _expand_after_special_chars(newText)
        newText = newText.replace("%", "%%")  # Escape any format chars.
        Text(newText).execute()
    else:  # Failed to get text from clipboard.
        Key('c-v').execute()  # Restore cut out text.
    _set_clipboard_text(saveText)
Exemplo n.º 6
0
def expand_count(n):
    """Formats n words to the left of the cursor by adding whitespace in
    certain positions.
    Note that word count differs between editors and programming languages.
    The examples are all from Eclipse/Python.

    Example, with to compact code:
    "result=(width1+width2)/2 'expand 9' " => "result = (width1 + width2) / 2"

    """
    saveText = _get_clipboard_text()
    cutText = _select_and_cut_text(n)
    if cutText:
        endSpace = cutText.endswith(' ')
        cutText = _expand_after_special_chars(cutText)
        reg = re.compile(
            r'([a-zA-Z0-9_\"\'\)][=\+\-\*/\%]|[=\+\-\*/\%][a-zA-Z0-9_\"\'\(])')
        hit = reg.search(cutText)
        count = 0
        while hit and count < 10:
            cutText = cutText[:hit.start() + 1] + ' ' + \
                cutText[hit.end() - 1:]
            hit = reg.search(cutText)
            count += 1
        newText = cutText
        if endSpace:
            newText = newText + ' '
        newText = newText.replace("%", "%%")  # Escape any format chars.
        Text(newText).execute()
    else:  # Failed to get text from clipboard.
        Key('c-v').execute()  # Restore cut out text.
    _set_clipboard_text(saveText)
Exemplo n.º 7
0
def title_case_text(text):
    """Formats dictated text to title case.

    Example:
    "'title case my new variable'" => "My New Variable".

    """
    newText = format_title_case(text)
    Text("%(text)s").execute({"text": newText})
Exemplo n.º 8
0
def lowercase_text(text):
    """Formats dictated text to lower case.

    Example:
    "'lower case John Johnson'" => "john johnson".

    """
    newText = format_lower_case(text)
    Text("%(text)s").execute({"text": newText})
Exemplo n.º 9
0
def camel_case_text(text):
    """Formats dictated text to camel case.

    Example:
    "'camel case my new variable'" => "myNewVariable".

    """
    newText = format_camel_case(text)
    Text("%(text)s").execute({"text": newText})
Exemplo n.º 10
0
def pascal_case_text(text):
    """Formats dictated text to pascal case.

    Example:
    "'pascal case my new variable'" => "MyNewVariable".

    """
    newText = format_pascal_case(text)
    Text("%(text)s").execute({"text": newText})
Exemplo n.º 11
0
def snake_case_text(text):
    """Formats dictated text to snake case.

    Example:
    "'snake case my new variable'" => "my_new_variable".

    """
    newText = format_snake_case(text)
    Text("%(text)s").execute({"text": newText})
Exemplo n.º 12
0
def squash_text(text):
    """Formats dictated text with whitespace removed.

    Example:
    "'squash my new variable'" => "mynewvariable".

    """
    newText = format_squash(text)
    Text("%(text)s").execute({"text": newText})
Exemplo n.º 13
0
def uppercase_text(text):
    """Formats dictated text to upper case.

    Example:
    "'upper case my new variable'" => "MY NEW VARIABLE".

    """
    newText = format_upper_case(text)
    Text("%(text)s").execute({"text": newText})
Exemplo n.º 14
0
class ChatRule(MappingRule):
    mapping = {
        "at <user>": Text("@%(user)s "),
        "send": Key("enter"),
    }

    extras = [
        Choice("user", hipchat_config.usernames.map),
    ]
Exemplo n.º 15
0
def format_text(text, formatType=None):
    if formatType:
        if type(formatType) != type([]):
            formatType = [formatType]
        result = ""
        method = None
        for value in formatType:
            if not result:
                if formatType == FormatTypes.spokenForm:
                    result = text.words
                else:
                    result = str(text)
            method = FORMAT_TYPES_MAP[value]
            result = method(result)
        Text("%(text)s").execute({"text": result})
Exemplo n.º 16
0
def lowercase_count(n):
    """Formats n words to the left of the cursor to lower case.
    Note that word count differs between editors and programming languages.
    The examples are all from Eclipse/Python.

    Example:
    "'John Johnson' *pause* 'lower case 2'" => "john johnson".

    """
    saveText = _get_clipboard_text()
    cutText = _select_and_cut_text(n)
    if cutText:
        newText = cutText.lower()
        newText = newText.replace("%", "%%")  # Escape any format chars.
        Text(newText).execute()
    else:  # Failed to get text from clipboard.
        Key('c-v').execute()  # Restore cut out text.
    _set_clipboard_text(saveText)
Exemplo n.º 17
0
class NavigationRule(MappingRule):
    mapping = {
        "move up [<n>]":
        Key("cs-tab:%(n)d"),
        "move down [<n>]":
        Key("c-tab:%(n)d"),
        "close tab":
        Key("c-w"),
        "(join room | private message) <room>":
        Key("c-j/25") + Text("%(room)s") + Key("enter"),
        "search [room] history":
        Key("c-f"),
    }

    extras = [
        IntegerRef("n", 1, 10),
        Dictation("room"),
    ]

    defaults = {
        "n": 1,
    }
Exemplo n.º 18
0
def snake_case_count(n):
    """Formats n words to the left of the cursor to snake case.
    Note that word count differs between editors and programming languages.
    The examples are all from Eclipse/Python.

    Example:
    "'my new variable' *pause* 'snake case 3'" => "my_new_variable".

    """
    saveText = _get_clipboard_text()
    cutText = _select_and_cut_text(n)
    if cutText:
        endSpace = cutText.endswith(' ')
        text = _cleanup_text(cutText.lower())
        newText = '_'.join(text.split(' '))
        if endSpace:
            newText = newText + ' '
        newText = newText.replace("%", "%%")  # Escape any format chars.
        Text(newText).execute()
    else:  # Failed to get text from clipboard.
        Key('c-v').execute()  # Restore cut out text.
    _set_clipboard_text(saveText)
Exemplo n.º 19
0
    "any": "any?",
    "collect": "collect",
    "each": "each",
    "each with index": "each_with_index",
    "find": "find",
    "find all": "find_all",
    "inject": "inject",
    "reject": "reject",
    "select": "select",
}

rules = MappingRule(
    mapping={
        # Commands and keywords:
        "and":
        Text(" && "),
        "and (equal|equals)":
        Text(" &&= "),
        "(append|stream)":
        Text(" << "),
        "assign":
        Text(" = "),
        "(attr|attribute) accessor":
        Text("attr_accessor :"),
        "(attr|attribute) accessor <text>":
        Text("attr_accessor :") + Function(lib.format.snake_case_text),
        "(attr|attribute) reader":
        Text("attr_reader :"),
        "(attr|attribute) reader <text>":
        Text("attr_reader :") + Function(lib.format.snake_case_text),
        "begin":
Exemplo n.º 20
0
def define_class_method(text):
    Text("def self.").execute()
    lib.format.snake_case_text(text)
    Text("()").execute()
    Key("left").execute()
Exemplo n.º 21
0
    "remote": "--remote",
    "short": "--short",
    "skip": "--skip",
    "tags": "--tags",
    "staged": "--staged",
    "theirs": "--theirs",
    "track": "--track",
    "verbose": "--verbose",
    "version": "--version",
}

series_rule = SeriesMappingRule(
    mapping={
        # Git commands.
        "git add":
        Text("git add "),
        "git add <text>":
        SCText("git add %(text)s"),
        "git add patch":
        Text("git add --patch "),
        "git add patch <text>":
        SCText("git add --patch %(text)s"),
        "git add (all|period|dot)":
        Text("git add .") + Key("enter"),
        "git archive":
        Text("git archive --format=tar "),
        "git blame":
        Text("git blame "),
        "git branch":
        Text("git branch") + Key("enter"),
        "git branch track":
Exemplo n.º 22
0
def end_tag(element):
    Text("</%s>" % str(element)).execute()


def attribute_with_content(attribute, text):
    Text(' %(attribute)s=""').execute()
    Key("left").execute()
    SCText(str(text)).execute()


rules = MappingRule(
    mapping={
        # Commands and keywords.
        "[start] tag":
        Text("<>") + Key("left"),
        "[start] tag <element>":
        Function(start_tag),
        "tags <element>":
        Function(tags),
        "end tag":
        Text("</>") + Key("left"),
        "end tag <element>":
        Function(end_tag),
        "attribute <attribute>":
        Text(' %(attribute)s=""') + Key("left"),
        "attribute <attribute> [equals] <text>":
        Function(attribute_with_content),  # @IgnorePep8
        # Comments.
        "comment":
        Text("<!--  -->") + Key("left:4"),
Exemplo n.º 23
0
def start_tag(element):
    if element in voidElements:
        Text("<%s />" % str(element)).execute()
    else:
        Text("<%s>" % str(element)).execute()
Exemplo n.º 24
0
    "find usages":
    DynamicAction(Key("a-f7"), Key("as-7")),

    # Edit.
    "save [file|all]":
    Key("c-s"),

    # Code.
    "show intentions":
    Key("a-enter"),
    "accept choice":
    Key("c-enter"),
    "go to line":
    Key("c-g"),
    "go to line <n>":
    Key("c-g/25") + Text("%(n)d") + Key("enter"),
    "[go to] start of line":
    Key("home"),
    "[go to] end of line":
    Key("end"),
    "implement method":
    Key("c-i"),
    "override method":
    Key("c-o"),

    # Window handling.
    "next tab":
    Key("a-right"),
    "previous tab":
    Key("a-left"),
    "close tab":
Exemplo n.º 25
0
def call_iterator(iterator):
    Text(".").execute()
    lib.format.lowercase_text(iterator)
    Text(" { |x| }").execute()
    Key("left").execute()
Exemplo n.º 26
0
    "message": "--message",
    "non-recursive": "--non-recursive",
    "password": "******",
    "quiet": "--quiet",
    "revision": "--revision",
    "username": "******",
    "verbose": "--verbose",
    "version": "--version",
}

svn = "(subversion|S V N) "

series_rule = SeriesMappingRule(
    mapping={
        # Subversion commands.
        svn + "add": Text("svn add "),
        svn + "add <text>": SCText("svn add %(text)s"),
        svn + "add (all|period|dot)": Text("svn add .") + Key("enter"),
        svn + "blame": Text("svn blame "),
        svn + "(check out|checkout)": Text("svn checkout "),
        svn + "(check out|checkout) <text>": SCText("svn checkout %(text)s"),
        svn + "commit": Text("svn commit -m ") + Key("dquote/3") + Key("dquote/3, left/3"),  # @IgnorePep8
        svn + "delete": Text("svn delete "),
        svn + "delete <text>": SCText("svn delete %(text)s"),\
        svn + "(diff|difference|differentiate)": Text("svn diff "),
        svn + "(diff|difference|differentiate) <text>": SCText("svn diff %(text)s"),  # @IgnorePep8
        svn + "help": Text("svn --help") + Key("enter"),
        svn + "help <svncmd>": Text("svn --help %(svncmd)s") + Key("enter"),
        svn + "log": Text("svn log "),
        svn + "log <text>": SCText("svn log %(text)s"),
        svn + "log limit <n>": Text("svn log -l %(n)d "),
Exemplo n.º 27
0
def define_class(text):
    Text("class ").execute()
    lib.format.pascal_case_text(text)
Exemplo n.º 28
0
def end_tag(element):
    Text("</%s>" % str(element)).execute()
Exemplo n.º 29
0
 # Closures.
 "angle brackets":
 Key("langle, rangle, left/3"),
 "brackets":
 Key("lbracket, rbracket, left/3"),
 "braces":
 Key("lbrace, rbrace, left/3"),
 "parens":
 Key("lparen, rparen, left/3"),
 "quotes":
 Key("dquote/3, dquote/3, left/3"),
 "single quotes":
 Key("squote, squote, left/3"),
 # Shorthand multiple characters.
 "double <char>":
 Text("%(char)s%(char)s"),
 "triple <char>":
 Text("%(char)s%(char)s%(char)s"),
 "double escape":
 Key("escape, escape"),  # Exiting menus.
 # Punctuation and separation characters, for quick editing.
 "colon [<n>]":
 Key("colon/2:%(n)d"),
 "semi-colon [<n>]":
 Key("semicolon/2:%(n)d"),
 "comma [<n>]":
 Key("comma/2:%(n)d"),
 "(dot|period) [<n>]":
 Key("dot/2:%(n)d"),
 "(dash|hyphen|minus) [<n>]":
 Key("hyphen/2:%(n)d"),
Exemplo n.º 30
0
        CompoundRule.__init__(self,
                              spec=compound_spec,
                              extras=compound_extras,
                              exported=True)

    def _process_recognition(self, node, extras):  # @UnusedVariable
        series = extras["series"]
        for action in series:
            action.execute()


series_rule = SeriesMappingRule(
    mapping={
        # Filler words.
        "foobar":
        Text("foobar"),
        "foo":
        Text("foo"),
        "bar":
        Text("bar"),
        # Lorem ipsum, filler text
        # (Multiple Key's are much faster than long Text's.)
        "Lorem ipsum [short]":
        Key("L,o,r,e,m,space,i,p,s,u,m,space,d,o,l,o,r,space,s,i,t,space,a,m,e,t,comma,space,c,o,n,s,e,c,t,e,t,u,r,space,a,d,i,p,i,s,i,c,i,n,g,space,e,l,i,t,dot"
            ),  # @IgnorePep8
        "Lorem ipsum medium":
        Key("L,o,r,e,m,space,i,p,s,u,m,space,d,o,l,o,r,space,s,i,t,space,a,m,e,t,comma,space,c,o,n,s,e,c,t,e,t,u,r,space,a,d,i,p,i,s,i,c,i,n,g,space,e,l,i,t,comma,space,s,e,d,space,d,o,space,e,i,u,s,m,o,d,space,t,e,m,p,o,r,space,i,n,c,i,d,i,d,u,n,t,space,u,t,space,l,a,b,o,r,e,space,e,t,space,d,o,l,o,r,e,space,m,a,g,n,a,space,a,l,i,q,u,a,dot,space,U,t,space,e,n,i,m,space,a,d,space,m,i,n,i,m,space,v,e,n,i,a,m,comma,space,q,u,i,s,space,n,o,s,t,r,u,d,space,e,x,e,r,c,i,t,a,t,i,o,n,space,u,l,l,a,m,c,o,space,l,a,b,o,r,i,s,space,n,i,s,i,space,u,t,space,a,l,i,q,u,i,p,space,e,x,space,e,a,space,c,o,m,m,o,d,o,space,c,o,n,s,e,q,u,a,t,dot"
            ),  # @IgnorePep8
        "Lorem ipsum long":
        Key("L,o,r,e,m,space,i,p,s,u,m,space,d,o,l,o,r,space,s,i,t,space,a,m,e,t,comma,space,c,o,n,s,e,c,t,e,t,u,r,space,a,d,i,p,i,s,i,c,i,n,g,space,e,l,i,t,comma,space,s,e,d,space,d,o,space,e,i,u,s,m,o,d,space,t,e,m,p,o,r,space,i,n,c,i,d,i,d,u,n,t,space,u,t,space,l,a,b,o,r,e,space,e,t,space,d,o,l,o,r,e,space,m,a,g,n,a,space,a,l,i,q,u,a,dot,space,U,t,space,e,n,i,m,space,a,d,space,m,i,n,i,m,space,v,e,n,i,a,m,comma,space,q,u,i,s,space,n,o,s,t,r,u,d,space,e,x,e,r,c,i,t,a,t,i,o,n,space,u,l,l,a,m,c,o,space,l,a,b,o,r,i,s,space,n,i,s,i,space,u,t,space,a,l,i,q,u,i,p,space,e,x,space,e,a,space,c,o,m,m,o,d,o,space,c,o,n,s,e,q,u,a,t,dot,space,D,u,i,s,space,a,u,t,e,space,i,r,u,r,e,space,d,o,l,o,r,space,i,n,space,r,e,p,r,e,h,e,n,d,e,r,i,t,space,i,n,space,v,o,l,u,p,t,a,t,e,space,v,e,l,i,t,space,e,s,s,e,space,c,i,l,l,u,m,space,d,o,l,o,r,e,space,e,u,space,f,u,g,i,a,t,space,n,u,l,l,a,space,p,a,r,i,a,t,u,r,dot,space,E,x,c,e,p,t,e,u,r,space,s,i,n,t,space,o,c,c,a,e,c,a,t,space,c,u,p,i,d,a,t,a,t,space,n,o,n,space,p,r,o,i,d,e,n,t,comma,space,s,u,n,t,space,i,n,space,c,u,l,p,a,space,q,u,i,space,o,f,f,i,c,i,a,space,d,e,s,e,r,u,n,t,space,m,o,l,l,i,t,space,a,n,i,m,space,i,d,space,e,s,t,space,l,a,b,o,r,u,m,dot,L,o,r,e,m,space,i,p,s,u,m,space,d,o,l,o,r,space,s,i,t,space,a,m,e,t,comma,space,c,o,n,s,e,c,t,e,t,u,r,space,a,d,i,p,i,s,i,c,i,n,g,space,e,l,i,t,comma,space,s,e,d,space,d,o,space,e,i,u,s,m,o,d,space,t,e,m,p,o,r,space,i,n,c,i,d,i,d,u,n,t,space,u,t,space,l,a,b,o,r,e,space,e,t,space,d,o,l,o,r,e,space,m,a,g,n,a,space,a,l,i,q,u,a,dot,space,U,t,space,e,n,i,m,space,a,d,space,m,i,n,i,m,space,v,e,n,i,a,m,comma,space,q,u,i,s,space,n,o,s,t,r,u,d,space,e,x,e,r,c,i,t,a,t,i,o,n,space,u,l,l,a,m,c,o,space,l,a,b,o,r,i,s,space,n,i,s,i,space,u,t,space,a,l,i,q,u,i,p,space,e,x,space,e,a,space,c,o,m,m,o,d,o,space,c,o,n,s,e,q,u,a,t,dot,space,D,u,i,s,space,a,u,t,e,space,i,r,u,r,e,space,d,o,l,o,r,space,i,n,space,r,e,p,r,e,h,e,n,d,e,r,i,t,space,i,n,space,v,o,l,u,p,t,a,t,e,space,v,e,l,i,t,space,e,s,s,e,space,c,i,l,l,u,m,space,d,o,l,o,r,e,space,e,u,space,f,u,g,i,a,t,space,n,u,l,l,a,space,p,a,r,i,a,t,u,r,dot,space,E,x,c,e,p,t,e,u,r,space,s,i,n,t,space,o,c,c,a,e,c,a,t,space,c,u,p,i,d,a,t,a,t,space,n,o,n,space,p,r,o,i,d,e,n,t,comma,space,s,u,n,t,space,i,n,space,c,u,l,p,a,space,q,u,i,space,o,f,f,i,c,i,a,space,d,e,s,e,r,u,n,t,space,m,o,l,l,i,t,space,a,n,i,m,space,i,d,space,e,s,t,space,l,a,b,o,r,u,m,dot"
            ),  # @IgnorePep8
Exemplo n.º 31
0
def attribute_with_content(attribute, text):
    Text(' %(attribute)s=""').execute()
    Key("left").execute()
    SCText(str(text)).execute()