Пример #1
0
 def replace(self, words):
     if len(words) == 1:
         api.send_string('{esc}:%s///g{left}{left}{left}')
         return
     api.send_string(r'{alt+1}{esc}:%s/\<{ctrl+r+w}\>/' +
                     vimutils.guess_at_text(words[1:]) +
                     '/g{enter}i{alt+2}')
Пример #2
0
 def launch_shell(self, words):
     buff_path = vimutils.get_clipboard_contents(
         "{escape}:let @+ = expand('%:p'){enter}")
     subprocess.call(['x-terminal-emulator'])
     time.sleep(1)
     print(os.path.split(buff_path))
     api.send_string('cd ' + os.path.split(buff_path)[0] + '{enter}')
Пример #3
0
 def manip_text_object(self, words):
     num = self._num(words)
     text_obj = self.text_objects[' '.join(words[1:])]
     action = self._actions[words[0]][0]
     cleanup = '' if words[0] != 'copy' else self._shortcuts['clearSelect']
     command = (text_obj + action + cleanup) * num
     api.send_string(command)
Пример #4
0
 def new_method(self, words):
     if len(words) == 1:
         api.send_string(
             'def (self):{left}{left}{left}{left}{left}{left}{left}')
         return
     func_name = baseutils.get_case(words[1:], self.variable_mode)
     api.send_string('def {}(self):{{left}}{{left}}'.format(func_name))
Пример #5
0
def get_clipboard_contents(keys):
    clipboard_contents = baseutils.get_clipboard_contents()
    api.send_string(keys)
    time.sleep(.1)
    new_contents = baseutils.get_clipboard_contents()
    baseutils.set_clipboard_contents(clipboard_contents)
    return new_contents
Пример #6
0
 def new_function(self, words):
     if len(words) == 1:
         api.send_string("function () {{{left}{left}{left}{left}")
         return
     func_name = vimutils.create_variable_name(words[1:])
     api.send_string("function {}() ".format(func_name) + "{{{left}{left}{left}")
     vimextension.VimExtensionGrammar.definitions.append("{}_function".format(func_name))
Пример #7
0
 def new_function(self, words):
     if len(words) == 1:
         api.send_string('def ():{left}{left}{left}')
         return
     func_name = vimutils.guess_at_text(words[1:])
     api.send_string('def {}():{{left}}{{left}}'.format(func_name))
     vimextension.VimExtensionGrammar.definitions.append('{}_function'.format(func_name))
Пример #8
0
 def new_class(self, words):
     if len(words) == 1:
         api.send_string('class ')
         return
     class_name = ''.join([word.title() for word in words[1:]])
     api.send_string('class {}:'.format(class_name))
     vimextension.VimExtensionGrammar.definitions.append('{}_class'.format(class_name))
Пример #9
0
 def index(self, words):
     api.send_string('[]{left}')
     if len(words) > 1:
         num = words[-1]
         if words[-2] in ['minus', 'negative']:
             num = str(-int(num))
         api.send_string(num + '{right}')
Пример #10
0
 def new_list(self, words):
     if len(words) == 1:
         api.send_string(' = []{left}{left}{left}{left}{left}')
         return
     list_name = vimutils.create_variable_name(words[1:])
     api.send_string('{} = []{{left}}'.format(list_name))
     vimextension.VimExtensionGrammar.definitions.append('{}_list'.format(list_name))
Пример #11
0
 def new_dictionary(self, words):
     if len(words) == 1:
         api.send_string(' = {{}}{left}{left}{left}{left}{left}')
         return
     dict_name = vimutils.create_variable_name(words[1:])
     api.send_string(dict_name + ' = ' + '{{}}' + '{left}')
     vimextension.VimExtensionGrammar.definitions.append('{}_dictionary'.format(dict_name))
Пример #12
0
def get_clipboard_contents(keys):
    clipboard_contents = baseutils.get_clipboard_contents()
    api.send_string(keys)
    time.sleep(.1)
    new_contents = baseutils.get_clipboard_contents()
    baseutils.set_clipboard_contents(clipboard_contents)
    return new_contents
Пример #13
0
 def index(self, words):
     api.send_string("[]{left}")
     if len(words) > 1:
         num = words[-1]
         if words[-2] in ["minus", "negative"]:
             num = str(-int(num))
         api.send_string(num + "{right}")
Пример #14
0
 def do_surround_same(self, words):
     text = self.activate + '1-' + atomutils.ACTIONS[words[0]]
     if words[1] == 'outer':
         text += '-a-'
     else:
         text += '-i-'
     text += ''.join(atomutils.STRING_OBJECTS[words[-1]]) + '`^'
     api.send_string(text)
Пример #15
0
 def letters(self, words):
     num = int(words.pop()) if words[-1].isdigit() else 1
     letter = baseutils.ALPHABET[words[-1]]
     if len(words) > 1 or self.capital:
         api.send_string(letter.upper())
         return
     for i in range(num):
         api.send_string(letter)
Пример #16
0
 def new_class(self, words):
     if len(words) == 1:
         api.send_string('class ')
         return
     class_name = ''.join([word.title() for word in words[1:]])
     api.send_string('class {}:'.format(class_name))
     vimextension.VimExtensionGrammar.definitions.append(
         '{}_class'.format(class_name))
Пример #17
0
 def do_motion(self, words):
     if not words[-1].isdigit():
         words.append('1')
     select_default = 's'
     if words[0] not in atomutils.ACTIONS:
         select_default = 'm'
     api.send_string(self.activate + select_default + atomutils.MOTIONS[words[-2]] + words[-1] + '!')
     atomutils.do_action(words[0])
Пример #18
0
 def new_list(self, words):
     if len(words) == 1:
         api.send_string(' = []{left}{left}{left}{left}{left}')
         return
     list_name = vimutils.create_variable_name(words[1:])
     api.send_string('{} = []{{left}}'.format(list_name))
     vimextension.VimExtensionGrammar.definitions.append(
         '{}_list'.format(list_name))
Пример #19
0
 def upper_incremental(self, words):
     if not words[-1].isdigit():
         words.append('1')
     action = atomutils.ACTIONS.get(words[0], 'm')
     limit = atomutils.INCREMENTAL_LIMITS[words[-4]]
     search_value = self.search_chars[words[-2]].upper()
     num = words[-1]
     api.send_string(self.activate + '{}-{}-{}-{}`^'.format(num, action, limit, search_value))
Пример #20
0
 def count(self, words):
     iter_count = int(words[-1]) + 1
     send_str = ''
     for i, num in enumerate(range(iter_count)):
         send_str += str(num)
         if i != iter_count - 1:
             send_str += ', '
     api.send_string(send_str)
Пример #21
0
 def new_dictionary(self, words):
     if len(words) == 1:
         api.send_string(' = {{}}{left}{left}{left}{left}{left}')
         return
     dict_name = vimutils.create_variable_name(words[1:])
     api.send_string(dict_name + ' = ' + '{{}}' + '{left}')
     vimextension.VimExtensionGrammar.definitions.append(
         '{}_dictionary'.format(dict_name))
Пример #22
0
 def execute_string_or_func(self, action):
     if isinstance(action, str):
         api.send_string(action)
         return True
     elif isinstance(action, tuple):
         action[0](*action[1], **action[2])
         return True
     return False
Пример #23
0
 def new_function(self, words):
     if len(words) == 1:
         api.send_string('def ():{left}{left}{left}')
         return
     func_name = vimutils.guess_at_text(words[1:])
     api.send_string('def {}():{{left}}{{left}}'.format(func_name))
     vimextension.VimExtensionGrammar.definitions.append(
         '{}_function'.format(func_name))
Пример #24
0
 def do_surround_same(self, words):
     text = self.activate + '1-' + atomutils.ACTIONS[words[0]]
     if words[1] == 'outer':
         text += '-a-'
     else:
         text += '-i-'
     text += ''.join(atomutils.STRING_OBJECTS[words[-1]]) + '`^'
     api.send_string(text)
Пример #25
0
 def bottom(self, words):
     text = (vimutils.FUNCTIONS['RightIfNotFirstCol'] +
             vimutils.FUNCTIONS['GoToVisualMode'] + '{F11}G$')
     if words[0] != 'select':
         text += vimutils.commands[words[0]]
         if words[0] == 'copy':
             text += 'i'
     api.send_string(text)
Пример #26
0
 def letters(self, words):
     num = int(words.pop()) if words[-1].isdigit() else 1
     letter = baseutils.ALPHABET[words[-1]]
     if len(words) > 1 or self.capital:
         api.send_string(letter.upper())
         return
     for i in range(num):
         api.send_string(letter)
Пример #27
0
 def increment(self, words):
     keys = "{ctrl+a}"
     if words[0] == "decrease":
         keys = "{ctrl+x}"
     num = ""
     if words[-1].isdigit():
         num = words[-1]
     api.send_string("{esc}" + "{}{}{}a".format(vimutils.FUNCTIONS["number jump"], num, keys))
Пример #28
0
 def count(self, words):
     iter_count = int(words[-1]) + 1
     send_str = ''
     for i, num in enumerate(range(iter_count)):
         send_str += str(num)
         if i != iter_count - 1:
             send_str += ', '
     api.send_string(send_str)
Пример #29
0
 def execute_string_or_func(self, action):
     if isinstance(action, str):
         api.send_string(action)
         return True
     elif isinstance(action, tuple):
         action[0](*action[1], **action[2])
         return True
     return False
Пример #30
0
 def bottom(self, words):
     text = (vimutils.FUNCTIONS['RightIfNotFirstCol'] +
             vimutils.FUNCTIONS['GoToVisualMode'] +
             '{F11}G$')
     if words[0] != 'select':
         text += vimutils.commands[words[0]]
         if words[0] == 'copy':
             text += 'i'
     api.send_string(text)
Пример #31
0
 def tab_direction(self, words):
     direction = '{ctrl+shift+tab}'
     if 'right' in [words[-1], words[-2]]:
         direction = '{ctrl+tab}'
     num = baseutils.last_number(words)
     for i in range(num):
         api.send_string(direction)
         if i + 1 < num:
             time.sleep(.2)
Пример #32
0
 def numbered_action(self, words):
     action = self._actions.get(words[0], [None])[0]
     count = self._num(words)
     if action is None:
         send_str = ''.join([self._shortcuts[words[0]] for i in range(count)])
     else:
         keys = '+'.join([self.numbered_directions[words[1]][1:-1] for i in range(count)])
         send_str = '{shift+' + keys + '}' + action
     api.send_string(send_str)
Пример #33
0
 def tag(self, words):
     text = '<'
     if words[-1] == 'close':
         text += '/'
     text += self.tags[' '.join(words[1:])]
     text += '>'
     if words[-1] != 'close':
         text += '{left}'
     api.send_string(text)
Пример #34
0
 def change_tab(self, words):
     direction = 'gt'
     if words[0] == 'left':
         direction = 'gT'
     num = int(baseutils.set_number(words))
     for i in range(num):
         if i != 0:
             time.sleep(.1)
         api.send_string('{escape}{escape}' + direction)
Пример #35
0
 def tab_direction(self, words):
     direction = '{ctrl+shift+tab}'
     if 'right' in [words[-1], words[-2]]:
         direction = '{ctrl+tab}'
     num = baseutils.last_number(words)
     for i in range(num):
         api.send_string(direction)
         if i + 1 < num:
             time.sleep(.2)
Пример #36
0
 def operator(self, words):
     text = ''
     if words[0] == 'short':
         text += vimutils.OPERATORS[words[1]]
     else:
         text += '{}{}{}'.format(vimutils.FUNCTIONS['SmartSpace'], vimutils.OPERATORS[words[0]], vimutils.FUNCTIONS['EndSpace'])
     if words[-1].isdigit():
         text += words[-1]
     api.send_string(text)
Пример #37
0
 def change_tab(self, words):
     direction = 'gt'
     if words[0] == 'left':
         direction = 'gT'
     num = int(baseutils.set_number(words))
     for i in range(num):
         if i != 0:
             time.sleep(.1)
         api.send_string('{escape}{escape}' + direction)
Пример #38
0
 def new_function(self, words):
     if len(words) == 1:
         api.send_string('function () {{{left}{left}{left}{left}')
         return
     func_name = vimutils.create_variable_name(words[1:])
     api.send_string('function {}() '.format(func_name) +
                     '{{{left}{left}{left}')
     vimextension.VimExtensionGrammar.definitions.append(
         '{}_function'.format(func_name))
Пример #39
0
 def top(self, words):
     text = (vimutils.FUNCTIONS['UpIfFirstCol'] +
             vimutils.FUNCTIONS['TrimLineWhitespace'] +
             vimutils.FUNCTIONS['GoToVisualMode'] + 'gg')
     if words[0] != 'select':
         text += vimutils.commands[words[0]]
         if words[0] == 'copy':
             text += 'i'
     api.send_string(text)
Пример #40
0
 def do_motion(self, words):
     if not words[-1].isdigit():
         words.append('1')
     select_default = 's'
     if words[0] not in atomutils.ACTIONS:
         select_default = 'm'
     api.send_string(self.activate + select_default +
                     atomutils.MOTIONS[words[-2]] + words[-1] + '!')
     atomutils.do_action(words[0])
Пример #41
0
 def manip_text_object_card(self, words):
     action = self._actions.get(words[0], '')
     if action:
         action = action[0]
     cleanup = '' if words[0] != 'copy' else self._shortcuts['clearSelect']
     text_obj = self.text_objects[words[-1]]
     if len(words) > 1:
         api.send_string('{{shift+{}}}{}{}'.format(text_obj, action, cleanup))
     else:
         api.send_string('{{{}}}{}{}'.format(text_obj, action, cleanup))
Пример #42
0
 def search_ahead(self, words):
     if not words[-1].isdigit():
         words.append('1')
     action = atomutils.ACTIONS.get(words[0], 'm')
     limit = atomutils.INCREMENTAL_LIMITS[words[-3]]
     search_value = self.search_chars[words[-2]]
     num = words[-1]
     api.send_string(
         self.activate +
         '{}-{}-{}-{}`^'.format(num, action, limit, search_value))
Пример #43
0
 def new_function(self, words):
     # create a camelcase function name from the words parameter
     func_name = words[2].lower() + ''.join([w.title() for w in words[3:]])
     if self.language == 'python':
         api.send_string('def ' + func_name + '():{left}{left}')
         # press left twice when we're done to put the cursor between the
         # parentheses. Keypresses are enclosed in curly braces and can be
         # combined with the plus sign e.g. {ctrl+alt+delete}
     elif self.language == 'perl':
         api.send_string('sub ' + func_name + '() {{}}')
Пример #44
0
 def increment(self, words):
     keys = '{ctrl+a}'
     if words[0] == 'decrease':
         keys = '{ctrl+x}'
     num = ''
     if words[-1].isdigit():
         num = words[-1]
     api.send_string(
         '{esc}' +
         '{}{}{}a'.format(vimutils.FUNCTIONS['number jump'], num, keys))
Пример #45
0
 def manip_text_object(self, words):
     num = self._num(words)
     text_obj = self.text_objects[' '.join(words[1:])]
     action = self._actions[words[0]]
     cleanup = '' if words[0] != 'copy' else '{esc}'
     if text_obj == '{ctrl+i}' and words[0] in ('grab', 'delete'):
         cleanup += '{back}'
     command = (text_obj * num) + action + cleanup
     print(command)
     api.send_string(command)
Пример #46
0
def open_shell():
    clipboard_contents = baseutils.get_clipboard_contents()
    api.send_string("{escape}:let @+ = expand('%:p'){enter}")
    subprocess.call(['x-terminal-emulator'])
    time.sleep(1)
    api.send_string(
        'cd {}'.format(os.path.dirname(baseutils.get_clipboard_contents())) +
        '{enter}')
    baseutils.set_clipboard_contents(clipboard_contents)
    time.sleep(.2)
Пример #47
0
 def numbered_action(self, words):
     action = self._actions.get(words[0], None)
     count = self._num(words)
     if action is None:
         send_str = ('{' + words[0] + '}') * count
         # send_str = ''.join([self._shortcuts[words[0]] for i in range(count)])
     else:
         # send_str = '{shift}' + (('{' + words[0] + '}') * count) + action
         send_str = ''.join(['{shift+' + words[1] + '}' + action for i in range(count)])
     api.send_string(send_str)
Пример #48
0
 def manip_text_object(self, words):
     num = self._num(words)
     text_obj = self.text_objects[' '.join(words[1:])]
     action = self._actions[words[0]]
     cleanup = '' if words[0] != 'copy' else '{esc}'
     if text_obj == '{ctrl+i}' and words[0] in ('grab', 'delete'):
         cleanup += '{back}'
     command = (text_obj * num) + action + cleanup
     print(command)
     api.send_string(command)
Пример #49
0
 def new_function(self, words):
     # create a camelcase function name from the words parameter
     func_name = words[2].lower() + ''.join([w.title() for w in words[3:]])
     if self.language == 'python':
         api.send_string('def ' + func_name + '():{left}{left}')
         # press left twice when we're done to put the cursor between the
         # parentheses. Keypresses are enclosed in curly braces and can be
         # combined with the plus sign e.g. {ctrl+alt+delete}
     elif self.language == 'perl':
         api.send_string('sub ' + func_name + '() {{}}')
Пример #50
0
 def top(self, words):
     text = (vimutils.FUNCTIONS['UpIfFirstCol'] +
             vimutils.FUNCTIONS['TrimLineWhitespace'] +
             vimutils.FUNCTIONS['GoToVisualMode'] +
             'gg')
     if words[0] != 'select':
         text += vimutils.commands[words[0]]
         if words[0] == 'copy':
             text += 'i'
     api.send_string(text)
Пример #51
0
 def indent(self, words):
     indent_commands = {
         'shoot': '{alt+h}',
         'ball': '{alt+l}',
     }
     cmd = indent_commands[words[0]]
     num = baseutils.set_number(words)
     if num == '1':
         api.send_string(cmd)
         return
     api.send_string('{escape}' + num + indent_commands[words[0]] + 'i')
Пример #52
0
 def left_right(self, words):
     num = 1
     if words[-1].isdigit():
         num = int(words[-1])
     for i in range(num):
         if words[0] == 'left':
             api.send_string('{ctrl+pageup}')
         else:
             api.send_string('{ctrl+pagedown}')
         if i != num:
             time.sleep(.1)
Пример #53
0
 def up_down(self, words):
     direction = '{up}'
     if words[0] == 'low':
         direction = '{down}'
     num = 1
     if len(words) > 1:
         num = int(words[-1])
     for i in range(num):
         api.send_string(direction)
         if i + 1 != num:
             time.sleep(.1)
Пример #54
0
 def left_right(self, words):
     num = 1
     if words[-1].isdigit():
         num = int(words[-1])
     for i in range(num):
         if words[0] == 'left':
             api.send_string('{ctrl+pageup}')
         else:
             api.send_string('{ctrl+pagedown}')
         if i != num:
             time.sleep(.1)
Пример #55
0
 def up_down(self, words):
     direction = '{up}'
     if words[0] == 'low':
         direction = '{down}'
     num = 1
     if len(words) > 1:
         num = int(words[-1])
     for i in range(num):
         api.send_string(direction)
         if i + 1 != num:
             time.sleep(.1)
Пример #56
0
 def dictate(self, words):
     if words[0] == 'camel':
         api.send_string(words[1] + ''.join(w.title() for w in words[2:]))
     elif words[0] == 'score':
         api.send_string('_'.join(words[1:]))
     elif words[0] == 'word':
         api.send_string(''.join(words[1:]))
     elif words[0] == 'dictate':
         api.send_string(' '.join(words[1:]))
     elif words[0] == 'title':
         api.send_string(''.join(w.title() for w in words[1:]))