2014-09-23 79 views
6

我最近開始使用Atom。我遇到的一個問題是,爲Ruby定義了太多/不明確的片段。這使得製表完成變得更糟,因爲你有時會得到一些不相關的代碼而不是你想要的名字。我想知道如何關閉「語言Ruby」包中的特定片段,否則關閉所有片段。最好不要完全禁用Ruby包。如何關閉Atom中的片段?

回答

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 
+0

似乎不工作了。 '無法找到模塊'/ usr/share/atom/resources/app.asar/node_modules/snippets'' – user33946 2015-12-19 12:27:01

相關問題