【问题标题】:Retrieve the current language from an editor object从编辑器对象中检索当前语言
【发布时间】:2015-04-09 03:51:50
【问题描述】:
使用此代码,我可以订阅 Atom 中每个编辑器的事件:
@subscriptions = new CompositeDisposable
@subscriptions.add atom.workspace.observeTextEditors (editor) =>
// any code to do on the editor
但是,如果编辑器使用特定语言,我只想订阅该编辑器。如何从编辑器对象中检索该语言?
【问题讨论】:
标签:
coffeescript
atom-editor
【解决方案1】:
这其实很简单!关键是Grammar 对象。
@subscriptions = new CompositeDisposable
@subscriptions.add atom.workspace.observeTextEditors (editor) =>
if editor.getGrammar().name == "name_of_language"
// code for this editor