コード例 #1
0
ファイル: general.py プロジェクト: codespeak/grammars
 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
ファイル: general.py プロジェクト: codespeak/grammars
 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
ファイル: manip.py プロジェクト: DumboSpeak/DumboGuest
 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
ファイル: hscommands.py プロジェクト: codespeak/grammars
 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
ファイル: pycommands.py プロジェクト: codespeak/grammars
 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
ファイル: pycommands.py プロジェクト: codespeak/grammars
 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
ファイル: pycommands.py プロジェクト: codespeak/grammars
 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
ファイル: pycommands.py プロジェクト: codespeak/grammars
 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
ファイル: vimutils.py プロジェクト: codespeak/grammars
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
ファイル: shortfuncs.py プロジェクト: codespeak/grammars
 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
ファイル: letters.py プロジェクト: codespeak/grammars
 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
ファイル: textmanip.py プロジェクト: codespeak/grammars
 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
ファイル: textmanip.py プロジェクト: codespeak/grammars
 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
ファイル: sample2.py プロジェクト: codespeak/grammars
 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
ファイル: textmanip.py プロジェクト: codespeak/grammars
 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
ファイル: letters.py プロジェクト: codespeak/grammars
 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
ファイル: shortfuncs.py プロジェクト: codespeak/grammars
 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
ファイル: history.py プロジェクト: DumboSpeak/DumboGuest
 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
ファイル: textmanip2.py プロジェクト: codespeak/grammars
 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
ファイル: manip.py プロジェクト: DumboSpeak/DumboGuest
 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
ファイル: html.py プロジェクト: codespeak/grammars
 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
ファイル: shortcuts.py プロジェクト: codespeak/grammars
 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
ファイル: operators.py プロジェクト: codespeak/grammars
 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
ファイル: fbase.py プロジェクト: codespeak/grammars
 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
ファイル: manip.py プロジェクト: DumboSpeak/DumboGuest
 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
ファイル: manip.py プロジェクト: DumboSpeak/DumboGuest
 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
ファイル: termutils.py プロジェクト: codespeak/grammars
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
ファイル: manip.py プロジェクト: DumboSpeak/DumboGuest
 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
ファイル: manip.py プロジェクト: DumboSpeak/DumboGuest
 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
ファイル: sample2.py プロジェクト: codespeak/grammars
 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
ファイル: textmanip2.py プロジェクト: codespeak/grammars
 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
ファイル: general.py プロジェクト: codespeak/grammars
 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
ファイル: termgeneral.py プロジェクト: codespeak/grammars
 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
ファイル: termgeneral.py プロジェクト: codespeak/grammars
 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
ファイル: dictation.py プロジェクト: DumboSpeak/DumboGuest
 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:]))