我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用sublime.get_clipboard()。
def run(self, edit, bracketed=False): # Lookup the sublime buffer instance for this view sub_buffer = SublimeBufferManager.load_from_id(self.view.id()) keypress_cb = sub_buffer.keypress_callback() if not keypress_cb: return # Check if bracketed paste mode is enabled bracketed = bracketed or sub_buffer.terminal_emulator().bracketed_paste_mode_enabled() if bracketed: keypress_cb("bracketed_paste_mode_start") copied = sublime.get_clipboard() copied = copied.replace("\r\n", "\n") for char in copied: if char == "\n" or char == "\r": keypress_cb("enter") elif char == "\t": keypress_cb("tab") else: keypress_cb(char) if bracketed: keypress_cb("bracketed_paste_mode_end")
def replace(self, start, end): replacement = self.spell.get('args').get('replacement') clipboard = sublime.get_clipboard() replacement = replacement.replace('$clipboard', clipboard) cursor_position = replacement.find('$cursor') if cursor_position is not -1: replacement = replacement.replace('$cursor', '') region = sublime.Region(start, end) self.view.replace(self.edit, region, replacement) if cursor_position != -1: new_cursor_position = start + cursor_position self.view.sel().clear() self.view.sel().add(sublime.Region(new_cursor_position)) if self.view.settings().get('vintage'): self.view.run_command("_enter_insert_mode")
def on_repo_selection(self, selection, subsequent_action, **args): if selection >= 0: if selection == 0: self.window.run_command('hide_panel') _param_on_enter_repo_info = partial( self.on_enter_repo_info, subsequent_action=subsequent_action, **args) content = sublime.get_clipboard(256) if content.count( "/") == 1: # Add a condition to try not to jerperdize irrelevant clipboard content sublime.set_clipboard(content.strip()) self.window.show_input_panel( 'Enter repo in the format username/repo_name:', '', _param_on_enter_repo_info, None, None) else: self.username, self.repo_name = self.entries[selection].split( '/') acquire_repo_info = issue.AcquireRepoInfo(self.username, self.repo_name) acquire_repo_info.start() subsequent_action(**args)
def cast(self): pattern = re.compile(self.spell.get('args').get('pattern')) replacement = self.spell.get('args').get('replacement') if replacement == '$clipboard': replacement = sublime.get_clipboard() for sel in self.view.sel(): line = self.view.line(sel.a) line_text = self.view.substr(line) new_line_text = re.sub(pattern, "%s" % replacement, line_text) self.view.replace(self.edit, line, new_line_text)
def testSettingRegisterSetsClipboardIfNeeded(self): self.regs.settings.view['vintageous_use_sys_clipboard'] = True self.regs.set('a', [100]) self.assertEqual(sublime.get_clipboard(), '100')
def testAppendSetsClipboardIfNeeded(self): self.regs.settings.view['vintageous_use_sys_clipboard'] = True self.regs.set('a', ['foo']) self.regs.append_to('A', ['bar']) self.assertEqual(sublime.get_clipboard(), 'foobar')
def get(self, name=REG_UNNAMED): # We accept integers or strings a register names. name = str(name) assert len(str(name)) == 1, "Register names must be 1 char long." # Did we request a special register? if name == REG_BLACK_HOLE: return elif name == REG_FILE_NAME: try: return [self.view.file_name()] except AttributeError: return '' elif name in REG_SYS_CLIPBOARD_ALL: return [sublime.get_clipboard()] elif ((name not in (REG_UNNAMED, REG_SMALL_DELETE)) and (name in REG_SPECIAL)): return # Special case lumped among these --user always wants the sys # clipboard. elif ((name == REG_UNNAMED) and (self.settings.view['vintageous_use_sys_clipboard'] is True)): return [sublime.get_clipboard()] # If the expression register holds a value and we're requesting the # unnamed register, return the expression register and clear it # aftwerwards. elif name == REG_UNNAMED and _REGISTER_DATA.get(REG_EXPRESSION, ''): value = _REGISTER_DATA[REG_EXPRESSION] _REGISTER_DATA[REG_EXPRESSION] = '' return value # We requested an [a-z0-9"] register. if name.isdigit(): if name == '0': return _REGISTER_DATA[name] return _REGISTER_DATA['1-9'][int(name) - 1] try: # In Vim, "A and "a seem to be synonyms, so accept either. return _REGISTER_DATA[name.lower()] except KeyError: pass
def run(self, edit): def md(t): sublime.message_dialog(str(t)) for selection in self.view.sel(): # on recupere le texte de la selection if selection.empty(): s = sublime.get_clipboard() else: s = self.view.substr(selection) if '_' not in s: # ca veut dire qu'il n'y a pas _, donc on doit le transformer pour qu'il soit valable dans le fichier de raccourci # ex: il etait : UnNomDePlugin # il devient : un_nom_de_plugin # on rajoute un _ devant chaque majuscule underscore_case = re.sub(r'([A-Z])', r'_\1', s) # on le met tout en minuscule underscore_case = underscore_case.lower() # on supprime le premier _ (_nom_de_votre_command_avant_ca) if underscore_case[0] == '_': underscore_case = underscore_case.replace('_', '', 1) # on split le texte tout les _ underscore_case = underscore_case.split('_') # pour pouvoir retirer le "command" a la fin if (underscore_case[-1] == 'command'): del(underscore_case[-1]) # l'index -1 recupere le dernier element de la liste # on le re assemble avec des _ underscore_case = '_'.join(underscore_case) new_text = underscore_case else: # il y a des underscore, donc on doit le transformer pour qu'il soit un nom de plugin valable # on split le texte tout les _ texte = s.split('_') camelCase = '' for mot in texte: camelCase += mot.capitalize() camelCase += 'Command' new_text = camelCase # on remplace la selection par notre texte modifie ! if selection.empty(): self.view.insert(edit, selection.begin(), new_text) else: self.view.replace(edit, selection, new_text)