升华文本3?向升华控制台发送命令

2024-04-19 02:28:09 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

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

有什么想法吗

谢谢


Tags: run文本命令功能view应用程序helloworld
1条回答
网友
1楼 · 发布于 2024-04-19 02:28:09

升华附带的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.

command参数要求您在一个参数中提供命令和所需的任何参数;例如:

tmartin:dart:~> subl  command "insert {\"characters\": \"Hello, World\"}"

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

subl命令是一个助手,它将其命令行参数提供给正在运行的Sublime实例并终止;在升华尚未运行的情况下,它首先启动升华,然后传递参数

在升华尚未运行的情况下, command参数将不起作用,因为subl在升华启动后立即提供参数,但插件主机需要一段时间才能对命令可用(在升华中,您可以在控制台中将此视为plugins loaded消息)

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

相关问题 更多 >