【问题标题】: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
    

    【讨论】:

    • 您可能会将您的答案标记为对其他人的正确答案:)
    • 我得再等一天。 =P
    猜你喜欢
    • 2015-04-06
    • 2014-01-26
    • 1970-01-01
    • 2010-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多