更轻松地访问 Sublime 宏 [英] Easier access to Sublime macros

查看:34
本文介绍了更轻松地访问 Sublime 宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在 Sublime Text 3 中记录、保存和加载宏,我也知道如何将这些宏绑定到键盘快捷键.

我想知道 sublime 中是否有插件或功能,这意味着我可以在侧边栏中显示我的宏?我知道我可以去

工具->宏->用户

但我希望可能有一个包或自定义选项,以便我可以在侧面板或菜单上看到我的宏并单击它们.我使用的是 mac,所以我不能使用诸如自动热键之类的东西来制作带有按钮的 GUI.

虽然我知道键盘快捷键很好且简单,但尝试记住哪个宏绑定到哪个组合键可能会有点棘手,更不用说不覆盖现有的快捷键了!

还有谁知道在 Sublime 中 Mac 键盘上弹出按钮的名称"键是什么?

解决方案

我想知道 sublime 中是否有一个插件或功能,这意味着我可以在侧边栏中显示我的宏?

侧边栏只能显示你在 Sublime 中打开过的文件和文件夹;它目前无法显示其他信息,也没有插件可以用来向其添加额外信息的 API.

可以使用现有功能对此进行近似处理,尽管它有点次优.您要做的第一件事是在您的 Preferences.sublime-settings 中关闭 preview_on_click,这样您就可以点击侧栏中的文件,而无需 Sublime 打开预览.

import sublime导入 sublime_plugin导入操作系统类 SidebarMacroCommand(sublime_plugin.TextCommand):def 运行(自我,编辑,文件=[]):宏 = "res://Packages%s" % (文件[0][len(sublime.packages_path()):].代替("\\", "/"))self.view.run_command("run_macro_file", {"file": 宏})def is_visible(self, files=[]):返回 (len(files) == 1 和files[0].startswith(sublime.packages_path()) 和文件[0].endswith(".sublime-macro"))

这个插件定义了一个 sidebar_macro 命令,如果侧边栏只选择了一个文件并且该文件是一个 sublime-macro,它只会在上下文菜单中显示自己位于 Packages 文件夹内某处的文件.选择后,它将执行该宏.

您还需要在您的 User 包中创建一个名为 Side Bar.sublime-menu 的文件,其中包含以下内容(如果您已经将命令添加到文件中)有一个):

<预><代码>[{ "caption": "-", "id": "end" },{ "caption": "Run Macro", "command": "sidebar_macro", "args": {"files": []} },]

总而言之,如果您将 User 包添加到侧栏(或者更合适地将您的宏放在一个文件夹中,然后只添加该子文件夹),您可以右键单击在侧栏中显示的宏之一上,然后选择 Run Macro 以执行它.

这在某种程度上可以满足您的需求,但它确实需要您使用特定设置并始终将特定文件夹添加到您的窗口中(尽管您也可以使用插件在某种程度上实现自动化).

<块引用>

还有谁知道mac键盘上弹出按钮的名称"键是什么?

为了知道 Sublime 如何看到键,用 View > 打开控制台.显示 Console 或关联的键(在项目旁边的菜单中可见),然后输入 sublime.log_input(True).一旦你这样做了,你按下的 Sublime 可以看到的每个键都将记录在控制台中,直到你重新启动 Sublime 或在调用中使用 False 将其关闭.

打开日志记录后,您可以按任意键来查看 Sublime 所看到的内容(如果有的话);操作系统或某些外部程序可能会看到密钥并使用它,而不允许 Sublime 看到它.在这种情况下,您要么无法使用该密钥,要么需要找到一种方法来让使用它的任何东西停止使用它.

I know how to record, save and load macros in Sublime Text 3, I also know how to bind these macros to keyboard shortcuts.

What I would like to know is there a plugin or feature in sublime that means I can have my macros showing in the sidebar ? I know that I can go to

tools->macros->user

But I was hoping that there was perhaps a package or customisation option so I can see my macros on a side panel or menu and click on them. I'm using a mac so I can't use things like auto hotkey to make a GUI with buttons.

And while I'm aware keyboard shortcuts are nice and easy, it can prove a little tricky trying remember what macro is bound to what key combination, not to mention not overwriting already existing shortcuts!

Also does anyone know what the key "name" is in Sublime for the eject button on the mac keyboard?

解决方案

What I would like to know is there a plugin or feature in sublime that means I can have my macros showing in the sidebar ?

The sidebar can only display the files and folders that you have open in Sublime; it can't display other information currently and there is also not an API that a plugin could use to add extra information to it either.

It's possible to approximate this with existing functionality, though it's a bit suboptimal. The first thing you have to do is turn off preview_on_click in your Preferences.sublime-settings so that you can click on files in the side bar without Sublime opening a preview.

import sublime
import sublime_plugin

import os


class SidebarMacroCommand(sublime_plugin.TextCommand):
    def run(self, edit, files=[]):
        macro = "res://Packages%s" % (
            files[0][len(sublime.packages_path()):]
            .replace("\\", "/")
            )
        self.view.run_command("run_macro_file", {"file": macro})

    def is_visible(self, files=[]):
        return (len(files) == 1 and
                files[0].startswith(sublime.packages_path()) and
                files[0].endswith(".sublime-macro"))

This plugin defines a sidebar_macro command that will only make itself visible in the context menu if the side bar has exactly one file selected and that file is a sublime-macro file that is somewhere inside of the Packages folder. When selected it will execute that macro.

You also need to create a file named Side Bar.sublime-menu in your User package with the following content (or add the command to the file if you already have one):

[
    { "caption": "-", "id": "end" },
    { "caption": "Run Macro", "command": "sidebar_macro", "args": {"files": []} },
]

Taken all together, if you add your User package to the side bar (or more appropriately put your macros inside of a folder in it and then add just that sub folder), you can right click on one of the displayed macros in the side bar and select Run Macro to execute it.

This will do somewhat what you want, but it does require that you use specific settings and always add a specific folder to your windows (although you could also automate that somewhat with a plugin as well).

Also does anyone know what the key "name" is in sublime for the eject button on the mac keyboard?

In order to know how Sublime sees keys, open the console with View > Show Console or the associated key (visible in the menu next to the item) and then enter sublime.log_input(True). Once you do that, every key you press that Sublime can see will be logged in the console until you restart Sublime or use False in the call to turn it off.

With logging turned on you can press any key to see what Sublime sees it as, if anything; it's possible that the operating system or some external program may see the key and use it without allowing Sublime to see it. In that case you either can't use the key or you need to find a way to make whatever it using it stop using it.

这篇关于更轻松地访问 Sublime 宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆