问题描述
我最近开始使用 Atom .我遇到的一个问题是,为Ruby定义的片段太多/含糊不清.这会使制表符的完成变得更糟,因为有时您会得到一些不相关的代码,而不是想要的名称.我想知道如何从"Language Ruby"包中关闭特定的片段,或者是否无法关闭所有片段.最好不要完全禁用Ruby软件包.
I've recently started using Atom. One problem I've run into is that there are too many / ambiguous snippets defined for Ruby. This makes tab completion worse, as you sometimes get a bit of irrelevant code instead of the name you wanted. I'm wondering how to turn off a specific snippet from the "Language Ruby" package, or failing that turning off all snippets. Preferably without disabling the Ruby package entirely.
推荐答案
遗憾的是,目前没有内置功能可用于这种事情.
Sadly, there's currently no built-in feature for this kind of thing.
在代码片段包中添加了一些过滤器功能之前,访问代码片段的唯一方法是从您的init脚本中猴子打包该包.
Until some filter feature is added to the snippets package, the only way to access the snippets is to monkey-patch the package from your init script.
例如,类似的内容将允许您在运行时过滤给定编辑器返回的代码片段:
For instance something like that will allow you to filter the snippets returned for a given editor at runtime:
# 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
这篇关于如何关闭Atom中的代码段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!