作者:HHH_YYYY | 来源:互联网 | 2022-12-29 10:44
1> OdatNurd..:
Sublime中有一个相当完整的核心命令列表,可通过非官方文档获得,特别是在命令列表部分.但是,这并不能帮助您了解第三方软件包和插件可能添加的命令.
在你的问题中,你提到了如何获得一个命令,但不知道它可能是为了在其他地方使用它的目的.如果您正在了解某种方式来调用命令(键,命令调色板,菜单)并想知道命令是什么,Sublime会让您满意.
如果使用Ctrl+`或打开Sublime控制台View > Show Console
,则可以输入以下命令:
sublime.log_commands(True)
现在每当你做任何事情时,Sublime都会记录它正在执行控制台的命令,以及它可能需要的任何参数.例如,如果您打开日志记录并依次按下每个箭头键,控制台将显示以下内容:
command: move {"by": "lines", "forward": false}
command: move {"by": "lines", "forward": true}
command: move {"by": "characters", "forward": false}
command: move {"by": "characters", "forward": true}
使用此工具,您可以确定各种操作所执行的命令,以便您可以在其他位置使用它们.例如,这也是一种用于诊断键盘快捷键等方法的便捷技术,这些键盘快捷键似乎没有按照您认为应该执行的操作.运行相同的命令False
而不是True
(或重新启动Sublime)以关闭注销.
如果您真的对每个可能命令的细节内部细节感兴趣,可以使用以下内容.这实现了一个标记的命令list_all_commands
,当您运行它时,会将所有类型的所有可用命令列入新的暂存缓冲区.
请注意,并非所有实现的命令都必须用于外部使用; 插件有时会定义帮助程序命令供自己使用.这意味着尽管这会告诉您所有存在的命令,但这并不意味着所有这些命令都适合您使用.
此外,虽然这大致列出run
了命令类上的方法所采用的参数(这是Sublime执行以运行命令的参数),但某些命令可能具有模糊的参数列表.
import sublime
import sublime_plugin
import inspect
from sublime_plugin import application_command_classes
from sublime_plugin import window_command_classes
from sublime_plugin import text_command_classes
class ListAllCommandsCommand(sublime_plugin.WindowCommand):
def run(self):
self.view = self.window.new_file()
self.view.set_scratch(True)
self.view.set_name("Command List")
self.list_category("Application Commands", application_command_classes)
self.list_category("Window Commands", window_command_classes)
self.list_category("Text Commands", text_command_classes)
def append(self, line):
self.view.run_command("append", {"characters": line + "\n"})
def list_category(self, title, command_list):
self.append(title)
self.append(len(title)*"=")
for command in command_list:
self.append("{cmd} {args}".format(
cmd=self.get_name(command),
args=str(inspect.signature(command.run))))
self.append("")
def get_name(self, cls):
clsname = cls.__name__
name = clsname[0].lower()
last_upper = False
for c in clsname[1:]:
if c.isupper() and not last_upper:
name += '_'
name += c.lower()
else:
name += c
last_upper = c.isupper()
if name.endswith("_command"):
name = name[0:-8]
return name