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

Retrieve the current language from an editor object

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

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

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

这其实很简单!关键是 Grammar 对象。

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