我想对我的Mercurial提交消息使用sublime,所以我设置了
HGEDITOR="C:\Program Files\Sublime Text 3\subl.exe" -w -n a
这将从名为hg-editor-mstdne.commit.hg.txt
的文件开始Sublime。
然后,我希望能够自动将其换成72个字符(例如Sublime Text line wrap and commit messages)。这可以按语法完成,因此我已经为其定义了语法
%YAML 1.2
---
name: hg-commit
file_extensions: [.commit.hg.txt]
scope: text.hg
contexts:
main:
- match: "^HG:.*"
captures:
0: comment.line.hg-commit
我可以手动选择语法,但是提交仍以纯文本格式打开。如果我选择View-> Syntax->'Open all with current extension as',那么所有其他.txt文件也将使用hg-commit语法打开。
有没有办法让它仅将我的语法用于汞提交消息文件?
[@ OdatNurd建议,on_load
事件非常简单。
import sublime_plugin
# Load special syntax for hg commit. Also sets line wrapping
class RtxOnload(sublime_plugin.EventListener):
def on_load(self, view):
if view.file_name().endswith('.commit.hg.txt'):
view.settings().set('syntax', 'Packages/MLA/hg-commit.sublime-syntax')
view.settings().set('wrap_width', 72)
唯一的问题是,仅当Sublime已在运行时,它才有效。这可能可以用其他挂钩解决,但对我来说这不是问题。