且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不编辑的情况下向 Sublime Text 中的语法定义添加功能?

更新时间:2021-11-15 01:41:04

在我看来,您想创建自己的语法文件,从 Python 语法文件 (source.python) 继承,并且在那里进行更改和自定义.Sublime Text 2 使用 .tmLanguage 格式的语法文件,有点复杂,不过好在大部分工作已经为你完成了,只需继承source.python即可.

Sounds to me like you want to create your own syntax file, inherit from the Python syntax file (source.python), and make your changes and customizations there. Sublime Text 2 uses the .tmLanguage format for syntax files, which is a bit complex, but fortunately most of the work has already been done for you, just by inheriting from source.python.

您要做的是设置一个正则表达式模式来匹配您要突出显示的子字符串,并为该模式命名;类似于 punctuation.definition.comment.epydoc,遵循 Java/JavaDoc.tmLanguage 中设置的约定.然后,检查您的配色方案文件(以 .tmTheme 结尾)并确保为您选择的范围或其中一个父级设置了设置,因为 ST2 应该使用正确的范围规则对于这种事情.

What you want to do is set up a regex pattern to match the substrings that you want to highlight, and give that pattern a name; something like punctuation.definition.comment.epydoc, to follow the convention set in Java/JavaDoc.tmLanguage. Then, check your color scheme file (ending in .tmTheme) and make sure there are settings for the scope that you've chosen -- or for one of its parents, since ST2 should use proper scoping rules for this sort of thing.

要使用您创建的语法文件,请将其粘贴在 Packages/User(以便 ST2 不会在升级时覆盖它),在编辑器中打开一个 Python 文件,然后选择窗口右下角下拉列表中的新语法.如果您已正确设置所有内容,则 epydoc 字符串应更改为您在配色方案中设置的任何颜色.

To use the syntax file you've created, stick it in Packages/User (so that ST2 doesn't overwrite it on upgrades), open a Python file in the editor, and then select your new syntax from the dropdown list in the bottom right corner of the window. If you've set up everything correctly, the epydoc strings should change to be whatever color you've set in your color scheme.

祝你好运!当你有一个有效的语法文件时,在某处张贴一个链接,这样其他人也可以看到和使用它!

Good luck! And post a link somewhere when you've got a syntax file that works, so others can see and use it, as well!