Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off snippets in Atom?

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.

like image 744
keiter Avatar asked Sep 23 '14 08:09

keiter


1 Answers

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
like image 95
Cédric Néhémie Avatar answered Sep 23 '22 22:09

Cédric Néhémie