使用此代码,我可以在Atom中订阅每个编辑器的事件:
@subscriptions = new CompositeDisposable
@subscriptions.add atom.workspace.observeTextEditors (editor) =>
// any code to do on the editor
但是,如果编辑器使用特定语言,我只想订阅编辑器。如何从编辑器对象中检索该语言?
答案 0 :(得分:1)
这实际上非常简单!关键是Grammar
对象。
@subscriptions = new CompositeDisposable
@subscriptions.add atom.workspace.observeTextEditors (editor) =>
if editor.getGrammar().name == "name_of_language"
// code for this editor