예제 #1
0
def key(m):
    words = [str(word).lower() for word in m._words]
    modifiers = []
    if 'command' in words:
        modifiers.append('cmd')
    if 'shift' in words:
        modifiers.append('shift')
    if 'control' in words:
        modifiers.append('ctrl')
    if 'option' in words or 'alt' in words:
        modifiers.append('alt')

    key = None
    for word in words:
        if word in alnum:
            key = alnum[word]
        if word in string.ascii_lowercase:
            key = word

    if key is None:
        print('no key', words)
        return

    Str("Key('{}')".format('-'.join(modifiers + [key])))(None)
예제 #2
0
def shrink_word(m):
    word = str(m._words[1])
    if not word in shrink_map:
        last_word = word
        raise Exception('%s not in shrink map' % word)
    Str(shrink_map[word])(None)
예제 #3
0
def insert(s):
    Str(s)(None)
예제 #4
0
 def path_function(m):
     press('cmd-shift-g')
     Str(path)(None)
     press('return')
예제 #5
0
def search_reverse(m):
    press('?')
    w = str(m.dgndictation[0]._words[0])
    w = w.lower()
    Str(w)(None)
    press('enter')
예제 #6
0
파일: vim.py 프로젝트: ekiefl/dotfiles
def HereToHereCommand(m):
    '''`Here-to-here` commands select and sometimes operate on a text selection defined by where the
       mouse is at the start and end of the utterance. In this sense the user sweeps with their eyes
       the text selection as they utter `<command_prefix> here to here`. They can also use
       `<command_prefix> to here` to use the starting cursor position as the first text selection
       point, or `<command_prefix> here` to select either a single character or line.'''
    utterance = []
    for w in m._words:
        utterance.append(w.word)

    marker1 = 't'  # original cursor pos
    marker2 = 'y'  # position of first click
    marker3 = 'u'  # position of second click

    command_prefix = utterance[0]

    if command_prefix == 'phipps':
        actions_dict = {
            'selection_type': Str("v"),
            'selection_movement': Str("{}{}".format(marker_operation,
                                                    marker3)),
        }

    elif command_prefix == 'block':
        actions_dict = {
            'selection_type': Key("ctrl-v"),
            'selection_movement': Str("{}{}".format(marker_operation,
                                                    marker3)),
        }

    elif command_prefix == 'bar':
        actions_dict = {
            'selection_type': Str("V"),
            'selection_movement': Str("{}{}".format(marker_operation,
                                                    marker3)),
        }

    elif command_prefix == 'kill':
        actions_dict = {
            'selection_type':
            Str("V"),
            'selection_movement':
            Str("{}{}".format(marker_operation, marker3)),
            'selection_ending_stroke':
            Str("d"),
            'return_to_start':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker1))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker1))]),
        }

    # .R files only.
    elif command_prefix == 'run':
        actions_dict = {
            'selection_type': Str("V"),
            'selection_movement': Str("{}{}".format(marker_operation,
                                                    marker3)),
            'selection_ending_stroke': [Str(",se"), Key('esc')],
        }

    elif command_prefix == 'steal':
        actions_dict = {
            'selection_type':
            Str("V"),
            'selection_movement':
            Str("{}{}".format(marker_operation, marker3)),
            'selection_ending_stroke':
            Str("y"),
            'return_to_start':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker1))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker1))]),
        }

    elif command_prefix == 'triple-quote':
        actions_dict = {
            'selection_type':
            Str("V"),
            'selection_movement':
            Str("{}{}".format(marker_operation, marker3)),
            'selection_ending_stroke':
            Str("S3\""),
            'return_to_start':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker1))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker1))]),
        }

    elif command_prefix == 'clippy':
        actions_dict = {
            'selection_type':
            Str("V"),
            'selection_movement':
            Str("{}{}".format(marker_operation, marker3)),
            'selection_ending_stroke':
            Key("ctrl-y"),
            'return_to_start':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker1))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker1))]),
        }

    elif command_prefix == 'psych':
        actions_dict = {
            'selection_type':
            Str("V"),
            'selection_movement':
            Str("{}{}".format(marker_operation, marker3)),
            'selection_ending_stroke':
            Str("y"),
            'return_to_start':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker1))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker1))]),
            'after_return_to_start':
            Str("p"),
        }

    elif command_prefix == 'big-psych':
        actions_dict = {
            'selection_type':
            Str("V"),
            'selection_movement':
            Str("{}{}".format(marker_operation, marker3)),
            'selection_ending_stroke':
            Str("y"),
            'return_to_start':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker1))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker1))]),
            'after_return_to_start':
            Str("P"),
        }

    elif command_prefix == 'stack':
        actions_dict = {
            'selection_type':
            Str("V"),
            'selection_movement':
            Str("{}{}".format(marker_operation, marker3)),
            'selection_ending_stroke':
            Str("y"),
            'after_stroke':
            Str("'>p".format(marker1)),
            'return_to_start':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker1))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker1))]),
        }

    elif command_prefix == 'linecert':
        actions_dict = {
            'before_selection': Str('^'),
            'selection_type': Key("ctrl-v"),
            'selection_movement': Str("{}{}".format(marker_operation,
                                                    marker3)),
            'selection_ending_stroke': Key("^ shift-i"),
        }

    elif command_prefix == 'comment':
        actions_dict = {
            'before_selection':
            Str('^'),
            'selection_type':
            Key("ctrl-v"),
            'selection_movement':
            Str("{}{}".format(marker_operation, marker3)),
            'selection_ending_stroke':
            Key("shift-i # space esc"),
            'return_to_start':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker1))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker1))]),
        }

    elif command_prefix == 'uncomment':
        actions_dict = {
            'before_selection':
            Str('^'),
            'selection_type':
            Key("ctrl-v"),
            'selection_movement':
            Str("{}{}".format(marker_operation, marker3)),
            'selection_ending_stroke':
            Key("^ right d"),
            'return_to_start':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker1))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker1))]),
        }

    actions_dict.update({
        'make_marker1':
        make_marker(marker1, m),
        'make_marker3':
        make_marker(marker3, m),
        'mark_start_window':
        [Str(':let winA = win_getid()'),
         Key('enter')] if not DISABLE_WINDOW_SWAPPING else Str(''),
        'final_pos_click':
        final_pos_click_function(m),
        'initial_pos_click':
        initial_pos_click_function(m)
    })

    command_variant_name = ' '.join(utterance[1:])

    if command_variant_name == 'here to here':
        action_order = [
            'make_marker1',
            'mark_start_window',
            'final_pos_click',
            'make_marker3',
            'initial_pos_click',
            'before_selection',
            'selection_type',
            'selection_movement',
            'selection_ending_stroke',
            'after_stroke',
            'return_to_start',
            'after_return_to_start',
        ]

    elif command_variant_name == 'to here':
        actions_dict['return_to_cursor'] = Str("{}{}".format(
            marker_operation, marker1))
        action_order = [
            'make_marker1',
            'final_pos_click',
            'make_marker3',
            'return_to_cursor',
            'before_selection',
            'selection_type',
            'selection_movement',
            'selection_ending_stroke',
            'after_stroke',
            'return_to_start',
            'after_return_to_start',
        ]

    elif command_variant_name == 'here':
        action_order = [
            'make_marker1',
            'make_marker3',
            'initial_pos_click',
            'before_selection',
            'selection_type',
            'selection_ending_stroke',
            'after_stroke',
            'return_to_start',
            'after_return_to_start',
        ]

    for action_name in action_order:
        action = actions_dict.get(action_name)
        if action:
            if hasattr(action, '__iter__'):
                # catches cases like [Key(...), Str(...), ...]
                for act in action:
                    act(None)
            else:
                # catches simpler cases like Key(...)
                action(None)
예제 #7
0
파일: vim.py 프로젝트: ekiefl/dotfiles
                          Key("enter")],

    # search stuff
    'search': [Key('esc'), initial_pos_click, '*'],
    'cancel hits': ["/asde", Key("enter")],
    'nex': Key("n"),
    'bex': Key("N"),
    'sore': [":s///g"] + [Key("left")] * 3,
    'globsore': [":%s///g"] + [Key("left")] * 3,
    'para': [Key("escape"), "o", Key("enter")],
}
vimmap.update(primitive_commands)

make_marker = lambda marker_key, *args: [
    Key("left right escape"),
    Str("m%s" % marker_key)
]


#  return function that can be called with None
def final_pos_click_function(m):
    def inner(*args):
        final_pos_click(m)

    return inner


#  return function that can be called with None
def initial_pos_click_function(m):
    def inner(*args):
        initial_pos_click(m)
예제 #8
0
def find_previous(m):
    press("left")
    press("cmd-f")
    Str(str(m.dgndictation[0]._words[0]))(None)
    press("cmd-shift-g")
    press("escape")
예제 #9
0
 def wrapper(m):
     Str(fmt.format(" ".join(parse_words(m))))(None)
예제 #10
0
def jump_to_next_word_instance(m):
    press('escape')
    press('cmd-f')
    Str(' '.join([str(s) for s in m.dgndictation[0]._words]))(None)
    press('return')
예제 #11
0
def Text(m):
    Str(' '.join(map(str, m.dgndictation[0]._words)))(None)
예제 #12
0
def search_for(m):
    press('cmd-l')
    tmp = [str(s).lower() for s in m.dgndictation[0]._words]
    words = [parse_word(word) for word in tmp]
    Str(' '.join(words))(None)
예제 #13
0
def shrink_word(m):
    # Str(shrink_map[" ".join(m["shrink.words"])])(None)
    Str(shrink_map[m[1]])(None)
예제 #14
0
def start_template(key):
    send_idea_command("action InsertLiveTemplate")
    time.sleep(0.3)
    Str(key + "\n")(None)
    time.sleep(0.2)
    Key("enter")
예제 #15
0
def select_line(m):
    line_no = extract_num_from_m(m)
    press("cmd-l")
    Str(str(line_no))(None)
    time.sleep(0.1)
    press("enter")
예제 #16
0
def insert(w, is_selection):
    if is_selection:
        clip.set(w)
        press("cmd-v", wait=0)
    else:
        Str(w)(None)
예제 #17
0
def find_next(m):
    press("cmd-f")
    Str(str(m.dgndictation[0]._words[0]))(None)
    press("escape")
예제 #18
0
 def path_function(m):
     press("cmd-shift-g")
     Str(path)(None)
     press("return")
예제 #19
0
 def snip(m):
     press('cmd-shift-r')
     sleep(0.1)
     Str(shortcut)(None)
     press('enter')
예제 #20
0
def new_to_do(m):
    press('return')
    Str('- [ ] ')(None)
예제 #21
0
파일: vim.py 프로젝트: ekiefl/dotfiles
def TeleportCommand(m):
    '''Teleport commands are a group of commands that carry out keystrokes both at the mouse\'s position
       AND the cursor's position at the time of first utterance. It is called teleport because the cursor
       'teleports' between these two positions. The general flow of this function is:

            1. make a marker at the cursor's position
            2. click where the mouse was at the start of the utterance
            3. carry out keystrokes for the command (e.g. select text, etc)
            4. optionally return to the marker and carry out more keystrokes (e.g. paste text, etc)

       The concept of these commands was seeded by the command `psych`, which is demonstrated in this
       video: https://www.youtube.com/watch?v=F2KEnQl7d2s
    '''
    utterance = []
    for w in m._words:
        utterance.append(w.word)

    teleport_movement = utterance[1:]
    teleport_operator = utterance[0]

    marker_key = 't'  # marks original cursor position

    if teleport_operator == "psych":
        actions_dict = {
            'preprend':
            Str('y'),
            'append':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker_key)),
                Str('pa')
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker_key)),
              Str('pa')])
        }

    elif teleport_operator == "big-psych":
        actions_dict = {
            'preprend':
            Str('y'),
            'append':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker_key)),
                Str('Pa')
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker_key)),
              Str('Pa')])
        }

    elif teleport_operator == "steal":
        actions_dict = {
            'preprend':
            Str('y'),
            'append': ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker_key))
            ] if not DISABLE_WINDOW_SWAPPING else
                       [Str("{}{}".format(marker_operation, marker_key))])
        }

    elif teleport_operator == "slice":
        actions_dict = {
            'preprend':
            Str('d'),
            'append':
            ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker_key)),
                Str('pa')
            ] if not DISABLE_WINDOW_SWAPPING else
             [Str("{}{}".format(marker_operation, marker_key)),
              Str('pa')])
        }

    elif teleport_operator == "kill":
        actions_dict = {
            'preprend':
            Str('d'),
            'append': ([
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker_key))
            ] if not DISABLE_WINDOW_SWAPPING else
                       [Str("{}{}".format(marker_operation, marker_key))])
        }

    elif teleport_operator == "kit":
        actions_dict = {
            'preprend': Str('c'),
            'append': Str(""),
        }

    elif teleport_operator == "phipps":
        actions_dict = {
            'preprend': Str('v'),
            'append': Str(""),
        }

    elif teleport_operator == "clippy":
        actions_dict = {
            'preprend':
            Str('v'),
            'append':
            ([
                Key("ctrl-y"),
                Str(':call win_gotoid(winA)'),
                Key('enter'),
                Str("{}{}".format(marker_operation, marker_key))
            ] if not DISABLE_WINDOW_SWAPPING else
             [Key('ctrl-y'),
              Str("{}{}".format(marker_operation, marker_key))])
        }

    else:
        raise Exception(
            "`{}` is not a keyword understood by TeleportCommand (vim.py)".
            format(teleport_operator))

    actions_dict.update({
        'make_marker':
        make_marker(marker_key, m),
        'mark_start_window':
        ([Str(':let winA = win_getid()'),
          Key('enter')] if not DISABLE_WINDOW_SWAPPING else Str('')),
        'initial_pos_click':
        initial_pos_click_function(m)
    })

    if len(teleport_movement):
        movement_strokes = ''
        if ' '.join(teleport_movement) in text_selectors:
            # the motion is self-contained; no number prefixes or movement targets
            movement_strokes += text_selectors[' '.join(teleport_movement)]
        else:
            # movement key or number prefix was uttered. fish them out
            if teleport_movement[0] in [str(x) for x in list(range(10))]:
                # the movement has been prefixed by a number (e.g. `2 til larry`)
                movement_strokes += teleport_movement.pop(0)
            movement_strokes += target_required_text_selectors[
                teleport_movement.pop(0)]
            movement_strokes += movement_targets[' '.join(teleport_movement)]
    else:
        # no movement stroke was specified, assuming 'inside word'
        movement_strokes = 'iw'

    actions_dict['movement_strokes'] = Str(movement_strokes)

    action_order = [
        'make_marker',
        'mark_start_window',
        'initial_pos_click',
        'preprend',
        'movement_strokes',
        'append',
    ]
    for action_name in action_order:
        action = actions_dict.get(action_name)
        if action:
            if hasattr(action, '__iter__'):
                # catches cases like [Key(...), Str(...), ...]
                for act in action:
                    act(None)
            else:
                # catches simpler cases like Key(...)
                action(None)
예제 #22
0
def execute_atom_command(command, parameters=None):
    press(atom_hotkey)
    press(command)
    if parameters:
        Str(parameters)(None)
        press("enter")
예제 #23
0
def text(m):
    tmp = [str(s).lower() for s in m.dgndictation[0]._words]
    words = [parse_word(word) for word in tmp]
    Str(' '.join(words))(None)
예제 #24
0
def bullet(m):
    press('return')
    Str('* ')(None)
예제 #25
0
def search_forward(m):
    press('/')
    w = str(m.dgndictation[0]._words[0])
    w = w.lower()
    Str(w)(None)
    press('return')
예제 #26
0
def find_previous(m):
    press('left')
    press('cmd-f')
    Str(str(m.dgndictation[0]._words[0]))(None)
    press('cmd-shift-g')
    press('escape')
예제 #27
0
def shrink_word(m):
    word = str(m._words[1])
    if word not in shrink_map:
        raise Exception("%s not in shrink map" % word)
    Str(shrink_map[word])(None)
예제 #28
0
def jump_to_bol(m):
    line = text_to_number(m)
    press('cmd-l')
    Str(str(line))(None)
    press('enter')
예제 #29
0
def jump_to_next_word_instance(m):
    press("escape")
    press(FIND_KEY)
    # noinspection PyProtectedMember
    Str(" ".join([str(s) for s in m.dgndictation[0]._words]))(None)
    press("return")
예제 #30
0
def find_next(m):
    press('cmd-f')
    Str(str(m.dgndictation[0]._words[0]))(None)
    press('escape')