从编辑器对象中检索当前语言

时间:2015-04-09 03:51:51

标签: coffeescript atom-editor

使用此代码,我可以在Atom中订阅每个编辑器的事件:

@subscriptions = new CompositeDisposable
@subscriptions.add atom.workspace.observeTextEditors (editor) =>
    // any code to do on the editor

但是,如果编辑器使用特定语言,我只想订阅编辑器。如何从编辑器对象中检索该语言?

1 个答案:

答案 0 :(得分:1)

这实际上非常简单!关键是Grammar对象。

@subscriptions = new CompositeDisposable
@subscriptions.add atom.workspace.observeTextEditors (editor) =>
    if editor.getGrammar().name == "name_of_language"
        // code for this editor