【发布时间】:2019-04-14 11:49:45
【问题描述】:
我一直在关注this、this、this、this 和 this 在 ST3 中创建自己的模板。因此,当我创建一个新文件时,我会使用模板内容预加载该文件。我已阅读我应该使用 sn-p 来执行此操作。
我创建了一个文件并尝试在新的view 中应用snippet,但没有任何反应,我没有得到任何反馈(即使我故意输入了错误的sn-p 名称也没有)。我的 sn-p 在我的插件文件夹中:
C:\Users\...\AppData\Roaming\Sublime Text 3\Packages\MyPlugin\templ.sublime-snippet
我的多次尝试如下:
def on_done(...):
...
open(path, 'a').close()
new_view = self.window.open_file(path)
# These seem to work, so the view seems valid
print(new_view.file_name())
print(new_view.line_height())
# Attempt 1
template = """<snippet>
<content><![CDATA[
Hello, \${1:this} is a \${2:snippet}.
]]></content>
</snippet>
"""
new_view.run_command("insert_snippet", {"contents": template})
# Attempt 2: from the user folder. Nothing happens
new_view.run_command("insert_snippet", { "name": "Packages/User/templ.sublime-snippet" })
# Attempt 3: from current (?) folder just in case
new_view.run_command("insert_snippet", {"name" : "templ.sublime-snippet"})
# Attempt 4, from the actual plugin folder
new_view.run_command("insert_snippet", {"name" : "Packages/MyPlugin/templ.sublime-snippet"})
# Attempt 5, absolute directory
new_view.run_command("insert_snippet", {"name" : "C:\\Users\\nerea\\AppData\\Roaming\\Sublime Text 3\\Packages\\MyPlugin\\templ.sublime-snippet"})
# Attempt 6, to check if I mistook the path if I would get any error
new_view.run_command("insert_snippet", {"name" : "Packages/User/nonexisting.sublime-snippet"})
# Attempt 7, nothing either
new_view.run_command("insert_snippet", {"contents" : "<snippet><content><![CDATA[Hello, ${1:this} is a ${2:snippet}.]]></content></snippet>"})
# This does nothing either. I supposed that should do something
new_view.run_command("insert", "wawawiwa")
【问题讨论】:
标签: python sublimetext3 sublime-text-plugin