How to turn off snippets in Atom?

社会主义新天地 提交于 2019-12-06 00:05:27

问题


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.


回答1:


Sadly, there's currently no built-in feature for this kind of thing.

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


来源:https://stackoverflow.com/questions/25989997/how-to-turn-off-snippets-in-atom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!