如何编辑内置命令行为 [英] How to edit built in command behavior
问题描述
我想编辑 find_under_expand
(ctrl+d
) 以将带连字符的单词视为单个单词.因此,当我尝试替换 var a
的所有实例时,它不应该匹配 a-b
之类的单词中的a"子字符串,而它目前确实如此.
I want to edit find_under_expand
(ctrl+d
) to consider hyphenated words, as single words. So when I try to replace all instance of var a
, it shouldn't match substrings of "a" in words like a-b
, which it currently does.
我假设 find_under_expand
将您当前的选择包裹在这样的正则表达式边界中:\ba\b
I'm assuming find_under_expand
wraps your current selection in regex boundaries like this: \ba\b
我需要用这样的方式包装它:\b(?<!-)a(?!-)\b
I need it to wrap in something like this: \b(?<!-)a(?!-)\b
find_under_expand
命令的源是否可以编辑?还是我必须重写整个事情?我不知道从哪里开始.
Is the find_under_expand
command's source available to edit? Or do I have to rewrite the whole thing? I'm not sure where to begin.
推荐答案
Sublime 的命令以以下几种方式之一实现:如 宏,如插件,并在内部作为编译程序的一部分(可能作为 C++).默认的宏和插件可以在 ST2 的 Packages/Default
目录中找到(其中 Packages
是选择 Preferences -> Browse 时打开的目录Packages...
),或压缩在 ST3 中的 Installed Packages/Default.sublime-package
文件中,使用@skuroda 的优秀PackageResourceViewer
插件,可通过包控制获得.宏具有 .sublime-macro
扩展名,而插件是用 Python 编写的并具有 .py
扩展名.
Sublime's commands are implemented in one of several ways: as macros, as plugins, and internally as part of the compiled program (probably as C++). The default macros and plugins can be found in the Packages/Default
directory in ST2 (where Packages
is the directory opened when selecting Preferences -> Browse Packages...
), or zipped in the Installed Packages/Default.sublime-package
file in ST3, extractable using @skuroda's excellent PackageResourceViewer
plugin, available via Package Control. Macros have .sublime-macro
extensions, while plugins are written in Python and have .py
extensions.
我在 ST3 中搜索了所有 Defaults
包(事情通常与 ST2 中的相同),但找不到包含的宏或 .py
文件find_under_expand
命令或 FindUnderExpand
,这是在插件中命名命令类时的约定.因此,我强烈怀疑这个命令是 Sublime 的内部命令,可能是用 C++ 编写的并链接到可执行文件或 .dll|.dylib|.so
库中.
I searched all through the Defaults
package in ST3 (things are generally the same as in ST2), and was unable to find a macro or .py
file that included the find_under_expand
command, or FindUnderExpand
, which is the convention when naming command classes in plugins. Therefore, I strongly suspect that this command is internal to Sublime, probably written in C++ and linked into the executable or in a .dll|.dylib|.so
library.
所以,看起来没有一个现有文件可以轻松修改以适应您的负面前瞻/后视模式(我认为这就是那些,我的正则表达式有点生疏......).相反,您必须从头开始实现自己的插件,读取设置文件中的 "word_separators"
值,而 find_under_expand
的当前实现似乎没有正在做,从你的上一个问题来看和我自己的测试.从理论上讲,这应该不会太困难 - 您可以打开一个快速面板,用户可以在其中输入要搜索的模式/正则表达式,并且您可以遍历当前视图以查找匹配项并突出显示/选择它们.
So, it doesn't look like there's an existing file that you could easily modify to adjust for your negative lookahead/lookbehind patterns (I assume that's what those are, my regex is a bit rusty...). Instead, you'll have to implement your own plugin from scratch that reads the "word_separators"
value in your settings file, which the current implementation of find_under_expand
doesn't seem to be doing, judging from your previous question and my own testing. Theoretically, this shouldn't be too terribly difficult - you can just open up a quick panel where the user enters the pattern/regex to be searched for, and you can just iterate through the current view looking for matches and highlighting/selecting them.
祝你好运!
这篇关于如何编辑内置命令行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!