私はSublime Text 3プラグインに取り組んでおり、これまでのところ、3つのクラスを使用して現在のファイルから別のファイルにすべてのテキストをコピーする小さなスクリプトがあります:
import sublime, sublime_plugin
# string and new file created
s = 0
newFile = 0
class CreateNewWindowCommand(sublime_plugin.WindowCommand):
def run(self):
global s, newFile
s = self.window.active_view().substr(sublime.Region(0, self.window.active_view().size()))
newFile = self.window.new_file()
class CopyTextCommand(sublime_plugin.TextCommand):
def printAChar(self,char,edit):
self.view.insert(edit, 0, char)
def run(self, edit):
global s
st = list(s)
for i in st[::-1]:
self.printAChar(i, edit)
class PrintCodeCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("create_new_window")
newFile.run_command("copy_text")
スクリプトは最初に PrintCodeCommand を介して実行されます。
このコードに関して複数の質問があります:
- これは「正しい」方法ですか?グローバル変数で何かを渡すのは少し汚いように見えるからです。
- WindowCommand と TextCommand を同時に使用できるクラスを作成する方法はありますか?
- 最初に挿入コマンド (CopyTextCommand 内) を挿入します。ファイルの最後に追加する方法はありますか?
もう 1 つ: sublime.set_timeout() を使用するにはどうすればよいですか? このように:
# ...
class CopyTextCommand(sublime_plugin.TextCommand):
def printAChar(self,char,edit):
sublime.set_timeout(self.view.insert(edit, 0, char) , 1000)
# I want to print a char one per second
または time.sleep() コマンドを使用していますが、機能していないようです...
前もって感謝します !