【发布时间】:2014-09-23 08:04:46
【问题描述】:
我最近开始使用Atom。我遇到的一个问题是为 Ruby 定义了太多/不明确的 sn-ps。这使制表符补全变得更糟,因为您有时会得到一些不相关的代码而不是您想要的名称。我想知道如何从“Language Ruby”包中关闭特定的 sn-p,或者无法关闭所有 sn-ps。最好不要完全禁用 Ruby 包。
【问题讨论】:
标签: configuration code-snippets atom-editor
我最近开始使用Atom。我遇到的一个问题是为 Ruby 定义了太多/不明确的 sn-ps。这使制表符补全变得更糟,因为您有时会得到一些不相关的代码而不是您想要的名称。我想知道如何从“Language Ruby”包中关闭特定的 sn-p,或者无法关闭所有 sn-ps。最好不要完全禁用 Ruby 包。
【问题讨论】:
标签: configuration code-snippets atom-editor
遗憾的是,目前还没有这种东西的内置功能。
在向 sn-ps 包添加一些过滤器功能之前,访问 sn-ps 的唯一方法是从您的 init 脚本中对包进行猴子补丁。
例如,类似的东西将允许您在运行时过滤给定编辑器返回的 sn-ps:
# we need a reference to the snippets package
snippetsPackage = require(atom.packages.getLoadedPackage('snippets').path)
# we need a reference to the original method we'll monkey patch
__oldGetSnippets = snippetsPackage.getSnippets
snippetsPackage.getSnippets = (editor) ->
snippets = __oldGetSnippets.call(this, editor)
# we're only concerned by ruby files
return snippets unless editor.getGrammar().scopeName is 'source.ruby'
# snippets is an object where keys are the snippets's prefixes and the values
# the snippets objects
console.log snippets
newSnippets = {}
excludedPrefixes = ['your','prefixes','exclusion','list']
for prefix, snippet of snippets
newSippets[prefix] = snippet unless prefix in excludedPrefixes
newSnippets
【讨论】:
Cannot find module '/usr/share/atom/resources/app.asar/node_modules/snippets'
有两个包:
snippets和autocomplete-snippets,您可以从设置视图包选项卡中禁用它们。autocomplete-snippets是将 sn-ps 添加到自动完成+建议的包。
【讨论】:
我也遭受了 Atom 中的 sn-p 过载的困扰。虽然我找不到在设置中关闭 sn-ps 的方法,但我现在找到了一个可行的解决方案。
在自定义 sn-ps 文件(Mac 菜单:Atom > Snippets...)中,在您的 sn-ps 前缀属性前添加一些字母。这样,它们总是被排序到自动完成列表的顶部。我选择了字母“aa”。
Ember sn-p 示例:
"Dirk's Label & Input":
'prefix': 'aaLabel & Input'
'body': """
<label>
$1
<Input
@type='text'
@value={{this.$2}}
/>
</label>
"""
现在,当我输入 aa 时,我的所有 sn-ps 都会先显示... ;-)
【讨论】: