如何关闭Atom中的代码段?

kei*_*ter 7 configuration code-snippets atom-editor

我最近开始使用Atom.我遇到的一个问题是为Ruby定义了太多/不明确的片段.这会使标签更糟糕,因为您有时会获得一些不相关的代码而不是您想要的名称.我想知道如何关闭"语言Ruby"包中的特定片段,或者关闭所有片段的失败.最好不要完全禁用Ruby包.

小智 3

遗憾的是,目前还没有此类功能的内置功能。

在将某些过滤器功能添加到片段包之前,访问片段的唯一方法是从初始化脚本中对包进行猴子修补。

例如,类似的东西将允许您在运行时过滤为给定编辑器返回的片段:

# 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
Run Code Online (Sandbox Code Playgroud)