Sublime Text 3 - ?发送命令到 sublime 控制台

fly*_*ris 3 python sublimetext sublimetext3 sublime-text-plugin

我想扩展 Sublime 功能,这将允许我将文本从任何应用程序发送到活动的 Sublime Text 窗口。我意识到可以使用以下命令从 Sublime 控制台添加文本:

view.run_command("insert", {"characters": "Hello World!"})

现在我想知道是否有任何内置解决方案可以从外部应用程序执行 sublime 控制台命令,例如。命令行界面接受外部命令?否则,我正在考虑应该可以设置Python来运行Socket服务器来侦听命令并接受输入?

有任何想法吗?

谢谢!

Oda*_*urd 5

Sublime 附带的命令subl允许您从命令行执行任意命令:

tmartin:dart:~> subl --help
Sublime Text build 3211

Usage: subl [arguments] [files]         Edit the given files
   or: subl [arguments] [directories]   Open the given directories

Arguments:
  --project <project>: Load the given project
  --command <command>: Run the given command
  -n or --new-window:  Open a new window
  -a or --add:         Add folders to the current window
  -w or --wait:        Wait for the files to be closed before returning
  -b or --background:  Don't activate the application
  -h or --help:        Show help (this message) and exit
  -v or --version:     Show version and exit

Filenames may be given a :line or :line:column suffix to open at a specific
location.
Run Code Online (Sandbox Code Playgroud)

--command参数期望您在单个参数中提供命令和所需的任何参数;例如:

tmartin:dart:~> subl --command "insert {\"characters\": \"Hello, World\"}"
Run Code Online (Sandbox Code Playgroud)

这适用于任何命令,就像 Sublime 控制台一样,TextCommand命令以当前为目标viewWindowCommand命令以当前window.

subl命令是一个帮助程序,它将命令行参数提供给正在运行的 Sublime 实例并终止;如果 Sublime 尚未运行,它会先启动 Sublime,然后传递参数。

在 Sublime 尚未运行的情况下,该--command参数将不起作用,因为sublSublime 启动后立即提供该参数,但插件主机需要一些时间才能可用于命令(在 Sublime 中,您会看到这种情况作为消息发生plugins loaded)在控制台中)。

因此,在执行此操作之前确保 Sublime 正在运行,或者先启动 Sublime,等待一秒钟左右,然后提供命令,这一点很重要。